@@ -649,6 +649,40 @@ <h3>Edit DNS Credential</h3>
649649 </ div >
650650 </ div >
651651
652+ <!-- Edit ZT-Domain Modal -->
653+ < div id ="edit-zt-domain-modal " class ="modal-overlay ">
654+ < div class ="modal ">
655+ < h3 > Edit ZT-Domain</ h3 >
656+ < input type ="hidden " id ="edit-domain-original ">
657+ < div class ="modal-field ">
658+ < label > Domain (cannot be changed)</ label >
659+ < input type ="text " id ="edit-domain-name " readonly disabled >
660+ </ div >
661+ < div class ="modal-field ">
662+ < label > DNS Credential</ label >
663+ < select id ="edit-domain-dns-cred ">
664+ < option value =""> Use Default</ option >
665+ </ select >
666+ </ div >
667+ < div class ="modal-field ">
668+ < label > Port (0 = default)</ label >
669+ < input type ="number " id ="edit-domain-port " placeholder ="443 " min ="0 " max ="65535 ">
670+ </ div >
671+ < div class ="modal-field ">
672+ < label > Node Binding (0 = any node)</ label >
673+ < input type ="number " id ="edit-domain-node " placeholder ="0 " min ="0 ">
674+ </ div >
675+ < div class ="modal-field ">
676+ < label > Priority (higher = preferred as default)</ label >
677+ < input type ="number " id ="edit-domain-priority " placeholder ="0 ">
678+ </ div >
679+ < div class ="modal-actions ">
680+ < button class ="action-btn secondary " onclick ="hideModal('edit-zt-domain-modal') "> Cancel</ button >
681+ < button class ="action-btn primary " onclick ="updateZtDomain() "> Update</ button >
682+ </ div >
683+ </ div >
684+ </ div >
685+
652686 <!-- Add ZT-Domain Modal -->
653687 < div id ="add-zt-domain-modal " class ="modal-overlay ">
654688 < div class ="modal ">
@@ -1037,6 +1071,8 @@ <h3>Add ZT-Domain</h3>
10371071
10381072 // ==================== ZT-Domains ====================
10391073
1074+ let ztDomains = [ ] ;
1075+
10401076 async function loadZtDomains ( ) {
10411077 try {
10421078 const response = await fetch ( '/prpc/Admin.ListZtDomains' , {
@@ -1045,7 +1081,8 @@ <h3>Add ZT-Domain</h3>
10451081 body : '{}'
10461082 } ) ;
10471083 const data = await response . json ( ) ;
1048- renderZtDomains ( data . domains || [ ] ) ;
1084+ ztDomains = data . domains || [ ] ;
1085+ renderZtDomains ( ztDomains ) ;
10491086 } catch ( e ) {
10501087 document . getElementById ( 'zt-domains' ) . innerHTML =
10511088 '<p style="color: #666;">Failed to load ZT-Domains</p>' ;
@@ -1100,6 +1137,7 @@ <h3>Add ZT-Domain</h3>
11001137 </td>
11011138 <td class="timestamp" data-original="${ expiresAt } ">${ certStatus . not_after || 0 } </td>
11021139 <td>
1140+ <button class="action-btn secondary" onclick="showEditZtDomainModal('${ escapeHtml ( config . domain ) } ')">Edit</button>
11031141 <button class="action-btn warning" onclick="renewZtDomainCert('${ escapeHtml ( config . domain ) } ', false)">Renew</button>
11041142 <button class="action-btn secondary" onclick="renewZtDomainCert('${ escapeHtml ( config . domain ) } ', true)">Force Renew</button>
11051143 <button class="action-btn danger" onclick="deleteZtDomain('${ escapeHtml ( config . domain ) } ')">Delete</button>
@@ -1138,6 +1176,76 @@ <h3>Add ZT-Domain</h3>
11381176 showModal ( 'add-zt-domain-modal' ) ;
11391177 }
11401178
1179+ function updateEditDnsCredSelect ( ) {
1180+ const select = document . getElementById ( 'edit-domain-dns-cred' ) ;
1181+ select . innerHTML = '<option value="">Use Default</option>' ;
1182+ for ( const cred of dnsCredentials ) {
1183+ const isDefault = cred . id === defaultDnsCredId ;
1184+ select . innerHTML += `<option value="${ cred . id } ">${ escapeHtml ( cred . name ) } ${ isDefault ? ' (default)' : '' } </option>` ;
1185+ }
1186+ }
1187+
1188+ function showEditZtDomainModal ( domain ) {
1189+ const item = ztDomains . find ( d => d . config && d . config . domain === domain ) ;
1190+ if ( ! item ) {
1191+ showToast ( 'ZT-Domain not found' , 'error' ) ;
1192+ return ;
1193+ }
1194+
1195+ const config = item . config ;
1196+ document . getElementById ( 'edit-domain-original' ) . value = config . domain ;
1197+ document . getElementById ( 'edit-domain-name' ) . value = config . domain ;
1198+ document . getElementById ( 'edit-domain-port' ) . value = config . port || 0 ;
1199+ document . getElementById ( 'edit-domain-node' ) . value = ( config . node !== undefined && config . node !== null ) ? config . node : 0 ;
1200+ document . getElementById ( 'edit-domain-priority' ) . value = config . priority || 0 ;
1201+
1202+ updateEditDnsCredSelect ( ) ;
1203+ document . getElementById ( 'edit-domain-dns-cred' ) . value = config . dns_cred_id || '' ;
1204+
1205+ showModal ( 'edit-zt-domain-modal' ) ;
1206+ }
1207+
1208+ async function updateZtDomain ( ) {
1209+ const domain = document . getElementById ( 'edit-domain-original' ) . value ;
1210+ const dnsCredId = document . getElementById ( 'edit-domain-dns-cred' ) . value ;
1211+ const port = parseInt ( document . getElementById ( 'edit-domain-port' ) . value ) || 0 ;
1212+ const nodeInput = document . getElementById ( 'edit-domain-node' ) . value . trim ( ) ;
1213+ const node = ( nodeInput && nodeInput !== '0' ) ? parseInt ( nodeInput ) : null ;
1214+ const priority = parseInt ( document . getElementById ( 'edit-domain-priority' ) . value ) || 0 ;
1215+
1216+ if ( ! domain ) {
1217+ showToast ( 'Domain is required' , 'error' ) ;
1218+ return ;
1219+ }
1220+
1221+ const body = {
1222+ domain : domain ,
1223+ dns_cred_id : dnsCredId ,
1224+ port : port ,
1225+ priority : priority
1226+ } ;
1227+ if ( node !== null && node > 0 ) {
1228+ body . node = node ;
1229+ }
1230+
1231+ try {
1232+ const response = await fetch ( '/prpc/Admin.UpdateZtDomain' , {
1233+ method : 'POST' ,
1234+ headers : { 'Content-Type' : 'application/json' } ,
1235+ body : JSON . stringify ( body )
1236+ } ) ;
1237+ if ( ! response . ok ) {
1238+ const err = await response . text ( ) ;
1239+ throw new Error ( err ) ;
1240+ }
1241+ hideModal ( 'edit-zt-domain-modal' ) ;
1242+ showToast ( 'ZT-Domain updated' , 'success' ) ;
1243+ await loadZtDomains ( ) ;
1244+ } catch ( e ) {
1245+ showToast ( 'Failed to update ZT-Domain: ' + e . message , 'error' ) ;
1246+ }
1247+ }
1248+
11411249 async function addZtDomain ( ) {
11421250 const domain = document . getElementById ( 'domain-name' ) . value . trim ( ) ;
11431251 const dnsCredId = document . getElementById ( 'domain-dns-cred' ) . value ;
0 commit comments