Skip to content

Commit ed6365e

Browse files
author
Thom
committed
Fix BIND manipulation (#4202)
1 parent 40c3826 commit ed6365e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

server/lib/classes/letsencrypt.inc.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -505,23 +505,29 @@ public function request_certificates($data, $server_type = 'apache') {
505505
$datalogfound = false;
506506
while (!$datalogfound) {
507507
if ($firstrun == true) {
508-
$success = $app->system->_exec($letsencrypt_cmd, $allow_return_codes);
508+
$success = $app->system->_exec("(" . $letsencrypt_cmd . ") > /dev/null &", $allow_return_codes);
509509
$firstrun = false;
510510
}
511-
$sql = "SELECT data FROM sys_datalog WHERE dbtable = 'dns_rr' AND data LIKE '%_acme-challenge%' AND status = 'pending'";
511+
$sql = "SELECT data FROM sys_datalog,server WHERE sys_datalog.server_id = \"1\" AND sys_datalog.datalog_id > server.updated AND sys_datalog.dbtable = 'dns_rr' AND data LIKE '%_acme-challenge%'";
512512
$datalogs = $app->dbmaster->queryAllRecords($sql);
513513
if (is_array($datalogs)) {
514+
$app->log("Found datalog for acme-challenge, appending to zonefile.", LOGLEVEL_DEBUG);
514515
foreach ($datalogs as $datalog) {
515-
$datalog = unserialize($datalog);
516+
$datalog = unserialize($datalog['data']);
516517
$hostname = $datalog['new']['name'];
517518
$data = $datalog['new']['data'];
518519
$record = "\n" . $hostname . "." . $zonedomain . "." . " 3600 TXT \"" . $data . "\"";
519-
file_put_contents($zonefile, $record, FILE_APPEND | LOCK_EX);
520+
$app->system->file_put_contents($zonefile, $record);
520521
}
521522
$app->services->registerService('bind', 'dns_module', 'restartBind');
522523
$app->services->restartService('bind', 'restart');
524+
$app->log("Waiting for acme.sh script to finish.", LOGLEVEL_DEBUG);
525+
sleep(60);
523526
$datalogfound = true;
524527
break;
528+
} else {
529+
$app->log("Can not find the datalog for the acme-challenge yet, waiting 20 seconds.", LOGLEVEL_DEBUG);
530+
sleep(20);
525531
}
526532
}
527533
} else {

0 commit comments

Comments
 (0)