index.php 7.4 KB

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