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

93 lines
2.4 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 Forwards extends \Panel\Vmail {
function beforeRoute($f3) {
parent::beforeRoute($f3);
$domain = $f3->get('PARAMS.domain');
/* first confirm domain exists */
if ($f3->call('\Panel::vGet', "vmail-domains-get.sh -d $domain -c")) {
/* check if we are looking for specific forward (email account) */
if ($f3->exists('PARAMS.mbox')) {
$mbox = $f3->get('PARAMS.mbox');
/* get forward */
if ($forwards_array = $f3->call('\Panel::vGet', array("vmail-forwards-get.sh -e $mbox@$domain -c", FALSE))) {
$f3->set('forwards_array', $forwards_array);
}
} else {
/* get forwards */
if ($forwards_array = $f3->call('\Panel::vGet', array("vmail-forwards-get.sh -d $domain -c", FALSE))) {
$f3->set('forwards_array', $forwards_array);
}
}
}
}
public static function get($f3) {
$domain = $f3->get('PARAMS.domain');
$forwards_array = $f3->get('forwards_array');
/* convert data for frontend display */
if (is_array($forwards_array) && count($forwards_array) > 0) {
foreach($forwards_array as $k=>$forward_array) {
if ($forward_array['save_local'] == 1) {
$forward_array['save_local'] = 'Keep';
} else {
$forward_array['save_local'] = 'Discard';
}
$forwards_array[$k] = $forward_array;
}
$f3->set('forwards_array', $forwards_array);
} elseif ($f3->exists('PARAMS.mbox')) {
/* request for specific email account, forwarding does not exist, go directly to Add forwarding form */
$f3->clear('forwards_array');
$mbox = $f3->get('PARAMS.mbox');
$mapping = $f3->get('NAV.mapping');
if ($mapping == 'vmail') {
$f3->reroute("/Accounts/$mbox/Forwarding/Add");
} else {
$f3->reroute("/Email/$domain/Accounts/$mbox/Forwarding/Add");
}
}
if ($f3->exists('PARAMS.mbox')) {
$mbox = $f3->get('PARAMS.mbox');
$f3->set('page_header', "Forwarding for $mbox@$domain");
} else {
$f3->set('page_header', "Email Forwarding for $domain");
}
echo \Template::instance()->render('vmail/forwards.html');
}
}