vpanel-stack/panel/classes/Panel/Vmail/DomainsAdd.php

135 lines
4.7 KiB
PHP
Raw Normal View History

2022-07-01 15:24:26 -07:00
<?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\Vmail;
class DomainsAdd extends \Panel\Vmail {
function beforeRoute($f3) {
parent::beforeRoute($f3);
/* get vm_domains defaults for "add new" form */
$vm_domains_defaults = $f3->call('\Panel::vGet', array("vmail-defaults-get.sh -c", FALSE));
$f3->set('vm_domains_defaults', $vm_domains_defaults[0]);
2024-04-15 10:41:09 -07:00
/* check if VHOSTLIMIT is set */
if (is_numeric($f3->get('VHOSTLIMIT'))) {
if ($f3->get('VHOSTLIMIT') > 0) {
$f3->set('vhostlimited', TRUE);
if ($domains_array = $f3->call('\Panel::vGet', array("vmail-domains-get.sh -c", FALSE))) {
$f3->set('vhostscount', count($domains_array));
}
}
}
2022-07-01 15:24:26 -07:00
}
static function get($f3) {
2024-04-15 10:41:09 -07:00
/* check VHOSTLIMIT */
if ($f3->get('vhostlimited') && ($f3->get('vhostscount') >= $f3->get('VHOSTLIMIT'))) {
echo \Template::instance()->render('vmail/domains-add-max.html');
} else {
echo \Template::instance()->render('vmail/domains-add.html');
}
2022-07-01 15:24:26 -07:00
}
function post($f3) {
extract($_POST);
$messages = array();
/* validate domain */
2023-06-19 11:53:16 -07:00
$domain = strtolower($_POST['domain']);
$domain = preg_replace('/^mail\./', '', $domain);
$domain = preg_replace('/^www\./', '', $domain);
if ($f3->call('\Panel::validateDomain', $domain)) {
if ($f3->call('\Panel::verifyVmailDomainExists', $domain)) {
$messages[] = "Email Domain '$domain' already exists.";
}
2022-07-01 15:24:26 -07:00
}
/* validate status */
if ($_POST['status'] != 0 && $_POST['status'] != 1) {
$messages[] = "Invalid 'Status'.";
} else {
$status = $_POST['status'];
}
/* validate mbox_limit */
if (strtolower($_POST['mbox_limit']) == 'unlimited' || strtolower($_POST['mbox_limit'] == 'null')) {
$mbox_limit = "NULL";
} elseif (is_numeric($_POST['mbox_limit'])) {
/* make sure mbox_limit is a possitive integer */
$mbox_limit = abs(intval($_POST['mbox_limit']));
if ($mbox_limit < 1) {
echo "Mailbox Limit must be a positive number or \"Unlimited\".\n";
$messages[] = "Mailbox Limit must be a positive number or \"Unlimited\".";
}
} else {
$messages[] = "Mailbox Limit must be a positive number or \"Unlimited\".";
}
/* validate mbox_quota_default */
if (strtolower($_POST['mbox_quota_default']) == 'unlimited' || strtolower($_POST['mbox_quota_default'] == 'null')) {
$mbox_quota_default = "NULL";
} elseif (is_numeric($_POST['mbox_quota_default'])) {
/* make sure mbox_quota_default is a possitive integer */
$mbox_quota_default = abs(intval($_POST['mbox_quota_default']));
if ($mbox_quota_default < 1) {
echo "Default Quota must be a positive number or \"Unlimited\".\n";
$messages[] = "Default Quota must be a positive number or \"Unlimited\".";
}
} else {
$messages[] = "Default Quota must be a positive number or \"Unlimited\".";
}
/* validate mbox_ratelimit_default */
if (strtolower($_POST['mbox_ratelimit_default']) == 'unlimited' || strtolower($_POST['mbox_ratelimit_default'] == 'null')) {
$mbox_ratelimit_default = "NULL";
} elseif (is_numeric($_POST['mbox_ratelimit_default'])) {
/* make sure mbox_ratelimit_default is a possitive integer */
$mbox_ratelimit_default = abs(intval($_POST['mbox_ratelimit_default']));
if ($mbox_ratelimit_default < 1) {
$messages[] = "Default Rate Limit must be a positive number or \"Unlimited\".";
}
} else {
$messages[] = "Default Rate Limit must be a positive number or \"Unlimited\".";
}
/* check for validation errors */
if (count($messages) > 0) {
$messages[] = "Please re-submit the form to try again.";
$f3->set('SESSION.messages', $messages);
$f3->call('\Panel\Vmail\DomainsAdd::get', $f3);
} else {
2023-06-19 11:53:16 -07:00
/* add email domain */
exec("/usr/local/bin/vmail-domains-add.sh -d $domain -l $mbox_limit -q $mbox_quota_default -r $mbox_ratelimit_default -s $status", $output, $result_code);
if ($result_code == 0) {
$messages[] = "Email Domain $domain has been added.";
$f3->set('SESSION.messages', $messages);
$f3->reroute("/Email/$domain");
} else {
if (count($output) > 0) {
foreach ($output as $k=>$output_message) {
$messages[] = "$output_message";
2022-07-01 15:24:26 -07:00
}
2023-06-19 11:53:16 -07:00
} else {
$messages[] = "Unknown error adding Email Domain $domain.";
2022-07-01 15:24:26 -07:00
}
$f3->set('SESSION.messages', $messages);
2023-06-19 11:53:16 -07:00
$f3->call('\Panel\Vmail\DomainsAdd::get', $f3);
2022-07-01 15:24:26 -07:00
}
}
}
}