forked from pi-hole/FTL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.c
155 lines (148 loc) · 3.45 KB
/
request.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* Pi-hole: A black hole for Internet advertisements
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* FTL Engine
* Socket request handling routines
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
#include "FTL.h"
#include "api.h"
bool command(char *client_message, const char* cmd) {
return strstr(client_message, cmd) != NULL;
}
void process_request(char *client_message, int *sock)
{
char EOT[2];
EOT[0] = 0x04;
EOT[1] = 0x00;
bool processed = false;
if(command(client_message, ">stats"))
{
processed = true;
getStats(sock);
}
else if(command(client_message, ">overTime"))
{
processed = true;
getOverTime(sock);
}
else if(command(client_message, ">top-domains") || command(client_message, ">top-ads"))
{
processed = true;
getTopDomains(client_message, sock);
}
else if(command(client_message, ">top-clients"))
{
processed = true;
getTopClients(client_message, sock);
}
else if(command(client_message, ">forward-dest"))
{
processed = true;
getForwardDestinations(client_message, sock);
}
else if(command(client_message, ">forward-names"))
{
processed = true;
getForwardDestinations(">forward-dest unsorted", sock);
}
else if(command(client_message, ">querytypes"))
{
processed = true;
getQueryTypes(sock);
}
else if(command(client_message, ">getallqueries"))
{
processed = true;
getAllQueries(client_message, sock);
}
else if(command(client_message, ">recentBlocked"))
{
processed = true;
getRecentBlocked(client_message, sock);
}
else if(command(client_message, ">clientID"))
{
processed = true;
getClientID(sock);
}
else if(command(client_message, ">QueryTypesoverTime"))
{
processed = true;
getQueryTypesOverTime(sock);
}
else if(command(client_message, ">version"))
{
processed = true;
getVersion(sock);
}
else if(command(client_message, ">dbstats"))
{
processed = true;
getDBstats(sock);
}
else if(command(client_message, ">ClientsoverTime"))
{
processed = true;
getClientsOverTime(sock);
}
else if(command(client_message, ">client-names"))
{
processed = true;
getClientNames(sock);
}
else if(command(client_message, ">unknown"))
{
processed = true;
getUnknownQueries(sock);
}
else if(command(client_message, ">domain"))
{
processed = true;
getDomainDetails(client_message, sock);
}
else if(command(client_message, ">cacheinfo"))
{
processed = true;
getCacheInformation(sock);
}
else if(command(client_message, ">reresolve"))
{
processed = true;
logg("Received API request to re-resolve host names");
// Need to release the thread lock already here to allow
// the resolver to process the incoming PTR requests
disable_thread_lock();
// onlynew=false -> reresolve all host names
resolveClients(false);
resolveForwardDestinations(false);
logg("Done re-resolving host names");
}
else if(command(client_message, ">recompile-regex"))
{
processed = true;
logg("Received API request to recompile regex");
free_regex();
read_regex_from_file();
}
// Test only at the end if we want to quit or kill
// so things can be processed before
if(command(client_message, ">quit") || command(client_message, EOT))
{
processed = true;
close(*sock);
*sock = 0;
}
if(!processed)
{
ssend(*sock,"unknown command: %s\n",client_message);
}
// End of queryable commands
if(*sock != 0)
{
// Send EOM
seom(*sock);
}
}