123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- #!/usr/bin/perl
- use strict;
- use warnings;
- my $tlUrl = "https://the-eye.eu/public/";
- my %currentPageRef;
- my $pageNest;
- my $curl = `which curl`;
- chomp $curl;
- if ( $curl eq "" || ! defined $curl ) {
- print "No curl, exiting...\n";
- exit 1;
- }
- sub dumpPage {
- my $page = shift;
- my @pageContent = split("\n", `$curl -s $page`);
- if ($page =~ m/public\/(.*)$/) {
- $pageNest = $1;
- }
- if ( $pageNest =~ m/\.\.\/$/ ) {
- # Need to lop off old nested dir
- $pageNest =~ s/\/([^\/]*\/\.\.\/)$//g;
- }
- if ( $pageNest !~ m/\/$/ ) {
- $pageNest .= "/";
- }
- my $count = 0;
- foreach my $line (@pageContent) {
- if ($line =~ m/text\/javascript/ || $line =~ m/\/div/ || $line =~ m/\/i/ || $line =~ m/img\ src/ || $line =~ m/\/script/) {
- next;
- }
- #if ($line =~ m/\"(.*\/)\"\>(.*)\</) {
- if ($line =~ m/\"(.*)\"\>(.*)\</) {
- my $link = $1;
- $link = $pageNest . $link;
- my $name = $2;
- if ($name =~ m/>/) {
- $name =~ s/>/>/g;
- }
- print "$count : $name\n";
- $currentPageRef{$count} = $link;
- $count++;
- }
- }
- }
- sub pageReturn {
- my $choice = shift;
- my $newPage = $tlUrl . $currentPageRef{$choice};
- return $newPage;
- }
- sub download {
- my $link = shift;
- system("wget $link");
- }
- sub printHelp {
- my $help = <<EOF
- * Basic usage:
- Type the number that corresponds with the link you'd like to browse to to browse there.
- ( Beware selecting a binary file will dump the output to your term )
- * Commands:
- ** top
- Return to the docroot of browseable files ( /public/ )
- ** download
- Type 'download' followed by the selection number to download the file
- ** search
- Type 'search' followed by a term to search the current dir tree
- If doing a multiword search, wrap the query in quotes like "search terms here"
- ** file
- Type file followed by the selection number to get the full link path
- EOF
- ;
- print "$help";
- }
- if ( defined $ARGV[0] && $ARGV[0] =~ /h/ ) {
- printHelp();
- exit 0;
- }
- print "The Eye CLI Browser\n";
- dumpPage($tlUrl);
- while () {
- print "Enter a selection: ";
- my $input = <STDIN>;
- chomp $input;
- if ($input =~ m/download/) {
- my @inputs = split(" ", $input);
- my $dlLink = $currentPageRef{$inputs[1]};
- $dlLink = $tlUrl . $dlLink;
- download($dlLink);
- next;
- }
- if ($input =~ m/file/) {
- my @inputs = split(" ", $input);
- my $queryLink = $currentPageRef{$inputs[1]};
- $queryLink = $tlUrl . $queryLink;
- print "File is: $queryLink\n";
- next;
- }
- if ($input =~ m/quit/||$input =~ /exit/) {
- print "Exiting..\n";
- exit 0;
- }
- if ($input =~ m/search/) {
- my @inputs = split(" ", $input);
- shift(@inputs);
- my $searchTerm = join(" ", @inputs);
- #my $searchTerm = $inputs[1];
- if ( $searchTerm =~ m/\"(.*)\"/ ) {
- $searchTerm = $1;
- $searchTerm =~ s/\ /%20/g;
- }
- foreach my $key ( keys %currentPageRef ) {
- if ( $currentPageRef{$key} =~ m/$searchTerm/i ) {
- my $printLine = $currentPageRef{$key};
- $printLine =~ s/%20/\ /g;
- $printLine =~ s/%2C/,/g;
- $printLine =~ s/%26/&/g;
- print "$key : $printLine\n";
- }
- }
- next;
- }
- my $newPage;
- if ($input eq "top") {
- $newPage = $tlUrl;
- } else {
- $newPage = pageReturn($input);
- #print "Your next request is: $newPage\n";
- }
- %currentPageRef = ();
- dumpPage($newPage);
- }
|