addAccount.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. // Adds users to the database
  3. // Variables
  4. $success = 0;
  5. if (isset($_GET['username'])) {
  6. $ftp_username = $_GET['username'];
  7. }
  8. if (isset($_GET['password'])) {
  9. $ftp_pass = $_GET['password'];
  10. }
  11. if (isset($_GET['dir'])) {
  12. $rDir = $_GET['dir'];
  13. }
  14. if (isset($errors)) {
  15. unset($errors);
  16. }
  17. if (file_exists("config.php")) {
  18. include 'config.php';
  19. } else {
  20. die("config.php must exist within the installation root folder!");
  21. }
  22. include_once 'db_functions.php';
  23. // Did we properly receive the variables from the OGP agent?
  24. if (isset($ftp_username) && isset($ftp_pass) && isset($rDir)) {
  25. // We received all necessary variables. Process what we received.
  26. $errorCount = 0;
  27. $errorInstallInt = 0;
  28. // OGP should be doing this validation... but it's not
  29. // Custom directory validation
  30. if (substr_count($rDir, '/') < 2) {
  31. $errorCount++;
  32. $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!";
  33. }
  34. if (stripos($rDir, "/") === FALSE || stripos($rDir, "/") != 0) {
  35. $errorCount++;
  36. $errors[] = "You have not chosen a valid directory!";
  37. }
  38. if ($rDir === "/var/www/" || stripos($rDir, "/var/www/") !== FALSE) {
  39. $errorCount++;
  40. $errors[] = "You may not create ftp accounts into the protected EHCP directories using this program.&nbsp; Create these accounts using EHCP software.";
  41. }
  42. if (stripos($rDir, "\\")) {
  43. $errorCount++;
  44. $errors[] = "This is not a Windows machine... use the correct slash character for path...";
  45. }
  46. // If the last character in the path is a slash (/) - Remove it from the string
  47. if (substr_count($rDir, '/') >= 2 && $rDir[strlen($rDir) - 1] == "/") {
  48. $end = strlen($rDir) - 1;
  49. $rDir = substr($rDir, 0, $end);
  50. }
  51. if ($errorCount == 0) {
  52. // Security checks
  53. $ftp_password_db = escapeSQLStr($ftp_pass, $connection);
  54. $ftp_username_db = escapeSQLStr($ftp_username, $connection);
  55. $rDir = escapeSQLStr($rDir, $connection);
  56. $SQL = "SELECT id FROM ftpaccounts WHERE ftpusername = '$ftp_username_db'";
  57. $Result = execSQL($SQL, $connection);
  58. if ($Result !== FALSE) {
  59. $count = countSQLResult($Result);
  60. if ($count > 0) {
  61. $errorCount++;
  62. $errors[] = "The FTP username supplied already exists!&nbsp; Please enter another unique username!";
  63. } else {
  64. // Make sure data enter is unique for homedir
  65. $SQL = "SELECT id FROM ftpaccounts WHERE homedir = '$rDir'";
  66. $Result = execSQL($SQL, $connection);
  67. if ($Result !== FALSE) {
  68. $count = countSQLResult($Result);
  69. // Insert the data into the
  70. $SQL = "INSERT INTO ftpaccounts (ftpusername, password, homedir) VALUES ('$ftp_username_db', password('$ftp_password_db'), '$rDir')";
  71. $Result = execSQL($SQL, $connection);
  72. if ($Result !== FALSE) {
  73. $success = 1;
  74. } else {
  75. $errorCount++;
  76. $errors[] = getSQLError($connection);
  77. }
  78. } else {
  79. $errorCount++;
  80. $errors[] = getSQLError($connection);
  81. }
  82. if ($errorCount > 0 && $success == 0) {
  83. unset($_POST['createFTP']);
  84. include 'admin/ftpCreateForm.php';
  85. }
  86. }
  87. } else {
  88. $errorCount++;
  89. $errors[] = getSQLError($connection);
  90. }
  91. }
  92. }
  93. // Log errors
  94. if ($errorCount > 0) {
  95. addToLog($errors);
  96. }
  97. // Return value:
  98. echo $success;
  99. ?>