1
0

index.php 9.5 KB

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