Entirely rewritten fiche
This commit is contained in:
159
fiche.h
159
fiche.h
@@ -5,7 +5,7 @@ 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
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
@@ -14,15 +14,7 @@ usage: fiche [-DepbsdolBuw].
|
||||
[-o output directory] [-B buffer size] [-u user name]
|
||||
[-l log file] [-b banlist] [-w whitelist]
|
||||
|
||||
-D option is for daemonizing fiche
|
||||
|
||||
-e option is for using an extended character set for the URL
|
||||
|
||||
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
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
@@ -31,91 +23,86 @@ $ cat fiche.c | nc localhost 9999
|
||||
#ifndef FICHE_H
|
||||
#define FICHE_H
|
||||
|
||||
#ifndef HAVE_INET6
|
||||
#define HAVE_INET6 1
|
||||
#endif
|
||||
#include <stdint.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>
|
||||
|
||||
int UID = -1;
|
||||
int GID = -1;
|
||||
char *LOG;
|
||||
char *BASEDIR;
|
||||
char *BANLIST;
|
||||
char *BANFILE;
|
||||
char *WHITEFILE;
|
||||
char *WHITELIST;
|
||||
int DAEMON = 0;
|
||||
int HTTPS = 0;
|
||||
int PORT = 9999;
|
||||
int IPv6 = 0;
|
||||
int SLUG_SIZE = 4;
|
||||
int BUFSIZE = 32768;
|
||||
int QUEUE_SIZE = 500;
|
||||
char DOMAIN[128] = "localhost/";
|
||||
char symbols[67] = "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;
|
||||
|
||||
unsigned int time_seed;
|
||||
/**
|
||||
* @brief Path to directory used for storing uploaded pastes
|
||||
*/
|
||||
char *output_dir_path;
|
||||
|
||||
struct thread_arguments
|
||||
{
|
||||
int connection_socket;
|
||||
struct sockaddr_in client_address;
|
||||
#if (HAVE_INET6)
|
||||
struct sockaddr_in6 client_address6;
|
||||
#endif
|
||||
};
|
||||
/**
|
||||
* @brief Port on which fiche is waiting for connections
|
||||
*/
|
||||
uint16_t port;
|
||||
|
||||
struct client_data
|
||||
{
|
||||
char *ip_address;
|
||||
char *hostname;
|
||||
};
|
||||
/**
|
||||
* @brief Length of a paste's name
|
||||
*/
|
||||
uint8_t slug_len;
|
||||
|
||||
int create_socket();
|
||||
int create_directory(char *slug);
|
||||
int check_protocol(char *buffer);
|
||||
/**
|
||||
* @brief Connection buffer length
|
||||
*
|
||||
* @remarks Length of this buffer limits max size of uploaded files
|
||||
*/
|
||||
uint32_t buffer_len;
|
||||
|
||||
void bind_to_port(int listen_socket, struct sockaddr_in serveraddr);
|
||||
#if (HAVE_INET6)
|
||||
void bind_to_port6(int listen_socket, struct sockaddr_in6 serveraddr6);
|
||||
#endif
|
||||
void error(char *buffer);
|
||||
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 set_domain_name();
|
||||
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 set_uid_gid();
|
||||
/**
|
||||
* @brief Name of the user that runs fiche process
|
||||
*/
|
||||
char *user_name;
|
||||
|
||||
char *check_banlist(char *ip_address);
|
||||
char *check_whitelist(char *ip_address);
|
||||
char *get_date();
|
||||
/**
|
||||
* @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);
|
||||
#if (HAVE_INET6)
|
||||
struct sockaddr_in6 set_address6(struct sockaddr_in6 serveraddr6);
|
||||
#endif
|
||||
struct client_data get_client_address(struct sockaddr_in client_address);
|
||||
#if (HAVE_INET6)
|
||||
struct client_data get_client_address6(struct sockaddr_in6 client_address6);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user