summaryrefslogtreecommitdiff
path: root/TelnetV6.c
diff options
context:
space:
mode:
authorDave Hibberd <hibby@debian.org>2026-09-29 21:39:24 +0100
committerDave Hibberd <hibby@debian.org>2026-09-29 21:39:24 +0100
commit592e5967b8fcd79423802071319d0c646f2080df (patch)
tree0eef3a28cfe1a939caf9d61e419a56d79b3c38e3 /TelnetV6.c
parent23de03a0c8bf8a564cc0442f49d050ed11e372b8 (diff)
New upstream version 6.0.25.41+repackupstream/6.0.25.41+repack
Diffstat (limited to 'TelnetV6.c')
-rw-r--r--TelnetV6.c156
1 files changed, 110 insertions, 46 deletions
diff --git a/TelnetV6.c b/TelnetV6.c
index abe5878..f261716 100644
--- a/TelnetV6.c
+++ b/TelnetV6.c
@@ -57,6 +57,8 @@ along with LinBPQ/BPQ32. If not, see http://www.gnu.org/licenses
extern UCHAR LogDirectory[];
extern int MONTOFILEFLAG;
+
+extern int LOCALNOTSECURE;
static char ClassName[]="TELNETSERVER";
static char WindowTitle[] = "Telnet Server";
@@ -92,6 +94,9 @@ void ProcessRHPWebSockClosed(SOCKET socket);
int ProcessSNMPPayload(UCHAR * Msg, int Len, UCHAR * Reply, int * OffPtr);
int RHPProcessHTTPMessage(struct ConnectionInfo * conn, char * response, char * Method, char * URL, char * request, BOOL LOCAL, BOOL COOKIE);
void checkNRTCPSockets(int portNo);
+int ProcessNewTermWebSock(struct ConnectionInfo * sockptr, char * Key);
+void ProcessWebTermInput(struct ConnectionInfo * sockptr, char * Payload);
+void ProcessWebTermClosed(struct ConnectionInfo * sockptr);
#ifndef LINBPQ
extern HKEY REGTREE;
@@ -182,6 +187,7 @@ int DeleteLogFile(char * Log, int KeepDays);
void DeleteLogFiles(int Age)
{
+ DeleteLogFile("NodeDebug", Age);
DeleteLogFile("Telnet", Age);
DeleteLogFile("CMSAccess_", Age);
DeleteLogFile("ConnectLog_",Age);
@@ -221,7 +227,6 @@ int DeleteLogFile(char * Log, int KeepDays)
{
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
- OutputDebugString(ffd.cFileName);
}
else
{
@@ -261,7 +266,7 @@ int DeleteLogFile(char * Log, int KeepDays)
struct dirent **namelist;
int n;
struct stat STAT;
- time_t now = time(NULL);
+ time_t now = NOW;
int Age = 0, res;
char FN[256];
@@ -527,6 +532,9 @@ int ProcessLine(char * buf, int Port)
else if (_stricmp(param,"SecureTelnet") == 0)
TCP->SecureTelnet = atoi(value);
+ else if (_stricmp(param,"noWebSocks") == 0)
+ TCP->noWebSocks = atoi(value);
+
else if (_stricmp(param,"CloseOnDisconnect") == 0)
TCP->DisconnectOnClose = atoi(value);
@@ -542,6 +550,8 @@ int ProcessLine(char * buf, int Port)
else if (_stricmp(param,"HTTPPORT") == 0)
HTTPPort = TCP->HTTPPort = atoi(value);
+
+
else if (_stricmp(param,"NETROMPORT") == 0)
TCP->NETROMPort = atoi(value);
@@ -957,7 +967,7 @@ static size_t ExtProc(int fn, int port, PDATAMESSAGE buff)
{
if (sockptr->WebSocks == 0)
{
- if (sockptr->LastSendTime && (time(NULL) - sockptr->LastSendTime) > 150) // ~ 2.5 mins
+ if (sockptr->LastSendTime && (NOW - sockptr->LastSendTime) > 150) // ~ 2.5 mins
{
closesocket(sockptr->socket);
sockptr->SocketActive = FALSE;
@@ -970,7 +980,7 @@ static size_t ExtProc(int fn, int port, PDATAMESSAGE buff)
// Normally keepalives are sent each way around every 9 mins
// Keepalives aren't sent when connecting so may need a bit longer
- if (sockptr->LastSendTime && (time(NULL) - sockptr->LastSendTime) > 20 * 60) // 20mins
+ if (sockptr->LastSendTime && (NOW - sockptr->LastSendTime) > 20 * 60) // 20mins
{
ProcessRHPWebSockClosed(sockptr->socket);
closesocket(sockptr->socket);
@@ -983,7 +993,7 @@ static size_t ExtProc(int fn, int port, PDATAMESSAGE buff)
{
// Time out Login
- if (sockptr->LoginState < 2 && (time(NULL) - sockptr->ConnectTime) > 30)
+ if (sockptr->LoginState < 2 && (NOW - sockptr->ConnectTime) > 30)
{
closesocket(sockptr->socket);
sockptr->SocketActive = FALSE;
@@ -992,12 +1002,11 @@ static size_t ExtProc(int fn, int port, PDATAMESSAGE buff)
}
}
}
-
-
-
- return 0;
-
- case 1: // poll
+ if (TNC->PageChanged)
+ {
+ BuildDevicePage(TNC);
+ TNC->PageChanged = FALSE;
+ }
for (Stream = 0; Stream <= MaxStreams; Stream++)
{
@@ -1034,7 +1043,17 @@ static size_t ExtProc(int fn, int port, PDATAMESSAGE buff)
STREAM->ReportDISC = TRUE;
}
}
+ }
+
+ return 0;
+ case 1:
+
+ TelnetPoll(port);
+
+ for (Stream = 0; Stream <= MaxStreams; Stream++)
+ {
+ STREAM = &TNC->Streams[Stream];
if (STREAM->ReportDISC)
{
STREAM->ReportDISC = FALSE;
@@ -1042,13 +1061,6 @@ static size_t ExtProc(int fn, int port, PDATAMESSAGE buff)
return -1;
}
- }
-
- TelnetPoll(port);
-
- for (Stream = 0; Stream <= MaxStreams; Stream++)
- {
- STREAM = &TNC->Streams[Stream];
if (STREAM->PACTORtoBPQ_Q !=0)
{
@@ -1312,8 +1324,7 @@ static int WebProc(struct TNCINFO * TNC, char * Buff, BOOL LOCAL)
strcpy(CMSStatus, "No CMS");
}
- Len = sprintf(Buff, "<html><meta http-equiv=expires content=0><meta http-equiv=refresh content=15>"
- "<head><title>Telnet Status</title></head><body><b>Telnet Status &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%s</b>", CMSStatus);
+ Len = sprintf(Buff, "<b>Telnet Status &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%s</b>", CMSStatus);
Len += sprintf(&Buff[Len], "<table style=\"text-align: left; width: 250px; font-family: monospace; align=center \" border=1 cellpadding=2 cellspacing=2>");
@@ -1337,9 +1348,9 @@ static int WebProc(struct TNCINFO * TNC, char * Buff, BOOL LOCAL)
char Addr[100];
Tel_Format_Addr(sockptr, Addr);
if (sockptr->WebSocks)
- sprintf(msg,"<tr><td>Websock<%s</td><td>&nbsp;</td><td>&nbsp;</td></tr>", Addr);
+ sprintf(msg,"<tr><td>Websock&lt;%s</td><td>&nbsp;</td><td>&nbsp;</td></tr>", Addr);
else
- sprintf(msg,"<tr><td>HTTP<%s</td><td>&nbsp;</td><td>&nbsp;</td></tr>", Addr);
+ sprintf(msg,"<tr><td>HTTP&lt;%s</td><td>&nbsp;</td><td>&nbsp;</td></tr>", Addr);
}
else if (sockptr->DRATSMode)
{
@@ -2470,7 +2481,7 @@ nosocks:
{
char logmsg[120];
sprintf(logmsg,"%d Disconnected. Bytes Sent = %d Bytes Received %d Time %d Seconds\r\n",
- sockptr->Number, STREAM->bytesTXed, STREAM->bytesRXed, (int)(time(NULL) - sockptr->ConnectTime));
+ sockptr->Number, STREAM->bytesTXed, STREAM->bytesRXed, (int)(NOW - sockptr->ConnectTime));
WriteCMSLog (logmsg);
}
@@ -2531,11 +2542,11 @@ nosocks:
if (sockptr->SocketActive && sockptr->Keepalive && L4LIMIT)
{
- if ((time(NULL) - sockptr->LastSendTime) > (L4LIMIT - 60)) // PC Ticks are about 10% slow
+ if ((NOW - sockptr->LastSendTime) > (L4LIMIT - 60)) // PC Ticks are about 10% slow
{
// Send Keepalive
- sockptr->LastSendTime = time(NULL);
+ sockptr->LastSendTime = NOW;
BuffertoNode(sockptr, "Keepalive\r", 10);
}
}
@@ -2665,7 +2676,7 @@ nosocks:
if (P3[0] == 'K' || P4[0] == 'K' || P5[0] == 'K' || P6[0] == 'K')
{
sockptr->Keepalive = TRUE;
- sockptr->LastSendTime = time(NULL);
+ sockptr->LastSendTime = NOW;
}
if (P3[0] == 'S' || P4[0] == 'S' || P5[0] == 'S' || P6[0] == 'S')
@@ -2857,7 +2868,7 @@ nosocks:
Msglen = sockptr->FromHostBuffPutptr - sockptr->FromHostBuffGetptr;
- if (Msglen)
+ if (Msglen > 0)
{
int Paclen = 0;
int Queued = 0;
@@ -2887,7 +2898,7 @@ nosocks:
if (Paclen == 0)
Paclen = 256;
- ShowConnections(TNC);
+// ShowConnections(TNC);
if (Msglen > Paclen)
Msglen = Paclen;
@@ -2897,7 +2908,7 @@ nosocks:
SendtoNode(TNC, Stream, &sockptr->FromHostBuffer[sockptr->FromHostBuffGetptr], Msglen);
sockptr->FromHostBuffGetptr += Msglen;
- sockptr->LastSendTime = time(NULL);
+ sockptr->LastSendTime = NOW;
}
}
}
@@ -3366,7 +3377,7 @@ int Socket_Accept(struct TNCINFO * TNC, SOCKET SocketId, int Port)
if (sockptr->sin.sin_family != AF_INET6)
{
- if (sockptr->sin.sin_addr.s_addr == htonl(INADDR_LOOPBACK)) // 127.0.0.1?
+ if (!LOCALNOTSECURE && sockptr->sin.sin_addr.s_addr == htonl(INADDR_LOOPBACK)) // 127.0.0.1?
LOCAL = TRUE;
else
{
@@ -3396,7 +3407,7 @@ int Socket_Accept(struct TNCINFO * TNC, SOCKET SocketId, int Port)
sockptr->UserPointer = 0;
sockptr->DoEcho = FALSE;
sockptr->BPQTermMode = FALSE;
- sockptr->ConnectTime = time(NULL);
+ sockptr->ConnectTime = NOW;
sockptr->Keepalive = FALSE;
sockptr->UTF8 = 0;
@@ -5090,6 +5101,8 @@ MsgLoop:
extern char * RigWebPage;
+
+
struct RHPParamBlock
{
unsigned char * Msg;
@@ -5217,11 +5230,28 @@ int DataSocket_ReadHTTP(struct TNCINFO * TNC, struct ConnectionInfo * sockptr, S
if (Opcode == 8)
{
- Debugprintf("WebSock Close");
+ char Msg[256];
+
+ if (strcmp(sockptr->WebURL, "WEBTERM") == 0)
+ {
+ ProcessWebTermClosed(sockptr);
+ }
+
+ // Msg[0] = 0x88; // Fin, Close
+ // Msg[1] = 9;
+ // strcpy(&Msg[2], "Close ACK");
+
+ // send(sockptr->socket, Msg, 11, 0);
}
else if (Opcode == 1)
{
- if (strcmp(sockptr->WebURL, "RIGCTL") == 0)
+ if (strcmp(sockptr->WebURL, "WEBTERM") == 0)
+ {
+ Payload[Len] = 0;
+ ProcessWebTermInput(sockptr, Payload);
+ }
+
+ else if (strcmp(sockptr->WebURL, "RIGCTL") == 0)
{
// PTT Message
@@ -5237,7 +5267,7 @@ int DataSocket_ReadHTTP(struct TNCINFO * TNC, struct ConnectionInfo * sockptr, S
{
sockcopy = malloc(sizeof(struct ConnectionInfo));
sockptr->TNC = TNC;
- sockptr->LastSendTime = time(NULL);
+ sockptr->LastSendTime = NOW;
memcpy(sockcopy, sockptr, sizeof(struct ConnectionInfo));
@@ -5255,7 +5285,7 @@ int DataSocket_ReadHTTP(struct TNCINFO * TNC, struct ConnectionInfo * sockptr, S
ParamBlock->Len = Len;
ParamBlock->Msg = malloc(Len + 10);
memcpy(ParamBlock->Msg, Payload, Len);
- sockptr->LastSendTime = time(NULL);
+ sockptr->LastSendTime = NOW;
_beginthread(RHPThread, 0, (VOID *)ParamBlock);
@@ -5297,7 +5327,7 @@ int DataSocket_ReadHTTP(struct TNCINFO * TNC, struct ConnectionInfo * sockptr, S
sockcopy = malloc(sizeof(struct ConnectionInfo));
sockptr->TNC = TNC;
- sockptr->LastSendTime = time(NULL);
+ sockptr->LastSendTime = NOW;
memcpy(sockcopy, sockptr, sizeof(struct ConnectionInfo));
@@ -5310,9 +5340,41 @@ int DataSocket_ReadHTTP(struct TNCINFO * TNC, struct ConnectionInfo * sockptr, S
ShowConnections(TNC);
memcpy(sockptr->WebURL, &MsgPtr[5], 31);
+ strlop(sockptr->WebURL, '?');
strlop(sockptr->WebURL, ' ');
- if (RigWebPage)
- RigWebPage[0] = 0;
+
+ if (strcmp(sockptr->WebURL, "RIGCTL") == 0)
+ {
+ if (RigWebPage)
+ RigWebPage[0] = 0;
+ }
+ else if (memcmp(sockptr->WebURL, "DEVICE", 6) == 0)
+ {
+ int Port = atoi(&sockptr->WebURL[6]);
+
+ if (Port > 0 && Port <= MaxBPQPortNo)
+ {
+ struct TNCINFO * PTNC = TNCInfo[Port];
+
+ if (PTNC)
+ {
+ if (PTNC->WebPage)
+ PTNC->WebPage[0] = 0;
+
+ PTNC->WebSockUsed = 1;
+ PTNC->PageChanged = 1;
+ }
+ }
+ }
+ else if (memcmp(sockptr->WebURL, "WEBTERM", 7) == 0)
+ {
+ // We have to hook this socket to the Terminal Session
+ char * Key = strlop(&MsgPtr[5], '?');
+
+ strlop(Key, ' ');
+ ProcessNewTermWebSock(sockptr, Key);
+ }
+
ptr = strstr(MsgPtr, "BPQSessionCookie=N");
@@ -5426,6 +5488,8 @@ int ShowConnections(struct TNCINFO * TNC)
SendMessage(TNC->hMonitor, LB_ADDSTRING ,0, (LPARAM)msg);
}
#endif
+
+ TNC->PageChanged = TNC->WebSockUsed;
return 0;
}
byte * EncodeCall(byte * Call)
@@ -5545,7 +5609,7 @@ int WriteLog(char * msg)
time_t T;
struct tm * tm;
- T = time(NULL);
+ T = NOW;
tm = gmtime(&T);
if (LogDirectory[0] == 0)
@@ -5600,7 +5664,7 @@ VOID WriteCMSLog(char * msg)
if (CMSLogEnabled == FALSE)
return;
- T = time(NULL);
+ T = NOW;
tm = gmtime(&T);
if (LogDirectory[0] == 0)
@@ -5791,7 +5855,7 @@ int Telnet_Connected(struct TNCINFO * TNC, struct ConnectionInfo * sockptr, SOCK
sockptr->InputLen = 0;
// sockptr->Number = Stream;
sockptr->RelayMode = FALSE;
- sockptr->ConnectTime = time(NULL);
+ sockptr->ConnectTime = NOW;
TNC->Streams[Stream].Connecting = FALSE;
TNC->Streams[Stream].Connected = TRUE;
@@ -6031,9 +6095,9 @@ CheckServers:
#ifndef LINBPQ
if (TCP->CMSOK)
- MySetWindowText(TCP->hCMSWnd, "CMS OK");
+ MySetWindowText(TNC, TCP->hCMSWnd, "CMS OK");
else
- MySetWindowText(TCP->hCMSWnd, "NO CMS");
+ MySetWindowText(TNC, TCP->hCMSWnd, "NO CMS");
#endif
return;
}
@@ -6360,7 +6424,7 @@ VOID SaveCMSHostInfo(int port, struct TCPINFO * TCP, int CMSNo)
memcpy(work, &TCP->CMSAddr[CMSNo].s_addr, 4);
- sprintf(Info,"%s %d %d.%d.%d.%d\n", TCP->CMSName[CMSNo], (int)time(NULL),
+ sprintf(Info,"%s %d %d.%d.%d.%d\n", TCP->CMSName[CMSNo], (int)NOW,
work[0], work[1], work[2], work[3]);
@@ -6400,7 +6464,7 @@ VOID SaveCMSHostInfo(int port, struct TCPINFO * TCP, int CMSNo)
if (n == 3)
{
- time_t age = time(NULL) - t;
+ time_t age = NOW - t;
// if not current server and not too old, copy across
@@ -7283,7 +7347,7 @@ int DoRefreshWebMailIndex()
{
sockcopy = malloc(sizeof(struct ConnectionInfo));
sockptr->TNC = TNC;
- sockptr->LastSendTime = time(NULL);
+ sockptr->LastSendTime = NOW;
memcpy(sockcopy, sockptr, sizeof(struct ConnectionInfo));