|
| 1 | +<?php |
| 2 | +// Init |
| 3 | +error_reporting(NULL); |
| 4 | +ob_start(); |
| 5 | +session_start(); |
| 6 | +$TAB = 'MAIL'; |
| 7 | +include($_SERVER['DOCUMENT_ROOT']."/inc/main.php"); |
| 8 | + |
| 9 | +// Header |
| 10 | +include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html'); |
| 11 | + |
| 12 | +// Panel |
| 13 | +top_panel($user,$TAB); |
| 14 | + |
| 15 | +// Are you admin? |
| 16 | +if ($_SESSION['user'] == 'admin') { |
| 17 | + |
| 18 | + // Cancel |
| 19 | + if (!empty($_POST['cancel'])) { |
| 20 | + header("Location: /list/mail/"); |
| 21 | + } |
| 22 | + |
| 23 | + // Mail Domain |
| 24 | + if (!empty($_POST['ok'])) { |
| 25 | + if (empty($_POST['v_domain'])) $errors[] = 'domain'; |
| 26 | + if (!empty($_POST['v_antispam'])) { |
| 27 | + $v_antispam = 'yes'; |
| 28 | + } else { |
| 29 | + $v_antispam = 'no'; |
| 30 | + } |
| 31 | + |
| 32 | + if (!empty($_POST['v_antivirus'])) { |
| 33 | + $v_antivirus = 'yes'; |
| 34 | + } else { |
| 35 | + $v_antivirus = 'no'; |
| 36 | + } |
| 37 | + |
| 38 | + if (!empty($_POST['v_dkim'])) { |
| 39 | + $v_dkim = 'yes'; |
| 40 | + } else { |
| 41 | + $v_dkim = 'no'; |
| 42 | + } |
| 43 | + |
| 44 | + // Protect input |
| 45 | + $v_domain = preg_replace("/^www./i", "", $_POST['v_domain']); |
| 46 | + $v_domain = escapeshellarg($v_domain); |
| 47 | + |
| 48 | + // Check for errors |
| 49 | + if (!empty($errors[0])) { |
| 50 | + foreach ($errors as $i => $error) { |
| 51 | + if ( $i == 0 ) { |
| 52 | + $error_msg = $error; |
| 53 | + } else { |
| 54 | + $error_msg = $error_msg.", ".$error; |
| 55 | + } |
| 56 | + } |
| 57 | + $_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank."; |
| 58 | + } else { |
| 59 | + |
| 60 | + // Add mail domain |
| 61 | + exec (VESTA_CMD."v_add_mail_domain ".$user." ".$v_domain." ".$v_antispam." ".$v_antivirus." ".$v_dkim, $output, $return_var); |
| 62 | + if ($return_var != 0) { |
| 63 | + $error = implode('<br>', $output); |
| 64 | + if (empty($error)) $error = 'Error: vesta did not return any output.'; |
| 65 | + $_SESSION['error_msg'] = $error; |
| 66 | + } |
| 67 | + unset($output); |
| 68 | + |
| 69 | + if (empty($_SESSION['error_msg'])) { |
| 70 | + $_SESSION['ok_msg'] = "OK: domain <b>".$_POST[v_domain]."</b> has been created successfully."; |
| 71 | + unset($v_domain); |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + |
| 77 | + // Mail Account |
| 78 | + if (!empty($_POST['ok_acc'])) { |
| 79 | + // Check input |
| 80 | + if (empty($_POST['v_domain'])) $errors[] = 'domain'; |
| 81 | + if (empty($_POST['v_account'])) $errors[] = 'account'; |
| 82 | + if (empty($_POST['v_password'])) $errors[] = 'password'; |
| 83 | + |
| 84 | + // Protect input |
| 85 | + $v_domain = escapeshellarg($_POST['v_domain']); |
| 86 | + $v_account = escapeshellarg($_POST['v_account']); |
| 87 | + $v_password = escapeshellarg($_POST['v_password']); |
| 88 | + $v_quota = escapeshellarg($_POST['v_quota']); |
| 89 | + if (empty($_POST['v_quota'])) $v_quota = 0; |
| 90 | + |
| 91 | + // Check for errors |
| 92 | + if (!empty($errors[0])) { |
| 93 | + foreach ($errors as $i => $error) { |
| 94 | + if ( $i == 0 ) { |
| 95 | + $error_msg = $error; |
| 96 | + } else { |
| 97 | + $error_msg = $error_msg.", ".$error; |
| 98 | + } |
| 99 | + } |
| 100 | + $_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank."; |
| 101 | + } else { |
| 102 | + // Add Mail Account |
| 103 | + exec (VESTA_CMD."v_add_mail_account ".$user." ".$v_domain." ".$v_account." ".$v_password." ".$v_quota, $output, $return_var); |
| 104 | + if ($return_var != 0) { |
| 105 | + $error = implode('<br>', $output); |
| 106 | + if (empty($error)) $error = 'Error: vesta did not return any output.'; |
| 107 | + $_SESSION['error_msg'] = $error; |
| 108 | + } |
| 109 | + unset($output); |
| 110 | + if (empty($_SESSION['error_msg'])) { |
| 111 | + $_SESSION['ok_msg'] = "OK: account <b>".$_POST['v_account']."</b> has been created successfully."; |
| 112 | + unset($v_account); |
| 113 | + unset($v_password); |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + |
| 119 | + if ((empty($_GET['domain'])) && (empty($_POST['domain']))) { |
| 120 | + $v_domain = $_GET['domain']; |
| 121 | + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_mail.html'); |
| 122 | + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_mail.html'); |
| 123 | + unset($_SESSION['error_msg']); |
| 124 | + unset($_SESSION['ok_msg']); |
| 125 | + } else { |
| 126 | + $v_domain = $_GET['domain']; |
| 127 | + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_mail_acc.html'); |
| 128 | + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_mail_acc.html'); |
| 129 | + unset($_SESSION['error_msg']); |
| 130 | + unset($_SESSION['ok_msg']); |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +// Footer |
| 135 | +include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html'); |
0 commit comments