55use OpenProvider \API \ApiHelper ;
66use OpenProvider \WhmcsRegistrar \helpers \DNS ;
77use OpenProvider \WhmcsRegistrar \helpers \DomainFullNameToDomainObject ;
8+ use OpenProvider \WhmcsRegistrar \helpers \DnssecManagement ;
89use WHMCS \Database \Capsule ;
910
1011/**
1617class ClientAreaPrimarySidebarController
1718{
1819 const DNSSEC_PAGE_NAME = '/dnssec.php ' ;
20+ const DNS_MANAGEMENT_PAGE_NAME = '/dnsmanagement.php ' ;
1921
2022 /**
2123 * @var ApiHelper
@@ -29,6 +31,8 @@ public function __construct(ApiHelper $apiHelper)
2931
3032 public function show ($ primarySidebar )
3133 {
34+ $ this ->ensureDnsManagementPageExists ();
35+
3236 $ this ->replaceDnsMenuItem ($ primarySidebar );
3337
3438 $ this ->addDNSSECMenuItem ($ primarySidebar );
@@ -43,7 +47,12 @@ private function replaceDnsMenuItem($primarySidebar)
4347 if (!$ dnsManagement = $ domainDetailsManagement ->getChild ('Manage DNS Host Records ' ))
4448 return ;
4549
46- if ($ url = DNS ::getDnsUrlOrFail ($ _REQUEST ['domainid ' ])) {
50+ $ domainId = $ _REQUEST ['domainid ' ] ?? $ _REQUEST ['id ' ] ?? null ;
51+ if (!$ domainId ) {
52+ return ;
53+ }
54+
55+ if ($ url = DNS ::getDnsUrlOrFail ($ domainId )) {
4756 // Update the URL.
4857 $ dnsManagement ->setUri ($ url );
4958
@@ -57,7 +66,10 @@ private function replaceDnsMenuItem($primarySidebar)
5766</script>
5867<a href= \'# \' style= \'display:none; \'> ' ;
5968 $ dnsManagement ->setLabel ($ label );
69+ return ;
6070 }
71+ // Fallback to custom DNS Management page if single-domain DNS URL is not available
72+ $ dnsManagement ->setUri ("dnsmanagement.php?domainid= {$ domainId }" );
6173 }
6274
6375 private function addDNSSECMenuItem ($ primarySidebar )
@@ -82,14 +94,43 @@ private function addDNSSECMenuItem($primarySidebar)
8294 $ domainId = isset ($ _REQUEST ['domainid ' ]) ? $ _REQUEST ['domainid ' ] : $ _REQUEST ['id ' ];
8395 $ isDomainEnabled = Capsule::table ('tbldomains ' )
8496 ->where ('id ' , $ domainId )
85- ->select ('status ' , ' dnsmanagement ' , 'domain ' )
97+ ->select ('status ' ,'domain ' )
8698 ->first ();
8799
88- if ($ isDomainEnabled ->dnsmanagement != 1 ){
100+ if (!$ isDomainEnabled ) {
101+ return ;
102+ }
103+
104+ $ dnssecMgmt = DnssecManagement::getFlag ((int )$ domainId ); // 0/1
105+ if ($ dnssecMgmt !== 1 ) {
89106 return ;
90107 }
91108
92109 $ domain = DomainFullNameToDomainObject::convert ($ isDomainEnabled ->domain );
110+ $ tld = null ;
111+ if (is_object ($ domain ) && method_exists ($ domain , 'getExtension ' )) {
112+ $ tld = $ domain ->getExtension ();
113+ } else {
114+ $ labels = array_values (array_filter (explode ('. ' , strtolower ($ isDomainEnabled ->domain ))));
115+ if (count ($ labels ) > 1 ) {
116+ array_shift ($ labels );
117+ $ tld = implode ('. ' , $ labels );
118+ }
119+ }
120+
121+ if (empty ($ tld )) {
122+ logModuleCall ('openprovider ' , 'supportsDnssec ' , ['domain ' => $ isDomainEnabled ->domain ], null , 'Could not derive TLD ' , null );
123+ return ;
124+ }
125+
126+ try {
127+ if (!$ this ->apiHelper ->supportsDnssec ($ tld )) {
128+ return ;
129+ }
130+ } catch (\Exception $ e ) {
131+ return ;
132+ }
133+
93134 try {
94135 $ op_domain = $ this ->apiHelper ->getDomain ($ domain );
95136 } catch (\Exception $ e ) {
@@ -109,4 +150,42 @@ private function addDNSSECMenuItem($primarySidebar)
109150 ->setOrder (100 );
110151 }
111152 }
112- }
153+
154+ private function ensureDnsManagementPageExists ()
155+ {
156+ $ rootDir = $ GLOBALS ['whmcsAppConfig ' ]->getRootDir ();
157+ $ destination = $ rootDir . self ::DNS_MANAGEMENT_PAGE_NAME ;
158+
159+ // Check if dnsmanagement.php file exists in the root directory
160+ if (file_exists ($ destination ) && !empty (trim ((string ) @file_get_contents ($ destination )))) {
161+ return ;
162+ }
163+
164+ $ source = $ rootDir . "/modules/registrars/openprovider/custom-pages " . self ::DNS_MANAGEMENT_PAGE_NAME ;
165+
166+ // Explicitly check source exists
167+ if (!file_exists ($ source )) {
168+ logModuleCall (
169+ 'openprovider nl ' ,
170+ 'copydnsmanagementfile ' ,
171+ ['source ' => $ source , 'destination ' => $ destination ],
172+ "Source dnsmanagement.php not found. Please upload it manually. " ,
173+ null ,
174+ null
175+ );
176+ return ;
177+ }
178+
179+ // copy
180+ if (!copy ($ source , $ destination )) {
181+ logModuleCall (
182+ 'openprovider nl ' ,
183+ 'copydnsmanagementfile ' ,
184+ ['source ' => $ source , 'destination ' => $ destination ],
185+ "Failed to copy dnsmanagement.php to WHMCS root directory. Please upload it manually. " ,
186+ null ,
187+ null
188+ );
189+ }
190+ }
191+ }
0 commit comments