index.php 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669
  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. $post_php = $_POST["v_php_versions"];
  265. if (empty($post_php)) {
  266. $post_php = [];
  267. }
  268. array_map(function ($php_version) use ($post_php) {
  269. if (array_key_exists($php_version->tpl, $post_php)) {
  270. if (!$php_version->installed) {
  271. exec(
  272. HESTIA_CMD .
  273. "v-add-web-php " .
  274. quoteshellarg($php_version->version),
  275. $output,
  276. $return_var,
  277. );
  278. check_return_code($return_var, $output);
  279. unset($output);
  280. if (empty($_SESSION["error_msg"])) {
  281. $php_version->installed = true;
  282. }
  283. }
  284. } else {
  285. if ($php_version->installed && !$php_version->protected) {
  286. exec(
  287. HESTIA_CMD .
  288. "v-delete-web-php " .
  289. quoteshellarg($php_version->version),
  290. $output,
  291. $return_var,
  292. );
  293. check_return_code($return_var, $output);
  294. unset($output);
  295. if (empty($_SESSION["error_msg"])) {
  296. $php_version->installed = false;
  297. }
  298. }
  299. }
  300. return $php_version;
  301. }, $v_php_versions);
  302. }
  303. }
  304. if (empty($_SESSION["error_msg"])) {
  305. if ("php-" . $_POST["v_php_default_version"] != DEFAULT_PHP_VERSION) {
  306. exec(
  307. HESTIA_CMD .
  308. "v-change-sys-php " .
  309. quoteshellarg($_POST["v_php_default_version"]),
  310. $output,
  311. $return_var,
  312. );
  313. check_return_code($return_var, $output);
  314. unset($output);
  315. //force reload
  316. $require_refresh = true;
  317. }
  318. }
  319. }
  320. // Change timezone
  321. if (empty($_SESSION["error_msg"])) {
  322. if (!empty($_POST["v_timezone"])) {
  323. if ($v_timezone != $_POST["v_timezone"]) {
  324. exec(
  325. HESTIA_CMD . "v-change-sys-timezone " . quoteshellarg($_POST["v_timezone"]),
  326. $output,
  327. $return_var,
  328. );
  329. check_return_code($return_var, $output);
  330. $v_timezone = $_POST["v_timezone"];
  331. unset($output);
  332. }
  333. }
  334. }
  335. // Change default language
  336. if (empty($_SESSION["error_msg"])) {
  337. if (!empty($_POST["v_language"]) && $_SESSION["LANGUAGE"] != $_POST["v_language"]) {
  338. if (isset($_POST["v_language_update"])) {
  339. exec(
  340. HESTIA_CMD .
  341. "v-change-sys-language " .
  342. quoteshellarg($_POST["v_language"]) .
  343. " yes",
  344. $output,
  345. $return_var,
  346. );
  347. if (empty($_SESSION["error_msg"])) {
  348. $_SESSION["LANGUAGE"] = $_POST["v_language"];
  349. }
  350. }
  351. exec(
  352. HESTIA_CMD . "v-change-sys-language " . quoteshellarg($_POST["v_language"]),
  353. $output,
  354. $return_var,
  355. );
  356. check_return_code($return_var, $output);
  357. unset($output);
  358. if (empty($_SESSION["error_msg"])) {
  359. $_SESSION["LANGUAGE"] = $_POST["v_language"];
  360. }
  361. }
  362. }
  363. // Update theme
  364. if (empty($_SESSION["error_msg"])) {
  365. if ($_POST["v_theme"] != $_SESSION["THEME"]) {
  366. exec(
  367. HESTIA_CMD . "v-change-sys-config-value THEME " . quoteshellarg($_POST["v_theme"]),
  368. $output,
  369. $return_var,
  370. );
  371. check_return_code($return_var, $output);
  372. unset($output);
  373. }
  374. }
  375. // Update debug mode status
  376. if (empty($_SESSION["error_msg"])) {
  377. if ($_POST["v_debug_mode"] == "on") {
  378. $_POST["v_debug_mode"] = "true";
  379. } else {
  380. $_POST["v_debug_mode"] = "false";
  381. }
  382. if ($_POST["v_debug_mode"] != $_SESSION["DEBUG_MODE"]) {
  383. exec(
  384. HESTIA_CMD .
  385. "v-change-sys-config-value DEBUG_MODE " .
  386. quoteshellarg($_POST["v_debug_mode"]),
  387. $output,
  388. $return_var,
  389. );
  390. check_return_code($return_var, $output);
  391. unset($output);
  392. $v_debug_mode_adv = "yes";
  393. }
  394. }
  395. // Enable/Disable Quick App Installer
  396. if (empty($_SESSION["error_msg"])) {
  397. if ($_POST["v_plugin_app_installer"] != $_SESSION["PLUGIN_APP_INSTALLER"]) {
  398. if ($_POST["v_plugin_app_installer"] == "true") {
  399. $_POST["v_plugin_app_installer"] = "true";
  400. } else {
  401. $_POST["v_plugin_app_installer"] = "false";
  402. }
  403. exec(
  404. HESTIA_CMD .
  405. "v-change-sys-config-value PLUGIN_APP_INSTALLER " .
  406. quoteshellarg($_POST["v_plugin_app_installer"]),
  407. $output,
  408. $return_var,
  409. );
  410. check_return_code($return_var, $output);
  411. unset($output);
  412. }
  413. }
  414. // Update experimental features status
  415. if (
  416. empty($_SESSION["error_msg"]) &&
  417. $_POST["v_experimental_features"] != $_SESSION["POLICY_SYSTEM_ENABLE_BACON"]
  418. ) {
  419. if ($_POST["v_experimental_features"] == "on") {
  420. $_POST["v_experimental_features"] = "true";
  421. } else {
  422. $_POST["v_experimental_features"] = "false";
  423. }
  424. if ($_POST["v_experimental_features"] != $_SESSION["POLICY_SYSTEM_ENABLE_BACON"]) {
  425. exec(
  426. HESTIA_CMD .
  427. "v-change-sys-config-value POLICY_SYSTEM_ENABLE_BACON " .
  428. quoteshellarg($_POST["v_experimental_features"]),
  429. $output,
  430. $return_var,
  431. );
  432. check_return_code($return_var, $output);
  433. unset($output);
  434. $v_debug_mode_adv = "yes";
  435. }
  436. if (
  437. $_POST["v_policy_user_view_suspended"] != $_SESSION["POLICY_SYSTEM_ENABLE_BACON"] &&
  438. $_POST["v_experimental_features"] == "false"
  439. ) {
  440. //disable preview mode
  441. exec(
  442. HESTIA_CMD .
  443. "v-change-sys-config-value POLICY_USER_VIEW_SUSPENDED " .
  444. quoteshellarg($_POST["v_policy_user_view_suspended"]),
  445. $output,
  446. $return_var,
  447. );
  448. check_return_code($return_var, $output);
  449. unset($output);
  450. }
  451. }
  452. // Set File Manager support
  453. if (empty($_SESSION["error_msg"])) {
  454. if (
  455. !empty($_POST["v_filemanager"]) &&
  456. $_SESSION["FILE_MANAGER"] != $_POST["v_filemanager"]
  457. ) {
  458. if ($_POST["v_filemanager"] == "true") {
  459. exec(HESTIA_CMD . "v-add-sys-filemanager", $output, $return_var);
  460. check_return_code($return_var, $output);
  461. unset($output);
  462. if (empty($_SESSION["error_msg"])) {
  463. $_SESSION["FILE_MANAGER"] = "true";
  464. }
  465. } else {
  466. exec(HESTIA_CMD . "v-delete-sys-filemanager", $output, $return_var);
  467. check_return_code($return_var, $output);
  468. unset($output);
  469. if (empty($_SESSION["error_msg"])) {
  470. $_SESSION["FILE_MANAGER"] = "false";
  471. }
  472. }
  473. }
  474. }
  475. // Set phpMyAdmin SSO key
  476. if (empty($_SESSION["error_msg"])) {
  477. if (!empty($_POST["v_phpmyadmin_key"])) {
  478. if ($_POST["v_phpmyadmin_key"] == "yes" && $_SESSION["PHPMYADMIN_KEY"] == "") {
  479. exec(HESTIA_CMD . "v-add-sys-pma-sso quiet", $output, $return_var);
  480. check_return_code($return_var, $output);
  481. unset($output);
  482. if (empty($_SESSION["error_msg"])) {
  483. $_SESSION["PHPMYADMIN_KEY"] != "";
  484. }
  485. } elseif ($_POST["v_phpmyadmin_key"] == "no" && $_SESSION["PHPMYADMIN_KEY"] != "") {
  486. exec(HESTIA_CMD . "v-delete-sys-pma-sso quiet", $output, $return_var);
  487. check_return_code($return_var, $output);
  488. unset($output);
  489. if (empty($_SESSION["error_msg"])) {
  490. $_SESSION["PHPMYADMIN_KEY"] = "";
  491. }
  492. }
  493. }
  494. }
  495. // Set disk_quota support
  496. if (empty($_SESSION["error_msg"])) {
  497. if (!empty($_POST["v_quota"]) && $_SESSION["DISK_QUOTA"] != $_POST["v_quota"]) {
  498. if ($_POST["v_quota"] == "yes") {
  499. exec(HESTIA_CMD . "v-add-sys-quota", $output, $return_var);
  500. check_return_code($return_var, $output);
  501. unset($output);
  502. if (empty($_SESSION["error_msg"])) {
  503. $_SESSION["DISK_QUOTA"] = "yes";
  504. }
  505. } else {
  506. exec(HESTIA_CMD . "v-delete-sys-quota", $output, $return_var);
  507. check_return_code($return_var, $output);
  508. unset($output);
  509. if (empty($_SESSION["error_msg"])) {
  510. $_SESSION["DISK_QUOTA"] = "no";
  511. }
  512. }
  513. }
  514. }
  515. // Set firewall support
  516. if (empty($_SESSION["error_msg"])) {
  517. if ($_SESSION["FIREWALL_SYSTEM"] == "iptables") {
  518. $v_firewall = "yes";
  519. }
  520. if ($_SESSION["FIREWALL_SYSTEM"] != "iptables") {
  521. $v_firewall = "no";
  522. }
  523. if (!empty($_POST["v_firewall"]) && $v_firewall != $_POST["v_firewall"]) {
  524. if ($_POST["v_firewall"] == "yes") {
  525. exec(HESTIA_CMD . "v-add-sys-firewall", $output, $return_var);
  526. check_return_code($return_var, $output);
  527. unset($output);
  528. if (empty($_SESSION["error_msg"])) {
  529. $_SESSION["FIREWALL_SYSTEM"] = "iptables";
  530. }
  531. } else {
  532. exec(HESTIA_CMD . "v-delete-sys-firewall", $output, $return_var);
  533. check_return_code($return_var, $output);
  534. unset($output);
  535. if (empty($_SESSION["error_msg"])) {
  536. $_SESSION["FIREWALL_SYSTEM"] = "";
  537. }
  538. }
  539. }
  540. }
  541. // Update mysql pasword
  542. if (empty($_SESSION["error_msg"])) {
  543. if (!empty($_POST["v_mysql_password"])) {
  544. exec(
  545. HESTIA_CMD .
  546. "v-change-database-host-password mysql localhost root " .
  547. quoteshellarg($_POST["v_mysql_password"]),
  548. $output,
  549. $return_var,
  550. );
  551. check_return_code($return_var, $output);
  552. unset($output);
  553. $v_db_adv = "yes";
  554. }
  555. }
  556. // Update webmail url
  557. if (empty($_SESSION["error_msg"])) {
  558. if ($_POST["v_webmail_alias"] != $_SESSION["WEBMAIL_ALIAS"]) {
  559. exec(
  560. HESTIA_CMD . "v-change-sys-webmail " . quoteshellarg($_POST["v_webmail_alias"]),
  561. $output,
  562. $return_var,
  563. );
  564. check_return_code($return_var, $output);
  565. unset($output);
  566. $v_mail_adv = "yes";
  567. }
  568. }
  569. // Update system wide smtp relay
  570. if (empty($_SESSION["error_msg"])) {
  571. if (isset($_POST["v_smtp_relay"]) && !empty($_POST["v_smtp_relay_host"])) {
  572. if (
  573. $_POST["v_smtp_relay_host"] != $v_smtp_relay_host ||
  574. $_POST["v_smtp_relay_user"] != $v_smtp_relay_user ||
  575. $_POST["v_smtp_relay_port"] != $v_smtp_relay_port
  576. ) {
  577. $v_smtp_relay = true;
  578. $v_smtp_relay_host = quoteshellarg($_POST["v_smtp_relay_host"]);
  579. $v_smtp_relay_user = quoteshellarg($_POST["v_smtp_relay_user"]);
  580. $v_smtp_relay_pass = quoteshellarg($_POST["v_smtp_relay_pass"]);
  581. if (!empty($_POST["v_smtp_relay_port"])) {
  582. $v_smtp_relay_port = quoteshellarg($_POST["v_smtp_relay_port"]);
  583. } else {
  584. $v_smtp_relay_port = "587";
  585. }
  586. exec(
  587. HESTIA_CMD .
  588. "v-add-sys-smtp-relay " .
  589. $v_smtp_relay_host .
  590. " " .
  591. $v_smtp_relay_user .
  592. " " .
  593. $v_smtp_relay_pass .
  594. " " .
  595. $v_smtp_relay_port,
  596. $output,
  597. $return_var,
  598. );
  599. check_return_code($return_var, $output);
  600. unset($output);
  601. }
  602. }
  603. if (!isset($_POST["v_smtp_relay"]) && $v_smtp_relay == true) {
  604. $v_smtp_relay = false;
  605. $v_smtp_relay_host = $v_smtp_relay_user = $v_smtp_relay_pass = $v_smtp_relay_port = "";
  606. exec(HESTIA_CMD . "v-delete-sys-smtp-relay", $output, $return_var);
  607. check_return_code($return_var, $output);
  608. unset($output);
  609. }
  610. }
  611. // Update phpMyAdmin url
  612. if (empty($_SESSION["error_msg"])) {
  613. if ($_POST["v_mysql_url"] != $_SESSION["DB_PMA_ALIAS"]) {
  614. exec(
  615. HESTIA_CMD . "v-change-sys-db-alias pma " . quoteshellarg($_POST["v_mysql_url"]),
  616. $output,
  617. $return_var,
  618. );
  619. check_return_code($return_var, $output);
  620. unset($output);
  621. $v_db_adv = "yes";
  622. }
  623. }
  624. // Update phpPgAdmin url
  625. if (empty($_SESSION["error_msg"])) {
  626. if ($_POST["v_pgsql_url"] != $_SESSION["DB_PGA_ALIAS"]) {
  627. exec(
  628. HESTIA_CMD . "v-change-sys-db-alias pga " . quoteshellarg($_POST["v_pgsql_url"]),
  629. $output,
  630. $return_var,
  631. );
  632. check_return_code($return_var, $output);
  633. unset($output);
  634. $v_db_adv = "yes";
  635. }
  636. }
  637. // Update send notification setting
  638. if (empty($_SESSION["error_msg"])) {
  639. if ($_SESSION["UPGRADE_SEND_EMAIL"] == "true") {
  640. $ugrade_send_mail = "on";
  641. } else {
  642. $ugrade_send_mail = "";
  643. }
  644. if ($_POST["v_upgrade_send_notification_email"] != $ugrade_send_mail) {
  645. if ($_POST["v_upgrade_send_notification_email"] == "on") {
  646. $_POST["v_upgrade_send_notification_email"] = "true";
  647. } else {
  648. $_POST["v_upgrade_send_notification_email"] = "false";
  649. }
  650. exec(
  651. HESTIA_CMD .
  652. "v-change-sys-config-value UPGRADE_SEND_EMAIL " .
  653. quoteshellarg($_POST["v_upgrade_send_notification_email"]),
  654. $output,
  655. $return_var,
  656. );
  657. check_return_code($return_var, $output);
  658. unset($output);
  659. $v_upgrade_notification_adv = "yes";
  660. }
  661. }
  662. // Update send log by email setting
  663. if (empty($_SESSION["error_msg"])) {
  664. if ($_SESSION["UPGRADE_SEND_EMAIL_LOG"] == "true") {
  665. $send_email_log = "on";
  666. } else {
  667. $send_email_log = "";
  668. }
  669. if (empty($_POST["v_upgrade_send_email_log"])) {
  670. $_POST["v_upgrade_send_email_log"] = "";
  671. }
  672. if ($_POST["v_upgrade_send_email_log"] != $send_email_log) {
  673. if ($_POST["v_upgrade_send_email_log"] == "on") {
  674. $_POST["v_upgrade_send_email_log"] = "true";
  675. } else {
  676. $_POST["v_upgrade_send_email_log"] = "false";
  677. }
  678. exec(
  679. HESTIA_CMD .
  680. "v-change-sys-config-value UPGRADE_SEND_EMAIL_LOG " .
  681. quoteshellarg($_POST["v_upgrade_send_email_log"]),
  682. $output,
  683. $return_var,
  684. );
  685. check_return_code($return_var, $output);
  686. unset($output);
  687. $v_upgrade_send_log_adv = "yes";
  688. }
  689. }
  690. // Disable local backup
  691. if (empty($_SESSION["error_msg"])) {
  692. if ($_POST["v_backup"] == "no" && $v_backup == "yes") {
  693. exec(HESTIA_CMD . "v-delete-backup-host local", $output, $return_var);
  694. check_return_code($return_var, $output);
  695. unset($output);
  696. if (empty($_SESSION["error_msg"])) {
  697. $v_backup = "no";
  698. }
  699. $v_backup_adv = "yes";
  700. }
  701. }
  702. // Enable local backups
  703. if (empty($_SESSION["error_msg"])) {
  704. if ($_POST["v_backup"] == "yes" && $v_backup != "yes") {
  705. exec(HESTIA_CMD . "v-add-backup-host local", $output, $return_var);
  706. check_return_code($return_var, $output);
  707. unset($output);
  708. if (empty($_SESSION["error_msg"])) {
  709. $v_backup = "yes";
  710. }
  711. $v_backup_adv = "yes";
  712. }
  713. }
  714. // Change backup gzip level
  715. if (empty($_SESSION["error_msg"])) {
  716. if ($_POST["v_backup_gzip"] != $v_backup_gzip) {
  717. if ($_POST["v_backup_mode"] == "gzip") {
  718. $_POST["v_backup_gzip"] = 9;
  719. }
  720. exec(
  721. HESTIA_CMD .
  722. "v-change-sys-config-value BACKUP_GZIP " .
  723. quoteshellarg($_POST["v_backup_gzip"]),
  724. $output,
  725. $return_var,
  726. );
  727. check_return_code($return_var, $output);
  728. unset($output);
  729. if (empty($_SESSION["error_msg"])) {
  730. $v_backup_gzip = $_POST["v_backup_gzip"];
  731. }
  732. $v_backup_adv = "yes";
  733. }
  734. }
  735. // Change backup mode
  736. if (empty($_SESSION["error_msg"])) {
  737. if ($_POST["v_backup_mode"] != $v_backup_mode) {
  738. exec(
  739. HESTIA_CMD .
  740. "v-change-sys-config-value BACKUP_MODE " .
  741. quoteshellarg($_POST["v_backup_mode"]),
  742. $output,
  743. $return_var,
  744. );
  745. check_return_code($return_var, $output);
  746. unset($output);
  747. if (empty($_SESSION["error_msg"])) {
  748. $v_backup_mode = $_POST["v_backup_mode"];
  749. }
  750. $v_backup_adv = "yes";
  751. if ($_POST["v_backup_mode"] == "gzip") {
  752. $_POST["v_backup_gzip"] = 9;
  753. if (empty($_SESSION["error_msg"])) {
  754. $v_backup_gzip = $_POST["v_backup_gzip"];
  755. }
  756. exec(
  757. HESTIA_CMD .
  758. "v-change-sys-config-value BACKUP_GZIP " .
  759. quoteshellarg($_POST["v_backup_gzip"]),
  760. $output,
  761. $return_var,
  762. );
  763. }
  764. }
  765. }
  766. // Change backup path
  767. if (empty($_SESSION["error_msg"])) {
  768. if (empty($_POST["v_backup_dir"])) {
  769. $_POST["v_backup_dir"] = "";
  770. }
  771. if ($_POST["v_backup_dir"] != $v_backup_dir) {
  772. /*
  773. See #1655
  774. exec (HESTIA_CMD."v-change-sys-config-value BACKUP ".quoteshellarg($_POST['v_backup_dir']), $output, $return_var);
  775. check_return_code($return_var,$output);
  776. unset($output);
  777. */
  778. if (empty($_SESSION["error_msg"])) {
  779. $v_backup_dir = $_POST["v_backup_dir"];
  780. }
  781. #$v_backup_adv = 'yes';
  782. }
  783. }
  784. // Add remote backup host
  785. if (empty($_SESSION["error_msg"])) {
  786. if (
  787. $v_backup_host == "" &&
  788. $v_backup_bucket == "" &&
  789. (!empty($_POST["v_backup_host"]) || !empty($_POST["v_backup_bucket"]))
  790. ) {
  791. if (in_array($_POST["v_backup_type"], ["ftp", "sftp"])) {
  792. $v_backup_host = quoteshellarg($_POST["v_backup_host"]);
  793. $v_backup_port = quoteshellarg($_POST["v_backup_port"]);
  794. $v_backup_type = quoteshellarg($_POST["v_backup_type"]);
  795. $v_backup_username = quoteshellarg($_POST["v_backup_username"]);
  796. $v_backup_password = quoteshellarg($_POST["v_backup_password"]);
  797. $v_backup_bpath = quoteshellarg($_POST["v_backup_bpath"]);
  798. exec(
  799. HESTIA_CMD .
  800. "v-add-backup-host " .
  801. $v_backup_type .
  802. " " .
  803. $v_backup_host .
  804. " " .
  805. $v_backup_username .
  806. " " .
  807. $v_backup_password .
  808. " " .
  809. $v_backup_bpath .
  810. " " .
  811. $v_backup_port,
  812. $output,
  813. $return_var,
  814. );
  815. check_return_code($return_var, $output);
  816. unset($output);
  817. if (empty($_SESSION["error_msg"])) {
  818. $v_backup_host = $_POST["v_backup_host"];
  819. }
  820. if (empty($_SESSION["error_msg"])) {
  821. $v_backup_type = $_POST["v_backup_type"];
  822. }
  823. if (empty($_SESSION["error_msg"])) {
  824. $v_backup_username = $_POST["v_backup_username"];
  825. }
  826. if (empty($_SESSION["error_msg"])) {
  827. $v_backup_password = $_POST["v_backup_password"];
  828. }
  829. if (empty($_SESSION["error_msg"])) {
  830. $v_backup_bpath = $_POST["v_backup_bpath"];
  831. }
  832. if (empty($_SESSION["error_msg"])) {
  833. $v_backup_port = $_POST["v_backup_port"];
  834. }
  835. $v_backup_new = "yes";
  836. $v_backup_adv = "yes";
  837. $v_backup_remote_adv = "yes";
  838. } elseif (in_array($_POST["v_backup_type"], ["b2"])) {
  839. $v_backup_type = quoteshellarg($_POST["v_backup_type"]);
  840. $v_backup_bucket = quoteshellarg($_POST["v_backup_bucket"]);
  841. $v_backup_application_id = quoteshellarg($_POST["v_backup_application_id"]);
  842. $v_backup_application_key = quoteshellarg($_POST["v_backup_application_key"]);
  843. exec(
  844. HESTIA_CMD .
  845. "v-add-backup-host " .
  846. $v_backup_type .
  847. " " .
  848. $v_backup_bucket .
  849. " " .
  850. $v_backup_application_id .
  851. " " .
  852. $v_backup_application_key,
  853. $output,
  854. $return_var,
  855. );
  856. check_return_code($return_var, $output);
  857. unset($output);
  858. if (empty($_SESSION["error_msg"])) {
  859. $v_backup_bucket = quoteshellarg($_POST["v_backup_bucket"]);
  860. }
  861. if (empty($_SESSION["error_msg"])) {
  862. $v_backup_application_id = quoteshellarg($_POST["v_backup_application_id"]);
  863. }
  864. if (empty($_SESSION["error_msg"])) {
  865. $v_backup_application_key = quoteshellarg($_POST["v_backup_application_key"]);
  866. }
  867. $v_backup_new = "yes";
  868. $v_backup_adv = "yes";
  869. $v_backup_remote_adv = "yes";
  870. }
  871. }
  872. if (
  873. $v_rclone_host == "" &&
  874. !empty($_POST["v_rclone_host"]) &&
  875. $_POST["v_backup_type"] == "rclone"
  876. ) {
  877. $v_rclone_host = quoteshellarg($_POST["v_rclone_host"]);
  878. $v_backup_type = quoteshellarg($_POST["v_backup_type"]);
  879. $v_rclone_path = quoteshellarg($_POST["v_rclone_path"]);
  880. exec(
  881. HESTIA_CMD .
  882. "v-add-backup-host " .
  883. $v_backup_type .
  884. " " .
  885. $v_rclone_host .
  886. " '' '' " .
  887. $v_rclone_path,
  888. $output,
  889. $return_var,
  890. );
  891. check_return_code($return_var, $output);
  892. unset($output);
  893. $v_backup_new = "yes";
  894. $v_backup_adv = "yes";
  895. $v_backup_remote_adv = "yes";
  896. }
  897. }
  898. // Change remote backup host type
  899. if (empty($_SESSION["error_msg"])) {
  900. if (
  901. !empty($_POST["v_backup_host"]) &&
  902. $_POST["v_backup_type"] != $v_backup_type &&
  903. $v_backup_type != ""
  904. ) {
  905. exec(
  906. HESTIA_CMD . "v-delete-backup-host " . quoteshellarg($v_backup_type),
  907. $output,
  908. $return_var,
  909. );
  910. unset($output);
  911. if (in_array($_POST["v_backup_type"], ["ftp", "sftp"])) {
  912. $v_backup_host = quoteshellarg($_POST["v_backup_host"]);
  913. $v_backup_port = quoteshellarg($_POST["v_backup_port"]);
  914. $v_backup_type = quoteshellarg($_POST["v_backup_type"]);
  915. $v_backup_username = quoteshellarg($_POST["v_backup_username"]);
  916. $v_backup_password = quoteshellarg($_POST["v_backup_password"]);
  917. $v_backup_bpath = quoteshellarg($_POST["v_backup_bpath"]);
  918. exec(
  919. HESTIA_CMD .
  920. "v-add-backup-host " .
  921. $v_backup_type .
  922. " " .
  923. $v_backup_host .
  924. " " .
  925. $v_backup_username .
  926. " " .
  927. $v_backup_password .
  928. " " .
  929. $v_backup_bpath .
  930. " " .
  931. $v_backup_port,
  932. $output,
  933. $return_var,
  934. );
  935. check_return_code($return_var, $output);
  936. unset($output);
  937. if (empty($_SESSION["error_msg"])) {
  938. $v_backup_host = $_POST["v_backup_host"];
  939. }
  940. if (empty($_SESSION["error_msg"])) {
  941. $v_backup_type = $_POST["v_backup_type"];
  942. }
  943. if (empty($_SESSION["error_msg"])) {
  944. $v_backup_username = $_POST["v_backup_username"];
  945. }
  946. if (empty($_SESSION["error_msg"])) {
  947. $v_backup_password = $_POST["v_backup_password"];
  948. }
  949. if (empty($_SESSION["error_msg"])) {
  950. $v_backup_bpath = $_POST["v_backup_bpath"];
  951. }
  952. if (empty($_SESSION["error_msg"])) {
  953. $v_backup_port = $_POST["v_backup_port"];
  954. }
  955. $v_backup_adv = "yes";
  956. $v_backup_remote_adv = "yes";
  957. } elseif (in_array($_POST["v_backup_type"], ["b2"])) {
  958. $v_backup_bucket = quoteshellarg($_POST["v_backup_bucket"]);
  959. $v_backup_application_id = quoteshellarg($_POST["v_backup_application_id"]);
  960. $v_backup_application_key = quoteshellarg($_POST["v_backup_application_key"]);
  961. exec(
  962. HESTIA_CMD .
  963. "v-add-backup-host " .
  964. $v_backup_type .
  965. " " .
  966. $v_backup_bucket .
  967. " " .
  968. $v_backup_application_id .
  969. " " .
  970. $v_backup_application_key,
  971. $output,
  972. $return_var,
  973. );
  974. check_return_code($return_var, $output);
  975. unset($output);
  976. $v_backup_type = quoteshellarg($_POST["v_backup_type"]);
  977. if (empty($_SESSION["error_msg"])) {
  978. $v_backup_bucket = quoteshellarg($_POST["v_backup_bucket"]);
  979. }
  980. if (empty($_SESSION["error_msg"])) {
  981. $v_backup_application_id = quoteshellarg($_POST["v_backup_application_id"]);
  982. }
  983. if (empty($_SESSION["error_msg"])) {
  984. $v_backup_application_key = quoteshellarg($_POST["v_backup_application_key"]);
  985. }
  986. $v_backup_adv = "yes";
  987. $v_backup_remote_adv = "yes";
  988. }
  989. }
  990. }
  991. // Change remote backup host
  992. if (empty($_SESSION["error_msg"])) {
  993. if ($_POST["v_backup_type"] == $v_backup_type && !isset($v_backup_new)) {
  994. if (in_array($_POST["v_backup_type"], ["ftp", "sftp"])) {
  995. if (
  996. $_POST["v_backup_host"] != $v_backup_host ||
  997. $_POST["v_backup_username"] != $v_backup_username ||
  998. $_POST["v_backup_password"] != $v_backup_password ||
  999. ($_POST["v_backup_bpath"] != $v_backup_bpath ||
  1000. $_POST["v_backup_port"] != $v_backup_port)
  1001. ) {
  1002. $v_backup_host = quoteshellarg($_POST["v_backup_host"]);
  1003. $v_backup_port = quoteshellarg($_POST["v_backup_port"]);
  1004. $v_backup_type = quoteshellarg($_POST["v_backup_type"]);
  1005. $v_backup_username = quoteshellarg($_POST["v_backup_username"]);
  1006. $v_backup_password = quoteshellarg($_POST["v_backup_password"]);
  1007. $v_backup_bpath = quoteshellarg($_POST["v_backup_bpath"]);
  1008. exec(
  1009. HESTIA_CMD .
  1010. "v-add-backup-host " .
  1011. $v_backup_type .
  1012. " " .
  1013. $v_backup_host .
  1014. " " .
  1015. $v_backup_username .
  1016. " " .
  1017. $v_backup_password .
  1018. " " .
  1019. $v_backup_bpath .
  1020. " " .
  1021. $v_backup_port,
  1022. $output,
  1023. $return_var,
  1024. );
  1025. check_return_code($return_var, $output);
  1026. unset($output);
  1027. if (empty($_SESSION["error_msg"])) {
  1028. $v_backup_host = $_POST["v_backup_host"];
  1029. }
  1030. if (empty($_SESSION["error_msg"])) {
  1031. $v_backup_type = $_POST["v_backup_type"];
  1032. }
  1033. if (empty($_SESSION["error_msg"])) {
  1034. $v_backup_username = $_POST["v_backup_username"];
  1035. }
  1036. if (empty($_SESSION["error_msg"])) {
  1037. $v_backup_password = $_POST["v_backup_password"];
  1038. }
  1039. if (empty($_SESSION["error_msg"])) {
  1040. $v_backup_bpath = $_POST["v_backup_bpath"];
  1041. }
  1042. if (empty($_SESSION["error_msg"])) {
  1043. $v_backup_port = $_POST["v_backup_port"];
  1044. }
  1045. $v_backup_adv = "yes";
  1046. $v_backup_remote_adv = "yes";
  1047. }
  1048. } elseif (in_array($_POST["v_backup_type"], ["b2"])) {
  1049. if (
  1050. $_POST["v_backup_bucket"] != $v_backup_bucket ||
  1051. $_POST["v_backup_application_key"] != $v_backup_application_key ||
  1052. $_POST["v_backup_application_id"] != $v_backup_application_id
  1053. ) {
  1054. $v_backup_type = quoteshellarg($_POST["v_backup_type"]);
  1055. $v_backup_bucket = quoteshellarg($_POST["v_backup_bucket"]);
  1056. $v_backup_application_id = quoteshellarg($_POST["v_backup_application_id"]);
  1057. $v_backup_application_key = quoteshellarg($_POST["v_backup_application_key"]);
  1058. exec(
  1059. HESTIA_CMD .
  1060. "v-add-backup-host " .
  1061. $v_backup_type .
  1062. " " .
  1063. $v_backup_bucket .
  1064. " " .
  1065. $v_backup_application_id .
  1066. " " .
  1067. $v_backup_application_key,
  1068. $output,
  1069. $return_var,
  1070. );
  1071. check_return_code($return_var, $output);
  1072. unset($output);
  1073. if (empty($_SESSION["error_msg"])) {
  1074. $v_backup_bucket = quoteshellarg($_POST["v_backup_bucket"]);
  1075. }
  1076. if (empty($_SESSION["error_msg"])) {
  1077. $v_backup_application_id = quoteshellarg($_POST["v_backup_application_id"]);
  1078. }
  1079. if (empty($_SESSION["error_msg"])) {
  1080. $v_backup_application_key = quoteshellarg(
  1081. $_POST["v_backup_application_key"],
  1082. );
  1083. }
  1084. $v_backup_adv = "yes";
  1085. $v_backup_remote_adv = "yes";
  1086. }
  1087. }
  1088. }
  1089. }
  1090. // Delete remote backup host
  1091. if (empty($_SESSION["error_msg"])) {
  1092. if (empty($_POST["v_backup_remote_adv"]) && $v_backup_remote_adv != "") {
  1093. exec(
  1094. HESTIA_CMD . "v-delete-backup-host " . quoteshellarg($v_backup_type),
  1095. $output,
  1096. $return_var,
  1097. );
  1098. check_return_code($return_var, $output);
  1099. unset($output);
  1100. if (empty($_SESSION["error_msg"])) {
  1101. $v_backup_host = "";
  1102. }
  1103. if (empty($_SESSION["error_msg"])) {
  1104. $v_backup_type = "";
  1105. }
  1106. if (empty($_SESSION["error_msg"])) {
  1107. $v_backup_username = "";
  1108. }
  1109. if (empty($_SESSION["error_msg"])) {
  1110. $v_backup_password = "";
  1111. }
  1112. if (empty($_SESSION["error_msg"])) {
  1113. $v_backup_bpath = "";
  1114. }
  1115. if (empty($_SESSION["error_msg"])) {
  1116. $v_backup_bucket = "";
  1117. }
  1118. if (empty($_SESSION["error_msg"])) {
  1119. $v_backup_application_id = "";
  1120. }
  1121. if (empty($_SESSION["error_msg"])) {
  1122. $v_backup_application_key = "";
  1123. }
  1124. $v_backup_adv = "";
  1125. $v_backup_remote_adv = "";
  1126. }
  1127. }
  1128. // Change INACTIVE_SESSION_TIMEOUT
  1129. if (empty($_SESSION["error_msg"])) {
  1130. if ($_POST["v_inactive_session_timeout"] != $_SESSION["INACTIVE_SESSION_TIMEOUT"]) {
  1131. if ($_POST["v_inactive_session_timeout"] < 1) {
  1132. $_SESSION["error_msg"] = _("Inactive session timeout can not lower than 1 minute");
  1133. } else {
  1134. exec(
  1135. HESTIA_CMD .
  1136. "v-change-sys-config-value INACTIVE_SESSION_TIMEOUT " .
  1137. quoteshellarg($_POST["v_inactive_session_timeout"]),
  1138. $output,
  1139. $return_var,
  1140. );
  1141. check_return_code($return_var, $output);
  1142. unset($output);
  1143. if (empty($_SESSION["error_msg"])) {
  1144. $v_inactive_session_timeout = $_POST["v_inactive_session_timeout"];
  1145. }
  1146. }
  1147. $v_security_adv = "yes";
  1148. }
  1149. }
  1150. // Change POLICY_CSRF_STRICTNESS
  1151. if (empty($_SESSION["error_msg"])) {
  1152. if ($_POST["v_policy_csrf_strictness"] != $_SESSION["POLICY_CSRF_STRICTNESS"]) {
  1153. exec(
  1154. HESTIA_CMD .
  1155. "v-change-sys-config-value POLICY_CSRF_STRICTNESS " .
  1156. quoteshellarg($_POST["v_policy_csrf_strictness"]),
  1157. $output,
  1158. $return_var,
  1159. );
  1160. check_return_code($return_var, $output);
  1161. unset($output);
  1162. if (empty($_SESSION["error_msg"])) {
  1163. $v_policy_csrf_strictness = $_POST["v_inactive_session_timeout"];
  1164. }
  1165. $v_security_adv = "yes";
  1166. }
  1167. }
  1168. // Change ENFORCE_SUBDOMAIN_OWNERSHIP
  1169. if (empty($_SESSION["error_msg"])) {
  1170. if ($_POST["v_enforce_subdomain_ownership"] != $_SESSION["ENFORCE_SUBDOMAIN_OWNERSHIP"]) {
  1171. exec(
  1172. HESTIA_CMD .
  1173. "v-change-sys-config-value ENFORCE_SUBDOMAIN_OWNERSHIP " .
  1174. quoteshellarg($_POST["v_enforce_subdomain_ownership"]),
  1175. $output,
  1176. $return_var,
  1177. );
  1178. check_return_code($return_var, $output);
  1179. unset($output);
  1180. if (empty($_SESSION["error_msg"])) {
  1181. $v_enforce_subdomain_ownership = $_POST["v_enforce_subdomain_ownership"];
  1182. }
  1183. $v_security_adv = "yes";
  1184. }
  1185. }
  1186. // Change POLICY_USER_EDIT_DETAILS
  1187. if (empty($_SESSION["error_msg"])) {
  1188. if ($_POST["v_policy_user_edit_details"] != $_SESSION["POLICY_USER_EDIT_DETAILS"]) {
  1189. exec(
  1190. HESTIA_CMD .
  1191. "v-change-sys-config-value POLICY_USER_EDIT_DETAILS " .
  1192. quoteshellarg($_POST["v_policy_user_edit_details"]),
  1193. $output,
  1194. $return_var,
  1195. );
  1196. check_return_code($return_var, $output);
  1197. unset($output);
  1198. if (empty($_SESSION["error_msg"])) {
  1199. $v_policy_user_edit_details = $_POST["v_policy_user_edit_details"];
  1200. }
  1201. $v_security_adv = "yes";
  1202. }
  1203. }
  1204. // Change POLICY_USER_EDIT_WEB_TEMPLATES
  1205. if (empty($_SESSION["error_msg"])) {
  1206. if (
  1207. $_POST["v_policy_user_edit_web_templates"] !=
  1208. $_SESSION["POLICY_USER_EDIT_WEB_TEMPLATES"]
  1209. ) {
  1210. exec(
  1211. HESTIA_CMD .
  1212. "v-change-sys-config-value POLICY_USER_EDIT_WEB_TEMPLATES " .
  1213. quoteshellarg($_POST["v_policy_user_edit_web_templates"]),
  1214. $output,
  1215. $return_var,
  1216. );
  1217. check_return_code($return_var, $output);
  1218. unset($output);
  1219. if (empty($_SESSION["error_msg"])) {
  1220. $v_policy_user_edit_details = $_POST["v_policy_user_edit_web_templates"];
  1221. }
  1222. $v_security_adv = "yes";
  1223. }
  1224. }
  1225. // Change POLICY_USER_EDIT_DNS_TEMPLATES
  1226. if (empty($_SESSION["error_msg"])) {
  1227. if (
  1228. $_POST["v_policy_user_edit_dns_templates"] !=
  1229. $_SESSION["POLICY_USER_EDIT_DNS_TEMPLATES"]
  1230. ) {
  1231. exec(
  1232. HESTIA_CMD .
  1233. "v-change-sys-config-value POLICY_USER_EDIT_DNS_TEMPLATES " .
  1234. quoteshellarg($_POST["v_policy_user_edit_dns_templates"]),
  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_dns_templates"];
  1242. }
  1243. $v_security_adv = "yes";
  1244. }
  1245. }
  1246. if (
  1247. $_POST["v_api_system"] != $_SESSION["API_SYSTEM"] ||
  1248. $_POST["v_api"] != $_SESSION["API"] ||
  1249. $_POST["v_api_allowed_ip"] != $_SESSION["API_ALLOWED_IP"]
  1250. ) {
  1251. if (empty($_SESSION["error_msg"])) {
  1252. if ($_POST["v_api"] == "no" && $_POST["v_api_system"] === 0) {
  1253. exec(HESTIA_CMD . "v-change-sys-api 'disable'", $output, $return_var);
  1254. check_return_code($return_var, $output);
  1255. unset($output);
  1256. }
  1257. if (
  1258. $_POST["v_api"] == "yes" ||
  1259. ($_POST["v_api_system"] !== 0 &&
  1260. $_POST["v_api_system"] != $_SESSION["API_SYSTEM"]) ||
  1261. $_POST["v_api"] != $_SESSION["API"]
  1262. ) {
  1263. exec(HESTIA_CMD . "v-change-sys-api 'enable'", $output, $return_var);
  1264. check_return_code($return_var, $output);
  1265. unset($output);
  1266. }
  1267. }
  1268. if (empty($_SESSION["error_msg"])) {
  1269. if ($_POST["v_api_system"] != $_SESSION["API_SYSTEM"]) {
  1270. exec(
  1271. HESTIA_CMD .
  1272. "v-change-sys-config-value API_SYSTEM " .
  1273. quoteshellarg($_POST["v_api_system"]),
  1274. $output,
  1275. $return_var,
  1276. );
  1277. check_return_code($return_var, $output);
  1278. unset($output);
  1279. if (empty($_SESSION["error_msg"])) {
  1280. $v_policy_user_edit_details = $_POST["v_api_system"];
  1281. }
  1282. $v_security_adv = "yes";
  1283. }
  1284. }
  1285. // Change API access
  1286. if (empty($_SESSION["error_msg"])) {
  1287. if ($_POST["v_api"] != $_SESSION["API"]) {
  1288. $api_status = "no";
  1289. if ($_POST["v_api"] == "yes") {
  1290. $api_status = "yes";
  1291. }
  1292. exec(
  1293. HESTIA_CMD . "v-change-sys-config-value API " . quoteshellarg($api_status),
  1294. $output,
  1295. $return_var,
  1296. );
  1297. check_return_code($return_var, $output);
  1298. unset($output);
  1299. if (empty($_SESSION["error_msg"])) {
  1300. $v_api = $_POST["v_api"];
  1301. }
  1302. $v_security_adv = "yes";
  1303. }
  1304. }
  1305. // Change API allowed IPs
  1306. if (empty($_SESSION["error_msg"])) {
  1307. if ($_POST["v_api_allowed_ip"] != $_SESSION["API_ALLOWED_IP"]) {
  1308. $ips = [];
  1309. foreach (explode("\n", $_POST["v_api_allowed_ip"]) as $ip) {
  1310. if (trim($ip) != "allow-all") {
  1311. if (filter_var(trim($ip), FILTER_VALIDATE_IP)) {
  1312. $ips[] = trim($ip);
  1313. }
  1314. } else {
  1315. $ips[] = trim($ip);
  1316. }
  1317. }
  1318. if (implode(",", $ips) != $_SESSION["API_ALLOWED_IP"]) {
  1319. exec(
  1320. HESTIA_CMD .
  1321. "v-change-sys-config-value API_ALLOWED_IP " .
  1322. quoteshellarg(implode(",", $ips)),
  1323. $output,
  1324. $return_var,
  1325. );
  1326. check_return_code($return_var, $output);
  1327. unset($output);
  1328. if (empty($_SESSION["error_msg"])) {
  1329. $v_api_allowed_ip = $_POST["v_api_allowed_ip"];
  1330. }
  1331. $v_security_adv = "yes";
  1332. }
  1333. }
  1334. }
  1335. }
  1336. // Change POLICY_USER_VIEW_LOGS
  1337. if (empty($_SESSION["error_msg"])) {
  1338. if ($_POST["v_policy_user_view_logs"] != $_SESSION["POLICY_USER_VIEW_LOGS"]) {
  1339. exec(
  1340. HESTIA_CMD .
  1341. "v-change-sys-config-value POLICY_USER_VIEW_LOGS " .
  1342. quoteshellarg($_POST["v_policy_user_view_logs"]),
  1343. $output,
  1344. $return_var,
  1345. );
  1346. check_return_code($return_var, $output);
  1347. unset($output);
  1348. if (empty($_SESSION["error_msg"])) {
  1349. $v_policy_user_view_logs = $_POST["v_policy_user_view_logs"];
  1350. }
  1351. $v_security_adv = "yes";
  1352. }
  1353. }
  1354. // Change POLICY_USER_DELETE_LOGS
  1355. if (empty($_SESSION["error_msg"])) {
  1356. if ($_POST["v_policy_user_delete_logs"] != $_SESSION["POLICY_USER_DELETE_LOGS"]) {
  1357. exec(
  1358. HESTIA_CMD .
  1359. "v-change-sys-config-value POLICY_USER_DELETE_LOGS " .
  1360. quoteshellarg($_POST["v_policy_user_delete_logs"]),
  1361. $output,
  1362. $return_var,
  1363. );
  1364. check_return_code($return_var, $output);
  1365. unset($output);
  1366. if (empty($_SESSION["error_msg"])) {
  1367. $v_policy_user_delete_logs = $_POST["v_policy_user_delete_logs"];
  1368. }
  1369. $v_security_adv = "yes";
  1370. }
  1371. }
  1372. // Change POLICY_SYSTEM_PASSWORD_RESET
  1373. if (empty($_SESSION["error_msg"])) {
  1374. if ($_POST["v_policy_system_password_reset"] != $_SESSION["POLICY_SYSTEM_PASSWORD_RESET"]) {
  1375. exec(
  1376. HESTIA_CMD .
  1377. "v-change-sys-config-value POLICY_SYSTEM_PASSWORD_RESET " .
  1378. quoteshellarg($_POST["v_policy_system_password_reset"]),
  1379. $output,
  1380. $return_var,
  1381. );
  1382. check_return_code($return_var, $output);
  1383. unset($output);
  1384. if (empty($_SESSION["error_msg"])) {
  1385. $v_policy_system_password_reset = $_POST["v_policy_system_password_reset"];
  1386. }
  1387. $v_security_adv = "yes";
  1388. }
  1389. }
  1390. // Change POLICY_SYSTEM_PROTECTED_ADMIN
  1391. if (empty($_SESSION["error_msg"])) {
  1392. if (
  1393. $_POST["v_policy_system_protected_admin"] != $_SESSION["POLICY_SYSTEM_PROTECTED_ADMIN"]
  1394. ) {
  1395. exec(
  1396. HESTIA_CMD .
  1397. "v-change-sys-config-value POLICY_SYSTEM_PROTECTED_ADMIN " .
  1398. quoteshellarg($_POST["v_policy_system_protected_admin"]),
  1399. $output,
  1400. $return_var,
  1401. );
  1402. check_return_code($return_var, $output);
  1403. unset($output);
  1404. if (empty($_SESSION["error_msg"])) {
  1405. $v_policy_system_protected_admin = $_POST["v_policy_system_protected_admin"];
  1406. }
  1407. $v_security_adv = "yes";
  1408. }
  1409. }
  1410. // Change POLICY_USER_VIEW_SUSPENDED
  1411. if (empty($_SESSION["error_msg"])) {
  1412. if (
  1413. $_POST["v_policy_user_view_suspended"] != $_SESSION["POLICY_USER_VIEW_SUSPENDED"] &&
  1414. !empty($_SESSION["POLICY_USER_VIEW_SUSPENDED"])
  1415. ) {
  1416. exec(
  1417. HESTIA_CMD .
  1418. "v-change-sys-config-value POLICY_USER_VIEW_SUSPENDED " .
  1419. quoteshellarg($_POST["v_policy_user_view_suspended"]),
  1420. $output,
  1421. $return_var,
  1422. );
  1423. check_return_code($return_var, $output);
  1424. unset($output);
  1425. if (empty($_SESSION["error_msg"])) {
  1426. $v_policy_system_hide_admin = $_POST["v_policy_user_view_suspended"];
  1427. }
  1428. $v_security_adv = "yes";
  1429. }
  1430. }
  1431. // Change POLICY_USER_CHANGE_THEME
  1432. if (empty($_SESSION["error_msg"])) {
  1433. if (empty($_POST["v_policy_user_change_theme"])) {
  1434. $_POST["v_policy_user_change_theme"] = "";
  1435. }
  1436. if ($_POST["v_policy_user_change_theme"] == "on") {
  1437. $_POST["v_policy_user_change_theme"] = "no";
  1438. } else {
  1439. $_POST["v_policy_user_change_theme"] = "yes";
  1440. }
  1441. if ($_POST["v_policy_user_change_theme"] != $_SESSION["POLICY_USER_CHANGE_THEME"]) {
  1442. exec(
  1443. HESTIA_CMD .
  1444. "v-change-sys-config-value POLICY_USER_CHANGE_THEME " .
  1445. quoteshellarg($_POST["v_policy_user_change_theme"]),
  1446. $output,
  1447. $return_var,
  1448. );
  1449. check_return_code($return_var, $output);
  1450. unset($output);
  1451. if ($_POST["v_policy_user_change_theme"]) {
  1452. unset($_SESSION["userTheme"]);
  1453. $require_refresh = true;
  1454. }
  1455. if (empty($_SESSION["error_msg"])) {
  1456. $v_policy_user_change_theme = $_POST["v_policy_user_change_theme"];
  1457. }
  1458. }
  1459. }
  1460. // Change POLICY_SYSTEM_HIDE_ADMIN
  1461. if (empty($_SESSION["error_msg"])) {
  1462. if ($_POST["v_policy_system_hide_admin"] != $_SESSION["POLICY_SYSTEM_HIDE_ADMIN"]) {
  1463. exec(
  1464. HESTIA_CMD .
  1465. "v-change-sys-config-value POLICY_SYSTEM_HIDE_ADMIN " .
  1466. quoteshellarg($_POST["v_policy_system_hide_admin"]),
  1467. $output,
  1468. $return_var,
  1469. );
  1470. check_return_code($return_var, $output);
  1471. unset($output);
  1472. if (empty($_SESSION["error_msg"])) {
  1473. $v_policy_system_hide_admin = $_POST["v_policy_system_hide_admin"];
  1474. }
  1475. $v_security_adv = "yes";
  1476. }
  1477. }
  1478. // Change POLICY_SYSTEM_HIDE_SERVICES
  1479. if (empty($_SESSION["error_msg"])) {
  1480. if ($_POST["v_policy_system_hide_services"] != $_SESSION["POLICY_SYSTEM_HIDE_SERVICES"]) {
  1481. exec(
  1482. HESTIA_CMD .
  1483. "v-change-sys-config-value POLICY_SYSTEM_HIDE_SERVICES " .
  1484. quoteshellarg($_POST["v_policy_system_hide_services"]),
  1485. $output,
  1486. $return_var,
  1487. );
  1488. check_return_code($return_var, $output);
  1489. unset($output);
  1490. if (empty($_SESSION["error_msg"])) {
  1491. $v_policy_system_hide_services = $_POST["v_policy_system_hide_services"];
  1492. }
  1493. $v_security_adv = "yes";
  1494. }
  1495. }
  1496. // Change login style
  1497. if (empty($_SESSION["error_msg"])) {
  1498. if ($_POST["v_login_style"] != $_SESSION["LOGIN_STYLE"]) {
  1499. exec(
  1500. HESTIA_CMD .
  1501. "v-change-sys-config-value LOGIN_STYLE " .
  1502. quoteshellarg($_POST["v_login_style"]),
  1503. $output,
  1504. $return_var,
  1505. );
  1506. check_return_code($return_var, $output);
  1507. unset($output);
  1508. if (empty($_SESSION["error_msg"])) {
  1509. $v_login_style = $_POST["v_login_style"];
  1510. }
  1511. $v_security_adv = "yes";
  1512. }
  1513. }
  1514. // Update SSL certificate
  1515. if (!empty($_POST["v_ssl_crt"]) && empty($_SESSION["error_msg"])) {
  1516. if (
  1517. $v_ssl_crt != str_replace("\r\n", "\n", $_POST["v_ssl_crt"]) ||
  1518. $v_ssl_key != str_replace("\r\n", "\n", $_POST["v_ssl_key"])
  1519. ) {
  1520. exec("mktemp -d", $mktemp_output, $return_var);
  1521. $tmpdir = $mktemp_output[0];
  1522. // Certificate
  1523. if (!empty($_POST["v_ssl_crt"])) {
  1524. $fp = fopen($tmpdir . "/certificate.crt", "w");
  1525. fwrite($fp, str_replace("\r\n", "\n", $_POST["v_ssl_crt"]));
  1526. fwrite($fp, "\n");
  1527. fclose($fp);
  1528. }
  1529. // Key
  1530. if (!empty($_POST["v_ssl_key"])) {
  1531. $fp = fopen($tmpdir . "/certificate.key", "w");
  1532. fwrite($fp, str_replace("\r\n", "\n", $_POST["v_ssl_key"]));
  1533. fwrite($fp, "\n");
  1534. fclose($fp);
  1535. }
  1536. exec(HESTIA_CMD . "v-change-sys-hestia-ssl " . $tmpdir, $output, $return_var);
  1537. check_return_code($return_var, $output);
  1538. unset($output);
  1539. // List ssl certificate info
  1540. exec(HESTIA_CMD . "v-list-sys-hestia-ssl json", $output, $return_var);
  1541. $ssl_str = json_decode(implode("", $output), true);
  1542. unset($output);
  1543. $v_ssl_crt = $ssl_str["HESTIA"]["CRT"];
  1544. $v_ssl_key = $ssl_str["HESTIA"]["KEY"];
  1545. $v_ssl_ca = $ssl_str["HESTIA"]["CA"];
  1546. $v_ssl_subject = $ssl_str["HESTIA"]["SUBJECT"];
  1547. $v_ssl_aliases = $ssl_str["HESTIA"]["ALIASES"];
  1548. $v_ssl_not_before = $ssl_str["HESTIA"]["NOT_BEFORE"];
  1549. $v_ssl_not_after = $ssl_str["HESTIA"]["NOT_AFTER"];
  1550. $v_ssl_signature = $ssl_str["HESTIA"]["SIGNATURE"];
  1551. $v_ssl_pub_key = $ssl_str["HESTIA"]["PUB_KEY"];
  1552. $v_ssl_issuer = $ssl_str["HESTIA"]["ISSUER"];
  1553. // Cleanup certificate tempfiles
  1554. if (file_exists($tmpdir . "/certificate.crt")) {
  1555. unlink($tmpdir . "/certificate.crt");
  1556. }
  1557. if (file_exists($tmpdir . "/certificate.key")) {
  1558. unlink($tmpdir . "/certificate.key");
  1559. }
  1560. rmdir($tmpdir);
  1561. }
  1562. }
  1563. // Flush field values on success
  1564. if (empty($_SESSION["error_msg"])) {
  1565. $_SESSION["ok_msg"] = _("Changes has been saved.");
  1566. }
  1567. if ($require_refresh == true) {
  1568. $refresh = $_SERVER["REQUEST_URI"];
  1569. $_SESSION["ok_msg"] = _("Changes has been saved.");
  1570. header("Location: $refresh");
  1571. die();
  1572. }
  1573. }
  1574. // Check system configuration
  1575. exec(HESTIA_CMD . "v-list-sys-config json", $output, $return_var);
  1576. $data = json_decode(implode("", $output), true);
  1577. unset($output);
  1578. $sys_arr = $data["config"];
  1579. foreach ($sys_arr as $key => $value) {
  1580. $_SESSION[$key] = $value;
  1581. }
  1582. // Render page
  1583. render_page($user, $TAB, "edit_server");
  1584. // Flush session messages
  1585. unset($_SESSION["error_msg"]);
  1586. unset($_SESSION["ok_msg"]);