diff --git a/clainsafecli/Makefile b/clainsafecli/Makefile index e27307d..6dd1528 100644 --- a/clainsafecli/Makefile +++ b/clainsafecli/Makefile @@ -3,13 +3,15 @@ TARGET = clainsafecli OBJS = clainsafecli.o CC = cc -CFLAGS = -MD -std=c11 -Wall -Wextra -O2 -march=native -lcurl +CFLAGSDEF = -MD -std=c11 -Wall -Wextra -O2 -march=native -lcurl +CFLAGS = -O2 -march=native + $(TARGET): clainsafecli.o - $(CC) $(CFLAGS) $(OBJS) -o $(TARGET) + $(CC) $(CFLAGS) $(CFLAGSDEF) $(OBJS) -o $(TARGET) %.o: %.c - $(CC) -c $(CFLAGS) $< -o $@ + $(CC) -c $(CFLAGS) $(CFLAGSDEF) $< -o $@ -include *.d diff --git a/clainsafecli/clainsafecli.c b/clainsafecli/clainsafecli.c index 8967abc..6c7680d 100644 --- a/clainsafecli/clainsafecli.c +++ b/clainsafecli/clainsafecli.c @@ -27,6 +27,7 @@ main(int argc, char **argv) fprintf(stderr,"Error allocating memory!\n"); return -1; } + CURL *easy_handle = curl_easy_init(); if(!easy_handle) { diff --git a/doc/clainsafecli.1 b/doc/clainsafecli.1 new file mode 100644 index 0000000..c2d55d8 --- /dev/null +++ b/doc/clainsafecli.1 @@ -0,0 +1,51 @@ +.\"Manpage for lainsafe +.TH clainsafecli 1 +.SH NAME +clainsafecli \- File uploader + +.SH DESCRIPTION + +clainsafecli is a file uploader. Intended for lainsafe, but also works +for 0x0.st, i.kalli.st and probably others. + +.SH INSTALLATION +.in +4n +.EX +make +(or gcc clainsafecli.c -lcurl -o clainsafecli) +cp clainsafecli ~/.local/bin +.EE +.SH OPTIONS + +.PP +.B +--server= +Specifies which server to use, can be a lainsafe instance, 0x0.st +instance or i.kalli.st. Probably other similar software. + +.B +--tor +Routes all the traffic on the socks proxy at 127.0.0.1:9050, +which is usually tor. This can be edited in the +.B options.h +file + +.B +--i2p +Routes all the traffic on the http proxy at 127.0.0.1:4444, +which is usually I2P. This can be edited in the +.B options.h +file + +.B +--ipv6 or -6 +Forces curl to use IPv6 only. + +.B +--ipv4 or -4 +Forces curl to use IPv4 only. + +.B +--silent or -S +tells clainsafecli to be silent. This means, it won't +print the progress. diff --git a/doc/lainsafecli.1 b/doc/lainsafecli.1 deleted file mode 100644 index aca4e40..0000000 --- a/doc/lainsafecli.1 +++ /dev/null @@ -1,94 +0,0 @@ -.\" Manpage for lainsafecli. -.TH lainsafecli 1 -.SH NAME -lainsafecli \- Command line interface for lainsafe -.SH SYNOPSIS -lainsafecli -.I -[--tor | --i2p] [--server] -file - -.SH DESCRIPTION - -.I lainsafecli -uploads a file to a given lainsafe server. This server may -be specified with the -.I --server -flag. If -.I --server -is not given. The content of the variable -.I $DEFAULT_SERVER -will be used instead. This variable is in the script. In the official -packages. this is https://lainsafe.delegao.moe - -.SH OPTIONS - -.I --server -Sets the server to use. If it is not given $DEFAULT_SERVER will be used instead. - -.I --help -Displays a simple help message and exits. This also specify which -server will be used if no -.I --server -is given. - -.I --tor -Uses tor to upload the file. This requires -.I LWP::Protocol::socks -to be installed on your system. You also need to have tor running at -127.0.0.1:9050 -If LWP::Protocol::socks is not installed, --tor is ignored, so don't -try it - -.I --i2p -Routes the traffic through I2P. This uses the HTTP proxy (which is -normally in port 4444). So -.I LWP::Protocol::socks -is not necessary. - -.I --get-response -If the server returned an error, --get-response will make lainsafecli -print the content, so it can help you find out why -lainsafecli isn't working! - -.SH CONFIGURATION - -there are configuration values in -.I lainsafecli -line 34. - -.I $DISPLAY_ASCII -If true (Any number but 0), It will display an ASCII art if no error -returned. - -.I $STORE_LINKS -If true, lainsafecli will store the links on a file, specified by -.I $LINKS_FILE - -.SH TROUBLESHOOTING - -.SS "whatever" is not running lainsafe. But works in the browser. - -This only happens with https lainsafe instances. To solve that. Make -sure that the module -.I LWP::UserAgent::https -is installed. You can install it using -.I cpan(1) - -.SS HTTP 413 is returned - -The file you specified is too big for the instance. Try using another -instance. By default lainsafe supports up to 100MBs. But this can be configured in lainsafe -.B AND -the web server. If the file exceds whatever your -.B server -allows. lainsafe can set another limit. If the lainsafe limit is less -than the server limit. lainsafe will return its own error message. - -.SH AUTHORS - -qorg11 - -.SH LICENSE - -GPLv3 or later. diff --git a/lainsafecli b/lainsafecli deleted file mode 100755 index f5dca29..0000000 --- a/lainsafecli +++ /dev/null @@ -1,155 +0,0 @@ -#!/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 . - -# This script is kind of deprecated. Use clainsafecli instead. - -use Getopt::Long; -use LWP::UserAgent; -my $ua = LWP::UserAgent->new; -use strict; -use warnings; -# variables -my $help; -my $tor; -my $i2p; -my $get_response; -my $DEFAULT_SERVER; -my $file; -my $DISPLAY_ASCII; -my $STORE_LINKS; -my $LINKS_FILE; -my $proxy_enabled = 1; -# Default options, if no specified. -$DEFAULT_SERVER = "https://lainsafe.delegao.moe"; -$DISPLAY_ASCII = 1; # 0 if you don't want the ascii -$STORE_LINKS = 1; # 0 if you don't want to keep track of your upload -$LINKS_FILE = "$ENV{HOME}/.cache/lainsafelinks"; - -eval "use LWP::Protocol::socks; 1" or $proxy_enabled = 0; -my $ASCII_ART = <<'EOF'; - _..-- ----- --.._ - ,-'' `-. - , \ - / \ - / ` . \ - ' / || ; - ; ^/| |/ | | - | /v /\`-'v√\'-|\ , - | /v` ,--- ---- .^.| ; - : | /´@@`, ,@@`\ | ; - ' | '. @@ / \@@ / |\ |; - | ^| ----- --- | \/|| - ` |` | /\ / - \ \ |/ |, - ' ; \ /| | - ` \ -- / | | - ` `. .-' | / - v,- `;._ _.; | | - `'`\ |-_ -^'^'| | - ------ |/ - -EOF - -# Subs - -print "This script is kind of deprecated. Use clainsafecli instead.\n"; - -sub help - { - 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; - } - -sub enable_tor - { - my $checker = $ua->proxy([qw(http https)] => 'socks://localhost:9050'); - } - -sub enable_i2p - { - my $checker = $ua->proxy([qw(http https)] => 'http://localhost:4444'); - } - -## PROGRAM - -GetOptions ("server=s" => \$DEFAULT_SERVER, - "help|" => \$help, - "tor"=> \$tor, - "i2p"=>\$i2p, - "get-response"=>\$get_response - ); - -&help if $help || not defined $ARGV[0]; -if ($i2p and $tor) { - print "What are you trying to do? I don't really get you sometimes...\n"; - exit; -} -&enable_tor if $tor and $proxy_enabled; -&enable_i2p if $i2p and $proxy_enabled; - - -# check if file is given - -$file = $ARGV[@ARGV-1]; - -die "File does not exist\n" unless -e $file; - - -my $req; - -# Fake user agent -$ua->agent("Mozilla/5.0 (X11; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0"); - -# modify url if necessary -substr($DEFAULT_SERVER, 0, 0, 'https://') unless $DEFAULT_SERVER =~ /^(http|https):\/\//; -# check if server is running lainsafe - -my $url_to_upload = $DEFAULT_SERVER . "/upload.cgi"; -if (!$ua->get($url_to_upload)->is_success) { - 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; -} - - -$req = $ua->post($url_to_upload, - Content_Type => 'form-data', - Content => [ - "file" => [ $file ], - ], - ); - - -print $ASCII_ART if $DISPLAY_ASCII; -if ($req->{_content} =~ /instance/) # If someone knows how to do it another way, I'm all ears - { - print $req->{_content} . "\n"; - exit; - } -print $req->{_content} . "\n"; - -if ($STORE_LINKS) { - open FILE,'>>',$LINKS_FILE or die $!; - print FILE $req->{_content} . " $file" ."\n"; - close FILE; -} -