summaryrefslogtreecommitdiff
path: root/nodeapi.c
diff options
context:
space:
mode:
authorDave Hibberd <hibby@debian.org>2025-02-25 09:32:57 +0000
committerDave Hibberd <hibby@debian.org>2025-02-25 09:32:57 +0000
commitc858986248f9ee86835be732f413824c0e42d729 (patch)
treed9862674659f5e7f7d5852b632f8fc29d275f25f /nodeapi.c
parent64d58d0c5a01551f8bfc52291986d1b8d681aca5 (diff)
New upstream version 6.0.24.65+repackupstream/6.0.24.65+repack
Diffstat (limited to 'nodeapi.c')
-rw-r--r--nodeapi.c57
1 files changed, 35 insertions, 22 deletions
diff --git a/nodeapi.c b/nodeapi.c
index 592d92a..538d78d 100644
--- a/nodeapi.c
+++ b/nodeapi.c
@@ -2,7 +2,6 @@
// Authentication is via Telnet USER records.
-
#define _CRT_SECURE_NO_DEPRECATE
#include "cheaders.h"
@@ -26,7 +25,7 @@ typedef struct API
{
char *URL;
int URLLen;
- int (* APIRoutine)(char * response, char * token, char * param);
+ int (* APIRoutine)(char * response, char * token, char * param, int Local);
int Auth;
} API;
@@ -34,7 +33,7 @@ typedef struct API
#define AuthNone 0
#define AuthUser 1
-#define Auth BBSUser 2
+#define AuthBBSUser 2
#define AuthSysop 4
// Function prototypes
@@ -50,14 +49,14 @@ void add_token_to_list(Token* token);
Token* find_token(const char* token);
Token* generate_token();
-int sendPortList(char * response, char * token, char * Rest);
-int sendNodeList(char * response, char * token, char * Rest);
-int sendUserList(char * response, char * token, char * Rest);
-int sendInfo(char * response, char * token, char * Rest);
-int sendLinks(char * response, char * token, char * Rest);
-int sendPortMHList(char * response, char * token, char * Rest);
-int sendWhatsPacState(char * response, char * token, char * param);
-int sendWhatsPacConfig(char * response, char * token, char * param);
+int sendPortList(char * response, char * token, char * Rest, int Local);
+int sendNodeList(char * response, char * token, char * Rest, int Local);
+int sendUserList(char * response, char * token, char * Rest, int Local);
+int sendInfo(char * response, char * token, char * Rest, int Local);
+int sendLinks(char * response, char * token, char * Rest, int Local);
+int sendPortMHList(char * response, char * token, char * Rest, int Local);
+int sendWhatsPacState(char * response, char * token, char * param, int Local);
+int sendWhatsPacConfig(char * response, char * token, char * param, int Local);
void BuildPortMH(char * MHJSON, struct PORTCONTROL * PORT);
DllExport struct PORTCONTROL * APIENTRY GetPortTableEntryFromSlot(int portslot);
@@ -74,8 +73,8 @@ struct API APIList[] =
"/api/links", 10, sendLinks, 0,
"/api/users", 10, sendUserList, 0,
"/api/mheard", 11, sendPortMHList, 0,
- "/api/v1/config", 14, sendWhatsPacConfig, 0,
- "/api/v1/state", 13, sendWhatsPacState, 0
+ "/api/v1/config", 14, sendWhatsPacConfig, AuthSysop,
+ "/api/v1/state", 13, sendWhatsPacState, AuthSysop
};
int APICount = sizeof(APIList) / sizeof(struct API);
@@ -159,6 +158,14 @@ int APIProcessHTTPMessage(char * response, char * Method, char * URL, char * req
return send_http_response(response, Resp);
}
+ if (strcmp(Method, "POST") == 0)
+ {
+ if (_stricmp(URL, "/api/v1/config") == 0)
+ {
+ return send_http_response(response, "200 (OK)");
+ }
+ }
+
if (strcmp(Method, "GET") != 0)
return send_http_response(response, "403 (Bad Method)");
@@ -202,7 +209,7 @@ if (token[0] == 0)
rest = &request[4 + APIEntry->URLLen]; // Anything following?
if (rest[0] == ' ' || rest[0] == '/' || rest[0] == '?')
- return APIEntry->APIRoutine(response, token, rest);
+ return APIEntry->APIRoutine(response, token, rest, LOCAL);
}
}
@@ -349,7 +356,7 @@ int send_http_response(char * response, const char* msg)
extern int MasterPort[MAXBPQPORTS+1]; // Pointer to first BPQ port for a specific MPSK or UZ7HO host
-int sendPortList(char * response, char * token, char * param)
+int sendPortList(char * response, char * token, char * param, int Local)
{
char * Array = 0;
int ArrayLen = 0;
@@ -561,7 +568,7 @@ extern struct DEST_LIST * DESTS; // NODE LIST
extern int DEST_LIST_LEN;
-int sendNodeList(char * response, char * token, char * param)
+int sendNodeList(char * response, char * token, char * param, int Local)
{
int ArrayPtr = 0;
@@ -665,7 +672,7 @@ int sendNodeList(char * response, char * token, char * param)
}
-int sendUserList(char * response, char * token, char * param)
+int sendUserList(char * response, char * token, char * param, int Local)
{
int ArrayPtr = 0;
int n = MAXCIRCUITS;
@@ -711,7 +718,7 @@ extern char MYALIASLOPPED[];
extern char TextVerstring[];
extern char LOCATOR[];
-int sendInfo(char * response, char * token, char * param)
+int sendInfo(char * response, char * token, char * param, int Local)
{
char call[10];
@@ -724,7 +731,7 @@ int sendInfo(char * response, char * token, char * param)
return strlen(response);
}
-int sendLinks(char * response, char * token, char * param)
+int sendLinks(char * response, char * token, char * param, int Local)
{
struct _LINKTABLE * Links = LINKS;
int MaxLinks = MAXLINKS;
@@ -789,7 +796,7 @@ int sendLinks(char * response, char * token, char * param)
return ReplyLen;
}
-int sendPortMHList(char * response, char * token, char * param)
+int sendPortMHList(char * response, char * token, char * param, int Local)
{
struct PORTCONTROL * PORTVEC ;
int n;
@@ -828,8 +835,11 @@ int sendPortMHList(char * response, char * token, char * param)
extern int WhatsPacConfigured;
-int sendWhatsPacState(char * response, char * token, char * param)
+int sendWhatsPacState(char * response, char * token, char * param, int Local)
{
+ if (Local == 0)
+ return send_http_response(response, "401 Not Authorised");
+
if (WhatsPacConfigured)
sprintf(response, "{\"configured\": true}\r\n");
else
@@ -839,7 +849,7 @@ int sendWhatsPacState(char * response, char * token, char * param)
}
-int sendWhatsPacConfig(char * response, char * token, char * param)
+int sendWhatsPacConfig(char * response, char * token, char * param, int Local)
{
char Template[] =
"{\"MODE\": 0,"
@@ -848,6 +858,9 @@ int sendWhatsPacConfig(char * response, char * token, char * param)
"\"INTERFACES\": [{\"INTERFACE\": 1,\"PROTOCOL\": \"KISS\",\"TYPE\": \"TCP\",\"IOADDR\": \"127.0.0.1\",\"INTNUM\": 8100}],"
"\"PORTS\": [{\"PORT\": 1,\"ID\": \"RHPPORT\", \"INTERFACENUM\": 1}]}";
+ if (Local == 0)
+ return send_http_response(response, "401 Not Authorised");
+
sprintf(response, Template, HTTPPort);
return strlen(response);