@@ -69,7 +69,8 @@ class AcmeSh extends FroxlorCron
69
69
* run the task
70
70
*
71
71
* @param bool $internal
72
- * @return number
72
+ * @return int
73
+ * @throws \Exception
73
74
*/
74
75
public static function run (bool $ internal = false )
75
76
{
@@ -85,6 +86,9 @@ public static function run(bool $internal = false)
85
86
if ($ issue_froxlor || !empty ($ issue_domains ) || !empty ($ renew_froxlor ) || $ renew_domains ) {
86
87
// insert task to generate certificates and vhost-configs
87
88
Cronjob::inserttask (TaskId::REBUILD_VHOST );
89
+ if ($ renew_froxlor ) {
90
+ Cronjob::inserttask (TaskId::UPDATE_LE_SERVICES );
91
+ }
88
92
}
89
93
return 0 ;
90
94
}
@@ -217,6 +221,7 @@ public static function run(bool $internal = false)
217
221
* check whether we need to issue a new certificate for froxlor itself
218
222
*
219
223
* @return boolean
224
+ * @throws \Exception
220
225
*/
221
226
private static function issueFroxlorVhost ()
222
227
{
@@ -340,6 +345,7 @@ private static function issueDomains()
340
345
* check whether we need to renew-check the certificate for froxlor itself
341
346
*
342
347
* @return boolean
348
+ * @throws \Exception
343
349
*/
344
350
private static function renewFroxlorVhost ()
345
351
{
@@ -539,6 +545,7 @@ private static function runIssueFor($certrows = [])
539
545
* @param array $domains
540
546
* @param int $domain_id
541
547
* @param FroxlorLogger $cronlog
548
+ * @throws \Exception
542
549
*/
543
550
private static function validateDns (array &$ domains , $ domain_id , &$ cronlog )
544
551
{
@@ -619,61 +626,83 @@ private static function runAcmeSh(array $certrow, array $domains, &$cronlog = nu
619
626
$ cronlog ->logAction (FroxlorLogger::CRON_ACTION , LOG_DEBUG , "Successful exit-code returned - storing certificate " );
620
627
$ cert_stored = self ::certToDb ($ certrow , $ cronlog , $ acme_result );
621
628
622
- if ($ cert_stored
623
- && $ renew_hook
624
- && !empty (trim (Settings::Get ('system.le_renew_services ' ) ?? "" ))
625
- && !empty (trim (Settings::Get ('system.le_renew_hook ' ) ?? "" ))
626
- ) {
627
- $ cronlog ->logAction (FroxlorLogger::CRON_ACTION , LOG_DEBUG , "Renew-hook is enabled - adjusting configurations " );
628
-
629
- $ certificate_folder = self ::getCertificateFolder (strtolower (Settings::Get ('system.hostname ' )));
630
- $ fullchain = FileDir::makeCorrectFile ($ certificate_folder . '/fullchain.cer ' );
631
- $ keyfile = FileDir::makeCorrectFile ($ certificate_folder . '/ ' . strtolower (Settings::Get ('system.hostname ' )) . '.key ' );
632
- $ ca_file = FileDir::makeCorrectFile ($ certificate_folder . '/ca.cer ' );
633
-
634
- if (Settings::IsInList ('system.le_renew_services ' , 'postfix ' )) {
635
- // "postconf -e" for postfix
636
- FileDir::safe_exec ('postconf -e smtpd_tls_cert_file= ' . escapeshellarg ($ fullchain ));
637
- FileDir::safe_exec ('postconf -e smtpd_tls_key_file= ' . escapeshellarg ($ keyfile ));
638
- }
639
- if (Settings::IsInList ('system.le_renew_services ' , 'dovecot ' )) {
640
- // custom config for dovecot
641
- $ dovecot_conf = '/etc/dovecot/conf.d/99-froxlor.ssl.conf ' ; // @fixme setting?
642
- $ ssl_content = <<<EOSSL
629
+ if ($ cert_stored && $ renew_hook ) {
630
+ self ::renewHookConfigs ($ cronlog );
631
+ }
632
+ }
633
+ }
634
+ }
635
+
636
+ public static function renewHookConfigs ($ cronlog )
637
+ {
638
+ if (!empty (trim (Settings::Get ('system.le_renew_services ' ) ?? "" ))
639
+ && !empty (trim (Settings::Get ('system.le_renew_hook ' ) ?? "" ))
640
+ ) {
641
+
642
+ $ cronlog ->logAction (FroxlorLogger::CRON_ACTION , LOG_DEBUG , "Renew-hook is enabled - adjusting configurations " );
643
+
644
+ $ certificate_folder = self ::getCertificateFolder (strtolower (Settings::Get ('system.hostname ' )));
645
+
646
+ if (empty ($ certificate_folder )) {
647
+ $ cronlog ->logAction (FroxlorLogger::CRON_ACTION , LOG_INFO , "No certificate folder for ' " . Settings::Get ('system.hostname ' ) . "' found " );
648
+ return ;
649
+ }
650
+
651
+ $ fullchain = FileDir::makeCorrectFile ($ certificate_folder . '/fullchain.cer ' );
652
+ $ keyfile = FileDir::makeCorrectFile ($ certificate_folder . '/ ' . strtolower (Settings::Get ('system.hostname ' )) . '.key ' );
653
+ $ ca_file = FileDir::makeCorrectFile ($ certificate_folder . '/ca.cer ' );
654
+
655
+ if (!file_exists ($ fullchain ) || !file_exists ($ keyfile ) || !file_exists ($ ca_file )) {
656
+ $ cronlog ->logAction (FroxlorLogger::CRON_ACTION , LOG_INFO , "At least one of the required certificate files for ' " . Settings::Get ('system.hostname ' ) . "' could not be found " );
657
+ return ;
658
+ }
659
+
660
+ $ dovecot_conf = '/etc/dovecot/conf.d/99-froxlor.ssl.conf ' ; // @fixme setting?
661
+
662
+ if (Settings::IsInList ('system.le_renew_services ' , 'postfix ' )) {
663
+ // "postconf -e" for postfix
664
+ FileDir::safe_exec ('postconf -e smtpd_tls_cert_file= ' . escapeshellarg ($ fullchain ));
665
+ FileDir::safe_exec ('postconf -e smtpd_tls_key_file= ' . escapeshellarg ($ keyfile ));
666
+ }
667
+ if (Settings::IsInList ('system.le_renew_services ' , 'dovecot ' )) {
668
+ // custom config for dovecot
669
+ $ ssl_content = <<<EOSSL
643
670
# Autogenerated configuration by froxlor.
644
671
# Do not manually edit this file as it will be overwritten.
645
672
646
673
ssl = yes
647
674
ssl_cert = < {$ fullchain }
648
675
ssl_key = < {$ keyfile }
649
676
EOSSL ;
650
- file_put_contents ($ dovecot_conf , $ ssl_content );
651
- }
652
- if (Settings::IsInList ('system.le_renew_services ' , 'proftpd ' )) {
653
- $ proftpd_conf = '/etc/proftpd/tls.conf ' ; // @fixme setting?
654
- $ rval = false ;
655
- // ECC certificate or not?
656
- if (strpos ($ certificate_folder , '_ecc ' ) === false ) {
657
- // comment out ECC related settings
658
- FileDir::safe_exec ("sed -i.bak 's|^TLSECCertificateFile|# TLSECCertificateFile|' " . escapeshellarg ($ proftpd_conf ), $ rval , ['| ' , '? ' ]);
659
- FileDir::safe_exec ("sed -i.bak 's|^TLSECCertificateKeyFile|# TLSECCertificateKeyFile|' " . escapeshellarg ($ proftpd_conf ), $ rval , ['| ' , '? ' ]);
660
- // add RSA directives
661
- FileDir::safe_exec ("sed -i.bak 's|^#\?\s\?TLSRSACertificateFile.*|TLSRSACertificateFile " . $ fullchain . "|' " . escapeshellarg ($ proftpd_conf ), $ rval , ['| ' , '? ' ]);
662
- FileDir::safe_exec ("sed -i.bak 's|^#\?\s\?TLSRSACertificateKeyFile.*|TLSRSACertificateKeyFile " . $ keyfile . "|' " . escapeshellarg ($ proftpd_conf ), $ rval , ['| ' , '? ' ]);
663
- } else {
664
- // comment out RSA related settings
665
- FileDir::safe_exec ("sed -i.bak 's|^TLSRSACertificateFile|# TLSRSACertificateFile|' " . escapeshellarg ($ proftpd_conf ), $ rval , ['| ' , '? ' ]);
666
- FileDir::safe_exec ("sed -i.bak 's|^TLSRSACertificateKeyFile|# TLSRSACertificateKeyFile|' " . escapeshellarg ($ proftpd_conf ), $ rval , ['| ' , '? ' ]);
667
- // add ECC directives
668
- FileDir::safe_exec ("sed -i.bak 's|^#\?\s\?TLSECCertificateFile.*|TLSECCertificateFile " . $ fullchain . "|' " . escapeshellarg ($ proftpd_conf ), $ rval , ['| ' , '? ' ]);
669
- FileDir::safe_exec ("sed -i.bak 's|^#\?\s\?TLSECCertificateKeyFile.*|TLSECCertificateKeyFile " . $ keyfile . "|' " . escapeshellarg ($ proftpd_conf ), $ rval , ['| ' , '? ' ]);
670
- }
671
- FileDir::safe_exec ("sed -i.bak 's|^#\?\s\?TLSCACertificateFile.*|TLSCACertificateFile " . $ ca_file . "|' " . escapeshellarg ($ proftpd_conf ), $ rval , ['| ' , '? ' ]);
672
- }
673
- // reload the services
674
- FileDir::safe_exec (Settings::Get ('system.le_renew_hook ' ));
677
+ file_put_contents ($ dovecot_conf , $ ssl_content );
678
+ } elseif (file_exists ($ dovecot_conf )) {
679
+ // safely remove the autogenerated config file
680
+ unlink ($ dovecot_conf );
681
+ }
682
+ if (Settings::IsInList ('system.le_renew_services ' , 'proftpd ' )) {
683
+ $ proftpd_conf = '/etc/proftpd/tls.conf ' ; // @fixme setting?
684
+ $ rval = false ;
685
+ // ECC certificate or not?
686
+ if (strpos ($ certificate_folder , '_ecc ' ) === false ) {
687
+ // comment out ECC related settings
688
+ FileDir::safe_exec ("sed -i.bak 's|^TLSECCertificateFile|# TLSECCertificateFile|' " . escapeshellarg ($ proftpd_conf ), $ rval , ['| ' , '? ' ]);
689
+ FileDir::safe_exec ("sed -i.bak 's|^TLSECCertificateKeyFile|# TLSECCertificateKeyFile|' " . escapeshellarg ($ proftpd_conf ), $ rval , ['| ' , '? ' ]);
690
+ // add RSA directives
691
+ FileDir::safe_exec ("sed -i.bak 's|^#\?\s\?TLSRSACertificateFile.*|TLSRSACertificateFile " . $ fullchain . "|' " . escapeshellarg ($ proftpd_conf ), $ rval , ['| ' , '? ' ]);
692
+ FileDir::safe_exec ("sed -i.bak 's|^#\?\s\?TLSRSACertificateKeyFile.*|TLSRSACertificateKeyFile " . $ keyfile . "|' " . escapeshellarg ($ proftpd_conf ), $ rval , ['| ' , '? ' ]);
693
+ } else {
694
+ // comment out RSA related settings
695
+ FileDir::safe_exec ("sed -i.bak 's|^TLSRSACertificateFile|# TLSRSACertificateFile|' " . escapeshellarg ($ proftpd_conf ), $ rval , ['| ' , '? ' ]);
696
+ FileDir::safe_exec ("sed -i.bak 's|^TLSRSACertificateKeyFile|# TLSRSACertificateKeyFile|' " . escapeshellarg ($ proftpd_conf ), $ rval , ['| ' , '? ' ]);
697
+ // add ECC directives
698
+ FileDir::safe_exec ("sed -i.bak 's|^#\?\s\?TLSECCertificateFile.*|TLSECCertificateFile " . $ fullchain . "|' " . escapeshellarg ($ proftpd_conf ), $ rval , ['| ' , '? ' ]);
699
+ FileDir::safe_exec ("sed -i.bak 's|^#\?\s\?TLSECCertificateKeyFile.*|TLSECCertificateKeyFile " . $ keyfile . "|' " . escapeshellarg ($ proftpd_conf ), $ rval , ['| ' , '? ' ]);
675
700
}
701
+ FileDir::safe_exec ("sed -i.bak 's|^#\?\s\?TLSCACertificateFile.*|TLSCACertificateFile " . $ ca_file . "|' " . escapeshellarg ($ proftpd_conf ), $ rval , ['| ' , '? ' ]);
676
702
}
703
+
704
+ // reload the services
705
+ FileDir::safe_exec (Settings::Get ('system.le_renew_hook ' ));
677
706
}
678
707
}
679
708
0 commit comments