177 lines
6.0 KiB
PHP
177 lines
6.0 KiB
PHP
<?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\Vhost;
|
|
|
|
class UsersEdit extends \Panel\Vhost {
|
|
|
|
function beforeRoute($f3) {
|
|
|
|
parent::beforeRoute($f3);
|
|
$username = $f3->get('PARAMS.username');
|
|
|
|
/* exta auth checks if logged in via vhost mapping */
|
|
if ($f3->get('NAV.mapping') == 'vhost') {
|
|
if ($f3->exists('SESSION.vhostusername')) {
|
|
/* vhostusername indicates vhost user login */
|
|
$vhostusername = $f3->get('SESSION.vhostusername');
|
|
if ($username != $vhostusername) {
|
|
/* trying to edit wrong username, redirect back home */
|
|
$messages[] = "Unauthorized request.";
|
|
$f3->set('SESSION.messages', $messages);
|
|
$f3->reroute("/");
|
|
}
|
|
} else {
|
|
/* SESSION.vhostusername not set. Something went wrong, redirect back home */
|
|
$messages[] = "Error verifying system user for domain $domain, can not edit.";
|
|
$f3->set('SESSION.messages', $messages);
|
|
$f3->reroute("/");
|
|
}
|
|
}
|
|
|
|
if ($user_array = $f3->call('\Panel::vGet', array("vhost-user-get.sh -u $username -c -v", FALSE))) {
|
|
if ($user_array[0]['passwd'] == "") {
|
|
$user_array[0]['passwd'] = '(unavailable)';
|
|
}
|
|
$f3->set('user_array', $user_array[0]);
|
|
}
|
|
|
|
}
|
|
|
|
static public function get($f3) {
|
|
|
|
if ($f3->exists('PARAMS.username')) {
|
|
|
|
$username = $f3->get('PARAMS.username');
|
|
$f3->set('page_header', "Edit User: $username");
|
|
echo \Template::instance()->render('vhost/users-edit.html');
|
|
|
|
} else {
|
|
|
|
$f3->set('page_header', "Users");
|
|
echo \Template::instance()->render('vhost/users.html');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function post($f3) {
|
|
|
|
$username = $f3->get('PARAMS.username');
|
|
$action = $_POST['action'];
|
|
|
|
if ($action == 'password') {
|
|
$password = $_POST['password'];
|
|
$password_confirm = $_POST['password_confirm'];
|
|
$f3->call('\Panel::validatePassword', array($password, $password_confirm));
|
|
/* check for validation errors */
|
|
if ($f3->exists('SESSION.messages')) {
|
|
$messages = $f3->get('SESSION.messages');
|
|
} else {
|
|
$password = escapeshellarg($password);
|
|
if ($f3->get('WRITEUSERINFO') == '1') {
|
|
exec("/usr/local/bin/vhost-user-mod.sh -u $username -p $password -w 1", $output, $result_code);
|
|
} else {
|
|
exec("/usr/local/bin/vhost-user-mod.sh -u $username -p $password", $output, $result_code);
|
|
}
|
|
if ($result_code == 0) {
|
|
$messages[] = "Success: Password for $username updated.";
|
|
} else {
|
|
$messages[] = "Error updating password.";
|
|
}
|
|
}
|
|
} elseif ($action == 'jail') {
|
|
exec("/usr/local/bin/vhost-user-jail.sh -u $username >/dev/null 2>/dev/null &", $output, $result_code);
|
|
$messages[] = "User is being jailed. Note: Setting up the jail environment takes about a minute to complete and is run in the background now.";
|
|
} elseif ($action == 'fpmmax') {
|
|
$fpmmax = $_POST['fpmmax'];
|
|
exec("/usr/local/bin/vhost-user-mod.sh -u $username -x $fpmmax", $output, $result_code);
|
|
if ($result_code == 0) {
|
|
$messages[] = "Success: PHP Workers updated.";
|
|
} else {
|
|
$messages[] = "Error updating PHP Workers.";
|
|
}
|
|
} else {
|
|
$messages[] = "Unkown edit action.";
|
|
}
|
|
|
|
$f3->set('SESSION.messages', $messages);
|
|
if ($f3->get('NAV.mapping') == 'vhost') {
|
|
if (isset($result_code) && $result_code == 0) {
|
|
$f3->reroute("/");
|
|
} else {
|
|
$f3->reroute("/Users/$username/Edit");
|
|
}
|
|
} else {
|
|
$f3->reroute("/Users/$username");
|
|
}
|
|
|
|
// /* 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);
|
|
// }
|
|
// }
|
|
|
|
}
|
|
|
|
}
|