eyebrow 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. my $tlUrl = "https://the-eye.eu/public/";
  5. my %currentPageRef;
  6. my $pageNest;
  7. my $curl = `which curl`;
  8. chomp $curl;
  9. if ( $curl eq "" || ! defined $curl ) {
  10. print "No curl, exiting...\n";
  11. exit 1;
  12. }
  13. sub dumpPage {
  14. my $page = shift;
  15. my @pageContent = split("\n", `$curl -s $page`);
  16. if ($page =~ m/public\/(.*)$/) {
  17. $pageNest = $1;
  18. }
  19. if ( $pageNest =~ m/\.\.\/$/ ) {
  20. # Need to lop off old nested dir
  21. $pageNest =~ s/\/([^\/]*\/\.\.\/)$//g;
  22. }
  23. if ( $pageNest !~ m/\/$/ ) {
  24. $pageNest .= "/";
  25. }
  26. my $count = 0;
  27. foreach my $line (@pageContent) {
  28. if ($line =~ m/text\/javascript/ || $line =~ m/\/div/ || $line =~ m/\/i/ || $line =~ m/img\ src/ || $line =~ m/\/script/) {
  29. next;
  30. }
  31. #if ($line =~ m/\"(.*\/)\"\>(.*)\</) {
  32. if ($line =~ m/\"(.*)\"\>(.*)\</) {
  33. my $link = $1;
  34. $link = $pageNest . $link;
  35. my $name = $2;
  36. if ($name =~ m/&gt;/) {
  37. $name =~ s/&gt;/>/g;
  38. }
  39. print "$count : $name\n";
  40. $currentPageRef{$count} = $link;
  41. $count++;
  42. }
  43. }
  44. }
  45. sub pageReturn {
  46. my $choice = shift;
  47. my $newPage = $tlUrl . $currentPageRef{$choice};
  48. return $newPage;
  49. }
  50. sub download {
  51. my $link = shift;
  52. system("wget $link");
  53. }
  54. sub printHelp {
  55. my $help = <<EOF
  56. * Basic usage:
  57. Type the number that corresponds with the link you'd like to browse to to browse there.
  58. ( Beware selecting a binary file will dump the output to your term )
  59. * Commands:
  60. ** top
  61. Return to the docroot of browseable files ( /public/ )
  62. ** download
  63. Type 'download' followed by the selection number to download the file
  64. ** search
  65. Type 'search' followed by a term to search the current dir tree
  66. If doing a multiword search, wrap the query in quotes like "search terms here"
  67. ** file
  68. Type file followed by the selection number to get the full link path
  69. EOF
  70. ;
  71. print "$help";
  72. }
  73. if ( defined $ARGV[0] && $ARGV[0] =~ /h/ ) {
  74. printHelp();
  75. exit 0;
  76. }
  77. print "The Eye CLI Browser\n";
  78. dumpPage($tlUrl);
  79. while () {
  80. print "Enter a selection: ";
  81. my $input = <STDIN>;
  82. chomp $input;
  83. if ($input =~ m/download/) {
  84. my @inputs = split(" ", $input);
  85. my $dlLink = $currentPageRef{$inputs[1]};
  86. $dlLink = $tlUrl . $dlLink;
  87. download($dlLink);
  88. next;
  89. }
  90. if ($input =~ m/file/) {
  91. my @inputs = split(" ", $input);
  92. my $queryLink = $currentPageRef{$inputs[1]};
  93. $queryLink = $tlUrl . $queryLink;
  94. print "File is: $queryLink\n";
  95. next;
  96. }
  97. if ($input =~ m/quit/||$input =~ /exit/) {
  98. print "Exiting..\n";
  99. exit 0;
  100. }
  101. if ($input =~ m/search/) {
  102. my @inputs = split(" ", $input);
  103. shift(@inputs);
  104. my $searchTerm = join(" ", @inputs);
  105. #my $searchTerm = $inputs[1];
  106. if ( $searchTerm =~ m/\"(.*)\"/ ) {
  107. $searchTerm = $1;
  108. $searchTerm =~ s/\ /%20/g;
  109. }
  110. foreach my $key ( keys %currentPageRef ) {
  111. if ( $currentPageRef{$key} =~ m/$searchTerm/i ) {
  112. my $printLine = $currentPageRef{$key};
  113. $printLine =~ s/%20/\ /g;
  114. $printLine =~ s/%2C/,/g;
  115. $printLine =~ s/%26/&/g;
  116. print "$key : $printLine\n";
  117. }
  118. }
  119. next;
  120. }
  121. my $newPage;
  122. if ($input eq "top") {
  123. $newPage = $tlUrl;
  124. } else {
  125. $newPage = pageReturn($input);
  126. #print "Your next request is: $newPage\n";
  127. }
  128. %currentPageRef = ();
  129. dumpPage($newPage);
  130. }