updateInfo.php 4.3 KB

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