index.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 token
  77. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  78. header('location: /login/');
  79. exit();
  80. }
  81. // Check empty fields
  82. if (empty($_POST['v_package'])) $errors[] = __('package');
  83. if (empty($_POST['v_web_template'])) $errors[] = __('web template');
  84. if (!empty($_SESSION['WEB_BACKEND'])) {
  85. if (empty($_POST['v_backend_template'])) $errors[] = __('backend template');
  86. }
  87. if (!empty($_SESSION['PROXY_SYSTEM'])) {
  88. if (empty($_POST['v_proxy_template'])) $errors[] = __('proxy template');
  89. }
  90. if (empty($_POST['v_dns_template'])) $errors[] = __('dns template');
  91. if (empty($_POST['v_shell'])) $errrors[] = __('shell');
  92. if (!isset($_POST['v_web_domains'])) $errors[] = __('web domains');
  93. if (!isset($_POST['v_web_aliases'])) $errors[] = __('web aliases');
  94. if (!isset($_POST['v_dns_domains'])) $errors[] = __('dns domains');
  95. if (!isset($_POST['v_dns_records'])) $errors[] = __('dns records');
  96. if (!isset($_POST['v_mail_domains'])) $errors[] = __('mail domains');
  97. if (!isset($_POST['v_mail_accounts'])) $errors[] = __('mail accounts');
  98. if (!isset($_POST['v_databases'])) $errors[] = __('databases');
  99. if (!isset($_POST['v_cron_jobs'])) $errors[] = __('cron jobs');
  100. if (!isset($_POST['v_backups'])) $errors[] = __('backups');
  101. if (!isset($_POST['v_disk_quota'])) $errors[] = __('quota');
  102. if (!isset($_POST['v_bandwidth'])) $errors[] = __('bandwidth');
  103. if (empty($_POST['v_ns1'])) $errors[] = __('ns1');
  104. if (empty($_POST['v_ns2'])) $errors[] = __('ns2');
  105. if (!empty($errors[0])) {
  106. foreach ($errors as $i => $error) {
  107. if ( $i == 0 ) {
  108. $error_msg = $error;
  109. } else {
  110. $error_msg = $error_msg.", ".$error;
  111. }
  112. }
  113. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  114. }
  115. // Protect input
  116. $v_package = escapeshellarg($_POST['v_package']);
  117. $v_web_template = escapeshellarg($_POST['v_web_template']);
  118. if (!empty($_SESSION['WEB_BACKEND'])) {
  119. $v_backend_template = escapeshellarg($_POST['v_backend_template']);
  120. }
  121. if (!empty($_SESSION['PROXY_SYSTEM'])) {
  122. $v_proxy_template = escapeshellarg($_POST['v_proxy_template']);
  123. }
  124. $v_dns_template = escapeshellarg($_POST['v_dns_template']);
  125. $v_shell = escapeshellarg($_POST['v_shell']);
  126. $v_web_domains = escapeshellarg($_POST['v_web_domains']);
  127. $v_web_aliases = escapeshellarg($_POST['v_web_aliases']);
  128. $v_dns_domains = escapeshellarg($_POST['v_dns_domains']);
  129. $v_dns_records = escapeshellarg($_POST['v_dns_records']);
  130. $v_mail_domains = escapeshellarg($_POST['v_mail_domains']);
  131. $v_mail_accounts = escapeshellarg($_POST['v_mail_accounts']);
  132. $v_databases = escapeshellarg($_POST['v_databases']);
  133. $v_cron_jobs = escapeshellarg($_POST['v_cron_jobs']);
  134. $v_backups = escapeshellarg($_POST['v_backups']);
  135. $v_disk_quota = escapeshellarg($_POST['v_disk_quota']);
  136. $v_bandwidth = escapeshellarg($_POST['v_bandwidth']);
  137. $v_ns1 = trim($_POST['v_ns1'], '.');
  138. $v_ns2 = trim($_POST['v_ns2'], '.');
  139. $v_ns3 = trim($_POST['v_ns3'], '.');
  140. $v_ns4 = trim($_POST['v_ns4'], '.');
  141. $v_ns = $v_ns1.",".$v_ns2;
  142. if (!empty($v_ns3)) $v_ns .= ",".$v_ns3;
  143. if (!empty($v_ns4)) $v_ns .= ",".$v_ns4;
  144. $v_ns = escapeshellarg($v_ns);
  145. $v_time = escapeshellarg(date('H:i:s'));
  146. $v_date = escapeshellarg(date('Y-m-d'));
  147. // Create temprorary directory
  148. exec ('mktemp -d', $output, $return_var);
  149. $tmpdir = $output[0];
  150. unset($output);
  151. // Save package file on a fs
  152. $pkg = "WEB_TEMPLATE=".$v_web_template."\n";
  153. $pkg .= "BACKEND_TEMPLATE=".$v_backend_template."\n";
  154. $pkg .= "PROXY_TEMPLATE=".$v_proxy_template."\n";
  155. $pkg .= "DNS_TEMPLATE=".$v_dns_template."\n";
  156. $pkg .= "WEB_DOMAINS=".$v_web_domains."\n";
  157. $pkg .= "WEB_ALIASES=".$v_web_aliases."\n";
  158. $pkg .= "DNS_DOMAINS=".$v_dns_domains."\n";
  159. $pkg .= "DNS_RECORDS=".$v_dns_records."\n";
  160. $pkg .= "MAIL_DOMAINS=".$v_mail_domains."\n";
  161. $pkg .= "MAIL_ACCOUNTS=".$v_mail_accounts."\n";
  162. $pkg .= "DATABASES=".$v_databases."\n";
  163. $pkg .= "CRON_JOBS=".$v_cron_jobs."\n";
  164. $pkg .= "DISK_QUOTA=".$v_disk_quota."\n";
  165. $pkg .= "BANDWIDTH=".$v_bandwidth."\n";
  166. $pkg .= "NS=".$v_ns."\n";
  167. $pkg .= "SHELL=".$v_shell."\n";
  168. $pkg .= "BACKUPS=".$v_backups."\n";
  169. $pkg .= "TIME=".$v_time."\n";
  170. $pkg .= "DATE=".$v_date."\n";
  171. $fp = fopen($tmpdir."/".$_POST['v_package'].".pkg", 'w');
  172. fwrite($fp, $pkg);
  173. fclose($fp);
  174. // Save changes
  175. exec (VESTA_CMD."v-add-user-package ".$tmpdir." ".$v_package." 'yes'", $output, $return_var);
  176. check_return_code($return_var,$output);
  177. unset($output);
  178. // Remove temporary dir
  179. exec ('rm -rf '.$tmpdir, $output, $return_var);
  180. unset($output);
  181. // Propogate new package
  182. exec (VESTA_CMD."v-update-user-package ".$v_package." 'json'", $output, $return_var);
  183. check_return_code($return_var,$output);
  184. unset($output);
  185. // Set success message
  186. if (empty($_SESSION['error_msg'])) {
  187. $_SESSION['ok_msg'] = __('Changes has been saved.');
  188. }
  189. }
  190. // Header
  191. include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
  192. // Panel
  193. top_panel($user,$TAB);
  194. // Display body
  195. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_package.html');
  196. // Flush session messages
  197. unset($_SESSION['error_msg']);
  198. unset($_SESSION['ok_msg']);
  199. // Footer
  200. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');