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

82 lines
2.6 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 AutorespondersEdit extends \Panel\Vmail {
function beforeRoute($f3) {
parent::beforeRoute($f3);
$mbox = $f3->get('PARAMS.mbox');
$domain = $f3->get('PARAMS.domain');
if ($autoresponder_array = $f3->call('\Panel::vGet', array("vmail-autoresponders-get.sh -e $mbox@$domain -c", FALSE))) {
$subject = $autoresponder_array[0]['subject'];
$subject = str_replace("\\'", "'", $subject);
$subject = stripslashes($subject);
$subject = substr_replace($subject, "", 0, 1);
$subject = substr_replace($subject, "", -1);
$autoresponder_array[0]['subject'] = $subject;
$autoresponder_array[0]['body'] = base64_decode(str_replace('\n', '', $autoresponder_array[0]['body']));
2022-07-01 15:24:26 -07:00
2022-09-27 15:53:10 -07:00
$autoresponders_array[0] = $autoresponder_array;
2022-07-01 15:24:26 -07:00
$f3->set('autoresponder_array', $autoresponder_array[0]);
}
}
static public function get($f3) {
echo \Template::instance()->render('vmail/autoresponders-edit.html');
}
function post($f3) {
/* run mod command here */
$mbox = $f3->get('PARAMS.mbox');
$domain = $f3->get('PARAMS.domain');
$autoresponder_array = $_POST;
$f3->set('autoresponder_array', $autoresponder_array);
extract($autoresponder_array);
$subject = addslashes($subject);
$body = base64_encode($body);
2022-07-01 15:24:26 -07:00
/* 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\AutorespondersEdit::get', $f3);
} else {
exec("/usr/local/bin/vmail-autoresponders-mod.sh -e $mbox@$domain -u \"$subject\" -b \"$body\" -o \"$mode\" -s \"$status\"", $output, $result_code);
if ($result_code == 0) {
$messages[] = "Success: Autoresponder for $mbox@$domain updated."; $f3->set('SESSION.messages', $messages);
$mapping = $f3->get('NAV.mapping');
if ($mapping == 'vmail') {
$f3->reroute("/Accounts/$mbox/Autoresponder");
} else {
$f3->reroute("/Email/$domain/Accounts/$mbox/Autoresponder");
}
} else {
$messages[] = "Error.";
$f3->set('SESSION.messages', $messages);
$f3->call('\Panel\Vmail\AutorespondersEdit::get', $f3);
}
}
}
}