index.php 7.9 KB

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