2 * Copyright (c) 2007, IRTrans GmbH
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.
37 #define MSG_NOSIGNAL 0
45 #define MSG_NOSIGNAL 0
49 #include <sys/types.h>
50 #include <sys/socket.h>
51 #include <netinet/in.h>
53 #include <arpa/inet.h>
64 #define closesocket close
69 #define LIRCD "/dev/lircd"
70 #define PERMISSIONS 0666
81 #include "webserver.h"
93 extern WSAEVENT WebEvent
;
98 void ProcessWebRequest (SOCKET sock
)
105 struct sockaddr_in cli_addr
;
107 clilen
= sizeof (cli_addr
);
109 call
= accept (sock
,(struct sockaddr
*)&cli_addr
,&clilen
);
112 adr
= ntohl (cli_addr
.sin_addr
.S_un
.S_addr
);
114 adr
= ntohl (cli_addr
.sin_addr
.s_addr
);
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
);
131 WSAEventSelect (call
,WebEvent
,0);
132 ioctlsocket (call
,FIONBIO
,&res
);
135 res
= recv (call
,data
,2048,MSG_NOSIGNAL
);
139 ParseRequest (data
,call
);
144 void ParseRequest (char* data
,SOCKET sock
)
149 if (!strncmp (data
,"GET ",4)) {
150 len
= GetHtmlPage (mem
,data
+ 4);
151 send (sock
,mem
,len
,0);
157 int GetHtmlPage (char *mem
,char *page
)
165 while (page
[i
] > ' ') i
++;
169 for (i
=0;page
[i
] && page
[i
] != '?';i
++);
170 if (page
[i
] == '?') {
173 strcpy (parm
,page
+ i
);
176 GetHtmlParameter (parm
,"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
);
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
)
235 while (parm
[i
] && parm
[i
] != '=' && parm
[i
] != '?' && parm
[i
] != '&') i
++;
236 if (!parm
[i
]) return;
237 if (parm
[i
] == '=') {
239 if (!strcmp (name
,parm
+j
)) {
241 while (parm
[i
] && parm
[i
] != '?' && parm
[i
] != '&') i
++;
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;
259 char remote
[100],command
[100];
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\"> </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
);
269 strcat (mem
,"<IMG src=\"BackButton.gif\" align = \"center\" border=\"0\"></a></td></tr></table><hr><br>");
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
);
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>");
290 if (mask
) mask
= ((word
)mask
& 0xffff) | 0x10000;
291 SendIR (cmd_num
,mask
);
300 void GetDeviceConfigPage (char *mem
,char *lang
,int id
)
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\"> </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
);
314 strcat (mem
,"<IMG src=\"BackButton.gif\" align = \"center\" border=\"0\"></a></td></tr></table><hr><br>");
316 res
= GetDeviceStatus (&buf
);
320 status
= (NETWORKMODE
*)&buf
;
323 strcat (mem
,"<font face=\"Verdana\" size=\"3\"><table><tr><td width=\"20\"> </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
);
327 strcat (mem
,"</table>");
328 strcat (mem
,"<font face=\"Verdana\" size=\"3\"><form method=\"GET\" action=\"SetConfig.htm\"><table><tr><td width=\"20\"> </td>");
329 strcat (mem
,"<td>Target Mask</td></tr><tr><td width=\"20\"> </td><td>");
330 sprintf (ln
,"<input type=\"hidden\" value=\"%d\" name=\"id\">",id
);
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
);
337 strcat (mem
,"</td></tr><tr><td> </td></tr>");
339 strcat (mem
,"<tr><td width=\"20\"> </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":""));
343 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":""));
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":""));
354 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":""));
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 über IR steuern",DEVMODE_IRCODE,(status->stat[id].device_mode & DEVMODE_IRCODE ? "checked":""));
365 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 über SBUS steuern",DEVMODE_SBUSCODE
,(status
->stat
[id
].device_mode
& DEVMODE_SBUSCODE
? "checked":""));
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":""));
375 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":""));
380 strcat (mem
,"</td></tr>");
382 strcat (mem
,"<tr><td>");
383 sprintf (ln
,"Hotremote <input type=\"text\" name=\"Remote\" value=\"%s\" size=\"20\"> ",status
->stat
[id
].remote
);
384 if (!strcmp (lang
,"DE")) sprintf (ln
,"PowerOn FB <input type=\"text\" name=\"Remote\" value=\"%s\" size=\"20\"> ",status
->stat
[id
].remote
);
386 strcat (mem
,"</td>");
388 sprintf (ln
,"Hotcommand <input type=\"text\" name=\"Command\" value=\"%s\" size=\"20\">",status
->stat
[id
].command
);
389 if (!strcmp (lang
,"DE")) sprintf (ln
,"PowerOn Befehl <input type=\"text\" name=\"Command\" value=\"%s\" size=\"20\">",status
->stat
[id
].command
);
391 strcat (mem
,"</td></tr>");
392 strcat (mem
,"<tr><td> ");
393 strcat (mem
,"</td></tr>");
394 strcat (mem
,"<tr><td> ");
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üller</font></p>",irserver_version
);
414 strcat (mem
,"</BODY></HTML>");
419 void GetDevicesPage (char *mem
,char *lang
,char *parm
)
421 int res
,cnt
,i
,id
,setres
= 0;
428 char remote
[100],command
[100];
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\"> </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
);
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
);
447 GetHtmlParameter (parm
,"id",value
);
449 if (*value
== 0 || id
< 0 || id
> 15) {
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");
456 for (i
=0;i
<=15;i
++) {
457 sprintf (nm
,"TM%02d",i
);
458 GetHtmlParameter (parm
,nm
,value
);
462 GetHtmlParameter (parm
,"DEVMODE_SEND",value
);
464 GetHtmlParameter (parm
,"DEVMODE_IR",value
);
466 GetHtmlParameter (parm
,"DEVMODE_SBUS",value
);
468 GetHtmlParameter (parm
,"DEVMODE_IRCODE",value
);
470 GetHtmlParameter (parm
,"DEVMODE_SBUSCODE",value
);
472 GetHtmlParameter (parm
,"DEVMODE_RAW",value
);
474 GetHtmlParameter (parm
,"DEVMODE_RAWFAST",value
);
476 GetHtmlParameter (parm
,"DEVMODE_REPEAT",value
);
478 GetHtmlParameter (parm
,"Remote",remote
);
479 GetHtmlParameter (parm
,"Command",command
);
481 res
= GetHotcode (remote
,command
,value
);
483 GetError (ERR_HOTCODE
,value
);
484 sprintf (err
,value
,remote
,command
);
488 StoreSwitch ((word
)id
,0,remote
,command
,1);
490 res
= SetTransceiverModusEx (0,md
,tm
,(byte
)id
,value
,res
,0xf,4,0,0,0); // !! Bus
492 strcpy (err
,"Could not set status");
493 if (!strcmp (lang
,"DE")) strcpy (err
,"Status konnte nicht gesetzt werden.");
497 strcpy (err
,"Devicestatus was updated.");
498 if (!strcmp (lang
,"DE")) strcpy (err
,"Devicestatus wurde gesetzt.");
509 status
= (NETWORKMODE
*)&buf
;
511 for (i
=0;i
< 16;i
++) {
512 if (status
->stat
[i
].version
[0]) cnt
++;
513 status
->stat
[i
].version
[8] = 0;
516 strcat (mem
,"<br><font face=\"Verdana\" size=\"4\" color=\"red\"><p align=\"center\">");
518 strcat (mem
,"</p></font><br>");
520 strcat (mem
,"<font face=\"Verdana\" size=\"3\"><table><tr><td width=\"20\"> </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
);
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\"> </td><td>%d </td><td>IRTrans %s </td><td>%s</td>",i
,nm
,status
->stat
[i
].version
);
532 sprintf (ln
,"<td><a href=\"DeviceConfig.htm?lang=%s&id=%d\"><img border=\"0\" src=\"GoButton.gif\"></a></td></tr>",lang
,i
);
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üller</font></p>",irserver_version
);
544 strcat (mem
,"</BODY></HTML>");
547 void GetIRTransType (char ver
,char typ
[])
559 strcpy (typ
,"USB B&O");
562 strcpy (typ
,"RS232/Bus");
565 strcpy (typ
,"RS232/Bus B&O");
568 strcpy (typ
,"IR Translator");
574 void GetIndexPage (char *mem
,char *lang
)
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\"> </td><td><table><tr><td>");
585 gethostname (nm
,100);
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
);
592 strcat (mem
,"<tr><td> </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);
596 if (!strcmp (lang
,"DE")) strcat (mem
,"</td></tr></table></td><td width=\"20\"> </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\"> </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\"> </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\"> </td><td><a href=\"DeviceList.htm?lang=%s\"><img border=\"0\" src=\"GoButton.gif\"></a></td></tr>",lang
);
604 strcat (mem
,"<tr><td width=\"20\"> </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\"> </td><td><a href=\"Learn.htm?lang=%s\"><img border=\"0\" src=\"GoButton.gif\"></a></td></tr>",lang);
609 strcat (mem,"<tr><td width=\"20\"> </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\"> </td><td><a href=\"Send.htm?lang=%s\"><img border=\"0\" src=\"GoButton.gif\"></a></td></tr>",lang);
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üller</font></p>",irserver_version
);
618 strcat (mem
,"</BODY></HTML>");
622 void GenerateErrorPage (char *mem
,int error
)
624 char ln
[1000],stat
[1000],body
[1000];
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");
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
));
637 strcat (mem
,"Expires: Sun, 21 Dec 2003 23:10:01 GMT\r\n");
638 strcat (mem
,"Cache-control: no-cache\r\n");
644 void GenerateHtmlHeader (char *mem
,char *data
)
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
);
657 strcat (mem
,"Expires: Sun, 21 Dec 2003 23:10:01 GMT\r\n");
658 strcat (mem
,"Cache-control: no-cache\r\n");
664 int GenerateImageHeader (char *mem
,char *data
,char *type
,int len
)
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
);
677 hlen
= (int)strlen (mem
);
678 memcpy (mem
+hlen
,data
,len
);