vpanel-stack/panel/classes/Panel/Cert/CertsDelete.php
2023-06-19 11:53:16 -07:00

71 lines
1.8 KiB
PHP

<?php
/**
* vpanel-stack
* https://git.stack-source.com/msb/vpanel-stack
* Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
* GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
*/
namespace Panel\Cert;
class CertsDelete extends \Panel\Cert {
function beforeRoute($f3) {
parent::beforeRoute($f3);
}
static function get($f3) {
$messages = $f3->get('SESSION.messages');
if ($f3->exists('PARAMS.cert')) {
$domain = $f3->get('PARAMS.cert');
if ($f3->call('\Panel::validateDomain', $domain)) {
if ($f3->call('\Panel::verifyCertificateExists', $domain)) {
/* delete the cert */
$f3->call('\Panel::vGet', array("letsencrypt-delete.sh -d $domain -r", FALSE));
/* check for and delete dovecot config */
if (preg_match('/^mail\./i', $domain)) {
$mxdomain = preg_replace('/^mail\./i', '', $f3->get('HOST'));
$f3->call('\Panel::vGet', array("vmail-dovecot-disable.sh -d $mxdomain", FALSE));
}
/* delete apache config (vhost or webmail) */
if (is_link("/etc/apache2/sites-enabled/$domain.conf")) {
$f3->call('\Panel::vGet', array("vhost-disable.sh -d $domain", FALSE));
}
$messages[] = "The Security Certificate and related configs for $domain have been deleted.";
} else {
$messages[] = "Security Certificate for $domain not found.";
}
} else {
$messages[] = "Invalid domain name ($domain).";
}
}
/* reroute user to page the originated from */
parse_str($f3->get('QUERY'), $output);
if (isset($output['r'])) {
$f3->reroute($output['r']);
} else {
/* default reroute as fallback */
$f3->reroute('/');
}
}
}