index.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. error_reporting(NULL);
  3. ob_start();
  4. $TAB = 'PACKAGE';
  5. // Main include
  6. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  7. // Check user
  8. if ($_SESSION['user'] != 'admin') {
  9. header("Location: /list/user");
  10. exit;
  11. }
  12. // Check package argument
  13. if (empty($_GET['package'])) {
  14. header("Location: /list/package/");
  15. exit;
  16. }
  17. // List package
  18. $v_package = escapeshellarg($_GET['package']);
  19. exec (VESTA_CMD."v-list-user-package ".$v_package." json", $output, $return_var);
  20. $data = json_decode(implode('', $output), true);
  21. unset($output);
  22. // Parse package
  23. $v_package = $_GET['package'];
  24. $v_web_template = $data[$v_package]['WEB_TEMPLATE'];
  25. $v_backend_template = $data[$v_package]['BACKEND_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_ns5 = $nameservers[4];
  46. $v_ns6 = $nameservers[5];
  47. $v_ns7 = $nameservers[6];
  48. $v_ns8 = $nameservers[7];
  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. // List web templates
  54. exec (VESTA_CMD."v-list-web-templates json", $output, $return_var);
  55. $web_templates = json_decode(implode('', $output), true);
  56. unset($output);
  57. // List backend templates
  58. if (!empty($_SESSION['WEB_BACKEND'])) {
  59. exec (VESTA_CMD."v-list-web-templates-backend json", $output, $return_var);
  60. $backend_templates = json_decode(implode('', $output), true);
  61. unset($output);
  62. }
  63. // List proxy templates
  64. if (!empty($_SESSION['PROXY_SYSTEM'])) {
  65. exec (VESTA_CMD."v-list-web-templates-proxy json", $output, $return_var);
  66. $proxy_templates = json_decode(implode('', $output), true);
  67. unset($output);
  68. }
  69. // List dns templates
  70. exec (VESTA_CMD."v-list-dns-templates json", $output, $return_var);
  71. $dns_templates = json_decode(implode('', $output), true);
  72. unset($output);
  73. // List shels
  74. exec (VESTA_CMD."v-list-sys-shells json", $output, $return_var);
  75. $shells = json_decode(implode('', $output), true);
  76. unset($output);
  77. // Check POST request
  78. if (!empty($_POST['save'])) {
  79. // Check token
  80. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  81. header('location: /login/');
  82. exit();
  83. }
  84. // Check empty fields
  85. if (empty($_POST['v_package'])) $errors[] = __('package');
  86. if (empty($_POST['v_web_template'])) $errors[] = __('web template');
  87. if (!empty($_SESSION['WEB_BACKEND'])) {
  88. if (empty($_POST['v_backend_template'])) $errors[] = __('backend template');
  89. }
  90. if (!empty($_SESSION['PROXY_SYSTEM'])) {
  91. if (empty($_POST['v_proxy_template'])) $errors[] = __('proxy template');
  92. }
  93. if (empty($_POST['v_dns_template'])) $errors[] = __('dns template');
  94. if (empty($_POST['v_shell'])) $errrors[] = __('shell');
  95. if (!isset($_POST['v_web_domains'])) $errors[] = __('web domains');
  96. if (!isset($_POST['v_web_aliases'])) $errors[] = __('web aliases');
  97. if (!isset($_POST['v_dns_domains'])) $errors[] = __('dns domains');
  98. if (!isset($_POST['v_dns_records'])) $errors[] = __('dns records');
  99. if (!isset($_POST['v_mail_domains'])) $errors[] = __('mail domains');
  100. if (!isset($_POST['v_mail_accounts'])) $errors[] = __('mail accounts');
  101. if (!isset($_POST['v_databases'])) $errors[] = __('databases');
  102. if (!isset($_POST['v_cron_jobs'])) $errors[] = __('cron jobs');
  103. if (!isset($_POST['v_backups'])) $errors[] = __('backups');
  104. if (!isset($_POST['v_disk_quota'])) $errors[] = __('quota');
  105. if (!isset($_POST['v_bandwidth'])) $errors[] = __('bandwidth');
  106. if (empty($_POST['v_ns1'])) $errors[] = __('ns1');
  107. if (empty($_POST['v_ns2'])) $errors[] = __('ns2');
  108. if (!empty($errors[0])) {
  109. foreach ($errors as $i => $error) {
  110. if ( $i == 0 ) {
  111. $error_msg = $error;
  112. } else {
  113. $error_msg = $error_msg.", ".$error;
  114. }
  115. }
  116. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  117. }
  118. // Protect input
  119. $v_package = escapeshellarg($_POST['v_package']);
  120. $v_web_template = escapeshellarg($_POST['v_web_template']);
  121. if (!empty($_SESSION['WEB_BACKEND'])) {
  122. $v_backend_template = escapeshellarg($_POST['v_backend_template']);
  123. }
  124. if (!empty($_SESSION['PROXY_SYSTEM'])) {
  125. $v_proxy_template = escapeshellarg($_POST['v_proxy_template']);
  126. }
  127. $v_dns_template = escapeshellarg($_POST['v_dns_template']);
  128. $v_shell = escapeshellarg($_POST['v_shell']);
  129. $v_web_domains = escapeshellarg($_POST['v_web_domains']);
  130. $v_web_aliases = escapeshellarg($_POST['v_web_aliases']);
  131. $v_dns_domains = escapeshellarg($_POST['v_dns_domains']);
  132. $v_dns_records = escapeshellarg($_POST['v_dns_records']);
  133. $v_mail_domains = escapeshellarg($_POST['v_mail_domains']);
  134. $v_mail_accounts = escapeshellarg($_POST['v_mail_accounts']);
  135. $v_databases = escapeshellarg($_POST['v_databases']);
  136. $v_cron_jobs = escapeshellarg($_POST['v_cron_jobs']);
  137. $v_backups = escapeshellarg($_POST['v_backups']);
  138. $v_disk_quota = escapeshellarg($_POST['v_disk_quota']);
  139. $v_bandwidth = escapeshellarg($_POST['v_bandwidth']);
  140. $v_ns1 = trim($_POST['v_ns1'], '.');
  141. $v_ns2 = trim($_POST['v_ns2'], '.');
  142. $v_ns3 = trim($_POST['v_ns3'], '.');
  143. $v_ns4 = trim($_POST['v_ns4'], '.');
  144. $v_ns5 = trim($_POST['v_ns5'], '.');
  145. $v_ns6 = trim($_POST['v_ns6'], '.');
  146. $v_ns7 = trim($_POST['v_ns7'], '.');
  147. $v_ns8 = trim($_POST['v_ns8'], '.');
  148. $v_ns = $v_ns1.",".$v_ns2;
  149. if (!empty($v_ns3)) $v_ns .= ",".$v_ns3;
  150. if (!empty($v_ns4)) $v_ns .= ",".$v_ns4;
  151. if (!empty($v_ns5)) $v_ns .= ",".$v_ns5;
  152. if (!empty($v_ns6)) $v_ns .= ",".$v_ns6;
  153. if (!empty($v_ns7)) $v_ns .= ",".$v_ns7;
  154. if (!empty($v_ns8)) $v_ns .= ",".$v_ns8;
  155. $v_ns = escapeshellarg($v_ns);
  156. $v_time = escapeshellarg(date('H:i:s'));
  157. $v_date = escapeshellarg(date('Y-m-d'));
  158. // Create temprorary directory
  159. exec ('mktemp -d', $output, $return_var);
  160. $tmpdir = $output[0];
  161. unset($output);
  162. // Save package file on a fs
  163. $pkg = "WEB_TEMPLATE=".$v_web_template."\n";
  164. $pkg .= "BACKEND_TEMPLATE=".$v_backend_template."\n";
  165. $pkg .= "PROXY_TEMPLATE=".$v_proxy_template."\n";
  166. $pkg .= "DNS_TEMPLATE=".$v_dns_template."\n";
  167. $pkg .= "WEB_DOMAINS=".$v_web_domains."\n";
  168. $pkg .= "WEB_ALIASES=".$v_web_aliases."\n";
  169. $pkg .= "DNS_DOMAINS=".$v_dns_domains."\n";
  170. $pkg .= "DNS_RECORDS=".$v_dns_records."\n";
  171. $pkg .= "MAIL_DOMAINS=".$v_mail_domains."\n";
  172. $pkg .= "MAIL_ACCOUNTS=".$v_mail_accounts."\n";
  173. $pkg .= "DATABASES=".$v_databases."\n";
  174. $pkg .= "CRON_JOBS=".$v_cron_jobs."\n";
  175. $pkg .= "DISK_QUOTA=".$v_disk_quota."\n";
  176. $pkg .= "BANDWIDTH=".$v_bandwidth."\n";
  177. $pkg .= "NS=".$v_ns."\n";
  178. $pkg .= "SHELL=".$v_shell."\n";
  179. $pkg .= "BACKUPS=".$v_backups."\n";
  180. $pkg .= "TIME=".$v_time."\n";
  181. $pkg .= "DATE=".$v_date."\n";
  182. $fp = fopen($tmpdir."/".$_POST['v_package'].".pkg", 'w');
  183. fwrite($fp, $pkg);
  184. fclose($fp);
  185. // Save changes
  186. exec (VESTA_CMD."v-add-user-package ".$tmpdir." ".$v_package." yes", $output, $return_var);
  187. check_return_code($return_var,$output);
  188. unset($output);
  189. // Remove temporary dir
  190. exec ('rm -rf '.$tmpdir, $output, $return_var);
  191. unset($output);
  192. // Propogate new package
  193. exec (VESTA_CMD."v-update-user-package ".$v_package." json", $output, $return_var);
  194. check_return_code($return_var,$output);
  195. unset($output);
  196. // Set success message
  197. if (empty($_SESSION['error_msg'])) {
  198. $_SESSION['ok_msg'] = __('Changes has been saved.');
  199. }
  200. }
  201. // Render page
  202. render_page($user, $TAB, 'edit_package');
  203. // Flush session messages
  204. unset($_SESSION['error_msg']);
  205. unset($_SESSION['ok_msg']);