index.php 8.9 KB

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