source: branches/monitor-improvement/oscam-http.h@ 1024

Last change on this file since 1024 was 1024, checked in by alno, 13 years ago

WebIF:
changelog:

  • templates can be loaded from hdd now (httptpl to set the path). if the file does not exist on disk, a default one is used
  • furthermore you can save them to hdd by calling savetemplates.html
  • other change: moved mapping of templates to header file
File size: 15.3 KB
Line 
1#include "globals.h"
2
3#define SERVER "webserver/1.0"
4#define PROTOCOL "HTTP/1.0"
5#define RFC1123FMT "%a, %d %b %Y %H:%M:%S GMT"
6#define AUTHREALM "OScam"
7#define AUTHNONCEVALIDSECS 15
8#define MAXGETPARAMS 100
9
10#define CSS "p {color: white; }\n\
11h2 {color: orange; font-family: Arial; font-size: 14px; line-height: 12px;}\n\
12h4 {color: black; font-family: Arial; font-size: 12px; line-height: 9px; }\n\
13TABLE{background-color:#66CCFF;}\n\
14TD{height:10px; border:1px solid gray; font-family: Arial; font-size: 11px; padding:5px; background-color:#6666FF;}\n\
15TH{height:10px; border:1px solid gray; font-family: Arial; font-size: 12px; padding:5px; background-color:#330033;color:#FFFF00;}\n\
16TR.s TD{background-color:#6666FF;}\n\
17TR.r TD{background-color:orange;}\n\
18TR.p TD{background-color:yellow;}\n\
19TR.c TD{background-color:green;}\n\
20TR.online TD{background-color:#009900;}\n\
21TR.expired TD{background-color:orange;}\n\
22DIV.log{border:1px solid black;background-color: black; font-family:\"Courier New\", monospace ; color:yellow; font-size: 11px;}\n\
23TABLE.menu{background-color:black; align:center; font-size: 10px;}\n\
24TABLE.menu TD{border:2px outset lightgrey; background-color:silver; font-color:black; font-family: Arial;}\n\
25TABLE.status{background-color:#66CCFF;empty-cells:show;}\n\
26TABLE.invisible TD {border:0px; font-family: Arial; font-size: 12px; padding:5px; background-color:#6666FF;}}\n\
27TD.menu {border:2px outset lightgrey; background-color:silver; font-color:black; font-family: Arial; font-size:11px;}\n\
28body {background-color: grey; font-family: Arial; font-size: 12px;}\n\
29A:link {text-decoration: none; color:blue}\n\
30A:visited {text-decoration: none; color:blue}\n\
31A:active {text-decoration: none; color:white}\n\
32A:hover {text-decoration: none; color: red;}"
33
34#define TPLHEADER "\
35<HTML>\n\
36 <HEAD>\n\
37 <TITLE>OSCAM ##CS_VERSION## build ###CS_SVN_VERSION##</TITLE>\n\
38 <link rel=\"stylesheet\" type=\"text/css\" href=\"site.css\">\n\
39 ##REFRESH##\
40 </HEAD>\n\
41 <BODY>\n\
42 <H2>OSCAM ##CS_VERSION## build ###CS_SVN_VERSION##</H2>"
43
44#define TPLFOOTER "\
45 <HR/><H4>OSCAM Webinterface - ##CURDATE## ##CURTIME##</H4>\
46 </BODY>\
47</HTML>"
48
49#define TPLREFRESH "\
50<meta http-equiv=\"refresh\" content=\"##REFRESHTIME##\"; URL=/status.html\" />\n"
51
52#define TPLMENU "\
53 <TABLE border=0 class=\"menu\">\n\
54 <TR>\n\
55 <TD CLASS=\"menu\"><A HREF=\"status.html\">STATUS</TD>\n\
56 <TD CLASS=\"menu\"><A HREF=\"config.html\">CONFIGURATION</TD>\n\
57 <TD CLASS=\"menu\"><A HREF=\"readers.html\">READERS</TD>\n\
58 <TD CLASS=\"menu\"><A HREF=\"userconfig.html\">USERS</TD>\n\
59 <TD CLASS=\"menu\"><A HREF=\"services.html\">SERVICES</TD>\n\
60 </TR>\n\
61 </TABLE>"
62
63#define TPLSTATUS "\
64 ##TPLHEADER##\
65 ##TPLMENU##\n\
66 <BR><BR>\n\
67 <TABLE WIDTH=\"100%\" cellspacing=\"0\" class=\"status\">\n\
68 <TR>\n\
69 <TH>PID</TH>\n\
70 <TH>Typ</TH>\n\
71 <TH>ID</TH>\n\
72 <TH>Label</TH>\n\
73 <TH>AU</TH>\n\
74 <TH>0</TH>\n\
75 <TH>Address</TH>\n\
76 <TH>Port</TH>\n\
77 <TH>Protocol</TH>\n\
78 <TH>Login</TH>\n\
79 <TH>Login</TH>\n\
80 <TH>Time</TH>\n\
81 <TH>caid:srvid</TH>\n\
82 <TH>Last Channel</TH>\n\
83 <TH>Idle</TH>\n\
84 <TH>CWOK</TH>\n\
85 <TH>CWNOK</TH>\n\
86 <TH>0</TH>\n\
87 </TR>\n\
88 ##CLIENTSTATUS##\
89 </TABLE><BR>\n\
90 <DIV class=\"log\">\n\
91 ##LOGHISTORY##\
92 </DIV>\n\
93 ##TPLFOOTER##"
94
95#define TPLCLIENTSTATUSBIT "\
96 <TR class=\"##CLIENTTYPE##\">\n\
97 <TD>##CLIENTPID##</TD>\n\
98 <TD>##CLIENTTYPE##</TD>\n\
99 <TD>##CLIENTCNR##</TD>\n\
100 <TD>##CLIENTUSER##</TD>\n\
101 <TD>##CLIENTCAU##</TD>\n\
102 <TD>##CLIENTCRYPTED##</TD>\n\
103 <TD>##CLIENTIP##</TD>\n\
104 <TD>##CLIENTPORT##</TD>\n\
105 <TD>##CLIENTPROTO##</TD>\n\
106 <TD>##CLIENTLOGINDATE##</TD>\n\
107 <TD>##CLIENTLOGINTIME##</TD>\n\
108 <TD>##CLIENTLOGINSECS##</TD>\n\
109 <TD>##CLIENTCAID##:##CLIENTSRVID##</TD>\n\
110 <TD>##CLIENTSRVNAME##</TD>\n\
111 <TD>##CLIENTIDLESECS##</TD>\n\
112 <TD>##CWOK##</TD>\n\
113 <TD>##CWNOK##</TD>\n\
114 <TD>##CLIENTCON##</TD>\n\
115 </TR>\n"
116
117#define TPLUSERCONFIGLIST "\
118 ##TPLHEADER##\
119 ##TPLMENU##\n\
120 ##MESSAGE##\
121 <BR><BR>\
122 <TABLE cellspacing=\"0\" cellpadding=\"10\">\n\
123 <TR>\n\
124 <TH>Label</TH>\n\
125 <TH>Status</TH>\n\
126 <TH>Last Channel</TH>\n\
127 <TH>Idle (Sec)</TH>\n\
128 <TH colspan=\"2\" align=\"center\">Action</TH>\n\
129 </TR>\n\
130 ##USERCONFIGS##\
131 <TR>\n\
132 <FORM action=\"user_edit.html\" method=\"get\">\n\
133 <TD>New User:</TD>\n\
134 <TD colspan=\"2\"><input name=\"user\" type=\"text\"></TD>\n\
135 <TD colspan=\"3\" align=\"center\"><input type=\"submit\" value=\"Add User\"></TD>\n\
136 </FORM>\n\
137 <TR>\n\
138 </TABLE>\n\
139 ##TPLFOOTER##"
140
141#define TPLUSERCONFIGLISTBIT "\
142 <TR class=\"##CLASSNAME##\">\n\
143 <TD>##USER##</TD>\n\
144 <TD>##STATUS####EXPIRED##</TD>\n\
145 <TD>##LASTCHANNEL##</TD>\n\
146 <TD>##IDLESECS##</TD>\n\
147 <TD><A HREF=\"user_edit.html?user=##USERENC##\">Edit Settings</A></TD>\n\
148 <TD><A HREF=\"userconfig.html?user=##USERENC##&action=delete\">Delete User</A></TD>\n\
149 </TR>\n"
150
151#define TPLUSEREDIT "\
152##TPLHEADER##\
153##TPLMENU##\n\
154##MESSAGE##\
155<BR><BR>\n\
156 <form action=\"user_edit.html\" method=\"get\">\n\
157 <input name=\"user\" type=\"hidden\" value=\"##USERNAME##\">\n\
158 <input name=\"action\" type=\"hidden\" value=\"execute\">\n\
159 <TABLE cellspacing=\"0\">\n\
160 <TR>\n\
161 <TH>&nbsp;</TH>\n\
162 <TH>Edit User ##USERNAME##</TH>\n\
163 <TR>\n\
164 <TD>Password:</TD>\n\
165 <TD><input name=\"pwd\" type=\"text\" size=\"30\" maxlength=\"30\" value=\"##PASSWORD##\"></TD>\n\
166 </TR>\n\
167 <TR>\n\
168 <TD>Exp. Date:</TD>\n\
169 <TD><input name=\"expdate\" type=\"text\" size=\"30\" maxlength=\"30\" value=\"##EXPDATE##\"></TD>\n\
170 </TR>\n\
171 <TR>\n\
172 <TD>Group:</TD>\n\
173 <TD><input name=\"group\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"##GROUPS##\"></TD>\n\
174 </TR>\n\
175 <TR>\n\
176 <TD>Hostname:</TD>\n\
177 <TD><input name=\"hostname\" type=\"text\" size=\"30\" maxlength=\"30\" value=\"##DYNDNS##\"></TD>\n\
178 </TR>\n\
179 <TR>\n\
180 <TD>Uniq:</TD>\n\
181 <TD><select name=\"uniq\">\n\
182 <option value=\"0\" ##UNIQSELECTED0##>none</option>\n\
183 <option value=\"1\" ##UNIQSELECTED1##>strict</option>\n\
184 <option value=\"2\" ##UNIQSELECTED2##>per IP</option>\n\
185 </SELECT></TD>\n\
186 </TR>\n\
187 <TR>\n\
188 <TD>Sleep:</TD>\n\
189 <TD><input name=\"sleep\" type=\"text\" size=\"4\" maxlength=\"4\" value=\"0\"></TD>\n\
190 </TR>\n\
191 <TR>\n\
192 <TD>Monlevel:</TD>\n\
193 <TD><select name=\"monlevel\">\n\
194 <option value=\"0\" ##MONSELECTED0##>no access to monitor</option>\n\
195 <option value=\"1\" ##MONSELECTED1##>only server and own procs</option>\n\
196 <option value=\"2\" ##MONSELECTED2##>all procs, but viewing only, default</option>\n\
197 <option value=\"3\" ##MONSELECTED3##>all procs, reload of oscam.user possible</option>\n\
198 <option value=\"4\" ##MONSELECTED4##>complete access</option>\n\
199 </select></TD>\n\
200 </TR>\n\
201 <TR>\n\
202 <TD>AU:</TD>\n\
203 <TD><select name=\"au\">\n\
204 <option value=\" \" ##AUSELECTED##>none</option>\n\
205 <option value=\"1\" ##AUTOAUSELECTED##>auto</option>\n\
206 ##RDROPTION##\
207 </select></TD>\n\
208 </TR>\n\
209 <TR>\n\
210 <TD>Services:</TD>\n\
211 <TD>\n\
212 <TABLE cellspacing=\"0\" class=\"invisible\">##SIDS##\
213 </TD>\n\
214 </TR>\n\
215 </TABLE>\n\
216 <TR>\n\
217 <TD>CAID:</TD>\n\
218 <TD><input name=\"caid\" type=\"text\" size=\"50\" maxlength=\"50\" value=\"##CAIDS##\"></TD>\n\
219 </TR>\n\
220 <TR>\n\
221 <TD>Ident:</TD>\n\
222 <TD><input name=\"ident\" type=\"text\" size=\"50\" maxlength=\"50\" value=\"##IDENTS##\"></TD>\n\
223 </TR>\n\
224 <TR>\n\
225 <TD>Betatunnel:</TD>\n\
226 <TD><input name=\"betatunnel\" type=\"text\" size=\"50\" maxlength=\"50\" value=\"##BETATUNNELS##\"></TD>\n\
227 </TR>\n\
228 ##TPLUSEREDITANTICASC##\
229 <TR>\n\
230 <TD>&nbsp;</TD>\n\
231 <TD align=\"right\"><input type=\"submit\" value=\"Save Settings\" title=\"Save settings and reload users\"></TD>\n\
232 </TR>\n\
233 </TABLE>\n\
234</form>\n\
235##TPLFOOTER##"
236
237#define TPLUSEREDITRDRSELECTED "\t<option value=\"##READERNAME##\" ##SELECTED##>##READERNAME##</option>"
238
239#define TPLUSEREDITSIDOKBIT "\
240 <TR>\n\
241 <TD><INPUT NAME=\"services\" TYPE=\"CHECKBOX\" VALUE=\"##SIDLABEL##\" ##CHECKED##> ##SIDLABEL##</TD>\n"
242
243#define TPLUSEREDITSIDNOBIT "\
244 <TD><INPUT NAME=\"services\" TYPE=\"CHECKBOX\" VALUE=\"!##SIDLABEL##\" ##CHECKED##> !##SIDLABEL##</TD>\n\
245 </TR>\n"
246
247#ifdef CS_ANTICASC
248# define TPLUSEREDITANTICASC "\
249 <TR>\n\
250 <TD>Anticascading numusers:</TD>\n\
251 <TD><input name=\"numusers\" type=\"text\" size=\"3\" maxlength=\"3\" value=\"##AC_USERS##\"></TD>\n\
252 </TR>\n\
253 <TR>\n\
254 <TD>Anticascading penalty:</TD>\n\
255 <TD><input name=\"penalty\" type=\"text\" size=\"3\" maxlength=\"3\" value=\"##AC_PENALTY##\"></TD>\n\
256 </TR>\n"
257#endif
258
259#define TPLSIDTAB "\
260 ##TPLHEADER##\
261 ##TPLMENU##\n\
262 <BR><BR><DIV class=\"log\">\n\
263 ##SIDTABS##\
264 </DIV>\n\
265 ##TPLFOOTER##"
266
267#define TPLSIDTABBIT "\
268label=##LABEL##<BR>\n\
269caid(##CAIDNUM##)=##CAIDS##<BR>\n\
270provider(##PROVIDNUM##)=##PROVIDS##<BR>\n\
271services(##SRVIDNUM##)=##SRVIDS##<BR><BR>\n"
272
273#define TPLREADERS "\
274##TPLHEADER##\
275##TPLMENU##\n\
276<BR><BR>\n\
277 <TABLE cellspacing=\"0\" cellpadding=\"10\">\n\
278 <TR>\n\
279 <TH>Reader</TH>\n\
280 <TH>Protocol</TH>\n\
281 <TH>Action</TH>\n\
282 </TR>\n\
283 ##READERLIST##\
284 </TABLE>\n\
285##TPLFOOTER##"
286
287#define TPLREADERSBIT "\
288 <TR>\n\
289 <TD>##READERNAME##</TD>\n\
290 <TD>##CTYP##</TD>\n\
291 <TD><A HREF=\"readerconfig.html?reader=##READERNAMEENC##\">Edit Settings</A> &nbsp;|&nbsp; <A HREF=\"entitlements.html?reader=##READERNAME##\">Show Entitlements</A></TD>\n\
292 </TR>\n"
293
294#define TPLENTITLEMENTS "\
295##TPLHEADER##\
296##TPLMENU##\n\
297<BR><BR>Entitlements for ##READERNAME##<BR><BR>\n\n\
298<DIV class=\"log\">\n\
299 ##LOGHISTORY##\
300</DIV>\n\
301##TPLFOOTER##"
302
303#define TPLREADERCONFIG "\
304##TPLHEADER##\
305##TPLMENU##\n\
306<BR><BR>\n\
307##MESSAGE##\
308 <form action=\"readerconfig.html?action=execute\" method=\"get\"><input name=\"reader\" type=\"hidden\" value=\"##READERNAME##\">\n\
309 <TABLE cellspacing=\"0\">\n\
310 <TR>\n\
311 <TH>&nbsp;</TH>\n\
312 <TH>Edit Reader ##READERNAME##</TH>\n\
313 </TR>\n\
314 <TR>\n\
315 <TD>Device:</TD>\n\
316 <TD><input name=\"device\" type=\"text\" size=\"30\" maxlength=\"50\" value=\"##DEVICE####R_PORT####L_PORT##\"></TD>\n\
317 </TR>\n\
318 <TR>\n\
319 <TD>Group:</TD>\n\
320 <TD><input name=\"grp\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"##GRP##\"></TD>\n\
321 </TR>\n\
322 <TR>\n\
323 <TD>Key:</TD>\n\
324 <TD><input name=\"key\" type=\"text\" size=\"30\" maxlength=\"50\" value=\"##NCD_KEY##\"></TD>\n\
325 </TR>\n\
326 <TR>\n\
327 <TD>Pincode:</TD>\n\
328 <TD><input name=\"pincode\" type=\"text\" size=\"30\" maxlength=\"50\" value=\"##PINCODE##\"></TD>\n\
329 </TR>\n\
330 <TR>\n\
331 <TD>Readnano:</TD>\n\
332 <TD><input name=\"readnano\" type=\"text\" size=\"30\" maxlength=\"50\" value=\"##EMMFILE##\"></TD>\n\
333 </TR>\n\
334 <TR>\n\
335 <TD>Services:</TD>\n\
336 <TD>\n\
337 <TABLE cellspacing=\"0\" class=\"invisible\">##SIDS##\
338 </TD>\n\
339 </TR>\n\
340 </TABLE>\n\
341 <TR>\n\
342 <TD>Inactivitytimeout:</TD>\n\
343 <TD><input name=\"inactivitytimeout\" type=\"text\" size=\"30\" maxlength=\"50\" value=\"##INACTIVITYTIMEOUT##\"></TD>\n\
344 </TR>\n\
345 <TR>\n\
346 <TD>Reconnecttimeout:</TD>\n\
347 <TD><input name=\"reconnecttimeout\" type=\"text\" size=\"30\" maxlength=\"50\" value=\"##RECEIVETIMEOUT##\"></TD>\n\
348 </TR>\n\
349 <TR>\n\
350 <TD>Disableserverfilter:</TD>\n\
351 <TD><input name=\"disableserverfilter\" type=\"text\" size=\"30\" maxlength=\"50\" value=\"##DISABLESERVERFILTER##\"></TD>\n\
352 </TR>\n\
353 <TR>\n\
354 <TD>Fallback:</TD>\n\
355 <TD><input name=\"fallback\" type=\"text\" size=\"3\" maxlength=\"3\" value=\"##FALLBACK##\"></TD>\n\
356 </TR>\n\
357 <TR>\n\
358 <TD>CAID:</TD>\n\
359 <TD><input name=\"caid\" type=\"text\" size=\"50\" maxlength=\"50\" value=\"##CAIDS##\"></TD>\n\
360 </TR>\n\
361 <TR>\n\
362 <TD>Boxid:</TD>\n\
363 <TD><input name=\"boxid\" type=\"text\" size=\"30\" maxlength=\"50\" value=\"##BOXID##\"></TD>\n\
364 </TR>\n\
365 </TABLE>\n\
366 <input type=\"submit\" value=\"OK\"></form>\n\
367<BR><BR>Saving not yet implemented - Nothing changes on click<BR><BR>\n\
368##TPLFOOTER##"
369#define TPLSAVETEMPLATES "##TPLHEADER##\
370##TPLMENU##\n\
371<br><b>Saved ##CNT## templates to ##PATH##</b><br>\n\
372##TPLFOOTER##"
373#define TPLREADERCONFIGSIDOKBIT "\
374 <TR>\n\
375 <TD><INPUT NAME=\"services\" TYPE=\"CHECKBOX\" VALUE=\"##SIDLABEL##\" ##CHECKED##> ##SIDLABEL##</TD>\n"
376
377#define TPLREADERCONFIGSIDNOBIT "\
378 <TD><INPUT NAME=\"services\" TYPE=\"CHECKBOX\" VALUE=\"!##SIDLABEL##\" ##CHECKED##> !##SIDLABEL##</TD>\n\
379 </TR>\n"
380
381enum refreshtypes {REFR_ACCOUNTS, REFR_READERS, REFR_SERVER, REFR_ANTICASC};
382
383char *tpl[]={
384 "HEADER",
385 "FOOTER",
386 "MENU",
387 "REFRESH",
388 "STATUS",
389 "CLIENTSTATUSBIT",
390 "USERCONFIGLIST",
391 "USERCONFIGLISTBIT",
392 "SIDTAB",
393 "SIDTABBIT",
394 "READERS",
395 "READERSBIT",
396 "ENTITLEMENTS",
397 "READERCONFIG",
398 "READERCONFIGSIDOKBIT",
399 "READERCONFIGSIDNOBIT",
400 "USEREDIT",
401 "USEREDITRDRSELECTED",
402 "USEREDITSIDOKBIT",
403 "USEREDITSIDNOBIT",
404 "SAVETEMPLATES"
405#ifdef CS_ANTICASC
406 ,"USEREDITANTICASC"
407#endif
408};
409
410char *tplmap[]={
411 TPLHEADER,
412 TPLFOOTER,
413 TPLMENU,
414 TPLREFRESH,
415 TPLSTATUS,
416 TPLCLIENTSTATUSBIT,
417 TPLUSERCONFIGLIST,
418 TPLUSERCONFIGLISTBIT,
419 TPLSIDTAB,
420 TPLSIDTABBIT,
421 TPLREADERS,
422 TPLREADERSBIT,
423 TPLENTITLEMENTS,
424 TPLREADERCONFIG,
425 TPLREADERCONFIGSIDOKBIT,
426 TPLREADERCONFIGSIDNOBIT,
427 TPLUSEREDIT,
428 TPLUSEREDITRDRSELECTED,
429 TPLUSEREDITSIDOKBIT,
430 TPLUSEREDITSIDNOBIT,
431 TPLSAVETEMPLATES
432#ifdef CS_ANTICASC
433 ,TPLUSEREDITANTICASC
434#endif
435};
436
437struct templatevars {
438 int varscnt;
439 int varsalloc;
440 int tmpcnt;
441 int tmpalloc;
442 char **names;
443 char **values;
444 char **tmp;
445};
446
447struct uriparams {
448 int paramcount;
449 char *params[MAXGETPARAMS];
450 char *values[MAXGETPARAMS];
451};
452
453static char hex2ascii[256][2];
454static char noncekey[33];
455
456
457char *tpl_addVar(struct templatevars *vars, int append, char *name, char *value);
458char *tpl_addTmp(struct templatevars *vars, char *value);
459char *tpl_printf(struct templatevars *vars, int append, char *varname, char *fmtstring, ...);
460char *tpl_getVar(struct templatevars *vars, char *name);
461struct templatevars *tpl_create();
462void tpl_clear(struct templatevars *vars);
463char *tpl_getUnparsedTpl(const char* name);
464char *tpl_getTpl(struct templatevars *vars, const char* name);
465char *parse_auth_value(char *value);
466void calculate_nonce(char *result, int resultlen);
467int check_auth(char *authstring, char *method, char *path, char *expectednonce);
468void send_headers(FILE *f, int status, char *title, char *extra, char *mime);
469void send_htmlhead(FILE *f, int refresh);
470void send_css(FILE *f);
471void send_footer(FILE *f);
472void send_oscam_menu(FILE *f);
473char *getParam(struct uriparams *params, char *name);
474int tpl_saveIncludedTpls(const char *path);
Note: See TracBrowser for help on using the repository browser.