vpanel-stack/panel/classes/Panel/Vmail/MboxesAdd.php
Matthew Saunders Brown fd94a4e3c4 initial commit
2022-07-01 15:24:26 -07:00

103 lines
3.5 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\Vmail;
class MboxesAdd extends \Panel\Vmail {
function beforeRoute($f3) {
parent::beforeRoute($f3);
/* get system defaults for new email accounts, also serves to verify domain exists */
$domain = $f3->get('PARAMS.domain');
if ($mbox_defaults = $f3->call('\Panel::vGet', "vmail-domains-get.sh -d $domain -c")) {
/* check mailbox allocation limit */
$mbox_limit = $mbox_defaults[0]['mbox_limit'];
$mbox_allocated = $mbox_defaults[0]['mbox_allocated'];
if ($mbox_limit != 'NULL') {
if ($mbox_allocated >= $mbox_limit) {
$messages[] = "This domain has used all $mbox_limit of it's available email accounts.";
$f3->set('SESSION.messages', $messages);
if ($mapping == 'vmail') {
$f3->reroute("/Accounts");
} else {
$f3->reroute("/Email/$domain/Accounts");
}
}
} else {
$mbox = array();
$mbox['status'] = 1;
$mbox['quota'] = $mbox_defaults[0]['mbox_quota_default'];
if ($mbox['quota'] == 'NULL') { $mbox['quota'] = 'Unlimited'; }
$mbox['ratelimit'] = $mbox_defaults[0]['mbox_ratelimit_default'];
if ($mbox['ratelimit'] == 'NULL') { $mbox['ratelimit'] = 'Unlimited'; }
$mbox['filtering'] = 2;
$f3->set('mbox', $mbox);
}
}
}
static function get($f3) {
echo \Template::instance()->render('vmail/mboxes-add.html');
}
function post($f3) {
extract($_POST);
$f3->call('\Panel::validateEmailLocalpart', $localpart);
$f3->call('\Panel::validateEmailPassword', array($password, $password_confirm));
settype($status, "integer");
$f3->call('\Panel::validateEmailStatus', $status);
if (strtolower($quota == 'unlimited') || strtolower($quota == 'null')) {
$quota = "NULL";
} else {
settype($quota, "integer");
}
$f3->call('\Panel::validateEmailQuota', $quota);
if (strtolower($ratelimit == 'unlimited') || strtolower($ratelimit == 'null')) {
$ratelimit = "NULL";
}
$f3->call('\Panel::validateEmailRatelimit', $ratelimit);
$f3->call('\Panel::validateEmailFiltering', $filtering);
/* check for validation errors */
if ($f3->exists('SESSION.messages')) {
$messages = $f3->get('SESSION.messages');
$messages[] = "Please make changes and re-submit the form to try again.";
$f3->set('SESSION.messages', $messages);
$f3->set('mbox', $_POST);
$f3->call('\Panel\Vmail\MboxesAdd::get', $f3);
} else {
$domain = $f3->get('PARAMS.domain');
$password = escapeshellarg($password);
exec("/usr/local/bin/vmail-mboxes-add.sh -e $localpart@$domain -p $password -q $quota -r $ratelimit -s $status -j $filtering", $output, $result_code);
if ($result_code == 0) {
$messages[] = "Success: Email account $localpart@$domain added.";
$f3->set('SESSION.messages', $messages);
$mapping = $f3->get('NAV.mapping');
if ($mapping == 'vmail') {
$f3->reroute("/Accounts");
} else {
$f3->reroute("/Email/$domain/Accounts");
}
} else {
$messages[] = "Error.";
$f3->set('SESSION.messages', $messages);
$f3->call('\Panel\Vmail\MboxesAdd::get', $f3);
}
}
}
}