index.php 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351
  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. $v_timezones = list_timezones();
  15. exec(HESTIA_CMD."v-get-sys-timezone", $output, $return_var);
  16. $v_timezone = $output[0];
  17. unset($output);
  18. if ($v_timezone == 'Etc/UTC') {
  19. $v_timezone = 'UTC';
  20. }
  21. if ($v_timezone == 'Pacific/Honolulu') {
  22. $v_timezone = 'HAST';
  23. }
  24. if ($v_timezone == 'US/Aleutian') {
  25. $v_timezone = 'HADT';
  26. }
  27. if ($v_timezone == 'Etc/GMT+9') {
  28. $v_timezone = 'AKST';
  29. }
  30. if ($v_timezone == 'America/Anchorage') {
  31. $v_timezone = 'AKDT';
  32. }
  33. if ($v_timezone == 'America/Dawson_Creek') {
  34. $v_timezone = 'PST';
  35. }
  36. if ($v_timezone == 'PST8PDT') {
  37. $v_timezone = 'PDT';
  38. }
  39. if ($v_timezone == 'MST7MDT') {
  40. $v_timezone = 'MDT';
  41. }
  42. if ($v_timezone == 'Canada/Saskatchewan') {
  43. $v_timezone = 'CST';
  44. }
  45. if ($v_timezone == 'CST6CDT') {
  46. $v_timezone = 'CDT';
  47. }
  48. if ($v_timezone == 'EST5EDT') {
  49. $v_timezone = 'EDT';
  50. }
  51. if ($v_timezone == 'America/Puerto_Rico') {
  52. $v_timezone = 'AST';
  53. }
  54. if ($v_timezone == 'America/Halifax') {
  55. $v_timezone = 'ADT';
  56. }
  57. // List supported php versions
  58. exec(HESTIA_CMD."v-list-web-templates-backend json", $output, $return_var);
  59. $backend_templates = json_decode(implode('', $output), true);
  60. unset($output);
  61. $v_php_versions = [
  62. 'php-5.6',
  63. 'php-7.0',
  64. 'php-7.1',
  65. 'php-7.2',
  66. 'php-7.3',
  67. 'php-7.4',
  68. 'php-8.0',
  69. 'php-8.1',
  70. ];
  71. sort($v_php_versions);
  72. if (empty($backend_templates)) {
  73. $v_php_versions=[];
  74. }
  75. $backends_active = backendtpl_with_webdomains();
  76. $v_php_versions = array_map(function ($php_version) use ($backend_templates, $backends_active) {
  77. // Mark installed php versions
  78. if (stripos($php_version, 'php') !== 0) {
  79. return false;
  80. }
  81. $phpinfo = (object) [
  82. "name" => $php_version,
  83. "tpl" => strtoupper(str_replace('.', '_', $php_version)),
  84. "version" => str_ireplace('php-', '', $php_version),
  85. "usedby" => [],
  86. "installed" => false,
  87. "protected" => false,
  88. ];
  89. if (in_array($phpinfo->tpl, $backend_templates)) {
  90. $phpinfo->installed = true;
  91. }
  92. if (array_key_exists($phpinfo->tpl, $backends_active)) {
  93. // Prevent used php version to be removed
  94. if ($phpinfo->installed) {
  95. $phpinfo->protected = true;
  96. }
  97. $phpinfo->usedby = $backends_active[$phpinfo->tpl];
  98. }
  99. if ($phpinfo->name == DEFAULT_PHP_VERSION) {
  100. // Prevent default php version to be removed
  101. if ($phpinfo->installed) {
  102. $phpinfo->protected = true;
  103. }
  104. if (!empty($backends_active['default'])) {
  105. $phpinfo->usedby = array_merge_recursive($phpinfo->usedby, $backends_active['default']);
  106. }
  107. }
  108. return $phpinfo;
  109. }, $v_php_versions);
  110. // List languages
  111. exec(HESTIA_CMD."v-list-sys-languages json", $output, $return_var);
  112. $language = json_decode(implode('', $output), true);
  113. foreach ($language as $lang) {
  114. $languages[$lang] = translate_json($lang);
  115. }
  116. asort($languages);
  117. unset($output);
  118. // List themes
  119. exec(HESTIA_CMD."v-list-sys-themes json", $output, $return_var);
  120. $theme = json_decode(implode('', $output), true);
  121. unset($output);
  122. // List dns cluster hosts
  123. exec(HESTIA_CMD."v-list-remote-dns-hosts json", $output, $return_var);
  124. $dns_cluster = json_decode(implode('', $output), true);
  125. unset($output);
  126. if (is_array($dns_cluster)) {
  127. foreach ($dns_cluster as $key => $value) {
  128. $v_dns_cluster = 'yes';
  129. }
  130. }
  131. if (empty($v_dns_cluster)) {
  132. $v_dns_cluster = '';
  133. }
  134. $v_release_branch = $_SESSION['RELEASE_BRANCH'];
  135. // List smtp relay settings
  136. if (!empty($_SESSION['SMTP_RELAY'])) {
  137. $v_smtp_relay = $_SESSION['SMTP_RELAY'];
  138. } else {
  139. $v_smtp_relay = '';
  140. }
  141. if (!empty($_SESSION['SMTP_RELAY_HOST'])) {
  142. $v_smtp_relay_host = $_SESSION['SMTP_RELAY_HOST'];
  143. } else {
  144. $v_smtp_relay_host = '';
  145. }
  146. if (!empty($_SESSION['SMTP_RELAY_PORT'])) {
  147. $v_smtp_relay_port = $_SESSION['SMTP_RELAY_PORT'];
  148. } else {
  149. $v_smtp_relay_port = '';
  150. }
  151. if (!empty($_SESSION['SMTP_RELAY_USER'])) {
  152. $v_smtp_relay_user = $_SESSION['SMTP_RELAY_USER'];
  153. } else {
  154. $v_smtp_relay_user = '';
  155. }
  156. $v_smtp_relay_pass = '';
  157. if (empty($_POST['v_experimental_features'])){
  158. $_POST['v_experimental_features'] = 'false';
  159. }
  160. if (empty($_POST['v_policy_user_view_suspended'])){
  161. $_POST['v_policy_user_view_suspended'] = 'false';
  162. }
  163. // List Database hosts
  164. exec(HESTIA_CMD."v-list-database-hosts json", $output, $return_var);
  165. $db_hosts = json_decode(implode('', $output), true);
  166. unset($output);
  167. $v_mysql_hosts = array_values(array_filter($db_hosts, function ($host) {
  168. return $host['TYPE'] === 'mysql';
  169. }));
  170. $v_mysql = count($v_mysql_hosts) ? 'yes' : 'no';
  171. $v_pgsql_hosts = array_values(array_filter($db_hosts, function ($host) {
  172. return $host['TYPE'] === 'pgsql';
  173. }));
  174. $v_pgsql = count($v_pgsql_hosts) ? 'yes' : 'no';
  175. unset($db_hosts);
  176. // List backup settings
  177. $v_backup_dir = "/backup";
  178. if (!empty($_SESSION['BACKUP'])) {
  179. $v_backup_dir = $_SESSION['BACKUP'];
  180. }
  181. $v_backup_gzip = '5';
  182. if (!empty($_SESSION['BACKUP_GZIP'])) {
  183. $v_backup_gzip = $_SESSION['BACKUP_GZIP'];
  184. }
  185. $v_backup_mode = 'gzip';
  186. if (!empty($_SESSION['BACKUP_MODE'])) {
  187. $v_backup_mode = $_SESSION['BACKUP_MODE'];
  188. }
  189. $backup_types = explode(",", $_SESSION['BACKUP_SYSTEM']);
  190. foreach ($backup_types as $backup_type) {
  191. if ($backup_type == 'local') {
  192. $v_backup = 'yes';
  193. } else {
  194. exec(HESTIA_CMD."v-list-backup-host ".quoteshellarg($backup_type)." json", $output, $return_var);
  195. $v_remote_backup = json_decode(implode('', $output), true);
  196. unset($output);
  197. if (in_array($backup_type, array('ftp','sftp'))) {
  198. $v_backup_host = $v_remote_backup[$backup_type]['HOST'];
  199. $v_backup_type = $v_remote_backup[$backup_type]['TYPE'];
  200. $v_backup_username = $v_remote_backup[$backup_type]['USERNAME'] ?? '';
  201. $v_backup_password = "";
  202. $v_backup_port = $v_remote_backup[$backup_type]['PORT'] ?? '';
  203. $v_backup_bpath = $v_remote_backup[$backup_type]['BPATH'];
  204. $v_backup_remote_adv = "yes";
  205. } elseif (in_array($backup_type, array('b2'))) {
  206. $v_backup_bucket = $v_remote_backup[$backup_type]['BUCKET'];
  207. $v_backup_type = $v_remote_backup[$backup_type]['TYPE'];
  208. $v_backup_application_id = $v_remote_backup[$backup_type]['B2_KEY_ID'];
  209. $v_backup_application_key = '';
  210. $v_backup_remote_adv = "yes";
  211. } elseif (in_array($backup_type, array('rclone'))) {
  212. $v_backup_type = $v_remote_backup[$backup_type]['TYPE'];
  213. $v_rclone_host = $v_remote_backup[$backup_type]['HOST'];
  214. $v_rclone_path = $v_remote_backup[$backup_type]['BPATH'];
  215. $v_backup_remote_adv = "yes";
  216. }
  217. }
  218. }
  219. if (empty($v_backup)) {
  220. $v_backup = '';
  221. }
  222. if (empty($v_backup_host)) {
  223. $v_backup_host = '';
  224. }
  225. if (empty($v_backup_type)) {
  226. $v_backup_type = '';
  227. }
  228. if (empty($v_backup_username)) {
  229. $v_backup_username = '';
  230. }
  231. if (empty($v_backup_password)) {
  232. $v_backup_password = '';
  233. }
  234. if (empty($v_backup_port)) {
  235. $v_backup_port = '';
  236. }
  237. if (empty($v_backup_bpath)) {
  238. $v_backup_bpath = '';
  239. }
  240. if (empty($v_backup_bucket)) {
  241. $v_backup_bucket = '';
  242. }
  243. if (empty($v_backup_application_id)) {
  244. $v_backup_application_id = '';
  245. }
  246. if (empty($v_backup_application_key)) {
  247. $v_backup_application_key = '';
  248. }
  249. if (empty($v_backup_remote_adv)) {
  250. $v_backup_remote_adv = '';
  251. }
  252. if (empty($v_rclone_host)) {
  253. $v_rclone_host = '';
  254. }
  255. if (empty($v_rclone_path)) {
  256. $v_rclone_path = '';
  257. }
  258. // List ssl certificate info
  259. exec(HESTIA_CMD."v-list-sys-hestia-ssl json", $output, $return_var);
  260. $ssl_str = json_decode(implode('', $output), true);
  261. unset($output);
  262. $v_ssl_crt = $ssl_str['HESTIA']['CRT'];
  263. $v_ssl_key = $ssl_str['HESTIA']['KEY'];
  264. $v_ssl_ca = $ssl_str['HESTIA']['CA'];
  265. $v_ssl_subject = $ssl_str['HESTIA']['SUBJECT'];
  266. $v_ssl_aliases = $ssl_str['HESTIA']['ALIASES'];
  267. $v_ssl_not_before = $ssl_str['HESTIA']['NOT_BEFORE'];
  268. $v_ssl_not_after = $ssl_str['HESTIA']['NOT_AFTER'];
  269. $v_ssl_signature = $ssl_str['HESTIA']['SIGNATURE'];
  270. $v_ssl_pub_key = $ssl_str['HESTIA']['PUB_KEY'];
  271. $v_ssl_issuer = $ssl_str['HESTIA']['ISSUER'];
  272. // Check POST request
  273. if (!empty($_POST['save'])) {
  274. $require_refresh = false;
  275. // Check token
  276. verify_csrf($_POST);
  277. // Change hostname
  278. if ((!empty($_POST['v_hostname'])) && ($v_hostname != $_POST['v_hostname'])) {
  279. exec(HESTIA_CMD."v-change-sys-hostname ".quoteshellarg($_POST['v_hostname']), $output, $return_var);
  280. check_return_code($return_var, $output);
  281. unset($output);
  282. $v_hostname = $_POST['v_hostname'];
  283. }
  284. if ($_SESSION['WEB_BACKEND'] == "php-fpm") {
  285. // Install/remove php versions
  286. if (empty($_SESSION['error_msg'])) {
  287. if (!empty($v_php_versions)) {
  288. $post_php = $_POST['v_php_versions'];
  289. if (empty($post_php)) {
  290. $post_php = array();
  291. }
  292. array_map(function ($php_version) use ($post_php) {
  293. if (array_key_exists($php_version->tpl, $post_php)) {
  294. if (!$php_version->installed) {
  295. exec(HESTIA_CMD . "v-add-web-php " . quoteshellarg($php_version->version), $output, $return_var);
  296. check_return_code($return_var, $output);
  297. unset($output);
  298. if (empty($_SESSION['error_msg'])) {
  299. $php_version->installed = true;
  300. }
  301. }
  302. } else {
  303. if ($php_version->installed && !$php_version->protected) {
  304. exec(HESTIA_CMD . "v-delete-web-php " . quoteshellarg($php_version->version), $output, $return_var);
  305. check_return_code($return_var, $output);
  306. unset($output);
  307. if (empty($_SESSION['error_msg'])) {
  308. $php_version->installed = false;
  309. }
  310. }
  311. }
  312. return $php_version;
  313. }, $v_php_versions);
  314. }
  315. }
  316. if (empty($_SESSION['error_msg'])) {
  317. if ('php-'.$_POST['v_php_default_version'] != DEFAULT_PHP_VERSION) {
  318. exec(HESTIA_CMD . "v-change-sys-php " . quoteshellarg($_POST['v_php_default_version']), $output, $return_var);
  319. check_return_code($return_var, $output);
  320. unset($output);
  321. //force reload
  322. $require_refresh = true;
  323. }
  324. }
  325. }
  326. // Change timezone
  327. if (empty($_SESSION['error_msg'])) {
  328. if (!empty($_POST['v_timezone'])) {
  329. $v_tz = $_POST['v_timezone'];
  330. if ($v_tz == 'UTC') {
  331. $v_tz = 'Etc/UTC';
  332. }
  333. if ($v_tz == 'HAST') {
  334. $v_tz = 'Pacific/Honolulu';
  335. }
  336. if ($v_tz == 'HADT') {
  337. $v_tz = 'US/Aleutian';
  338. }
  339. if ($v_tz == 'AKST') {
  340. $v_tz = 'Etc/GMT+9';
  341. }
  342. if ($v_tz == 'AKDT') {
  343. $v_tz = 'America/Anchorage';
  344. }
  345. if ($v_tz == 'PST') {
  346. $v_tz = 'America/Dawson_Creek';
  347. }
  348. if ($v_tz == 'PDT') {
  349. $v_tz = 'PST8PDT';
  350. }
  351. if ($v_tz == 'MDT') {
  352. $v_tz = 'MST7MDT';
  353. }
  354. if ($v_tz == 'CST') {
  355. $v_tz = 'Canada/Saskatchewan';
  356. }
  357. if ($v_tz == 'CDT') {
  358. $v_tz = 'CST6CDT';
  359. }
  360. if ($v_tz == 'EDT') {
  361. $v_tz = 'EST5EDT';
  362. }
  363. if ($v_tz == 'AST') {
  364. $v_tz = 'America/Puerto_Rico';
  365. }
  366. if ($v_tz == 'ADT') {
  367. $v_tz = 'America/Halifax';
  368. }
  369. if ($v_timezone != $v_tz) {
  370. exec(HESTIA_CMD."v-change-sys-timezone ".quoteshellarg($v_tz), $output, $return_var);
  371. check_return_code($return_var, $output);
  372. $v_timezone = $v_tz;
  373. unset($output);
  374. }
  375. }
  376. }
  377. // Change default language
  378. if (empty($_SESSION['error_msg'])) {
  379. if ((!empty($_POST['v_language'])) && ($_SESSION['LANGUAGE'] != $_POST['v_language'])) {
  380. if (isset($_POST['v_language_update'])) {
  381. exec(HESTIA_CMD."v-change-sys-language ".quoteshellarg($_POST['v_language'])." yes", $output, $return_var);
  382. if (empty($_SESSION['error_msg'])) {
  383. $_SESSION['LANGUAGE'] = $_POST['v_language'];
  384. }
  385. }
  386. exec(HESTIA_CMD."v-change-sys-language ".quoteshellarg($_POST['v_language']), $output, $return_var);
  387. check_return_code($return_var, $output);
  388. unset($output);
  389. if (empty($_SESSION['error_msg'])) {
  390. $_SESSION['LANGUAGE'] = $_POST['v_language'];
  391. }
  392. }
  393. }
  394. // Update theme
  395. if (empty($_SESSION['error_msg'])) {
  396. if ($_POST['v_theme'] != $_SESSION['THEME']) {
  397. exec(HESTIA_CMD."v-change-sys-config-value THEME ".quoteshellarg($_POST['v_theme']), $output, $return_var);
  398. check_return_code($return_var, $output);
  399. unset($output);
  400. }
  401. }
  402. // Update debug mode status
  403. if (empty($_SESSION['error_msg'])) {
  404. if ($_POST['v_debug_mode'] == 'on') {
  405. $_POST['v_debug_mode'] = 'true';
  406. } else {
  407. $_POST['v_debug_mode'] = 'false';
  408. }
  409. if ($_POST['v_debug_mode'] != $_SESSION['DEBUG_MODE']) {
  410. exec(HESTIA_CMD."v-change-sys-config-value DEBUG_MODE ".quoteshellarg($_POST['v_debug_mode']), $output, $return_var);
  411. check_return_code($return_var, $output);
  412. unset($output);
  413. $v_debug_mode_adv = 'yes';
  414. }
  415. }
  416. // Enable/Disable Quick App Installer
  417. if (empty($_SESSION['error_msg'])) {
  418. if ($_POST['v_plugin_app_installer'] != $_SESSION['PLUGIN_APP_INSTALLER']) {
  419. if ($_POST['v_plugin_app_installer'] == 'true') {
  420. $_POST['v_plugin_app_installer'] = 'true';
  421. } else {
  422. $_POST['v_plugin_app_installer'] = 'false';
  423. }
  424. exec(HESTIA_CMD."v-change-sys-config-value PLUGIN_APP_INSTALLER ".quoteshellarg($_POST['v_plugin_app_installer']), $output, $return_var);
  425. check_return_code($return_var, $output);
  426. unset($output);
  427. }
  428. }
  429. // Update experimental features status
  430. if (empty($_SESSION['error_msg']) && $_POST['v_experimental_features'] != $_SESSION['POLICY_SYSTEM_ENABLE_BACON']) {
  431. if ($_POST['v_experimental_features'] == 'on') {
  432. $_POST['v_experimental_features'] = 'true';
  433. } else {
  434. $_POST['v_experimental_features'] = 'false';
  435. }
  436. if ($_POST['v_experimental_features'] != $_SESSION['POLICY_SYSTEM_ENABLE_BACON']) {
  437. exec(HESTIA_CMD."v-change-sys-config-value POLICY_SYSTEM_ENABLE_BACON ".quoteshellarg($_POST['v_experimental_features']), $output, $return_var);
  438. check_return_code($return_var, $output);
  439. unset($output);
  440. $v_debug_mode_adv = 'yes';
  441. }
  442. if (($_POST['v_policy_user_view_suspended'] != $_SESSION['POLICY_SYSTEM_ENABLE_BACON']) && $_POST['v_experimental_features'] == "false") {
  443. //disable preview mode
  444. exec(HESTIA_CMD."v-change-sys-config-value POLICY_USER_VIEW_SUSPENDED ".quoteshellarg($_POST['v_policy_user_view_suspended']), $output, $return_var);
  445. check_return_code($return_var, $output);
  446. unset($output);
  447. }
  448. }
  449. // Set File Manager support
  450. if (empty($_SESSION['error_msg'])) {
  451. if ((!empty($_POST['v_filemanager'])) && ($_SESSION['FILE_MANAGER'] != $_POST['v_filemanager'])) {
  452. if ($_POST['v_filemanager'] == 'true') {
  453. exec(HESTIA_CMD."v-add-sys-filemanager", $output, $return_var);
  454. check_return_code($return_var, $output);
  455. unset($output);
  456. if (empty($_SESSION['error_msg'])) {
  457. $_SESSION['FILE_MANAGER'] = 'true';
  458. }
  459. } else {
  460. exec(HESTIA_CMD."v-delete-sys-filemanager", $output, $return_var);
  461. check_return_code($return_var, $output);
  462. unset($output);
  463. if (empty($_SESSION['error_msg'])) {
  464. $_SESSION['FILE_MANAGER'] = 'false';
  465. }
  466. }
  467. }
  468. }
  469. // Set phpMyAdmin SSO key
  470. if (empty($_SESSION['error_msg'])) {
  471. if (!empty($_POST['v_phpmyadmin_key'])) {
  472. if ($_POST['v_phpmyadmin_key'] == 'yes' && $_SESSION['PHPMYADMIN_KEY'] == '') {
  473. exec(HESTIA_CMD."v-add-sys-pma-sso quiet", $output, $return_var);
  474. check_return_code($return_var, $output);
  475. unset($output);
  476. if (empty($_SESSION['error_msg'])) {
  477. $_SESSION['PHPMYADMIN_KEY'] != "";
  478. }
  479. } elseif ($_POST['v_phpmyadmin_key'] == 'no' && $_SESSION['PHPMYADMIN_KEY'] != '') {
  480. exec(HESTIA_CMD."v-delete-sys-pma-sso quiet", $output, $return_var);
  481. check_return_code($return_var, $output);
  482. unset($output);
  483. if (empty($_SESSION['error_msg'])) {
  484. $_SESSION['PHPMYADMIN_KEY'] = '';
  485. }
  486. }
  487. }
  488. }
  489. // Set disk_quota support
  490. if (empty($_SESSION['error_msg'])) {
  491. if ((!empty($_POST['v_quota'])) && ($_SESSION['DISK_QUOTA'] != $_POST['v_quota'])) {
  492. if ($_POST['v_quota'] == 'yes') {
  493. exec(HESTIA_CMD."v-add-sys-quota", $output, $return_var);
  494. check_return_code($return_var, $output);
  495. unset($output);
  496. if (empty($_SESSION['error_msg'])) {
  497. $_SESSION['DISK_QUOTA'] = 'yes';
  498. }
  499. } else {
  500. exec(HESTIA_CMD."v-delete-sys-quota", $output, $return_var);
  501. check_return_code($return_var, $output);
  502. unset($output);
  503. if (empty($_SESSION['error_msg'])) {
  504. $_SESSION['DISK_QUOTA'] = 'no';
  505. }
  506. }
  507. }
  508. }
  509. // Set firewall support
  510. if (empty($_SESSION['error_msg'])) {
  511. if ($_SESSION['FIREWALL_SYSTEM'] == 'iptables') {
  512. $v_firewall = 'yes';
  513. }
  514. if ($_SESSION['FIREWALL_SYSTEM'] != 'iptables') {
  515. $v_firewall = 'no';
  516. }
  517. if ((!empty($_POST['v_firewall'])) && ($v_firewall != $_POST['v_firewall'])) {
  518. if ($_POST['v_firewall'] == 'yes') {
  519. exec(HESTIA_CMD."v-add-sys-firewall", $output, $return_var);
  520. check_return_code($return_var, $output);
  521. unset($output);
  522. if (empty($_SESSION['error_msg'])) {
  523. $_SESSION['FIREWALL_SYSTEM'] = 'iptables';
  524. }
  525. } else {
  526. exec(HESTIA_CMD."v-delete-sys-firewall", $output, $return_var);
  527. check_return_code($return_var, $output);
  528. unset($output);
  529. if (empty($_SESSION['error_msg'])) {
  530. $_SESSION['FIREWALL_SYSTEM'] = '';
  531. }
  532. }
  533. }
  534. }
  535. // Update mysql pasword
  536. if (empty($_SESSION['error_msg'])) {
  537. if (!empty($_POST['v_mysql_password'])) {
  538. exec(HESTIA_CMD."v-change-database-host-password mysql localhost root ".quoteshellarg($_POST['v_mysql_password']), $output, $return_var);
  539. check_return_code($return_var, $output);
  540. unset($output);
  541. $v_db_adv = 'yes';
  542. }
  543. }
  544. // Update webmail url
  545. if (empty($_SESSION['error_msg'])) {
  546. if ($_POST['v_webmail_alias'] != $_SESSION['WEBMAIL_ALIAS']) {
  547. exec(HESTIA_CMD."v-change-sys-webmail ".quoteshellarg($_POST['v_webmail_alias']), $output, $return_var);
  548. check_return_code($return_var, $output);
  549. unset($output);
  550. $v_mail_adv = 'yes';
  551. }
  552. }
  553. // Update system wide smtp relay
  554. if (empty($_SESSION['error_msg'])) {
  555. if (isset($_POST['v_smtp_relay']) && !empty($_POST['v_smtp_relay_host'])) {
  556. if (($_POST['v_smtp_relay_host'] != $v_smtp_relay_host) ||
  557. ($_POST['v_smtp_relay_user'] != $v_smtp_relay_user) ||
  558. ($_POST['v_smtp_relay_port'] != $v_smtp_relay_port)) {
  559. $v_smtp_relay = true;
  560. $v_smtp_relay_host = quoteshellarg($_POST['v_smtp_relay_host']);
  561. $v_smtp_relay_user = quoteshellarg($_POST['v_smtp_relay_user']);
  562. $v_smtp_relay_pass = quoteshellarg($_POST['v_smtp_relay_pass']);
  563. if (!empty($_POST['v_smtp_relay_port'])) {
  564. $v_smtp_relay_port = quoteshellarg($_POST['v_smtp_relay_port']);
  565. } else {
  566. $v_smtp_relay_port = '587';
  567. }
  568. exec(HESTIA_CMD."v-add-sys-smtp-relay ".$v_smtp_relay_host." ".$v_smtp_relay_user." ".$v_smtp_relay_pass." ".$v_smtp_relay_port, $output, $return_var);
  569. check_return_code($return_var, $output);
  570. unset($output);
  571. }
  572. }
  573. if ((!isset($_POST['v_smtp_relay'])) && ($v_smtp_relay == true)) {
  574. $v_smtp_relay = false;
  575. $v_smtp_relay_host = $v_smtp_relay_user = $v_smtp_relay_pass = $v_smtp_relay_port = '';
  576. exec(HESTIA_CMD."v-delete-sys-smtp-relay", $output, $return_var);
  577. check_return_code($return_var, $output);
  578. unset($output);
  579. }
  580. }
  581. // Update phpMyAdmin url
  582. if (empty($_SESSION['error_msg'])) {
  583. if ($_POST['v_mysql_url'] != $_SESSION['DB_PMA_ALIAS']) {
  584. exec(HESTIA_CMD."v-change-sys-db-alias pma ".quoteshellarg($_POST['v_mysql_url']), $output, $return_var);
  585. check_return_code($return_var, $output);
  586. unset($output);
  587. $v_db_adv = 'yes';
  588. }
  589. }
  590. // Update phpPgAdmin url
  591. if (empty($_SESSION['error_msg'])) {
  592. if ($_POST['v_pgsql_url'] != $_SESSION['DB_PGA_ALIAS']) {
  593. exec(HESTIA_CMD."v-change-sys-db-alias pga ".quoteshellarg($_POST['v_pgsql_url']), $output, $return_var);
  594. check_return_code($return_var, $output);
  595. unset($output);
  596. $v_db_adv = 'yes';
  597. }
  598. }
  599. // Update send notification setting
  600. if (empty($_SESSION['error_msg'])) {
  601. if ($_SESSION['UPGRADE_SEND_EMAIL'] == 'true') {
  602. $ugrade_send_mail = 'on';
  603. } else {
  604. $ugrade_send_mail = '';
  605. }
  606. if ($_POST['v_upgrade_send_notification_email'] != $ugrade_send_mail) {
  607. if ($_POST['v_upgrade_send_notification_email'] == 'on') {
  608. $_POST['v_upgrade_send_notification_email'] = 'true';
  609. } else {
  610. $_POST['v_upgrade_send_notification_email'] = 'false';
  611. }
  612. exec(HESTIA_CMD."v-change-sys-config-value UPGRADE_SEND_EMAIL ".quoteshellarg($_POST['v_upgrade_send_notification_email']), $output, $return_var);
  613. check_return_code($return_var, $output);
  614. unset($output);
  615. $v_upgrade_notification_adv = 'yes';
  616. }
  617. }
  618. // Update send log by email setting
  619. if (empty($_SESSION['error_msg'])) {
  620. if ($_SESSION['UPGRADE_SEND_EMAIL_LOG'] == 'true') {
  621. $send_email_log = 'on';
  622. } else {
  623. $send_email_log = '';
  624. }
  625. if (empty($_POST['v_upgrade_send_email_log'])) {
  626. $_POST['v_upgrade_send_email_log'] = '';
  627. }
  628. if ($_POST['v_upgrade_send_email_log'] != $send_email_log) {
  629. if ($_POST['v_upgrade_send_email_log'] == 'on') {
  630. $_POST['v_upgrade_send_email_log'] = 'true';
  631. } else {
  632. $_POST['v_upgrade_send_email_log'] = 'false';
  633. }
  634. exec(HESTIA_CMD."v-change-sys-config-value UPGRADE_SEND_EMAIL_LOG ".quoteshellarg($_POST['v_upgrade_send_email_log']), $output, $return_var);
  635. check_return_code($return_var, $output);
  636. unset($output);
  637. $v_upgrade_send_log_adv = 'yes';
  638. }
  639. }
  640. // Disable local backup
  641. if (empty($_SESSION['error_msg'])) {
  642. if (($_POST['v_backup'] == 'no') && ($v_backup == 'yes')) {
  643. exec(HESTIA_CMD."v-delete-backup-host local", $output, $return_var);
  644. check_return_code($return_var, $output);
  645. unset($output);
  646. if (empty($_SESSION['error_msg'])) {
  647. $v_backup = 'no';
  648. }
  649. $v_backup_adv = 'yes';
  650. }
  651. }
  652. // Enable local backups
  653. if (empty($_SESSION['error_msg'])) {
  654. if (($_POST['v_backup'] == 'yes') && ($v_backup != 'yes')) {
  655. exec(HESTIA_CMD."v-add-backup-host local", $output, $return_var);
  656. check_return_code($return_var, $output);
  657. unset($output);
  658. if (empty($_SESSION['error_msg'])) {
  659. $v_backup = 'yes';
  660. }
  661. $v_backup_adv = 'yes';
  662. }
  663. }
  664. // Change backup gzip level
  665. if (empty($_SESSION['error_msg'])) {
  666. if ($_POST['v_backup_gzip'] != $v_backup_gzip) {
  667. if ($_POST['v_backup_mode'] == 'gzip') {
  668. $_POST['v_backup_gzip'] = 9;
  669. }
  670. exec(HESTIA_CMD."v-change-sys-config-value BACKUP_GZIP ".quoteshellarg($_POST['v_backup_gzip']), $output, $return_var);
  671. check_return_code($return_var, $output);
  672. unset($output);
  673. if (empty($_SESSION['error_msg'])) {
  674. $v_backup_gzip = $_POST['v_backup_gzip'];
  675. }
  676. $v_backup_adv = 'yes';
  677. }
  678. }
  679. // Change backup mode
  680. if (empty($_SESSION['error_msg'])) {
  681. if ($_POST['v_backup_mode'] != $v_backup_mode) {
  682. exec(HESTIA_CMD."v-change-sys-config-value BACKUP_MODE ".quoteshellarg($_POST['v_backup_mode']), $output, $return_var);
  683. check_return_code($return_var, $output);
  684. unset($output);
  685. if (empty($_SESSION['error_msg'])) {
  686. $v_backup_mode = $_POST['v_backup_mode'];
  687. }
  688. $v_backup_adv = 'yes';
  689. if ($_POST['v_backup_mode'] == 'gzip') {
  690. $_POST['v_backup_gzip'] = 9;
  691. if (empty($_SESSION['error_msg'])) {
  692. $v_backup_gzip = $_POST['v_backup_gzip'];
  693. }
  694. exec(HESTIA_CMD."v-change-sys-config-value BACKUP_GZIP ".quoteshellarg($_POST['v_backup_gzip']), $output, $return_var);
  695. }
  696. }
  697. }
  698. // Change backup path
  699. if (empty($_SESSION['error_msg'])) {
  700. if (empty($_POST['v_backup_dir'])) {
  701. $_POST['v_backup_dir'] = '';
  702. }
  703. if ($_POST['v_backup_dir'] != $v_backup_dir) {
  704. /*
  705. See #1655
  706. exec (HESTIA_CMD."v-change-sys-config-value BACKUP ".quoteshellarg($_POST['v_backup_dir']), $output, $return_var);
  707. check_return_code($return_var,$output);
  708. unset($output);
  709. */
  710. if (empty($_SESSION['error_msg'])) {
  711. $v_backup_dir = $_POST['v_backup_dir'];
  712. }
  713. #$v_backup_adv = 'yes';
  714. }
  715. }
  716. // Add remote backup host
  717. if (empty($_SESSION['error_msg'])) {
  718. if (($v_backup_host == '' && $v_backup_bucket == '' && ((!empty($_POST['v_backup_host'])) || !empty($_POST['v_backup_bucket'])))) {
  719. if (in_array($_POST['v_backup_type'], array('ftp','sftp'))) {
  720. $v_backup_host = quoteshellarg($_POST['v_backup_host']);
  721. $v_backup_port = quoteshellarg($_POST['v_backup_port']);
  722. $v_backup_type = quoteshellarg($_POST['v_backup_type']);
  723. $v_backup_username = quoteshellarg($_POST['v_backup_username']);
  724. $v_backup_password = quoteshellarg($_POST['v_backup_password']);
  725. $v_backup_bpath = quoteshellarg($_POST['v_backup_bpath']);
  726. exec(HESTIA_CMD."v-add-backup-host ". $v_backup_type ." ". $v_backup_host ." ". $v_backup_username ." ". $v_backup_password ." ". $v_backup_bpath." ".$v_backup_port, $output, $return_var);
  727. check_return_code($return_var, $output);
  728. unset($output);
  729. if (empty($_SESSION['error_msg'])) {
  730. $v_backup_host = $_POST['v_backup_host'];
  731. }
  732. if (empty($_SESSION['error_msg'])) {
  733. $v_backup_type = $_POST['v_backup_type'];
  734. }
  735. if (empty($_SESSION['error_msg'])) {
  736. $v_backup_username = $_POST['v_backup_username'];
  737. }
  738. if (empty($_SESSION['error_msg'])) {
  739. $v_backup_password = $_POST['v_backup_password'];
  740. }
  741. if (empty($_SESSION['error_msg'])) {
  742. $v_backup_bpath = $_POST['v_backup_bpath'];
  743. }
  744. if (empty($_SESSION['error_msg'])) {
  745. $v_backup_port = $_POST['v_backup_port'];
  746. }
  747. $v_backup_new = 'yes';
  748. $v_backup_adv = 'yes';
  749. $v_backup_remote_adv = 'yes';
  750. } elseif (in_array($_POST['v_backup_type'], array('b2'))) {
  751. $v_backup_type = quoteshellarg($_POST['v_backup_type']);
  752. $v_backup_bucket = quoteshellarg($_POST['v_backup_bucket']);
  753. $v_backup_application_id = quoteshellarg($_POST['v_backup_application_id']);
  754. $v_backup_application_key = quoteshellarg($_POST['v_backup_application_key']);
  755. exec(HESTIA_CMD."v-add-backup-host ". $v_backup_type ." ". $v_backup_bucket ." ". $v_backup_application_id ." ". $v_backup_application_key, $output, $return_var);
  756. check_return_code($return_var, $output);
  757. unset($output);
  758. if (empty($_SESSION['error_msg'])) {
  759. $v_backup_bucket = quoteshellarg($_POST['v_backup_bucket']);
  760. }
  761. if (empty($_SESSION['error_msg'])) {
  762. $v_backup_application_id = quoteshellarg($_POST['v_backup_application_id']);
  763. }
  764. if (empty($_SESSION['error_msg'])) {
  765. $v_backup_application_key = quoteshellarg($_POST['v_backup_application_key']);
  766. }
  767. $v_backup_new = 'yes';
  768. $v_backup_adv = 'yes';
  769. $v_backup_remote_adv = 'yes';
  770. }
  771. }
  772. if ($v_rclone_host == '' && !empty($_POST['v_rclone_host']) && $_POST['v_backup_type'] =="rclone" ) {
  773. $v_rclone_host = quoteshellarg($_POST['v_rclone_host']);
  774. $v_backup_type = quoteshellarg($_POST['v_backup_type']);
  775. $v_rclone_path = quoteshellarg($_POST['v_rclone_path']);
  776. exec(HESTIA_CMD."v-add-backup-host ". $v_backup_type ." ". $v_rclone_host ." '' '' ".$v_rclone_path, $output, $return_var);
  777. check_return_code($return_var, $output);
  778. unset($output);
  779. $v_backup_new = 'yes';
  780. $v_backup_adv = 'yes';
  781. $v_backup_remote_adv = 'yes';
  782. }
  783. }
  784. // Change remote backup host type
  785. if (empty($_SESSION['error_msg'])) {
  786. if ((!empty($_POST['v_backup_host'])) && ($_POST['v_backup_type'] != $v_backup_type) && $v_backup_type != '') {
  787. exec(HESTIA_CMD."v-delete-backup-host " . quoteshellarg($v_backup_type), $output, $return_var);
  788. unset($output);
  789. if (in_array($_POST['v_backup_type'], array('ftp','sftp'))) {
  790. $v_backup_host = quoteshellarg($_POST['v_backup_host']);
  791. $v_backup_port = quoteshellarg($_POST['v_backup_port']);
  792. $v_backup_type = quoteshellarg($_POST['v_backup_type']);
  793. $v_backup_username = quoteshellarg($_POST['v_backup_username']);
  794. $v_backup_password = quoteshellarg($_POST['v_backup_password']);
  795. $v_backup_bpath = quoteshellarg($_POST['v_backup_bpath']);
  796. exec(HESTIA_CMD."v-add-backup-host ". $v_backup_type ." ". $v_backup_host ." ". $v_backup_username ." ". $v_backup_password ." ". $v_backup_bpath." ".$v_backup_port, $output, $return_var);
  797. check_return_code($return_var, $output);
  798. unset($output);
  799. if (empty($_SESSION['error_msg'])) {
  800. $v_backup_host = $_POST['v_backup_host'];
  801. }
  802. if (empty($_SESSION['error_msg'])) {
  803. $v_backup_type = $_POST['v_backup_type'];
  804. }
  805. if (empty($_SESSION['error_msg'])) {
  806. $v_backup_username = $_POST['v_backup_username'];
  807. }
  808. if (empty($_SESSION['error_msg'])) {
  809. $v_backup_password = $_POST['v_backup_password'];
  810. }
  811. if (empty($_SESSION['error_msg'])) {
  812. $v_backup_bpath = $_POST['v_backup_bpath'];
  813. }
  814. if (empty($_SESSION['error_msg'])) {
  815. $v_backup_port = $_POST['v_backup_port'];
  816. }
  817. $v_backup_adv = 'yes';
  818. $v_backup_remote_adv = 'yes';
  819. } elseif (in_array($_POST['v_backup_type'], array('b2'))) {
  820. $v_backup_bucket = quoteshellarg($_POST['v_backup_bucket']);
  821. $v_backup_application_id = quoteshellarg($_POST['v_backup_application_id']);
  822. $v_backup_application_key = quoteshellarg($_POST['v_backup_application_key']);
  823. exec(HESTIA_CMD."v-add-backup-host ". $v_backup_type ." ". $v_backup_bucket ." ". $v_backup_application_id ." ". $v_backup_application_key, $output, $return_var);
  824. check_return_code($return_var, $output);
  825. unset($output);
  826. $v_backup_type = quoteshellarg($_POST['v_backup_type']);
  827. if (empty($_SESSION['error_msg'])) {
  828. $v_backup_bucket = quoteshellarg($_POST['v_backup_bucket']);
  829. }
  830. if (empty($_SESSION['error_msg'])) {
  831. $v_backup_application_id = quoteshellarg($_POST['v_backup_application_id']);
  832. }
  833. if (empty($_SESSION['error_msg'])) {
  834. $v_backup_application_key = quoteshellarg($_POST['v_backup_application_key']);
  835. }
  836. $v_backup_adv = 'yes';
  837. $v_backup_remote_adv = 'yes';
  838. }
  839. }
  840. }
  841. // Change remote backup host
  842. if (empty($_SESSION['error_msg'])) {
  843. if ((!empty($_POST['v_backup_host'])) && ($_POST['v_backup_type'] == $v_backup_type) && (!isset($v_backup_new))) {
  844. if (in_array($_POST['v_backup_type'], array('ftp','sftp'))) {
  845. if (($_POST['v_backup_host'] != $v_backup_host) || ($_POST['v_backup_username'] != $v_backup_username) || ($_POST['v_backup_password'] != $v_backup_password) || ($_POST['v_backup_bpath'] != $v_backup_bpath || $_POST['v_backup_port'] != $v_backup_port)) {
  846. $v_backup_host = quoteshellarg($_POST['v_backup_host']);
  847. $v_backup_port = quoteshellarg($_POST['v_backup_port']);
  848. $v_backup_type = quoteshellarg($_POST['v_backup_type']);
  849. $v_backup_username = quoteshellarg($_POST['v_backup_username']);
  850. $v_backup_password = quoteshellarg($_POST['v_backup_password']);
  851. $v_backup_bpath = quoteshellarg($_POST['v_backup_bpath']);
  852. exec(HESTIA_CMD."v-add-backup-host ". $v_backup_type ." ". $v_backup_host ." ". $v_backup_username ." ". $v_backup_password ." ". $v_backup_bpath." ".$v_backup_port, $output, $return_var);
  853. check_return_code($return_var, $output);
  854. unset($output);
  855. if (empty($_SESSION['error_msg'])) {
  856. $v_backup_host = $_POST['v_backup_host'];
  857. }
  858. if (empty($_SESSION['error_msg'])) {
  859. $v_backup_type = $_POST['v_backup_type'];
  860. }
  861. if (empty($_SESSION['error_msg'])) {
  862. $v_backup_username = $_POST['v_backup_username'];
  863. }
  864. if (empty($_SESSION['error_msg'])) {
  865. $v_backup_password = $_POST['v_backup_password'];
  866. }
  867. if (empty($_SESSION['error_msg'])) {
  868. $v_backup_bpath = $_POST['v_backup_bpath'];
  869. }
  870. if (empty($_SESSION['error_msg'])) {
  871. $v_backup_port = $_POST['v_backup_port'];
  872. }
  873. $v_backup_adv = 'yes';
  874. $v_backup_remote_adv = 'yes';
  875. }
  876. } elseif (in_array($_POST['v_backup_type'], array('b2'))) {
  877. if (($_POST['v_backup_bucket'] != $v_backup_bucket) || ($_POST['v_backup_application_key'] != $v_backup_application_key) || ($_POST['v_backup_application_id'] != $v_backup_application_id)) {
  878. $v_backup_type = quoteshellarg($_POST['v_backup_type']);
  879. $v_backup_bucket = quoteshellarg($_POST['v_backup_bucket']);
  880. $v_backup_application_id = quoteshellarg($_POST['v_backup_application_id']);
  881. $v_backup_application_key = quoteshellarg($_POST['v_backup_application_key']);
  882. exec(HESTIA_CMD."v-add-backup-host ". $v_backup_type ." ". $v_backup_bucket ." ". $v_backup_application_id ." ". $v_backup_application_key, $output, $return_var);
  883. check_return_code($return_var, $output);
  884. unset($output);
  885. if (empty($_SESSION['error_msg'])) {
  886. $v_backup_bucket = quoteshellarg($_POST['v_backup_bucket']);
  887. }
  888. if (empty($_SESSION['error_msg'])) {
  889. $v_backup_application_id = quoteshellarg($_POST['v_backup_application_id']);
  890. }
  891. if (empty($_SESSION['error_msg'])) {
  892. $v_backup_application_key = quoteshellarg($_POST['v_backup_application_key']);
  893. }
  894. $v_backup_adv = 'yes';
  895. $v_backup_remote_adv = 'yes';
  896. }
  897. }
  898. }
  899. }
  900. // Delete remote backup host
  901. if (empty($_SESSION['error_msg'])) {
  902. if (empty($_POST['v_backup_remote_adv']) && $v_backup_remote_adv != '') {
  903. exec(HESTIA_CMD."v-delete-backup-host ".quoteshellarg($v_backup_type), $output, $return_var);
  904. check_return_code($return_var, $output);
  905. unset($output);
  906. if (empty($_SESSION['error_msg'])) {
  907. $v_backup_host = '';
  908. }
  909. if (empty($_SESSION['error_msg'])) {
  910. $v_backup_type = '';
  911. }
  912. if (empty($_SESSION['error_msg'])) {
  913. $v_backup_username = '';
  914. }
  915. if (empty($_SESSION['error_msg'])) {
  916. $v_backup_password = '';
  917. }
  918. if (empty($_SESSION['error_msg'])) {
  919. $v_backup_bpath = '';
  920. }
  921. if (empty($_SESSION['error_msg'])) {
  922. $v_backup_bucket = '';
  923. }
  924. if (empty($_SESSION['error_msg'])) {
  925. $v_backup_application_id = '';
  926. }
  927. if (empty($_SESSION['error_msg'])) {
  928. $v_backup_application_key = '';
  929. }
  930. $v_backup_adv = '';
  931. $v_backup_remote_adv = '';
  932. }
  933. }
  934. // Change INACTIVE_SESSION_TIMEOUT
  935. if (empty($_SESSION['error_msg'])) {
  936. if ($_POST['v_inactive_session_timeout'] != $_SESSION['INACTIVE_SESSION_TIMEOUT']) {
  937. if ($_POST['v_inactive_session_timeout'] < 1) {
  938. $_SESSION['error_msg'] = _('Inactive session timeout can not lower than 1 minute');
  939. } else {
  940. exec(HESTIA_CMD."v-change-sys-config-value INACTIVE_SESSION_TIMEOUT ".quoteshellarg($_POST['v_inactive_session_timeout']), $output, $return_var);
  941. check_return_code($return_var, $output);
  942. unset($output);
  943. if (empty($_SESSION['error_msg'])) {
  944. $v_inactive_session_timeout = $_POST['v_inactive_session_timeout'];
  945. }
  946. }
  947. $v_security_adv = 'yes';
  948. }
  949. }
  950. // Change POLICY_CSRF_STRICTNESS
  951. if (empty($_SESSION['error_msg'])) {
  952. if ($_POST['v_policy_csrf_strictness'] != $_SESSION['POLICY_CSRF_STRICTNESS']) {
  953. exec(HESTIA_CMD."v-change-sys-config-value POLICY_CSRF_STRICTNESS ".quoteshellarg($_POST['v_policy_csrf_strictness']), $output, $return_var);
  954. check_return_code($return_var, $output);
  955. unset($output);
  956. if (empty($_SESSION['error_msg'])) {
  957. $v_policy_csrf_strictness = $_POST['v_inactive_session_timeout'];
  958. }
  959. $v_security_adv = 'yes';
  960. }
  961. }
  962. // Change ENFORCE_SUBDOMAIN_OWNERSHIP
  963. if (empty($_SESSION['error_msg'])) {
  964. if ($_POST['v_enforce_subdomain_ownership'] != $_SESSION['ENFORCE_SUBDOMAIN_OWNERSHIP']) {
  965. exec(HESTIA_CMD."v-change-sys-config-value ENFORCE_SUBDOMAIN_OWNERSHIP ".quoteshellarg($_POST['v_enforce_subdomain_ownership']), $output, $return_var);
  966. check_return_code($return_var, $output);
  967. unset($output);
  968. if (empty($_SESSION['error_msg'])) {
  969. $v_enforce_subdomain_ownership = $_POST['v_enforce_subdomain_ownership'];
  970. }
  971. $v_security_adv = 'yes';
  972. }
  973. }
  974. // Change POLICY_USER_EDIT_DETAILS
  975. if (empty($_SESSION['error_msg'])) {
  976. if ($_POST['v_policy_user_edit_details'] != $_SESSION['POLICY_USER_EDIT_DETAILS']) {
  977. exec(HESTIA_CMD."v-change-sys-config-value POLICY_USER_EDIT_DETAILS ".quoteshellarg($_POST['v_policy_user_edit_details']), $output, $return_var);
  978. check_return_code($return_var, $output);
  979. unset($output);
  980. if (empty($_SESSION['error_msg'])) {
  981. $v_policy_user_edit_details = $_POST['v_policy_user_edit_details'];
  982. }
  983. $v_security_adv = 'yes';
  984. }
  985. }
  986. // Change POLICY_USER_EDIT_WEB_TEMPLATES
  987. if (empty($_SESSION['error_msg'])) {
  988. if ($_POST['v_policy_user_edit_web_templates'] != $_SESSION['POLICY_USER_EDIT_WEB_TEMPLATES']) {
  989. exec(HESTIA_CMD."v-change-sys-config-value POLICY_USER_EDIT_WEB_TEMPLATES ".quoteshellarg($_POST['v_policy_user_edit_web_templates']), $output, $return_var);
  990. check_return_code($return_var, $output);
  991. unset($output);
  992. if (empty($_SESSION['error_msg'])) {
  993. $v_policy_user_edit_details = $_POST['v_policy_user_edit_web_templates'];
  994. }
  995. $v_security_adv = 'yes';
  996. }
  997. }
  998. // Change POLICY_USER_EDIT_DNS_TEMPLATES
  999. if (empty($_SESSION['error_msg'])) {
  1000. if ($_POST['v_policy_user_edit_dns_templates'] != $_SESSION['POLICY_USER_EDIT_DNS_TEMPLATES']) {
  1001. exec(HESTIA_CMD."v-change-sys-config-value POLICY_USER_EDIT_DNS_TEMPLATES ".quoteshellarg($_POST['v_policy_user_edit_dns_templates']), $output, $return_var);
  1002. check_return_code($return_var, $output);
  1003. unset($output);
  1004. if (empty($_SESSION['error_msg'])) {
  1005. $v_policy_user_edit_details = $_POST['v_policy_user_edit_dns_templates'];
  1006. }
  1007. $v_security_adv = 'yes';
  1008. }
  1009. }
  1010. if ($_POST['v_api_system'] != $_SESSION['API_SYSTEM'] || $_POST['v_api'] != $_SESSION['API'] || $_POST['v_api_allowed_ip'] != $_SESSION['API_ALLOWED_IP']){
  1011. if (empty($_SESSION['error_msg'])) {
  1012. if($_POST['v_api'] == "no" && $_POST['v_api_system'] === 0 ){
  1013. exec(HESTIA_CMD."v-change-sys-api 'disable'", $output, $return_var);
  1014. check_return_code($return_var, $output);
  1015. unset($output);
  1016. }
  1017. if($_POST['v_api'] == "yes" || $_POST['v_api_system'] !== 0 && $_POST['v_api_system'] != $_SESSION['API_SYSTEM'] || $_POST['v_api'] != $_SESSION['API']){
  1018. exec(HESTIA_CMD."v-change-sys-api 'enable'", $output, $return_var);
  1019. check_return_code($return_var, $output);
  1020. unset($output);
  1021. }
  1022. }
  1023. if (empty($_SESSION['error_msg'])) {
  1024. if ($_POST['v_api_system'] != $_SESSION['API_SYSTEM']) {
  1025. exec(HESTIA_CMD."v-change-sys-config-value API_SYSTEM ".quoteshellarg($_POST['v_api_system']), $output, $return_var);
  1026. check_return_code($return_var, $output);
  1027. unset($output);
  1028. if (empty($_SESSION['error_msg'])) {
  1029. $v_policy_user_edit_details = $_POST['v_api_system'];
  1030. }
  1031. $v_security_adv = 'yes';
  1032. }
  1033. }
  1034. // Change API access
  1035. if (empty($_SESSION['error_msg'])) {
  1036. if ($_POST['v_api'] != $_SESSION['API']) {
  1037. $api_status = 'no';
  1038. if ($_POST['v_api'] == 'yes') {
  1039. $api_status = 'yes';
  1040. }
  1041. exec(HESTIA_CMD."v-change-sys-config-value API ".quoteshellarg($api_status), $output, $return_var);
  1042. check_return_code($return_var, $output);
  1043. unset($output);
  1044. if (empty($_SESSION['error_msg'])) {
  1045. $v_api = $_POST['v_api'];
  1046. }
  1047. $v_security_adv = 'yes';
  1048. }
  1049. }
  1050. // Change API allowed IPs
  1051. if (empty($_SESSION['error_msg'])) {
  1052. if ($_POST['v_api_allowed_ip'] != $_SESSION['API_ALLOWED_IP']) {
  1053. $ips = array();
  1054. foreach (explode("\n", $_POST['v_api_allowed_ip']) as $ip) {
  1055. if (trim($ip) != "allow-all") {
  1056. if (filter_var(trim($ip), FILTER_VALIDATE_IP)) {
  1057. $ips[] = trim($ip);
  1058. }
  1059. } else {
  1060. $ips[] = trim($ip);
  1061. }
  1062. }
  1063. if (implode(',', $ips) != $_SESSION['API_ALLOWED_IP']) {
  1064. exec(HESTIA_CMD."v-change-sys-config-value API_ALLOWED_IP ".quoteshellarg(implode(',', $ips)), $output, $return_var);
  1065. check_return_code($return_var, $output);
  1066. unset($output);
  1067. if (empty($_SESSION['error_msg'])) {
  1068. $v_api_allowed_ip = $_POST['v_api_allowed_ip'];
  1069. }
  1070. $v_security_adv = 'yes';
  1071. }
  1072. }
  1073. }
  1074. }
  1075. // Change POLICY_USER_VIEW_LOGS
  1076. if (empty($_SESSION['error_msg'])) {
  1077. if ($_POST['v_policy_user_view_logs'] != $_SESSION['POLICY_USER_VIEW_LOGS']) {
  1078. exec(HESTIA_CMD."v-change-sys-config-value POLICY_USER_VIEW_LOGS ".quoteshellarg($_POST['v_policy_user_view_logs']), $output, $return_var);
  1079. check_return_code($return_var, $output);
  1080. unset($output);
  1081. if (empty($_SESSION['error_msg'])) {
  1082. $v_policy_user_view_logs = $_POST['v_policy_user_view_logs'];
  1083. }
  1084. $v_security_adv = 'yes';
  1085. }
  1086. }
  1087. // Change POLICY_USER_DELETE_LOGS
  1088. if (empty($_SESSION['error_msg'])) {
  1089. if ($_POST['v_policy_user_delete_logs'] != $_SESSION['POLICY_USER_DELETE_LOGS']) {
  1090. exec(HESTIA_CMD."v-change-sys-config-value POLICY_USER_DELETE_LOGS ".quoteshellarg($_POST['v_policy_user_delete_logs']), $output, $return_var);
  1091. check_return_code($return_var, $output);
  1092. unset($output);
  1093. if (empty($_SESSION['error_msg'])) {
  1094. $v_policy_user_delete_logs = $_POST['v_policy_user_delete_logs'];
  1095. }
  1096. $v_security_adv = 'yes';
  1097. }
  1098. }
  1099. // Change POLICY_SYSTEM_PASSWORD_RESET
  1100. if (empty($_SESSION['error_msg'])) {
  1101. if ($_POST['v_policy_system_password_reset'] != $_SESSION['POLICY_SYSTEM_PASSWORD_RESET']) {
  1102. exec(HESTIA_CMD."v-change-sys-config-value POLICY_SYSTEM_PASSWORD_RESET ".quoteshellarg($_POST['v_policy_system_password_reset']), $output, $return_var);
  1103. check_return_code($return_var, $output);
  1104. unset($output);
  1105. if (empty($_SESSION['error_msg'])) {
  1106. $v_policy_system_password_reset = $_POST['v_policy_system_password_reset'];
  1107. }
  1108. $v_security_adv = 'yes';
  1109. }
  1110. }
  1111. // Change POLICY_SYSTEM_PROTECTED_ADMIN
  1112. if (empty($_SESSION['error_msg'])) {
  1113. if ($_POST['v_policy_system_protected_admin'] != $_SESSION['POLICY_SYSTEM_PROTECTED_ADMIN']) {
  1114. exec(HESTIA_CMD."v-change-sys-config-value POLICY_SYSTEM_PROTECTED_ADMIN ".quoteshellarg($_POST['v_policy_system_protected_admin']), $output, $return_var);
  1115. check_return_code($return_var, $output);
  1116. unset($output);
  1117. if (empty($_SESSION['error_msg'])) {
  1118. $v_policy_system_protected_admin = $_POST['v_policy_system_protected_admin'];
  1119. }
  1120. $v_security_adv = 'yes';
  1121. }
  1122. }
  1123. // Change POLICY_USER_VIEW_SUSPENDED
  1124. if (empty($_SESSION['error_msg'])) {
  1125. if ($_POST['v_policy_user_view_suspended'] != $_SESSION['POLICY_USER_VIEW_SUSPENDED'] && !empty($_SESSION['POLICY_USER_VIEW_SUSPENDED'])) {
  1126. exec(HESTIA_CMD."v-change-sys-config-value POLICY_USER_VIEW_SUSPENDED ".quoteshellarg($_POST['v_policy_user_view_suspended']), $output, $return_var);
  1127. check_return_code($return_var, $output);
  1128. unset($output);
  1129. if (empty($_SESSION['error_msg'])) {
  1130. $v_policy_system_hide_admin = $_POST['v_policy_user_view_suspended'];
  1131. }
  1132. $v_security_adv = 'yes';
  1133. }
  1134. }
  1135. // Change POLICY_USER_CHANGE_THEME
  1136. if (empty($_SESSION['error_msg'])) {
  1137. if (empty($_POST['v_policy_user_change_theme'])) {
  1138. $_POST['v_policy_user_change_theme'] = '';
  1139. }
  1140. if ($_POST['v_policy_user_change_theme'] == 'on') {
  1141. $_POST['v_policy_user_change_theme'] = 'no';
  1142. } else {
  1143. $_POST['v_policy_user_change_theme'] = 'yes';
  1144. }
  1145. {
  1146. if ($_POST['v_policy_user_change_theme'] != $_SESSION['POLICY_USER_CHANGE_THEME']) {
  1147. exec(HESTIA_CMD."v-change-sys-config-value POLICY_USER_CHANGE_THEME ".quoteshellarg($_POST['v_policy_user_change_theme']), $output, $return_var);
  1148. check_return_code($return_var, $output);
  1149. unset($output);
  1150. if ($_POST['v_policy_user_change_theme']) {
  1151. unset($_SESSION['userTheme']);
  1152. $require_refresh = true;
  1153. }
  1154. if (empty($_SESSION['error_msg'])) {
  1155. $v_policy_user_change_theme = $_POST['v_policy_user_change_theme'];
  1156. }
  1157. }
  1158. }
  1159. }
  1160. // Change POLICY_SYSTEM_HIDE_ADMIN
  1161. if (empty($_SESSION['error_msg'])) {
  1162. if ($_POST['v_policy_system_hide_admin'] != $_SESSION['POLICY_SYSTEM_HIDE_ADMIN']) {
  1163. exec(HESTIA_CMD."v-change-sys-config-value POLICY_SYSTEM_HIDE_ADMIN ".quoteshellarg($_POST['v_policy_system_hide_admin']), $output, $return_var);
  1164. check_return_code($return_var, $output);
  1165. unset($output);
  1166. if (empty($_SESSION['error_msg'])) {
  1167. $v_policy_system_hide_admin = $_POST['v_policy_system_hide_admin'];
  1168. }
  1169. $v_security_adv = 'yes';
  1170. }
  1171. }
  1172. // Change POLICY_SYSTEM_HIDE_SERVICES
  1173. if (empty($_SESSION['error_msg'])) {
  1174. if ($_POST['v_policy_system_hide_services'] != $_SESSION['POLICY_SYSTEM_HIDE_SERVICES']) {
  1175. exec(HESTIA_CMD."v-change-sys-config-value POLICY_SYSTEM_HIDE_SERVICES ".quoteshellarg($_POST['v_policy_system_hide_services']), $output, $return_var);
  1176. check_return_code($return_var, $output);
  1177. unset($output);
  1178. if (empty($_SESSION['error_msg'])) {
  1179. $v_policy_system_hide_services = $_POST['v_policy_system_hide_services'];
  1180. }
  1181. $v_security_adv = 'yes';
  1182. }
  1183. }
  1184. // Change login style
  1185. if (empty($_SESSION['error_msg'])) {
  1186. if ($_POST['v_login_style'] != $_SESSION['LOGIN_STYLE']) {
  1187. exec(HESTIA_CMD."v-change-sys-config-value LOGIN_STYLE ".quoteshellarg($_POST['v_login_style']), $output, $return_var);
  1188. check_return_code($return_var, $output);
  1189. unset($output);
  1190. if (empty($_SESSION['error_msg'])) {
  1191. $v_login_style = $_POST['v_login_style'];
  1192. }
  1193. $v_security_adv = 'yes';
  1194. }
  1195. }
  1196. // Update SSL certificate
  1197. if ((!empty($_POST['v_ssl_crt'])) && (empty($_SESSION['error_msg']))) {
  1198. if (($v_ssl_crt != str_replace("\r\n", "\n", $_POST['v_ssl_crt'])) || ($v_ssl_key != str_replace("\r\n", "\n", $_POST['v_ssl_key']))) {
  1199. exec('mktemp -d', $mktemp_output, $return_var);
  1200. $tmpdir = $mktemp_output[0];
  1201. // Certificate
  1202. if (!empty($_POST['v_ssl_crt'])) {
  1203. $fp = fopen($tmpdir."/certificate.crt", 'w');
  1204. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt']));
  1205. fwrite($fp, "\n");
  1206. fclose($fp);
  1207. }
  1208. // Key
  1209. if (!empty($_POST['v_ssl_key'])) {
  1210. $fp = fopen($tmpdir."/certificate.key", 'w');
  1211. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key']));
  1212. fwrite($fp, "\n");
  1213. fclose($fp);
  1214. }
  1215. exec(HESTIA_CMD."v-change-sys-hestia-ssl ".$tmpdir, $output, $return_var);
  1216. check_return_code($return_var, $output);
  1217. unset($output);
  1218. // List ssl certificate info
  1219. exec(HESTIA_CMD."v-list-sys-hestia-ssl json", $output, $return_var);
  1220. $ssl_str = json_decode(implode('', $output), true);
  1221. unset($output);
  1222. $v_ssl_crt = $ssl_str['HESTIA']['CRT'];
  1223. $v_ssl_key = $ssl_str['HESTIA']['KEY'];
  1224. $v_ssl_ca = $ssl_str['HESTIA']['CA'];
  1225. $v_ssl_subject = $ssl_str['HESTIA']['SUBJECT'];
  1226. $v_ssl_aliases = $ssl_str['HESTIA']['ALIASES'];
  1227. $v_ssl_not_before = $ssl_str['HESTIA']['NOT_BEFORE'];
  1228. $v_ssl_not_after = $ssl_str['HESTIA']['NOT_AFTER'];
  1229. $v_ssl_signature = $ssl_str['HESTIA']['SIGNATURE'];
  1230. $v_ssl_pub_key = $ssl_str['HESTIA']['PUB_KEY'];
  1231. $v_ssl_issuer = $ssl_str['HESTIA']['ISSUER'];
  1232. // Cleanup certificate tempfiles
  1233. if (file_exists($tmpdir . '/certificate.crt')) {
  1234. unlink($tmpdir . '/certificate.crt');
  1235. }
  1236. if (file_exists($tmpdir . '/certificate.key')) {
  1237. unlink($tmpdir . '/certificate.key');
  1238. }
  1239. rmdir($tmpdir);
  1240. }
  1241. }
  1242. // Flush field values on success
  1243. if (empty($_SESSION['error_msg'])) {
  1244. $_SESSION['ok_msg'] = _('Changes has been saved.');
  1245. }
  1246. if ($require_refresh == true) {
  1247. $refresh = $_SERVER['REQUEST_URI'];
  1248. $_SESSION['ok_msg'] = _('Changes has been saved.');
  1249. header("Location: $refresh");
  1250. die();
  1251. }
  1252. }
  1253. // Check system configuration
  1254. exec(HESTIA_CMD . "v-list-sys-config json", $output, $return_var);
  1255. $data = json_decode(implode('', $output), true);
  1256. unset($output);
  1257. $sys_arr = $data['config'];
  1258. foreach ($sys_arr as $key => $value) {
  1259. $_SESSION[$key] = $value;
  1260. }
  1261. // Render page
  1262. render_page($user, $TAB, 'edit_server');
  1263. // Flush session messages
  1264. unset($_SESSION['error_msg']);
  1265. unset($_SESSION['ok_msg']);