* GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) */ namespace Panel\Vmail; class AliasesAdd extends \Panel\Vmail { function beforeRoute($f3) { parent::beforeRoute($f3); /* verify email account exists */ $mbox = $f3->get('PARAMS.mbox'); $domain = $f3->get('PARAMS.domain'); $f3->call('\Panel::vGet', "vmail-mboxes-get.sh -e $mbox@$domain -c"); } static function get($f3) { echo \Template::instance()->render('vmail/aliases-add.html'); } function post($f3) { $alias = $_POST['alias']; $mbox = $f3->get('PARAMS.mbox'); $domain = $f3->get('PARAMS.domain'); /* validate alias local part */ $f3->call('\Panel::validateEmailLocalpart', $alias); /* 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->call('\Panel\Vmail\MboxesAdd::get', $f3); } else { exec("/usr/local/bin/vmail-aliases-add.sh -e $mbox@$domain -a $alias", $output, $result_code); if ($result_code == 0) { $messages[] = "Success: Email alias $alias@$domain added."; $f3->set('SESSION.messages', $messages); $f3->reroute("/Email/$domain/Accounts/$mbox/Aliases"); } else { /* failure, set error messages */ if (count($output) > 0) { foreach ($output as $k=>$output_message) { $messages[] = "$output_message"; } } else { $messages[] = "Unknown error."; } $f3->set('SESSION.messages', $messages); $f3->call('\Panel\Vmail\AliasesAdd::get', $f3); } } } }