index.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704
  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. if (empty($_SESSION["error_msg"])) {
  1497. if ($_POST["v_policy_sync_error_documents"] != $_SESSION["POLICY_SYNC_ERROR_DOCUMENTS"]) {
  1498. exec(
  1499. HESTIA_CMD .
  1500. "v-change-sys-config-value POLICY_SYNC_ERROR_DOCUMENTS " .
  1501. quoteshellarg($_POST["v_policy_sync_error_documents"]),
  1502. $output,
  1503. $return_var,
  1504. );
  1505. check_return_code($return_var, $output);
  1506. unset($output);
  1507. if (empty($_SESSION["error_msg"])) {
  1508. $v_policy_system_hide_services = $_POST["v_policy_sync_error_documents"];
  1509. }
  1510. $v_security_adv = "yes";
  1511. }
  1512. }
  1513. if (empty($_SESSION["error_msg"])) {
  1514. if ($_POST["v_policy_sync_skeleton"] != $_SESSION["POLICY_SYNC_SKELETON"]) {
  1515. exec(
  1516. HESTIA_CMD .
  1517. "v-change-sys-config-value POLICY_SYNC_SKELETON " .
  1518. quoteshellarg($_POST["v_policy_sync_skeleton"]),
  1519. $output,
  1520. $return_var,
  1521. );
  1522. check_return_code($return_var, $output);
  1523. unset($output);
  1524. if (empty($_SESSION["error_msg"])) {
  1525. $v_policy_system_hide_services = $_POST["v_policy_sync_skeleton"];
  1526. }
  1527. $v_security_adv = "yes";
  1528. }
  1529. }
  1530. // Change login style
  1531. if (empty($_SESSION["error_msg"])) {
  1532. if ($_POST["v_login_style"] != $_SESSION["LOGIN_STYLE"]) {
  1533. exec(
  1534. HESTIA_CMD .
  1535. "v-change-sys-config-value LOGIN_STYLE " .
  1536. quoteshellarg($_POST["v_login_style"]),
  1537. $output,
  1538. $return_var,
  1539. );
  1540. check_return_code($return_var, $output);
  1541. unset($output);
  1542. if (empty($_SESSION["error_msg"])) {
  1543. $v_login_style = $_POST["v_login_style"];
  1544. }
  1545. $v_security_adv = "yes";
  1546. }
  1547. }
  1548. // Update SSL certificate
  1549. if (!empty($_POST["v_ssl_crt"]) && empty($_SESSION["error_msg"])) {
  1550. if (
  1551. $v_ssl_crt != str_replace("\r\n", "\n", $_POST["v_ssl_crt"]) ||
  1552. $v_ssl_key != str_replace("\r\n", "\n", $_POST["v_ssl_key"])
  1553. ) {
  1554. exec("mktemp -d", $mktemp_output, $return_var);
  1555. $tmpdir = $mktemp_output[0];
  1556. // Certificate
  1557. if (!empty($_POST["v_ssl_crt"])) {
  1558. $fp = fopen($tmpdir . "/certificate.crt", "w");
  1559. fwrite($fp, str_replace("\r\n", "\n", $_POST["v_ssl_crt"]));
  1560. fwrite($fp, "\n");
  1561. fclose($fp);
  1562. }
  1563. // Key
  1564. if (!empty($_POST["v_ssl_key"])) {
  1565. $fp = fopen($tmpdir . "/certificate.key", "w");
  1566. fwrite($fp, str_replace("\r\n", "\n", $_POST["v_ssl_key"]));
  1567. fwrite($fp, "\n");
  1568. fclose($fp);
  1569. }
  1570. exec(HESTIA_CMD . "v-change-sys-hestia-ssl " . $tmpdir, $output, $return_var);
  1571. check_return_code($return_var, $output);
  1572. unset($output);
  1573. // List ssl certificate info
  1574. exec(HESTIA_CMD . "v-list-sys-hestia-ssl json", $output, $return_var);
  1575. $ssl_str = json_decode(implode("", $output), true);
  1576. unset($output);
  1577. $v_ssl_crt = $ssl_str["HESTIA"]["CRT"];
  1578. $v_ssl_key = $ssl_str["HESTIA"]["KEY"];
  1579. $v_ssl_ca = $ssl_str["HESTIA"]["CA"];
  1580. $v_ssl_subject = $ssl_str["HESTIA"]["SUBJECT"];
  1581. $v_ssl_aliases = $ssl_str["HESTIA"]["ALIASES"];
  1582. $v_ssl_not_before = $ssl_str["HESTIA"]["NOT_BEFORE"];
  1583. $v_ssl_not_after = $ssl_str["HESTIA"]["NOT_AFTER"];
  1584. $v_ssl_signature = $ssl_str["HESTIA"]["SIGNATURE"];
  1585. $v_ssl_pub_key = $ssl_str["HESTIA"]["PUB_KEY"];
  1586. $v_ssl_issuer = $ssl_str["HESTIA"]["ISSUER"];
  1587. // Cleanup certificate tempfiles
  1588. if (file_exists($tmpdir . "/certificate.crt")) {
  1589. unlink($tmpdir . "/certificate.crt");
  1590. }
  1591. if (file_exists($tmpdir . "/certificate.key")) {
  1592. unlink($tmpdir . "/certificate.key");
  1593. }
  1594. rmdir($tmpdir);
  1595. }
  1596. }
  1597. // Flush field values on success
  1598. if (empty($_SESSION["error_msg"])) {
  1599. $_SESSION["ok_msg"] = _("Changes have been saved.");
  1600. }
  1601. if ($require_refresh == true) {
  1602. $refresh = $_SERVER["REQUEST_URI"];
  1603. $_SESSION["ok_msg"] = _("Changes have been saved.");
  1604. header("Location: $refresh");
  1605. die();
  1606. }
  1607. }
  1608. // Check system configuration
  1609. exec(HESTIA_CMD . "v-list-sys-config json", $output, $return_var);
  1610. $data = json_decode(implode("", $output), true);
  1611. unset($output);
  1612. $sys_arr = $data["config"];
  1613. foreach ($sys_arr as $key => $value) {
  1614. $_SESSION[$key] = $value;
  1615. }
  1616. // Render page
  1617. render_page($user, $TAB, "edit_server");
  1618. // Flush session messages
  1619. unset($_SESSION["error_msg"]);
  1620. unset($_SESSION["ok_msg"]);