listAllUsers.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. // Returns a list of all custom FTP users
  3. // Only custom users are setup when tying into the EHCP FTP API
  4. $countNotNull = 0;
  5. $users_list = "";
  6. $success = 0;
  7. $errorCount = 0;
  8. if (isset($errors)) {
  9. unset($errors);
  10. }
  11. if (!isset($connection)) {
  12. include "config.php";
  13. }
  14. include_once 'db_functions.php';
  15. if (!isset($connection)) {
  16. die("Problem setting up connection!");
  17. } else {
  18. $SQL = "SELECT ftpusername, homedir, domainname, status FROM ftpaccounts";
  19. $Result = execSQL($SQL, $connection);
  20. if ($Result !== FALSE) {
  21. $count = countSQLResult($Result);
  22. if ($count > 0) {
  23. while ($row = getSQLRow($Result)) {
  24. // Only show custom entries... do not allow to modify EHCP accounts.
  25. // domainname field will be NULL for custom FTP entries
  26. if (!empty($row['homedir']) && (empty($row['domainname']) || $row['domainname'] === NULL) && (empty($row['status']) || $row['status'] === NULL)) {
  27. $countNotNull++;
  28. $username = $row['ftpusername'];
  29. $dir = $row['homedir'];
  30. $users_list.= $username . "\t" . $dir . "/./\n";
  31. }
  32. }
  33. if ($countNotNull == 0) {
  34. $errorCount++;
  35. $errors[] = "There are no custom FTP accounts yet in the EHCP database!";
  36. }
  37. } else {
  38. $errorCount++;
  39. $errors[] = "No FTP accounts exist from the ftpaccounts table!";
  40. }
  41. } else {
  42. $errorCount++;
  43. $errors[] = getSQLError($connection);
  44. $success = 0;
  45. }
  46. // Log errors
  47. if ($errorCount > 0) {
  48. addToLog($errors);
  49. }
  50. }
  51. // Return the user list
  52. echo $users_list;
  53. ?>