Mostly minor fixes up until version 0.8.10.
[irreco.git] / irtrans / irserver / src / webserver.c
blob739a07afbc5c4574072ed58356c0befb640826fd
1 /*
2 * Copyright (c) 2007, IRTrans GmbH
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of IRTrans GmbH nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY IRTrans GmbH ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL IRTrans GmbH BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifdef WIN32
32 #include <winsock2.h>
33 #include <windows.h>
34 #include <io.h>
35 #include <direct.h>
37 #define MSG_NOSIGNAL 0
38 #endif
40 #ifdef WINCE
42 #include <winsock2.h>
43 #include <windows.h>
45 #define MSG_NOSIGNAL 0
46 #endif
48 #ifdef LINUX
49 #include <sys/types.h>
50 #include <sys/socket.h>
51 #include <netinet/in.h>
52 #include <sys/un.h>
53 #include <arpa/inet.h>
54 #include <dirent.h>
55 #include <sys/stat.h>
56 #include <errno.h>
57 #include <fcntl.h>
58 #include <signal.h>
59 #include <stdint.h>
61 typedef int SOCKET;
62 typedef int DWORD;
63 typedef int WSAEVENT;
64 #define closesocket close
65 extern int hCom;
67 SOCKET local_socket;
69 #define LIRCD "/dev/lircd"
70 #define PERMISSIONS 0666
73 #endif
76 #include <stdio.h>
77 #include <time.h>
80 #include "pictures.h"
81 #include "webserver.h"
82 #include "remote.h"
83 #include "network.h"
84 #include "errcode.h"
85 #include "dbstruct.h"
86 #include "global.h"
87 #include "server.h"
88 #include "lowlevel.h"
89 #include "fileio.h"
92 #ifdef WIN32
93 extern WSAEVENT WebEvent;
94 #endif
98 void ProcessWebRequest (SOCKET sock)
100 int res;
101 char data[2048];
102 SOCKET call;
103 int clilen;
104 unsigned int adr;
105 struct sockaddr_in cli_addr;
107 clilen = sizeof (cli_addr);
109 call = accept (sock,(struct sockaddr *)&cli_addr,&clilen);
111 #ifdef WIN32
112 adr = ntohl (cli_addr.sin_addr.S_un.S_addr);
113 #else
114 adr = ntohl (cli_addr.sin_addr.s_addr);
115 #endif
116 if (adr != 0x7f000001) {
117 for (res=0;res < netcount;res++) {
118 if ((netip[res] & netmask[res]) == (adr & netmask[res])) break;
120 if (netcount && res == netcount) {
121 sprintf (data,"Error: IP Address %s not allowed (Access rights).\n",inet_ntoa (cli_addr.sin_addr));
122 log_print (data,LOG_ERROR);
123 shutdown (call,2);
124 closesocket (call);
125 return;
129 #ifdef WIN32
130 res = 0;
131 WSAEventSelect (call,WebEvent,0);
132 ioctlsocket (call,FIONBIO,&res);
133 #endif
135 res = recv (call,data,2048,MSG_NOSIGNAL);
137 data[res] = 0;
139 ParseRequest (data,call);
144 void ParseRequest (char* data,SOCKET sock)
146 char mem[65536];
147 int len;
149 if (!strncmp (data,"GET ",4)) {
150 len = GetHtmlPage (mem,data + 4);
151 send (sock,mem,len,0);
152 closesocket (sock);
157 int GetHtmlPage (char *mem,char *page)
159 int i = 0;
160 char content[65536];
161 char parm[2050];
162 char value[2050];
163 char lang[10];
165 while (page[i] > ' ') i++;
166 page[i] = 0;
168 *parm = 0;
169 for (i=0;page[i] && page[i] != '?';i++);
170 if (page[i] == '?') {
171 page[i++] = 0;
172 page[i + 2048] = 0;
173 strcpy (parm,page + i);
176 GetHtmlParameter (parm,"lang",value);
177 value[8] = 0;
178 strcpy (lang,value);
180 if (*lang == 0) strcpy (lang,"EN");
182 printf ("%s\n",page);
184 if (!strcmp (page,"/") || !strcmp (page,"/index.htm") || !strcmp (page,"/index.html")) {
185 GetIndexPage (content,lang);
186 GenerateHtmlHeader (mem,content);
187 return ((int)strlen (mem));
189 if (!strcmp (page,"/DeviceList.htm")) {
190 GetDevicesPage (content,lang,NULL);
191 GenerateHtmlHeader (mem,content);
192 return ((int)strlen (mem));
194 if (!strcmp (page,"/DeviceConfig.htm")) {
195 GetHtmlParameter (parm,"id",value);
196 i = atoi (value);
197 if (i < 0 || i > 15) i = 0;
198 GetDeviceConfigPage (content,lang,i);
199 GenerateHtmlHeader (mem,content);
200 return ((int)strlen (mem));
202 if (!strcmp (page,"/SetConfig.htm")) {
203 GetDevicesPage (content,lang,parm);
204 GenerateHtmlHeader (mem,content);
205 return ((int)strlen (mem));
208 if (!strcmp (page,"/Send.htm")) {
209 GetSendPage (content,lang,parm);
210 GenerateHtmlHeader (mem,content);
211 return ((int)strlen (mem));
214 if (!strcmp (page,"/IRTransLogo.gif")) return (GenerateImageHeader (mem,irtrans_logo,"gif",sizeof (irtrans_logo)));
215 if (!strcmp (page,"/OKButton.gif")) return (GenerateImageHeader (mem,ok_button,"gif",sizeof (ok_button)));
216 if (!strcmp (page,"/GoButton.gif")) return (GenerateImageHeader (mem,go_button,"gif",sizeof (go_button)));
217 if (!strcmp (page,"/English.jpg")) return (GenerateImageHeader (mem,england_logo,"jpeg",sizeof (england_logo)));
218 if (!strcmp (page,"/Deutsch.jpg")) return (GenerateImageHeader (mem,deutschland_logo,"jpeg",sizeof (deutschland_logo)));
219 if (!strcmp (page,"/BackButton.gif")) return (GenerateImageHeader (mem,back_button,"gif",sizeof (back_button)));
221 GenerateErrorPage (mem,404);
222 return ((int)strlen (mem));
227 void GetHtmlParameter (char *pnt,char *name,char *value)
229 char parm[2050];
230 int i = 0,j;
231 *value = 0;
232 strcpy (parm,pnt);
233 while (parm[i]) {
234 j = i;
235 while (parm[i] && parm[i] != '=' && parm[i] != '?' && parm[i] != '&') i++;
236 if (!parm[i]) return;
237 if (parm[i] == '=') {
238 parm[i++] = 0;
239 if (!strcmp (name,parm+j)) {
240 j = i;
241 while (parm[i] && parm[i] != '?' && parm[i] != '&') i++;
242 parm[i] = 0;
243 strcpy (value,parm+j);
245 while (parm[i] && parm[i] != '?' && parm[i] != '&') i++;
247 if (parm[i] == '?' || parm[i] == '&') i++;
252 void GetSendPage (char *mem,char *lang,char *parm)
254 int res,mask,setres = 0;
255 int cmd_num;
256 char err[1000];
257 char value[1000];
258 char ln[1000];
259 char remote[100],command[100];
260 STATUSBUFFER stat;
261 NETWORKSTATUS *ns;
263 strcpy (mem,"<HTML><HEAD><TITLE>IRTrans Send Command</TITLE></HEAD><BODY bgcolor=\"#C0C0C0\">");
264 strcat (mem,"<table width=\"80%\"><tr><td align = \"center\">");
265 strcat (mem,"<IMG src=\"IRTransLogo.gif\" align = \"center\">");
266 strcat (mem,"</td><td width=\"40\">&nbsp</td><td align = \"center\"><font face=\"Verdana\" size=\"4\">IRTrans Send Command</font></td><td>");
267 sprintf (ln,"<a href=\"index.htm?lang=%s\">",lang);
268 strcat (mem,ln);
269 strcat (mem,"<IMG src=\"BackButton.gif\" align = \"center\" border=\"0\"></a></td></tr></table><hr><br>");
271 if (parm) {
272 mask = 0;
273 GetHtmlParameter (parm,"remote",remote);
274 GetHtmlParameter (parm,"command",command);
275 GetHtmlParameter (parm,"sendmask",value);
276 sscanf (value,"%x",&mask);
277 if (*remote && *command) {
278 res = DBFindRemoteCommand (remote,command,&cmd_num,NULL);
279 if (res) {
280 ns = (NETWORKSTATUS *)&stat;
281 PutNetworkStatus (res,NULL,&stat);
282 strcpy (err,ns->message);
283 if (res == ERR_REMOTENOTFOUND) sprintf (ns->message,err,remote);
284 if (res == ERR_COMMANDNOTFOUND) sprintf (ns->message,err,command);
285 strcat (mem,"<p align=\"center\"><font face=\"Verdana\" size=\"4\">");
286 strcat (mem,ns->message);
287 strcat (mem,"</p></font>");
289 else {
290 if (mask) mask = ((word)mask & 0xffff) | 0x10000;
291 SendIR (cmd_num,mask);
293 resend_flag = 0;
294 return;
300 void GetDeviceConfigPage (char *mem,char *lang,int id)
302 int res,i;
303 char ln[1000];
304 STATUSBUFFER buf;
305 NETWORKMODE *status;
308 strcpy (mem,"<HTML><HEAD><TITLE>IRTrans Device Status</TITLE></HEAD><BODY bgcolor=\"#C0C0C0\">");
309 strcat (mem,"<table width=\"80%\"><tr><td align = \"center\">");
310 strcat (mem,"<IMG src=\"IRTransLogo.gif\" align = \"center\">");
311 strcat (mem,"</td><td width=\"40\">&nbsp</td><td align = \"center\"><font face=\"Verdana\" size=\"4\">IRTrans Device Configuration</font></td><td>");
312 sprintf (ln,"<a href=\"DeviceList.htm?lang=%s\">",lang);
313 strcat (mem,ln);
314 strcat (mem,"<IMG src=\"BackButton.gif\" align = \"center\" border=\"0\"></a></td></tr></table><hr><br>");
316 res = GetDeviceStatus (&buf);
317 if (res) {
319 else {
320 status = (NETWORKMODE *)&buf;
323 strcat (mem,"<font face=\"Verdana\" size=\"3\"><table><tr><td width=\"20\">&nbsp;</td><td>");
324 sprintf (ln,"Configuring IRTrans Device ID %d:</td></tr>",id);
325 if (!strcmp (lang,"DE")) sprintf (ln,"IRTrans mit ID %d wird konfiguriert:</td></tr>",id);
326 strcat (mem,ln);
327 strcat (mem,"</table>");
328 strcat (mem,"<font face=\"Verdana\" size=\"3\"><form method=\"GET\" action=\"SetConfig.htm\"><table><tr><td width=\"20\">&nbsp;</td>");
329 strcat (mem,"<td>Target Mask</td></tr><tr><td width=\"20\">&nbsp;</td><td>");
330 sprintf (ln,"<input type=\"hidden\" value=\"%d\" name=\"id\">",id);
331 strcat (mem,ln);
332 for (i=0; i<=15; i++) {
333 if (status->stat[id].send_mask & (1 << i)) sprintf (ln,"<input type=\"checkbox\" name=\"TM%02d\" value=\"%d\" checked>%d",i,1<<i,i);
334 else sprintf (ln,"<input type=\"checkbox\" name=\"TM%02d\" value=\"%d\">%d",i,1<<i,i);
335 strcat (mem,ln);
337 strcat (mem,"</td></tr><tr><td>&nbsp;</td></tr>");
339 strcat (mem,"<tr><td width=\"20\">&nbsp;</td><td><table width=\"100%\"><tr><td>");
340 sprintf (ln,"<input type=\"checkbox\" name=\"DEVMODE_SEND\" value=\"%d\" %s>IR Send",DEVMODE_SEND,(status->stat[id].device_mode & DEVMODE_SEND ? "checked":""));
341 if (!strcmp (lang,"DE")) sprintf (ln,"<input type=\"checkbox\" name=\"SEND\" value=\"%d\" %s>IR Senden",DEVMODE_SEND,(status->stat[id].device_mode & DEVMODE_SEND ? "checked":""));
342 strcat (mem,ln);
343 strcat (mem,"</td>");
344 strcat (mem,"<td>");
345 sprintf (ln,"<input type=\"checkbox\" name=\"DEVMODE_IR\" value=\"%d\" %s>IR Receive",DEVMODE_IR,(status->stat[id].device_mode & DEVMODE_IR ? "checked":""));
346 if (!strcmp (lang,"DE")) sprintf (ln,"<input type=\"checkbox\" name=\"RECEIVE\" value=\"%d\" %s>IR Empfangen",DEVMODE_IR,(status->stat[id].device_mode & DEVMODE_IR ? "checked":""));
347 strcat (mem,ln);
348 strcat (mem,"</td></tr>");
350 strcat (mem,"<tr><td>");
351 sprintf (ln,"<input type=\"checkbox\" name=\"DEVMODE_REPEAT\" value=\"%d\" %s>Repeat Mode",DEVMODE_REPEAT,(status->stat[id].device_mode & DEVMODE_REPEAT ? "checked":""));
352 if (!strcmp (lang,"DE")) sprintf (ln,"<input type=\"checkbox\" name=\"REPEAT\" value=\"%d\" %s>Repeat Modus",DEVMODE_REPEAT,(status->stat[id].device_mode & DEVMODE_REPEAT ? "checked":""));
353 strcat (mem,ln);
354 strcat (mem,"</td>");
355 strcat (mem,"<td>");
356 sprintf (ln,"<input type=\"checkbox\" name=\"DEVMODE_SBUS\" value=\"%d\" %s>SBUS Active",DEVMODE_SBUS,(status->stat[id].device_mode & DEVMODE_SBUS ? "checked":""));
357 if (!strcmp (lang,"DE")) sprintf (ln,"<input type=\"checkbox\" name=\"SBUS\" value=\"%d\" %s>SBUS aktivieren",DEVMODE_SBUS,(status->stat[id].device_mode & DEVMODE_SBUS ? "checked":""));
358 strcat (mem,ln);
359 strcat (mem,"</td></tr>");
361 /* strcat (mem,"<tr><td>");
362 sprintf (ln,"<input type=\"checkbox\" name=\"DEVMODE_IRCODE\" value=\"%d\" %s>Remote Control IR",DEVMODE_IRCODE,(status->stat[id].device_mode & DEVMODE_IRCODE ? "checked":""));
363 if (!strcmp (lang,"DE")) sprintf (ln,"<input type=\"checkbox\" name=\"RCIR\" value=\"%d\" %s>PC &uumlber IR steuern",DEVMODE_IRCODE,(status->stat[id].device_mode & DEVMODE_IRCODE ? "checked":""));
364 strcat (mem,ln);
365 strcat (mem,"</td>");*/
366 strcat (mem,"<td>");
367 sprintf (ln,"<input type=\"checkbox\" name=\"DEVMODE_SBUSCODE\" value=\"%d\" %s>Remote Control SBUS",DEVMODE_SBUSCODE,(status->stat[id].device_mode & DEVMODE_SBUSCODE ? "checked":""));
368 if (!strcmp (lang,"DE")) sprintf (ln,"<input type=\"checkbox\" name=\"RCSBUS\" value=\"%d\" %s>PC &uumlber SBUS steuern",DEVMODE_SBUSCODE,(status->stat[id].device_mode & DEVMODE_SBUSCODE ? "checked":""));
369 strcat (mem,ln);
370 strcat (mem,"</td></tr>");
372 strcat (mem,"<tr><td>");
373 sprintf (ln,"<input type=\"checkbox\" name=\"DEVMODE_RAWFAST\" value=\"%d\" %s>Fast Control",DEVMODE_RAWFAST,(status->stat[id].device_mode & DEVMODE_RAWFAST ? "checked":""));
374 strcat (mem,ln);
375 strcat (mem,"</td>");
376 strcat (mem,"<td>");
377 sprintf (ln,"<input type=\"checkbox\" name=\"DEVMODE_RAW\" value=\"%d\" %s>RAW Mode",DEVMODE_RAW,(status->stat[id].device_mode & DEVMODE_RAW ? "checked":""));
378 if (!strcmp (lang,"DE")) sprintf (ln,"<input type=\"checkbox\" name=\"RAW\" value=\"%d\" %s>RAW Modus",DEVMODE_RAW,(status->stat[id].device_mode & DEVMODE_RAW ? "checked":""));
379 strcat (mem,ln);
380 strcat (mem,"</td></tr>");
382 strcat (mem,"<tr><td>");
383 sprintf (ln,"Hotremote&nbsp;&nbsp;<input type=\"text\" name=\"Remote\" value=\"%s\" size=\"20\">&nbsp;",status->stat[id].remote);
384 if (!strcmp (lang,"DE")) sprintf (ln,"PowerOn FB&nbsp;&nbsp;<input type=\"text\" name=\"Remote\" value=\"%s\" size=\"20\">&nbsp;",status->stat[id].remote);
385 strcat (mem,ln);
386 strcat (mem,"</td>");
387 strcat (mem,"<td>");
388 sprintf (ln,"Hotcommand&nbsp;&nbsp;<input type=\"text\" name=\"Command\" value=\"%s\" size=\"20\">",status->stat[id].command);
389 if (!strcmp (lang,"DE")) sprintf (ln,"PowerOn Befehl&nbsp;&nbsp;<input type=\"text\" name=\"Command\" value=\"%s\" size=\"20\">",status->stat[id].command);
390 strcat (mem,ln);
391 strcat (mem,"</td></tr>");
392 strcat (mem,"<tr><td>&nbsp");
393 strcat (mem,"</td></tr>");
394 strcat (mem,"<tr><td>&nbsp");
395 strcat (mem,"</td></tr>");
397 strcat (mem,"<tr><td align=\"center\">");
398 // strcat (mem,"<input type=\"submit\" value=\"Werte setzen\" name=\"SET\">");
399 strcat (mem,"</td>");
400 strcat (mem,"<td align=\"center\">");
401 // strcat (mem,"<input type=\"reset\">");
402 strcat (mem,"</td></tr>");
404 strcat (mem,"</table></td></tr>");
406 strcat (mem,"</table></form>");
410 strcat (mem,"<br><br><br><br>");
411 strcat (mem,"<p align=\"center\"><font face=\"Verdana\" size=\"3\">");
412 sprintf (ln,"IRServer %s (c) 2003 Marcus M&uumlller</font></p>",irserver_version);
413 strcat (mem,ln);
414 strcat (mem,"</BODY></HTML>");
419 void GetDevicesPage (char *mem,char *lang,char *parm)
421 int res,cnt,i,id,setres = 0;
422 word tm;
423 byte md;
424 char err[1000];
425 char nm[100];
426 char value[1000];
427 char ln[1000];
428 char remote[100],command[100];
429 STATUSBUFFER buf;
430 NETWORKMODE *status;
432 strcpy (mem,"<HTML><HEAD><TITLE>IRTrans Device Status</TITLE></HEAD><BODY bgcolor=\"#C0C0C0\">");
433 strcat (mem,"<table width=\"80%\"><tr><td align = \"center\">");
434 strcat (mem,"<IMG src=\"IRTransLogo.gif\" align = \"center\">");
435 strcat (mem,"</td><td width=\"40\">&nbsp</td><td align = \"center\"><font face=\"Verdana\" size=\"4\">IRTrans Device Status</font></td><td>");
436 sprintf (ln,"<a href=\"index.htm?lang=%s\">",lang);
437 strcat (mem,ln);
438 strcat (mem,"<IMG src=\"BackButton.gif\" align = \"center\" border=\"0\"></a></td></tr></table><hr><br>");
440 status = (NETWORKMODE *)&buf;
441 res = GetDeviceStatus (&buf);
443 if (res) {
445 else {
446 if (parm) {
447 GetHtmlParameter (parm,"id",value);
448 id = atoi (value);
449 if (*value == 0 || id < 0 || id > 15) {
450 setres = -1;
451 strcpy (err,"Can not set status: Illegal Device ID");
452 if (!strcmp (lang,"DE")) strcpy (err,"Status kann nicht gesetzt werden: Illegale Device ID");
454 else {
455 tm = 0;
456 for (i=0;i<=15;i++) {
457 sprintf (nm,"TM%02d",i);
458 GetHtmlParameter (parm,nm,value);
459 tm += atoi (value);
461 md = 0;
462 GetHtmlParameter (parm,"DEVMODE_SEND",value);
463 md += atoi (value);
464 GetHtmlParameter (parm,"DEVMODE_IR",value);
465 md += atoi (value);
466 GetHtmlParameter (parm,"DEVMODE_SBUS",value);
467 md += atoi (value);
468 GetHtmlParameter (parm,"DEVMODE_IRCODE",value);
469 md += atoi (value);
470 GetHtmlParameter (parm,"DEVMODE_SBUSCODE",value);
471 md += atoi (value);
472 GetHtmlParameter (parm,"DEVMODE_RAW",value);
473 md += atoi (value);
474 GetHtmlParameter (parm,"DEVMODE_RAWFAST",value);
475 md += atoi (value);
476 GetHtmlParameter (parm,"DEVMODE_REPEAT",value);
477 md += atoi (value);
478 GetHtmlParameter (parm,"Remote",remote);
479 GetHtmlParameter (parm,"Command",command);
481 res = GetHotcode (remote,command,value);
482 if (res == -1) {
483 GetError (ERR_HOTCODE,value);
484 sprintf (err,value,remote,command);
485 setres = -1;
487 else {
488 StoreSwitch ((word)id,0,remote,command,1);
489 WriteSwitches ();
490 res = SetTransceiverModusEx (0,md,tm,(byte)id,value,res,0xf,4,0,0,0); // !! Bus
491 if (res) {
492 strcpy (err,"Could not set status");
493 if (!strcmp (lang,"DE")) strcpy (err,"Status konnte nicht gesetzt werden.");
494 setres = -1;
496 else {
497 strcpy (err,"Devicestatus was updated.");
498 if (!strcmp (lang,"DE")) strcpy (err,"Devicestatus wurde gesetzt.");
499 setres = 1;
503 status_changed = 1;
509 status = (NETWORKMODE *)&buf;
510 cnt = 0;
511 for (i=0;i < 16;i++) {
512 if (status->stat[i].version[0]) cnt++;
513 status->stat[i].version[8] = 0;
515 if (setres) {
516 strcat (mem,"<br><font face=\"Verdana\" size=\"4\" color=\"red\"><p align=\"center\">");
517 strcat (mem,err);
518 strcat (mem,"</p></font><br>");
520 strcat (mem,"<font face=\"Verdana\" size=\"3\"><table><tr><td width=\"20\">&nbsp;</td><td>");
522 sprintf (ln,"%d IRTrans Devices found:</td></tr>",cnt);
523 if (!strcmp (lang,"DE")) sprintf (ln,"%d IRTrans gefunden:</td></tr>",cnt);
524 strcat (mem,ln);
526 strcat (mem,"<font face=\"Verdana\" size=\"3\"><table>");
528 for (i=0;i < 16;i++) if (status->stat[i].version[0]) {
529 GetIRTransType (status->stat[i].version[0],nm);
530 sprintf (ln,"<tr><td width=\"20\">&nbsp;</td><td>%d&nbsp;&nbsp;&nbsp;&nbsp;</td><td>IRTrans %s&nbsp;&nbsp;&nbsp;&nbsp;</td><td>%s</td>",i,nm,status->stat[i].version);
531 strcat (mem,ln);
532 sprintf (ln,"<td><a href=\"DeviceConfig.htm?lang=%s&id=%d\"><img border=\"0\" src=\"GoButton.gif\"></a></td></tr>",lang,i);
533 strcat (mem,ln);
536 strcat (mem,"</table>");
540 strcat (mem,"<br><br><br><br>");
541 strcat (mem,"<p align=\"center\"><font face=\"Verdana\" size=\"3\">");
542 sprintf (ln,"IRServer %s (c) 2003 Marcus M&uumlller</font></p>",irserver_version);
543 strcat (mem,ln);
544 strcat (mem,"</BODY></HTML>");
547 void GetIRTransType (char ver,char typ[])
550 *typ = 0;
551 switch (ver) {
552 case 'C':
553 strcpy (typ,"Temp");
554 return;
555 case 'U':
556 strcpy (typ,"USB");
557 return;
558 case 'V':
559 strcpy (typ,"USB B&O");
560 return;
561 case 'S':
562 strcpy (typ,"RS232/Bus");
563 return;
564 case 'T':
565 strcpy (typ,"RS232/Bus B&O");
566 return;
567 case 'X':
568 strcpy (typ,"IR Translator");
569 return;
574 void GetIndexPage (char *mem,char *lang)
576 char nm[100];
577 char ln[1000];
578 char intfc[20];
580 strcpy (mem,"<HTML><HEAD><TITLE>IRTrans Server</TITLE></HEAD><BODY bgcolor=\"#C0C0C0\">");
581 strcat (mem,"<table><tr><td align = \"center\">");
582 strcat (mem,"<IMG src=\"IRTransLogo.gif\" align = center>");
583 strcat (mem,"</td><td width=\"30\">&nbsp</td><td><table><tr><td>");
584 *nm = 0;
585 gethostname (nm,100);
586 *intfc = 0;
587 if (*irtrans_version == 'U' || *irtrans_version == 'V') strcpy (intfc,"USB");
588 if (*irtrans_version == 'S' || *irtrans_version == 'T') strcpy (intfc,"RS232");
589 sprintf (ln,"<font face=\"Verdana\" size=\"4\">IRTrans Server on <font face=\"Courier\" color=\"blue\">%s</font></font></td></tr>",nm);
590 if (!strcmp (lang,"DE")) sprintf (ln,"<font face=\"Verdana\" size=\"4\">IRTrans Server auf <font face=\"Courier\" color=\"blue\">%s</font></font></td></tr>",nm);
591 strcat (mem,ln);
592 strcat (mem,"<tr><td>&nbsp;</td></tr>");
593 // sprintf (ln,"<tr><td><font face=\"Verdana\" size=\"4\">IRTrans <font face=\"Courier\" color=\"blue\">%s %s SerNo.%u</font> connected.",intfc,irtrans_version,serno);
594 //t if (!strcmp (lang,"DE")) sprintf (ln,"<tr><td><font face=\"Verdana\" size=\"4\">IRTrans <font face=\"Courier\" color=\"blue\">%s %s SerNr.%u</font> angeschlossen.",intfc,irtrans_version,serno);
595 strcat (mem,ln);
596 if (!strcmp (lang,"DE")) strcat (mem,"</td></tr></table></td><td width=\"20\">&nbsp;</td><td align=\"center\"><a href=\"index.htm?lang=EN\"><img border=\"0\" src=\"English.jpg\"><br><font face=\"Verdana\" size=\"2\">English</font></a></td></tr></table>");
597 else strcat (mem,"</td></tr></table></td><td width=\"20\">&nbsp;</td><td align=\"center\"><a href=\"index.htm?lang=DE\"><img border=\"0\" src=\"Deutsch.jpg\"><br><font face=\"Verdana\" size=\"2\">Deutsch</font></a></td></tr></table>");
598 strcat (mem,"<br><hr><br><table>");
599 strcat (mem,"<tr><td width=\"20\">&nbsp</td>");
600 if (!strcmp (lang,"DE")) strcat (mem,"<td height=\"40\"><font face=\"Verdana\" size=\"4\">IRTrans Devices am Bus zeigen</font></td>");
601 else strcat (mem,"<td height=\"40\"><font face=\"Verdana\" size=\"4\">Show IRTrans Devices connected to the Bus</font></td>");
602 sprintf (ln,"<td width=\"10\">&nbsp;</td><td><a href=\"DeviceList.htm?lang=%s\"><img border=\"0\" src=\"GoButton.gif\"></a></td></tr>",lang);
603 strcat (mem,ln);
604 strcat (mem,"<tr><td width=\"20\">&nbsp</td>");
605 /* if (!strcmp (lang,"DE")) strcat (mem,"<td height=\"40\"><font face=\"Verdana\" size=\"4\">IR Befehle lernen</font></td>");
606 else strcat (mem,"<td height=\"40\"><font face=\"Verdana\" size=\"4\">Learn IR Commands</font></td>");
607 sprintf (ln,"<td width=\"10\">&nbsp;</td><td><a href=\"Learn.htm?lang=%s\"><img border=\"0\" src=\"GoButton.gif\"></a></td></tr>",lang);
608 strcat (mem,ln);
609 strcat (mem,"<tr><td width=\"20\">&nbsp</td>");
610 if (!strcmp (lang,"DE")) strcat (mem,"<td height=\"40\"><font face=\"Verdana\" size=\"4\">IR Befehle senden</font></td>");
611 else strcat (mem,"<td height=\"40\"><font face=\"Verdana\" size=\"4\">Send IR Commands</font></td>");
612 sprintf (ln,"<td width=\"10\">&nbsp;</td><td><a href=\"Send.htm?lang=%s\"><img border=\"0\" src=\"GoButton.gif\"></a></td></tr>",lang);
613 strcat (mem,ln);*/
614 strcat (mem,"</table><br><br><br><br>");
615 strcat (mem,"<p align=\"center\"><font face=\"Verdana\" size=\"3\">");
616 sprintf (ln,"IRServer %s (c) 2003 Marcus M&uumlller</font></p>",irserver_version);
617 strcat (mem,ln);
618 strcat (mem,"</BODY></HTML>");
622 void GenerateErrorPage (char *mem,int error)
624 char ln[1000],stat[1000],body[1000];
626 if (error == 404) {
627 sprintf (body,"<HTML><HEAD><TITLE>404 Not found</TITLE></HEAD><BODY>The requested page was not found on this Server</BODY></HTML>");
628 sprintf (stat,"HTTP/1.1 404 Not found\r\n");
630 strcpy (mem,stat);
631 strcat (mem,"Date: Sun, 21 Dec 2003 23:10:01 GMT\r\n");
632 strcat (mem,"Server: IRTrans 2.0\r\n");
633 strcat (mem,"Mime-Version: 1.0\r\n");
634 sprintf (ln,"Content-Type: text/html\r\nContent-Length: %6d\r\n",strlen (body));
635 strcat (mem,ln);
637 strcat (mem,"Expires: Sun, 21 Dec 2003 23:10:01 GMT\r\n");
638 strcat (mem,"Cache-control: no-cache\r\n");
640 strcat (mem,"\r\n");
641 strcat (mem,body);
644 void GenerateHtmlHeader (char *mem,char *data)
646 int len;
647 char ln[1000];
649 len = (int)strlen (data);
650 sprintf (mem,"HTTP/1.1 200 OK\r\n");
651 strcat (mem,"Date: Sun, 21 Dec 2003 23:10:01 GMT\r\n");
652 strcat (mem,"Server: IRTrans 2.0\r\n");
653 strcat (mem,"Mime-Version: 1.0\r\n");
654 sprintf (ln,"Content-Type: text/html\r\nContent-Length: %6d\r\n",len);
655 strcat (mem,ln);
657 strcat (mem,"Expires: Sun, 21 Dec 2003 23:10:01 GMT\r\n");
658 strcat (mem,"Cache-control: no-cache\r\n");
660 strcat (mem,"\r\n");
661 strcat (mem,data);
664 int GenerateImageHeader (char *mem,char *data,char *type,int len)
666 char ln[1000];
667 int hlen;
669 sprintf (mem,"HTTP/1.1 200 OK\r\n");
670 strcat (mem,"Date: Sun, 21 Dec 2003 23:10:01 GMT\r\n");
671 strcat (mem,"Server: IRTrans 2.0\r\n");
672 strcat (mem,"Mime-Version: 1.0\r\n");
673 sprintf (ln,"Content-Type: image/%s\r\nContent-Length: %6d\r\n",type,len);
674 strcat (mem,ln);
676 strcat (mem,"\r\n");
677 hlen = (int)strlen (mem);
678 memcpy (mem+hlen,data,len);
679 return (hlen + len);