Improved code formating

This commit is contained in:
Serghey Rodin 2014-07-30 15:34:34 +03:00
commit 2558fa550d
15 changed files with 1723 additions and 1655 deletions

View file

@ -4,32 +4,19 @@ error_reporting(NULL);
ob_start();
session_start();
$TAB = 'CRON';
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
// Header
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
// Panel
top_panel($user,$TAB);
// Check POST request
if (!empty($_POST['ok'])) {
// Check input
// Check empty fields
if ((!isset($_POST['v_min'])) || ($_POST['v_min'] == '')) $errors[] = __('minute');
if ((!isset($_POST['v_hour'])) || ($_POST['v_hour'] == '')) $errors[] = __('hour');
if ((!isset($_POST['v_day'])) || ($_POST['v_day'] == '')) $errors[] = __('day');
if ((!isset($_POST['v_month'])) || ($_POST['v_month'] == '')) $errors[] = __('month');
if ((!isset($_POST['v_wday'])) || ($_POST['v_wday'] == '')) $errors[] = __('day of week');
if ((!isset($_POST['v_cmd'])) || ($_POST['v_cmd'] == '')) $errors[] = __('cmd');
// Protect input
$v_min = escapeshellarg($_POST['v_min']);
$v_hour = escapeshellarg($_POST['v_hour']);
$v_day = escapeshellarg($_POST['v_day']);
$v_month = escapeshellarg($_POST['v_month']);
$v_wday = escapeshellarg($_POST['v_wday']);
$v_cmd = escapeshellarg($_POST['v_cmd']);
// Check for errors
if (!empty($errors[0])) {
foreach ($errors as $i => $error) {
if ( $i == 0 ) {
@ -39,32 +26,46 @@ if (!empty($_POST['ok'])) {
}
}
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
} else {
// Add Cron Job
}
// Protect input
$v_min = escapeshellarg($_POST['v_min']);
$v_hour = escapeshellarg($_POST['v_hour']);
$v_day = escapeshellarg($_POST['v_day']);
$v_month = escapeshellarg($_POST['v_month']);
$v_wday = escapeshellarg($_POST['v_wday']);
$v_cmd = escapeshellarg($_POST['v_cmd']);
// Add cron job
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-add-cron-job ".$user." ".$v_min." ".$v_hour." ".$v_day." ".$v_month." ".$v_wday." ".$v_cmd, $output, $return_var);
$v_type = $_POST['v_type'];
$v_charset = $_POST['v_charset'];
check_return_code($return_var,$output);
unset($v_password);
unset($output);
if (empty($_SESSION['error_msg'])) {
$_SESSION['ok_msg'] = __('CRON_CREATED_OK');
unset($v_min);
unset($v_hour);
unset($v_day);
unset($v_month);
unset($v_wday);
unset($v_cmd);
unset($output);
}
}
// Flush field values on success
if (empty($_SESSION['error_msg'])) {
$_SESSION['ok_msg'] = __('CRON_CREATED_OK');
unset($v_min);
unset($v_hour);
unset($v_day);
unset($v_month);
unset($v_wday);
unset($v_cmd);
unset($output);
}
}
exec (VESTA_CMD."v-list-database-types 'json'", $output, $return_var);
$db_types = json_decode(implode('', $output), true);
unset($output);
// Header
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
// Panel
top_panel($user,$TAB);
// Display body
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_cron.html');
// Flush session messages
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);

View file

@ -6,24 +6,16 @@ session_start();
$TAB = 'DB';
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
// Header
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
// Panel
top_panel($user,$TAB);
$v_db_email = $panel[$user]['CONTACT'];
// Check POST request
if (!empty($_POST['ok'])) {
// Check input
// Check empty fields
if (empty($_POST['v_database'])) $errors[] = __('database');
if (empty($_POST['v_dbuser'])) $errors[] = __('username');
if (empty($_POST['v_password'])) $errors[] = __('password');
if (empty($_POST['v_type'])) $errors[] = __('type');
if (empty($_POST['v_host'])) $errors[] = __('host');
if (empty($_POST['v_charset'])) $errors[] = __('charset');
// Check for errors
if (!empty($errors[0])) {
foreach ($errors as $i => $error) {
if ( $i == 0 ) {
@ -36,12 +28,18 @@ if (!empty($_POST['ok'])) {
}
// Validate email
if (!empty($_POST['v_db_email'])) {
if ((!empty($_POST['v_db_email'])) && (empty($_SESSION['error_msg']))) {
if (!filter_var($_POST['v_db_email'], FILTER_VALIDATE_EMAIL)) {
$_SESSION['error_msg'] = __('Please enter valid email address.');
}
}
// Check password length
if (empty($_SESSION['error_msg'])) {
$pw_len = strlen($_POST['v_password']);
if ($pw_len < 6 ) $_SESSION['error_msg'] = __('Password is too short.',$error_msg);
}
// Protect input
$v_database = escapeshellarg($_POST['v_database']);
$v_dbuser = escapeshellarg($_POST['v_dbuser']);
@ -51,63 +49,71 @@ if (!empty($_POST['ok'])) {
$v_host = $_POST['v_host'];
$v_db_email = $_POST['v_db_email'];
// Check password length
// Add database
if (empty($_SESSION['error_msg'])) {
$pw_len = strlen($_POST['v_password']);
if ($pw_len < 6 ) $_SESSION['error_msg'] = __('Password is too short.',$error_msg);
}
if (empty($_SESSION['error_msg'])) {
// Add Database
$v_type = escapeshellarg($_POST['v_type']);
$v_charset = escapeshellarg($_POST['v_charset']);
$v_host = escapeshellarg($_POST['v_host']);
exec (VESTA_CMD."v-add-database ".$user." ".$v_database." ".$v_dbuser." ".$v_password." ".$v_type." ".$v_host." ".$v_charset, $output, $return_var);
check_return_code($return_var,$output);
unset($output);
$v_type = $_POST['v_type'];
$v_host = $_POST['v_host'];
$v_charset = $_POST['v_charset'];
check_return_code($return_var,$output);
}
// Get database manager url
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-list-sys-config json", $output, $return_var);
$sys = json_decode(implode('', $output), true);
unset($output);
if ((!empty($v_db_email)) && (empty($_SESSION['error_msg']))) {
list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"]);
if ($_POST['v_type'] == 'mysql') $db_admin_link = "http://".$http_host."/phpmyadmin/";
if ($_POST['v_type'] == 'pgsql') $db_admin_link = "http://".$http_host."/phppgadmin/";
$to = $v_db_email;
$subject = __("Database Credentials");
$hostname = exec('hostname');
$from = __('MAIL_FROM',$hostname);
$mailtext = __('DATABASE_READY',$user."_".$_POST['v_database'],$user."_".$_POST['v_dbuser'],$_POST['v_password'],$db_admin_link);
send_email($to, $subject, $mailtext, $from);
}
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-list-sys-config json", $output, $return_var);
$sys = json_decode(implode('', $output), true);
unset($output);
list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"] . ":");
if ($_POST['v_host'] != 'localhost' ) $http_host = $_POST['v_host'];
if ($_POST['v_type'] == 'mysql') $db_admin = "phpMyAdmin";
if ($_POST['v_type'] == 'mysql') $db_admin_link = "http://".$http_host."/phpmyadmin/";
if (($_POST['v_type'] == 'mysql') && (!empty($sys['config']['DB_PMA_URL']))) $db_admin_link = $sys['config']['DB_PMA_URL'];
if ($_POST['v_type'] == 'pgsql') $db_admin = "phpPgAdmin";
if ($_POST['v_type'] == 'pgsql') $db_admin_link = "http://".$http_host."/phppgadmin/";
if (($_POST['v_type'] == 'pgsql') && (!empty($sys['config']['DB_PGA_URL']))) $db_admin_link = $sys['config']['DB_PGA_URL'];
}
list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"] . ":");
if ($_POST['v_host'] != 'localhost' ) $http_host = $_POST['v_host'];
if ($_POST['v_type'] == 'mysql') $db_admin = "phpMyAdmin";
if ($_POST['v_type'] == 'mysql') $db_admin_link = "http://".$http_host."/phpmyadmin/";
if (($_POST['v_type'] == 'mysql') && (!empty($sys['config']['DB_PMA_URL']))) $db_admin_link = $sys['config']['DB_PMA_URL'];
if ($_POST['v_type'] == 'pgsql') $db_admin = "phpPgAdmin";
if ($_POST['v_type'] == 'pgsql') $db_admin_link = "http://".$http_host."/phppgadmin/";
if (($_POST['v_type'] == 'pgsql') && (!empty($sys['config']['DB_PGA_URL']))) $db_admin_link = $sys['config']['DB_PGA_URL'];
// Email login credentials
if ((!empty($v_db_email)) && (empty($_SESSION['error_msg']))) {
$to = $v_db_email;
$subject = __("Database Credentials");
$hostname = exec('hostname');
$from = __('MAIL_FROM',$hostname);
$mailtext = __('DATABASE_READY',$user."_".$_POST['v_database'],$user."_".$_POST['v_dbuser'],$_POST['v_password'],$db_admin_link);
send_email($to, $subject, $mailtext, $from);
}
$_SESSION['ok_msg'] = __('DATABASE_CREATED_OK',$user."_".$_POST['v_database'],$user."_".$_POST['v_database']);
$_SESSION['ok_msg'] .= " / <a href=".$db_admin_link." target='_blank'>" . __('open %s',$db_admin) . "</a>";
unset($v_database);
unset($v_dbuser);
unset($v_password);
unset($v_type);
unset($v_charset);
}
// Flush field values on success
if (empty($_SESSION['error_msg'])) {
$_SESSION['ok_msg'] = __('DATABASE_CREATED_OK',$user."_".$_POST['v_database'],$user."_".$_POST['v_database']);
$_SESSION['ok_msg'] .= " / <a href=".$db_admin_link." target='_blank'>" . __('open %s',$db_admin) . "</a>";
unset($v_database);
unset($v_dbuser);
unset($v_password);
unset($v_type);
unset($v_charset);
}
}
// Header
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
// Panel
top_panel($user,$TAB);
// Get user email
$v_db_email = $panel[$user]['CONTACT'];
// List avaiable database types
exec (VESTA_CMD."v-list-database-types 'json'", $output, $return_var);
$db_types = json_decode(implode('', $output), true);
unset($output);
// List available database servers
$db_hosts = array();
foreach ($db_types as $db_type ) {
exec (VESTA_CMD."v-list-database-hosts ".$db_type." 'json'", $output, $return_var);
@ -117,7 +123,10 @@ foreach ($db_types as $db_type ) {
unset($output);
}
// Display body
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_db.html');
// Flush session messages
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);

View file

@ -4,31 +4,15 @@ error_reporting(NULL);
ob_start();
session_start();
$TAB = 'DNS';
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
// Header
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
// Panel
top_panel($user,$TAB);
// Check POST request for dns domain
if (!empty($_POST['ok'])) {
// Check input
// Check empty fields
if (empty($_POST['v_domain'])) $errors[] = __('domain');
if (empty($_POST['v_ip'])) $errors[] = __('ip');
// Protect input
$v_domain = preg_replace("/^www./i", "", $_POST['v_domain']);
$v_domain = escapeshellarg($v_domain);
$v_domain = strtolower($v_domain);
$v_ip = escapeshellarg($_POST['v_ip']);
if (!empty($_POST['v_ns1'])) $v_ns1 = escapeshellarg($_POST['v_ns1']);
if (!empty($_POST['v_ns2'])) $v_ns2 = escapeshellarg($_POST['v_ns2']);
if (!empty($_POST['v_ns3'])) $v_ns3 = escapeshellarg($_POST['v_ns3']);
if (!empty($_POST['v_ns4'])) $v_ns4 = escapeshellarg($_POST['v_ns4']);
// Check for errors
if (!empty($errors[0])) {
foreach ($errors as $i => $error) {
if ( $i == 0 ) {
@ -38,49 +22,78 @@ if (!empty($_POST['ok'])) {
}
}
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
} else {
// Add DNS
}
// Protect input
$v_domain = preg_replace("/^www./i", "", $_POST['v_domain']);
$v_domain = escapeshellarg($v_domain);
$v_domain = strtolower($v_domain);
$v_ip = escapeshellarg($_POST['v_ip']);
if (!empty($_POST['v_ns1'])) $v_ns1 = escapeshellarg($_POST['v_ns1']);
if (!empty($_POST['v_ns2'])) $v_ns2 = escapeshellarg($_POST['v_ns2']);
if (!empty($_POST['v_ns3'])) $v_ns3 = escapeshellarg($_POST['v_ns3']);
if (!empty($_POST['v_ns4'])) $v_ns4 = escapeshellarg($_POST['v_ns4']);
// Add dns domain
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-add-dns-domain ".$user." ".$v_domain." ".$v_ip." ".$v_ns1." ".$v_ns2." ".$v_ns3." ".$v_ns4." no", $output, $return_var);
check_return_code($return_var,$output);
unset($output);
}
// Change Expiriation date
// Set expiriation date
if (empty($_SESSION['error_msg'])) {
if ((!empty($_POST['v_exp'])) && ($_POST['v_exp'] != date('Y-m-d', strtotime('+1 year')))) {
$v_exp = escapeshellarg($_POST['v_exp']);
exec (VESTA_CMD."v-change-dns-domain-exp ".$user." ".$v_domain." ".$v_exp." no", $output, $return_var);
check_return_code($return_var,$output);
unset($output);
}
}
// Change TTL
// Set ttl
if (empty($_SESSION['error_msg'])) {
if ((!empty($_POST['v_ttl'])) && ($_POST['v_ttl'] != '14400') && (empty($_SESSION['error_msg']))) {
$v_ttl = escapeshellarg($_POST['v_ttl']);
exec (VESTA_CMD."v-change-dns-domain-ttl ".$user." ".$v_domain." ".$v_ttl." no", $output, $return_var);
check_return_code($return_var,$output);
unset($output);
}
}
if (empty($_SESSION['error_msg'])) {
$_SESSION['ok_msg'] = __('DNS_DOMAIN_CREATED_OK',$_POST[v_domain],$_POST[v_domain]);
unset($v_domain);
}
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-restart-dns", $output, $return_var);
check_return_code($return_var,$output);
unset($output);
}
// Restart dns server
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-restart-dns", $output, $return_var);
check_return_code($return_var,$output);
unset($output);
}
// Flush field values on success
if (empty($_SESSION['error_msg'])) {
$_SESSION['ok_msg'] = __('DNS_DOMAIN_CREATED_OK',$_POST[v_domain],$_POST[v_domain]);
unset($v_domain);
}
}
// DNS Record
// Check POST request for dns record
if (!empty($_POST['ok_rec'])) {
// Check input
// Check empty fields
if (empty($_POST['v_domain'])) $errors[] = 'domain';
if (empty($_POST['v_rec'])) $errors[] = 'record';
if (empty($_POST['v_type'])) $errors[] = 'type';
if (empty($_POST['v_val'])) $errors[] = 'value';
if (!empty($errors[0])) {
foreach ($errors as $i => $error) {
if ( $i == 0 ) {
$error_msg = $error;
} else {
$error_msg = $error_msg.", ".$error;
}
}
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
}
// Protect input
$v_domain = escapeshellarg($_POST['v_domain']);
@ -89,34 +102,36 @@ if (!empty($_POST['ok_rec'])) {
$v_val = escapeshellarg($_POST['v_val']);
$v_priority = escapeshellarg($_POST['v_priority']);
// Check for errors
if (!empty($errors[0])) {
foreach ($errors as $i => $error) {
if ( $i == 0 ) {
$error_msg = $error;
} else {
$error_msg = $error_msg.", ".$error;
}
}
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
} else {
// Add DNS Record
// Add dns record
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-add-dns-record ".$user." ".$v_domain." ".$v_rec." ".$v_type." ".$v_val." ".$v_priority, $output, $return_var);
$v_type = $_POST['v_type'];
check_return_code($return_var,$output);
unset($output);
if (empty($_SESSION['error_msg'])) {
$_SESSION['ok_msg'] = __('DNS_RECORD_CREATED_OK',$_POST[v_rec],$_POST[v_domain]);
unset($v_domain);
unset($v_rec);
unset($v_val);
unset($v_priority);
}
$v_type = $_POST['v_type'];
}
// Flush field values on success
if (empty($_SESSION['error_msg'])) {
$_SESSION['ok_msg'] = __('DNS_RECORD_CREATED_OK',$_POST[v_rec],$_POST[v_domain]);
unset($v_domain);
unset($v_rec);
unset($v_val);
unset($v_priority);
}
}
if ((empty($_GET['domain'])) && (empty($_POST['domain']))) {
if ((empty($v_ns1)) && (empty($v_ns2))) {
// Header
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
// Panel
top_panel($user,$TAB);
// Display body for dns domain
if (empty($_GET['domain'])) {
if (empty($v_ttl)) $v_ttl = 14400;
if (empty($v_exp)) $v_exp = date('Y-m-d', strtotime('+1 year'));
if (empty($v_ns1)) {
exec (VESTA_CMD."v-list-user-ns ".$user." json", $output, $return_var);
$nameservers = json_decode(implode('', $output), true);
$v_ns1 = $nameservers[0];
@ -125,17 +140,18 @@ if ((empty($_GET['domain'])) && (empty($_POST['domain']))) {
$v_ns4 = $nameservers[3];
unset($output);
}
if (empty($v_ttl)) $v_ttl = 14400;
if (empty($v_exp)) $v_exp = date('Y-m-d', strtotime('+1 year'));
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns.html');
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);
} else {
}
// Display body for dns record
if (!empty($_GET['domain'])) {
$v_domain = $_GET['domain'];
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns_rec.html');
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);
}
// Flush session messages
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);
// Footer
include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');

View file

@ -4,80 +4,93 @@ error_reporting(NULL);
ob_start();
session_start();
$TAB = 'IP';
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
// Check user
if ($_SESSION['user'] != 'admin') {
header("Location: /list/user");
exit;
}
// Check POST request
if (!empty($_POST['ok'])) {
// Check empty fields
if (empty($_POST['v_ip'])) $errors[] = __('ip address');
if (empty($_POST['v_netmask'])) $errors[] = __('netmask');
if (empty($_POST['v_interface'])) $errors[] = __('interface');
if (empty($_POST['v_owner'])) $errors[] = __('assigned user');
if (!empty($errors[0])) {
foreach ($errors as $i => $error) {
if ( $i == 0 ) {
$error_msg = $error;
} else {
$error_msg = $error_msg.", ".$error;
}
}
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
}
// Protect input
$v_ip = escapeshellarg($_POST['v_ip']);
$v_netmask = escapeshellarg($_POST['v_netmask']);
$v_name = escapeshellarg($_POST['v_name']);
$v_nat = escapeshellarg($_POST['v_nat']);
$v_interface = escapeshellarg($_POST['v_interface']);
$v_owner = escapeshellarg($_POST['v_owner']);
$v_shared = $_POST['v_shared'];
// Check shared checkmark
if ($v_shared == 'on') {
$ip_status = 'shared';
} else {
$ip_status = 'dedicated';
$v_dedicated = 'yes';
}
// Add IP
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-add-sys-ip ".$v_ip." ".$v_netmask." ".$v_interface." ".$v_owner." '".$ip_status."' ".$v_name." ".$v_nat, $output, $return_var);
check_return_code($return_var,$output);
unset($output);
$v_owner = $_POST['v_owner'];
$v_interface = $_POST['v_interface'];
}
// Flush field values on success
if (empty($_SESSION['error_msg'])) {
$_SESSION['ok_msg'] = __('IP_CREATED_OK',$_POST['v_ip'],$_POST['v_ip']);
unset($v_ip);
unset($v_netmask);
unset($v_name);
unset($v_nat);
}
}
// Header
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
// Panel
top_panel($user,$TAB);
// Are you admin?
if ($_SESSION['user'] == 'admin') {
if (!empty($_POST['ok'])) {
// Check input
if (empty($_POST['v_ip'])) $errors[] = __('ip address');
if (empty($_POST['v_netmask'])) $errors[] = __('netmask');
if (empty($_POST['v_interface'])) $errors[] = __('interface');
if (empty($_POST['v_owner'])) $errors[] = __('assigned user');
// List network interfaces
exec (VESTA_CMD."v-list-sys-interfaces 'json'", $output, $return_var);
$interfaces = json_decode(implode('', $output), true);
unset($output);
// Protect input
$v_ip = escapeshellarg($_POST['v_ip']);
$v_netmask = escapeshellarg($_POST['v_netmask']);
$v_name = escapeshellarg($_POST['v_name']);
$v_nat = escapeshellarg($_POST['v_nat']);
// List users
exec (VESTA_CMD."v-list-sys-users 'json'", $output, $return_var);
$users = json_decode(implode('', $output), true);
unset($output);
$v_interface = $_POST['v_interface'];
$v_shared = $_POST['v_shared'];
if ($v_shared == 'on') {
$ip_status = 'shared';
} else {
$ip_status = 'dedicated';
$v_dedicated = 'yes';
}
// Display body
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_ip.html');
$v_owner = $_POST['v_owner'];
// Check for errors
if (!empty($errors[0])) {
foreach ($errors as $i => $error) {
if ( $i == 0 ) {
$error_msg = $error;
} else {
$error_msg = $error_msg.", ".$error;
}
}
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
} else {
// Add IP
$v_interface = escapeshellarg($_POST['v_interface']);
$v_owner = $_POST['v_owner'];
exec (VESTA_CMD."v-add-sys-ip ".$v_ip." ".$v_netmask." ".$v_interface." ".$v_owner." '".$ip_status."' ".$v_name." ".$v_nat, $output, $return_var);
$v_owner = $_POST['v_owner'];
$v_interface = $_POST['v_interface'];
check_return_code($return_var,$output);
unset($output);
if (empty($_SESSION['error_msg'])) {
$_SESSION['ok_msg'] = __('IP_CREATED_OK',$_POST['v_ip'],$_POST['v_ip']);
unset($v_ip);
unset($v_netmask);
unset($v_name);
unset($v_nat);
}
}
}
exec (VESTA_CMD."v-list-sys-interfaces 'json'", $output, $return_var);
$interfaces = json_decode(implode('', $output), true);
unset($output);
exec (VESTA_CMD."v-list-sys-users 'json'", $output, $return_var);
$users = json_decode(implode('', $output), true);
unset($output);
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_ip.html');
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);
}
// Flush session messages
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);
// Footer
include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');

View file

@ -4,41 +4,15 @@ error_reporting(NULL);
ob_start();
session_start();
$TAB = 'MAIL';
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
// Header
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
// Panel
top_panel($user,$TAB);
// Mail Domain
// Check POST request for mail domain
if (!empty($_POST['ok'])) {
// Check empty fields
if (empty($_POST['v_domain'])) $errors[] = __('domain');
if (!empty($_POST['v_antispam'])) {
$v_antispam = 'yes';
} else {
$v_antispam = 'no';
}
if (!empty($_POST['v_antivirus'])) {
$v_antivirus = 'yes';
} else {
$v_antivirus = 'no';
}
if (!empty($_POST['v_dkim'])) {
$v_dkim = 'yes';
} else {
$v_dkim = 'no';
}
// Protect input
$v_domain = preg_replace("/^www./i", "", $_POST['v_domain']);
$v_domain = escapeshellarg($v_domain);
$v_domain = strtolower($v_domain);
// Check for errors
if (!empty($errors[0])) {
foreach ($errors as $i => $error) {
if ( $i == 0 ) {
@ -48,27 +22,66 @@ if (!empty($_POST['ok'])) {
}
}
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
} else {
}
// Add mail domain
// Check antispam option
if (!empty($_POST['v_antispam'])) {
$v_antispam = 'yes';
} else {
$v_antispam = 'no';
}
// Check antivirus option
if (!empty($_POST['v_antivirus'])) {
$v_antivirus = 'yes';
} else {
$v_antivirus = 'no';
}
// Check dkim option
if (!empty($_POST['v_dkim'])) {
$v_dkim = 'yes';
} else {
$v_dkim = 'no';
}
// Set domain name to lowercase and remove www prefix
$v_domain = preg_replace("/^www./i", "", $_POST['v_domain']);
$v_domain = escapeshellarg($v_domain);
$v_domain = strtolower($v_domain);
// Add mail domain
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-add-mail-domain ".$user." ".$v_domain." ".$v_antispam." ".$v_antivirus." ".$v_dkim, $output, $return_var);
check_return_code($return_var,$output);
unset($output);
}
if (empty($_SESSION['error_msg'])) {
$_SESSION['ok_msg'] = __('MAIL_DOMAIN_CREATED_OK',$_POST['v_domain'],$_POST['v_domain']);
unset($v_domain);
}
// Flush field values on success
if (empty($_SESSION['error_msg'])) {
$_SESSION['ok_msg'] = __('MAIL_DOMAIN_CREATED_OK',$_POST['v_domain'],$_POST['v_domain']);
unset($v_domain);
}
}
// Mail Account
// Check POST request for mail account
if (!empty($_POST['ok_acc'])) {
// Check input
// Check empty fields
if (empty($_POST['v_domain'])) $errors[] = __('domain');
if (empty($_POST['v_account'])) $errors[] = __('account');
if (empty($_POST['v_password'])) $errors[] = __('password');
if (!empty($errors[0])) {
foreach ($errors as $i => $error) {
if ( $i == 0 ) {
$error_msg = $error;
} else {
$error_msg = $error_msg.", ".$error;
}
}
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
}
// Protect input
$v_domain = escapeshellarg($_POST['v_domain']);
@ -78,99 +91,100 @@ if (!empty($_POST['ok_acc'])) {
$v_quota = escapeshellarg($_POST['v_quota']);
$v_aliases = $_POST['v_aliases'];
$v_fwd = $_POST['v_fwd'];
if (empty($_POST['v_quota'])) $v_quota = 0;
if ((!empty($_POST['v_quota'])) || (!empty($_POST['v_aliases'])) || (!empty($_POST['v_fwd'])) ) $v_adv = 'yes';
// Check for errors
if (!empty($errors[0])) {
foreach ($errors as $i => $error) {
if ( $i == 0 ) {
$error_msg = $error;
} else {
$error_msg = $error_msg.", ".$error;
}
}
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
} else {
// Add Mail Account
// Add Mail Account
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-add-mail-account ".$user." ".$v_domain." ".$v_account." ".$v_password." ".$v_quota, $output, $return_var);
check_return_code($return_var,$output);
unset($output);
}
// Add Aliases
if ((!empty($_POST['v_aliases'])) && (empty($_SESSION['error_msg']))) {
$valiases = preg_replace("/\n/", " ", $_POST['v_aliases']);
$valiases = preg_replace("/,/", " ", $valiases);
$valiases = preg_replace('/\s+/', ' ',$valiases);
$valiases = trim($valiases);
$aliases = explode(" ", $valiases);
foreach ($aliases as $alias) {
$alias = escapeshellarg($alias);
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-add-mail-account-alias ".$user." ".$v_domain." ".$v_account." ".$alias, $output, $return_var);
check_return_code($return_var,$output);
}
unset($output);
}
}
// Add Forwads
if ((!empty($_POST['v_fwd'])) && (empty($_SESSION['error_msg']))) {
$vfwd = preg_replace("/\n/", " ", $_POST['v_fwd']);
$vfwd = preg_replace("/,/", " ", $vfwd);
$vfwd = preg_replace('/\s+/', ' ',$vfwd);
$vfwd = trim($vfwd);
$fwd = explode(" ", $vfwd);
foreach ($fwd as $forward) {
$forward = escapeshellarg($forward);
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-add-mail-account-forward ".$user." ".$v_domain." ".$v_account." ".$forward, $output, $return_var);
check_return_code($return_var,$output);
}
unset($output);
}
// Add fwd_only flag
if ((!empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) {
exec (VESTA_CMD."v-add-mail-account-fwd-only ".$user." ".$v_domain." ".$v_account, $output, $return_var);
// Add Aliases
if ((!empty($_POST['v_aliases'])) && (empty($_SESSION['error_msg']))) {
$valiases = preg_replace("/\n/", " ", $_POST['v_aliases']);
$valiases = preg_replace("/,/", " ", $valiases);
$valiases = preg_replace('/\s+/', ' ',$valiases);
$valiases = trim($valiases);
$aliases = explode(" ", $valiases);
foreach ($aliases as $alias) {
$alias = escapeshellarg($alias);
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-add-mail-account-alias ".$user." ".$v_domain." ".$v_account." ".$alias, $output, $return_var);
check_return_code($return_var,$output);
unset($output);
}
}
}
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-list-sys-config json", $output, $return_var);
$sys = json_decode(implode('', $output), true);
unset($output);
list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"].":");
$webmail = "http://".$http_host."/webmail/";
if (!empty($sys['config']['MAIL_URL'])) $webmail = $sys['config']['MAIL_URL'];
$_SESSION['ok_msg'] = __('MAIL_ACCOUNT_CREATED_OK',strtolower($_POST['v_account']),$_POST[v_domain],strtolower($_POST['v_account']),$_POST[v_domain]);
$_SESSION['ok_msg'] .= " / <a href=".$webmail." target='_blank'>" . __('open webmail') . "</a>";
unset($v_account);
unset($v_password);
unset($v_password);
unset($v_aliases);
unset($v_fwd);
unset($v_quota);
// Add Forwarders
if ((!empty($_POST['v_fwd'])) && (empty($_SESSION['error_msg']))) {
$vfwd = preg_replace("/\n/", " ", $_POST['v_fwd']);
$vfwd = preg_replace("/,/", " ", $vfwd);
$vfwd = preg_replace('/\s+/', ' ',$vfwd);
$vfwd = trim($vfwd);
$fwd = explode(" ", $vfwd);
foreach ($fwd as $forward) {
$forward = escapeshellarg($forward);
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-add-mail-account-forward ".$user." ".$v_domain." ".$v_account." ".$forward, $output, $return_var);
check_return_code($return_var,$output);
unset($output);
}
}
}
// Add fwd_only flag
if ((!empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) {
exec (VESTA_CMD."v-add-mail-account-fwd-only ".$user." ".$v_domain." ".$v_account, $output, $return_var);
check_return_code($return_var,$output);
unset($output);
}
// Get webmail url
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-list-sys-config json", $output, $return_var);
$sys = json_decode(implode('', $output), true);
unset($output);
list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"].":");
$webmail = "http://".$http_host."/webmail/";
if (!empty($sys['config']['MAIL_URL'])) $webmail = $sys['config']['MAIL_URL'];
}
// Flush field values on success
if (empty($_SESSION['error_msg'])) {
$_SESSION['ok_msg'] = __('MAIL_ACCOUNT_CREATED_OK',strtolower($_POST['v_account']),$_POST[v_domain],strtolower($_POST['v_account']),$_POST[v_domain]);
$_SESSION['ok_msg'] .= " / <a href=".$webmail." target='_blank'>" . __('open webmail') . "</a>";
unset($v_account);
unset($v_password);
unset($v_password);
unset($v_aliases);
unset($v_fwd);
unset($v_quota);
}
}
// Header
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
if ((empty($_GET['domain'])) && (empty($_POST['domain']))) {
$v_domain = (isset($_GET['domain'])?$_GET['domain']:'');
// Panel
top_panel($user,$TAB);
// Display body for mail domain
if (empty($_GET['domain'])) {
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_mail.html');
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);
} else {
}
// Display body for mail account
if (!empty($_GET['domain'])) {
$v_domain = $_GET['domain'];
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_mail_acc.html');
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);
}
// Flush session messages
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);
// Footer
include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');

View file

@ -4,175 +4,181 @@ error_reporting(NULL);
ob_start();
session_start();
$TAB = 'PACKAGE';
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
if (empty($_SESSION['user'])) {
header("Location: /login/");
// Check user
if ($_SESSION['user'] != 'admin') {
header("Location: /list/user");
exit;
}
// Check POST request
if (!empty($_POST['ok'])) {
// Check empty fields
if (empty($_POST['v_package'])) $errors[] = __('package');
if (empty($_POST['v_web_template'])) $errors[] = __('web template');
if (empty($_POST['v_proxy_template'])) $errors[] = __('proxy template');
if (empty($_POST['v_dns_template'])) $errors[] = __('dns template');
if (empty($_POST['v_shell'])) $errrors[] = __('shell');
if (!isset($_POST['v_web_domains'])) $errors[] = __('web domains');
if (!isset($_POST['v_web_aliases'])) $errors[] = __('web aliases');
if (!isset($_POST['v_dns_domains'])) $errors[] = __('dns domains');
if (!isset($_POST['v_dns_records'])) $errors[] = __('dns records');
if (!isset($_POST['v_mail_domains'])) $errors[] = __('mail domains');
if (!isset($_POST['v_mail_accounts'])) $errors[] = __('mail accounts');
if (!isset($_POST['v_databases'])) $errors[] = __('databases');
if (!isset($_POST['v_cron_jobs'])) $errors[] = __('cron jobs');
if (!isset($_POST['v_backups'])) $errors[] = __('backups');
if (!isset($_POST['v_disk_quota'])) $errors[] = __('quota');
if (!isset($_POST['v_bandwidth'])) $errors[] = __('bandwidth');
if (empty($_POST['v_ns1'])) $errors[] = __('ns1');
if (empty($_POST['v_ns2'])) $errors[] = __('ns2');
if (!empty($errors[0])) {
foreach ($errors as $i => $error) {
if ( $i == 0 ) {
$error_msg = $error;
} else {
$error_msg = $error_msg.", ".$error;
}
}
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
}
// Protect input
$v_package = escapeshellarg($_POST['v_package']);
$v_web_template = escapeshellarg($_POST['v_web_template']);
$v_proxy_template = escapeshellarg($_POST['v_proxy_template']);
$v_dns_template = escapeshellarg($_POST['v_dns_template']);
$v_shell = escapeshellarg($_POST['v_shell']);
$v_web_domains = escapeshellarg($_POST['v_web_domains']);
$v_web_aliases = escapeshellarg($_POST['v_web_aliases']);
$v_dns_domains = escapeshellarg($_POST['v_dns_domains']);
$v_dns_records = escapeshellarg($_POST['v_dns_records']);
$v_mail_domains = escapeshellarg($_POST['v_mail_domains']);
$v_mail_accounts = escapeshellarg($_POST['v_mail_accounts']);
$v_databases = escapeshellarg($_POST['v_databases']);
$v_cron_jobs = escapeshellarg($_POST['v_cron_jobs']);
$v_backups = escapeshellarg($_POST['v_backups']);
$v_disk_quota = escapeshellarg($_POST['v_disk_quota']);
$v_bandwidth = escapeshellarg($_POST['v_bandwidth']);
$v_ns1 = trim($_POST['v_ns1'], '.');
$v_ns2 = trim($_POST['v_ns2'], '.');
$v_ns3 = trim($_POST['v_ns3'], '.');
$v_ns4 = trim($_POST['v_ns4'], '.');
$v_ns = $v_ns1.",".$v_ns2;
if (!empty($v_ns3)) $v_ns .= ",".$v_ns3;
if (!empty($v_ns4)) $v_ns .= ",".$v_ns4;
$v_ns = escapeshellarg($v_ns);
$v_time = escapeshellarg(date('H:i:s'));
$v_date = escapeshellarg(date('Y-m-d'));
// Create temporary dir
if (empty($_SESSION['error_msg'])) {
exec ('mktemp -d', $output, $return_var);
$tmpdir = $output[0];
check_return_code($return_var,$output);
unset($output);
}
// Create package file
if (empty($_SESSION['error_msg'])) {
$pkg = "WEB_TEMPLATE=".$v_web_template."\n";
$pkg .= "PROXY_TEMPLATE=".$v_proxy_template."\n";
$pkg .= "DNS_TEMPLATE=".$v_dns_template."\n";
$pkg .= "WEB_DOMAINS=".$v_web_domains."\n";
$pkg .= "WEB_ALIASES=".$v_web_aliases."\n";
$pkg .= "DNS_DOMAINS=".$v_dns_domains."\n";
$pkg .= "DNS_RECORDS=".$v_dns_records."\n";
$pkg .= "MAIL_DOMAINS=".$v_mail_domains."\n";
$pkg .= "MAIL_ACCOUNTS=".$v_mail_accounts."\n";
$pkg .= "DATABASES=".$v_databases."\n";
$pkg .= "CRON_JOBS=".$v_cron_jobs."\n";
$pkg .= "DISK_QUOTA=".$v_disk_quota."\n";
$pkg .= "BANDWIDTH=".$v_bandwidth."\n";
$pkg .= "NS=".$v_ns."\n";
$pkg .= "SHELL=".$v_shell."\n";
$pkg .= "BACKUPS=".$v_backups."\n";
$pkg .= "TIME=".$v_time."\n";
$pkg .= "DATE=".$v_date."\n";
$fp = fopen($tmpdir."/".$_POST['v_package'].".pkg", 'w');
fwrite($fp, $pkg);
fclose($fp);
}
// Add new package
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-add-user-package ".$tmpdir." ".$v_package, $output, $return_var);
check_return_code($return_var,$output);
unset($output);
}
// Remove tmpdir
exec ('rm -rf '.$tmpdir, $output, $return_var);
unset($output);
// Flush field values on success
if (empty($_SESSION['error_msg'])) {
$_SESSION['ok_msg'] = __('PACKAGE_CREATED_OK',$_POST['v_package'],$_POST['v_package']);
unset($v_package);
}
}
// Header
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
// Panel
top_panel($user,$TAB);
// Are you admin?
if ($_SESSION['user'] == 'admin') {
if (!empty($_POST['ok'])) {
// Check input
if (empty($_POST['v_package'])) $errors[] = __('package');
if (empty($_POST['v_web_template'])) $errors[] = __('web template');
if (empty($_POST['v_proxy_template'])) $errors[] = __('proxy template');
if (empty($_POST['v_dns_template'])) $errors[] = __('dns template');
if (empty($_POST['v_shell'])) $errrors[] = __('shell');
if (!isset($_POST['v_web_domains'])) $errors[] = __('web domains');
if (!isset($_POST['v_web_aliases'])) $errors[] = __('web aliases');
if (!isset($_POST['v_dns_domains'])) $errors[] = __('dns domains');
if (!isset($_POST['v_dns_records'])) $errors[] = __('dns records');
if (!isset($_POST['v_mail_domains'])) $errors[] = __('mail domains');
if (!isset($_POST['v_mail_accounts'])) $errors[] = __('mail accounts');
if (!isset($_POST['v_databases'])) $errors[] = __('databases');
if (!isset($_POST['v_cron_jobs'])) $errors[] = __('cron jobs');
if (!isset($_POST['v_backups'])) $errors[] = __('backups');
if (!isset($_POST['v_disk_quota'])) $errors[] = __('quota');
if (!isset($_POST['v_bandwidth'])) $errors[] = __('bandwidth');
if (empty($_POST['v_ns1'])) $errors[] = __('ns1');
if (empty($_POST['v_ns2'])) $errors[] = __('ns2');
// List web temmplates
exec (VESTA_CMD."v-list-web-templates json", $output, $return_var);
$web_templates = json_decode(implode('', $output), true);
unset($output);
// List web templates for proxy
exec (VESTA_CMD."v-list-web-templates-proxy json", $output, $return_var);
$proxy_templates = json_decode(implode('', $output), true);
unset($output);
// Protect input
$v_package = escapeshellarg($_POST['v_package']);
$v_web_template = escapeshellarg($_POST['v_web_template']);
$v_proxy_template = escapeshellarg($_POST['v_proxy_template']);
$v_dns_template = escapeshellarg($_POST['v_dns_template']);
$v_shell = escapeshellarg($_POST['v_shell']);
$v_web_domains = escapeshellarg($_POST['v_web_domains']);
$v_web_aliases = escapeshellarg($_POST['v_web_aliases']);
$v_dns_domains = escapeshellarg($_POST['v_dns_domains']);
$v_dns_records = escapeshellarg($_POST['v_dns_records']);
$v_mail_domains = escapeshellarg($_POST['v_mail_domains']);
$v_mail_accounts = escapeshellarg($_POST['v_mail_accounts']);
$v_databases = escapeshellarg($_POST['v_databases']);
$v_cron_jobs = escapeshellarg($_POST['v_cron_jobs']);
$v_backups = escapeshellarg($_POST['v_backups']);
$v_disk_quota = escapeshellarg($_POST['v_disk_quota']);
$v_bandwidth = escapeshellarg($_POST['v_bandwidth']);
$v_ns1 = trim($_POST['v_ns1'], '.');
$v_ns2 = trim($_POST['v_ns2'], '.');
$v_ns3 = trim($_POST['v_ns3'], '.');
$v_ns4 = trim($_POST['v_ns4'], '.');
$v_ns = $v_ns1.",".$v_ns2;
if (!empty($v_ns3)) $v_ns .= ",".$v_ns3;
if (!empty($v_ns4)) $v_ns .= ",".$v_ns4;
$v_ns = escapeshellarg($v_ns);
$v_time = escapeshellarg(date('H:i:s'));
$v_date = escapeshellarg(date('Y-m-d'));
// List DNS templates
exec (VESTA_CMD."v-list-dns-templates json", $output, $return_var);
$dns_templates = json_decode(implode('', $output), true);
unset($output);
// Check for errors
if (!empty($errors[0])) {
foreach ($errors as $i => $error) {
if ( $i == 0 ) {
$error_msg = $error;
} else {
$error_msg = $error_msg.", ".$error;
}
}
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
} else {
exec ('mktemp -d', $output, $return_var);
$tmpdir = $output[0];
unset($output);
// List system shells
exec (VESTA_CMD."v-list-sys-shells json", $output, $return_var);
$shells = json_decode(implode('', $output), true);
unset($output);
// Create package
$pkg = "WEB_TEMPLATE=".$v_web_template."\n";
$pkg .= "PROXY_TEMPLATE=".$v_proxy_template."\n";
$pkg .= "DNS_TEMPLATE=".$v_dns_template."\n";
$pkg .= "WEB_DOMAINS=".$v_web_domains."\n";
$pkg .= "WEB_ALIASES=".$v_web_aliases."\n";
$pkg .= "DNS_DOMAINS=".$v_dns_domains."\n";
$pkg .= "DNS_RECORDS=".$v_dns_records."\n";
$pkg .= "MAIL_DOMAINS=".$v_mail_domains."\n";
$pkg .= "MAIL_ACCOUNTS=".$v_mail_accounts."\n";
$pkg .= "DATABASES=".$v_databases."\n";
$pkg .= "CRON_JOBS=".$v_cron_jobs."\n";
$pkg .= "DISK_QUOTA=".$v_disk_quota."\n";
$pkg .= "BANDWIDTH=".$v_bandwidth."\n";
$pkg .= "NS=".$v_ns."\n";
$pkg .= "SHELL=".$v_shell."\n";
$pkg .= "BACKUPS=".$v_backups."\n";
$pkg .= "TIME=".$v_time."\n";
$pkg .= "DATE=".$v_date."\n";
// Set default values
if (empty($v_web_template)) $v_web_template = 'default';
if (empty($v_proxy_template)) $v_proxy_template = 'default';
if (empty($v_dns_template)) $v_dns_template = 'default';
if (empty($v_shell)) $v_shell = 'nologin';
if (empty($v_web_domains)) $v_web_domains = "'0'";
if (empty($v_web_aliases)) $v_web_aliases = "'0'";
if (empty($v_dns_domains)) $v_dns_domains = "'0'";
if (empty($v_dns_records)) $v_dns_records = "'0'";
if (empty($v_mail_domains)) $v_mail_domains = "'0'";
if (empty($v_mail_accounts)) $v_mail_accounts = "'0'";
if (empty($v_databases)) $v_databases = "'0'";
if (empty($v_cron_jobs)) $v_cron_jobs = "'0'";
if (empty($v_backups)) $v_backups = "'0'";
if (empty($v_disk_quota)) $v_disk_quota = "'0'";
if (empty($v_bandwidth)) $v_bandwidth = "'0'";
if (empty($v_ns1)) $v_ns1 = 'ns1.example.ltd';
if (empty($v_ns2)) $v_ns2 = 'ns2.example.ltd';
// Write package
$fp = fopen($tmpdir."/".$_POST['v_package'].".pkg", 'w');
fwrite($fp, $pkg);
fclose($fp);
// Display body
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_package.html');
// Add new package
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-add-user-package ".$tmpdir." ".$v_package, $output, $return_var);
check_return_code($return_var,$output);
unset($output);
}
// Remove tmpdir
exec ('rm -rf '.$tmpdir, $output, $return_var);
unset($output);
// Check output
if (empty($_SESSION['error_msg'])) {
$_SESSION['ok_msg'] = __('PACKAGE_CREATED_OK',$_POST['v_package'],$_POST['v_package']);
unset($v_package);
}
}
}
exec (VESTA_CMD."v-list-web-templates json", $output, $return_var);
check_error($return_var);
$web_templates = json_decode(implode('', $output), true);
unset($output);
exec (VESTA_CMD."v-list-web-templates-proxy json", $output, $return_var);
check_error($return_var);
$proxy_templates = json_decode(implode('', $output), true);
unset($output);
exec (VESTA_CMD."v-list-dns-templates json", $output, $return_var);
check_error($return_var);
$dns_templates = json_decode(implode('', $output), true);
unset($output);
exec (VESTA_CMD."v-list-sys-shells json", $output, $return_var);
check_error($return_var);
$shells = json_decode(implode('', $output), true);
unset($output);
// Set default values
if (empty($v_web_template)) $v_web_template = 'default';
if (empty($v_proxy_template)) $v_proxy_template = 'default';
if (empty($v_dns_template)) $v_dns_template = 'default';
if (empty($v_shell)) $v_shell = 'nologin';
if (empty($v_web_domains)) $v_web_domains = "'0'";
if (empty($v_web_aliases)) $v_web_aliases = "'0'";
if (empty($v_dns_domains)) $v_dns_domains = "'0'";
if (empty($v_dns_records)) $v_dns_records = "'0'";
if (empty($v_mail_domains)) $v_mail_domains = "'0'";
if (empty($v_mail_accounts)) $v_mail_accounts = "'0'";
if (empty($v_databases)) $v_databases = "'0'";
if (empty($v_cron_jobs)) $v_cron_jobs = "'0'";
if (empty($v_backups)) $v_backups = "'0'";
if (empty($v_disk_quota)) $v_disk_quota = "'0'";
if (empty($v_bandwidth)) $v_bandwidth = "'0'";
if (empty($v_ns1)) $v_ns1 = 'ns1.example.ltd';
if (empty($v_ns2)) $v_ns2 = 'ns2.example.ltd';
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_package.html');
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);
}
// Flush session messages
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);
// Footer
include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');

View file

@ -1,110 +1,128 @@
<?php
// Init
error_reporting(NULL);
ob_start();
session_start();
$TAB = 'USER';
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
if (empty($_SESSION['user'])) {
header("Location: /login/");
// Check user
if ($_SESSION['user'] != 'admin') {
header("Location: /list/user");
exit;
}
// Check POST request
if (!empty($_POST['ok'])) {
// Check empty fields
if (empty($_POST['v_username'])) $errors[] = __('user');
if (empty($_POST['v_password'])) $errors[] = __('password');
if (empty($_POST['v_package'])) $errrors[] = __('package');
if (empty($_POST['v_email'])) $errors[] = __('email');
if (empty($_POST['v_fname'])) $errors[] = __('first name');
if (empty($_POST['v_lname'])) $errors[] = __('last name');
if (!empty($errors[0])) {
foreach ($errors as $i => $error) {
if ( $i == 0 ) {
$error_msg = $error;
} else {
$error_msg = $error_msg.", ".$error;
}
}
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
}
// Validate email
if ((empty($_SESSION['error_msg'])) && (!filter_var($_POST['v_email'], FILTER_VALIDATE_EMAIL))) {
$_SESSION['error_msg'] = __('Please enter valid email address.');
}
// Check password length
if (empty($_SESSION['error_msg'])) {
$pw_len = strlen($_POST['v_password']);
if ($pw_len < 6 ) $_SESSION['error_msg'] = __('Password is too short.',$error_msg);
}
// Protect input
$v_username = escapeshellarg($_POST['v_username']);
$v_password = escapeshellarg($_POST['v_password']);
$v_email = escapeshellarg($_POST['v_email']);
$v_package = escapeshellarg($_POST['v_package']);
$v_language = escapeshellarg($_POST['v_language']);
$v_fname = escapeshellarg($_POST['v_fname']);
$v_lname = escapeshellarg($_POST['v_lname']);
$v_notify = $_POST['v_notify'];
// Add user
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-add-user ".$v_username." ".$v_password." ".$v_email." ".$v_package." ".$v_fname." ".$v_lname, $output, $return_var);
check_return_code($return_var,$output);
unset($output);
}
// Set language
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-change-user-language ".$v_username." ".$v_language, $output, $return_var);
check_return_code($return_var,$output);
unset($output);
}
// Send email to the new user
if ((empty($_SESSION['error_msg'])) && (!empty($v_notify))) {
$to = $_POST['v_notify'];
$subject = _translate($_POST['v_language'],"Welcome to Vesta Control Panel");
$hostname = exec('hostname');
unset($output);
$from = _translate($_POST['v_language'],'MAIL_FROM',$hostname);
if (!empty($_POST['v_fname'])) {
$mailtext = _translate($_POST['v_language'],'GREETINGS_GORDON_FREEMAN',$_POST['v_fname'],$_POST['v_lname']);
} else {
$mailtext = _translate($_POST['v_language'],'GREETINGS');
}
$mailtext .= _translate($_POST['v_language'],'ACCOUNT_READY',$_SERVER['HTTP_HOST'],$_POST['v_username'],$_POST['v_password']);
send_email($to, $subject, $mailtext, $from);
}
// Flush field values on success
if (empty($_SESSION['error_msg'])) {
$_SESSION['ok_msg'] = __('USER_CREATED_OK',$_POST['v_username'],$_POST['v_username']);
$_SESSION['ok_msg'] .= " / <a href=/login/?loginas=".$_POST['v_username'].">" . __('login as') ." ".$_POST['v_username']. "</a>";
unset($v_username);
unset($v_password);
unset($v_email);
unset($v_fname);
unset($v_lname);
unset($v_notify);
}
}
// Header
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
// Panel
top_panel($user,$TAB);
// Are you admin?
if ($_SESSION['user'] == 'admin') {
if (!empty($_POST['ok'])) {
// Check input
if (empty($_POST['v_username'])) $errors[] = __('user');
if (empty($_POST['v_password'])) $errors[] = __('password');
if (empty($_POST['v_package'])) $errrors[] = __('package');
if (empty($_POST['v_email'])) $errors[] = __('email');
if (empty($_POST['v_fname'])) $errors[] = __('first name');
if (empty($_POST['v_lname'])) $errors[] = __('last name');
// List hosting packages
exec (VESTA_CMD."v-list-user-packages json", $output, $return_var);
check_error($return_var);
$data = json_decode(implode('', $output), true);
unset($output);
// Protect input
$v_username = escapeshellarg($_POST['v_username']);
$v_password = escapeshellarg($_POST['v_password']);
$v_email = escapeshellarg($_POST['v_email']);
$v_package = escapeshellarg($_POST['v_package']);
$v_language = escapeshellarg($_POST['v_language']);
$v_fname = escapeshellarg($_POST['v_fname']);
$v_lname = escapeshellarg($_POST['v_lname']);
$v_notify = $_POST['v_notify'];
// List languages
exec (VESTA_CMD."v-list-sys-languages json", $output, $return_var);
$languages = json_decode(implode('', $output), true);
unset($output);
// Validate email
if (!filter_var($_POST['v_email'], FILTER_VALIDATE_EMAIL)) {
$_SESSION['error_msg'] = __('Please enter valid email address.');
}
// Display body
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_user.html');
// Check for errors
if (!empty($errors[0])) {
foreach ($errors as $i => $error) {
if ( $i == 0 ) {
$error_msg = $error;
} else {
$error_msg = $error_msg.", ".$error;
}
}
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
}
// Check password length
if (empty($_SESSION['error_msg'])) {
$pw_len = strlen($_POST['v_password']);
if ($pw_len < 6 ) $_SESSION['error_msg'] = __('Password is too short.',$error_msg);
}
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-add-user ".$v_username." ".$v_password." ".$v_email." ".$v_package." ".$v_fname." ".$v_lname, $output, $return_var);
check_return_code($return_var,$output);
unset($output);
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-change-user-language ".$v_username." ".$v_language, $output, $return_var);
if (!empty($v_notify)) {
$to = $_POST['v_notify'];
$subject = _translate($_POST['v_language'],"Welcome to Vesta Control Panel");
$hostname = exec('hostname');
$from = _translate($_POST['v_language'],'MAIL_FROM',$hostname);
if (!empty($_POST['v_fname'])) {
$mailtext = _translate($_POST['v_language'],'GREETINGS_GORDON_FREEMAN',$_POST['v_fname'],$_POST['v_lname']);
} else {
$mailtext = _translate($_POST['v_language'],'GREETINGS');
}
$mailtext .= _translate($_POST['v_language'],'ACCOUNT_READY',$_SERVER['HTTP_HOST'],$_POST['v_username'],$_POST['v_password']);
send_email($to, $subject, $mailtext, $from);
}
$_SESSION['ok_msg'] = __('USER_CREATED_OK',$_POST[v_username],$_POST[v_username]);
$_SESSION['ok_msg'] .= " / <a href=/login/?loginas=".$_POST[v_username].">" . __('login as') ." ".$_POST[v_username]. "</a>";
unset($v_username);
unset($v_password);
unset($v_email);
unset($v_fname);
unset($v_lname);
unset($v_notify);
}
unset($output);
}
}
exec (VESTA_CMD."v-list-user-packages json", $output, $return_var);
check_error($return_var);
$data = json_decode(implode('', $output), true);
unset($output);
exec (VESTA_CMD."v-list-sys-languages json", $output, $return_var);
$languages = json_decode(implode('', $output), true);
unset($output);
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_user.html');
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);
}
// Flush session messages
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);
// Footer
include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');