2020-04-19 14:39:34 +00:00
|
|
|
|
#!/usr/bin/perl
|
|
|
|
|
# Lainsafe cli
|
|
|
|
|
|
|
|
|
|
# This file is part of lainsafe.
|
|
|
|
|
|
|
|
|
|
# lainsafe is free software: you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
# lainsafe is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with lainsafe. If not, see <https://www.gnu.org/licenses/>.
|
2020-08-15 19:06:24 +00:00
|
|
|
|
|
2021-02-09 17:23:43 +00:00
|
|
|
|
# This script is kind of deprecated. Use clainsafecli instead.
|
|
|
|
|
|
2020-04-19 14:39:34 +00:00
|
|
|
|
use Getopt::Long;
|
|
|
|
|
use LWP::UserAgent;
|
2020-08-15 19:06:24 +00:00
|
|
|
|
my $ua = LWP::UserAgent->new;
|
2020-04-19 14:39:34 +00:00
|
|
|
|
use strict;
|
|
|
|
|
use warnings;
|
|
|
|
|
# variables
|
|
|
|
|
my $help;
|
2020-08-15 19:06:24 +00:00
|
|
|
|
my $tor;
|
2020-09-04 17:31:01 +00:00
|
|
|
|
my $i2p;
|
2020-08-15 19:48:03 +00:00
|
|
|
|
my $get_response;
|
2020-04-19 14:39:34 +00:00
|
|
|
|
my $DEFAULT_SERVER;
|
|
|
|
|
my $file;
|
|
|
|
|
my $DISPLAY_ASCII;
|
2020-08-06 20:55:51 +00:00
|
|
|
|
my $STORE_LINKS;
|
2020-08-07 17:27:57 +00:00
|
|
|
|
my $LINKS_FILE;
|
2020-09-04 17:31:01 +00:00
|
|
|
|
my $proxy_enabled = 1;
|
2020-04-19 14:39:34 +00:00
|
|
|
|
# Default options, if no specified.
|
2020-10-20 14:06:15 +00:00
|
|
|
|
$DEFAULT_SERVER = "https://lainsafe.delegao.moe";
|
2020-04-19 14:39:34 +00:00
|
|
|
|
$DISPLAY_ASCII = 1; # 0 if you don't want the ascii
|
2020-08-15 19:06:24 +00:00
|
|
|
|
$STORE_LINKS = 1; # 0 if you don't want to keep track of your upload
|
2020-08-07 17:29:56 +00:00
|
|
|
|
$LINKS_FILE = "$ENV{HOME}/.cache/lainsafelinks";
|
2020-08-07 17:27:57 +00:00
|
|
|
|
|
2020-09-04 17:31:01 +00:00
|
|
|
|
eval "use LWP::Protocol::socks; 1" or $proxy_enabled = 0;
|
2020-04-19 14:39:34 +00:00
|
|
|
|
my $ASCII_ART = <<'EOF';
|
|
|
|
|
_..-- ----- --.._
|
|
|
|
|
,-'' `-.
|
|
|
|
|
, \
|
|
|
|
|
/ \
|
|
|
|
|
/ ` . \
|
|
|
|
|
' / || ;
|
|
|
|
|
; ^/| |/ | |
|
|
|
|
|
| /v /\`-'v√\'-|\ ,
|
|
|
|
|
| /v` ,--- ---- .^.| ;
|
|
|
|
|
: | /´@@`, ,@@`\ | ;
|
|
|
|
|
' | '. @@ / \@@ / |\ |;
|
|
|
|
|
| ^| ----- --- | \/||
|
|
|
|
|
` |` | /\ /
|
|
|
|
|
\ \ |/ |,
|
|
|
|
|
' ; \ /| |
|
|
|
|
|
` \ -- / | |
|
|
|
|
|
` `. .-' | /
|
|
|
|
|
v,- `;._ _.; | |
|
|
|
|
|
`'`\ |-_ -^'^'| |
|
|
|
|
|
------ |/
|
2020-08-15 19:06:24 +00:00
|
|
|
|
|
2020-04-19 14:39:34 +00:00
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
# Subs
|
|
|
|
|
|
|
|
|
|
sub help
|
2021-02-09 17:23:43 +00:00
|
|
|
|
{
|
|
|
|
|
print "lainsafecli, a command line interface for lainsafe.\n";
|
|
|
|
|
print "USAGE: lainsafecli [--tor | --i2p] [--server] FILE\n\n";
|
|
|
|
|
print "if --server not given, $DEFAULT_SERVER is used.\n";
|
|
|
|
|
print "--tor and --i2p are available\n" if $proxy_enabled;
|
|
|
|
|
print "--tor and --i2p are unavailable, flag are ignored\n" unless $proxy_enabled;
|
|
|
|
|
exit;
|
|
|
|
|
}
|
2020-08-15 19:06:24 +00:00
|
|
|
|
|
|
|
|
|
sub enable_tor
|
2021-02-09 17:23:43 +00:00
|
|
|
|
{
|
|
|
|
|
my $checker = $ua->proxy([qw(http https)] => 'socks://localhost:9050');
|
|
|
|
|
}
|
2020-04-19 14:39:34 +00:00
|
|
|
|
|
2020-09-04 17:31:01 +00:00
|
|
|
|
sub enable_i2p
|
2021-02-09 17:23:43 +00:00
|
|
|
|
{
|
|
|
|
|
my $checker = $ua->proxy([qw(http https)] => 'http://localhost:4444');
|
|
|
|
|
}
|
2020-09-04 17:31:01 +00:00
|
|
|
|
|
2020-04-19 14:39:34 +00:00
|
|
|
|
## PROGRAM
|
2020-08-15 19:06:24 +00:00
|
|
|
|
|
2020-04-19 14:39:34 +00:00
|
|
|
|
GetOptions ("server=s" => \$DEFAULT_SERVER,
|
2020-08-15 19:06:24 +00:00
|
|
|
|
"help|" => \$help,
|
2020-08-15 19:48:03 +00:00
|
|
|
|
"tor"=> \$tor,
|
2020-09-04 17:31:01 +00:00
|
|
|
|
"i2p"=>\$i2p,
|
2020-08-21 01:51:41 +00:00
|
|
|
|
"get-response"=>\$get_response
|
2021-02-09 17:23:43 +00:00
|
|
|
|
);
|
2020-04-19 14:39:34 +00:00
|
|
|
|
|
2020-08-06 21:52:52 +00:00
|
|
|
|
&help if $help || not defined $ARGV[0];
|
2020-09-04 17:31:01 +00:00
|
|
|
|
if ($i2p and $tor) {
|
2021-02-09 17:23:43 +00:00
|
|
|
|
print "What are you trying to do? I don't really get you sometimes...\n";
|
|
|
|
|
exit;
|
2020-09-04 17:31:01 +00:00
|
|
|
|
}
|
|
|
|
|
&enable_tor if $tor and $proxy_enabled;
|
|
|
|
|
&enable_i2p if $i2p and $proxy_enabled;
|
2020-08-21 01:51:41 +00:00
|
|
|
|
|
2020-04-19 14:39:34 +00:00
|
|
|
|
|
|
|
|
|
# check if file is given
|
|
|
|
|
|
2020-04-22 00:49:13 +00:00
|
|
|
|
$file = $ARGV[@ARGV-1];
|
|
|
|
|
|
2020-08-06 21:52:52 +00:00
|
|
|
|
die "File does not exist\n" unless -e $file;
|
2020-04-22 00:49:13 +00:00
|
|
|
|
|
2020-10-08 11:49:19 +00:00
|
|
|
|
|
2020-04-19 14:39:34 +00:00
|
|
|
|
my $req;
|
2020-04-20 14:58:59 +00:00
|
|
|
|
|
|
|
|
|
# Fake user agent
|
|
|
|
|
$ua->agent("Mozilla/5.0 (X11; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0");
|
|
|
|
|
|
2020-10-08 11:49:19 +00:00
|
|
|
|
# modify url if necessary
|
|
|
|
|
substr($DEFAULT_SERVER, 0, 0, 'https://') unless $DEFAULT_SERVER =~ /^(http|https):\/\//;
|
2020-04-19 14:39:34 +00:00
|
|
|
|
# check if server is running lainsafe
|
|
|
|
|
|
2020-10-08 11:49:19 +00:00
|
|
|
|
my $url_to_upload = $DEFAULT_SERVER . "/upload.cgi";
|
2020-08-15 19:06:24 +00:00
|
|
|
|
if (!$ua->get($url_to_upload)->is_success) {
|
2021-02-09 17:23:43 +00:00
|
|
|
|
print "$url_to_upload is not running lainsafe. (--get-response to check the error)\n";
|
|
|
|
|
print $ua->get($url_to_upload)->decoded_content if $get_response;
|
|
|
|
|
exit;
|
2020-04-19 14:39:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$req = $ua->post($url_to_upload,
|
2020-09-04 17:31:01 +00:00
|
|
|
|
Content_Type => 'form-data',
|
|
|
|
|
Content => [
|
2021-02-09 17:23:43 +00:00
|
|
|
|
"file" => [ $file ],
|
|
|
|
|
],
|
|
|
|
|
);
|
2020-04-19 14:39:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print $ASCII_ART if $DISPLAY_ASCII;
|
2020-08-15 19:06:24 +00:00
|
|
|
|
if ($req->{_content} =~ /instance/) # If someone knows how to do it another way, I'm all ears
|
2021-02-09 17:23:43 +00:00
|
|
|
|
{
|
|
|
|
|
print $req->{_content} . "\n";
|
|
|
|
|
exit;
|
|
|
|
|
}
|
2020-08-30 16:08:36 +00:00
|
|
|
|
print $req->{_content} . "\n";
|
2020-08-15 19:06:24 +00:00
|
|
|
|
|
|
|
|
|
if ($STORE_LINKS) {
|
2021-02-09 17:23:43 +00:00
|
|
|
|
open FILE,'>>',$LINKS_FILE or die $!;
|
|
|
|
|
print FILE $req->{_content} . " $file" ."\n";
|
|
|
|
|
close FILE;
|
2020-08-15 19:06:24 +00:00
|
|
|
|
}
|
2021-02-09 17:23:43 +00:00
|
|
|
|
|