* GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) */ namespace Panel\Vmail; class MboxesEdit extends \Panel\Vmail { function beforeRoute($f3) { parent::beforeRoute($f3); $mbox = $f3->get('PARAMS.mbox'); $domain = $f3->get('PARAMS.domain'); if ($mbox_array = $f3->call('\Panel::vGet', array("vmail-mboxes-get.sh -e $mbox@$domain -c", FALSE))) { $f3->set('mbox_array', $mbox_array[0]); } } static public function get($f3) { $mbox_array = $f3->get('mbox_array'); /* convert data for frontend display */ foreach ($mbox_array as $k=>$v) { if ($mbox_array['quota'] == "NULL") { $mbox_array['quota'] = 'Unlimited'; } if ($mbox_array['ratelimit'] == "NULL") { $mbox_array['ratelimit'] = 'Unlimited'; } } /* reset f3 mbox_array with converted data */ $f3->set('mbox_array', $mbox_array); echo \Template::instance()->render('vmail/mboxes-edit.html'); } function post($f3) { /* run mod command here */ $mbox = $f3->get('PARAMS.mbox'); $domain = $f3->get('PARAMS.domain'); $mbox_array = $_POST; $f3->set('mbox_array', $mbox_array); foreach ($mbox_array as $k=>$v) { if (strtolower($v) == 'unlimited') { $mbox_array[$k] = 'NULL'; } } extract($mbox_array); if ($password != '') { $f3->call('\Panel::validatePassword', 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', $filter); /* 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\MboxesEdit::get', $f3); } else { if ($password != '') { $password = escapeshellarg($password); $pword_cmd = "-p $password"; } else { $pword_cmd = ''; } exec("/usr/local/bin/vmail-mboxes-mod.sh -e $mbox@$domain $pword_cmd -q $quota -r $ratelimit -s $status -j $filter", $output, $result_code); if ($result_code == 0) { $messages[] = "Success: Email account $mbox@$domain updated."; $f3->set('SESSION.messages', $messages); $mapping = $f3->get('NAV.mapping'); if ($mapping == 'vmail') { $f3->reroute("/Accounts/$mbox"); } else { $f3->reroute("/Email/$domain/Accounts/$mbox"); } } else { $messages[] = "Error."; $f3->set('SESSION.messages', $messages); $f3->call('\Panel\Vmail\MboxesEdit::get', $f3); } } } }