index.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <?php
  2. error_reporting(NULL);
  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['user'] == '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. // List user
  21. exec (HESTIA_CMD."v-list-user ".escapeshellarg($v_username)." json", $output, $return_var);
  22. check_return_code($return_var,$output);
  23. $data = json_decode(implode('', $output), true);
  24. unset($output);
  25. // Parse user
  26. $v_password = "";
  27. $v_email = $data[$v_username]['CONTACT'];
  28. $v_package = $data[$v_username]['PACKAGE'];
  29. $v_language = $data[$v_username]['LANGUAGE'];
  30. $v_name = $data[$v_username]['NAME'];
  31. $v_shell = $data[$v_username]['SHELL'];
  32. $v_twofa = $data[$v_username]['TWOFA'];
  33. $v_qrcode = $data[$v_username]['QRCODE'];
  34. $v_phpcli = $data[$v_username]['PHPCLI'];
  35. $v_role = $data[$v_username]['ROLE'];
  36. $v_ns = $data[$v_username]['NS'];
  37. $nameservers = explode(",", $v_ns);
  38. $v_ns1 = $nameservers[0];
  39. $v_ns2 = $nameservers[1];
  40. $v_ns3 = $nameservers[2];
  41. $v_ns4 = $nameservers[3];
  42. $v_ns5 = $nameservers[4];
  43. $v_ns6 = $nameservers[5];
  44. $v_ns7 = $nameservers[6];
  45. $v_ns8 = $nameservers[7];
  46. $v_suspended = $data[$v_username]['SUSPENDED'];
  47. if ( $v_suspended == 'yes' ) {
  48. $v_status = 'suspended';
  49. } else {
  50. $v_status = 'active';
  51. }
  52. $v_time = $data[$v_username]['TIME'];
  53. $v_date = $data[$v_username]['DATE'];
  54. if(empty($v_phpcli)){
  55. $v_phpcli = substr(DEFAULT_PHP_VERSION,4);
  56. }
  57. // List packages
  58. exec (HESTIA_CMD."v-list-user-packages json", $output, $return_var);
  59. $packages = json_decode(implode('', $output), true);
  60. unset($output);
  61. // List languages
  62. exec (HESTIA_CMD."v-list-sys-languages json", $output, $return_var);
  63. $languages = json_decode(implode('', $output), true);
  64. unset($output);
  65. // List shells
  66. exec (HESTIA_CMD."v-list-sys-shells json", $output, $return_var);
  67. $shells = json_decode(implode('', $output), true);
  68. unset($output);
  69. //List PHP Versions
  70. // List supported php versions
  71. exec (HESTIA_CMD."v-list-sys-php json", $output, $return_var);
  72. $php_versions = json_decode(implode('', $output), true);
  73. unset($output);
  74. // Are you admin?
  75. // Check POST request
  76. if (!empty($_POST['save'])) {
  77. // Check token
  78. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  79. header('location: /login/');
  80. exit();
  81. }
  82. // Change password
  83. if ((!empty($_POST['v_password'])) && (empty($_SESSION['error_msg']))) {
  84. // Check password length
  85. $pw_len = strlen($_POST['v_password']);
  86. if (!validate_password($_POST['v_password'])) {
  87. $_SESSION['error_msg'] = __('Password does not match the minimum requirements');
  88. }
  89. if (empty($_SESSION['error_msg'])) {
  90. $v_password = tempnam("/tmp","vst");
  91. $fp = fopen($v_password, "w");
  92. fwrite($fp, $_POST['v_password']."\n");
  93. fclose($fp);
  94. exec (HESTIA_CMD."v-change-user-password ".escapeshellarg($v_username)." ".$v_password, $output, $return_var);
  95. check_return_code($return_var,$output);
  96. unset($output);
  97. unlink($v_password);
  98. $v_password = escapeshellarg($_POST['v_password']);
  99. }
  100. }
  101. // Enable twofa
  102. if ((!empty($_POST['v_twofa'])) && (empty($_SESSION['error_msg']))) {
  103. exec (HESTIA_CMD."v-add-user-2fa ".escapeshellarg($v_username), $output, $return_var);
  104. check_return_code($return_var,$output);
  105. unset($output);
  106. // List user
  107. exec (HESTIA_CMD."v-list-user ".escapeshellarg($v_username)." json", $output, $return_var);
  108. check_return_code($return_var,$output);
  109. $data = json_decode(implode('', $output), true);
  110. unset($output);
  111. // Parse user twofa
  112. $v_twofa = $data[$v_username]['TWOFA'];
  113. $v_qrcode = $data[$v_username]['QRCODE'];
  114. }
  115. // Disable twofa
  116. if ((empty($_POST['v_twofa'])) && (!empty($v_twofa)) && (empty($_SESSION['error_msg']))) {
  117. exec (HESTIA_CMD."v-delete-user-2fa ".escapeshellarg($v_username), $output, $return_var);
  118. check_return_code($return_var,$output);
  119. unset($output);
  120. $v_twofa = '';
  121. $v_qrcode = '';
  122. }
  123. // Change package (admin only)
  124. if (($v_package != $_POST['v_package']) && ($_SESSION['user'] == 'admin') && (empty($_SESSION['error_msg']))) {
  125. $v_package = escapeshellarg($_POST['v_package']);
  126. exec (HESTIA_CMD."v-change-user-package ".escapeshellarg($v_username)." ".$v_package, $output, $return_var);
  127. check_return_code($return_var,$output);
  128. unset($output);
  129. }
  130. // Change phpcli (admin only)
  131. if (($v_phpcli != $_POST['v_phpcli']) && ($_SESSION['user'] == 'admin') && (empty($_SESSION['error_msg']))) {
  132. $v_phpcli = escapeshellarg($_POST['v_phpcli']);
  133. exec (HESTIA_CMD."v-change-user-php-cli ".escapeshellarg($v_username)." ".$v_phpcli, $output, $return_var);
  134. check_return_code($return_var,$output);
  135. unset($output);
  136. }
  137. // Change Role (admin only)
  138. if (($v_role != $_POST['$v_role']) && ($_SESSION['user'] == 'admin') && (empty($_SESSION['error_msg']))) {
  139. $v_role = escapeshellarg($_POST['v_role']);
  140. exec (HESTIA_CMD."v-change-user-role ".escapeshellarg($v_username)." ".$v_role, $output, $return_var);
  141. check_return_code($return_var,$output);
  142. unset($output);
  143. $v_role = $_POST['v_role'];
  144. }
  145. // Change language
  146. if (($v_language != $_POST['v_language']) && (empty($_SESSION['error_msg']))) {
  147. $v_language = escapeshellarg($_POST['v_language']);
  148. exec (HESTIA_CMD."v-change-user-language ".escapeshellarg($v_username)." ".$v_language, $output, $return_var);
  149. check_return_code($return_var,$output);
  150. if (empty($_SESSION['error_msg'])) {
  151. if ((empty($_GET['user'])) || ($_GET['user'] == $_SESSION['user'])) $_SESSION['language'] = $_POST['v_language'];
  152. }
  153. unset($output);
  154. }
  155. // Change shell (admin only)
  156. if (($v_shell != $_POST['v_shell']) && ($_SESSION['user'] == 'admin') && (empty($_SESSION['error_msg']))) {
  157. $v_shell = escapeshellarg($_POST['v_shell']);
  158. exec (HESTIA_CMD."v-change-user-shell ".escapeshellarg($v_username)." ".$v_shell, $output, $return_var);
  159. check_return_code($return_var,$output);
  160. unset($output);
  161. }
  162. // Change contact email
  163. if (($v_email != $_POST['v_email']) && (empty($_SESSION['error_msg']))) {
  164. if (!filter_var($_POST['v_email'], FILTER_VALIDATE_EMAIL)) {
  165. $_SESSION['error_msg'] = _('Please enter valid email address.');
  166. } else {
  167. $v_email = escapeshellarg($_POST['v_email']);
  168. exec (HESTIA_CMD."v-change-user-contact ".escapeshellarg($v_username)." ".$v_email, $output, $return_var);
  169. check_return_code($return_var,$output);
  170. unset($output);
  171. }
  172. }
  173. // Change full name
  174. if ($v_name != $_POST['v_name']){
  175. if (empty($_POST['v_name'])) {
  176. $_SESSION['error_msg'] = _('Please enter a valid name');
  177. }else{
  178. $v_name = escapeshellarg($_POST['v_name']);
  179. exec (HESTIA_CMD."v-change-user-name ".escapeshellarg($v_username). " ".$v_name, $output, $return_var);
  180. check_return_code($return_var,$output);
  181. unset($output);
  182. $v_name = $_POST['v_name'];
  183. }
  184. }
  185. // Change NameServers
  186. if (($v_ns1 != $_POST['v_ns1']) || ($v_ns2 != $_POST['v_ns2']) || ($v_ns3 != $_POST['v_ns3']) || ($v_ns4 != $_POST['v_ns4']) || ($v_ns5 != $_POST['v_ns5'])
  187. || ($v_ns6 != $_POST['v_ns6']) || ($v_ns7 != $_POST['v_ns7']) || ($v_ns8 != $_POST['v_ns8']) && (empty($_SESSION['error_msg']))) {
  188. $v_ns1 = escapeshellarg($_POST['v_ns1']);
  189. $v_ns2 = escapeshellarg($_POST['v_ns2']);
  190. $v_ns3 = escapeshellarg($_POST['v_ns3']);
  191. $v_ns4 = escapeshellarg($_POST['v_ns4']);
  192. $v_ns5 = escapeshellarg($_POST['v_ns5']);
  193. $v_ns6 = escapeshellarg($_POST['v_ns6']);
  194. $v_ns7 = escapeshellarg($_POST['v_ns7']);
  195. $v_ns8 = escapeshellarg($_POST['v_ns8']);
  196. $ns_cmd = HESTIA_CMD."v-change-user-ns ".escapeshellarg($v_username)." ".$v_ns1." ".$v_ns2;
  197. if (!empty($_POST['v_ns3'])) $ns_cmd = $ns_cmd." ".$v_ns3;
  198. if (!empty($_POST['v_ns4'])) $ns_cmd = $ns_cmd." ".$v_ns4;
  199. if (!empty($_POST['v_ns5'])) $ns_cmd = $ns_cmd." ".$v_ns5;
  200. if (!empty($_POST['v_ns6'])) $ns_cmd = $ns_cmd." ".$v_ns6;
  201. if (!empty($_POST['v_ns7'])) $ns_cmd = $ns_cmd." ".$v_ns7;
  202. if (!empty($_POST['v_ns8'])) $ns_cmd = $ns_cmd." ".$v_ns8;
  203. exec ($ns_cmd, $output, $return_var);
  204. check_return_code($return_var,$output);
  205. unset($output);
  206. $v_ns1 = str_replace("'","", $v_ns1);
  207. $v_ns2 = str_replace("'","", $v_ns2);
  208. $v_ns3 = str_replace("'","", $v_ns3);
  209. $v_ns4 = str_replace("'","", $v_ns4);
  210. $v_ns5 = str_replace("'","", $v_ns5);
  211. $v_ns6 = str_replace("'","", $v_ns6);
  212. $v_ns7 = str_replace("'","", $v_ns7);
  213. $v_ns8 = str_replace("'","", $v_ns8);
  214. }
  215. // Set success message
  216. if (empty($_SESSION['error_msg'])) {
  217. $_SESSION['ok_msg'] = _('Changes has been saved.');
  218. }
  219. }
  220. // Render page
  221. render_page($user, $TAB, 'edit_user');
  222. // Flush session messages
  223. unset($_SESSION['error_msg']);
  224. unset($_SESSION['ok_msg']);