index.php 7.6 KB

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