listAllUsers.php 1.8 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. if (!isset($connection)) {
  15. die("Problem setting up connection!");
  16. } else {
  17. $SQL = "SELECT ftpusername, homedir, domainname, status FROM ftpaccounts";
  18. $Result = mysql_query($SQL, $connection);
  19. if ($Result !== FALSE) {
  20. $count = mysql_num_rows($Result);
  21. if ($count > 0) {
  22. while ($row = mysql_fetch_assoc($Result)) {
  23. // Only show custom entries... do not allow to modify EHCP accounts.
  24. // domainname field will be NULL for custom FTP entries
  25. if (!empty($row['homedir']) && (empty($row['domainname']) || $row['domainname'] === NULL) && (empty($row['status']) || $row['status'] === NULL)) {
  26. $countNotNull++;
  27. $username = $row['ftpusername'];
  28. $dir = $row['homedir'];
  29. $users_list.= $username . "\t" . $dir . "/./\n";
  30. }
  31. }
  32. if ($countNotNull == 0) {
  33. $errorCount++;
  34. $errors[] = "There are no custom FTP accounts yet in the EHCP database!";
  35. }
  36. } else {
  37. $errorCount++;
  38. $errors[] = "No FTP accounts exist from the ftpaccounts table!";
  39. }
  40. } else {
  41. $errorCount++;
  42. $errors[] = "Error code " . mysql_errno($connection) . ": " . mysql_error($connection);
  43. }
  44. // Log errors
  45. if ($errorCount > 0) {
  46. addToLog($errors);
  47. }
  48. }
  49. // Return the user list
  50. echo $users_list;
  51. ?>