index.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. // Header
  9. include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
  10. // Panel
  11. top_panel($user,$TAB);
  12. $lang = 'ru_RU.utf8';
  13. setlocale(LC_ALL, $lang);
  14. // Are you admin?
  15. if ($_SESSION['user'] == 'admin') {
  16. // Check user argument?
  17. if (empty($_GET['package'])) {
  18. header("Location: /list/package/");
  19. exit;
  20. }
  21. $v_package = escapeshellarg($_GET['package']);
  22. exec (VESTA_CMD."v-list-user-package ".$v_package." 'json'", $output, $return_var);
  23. if ($return_var != 0) {
  24. $error = implode('<br>', $output);
  25. if (empty($error)) $error = _('Error: vesta did not return any output.');
  26. $_SESSION['error_msg'] = $error;
  27. } else {
  28. $data = json_decode(implode('', $output), true);
  29. unset($output);
  30. $v_package = $_GET['package'];
  31. $v_template = $data[$v_package]['TEMPLATE'];
  32. $v_web_domains = $data[$v_package]['WEB_DOMAINS'];
  33. $v_web_aliases = $data[$v_package]['WEB_ALIASES'];
  34. $v_dns_domains = $data[$v_package]['DNS_DOMAINS'];
  35. $v_dns_records = $data[$v_package]['DNS_RECORDS'];
  36. $v_mail_domains = $data[$v_package]['MAIL_DOMAINS'];
  37. $v_mail_accounts = $data[$v_package]['MAIL_ACCOUNTS'];
  38. $v_databases = $data[$v_package]['DATABASES'];
  39. $v_cron_jobs = $data[$v_package]['CRON_JOBS'];
  40. $v_disk_quota = $data[$v_package]['DISK_QUOTA'];
  41. $v_bandwidth = $data[$v_package]['BANDWIDTH'];
  42. $v_shell = $data[$v_package]['SHELL'];
  43. $v_ns = $data[$v_package]['NS'];
  44. $nameservers = explode(", ", $v_ns);
  45. $v_ns1 = $nameservers[0];
  46. $v_ns2 = $nameservers[1];
  47. $v_ns3 = $nameservers[2];
  48. $v_ns4 = $nameservers[3];
  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. exec (VESTA_CMD."v-list-web-templates json", $output, $return_var);
  54. check_error($return_var);
  55. $templates = json_decode(implode('', $output), true);
  56. unset($output);
  57. exec (VESTA_CMD."v-list-sys-shells json", $output, $return_var);
  58. check_error($return_var);
  59. $shells = json_decode(implode('', $output), true);
  60. unset($output);
  61. // Action
  62. if (!empty($_POST['save'])) {
  63. // Check input
  64. if (empty($_POST['v_package'])) $errors[] = _('package');
  65. if (empty($_POST['v_template'])) $errors[] = _('template');
  66. if (empty($_POST['v_shell'])) $errrors[] = _('shell');
  67. if (!isset($_POST['v_web_domains'])) $errors[] = _('web domains');
  68. if (!isset($_POST['v_web_aliases'])) $errors[] = _('web aliases');
  69. if (!isset($_POST['v_dns_domains'])) $errors[] = _('dns domains');
  70. if (!isset($_POST['v_dns_records'])) $errors[] = _('dns records');
  71. if (!isset($_POST['v_mail_domains'])) $errors[] = _('mail domains');
  72. if (!isset($_POST['v_mail_accounts'])) $errors[] = _('mail accounts');
  73. if (!isset($_POST['v_databases'])) $errors[] = _('databases');
  74. if (!isset($_POST['v_cron_jobs'])) $errors[] = _('cron jobs');
  75. if (!isset($_POST['v_backups'])) $errors[] = _('backups');
  76. if (!isset($_POST['v_disk_quota'])) $errors[] = _('quota');
  77. if (!isset($_POST['v_bandwidth'])) $errors[] = _('bandwidth');
  78. if (empty($_POST['v_ns1'])) $errors[] = _('ns1');
  79. if (empty($_POST['v_ns2'])) $errors[] = _('ns2');
  80. // Protect input
  81. $v_package = escapeshellarg($_POST['v_package']);
  82. $v_template = escapeshellarg($_POST['v_template']);
  83. $v_shell = escapeshellarg($_POST['v_shell']);
  84. $v_web_domains = escapeshellarg($_POST['v_web_domains']);
  85. $v_web_aliases = escapeshellarg($_POST['v_web_aliases']);
  86. $v_dns_domains = escapeshellarg($_POST['v_dns_domains']);
  87. $v_dns_records = escapeshellarg($_POST['v_dns_records']);
  88. $v_mail_domains = escapeshellarg($_POST['v_mail_domains']);
  89. $v_mail_accounts = escapeshellarg($_POST['v_mail_accounts']);
  90. $v_databases = escapeshellarg($_POST['v_databases']);
  91. $v_cron_jobs = escapeshellarg($_POST['v_cron_jobs']);
  92. $v_backups = escapeshellarg($_POST['v_backups']);
  93. $v_disk_quota = escapeshellarg($_POST['v_disk_quota']);
  94. $v_bandwidth = escapeshellarg($_POST['v_bandwidth']);
  95. $v_ns1 = trim($_POST['v_ns1'], '.');
  96. $v_ns2 = trim($_POST['v_ns2'], '.');
  97. $v_ns3 = trim($_POST['v_ns3'], '.');
  98. $v_ns4 = trim($_POST['v_ns4'], '.');
  99. $v_ns = $v_ns1.",".$v_ns2;
  100. if (!empty($v_ns3)) $v_ns .= ",".$v_ns3;
  101. if (!empty($v_ns4)) $v_ns .= ",".$v_ns4;
  102. $v_ns = escapeshellarg($v_ns);
  103. $v_time = escapeshellarg(date('H:i:s'));
  104. $v_date = escapeshellarg(date('Y-m-d'));
  105. // Check for errors
  106. if (!empty($errors[0])) {
  107. foreach ($errors as $i => $error) {
  108. if ( $i == 0 ) {
  109. $error_msg = $error;
  110. } else {
  111. $error_msg = $error_msg.", ".$error;
  112. }
  113. }
  114. $_SESSION['error_msg'] = _('Error: field "%s" can not be blank.',$error_msg);
  115. } else {
  116. exec ('mktemp -d', $output, $return_var);
  117. $tmpdir = $output[0];
  118. unset($output);
  119. // Create package
  120. $pkg = "TEMPLATE=".$v_template."\n";
  121. $pkg .= "WEB_DOMAINS=".$v_web_domains."\n";
  122. $pkg .= "WEB_ALIASES=".$v_web_aliases."\n";
  123. $pkg .= "DNS_DOMAINS=".$v_dns_domains."\n";
  124. $pkg .= "DNS_RECORDS=".$v_dns_records."\n";
  125. $pkg .= "MAIL_DOMAINS=".$v_mail_domains."\n";
  126. $pkg .= "MAIL_ACCOUNTS=".$v_mail_accounts."\n";
  127. $pkg .= "DATABASES=".$v_databases."\n";
  128. $pkg .= "CRON_JOBS=".$v_cron_jobs."\n";
  129. $pkg .= "DISK_QUOTA=".$v_disk_quota."\n";
  130. $pkg .= "BANDWIDTH=".$v_bandwidth."\n";
  131. $pkg .= "NS=".$v_ns."\n";
  132. $pkg .= "SHELL=".$v_shell."\n";
  133. $pkg .= "BACKUPS=".$v_backups."\n";
  134. $pkg .= "TIME=".$v_time."\n";
  135. $pkg .= "DATE=".$v_date."\n";
  136. // Write package
  137. $fp = fopen($tmpdir."/".$_POST['v_package'].".pkg", 'w');
  138. fwrite($fp, $pkg);
  139. fclose($fp);
  140. // Rewrite package
  141. if (empty($_SESSION['error_msg'])) {
  142. exec (VESTA_CMD."v-add-user-package ".$tmpdir." ".$v_package." 'yes'", $output, $return_var);
  143. if ($return_var != 0) {
  144. $error = implode('<br>', $output);
  145. if (empty($error)) $error = _('Error: vesta did not return any output.');
  146. $_SESSION['error_msg'] = $error;
  147. }
  148. unset($output);
  149. }
  150. // Remove tmpdir
  151. exec ('rm -rf '.$tmpdir, $output, $return_var);
  152. unset($output);
  153. // Propogate new package
  154. exec (VESTA_CMD."v-update-user-package ".$v_package." 'json'", $output, $return_var);
  155. if ($return_var != 0) {
  156. $error = implode('<br>', $output);
  157. if (empty($error)) $error = _('Error: vesta did not return any output.');
  158. $_SESSION['error_msg'] = $error;
  159. }
  160. if (empty($_SESSION['error_msg'])) {
  161. $_SESSION['ok_msg'] = _('OK: changes has been saved.');
  162. }
  163. }
  164. }
  165. }
  166. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_package.html');
  167. unset($_SESSION['error_msg']);
  168. unset($_SESSION['ok_msg']);
  169. }
  170. // Footer
  171. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');