index.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. <?php
  2. use function Hestiacp\quoteshellarg\quoteshellarg;
  3. ob_start();
  4. $TAB = "USER";
  5. // Main include
  6. include $_SERVER["DOCUMENT_ROOT"] . "/inc/main.php";
  7. // Check user argument
  8. if (empty($_GET["user"])) {
  9. header("Location: /list/user/");
  10. exit();
  11. }
  12. // Edit as someone else?
  13. if ($_SESSION["userContext"] === "admin" && !empty($_GET["user"])) {
  14. $user = $_GET["user"];
  15. $v_username = $_GET["user"];
  16. } else {
  17. $user = $_SESSION["user"];
  18. $v_username = $_SESSION["user"];
  19. }
  20. // Prevent other users with admin privileges from editing properties of default 'admin' user
  21. if (
  22. ($_SESSION["userContext"] === "admin" &&
  23. $_SESSION["look"] != "" &&
  24. $user == $_SESSION["ROOT_USER"]) ||
  25. ($_SESSION["userContext"] === "admin" &&
  26. !isset($_SESSION["look"]) &&
  27. $user == "admin" &&
  28. $_SESSION["user"] != $_SESSION["ROOT_USER"])
  29. ) {
  30. header("Location: /list/user/");
  31. exit();
  32. }
  33. // Check token
  34. verify_csrf($_GET);
  35. // List user
  36. exec(HESTIA_CMD . "v-list-user " . quoteshellarg($v_username) . " json", $output, $return_var);
  37. check_return_code_redirect($return_var, $output, "/list/user/");
  38. $data = json_decode(implode("", $output), true);
  39. unset($output);
  40. // Parse user
  41. $v_password = "";
  42. $v_email = $data[$v_username]["CONTACT"];
  43. $v_package = $data[$v_username]["PACKAGE"];
  44. $v_language = $data[$v_username]["LANGUAGE"];
  45. $v_user_theme = $data[$v_username]["THEME"];
  46. $v_sort_order = $data[$v_username]["PREF_UI_SORT"];
  47. $v_name = $data[$v_username]["NAME"];
  48. $v_shell = $data[$v_username]["SHELL"];
  49. $v_twofa = $data[$v_username]["TWOFA"];
  50. $v_qrcode = $data[$v_username]["QRCODE"];
  51. $v_phpcli = $data[$v_username]["PHPCLI"];
  52. $v_role = $data[$v_username]["ROLE"];
  53. $v_login_disabled = $data[$v_username]["LOGIN_DISABLED"];
  54. $v_login_use_iplist = $data[$v_username]["LOGIN_USE_IPLIST"];
  55. $v_login_allowed_ips = $data[$v_username]["LOGIN_ALLOW_IPS"];
  56. $v_ns = $data[$v_username]["NS"];
  57. $nameservers = explode(",", $v_ns);
  58. if (empty($nameservers[0])) {
  59. $v_ns1 = "";
  60. } else {
  61. $v_ns1 = $nameservers[0];
  62. }
  63. if (empty($nameservers[1])) {
  64. $v_ns2 = "";
  65. } else {
  66. $v_ns2 = $nameservers[1];
  67. }
  68. if (empty($nameservers[2])) {
  69. $v_ns3 = "";
  70. } else {
  71. $v_ns3 = $nameservers[2];
  72. }
  73. if (empty($nameservers[3])) {
  74. $v_ns4 = "";
  75. } else {
  76. $v_ns4 = $nameservers[3];
  77. }
  78. if (empty($nameservers[4])) {
  79. $v_ns5 = "";
  80. } else {
  81. $v_ns5 = $nameservers[4];
  82. }
  83. if (empty($nameservers[5])) {
  84. $v_ns6 = "";
  85. } else {
  86. $v_ns6 = $nameservers[5];
  87. }
  88. if (empty($nameservers[6])) {
  89. $v_ns7 = "";
  90. } else {
  91. $v_ns7 = $nameservers[6];
  92. }
  93. if (empty($nameservers[7])) {
  94. $v_ns8 = "";
  95. } else {
  96. $v_ns8 = $nameservers[7];
  97. }
  98. $v_suspended = $data[$v_username]["SUSPENDED"];
  99. if ($v_suspended == "yes") {
  100. $v_status = "suspended";
  101. } else {
  102. $v_status = "active";
  103. }
  104. $v_time = $data[$v_username]["TIME"];
  105. $v_date = $data[$v_username]["DATE"];
  106. if (empty($v_phpcli)) {
  107. $v_phpcli = substr(DEFAULT_PHP_VERSION, 4);
  108. }
  109. // List packages
  110. exec(HESTIA_CMD . "v-list-user-packages json", $output, $return_var);
  111. $packages = json_decode(implode("", $output), true);
  112. unset($output);
  113. // List languages
  114. exec(HESTIA_CMD . "v-list-sys-languages json", $output, $return_var);
  115. $language = json_decode(implode("", $output), true);
  116. foreach ($language as $lang) {
  117. $languages[$lang] = translate_json($lang);
  118. }
  119. asort($languages);
  120. unset($output);
  121. // List themes
  122. exec(HESTIA_CMD . "v-list-sys-themes json", $output, $return_var);
  123. $themes = json_decode(implode("", $output), true);
  124. unset($output);
  125. // List shells
  126. exec(HESTIA_CMD . "v-list-sys-shells json", $output, $return_var);
  127. $shells = json_decode(implode("", $output), true);
  128. unset($output);
  129. //List PHP Versions
  130. // List supported php versions
  131. exec(HESTIA_CMD . "v-list-sys-php json", $output, $return_var);
  132. $php_versions = json_decode(implode("", $output), true);
  133. unset($output);
  134. // Check POST request
  135. if (!empty($_POST["save"])) {
  136. // Check token
  137. verify_csrf($_POST);
  138. // Change password
  139. if (!empty($_POST["v_password"]) && empty($_SESSION["error_msg"])) {
  140. // Check password length
  141. $pw_len = strlen($_POST["v_password"]);
  142. if (!validate_password($_POST["v_password"])) {
  143. $_SESSION["error_msg"] = _("Password does not match the minimum requirements.");
  144. }
  145. if (empty($_SESSION["error_msg"])) {
  146. $v_password = tempnam("/tmp", "vst");
  147. $fp = fopen($v_password, "w");
  148. fwrite($fp, $_POST["v_password"] . "\n");
  149. fclose($fp);
  150. exec(
  151. HESTIA_CMD .
  152. "v-change-user-password " .
  153. quoteshellarg($v_username) .
  154. " " .
  155. $v_password,
  156. $output,
  157. $return_var,
  158. );
  159. check_return_code($return_var, $output);
  160. unset($output);
  161. unlink($v_password);
  162. $v_password = quoteshellarg($_POST["v_password"]);
  163. }
  164. }
  165. // Enable twofa
  166. if (!empty($_POST["v_twofa"]) && empty($v_twofa) && empty($_SESSION["error_msg"])) {
  167. exec(HESTIA_CMD . "v-add-user-2fa " . quoteshellarg($v_username), $output, $return_var);
  168. check_return_code($return_var, $output);
  169. unset($output);
  170. // List user
  171. exec(
  172. HESTIA_CMD . "v-list-user " . quoteshellarg($v_username) . " json",
  173. $output,
  174. $return_var,
  175. );
  176. check_return_code($return_var, $output);
  177. $data = json_decode(implode("", $output), true);
  178. unset($output);
  179. // Parse user twofa
  180. $v_twofa = $data[$v_username]["TWOFA"];
  181. $v_qrcode = $data[$v_username]["QRCODE"];
  182. }
  183. // Disable twofa
  184. if (empty($_POST["v_twofa"]) && !empty($v_twofa) && empty($_SESSION["error_msg"])) {
  185. exec(HESTIA_CMD . "v-delete-user-2fa " . quoteshellarg($v_username), $output, $return_var);
  186. check_return_code($return_var, $output);
  187. unset($output);
  188. $v_twofa = "";
  189. $v_qrcode = "";
  190. }
  191. // Change default sort order
  192. if ($v_sort_order != $_POST["v_sort_order"] && empty($_SESSION["error_msg"])) {
  193. $v_sort_order = quoteshellarg($_POST["v_sort_order"]);
  194. exec(
  195. HESTIA_CMD .
  196. "v-change-user-sort-order " .
  197. quoteshellarg($v_username) .
  198. " " .
  199. $v_sort_order,
  200. $output,
  201. $return_var,
  202. );
  203. check_return_code($return_var, $output);
  204. unset($_SESSION["userSortOrder"]);
  205. $_SESSION["userSortOrder"] = $v_sort_order;
  206. unset($output);
  207. }
  208. // Update Control Panel login disabled status (admin only)
  209. if (empty($_SESSION["error_msg"])) {
  210. if (empty($_POST["v_login_disabled"])) {
  211. $_POST["v_login_disabled"] = "";
  212. }
  213. if ($_POST["v_login_disabled"] != $v_login_disabled) {
  214. if ($_POST["v_login_disabled"] == "on") {
  215. $_POST["v_login_disabled"] = "yes";
  216. } else {
  217. $_POST["v_login_disabled"] = "no";
  218. }
  219. exec(
  220. HESTIA_CMD .
  221. "v-change-user-config-value " .
  222. quoteshellarg($v_username) .
  223. " LOGIN_DISABLED " .
  224. quoteshellarg($_POST["v_login_disabled"]),
  225. $output,
  226. $return_var,
  227. );
  228. check_return_code($return_var, $output);
  229. $data[$user]["LOGIN_DISABLED"] = $_POST["v_login_disabled"];
  230. unset($output);
  231. }
  232. }
  233. // Update IP whitelist option
  234. if (empty($_SESSION["error_msg"])) {
  235. if (empty($_POST["v_login_use_iplist"])) {
  236. $_POST["v_login_use_iplist"] = "";
  237. }
  238. if ($_POST["v_login_use_iplist"] != $v_login_use_iplist) {
  239. if ($_POST["v_login_use_iplist"] == "on") {
  240. $_POST["v_login_use_iplist"] = "yes";
  241. } else {
  242. $_POST["v_login_use_iplist"] = "no";
  243. }
  244. exec(
  245. HESTIA_CMD .
  246. "v-change-user-config-value " .
  247. quoteshellarg($v_username) .
  248. " LOGIN_USE_IPLIST " .
  249. quoteshellarg($_POST["v_login_use_iplist"]),
  250. $output,
  251. $return_var,
  252. );
  253. if ($_POST["v_login_use_iplist"] === "no") {
  254. exec(
  255. HESTIA_CMD .
  256. "v-change-user-config-value " .
  257. quoteshellarg($v_username) .
  258. " LOGIN_ALLOW_IPS ''",
  259. $output,
  260. $return_var,
  261. );
  262. $v_login_allowed_ips = "";
  263. } else {
  264. exec(
  265. HESTIA_CMD .
  266. "v-change-user-config-value " .
  267. quoteshellarg($v_username) .
  268. " LOGIN_ALLOW_IPS " .
  269. quoteshellarg($_POST["v_login_allowed_ips"]),
  270. $output,
  271. $return_var,
  272. );
  273. unset($v_login_allowed_ips);
  274. $v_login_allowed_ips = $_POST["v_login_allowed_ips"];
  275. }
  276. check_return_code($return_var, $output);
  277. $data[$user]["LOGIN_USE_IPLIST"] = $_POST["v_login_use_iplist"];
  278. unset($output);
  279. }
  280. }
  281. if ($_SESSION["userContext"] === "admin") {
  282. // Change package (admin only)
  283. if (
  284. $v_package != $_POST["v_package"] &&
  285. $_SESSION["userContext"] === "admin" &&
  286. empty($_SESSION["error_msg"])
  287. ) {
  288. $v_package = quoteshellarg($_POST["v_package"]);
  289. exec(
  290. HESTIA_CMD .
  291. "v-change-user-package " .
  292. quoteshellarg($v_username) .
  293. " " .
  294. $v_package,
  295. $output,
  296. $return_var,
  297. );
  298. check_return_code($return_var, $output);
  299. unset($output);
  300. }
  301. // Change phpcli (admin only)
  302. if (
  303. $v_phpcli != $_POST["v_phpcli"] &&
  304. $_SESSION["userContext"] === "admin" &&
  305. empty($_SESSION["error_msg"])
  306. ) {
  307. $v_phpcli = quoteshellarg($_POST["v_phpcli"]);
  308. exec(
  309. HESTIA_CMD .
  310. "v-change-user-php-cli " .
  311. quoteshellarg($v_username) .
  312. " " .
  313. $v_phpcli,
  314. $output,
  315. $return_var,
  316. );
  317. check_return_code($return_var, $output);
  318. unset($output);
  319. }
  320. $_POST["v_role"] = $_POST["v_role"] ?? "";
  321. if (
  322. $v_role != $_POST["v_role"] &&
  323. $_SESSION["userContext"] === "admin" &&
  324. $v_username != "admin" &&
  325. empty($_SESSION["error_msg"])
  326. ) {
  327. if (!empty($_POST["v_role"])) {
  328. $v_role = quoteshellarg($_POST["v_role"]);
  329. exec(
  330. HESTIA_CMD . "v-change-user-role " . quoteshellarg($v_username) . " " . $v_role,
  331. $output,
  332. $return_var,
  333. );
  334. check_return_code($return_var, $output);
  335. unset($output);
  336. $v_role = $_POST["v_role"];
  337. }
  338. }
  339. // Change shell (admin only)
  340. if (!empty($_POST["v_shell"])) {
  341. if (
  342. $v_shell != $_POST["v_shell"] &&
  343. $_SESSION["userContext"] === "admin" &&
  344. empty($_SESSION["error_msg"])
  345. ) {
  346. $v_shell = quoteshellarg($_POST["v_shell"]);
  347. $v_shell_jail_enabled = quoteshellarg($_POST["v_shell_jail_enabled"]);
  348. exec(
  349. HESTIA_CMD .
  350. "v-change-user-shell " .
  351. quoteshellarg($v_username) .
  352. " " .
  353. $v_shell,
  354. $output,
  355. $return_var,
  356. );
  357. check_return_code($return_var, $output);
  358. unset($output);
  359. }
  360. }
  361. }
  362. // Change language
  363. if ($v_language != $_POST["v_language"] && empty($_SESSION["error_msg"])) {
  364. $v_language = quoteshellarg($_POST["v_language"]);
  365. exec(
  366. HESTIA_CMD . "v-change-user-language " . quoteshellarg($v_username) . " " . $v_language,
  367. $output,
  368. $return_var,
  369. );
  370. check_return_code($return_var, $output);
  371. if (empty($_SESSION["error_msg"])) {
  372. if ($_GET["user"] == $_SESSION["user"]) {
  373. unset($_SESSION["language"]);
  374. $_SESSION["language"] = $_POST["v_language"];
  375. $refresh = $_SERVER["REQUEST_URI"];
  376. header("Location: $refresh");
  377. }
  378. }
  379. unset($output);
  380. }
  381. // Change contact email
  382. if ($v_email != $_POST["v_email"] && empty($_SESSION["error_msg"])) {
  383. if (!filter_var($_POST["v_email"], FILTER_VALIDATE_EMAIL)) {
  384. $_SESSION["error_msg"] = _("Please enter a valid email address.");
  385. } else {
  386. $v_email = quoteshellarg($_POST["v_email"]);
  387. exec(
  388. HESTIA_CMD . "v-change-user-contact " . quoteshellarg($v_username) . " " . $v_email,
  389. $output,
  390. $return_var,
  391. );
  392. check_return_code($return_var, $output);
  393. unset($output);
  394. }
  395. }
  396. // Change full name
  397. if ($v_name != $_POST["v_name"]) {
  398. if (empty($_POST["v_name"])) {
  399. $_SESSION["error_msg"] = _("Please enter a valid contact name.");
  400. } else {
  401. $v_name = quoteshellarg($_POST["v_name"]);
  402. exec(
  403. HESTIA_CMD . "v-change-user-name " . quoteshellarg($v_username) . " " . $v_name,
  404. $output,
  405. $return_var,
  406. );
  407. check_return_code($return_var, $output);
  408. unset($output);
  409. $v_name = $_POST["v_name"];
  410. }
  411. }
  412. // Update theme
  413. if (empty($_SESSION["error_msg"])) {
  414. if (empty($_SESSION["userTheme"])) {
  415. $_SESSION["userTheme"] = "";
  416. }
  417. if ($_POST["v_user_theme"] != $_SESSION["userTheme"]) {
  418. exec(
  419. HESTIA_CMD .
  420. "v-change-user-theme " .
  421. quoteshellarg($v_username) .
  422. " " .
  423. quoteshellarg($_POST["v_user_theme"]),
  424. $output,
  425. $return_var,
  426. );
  427. check_return_code($return_var, $output);
  428. unset($output);
  429. $v_user_theme = $_POST["v_user_theme"];
  430. if ($_SESSION["user"] === $v_username) {
  431. unset($_SESSION["userTheme"]);
  432. $_SESSION["userTheme"] = $v_user_theme;
  433. }
  434. }
  435. }
  436. if (!empty($_SESSION["DNS_SYSTEM"])) {
  437. if ($_SESSION["userContext"] === "admin") {
  438. // Change NameServers
  439. if (empty($_POST["v_ns1"])) {
  440. $_POST["v_ns1"] = "";
  441. }
  442. if (empty($_POST["v_ns2"])) {
  443. $_POST["v_ns2"] = "";
  444. }
  445. if (empty($_POST["v_ns3"])) {
  446. $_POST["v_ns3"] = "";
  447. }
  448. if (empty($_POST["v_ns4"])) {
  449. $_POST["v_ns4"] = "";
  450. }
  451. if (empty($_POST["v_ns5"])) {
  452. $_POST["v_ns5"] = "";
  453. }
  454. if (empty($_POST["v_ns6"])) {
  455. $_POST["v_ns6"] = "";
  456. }
  457. if (empty($_POST["v_ns7"])) {
  458. $_POST["v_ns7"] = "";
  459. }
  460. if (empty($_POST["v_ns8"])) {
  461. $_POST["v_ns8"] = "";
  462. }
  463. if (
  464. $v_ns1 != $_POST["v_ns1"] ||
  465. $v_ns2 != $_POST["v_ns2"] ||
  466. $v_ns3 != $_POST["v_ns3"] ||
  467. $v_ns4 != $_POST["v_ns4"] ||
  468. $v_ns5 != $_POST["v_ns5"] ||
  469. $v_ns6 != $_POST["v_ns6"] ||
  470. $v_ns7 != $_POST["v_ns7"] ||
  471. ($v_ns8 != $_POST["v_ns8"] &&
  472. empty($_SESSION["error_msg"] && !empty($_POST["v_ns1"]) && $_POST["v_ns2"]))
  473. ) {
  474. $v_ns1 = quoteshellarg($_POST["v_ns1"]);
  475. $v_ns2 = quoteshellarg($_POST["v_ns2"]);
  476. $v_ns3 = quoteshellarg($_POST["v_ns3"]);
  477. $v_ns4 = quoteshellarg($_POST["v_ns4"]);
  478. $v_ns5 = quoteshellarg($_POST["v_ns5"]);
  479. $v_ns6 = quoteshellarg($_POST["v_ns6"]);
  480. $v_ns7 = quoteshellarg($_POST["v_ns7"]);
  481. $v_ns8 = quoteshellarg($_POST["v_ns8"]);
  482. $ns_cmd =
  483. HESTIA_CMD .
  484. "v-change-user-ns " .
  485. quoteshellarg($v_username) .
  486. " " .
  487. $v_ns1 .
  488. " " .
  489. $v_ns2;
  490. if (!empty($_POST["v_ns3"])) {
  491. $ns_cmd = $ns_cmd . " " . $v_ns3;
  492. }
  493. if (!empty($_POST["v_ns4"])) {
  494. $ns_cmd = $ns_cmd . " " . $v_ns4;
  495. }
  496. if (!empty($_POST["v_ns5"])) {
  497. $ns_cmd = $ns_cmd . " " . $v_ns5;
  498. }
  499. if (!empty($_POST["v_ns6"])) {
  500. $ns_cmd = $ns_cmd . " " . $v_ns6;
  501. }
  502. if (!empty($_POST["v_ns7"])) {
  503. $ns_cmd = $ns_cmd . " " . $v_ns7;
  504. }
  505. if (!empty($_POST["v_ns8"])) {
  506. $ns_cmd = $ns_cmd . " " . $v_ns8;
  507. }
  508. exec($ns_cmd, $output, $return_var);
  509. check_return_code($return_var, $output);
  510. unset($output);
  511. $v_ns1 = str_replace("'", "", $v_ns1);
  512. $v_ns2 = str_replace("'", "", $v_ns2);
  513. $v_ns3 = str_replace("'", "", $v_ns3);
  514. $v_ns4 = str_replace("'", "", $v_ns4);
  515. $v_ns5 = str_replace("'", "", $v_ns5);
  516. $v_ns6 = str_replace("'", "", $v_ns6);
  517. $v_ns7 = str_replace("'", "", $v_ns7);
  518. $v_ns8 = str_replace("'", "", $v_ns8);
  519. }
  520. }
  521. }
  522. // Set success message
  523. if (empty($_SESSION["error_msg"])) {
  524. $_SESSION["ok_msg"] = _("Changes have been saved.");
  525. }
  526. }
  527. // Render page
  528. render_page($user, $TAB, "edit_user");
  529. // Flush session messages
  530. unset($_SESSION["error_msg"]);
  531. unset($_SESSION["ok_msg"]);