@@ -78,7 +78,7 @@ public function get_acme_command($domains, $key_file, $bundle_file, $cert_file,
7878 }
7979
8080 $ dns = '' ;
81- if ($ global_sites_config ['acme_dns_user ' ] != '' ) {
81+ if ($ global_sites_config ['acme_dns_user ' ] != '' && (! isset ( $ conf [ ' powerdns ' ][ ' installed ' ]) || isset ( $ conf [ ' powerdns ' ][ ' installed ' ]) && $ conf [ ' powerdns ' ][ ' installed ' ] == false ) ) {
8282 $ dns_ISPC_User = $ global_sites_config ['acme_dns_user ' ];
8383 $ dns_ISPC_Password = $ global_sites_config ['acme_dns_password ' ];
8484 $ dns_ISPC_Api = $ global_sites_config ['acme_dns_api ' ];
@@ -384,9 +384,9 @@ public function request_certificates($data, $server_type = 'apache') {
384384 $ aliasdomains = null ;
385385
386386 //* be sure to have good domain
387- if (substr ($ domain ,0 ,4 ) != 'www. ' && ($ data ['new ' ]['subdomain ' ] == "www " || ($ data ['new ' ]['subdomain ' ] == "* " && (!$ use_acme || $ global_sites_config ['acme_dns_user ' ] == '' )))) {
387+ if (substr ($ domain ,0 ,4 ) != 'www. ' && ($ data ['new ' ]['subdomain ' ] == "www " || ($ data ['new ' ]['subdomain ' ] == "* " && (!$ use_acme || $ global_sites_config ['acme_dns_user ' ] == '' && (! isset ( $ conf [ ' powerdns ' ][ ' installed ' ]) || isset ( $ conf [ ' powerdns ' ][ ' installed ' ]) && $ conf [ ' powerdns ' ][ ' installed ' ] == false ) )))) {
388388 $ temp_domains [] = "www. " . $ domain ;
389- } elseif ($ data ['new ' ]['subdomain ' ] == "* " && ($ use_acme && $ global_sites_config ['acme_dns_user ' ] != '' )) {
389+ } elseif ($ data ['new ' ]['subdomain ' ] == "* " && ($ use_acme && $ global_sites_config ['acme_dns_user ' ] != '' && (! isset ( $ conf [ ' powerdns ' ][ ' installed ' ]) || isset ( $ conf [ ' powerdns ' ][ ' installed ' ]) && $ conf [ ' powerdns ' ][ ' installed ' ] == false ) )) {
390390 $ temp_domains [] = "*. " . $ domain ;
391391 }
392392
@@ -403,9 +403,9 @@ public function request_certificates($data, $server_type = 'apache') {
403403 if (is_array ($ aliasdomains )) {
404404 foreach ($ aliasdomains as $ aliasdomain ) {
405405 $ temp_domains [] = $ aliasdomain ['domain ' ];
406- if (isset ($ aliasdomain ['subdomain ' ]) && substr ($ aliasdomain ['domain ' ],0 ,4 ) != 'www. ' && ($ aliasdomain ['domain ' ]['subdomain ' ] == "www " || ($ aliasdomain ['domain ' ]['subdomain ' ] == "* " && (!$ use_acme || $ global_sites_config ['acme_dns_user ' ] == '' )))) {
406+ if (isset ($ aliasdomain ['subdomain ' ]) && substr ($ aliasdomain ['domain ' ],0 ,4 ) != 'www. ' && ($ aliasdomain ['domain ' ]['subdomain ' ] == "www " || ($ aliasdomain ['domain ' ]['subdomain ' ] == "* " && (!$ use_acme || $ global_sites_config ['acme_dns_user ' ] == '' && (! isset ( $ conf [ ' powerdns ' ][ ' installed ' ]) || isset ( $ conf [ ' powerdns ' ][ ' installed ' ]) && $ conf [ ' powerdns ' ][ ' installed ' ] == false ) )))) {
407407 $ temp_domains [] = "www. " . $ aliasdomain ['domain ' ];
408- } elseif ($ aliasdomain ['domain ' ]['subdomain ' ] == "* " && ($ use_acme && $ global_sites_config ['acme_dns_user ' ] != '' )) {
408+ } elseif ($ aliasdomain ['domain ' ]['subdomain ' ] == "* " && ($ use_acme && $ global_sites_config ['acme_dns_user ' ] != '' && (! isset ( $ conf [ ' powerdns ' ][ ' installed ' ]) || isset ( $ conf [ ' powerdns ' ][ ' installed ' ]) && $ conf [ ' powerdns ' ][ ' installed ' ] == false ) )) {
409409 $ temp_domains [] = "*. " . $ aliasdomain ['domain ' ];
410410 }
411411 }
@@ -427,7 +427,7 @@ public function request_certificates($data, $server_type = 'apache') {
427427 if ((isset ($ web_config ['skip_le_check ' ]) && $ web_config ['skip_le_check ' ] == 'y ' ) || (isset ($ server_config ['migration_mode ' ]) && $ server_config ['migration_mode ' ] == 'y ' )) {
428428 $ le_domains [] = $ temp_domain ;
429429 } else {
430- if ($ global_sites_config ['acme_dns_user ' ] == '' || !$ use_acme ) {
430+ if ($ global_sites_config ['acme_dns_user ' ] == '' || !$ use_acme || ( isset ( $ conf [ ' powerdns ' ][ ' installed ' ]) && $ conf [ ' powerdns ' ][ ' installed ' ] == true ) ) {
431431 $ le_hash_check = trim (@file_get_contents ('http:// ' . $ temp_domain . '/.well-known/acme-challenge/ ' . $ le_rnd_file ));
432432 if ($ le_hash_check == $ le_rnd_hash ) {
433433 $ le_domains [] = $ temp_domain ;
@@ -443,12 +443,16 @@ public function request_certificates($data, $server_type = 'apache') {
443443 array_shift ($ temp_domain_parts );
444444 }
445445 }
446- $ queryOr = "origin = ' " . $ temp_domain . ".' " ;
447446 foreach ($ queryDomains as $ queryDomain ) {
448- $ queryOr .= " OR origin = ' " . $ queryDomain . ".' " ;
447+ $ sql = "SELECT * FROM dns_soa WHERE active = 'y' AND origin = ' " . $ queryDomain . ".' " ;
448+ if (is_array ($ app ->dbmaster ->queryOneRecord ($ sql ))) {
449+ $ zoneExists = true ;
450+ $ zonedomain = $ queryDomain ;
451+ $ dns_server_id = $ sql ['server_id ' ];
452+ break ;
453+ }
449454 }
450- $ sql = "SELECT * FROM dns_soa WHERE active = 'y' AND " . $ queryOr ;
451- if (is_array ($ app ->dbmaster ->queryOneRecord ($ sql ))) {
455+ if ($ zoneExists ) {
452456 $ le_domains [] = $ temp_domain ;
453457 $ app ->log ("Verified domain " . $ temp_domain . " has a DNS zone in this setup for the acme (Let's Encrypt) challenge. " , LOGLEVEL_DEBUG );
454458 } else {
@@ -488,12 +492,38 @@ public function request_certificates($data, $server_type = 'apache') {
488492 }
489493
490494 $ success = false ;
495+
496+
491497 if ($ letsencrypt_cmd ) {
492498 if (!isset ($ server_config ['migration_mode ' ]) || $ server_config ['migration_mode ' ] != 'y ' ) {
493499 $ app ->log ("Create Let's Encrypt SSL Cert for: $ domain " , LOGLEVEL_DEBUG );
494500 $ app ->log ("Let's Encrypt SSL Cert domains: $ cli_domain_arg " , LOGLEVEL_DEBUG );
495501
496- $ success = $ app ->system ->_exec ($ letsencrypt_cmd , $ allow_return_codes );
502+ if ($ use_acme && $ global_sites_config ['acme_dns_user ' ] != '' && $ dns_server_id == $ conf ["server_id " ]) {
503+ $ dns_config = $ app ->getconf ->get_server_config ($ conf ["server_id " ], 'dns ' );
504+ $ zonefile = $ dns_config ['bind_zonefiles_dir ' ].'/ ' . "pri. " . $ zonedomain ;
505+ $ datalogfound = false ;
506+ while ($ success = $ app ->system ->_exec ($ letsencrypt_cmd , $ allow_return_codes )) {
507+ while (!$ datalogfound ) {
508+ $ sql = "SELECT data FROM sys_datalog WHERE dbtable = 'dns_rr' AND data LIKE '%_acme-challenge%' AND status = 'pending' " ;
509+ $ datalogs = $ app ->dbmaster ->queryAllRecords ($ sql );
510+ if (is_array ($ datalogs )) {
511+ foreach ($ datalogs as $ datalog ) {
512+ $ datalog = unserialize ($ datalog );
513+ $ hostname = $ datalog ['new ' ]['name ' ];
514+ $ data = $ datalog ['new ' ]['data ' ];
515+ $ record = "\n" . $ hostname . ". " . $ zonedomain . ". " . " 3600 TXT \"" . $ data . "\"" ;
516+ file_put_contents ($ zonefile , $ record , FILE_APPEND | LOCK_EX );
517+ }
518+ $ app ->services ->restartService ('named ' , 'restart ' );
519+ $ datalogfound = true ;
520+ break ;
521+ }
522+ }
523+ }
524+ } else {
525+ $ success = $ app ->system ->_exec ($ letsencrypt_cmd , $ allow_return_codes );
526+ }
497527 } else {
498528 $ app ->log ("Migration mode active, skipping Let's Encrypt SSL Cert creation for: $ domain " , LOGLEVEL_DEBUG );
499529 $ success = true ;
0 commit comments