1
0
mirror of https://github.com/myvesta/vesta.git synced 2025-02-24 10:57:22 -08:00

215 lines
7.2 KiB
PHP
Raw Permalink Normal View History

2013-01-18 18:23:04 +04:00
<?php
error_reporting(NULL);
ob_start();
$TAB = 'MAIL';
// Main include
2014-07-30 15:34:34 +03:00
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
2013-01-18 18:23:04 +04:00
2014-07-30 15:34:34 +03:00
// Check POST request for mail domain
2013-10-29 00:34:26 +02:00
if (!empty($_POST['ok'])) {
2014-07-30 15:34:34 +03:00
2015-06-03 02:31:03 +03:00
// Check token
if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
header('location: /login/');
exit();
2015-06-03 02:31:03 +03:00
}
2014-07-30 15:34:34 +03:00
// Check empty fields
2013-10-29 00:34:26 +02:00
if (empty($_POST['v_domain'])) $errors[] = __('domain');
2014-07-30 15:34:34 +03:00
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 antispam option
2013-10-29 00:34:26 +02:00
if (!empty($_POST['v_antispam'])) {
$v_antispam = 'yes';
} else {
$v_antispam = 'no';
}
2013-01-18 18:23:04 +04:00
2014-07-30 15:34:34 +03:00
// Check antivirus option
2013-10-29 00:34:26 +02:00
if (!empty($_POST['v_antivirus'])) {
$v_antivirus = 'yes';
} else {
$v_antivirus = 'no';
}
2013-01-18 18:23:04 +04:00
2014-07-30 15:34:34 +03:00
// Check dkim option
2013-10-29 00:34:26 +02:00
if (!empty($_POST['v_dkim'])) {
$v_dkim = 'yes';
} else {
$v_dkim = 'no';
}
2013-01-18 18:23:04 +04:00
2014-07-30 15:34:34 +03:00
// Set domain name to lowercase and remove www prefix
2013-10-29 00:34:26 +02:00
$v_domain = preg_replace("/^www./i", "", $_POST['v_domain']);
$v_domain = escapeshellarg($v_domain);
2013-10-29 00:34:26 +02:00
$v_domain = strtolower($v_domain);
2014-07-30 15:34:34 +03:00
// 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);
2014-07-30 15:34:34 +03:00
}
2013-01-18 18:23:04 +04:00
2014-07-30 15:34:34 +03:00
// Flush field values on success
if (empty($_SESSION['error_msg'])) {
$_SESSION['ok_msg'] = __('MAIL_DOMAIN_CREATED_OK',htmlentities($_POST['v_domain']),htmlentities($_POST['v_domain']));
2014-07-30 15:34:34 +03:00
unset($v_domain);
2013-10-29 00:34:26 +02:00
}
}
2014-07-30 15:34:34 +03:00
// Check POST request for mail account
2013-10-29 00:34:26 +02:00
if (!empty($_POST['ok_acc'])) {
2014-07-30 15:34:34 +03:00
2015-06-03 02:31:03 +03:00
// Check token
if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
header('location: /login/');
exit();
2015-06-03 02:31:03 +03:00
}
2014-07-30 15:34:34 +03:00
// Check empty fields
2013-10-29 00:34:26 +02:00
if (empty($_POST['v_domain'])) $errors[] = __('domain');
if (empty($_POST['v_account'])) $errors[] = __('account');
if (empty($_POST['v_password'])) $errors[] = __('password');
2014-07-30 15:34:34 +03:00
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);
2014-07-30 15:34:34 +03:00
}
2013-10-29 00:34:26 +02:00
2017-04-09 02:35:13 +02:00
// Validate email
if ((!empty($_POST['v_send_email'])) && (empty($_SESSION['error_msg']))) {
if (!filter_var($_POST['v_send_email'], FILTER_VALIDATE_EMAIL)) {
$_SESSION['error_msg'] = __('Please enter valid email address.');
}
}
2013-10-29 00:34:26 +02:00
// Protect input
$v_domain = escapeshellarg($_POST['v_domain']);
$v_domain = strtolower($v_domain);
$v_account = escapeshellarg($_POST['v_account']);
$v_quota = escapeshellarg($_POST['v_quota']);
2017-04-09 02:35:13 +02:00
$v_send_email = $_POST['v_send_email'];
$v_credentials = $_POST['v_credentials'];
2013-10-29 00:34:26 +02:00
$v_aliases = $_POST['v_aliases'];
$v_fwd = $_POST['v_fwd'];
if (empty($_POST['v_quota'])) $v_quota = 0;
2013-10-29 00:34:26 +02:00
if ((!empty($_POST['v_quota'])) || (!empty($_POST['v_aliases'])) || (!empty($_POST['v_fwd'])) ) $v_adv = 'yes';
2014-07-30 15:34:34 +03:00
// Add Mail Account
if (empty($_SESSION['error_msg'])) {
2015-03-31 00:01:44 +03:00
$v_password = tempnam("/tmp","vst");
$fp = fopen($v_password, "w");
fwrite($fp, $_POST['v_password']."\n");
fclose($fp);
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);
2015-03-31 00:01:44 +03:00
unlink($v_password);
$v_password = escapeshellarg($_POST['v_password']);
2014-07-30 15:34:34 +03:00
}
2013-10-29 00:34:26 +02:00
2014-07-30 15:34:34 +03:00
// Add Aliases
if ((!empty($_POST['v_aliases'])) && (empty($_SESSION['error_msg']))) {
$valiases = preg_replace("/\n/", " ", $_POST['v_aliases']);
$valiases = preg_replace("/,/", " ", $valiases);
2014-07-30 15:34:34 +03:00
$valiases = preg_replace('/\s+/', ' ',$valiases);
$valiases = trim($valiases);
$aliases = explode(" ", $valiases);
2014-07-30 15:34:34 +03:00
foreach ($aliases as $alias) {
$alias = escapeshellarg($alias);
2014-07-30 15:34:34 +03:00
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);
2013-01-18 18:23:04 +04:00
}
2013-10-29 00:34:26 +02:00
}
2014-07-30 15:34:34 +03:00
}
2013-01-18 18:23:04 +04:00
2014-07-30 15:34:34 +03:00
// Add Forwarders
if ((!empty($_POST['v_fwd'])) && (empty($_SESSION['error_msg']))) {
$vfwd = preg_replace("/\n/", " ", $_POST['v_fwd']);
$vfwd = preg_replace("/,/", " ", $vfwd);
2014-07-30 15:34:34 +03:00
$vfwd = preg_replace('/\s+/', ' ',$vfwd);
$vfwd = trim($vfwd);
$fwd = explode(" ", $vfwd);
2014-07-30 15:34:34 +03:00
foreach ($fwd as $forward) {
$forward = escapeshellarg($forward);
2014-07-30 15:34:34 +03:00
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);
2013-11-13 11:40:23 +02:00
}
2013-01-18 18:23:04 +04:00
}
2014-07-30 15:34:34 +03:00
}
2013-10-29 00:34:26 +02:00
2014-07-30 15:34:34 +03:00
// 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);
2014-07-30 15:34:34 +03:00
}
// Get webmail url
if (empty($_SESSION['error_msg'])) {
list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"].":");
$webmail = "http://".$http_host."/webmail/";
if (!empty($_SESSION['MAIL_URL'])) $webmail = $_SESSION['MAIL_URL'];
2014-07-30 15:34:34 +03:00
}
2017-04-09 02:35:13 +02:00
// Email login credentials
if ((!empty($v_send_email)) && (empty($_SESSION['error_msg']))) {
$to = $v_send_email;
$subject = __("Email Credentials");
$hostname = exec('hostname');
$from = __('MAIL_FROM', $hostname);
$mailtext = $v_credentials;
send_email($to, $subject, $mailtext, $from);
}
2014-07-30 15:34:34 +03:00
// Flush field values on success
if (empty($_SESSION['error_msg'])) {
$_SESSION['ok_msg'] = __('MAIL_ACCOUNT_CREATED_OK',htmlentities(strtolower($_POST['v_account'])),htmlentities($_POST[v_domain]),htmlentities(strtolower($_POST['v_account'])),htmlentities($_POST[v_domain]));
2023-06-12 16:28:15 +02:00
$_SESSION['ok_msg'] .= " / <a style=\"text-decoration: underline; color: #9c8cff;\" href=".$webmail." target='_blank'>" . __('open webmail') . "</a>";
2014-07-30 15:34:34 +03:00
unset($v_account);
unset($v_password);
unset($v_password);
unset($v_aliases);
unset($v_fwd);
unset($v_quota);
2013-01-18 18:23:04 +04:00
}
2013-10-29 00:34:26 +02:00
}
// Render page
if (empty($_GET['domain'])) {
// Display body for mail domain
2013-10-29 00:34:26 +02:00
2016-07-02 21:40:46 +09:00
render_page($user, $TAB, 'add_mail');
} else {
// Display body for mail account
2014-07-30 15:34:34 +03:00
2013-10-29 00:34:26 +02:00
$v_domain = $_GET['domain'];
2016-07-02 21:40:46 +09:00
render_page($user, $TAB, 'add_mail_acc');
2013-10-29 00:34:26 +02:00
}
2013-01-18 18:23:04 +04:00
2014-07-30 15:34:34 +03:00
// Flush session messages
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);