forked from team-eureka/Eureka-Panel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpanel.c
258 lines (248 loc) · 8.19 KB
/
webpanel.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include "assert.h"
#include "string.h"
#include "minIni.h"
#include "malloc.h"
#include "modules/common_func.c"
#include "modules/web_module_home.c"
#include "modules/web_module_logcat.c"
#include "modules/web_module_settings.c"
#include "modules/web_module_headers.c"
#include "modules/web_module_footer.c"
#include "modules/web_module_status.c"
#include "modules/web_module_debug.c"
#include "modules/web_module_aboutus.c"
#include "modules/web_module_companion.c"
#include "modules/web_module_popup_headers.c"
#define sizearray(a) (sizeof(a) / sizeof((a)[0]))
#define QS_LEN 65536
#define BLOCK_SIZE 512
//This is the main web panel application that includes all portal modules
//Please make modules where possible, and include them. Only modify this if necessary
int processPostData(char *postData)
{
char *token;
char buf[1024];
char decodedToken[100];
char action[80];
char section[80];
char field[80];
char value[80];
int smartDnsUpdatePerformed;
char smartDnsProviderPrimary[1024];
char smartDnsProviderSecondary[1024];
int n;
sscanf(postData, "action=%[0-9a-zA-Z]", &action);
if(compStr(action, "update", sizearray(action)))
{
token = strtok (postData,"&");
while (token != NULL)
{
//check if contains / so we know it's a var to update
urldecode2(decodedToken, token);
if(strstr(decodedToken, "/") != NULL)
{
sscanf(decodedToken, "%[0-9a-zA-Z]/%[0-9a-zA-Z]=%[0-9a-zA-Z.:/_%-]", section, field, value);
//check if DNS update and allowed to perform
if(compStr(section, "DNS", sizearray(section)) && !compStr(field, "useDHCP", sizearray(field)) && (smartDnsUpdatePerformed == 1))
{
//do nothing
}
else
{
n = write_config_var(section, field, value);
}
//Check if an update for smartDNS selected which is not set to other
if(compStr(section, "SmartDNS", sizearray(section)) && compStr(field, "selected", sizearray(section)) && !compStr(value, "other", sizearray(section)))
{
strcpy(buf, "SmartDNS-");
strcat(buf, value);
//get DNS details for SmartDNS provider
read_config_var(buf, "primary", smartDnsProviderPrimary);
read_config_var(buf, "secondary", smartDnsProviderSecondary);
//set DNS details to selected SmartDNS Provider
n = write_config_var("DNS", "primary", smartDnsProviderPrimary);
n = write_config_var("DNS", "secondary", smartDnsProviderSecondary);
//set that DNS update has been performed so any unwanted commits don't occur after
smartDnsUpdatePerformed=1;
}
}
token = strtok (NULL, "&");
}
}
}
//main function for web services
int main(void)
{
long n;
char strPage[1023];
char strFooters[1023];
char strHeaders[1023];
char strPopup[1023];
char str[1024];
char command[1024] = "echo Welcome to EurekaRom";
char decodedCommand[1024];
char *data;
char *token;
char *headers;
char *page = NULL;
const char *key, *value;
char *postBuffer = NULL;
int postRead;
unsigned int postLen;
char postData[4096];
char * queryString;
char query_action[1024];
char query_section[1024];
char query_field[1024];
char query_value[1024];
data = malloc(QS_LEN);
token = malloc(QS_LEN);
key = malloc(QS_LEN);
value = malloc(QS_LEN);
//Operations if POST detected
if(compStr(getenv("REQUEST_METHOD"), "POST", sizearray(getenv("REQUEST_METHOD"))))
{
if (getenv("QUERY_STRING"))
{
token = strtok (getenv("QUERY_STRING"),"&");
while (token != NULL)
{
sscanf(token, "%[^=]=%65536s", key, value);
if ( compStr(key, "page", sizearray(key) ))
{
strcpy(strPage, value);
}
token = strtok (NULL, "&");
}
}
postRead = getline(&postBuffer, &postLen, stdin);
if (-1 != postRead)
{
strcpy(postData, postBuffer);
}
if (compStr(strPage, "debug", sizearray(strPage) ))
{
sscanf(postData, "page=debug&command=%[^,]", command);
urldecode2(decodedCommand, command);
web_module_headers(strPage);
web_module_debug(decodedCommand);
web_module_footer();
}
if (compStr(strPage, "settings", sizearray(strPage) ))
{
processPostData(postData);
web_module_headers(strPage);
web_module_settings();
web_module_footer();
}
free(postBuffer);
}
else
{
if (!getenv("QUERY_STRING"))
{
//no query string
web_module_headers("home");
web_module_home();
}
if (getenv("QUERY_STRING"))
{
//parse Query_STRING for page
//query string present
token = strtok (getenv("QUERY_STRING"),"&");
while (token != NULL)
{
sscanf(token, "%[^=]=%65536s", key, value);
if ( compStr(key, "page", sizearray(key) ))
{
strcpy(strPage, value);
}
if ( compStr(key, "headers", sizearray(key) ))
{
strcpy(strHeaders, value);
}
if ( compStr(key, "footers", sizearray(key) ))
{
strcpy(strFooters, value);
}
if ( compStr(key, "popup", sizearray(key) ))
{
strcpy(strPopup, value);
}
token = strtok (NULL, "&");
}
// Call this before headers
if ( compStr(strPage, "dumpstate", sizearray(strPage) ))
{
dumpstate();
exit(0);
}
//check for which page to load
if ( compStr(strHeaders, "0", sizearray(strHeaders) ))
{
}
else
{
web_module_headers(strPage);
}
if ( compStr(strPopup, "1", sizearray(strHeaders) ))
{
web_module_popup_headers(strPage);
}
if ( compStr(strPage, "home", sizearray(strPage) ))
{
web_module_home();
}
if ( compStr(strPage, "logcat", sizearray(strPage) ))
{
web_module_logcat();
}
if ( compStr(strPage, "forceeurekaupdate", sizearray(strPage) ))
{
forceeurekaupdate();
}
if ( compStr(strPage, "debug", sizearray(strPage) ))
{
web_module_debug(command);
}
if ( compStr(strPage, "settings", sizearray(strPage) ))
{
web_module_settings();
}
if ( compStr(strPage, "status", sizearray(strPage) ))
{
web_module_status();
}
if ( compStr(strPage, "companion", sizearray(strPage) ))
{
web_module_companion();
}
if ( compStr(strPage, "aboutus", sizearray(strPage) ))
{
web_module_aboutus();
}
if ( compStr(strPage, "Reboot", sizearray(strPage) ))
{
reboot();
}
if ( compStr(strPage, "sysupdate", sizearray(strPage) ))
{
sysupdate();
}
if ( compStr(strPage, "factorydatareset", sizearray(strPage) ))
{
factorydatareset();
}
if ( compStr(strFooters, "0", sizearray(strFooters) ))
{
}
else
{
web_module_footer();
}
}
}
}