Compare commits
83 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4bba916e0f | ||
|
|
21ff9787e8 | ||
|
|
6f3edbdfd9 | ||
|
|
e3c7ce0604 | ||
|
|
441debc4c7 | ||
|
|
9206dce65f | ||
|
|
038a9176d5 | ||
|
|
10129c8302 | ||
|
|
288bf2ef84 | ||
|
|
6d292a3001 | ||
|
|
680bb77f2c | ||
|
|
1220515107 | ||
|
|
801231514c | ||
|
|
4537a6897a | ||
|
|
e3f7005180 | ||
|
|
e2daffecd3 | ||
|
|
9e3986fa66 | ||
|
|
ef12b5d54f | ||
|
|
cdd910b150 | ||
|
|
1cba8ad493 | ||
|
|
9bab68e44a | ||
|
|
5abe89fc9c | ||
|
|
f4114ce2a6 | ||
|
|
a2fb9ab838 | ||
|
|
10cb524891 | ||
|
|
99b45b93f2 | ||
|
|
c1725790bb | ||
|
|
b554845749 | ||
|
|
7ad6a82fd4 | ||
|
|
53c0027b3c | ||
|
|
7575609c41 | ||
|
|
319bd73273 | ||
|
|
2c88f3c990 | ||
|
|
bd1751693b | ||
|
|
54838f5dab | ||
|
|
8ff08a0409 | ||
|
|
c054f8dc20 | ||
|
|
44b908ff2b | ||
|
|
55ef361999 | ||
|
|
231954696e | ||
|
|
b9ed17e937 | ||
|
|
a5c137c06d | ||
|
|
abf8ae5117 | ||
|
|
8f3e23d3de | ||
|
|
21d8ac90e8 | ||
|
|
f76eea8931 | ||
|
|
fdbfa98938 | ||
|
|
5ceb31a97e | ||
|
|
f6ecdab9c5 | ||
|
|
bea2fc990d | ||
|
|
a409d1cee6 | ||
|
|
4c3f5908e3 | ||
|
|
79d3f1992e | ||
|
|
c42b8526f0 | ||
|
|
053bd8d5d6 | ||
|
|
36f8df2011 | ||
|
|
880e5edf1b | ||
|
|
a284706e78 | ||
|
|
b1de821740 | ||
|
|
7e33e463bb | ||
|
|
f7926b75fc | ||
|
|
f9d7f3d5c8 | ||
|
|
9c2919f01d | ||
|
|
19c2d8df76 | ||
|
|
888b578907 | ||
|
|
2972046f5f | ||
|
|
6f16b43387 | ||
|
|
7a2b8b1888 | ||
|
|
89c5fc8680 | ||
|
|
bb59a374a1 | ||
|
|
a0bbd2fa28 | ||
|
|
047ecf672c | ||
|
|
73bc067641 | ||
|
|
8ccfcc8c06 | ||
|
|
caa6f5ed6a | ||
|
|
1bc2132e1d | ||
|
|
d771d7bdfd | ||
|
|
49ea4c7ccd | ||
|
|
318987c100 | ||
|
|
a85e04d816 | ||
|
|
48c540d83b | ||
|
|
c75f4b29a1 | ||
|
|
7ee9910cac |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,2 +1,8 @@
|
||||
# ignore binaries
|
||||
/fiche
|
||||
|
||||
# ignore default outpit dir
|
||||
code/
|
||||
|
||||
# ignore log files
|
||||
*.log
|
||||
|
||||
21
.travis.yml
21
.travis.yml
@@ -1,2 +1,21 @@
|
||||
language: c
|
||||
script: make
|
||||
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- cppcheck
|
||||
- clang-3.5
|
||||
|
||||
install:
|
||||
- export PYTHONUSERBASE=~/.local
|
||||
- easy_install --user scan-build
|
||||
- easy_install --user typing
|
||||
|
||||
script:
|
||||
- cppcheck --enable=all --error-exitcode=1 --inconclusive main.c fiche.c
|
||||
- make
|
||||
- scan-build --status-bugs make -B
|
||||
|
||||
23
Makefile
23
Makefile
@@ -1,15 +1,14 @@
|
||||
# -----------------------------------
|
||||
# Fiche MAKEFILE
|
||||
# https://github.com/solusipse/fiche
|
||||
# solusipse.net
|
||||
# -----------------------------------
|
||||
# for debug add -g -O0 to line below
|
||||
CFLAGS+=-pthread -O2 -Wall -Wextra -Wpedantic -Wstrict-overflow -fno-strict-aliasing -std=gnu11 -g -O0
|
||||
prefix=/usr/local/bin
|
||||
|
||||
CC=gcc
|
||||
CFLAGS=-pthread -O2
|
||||
prefix=/usr/local
|
||||
|
||||
all: fiche.c
|
||||
$(CC) -o fiche $(CFLAGS) fiche.c
|
||||
all:
|
||||
${CC} main.c fiche.c $(CFLAGS) -o fiche
|
||||
|
||||
install: fiche
|
||||
install -m 0755 fiche $(prefix)/bin
|
||||
install -m 0755 fiche $(prefix)
|
||||
|
||||
clean:
|
||||
rm -f fiche
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
336
README.md
336
README.md
@@ -3,15 +3,123 @@ fiche []
|
||||
|
||||
Command line pastebin for sharing terminal output.
|
||||
|
||||
## Installation ##
|
||||
# Client-side usage
|
||||
|
||||
1. Clone into repository:
|
||||
Self-explanatory live examples (using public server):
|
||||
|
||||
```
|
||||
echo just testing! | nc termbin.com 9999
|
||||
```
|
||||
|
||||
```
|
||||
cat file.txt | nc termbin.com 9999
|
||||
```
|
||||
|
||||
In case you installed and started fiche on localhost:
|
||||
|
||||
```
|
||||
ls -la | nc localhost 9999
|
||||
```
|
||||
|
||||
You will get an url to your paste as a response, e.g.:
|
||||
|
||||
```
|
||||
http://termbin.com/ydxh
|
||||
```
|
||||
|
||||
You can use our beautification service to get any paste colored and numbered. Just ask for it using `l.termbin.com` subdomain, e.g.:
|
||||
|
||||
```
|
||||
http://l.termbin.com/ydxh
|
||||
```
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
## Useful aliases
|
||||
|
||||
You can make your life easier by adding a termbin alias to your rc file. We list some of them here:
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
### Pure-bash alternative to netcat
|
||||
|
||||
__Linux/macOS:__
|
||||
```
|
||||
alias tb="(exec 3<>/dev/tcp/termbin.com/9999; cat >&3; cat <&3; exec 3<&-)"
|
||||
```
|
||||
|
||||
```
|
||||
echo less typing now! | tb
|
||||
```
|
||||
|
||||
_See [#42](https://github.com/solusipse/fiche/issues/42), [#43](https://github.com/solusipse/fiche/issues/43) for more info._
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
### `tb` alias
|
||||
|
||||
__Linux (Bash):__
|
||||
```
|
||||
echo 'alias tb="nc termbin.com 9999"' >> .bashrc
|
||||
```
|
||||
|
||||
```
|
||||
echo less typing now! | tb
|
||||
```
|
||||
|
||||
__macOS:__
|
||||
|
||||
```
|
||||
echo 'alias tb="nc termbin.com 9999"' >> .bash_profile
|
||||
```
|
||||
|
||||
```
|
||||
echo less typing now! | tb
|
||||
```
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
### Copy output to clipboard
|
||||
|
||||
__Linux (Bash):__
|
||||
```
|
||||
echo 'alias tbc="netcat termbin.com 9999 | xclip -selection c"' >> .bashrc
|
||||
```
|
||||
|
||||
```
|
||||
echo less typing now! | tbc
|
||||
```
|
||||
|
||||
__macOS:__
|
||||
|
||||
```
|
||||
echo 'alias tbc="nc termbin.com 9999 | pbcopy"' >> .bash_profile
|
||||
```
|
||||
|
||||
```
|
||||
echo less typing now! | tbc
|
||||
```
|
||||
|
||||
__Remember__ to reload the shell with `source ~/.bashrc` or `source ~/.bash_profile` after adding any of provided above!
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
## Requirements
|
||||
To use fiche you have to have netcat installed. You probably already have it - try typing `nc` or `netcat` into your terminal!
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
# Server-side usage
|
||||
|
||||
## Installation
|
||||
|
||||
1. Clone:
|
||||
|
||||
```
|
||||
https://github.com/solusipse/fiche.git
|
||||
git clone https://github.com/solusipse/fiche.git
|
||||
```
|
||||
|
||||
2. Build program:
|
||||
2. Build:
|
||||
|
||||
```
|
||||
make
|
||||
@@ -23,71 +131,49 @@ Command line pastebin for sharing terminal output.
|
||||
sudo make install
|
||||
```
|
||||
|
||||
## Client-side usage ##
|
||||
### Using Ports on FreeBSD
|
||||
|
||||
Self explanatory live examples:
|
||||
To install the port: `cd /usr/ports/net/fiche/ && make install clean`. To add the package: `pkg install fiche`.
|
||||
|
||||
_See [#86](https://github.com/solusipse/fiche/issues/86) for more info._
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
ls -la | nc localhost 9999
|
||||
```
|
||||
|
||||
```
|
||||
cat file.txt | nc solusipse.net 9999
|
||||
```
|
||||
|
||||
```
|
||||
echo just testing! | nc code.solusipse.net 9999
|
||||
```
|
||||
|
||||
If you haven't already set up your server on localhost, try second or third command. My personal server is
|
||||
providing fiche-based service all the time on this address `solusipse.net` and this port `9999`.
|
||||
|
||||
- To upload text you need to have netcat installed (to check if netcat is installed, simply type ```nc``` in terminal).
|
||||
|
||||
## Server-side usage ##
|
||||
|
||||
```
|
||||
usage: fiche [-pbsdolBuw].
|
||||
[-d domain] [-p port] [-s slug size]
|
||||
usage: fiche [-D6epbsdSolBuw].
|
||||
[-d domain] [-L listen_addr ] [-p port] [-s slug size]
|
||||
[-o output directory] [-B buffer size] [-u user name]
|
||||
[-l log file] [-b banlist] [-w whitelist]
|
||||
[-l log file] [-b banlist] [-w whitelist] [-S]
|
||||
```
|
||||
|
||||
These are command line arguments. You don't have to provide any, but providing basic is recommended. Without them, program
|
||||
will use these default settings:
|
||||
These are command line arguments. You don't have to provide any of them to run the application. Default settings will be used in such case. See section below for more info.
|
||||
|
||||
### Settings
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
#### Output directory `-o`
|
||||
|
||||
Relative or absolute path to the directory where you want to store user-posted pastes.
|
||||
|
||||
```
|
||||
domain = "http://localhost/";
|
||||
basedir= "~/code/";
|
||||
port = 9999;
|
||||
slug_size = 4;
|
||||
buffer_size = 8192;
|
||||
```
|
||||
|
||||
### Arguments ###
|
||||
|
||||
Most important is providing **basedir** and **domain**.
|
||||
|
||||
-----------------
|
||||
|
||||
#### Basedir ####
|
||||
|
||||
Basedir should be **absolute** path to directory where you would like to store text files.
|
||||
|
||||
|
||||
```
|
||||
fiche -o /absolute/path/to/directory/
|
||||
fiche -o ./code
|
||||
```
|
||||
|
||||
```
|
||||
fiche -o /home/www/code/
|
||||
```
|
||||
|
||||
-----------------
|
||||
__Default value:__ `./code`
|
||||
|
||||
#### Domain ####
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Domain should be provided in such format ```domain.com```.
|
||||
#### Domain `-d`
|
||||
|
||||
This will be used as a prefix for an output received by the client.
|
||||
Value will be prepended with `http`.
|
||||
|
||||
```
|
||||
fiche -d domain.com
|
||||
@@ -97,132 +183,140 @@ fiche -d domain.com
|
||||
fiche -d subdomain.domain.com
|
||||
```
|
||||
|
||||
-----------------
|
||||
```
|
||||
fiche -d subdomain.domain.com/some_directory
|
||||
```
|
||||
|
||||
#### Slug size ####
|
||||
__Default value:__ `localhost`
|
||||
|
||||
This will force fiche to create random slugs with given length, example:
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
#### Slug size `-s`
|
||||
|
||||
This will force slugs to be of required length:
|
||||
|
||||
```
|
||||
fiche -s 6
|
||||
```
|
||||
|
||||
```
|
||||
http://domain.com/abcdef/
|
||||
```
|
||||
__Output url with default value__: `http://localhost/xxxx`,
|
||||
where x is a randomized character
|
||||
|
||||
-----------------
|
||||
__Output url with example value 6__: `http://localhost/xxxxxx`,
|
||||
where x is a randomized character
|
||||
|
||||
#### User name ####
|
||||
__Default value:__ 4
|
||||
|
||||
If you use fiche as service (see details below) you may want to save files as other user, to do that use `-u` option,
|
||||
there's example:
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
#### HTTPS `-S`
|
||||
|
||||
If set, fiche returns url with https prefix instead of http
|
||||
|
||||
```
|
||||
fiche -u http
|
||||
fiche -S
|
||||
```
|
||||
|
||||
-----------------
|
||||
__Output url with this parameter__: `https://localhost/xxxx`,
|
||||
where x is a randomized character
|
||||
|
||||
#### Buffersize ####
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
This parameter defines max file size uploaded by user, by default it is set to `32768`.
|
||||
Use `-B` parameter to change it:
|
||||
#### User name `-u`
|
||||
|
||||
Fiche will try to switch to the requested user on startup if any is provided.
|
||||
|
||||
```
|
||||
fiche -u _fiche
|
||||
```
|
||||
|
||||
__Default value:__ not set
|
||||
|
||||
__WARNING:__ This requires that fiche is started as a root.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
#### Buffer size `-B`
|
||||
|
||||
This parameter defines size of the buffer used for getting data from the user.
|
||||
Maximum size (in bytes) of all input files is defined by this value.
|
||||
|
||||
```
|
||||
fiche -B 2048
|
||||
```
|
||||
|
||||
-----------------
|
||||
__Default value:__ 32768
|
||||
|
||||
#### Log file ###
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Path to file where all logs will be stored:
|
||||
#### Log file `-l`
|
||||
|
||||
```
|
||||
fiche -l /home/www/fiche-log.txt
|
||||
```
|
||||
|
||||
-----------------
|
||||
__Default value:__ not set
|
||||
|
||||
#### Ban list ###
|
||||
__WARNING:__ this file has to be user-writable
|
||||
|
||||
Path to file where you provided all banned IP adresses:
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
#### Ban list `-b`
|
||||
|
||||
Relative or absolute path to a file containing IP addresses of banned users.
|
||||
|
||||
```
|
||||
fiche -b /home/www/fiche-bans.txt
|
||||
fiche -b fiche-bans.txt
|
||||
```
|
||||
|
||||
-----------------
|
||||
__Format of the file:__ this file should contain only addresses, one per line.
|
||||
|
||||
#### White list ####
|
||||
__Default value:__ not set
|
||||
|
||||
If whitelist mode is enabled, only addresses from list will be able to upload files. There's example:
|
||||
__WARNING:__ not implemented yet
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
#### White list `-w`
|
||||
|
||||
If whitelist mode is enabled, only addresses from the list will be able
|
||||
to upload files.
|
||||
|
||||
```
|
||||
fiche -w /home/www/fiche-whitelist.txt
|
||||
fiche -w fiche-whitelist.txt
|
||||
```
|
||||
|
||||
-----------------
|
||||
__Format of the file:__ this file should contain only addresses, one per line.
|
||||
|
||||
#### Whitelist and banlist syntax ####
|
||||
__Default value:__ not set
|
||||
|
||||
There is no specific syntax, there files may contain not only addresses.
|
||||
__WARNING:__ not implemented yet
|
||||
|
||||
-----------------
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
#### Examples ####
|
||||
|
||||
Logging connections with banlist:
|
||||
|
||||
```
|
||||
fiche -d domain.com -l /home/www/log.txt -b /home/www/bans.txt
|
||||
```
|
||||
|
||||
-----------------
|
||||
|
||||
Only for personal use with whitelist
|
||||
|
||||
```
|
||||
fiche -d domain.com -w /home/www/whitelist.txt
|
||||
```
|
||||
|
||||
-----------------
|
||||
|
||||
Custom output directory, bigger slug size, reduced buffer, custom port:
|
||||
|
||||
```
|
||||
fiche -d domain.com -o /media/disk/fiche/ -s 8 -B 2048 -p 6666
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Running as service ##
|
||||
You can run fiche as service, there is simple systemd example:
|
||||
### Running as a service
|
||||
|
||||
There's a simple systemd example:
|
||||
```
|
||||
[Unit]
|
||||
Description=FICHE-SERVER
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/local/bin/fiche -d code.solusipse.net -o /home/www/code/ -l /home/www/log.txt
|
||||
ExecStart=/usr/local/bin/fiche -d yourdomain.com -o /path/to/output -l /path/to/log -u youruser
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
In service mode you have to set output directory with `-o` parameter, there's example:
|
||||
__WARNING:__ In service mode you have to set output directory with `-o` parameter.
|
||||
|
||||
```
|
||||
fiche -o /home/www/code/
|
||||
```
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
## Webserver ##
|
||||
### Example nginx config
|
||||
|
||||
To make files available for users, you need to host them somehow. Http server is easiest option. Just set root
|
||||
directory to ```BASEDIR```.
|
||||
Fiche has no http server built-in, thus you need to setup one if you want to make files available through http.
|
||||
|
||||
There is sample configuration for nginx:
|
||||
There's a sample configuration for nginx:
|
||||
|
||||
```
|
||||
server {
|
||||
@@ -237,6 +331,6 @@ server {
|
||||
}
|
||||
```
|
||||
|
||||
## License ##
|
||||
## License
|
||||
|
||||
Fiche is MIT licensed.
|
||||
|
||||
0
extras/lines/__init__.py
Normal file
0
extras/lines/__init__.py
Normal file
51
extras/lines/lines.py
Normal file
51
extras/lines/lines.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from flask import Flask, abort, redirect
|
||||
app = Flask(__name__)
|
||||
|
||||
import argparse, os, pygments
|
||||
from pygments import highlight
|
||||
from pygments.lexers import guess_lexer
|
||||
from pygments.formatters import HtmlFormatter
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("root_dir", help="Path to directory with pastes")
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def main():
|
||||
return redirect("http://termbin.com", code=302)
|
||||
|
||||
|
||||
@app.route('/<slug>')
|
||||
def beautify(slug):
|
||||
# Return 404 in case of urls longer than 64 chars
|
||||
if len(slug) > 64:
|
||||
abort(404)
|
||||
|
||||
# Create path for the target dir
|
||||
target_dir = os.path.join(args.root_dir, slug)
|
||||
|
||||
# Block directory traversal attempts
|
||||
if not target_dir.startswith(args.root_dir):
|
||||
abort(404)
|
||||
|
||||
# Check if directory with requested slug exists
|
||||
if os.path.isdir(target_dir):
|
||||
target_file = os.path.join(target_dir, "index.txt")
|
||||
|
||||
# File index.txt found inside that dir
|
||||
with open(target_file) as f:
|
||||
code = f.read()
|
||||
# Identify language
|
||||
lexer = guess_lexer(code)
|
||||
# Create formatter with line numbers
|
||||
formatter = HtmlFormatter(linenos=True, full=True)
|
||||
# Return parsed code
|
||||
return highlight(code, lexer, formatter)
|
||||
|
||||
# Not found
|
||||
abort(404)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
156
fiche.h
156
fiche.h
@@ -5,20 +5,16 @@ Fiche - Command line pastebin for sharing terminal output.
|
||||
|
||||
License: MIT (http://www.opensource.org/licenses/mit-license.php)
|
||||
Repository: https://github.com/solusipse/fiche/
|
||||
Live example: http://code.solusipse.net/
|
||||
Live example: http://termbin.com
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
usage: fiche [-pbsdolBuw].
|
||||
[-d domain] [-p port] [-s slug size]
|
||||
usage: fiche [-DepbsdolBuw].
|
||||
[-D] [-e] [-d domain] [-p port] [-s slug size]
|
||||
[-o output directory] [-B buffer size] [-u user name]
|
||||
[-l log file] [-b banlist] [-w whitelist]
|
||||
|
||||
Compile with Makefile or manually with -O2 and -pthread flags.
|
||||
To install use `make install` command.
|
||||
|
||||
Use netcat to push text - example:
|
||||
|
||||
$ cat fiche.c | nc localhost 9999
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
@@ -27,75 +23,97 @@ $ cat fiche.c | nc localhost 9999
|
||||
#ifndef FICHE_H
|
||||
#define FICHE_H
|
||||
|
||||
#include <pwd.h>
|
||||
#include <time.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int UID = -1;
|
||||
int GID = -1;
|
||||
char *LOG;
|
||||
char *BASEDIR;
|
||||
char *BANLIST;
|
||||
char *BANFILE;
|
||||
char *WHITEFILE;
|
||||
char *WHITELIST;
|
||||
int PORT = 9999;
|
||||
int SLUG_SIZE = 4;
|
||||
int BUFSIZE = 32768;
|
||||
int QUEUE_SIZE = 500;
|
||||
char DOMAIN[128] = "http://localhost/";
|
||||
|
||||
unsigned int time_seed;
|
||||
const char *symbols = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
/**
|
||||
* @brief Used as a container for fiche settings. Create before
|
||||
* the initialization
|
||||
*
|
||||
*/
|
||||
typedef struct Fiche_Settings {
|
||||
/**
|
||||
* @brief Domain used in output links
|
||||
*/
|
||||
char *domain;
|
||||
|
||||
struct thread_arguments
|
||||
{
|
||||
int connection_socket;
|
||||
struct sockaddr_in client_address;
|
||||
};
|
||||
/**
|
||||
* @brief Path to directory used for storing uploaded pastes
|
||||
*/
|
||||
char *output_dir_path;
|
||||
|
||||
struct client_data
|
||||
{
|
||||
char *ip_address;
|
||||
char *hostname;
|
||||
};
|
||||
/**
|
||||
* @brief Address on which fiche is waiting for connections
|
||||
*/
|
||||
char *listen_addr;
|
||||
|
||||
int create_socket();
|
||||
int create_directory(char *slug);
|
||||
int check_protocol(char *buffer);
|
||||
/**
|
||||
* @brief Port on which fiche is waiting for connections
|
||||
*/
|
||||
uint16_t port;
|
||||
|
||||
void bind_to_port(int listen_socket, struct sockaddr_in serveraddr);
|
||||
void display_line(){printf("====================================\n");}
|
||||
void error(char *error_code){perror(error_code); exit(1);}
|
||||
void display_date();
|
||||
void perform_connection(int listen_socket);
|
||||
void generate_url(char *buffer, char *slug, size_t slug_length, struct client_data data);
|
||||
void save_to_file(char *buffer, char *slug, struct client_data data);
|
||||
void display_info(struct client_data data, char *slug, char *message);
|
||||
void startup_message();
|
||||
void set_basedir();
|
||||
void load_list(char *file_path, int type);
|
||||
void parse_parameters(int argc, char **argv);
|
||||
void save_log(char *slug, char *hostaddrp, char *h_name);
|
||||
void change_owner(char *directory);
|
||||
void set_uid_gid();
|
||||
/**
|
||||
* @brief Length of a paste's name
|
||||
*/
|
||||
uint8_t slug_len;
|
||||
|
||||
char *return_line(){return("\n====================================");}
|
||||
char *check_banlist(char *ip_address);
|
||||
char *check_whitelist(char *ip_address);
|
||||
char *get_date();
|
||||
/**
|
||||
* @brief If set, returns url with https prefix instead of http
|
||||
*/
|
||||
bool https;
|
||||
|
||||
/**
|
||||
* @brief Connection buffer length
|
||||
*
|
||||
* @remarks Length of this buffer limits max size of uploaded files
|
||||
*/
|
||||
uint32_t buffer_len;
|
||||
|
||||
/**
|
||||
* @brief Name of the user that runs fiche process
|
||||
*/
|
||||
char *user_name;
|
||||
|
||||
/**
|
||||
* @brief Path to the log file
|
||||
*/
|
||||
char *log_file_path;
|
||||
|
||||
/**
|
||||
* @brief Path to the file with banned IPs
|
||||
*/
|
||||
char *banlist_path;
|
||||
|
||||
/**
|
||||
* @brief Path to the file with whitelisted IPs
|
||||
*/
|
||||
char *whitelist_path;
|
||||
|
||||
|
||||
|
||||
} Fiche_Settings;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initializes Fiche_Settings instance
|
||||
*/
|
||||
void fiche_init(Fiche_Settings *settings);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Runs fiche server
|
||||
*
|
||||
* @return 0 if it was able to start, any other value otherwise
|
||||
*/
|
||||
int fiche_run(Fiche_Settings settings);
|
||||
|
||||
|
||||
/**
|
||||
* @brief array of symbols used in slug generation
|
||||
* @remarks defined in fiche.c
|
||||
*/
|
||||
extern const char *Fiche_Symbols;
|
||||
|
||||
struct sockaddr_in set_address(struct sockaddr_in serveraddr);
|
||||
struct client_data get_client_address(struct sockaddr_in client_address);
|
||||
|
||||
#endif
|
||||
|
||||
147
main.c
Normal file
147
main.c
Normal file
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
Fiche - Command line pastebin for sharing terminal output.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
License: MIT (http://www.opensource.org/licenses/mit-license.php)
|
||||
Repository: https://github.com/solusipse/fiche/
|
||||
Live example: http://termbin.com
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
usage: fiche [-DepbsdolBuw].
|
||||
[-D] [-e] [-d domain] [-p port] [-s slug size]
|
||||
[-o output directory] [-B buffer size] [-u user name]
|
||||
[-l log file] [-b banlist] [-w whitelist]
|
||||
|
||||
Use netcat to push text - example:
|
||||
$ cat fiche.c | nc localhost 9999
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "fiche.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
// Fiche settings instance
|
||||
Fiche_Settings fs;
|
||||
|
||||
// Initialize settings instance to default values
|
||||
fiche_init(&fs);
|
||||
|
||||
// Note: fiche_run is responsible for checking if these values
|
||||
// were set correctly
|
||||
|
||||
// Note: according to getopt documentation, we don't need to
|
||||
// copy strings, so we decided to go with pointer approach for these
|
||||
|
||||
// Parse input arguments
|
||||
int c;
|
||||
while ((c = getopt(argc, argv, "D6eSL:p:b:s:d:o:l:B:u:w:")) != -1) {
|
||||
switch (c) {
|
||||
|
||||
// domain
|
||||
case 'd':
|
||||
{
|
||||
fs.domain = optarg;
|
||||
}
|
||||
break;
|
||||
|
||||
// port
|
||||
case 'p':
|
||||
{
|
||||
fs.port = atoi(optarg);
|
||||
}
|
||||
break;
|
||||
|
||||
// listen_addr
|
||||
case 'L':
|
||||
{
|
||||
fs.listen_addr = optarg;
|
||||
}
|
||||
break;
|
||||
|
||||
// slug size
|
||||
case 's':
|
||||
{
|
||||
fs.slug_len = atoi(optarg);
|
||||
}
|
||||
break;
|
||||
|
||||
// https
|
||||
case 'S':
|
||||
{
|
||||
fs.https = true;
|
||||
}
|
||||
break;
|
||||
|
||||
// output directory path
|
||||
case 'o':
|
||||
{
|
||||
fs.output_dir_path = optarg;
|
||||
}
|
||||
break;
|
||||
|
||||
// buffer size
|
||||
case 'B':
|
||||
{
|
||||
fs.buffer_len = atoi(optarg);
|
||||
}
|
||||
break;
|
||||
|
||||
// user name
|
||||
case 'u':
|
||||
{
|
||||
fs.user_name = optarg;
|
||||
}
|
||||
break;
|
||||
|
||||
// log file path
|
||||
case 'l':
|
||||
{
|
||||
fs.log_file_path = optarg;
|
||||
}
|
||||
break;
|
||||
|
||||
// banlist file path
|
||||
case 'b':
|
||||
{
|
||||
fs.banlist_path = optarg;
|
||||
}
|
||||
break;
|
||||
|
||||
// whitelist file path
|
||||
case 'w':
|
||||
{
|
||||
fs.whitelist_path = optarg;
|
||||
}
|
||||
break;
|
||||
|
||||
// Display help in case of any unsupported argument
|
||||
default:
|
||||
{
|
||||
printf("usage: fiche [-dLpsSoBulbw].\n");
|
||||
printf(" [-d domain] [-L listen_addr] [-p port] [-s slug size]\n");
|
||||
printf(" [-o output directory] [-B buffer size] [-u user name]\n");
|
||||
printf(" [-l log file] [-b banlist] [-w whitelist] [-S]\n");
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fiche_run(fs);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user