You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

125 lines
3.0 KiB

  1. #!/usr/bin/perl
  2. # Lainsafe cli
  3. # This file is part of lainsafe.
  4. # lainsafe is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # lainsafe is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with lainsafe. If not, see <https://www.gnu.org/licenses/>.
  14. use Getopt::Long;
  15. use LWP::UserAgent;
  16. use strict;
  17. use warnings;
  18. # variables
  19. my $help;
  20. my $DEFAULT_SERVER;
  21. my $file;
  22. my $DISPLAY_ASCII;
  23. my $STORE_LINKS;
  24. # Default options, if no specified.
  25. $DEFAULT_SERVER = "https://lainsafe.delegao.moe";
  26. $DISPLAY_ASCII = 1; # 0 if you don't want the ascii
  27. $STORE_LINKS = 1; # 0 if you don't want to keep track of your upload
  28. my $ASCII_ART = <<'EOF';
  29. _..-- ----- --.._
  30. ,-'' `-.
  31. , \
  32. / \
  33. / ` . \
  34. ' / || ;
  35. ; ^/| |/ | |
  36. | /v /\`-'v√\'-|\ ,
  37. | /v` ,--- ---- .^.| ;
  38. : | /´@@`, ,@@`\ | ;
  39. ' | '. @@ / \@@ / |\ |;
  40. | ^| ----- --- | \/||
  41. ` |` | /\ /
  42. \ \ |/ |,
  43. ' ; \ /| |
  44. ` \ -- / | |
  45. ` `. .-' | /
  46. v,- `;._ _.; | |
  47. `'`\ |-_ -^'^'| |
  48. ------ |/
  49. EOF
  50. # Subs
  51. sub help
  52. {
  53. print "lainsafecli, a command line interface for lainsafe.\n";
  54. print "USAGE: lainsafecli [--server] FILE\n\n";
  55. print "if --server not given, $DEFAULT_SERVER is used.\n";
  56. exit;
  57. }
  58. ## PROGRAM
  59. my $ua = LWP::UserAgent->new;
  60. GetOptions ("server=s" => \$DEFAULT_SERVER,
  61. "help|" => \$help);
  62. if($help || not defined $ARGV[0])
  63. {
  64. &help;
  65. }
  66. # check if file is given
  67. $file = $ARGV[@ARGV-1];
  68. die "File does not exist\n" if !-e $file;
  69. my $url_to_upload = $DEFAULT_SERVER . "/upload.cgi";
  70. my $req;
  71. # Fake user agent
  72. $ua->agent("Mozilla/5.0 (X11; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0");
  73. # check if server is running lainsafe
  74. if(!$ua->get($url_to_upload)->is_success)
  75. {
  76. print "$url_to_upload is not running lainsafe.\n";
  77. exit;
  78. }
  79. $req = $ua->post($url_to_upload,
  80. Content_Type => 'form-data',
  81. Content => [
  82. "file" => [ $file ],
  83. ],
  84. );
  85. print $ASCII_ART if $DISPLAY_ASCII;
  86. if($req->{_content} =~ /instance/) # If someone knows how to do it another way, I'm all ears
  87. {
  88. print $req->{_content} . "\n";
  89. exit;
  90. }
  91. print $DEFAULT_SERVER . "/" . $req->{_content} . "\n";
  92. if($STORE_LINKS)
  93. {
  94. open FILE,'>>',"$ENV{HOME}/.cache/lainsafelinks" or die $!;
  95. print FILE $DEFAULT_SERVER . "/" . $req->{_content} . " $file" ."\n";
  96. close FILE;
  97. }