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

67 lines
1.9 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 ForwardsAdd extends \Panel\Vmail {
function beforeRoute($f3) {
parent::beforeRoute($f3);
// verify email address exists
// verify forward does *not* exist
}
static function get($f3) {
2022-09-27 15:53:10 -07:00
/* initialize forward_array */
$forward_array = array('forward' => '', 'save_local' => '0');
$f3->set('forward_array', $forward_array);
2022-07-01 15:24:26 -07:00
echo \Template::instance()->render('vmail/forwards-add.html');
}
function post($f3) {
extract($_POST);
$f3->call('\Panel::validateEmail', array($forward));
/* 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('forward_array', $_POST);
$f3->call('\Panel\Vmail\ForwardsAdd::get', $f3);
} else {
$mbox = $f3->get('PARAMS.mbox');
$domain = $f3->get('PARAMS.domain');
exec("/usr/local/bin/vmail-forwards-add.sh -e $mbox@$domain -f $forward -k $save_local", $output, $result_code);
if ($result_code == 0) {
$messages[] = "Success: Forwarding for email account $mbox@$domain added.";
$f3->set('SESSION.messages', $messages);
2024-08-29 13:53:01 -07:00
$mapping = $f3->get('NAV.mapping');
if ($mapping == 'vmail') {
2022-07-01 15:24:26 -07:00
$f3->reroute("/Accounts/$mbox/Forwarding");
} else {
$f3->reroute("/Email/$domain/Accounts/$mbox/Forwarding");
}
} else {
$messages[] = "Error.";
$f3->set('SESSION.messages', $messages);
$f3->call('\Panel\Vmail\ForwardsAdd::get', $f3);
}
}
}
}