4 # This file is part of lainsafe.
6 # lainsafe is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # lainsafe is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with lainsafe. If not, see <https://www.gnu.org/licenses/>.
19 # This script is kind of deprecated. Use clainsafecli instead.
23 my $ua = LWP
::UserAgent
->new;
36 my $proxy_enabled = 1;
37 # Default options, if no specified.
38 $DEFAULT_SERVER = "https://lainsafe.delegao.moe";
39 $DISPLAY_ASCII = 1; # 0 if you don't want the ascii
40 $STORE_LINKS = 1; # 0 if you don't want to keep track of your upload
41 $LINKS_FILE = "$ENV{HOME}/.cache/lainsafelinks";
43 eval "use LWP::Protocol::socks; 1" or $proxy_enabled = 0;
44 my $ASCII_ART = <<'EOF';
53 | /v` ,--- ---- .^.| ;
55 ' | '. @@ / \@@ / |\ |;
70 print "This script is kind of deprecated. Use clainsafecli instead.\n";
74 print "lainsafecli, a command line interface for lainsafe.\n";
75 print "USAGE: lainsafecli [--tor | --i2p] [--server] FILE\n\n";
76 print "if --server not given, $DEFAULT_SERVER is used.\n";
77 print "--tor and --i2p are available\n" if $proxy_enabled;
78 print "--tor and --i2p are unavailable, flag are ignored\n" unless $proxy_enabled;
84 my $checker = $ua->proxy([qw(http https)] => 'socks://localhost:9050');
89 my $checker = $ua->proxy([qw(http https)] => 'http://localhost:4444');
94 GetOptions
("server=s" => \
$DEFAULT_SERVER,
98 "get-response"=>\
$get_response
101 &help
if $help || not defined $ARGV[0];
103 print "What are you trying to do? I don't really get you sometimes...\n";
106 &enable_tor
if $tor and $proxy_enabled;
107 &enable_i2p
if $i2p and $proxy_enabled;
110 # check if file is given
112 $file = $ARGV[@ARGV-1];
114 die "File does not exist\n" unless -e
$file;
120 $ua->agent("Mozilla/5.0 (X11; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0");
122 # modify url if necessary
123 substr($DEFAULT_SERVER, 0, 0, 'https://') unless $DEFAULT_SERVER =~ /^(http|https):\/\
//;
124 # check if server is running lainsafe
126 my $url_to_upload = $DEFAULT_SERVER . "/upload.cgi";
127 if (!$ua->get($url_to_upload)->is_success) {
128 print "$url_to_upload is not running lainsafe. (--get-response to check the error)\n";
129 print $ua->get($url_to_upload)->decoded_content if $get_response;
134 $req = $ua->post($url_to_upload,
135 Content_Type
=> 'form-data',
142 print $ASCII_ART if $DISPLAY_ASCII;
143 if ($req->{_content
} =~ /instance/) # If someone knows how to do it another way, I'm all ears
145 print $req->{_content
} . "\n";
148 print $req->{_content
} . "\n";
151 open FILE
,'>>',$LINKS_FILE or die $!;
152 print FILE
$req->{_content
} . " $file" ."\n";