DirectoryServer.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. //These vars may be changed to fit your needs.
  3. //User executing the script must have write access to the file directory.
  4. define("PASSWORD_FILE", "pw");
  5. define("RECORD_FILE", "RecordFile.data.php");
  6. define("TIMEOUT", 60);
  7. include("lib/PasswordManager.class.php");
  8. include("lib/RecordManager.class.php");
  9. $pm = new PasswordManager();
  10. //Check if password exists. If it doesn't exist create the password form for the user
  11. //to input their passwords.
  12. if(!file_exists(PASSWORD_FILE)){
  13. $error = "";
  14. $message = "";
  15. if(!empty($_POST)){
  16. $error = $pm->validatePasswords($_POST);
  17. if(empty($error)){
  18. $pm->savePasswords($_POST);
  19. header("Location: DirectoryServer.php");
  20. exit;
  21. }
  22. }
  23. echo $pm->generateCss();
  24. echo $error;
  25. echo $pm->generatePasswordForm();
  26. }
  27. else{
  28. //If the password file exists use controller logic
  29. $rm = new RecordManager();
  30. $passwords = $pm->getPasswords();
  31. $rm->expireRecords();
  32. //If upload mode and uploadPassword matches
  33. if(!empty($_GET["query"]) && $_GET["query"] == "upload"){
  34. if(isset($_GET["uploadPassword"]) && md5($_GET["uploadPassword"]) == $passwords["uploadPassword"]){
  35. //Use the following code to read post body. Not regular form posts which would be accessed with $_POST
  36. $postText = trim(file_get_contents('php://input'));
  37. $output = $rm->uploadRecords($postText);
  38. echo $output;
  39. }
  40. }
  41. //If download mode and downloadPassword matches
  42. elseif(!empty($_GET["query"]) && $_GET["query"] == "download"){
  43. if(isset($_GET["downloadPassword"]) && md5($_GET["downloadPassword"]) == $passwords["downloadPassword"]){
  44. $output = $rm->downloadRecords();
  45. echo $output;
  46. }
  47. }
  48. //If upDown mode and downloadPassword and uploadPassword matches
  49. elseif(!empty($_GET["query"]) && $_GET["query"] == "upDown"){
  50. if(isset($_GET["downloadPassword"]) && md5($_GET["downloadPassword"]) == $passwords["downloadPassword"]
  51. && isset($_GET["uploadPassword"]) && md5($_GET["uploadPassword"]) == $passwords["uploadPassword"] ){
  52. // Use the following code to read post body. Not regular form posts which would be accessed with $_POST
  53. $postText = trim(file_get_contents('php://input') );
  54. $output = $rm->downloadRecords();
  55. echo $output;
  56. $output = $rm->uploadRecords($postText);
  57. echo $output;
  58. }
  59. }
  60. //Else you're in view mode just display the records with html and css
  61. else{
  62. echo $rm->generateCss();
  63. echo $rm->viewRecords();
  64. }
  65. }
  66. ?>
粤ICP备19079148号