index.php 9.0 KB

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