index.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. // Check user
  9. if ($_SESSION['user'] != 'admin') {
  10. header("Location: /list/user");
  11. exit;
  12. }
  13. // Check package argument
  14. if (empty($_GET['package'])) {
  15. header("Location: /list/package/");
  16. exit;
  17. }
  18. // List package
  19. $v_package = escapeshellarg($_GET['package']);
  20. exec (VESTA_CMD."v-list-user-package ".$v_package." 'json'", $output, $return_var);
  21. $data = json_decode(implode('', $output), true);
  22. unset($output);
  23. // Parse package
  24. $v_package = $_GET['package'];
  25. $v_web_template = $data[$v_package]['WEB_TEMPLATE'];
  26. $v_proxy_template = $data[$v_package]['PROXY_TEMPLATE'];
  27. $v_dns_template = $data[$v_package]['DNS_TEMPLATE'];
  28. $v_web_domains = $data[$v_package]['WEB_DOMAINS'];
  29. $v_web_aliases = $data[$v_package]['WEB_ALIASES'];
  30. $v_dns_domains = $data[$v_package]['DNS_DOMAINS'];
  31. $v_dns_records = $data[$v_package]['DNS_RECORDS'];
  32. $v_mail_domains = $data[$v_package]['MAIL_DOMAINS'];
  33. $v_mail_accounts = $data[$v_package]['MAIL_ACCOUNTS'];
  34. $v_databases = $data[$v_package]['DATABASES'];
  35. $v_cron_jobs = $data[$v_package]['CRON_JOBS'];
  36. $v_disk_quota = $data[$v_package]['DISK_QUOTA'];
  37. $v_bandwidth = $data[$v_package]['BANDWIDTH'];
  38. $v_shell = $data[$v_package]['SHELL'];
  39. $v_ns = $data[$v_package]['NS'];
  40. $nameservers = explode(", ", $v_ns);
  41. $v_ns1 = $nameservers[0];
  42. $v_ns2 = $nameservers[1];
  43. $v_ns3 = $nameservers[2];
  44. $v_ns4 = $nameservers[3];
  45. $v_backups = $data[$v_package]['BACKUPS'];
  46. $v_date = $data[$v_package]['DATE'];
  47. $v_time = $data[$v_package]['TIME'];
  48. $v_status = 'active';
  49. // List web templates
  50. exec (VESTA_CMD."v-list-web-templates json", $output, $return_var);
  51. $web_templates = json_decode(implode('', $output), true);
  52. unset($output);
  53. // List proxy templates
  54. if (!empty($_SESSION['PROXY_SYSTEM'])) {
  55. exec (VESTA_CMD."v-list-web-templates-proxy json", $output, $return_var);
  56. $proxy_templates = json_decode(implode('', $output), true);
  57. unset($output);
  58. }
  59. // List dns templates
  60. exec (VESTA_CMD."v-list-dns-templates json", $output, $return_var);
  61. $dns_templates = json_decode(implode('', $output), true);
  62. unset($output);
  63. // List shels
  64. exec (VESTA_CMD."v-list-sys-shells json", $output, $return_var);
  65. $shells = json_decode(implode('', $output), true);
  66. unset($output);
  67. // Check POST request
  68. if (!empty($_POST['save'])) {
  69. // Check empty fields
  70. if (empty($_POST['v_package'])) $errors[] = __('package');
  71. if (empty($_POST['v_web_template'])) $errors[] = __('web template');
  72. if (empty($_POST['v_proxy_template'])) $errors[] = __('proxy template');
  73. if (empty($_POST['v_dns_template'])) $errors[] = __('dns template');
  74. if (empty($_POST['v_shell'])) $errrors[] = __('shell');
  75. if (!isset($_POST['v_web_domains'])) $errors[] = __('web domains');
  76. if (!isset($_POST['v_web_aliases'])) $errors[] = __('web aliases');
  77. if (!isset($_POST['v_dns_domains'])) $errors[] = __('dns domains');
  78. if (!isset($_POST['v_dns_records'])) $errors[] = __('dns records');
  79. if (!isset($_POST['v_mail_domains'])) $errors[] = __('mail domains');
  80. if (!isset($_POST['v_mail_accounts'])) $errors[] = __('mail accounts');
  81. if (!isset($_POST['v_databases'])) $errors[] = __('databases');
  82. if (!isset($_POST['v_cron_jobs'])) $errors[] = __('cron jobs');
  83. if (!isset($_POST['v_backups'])) $errors[] = __('backups');
  84. if (!isset($_POST['v_disk_quota'])) $errors[] = __('quota');
  85. if (!isset($_POST['v_bandwidth'])) $errors[] = __('bandwidth');
  86. if (empty($_POST['v_ns1'])) $errors[] = __('ns1');
  87. if (empty($_POST['v_ns2'])) $errors[] = __('ns2');
  88. if (!empty($errors[0])) {
  89. foreach ($errors as $i => $error) {
  90. if ( $i == 0 ) {
  91. $error_msg = $error;
  92. } else {
  93. $error_msg = $error_msg.", ".$error;
  94. }
  95. }
  96. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  97. }
  98. // Protect input
  99. $v_package = escapeshellarg($_POST['v_package']);
  100. $v_web_template = escapeshellarg($_POST['v_web_template']);
  101. $v_proxy_template = escapeshellarg($_POST['v_proxy_template']);
  102. $v_dns_template = escapeshellarg($_POST['v_dns_template']);
  103. $v_shell = escapeshellarg($_POST['v_shell']);
  104. $v_web_domains = escapeshellarg($_POST['v_web_domains']);
  105. $v_web_aliases = escapeshellarg($_POST['v_web_aliases']);
  106. $v_dns_domains = escapeshellarg($_POST['v_dns_domains']);
  107. $v_dns_records = escapeshellarg($_POST['v_dns_records']);
  108. $v_mail_domains = escapeshellarg($_POST['v_mail_domains']);
  109. $v_mail_accounts = escapeshellarg($_POST['v_mail_accounts']);
  110. $v_databases = escapeshellarg($_POST['v_databases']);
  111. $v_cron_jobs = escapeshellarg($_POST['v_cron_jobs']);
  112. $v_backups = escapeshellarg($_POST['v_backups']);
  113. $v_disk_quota = escapeshellarg($_POST['v_disk_quota']);
  114. $v_bandwidth = escapeshellarg($_POST['v_bandwidth']);
  115. $v_ns1 = trim($_POST['v_ns1'], '.');
  116. $v_ns2 = trim($_POST['v_ns2'], '.');
  117. $v_ns3 = trim($_POST['v_ns3'], '.');
  118. $v_ns4 = trim($_POST['v_ns4'], '.');
  119. $v_ns = $v_ns1.",".$v_ns2;
  120. if (!empty($v_ns3)) $v_ns .= ",".$v_ns3;
  121. if (!empty($v_ns4)) $v_ns .= ",".$v_ns4;
  122. $v_ns = escapeshellarg($v_ns);
  123. $v_time = escapeshellarg(date('H:i:s'));
  124. $v_date = escapeshellarg(date('Y-m-d'));
  125. // Create temprorary directory
  126. exec ('mktemp -d', $output, $return_var);
  127. $tmpdir = $output[0];
  128. unset($output);
  129. // Save package file on a fs
  130. $pkg = "WEB_TEMPLATE=".$v_web_template."\n";
  131. $pkg .= "PROXY_TEMPLATE=".$v_proxy_template."\n";
  132. $pkg .= "DNS_TEMPLATE=".$v_dns_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. $fp = fopen($tmpdir."/".$_POST['v_package'].".pkg", 'w');
  149. fwrite($fp, $pkg);
  150. fclose($fp);
  151. // Save changes
  152. exec (VESTA_CMD."v-add-user-package ".$tmpdir." ".$v_package." 'yes'", $output, $return_var);
  153. check_return_code($return_var,$output);
  154. unset($output);
  155. // Remove temporary dir
  156. exec ('rm -rf '.$tmpdir, $output, $return_var);
  157. unset($output);
  158. // Propogate new package
  159. exec (VESTA_CMD."v-update-user-package ".$v_package." 'json'", $output, $return_var);
  160. check_return_code($return_var,$output);
  161. unset($output);
  162. // Set success message
  163. if (empty($_SESSION['error_msg'])) {
  164. $_SESSION['ok_msg'] = __('Changes has been saved.');
  165. }
  166. }
  167. // Header
  168. include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
  169. // Panel
  170. top_panel($user,$TAB);
  171. // Display body
  172. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_package.html');
  173. // Flush session messages
  174. unset($_SESSION['error_msg']);
  175. unset($_SESSION['ok_msg']);
  176. // Footer
  177. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');