diff --git a/Certman.class.php b/Certman.class.php index 87ffb1c..bb23240 100644 --- a/Certman.class.php +++ b/Certman.class.php @@ -86,6 +86,13 @@ public function install() { //return false; } } + + //delete Cron deprecated since 15.0.12 -> https://sangomakb.atlassian.net/wiki/spaces/FP/pages/10518892/Cron + $this->removeCronJob(); + + //register Job with random timing + $this->FreePBX->Job()->addClass('certman', 'update', 'FreePBX\modules\Certman\Job', rand(0, 59) . ' ' . rand(0, 3) . ' * * *'); + return true; } @@ -94,6 +101,7 @@ public function uninstall() { $this->removeCSR(); $this->removeCA(); $this->removeCronJob(); + //Jobs are automatically removed by freepbx $certs = $this->getAllManagedCertificates(); foreach($certs as $cert) { $this->removeCertificate($cert['cid']); diff --git a/Job.php b/Job.php new file mode 100644 index 0000000..3ed0a39 --- /dev/null +++ b/Job.php @@ -0,0 +1,48 @@ +writeln("Starting Certman update check..."); + + $certman = \FreePBX::Certman(); + + //copied straight from the Console class (updateall) + $messages = $certman->checkUpdateCertificates(); + $hints = array(); + foreach ($messages as $message) { + if (!empty($message['hints'])) { + $hints = array_merge($hints, $message['hints']); + } + if ($message['type'] == "danger") { + $danger = true; + } + } + if ($danger) { + $certman->showhints($certman, $output, array_unique($hints)); + } + foreach ($messages as $message) { + $m = $message['message']; + switch ($message['type']) { + case "danger": + $output->writeln("" . $m . ""); + break; + case "warning": + $output->writeln("" . $m . ""); + break; + case "success": + $output->writeln("" . $m . ""); + break; + } + } + + $output->writeln("Finished"); + return true; + } +} diff --git a/install.php b/install.php index 11a78a7..5a118d8 100644 --- a/install.php +++ b/install.php @@ -1,22 +1,5 @@ get("AMPSBIN"); -foreach(FreePBX::Cron()->getAll() as $cron) { - $str = "fwconsole certificates updateall -q"; - if(preg_match("/".$str."/i",$cron,$matches)) { - FreePBX::Cron()->remove($cron); - } - $str = "fwconsole certificates --updateall -q"; - if(preg_match("/".$str."/i",$cron,$matches)) { - FreePBX::Cron()->remove($cron); - } -} -FreePBX::Cron()->add(array( - "command" => $ampsbin."/fwconsole certificates --updateall -q 2>&1 >/dev/null", - "hour" => rand(0,3), - "minute" => rand(0,59), -)); - $freepbx_conf = freepbx_conf::create(); $set['value'] = '730'; $set['defaultval'] =& $set['value'];