Whoops
[lainsafe.git] / lainsafecli
blob18c0bf57f04056f99f8df58867057cbdb7b3ebc9
1 #!/usr/bin/perl
2 # Lainsafe cli
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/>.
21 use Getopt::Long;
22 use LWP::UserAgent;
24 use strict;
25 use warnings;
26 # variables
27 my $help;
28 my $DEFAULT_SERVER;
29 my $file;
30 my $DISPLAY_ASCII;
32 # Default options, if no specified.
33 $DEFAULT_SERVER = "https://lainsafe.delegao.moe";
34 $DISPLAY_ASCII = 1; # 0 if you don't want the ascii
36 my $ASCII_ART = <<'EOF';
39 _..-- ----- --.._
40 ,-'' `-.
41 , \
42 / \
43 / ` . \
44 ' / || ;
45 ; ^/| |/ | |
46 | /v /\`-'v√\'-|\ ,
47 | /v` ,--- ---- .^.| ;
48 : | /´@@`, ,@@`\ | ;
49 ' | '. @@ / \@@ / |\ |;
50 | ^| ----- --- | \/||
51 ` |` | /\ /
52 \ \ |/ |,
53 ' ; \ /| |
54 ` \ -- / | |
55 ` `. .-' | /
56 v,- `;._ _.; | |
57 `'`\ |-_ -^'^'| |
58 ------ |/
60 EOF
62 # Subs
64 sub help
66 print "lainsafecli, a command line interface for lainsafe.\n";
67 print "USAGE: lainsafecli [--server] FILE\n\n";
68 print "if --server not given, $DEFAULT_SERVER is used.\n";
70 exit;
73 ## PROGRAM
74 my $ua = LWP::UserAgent->new;
75 GetOptions ("server=s" => \$DEFAULT_SERVER,
76 "help|" => \$help);
78 if($help || not defined $ARGV[0])
80 &help;
83 # check if file is given
85 $file = $ARGV[@ARGV-1];
87 die "File does not exist\n" if !-e $file;
89 die "Give a file\n" unless defined $file;
93 my $url_to_upload = $DEFAULT_SERVER . "/upload.cgi";
94 my $req;
96 # Fake user agent
97 $ua->agent("Mozilla/5.0 (X11; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0");
99 # check if server is running lainsafe
101 if(!$ua->get($url_to_upload)->is_success)
103 print "$url_to_upload is not running lainsafe.\n";
104 exit;
108 $req = $ua->post($url_to_upload,
109 Content_Type => 'form-data',
110 Content => [
111 "file" => [ $file ],
116 print $ASCII_ART if $DISPLAY_ASCII;
117 print $DEFAULT_SERVER . "/" . $req->{_content} . "\n";