Skip to content

Commit

Permalink
Merge pull request #165 from pi-hole/release/2.12
Browse files Browse the repository at this point in the history
FTL v2.12
  • Loading branch information
Jacob Salmela authored Dec 7, 2017
2 parents 48068d3 + c63cd5e commit 437af07
Show file tree
Hide file tree
Showing 16 changed files with 4,101 additions and 2,755 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ script:
- mv pihole-FTL "${DEST_DIR}/${BIN_NAME}"
- cd "${DEST_DIR}"
- sha1sum pihole-FTL-* > ${BIN_NAME}.sha1
- wget https://ftl.pi-hole.net:8080/FTL-client
- chmod +x ./FTL-client
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then ./FTL-client "${TRAVIS_BRANCH}" "${BIN_NAME}" "${travissecret}"; fi'
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then ./FTL-client "${TRAVIS_BRANCH}" "${BIN_NAME}.sha1" "${travissecret}"; fi'
- rm ./FTL-client
- ls -lah "${DEST_DIR}"
deploy:
skip_cleanup: true
Expand Down
10 changes: 10 additions & 0 deletions FTL.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include <syslog.h>
// SQLite
#include "sqlite3.h"
// tolower()
#include <ctype.h>

#include "routines.h"

Expand Down Expand Up @@ -86,6 +88,7 @@ typedef struct {
const char* setupVars;
const char* wildcards;
const char* auditlist;
const char* dnsmasqconfig;
} logFileNamesStruct;

typedef struct {
Expand Down Expand Up @@ -120,6 +123,8 @@ typedef struct {
bool query_display;
bool analyze_AAAA;
int maxDBdays;
bool resolveIPv6;
bool resolveIPv4;
} ConfigStruct;

// Dynamic structs
Expand Down Expand Up @@ -168,6 +173,8 @@ typedef struct {
int forwardnum;
int *forwarddata;
int *querytypedata;
int clientnum;
int *clientdata;
} overTimeDataStruct;

typedef struct {
Expand All @@ -178,6 +185,7 @@ typedef struct {
int forwardedips;
int forwardednames;
int forwarddata;
int clientdata;
int querytypedata;
} memoryStruct;

Expand Down Expand Up @@ -209,6 +217,7 @@ bool debugGC;
bool debugDB;
bool threadwritelock;
bool threadreadlock;
unsigned char blockingstatus;

char ** wildcarddomains;

Expand All @@ -224,3 +233,4 @@ bool database;
long int lastdbindex;
bool travis;
bool DBdeleteoldqueries;
bool rereadgravity;
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ OBJ = main.o structs.o log.o daemon.o parser.o signals.o socket.o request.o grep

# Get git commit version and date
GIT_BRANCH := $(shell git branch | sed -n 's/^\* //p')
GIT_HASH := $(shell git --no-pager describe --always --dirty)
GIT_VERSION := $(shell git --no-pager describe --tags --always --dirty)
GIT_DATE := $(shell git --no-pager show --date=short --format="%ai" --name-only | head -n 1)
GIT_TAG := $(shell git describe --tags --abbrev=0)
Expand Down Expand Up @@ -72,6 +73,7 @@ version.h: version~
@echo '#define GIT_DATE "$(GIT_DATE)"' >> "$@"
@echo '#define GIT_BRANCH "$(GIT_BRANCH)"' >> "$@"
@echo '#define GIT_TAG "$(GIT_TAG)"' >> "$@"
@echo '#define GIT_HASH "$(GIT_HASH)"' >> "$@"
@echo "Making FTL version on branch $(GIT_BRANCH) - $(GIT_VERSION) ($(GIT_DATE))"

prefix=/usr
Expand Down
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,16 @@ Once you are used to it, you can skip most of the steps and debugging is actuall
* `sudo chown pi:pi /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port`
* `sudo chmod 0644 /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port`
6. Start `pihole-FTL` in the debugger: `gdb pihole-FTL`
7. Type `run debug` to start `FTL` (you should see some lines of text and `FTL` should start successfully).
8. You can now close the terminal (Ctrl+A and then D to detach) and come back later using (`screen -r`) when it has crashed
9. If it has crashed, copy&paste the terminal output, and
10. type also `backtrace` and post the output in a (new) issue
11. We might ask for additional information in order to isolate your particular issue
7. Type `handle SIGHUP nostop SIGPIPE nostop` to instruct the debugger to don't stop on expected signals
8. Type `run debug` to start `FTL` (you should see some lines of text and `FTL` should start successfully)
9. You can now close the terminal (Ctrl+A and then D to detach) and come back later using (`screen -r`) when it has crashed
10. If it has crashed, copy&paste the terminal output, and
11. type also `backtrace` and post the output in a (new) issue
12. We might ask for additional information in order to isolate your particular issue

#### Simplified debugging instructions (when `FTL` is running)

`FTL` has been designed such that a debugger can be attached to an already running process to ease debugging. Use `sudo gdb -p $(pidof pihole-FTL)` to attach to an already running `pihole-FTL` process. You can leave off `sudo` if you are running `pihole-FTL` with the current user. Once loading of the symbols has finished (the `(gdb)` input prompt is shown), run `continue` to continue operation of `pihole-FTL` inside the debugger. All debugger features are now available.
`FTL` has been designed such that a debugger can be attached to an already running process to ease debugging. Use `sudo gdb -p $(pidof pihole-FTL)` to attach to an already running `pihole-FTL` process. You can leave off `sudo` if you are running `pihole-FTL` with the current user. Once loading of the symbols has finished (the `(gdb)` input prompt is shown), run `handle SIGHUP nostop SIGPIPE nostop` followed by `continue` to continue operation of `pihole-FTL` inside the debugger. All debugger features are now available.

If `pihole-FTL` has crashed, copy&paste the terminal output into a (new) issue. Also type `backtrace` and include its output. We might ask for additional information in order to isolate your particular issue.

Expand All @@ -80,6 +81,10 @@ When you want to detach the debugger from `FTL` without terminating the process,
- `debug` - Don't go into daemon mode (stay in foreground) + more verbose logging
- `test` - Start `FTL` and process everything, but shut down immediately afterwards
- `version` - Don't start `FTL`, show only version
- `tag` - Don't start `FTL`, show only git tag
- `branch` - Don't start `FTL`, show only git branch `FTL` was compiled from
- `no-daemon` or `-f` - Don't go into background (daemon mode)
- `help` or `-h` - Don't start `FTL`, show help

Command line arguments can be arbitrarily combined, e.g. `pihole-FTL debug test`

Expand All @@ -104,6 +109,8 @@ Possible settings (**the option shown first is the default**):
- `QUERY_DISPLAY=yes|no` (Display all queries? Set to `no` to hide query display)
- `AAAA_QUERY_ANALYSIS=yes|no` (Allow `FTL` to analyze AAAA queries from pihole.log?)
- `MAXDBDAYS=365` (How long should queries be stored in the database? Setting this to `0` disables the database altogether)
- `RESOLVE_IPV6=yes|no` (Should `FTL` try to resolve IPv6 addresses to host names?)
- `RESOLVE_IPV4=yes|no` (Should `FTL` try to resolve IPv4 addresses to host names?)

### Implemented keywords (starting with `>`, subject to change):

Expand Down
75 changes: 68 additions & 7 deletions args.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,60 +22,90 @@ bool travis = false;
void parse_args(int argc, char* argv[])
{
int i;
for(i=0; i < argc; i++) {
if((strcmp(argv[i], "d") == 0) || (strcmp(argv[i], "debug") == 0))
// start from 1, as argv[0] is the executable name "pihole-FTL"
for(i=1; i < argc; i++)
{
bool ok = false;
if(strcmp(argv[i], "d") == 0 ||
strcmp(argv[i], "debug") == 0)
{
debug = true;
ok = true;
}

if(strcmp(argv[i], "debugthreads") == 0)
{
debug = true;
debugthreads = true;
ok = true;
}

if(strcmp(argv[i], "debugclients") == 0)
{
debug = true;
debugclients = true;
ok = true;
}

if(strcmp(argv[i], "debugGC") == 0)
{
debug = true;
debugGC = true;
ok = true;
}

if(strcmp(argv[i], "debugDB") == 0)
{
debug = true;
debugDB = true;
ok = true;
}

if(strcmp(argv[i], "test") == 0)
{
killed = 1;
ok = true;
}

if(strcmp(argv[i], "version") == 0)
if(strcmp(argv[i], "-v") == 0 ||
strcmp(argv[i], "version") == 0)
{
printf("%s\n",GIT_VERSION);
if(strcmp(GIT_BRANCH, "master") == 0)
printf("%s\n",GIT_VERSION);
else
printf("vDev-%s\n",GIT_HASH);
exit(EXIT_SUCCESS);
}

if(strcmp(argv[i], "tag") == 0)
if(strcmp(argv[i], "-t") == 0 ||
strcmp(argv[i], "tag") == 0)
{
printf("%s\n",GIT_TAG);
exit(EXIT_SUCCESS);
}

if(strcmp(argv[i], "-b") == 0 ||
strcmp(argv[i], "branch") == 0)
{
printf("%s\n",GIT_BRANCH);
exit(EXIT_SUCCESS);
}

// pihole-FTL running
// will test if another pihole-FTL process is running
// and exits even if not (instead of starting a new one)
if(strcmp(argv[i], "running") == 0)
{
runtest = true;
ok = true;
}

if(strcmp(argv[i], "no-daemon") == 0 || strcmp(argv[i], "-f") == 0)
// Don't go into background
if(strcmp(argv[i], "-f") == 0 ||
strcmp(argv[i], "no-daemon") == 0)
{
daemonmode = false;
ok = true;
}

// Use files in local places for Travis-CI tests
Expand All @@ -85,8 +115,39 @@ void parse_args(int argc, char* argv[])
FTLfiles.log = "pihole-FTL.log";
FTLfiles.db = "pihole-FTL.db";
files.log = "pihole.log";
ok = true;
}

// Other arguments are ignored
// List of implemented arguments
if(strcmp(argv[i], "-h") == 0 ||
strcmp(argv[i], "help") == 0)
{
printf("pihole-FTL - The Pi-hole FTL engine\n\n");
printf("Usage: sudo service pihole-FTL <action>\n");
printf("where '<action>' is one of start / stop / restart\n\n");
printf("Available arguments:\n");
printf("\t debug More verbose logging,\n");
printf("\t don't go into daemon mode\n");
printf("\t test Don't start pihole-FTL but\n");
printf("\t instead quit immediately\n");
printf("\t-v, version Return version\n");
printf("\t-t, tag Return git tag\n");
printf("\t-b, branch Return git branch\n");
printf("\t running Test if another pihole-FTL\n");
printf("\t process is running and exit\n");
printf("\t even if not (instead of\n");
printf("\t starting a new one)\n");
printf("\t-f, no-daemon Don't go into daemon mode\n");
printf("\t-h, help Display this help and exit\n");
printf("\n\nOnline help: https://github.com/pi-hole/FTL\n");
exit(EXIT_SUCCESS);
}

// Complain if invalid options have been found
if(!ok)
{
printf("pihole-FTL: invalid option -- '%s'\nTry '%s --help' for more information\n", argv[i], argv[0]);
exit(EXIT_FAILURE);
}
}
}
89 changes: 54 additions & 35 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ void read_FTLconf(void)
// defaults to: listen only local
config.socket_listenlocal = true;
buffer = parse_FTLconf(fp, "SOCKET_LISTENING");
if(buffer != NULL)
{
if(strcmp(buffer, "all") == 0)
config.socket_listenlocal = false;
}

if(buffer != NULL && strcmp(buffer, "all") == 0)
config.socket_listenlocal = false;

if(config.socket_listenlocal)
logg(" SOCKET_LISTENING: only local");
else
Expand All @@ -49,33 +48,31 @@ void read_FTLconf(void)
config.rolling_24h = true;
config.include_yesterday = true;
buffer = parse_FTLconf(fp, "TIMEFRAME");
if(buffer != NULL)

if(buffer != NULL && strcmp(buffer, "yesterday") == 0)
{
config.include_yesterday = true;
config.rolling_24h = false;
logg(" TIMEFRAME: Yesterday + Today");
}
else if(buffer != NULL && strcmp(buffer, "today") == 0)
{
if(strcmp(buffer, "yesterday") == 0)
{
config.include_yesterday = true;
config.rolling_24h = false;
logg(" TIMEFRAME: Yesterday + Today");
}
else if(strcmp(buffer, "today") == 0)
{
config.include_yesterday = false;
config.rolling_24h = false;
logg(" TIMEFRAME: Today");
}
config.include_yesterday = false;
config.rolling_24h = false;
logg(" TIMEFRAME: Today");
}

if(config.rolling_24h)
logg(" TIMEFRAME: Rolling 24h");

// QUERY_DISPLAY
// defaults to: Yes
config.query_display = true;
buffer = parse_FTLconf(fp, "QUERY_DISPLAY");
if(buffer != NULL)
{
if(strcmp(buffer, "no") == 0)
config.query_display = false;
}

if(buffer != NULL && strcmp(buffer, "no") == 0)
config.query_display = false;

if(config.query_display)
logg(" QUERY_DISPLAY: Show queries");
else
Expand All @@ -85,11 +82,10 @@ void read_FTLconf(void)
// defaults to: Yes
config.analyze_AAAA = true;
buffer = parse_FTLconf(fp, "AAAA_QUERY_ANALYSIS");
if(buffer != NULL)
{
if(strcmp(buffer, "no") == 0)
config.analyze_AAAA = false;
}

if(buffer != NULL && strcmp(buffer, "no") == 0)
config.analyze_AAAA = false;

if(config.analyze_AAAA)
logg(" AAAA_QUERY_ANALYSIS: Show AAAA queries");
else
Expand All @@ -99,18 +95,41 @@ void read_FTLconf(void)
// defaults to: 365 days
config.maxDBdays = 365;
buffer = parse_FTLconf(fp, "MAXDBDAYS");
if(buffer != NULL)
{
int value = 0;
if(sscanf(buffer, "%i", &value))
if(value >= 0)
config.maxDBdays = value;
}

int value = 0;
if(buffer != NULL && sscanf(buffer, "%i", &value))
if(value >= 0)
config.maxDBdays = value;

if(config.maxDBdays == 0)
logg(" MAXDBDAYS: --- (DB disabled)", config.maxDBdays);
else
logg(" MAXDBDAYS: max age for stored queries is %i days", config.maxDBdays);

// RESOLVE_IPV6
// defaults to: Yes
config.resolveIPv6 = true;
buffer = parse_FTLconf(fp, "RESOLVE_IPV6");

if(buffer != NULL && strcmp(buffer, "no") == 0)
config.resolveIPv6 = false;

if(config.resolveIPv6)
logg(" RESOLVE_IPV6: Resolve IPv6 addresses");
else
logg(" RESOLVE_IPV6: Don\'t resolve IPv6 addresses");

// RESOLVE_IPV4
// defaults to: Yes
config.resolveIPv4 = true;
buffer = parse_FTLconf(fp, "RESOLVE_IPV4");
if(buffer != NULL && strcmp(buffer, "no") == 0)
config.resolveIPv4 = false;
if(config.resolveIPv4)
logg(" RESOLVE_IPV4: Resolve IPv4 addresses");
else
logg(" RESOLVE_IPV4: Don\'t resolve IPv4 addresses");

logg("Finished config file parsing");

if(conflinebuffer != NULL)
Expand Down
Loading

0 comments on commit 437af07

Please sign in to comment.