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

105 lines
3.5 KiB
PHP
Raw Permalink 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 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");
}
}
}
2022-07-02 10:51:13 -07:00
$mbox = array();
2022-09-27 16:06:29 -07:00
$mbox['localpart'] = '';
$mbox['password'] = '';
$mbox['password_confirm'] = '';
2022-07-02 10:51:13 -07:00
$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);
2022-07-01 15:24:26 -07:00
}
}
static function get($f3) {
echo \Template::instance()->render('vmail/mboxes-add.html');
}
function post($f3) {
extract($_POST);
$f3->call('\Panel::validateEmailLocalpart', $localpart);
2023-06-19 11:53:16 -07:00
$f3->call('\Panel::validatePassword', array($password, $password_confirm));
2022-07-01 15:24:26 -07:00
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);
}
}
}
}