|
| 1 | +<?php |
| 2 | +// Init |
| 3 | +error_reporting(NULL); |
| 4 | +ob_start(); |
| 5 | +session_start(); |
| 6 | + |
| 7 | +$TAB = 'PACKAGE'; |
| 8 | +include($_SERVER['DOCUMENT_ROOT']."/inc/main.php"); |
| 9 | + |
| 10 | +// Header |
| 11 | +include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html'); |
| 12 | + |
| 13 | +// Panel |
| 14 | +top_panel($user,$TAB); |
| 15 | + |
| 16 | +// Are you admin? |
| 17 | +if ($_SESSION['user'] == 'admin') { |
| 18 | + |
| 19 | + // Check user argument? |
| 20 | + if (empty($_GET['package'])) { |
| 21 | + header("Location: /list/package/"); |
| 22 | + exit; |
| 23 | + } |
| 24 | + |
| 25 | + $v_package = escapeshellarg($_GET['package']); |
| 26 | + exec (VESTA_CMD."v_list_user_package ".$v_package." 'json'", $output, $return_var); |
| 27 | + if ($return_var != 0) { |
| 28 | + $error = implode('<br>', $output); |
| 29 | + if (empty($error)) $error = 'Error: vesta did not return any output.'; |
| 30 | + $_SESSION['error_msg'] = $error; |
| 31 | + } else { |
| 32 | + $data = json_decode(implode('', $output), true); |
| 33 | + unset($output); |
| 34 | + |
| 35 | + $v_package = $_GET['package']; |
| 36 | + $v_template = $data[$v_package]['TEMPLATE']; |
| 37 | + $v_web_domains = $data[$v_package]['WEB_DOMAINS']; |
| 38 | + $v_web_aliases = $data[$v_package]['WEB_ALIASES']; |
| 39 | + $v_dns_domains = $data[$v_package]['DNS_DOMAINS']; |
| 40 | + $v_dns_records = $data[$v_package]['DNS_RECORDS']; |
| 41 | + $v_mail_domains = $data[$v_package]['MAIL_DOMAINS']; |
| 42 | + $v_mail_accounts = $data[$v_package]['MAIL_ACCOUNTS']; |
| 43 | + $v_databases = $data[$v_package]['DATABASES']; |
| 44 | + $v_cron_jobs = $data[$v_package]['CRON_JOBS']; |
| 45 | + $v_disk_quota = $data[$v_package]['DISK_QUOTA']; |
| 46 | + $v_bandwidth = $data[$v_package]['BANDWIDTH']; |
| 47 | + $v_shell = $data[$v_package]['SHELL']; |
| 48 | + $v_ns = $data[$v_package]['NS']; |
| 49 | + $nameservers = explode(", ", $v_ns); |
| 50 | + $v_ns1 = $nameservers[0]; |
| 51 | + $v_ns2 = $nameservers[1]; |
| 52 | + $v_ns3 = $nameservers[2]; |
| 53 | + $v_ns4 = $nameservers[3]; |
| 54 | + $v_backups = $data[$v_package]['BACKUPS']; |
| 55 | + $v_date = $data[$v_package]['DATE']; |
| 56 | + $v_time = $data[$v_package]['TIME']; |
| 57 | + $v_status = 'active'; |
| 58 | + |
| 59 | + |
| 60 | + exec (VESTA_CMD."v_list_web_templates json", $output, $return_var); |
| 61 | + check_error($return_var); |
| 62 | + $templates = json_decode(implode('', $output), true); |
| 63 | + unset($output); |
| 64 | + |
| 65 | + exec (VESTA_CMD."v_list_sys_shells json", $output, $return_var); |
| 66 | + check_error($return_var); |
| 67 | + $shells = json_decode(implode('', $output), true); |
| 68 | + unset($output); |
| 69 | + |
| 70 | + // Action |
| 71 | + if (!empty($_POST['save'])) { |
| 72 | + // Check input |
| 73 | + if (empty($_POST['v_package'])) $errors[] = 'package'; |
| 74 | + if (empty($_POST['v_template'])) $errors[] = 'template'; |
| 75 | + if (empty($_POST['v_shell'])) $errrors[] = 'shell'; |
| 76 | + if (!isset($_POST['v_web_domains'])) $errors[] = 'web domains'; |
| 77 | + if (!isset($_POST['v_web_aliases'])) $errors[] = 'web aliases'; |
| 78 | + if (!isset($_POST['v_dns_domains'])) $errors[] = 'dns domains'; |
| 79 | + if (!isset($_POST['v_dns_records'])) $errors[] = 'dns records'; |
| 80 | + if (!isset($_POST['v_mail_domains'])) $errors[] = 'mail domains'; |
| 81 | + if (!isset($_POST['v_mail_accounts'])) $errors[] = 'mail accounts'; |
| 82 | + if (!isset($_POST['v_databases'])) $errors[] = 'databases'; |
| 83 | + if (!isset($_POST['v_cron_jobs'])) $errors[] = 'cron jobs'; |
| 84 | + if (!isset($_POST['v_backups'])) $errors[] = 'backups'; |
| 85 | + if (!isset($_POST['v_disk_quota'])) $errors[] = 'quota'; |
| 86 | + if (!isset($_POST['v_bandwidth'])) $errors[] = 'bandwidth'; |
| 87 | + if (empty($_POST['v_ns1'])) $errors[] = 'ns1'; |
| 88 | + if (empty($_POST['v_ns2'])) $errors[] = 'ns2'; |
| 89 | + |
| 90 | + // Protect input |
| 91 | + $v_package = escapeshellarg($_POST['v_package']); |
| 92 | + $v_template = escapeshellarg($_POST['v_template']); |
| 93 | + $v_shell = escapeshellarg($_POST['v_shell']); |
| 94 | + $v_web_domains = escapeshellarg($_POST['v_web_domains']); |
| 95 | + $v_web_aliases = escapeshellarg($_POST['v_web_aliases']); |
| 96 | + $v_dns_domains = escapeshellarg($_POST['v_dns_domains']); |
| 97 | + $v_dns_records = escapeshellarg($_POST['v_dns_records']); |
| 98 | + $v_mail_domains = escapeshellarg($_POST['v_mail_domains']); |
| 99 | + $v_mail_accounts = escapeshellarg($_POST['v_mail_accounts']); |
| 100 | + $v_databases = escapeshellarg($_POST['v_databases']); |
| 101 | + $v_cron_jobs = escapeshellarg($_POST['v_cron_jobs']); |
| 102 | + $v_backups = escapeshellarg($_POST['v_backups']); |
| 103 | + $v_disk_quota = escapeshellarg($_POST['v_disk_quota']); |
| 104 | + $v_bandwidth = escapeshellarg($_POST['v_bandwidth']); |
| 105 | + $v_ns1 = trim($_POST['v_ns1'], '.'); |
| 106 | + $v_ns2 = trim($_POST['v_ns2'], '.'); |
| 107 | + $v_ns3 = trim($_POST['v_ns3'], '.'); |
| 108 | + $v_ns4 = trim($_POST['v_ns4'], '.'); |
| 109 | + $v_ns = $v_ns1.",".$v_ns2; |
| 110 | + if (!empty($v_ns3)) $v_ns .= ",".$v_ns3; |
| 111 | + if (!empty($v_ns4)) $v_ns .= ",".$v_ns4; |
| 112 | + $v_ns = escapeshellarg($v_ns); |
| 113 | + $v_time = escapeshellarg(date('H:i:s')); |
| 114 | + $v_date = escapeshellarg(date('Y-m-d')); |
| 115 | + |
| 116 | + // Check for errors |
| 117 | + if (!empty($errors[0])) { |
| 118 | + foreach ($errors as $i => $error) { |
| 119 | + if ( $i == 0 ) { |
| 120 | + $error_msg = $error; |
| 121 | + } else { |
| 122 | + $error_msg = $error_msg.", ".$error; |
| 123 | + } |
| 124 | + } |
| 125 | + $_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank."; |
| 126 | + } else { |
| 127 | + exec ('mktemp -d', $output, $return_var); |
| 128 | + $tmpdir = $output[0]; |
| 129 | + unset($output); |
| 130 | + |
| 131 | + // Create package |
| 132 | + $pkg = "TEMPLATE=".$v_template."\n"; |
| 133 | + $pkg .= "WEB_DOMAINS=".$v_web_domains."\n"; |
| 134 | + $pkg .= "WEB_ALIASES=".$v_web_aliases."\n"; |
| 135 | + $pkg .= "DNS_DOMAINS=".$v_dns_domains."\n"; |
| 136 | + $pkg .= "DNS_RECORDS=".$v_dns_records."\n"; |
| 137 | + $pkg .= "MAIL_DOMAINS=".$v_mail_domains."\n"; |
| 138 | + $pkg .= "MAIL_ACCOUNTS=".$v_mail_accounts."\n"; |
| 139 | + $pkg .= "DATABASES=".$v_databases."\n"; |
| 140 | + $pkg .= "CRON_JOBS=".$v_cron_jobs."\n"; |
| 141 | + $pkg .= "DISK_QUOTA=".$v_disk_quota."\n"; |
| 142 | + $pkg .= "BANDWIDTH=".$v_bandwidth."\n"; |
| 143 | + $pkg .= "NS=".$v_ns."\n"; |
| 144 | + $pkg .= "SHELL=".$v_shell."\n"; |
| 145 | + $pkg .= "BACKUPS=".$v_backups."\n"; |
| 146 | + $pkg .= "TIME=".$v_time."\n"; |
| 147 | + $pkg .= "DATE=".$v_date."\n"; |
| 148 | + |
| 149 | + // Write package |
| 150 | + $fp = fopen($tmpdir."/".$_POST['v_package'].".pkg", 'w'); |
| 151 | + fwrite($fp, $pkg); |
| 152 | + fclose($fp); |
| 153 | + |
| 154 | + // Rewrite package |
| 155 | + if (empty($_SESSION['error_msg'])) { |
| 156 | + exec (VESTA_CMD."v_add_user_package ".$tmpdir." ".$v_package." 'yes'", $output, $return_var); |
| 157 | + if ($return_var != 0) { |
| 158 | + $error = implode('<br>', $output); |
| 159 | + if (empty($error)) $error = 'Error: vesta did not return any output.'; |
| 160 | + $_SESSION['error_msg'] = $error; |
| 161 | + } |
| 162 | + unset($output); |
| 163 | + } |
| 164 | + |
| 165 | + // Remove tmpdir |
| 166 | + exec ('rm -rf '.$tmpdir, $output, $return_var); |
| 167 | + unset($output); |
| 168 | + |
| 169 | + // Propogate new package |
| 170 | + exec (VESTA_CMD."v_update_user_package ".$v_package." 'json'", $output, $return_var); |
| 171 | + if ($return_var != 0) { |
| 172 | + $error = implode('<br>', $output); |
| 173 | + if (empty($error)) $error = 'Error: vesta did not return any output.'; |
| 174 | + $_SESSION['error_msg'] = $error; |
| 175 | + } |
| 176 | + |
| 177 | + if (empty($_SESSION['error_msg'])) { |
| 178 | + $_SESSION['ok_msg'] = "OK: changes has been saved."; |
| 179 | + } |
| 180 | + } |
| 181 | + } |
| 182 | + } |
| 183 | + |
| 184 | + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_edit_package.html'); |
| 185 | + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_package.html'); |
| 186 | + unset($_SESSION['error_msg']); |
| 187 | + unset($_SESSION['ok_msg']); |
| 188 | +} |
| 189 | + |
| 190 | +// Footer |
| 191 | +include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html'); |
0 commit comments