forked from g8bpq/OldLinBPQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BBSHTMLConfig.c
3660 lines (2842 loc) · 90.3 KB
/
BBSHTMLConfig.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
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
/*
Copyright 2001-2015 John Wiseman G8BPQ
This file is part of LinBPQ/BPQ32.
LinBPQ/BPQ32 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LinBPQ/BPQ32 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LinBPQ/BPQ32. If not, see http://www.gnu.org/licenses
*/
#include "BPQMail.h"
extern char NodeTail[];
extern char BBSName[10];
extern char LTFROMString[2048];
extern char LTTOString[2048];
extern char LTATString[2048];
//static UCHAR BPQDirectory[260];
extern ConnectionInfo Connections[];
extern int NumberofStreams;
extern int SMTPMsgs;
extern int ChatApplNum;
extern int MaxChatStreams;
extern char Position[81];
extern char PopupText[251];
extern int PopupMode;
#define MaxCMS 10 // Numbr of addresses we can keep - currently 4 are used.
struct UserInfo * BBSLIST[NBBBS + 1];
int MaxBBS = 0;
#define MAIL
#include "HTTPConnectionInfo.h"
struct TCPINFO * TCP;
VOID ProcessMailSignon(struct TCPINFO * TCP, char * MsgPtr, char * Appl, char * Reply, int * RLen);
static struct HTTPConnectionInfo * FindSession(char * Key);
VOID ProcessUserUpdate(struct HTTPConnectionInfo * Session, char * MsgPtr, char * Reply, int * RLen, char * Rest);
VOID ProcessMsgFwdUpdate(struct HTTPConnectionInfo * Session, char * MsgPtr, char * Reply, int * RLen, char * Rest);
VOID SendConfigPage(char * Reply, int * ReplyLen, char * Key);
VOID ProcessConfUpdate(struct HTTPConnectionInfo * Session, char * MsgPtr, char * Reply, int * RLen, char * Rest);
VOID ProcessUIUpdate(struct HTTPConnectionInfo * Session, char * MsgPtr, char * Reply, int * RLen, char * Rest);
VOID SendUserSelectPage(char * Reply, int * ReplyLen, char * Key);
VOID SendFWDSelectPage(char * Reply, int * ReplyLen, char * Key);
int EncryptPass(char * Pass, char * Encrypt);
VOID ProcessFWDUpdate(struct HTTPConnectionInfo * Session, char * MsgPtr, char * Reply, int * RLen, char * Rest);
VOID SendStatusPage(char * Reply, int * ReplyLen, char * Key);
VOID SendUIPage(char * Reply, int * ReplyLen, char * Key);
VOID GetParam(char * input, char * key, char * value);
BOOL GetConfig(char * ConfigName);
VOID ProcessDisUser(struct HTTPConnectionInfo * Session, char * MsgPtr, char * Reply, int * RLen, char * Rest);
int APIENTRY SessionControl(int stream, int command, int param);
int SendMessageDetails(struct MsgInfo * Msg, char * Reply, char * Key);
VOID ProcessMsgUpdate(struct HTTPConnectionInfo * Session, char * MsgPtr, char * Reply, int * RLen, char * Rest);
VOID ProcessMsgAction(struct HTTPConnectionInfo * Session, char * MsgPtr, char * Reply, int * RLen, char * Rest);
int APIENTRY GetNumberofPorts();
int APIENTRY GetPortNumber(int portslot);
UCHAR * APIENTRY GetPortDescription(int portslot, char * Desc);
struct PORTCONTROL * APIENTRY GetPortTableEntryFromSlot(int portslot);
VOID SendHouseKeeping(char * Reply, int * ReplyLen, char * Key);
VOID SendWelcomePage(char * Reply, int * ReplyLen, char * Key);
VOID SaveWelcome(struct HTTPConnectionInfo * Session, char * MsgPtr, char * Reply, int * RLen, char * Key);
VOID GetMallocedParam(char * input, char * key, char ** value);
VOID SaveMessageText(struct HTTPConnectionInfo * Session, char * MsgPtr, char * Reply, int * RLen, char * Rest);
VOID SaveHousekeeping(struct HTTPConnectionInfo * Session, char * MsgPtr, char * Reply, int * RLen, char * Key);
VOID SaveWP(struct HTTPConnectionInfo * Session, char * MsgPtr, char * Reply, int * RLen, char * Key);
int SendWPDetails(WPRec * WP, char * Reply, char * Key);
int SendUserDetails(struct HTTPConnectionInfo * Session, char * Reply, char * Key);
int SetupNodeMenu(char * Buff);
VOID SendFwdSelectPage(char * Reply, int * ReplyLen, char * Key);
VOID SendFwdDetails(struct HTTPConnectionInfo * Session, char * Reply, int * ReplyLen, char * Key);
VOID SetMultiStringValue(char ** values, char * Multi);
VOID SendFwdMainPage(char * Reply, int * ReplyLen, char * Key);
VOID SaveFwdCommon(struct HTTPConnectionInfo * Session, char * MsgPtr, char * Reply, int * RLen, char * Rest);
VOID SaveFwdDetails(struct HTTPConnectionInfo * Session, char * MsgPtr, char * Reply, int * RLen, char * Rest);
char ** SeparateMultiString(char * MultiString, BOOL NoToUpper);
VOID TidyPrompts();
char * GetTemplateFromFile(int Version, char * FN);
VOID FormatTime(char * Time, time_t cTime);
struct MsgInfo * GetMsgFromNumber(int msgno);
BOOL CheckUserMsg(struct MsgInfo * Msg, char * Call, BOOL SYSOP);
BOOL OkToKillMessage(BOOL SYSOP, char * Call, struct MsgInfo * Msg);
char UNC[] = "";
char CHKD[] = "checked=checked ";
char sel[] = "selected";
char Sent[] = "#98FFA0";
char ToSend[] = "#FFFF00";
char NotThisOne[] = "#FFFFFF";
static char PassError[] = "<p align=center>Sorry, User or Password is invalid - please try again</p>";
static char BusyError[] = "<p align=center>Sorry, No sessions available - please try later</p>";
char MailSignon[] = "<html><head><title>BPQ32 Mail Server Access</title></head><body background=\"/background.jpg\">"
"<h3 align=center>BPQ32 Mail Server %s Access</h3>"
"<h3 align=center>Please enter Callsign and Password to access the BBS</h3>"
"<form method=post action=/Mail/Signon?Mail>"
"<table align=center bgcolor=white>"
"<tr><td>User</td><td><input type=text name=user tabindex=1 size=20 maxlength=50 /></td></tr>"
"<tr><td>Password</td><td><input type=password name=password tabindex=2 size=20 maxlength=50 /></td></tr></table>"
"<p align=center><input type=submit value=Submit /><input type=submit value=Cancel name=Cancel /></form>";
char WebMailSignon[] = "<html><head><title>BPQ32 Mail Server Access</title></head><body background=\"/background.jpg\">"
"<h3 align=center>BPQ32 Mail Server %s Access</h3>"
"<h3 align=center>Please enter Callsign and Password to access WebMail</h3>"
"<form method=post action=/WebMail/Signon>"
"<table align=center bgcolor=white>"
"<tr><td>User</td><td><input type=text name=user tabindex=1 size=20 maxlength=50 /></td></tr>"
"<tr><td>Password</td><td><input type=password name=password tabindex=2 size=20 maxlength=50 /></td></tr></table>"
"<p align=center><input type=submit value=Submit /><input type=submit value=Cancel name=Cancel /></form>";
char MailPage[] = "<html><head><title>%s's BBS Web Server</title></head>"
"<body background=\"/background.jpg\"><h3 align=center>BPQ32 BBS %s</h3><P>"
"<P align=center><table border=1 cellpadding=2 bgcolor=white><tr>"
"<td><a href=/Mail/Status?%s>Status</a></td>"
"<td><a href=/Mail/Conf?%s>Configuration</a></td>"
"<td><a href=/Mail/Users?%s>Users</a></td>"
"<td><a href=/Mail/Msgs?%s>Messages</a></td>"
"<td><a href=/Mail/FWD?%s>Forwarding</a></td>"
"<td><a href=/Mail/Wel?%s>Welcome Msgs & Prompts</a></td>"
"<td><a href=/Mail/HK?%s>Housekeeping</a></td>"
"<td><a href=/Mail/WP?%s>WP Update</a></td>"
"<td><a href=/>Node Menu</a></td>"
"</tr></table>";
char RefreshMainPage[] = "<html><head>"
"<meta http-equiv=refresh content=10>"
"<title>%s's BBS Web Server</title></head>"
"<body background=\"/background.jpg\"><h3 align=center>BPQ32 BBS %s</h3><P>"
"<P align=center><table border=1 cellpadding=2 bgcolor=white><tr>"
"<td><a href=/Mail/Status?%s>Status</a></td>"
"<td><a href=/Mail/Conf?%s>Configuration</a></td>"
"<td><a href=/Mail/Users?%s>Users</a></td>"
"<td><a href=/Mail/Msgs?%s>Messages</a></td>"
"<td><a href=/Mail/FWD?%s>Forwarding</a></td>"
"<td><a href=/Mail/Wel?%s>Welcome Msgs & Prompts</a></td>"
"<td><a href=/Mail/HK?%s>Housekeeping</a></td>"
"<td><a href=/Mail/WP?%s>WP Update</a></td>"
"<td><a href=/>Node Menu</a></td>"
"</tr></table>";
char StatusPage [] =
"<form style=\"font-family: monospace; text-align: center\" method=post action=/Mail/DisSession?%s>"
"<br>User Callsign Stream Queue<br>"
"<select style=\"font-family: monospace;\" tabindex=1 size=10 name=call>";
char StatusTail [] =
"</select><br><input name=Disconnect value=Disconnect type=submit><br><br>"
"Msgs <input readonly=readonly value=%d size=3><br>"
"Sysop Msgs <input readonly=readonly value=%d size=3><br>"
"Held Msgs <input readonly=readonly value=%d size=3><br>"
"SMTP Msgs <input readonly=readonly value=%d size=3><br></form>";
char UIHddr [] = "<form style=\"font-family: monospace;\" align=center method=post"
" action=/Mail/UI?%s> Mailfor Header <input size=40 value=\"%s\" name=MailFor><br>"
" "
" (use \\r to insert newline in message)<br><br>"
"Enable Port "
" Path "
" Send: MailFor Headers Empty Mailfor<br><br>";
char UILine[] = "<input %sname=En%d type=checkbox> %s <input size=40 value=\"%s\" name=Path%d>"
" <input %sname=SndMF%d type=checkbox>"
" <input %sname=SndHDDR%d type=checkbox>"
" <input %sname=SndNull%d type=checkbox><br>";
char UITail[] = "<br><br><input name=Update value=Update type=submit> "
"<input name=Cancel value=Cancel type=submit><br></form>";
char FWDSelectHddr[] =
"<form style=\"font-family: monospace; text-align: center;\" method=post action=/Mail/FWDSel?%s>"
"Max Size to Send <input value=%d size=3 name=MaxTX><br>"
"Max Size to Receive <input value=%d size=3 name=MaxRX><br>"
"Warn if no route for P or T <input %sname=WarnNoRoute type=checkbox><br>"
"Use Local Time "
"<input %sname=LocalTime type=checkbox><br><br>"
"Aliases Select BBS<br>"
"<textarea rows=10 cols=20 name=Aliases>%s</textarea>  <select tabindex=1 size=10 name=call>";
char FWDSelectTail[] =
"</select><br> <input name=Save value=Save type=submit> <input "
"name=Cancel value=Cancel type=submit> "
" <input name=Select value=Select type=submit></form>";
char UserSelectHddr[] =
"<form style=\"font-family: monospace; text-align: center\" method=post action=/Mail/Users?%s>"
"Please Select User<br><br><select tabindex=1 size=10 name=call>";
char UserSelectLine[] = "<option value=%s>%s</option>";
char StatusLine[] = "<option value=%d>%s</option>";
char UserSelectTail[] = "</select><br><br>"
"<input size=6 value=\"\" name=NewCall>"
"<input type=submit value=\"Add User\" name=Adduser><br>"
"<input type=submit value=Select> "
"<input type=submit value=Cancel name=Cancel><br></form>";
char UserUpdateHddr[] =
"<h3 align=center>Update User %s</h3>"
"<form style=\"font-family: monospace; text-align: center\" method=post action=/Mail/Users?%s>";
char UserUpdateLine[] = "<option value=%s>%s</option>";
//<option value="G8BPQ">G8BPQ</option>
//<input checked="checked" name=%s type="checkbox"><br>
char FWDUpdate[] =
"<h3 align=center>Update Forwarding for BBS %s</h3>"
"<form style=\"font-family: monospace; text-align: center\" method=post action=/Mail/FWD?%s"
" name=Test> "
"TO "
"AT "
"TIMES Connect Script<br>"
"<textarea wrap=hard rows=10 cols=10 name=TO>%s</textarea>"
" <textarea wrap=hard rows=10 cols=10 name=AT>%s</textarea>"
" <textarea wrap=hard rows=10 cols=10 name=Times>%s</textarea>"
" <textarea wrap=hard rows=10 cols=20 name=FWD>%s</textarea><br>"
"<textarea wrap=hard rows=10 cols=30 name=HRB>%s</textarea>"
" <textarea wrap=hard rows=10 cols=30 name=HRP>%s</textarea><br><br>"
"Enable Forwarding <input %sname=EnF type=checkbox> Interval"
"<input value=%d size=3 name=Interval>(Secs) Request Reverse"
"<input %sname=EnR type=checkbox> Interval <input value=%d size=3 "
"name=RInterval>(Secs)<br>"
"Send new messages without waiting for poll timer<input %sname=NoWait type=checkbox><br>"
"BBS HA <input value=%s size=60 name=BBSHA> FBB Max Block <input "
"value=%d size=3 name=FBBBlock><br>"
"Send Personal Mail Only <input %sname=Personal type=checkbox> "
"Allow Binary <input %sname=Bin type=checkbox> Use B1 "
"Protocol <input %sname=B1 type=checkbox> Use B2 Protocol<input "
"%sname=B2 type=checkbox><br><br>"
"<input name=Submit value=Update type=submit> <input name=Fwd value=\"Start Forwarding\" type=submit> "
"<input name=Cancel value=Cancel type=submit></form><br></body></html>";
static char MailDetailPage[] =
"<html><head><meta content=\"text/html; charset=ISO-8859-1\" http-equiv=\"content-type\">"
"<title>MsgEdit</title></head><body><h4>Message %d</h4>"
"<form style=\"font-family: monospace;\" method=post action=/Mail/Msg?%s name=Msgs>"
"From <input style=\"font-family: monospace;\" size=10 name=From value=%s> Sent "
" <input readonly=readonly size=12 name=Sent value=\"%s\"> "
"Type <select tabindex=1 size=1 name=Type>"
"<option %s value=B>B</option>"
"<option %s value=P>P</option>"
"<option %s value=T>T</option>"
"</select><br>"
"To <input style=\"font-family: monospace;\" size=10 name=To value=%s>"
" Received <input readonly=readonly size=12 name=RX value=\"%s\"> "
"Status <select tabindex=1 size=1 name=Status>"
"<option %s value=N>N</option>"
"<option %s value=Y>Y</option>"
"<option %s value=F>F</option>"
"<option %s value=K>K</option>"
"<option %s value=H>H</option>"
"<option %s value=D>D</option>"
"<option %s value=$>$</option>"
"</select><br>"
"BID <input style=\"width:100px; font-family: monospace; \" name=BID value=\"%s\"> Last Changed <input readonly=readonly size=12 name=LastChange value=\"%s\"> "
"Size <input readonly=readonly size=5 name=Size value=%d><br><br>"
"%s" // Email from Line
" VIA <input style=\"width:360px;\" name=VIA value=%s><br>"
"Title <input style=\"width:360px;\" name=Title value=\"%s\"> <br><br>"
"<span align = center><input onclick=editmsg(\"EditM?%s?%d\") value=\"Edit Text\" type=button> "
"<input onclick=save(this.form) value=Save type=button> "
"<td><a href=/Mail/SaveMessage?%s><button type = button>Save Message</button></a></td>"
"<td><a href=/Mail/SaveAttachment?%s><button type = button %s>Save Attachment</button></a></td>"
//"<input onclick=doit(\"SavetoFile\") value=\"Save to File\" type=button> "
"<input onclick=doit(\"Print\") value=Print type=button> "
"<input onclick=doit(\"Export\") value=Export type=button></span><br><br>"
"Green = Sent, Yellow = Queued"
"<table style=\"text-align: left; width: 490px; font-family: monospace; align=center \" border=1 cellpadding=2 cellspacing=2>";
char MailDetailTail[] = "</table></form>";
char Welcome[] = "<form style=\"font-family: monospace; text-align: center;\""
"method=post action=/Mail/Welcome?%s>"
"Normal User Welcome<br>"
"<textarea cols=80 rows=3 name=NUWelcome>%s</textarea><br>"
"New User Welcome<br>"
"<textarea cols=80 rows=3 name=NewWelcome>%s</textarea><br>"
"Expert User Welcome<br>"
"<textarea cols=80 rows=3 name=ExWelcome>%s</textarea><br>"
"Normal User Prompt<br>"
"<textarea cols=80 rows=3 name=NUPrompt>%s</textarea><br>"
"New User Prompt<br>"
"<textarea cols=80 rows=3 name=NewPrompt>%s</textarea><br>"
"Expert User Prompt<br>"
"<textarea cols=80 rows=1 name=ExPrompt>%s</textarea><br>"
"Signoff<br>"
"<textarea cols=80 rows=1 name=Bye>%s</textarea><br><br>"
"$U:Callsign of the user $I:First name of the user $X:Messages for user $x:Unread messages<br>"
"$L:Number of the latest message $N:Number of active messages. $Z:Last message read by user<br><br>"
"<input name=Save value=Save type=submit> <inputcname=Cancel value=Cancel type=submit></form>";
static char MsgEditPage[] = "<html><head><meta content=\"text/html; charset=ISO-8859-1\" http-equiv=\"content-type\">"
"<title></title></head><body>"
"<form style=\"font-family: monospace; text-align: center;\"method=post action=EMSave?%s>"
"<textarea cols=90 rows=33 name=Msg>%s</textarea><br><br>"
"<input name=Save value=Save type=submit><input name=Cancel value=Cancel type=submit><br></form>";
static char MsgInputPage[] = "<html><head><meta content=\"text/html; charset=ISO-8859-1\" http-equiv=\"content-type\">"
"<title></title></head><body>"
"<form style=\"font-family: monospace; \"method=post action=EMSave?%s>"
"To <input size=60 value=\"%s\" name=To><br>"
"Subject <input size=60 name=Subj value=\"%s\"><br>"
"Type <select tabindex=1 size=1 name=Type>"
"<option value=P>P</option><option value=B>B</option><option value=T>T</option>"
"</select> BID <input name=BID><br>"
"<textarea cols=90 rows=33 name=Msg></textarea><br><br>"
"<div style=\"text-align: center;\"><input name=Send value=Send type=submit><input name=Cancel value=Cancel type=submit></div><br></form>";
static char WPDetail[] = "<form style=\"font-family: monospace;\" method=post action=/Mail/WP?%s>"
"<br><table style=\"text-align: left; width: 431px;\" border=0 cellpadding=2 cellspacing=2><tbody>"
"<tr><td>Call</td><td><input readonly=readonly size=10 value=\"%s\"></td></tr>"
"<tr><td>Name</td><td><input size=30 name=Name value=\"%s\"></td></tr>"
"<tr><td>Home BBS 1</td><td><input size=40 name=Home1 value=%s></td></tr>"
"<tr><td>Home BBS 2</td><td><input size=40 name=Home2 value %s></td></tr>"
"<tr><td>QTH 1</td><td><input size=40 name=QTH1 value=\"%s\"></td></tr>"
"<tr><td>QTH 2</td><td><input size=40 name=QTH2 value=\"%s\"></td></tr>"
"<tr><td>ZIP 1<br></td><td><input size=10 name=ZIP1 value=%s></td></tr>"
"<tr><td>ZIP 2<br></td><td><input size=10 name=ZIP2 value=%s></td></tr>"
"<tr><td>Last Seen<br></td><td><input size=15 name=Seen value=\"%s\"></td></tr>"
"<tr><td>Last Modified<br></td><td><input size=15 name=Modif value=\"%s\"></td></tr>"
"<tr><td>Type<br></td><td><input size=4 name=Type value=%c></td></tr>"
"<tr><td>Changed<br></td><td><input size=4 name=Changed value=%d></td></tr>"
"<tr><td>Seen<br></td><td><input size=4 name=Seen value=%d></td></tr></tbody></table>"
"<br><input onclick=save(this.form) value=Save type=button> "
"<input onclick=del(this.form) value=Delete type=button> "
"<input name=Cancel value=Cancel type=submit></form>";
static char LostSession[] = "<html><body>"
"<form style=\"font-family: monospace; text-align: center;\" method=post action=/Mail/Lost?%s>"
"Sorry, Session had been lost<br><br> "
"<input name=Submit value=Restart type=submit> <input type=submit value=Exit name=Cancel><br></form>";
char * MsgEditTemplate = NULL;
char * HousekeepingTemplate = NULL;
char * ConfigTemplate = NULL;
char * WPTemplate = NULL;
char * UserListTemplate = NULL;
char * UserDetailTemplate = NULL;
char * FwdTemplate = NULL;
char * FwdDetailTemplate = NULL;
char * WebMailTemplate = NULL;
char * WebMailMsgTemplate = NULL;
char * jsTemplate = NULL;
static struct HTTPConnectionInfo * WebSessionList; // active WebMail sessions
#ifdef LINBPQ
UCHAR * GetBPQDirectory();
#endif
static int compare(const void *arg1, const void *arg2)
{
// Compare Calls. Fortunately call is at start of stuct
return _stricmp(*(char**)arg1 , *(char**)arg2);
}
int SendHeader(char * Reply, char * Key)
{
return sprintf(Reply, MailPage, BBSName, BBSName, Key, Key, Key, Key, Key, Key, Key, Key);
}
struct HTTPConnectionInfo * FindWMSession(char * Key)
{
struct HTTPConnectionInfo * Session = WebSessionList;
while (Session)
{
if (strcmp(Session->Key, Key) == 0)
{
Session->WebMailLastUsed = time(NULL);
return Session;
}
Session = Session->Next;
}
return NULL;
}
struct HTTPConnectionInfo * AllocateWebMailSession()
{
int KeyVal;
struct HTTPConnectionInfo * Session, * SaveNext;
time_t NOW = time(NULL);
// First see if any session records havent been used for a while
Session = WebSessionList;
while (Session)
{
if (NOW - Session->WebMailLastUsed > 1200) // 20 Mins
{
SaveNext = Session->Next;
memset(Session, 0, sizeof(struct HTTPConnectionInfo));
Session->Next = SaveNext;
goto UseThis;
}
Session = Session->Next;
}
Session = zalloc(sizeof(struct HTTPConnectionInfo));
if (Session == NULL)
return NULL;
if (WebSessionList)
Session->Next = WebSessionList;
WebSessionList = Session;
UseThis:
KeyVal = ((rand() % 100) + 1);
KeyVal *= time(NULL);
sprintf(Session->Key, "%c%08X", 'W', KeyVal);
return Session;
}
int SendWebMailHeader(char * Reply, char * Key, struct HTTPConnectionInfo * Session)
{
struct UserInfo * User = Session->User;
char Messages[8192];
int m;
struct MsgInfo * Msg;
char * ptr = Messages;
int n = 35;
char Via[64];
int Count = 0;
ptr += sprintf(ptr, "%s", " # Date XX Len To @ From Subject\r\n\r\n");
for (m = LatestMsg; m >= 1; m--)
{
Msg = GetMsgFromNumber(m);
if (Msg && CheckUserMsg(Msg, User->Call, User->flags & F_SYSOP))
{
// List if it is the right type and in the page range we want
if (Session->WebMailTypes[0] && strchr(Session->WebMailTypes, Msg->type) == 0)
continue;
// All Types or right Type. Check Mine Flag
if (Session->WebMailMine)
{
// Only list if to or from me
if (strcmp(User->Call, Msg->to) != 0 && strcmp(User->Call, Msg->from) != 0)
continue;
}
if (Count++ < Session->WebMailSkip)
continue;
strcpy(Via, Msg->via);
strlop(Via, '.');
ptr += sprintf(ptr, "<a href=""/WebMail/WM/%d?%s"">%6d</a> %s %c%c %5d %-8s%-8s%-8s%s\r\n",
Msg->number, Key, Msg->number,
FormatDateAndTime(Msg->datecreated, TRUE), Msg->type,
Msg->status, Msg->length, Msg->to, Via,
Msg->from, Msg->title);
n--;
if (n == 0)
break;
}
}
if (WebMailTemplate == NULL)
WebMailTemplate = GetTemplateFromFile(5, "WebMailPage.txt");
return sprintf(Reply, WebMailTemplate, BBSName, User->Call, Key, Key, Key, Key, Key, Key, Key, Key, Key, Key, Messages);
}
int SendWebMailMessage(char * Reply, char * Key, struct UserInfo * User, int Number)
{
char Message[100000] = "";
struct MsgInfo * Msg;
char * ptr = Message;
char * MsgBytes, * Save;
char FullTo[100];
int Index;
Msg = GetMsgFromNumber(Number);
if (Msg == NULL)
{
ptr += sprintf(ptr, "Message %d not found\r\n", Number);
return sprintf(Reply, WebMailTemplate, BBSName, User->Call, Key, Key, Key, Key, Key, Key, Key, Key, Key, Key, Message);
}
if (!CheckUserMsg(Msg, User->Call, User->flags & F_SYSOP))
{
ptr += sprintf(ptr, "Message %d not for you\r", Number);
return sprintf(Reply, WebMailTemplate, BBSName, User->Call, Key, Key, Key, Key, Key, Key, Key, Key, Key, Key, Message);
}
if (_stricmp(Msg->to, "RMS") == 0)
sprintf(FullTo, "RMS:%s", Msg->via);
else
if (Msg->to[0] == 0)
sprintf(FullTo, "smtp:%s", Msg->via);
else
strcpy(FullTo, Msg->to);
ptr += sprintf(ptr, "From: %s%s\nTo: %s\nType/Status: %c%c\nDate/Time: %s\nBid: %s\nTitle: %s\n\n",
Msg->from, Msg->emailfrom, FullTo, Msg->type, Msg->status, FormatDateAndTime(Msg->datecreated, FALSE), Msg->bid, Msg->title);
MsgBytes = Save = ReadMessageFile(Number);
if (Msg->type == 'P')
Index = PMSG;
else if (Msg->type == 'B')
Index = BMSG;
else if (Msg->type == 'T')
Index = TMSG;
if (MsgBytes)
{
if (Msg->B2Flags)
{
char * ptr1;
// if message has attachments, display them if plain text
if (Msg->B2Flags & Attachments)
{
char * FileName[100];
int FileLen[100];
int Files = 0;
int BodyLen, NewLen;
int i;
char *ptr2;
ptr1 = MsgBytes;
ptr += sprintf(ptr, "Message has Attachments\r\n\r\n");
while(*ptr1 != 13)
{
ptr2 = strchr(ptr1, 10); // Find CR
if (memcmp(ptr1, "Body: ", 6) == 0)
{
BodyLen = atoi(&ptr1[6]);
}
if (memcmp(ptr1, "File: ", 6) == 0)
{
char * ptr3 = strchr(&ptr1[6], ' '); // Find Space
FileLen[Files] = atoi(&ptr1[6]);
FileName[Files++] = &ptr3[1];
*(ptr2 - 1) = 0;
}
ptr1 = ptr2;
ptr1++;
}
ptr1 += 2; // Over Blank Line and Separator
ptr += sprintf(ptr, "%s", ptr1);
ptr1 += BodyLen + 2; // to first file
for (i = 0; i < Files; i++)
{
int n;
char * p = ptr1;
char c;
// Check if message is probably binary
int BinCount = 0;
NewLen = RemoveLF(ptr1, FileLen[i]); // Removes LF agter CR but not on its own
for (n = 0; n < NewLen; n++)
{
c = *p;
if (c == 10)
*p = 13;
if (c==0 || (c & 128))
BinCount++;
p++;
}
if (BinCount > NewLen/10)
{
// File is probably Binary
ptr += sprintf(ptr, "\rAttachment %s is a binary file\r", FileName[i]);
}
else
{
ptr += sprintf(ptr, "\rAttachment %s\r\r", FileName[i]);
User->Total.MsgsSent[Index] ++;
User->Total.BytesForwardedOut[Index] += NewLen;
}
ptr1 += FileLen[i];
ptr1 +=2; // Over separator
}
return sprintf(Reply, WebMailMsgTemplate, BBSName, User->Call, Msg->number, Msg->number, Key, Msg->number, Key, Key, Message);
}
// Remove B2 Headers (up to the File: Line)
ptr1 = strstr(MsgBytes, "Body:");
if (ptr1)
MsgBytes = ptr1;
}
// Remove lf chars
// Length = RemoveLF(MsgBytes, strlen(MsgBytes));
User->Total.MsgsSent[Index] ++;
// User->Total.BytesForwardedOut[Index] += Length;
ptr += sprintf(ptr, "%s", MsgBytes);
free(Save);
ptr += sprintf(ptr, "\r\r[End of Message #%d from %s]\r", Number, Msg->from);
if ((_stricmp(Msg->to, User->Call) == 0) || ((User->flags & F_SYSOP) && (_stricmp(Msg->to, "SYSOP") == 0)))
{
if ((Msg->status != 'K') && (Msg->status != 'H') && (Msg->status != 'F') && (Msg->status != 'D'))
{
if (Msg->status != 'Y')
{
Msg->status = 'Y';
Msg->datechanged=time(NULL);
}
}
}
}
else
{
ptr += sprintf(ptr, "File for Message %d not found\r", Number);
}
return sprintf(Reply, WebMailMsgTemplate, BBSName, User->Call, Msg->number, Msg->number, Key, Msg->number, Key, Key, Message);
}
int KillWebMailMessage(char * Reply, char * Key, struct UserInfo * User, int Number)
{
struct MsgInfo * Msg;
char Message[100] = "";
Msg = GetMsgFromNumber(Number);
if (Msg == NULL)
{
sprintf(Message, "Message %d not found", Number);
goto returnit;
}
if (OkToKillMessage(User->flags & F_SYSOP, User->Call, Msg))
{
FlagAsKilled(Msg);
sprintf(Message, "Message #%d Killed\r", Number);
goto returnit;
}
sprintf(Message, "Not your message\r");
returnit:
return sprintf(Reply, WebMailMsgTemplate, BBSName, User->Call, Msg->number, Msg->number, Key, Msg->number, Key, Key, Message);
}
VOID UndoTransparency(char * ptr)
{
// Undo any % transparency
char * ptr1, * ptr2;
char c;
ptr1 = ptr2 = ptr;
c = *(ptr1++);
while (c)
{
if (c == '%')
{
int n;
int m = *(ptr1++) - '0';
if (m > 9) m = m - 7;
n = *(ptr1++) - '0';
if (n > 9) n = n - 7;
*(ptr2++) = m * 16 + n;
}
else if (c == '+')
*(ptr2++) = ' ';
else
*(ptr2++) = c;
c = *(ptr1++);
}
*(ptr2++) = 0;
}
VOID SaveNewMessage(struct HTTPConnectionInfo * Session, char * MsgPtr, char * Reply, int * RLen, char * Rest)
{
int ReplyLen = 0;
struct MsgInfo * Msg;
char * ptr, *input;
int MsgLen;
FILE * hFile;
char Type;
char * via = NULL;
char BID[32];
BIDRec * BIDRec;
char * MailBuffer;
char MsgFile[MAX_PATH];
int WriteLen=0;
char * HDest;
char * Title;
char * Vptr;
char * Context;
char Prompt[256] = "Message Saved";
input = strstr(MsgPtr, "\r\n\r\n"); // End of headers
if (input == NULL)
return;
if (strstr(input, "Cancel=Cancel"))
{
*RLen = sprintf(Reply, "%s", "<html><script>window.close();</script></html>");
return;
}
if (!strstr(input, "Send=Send"))
return;
ptr = strtok_s(input + 4, "&", &Context);
if (ptr)
HDest = &ptr[3];
ptr = strtok_s(NULL, "&", &Context);
if (ptr)
Title = &ptr[5];
ptr = strtok_s(NULL, "&", &Context);
if (ptr)
Type = ptr[5];
ptr = strtok_s(NULL, "&", &Context);
if (ptr)
strcpy(BID, &ptr[4]);
UndoTransparency(BID);
UndoTransparency(HDest);
UndoTransparency(Title);
strlop(BID, ' ');
if (strlen(BID) > 12)
BID[12] = 0;
ptr = strtok_s(NULL, "&", &Context);
if (ptr)
ptr+=4; // to message body
UndoTransparency(ptr);
MsgLen = strlen(ptr);
if (strlen(HDest) == 0)
{
*RLen = sprintf(Reply, "%s", "<html><script>alert(\"To: Call Missing!\");window.close();</script></html>");
return;
}
if (strlen(BID))
{
if (LookupBID(BID))
{
// Duplicate bid
*RLen = sprintf(Reply, "%s", "<html><script>alert(\"Duplicate BID\");window.close();</script></html>");
return;
}
}
if (Type == 'B')
{
if (RefuseBulls)
{
*RLen = sprintf(Reply, "%s", "<html><script>alert(\"This system doesn't allow sending Bulls\");window.close();</script></html>");
return;
}
if (Session->User->flags & F_NOBULLS)
{
*RLen = sprintf(Reply, "%s", "<html><script>alert(\"You are not allowed to send Bulls\");window.close();</script></html>");
return;
}
}
Msg = AllocateMsgRecord();
// Set number here so they remain in sequence
Msg->number = ++LatestMsg;
MsgnotoMsg[Msg->number] = Msg;
strcpy(Msg->from, Session->User->Call);
if (_memicmp(HDest, "rms:", 4) == 0 || _memicmp(HDest, "rms/", 4) == 0)
{
Vptr=&HDest[4];
strcpy(Msg->to, "RMS");
}
else if (_memicmp(HDest, "smtp:", 5) == 0)
{
if (ISP_Gateway_Enabled)
{
Vptr=&HDest[5];
Msg->to[0] = 0;
}
}
else
{
Vptr = strlop(HDest, '@');
strcpy(Msg->to, _strupr(HDest));
}
if (SendBBStoSYSOPCall)
if (_stricmp(HDest, BBSName) == 0)
strcpy(Msg->to, SYSOPCall);
if (Vptr)
{
if (strlen(Vptr) > 40)
Vptr[40] = 0;
strcpy(Msg->via, _strupr(Vptr));
}
else
{
// No via. If not local user try to add BBS
struct UserInfo * ToUser = LookupCall(Msg->to);
if (ToUser)
{
// Local User. If Home BBS is specified, use it
if (ToUser->HomeBBS[0])
{
strcpy(Msg->via, ToUser->HomeBBS);
sprintf(Prompt, "%s added from HomeBBS", Msg->via);
}
}
else
{
// Not local user - Check WP
WPRecP WP = LookupWP(Msg->to);
if (WP)
{
strcpy(Msg->via, WP->first_homebbs);
sprintf(Prompt, "%s added from WP", Msg->via);
}
}
}
if (strlen(Title) > 60)
Title[60] = 0;
strcpy(Msg->title,Title);
Msg->type = Type;
Msg->status = 'N';
if (strlen(BID) == 0)
sprintf_s(BID, sizeof(BID), "%d_%s", LatestMsg, BBSName);
strcpy(Msg->bid, BID);
Msg->datereceived = Msg->datechanged = Msg->datecreated = time(NULL);
BIDRec = AllocateBIDRecord();
strcpy(BIDRec->BID, Msg->bid);
BIDRec->mode = Msg->type;
BIDRec->u.msgno = LOWORD(Msg->number);
BIDRec->u.timestamp = LOWORD(time(NULL)/86400);
MailBuffer = malloc(MsgLen + 2000); // Allow for a B2 Header if attachments
Msg->length = MsgLen;
sprintf_s(MsgFile, sizeof(MsgFile), "%s/m_%06d.mes", MailDir, Msg->number);
hFile = fopen(MsgFile, "wb");
if (hFile)
{
WriteLen = fwrite(ptr, 1, Msg->length, hFile);
fclose(hFile);
}
MatchMessagetoBBSList(Msg, 0);
BuildNNTPList(Msg); // Build NNTP Groups list
SaveMessageDatabase();
SaveBIDDatabase();
*RLen = sprintf(Reply, "<html><script>alert(\"%s\");window.close();</script></html>", Prompt);
return;
}
void ProcessMailHTTPMessage(struct HTTPConnectionInfo * Session, char * Method, char * URL, char * input, char * Reply, int * RLen)
{
char * Context = 0, * NodeURL;
int ReplyLen;
BOOL LOCAL = FALSE;
char * Key;
char Appl = 'M';
if (URL[0] == 0 || Method == NULL)
return;
if (strstr(input, "Host: 127.0.0.1"))
LOCAL = TRUE;