-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathhttp.cpp
1783 lines (1691 loc) · 55.9 KB
/
http.cpp
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************
BayCom(R) Packet-Radio fuer IBM PC
OpenBCM-Mailbox
-------------------
HTTP-Server for BCM Reference: RFC 1945
-------------------
Copyright (C) Florian Radlherr
Taubenbergstr. 32
83627 Warngau
Alle Rechte vorbehalten / All Rights Reserved
***************************************************************/
//19980115 OE3DZW utcoffset -> ad_timezone, increased expire by 800s
//19980329 OE3DZW fixed send
//19980428 OE3DZW fixed conversion of to/subject
//19980505 OE3DZW l baybox -30 statt st l in Leiste, logout als
// remove cookie, "home" statt back
//19980525 DG9MHZ added support for MS IE ;-((( (fixed parser bug)
//19980916 OE3DZW added signature
//19981013 OE3DZW added debug output to find bug in http-post (send mails)
//1999xxxx Jan cleaned up HTML syntax, better noframe support, 7+ download
//19991122 Jan fixed HTTP version determination, fixed send contents parsing
// large security fixes, clean-up
//19991211 Jan read is now normal cmd, longer expire
//19991212 Jan removed "Go back" link, was pointing back to /command
// which is not what we want to have in bottom frame
//20000108 OE3DZW fixed (twice) protocol-check of http
//20000115 Jan removed obsolete HTTP/0.9 for good, most WWW servers (Apache)
// don't care about HTTP version
//20021205 DH8YMB createlogin if m.guestcall & _GUEST hinzu, some other changes
//20021208 DH8YMB Login-Callsign in ROT
//20021212 DH8YMB Guestcall-Fehlermeldung hinzu
//20030101 hpk in the CB-BCNNET login-concept: if user is
// HTTP-Authenticated, logintype will be set to 1 (full-login)
//20050401 DH8YMB added frameless CSS Style
#include "baycom.h"
#define BGCOL "\"#FFFFFF\""
#define HTTPSIGSTR "OBCMHTTPD"
//define this if you want files under bcm/http/ to be accessible without pw
//increases possibility of security-hole in something world-open
//#define FILES_WITHOUT_PW
/*---------------------------------------------------------------------------*/
class httpd
{
public:
httpd (void);
~httpd (void);
void start_http (char *name);
private:
// data
char signature[sizeof(HTTPSIGSTR)];
enum { GET, HEAD, POST } method;
enum { NONE, BIN, TXT, GIF, JPG, WAV} _mimetype;
char uri[200];
char login[CALLEN+1];
char cookie_login[CALLEN+1];
char pw[NAMELEN+1];
char cookie_pw[NAMELEN+1];
char guestpw[NAMELEN+5];
int status;
int logout;
int userlogin, guestlogin;
char file[80];
char userpass[50];
// char referer[100];
char host[100];
long contentlength;
char *content;
int nocookie;
int mimetype;
int httpsurface;
// user_t uu;
// methods
char *ht_time (time_t tt);
void generate_css (void);
void base64bin (char *in, char *out, int maxlen);
void get_authorization (char *buf, int cookie);
void get_contentlength (char *buf);
void get_field (char *buf, char *dest, unsigned maxlen);
// void form_referer(void);
void get_request (void);
void get_postarea (char *tag, char *out, int max, unsigned wrap = 0);
void put_header (char *title);
void put_homepage (char *cmd);
void put_css_footer (void);
void put_frame (void);
void put_sendform (char *to, char *lt, char *subj, char *read);
void put_createlogin (char *createlogin, char *createpw);
// void postmsg (char *in, char *out, int outlen);
};
/*---------------------------------------------------------------------------*/
httpd::httpd (void)
//*************************************************************************
//
// Initialization
//
//*************************************************************************
{
strcpy(signature, HTTPSIGSTR);
}
/*---------------------------------------------------------------------------*/
httpd::~httpd (void)
//*************************************************************************
//
// Deinitialization
//
//*************************************************************************
{
if (strcmp(signature, HTTPSIGSTR))
trace(fatal, "httpd", "sig broken");
}
/*---------------------------------------------------------------------------*/
char *httpd::ht_time (time_t ut)
//*************************************************************************
//
// Gibt RFC-Datum als String zurueck
//
//*************************************************************************
{
return datestr(ut - ad_timezone(), 18); // UTC RFC-Date
}
/*---------------------------------------------------------------------------*/
void httpd::generate_css (void)
//*************************************************************************
//
// Generiert die default CSS-Style Datei
//
//*************************************************************************
{
FILE *cssfile = NULL;
FILE *backfile = NULL;
if ((cssfile = s_fopen("http/style.css", "srt")) != NULL) {}
else
{
cssfile = s_fopen("http/style.css", "sat"); //schreibend oeffnen
fputs("/* Schriftstil, Abstaende */\n", cssfile);
fputs("body\n", cssfile);
fputs("{\n", cssfile);
fputs("margin-top:8px;\n", cssfile);
fputs("margin-left:8px;\n", cssfile);
fputs("margin-right:8px;\n", cssfile);
fputs("margin-bottom:8px;\n", cssfile);
fputs("color:black;\n", cssfile);
fputs("background-color:#ffffff;\n", cssfile);
backfile = s_fopen("http/back.jpg", "srt");
if (backfile)
{
s_fclose(backfile);
fputs("background-image:url(back.jpg);\n", cssfile);
}
fputs("font-family:verdana,arial;\n", cssfile);
fputs("font-size: 10pt;\n", cssfile);
fputs("}\n", cssfile);
fputs("table,tr,td\n", cssfile);
fputs("{\n", cssfile);
fputs("color:black;\n", cssfile);
fputs("font-family:verdana,arial;\n", cssfile);
fputs("font-size: 10pt\n", cssfile);
fputs("}\n", cssfile);
fputs("/* Scrollleiste Internet Explorer ab v5.5 */\n", cssfile);
fputs("body\n", cssfile);
fputs("{\n", cssfile);
fputs("scrollbar-arrow-color:#808080;\n", cssfile);
fputs("scrollbar-base-color:white;\n", cssfile);
fputs("scrollbar-highlight-color:#808080;\n", cssfile);
fputs("scrollbar-shadow-color:#000000;\n", cssfile);
fputs("SCROLLBAR-TRACK-COLOR:#cccccc;\n", cssfile);
fputs("}\n", cssfile);
fputs("/* Menue */\n", cssfile);
fputs("#menu a\n", cssfile);
fputs("{\n", cssfile);
fputs("display:block;\n", cssfile);
fputs("background-color:#ffffff;\n", cssfile);
fputs("color:black;\n", cssfile);
fputs("text-decoration:none;\n", cssfile);
fputs("font-family:verdana,sans-serif;\n", cssfile);
fputs("font-size:10pt;\n", cssfile);
fputs("width:140px;\n", cssfile);
fputs("border-bottom:solid 1px #ffffff;\n", cssfile);
fputs("border-top:solid 1px #ffffff;\n", cssfile);
fputs("}\n", cssfile);
fputs("#menu a:visited\n", cssfile);
fputs("{\n", cssfile);
fputs("background-color:#ffffff;\n", cssfile);
fputs("color:black;\n", cssfile);
fputs("text-decoration:none;\n", cssfile);
fputs("font-family:verdana,sans-serif;\n", cssfile);
fputs("font-size:10pt;\n", cssfile);
fputs("width:140px;\n", cssfile);
fputs("border-bottom:solid 1px #ffffff;\n", cssfile);
fputs("border-top:solid 1px #ffffff;\n", cssfile);
fputs("}\n", cssfile);
fputs("#menu a:active\n", cssfile);
fputs("{\n", cssfile);
fputs("background-color:#ffffff;\n", cssfile);
fputs("color:black;\n", cssfile);
fputs("text-decoration:none;\n", cssfile);
fputs("font-family:verdana,sans-serif;\n", cssfile);
fputs("font-size:10pt;\n", cssfile);
fputs("width:140px;\n", cssfile);
fputs("border-bottom:solid 1px #ffffff;\n", cssfile);
fputs("border-top:solid 1px #ffffff;6;\n", cssfile);
fputs("}\n", cssfile);
fputs("#menu a:hover\n", cssfile);
fputs("{\n", cssfile);
fputs("background-color:#e6e6e6;\n", cssfile);
fputs("color:black;\n", cssfile);
fputs("text-decoration:none;\n", cssfile);
fputs("font-family:verdana,sans-serif;\n", cssfile);
fputs("font-size:10pt;\n", cssfile);
fputs("width:140px;\n", cssfile);
fputs("border-bottom:solid 1px #000000;\n", cssfile);
fputs("border-top:solid 1px #000000;\n", cssfile);
fputs("}\n", cssfile);
fputs("/* Menuetitel */\n", cssfile);
fputs(".rubrik\n", cssfile);
fputs("{\n", cssfile);
fputs("background-color:#9198ab;\n", cssfile);
fputs("color:white;\n", cssfile);
fputs("text-decoration:none;\n", cssfile);
fputs("font-family:verdana,sans-serif;\n", cssfile);
fputs("font-size:10pt;\n", cssfile);
fputs("width:140px;\n", cssfile);
fputs("border-bottom:solid 1px #000000;\n", cssfile);
fputs("border-top:solid 1px #000000;\n", cssfile);
fputs("height:19px;\n", cssfile);
fputs("}\n", cssfile);
fputs("/* Fuss- und Kopfleiste */\n", cssfile);
fputs(".leiste\n", cssfile);
fputs("{\n", cssfile);
fputs("background-color:#9198ab;\n", cssfile);
fputs("color:white;\n", cssfile);
fputs("text-decoration:none;\n", cssfile);
fputs("font-family:verdana,sans-serif;\n", cssfile);
fputs("font-size:10pt;\n", cssfile);
fputs("height:17px;\n", cssfile);
fputs("}\n", cssfile);
fputs("/* Schriftform und -farbe von allgemeinen Links */\n", cssfile);
fputs("a:link\n", cssfile);
fputs("{\n", cssfile);
fputs("color:blue;\n", cssfile);
fputs("text-decoration:underline;\n", cssfile);
fputs("font-family:courier;\n", cssfile);
fputs("font-size:10pt;\n", cssfile);
fputs("}\n", cssfile);
fputs("a:visited\n", cssfile);
fputs("{\n", cssfile);
fputs("color:blue;\n", cssfile);
fputs("text-decoration:underline;\n", cssfile);
fputs("font-family:courier;\n", cssfile);
fputs("font-size:10pt;\n", cssfile);
fputs("}\n", cssfile);
fputs("a:active\n", cssfile);
fputs("{\n", cssfile);
fputs("color:blue;\n", cssfile);
fputs("text-decoration:underline;\n", cssfile);
fputs("font-family:courier;\n", cssfile);
fputs("font-size:10pt;\n", cssfile);
fputs("}\n", cssfile);
fputs("a:hover\n", cssfile);
fputs("{\n", cssfile);
fputs("color:#808080;\n", cssfile);
fputs("background-color:white;\n", cssfile);
fputs("text-decoration:none;\n", cssfile);
fputs("font-family:courier;\n", cssfile);
fputs("font-size:10pt;\n", cssfile);
fputs("}\n", cssfile);
fputs("form\n", cssfile);
fputs("{\n", cssfile);
fputs("margin-bottom:0px;\n", cssfile);
fputs("}\n", cssfile);
trace(report, "generate_css", "default http/style.css created");
}
s_fclose(cssfile);
}
/*---------------------------------------------------------------------------*/
int isamprnet (char *ip)
//*************************************************************************
//
// Stellt fest, ob es sich um eine Ampr-Net Adresse handelt.
//
//*************************************************************************
{
if (m.httpttypw)
return 0;
else
{
if (! strncmp(ip, "44.", 3)) return 2;
else if (! strncmp(ip, "127.", 4)) return 1;
else return 0;
}
}
/*---------------------------------------------------------------------------*/
void httpd::base64bin (char *in, char *out, int maxlen)
//*************************************************************************
//
// highly simplified base64-decoder, according RFC1521
// constraints: - no line feeds
// - no inappropriate characters (lead to abort of conversion)
// - no zero bytes within data
//
//*************************************************************************
{
int i, a, end = 0;
long outword = 0;
while (*in && ! end && maxlen > 3)
{
for (i = 0; i < 4; i++)
{
if (! in[i]) end = 1;
outword <<= 6;
a = in[i];
if (isalpha(a) && isupper(a)) a -= ('A');
else if (isalpha(a) && islower(a)) a -= ('a' - 26);
else if (isdigit(a)) a += 4;
else if (a == '+') a = 62;
else if (a == '/') a = 63;
else a = 0; // text only! Padding with 0-Bytes
outword |= a;
}
out[0] = (outword >> 16) & 255; // slow, but portable (byte order!)
out[1] = (outword >> 8) & 255;
out[2] = (outword) & 255;
in += 4;
out += 3;
maxlen -= 3;
}
*out = 0;
}
/*---------------------------------------------------------------------------*/
void httpd::get_contentlength (char *buf)
//*************************************************************************
//
//*************************************************************************
{
char *dop;
dop = strchr(buf, ':');
if (dop) contentlength = atol(dop + 1);
}
/*---------------------------------------------------------------------------*/
void httpd::get_field (char *buf, char *dest, unsigned maxlen)
//*************************************************************************
//
//*************************************************************************
{
char *dop;
dop = strchr(buf, ':');
if (dop)
{
dop++;
while (*dop == ' ') dop++;
if (strlen(dop) >= maxlen) dop[maxlen - 1] = 0;
strcpy(dest, dop);
}
else *dest = 0;
}
/*---------------------------------------------------------------------------*/
//void httpd::form_referer(void)
//*************************************************************************
//
//*************************************************************************
/*
{
char tmp[80];
char *hostpos = stristr(referer, host);
if (referer[0] && host[0] && hostpos)
{
if ((strlen(hostpos + strlen(host)) > 79))
{
trace(serious, "httpd", "referer str too long, ip[%s]", b->peerip);
strcpy(referer, "/");
return;
}
strcpy(tmp, hostpos + strlen(host));
strcpy(referer, tmp);
}
else strcpy(referer, "/");
}*/
/*---------------------------------------------------------------------------*/
void httpd::get_authorization (char *buf, int cookie)
//*************************************************************************
//
//*************************************************************************
{
char *search;
char *basic;
char loginpw[50];
char *locpw;
if (cookie) search = m.boxname;
else search = "Basic";
basic = strstr(buf, search);
if (basic)
{
basic += strlen(search);
if (*basic) basic++;
safe_strcpy(userpass, basic);
base64bin(basic, loginpw, 49);
locpw = strchr(loginpw, ':');
if (locpw && locpw[0] && locpw[1])
{
if (cookie)
safe_strcpy(cookie_pw, locpw + 1)
else
safe_strcpy(pw, locpw + 1)
*locpw = ' ';
}
locpw = strchr(loginpw, ' ');
if (locpw) *locpw = 0;
loginpw[NAMELEN] = 0;
if (cookie)
strcpy(cookie_login, loginpw);
else
strcpy(login, loginpw);
}
}
/*---------------------------------------------------------------------------*/
void httpd::get_request (void)
//*************************************************************************
//
//*************************************************************************
{
char locinbuf[301];
char *vers;
getline(locinbuf, sizeof(locinbuf) - 1, 1);
if ((m.tcpiptrace == 1) || (m.tcpiptrace == 8)) httplog("RX", locinbuf);
char *locmethod = locinbuf;
char *locuri = skip(locmethod);
char *locprotocol = skip(locuri);
char userpw[NAMELEN+5];
skip(locprotocol);
contentlength = 0L;
content = NULL;
userpass[0] = 0;
status = 200;
logout = 0;
userlogin = 0;
guestlogin = 0;
*file = 0;
*login = 0;
*pw = 0;
*cookie_login = 0;
*cookie_pw = 0;
nocookie = 0;
// referer[0]=0;
mimetype = NONE;
*uri = 0;
*host = 0;
if (m.disable)
{
status = 503;
return;
}
if (! locmethod || ! locuri || ! locprotocol || strlen(locmethod) > 10
|| strlen(locuri) > (sizeof(uri) - 2) || strlen(locprotocol) > 10)
{
//don't waste time with that ..
status = 400;
return;
}
//determine protocol version
vers = stristr(locprotocol, "HTTP/");
if (vers != locprotocol)
{
status = 400;
return;
}
//check URL
if (*locuri != '/')
{
status = 400;
return;
}
safe_strcpy(uri, locuri);
if (! stricmp(locmethod, "GET")) method = GET;
else if (! stricmp(locmethod, "HEAD")) method = HEAD;
else if (! stricmp(locmethod, "POST")) method = POST;
else
{
status = 501;
return;
}
// check if we should send a file
if (strchr(uri, '.') && ! strchr(uri, '?'))
{ // hm, yes it is a dirty hack...
snprintf(file, sizeof(file), "http%s", locuri);
if (strstr(file, "..")) //no "../../etc/passwd" constructions
{
status = 403;
return;
}
if (file[strlen(file) - 1] == '/') file[strlen(file) - 1] = 0;
#ifndef _WIN32
if (access(file, R_OK))
{
status = 404;
return;
}
#endif
}
if (! stricmp(uri, "/logout"))
{
status = 401;
logout = 1;
return;
}
if (! stricmp(uri, "/userlogin"))
{
if (m.httpguestfirst)
{
userlogin = 1;
safe_strcpy(login, "");
safe_strcpy(pw, "");
safe_strcpy(cookie_login, "");
safe_strcpy(cookie_pw, "");
}
}
#ifdef _GUEST
if (! stricmp(uri, "/guestlogin"))
{
guestlogin = 0;
safe_strcpy(login, "");
safe_strcpy(pw, "");
safe_strcpy(cookie_login, "");
safe_strcpy(cookie_pw, "");
}
#endif
if (httpsurface == 0)
{
//check for valid url - this is really needed only if not using frames
//when header is generated before cmd parsing
if (strcmp(uri, "/") && strncmp(uri, "/cmd?", 5)
&& strncmp(uri, "/bread/", 7) && strncmp(uri, "/send?", 6)
&& strcmp(uri, "/send") && strcmp(uri, "/ask")
&& strcmp(uri, "/sendok") && strcmp(uri, "/askok")
&& strcmp(uri, "/userlogin")
&& strcmp(uri, "/login") && strcmp(uri, "/command")
#ifdef _GUEST
&& strcmp(uri, "/guestlogin")
#endif
&& ! (strchr(uri, '.') && ! strchr(uri, '?'))
)
{
status = 404;
return;
}
}
else
{
if (strcmp(uri, "/") && strncmp(uri, "/cmd?", 5)
&& strncmp(uri, "/bread/", 7) && strncmp(uri, "/send?", 6)
&& strcmp(uri, "/send") && strcmp(uri, "/ask")
&& strcmp(uri, "/sendok") && strcmp(uri, "/askok")
&& strcmp(uri, "/userlogin")
#ifdef _GUEST
&& strcmp(uri, "/guestlogin")
#endif
&& ! (strchr(uri, '.') && ! strchr(uri, '?'))
)
{
status = 404;
return;
}
}
do //request is ok .. now parse the headers
{
getline(locinbuf, sizeof(locinbuf) - 1, 1);
if ((m.tcpiptrace == 1) || (m.tcpiptrace == 8))
httplog("RX", locinbuf);
if (*locinbuf)
{
if (stristr(locinbuf, "Authorization") == locinbuf)
{
get_authorization(locinbuf, 0);
}
if (stristr(locinbuf, "Cookie") == locinbuf)
get_authorization(locinbuf, 1);
/* if (stristr(locinbuf, "Referer") == locinbuf)
get_field(locinbuf, referer, sizeof(referer)); */
if (stristr(locinbuf, "Host") == locinbuf)
get_field(locinbuf, host, sizeof(host));
if (stristr(locinbuf, "Content-length") == locinbuf)
get_contentlength(locinbuf);
}
}
while (*locinbuf);
#ifdef _GUEST
if (m.httpguestfirst || guestlogin)
{
//dh8ymb: falls author. fail und "not userlogin" und _guest
// dann login als guest
if (! userlogin)
if (((! *login && ! *cookie_login) || (! *pw && ! *cookie_pw)) )
{
safe_strcpy(login, m.guestcall);
get_ttypw(m.guestcall, guestpw);
safe_strcpy(pw, guestpw);
}
}
#endif
if (((! *login && ! *cookie_login) || (! *pw && ! *cookie_pw))
#ifdef FILES_WITHOUT_PW
&& ! *file
#endif
)
{ //shortcut ..
status = 401;
return;
}
#ifdef FILES_WITHOUT_PW
if (! *file)
{
#endif
// oe3dzw ttypw nur beim Drahtzugang, sonst Name des Users
if (*login)
{
if (isamprnet(b->peerip) > 0)
get_httppw(login, userpw);
else
get_ttypw(login, userpw);
if (! *pw || stricmp(userpw, pw))
{
status = 401;
pwlog(b->peerip, b->uplink, "bad password");
return;
}
else b->pwok = OK;
}
else
{
if (isamprnet(b->peerip) > 0)
get_httppw(cookie_login, userpw);
else
get_ttypw(cookie_login, userpw);
if (! *cookie_pw || stricmp(userpw, cookie_pw))
{
status = 401;
pwlog(b->peerip, b->uplink, "bad cookie");
return;
}
else
b->pwok = OK;
safe_strcpy(pw, cookie_pw);
safe_strcpy(login, cookie_login);
nocookie = 1;
}
strupr(login);
loaduser(login, u, 0);
if (u->httpsurface == 0)
httpsurface = m.defhttpsurface;
else
httpsurface = u->httpsurface - 1;
sprintf(t->name, "/%s", login);
#ifdef FILES_WITHOUT_PW
}
#endif
b->charset = 1;
//get_ttycharset(login) ..
if (contentlength)
{
long l;
/* dh8ymb: wozu?
if (contentlength > MAXMAILLEN)
{
trace(serious, "httpd", "content too long, ip [%s]", b->peerip);
status = 500;
return;
}
*/
content = (char *) t_malloc(contentlength + 1, "hcon");
*content = getv(); //skip leading CR/LFs
//(some?) browsers put two newlines before content
while (*content == LF || *content == CR) *content = getv();
for (l = 1; l < contentlength; l++) content[l] = getv();
content[l] = 0;
}
else if (method == POST)
{
status = 400;
return;
}
locuri = strchr(uri, '?');
if (locuri)
{
if (! content)
{
*locuri = 0;
content = locuri + 1;
}
}
// form_referer();
}
/*---------------------------------------------------------------------------*/
void httpd::get_postarea (char *tag, char *result, int max, unsigned wrap)
//*************************************************************************
//
//*************************************************************************
{
unsigned int i;
*result = 0;
char *firstresult = result;
char *found;
char hex[3];
unsigned val;
if (! content) return;
found = stristr(content, tag);
if (found)
{
found += strlen(tag);
while (*found && *found != '&' && max)
{
if (*found == '+') *result = ' ';
else if (*found == '%' && found[1] && found[2])
{
hex[0] = found[1];
hex[1] = found[2];
hex[2] = 0;
sscanf(hex, "%2X", &val);
found += 2;
if (val == 0x0D)
{
found++;
continue;
}
*result = val;
}
else *result = *found;
result++;
found++;
max--;
*result = 0;
}
}
// do word wrapping since the browser seems not to be able to do it
if (wrap)
{
result = firstresult;
while (*result)
{
if (*result == LF)
{
result++;
continue;
}
for (i = 0; i < wrap && result[i] && result[i] != LF; i++);
if (i == wrap)
{
while (i && result[i] != ' ') i--;
if (! i) i = wrap;
else result[i] = LF;
}
result += i;
}
}
}
/*---------------------------------------------------------------------------*/
void httpd::put_header (char *title)
//*************************************************************************
//
// creates HTTP header, puts <HTML>...<BODY> if title!=NULL
//
//*************************************************************************
{
struct
{ int status;
char *phrase;
}
st_tab[] =
{
{ 200, "OK" },
{ 201, "Created" },
{ 202, "Accepted" },
{ 204, "No Content" },
{ 301, "Moved Permanently" },
{ 302, "Moved Temporarily" },
{ 304, "Not Modified" },
{ 400, "Bad Request" },
{ 401, "Unauthorized" },
{ 403, "Forbidden" },
{ 404, "Not Found" },
{ 500, "Internal Server Error" },
{ 501, "Not Implemented" },
{ 502, "Bad Gateway" },
{ 503, "Service Unavailable" },
{ 0, "Unknown" }
};
int st;
int expsec;
char *mimestr;
int ht = b->http;
FILE *wavfile = NULL;
FILE *backfile = NULL;
b->http = 1;
for (st = 0; st_tab[st].status; st++)
{
if (st_tab[st].status == status) break;
}
html_putf("HTTP/1.0 %d %s\n", status, st_tab[st].phrase);
html_putf("Date: %s\n", ht_time(ad_time()));
html_putf("Server: " STD_BOXHEADER "/" VNUMMER "\n");
if (status == 401)
{
if (strcmp(uri, "/logout"))
html_putf("WWW-Authenticate: Basic realm=\"%s\"\n", m.boxname);
html_putf("Set-Cookie: %s=; path=/; expires=%s;\n",
m.boxname, ht_time(ad_time()) );
// html_putf("Set-Cookie: %s=; path=/; expires=Tue, 01 Jan 1980 1:00 GMT;",
// m.boxname);
// html_putf("Cache-Control: max-age=0 Cache-Control: must-revalidate\n");
}
else if (status == 200 && ! strcmp(uri, "/") && *pw && ! nocookie)
{
html_putf("Set-Cookie: %s=%s; path=/; expires=%s;\n",
m.boxname, userpass, ht_time(ad_time() + MAXAGE));
// html_putf("Set-Cookie: %s=%s; path=/; expires=%s;",
// m.boxname, userpass, ht_time(ad_time() + MAXAGE));
// html_putf("Cache-Control: max-age=0\nCache-Control: must-revalidate\n");
}
if (mimetype == NONE && status == 200)
{
if (stristr(uri, ".jpg")) mimetype = JPG;
if (stristr(uri, ".gif")) mimetype = GIF;
if (stristr(uri, ".wav")) mimetype = WAV;
}
switch (mimetype)
{
case JPG: mimestr = MIME_JPG; break;
case GIF: mimestr = MIME_GIF; break;
case BIN: mimestr = MIME_BIN; break;
case WAV: mimestr = MIME_WAV; break;
default: mimestr = MIME_TXT;
}
html_putf("Content-type: %s\n", mimestr);
html_putf("Cache-Control: max-age=0\nCache-Control: must-revalidate\n");
if (status == 200)
{
if (*file)
{
html_putf("Content-length: %ld\n", filesize(file));
html_putf("Last-modified: %s\n", ht_time(file_isreg(file)));
}
else
{
expsec = 1800;
if (stristr(uri, "/send") == uri) expsec = 8000; //OE3DZW was 7200
html_putf("Expires: %s\n", ht_time(ad_time() + expsec));
}
}
html_putf("\n");
if (status != 200) //something is wrong ..
{
if (status != 401 && status != 404 && status != 503)
trace(replog, "httpd", "strange request from [%s]", b->peerip);
if (! strcmp(uri, "/logout"))
{
html_putf("<html><head><title>%s</title></head>\n", m.boxname);
html_putf("<body><h1>%s</h1>\n", m.boxname);
}
else
{
html_putf("<html><head><title>%s</title></head>\n", st_tab[st].phrase);
html_putf("<body><h1>%s (%d)</h1>\n", st_tab[st].phrase, status);
}
if (status == 503) // m.disable=1
{
html_putf(ms(m_maintenance), m.boxname);
return;
}
if (! logout)
{
html_putf("<p>An error ocurred while processing your query.</p>\n");
#ifdef _GUEST
if (strcmp(m.guestcall, "OFF"))
{
get_ttypw(m.guestcall, guestpw);
if (strlen(guestpw) > 1)
{
html_putf("<p><b>You can log in as user '%s' with password '%s' for read-only access!</b><br>\n",
m.guestcall, guestpw);
html_putf("<b>If you need full access contact sysop %s!</b></p>\n",
m.sysopcall);
}
else
if (m.httpguestfirst)
html_putf("HTTPD guest error: no ttypw set for guestcall - inform sysop!</p>\n");
}
#endif
}
else
{
// leider behalten die Browser die Authentization-Info bis zum Browserneustart,
// so dass der Browser ein neues Cookie anfordert wenn er nicht neugestartet wird!
html_putf("<p> Your cookie has been removed... now close all browser windows to take effect!</p>\n");
}
html_putf("<b>" STD_BOXHEADER "</b> - Version " VNUMMER " - <i>httpd</i>\n");
html_putf("</body></html>\n");
}
if (title)
{
html_putf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
html_putf("<html><head>\n");
if (m.httprobots)
{
html_putf("<meta name=\"ROBOTS\" content=\"INDEX,FOLLOW\">\n");
html_putf("<meta name=\"DESCRIPTION\" content=\"PACKET RADIO MAILBOX %s\">\n",
m.boxname);
}
else
html_putf("<meta name=\"ROBOTS\" content=\"NOINDEX,NOFOLLOW\">\n");
html_putf("<meta http-equiv=\"expires\" content=\"0\">\n");
html_putf("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n");
html_putf("<title>%s - %s</title>", m.boxname, title);
if (httpsurface == 1)
{
html_putf("<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">");
html_putf("<script type=\"text/javascript\">\n"
"<!--\n"
"function BlurLinks()\n"
"{\n"
" lnks=document.getElementsByTagName('a');\n"
" for(i=0;i<lnks.length;i++)\n"
" {\n"
" lnks[i].onfocus=new Function(\"if(this.blur)this.blur()\");\n"
" }\n"
"}\n"
"onload=BlurLinks;\n"
"-->\n"
"</script>\n");
}
html_putf("</head>\n");
if (httpsurface != 1)
{
backfile = s_fopen("http/back.jpg", "srt");
if (backfile)
{
s_fclose(backfile);
html_putf("<body BGCOLOR=" BGCOL " background=\"/back.jpg\">\n");
}
else
html_putf("<body BGCOLOR=" BGCOL ">\n");
}
else
html_putf("<body>\n");
wavfile = s_fopen("http/qsl.wav", "srt");
if (wavfile)
{
s_fclose(wavfile);
html_putf("<EMBED src=\"qsl.wav\" autostart=true loop=false height=0 width=0 volume=100>\n");
}
}
b->http = ht;
return;