index.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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_template = $data[$v_package]['TEMPLATE'];
  30. $v_web_domains = $data[$v_package]['WEB_DOMAINS'];
  31. $v_web_aliases = $data[$v_package]['WEB_ALIASES'];
  32. $v_dns_domains = $data[$v_package]['DNS_DOMAINS'];
  33. $v_dns_records = $data[$v_package]['DNS_RECORDS'];
  34. $v_mail_domains = $data[$v_package]['MAIL_DOMAINS'];
  35. $v_mail_accounts = $data[$v_package]['MAIL_ACCOUNTS'];
  36. $v_databases = $data[$v_package]['DATABASES'];
  37. $v_cron_jobs = $data[$v_package]['CRON_JOBS'];
  38. $v_disk_quota = $data[$v_package]['DISK_QUOTA'];
  39. $v_bandwidth = $data[$v_package]['BANDWIDTH'];
  40. $v_shell = $data[$v_package]['SHELL'];
  41. $v_ns = $data[$v_package]['NS'];
  42. $nameservers = explode(", ", $v_ns);
  43. $v_ns1 = $nameservers[0];
  44. $v_ns2 = $nameservers[1];
  45. $v_ns3 = $nameservers[2];
  46. $v_ns4 = $nameservers[3];
  47. $v_backups = $data[$v_package]['BACKUPS'];
  48. $v_date = $data[$v_package]['DATE'];
  49. $v_time = $data[$v_package]['TIME'];
  50. $v_status = 'active';
  51. exec (VESTA_CMD."v-list-web-templates json", $output, $return_var);
  52. check_error($return_var);
  53. $templates = json_decode(implode('', $output), true);
  54. unset($output);
  55. exec (VESTA_CMD."v-list-sys-shells json", $output, $return_var);
  56. check_error($return_var);
  57. $shells = json_decode(implode('', $output), true);
  58. unset($output);
  59. // Action
  60. if (!empty($_POST['save'])) {
  61. // Check input
  62. if (empty($_POST['v_package'])) $errors[] = __('package');
  63. if (empty($_POST['v_template'])) $errors[] = __('template');
  64. if (empty($_POST['v_shell'])) $errrors[] = __('shell');
  65. if (!isset($_POST['v_web_domains'])) $errors[] = __('web domains');
  66. if (!isset($_POST['v_web_aliases'])) $errors[] = __('web aliases');
  67. if (!isset($_POST['v_dns_domains'])) $errors[] = __('dns domains');
  68. if (!isset($_POST['v_dns_records'])) $errors[] = __('dns records');
  69. if (!isset($_POST['v_mail_domains'])) $errors[] = __('mail domains');
  70. if (!isset($_POST['v_mail_accounts'])) $errors[] = __('mail accounts');
  71. if (!isset($_POST['v_databases'])) $errors[] = __('databases');
  72. if (!isset($_POST['v_cron_jobs'])) $errors[] = __('cron jobs');
  73. if (!isset($_POST['v_backups'])) $errors[] = __('backups');
  74. if (!isset($_POST['v_disk_quota'])) $errors[] = __('quota');
  75. if (!isset($_POST['v_bandwidth'])) $errors[] = __('bandwidth');
  76. if (empty($_POST['v_ns1'])) $errors[] = __('ns1');
  77. if (empty($_POST['v_ns2'])) $errors[] = __('ns2');
  78. // Protect input
  79. $v_package = escapeshellarg($_POST['v_package']);
  80. $v_template = escapeshellarg($_POST['v_template']);
  81. $v_shell = escapeshellarg($_POST['v_shell']);
  82. $v_web_domains = escapeshellarg($_POST['v_web_domains']);
  83. $v_web_aliases = escapeshellarg($_POST['v_web_aliases']);
  84. $v_dns_domains = escapeshellarg($_POST['v_dns_domains']);
  85. $v_dns_records = escapeshellarg($_POST['v_dns_records']);
  86. $v_mail_domains = escapeshellarg($_POST['v_mail_domains']);
  87. $v_mail_accounts = escapeshellarg($_POST['v_mail_accounts']);
  88. $v_databases = escapeshellarg($_POST['v_databases']);
  89. $v_cron_jobs = escapeshellarg($_POST['v_cron_jobs']);
  90. $v_backups = escapeshellarg($_POST['v_backups']);
  91. $v_disk_quota = escapeshellarg($_POST['v_disk_quota']);
  92. $v_bandwidth = escapeshellarg($_POST['v_bandwidth']);
  93. $v_ns1 = trim($_POST['v_ns1'], '.');
  94. $v_ns2 = trim($_POST['v_ns2'], '.');
  95. $v_ns3 = trim($_POST['v_ns3'], '.');
  96. $v_ns4 = trim($_POST['v_ns4'], '.');
  97. $v_ns = $v_ns1.",".$v_ns2;
  98. if (!empty($v_ns3)) $v_ns .= ",".$v_ns3;
  99. if (!empty($v_ns4)) $v_ns .= ",".$v_ns4;
  100. $v_ns = escapeshellarg($v_ns);
  101. $v_time = escapeshellarg(date('H:i:s'));
  102. $v_date = escapeshellarg(date('Y-m-d'));
  103. // Check for errors
  104. if (!empty($errors[0])) {
  105. foreach ($errors as $i => $error) {
  106. if ( $i == 0 ) {
  107. $error_msg = $error;
  108. } else {
  109. $error_msg = $error_msg.", ".$error;
  110. }
  111. }
  112. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  113. } else {
  114. exec ('mktemp -d', $output, $return_var);
  115. $tmpdir = $output[0];
  116. unset($output);
  117. // Create package
  118. $pkg = "TEMPLATE=".$v_template."\n";
  119. $pkg .= "WEB_DOMAINS=".$v_web_domains."\n";
  120. $pkg .= "WEB_ALIASES=".$v_web_aliases."\n";
  121. $pkg .= "DNS_DOMAINS=".$v_dns_domains."\n";
  122. $pkg .= "DNS_RECORDS=".$v_dns_records."\n";
  123. $pkg .= "MAIL_DOMAINS=".$v_mail_domains."\n";
  124. $pkg .= "MAIL_ACCOUNTS=".$v_mail_accounts."\n";
  125. $pkg .= "DATABASES=".$v_databases."\n";
  126. $pkg .= "CRON_JOBS=".$v_cron_jobs."\n";
  127. $pkg .= "DISK_QUOTA=".$v_disk_quota."\n";
  128. $pkg .= "BANDWIDTH=".$v_bandwidth."\n";
  129. $pkg .= "NS=".$v_ns."\n";
  130. $pkg .= "SHELL=".$v_shell."\n";
  131. $pkg .= "BACKUPS=".$v_backups."\n";
  132. $pkg .= "TIME=".$v_time."\n";
  133. $pkg .= "DATE=".$v_date."\n";
  134. // Write package
  135. $fp = fopen($tmpdir."/".$_POST['v_package'].".pkg", 'w');
  136. fwrite($fp, $pkg);
  137. fclose($fp);
  138. // Rewrite package
  139. if (empty($_SESSION['error_msg'])) {
  140. exec (VESTA_CMD."v-add-user-package ".$tmpdir." ".$v_package." 'yes'", $output, $return_var);
  141. if ($return_var != 0) {
  142. $error = implode('<br>', $output);
  143. if (empty($error)) $error = __('Error code:',$return_var);
  144. $_SESSION['error_msg'] = $error;
  145. }
  146. unset($output);
  147. }
  148. // Remove tmpdir
  149. exec ('rm -rf '.$tmpdir, $output, $return_var);
  150. unset($output);
  151. // Propogate new package
  152. exec (VESTA_CMD."v-update-user-package ".$v_package." 'json'", $output, $return_var);
  153. if ($return_var != 0) {
  154. $error = implode('<br>', $output);
  155. if (empty($error)) $error = __('Error code:',$return_var);
  156. $_SESSION['error_msg'] = $error;
  157. }
  158. if (empty($_SESSION['error_msg'])) {
  159. $_SESSION['ok_msg'] = __('Changes has been saved.');
  160. }
  161. }
  162. }
  163. }
  164. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_package.html');
  165. unset($_SESSION['error_msg']);
  166. unset($_SESSION['ok_msg']);
  167. }
  168. // Footer
  169. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');