index.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <?php
  2. ob_start();
  3. $TAB = 'PACKAGE';
  4. // Main include
  5. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  6. // Check user
  7. if ($_SESSION['userContext'] != 'admin') {
  8. header("Location: /list/user");
  9. exit;
  10. }
  11. // Check POST request
  12. if (!empty($_POST['ok'])) {
  13. // Check token
  14. verify_csrf($_POST);
  15. // Check empty fields
  16. if (empty($_POST['v_package'])) {
  17. $errors[] = _('package');
  18. }
  19. if (empty($_POST['v_web_template'])) {
  20. $errors[] = _('web template');
  21. }
  22. if (!empty($_SESSION['WEB_BACKEND'])) {
  23. if (empty($_POST['v_backend_template'])) {
  24. $errors[] = _('backend template');
  25. }
  26. }
  27. if (!empty($_SESSION['PROXY_SYSTEM'])) {
  28. if (empty($_POST['v_proxy_template'])) {
  29. $errors[] = _('proxy template');
  30. }
  31. }
  32. if (empty($_POST['v_dns_template'])) {
  33. $errors[] = _('dns template');
  34. }
  35. if (empty($_POST['v_shell'])) {
  36. $errrors[] = _('shell');
  37. }
  38. if (!isset($_POST['v_web_domains'])) {
  39. $errors[] = _('web domains');
  40. }
  41. if (!isset($_POST['v_web_aliases'])) {
  42. $errors[] = _('web aliases');
  43. }
  44. if (!isset($_POST['v_dns_domains'])) {
  45. $errors[] = _('dns domains');
  46. }
  47. if (!isset($_POST['v_dns_records'])) {
  48. $errors[] = _('dns records');
  49. }
  50. if (!isset($_POST['v_mail_domains'])) {
  51. $errors[] = _('mail domains');
  52. }
  53. if (!isset($_POST['v_mail_accounts'])) {
  54. $errors[] = _('mail accounts');
  55. }
  56. if (!isset($_POST['v_databases'])) {
  57. $errors[] = _('databases');
  58. }
  59. if (!isset($_POST['v_cron_jobs'])) {
  60. $errors[] = _('cron jobs');
  61. }
  62. if (!isset($_POST['v_backups'])) {
  63. $errors[] = _('backups');
  64. }
  65. if (!isset($_POST['v_disk_quota'])) {
  66. $errors[] = _('quota');
  67. }
  68. if (!isset($_POST['v_bandwidth'])) {
  69. $errors[] = _('bandwidth');
  70. }
  71. // Check if name server entries are blank if DNS server is installed
  72. if ((isset($_SESSION['DNS_SYSTEM'])) && (!empty($_SESSION['DNS_SYSTEM']))) {
  73. if (empty($_POST['v_ns1'])) {
  74. $errors[] = _('ns1');
  75. }
  76. if (empty($_POST['v_ns2'])) {
  77. $errors[] = _('ns2');
  78. }
  79. }
  80. if (!empty($errors[0])) {
  81. foreach ($errors as $i => $error) {
  82. if ($i == 0) {
  83. $error_msg = $error;
  84. } else {
  85. $error_msg = $error_msg.", ".$error;
  86. }
  87. }
  88. $_SESSION['error_msg'] = sprintf(_('Field "%s" can not be blank.'), $error_msg);
  89. }
  90. // Protect input
  91. $v_package = escapeshellarg($_POST['v_package']);
  92. $v_web_template = escapeshellarg($_POST['v_web_template']);
  93. $v_backend_template = escapeshellarg($_POST['v_backend_template']);
  94. $v_proxy_template = escapeshellarg($_POST['v_proxy_template']);
  95. $v_dns_template = escapeshellarg($_POST['v_dns_template']);
  96. $v_shell = escapeshellarg($_POST['v_shell']);
  97. $v_web_domains = escapeshellarg($_POST['v_web_domains']);
  98. $v_web_aliases = escapeshellarg($_POST['v_web_aliases']);
  99. $v_dns_domains = escapeshellarg($_POST['v_dns_domains']);
  100. $v_dns_records = escapeshellarg($_POST['v_dns_records']);
  101. $v_mail_domains = escapeshellarg($_POST['v_mail_domains']);
  102. $v_mail_accounts = escapeshellarg($_POST['v_mail_accounts']);
  103. $v_databases = escapeshellarg($_POST['v_databases']);
  104. $v_cron_jobs = escapeshellarg($_POST['v_cron_jobs']);
  105. $v_backups = escapeshellarg($_POST['v_backups']);
  106. $v_disk_quota = escapeshellarg($_POST['v_disk_quota']);
  107. $v_bandwidth = escapeshellarg($_POST['v_bandwidth']);
  108. $v_ns1 = trim($_POST['v_ns1'], '.');
  109. $v_ns2 = trim($_POST['v_ns2'], '.');
  110. $v_ns3 = trim($_POST['v_ns3'], '.');
  111. $v_ns4 = trim($_POST['v_ns4'], '.');
  112. $v_ns5 = trim($_POST['v_ns5'], '.');
  113. $v_ns6 = trim($_POST['v_ns6'], '.');
  114. $v_ns7 = trim($_POST['v_ns7'], '.');
  115. $v_ns8 = trim($_POST['v_ns8'], '.');
  116. $v_ns = $v_ns1.",".$v_ns2;
  117. if (!empty($v_ns3)) {
  118. $v_ns .= ",".$v_ns3;
  119. }
  120. if (!empty($v_ns4)) {
  121. $v_ns .= ",".$v_ns4;
  122. }
  123. if (!empty($v_ns5)) {
  124. $v_ns .= ",".$v_ns5;
  125. }
  126. if (!empty($v_ns6)) {
  127. $v_ns .= ",".$v_ns6;
  128. }
  129. if (!empty($v_ns7)) {
  130. $v_ns .= ",".$v_ns7;
  131. }
  132. if (!empty($v_ns8)) {
  133. $v_ns .= ",".$v_ns8;
  134. }
  135. $v_ns = escapeshellarg($v_ns);
  136. $v_time = escapeshellarg(date('H:i:s'));
  137. $v_date = escapeshellarg(date('Y-m-d'));
  138. // Create package file
  139. if (empty($_SESSION['error_msg'])) {
  140. $pkg = "WEB_TEMPLATE=".$v_web_template."\n";
  141. if (!empty($_SESSION['WEB_BACKEND'])) {
  142. $pkg .= "BACKEND_TEMPLATE=".$v_backend_template."\n";
  143. }
  144. if (!empty($_SESSION['PROXY_SYSTEM'])) {
  145. $pkg .= "PROXY_TEMPLATE=".$v_proxy_template."\n";
  146. }
  147. $pkg .= "DNS_TEMPLATE=".$v_dns_template."\n";
  148. $pkg .= "WEB_DOMAINS=".$v_web_domains."\n";
  149. $pkg .= "WEB_ALIASES=".$v_web_aliases."\n";
  150. $pkg .= "DNS_DOMAINS=".$v_dns_domains."\n";
  151. $pkg .= "DNS_RECORDS=".$v_dns_records."\n";
  152. $pkg .= "MAIL_DOMAINS=".$v_mail_domains."\n";
  153. $pkg .= "MAIL_ACCOUNTS=".$v_mail_accounts."\n";
  154. $pkg .= "DATABASES=".$v_databases."\n";
  155. $pkg .= "CRON_JOBS=".$v_cron_jobs."\n";
  156. $pkg .= "DISK_QUOTA=".$v_disk_quota."\n";
  157. $pkg .= "BANDWIDTH=".$v_bandwidth."\n";
  158. $pkg .= "NS=".$v_ns."\n";
  159. $pkg .= "SHELL=".$v_shell."\n";
  160. $pkg .= "BACKUPS=".$v_backups."\n";
  161. $pkg .= "TIME=".$v_time."\n";
  162. $pkg .= "DATE=".$v_date."\n";
  163. $tmpfile = tempnam('/tmp/', 'hst_');
  164. $fp = fopen($tmpfile, 'w');
  165. fwrite($fp, $pkg);
  166. exec(HESTIA_CMD."v-add-user-package ".$tmpfile." ".$v_package, $output, $return_var);
  167. check_return_code($return_var, $output);
  168. unset($output);
  169. fclose($fp);
  170. unlink($tmpfile);
  171. }
  172. // Flush field values on success
  173. if (empty($_SESSION['error_msg'])) {
  174. $_SESSION['ok_msg'] = sprintf(_('PACKAGE_CREATED_OK'), htmlentities($_POST['v_package']), htmlentities($_POST['v_package']));
  175. unset($v_package);
  176. }
  177. }
  178. // List web temmplates
  179. exec(HESTIA_CMD."v-list-web-templates json", $output, $return_var);
  180. $web_templates = json_decode(implode('', $output), true);
  181. unset($output);
  182. // List web templates for backend
  183. if (!empty($_SESSION['WEB_BACKEND'])) {
  184. exec(HESTIA_CMD."v-list-web-templates-backend json", $output, $return_var);
  185. $backend_templates = json_decode(implode('', $output), true);
  186. unset($output);
  187. }
  188. // List web templates for proxy
  189. if (!empty($_SESSION['PROXY_SYSTEM'])) {
  190. exec(HESTIA_CMD."v-list-web-templates-proxy json", $output, $return_var);
  191. $proxy_templates = json_decode(implode('', $output), true);
  192. unset($output);
  193. }
  194. // List DNS templates
  195. exec(HESTIA_CMD."v-list-dns-templates json", $output, $return_var);
  196. $dns_templates = json_decode(implode('', $output), true);
  197. unset($output);
  198. // List system shells
  199. exec(HESTIA_CMD."v-list-sys-shells json", $output, $return_var);
  200. $shells = json_decode(implode('', $output), true);
  201. unset($output);
  202. // Set default values
  203. if (empty($v_package)) {
  204. $v_package = '';
  205. }
  206. if (empty($v_web_template)) {
  207. $v_web_template = 'default';
  208. }
  209. if (empty($v_backend_template)) {
  210. $v_backend_template = 'default';
  211. }
  212. if (empty($v_proxy_template)) {
  213. $v_proxy_template = 'default';
  214. }
  215. if (empty($v_dns_template)) {
  216. $v_dns_template = 'default';
  217. }
  218. if (empty($v_shell)) {
  219. $v_shell = 'nologin';
  220. }
  221. if (empty($v_web_domains)) {
  222. $v_web_domains = "'1'";
  223. }
  224. if (empty($v_web_aliases)) {
  225. $v_web_aliases = "'5'";
  226. }
  227. if (empty($v_dns_domains)) {
  228. $v_dns_domains = "'1'";
  229. }
  230. if (empty($v_dns_records)) {
  231. $v_dns_records = "'unlimited'";
  232. }
  233. if (empty($v_mail_domains)) {
  234. $v_mail_domains = "'1'";
  235. }
  236. if (empty($v_mail_accounts)) {
  237. $v_mail_accounts = "'5'";
  238. }
  239. if (empty($v_databases)) {
  240. $v_databases = "'1'";
  241. }
  242. if (empty($v_cron_jobs)) {
  243. $v_cron_jobs = "'1'";
  244. }
  245. if (empty($v_backups)) {
  246. $v_backups = "'1'";
  247. }
  248. if (empty($v_disk_quota)) {
  249. $v_disk_quota = "'1000'";
  250. }
  251. if (empty($v_bandwidth)) {
  252. $v_bandwidth = "'1000'";
  253. }
  254. if (empty($v_ns1)) {
  255. $v_ns1 = 'ns1.example.ltd';
  256. }
  257. if (empty($v_ns2)) {
  258. $v_ns2 = 'ns2.example.ltd';
  259. }
  260. if (empty($v_ns3)) {
  261. $v_ns3 = '';
  262. }
  263. if (empty($v_ns4)) {
  264. $v_ns4 = '';
  265. }
  266. if (empty($v_ns5)) {
  267. $v_ns5 = '';
  268. }
  269. if (empty($v_ns6)) {
  270. $v_ns6 = '';
  271. }
  272. if (empty($v_ns7)) {
  273. $v_ns7 = '';
  274. }
  275. if (empty($v_ns8)) {
  276. $v_ns8 = '';
  277. }
  278. // Render page
  279. render_page($user, $TAB, 'add_package');
  280. // Flush session messages
  281. unset($_SESSION['error_msg']);
  282. unset($_SESSION['ok_msg']);