-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cmd.c
5341 lines (3981 loc) · 119 KB
/
Cmd.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-2018 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
*/
//
// C replacement for cmd.asm
//
#define Kernel
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_32BIT_TIME_T
#pragma data_seg("_BPQDATA")
//#include "windows.h"
//#include "winerror.h"
#include "time.h"
#include "stdio.h"
#include <fcntl.h>
//#include "vmm.h"
//#include "SHELLAPI.H"
#include "CHeaders.h"
#pragma pack()
#include "tncinfo.h"
#include "telnetserver.h"
//#include "GetVersion.h"
//#define DllImport __declspec( dllimport )
//#define DllExport __declspec( dllexport )
BOOL DecodeCallString(char * Calls, BOOL * Stay, BOOL * Spy, UCHAR *AXCalls);
VOID Send_AX_Datagram(PDIGIMESSAGE Block, DWORD Len, UCHAR Port);
int APIENTRY ClearNodes();
VOID GetJSONValue(char * _REPLYBUFFER, char * Name, char * Value);
VOID SendHTTPRequest(SOCKET sock, char * Host, int Port, char * Request, char * Params, int Len, char * Return);
SOCKET OpenWL2KHTTPSock();
VOID FormatTime3(char * Time, time_t cTime);
VOID Format_Addr(unsigned char * Addr, char * Output, BOOL IPV6);
VOID Tel_Format_Addr(struct ConnectionInfo * sockptr, char * dst);
VOID FindLostBuffers();
BOOL CheckCMS(struct TNCINFO * TNC);
VOID L2SENDXID(struct _LINKTABLE * LINK);
char COMMANDBUFFER[81] = ""; // Command Hander input buffer
char OrigCmdBuffer[81] = ""; // Command Hander input buffer
struct DATAMESSAGE * REPLYBUFFER = NULL;
UINT APPLMASK = 0;
UCHAR SAVEDAPPLFLAGS = 0;
UCHAR ALIASINVOKED = 0;
VOID * CMDPTR = 0;
short CMDPACLEN = 0;
char OKMSG[] = "Ok\r";
char CMDERRMSG[] = "Invalid command - Enter ? for command list\r";
#define CMDERRLEN sizeof(CMDERRMSG) - 1
char PASSWORDMSG[] = "Command requires SYSOP status - enter password\r";
#define LPASSMSG sizeof(PASSWORDMSG) - 1
char CMDLIST[] = "CONNECT BYE INFO NODES PORTS ROUTES USERS MHEARD";
#define CMDLISTLEN sizeof(CMDLIST) - 1
char BADMSG[] = "Bad Parameter\r";
char BADPORT[] = "Invalid Port Number\r";
char NOTEXTPORT[] = "Only valid on EXT ports\r";
char NOVALCALLS[] = "No Valid Calls defined on this port\r";
char BADVALUEMSG[] = "Invalid parameter\r";
char BADCONFIGMSG[] = "Configuration File check falled - will continue with old config\r";
#ifdef LINBPQ
char REBOOTOK[] = "Rebooting\r";
#else
char REBOOTOK[] = "Rebooting in 20 secs\r";
#endif
char REBOOTFAILED[] = "Shutdown failed\r";
char RESTARTOK[] = "Restarting\r";
char RESTARTFAILED[] = "Restart failed\r";
UCHAR ARDOP[7] = {'A'+'A','R'+'R','D'+'D','O'+'O','P'+'P',' '+' '}; // ARDOP IN AX25
int STATSTIME = 0;
int MAXBUFFS = 0;
int QCOUNT = 0;
int MINBUFFCOUNT = 65535;
int NOBUFFCOUNT = 0;
int BUFFERWAITS = 0;
int MAXDESTS = 0;
int NUMBEROFNODES = 0;
int L4CONNECTSOUT = 0;
int L4CONNECTSIN = 0;
int L4FRAMESTX = 0;
int L4FRAMESRX = 0;
int L4FRAMESRETRIED = 0;
int OLDFRAMES = 0;
int L3FRAMES = 0;
VOID SENDSABM();
VOID RESET2();
int APPL1 = 0;
int PASSCMD = 0;
#pragma pack (1)
struct _EXTPORTDATA DP; // Only way I can think of to get offets to port data into cmd table
char CMDALIAS[ALIASLEN][NumberofAppls] = {0};
char * ALIASPTR = &CMDALIAS[0][0];
CMDX COMMANDS[];
int CMDXLEN = sizeof (CMDX);
VOID SENDNODESMSG();
VOID KISSCMD(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD);
VOID STOPCMS(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD);
VOID STARTCMS(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD);
VOID STOPPORT(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD);
VOID STARTPORT(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD);
VOID FINDBUFFS(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD);
VOID WL2KSYSOP(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD);
VOID AXRESOLVER(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD);
VOID AXMHEARD(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD);
VOID SHOWTELNET(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD);
VOID SHOWAGW(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD);
VOID SHOWARP(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD);
VOID SHOWNAT(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD);
VOID PING(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD);
VOID SHOWIPROUTE(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD);
VOID FLMSG(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * UserCMD);
void ListExcludedCalls(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD);
VOID SENDNODES(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD)
{
SENDNODESMSG();
strcpy(Bufferptr, OKMSG);
Bufferptr += strlen(OKMSG);
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
}
VOID SAVENODES(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD)
{
SaveNodes();
strcpy(Bufferptr, OKMSG);
Bufferptr += strlen(OKMSG);
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
}
VOID DUMPCMD(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD)
{
char * ptr = 0;
*ptr = 0;
strcpy(Bufferptr, OKMSG);
Bufferptr += strlen(OKMSG);
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
}
VOID RECONFIG(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD)
{
if (Reconfig())
{
strcpy(Bufferptr, OKMSG);
Bufferptr += strlen(OKMSG);
}
else
{
strcpy(Bufferptr, BADCONFIGMSG);
Bufferptr += strlen(BADCONFIGMSG);
}
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
}
VOID REBOOT(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD)
{
if (Reboot())
{
strcpy(Bufferptr, REBOOTOK);
Bufferptr += strlen(REBOOTOK);
}
else
{
strcpy(Bufferptr, REBOOTFAILED);
Bufferptr += strlen(REBOOTFAILED);
}
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
}
VOID RESTART(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD)
{
if (Restart())
{
strcpy(Bufferptr, RESTARTOK);
Bufferptr += strlen(RESTARTOK);
}
else
{
strcpy(Bufferptr, RESTARTFAILED);
Bufferptr += strlen(RESTARTFAILED);
}
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
}
UCHAR VALNODESFLAG = 0, EXTONLY = 0;
VOID PORTVAL (TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD);
VOID VALNODES(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD)
{
VALNODESFLAG = 1;
PORTVAL(Session, Bufferptr, CmdTail, CMD);
}
VOID EXTPORTVAL(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD)
{
EXTONLY = 1;
PORTVAL(Session, Bufferptr, CmdTail, CMD);
}
VOID PORTVAL(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD)
{
// PROCESS PORT VALUE COMMANDS
char * ptr, *Context, * ptr1;
int portno;
UCHAR oldvalue, newvalue;
struct PORTCONTROL * PORT = PORTTABLE;
int n = NUMBEROFPORTS;
UINT offset, DPBASE;
UCHAR * valueptr;
// Get port number
ptr = strtok_s(CmdTail, " ", &Context);
if (ptr)
{
portno = atoi (ptr);
if (portno)
{
while (n--)
{
if (PORT->PORTNUMBER == portno)
{
if (VALNODESFLAG)
{
char * VNPtr = PORT->PERMITTEDCALLS;
char Normcall[10];
int len;
VALNODESFLAG = 0;
if (VNPtr)
{
while (VNPtr[0])
{
Bufferptr = CHECKBUFFER(Session, Bufferptr); // ENSURE ROOM
len = ConvFromAX25(VNPtr, Normcall);
len++; // Add a space
memcpy(Bufferptr, Normcall, len);
Bufferptr += len;
VNPtr += 7;
}
*(Bufferptr++) = 13;
}
else
{
strcpy(Bufferptr, NOVALCALLS);
Bufferptr += strlen(NOVALCALLS);
}
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
return;
}
if (EXTONLY)
{
// Make sure an Extenal Port
EXTONLY = 0;
if (PORT->PORTTYPE != 0x10)
{
strcpy(Bufferptr, NOTEXTPORT);
Bufferptr += strlen(NOTEXTPORT);
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
return;
}
}
valueptr = (UCHAR *)PORT;
offset = (UINT)CMD->CMDFLAG;
DPBASE = (UINT)&DP;
offset -= DPBASE;
valueptr += offset;
oldvalue = (UCHAR)*valueptr;
// Display Param Namee
ptr1 = &CMD->String[0];
n = 12;
while (*(ptr1) != ' ' && n--)
*(Bufferptr++) = *(ptr1++);
// See if another param - if not, just display current value
ptr = strtok_s(NULL, " ", &Context);
if (ptr && ptr[0])
{
// Get new value
newvalue = atoi(ptr);
*valueptr = newvalue;
Bufferptr += sprintf(Bufferptr, " was %d now %d\r", oldvalue, newvalue);
}
else
Bufferptr += sprintf(Bufferptr, " %d\r", oldvalue);
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
return;
}
PORT = PORT->PORTPOINTER;
}
}
}
// Bad port
strcpy(Bufferptr, BADPORT);
Bufferptr += strlen(BADPORT);
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
return;
}
VOID SWITCHVAL (TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD)
{
// Update switch 8 bit value
char * ptr, *Context, * ptr1;
UCHAR oldvalue, newvalue;
int n;
UCHAR * valueptr;
valueptr = CMD->CMDFLAG;
oldvalue = (UCHAR)*valueptr;
// Display Param Name
ptr1 = &CMD->String[0];
n = 12;
while (*(ptr1) != ' ' && n--)
*(Bufferptr++) = *(ptr1++);
// See if a param - if not, just display current value
ptr = strtok_s(CmdTail, " ", &Context);
if (ptr && ptr[0])
{
// Get new value
newvalue = atoi(ptr);
*valueptr = newvalue;
Bufferptr += sprintf(Bufferptr, " was %d now %d\r", oldvalue, newvalue);
}
else
Bufferptr += sprintf(Bufferptr, " %d\r", oldvalue);
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
return;
}
VOID SWITCHVALW (TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD)
{
// Update switch 16 bit value
char * ptr, *Context, * ptr1;
USHORT oldvalue, newvalue;
int n;
USHORT * valueptr;
valueptr = CMD->CMDFLAG;
oldvalue = (USHORT)*valueptr;
// Display Param Name
ptr1 = &CMD->String[0];
n = 12;
while (*(ptr1) != ' ' && n--)
*(Bufferptr++) = *(ptr1++);
// See if a param - if not, just display current value
ptr = strtok_s(CmdTail, " ", &Context);
if (ptr && ptr[0])
{
// Get new value
newvalue = atoi(ptr);
*valueptr = newvalue;
Bufferptr += sprintf(Bufferptr, " was %d now %d\r", oldvalue, newvalue);
}
else
Bufferptr += sprintf(Bufferptr, " %d\r", oldvalue);
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
return;
}
TRANSPORTENTRY * SetupSessionFromSession(TRANSPORTENTRY * Session, PBPQVECSTRUC HOSTSESS, UINT APPLMASK)
{
// Create a Transport (L4) session linked to an incoming Session
TRANSPORTENTRY * NewSess = L4TABLE;
int Index = 0;
while (Index < MAXCIRCUITS)
{
if (NewSess->L4USER[0] == 0)
{
// Got One
UCHAR * ourcall = &MYCALL[0];
Session->L4CROSSLINK = NewSess;
NewSess->L4CROSSLINK = Session;
if (APPLMASK)
{
// Circuit for APPL - look for an APPLCALL
APPLCALLS * APPL = APPLCALLTABLE;
while ((APPLMASK & 1) == 0)
{
APPLMASK >>= 1;
APPL++;
}
if (APPL->APPLCALL[0] > 0x40) // We have an applcall
ourcall = &APPL->APPLCALL[0];
}
memcpy(NewSess->L4USER, ourcall, 7);
memcpy(NewSess->L4MYCALL, Session->L4MYCALL, 7);
NewSess->CIRCUITINDEX = Index; //OUR INDEX
NewSess->CIRCUITID = NEXTID;
NEXTID++;
if (NEXTID == 0)
NEXTID++; // kEEP nON-ZERO
NewSess->SESSIONT1 = Session->SESSIONT1;
NewSess->L4WINDOW = (UCHAR)L4DEFAULTWINDOW;
NewSess->SESSPACLEN = PACLEN; // Default;
NewSess->L4TARGET.HOST = HOSTSESS;
NewSess->L4STATE = 5;
return NewSess;
}
Index++;
NewSess++;
}
return NULL;
}
extern int GETCONNECTIONINFO();
BOOL cATTACHTOBBS(TRANSPORTENTRY * Session, UINT Mask, int Paclen, int * AnySessions)
{
PBPQVECSTRUC HOSTSESS = BPQHOSTVECTOR;
TRANSPORTENTRY * NewSess;
int ApplNum;
int n = BPQHOSTSTREAMS;
int ConfigedPorts = 0;
// LOOK FOR A FREE HOST SESSION
while (n--)
{
if (HOSTSESS->HOSTAPPLMASK & Mask)
{
// Right appl
ConfigedPorts++;
if (HOSTSESS->HOSTSESSION == NULL && (HOSTSESS->HOSTFLAGS & 3) == 0) // Not attached and no report outstanding
{
// WEVE GOT A FREE BPQ HOST PORT - USE IT
NewSess = SetupSessionFromSession(Session, HOSTSESS, Mask);
if (NewSess == NULL)
return FALSE; // Appl not available
HOSTSESS->HOSTSESSION = NewSess;
// Convert APPLMASK to APPLNUM
ApplNum = 1;
while (APPLMASK && (APPLMASK & 1) == 0)
{
ApplNum++;
APPLMASK >>= 1;
}
HOSTSESS->HOSTAPPLNUM = ApplNum;
HOSTSESS->HOSTFLAGS |= 2; // Indicate State Change
NewSess->L4CIRCUITTYPE = BPQHOST | DOWNLINK;
PostStateChange(NewSess);
NewSess->SESS_APPLFLAGS = HOSTSESS->HOSTAPPLFLAGS;
NewSess->SESSPACLEN = Paclen;
return TRUE;
}
}
HOSTSESS++;
}
*AnySessions = ConfigedPorts; // to distinguish between none and all in use
return FALSE;
}
VOID APPLCMD(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD)
{
BOOL CONFAILED = 0;
UINT CONERROR ;
char APPName[13];
char * ptr1, *ptr2;
int n = 12;
BOOL Stay = FALSE;
// Copy Appl and Null Terminate
ptr1 = &CMD->String[0];
ptr2 = APPName;
while (*(ptr1) != ' ' && n--)
*(ptr2++) = *(ptr1++);
*(ptr2) = 0;
if (Session->LISTEN)
{
Bufferptr += sprintf(Bufferptr, "Can't use %s while listening\r", APPName);
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
return;
}
if (CmdTail[0] == 'S')
Stay = TRUE;
Session->STAYFLAG = Stay;
memcpy(Session->APPL, CMD->String, 12);
// SEE IF THERE IS AN ALIAS DEFINDED FOR THIS COMMAND
if (ALIASPTR[0] > ' ')
{
// COPY ALIAS TO COMMAND BUFFER, THEN REENTER COMMAND HANDLER
memcpy(COMMANDBUFFER, ALIASPTR, ALIASLEN);
_strupr(COMMANDBUFFER);
memcpy(OrigCmdBuffer, ALIASPTR, ALIASLEN); // In case original case version needed
ALIASINVOKED = 1; // To prevent Alias Loops
DoTheCommand(Session);
return;
}
if (cATTACHTOBBS(Session, APPLMASK, CMDPACLEN, &CONERROR) == 0)
{
// No Streams
if (CONERROR)
Bufferptr += sprintf(Bufferptr, "Sorry, All %s Ports are in use - Please try later\r", APPName);
else
Bufferptr += sprintf(Bufferptr, "Sorry, Application %s is not running - Please try later\r", APPName);
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
return;
}
// IF CMD_TO_APPL SET IN APPLFLAGS, SEND INPUT MSG TO APPL
if (Session->L4CROSSLINK->SESS_APPLFLAGS & CMD_TO_APPL)
{
struct DATAMESSAGE * Msg = (struct DATAMESSAGE *)GetBuff();
TRANSPORTENTRY * XSession = Session->L4CROSSLINK;
if (Msg)
{
COMMANDBUFFER[72] = 13;
memcpy(Msg->L2DATA, COMMANDBUFFER, 73);
Msg->LENGTH = 81;
Msg->PID = 0xf0;
C_Q_ADD(&XSession->L4TX_Q, (UINT *)Msg);
PostDataAvailable(XSession);
}
}
if (Stay)
Session->L4CROSSLINK->L4TARGET.HOST->HOSTFLAGS |= 0x20;
// IF MSG_TO_USER SET, SEND 'CONNECTED' MESSAGE TO USER
Session->SESS_APPLFLAGS = Session->L4CROSSLINK->SESS_APPLFLAGS;
if (Session->L4CROSSLINK->SESS_APPLFLAGS & MSG_TO_USER)
{
Bufferptr += sprintf(Bufferptr, "Connected to %s\r", APPName);
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
return;
}
// DONT NEED BUFFER ANY MORE
ReleaseBuffer((UINT *)REPLYBUFFER);
return;
}
VOID CMDI00(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD)
{
Bufferptr = MOVEANDCHECK(Session, Bufferptr, INFOMSG, INFOLEN);
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
}
VOID CMDV00(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD)
{
Bufferptr += sprintf(Bufferptr, "Version %s\r", VersionString);
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
}
VOID BYECMD(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD)
{
CLOSECURRENTSESSION(Session); // Kills any crosslink, plus local link
ReleaseBuffer((UINT *)REPLYBUFFER);
return;
}
VOID CMDPAC(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD)
{
// SET PACLEN FOR THIS SESSION
char * ptr, *Context;
int newvalue;
ptr = strtok_s(CmdTail, " ", &Context);
if (ptr && ptr[0])
{
// Get new value
newvalue = atoi(ptr);
if (newvalue > 29 && newvalue < 256)
Session->SESSPACLEN = newvalue & 0xff;
}
Bufferptr += sprintf(Bufferptr, "PACLEN - %d\r", Session->SESSPACLEN);
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
}
VOID CMDIDLE(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD)
{
// SET IDLETIME FOR THIS SESSION
char * ptr, *Context;
int newvalue;
ptr = strtok_s(CmdTail, " ", &Context);
if (ptr && ptr[0])
{
// Get new value
newvalue = atoi(ptr);
if (newvalue > 59 && newvalue < 901)
Session->L4LIMIT = newvalue;
}
Bufferptr += sprintf(Bufferptr, "IDLETIME - %d\r", Session->L4LIMIT);
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
}
VOID CMDT00(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD)
{
// SET L4 TIMEOUT FOR CONNECTS ON THIS SESSION
char * ptr, *Context;
int newvalue;
ptr = strtok_s(CmdTail, " ", &Context);
if (ptr && ptr[0])
{
// Get new value
newvalue = atoi(ptr);
if (newvalue > 20)
Session->SESSIONT1 = newvalue;
}
Bufferptr += sprintf(Bufferptr, "L4TIMEOUT - %d\r", Session->SESSIONT1);
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
}
UCHAR PWLen;
char PWTEXT[80];
VOID PWDCMD(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD)
{
char * ptr, *Context;
USHORT pwsum = 0;
int n = 5, p1, p2, p3, p4, p5;
if (Session->Secure_Session) // HOST - SET AUTHORISED REGARDLESS
{
Session->PASSWORD = 0xFFFF; // SET AUTHORISED
Session->Secure_Session = 1;
strcpy(Bufferptr, OKMSG);
Bufferptr += strlen(OKMSG);
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
return;
}
ptr = strtok_s(CmdTail, " ", &Context);
if (ptr && ptr[0])
{
// Check Password
n = 5;
while (n--)
pwsum += *(ptr++);
if (Session->PASSWORD == pwsum)
{
Session->PASSWORD = 0xFFFF; // SET AUTHORISED
Session->Secure_Session = 1;
strcpy(Bufferptr, OKMSG);
Bufferptr += strlen(OKMSG);
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
return;
}
ReleaseBuffer((UINT *)REPLYBUFFER);
return;
}
// SEND PASSWORD PROMPT
if (PWLen == 0)
PWLen = 1;
p1 = rand() % PWLen;
pwsum += PWTEXT[p1++];
p2 = rand() % PWLen;
pwsum += PWTEXT[p2++];
p3 = rand() % PWLen;
pwsum += PWTEXT[p3++];
p4 = rand() % PWLen;
pwsum += PWTEXT[p4++];
p5 = rand() % PWLen;
pwsum += PWTEXT[p5++];
Session->PASSWORD = pwsum;
Bufferptr += sprintf(Bufferptr, "%d %d %d %d %d\r", p1, p2, p3, p4, p5);
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
return;
}
VOID CMDSTATS(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD)
{
char * ptr, *Context;
int Port = 0, cols = NUMBEROFPORTS, i;
char * uptime;
struct PORTCONTROL * PORT = PORTTABLE;
struct PORTCONTROL * STARTPORT;
*(Bufferptr++) = 13;
// SEE IF ANY PARAM
ptr = strtok_s(CmdTail, " ", &Context);
if (ptr && ptr[0])
Port = atoi(ptr);
// IF ASKING FOR PORT STATS, DONT DO SYSTEM ONES
if (Port == 0)
{
uptime = FormatUptime(STATSTIME);
Bufferptr += sprintf(Bufferptr, "%s", uptime);
Bufferptr += sprintf(Bufferptr, "Semaphore Get-Rel/Clashes %9d%9d\r",
Semaphore.Gets - Semaphore.Rels, Semaphore.Clashes);
Bufferptr = CHECKBUFFER(Session, Bufferptr); // ENSURE ROOM
Bufferptr += sprintf(Bufferptr, "Buffers:Max/Cur/Min/Out/Wait%9d%9d%9d%9d%9d\r",
MAXBUFFS, QCOUNT, MINBUFFCOUNT, NOBUFFCOUNT, BUFFERWAITS);
Bufferptr = CHECKBUFFER(Session, Bufferptr); // ENSURE ROOM
Bufferptr += sprintf(Bufferptr, "Known Nodes/Max Nodes %9d%9d\r",
NUMBEROFNODES, MAXDESTS);
Bufferptr = CHECKBUFFER(Session, Bufferptr); // ENSURE ROOM
Bufferptr += sprintf(Bufferptr, "L4 Connects Sent/Rxed %9d%9d\r",
L4CONNECTSOUT, L4CONNECTSIN);
Bufferptr = CHECKBUFFER(Session, Bufferptr); // ENSURE ROOM
Bufferptr += sprintf(Bufferptr, "L4 Frames TX/RX/Resent/Reseq%9d%9d%9d%9d\r",
L4FRAMESTX, L4FRAMESRX, L4FRAMESRETRIED, OLDFRAMES);
Bufferptr = CHECKBUFFER(Session, Bufferptr); // ENSURE ROOM
Bufferptr += sprintf(Bufferptr, "L3 Frames Relayed %9d\r", L3FRAMES);
if (ptr && ptr[0] == 'S')
{
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
return;
}
}
Bufferptr = CHECKBUFFER(Session, Bufferptr); // ENSURE ROOM
// POSITION TO REQUESTED PORT
if (Port)
{
while (PORT && PORT->PORTNUMBER != Port)
{
PORT = PORT->PORTPOINTER;
cols--;
}
}
if (PORT == NULL) // REQUESTED PORT NOT FOUND
{
SendCommandReply(Session, REPLYBUFFER, Bufferptr - (char *)REPLYBUFFER);
return;
}
Bufferptr = CHECKBUFFER(Session, Bufferptr); // ENSURE ROOM
STARTPORT = PORT;
if (cols > 7)
cols = 7;
Bufferptr += sprintf(Bufferptr, " ");
for (i = 0; i < cols; i++)
{
Bufferptr += sprintf(Bufferptr, "Port %02d ", PORT->PORTNUMBER);
PORT = PORT->PORTPOINTER;
}
*(Bufferptr++) = 13;
PORT = STARTPORT;
Bufferptr = CHECKBUFFER(Session, Bufferptr); // ENSURE ROOM
Bufferptr += sprintf(Bufferptr, "L2 Frames Digied");
for (i = 0; i < cols; i++)
{
Bufferptr += sprintf(Bufferptr, "%9d", PORT->L2DIGIED);
PORT = PORT->PORTPOINTER;
}
*(Bufferptr++) = 13;
PORT = STARTPORT;
Bufferptr = CHECKBUFFER(Session, Bufferptr); // ENSURE ROOM
Bufferptr += sprintf(Bufferptr, "L2 Frames Heard ");
for (i = 0; i < cols; i++)
{
Bufferptr += sprintf(Bufferptr, "%9d", PORT->L2FRAMES);
PORT = PORT->PORTPOINTER;
}
*(Bufferptr++) = 13;
PORT = STARTPORT;
Bufferptr = CHECKBUFFER(Session, Bufferptr); // ENSURE ROOM
Bufferptr += sprintf(Bufferptr, "L2 Frames Rxed ");
for (i = 0; i < cols; i++)
{
Bufferptr += sprintf(Bufferptr, "%9d", PORT->L2FRAMESFORUS);
PORT = PORT->PORTPOINTER;
}
*(Bufferptr++) = 13;
PORT = STARTPORT;
Bufferptr = CHECKBUFFER(Session, Bufferptr); // ENSURE ROOM
Bufferptr += sprintf(Bufferptr, "L2 Frames Sent ");
for (i = 0; i < cols; i++)
{
Bufferptr += sprintf(Bufferptr, "%9d", PORT->L2FRAMESSENT);
PORT = PORT->PORTPOINTER;
}
*(Bufferptr++) = 13;
PORT = STARTPORT;
Bufferptr = CHECKBUFFER(Session, Bufferptr); // ENSURE ROOM
Bufferptr += sprintf(Bufferptr, "L2 Timeouts ");
for (i = 0; i < cols; i++)
{
Bufferptr += sprintf(Bufferptr, "%9d", PORT->L2TIMEOUTS);
PORT = PORT->PORTPOINTER;
}
*(Bufferptr++) = 13;