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