mirror of git://git.qorg11.net/lainsafe.git
Compare commits
94 Commits
Author | SHA1 | Date |
---|---|---|
qorg11 | 491e309c9d | |
qorg11 | 68e00034bb | |
qorg11 | efc3ac374d | |
qorg11 | 0d1e07fe51 | |
qorg11 | 0987a4cfa3 | |
qorg11 | fdf5264e18 | |
qorg11 | 1c896a7b32 | |
qorg11 | 1d4b10b9a2 | |
qorg11 | 46162aab5f | |
qorg11 | 54b4b7cf86 | |
qorg11 | 3d5593abc9 | |
qorg11 | 6e67fb78ed | |
qorg11 | d041a216f7 | |
qorg11 | 3f3d173e5d | |
qorg11 | 20b30be2f5 | |
qorg11 | d9afa6076a | |
qorg11 | 50a2682cab | |
qorg11 | 807e1302fe | |
qorg11 | c81acdd4fd | |
qorg11 | 89ad06ce23 | |
qorg11 | efbcccbe03 | |
qorg11 | 082d1ae23a | |
qorg11 | a5b0de143b | |
qorg11 | 7f96695e4e | |
qorg11 | 018f0d64e4 | |
qorg11 | 3e27f25236 | |
qorg11 | 7f88127116 | |
qorg11 | 8c9529a7ba | |
qorg11 | fbc96d4b47 | |
qorg11 | 3c03246af4 | |
qorg11 | 6608a22922 | |
qorg11 | 7fec1f8e01 | |
qorg11 | 0658b5f237 | |
qorg11 | 5f840b01da | |
qorg11 | acb47dd5bb | |
qorg11 | e87c6c9b1c | |
qorg11 | 8170a8a935 | |
qorg11 | d2c48dcb66 | |
qorg11 | 4535b267a9 | |
qorg11 | 509c6e9c68 | |
qorg11 | 693be32ee3 | |
qorg11 | 6aafa6783b | |
qorg11 | e136eebd2c | |
qorg11 | ffd96c69cc | |
qorg11 | bdc0246971 | |
qorg11 | 551ed15a5a | |
qorg11 | 100c1666f3 | |
qorg11 | bb3ac7f248 | |
qorg11 | 7a39f6a32c | |
qorg11 | 267a7807d6 | |
qorg11 | ac4c841e64 | |
qorg11 | 59ae705c09 | |
qorg11 | a3211d897e | |
qorg11 | 68d9f1e56e | |
qorg11 | d85e35d0d5 | |
qorg11 | 44c566380c | |
qorg11 | d363d9695b | |
qorg11 | 6165c4bfc3 | |
qorg11 | abbfb622a0 | |
qorg11 | 29bd98c134 | |
qorg11 | 3c9e3897f6 | |
qorg11 | d2c759f53d | |
qorg11 | baec5b3edd | |
qorg11 | c055fb17a3 | |
qorg11 | 072c16cceb | |
qorg11 | 80bd21f841 | |
qorg11 | c3c63f6651 | |
qorg11 | d1908fe776 | |
qorg11 | 706d73d151 | |
qorg11 | 798b471aff | |
qorg11 | 8ea7f1159f | |
qorg11 | 82061f08fb | |
Kyle Czar | b6e32c25a5 | |
qorg11 | 4385c9ed1d | |
qorg11 | 8a557ca108 | |
qorg11 | 81a7b12d7a | |
qorg11 | b2bbd5018c | |
qorg11 | 77d8559d30 | |
qorg11 | 9d3844bed5 | |
qorg11 | a2c8f92c50 | |
qorg11 | c5976c8200 | |
qorg11 | c645b36fb2 | |
qorg11 | 730e8edbfe | |
qorg11 | 8418a7a84b | |
qorg11 | 4774c6c26d | |
qorg11 | 97e5c795e7 | |
qorg11 | 95ab4caca1 | |
qorg11 | c35ca47d5b | |
qorg11 | 6a2465e24d | |
qorg11 | 1ce7380466 | |
qorg11 | 34363928cc | |
Dustin Van Tate Testa | d23a85bac6 | |
qorg11 | c01d7cdc95 | |
qorg11 | f5967c88c0 |
|
@ -0,0 +1,3 @@
|
|||
sakisafecli
|
||||
*.o
|
||||
*.d
|
4
Makefile
4
Makefile
|
@ -1,4 +0,0 @@
|
|||
install: lainsafecli
|
||||
cp lainsafecli /usr/bin/
|
||||
gzip -k doc/lainsafecli.1
|
||||
cp doc/lainsafecli.1.gz /usr/share/man/man1
|
83
README.MD
83
README.MD
|
@ -1,83 +0,0 @@
|
|||
# Lainsafe
|
||||
### simple file upload.
|
||||
|
||||
### Installation:
|
||||
|
||||
1. Configure your webserver to run CGI
|
||||
2. If running nginx, set ```client_max_body_size``` to the max size of
|
||||
the file
|
||||
2. There you go.
|
||||
|
||||
## lainsafecli
|
||||
|
||||
### Installation
|
||||
|
||||
#### Debian
|
||||
Lainsafe has official packages for Debian, they shold work for any
|
||||
dpkg-based distro, such as Ubuntu and so on
|
||||
|
||||
You can download a possible outdated deb package
|
||||
[here](http://repo.qorg11.net/debian/pool/main/l/lainsafecli/lainsafecli_0.3_all.deb)
|
||||
|
||||
If you want updates for your package, you have to add
|
||||
`repo.qorg11.net` to your sources.list:
|
||||
|
||||
~~~
|
||||
echo "deb http://repo.qorg11.net/debian stable main" >> /etc/apt/sources.list
|
||||
wget http://repo.qorg11.net/repo.key -q -O - | sudo apt-key add
|
||||
sudo apt updates
|
||||
sudo apt install lainsafecli
|
||||
~~~
|
||||
#### Arch
|
||||
TODO
|
||||
|
||||
### lainsafecli configuration
|
||||
|
||||
edit the file with your favorite text editor and change these
|
||||
variables:
|
||||
|
||||
```$DEFAULT_SERVER``` This is the server where lainsafecli will try to
|
||||
upload the files.
|
||||
|
||||
```$DISPLAY_ASCII``` By default 1, change to 0 if you don't want the
|
||||
Lain ascii art to appear when you upload a file.
|
||||
|
||||
### Command line arguments
|
||||
|
||||
```--server``` If given, it will be used instead of $DEFAULT_SERVER
|
||||
|
||||
```--help``` Displays a simple help message and exits.
|
||||
|
||||
```--file``` the file you want to upload (useless in newer versions)
|
||||
|
||||
### Example
|
||||
|
||||
~~~
|
||||
$ lainsafecli --server https://lainsafe.delegao.moe sicp.png
|
||||
|
||||
|
||||
|
||||
_..-- ----- --.._
|
||||
,-'' `-.
|
||||
, \
|
||||
/ \
|
||||
/ ` . \
|
||||
' / || ;
|
||||
; ^/| |/ | |
|
||||
| /v /\`-'v√\'-|\ ,
|
||||
| /v` ,--- ---- .^.| ;
|
||||
: | /´@@`, ,@@`\ | ;
|
||||
' | '. @@ / \@@ / |\ |;
|
||||
| ^| ----- --- | \/||
|
||||
` |` | /\ /
|
||||
\ \ |/ |,
|
||||
' ; \ /| |
|
||||
` \ -- / | |
|
||||
` `. .-' | /
|
||||
v,- `;._ _.; | |
|
||||
`'`\ |-_ -^'^'| |
|
||||
------ |/
|
||||
|
||||
https://lainsafe.delegao.moe/files/EWwEnBHk.png
|
||||
|
||||
~~~
|
|
@ -0,0 +1,38 @@
|
|||
# Sakisafe (formerly lainsafe)
|
||||
|
||||
## Simple file upload
|
||||
|
||||
## Features
|
||||
|
||||
* Written in perl
|
||||
* Can be used as pastebin
|
||||
* Or as a URL shorter
|
||||
* Runs with CGI
|
||||
* Tor access ;)
|
||||
|
||||
## Installation:
|
||||
|
||||
1. Configure your webserver to run CGI
|
||||
2. If running nginx, set `client_max_body_size` to the max size of
|
||||
the file
|
||||
2. There you go.
|
||||
|
||||
|
||||
# sakisafecli
|
||||
|
||||
`sakisafecli` is the command line interface for sakisafe (and other
|
||||
filesharing services)
|
||||
|
||||
## usage
|
||||
|
||||
`sakisafecli --server=http://server <file>`
|
||||
|
||||
(for more info see -h)
|
||||
|
||||
# Donate
|
||||
|
||||
Thanks!
|
||||
|
||||
**Bitcoin**: bc1qghl6f27dpgktynpvkrxte2s3gm9pcv8vlwuzum
|
||||
|
||||
**Monero**: 47QTumjtqJabbo1s9pLDdXeJarLVLfs1AaEcbi1xrEiV852mqcbe5AHLNXTk7tH9MscxcxQDfJQnvH5LpxvfgwSJQZ3zbS6
|
|
@ -0,0 +1,10 @@
|
|||
* Known lainsafe instances
|
||||
|
||||
In this document i'll add all the lainsafe instance i know :)
|
||||
|
||||
- https://lainsafe.delegao.moe
|
||||
- https://lainsafe.duckdns.org (don't use it, old lainsafe version
|
||||
and a bit incompatible with lainsafecli)
|
||||
- https://lainsafe.kalli.st
|
||||
- http://lainsafe.kallist4mcluuxbjnr5p2asdlmdhaos3pcrvhk3fbzmiiiftwg6zncid.onion/ (onion mirror)
|
||||
- http://gnaumuq27fagoo24pb2mmf25rdic7lrthq2fsfolgrpzycc2hwga.b32.i2p/
|
4
TODO.MD
4
TODO.MD
|
@ -1,2 +1,2 @@
|
|||
* set $MAX_SIZE variable in upload.cgi
|
||||
* echo links in .cache/lainsafelinks in lainsafecli
|
||||
[x] set $MAX_SIZE variable in upload.cgi
|
||||
[x] echo links in .cache/lainsafelinks in lainsafecli
|
||||
|
|
133
doc/index.md
133
doc/index.md
|
@ -1,133 +0,0 @@
|
|||
# lainsafecli documentation
|
||||
|
||||
## History
|
||||
|
||||
[delegao](https://kill-9.xyz/rocks/people/delegao) and I were talking about how much I hate the modern web. He runs <https://safe.delegao.moe> which is the same but with JS, so I think it sucked. I started to make lainsafe to replace lolisafe.
|
||||
|
||||
## Lainsafe installation
|
||||
|
||||
Just put index.html and upload.cgi in a HTTP directory. I use fcgi to run my cgi scripts. So it's what i recommend. To install fcgi on Debian, run: ```# apt install fcgiwrap```
|
||||
|
||||
here's an example configuration for lainsafe, using nginx.
|
||||
|
||||
~~~
|
||||
server
|
||||
{
|
||||
server_name lainsafe.foo.tld;
|
||||
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
client_max_body_size 100m; # max size 100MBs, change 10 to 100 in upload.cgi in line 30
|
||||
root /var/www/lainsafe;
|
||||
|
||||
location ~ \.cgi$ {
|
||||
gzip off;
|
||||
include /etc/nginx/fastcgi_params;
|
||||
fastcgi_pass unix:/var/run/fcgiwrap.socket;
|
||||
fastcgi_index index.cgi;
|
||||
fastcgi_param SCRIPT_FILENAME /var/www/lainsafe/$fastcgi_script_name;
|
||||
}
|
||||
}
|
||||
~~~
|
||||
|
||||
## lainsafecli
|
||||
|
||||
lainsafecli is a command line interface for lainsafe. It can be used
|
||||
in whatever that runs Perl. Installation is simple: if you're running
|
||||
Debian install the libwww-perl package. If you are not running Debian,
|
||||
search for that package in your repositories. Or use ```# cpan -i
|
||||
LWP::UserAgent``` Also LWP::UserAgent::https is needed. In Debian,
|
||||
install liblwp-protocol-https-perl, in other distros try # cpan -i
|
||||
LWP::UserAgent
|
||||
|
||||
### Installation
|
||||
|
||||
I haven't made a package for lainsafecli yet. So installation is basically:
|
||||
|
||||
~~~
|
||||
# wget https://raw.githubusercontent.com/qorg11/lainsafe/master/lainsafecli \
|
||||
-O /bin/lainsafecli && chmod +x /bin/lainsafecli
|
||||
~~~
|
||||
|
||||
That will install lainsafecli, run ```lainsafecli``` to make sure it is installed.
|
||||
|
||||
### Configuration
|
||||
|
||||
lainsafecli is a simple software. So it has just 2 configurable
|
||||
parameters. lainsafecli do not have a config file. So you have to
|
||||
change these parameters in the executable file.
|
||||
|
||||
These parameters are located in the line 34 of lainsafecli.
|
||||
|
||||
```$DEFAULT_SERVER``` the server that will be used if --server is not
|
||||
specified.
|
||||
```$DISPLAY_ASCII``` By default is true, change to 0 if you don't want
|
||||
the Lain ASCII art to appear when you upload a file.
|
||||
|
||||
the most "official" lainsafe instance is <https://lainsafe.delegao.moe>.
|
||||
|
||||
### Usage
|
||||
|
||||
Before 1b8373
|
||||
|
||||
~~~
|
||||
USAGE: lainsafecli [--server] --file=FILE
|
||||
~~~
|
||||
|
||||
After 1b8373
|
||||
|
||||
~~~
|
||||
USAGE: lainsafecli [--server] FILE
|
||||
~~~
|
||||
|
||||
|
||||
for example:
|
||||
|
||||
```lainsafe --server=https://lainsafe.foo.bar sicp.pdf```
|
||||
|
||||
will upload sicp.pdf to lainsafe.foo.bar
|
||||
|
||||
### Sample output
|
||||
|
||||
In this output, ```$DEFAULT_SERVER``` is lainsafe.delegao.moe. and ```
|
||||
$DISPLAY_ASCII``` equals 1 (true)
|
||||
|
||||
~~~
|
||||
lainsafecli sicp.pdf
|
||||
|
||||
_..-- ----- --.._
|
||||
,-'' `-.
|
||||
, \
|
||||
/ \
|
||||
/ ` . \
|
||||
' / || ;
|
||||
; ^/| |/ | |
|
||||
| /v /\`-'v√\'-|\ ,
|
||||
| /v` ,--- ---- .^.| ;
|
||||
: | /´@@`, ,@@`\ | ;
|
||||
' | '. @@ / \@@ / |\ |;
|
||||
| ^| ----- --- | \/||
|
||||
` |` | /\ /
|
||||
\ \ |/ |,
|
||||
' ; \ /| |
|
||||
` \ -- / | |
|
||||
` `. .-' | /
|
||||
v,- `;._ _.; | |
|
||||
`'`\ |-_ -^'^'| |
|
||||
------ |/
|
||||
|
||||
https://lainsafe.delegao.moe/files/nzOhDKtB.pdf
|
||||
~~~
|
||||
|
||||
# upload.cgi
|
||||
|
||||
```upload.cgi``` is the perl script that do all the works. You could
|
||||
delete index.cgi from your sever and just upload.cgi. You'd upload
|
||||
files through ```lainsafecli```.
|
||||
|
||||
## Configuration
|
||||
|
||||
Only one parameter: ```$MAX_SIZE``` specify, in megabytes, the max size of files allowed. So for example. If you want to set 100MBs as max size . ```$MAX_SIZE``` would be like this: ```$MAX_SIZE = 1024*1024*100```
|
||||
|
||||
If someone tries to upload a file bigger than 100MBs. It will return
|
||||
Max size for a file is 100 MBs, then, upload.cgi will die.
|
|
@ -1,61 +0,0 @@
|
|||
.\" Manpage for lainsafecli.
|
||||
.TH lainsafecli 1
|
||||
.SH NAME
|
||||
lainsafecli \- Command line interface for lainsafe
|
||||
.SH SYNOPSIS
|
||||
lainsafecli
|
||||
.I
|
||||
[--server=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.
|
||||
|
||||
.SH TROUBLESHOOTING
|
||||
|
||||
.B "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)
|
||||
|
||||
.B 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 <qorg@vxempire.xyz>
|
||||
|
||||
.SH LICENSE
|
||||
|
||||
GPLv3 or later.
|
|
@ -0,0 +1,51 @@
|
|||
.\"Manpage for lainsafe
|
||||
.TH sakisafecli 1
|
||||
.SH NAME
|
||||
sakisafecli \- File uploader
|
||||
|
||||
.SH DESCRIPTION
|
||||
|
||||
sakisafecli 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 sakisafecli.c -lcurl -o sakisafecli)
|
||||
cp sakisafecli ~/.local/bin
|
||||
.EE
|
||||
.SH OPTIONS
|
||||
|
||||
.PP
|
||||
.B
|
||||
--server=<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 sakisafecli to be silent. This means, it won't
|
||||
print the progress.
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
# This file is part of lainsafe.
|
||||
# This file is part of sakisafe.
|
||||
# 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
|
||||
|
@ -14,32 +14,15 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with lainsafe. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
my $disk_size = `df -h | awk 'NR==2 {print \$2; exit}'`;
|
||||
my $disk_usage = `df -h | awk 'NR==2 {print \$3; exit}'`;
|
||||
my $disk_free = `df -h | awk 'NR==2 {print \$4; exit}'`;
|
||||
my $disk_percentage = `df -h | awk 'NR==2 {print \$5; exit}'`;
|
||||
if ($ENV{REQUEST_METHOD} eq "POST") {
|
||||
do "./upload.cgi";
|
||||
exit;
|
||||
}
|
||||
|
||||
my $SITE_URL = $ENV{REMOTE_ADDR};
|
||||
|
||||
print "Content-type: text/html\n\n";
|
||||
|
||||
print "<!DOCTYPE html>
|
||||
<html lang=\"en\">
|
||||
<head>
|
||||
<title>lainsafe</title>
|
||||
</head>
|
||||
<body>
|
||||
open(my $fh, "<index.html");
|
||||
|
||||
<h1>lainsafe</h1>
|
||||
|
||||
<img src='https://lainchan.org/static/lain_is_cute_datass_small.png'
|
||||
width=200 alt='cool lain' />
|
||||
<form ENCTYPE='multipart/form-data' method='post' action='upload.cgi'>
|
||||
<input type='file' name='file' size='30'>
|
||||
<input type='submit' value='upload'>
|
||||
</form>
|
||||
<a href='https://github.com/qorg11/lainsafe'>star me</a>
|
||||
|
||||
|
||||
</body>
|
||||
</html>";
|
||||
|
||||
print $disk_free ." available from ". $disk_size ." total";
|
||||
print while <$fh>;
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
p {
|
||||
color: white;
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* p code {display: block;} */
|
||||
|
||||
code {
|
||||
background: #4e4e4e;
|
||||
font-family: monospace;
|
||||
color: #e3e3e3;
|
||||
margin: 30px;
|
||||
}
|
||||
|
||||
body, input, select, textarea {
|
||||
color: #333;
|
||||
font-size: 10pt;
|
||||
line-height: 1.65em;
|
||||
letter-spacing: -0.015em;
|
||||
}
|
||||
|
||||
body {
|
||||
background:#040304;
|
||||
}
|
||||
|
||||
h1, h2 {
|
||||
color: #e3e3e3;
|
||||
}
|
||||
.left {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 30px;
|
||||
border-left-color: #333;
|
||||
border-left-width: 2px;
|
||||
border-left-style: solid;
|
||||
padding: 10px;
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>sakisafe</title>
|
||||
<link rel="stylesheet" type="text/css" href="index.css"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
</head>
|
||||
<body>
|
||||
<h1>sakisafe</h1>
|
||||
<h2>shitless file upload, pastebin and url shorter</h2>
|
||||
<img src="saki.png"/>
|
||||
<h2>USAGE</h2>
|
||||
<p>POST a file:</p>
|
||||
<code>curl -F 'file=@yourfile.png' $SITE_URL</code>
|
||||
<p>Shorten URL:</p>
|
||||
<code>curl -F 'url=https://example.org' $SITE_URL</code>
|
||||
<p>Post your text directly</p>
|
||||
<code>curl -F 'file=@-' $SITE_URL</code>
|
||||
<div class="left">
|
||||
<h2>Or just upload a file here</h2>
|
||||
<form ENCTYPE='multipart/form-data' method='post' action='upload.cgi'>
|
||||
<input type='file' name='file' size='30'/>
|
||||
<input type='submit' value='upload'/>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
After Width: | Height: | Size: 107 KiB |
119
http/upload.cgi
119
http/upload.cgi
|
@ -1,87 +1,108 @@
|
|||
#!/usr/bin/perl
|
||||
# This file is part of lainsafe.
|
||||
# This file is part of sakisafe.
|
||||
|
||||
# lainsafe is free software: you can redistribute it and/or modify
|
||||
# sakisafe 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,
|
||||
# sakisafe 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/>.
|
||||
# along with sakisafe. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use CGI;
|
||||
use CGI::Carp qw(fatalsToBrowser);
|
||||
|
||||
my $q = CGI->new;
|
||||
|
||||
my $filename = $q->param('file');
|
||||
# TODO: fix 502
|
||||
my $url = $q->param('url');
|
||||
|
||||
my $upload_dir = "files/";
|
||||
print $q->header();
|
||||
|
||||
$size = $ENV{CONTENT_LENGTH};
|
||||
|
||||
# Configuration
|
||||
|
||||
our $MAX_SIZE = 1024*1024*10; # Change for your size
|
||||
our $MAX_SIZE = 1024*1024*100; # Change for your size
|
||||
our $MAX_SIZE_MB = $MAX_SIZE / 1024 / 1024; # Don't change this
|
||||
|
||||
our @not_allowed_extensions = qw(sh out exe);
|
||||
|
||||
if($filename eq "")
|
||||
{
|
||||
print("What are you looking for?");
|
||||
exit;
|
||||
print $q->header();
|
||||
|
||||
# do something better
|
||||
if ($url ne "") {
|
||||
goto url_shorter;
|
||||
}
|
||||
|
||||
if($size > $MAX_SIZE)
|
||||
{
|
||||
print("Max size for a file is $MAX_SIZE_MB MBs");
|
||||
exit;
|
||||
if ($filename eq "" || $ENV{REQUEST_METHOD} eq "GET") {
|
||||
print("What are you looking for?");
|
||||
exit;
|
||||
}
|
||||
|
||||
my $extension = $filename;
|
||||
$extension =~ s/.*\.//; # tar.gz sucks with this
|
||||
if ($filename) {
|
||||
if ($size > $MAX_SIZE) {
|
||||
print("Max size for a file is $MAX_SIZE_MB MBs");
|
||||
exit;
|
||||
}
|
||||
|
||||
# Generate random string
|
||||
my @chars = ("A".."Z", "a".."z");
|
||||
my $string;
|
||||
$string .= $chars[rand @chars] for 1..8;
|
||||
|
||||
my $upload_filehandle = $q->upload("file");
|
||||
my @chars = ("A"..."z","a"..."z");
|
||||
my $dirname;
|
||||
my $extension = $filename;
|
||||
|
||||
$filename = $string . "." . $extension;
|
||||
my $allowed_extension = 1;
|
||||
$dirname .= $chars[rand @chars] for 1..8;
|
||||
$extension =~ s/.*\.//;
|
||||
$filename .= ".notcgi" if $extension eq "cgi";
|
||||
|
||||
foreach(@not_allowed_extensions)
|
||||
{
|
||||
if($filename =~ /\.$_$/i)
|
||||
{
|
||||
$allowed_extension = 0;
|
||||
last;
|
||||
}
|
||||
mkdir("$upload_dir/$dirname");
|
||||
my $upload_filehandle = $q->upload("file");
|
||||
|
||||
}
|
||||
# onion urls will be http
|
||||
my $prot = length $ENV{HTTPS} ? "https" : "http";
|
||||
|
||||
if($allowed_extension)
|
||||
{
|
||||
|
||||
open(FILE,">$upload_dir/$filename");
|
||||
binmode(FILE);
|
||||
my $allowed_extension = 1;
|
||||
|
||||
while(<$upload_filehandle>)
|
||||
{
|
||||
print FILE;
|
||||
}
|
||||
|
||||
close FILE;
|
||||
|
||||
print $ENV{HTTP_REFERER} . "$upload_dir$filename";
|
||||
}
|
||||
|
||||
else {
|
||||
print "The file extension .$extension is not allowed in this instance.";
|
||||
foreach (@not_allowed_extensions) {
|
||||
if ($filename =~ /\.$_$/i) {
|
||||
$allowed_extension = 0;
|
||||
last;
|
||||
}
|
||||
|
||||
}
|
||||
if ($filename eq "-") {
|
||||
$filename .= ".txt"; # for pastes
|
||||
}
|
||||
if ($allowed_extension) {
|
||||
|
||||
open(FILE,">$upload_dir/$dirname/$filename");
|
||||
binmode(FILE);
|
||||
while (<$upload_filehandle>) {
|
||||
print FILE;
|
||||
}
|
||||
close FILE;
|
||||
$filename =~ s/ /%20/g;
|
||||
|
||||
print $prot. "://" . $ENV{HTTP_HOST} . "/$upload_dir$dirname/$filename" . "\n";
|
||||
} else {
|
||||
print "The file extension .$extension is not allowed in this instance.";
|
||||
}
|
||||
exit;
|
||||
} elsif ($url != "" && !$filename) {
|
||||
url_shorter:
|
||||
my $template = "<meta http-equiv=\"Refresh\" content=\"0; url='$url'\"/>";
|
||||
my @chars = ("A"..."z","a"..."z",1..9);
|
||||
my $dirname;
|
||||
$dirname .= $chars[rand @chars] for 1..4;
|
||||
mkdir($dirname);
|
||||
open(my $fh, ">$dirname/index.html");
|
||||
print $fh $template;
|
||||
my $prot = length $ENV{HTTPS} ? "https" : "http";
|
||||
print $prot. "://" . $ENV{HTTP_HOST} . "/$dirname" . "\n";
|
||||
exit;
|
||||
}
|
||||
|
|
118
lainsafecli
118
lainsafecli
|
@ -1,118 +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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
|
||||
use Getopt::Long;
|
||||
use LWP::UserAgent;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
# variables
|
||||
my $help;
|
||||
my $DEFAULT_SERVER;
|
||||
my $file;
|
||||
my $DISPLAY_ASCII;
|
||||
|
||||
# Default options, if no specified.
|
||||
$DEFAULT_SERVER = "https://lainsafe.delegao.moe";
|
||||
$DISPLAY_ASCII = 1; # 0 if you don't want the ascii
|
||||
|
||||
my $ASCII_ART = <<'EOF';
|
||||
|
||||
|
||||
_..-- ----- --.._
|
||||
,-'' `-.
|
||||
, \
|
||||
/ \
|
||||
/ ` . \
|
||||
' / || ;
|
||||
; ^/| |/ | |
|
||||
| /v /\`-'v√\'-|\ ,
|
||||
| /v` ,--- ---- .^.| ;
|
||||
: | /´@@`, ,@@`\ | ;
|
||||
' | '. @@ / \@@ / |\ |;
|
||||
| ^| ----- --- | \/||
|
||||
` |` | /\ /
|
||||
\ \ |/ |,
|
||||
' ; \ /| |
|
||||
` \ -- / | |
|
||||
` `. .-' | /
|
||||
v,- `;._ _.; | |
|
||||
`'`\ |-_ -^'^'| |
|
||||
------ |/
|
||||
|
||||
EOF
|
||||
|
||||
# Subs
|
||||
|
||||
sub help
|
||||
{
|
||||
print "lainsafecli, a command line interface for lainsafe.\n";
|
||||
print "USAGE: lainsafecli [--server] FILE\n\n";
|
||||
print "if --server not given, $DEFAULT_SERVER is used.\n";
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
## PROGRAM
|
||||
my $ua = LWP::UserAgent->new;
|
||||
GetOptions ("server=s" => \$DEFAULT_SERVER,
|
||||
"help|" => \$help);
|
||||
|
||||
if($help || not defined $ARGV[0])
|
||||
{
|
||||
&help;
|
||||
}
|
||||
|
||||
# check if file is given
|
||||
|
||||
$file = $ARGV[@ARGV-1];
|
||||
|
||||
die "File does not exist\n" if !-e $file;
|
||||
|
||||
my $url_to_upload = $DEFAULT_SERVER . "/upload.cgi";
|
||||
my $req;
|
||||
|
||||
# Fake user agent
|
||||
$ua->agent("Mozilla/5.0 (X11; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0");
|
||||
|
||||
# check if server is running lainsafe
|
||||
|
||||
if(!$ua->get($url_to_upload)->is_success)
|
||||
{
|
||||
print "$url_to_upload is not running lainsafe.\n";
|
||||
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 $DEFAULT_SERVER . "/" . $req->{_content} . "\n";
|
|
@ -0,0 +1,166 @@
|
|||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: Mozilla
|
||||
AccessModifierOffset: -2
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveMacros: None
|
||||
AlignConsecutiveAssignments: None
|
||||
AlignConsecutiveBitFields: None
|
||||
AlignConsecutiveDeclarations: None
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: Align
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortEnumsOnASingleLine: true
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: TopLevel
|
||||
AlwaysBreakAfterReturnType: TopLevel
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
AttributeMacros:
|
||||
- __capability
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: true
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: true
|
||||
AfterUnion: true
|
||||
AfterExternBlock: true
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeConceptDeclarations: true
|
||||
BreakBeforeBraces: Mozilla
|
||||
BreakBeforeInheritanceComma: true
|
||||
BreakInheritanceList: BeforeComma
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 80
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 5
|
||||
ContinuationIndentWidth: 5
|
||||
Cpp11BracedListStyle: false
|
||||
DeriveLineEnding: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: false
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
StatementAttributeLikeMacros:
|
||||
- Q_EMIT
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
Priority: 3
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IncludeIsMainSourceRegex: ''
|
||||
IndentCaseLabels: true
|
||||
IndentCaseBlocks: false
|
||||
IndentGotoLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentExternBlock: AfterExternBlock
|
||||
IndentRequires: false
|
||||
IndentWidth: 5
|
||||
IndentWrappedFunctionNames: false
|
||||
InsertTrailingCommas: None
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 5
|
||||
ObjCBreakBeforeNestedBlockParam: true
|
||||
ObjCSpaceAfterProperty: true
|
||||
ObjCSpaceBeforeProtocolList: false
|
||||
PenaltyBreakAssignment: 5
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 200
|
||||
PenaltyIndentedWhitespace: 0
|
||||
PointerAlignment: Right
|
||||
ReflowComments: true
|
||||
SortIncludes: false
|
||||
SortJavaStaticImport: Before
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCaseColon: false
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: false
|
||||
SpaceAroundPointerQualifiers: Default
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
SpaceBeforeSquareBrackets: false
|
||||
BitFieldColonSpacing: Both
|
||||
Standard: Latest
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TabWidth: 5
|
||||
UseCRLF: false
|
||||
UseTab: Always
|
||||
WhitespaceSensitiveMacros:
|
||||
- STRINGIZE
|
||||
- PP_STRINGIZE
|
||||
- BOOST_PP_STRINGIZE
|
||||
- NS_SWIFT_NAME
|
||||
- CF_SWIFT_NAME
|
||||
...
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
# sakisafecli makefile
|
||||
|
||||
TARGET = sakisafecli
|
||||
OBJS = sakisafecli.o funcs.o
|
||||
CC = cc
|
||||
CFLAGSDEF += -MD -std=c11 -Wall -Wextra -lcurl -lconfig
|
||||
CFLAGS += -O2 -ggdb
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJS)
|
||||
$(CC) $(CFLAGS) $(CFLAGSDEF) $(OBJS) -o $(TARGET)
|
||||
|
||||
%.o: %.c
|
||||
$(CC) -c $(CFLAGS) $(CFLAGSDEF) $< -o $@
|
||||
|
||||
-include *.d
|
||||
|
||||
install: all
|
||||
@cp sakisafecli /usr/local/bin/
|
||||
|
||||
.PHONY: clean install
|
||||
clean:
|
||||
rm -f *.d *.o sakisafecli
|
|
@ -0,0 +1,65 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <libconfig.h>
|
||||
#include "sakisafecli.h"
|
||||
|
||||
size_t
|
||||
write_data(void *buffer, size_t size, size_t nmemb,
|
||||
void *userp)
|
||||
{
|
||||
memcpy(userp, buffer, nmemb*size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
print_usage()
|
||||
{
|
||||
printf("USAGE: sakisafecli [--socks-proxy=socks_address|--http_proxy=proxy_address] [-6|-4] [--server] file\n");
|
||||
return;
|
||||
}
|
||||
|
||||
int
|
||||
store_link(const char *path, const char *buf)
|
||||
{
|
||||
FILE *fp = fopen(path,"a+");
|
||||
if(fp == NULL) {
|
||||
fprintf(stderr,"Error opening file %i: %s\n",errno,
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
fwrite(buf,strlen(buf),1,fp);
|
||||
fputc('\n',fp);
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
print_help()
|
||||
{
|
||||
printf("--server <server>: specifies the sakisafe server\n%s\n%s\n%s\n%s\n%s\n%s\n%s",
|
||||
"-t|--token: Authentication token (https://u.kalli.st)",
|
||||
"--tor: uses tor.",
|
||||
"--i2p: uses i2p.",
|
||||
"-6|--ipv6: uses IPv6 only.",
|
||||
"-4|--ipv6: uses IPv4 only.",
|
||||
"--silent: doesn't print progress.",
|
||||
"--help: print this message.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
progress(void *clientp,
|
||||
double dltotal,
|
||||
double dlnow,
|
||||
double ultotal,
|
||||
double ulnow)
|
||||
{
|
||||
/* So I don't get a warning */
|
||||
dltotal += 1;
|
||||
dlnow += 1;
|
||||
printf("\r%0.f uploaded of %0.f (\E[32;1m%0.f%%\E[30;0m)",ulnow,ultotal,
|
||||
ulnow*100/ultotal);
|
||||
fflush(stdout);
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
/* clainsafecli options */
|
||||
|
||||
/* Default server you'll upload files to */
|
||||
char *server = "https://lainsafe.kalli.st";
|
||||
|
||||
/* proxy urls, socks and http. in that order, by default they're
|
||||
* configured to be used for tor and i2p, but if you have another
|
||||
* socks/http proxy, you can set it here.
|
||||
*/
|
||||
|
||||
/* Enable "history" files and where to store that file */
|
||||
|
||||
char history_file_path[256];
|
||||
const int enable_links_history = 1;
|
||||
const char *path = ".cache/lainsafelinks";
|
||||
|
|
@ -0,0 +1,254 @@
|
|||
#include <libconfig.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <unistd.h>
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include "options.h"
|
||||
#include "sakisafecli.h"
|
||||
|
||||
/* Config variables */
|
||||
char *socks_proxy_url, *http_proxy_url;
|
||||
|
||||
bool socks_proxy_flag = false, http_proxy_flag = false;
|
||||
bool ipv6_flag = false, ipv4_flag = false;
|
||||
bool silent_flag = false;
|
||||
config_t runtime_config;
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct curl_httppost *post = NULL;
|
||||
struct curl_httppost *last = NULL;
|
||||
|
||||
char *token = NULL;
|
||||
char *form_key = "file";
|
||||
|
||||
char *buffer = (char *)calloc(1024, sizeof(char));
|
||||
|
||||
if(buffer == NULL) {
|
||||
fprintf(stderr, "Error allocating memory!\n");
|
||||
return -1;
|
||||
}
|
||||
char config_location[512];
|
||||
char *sakisafeclirc_env = getenv("SAKISAFECLIRC");
|
||||
|
||||
if(sakisafeclirc_env == NULL) {
|
||||
snprintf(config_location, 512, "%s/.sakisafeclirc", getenv("HOME"));
|
||||
FILE *fp = fopen(config_location, "r");
|
||||
if(fp != NULL) {
|
||||
parse_config_file(fp);
|
||||
fclose(fp);
|
||||
}
|
||||
} else {
|
||||
strncpy(config_location, sakisafeclirc_env, 512);
|
||||
FILE *fp = fopen(config_location, "r");
|
||||
if(fp != NULL) {
|
||||
parse_config_file(fp);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
CURL *easy_handle = curl_easy_init();
|
||||
|
||||
if(!easy_handle) {
|
||||
fprintf(stderr, "Error initializing libcurl\n");
|
||||
return -1;
|
||||
}
|
||||
if(argc == optind) {
|
||||
print_usage();
|
||||
free(buffer);
|
||||
curl_easy_cleanup(easy_handle);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int option_index = 0;
|
||||
static struct option long_options[] = {
|
||||
{ "server", required_argument, 0, 's' },
|
||||
{ "help", no_argument, 0, 'h' },
|
||||
{ "socks-proxy", required_argument, 0, 'p' },
|
||||
{ "token", required_argument, 0, 'T' },
|
||||
{ "http-proxy", required_argument, 0, 'P' },
|
||||
{ "silent", no_argument, 0, 'S' },
|
||||
{ "ipv4", no_argument, 0, '4' },
|
||||
{ "ipv6", no_argument, 0, '6' },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
int c = 0;
|
||||
while((c = getopt_long(
|
||||
argc, argv, "46hT:p:P:Ss:", long_options, &option_index)) !=
|
||||
-1) {
|
||||
switch(c) {
|
||||
case 's':
|
||||
server = optarg;
|
||||
break;
|
||||
case 'h':
|
||||
print_help();
|
||||
free(buffer);
|
||||
curl_easy_cleanup(easy_handle);
|
||||
return 0;
|
||||
break;
|
||||
case 'p':
|
||||
socks_proxy_url = optarg;
|
||||
socks_proxy_flag = true;
|
||||
break;
|
||||
case 'P':
|
||||
http_proxy_url = optarg;
|
||||
http_proxy_flag = true;
|
||||
break;
|
||||
case 'S':
|
||||
silent_flag = true;
|
||||
break;
|
||||
case 'T':
|
||||
token = optarg;
|
||||
break;
|
||||
case '4':
|
||||
ipv4_flag = true;
|
||||
break;
|
||||
case '6':
|
||||
ipv6_flag = true;
|
||||
break;
|
||||
case '?':
|
||||
print_usage();
|
||||
return 0;
|
||||
break;
|
||||
default:
|
||||
print_usage();
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(access(argv[optind], F_OK)) {
|
||||
fprintf(stderr, "Error opening file\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* curl options */
|
||||
curl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, write_data);
|
||||
curl_easy_setopt(easy_handle, CURLOPT_WRITEDATA, buffer);
|
||||
curl_easy_setopt(easy_handle, CURLOPT_URL, server);
|
||||
|
||||
/* Proxy options */
|
||||
|
||||
if(socks_proxy_flag && http_proxy_flag) {
|
||||
fprintf(stderr, "Socks_Proxy and HTTP_PROXY can't be used at once\n");
|
||||
return -1;
|
||||
} else if(socks_proxy_flag) {
|
||||
curl_easy_setopt(easy_handle, CURLOPT_PROXY, socks_proxy_url);
|
||||
curl_easy_setopt(
|
||||
easy_handle, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);
|
||||
} else if(http_proxy_flag) {
|
||||
curl_easy_setopt(easy_handle, CURLOPT_PROXY, http_proxy_url);
|
||||
curl_easy_setopt(easy_handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
|
||||
}
|
||||
|
||||
/* Which address to use */
|
||||
|
||||
if(ipv6_flag)
|
||||
curl_easy_setopt(easy_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6);
|
||||
else if(ipv4_flag)
|
||||
curl_easy_setopt(easy_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||
else
|
||||
curl_easy_setopt(
|
||||
easy_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_WHATEVER);
|
||||
|
||||
/* Form parameters */
|
||||
|
||||
/* File name */
|
||||
|
||||
/* TODO: make it iterate on args so you can upload multiple files
|
||||
* at once (sakisafecli file1 file2 ... filen)
|
||||
*/
|
||||
|
||||
for(int i = optind; i < argc; i++) {
|
||||
curl_formadd(&post,
|
||||
&last,
|
||||
CURLFORM_COPYNAME,
|
||||
form_key,
|
||||
CURLFORM_FILE,
|
||||
argv[i],
|
||||
CURLFORM_END);
|
||||
/* Actual file content */
|
||||
curl_formadd(&post,
|
||||
&last,
|
||||
CURLFORM_COPYNAME,
|
||||
form_key,
|
||||
CURLFORM_COPYCONTENTS,
|
||||
argv[i],
|
||||
CURLFORM_END);
|
||||
if(token)
|
||||
curl_formadd(&post,
|
||||
&last,
|
||||
CURLFORM_COPYNAME,
|
||||
"token",
|
||||
CURLFORM_COPYCONTENTS,
|
||||
token,
|
||||
CURLFORM_END);
|
||||
|
||||
curl_easy_setopt(easy_handle, CURLOPT_NOPROGRESS, silent_flag);
|
||||
curl_easy_setopt(easy_handle, CURLOPT_PROGRESSFUNCTION, progress);
|
||||
|
||||
curl_easy_setopt(easy_handle, CURLOPT_HTTPPOST, post);
|
||||
|
||||
curl_easy_perform(easy_handle);
|
||||
|
||||
if(!silent_flag)
|
||||
putchar('\n');
|
||||
|
||||
printf("%s", buffer);
|
||||
}
|
||||
curl_formfree(post);
|
||||
curl_easy_cleanup(easy_handle);
|
||||
|
||||
/* Store link if needed */
|
||||
|
||||
if(enable_links_history) {
|
||||
snprintf(history_file_path, 256, "%s/%s", getenv("HOME"), path);
|
||||
store_link(history_file_path, buffer);
|
||||
}
|
||||
free(buffer);
|
||||
config_destroy(&runtime_config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
parse_config_file(FILE *config)
|
||||
{
|
||||
config_init(&runtime_config);
|
||||
config_read(&runtime_config, config);
|
||||
config_setting_t *cur;
|
||||
cur = config_lookup(&runtime_config, "server");
|
||||
if(config != NULL) {
|
||||
if(cur != NULL)
|
||||
server = (char *)config_setting_get_string(cur);
|
||||
cur = config_lookup(&runtime_config, "socks_proxy");
|
||||
if(cur != NULL)
|
||||
socks_proxy_url = (char *)config_setting_get_string(cur);
|
||||
cur = config_lookup(&runtime_config, "http_proxy");
|
||||
if(cur != NULL)
|
||||
http_proxy_url = (char *)config_setting_get_string(cur);
|
||||
cur = config_lookup(&runtime_config, "use_socks_proxy");
|
||||
if(cur != NULL)
|
||||
socks_proxy_flag = config_setting_get_bool(cur);
|
||||
cur = config_lookup(&runtime_config, "use_http_proxy");
|
||||
|
||||
if(cur != NULL)
|
||||
http_proxy_flag = config_setting_get_bool(cur);
|
||||
|
||||
cur = config_lookup(&runtime_config, "silent");
|
||||
if(cur != NULL)
|
||||
silent_flag = config_setting_get_bool(cur);
|
||||
cur = config_lookup(&runtime_config, "force_ipv6");
|
||||
if(cur != NULL)
|
||||
ipv6_flag = config_setting_get_bool(cur);
|
||||
cur = config_lookup(&runtime_config, "force_ipv4");
|
||||
if(cur != NULL)
|
||||
ipv4_flag = config_setting_get_bool(cur);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
size_t
|
||||
write_data(void *buffer, size_t size, size_t nmemb, void *userp);
|
||||
|
||||
void
|
||||
print_usage();
|
||||
|
||||
int
|
||||
store_link(const char *path, const char *buf);
|
||||
|
||||
void
|
||||
print_help();
|
||||
|
||||
void
|
||||
progress(
|
||||
void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
|
||||
|
||||
void
|
||||
parse_config_file(FILE *config);
|
Loading…
Reference in New Issue