updateInfo.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. if (file_exists("config.php")) {
  3. include 'config.php';
  4. } else {
  5. die("config.php must exist within the installation root folder!");
  6. }
  7. // Updates ftpuser's password
  8. $success = 0;
  9. $errorCount = 0;
  10. if (isset($errors)) {
  11. unset($errors);
  12. }
  13. if (isset($_GET['username'])) {
  14. $ftp_username = $_GET['username'];
  15. }
  16. if (isset($_GET['password'])) {
  17. $arrOfVals = trim($_GET['password']);
  18. }
  19. if (isset($arrOfVals) && !empty($arrOfVals)) {
  20. $arrOfVals = explode("\n", $arrOfVals);
  21. $arrOfVals = array_filter($arrOfVals);
  22. foreach ($arrOfVals as $passIn) {
  23. $passIn = trim($passIn);
  24. // Replace all tabs or spaces
  25. $pattern = '/\s+/';
  26. $passIn = preg_replace($pattern, ' ', $passIn);
  27. $keyAndVal = explode(' ', $passIn);
  28. if (count($keyAndVal) == 2) {
  29. $arr[$keyAndVal[0]] = $keyAndVal[1];
  30. }
  31. if (isset($arr['new_password']) && !empty($arr['new_password'])) {
  32. $ftp_pass = $arr['new_password'];
  33. }
  34. if (isset($arr['Directory']) && !empty($arr['Directory'])) {
  35. $update_dir = $arr['Directory'];
  36. }
  37. if (isset($arr['orig_user']) && !empty($arr['orig_user'])) {
  38. $ftp_old_username = $arr['orig_user'];
  39. }
  40. if (isset($arr['Username']) && !empty($arr['Username'])) {
  41. $ftp_username = $arr['Username'];
  42. }
  43. }
  44. }
  45. if (!isset($ftp_username) || !isset($update_dir)) {
  46. $errorCount++;
  47. $errors[] = "No FTP accounts could be modified! Updated username and homedir were not sent by the panel.";
  48. } else {
  49. if (substr_count($update_dir, '/') < 2) {
  50. $errorCount++;
  51. $errors[] = "In order to prevent security risks, users cannot be granted access to the main directories in the root file system of the server.&nbsp; You must go down two directory levels!&nbsp; Example: /games/user1!";
  52. }
  53. if (stripos($update_dir, "/") === FALSE || stripos($update_dir, "/") != 0) {
  54. $errorCount++;
  55. $errors[] = "You have not chosen a valid directory!";
  56. }
  57. if ($update_dir === "/var/www/" || stripos($update_dir, "/var/www/") !== FALSE) {
  58. $errorCount++;
  59. $errors[] = "You may not create ftp accounts into the protected EHCP directories using this program.&nbsp; Create these accounts using EHCP software.";
  60. }
  61. if (stripos($update_dir, "\\")) {
  62. $errorCount++;
  63. $errors[] = "This is not a Windows machine... use the correct slash character for path...";
  64. }
  65. // If the last character in the path is a slash (/) - Remove it from the string
  66. if (substr_count($update_dir, '/') > 2 && $update_dir[strlen($update_dir) - 1] == "/") {
  67. $end = strlen($update_dir) - 2;
  68. $update_dir = substr($update_dir, 0, $end);
  69. }
  70. if ($errorCount == 0) {
  71. // Security checks
  72. if (isset($ftp_pass)) {
  73. $ftp_password_db = mysql_real_escape_string($ftp_pass);
  74. }
  75. $ftp_username_db = mysql_real_escape_string($ftp_username);
  76. $SQL = "SELECT * FROM ftpaccounts WHERE ftpusername = '$ftp_username_db'";
  77. $Result = mysql_query($SQL, $connection);
  78. if ($Result !== FALSE) {
  79. $count = mysql_num_rows($Result);
  80. if ($count != 1) {
  81. $errorCount++;
  82. $errors[] = "FTP User " . $ftp_username . " does not exist in the database. Account information cannot be updated";
  83. } else {
  84. // Update user's password data into DB:
  85. $SQL = "UPDATE ftpaccounts SET ";
  86. if (isset($ftp_password_db)) {
  87. $SQL.= "password=password('$ftp_password_db'), ";
  88. }
  89. $SQL.= "homedir='$update_dir' WHERE ftpusername='$ftp_username_db'";
  90. $Result = mysql_query($SQL, $connection);
  91. if ($Result !== FALSE) {
  92. $success = 1;
  93. } else {
  94. $errorCount++;
  95. $errors[] = "Error code " . mysql_errno($connection) . ": " . mysql_error($connection);
  96. }
  97. }
  98. } else {
  99. $errorCount++;
  100. $errors[] = "Error code " . mysql_errno($connection) . ": " . mysql_error($connection);
  101. }
  102. }
  103. }
  104. // Log errors
  105. if ($errorCount > 0) {
  106. addToLog($errors);
  107. }
  108. // Return value:
  109. echo $success;
  110. ?>