Advertisement
Guest User

soucer.txt

a guest
May 4th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. <?php
  2. / **
  3. * This funtion will take a pattern and a folder as the argument and go thru it(recursivly if needed)and return the list of
  4. * all files in that folder.
  5. * Link: http://www.bin-co.com/php/scripts/filesystem/ls/
  6. * Arguments : $pattern - The pattern to look out for [OPTIONAL]
  7. * $folder - The path of the directory of which's directory list you want [OPTIONAL]
  8. * $recursivly - The funtion will traverse the folder tree recursivly if this is true. Defaults to false. [OPTIONAL]
  9. * $options - An array of values 'return_files' or 'return_folders' or both
  10. * Returns : A flat list with the path of all the files(no folders) that matches the condition given.
  11. * /
  12. function ls($pattern="*", $folder="", $recursivly=false, $options=array('return_files','return_folders')) {
  13. if($folder) {
  14. $current_folder = realpath('.');
  15. if(in_array('quiet', $options)) { // If quiet is on, we will suppress the 'no such folder' error
  16. if(!file_exists($folder)) return array();
  17. }
  18.  
  19. if(!chdir($folder)) return array();
  20. }
  21.  
  22.  
  23. $get_files = in_array('return_files', $options);
  24. $get_folders= in_array('return_folders', $options);
  25. $both = array();
  26. $folders = array();
  27.  
  28. // Get the all files and folders in the given directory.
  29. if($get_files) $both = glob($pattern, GLOB_BRACE + GLOB_MARK);
  30. if($recursivly or $get_folders) $folders = glob("*", GLOB_ONLYDIR + GLOB_MARK);
  31.  
  32. //If a pattern is specified, make sure even the folders match that pattern.
  33. $matching_folders = array();
  34. if($pattern !== '*') $matching_folders = glob($pattern, GLOB_ONLYDIR + GLOB_MARK);
  35.  
  36. //Get just the files by removing the folders from the list of all files.
  37. $all = array_values(array_diff($both,$folders));
  38.  
  39. if($recursivly or $get_folders) {
  40. foreach ($folders as $this_folder) {
  41. if($get_folders) {
  42. //If a pattern is specified, make sure even the folders match that pattern.
  43. if($pattern !== '*') {
  44. if(in_array($this_folder, $matching_folders)) array_push($all, $this_folder);
  45. }
  46. else array_push($all, $this_folder);
  47. }
  48.  
  49. if($recursivly) {
  50. // Continue calling this function for all the folders
  51. $deep_items = ls($pattern, $this_folder, $recursivly, $options); # :RECURSION:
  52. foreach ($deep_items as $item) {
  53. array_push($all, $this_folder . $item);
  54. }
  55. }
  56. }
  57. }
  58.  
  59. if($folder) chdir($current_folder);
  60. return $all;
  61. }
  62. libxml_disable_entity_loader (false);
  63. $xmlfile = $_POST['body']; //file_get_contents('php://input');
  64. $ dom = new DOMDocument () ;
  65. $dom->loadXML($xmlfile, LIBXML_NOENT | LIBXML_DTDLOAD);
  66. $creds = simplexml_import_dom($dom);
  67. $user = $creds->user;
  68. $pass = $creds->pass;
  69. echo "<html> <head> <link rel=\"stylesheet\" type=\"text/css\" href=\"./countrylane.css\"></head>";
  70. if ($user == "admin") {
  71. if ($pass == "0e1234") {
  72. echo "<p> The creds [ $user : $pass ] were correct! </p>";
  73. echo "<br>";
  74. print("<p> You won the directory listing! </p>");
  75. echo "<br>";
  76. $listing = ls("*");
  77. echo "<p>";
  78. print_r($listing);
  79. echo "</p>";
  80. } else {
  81. echo "Wrong password [ $user : $pass ]";
  82. }
  83. } else {
  84. echo "<p> Wrong creds [ $user : $pass ] </p>";
  85. }
  86. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement