* 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]); /* 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)); } } } } static function get($f3) { /* 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'); } } function post($f3) { extract($_POST); $messages = array(); /* validate domain */ $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."; } } /* 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 { /* 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"; } } else { $messages[] = "Unknown error adding Email Domain $domain."; } $f3->set('SESSION.messages', $messages); $f3->call('\Panel\Vmail\DomainsAdd::get', $f3); } } } }