index.php 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777
  1. <?php
  2. use function Hestiacp\quoteshellarg\quoteshellarg;
  3. $TAB = "SERVER";
  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. // Get server hostname
  12. $v_hostname = exec("hostname");
  13. // List available timezones and get current one
  14. exec(HESTIA_CMD . "v-get-sys-timezone", $output, $return_var);
  15. $v_timezone = $output[0];
  16. unset($output);
  17. exec(HESTIA_CMD . "v-get-sys-timezones json", $output, $return_var);
  18. $v_timezones = json_decode(implode("", $output), true);
  19. unset($output);
  20. // List supported php versions
  21. exec(HESTIA_CMD . "v-list-web-templates-backend json", $output, $return_var);
  22. $backend_templates = json_decode(implode("", $output), true);
  23. unset($output);
  24. $v_php_versions = [
  25. "php-5.6",
  26. "php-7.0",
  27. "php-7.1",
  28. "php-7.2",
  29. "php-7.3",
  30. "php-7.4",
  31. "php-8.0",
  32. "php-8.1",
  33. "php-8.2",
  34. ];
  35. sort($v_php_versions);
  36. if (empty($backend_templates)) {
  37. $v_php_versions = [];
  38. }
  39. $backends_active = backendtpl_with_webdomains();
  40. $v_php_versions = array_map(function ($php_version) use ($backend_templates, $backends_active) {
  41. // Mark installed php versions
  42. if (stripos($php_version, "php") !== 0) {
  43. return false;
  44. }
  45. $phpinfo = (object) [
  46. "name" => $php_version,
  47. "tpl" => strtoupper(str_replace(".", "_", $php_version)),
  48. "version" => str_ireplace("php-", "", $php_version),
  49. "usedby" => [],
  50. "installed" => false,
  51. "protected" => false,
  52. ];
  53. if (in_array($phpinfo->tpl, $backend_templates)) {
  54. $phpinfo->installed = true;
  55. }
  56. if (array_key_exists($phpinfo->tpl, $backends_active)) {
  57. // Prevent used php version to be removed
  58. if ($phpinfo->installed) {
  59. $phpinfo->protected = true;
  60. }
  61. $phpinfo->usedby = $backends_active[$phpinfo->tpl];
  62. }
  63. if ($phpinfo->name == DEFAULT_PHP_VERSION) {
  64. // Prevent default php version to be removed
  65. if ($phpinfo->installed) {
  66. $phpinfo->protected = true;
  67. }
  68. if (!empty($backends_active["default"])) {
  69. $phpinfo->usedby = array_merge_recursive($phpinfo->usedby, $backends_active["default"]);
  70. }
  71. }
  72. return $phpinfo;
  73. }, $v_php_versions);
  74. // List languages
  75. exec(HESTIA_CMD . "v-list-sys-languages json", $output, $return_var);
  76. $language = json_decode(implode("", $output), true);
  77. foreach ($language as $lang) {
  78. $languages[$lang] = translate_json($lang);
  79. }
  80. asort($languages);
  81. unset($output);
  82. // List themes
  83. exec(HESTIA_CMD . "v-list-sys-themes json", $output, $return_var);
  84. $theme = json_decode(implode("", $output), true);
  85. unset($output);
  86. // List dns cluster hosts
  87. exec(HESTIA_CMD . "v-list-remote-dns-hosts json", $output, $return_var);
  88. $dns_cluster = json_decode(implode("", $output), true);
  89. unset($output);
  90. if (is_array($dns_cluster)) {
  91. foreach ($dns_cluster as $key => $value) {
  92. $v_dns_cluster = "yes";
  93. }
  94. }
  95. if (empty($v_dns_cluster)) {
  96. $v_dns_cluster = "";
  97. }
  98. $v_release_branch = $_SESSION["RELEASE_BRANCH"];
  99. // List smtp relay settings
  100. if (!empty($_SESSION["SMTP_RELAY"])) {
  101. $v_smtp_relay = $_SESSION["SMTP_RELAY"];
  102. } else {
  103. $v_smtp_relay = "";
  104. }
  105. if (!empty($_SESSION["SMTP_RELAY_HOST"])) {
  106. $v_smtp_relay_host = $_SESSION["SMTP_RELAY_HOST"];
  107. } else {
  108. $v_smtp_relay_host = "";
  109. }
  110. if (!empty($_SESSION["SMTP_RELAY_PORT"])) {
  111. $v_smtp_relay_port = $_SESSION["SMTP_RELAY_PORT"];
  112. } else {
  113. $v_smtp_relay_port = "";
  114. }
  115. if (!empty($_SESSION["SMTP_RELAY_USER"])) {
  116. $v_smtp_relay_user = $_SESSION["SMTP_RELAY_USER"];
  117. } else {
  118. $v_smtp_relay_user = "";
  119. }
  120. $v_smtp_relay_pass = "";
  121. if (empty($_POST["v_experimental_features"])) {
  122. $_POST["v_experimental_features"] = "false";
  123. }
  124. if (empty($_POST["v_policy_user_view_suspended"])) {
  125. $_POST["v_policy_user_view_suspended"] = "false";
  126. }
  127. // List Database hosts
  128. exec(HESTIA_CMD . "v-list-database-hosts json", $output, $return_var);
  129. $db_hosts = json_decode(implode("", $output), true);
  130. unset($output);
  131. $v_mysql_hosts = array_values(
  132. array_filter($db_hosts, function ($host) {
  133. return $host["TYPE"] === "mysql";
  134. }),
  135. );
  136. $v_mysql = count($v_mysql_hosts) ? "yes" : "no";
  137. $v_pgsql_hosts = array_values(
  138. array_filter($db_hosts, function ($host) {
  139. return $host["TYPE"] === "pgsql";
  140. }),
  141. );
  142. $v_pgsql = count($v_pgsql_hosts) ? "yes" : "no";
  143. unset($db_hosts);
  144. // List backup settings
  145. $v_backup_dir = "/backup";
  146. if (!empty($_SESSION["BACKUP"])) {
  147. $v_backup_dir = $_SESSION["BACKUP"];
  148. }
  149. $v_backup_gzip = "5";
  150. if (!empty($_SESSION["BACKUP_GZIP"])) {
  151. $v_backup_gzip = $_SESSION["BACKUP_GZIP"];
  152. }
  153. $v_backup_mode = "gzip";
  154. if (!empty($_SESSION["BACKUP_MODE"])) {
  155. $v_backup_mode = $_SESSION["BACKUP_MODE"];
  156. }
  157. $backup_types = explode(",", $_SESSION["BACKUP_SYSTEM"]);
  158. foreach ($backup_types as $backup_type) {
  159. if ($backup_type == "local") {
  160. $v_backup = "yes";
  161. } else {
  162. exec(
  163. HESTIA_CMD . "v-list-backup-host " . quoteshellarg($backup_type) . " json",
  164. $output,
  165. $return_var,
  166. );
  167. $v_remote_backup = json_decode(implode("", $output), true);
  168. unset($output);
  169. if (in_array($backup_type, ["ftp", "sftp"])) {
  170. $v_backup_host = $v_remote_backup[$backup_type]["HOST"];
  171. $v_backup_type = $v_remote_backup[$backup_type]["TYPE"];
  172. $v_backup_username = $v_remote_backup[$backup_type]["USERNAME"] ?? "";
  173. $v_backup_password = "";
  174. $v_backup_port = $v_remote_backup[$backup_type]["PORT"] ?? "";
  175. $v_backup_bpath = $v_remote_backup[$backup_type]["BPATH"];
  176. $v_backup_remote_adv = "yes";
  177. } elseif (in_array($backup_type, ["b2"])) {
  178. $v_backup_bucket = $v_remote_backup[$backup_type]["BUCKET"];
  179. $v_backup_type = $v_remote_backup[$backup_type]["TYPE"];
  180. $v_backup_application_id = $v_remote_backup[$backup_type]["B2_KEY_ID"];
  181. $v_backup_application_key = "";
  182. $v_backup_remote_adv = "yes";
  183. } elseif (in_array($backup_type, ["rclone"])) {
  184. $v_backup_type = $v_remote_backup[$backup_type]["TYPE"];
  185. $v_rclone_host = $v_remote_backup[$backup_type]["HOST"];
  186. $v_rclone_path = $v_remote_backup[$backup_type]["BPATH"];
  187. $v_backup_remote_adv = "yes";
  188. }
  189. }
  190. }
  191. if (empty($v_backup)) {
  192. $v_backup = "";
  193. }
  194. if (empty($v_backup_host)) {
  195. $v_backup_host = "";
  196. }
  197. if (empty($v_backup_type)) {
  198. $v_backup_type = "";
  199. }
  200. if (empty($v_backup_username)) {
  201. $v_backup_username = "";
  202. }
  203. if (empty($v_backup_password)) {
  204. $v_backup_password = "";
  205. }
  206. if (empty($v_backup_port)) {
  207. $v_backup_port = "";
  208. }
  209. if (empty($v_backup_bpath)) {
  210. $v_backup_bpath = "";
  211. }
  212. if (empty($v_backup_bucket)) {
  213. $v_backup_bucket = "";
  214. }
  215. if (empty($v_backup_application_id)) {
  216. $v_backup_application_id = "";
  217. }
  218. if (empty($v_backup_application_key)) {
  219. $v_backup_application_key = "";
  220. }
  221. if (empty($v_backup_remote_adv)) {
  222. $v_backup_remote_adv = "";
  223. }
  224. if (empty($v_rclone_host)) {
  225. $v_rclone_host = "";
  226. }
  227. if (empty($v_rclone_path)) {
  228. $v_rclone_path = "";
  229. }
  230. // List ssl certificate info
  231. exec(HESTIA_CMD . "v-list-sys-hestia-ssl json", $output, $return_var);
  232. $ssl_str = json_decode(implode("", $output), true);
  233. unset($output);
  234. $v_ssl_crt = $ssl_str["HESTIA"]["CRT"];
  235. $v_ssl_key = $ssl_str["HESTIA"]["KEY"];
  236. $v_ssl_ca = $ssl_str["HESTIA"]["CA"];
  237. $v_ssl_subject = $ssl_str["HESTIA"]["SUBJECT"];
  238. $v_ssl_aliases = $ssl_str["HESTIA"]["ALIASES"];
  239. $v_ssl_not_before = $ssl_str["HESTIA"]["NOT_BEFORE"];
  240. $v_ssl_not_after = $ssl_str["HESTIA"]["NOT_AFTER"];
  241. $v_ssl_signature = $ssl_str["HESTIA"]["SIGNATURE"];
  242. $v_ssl_pub_key = $ssl_str["HESTIA"]["PUB_KEY"];
  243. $v_ssl_issuer = $ssl_str["HESTIA"]["ISSUER"];
  244. // Check POST request
  245. if (!empty($_POST["save"])) {
  246. $require_refresh = false;
  247. // Check token
  248. verify_csrf($_POST);
  249. // Change hostname
  250. if (!empty($_POST["v_hostname"]) && $v_hostname != $_POST["v_hostname"]) {
  251. exec(
  252. HESTIA_CMD . "v-change-sys-hostname " . quoteshellarg($_POST["v_hostname"]),
  253. $output,
  254. $return_var,
  255. );
  256. check_return_code($return_var, $output);
  257. unset($output);
  258. $v_hostname = $_POST["v_hostname"];
  259. }
  260. if ($_SESSION["WEB_BACKEND"] == "php-fpm") {
  261. // Install/remove php versions
  262. if (empty($_SESSION["error_msg"])) {
  263. if (!empty($v_php_versions)) {
  264. if (!empty($_POST["v_php_versions"])) {
  265. $post_php = $_POST["v_php_versions"];
  266. }
  267. if (empty($post_php)) {
  268. $post_php = [];
  269. }
  270. array_map(function ($php_version) use ($post_php) {
  271. if (array_key_exists($php_version->tpl, $post_php)) {
  272. if (!$php_version->installed) {
  273. exec(
  274. HESTIA_CMD .
  275. "v-add-web-php " .
  276. quoteshellarg($php_version->version),
  277. $output,
  278. $return_var,
  279. );
  280. check_return_code($return_var, $output);
  281. unset($output);
  282. if (empty($_SESSION["error_msg"])) {
  283. $php_version->installed = true;
  284. }
  285. }
  286. } else {
  287. if ($php_version->installed && !$php_version->protected) {
  288. exec(
  289. HESTIA_CMD .
  290. "v-delete-web-php " .
  291. quoteshellarg($php_version->version),
  292. $output,
  293. $return_var,
  294. );
  295. check_return_code($return_var, $output);
  296. unset($output);
  297. if (empty($_SESSION["error_msg"])) {
  298. $php_version->installed = false;
  299. }
  300. }
  301. }
  302. return $php_version;
  303. }, $v_php_versions);
  304. }
  305. }
  306. if (empty($_SESSION["error_msg"])) {
  307. if ("php-" . $_POST["v_php_default_version"] != DEFAULT_PHP_VERSION) {
  308. exec(
  309. HESTIA_CMD .
  310. "v-change-sys-php " .
  311. quoteshellarg($_POST["v_php_default_version"]),
  312. $output,
  313. $return_var,
  314. );
  315. check_return_code($return_var, $output);
  316. unset($output);
  317. //force reload
  318. $require_refresh = true;
  319. }
  320. }
  321. }
  322. // Change timezone
  323. if (empty($_SESSION["error_msg"])) {
  324. if (!empty($_POST["v_timezone"])) {
  325. if ($v_timezone != $_POST["v_timezone"]) {
  326. exec(
  327. HESTIA_CMD . "v-change-sys-timezone " . quoteshellarg($_POST["v_timezone"]),
  328. $output,
  329. $return_var,
  330. );
  331. check_return_code($return_var, $output);
  332. $v_timezone = $_POST["v_timezone"];
  333. unset($output);
  334. }
  335. }
  336. }
  337. // Change default language
  338. if (empty($_SESSION["error_msg"])) {
  339. if (!empty($_POST["v_language"]) && $_SESSION["LANGUAGE"] != $_POST["v_language"]) {
  340. if (isset($_POST["v_language_update"])) {
  341. exec(
  342. HESTIA_CMD .
  343. "v-change-sys-language " .
  344. quoteshellarg($_POST["v_language"]) .
  345. " yes",
  346. $output,
  347. $return_var,
  348. );
  349. if (empty($_SESSION["error_msg"])) {
  350. $_SESSION["LANGUAGE"] = $_POST["v_language"];
  351. }
  352. }
  353. exec(
  354. HESTIA_CMD . "v-change-sys-language " . quoteshellarg($_POST["v_language"]),
  355. $output,
  356. $return_var,
  357. );
  358. check_return_code($return_var, $output);
  359. unset($output);
  360. if (empty($_SESSION["error_msg"])) {
  361. $_SESSION["LANGUAGE"] = $_POST["v_language"];
  362. }
  363. }
  364. }
  365. // Update theme
  366. if (empty($_SESSION["error_msg"])) {
  367. if ($_POST["v_theme"] != $_SESSION["THEME"]) {
  368. exec(
  369. HESTIA_CMD . "v-change-sys-config-value THEME " . quoteshellarg($_POST["v_theme"]),
  370. $output,
  371. $return_var,
  372. );
  373. check_return_code($return_var, $output);
  374. unset($output);
  375. }
  376. }
  377. // Update debug mode status
  378. if (empty($_SESSION["error_msg"])) {
  379. if (!empty($_POST["v_debug_mode"])) {
  380. if ($_POST["v_debug_mode"] == "on") {
  381. $_POST["v_debug_mode"] = "true";
  382. } else {
  383. $_POST["v_debug_mode"] = "false";
  384. }
  385. } else {
  386. $_POST["v_debug_mode"] = "false";
  387. }
  388. if ($_POST["v_debug_mode"] != $_SESSION["DEBUG_MODE"]) {
  389. exec(
  390. HESTIA_CMD .
  391. "v-change-sys-config-value DEBUG_MODE " .
  392. quoteshellarg($_POST["v_debug_mode"]),
  393. $output,
  394. $return_var,
  395. );
  396. check_return_code($return_var, $output);
  397. unset($output);
  398. $v_debug_mode_adv = "yes";
  399. }
  400. }
  401. // Enable/Disable Quick App Installer
  402. if (empty($_SESSION["error_msg"])) {
  403. if ($_POST["v_plugin_app_installer"] != $_SESSION["PLUGIN_APP_INSTALLER"]) {
  404. if ($_POST["v_plugin_app_installer"] == "true") {
  405. $_POST["v_plugin_app_installer"] = "true";
  406. } else {
  407. $_POST["v_plugin_app_installer"] = "false";
  408. }
  409. exec(
  410. HESTIA_CMD .
  411. "v-change-sys-config-value PLUGIN_APP_INSTALLER " .
  412. quoteshellarg($_POST["v_plugin_app_installer"]),
  413. $output,
  414. $return_var,
  415. );
  416. check_return_code($return_var, $output);
  417. unset($output);
  418. }
  419. }
  420. // Update experimental features status
  421. if (
  422. empty($_SESSION["error_msg"]) &&
  423. $_POST["v_experimental_features"] != $_SESSION["POLICY_SYSTEM_ENABLE_BACON"]
  424. ) {
  425. if ($_POST["v_experimental_features"] == "on") {
  426. $_POST["v_experimental_features"] = "true";
  427. } else {
  428. $_POST["v_experimental_features"] = "false";
  429. }
  430. if ($_POST["v_experimental_features"] != $_SESSION["POLICY_SYSTEM_ENABLE_BACON"]) {
  431. exec(
  432. HESTIA_CMD .
  433. "v-change-sys-config-value POLICY_SYSTEM_ENABLE_BACON " .
  434. quoteshellarg($_POST["v_experimental_features"]),
  435. $output,
  436. $return_var,
  437. );
  438. check_return_code($return_var, $output);
  439. unset($output);
  440. $v_debug_mode_adv = "yes";
  441. }
  442. if (
  443. $_POST["v_policy_user_view_suspended"] != $_SESSION["POLICY_SYSTEM_ENABLE_BACON"] &&
  444. $_POST["v_experimental_features"] == "false"
  445. ) {
  446. //disable preview mode
  447. exec(
  448. HESTIA_CMD .
  449. "v-change-sys-config-value POLICY_USER_VIEW_SUSPENDED " .
  450. quoteshellarg($_POST["v_policy_user_view_suspended"]),
  451. $output,
  452. $return_var,
  453. );
  454. check_return_code($return_var, $output);
  455. unset($output);
  456. }
  457. }
  458. // Set File Manager support
  459. if (empty($_SESSION["error_msg"])) {
  460. if (
  461. !empty($_POST["v_filemanager"]) &&
  462. $_SESSION["FILE_MANAGER"] != $_POST["v_filemanager"]
  463. ) {
  464. if ($_POST["v_filemanager"] == "true") {
  465. exec(HESTIA_CMD . "v-add-sys-filemanager", $output, $return_var);
  466. check_return_code($return_var, $output);
  467. unset($output);
  468. if (empty($_SESSION["error_msg"])) {
  469. $_SESSION["FILE_MANAGER"] = "true";
  470. }
  471. } else {
  472. exec(HESTIA_CMD . "v-delete-sys-filemanager", $output, $return_var);
  473. check_return_code($return_var, $output);
  474. unset($output);
  475. if (empty($_SESSION["error_msg"])) {
  476. $_SESSION["FILE_MANAGER"] = "false";
  477. }
  478. }
  479. }
  480. }
  481. // Set Web Terminal support
  482. if (empty($_SESSION["error_msg"])) {
  483. if (
  484. !empty($_POST["v_web_terminal"]) &&
  485. $_SESSION["WEB_TERMINAL"] != $_POST["v_web_terminal"]
  486. ) {
  487. if ($_POST["v_web_terminal"] == "true") {
  488. exec(HESTIA_CMD . "v-add-sys-web-terminal", $output, $return_var);
  489. check_return_code($return_var, $output);
  490. unset($output);
  491. if (empty($_SESSION["error_msg"])) {
  492. $_SESSION["WEB_TERMINAL"] = "true";
  493. }
  494. } else {
  495. exec(HESTIA_CMD . "v-delete-sys-web-terminal", $output, $return_var);
  496. check_return_code($return_var, $output);
  497. unset($output);
  498. if (empty($_SESSION["error_msg"])) {
  499. $_SESSION["WEB_TERMINAL"] = "false";
  500. }
  501. }
  502. }
  503. }
  504. // Set phpMyAdmin SSO key
  505. if (empty($_SESSION["error_msg"])) {
  506. if (!empty($_POST["v_phpmyadmin_key"])) {
  507. if ($_POST["v_phpmyadmin_key"] == "yes" && $_SESSION["PHPMYADMIN_KEY"] == "") {
  508. exec(HESTIA_CMD . "v-add-sys-pma-sso quiet", $output, $return_var);
  509. check_return_code($return_var, $output);
  510. unset($output);
  511. if (empty($_SESSION["error_msg"])) {
  512. $_SESSION["PHPMYADMIN_KEY"] != "";
  513. }
  514. } elseif ($_POST["v_phpmyadmin_key"] == "no" && $_SESSION["PHPMYADMIN_KEY"] != "") {
  515. exec(HESTIA_CMD . "v-delete-sys-pma-sso quiet", $output, $return_var);
  516. check_return_code($return_var, $output);
  517. unset($output);
  518. if (empty($_SESSION["error_msg"])) {
  519. $_SESSION["PHPMYADMIN_KEY"] = "";
  520. }
  521. }
  522. }
  523. }
  524. // Set disk_quota support
  525. if (empty($_SESSION["error_msg"])) {
  526. if (!empty($_POST["v_quota"]) && $_SESSION["DISK_QUOTA"] != $_POST["v_quota"]) {
  527. if ($_POST["v_quota"] == "yes") {
  528. exec(HESTIA_CMD . "v-add-sys-quota", $output, $return_var);
  529. check_return_code($return_var, $output);
  530. unset($output);
  531. if (empty($_SESSION["error_msg"])) {
  532. $_SESSION["DISK_QUOTA"] = "yes";
  533. }
  534. } else {
  535. exec(HESTIA_CMD . "v-delete-sys-quota", $output, $return_var);
  536. check_return_code($return_var, $output);
  537. unset($output);
  538. if (empty($_SESSION["error_msg"])) {
  539. $_SESSION["DISK_QUOTA"] = "no";
  540. }
  541. }
  542. }
  543. }
  544. // Set firewall support
  545. if (empty($_SESSION["error_msg"])) {
  546. if ($_SESSION["FIREWALL_SYSTEM"] == "iptables") {
  547. $v_firewall = "yes";
  548. }
  549. if ($_SESSION["FIREWALL_SYSTEM"] != "iptables") {
  550. $v_firewall = "no";
  551. }
  552. if (!empty($_POST["v_firewall"]) && $v_firewall != $_POST["v_firewall"]) {
  553. if ($_POST["v_firewall"] == "yes") {
  554. exec(HESTIA_CMD . "v-add-sys-firewall", $output, $return_var);
  555. check_return_code($return_var, $output);
  556. unset($output);
  557. if (empty($_SESSION["error_msg"])) {
  558. $_SESSION["FIREWALL_SYSTEM"] = "iptables";
  559. }
  560. } else {
  561. exec(HESTIA_CMD . "v-delete-sys-firewall", $output, $return_var);
  562. check_return_code($return_var, $output);
  563. unset($output);
  564. if (empty($_SESSION["error_msg"])) {
  565. $_SESSION["FIREWALL_SYSTEM"] = "";
  566. }
  567. }
  568. }
  569. }
  570. // Update mysql pasword
  571. if (empty($_SESSION["error_msg"])) {
  572. if (!empty($_POST["v_mysql_password"])) {
  573. exec(
  574. HESTIA_CMD .
  575. "v-change-database-host-password mysql localhost root " .
  576. quoteshellarg($_POST["v_mysql_password"]),
  577. $output,
  578. $return_var,
  579. );
  580. check_return_code($return_var, $output);
  581. unset($output);
  582. $v_db_adv = "yes";
  583. }
  584. }
  585. if (!empty($_SESSION["MAIL_SYSTEM"])) {
  586. // Update webmail url
  587. if (empty($_SESSION["error_msg"])) {
  588. if ($_SESSION["WEBMAIL_SYSTEM"] != "") {
  589. if ($_POST["v_webmail_alias"] != $_SESSION["WEBMAIL_ALIAS"]) {
  590. exec(
  591. HESTIA_CMD .
  592. "v-change-sys-webmail " .
  593. quoteshellarg($_POST["v_webmail_alias"]),
  594. $output,
  595. $return_var,
  596. );
  597. check_return_code($return_var, $output);
  598. unset($output);
  599. $v_mail_adv = "yes";
  600. }
  601. }
  602. }
  603. }
  604. // Update system wide smtp relay
  605. if (empty($_SESSION["error_msg"])) {
  606. if (isset($_POST["v_smtp_relay"]) && !empty($_POST["v_smtp_relay_host"])) {
  607. if (
  608. $_POST["v_smtp_relay_host"] != $v_smtp_relay_host ||
  609. $_POST["v_smtp_relay_user"] != $v_smtp_relay_user ||
  610. $_POST["v_smtp_relay_port"] != $v_smtp_relay_port ||
  611. !empty($_POST["v_smtp_relay_pass"])
  612. ) {
  613. $v_smtp_relay = true;
  614. $v_smtp_relay_host = quoteshellarg($_POST["v_smtp_relay_host"]);
  615. $v_smtp_relay_user = quoteshellarg($_POST["v_smtp_relay_user"]);
  616. $v_smtp_relay_pass = quoteshellarg($_POST["v_smtp_relay_pass"]);
  617. if (!empty($_POST["v_smtp_relay_port"])) {
  618. $v_smtp_relay_port = quoteshellarg($_POST["v_smtp_relay_port"]);
  619. } else {
  620. $v_smtp_relay_port = "587";
  621. }
  622. exec(
  623. HESTIA_CMD .
  624. "v-add-sys-smtp-relay " .
  625. $v_smtp_relay_host .
  626. " " .
  627. $v_smtp_relay_user .
  628. " " .
  629. $v_smtp_relay_pass .
  630. " " .
  631. $v_smtp_relay_port,
  632. $output,
  633. $return_var,
  634. );
  635. check_return_code($return_var, $output);
  636. unset($output);
  637. }
  638. }
  639. if (!isset($_POST["v_smtp_relay"]) && $v_smtp_relay == true) {
  640. $v_smtp_relay = false;
  641. $v_smtp_relay_host = $v_smtp_relay_user = $v_smtp_relay_pass = $v_smtp_relay_port = "";
  642. exec(HESTIA_CMD . "v-delete-sys-smtp-relay", $output, $return_var);
  643. check_return_code($return_var, $output);
  644. unset($output);
  645. }
  646. }
  647. // Update phpMyAdmin url
  648. if (empty($_SESSION["error_msg"])) {
  649. if ($_POST["v_mysql_url"] != $_SESSION["DB_PMA_ALIAS"]) {
  650. exec(
  651. HESTIA_CMD . "v-change-sys-db-alias pma " . quoteshellarg($_POST["v_mysql_url"]),
  652. $output,
  653. $return_var,
  654. );
  655. check_return_code($return_var, $output);
  656. unset($output);
  657. $v_db_adv = "yes";
  658. }
  659. }
  660. // Update phpPgAdmin url
  661. if (empty($_SESSION["error_msg"])) {
  662. if (empty($_POST["v_pgsql_url"])) {
  663. $_POST["v_pgsql_url"] = "";
  664. }
  665. if ($_POST["v_pgsql_url"] != $_SESSION["DB_PGA_ALIAS"]) {
  666. exec(
  667. HESTIA_CMD . "v-change-sys-db-alias pga " . quoteshellarg($_POST["v_pgsql_url"]),
  668. $output,
  669. $return_var,
  670. );
  671. check_return_code($return_var, $output);
  672. unset($output);
  673. $v_db_adv = "yes";
  674. }
  675. }
  676. // Update send notification setting
  677. if (empty($_SESSION["error_msg"])) {
  678. if ($_SESSION["UPGRADE_SEND_EMAIL"] == "true") {
  679. $ugrade_send_mail = "on";
  680. } else {
  681. $ugrade_send_mail = "";
  682. }
  683. if (empty($_POST["v_upgrade_send_notification_email"])) {
  684. $_POST["v_upgrade_send_notification_email"] = "";
  685. }
  686. if ($_POST["v_upgrade_send_notification_email"] != $ugrade_send_mail) {
  687. if ($_POST["v_upgrade_send_notification_email"] == "on") {
  688. $_POST["v_upgrade_send_notification_email"] = "true";
  689. } else {
  690. $_POST["v_upgrade_send_notification_email"] = "false";
  691. }
  692. exec(
  693. HESTIA_CMD .
  694. "v-change-sys-config-value UPGRADE_SEND_EMAIL " .
  695. quoteshellarg($_POST["v_upgrade_send_notification_email"]),
  696. $output,
  697. $return_var,
  698. );
  699. check_return_code($return_var, $output);
  700. unset($output);
  701. $v_upgrade_notification_adv = "yes";
  702. }
  703. }
  704. // Update send log by email setting
  705. if (empty($_SESSION["error_msg"])) {
  706. if ($_SESSION["UPGRADE_SEND_EMAIL_LOG"] == "true") {
  707. $send_email_log = "on";
  708. } else {
  709. $send_email_log = "";
  710. }
  711. if (empty($_POST["v_upgrade_send_email_log"])) {
  712. $_POST["v_upgrade_send_email_log"] = "";
  713. }
  714. if ($_POST["v_upgrade_send_email_log"] != $send_email_log) {
  715. if ($_POST["v_upgrade_send_email_log"] == "on") {
  716. $_POST["v_upgrade_send_email_log"] = "true";
  717. } else {
  718. $_POST["v_upgrade_send_email_log"] = "false";
  719. }
  720. exec(
  721. HESTIA_CMD .
  722. "v-change-sys-config-value UPGRADE_SEND_EMAIL_LOG " .
  723. quoteshellarg($_POST["v_upgrade_send_email_log"]),
  724. $output,
  725. $return_var,
  726. );
  727. check_return_code($return_var, $output);
  728. unset($output);
  729. $v_upgrade_send_log_adv = "yes";
  730. }
  731. }
  732. // Disable local backup
  733. if (empty($_SESSION["error_msg"])) {
  734. if ($_POST["v_backup"] == "no" && $v_backup == "yes") {
  735. exec(HESTIA_CMD . "v-delete-backup-host local", $output, $return_var);
  736. check_return_code($return_var, $output);
  737. unset($output);
  738. if (empty($_SESSION["error_msg"])) {
  739. $v_backup = "no";
  740. }
  741. $v_backup_adv = "yes";
  742. }
  743. }
  744. // Enable local backups
  745. if (empty($_SESSION["error_msg"])) {
  746. if ($_POST["v_backup"] == "yes" && $v_backup != "yes") {
  747. exec(HESTIA_CMD . "v-add-backup-host local", $output, $return_var);
  748. check_return_code($return_var, $output);
  749. unset($output);
  750. if (empty($_SESSION["error_msg"])) {
  751. $v_backup = "yes";
  752. }
  753. $v_backup_adv = "yes";
  754. }
  755. }
  756. // Change backup gzip level
  757. if (empty($_SESSION["error_msg"])) {
  758. if ($_POST["v_backup_gzip"] != $v_backup_gzip) {
  759. if ($_POST["v_backup_mode"] == "gzip") {
  760. $_POST["v_backup_gzip"] = 9;
  761. }
  762. exec(
  763. HESTIA_CMD .
  764. "v-change-sys-config-value BACKUP_GZIP " .
  765. quoteshellarg($_POST["v_backup_gzip"]),
  766. $output,
  767. $return_var,
  768. );
  769. check_return_code($return_var, $output);
  770. unset($output);
  771. if (empty($_SESSION["error_msg"])) {
  772. $v_backup_gzip = $_POST["v_backup_gzip"];
  773. }
  774. $v_backup_adv = "yes";
  775. }
  776. }
  777. // Change backup mode
  778. if (empty($_SESSION["error_msg"])) {
  779. if ($_POST["v_backup_mode"] != $v_backup_mode) {
  780. exec(
  781. HESTIA_CMD .
  782. "v-change-sys-config-value BACKUP_MODE " .
  783. quoteshellarg($_POST["v_backup_mode"]),
  784. $output,
  785. $return_var,
  786. );
  787. check_return_code($return_var, $output);
  788. unset($output);
  789. if (empty($_SESSION["error_msg"])) {
  790. $v_backup_mode = $_POST["v_backup_mode"];
  791. }
  792. $v_backup_adv = "yes";
  793. if ($_POST["v_backup_mode"] == "gzip") {
  794. $_POST["v_backup_gzip"] = 9;
  795. if (empty($_SESSION["error_msg"])) {
  796. $v_backup_gzip = $_POST["v_backup_gzip"];
  797. }
  798. exec(
  799. HESTIA_CMD .
  800. "v-change-sys-config-value BACKUP_GZIP " .
  801. quoteshellarg($_POST["v_backup_gzip"]),
  802. $output,
  803. $return_var,
  804. );
  805. }
  806. }
  807. }
  808. // Change backup path
  809. if (empty($_SESSION["error_msg"])) {
  810. if (empty($_POST["v_backup_dir"])) {
  811. $_POST["v_backup_dir"] = "";
  812. }
  813. if ($_POST["v_backup_dir"] != $v_backup_dir) {
  814. /*
  815. See #1655
  816. exec (HESTIA_CMD."v-change-sys-config-value BACKUP ".quoteshellarg($_POST['v_backup_dir']), $output, $return_var);
  817. check_return_code($return_var,$output);
  818. unset($output);
  819. */
  820. if (empty($_SESSION["error_msg"])) {
  821. $v_backup_dir = $_POST["v_backup_dir"];
  822. }
  823. #$v_backup_adv = 'yes';
  824. }
  825. }
  826. // Add remote backup host
  827. if (empty($_SESSION["error_msg"])) {
  828. if (
  829. $v_backup_host == "" &&
  830. $v_backup_bucket == "" &&
  831. (!empty($_POST["v_backup_host"]) || !empty($_POST["v_backup_bucket"]))
  832. ) {
  833. if (in_array($_POST["v_backup_type"], ["ftp", "sftp"])) {
  834. $v_backup_host = quoteshellarg($_POST["v_backup_host"]);
  835. $v_backup_port = quoteshellarg($_POST["v_backup_port"]);
  836. $v_backup_type = quoteshellarg($_POST["v_backup_type"]);
  837. $v_backup_username = quoteshellarg($_POST["v_backup_username"]);
  838. $v_backup_password = quoteshellarg($_POST["v_backup_password"]);
  839. $v_backup_bpath = quoteshellarg($_POST["v_backup_bpath"]);
  840. exec(
  841. HESTIA_CMD .
  842. "v-add-backup-host " .
  843. $v_backup_type .
  844. " " .
  845. $v_backup_host .
  846. " " .
  847. $v_backup_username .
  848. " " .
  849. $v_backup_password .
  850. " " .
  851. $v_backup_bpath .
  852. " " .
  853. $v_backup_port,
  854. $output,
  855. $return_var,
  856. );
  857. check_return_code($return_var, $output);
  858. unset($output);
  859. if (empty($_SESSION["error_msg"])) {
  860. $v_backup_host = $_POST["v_backup_host"];
  861. }
  862. if (empty($_SESSION["error_msg"])) {
  863. $v_backup_type = $_POST["v_backup_type"];
  864. }
  865. if (empty($_SESSION["error_msg"])) {
  866. $v_backup_username = $_POST["v_backup_username"];
  867. }
  868. if (empty($_SESSION["error_msg"])) {
  869. $v_backup_password = $_POST["v_backup_password"];
  870. }
  871. if (empty($_SESSION["error_msg"])) {
  872. $v_backup_bpath = $_POST["v_backup_bpath"];
  873. }
  874. if (empty($_SESSION["error_msg"])) {
  875. $v_backup_port = $_POST["v_backup_port"];
  876. }
  877. $v_backup_new = "yes";
  878. $v_backup_adv = "yes";
  879. $v_backup_remote_adv = "yes";
  880. } elseif (in_array($_POST["v_backup_type"], ["b2"])) {
  881. $v_backup_type = quoteshellarg($_POST["v_backup_type"]);
  882. $v_backup_bucket = quoteshellarg($_POST["v_backup_bucket"]);
  883. $v_backup_application_id = quoteshellarg($_POST["v_backup_application_id"]);
  884. $v_backup_application_key = quoteshellarg($_POST["v_backup_application_key"]);
  885. exec(
  886. HESTIA_CMD .
  887. "v-add-backup-host " .
  888. $v_backup_type .
  889. " " .
  890. $v_backup_bucket .
  891. " " .
  892. $v_backup_application_id .
  893. " " .
  894. $v_backup_application_key,
  895. $output,
  896. $return_var,
  897. );
  898. check_return_code($return_var, $output);
  899. unset($output);
  900. if (empty($_SESSION["error_msg"])) {
  901. $v_backup_bucket = quoteshellarg($_POST["v_backup_bucket"]);
  902. }
  903. if (empty($_SESSION["error_msg"])) {
  904. $v_backup_application_id = quoteshellarg($_POST["v_backup_application_id"]);
  905. }
  906. if (empty($_SESSION["error_msg"])) {
  907. $v_backup_application_key = quoteshellarg($_POST["v_backup_application_key"]);
  908. }
  909. $v_backup_new = "yes";
  910. $v_backup_adv = "yes";
  911. $v_backup_remote_adv = "yes";
  912. }
  913. }
  914. if (
  915. $v_rclone_host == "" &&
  916. !empty($_POST["v_rclone_host"]) &&
  917. $_POST["v_backup_type"] == "rclone"
  918. ) {
  919. $v_rclone_host = quoteshellarg($_POST["v_rclone_host"]);
  920. $v_backup_type = quoteshellarg($_POST["v_backup_type"]);
  921. $v_rclone_path = quoteshellarg($_POST["v_rclone_path"]);
  922. exec(
  923. HESTIA_CMD .
  924. "v-add-backup-host " .
  925. $v_backup_type .
  926. " " .
  927. $v_rclone_host .
  928. " '' '' " .
  929. $v_rclone_path,
  930. $output,
  931. $return_var,
  932. );
  933. check_return_code($return_var, $output);
  934. unset($output);
  935. $v_backup_new = "yes";
  936. $v_backup_adv = "yes";
  937. $v_backup_remote_adv = "yes";
  938. }
  939. }
  940. // Change remote backup host type
  941. if (empty($_SESSION["error_msg"])) {
  942. if (
  943. !empty($_POST["v_backup_host"]) &&
  944. $_POST["v_backup_type"] != $v_backup_type &&
  945. $v_backup_type != ""
  946. ) {
  947. exec(
  948. HESTIA_CMD . "v-delete-backup-host " . quoteshellarg($v_backup_type),
  949. $output,
  950. $return_var,
  951. );
  952. unset($output);
  953. if (in_array($_POST["v_backup_type"], ["ftp", "sftp"])) {
  954. $v_backup_host = quoteshellarg($_POST["v_backup_host"]);
  955. $v_backup_port = quoteshellarg($_POST["v_backup_port"]);
  956. $v_backup_type = quoteshellarg($_POST["v_backup_type"]);
  957. $v_backup_username = quoteshellarg($_POST["v_backup_username"]);
  958. $v_backup_password = quoteshellarg($_POST["v_backup_password"]);
  959. $v_backup_bpath = quoteshellarg($_POST["v_backup_bpath"]);
  960. exec(
  961. HESTIA_CMD .
  962. "v-add-backup-host " .
  963. $v_backup_type .
  964. " " .
  965. $v_backup_host .
  966. " " .
  967. $v_backup_username .
  968. " " .
  969. $v_backup_password .
  970. " " .
  971. $v_backup_bpath .
  972. " " .
  973. $v_backup_port,
  974. $output,
  975. $return_var,
  976. );
  977. check_return_code($return_var, $output);
  978. unset($output);
  979. if (empty($_SESSION["error_msg"])) {
  980. $v_backup_host = $_POST["v_backup_host"];
  981. }
  982. if (empty($_SESSION["error_msg"])) {
  983. $v_backup_type = $_POST["v_backup_type"];
  984. }
  985. if (empty($_SESSION["error_msg"])) {
  986. $v_backup_username = $_POST["v_backup_username"];
  987. }
  988. if (empty($_SESSION["error_msg"])) {
  989. $v_backup_password = $_POST["v_backup_password"];
  990. }
  991. if (empty($_SESSION["error_msg"])) {
  992. $v_backup_bpath = $_POST["v_backup_bpath"];
  993. }
  994. if (empty($_SESSION["error_msg"])) {
  995. $v_backup_port = $_POST["v_backup_port"];
  996. }
  997. $v_backup_adv = "yes";
  998. $v_backup_remote_adv = "yes";
  999. } elseif (in_array($_POST["v_backup_type"], ["b2"])) {
  1000. $v_backup_bucket = quoteshellarg($_POST["v_backup_bucket"]);
  1001. $v_backup_application_id = quoteshellarg($_POST["v_backup_application_id"]);
  1002. $v_backup_application_key = quoteshellarg($_POST["v_backup_application_key"]);
  1003. exec(
  1004. HESTIA_CMD .
  1005. "v-add-backup-host " .
  1006. $v_backup_type .
  1007. " " .
  1008. $v_backup_bucket .
  1009. " " .
  1010. $v_backup_application_id .
  1011. " " .
  1012. $v_backup_application_key,
  1013. $output,
  1014. $return_var,
  1015. );
  1016. check_return_code($return_var, $output);
  1017. unset($output);
  1018. $v_backup_type = quoteshellarg($_POST["v_backup_type"]);
  1019. if (empty($_SESSION["error_msg"])) {
  1020. $v_backup_bucket = quoteshellarg($_POST["v_backup_bucket"]);
  1021. }
  1022. if (empty($_SESSION["error_msg"])) {
  1023. $v_backup_application_id = quoteshellarg($_POST["v_backup_application_id"]);
  1024. }
  1025. if (empty($_SESSION["error_msg"])) {
  1026. $v_backup_application_key = quoteshellarg($_POST["v_backup_application_key"]);
  1027. }
  1028. $v_backup_adv = "yes";
  1029. $v_backup_remote_adv = "yes";
  1030. }
  1031. }
  1032. }
  1033. // Change remote backup host
  1034. if (empty($_SESSION["error_msg"])) {
  1035. if ($_POST["v_backup_type"] == $v_backup_type && !isset($v_backup_new)) {
  1036. if (in_array($_POST["v_backup_type"], ["ftp", "sftp"])) {
  1037. if (
  1038. $_POST["v_backup_host"] != $v_backup_host ||
  1039. $_POST["v_backup_username"] != $v_backup_username ||
  1040. $_POST["v_backup_password"] != $v_backup_password ||
  1041. ($_POST["v_backup_bpath"] != $v_backup_bpath ||
  1042. $_POST["v_backup_port"] != $v_backup_port)
  1043. ) {
  1044. $v_backup_host = quoteshellarg($_POST["v_backup_host"]);
  1045. $v_backup_port = quoteshellarg($_POST["v_backup_port"]);
  1046. $v_backup_type = quoteshellarg($_POST["v_backup_type"]);
  1047. $v_backup_username = quoteshellarg($_POST["v_backup_username"]);
  1048. $v_backup_password = quoteshellarg($_POST["v_backup_password"]);
  1049. $v_backup_bpath = quoteshellarg($_POST["v_backup_bpath"]);
  1050. exec(
  1051. HESTIA_CMD .
  1052. "v-add-backup-host " .
  1053. $v_backup_type .
  1054. " " .
  1055. $v_backup_host .
  1056. " " .
  1057. $v_backup_username .
  1058. " " .
  1059. $v_backup_password .
  1060. " " .
  1061. $v_backup_bpath .
  1062. " " .
  1063. $v_backup_port,
  1064. $output,
  1065. $return_var,
  1066. );
  1067. check_return_code($return_var, $output);
  1068. unset($output);
  1069. if (empty($_SESSION["error_msg"])) {
  1070. $v_backup_host = $_POST["v_backup_host"];
  1071. }
  1072. if (empty($_SESSION["error_msg"])) {
  1073. $v_backup_type = $_POST["v_backup_type"];
  1074. }
  1075. if (empty($_SESSION["error_msg"])) {
  1076. $v_backup_username = $_POST["v_backup_username"];
  1077. }
  1078. if (empty($_SESSION["error_msg"])) {
  1079. $v_backup_password = $_POST["v_backup_password"];
  1080. }
  1081. if (empty($_SESSION["error_msg"])) {
  1082. $v_backup_bpath = $_POST["v_backup_bpath"];
  1083. }
  1084. if (empty($_SESSION["error_msg"])) {
  1085. $v_backup_port = $_POST["v_backup_port"];
  1086. }
  1087. $v_backup_adv = "yes";
  1088. $v_backup_remote_adv = "yes";
  1089. }
  1090. } elseif (in_array($_POST["v_backup_type"], ["b2"])) {
  1091. if (
  1092. $_POST["v_backup_bucket"] != $v_backup_bucket ||
  1093. $_POST["v_backup_application_key"] != $v_backup_application_key ||
  1094. $_POST["v_backup_application_id"] != $v_backup_application_id
  1095. ) {
  1096. $v_backup_type = quoteshellarg($_POST["v_backup_type"]);
  1097. $v_backup_bucket = quoteshellarg($_POST["v_backup_bucket"]);
  1098. $v_backup_application_id = quoteshellarg($_POST["v_backup_application_id"]);
  1099. $v_backup_application_key = quoteshellarg($_POST["v_backup_application_key"]);
  1100. exec(
  1101. HESTIA_CMD .
  1102. "v-add-backup-host " .
  1103. $v_backup_type .
  1104. " " .
  1105. $v_backup_bucket .
  1106. " " .
  1107. $v_backup_application_id .
  1108. " " .
  1109. $v_backup_application_key,
  1110. $output,
  1111. $return_var,
  1112. );
  1113. check_return_code($return_var, $output);
  1114. unset($output);
  1115. if (empty($_SESSION["error_msg"])) {
  1116. $v_backup_bucket = quoteshellarg($_POST["v_backup_bucket"]);
  1117. }
  1118. if (empty($_SESSION["error_msg"])) {
  1119. $v_backup_application_id = quoteshellarg($_POST["v_backup_application_id"]);
  1120. }
  1121. if (empty($_SESSION["error_msg"])) {
  1122. $v_backup_application_key = quoteshellarg(
  1123. $_POST["v_backup_application_key"],
  1124. );
  1125. }
  1126. $v_backup_adv = "yes";
  1127. $v_backup_remote_adv = "yes";
  1128. }
  1129. }
  1130. }
  1131. }
  1132. // Delete remote backup host
  1133. if (empty($_SESSION["error_msg"])) {
  1134. if (empty($_POST["v_backup_remote_adv"]) && $v_backup_remote_adv != "") {
  1135. exec(
  1136. HESTIA_CMD . "v-delete-backup-host " . quoteshellarg($v_backup_type),
  1137. $output,
  1138. $return_var,
  1139. );
  1140. check_return_code($return_var, $output);
  1141. unset($output);
  1142. if (empty($_SESSION["error_msg"])) {
  1143. $v_backup_host = "";
  1144. }
  1145. if (empty($_SESSION["error_msg"])) {
  1146. $v_backup_type = "";
  1147. }
  1148. if (empty($_SESSION["error_msg"])) {
  1149. $v_backup_username = "";
  1150. }
  1151. if (empty($_SESSION["error_msg"])) {
  1152. $v_backup_password = "";
  1153. }
  1154. if (empty($_SESSION["error_msg"])) {
  1155. $v_backup_bpath = "";
  1156. }
  1157. if (empty($_SESSION["error_msg"])) {
  1158. $v_backup_bucket = "";
  1159. }
  1160. if (empty($_SESSION["error_msg"])) {
  1161. $v_backup_application_id = "";
  1162. }
  1163. if (empty($_SESSION["error_msg"])) {
  1164. $v_backup_application_key = "";
  1165. }
  1166. $v_backup_adv = "";
  1167. $v_backup_remote_adv = "";
  1168. }
  1169. }
  1170. // Change INACTIVE_SESSION_TIMEOUT
  1171. if (empty($_SESSION["error_msg"])) {
  1172. if ($_POST["v_inactive_session_timeout"] != $_SESSION["INACTIVE_SESSION_TIMEOUT"]) {
  1173. if ($_POST["v_inactive_session_timeout"] < 1) {
  1174. $_SESSION["error_msg"] = _("Inactive session timeout can not lower than 1 minute.");
  1175. } else {
  1176. exec(
  1177. HESTIA_CMD .
  1178. "v-change-sys-config-value INACTIVE_SESSION_TIMEOUT " .
  1179. quoteshellarg($_POST["v_inactive_session_timeout"]),
  1180. $output,
  1181. $return_var,
  1182. );
  1183. check_return_code($return_var, $output);
  1184. unset($output);
  1185. if (empty($_SESSION["error_msg"])) {
  1186. $v_inactive_session_timeout = $_POST["v_inactive_session_timeout"];
  1187. }
  1188. }
  1189. $v_security_adv = "yes";
  1190. }
  1191. }
  1192. // Change POLICY_CSRF_STRICTNESS
  1193. if (empty($_SESSION["error_msg"])) {
  1194. if ($_POST["v_policy_csrf_strictness"] != $_SESSION["POLICY_CSRF_STRICTNESS"]) {
  1195. exec(
  1196. HESTIA_CMD .
  1197. "v-change-sys-config-value POLICY_CSRF_STRICTNESS " .
  1198. quoteshellarg($_POST["v_policy_csrf_strictness"]),
  1199. $output,
  1200. $return_var,
  1201. );
  1202. check_return_code($return_var, $output);
  1203. unset($output);
  1204. if (empty($_SESSION["error_msg"])) {
  1205. $v_policy_csrf_strictness = $_POST["v_inactive_session_timeout"];
  1206. }
  1207. $v_security_adv = "yes";
  1208. }
  1209. }
  1210. // Change ENFORCE_SUBDOMAIN_OWNERSHIP
  1211. if (empty($_SESSION["error_msg"])) {
  1212. if ($_POST["v_enforce_subdomain_ownership"] != $_SESSION["ENFORCE_SUBDOMAIN_OWNERSHIP"]) {
  1213. exec(
  1214. HESTIA_CMD .
  1215. "v-change-sys-config-value ENFORCE_SUBDOMAIN_OWNERSHIP " .
  1216. quoteshellarg($_POST["v_enforce_subdomain_ownership"]),
  1217. $output,
  1218. $return_var,
  1219. );
  1220. check_return_code($return_var, $output);
  1221. unset($output);
  1222. if (empty($_SESSION["error_msg"])) {
  1223. $v_enforce_subdomain_ownership = $_POST["v_enforce_subdomain_ownership"];
  1224. }
  1225. $v_security_adv = "yes";
  1226. }
  1227. }
  1228. // Change POLICY_USER_EDIT_DETAILS
  1229. if (empty($_SESSION["error_msg"])) {
  1230. if ($_POST["v_policy_user_edit_details"] != $_SESSION["POLICY_USER_EDIT_DETAILS"]) {
  1231. exec(
  1232. HESTIA_CMD .
  1233. "v-change-sys-config-value POLICY_USER_EDIT_DETAILS " .
  1234. quoteshellarg($_POST["v_policy_user_edit_details"]),
  1235. $output,
  1236. $return_var,
  1237. );
  1238. check_return_code($return_var, $output);
  1239. unset($output);
  1240. if (empty($_SESSION["error_msg"])) {
  1241. $v_policy_user_edit_details = $_POST["v_policy_user_edit_details"];
  1242. }
  1243. $v_security_adv = "yes";
  1244. }
  1245. }
  1246. // Change POLICY_USER_EDIT_WEB_TEMPLATES
  1247. if (empty($_SESSION["error_msg"])) {
  1248. if (
  1249. $_POST["v_policy_user_edit_web_templates"] !=
  1250. $_SESSION["POLICY_USER_EDIT_WEB_TEMPLATES"]
  1251. ) {
  1252. exec(
  1253. HESTIA_CMD .
  1254. "v-change-sys-config-value POLICY_USER_EDIT_WEB_TEMPLATES " .
  1255. quoteshellarg($_POST["v_policy_user_edit_web_templates"]),
  1256. $output,
  1257. $return_var,
  1258. );
  1259. check_return_code($return_var, $output);
  1260. unset($output);
  1261. if (empty($_SESSION["error_msg"])) {
  1262. $v_policy_user_edit_details = $_POST["v_policy_user_edit_web_templates"];
  1263. }
  1264. $v_security_adv = "yes";
  1265. }
  1266. }
  1267. // Change POLICY_USER_EDIT_DNS_TEMPLATES
  1268. if (empty($_SESSION["error_msg"])) {
  1269. if (
  1270. $_POST["v_policy_user_edit_dns_templates"] !=
  1271. $_SESSION["POLICY_USER_EDIT_DNS_TEMPLATES"]
  1272. ) {
  1273. exec(
  1274. HESTIA_CMD .
  1275. "v-change-sys-config-value POLICY_USER_EDIT_DNS_TEMPLATES " .
  1276. quoteshellarg($_POST["v_policy_user_edit_dns_templates"]),
  1277. $output,
  1278. $return_var,
  1279. );
  1280. check_return_code($return_var, $output);
  1281. unset($output);
  1282. if (empty($_SESSION["error_msg"])) {
  1283. $v_policy_user_edit_details = $_POST["v_policy_user_edit_dns_templates"];
  1284. }
  1285. $v_security_adv = "yes";
  1286. }
  1287. }
  1288. if (
  1289. $_POST["v_api_system"] != $_SESSION["API_SYSTEM"] ||
  1290. $_POST["v_api"] != $_SESSION["API"] ||
  1291. $_POST["v_api_allowed_ip"] != $_SESSION["API_ALLOWED_IP"]
  1292. ) {
  1293. if (empty($_SESSION["error_msg"])) {
  1294. if ($_POST["v_api"] == "no" && $_POST["v_api_system"] === 0) {
  1295. exec(HESTIA_CMD . "v-change-sys-api 'disable'", $output, $return_var);
  1296. check_return_code($return_var, $output);
  1297. unset($output);
  1298. }
  1299. if (
  1300. $_POST["v_api"] == "yes" ||
  1301. ($_POST["v_api_system"] !== 0 &&
  1302. $_POST["v_api_system"] != $_SESSION["API_SYSTEM"]) ||
  1303. $_POST["v_api"] != $_SESSION["API"]
  1304. ) {
  1305. exec(HESTIA_CMD . "v-change-sys-api 'enable'", $output, $return_var);
  1306. check_return_code($return_var, $output);
  1307. unset($output);
  1308. }
  1309. }
  1310. if (empty($_SESSION["error_msg"])) {
  1311. if ($_POST["v_api_system"] != $_SESSION["API_SYSTEM"]) {
  1312. exec(
  1313. HESTIA_CMD .
  1314. "v-change-sys-config-value API_SYSTEM " .
  1315. quoteshellarg($_POST["v_api_system"]),
  1316. $output,
  1317. $return_var,
  1318. );
  1319. check_return_code($return_var, $output);
  1320. unset($output);
  1321. if (empty($_SESSION["error_msg"])) {
  1322. $v_policy_user_edit_details = $_POST["v_api_system"];
  1323. }
  1324. $v_security_adv = "yes";
  1325. }
  1326. }
  1327. // Change API access
  1328. if (empty($_SESSION["error_msg"])) {
  1329. if ($_POST["v_api"] != $_SESSION["API"]) {
  1330. $api_status = "no";
  1331. if ($_POST["v_api"] == "yes") {
  1332. $api_status = "yes";
  1333. }
  1334. exec(
  1335. HESTIA_CMD . "v-change-sys-config-value API " . quoteshellarg($api_status),
  1336. $output,
  1337. $return_var,
  1338. );
  1339. check_return_code($return_var, $output);
  1340. unset($output);
  1341. if (empty($_SESSION["error_msg"])) {
  1342. $v_api = $_POST["v_api"];
  1343. }
  1344. $v_security_adv = "yes";
  1345. }
  1346. }
  1347. // Change API allowed IPs
  1348. if (empty($_SESSION["error_msg"])) {
  1349. if ($_POST["v_api_allowed_ip"] != $_SESSION["API_ALLOWED_IP"]) {
  1350. $ips = [];
  1351. foreach (explode("\n", $_POST["v_api_allowed_ip"]) as $ip) {
  1352. if (trim($ip) != "allow-all") {
  1353. if (filter_var(trim($ip), FILTER_VALIDATE_IP)) {
  1354. $ips[] = trim($ip);
  1355. }
  1356. } else {
  1357. $ips[] = trim($ip);
  1358. }
  1359. }
  1360. if (implode(",", $ips) != $_SESSION["API_ALLOWED_IP"]) {
  1361. exec(
  1362. HESTIA_CMD .
  1363. "v-change-sys-config-value API_ALLOWED_IP " .
  1364. quoteshellarg(implode(",", $ips)),
  1365. $output,
  1366. $return_var,
  1367. );
  1368. check_return_code($return_var, $output);
  1369. unset($output);
  1370. if (empty($_SESSION["error_msg"])) {
  1371. $v_api_allowed_ip = $_POST["v_api_allowed_ip"];
  1372. }
  1373. $v_security_adv = "yes";
  1374. }
  1375. }
  1376. }
  1377. }
  1378. // Change POLICY_USER_VIEW_LOGS
  1379. if (empty($_SESSION["error_msg"])) {
  1380. if ($_POST["v_policy_user_view_logs"] != $_SESSION["POLICY_USER_VIEW_LOGS"]) {
  1381. exec(
  1382. HESTIA_CMD .
  1383. "v-change-sys-config-value POLICY_USER_VIEW_LOGS " .
  1384. quoteshellarg($_POST["v_policy_user_view_logs"]),
  1385. $output,
  1386. $return_var,
  1387. );
  1388. check_return_code($return_var, $output);
  1389. unset($output);
  1390. if (empty($_SESSION["error_msg"])) {
  1391. $v_policy_user_view_logs = $_POST["v_policy_user_view_logs"];
  1392. }
  1393. $v_security_adv = "yes";
  1394. }
  1395. }
  1396. // Change POLICY_USER_DELETE_LOGS
  1397. if (empty($_SESSION["error_msg"])) {
  1398. if ($_POST["v_policy_user_delete_logs"] != $_SESSION["POLICY_USER_DELETE_LOGS"]) {
  1399. exec(
  1400. HESTIA_CMD .
  1401. "v-change-sys-config-value POLICY_USER_DELETE_LOGS " .
  1402. quoteshellarg($_POST["v_policy_user_delete_logs"]),
  1403. $output,
  1404. $return_var,
  1405. );
  1406. check_return_code($return_var, $output);
  1407. unset($output);
  1408. if (empty($_SESSION["error_msg"])) {
  1409. $v_policy_user_delete_logs = $_POST["v_policy_user_delete_logs"];
  1410. }
  1411. $v_security_adv = "yes";
  1412. }
  1413. }
  1414. // Change POLICY_SYSTEM_PASSWORD_RESET
  1415. if (empty($_SESSION["error_msg"])) {
  1416. if ($_POST["v_policy_system_password_reset"] != $_SESSION["POLICY_SYSTEM_PASSWORD_RESET"]) {
  1417. exec(
  1418. HESTIA_CMD .
  1419. "v-change-sys-config-value POLICY_SYSTEM_PASSWORD_RESET " .
  1420. quoteshellarg($_POST["v_policy_system_password_reset"]),
  1421. $output,
  1422. $return_var,
  1423. );
  1424. check_return_code($return_var, $output);
  1425. unset($output);
  1426. if (empty($_SESSION["error_msg"])) {
  1427. $v_policy_system_password_reset = $_POST["v_policy_system_password_reset"];
  1428. }
  1429. $v_security_adv = "yes";
  1430. }
  1431. }
  1432. // Change POLICY_SYSTEM_PROTECTED_ADMIN
  1433. if (empty($_SESSION["error_msg"])) {
  1434. if (!empty($_POST["v_policy_system_protected_admin"])) {
  1435. if (
  1436. $_POST["v_policy_system_protected_admin"] !=
  1437. $_SESSION["POLICY_SYSTEM_PROTECTED_ADMIN"]
  1438. ) {
  1439. exec(
  1440. HESTIA_CMD .
  1441. "v-change-sys-config-value POLICY_SYSTEM_PROTECTED_ADMIN " .
  1442. quoteshellarg($_POST["v_policy_system_protected_admin"]),
  1443. $output,
  1444. $return_var,
  1445. );
  1446. check_return_code($return_var, $output);
  1447. unset($output);
  1448. if (empty($_SESSION["error_msg"])) {
  1449. $v_policy_system_protected_admin = $_POST["v_policy_system_protected_admin"];
  1450. }
  1451. $v_security_adv = "yes";
  1452. }
  1453. }
  1454. }
  1455. // Change POLICY_USER_VIEW_SUSPENDED
  1456. if (empty($_SESSION["error_msg"])) {
  1457. if (!empty($_POST["v_policy_user_view_suspended"])) {
  1458. if (
  1459. $_POST["v_policy_user_view_suspended"] != $_SESSION["POLICY_USER_VIEW_SUSPENDED"] &&
  1460. !empty($_SESSION["POLICY_USER_VIEW_SUSPENDED"])
  1461. ) {
  1462. exec(
  1463. HESTIA_CMD .
  1464. "v-change-sys-config-value POLICY_USER_VIEW_SUSPENDED " .
  1465. quoteshellarg($_POST["v_policy_user_view_suspended"]),
  1466. $output,
  1467. $return_var,
  1468. );
  1469. check_return_code($return_var, $output);
  1470. unset($output);
  1471. if (empty($_SESSION["error_msg"])) {
  1472. $v_policy_user_view_suspended = $_POST["v_policy_user_view_suspended"];
  1473. }
  1474. $v_security_adv = "yes";
  1475. }
  1476. }
  1477. }
  1478. // Change POLICY_USER_CHANGE_THEME
  1479. if (empty($_SESSION["error_msg"])) {
  1480. if (empty($_POST["v_policy_user_change_theme"])) {
  1481. $_POST["v_policy_user_change_theme"] = "";
  1482. }
  1483. if ($_POST["v_policy_user_change_theme"] == "on") {
  1484. $_POST["v_policy_user_change_theme"] = "no";
  1485. } else {
  1486. $_POST["v_policy_user_change_theme"] = "yes";
  1487. }
  1488. if ($_POST["v_policy_user_change_theme"] != $_SESSION["POLICY_USER_CHANGE_THEME"]) {
  1489. exec(
  1490. HESTIA_CMD .
  1491. "v-change-sys-config-value POLICY_USER_CHANGE_THEME " .
  1492. quoteshellarg($_POST["v_policy_user_change_theme"]),
  1493. $output,
  1494. $return_var,
  1495. );
  1496. check_return_code($return_var, $output);
  1497. unset($output);
  1498. if ($_POST["v_policy_user_change_theme"]) {
  1499. unset($_SESSION["userTheme"]);
  1500. $require_refresh = true;
  1501. }
  1502. if (empty($_SESSION["error_msg"])) {
  1503. $v_policy_user_change_theme = $_POST["v_policy_user_change_theme"];
  1504. }
  1505. }
  1506. }
  1507. // Change POLICY_SYSTEM_HIDE_ADMIN
  1508. if (empty($_SESSION["error_msg"])) {
  1509. if (!empty($_POST["v_policy_system_hide_admin"])) {
  1510. if ($_POST["v_policy_system_hide_admin"] != $_SESSION["POLICY_SYSTEM_HIDE_ADMIN"]) {
  1511. exec(
  1512. HESTIA_CMD .
  1513. "v-change-sys-config-value POLICY_SYSTEM_HIDE_ADMIN " .
  1514. quoteshellarg($_POST["v_policy_system_hide_admin"]),
  1515. $output,
  1516. $return_var,
  1517. );
  1518. check_return_code($return_var, $output);
  1519. unset($output);
  1520. if (empty($_SESSION["error_msg"])) {
  1521. $v_policy_system_hide_admin = $_POST["v_policy_system_hide_admin"];
  1522. }
  1523. $v_security_adv = "yes";
  1524. }
  1525. }
  1526. }
  1527. // Change POLICY_SYSTEM_HIDE_SERVICES
  1528. if (empty($_SESSION["error_msg"])) {
  1529. if (!empty($_POST["v_policy_system_hide_services"])) {
  1530. if (
  1531. $_POST["v_policy_system_hide_services"] != $_SESSION["POLICY_SYSTEM_HIDE_SERVICES"]
  1532. ) {
  1533. exec(
  1534. HESTIA_CMD .
  1535. "v-change-sys-config-value POLICY_SYSTEM_HIDE_SERVICES " .
  1536. quoteshellarg($_POST["v_policy_system_hide_services"]),
  1537. $output,
  1538. $return_var,
  1539. );
  1540. check_return_code($return_var, $output);
  1541. unset($output);
  1542. if (empty($_SESSION["error_msg"])) {
  1543. $v_policy_system_hide_services = $_POST["v_policy_system_hide_services"];
  1544. }
  1545. $v_security_adv = "yes";
  1546. }
  1547. }
  1548. }
  1549. // Change POLICY_SYSTEM_HIDE_SERVICES
  1550. if (empty($_SESSION["error_msg"])) {
  1551. if (
  1552. $_POST["v_policy_backup_suspended_users"] != $_SESSION["POLICY_BACKUP_SUSPENDED_USERS"]
  1553. ) {
  1554. exec(
  1555. HESTIA_CMD .
  1556. "v-change-sys-config-value POLICY_BACKUP_SUSPENDED_USERS " .
  1557. quoteshellarg($_POST["v_policy_backup_suspended_users"]),
  1558. $output,
  1559. $return_var,
  1560. );
  1561. check_return_code($return_var, $output);
  1562. unset($output);
  1563. if (empty($_SESSION["error_msg"])) {
  1564. $v_policy_system_hide_services = $_POST["v_policy_backup_suspended_users"];
  1565. }
  1566. $v_security_adv = "yes";
  1567. }
  1568. }
  1569. if (empty($_SESSION["error_msg"])) {
  1570. if ($_POST["v_policy_sync_error_documents"] != $_SESSION["POLICY_SYNC_ERROR_DOCUMENTS"]) {
  1571. exec(
  1572. HESTIA_CMD .
  1573. "v-change-sys-config-value POLICY_SYNC_ERROR_DOCUMENTS " .
  1574. quoteshellarg($_POST["v_policy_sync_error_documents"]),
  1575. $output,
  1576. $return_var,
  1577. );
  1578. check_return_code($return_var, $output);
  1579. unset($output);
  1580. if (empty($_SESSION["error_msg"])) {
  1581. $v_policy_sync_error_documents = $_POST["v_policy_sync_error_documents"];
  1582. }
  1583. $v_security_adv = "yes";
  1584. }
  1585. }
  1586. if (empty($_SESSION["error_msg"])) {
  1587. if ($_POST["v_policy_sync_skeleton"] != $_SESSION["POLICY_SYNC_SKELETON"]) {
  1588. exec(
  1589. HESTIA_CMD .
  1590. "v-change-sys-config-value POLICY_SYNC_SKELETON " .
  1591. quoteshellarg($_POST["v_policy_sync_skeleton"]),
  1592. $output,
  1593. $return_var,
  1594. );
  1595. check_return_code($return_var, $output);
  1596. unset($output);
  1597. if (empty($_SESSION["error_msg"])) {
  1598. $v_policy_sync_skeleton = $_POST["v_policy_sync_skeleton"];
  1599. }
  1600. $v_security_adv = "yes";
  1601. }
  1602. }
  1603. // Change login style
  1604. if (empty($_SESSION["error_msg"])) {
  1605. if ($_POST["v_login_style"] != $_SESSION["LOGIN_STYLE"]) {
  1606. exec(
  1607. HESTIA_CMD .
  1608. "v-change-sys-config-value LOGIN_STYLE " .
  1609. quoteshellarg($_POST["v_login_style"]),
  1610. $output,
  1611. $return_var,
  1612. );
  1613. check_return_code($return_var, $output);
  1614. unset($output);
  1615. if (empty($_SESSION["error_msg"])) {
  1616. $v_login_style = $_POST["v_login_style"];
  1617. }
  1618. $v_security_adv = "yes";
  1619. }
  1620. }
  1621. // Update SSL certificate
  1622. if (!empty($_POST["v_ssl_crt"]) && empty($_SESSION["error_msg"])) {
  1623. if (
  1624. $v_ssl_crt != str_replace("\r\n", "\n", $_POST["v_ssl_crt"]) ||
  1625. $v_ssl_key != str_replace("\r\n", "\n", $_POST["v_ssl_key"])
  1626. ) {
  1627. exec("mktemp -d", $mktemp_output, $return_var);
  1628. $tmpdir = $mktemp_output[0];
  1629. // Certificate
  1630. if (!empty($_POST["v_ssl_crt"])) {
  1631. $fp = fopen($tmpdir . "/certificate.crt", "w");
  1632. fwrite($fp, str_replace("\r\n", "\n", $_POST["v_ssl_crt"]));
  1633. fwrite($fp, "\n");
  1634. fclose($fp);
  1635. }
  1636. // Key
  1637. if (!empty($_POST["v_ssl_key"])) {
  1638. $fp = fopen($tmpdir . "/certificate.key", "w");
  1639. fwrite($fp, str_replace("\r\n", "\n", $_POST["v_ssl_key"]));
  1640. fwrite($fp, "\n");
  1641. fclose($fp);
  1642. }
  1643. exec(HESTIA_CMD . "v-change-sys-hestia-ssl " . $tmpdir, $output, $return_var);
  1644. check_return_code($return_var, $output);
  1645. unset($output);
  1646. // List ssl certificate info
  1647. exec(HESTIA_CMD . "v-list-sys-hestia-ssl json", $output, $return_var);
  1648. $ssl_str = json_decode(implode("", $output), true);
  1649. unset($output);
  1650. $v_ssl_crt = $ssl_str["HESTIA"]["CRT"];
  1651. $v_ssl_key = $ssl_str["HESTIA"]["KEY"];
  1652. $v_ssl_ca = $ssl_str["HESTIA"]["CA"];
  1653. $v_ssl_subject = $ssl_str["HESTIA"]["SUBJECT"];
  1654. $v_ssl_aliases = $ssl_str["HESTIA"]["ALIASES"];
  1655. $v_ssl_not_before = $ssl_str["HESTIA"]["NOT_BEFORE"];
  1656. $v_ssl_not_after = $ssl_str["HESTIA"]["NOT_AFTER"];
  1657. $v_ssl_signature = $ssl_str["HESTIA"]["SIGNATURE"];
  1658. $v_ssl_pub_key = $ssl_str["HESTIA"]["PUB_KEY"];
  1659. $v_ssl_issuer = $ssl_str["HESTIA"]["ISSUER"];
  1660. // Cleanup certificate tempfiles
  1661. if (file_exists($tmpdir . "/certificate.crt")) {
  1662. unlink($tmpdir . "/certificate.crt");
  1663. }
  1664. if (file_exists($tmpdir . "/certificate.key")) {
  1665. unlink($tmpdir . "/certificate.key");
  1666. }
  1667. rmdir($tmpdir);
  1668. }
  1669. }
  1670. // Flush field values on success
  1671. if (empty($_SESSION["error_msg"])) {
  1672. $_SESSION["ok_msg"] = _("Changes have been saved.");
  1673. }
  1674. if ($require_refresh == true) {
  1675. $refresh = $_SERVER["REQUEST_URI"];
  1676. $_SESSION["ok_msg"] = _("Changes have been saved.");
  1677. header("Location: $refresh");
  1678. die();
  1679. }
  1680. }
  1681. // Check system configuration
  1682. exec(HESTIA_CMD . "v-list-sys-config json", $output, $return_var);
  1683. $data = json_decode(implode("", $output), true);
  1684. unset($output);
  1685. $sys_arr = $data["config"];
  1686. foreach ($sys_arr as $key => $value) {
  1687. $_SESSION[$key] = $value;
  1688. }
  1689. // Render page
  1690. render_page($user, $TAB, "edit_server");
  1691. // Flush session messages
  1692. unset($_SESSION["error_msg"]);
  1693. unset($_SESSION["ok_msg"]);