index.php 8.5 KB

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