index.php 9.0 KB

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