Skip to content
Snippets Groups Projects
Commit b4639b0f authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

node utility can now display one/some/all key/values from node*/client.ini

<nelgin> Remind me why you can't show the ip address on node status? :)

Using the new '-v[key]' option, a sysop can view one, some, or all of the
key/value pairs from the nodes with a connected client. For nodes without
a connected client, the client.ini file values aren't particularly useful, but
if someone wants an option to show those values for non-client-connected nodes
I can do that too.

When using '-v', all the client.ini key/value pairs will be displayed for all
the node records requested with currently connected clients. By specifying
'-v[key]' the sysop can specify a key to display (rather than all of them)
e.g. 'node list -vaddr' to list nodes with remote client IP addresses.
This option can be used multiple times on the command-line to view multiple
keys. See node*/client.ini for the list of supported keys.

This feature only works for nodes whose directory paths are ../node#/
relative to the ctrl directory. Since the node utility doesn't read any
configuration files, this is a limitation. If you have different node
directory names/parents and need to use this feature, let me know and I'll
see about adding support for reading/parsing main.ini file to discover those
non-standard/default node directory paths automatically.

The version number displayed is now taken from the sbbs version (sbbsdefs.h).
The maximum ctrl directory path is now extended from 40 chars to MAX_PATH.
More readable help/usage output (using indentation).
parent 622ffe3d
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #4666 passed
......@@ -31,6 +31,7 @@
#include <string.h>
#include <errno.h>
#include <ctype.h> /* isdigit */
#include <stdbool.h>
/* Synchronet-specific */
#include "sbbsdefs.h"
......@@ -38,6 +39,8 @@
#include "filewrap.h" /* lock/unlock/sopen */
#include "getctrl.h"
#include "str_util.h" // strip_ctrl()
#define NO_SOCKET_SUPPORT
#include "ini_file.h"
enum {
MODE_LIST
......@@ -445,7 +448,6 @@ void printnodedat(int number, node_t node)
}
if(node.errors)
printf(" %d error%c",node.errors, node.errors>1 ? 's' : '\0' );
printf("\n");
}
......@@ -454,7 +456,7 @@ void printnodedat(int number, node_t node)
/****************************/
int main(int argc, char **argv)
{
char str[256],ctrl_dir[41],debug=0;
char str[256],ctrl_dir[MAX_PATH + 1],debug=0;
int sys_nodes,node_num=0,onoff=0;
int i,j,mode=0,misc;
int modify=0;
......@@ -462,12 +464,10 @@ int main(int argc, char **argv)
int pause=0;
long value=0;
node_t node;
bool verbose = false;
str_list_t key_list = strListInit();
char revision[16];
sscanf("$Revision: 1.34 $", "%*s %s", revision);
printf("\nSynchronet Node Display/Control Utility v%s\n\n", revision);
printf("\nSynchronet Node Display/Control Utility v%s\n\n", VERSION);
if(sizeof(node_t)!=SIZEOF_NODE_T) {
printf("COMPILER ERROR: sizeof(node_t)=%" XP_PRIsize_t "u instead of %d\n"
......@@ -476,28 +476,33 @@ int main(int argc, char **argv)
}
if(argc<2) {
printf("usage: node [-debug] [action [on|off]] [node numbers] [...]"
printf("usage: node [-v[key]] [-debug] [action [on|off]] [node numbers] [...]"
"\n\n");
printf("actions (default is list):\n\n");
printf("list = list status\n");
printf("anon = anonymous user\n");
printf("lock = locked\n");
printf("intr = interrupt\n");
printf("down = shut-down\n");
printf("rerun = rerun\n");
printf("event = run event\n");
printf("nopage = page disable\n");
printf("noalerts = activity alerts disable\n");
printf("status=# = set status value\n");
printf(" %d = Waiting for connection\n", NODE_WFC);
printf(" %d = Offline\n", NODE_OFFLINE);
printf("useron=# = set useron number\n");
printf("action=# = set action value\n");
printf("errors=# = set error counter\n");
printf("conn=# = set connection value\n");
printf("misc=# = set misc value\n");
printf("aux=# = set aux value\n");
printf("extaux=# = set extended aux value\n");
printf("actions (default action is 'list'):\n\n");
printf(" list = list status\n");
printf(" anon = anonymous user\n");
printf(" lock = locked\n");
printf(" intr = interrupt\n");
printf(" down = shut-down\n");
printf(" rerun = rerun\n");
printf(" event = run event\n");
printf(" nopage = page disable\n");
printf(" noalerts = activity alerts disable\n");
printf(" status=# = set status value\n");
printf(" %d = Waiting for connection\n", NODE_WFC);
printf(" %d = Offline\n", NODE_OFFLINE);
printf(" useron=# = set useron number\n");
printf(" action=# = set action value\n");
printf(" errors=# = set error counter\n");
printf(" conn=# = set connection value\n");
printf(" misc=# = set misc value\n");
printf(" aux=# = set aux value\n");
printf(" extaux=# = set extended aux value\n");
printf("\n");
printf("options:\n\n");
printf(" -debug = display numeric values of each node record field\n");
printf(" -v[key] = view a connected-client key value (default: all)\n");
printf(" (may be used multiple times to display multiple keys)\n");
exit(0);
}
......@@ -532,7 +537,11 @@ int main(int argc, char **argv)
loop=1;
if(!stricmp(argv[i],"-PAUSE"))
pause=1;
if(strncmp(argv[i], "-v", 2) == 0) {
verbose = true;
if(argv[i][2])
strListPush(&key_list, argv[i] + 2);
}
else if(!stricmp(argv[i],"LOCK"))
mode=MODE_LOCK;
else if(!stricmp(argv[i],"ANON"))
......@@ -659,15 +668,36 @@ int main(int argc, char **argv)
if(modify)
putnodedat(j,node);
printnodedat(j,node);
if(verbose && NODE_CLIENT_CONNECTED(node.status)) {
char client_path[MAX_PATH + 1];
snprintf(client_path, sizeof(client_path), "%s../node%u/client.ini", ctrl_dir, j);
FILE* fp = iniOpenFile(client_path, /* modify: */false);
if(fp != NULL) {
str_list_t ini = iniReadFile(fp);
iniCloseFile(fp);
if(key_list[0] == NULL) {
for(int k = 0; ini[k] != NULL; ++k) {
printf("\n\t%s", ini[k]);
}
} else {
for(int k = 0; key_list[k] != NULL; ++k) {
printf("\n\t%s=%s"
, key_list[k], iniGetString(ini, NULL, key_list[k], NULL, NULL));
}
}
iniFreeStringList(ini);
}
}
printf("\n");
if(debug) {
printf("status=%u\n",node.status);
printf("errors=%u\n",node.errors);
printf("action=%d\n",node.action);
printf("useron=%u\n",node.useron);
printf("conn=%u\n",node.connection);
printf("misc=%u\n",node.misc);
printf("aux=%u\n",node.aux);
printf("extaux=%"PRIu32"\n",node.extaux);
printf("\tstatus=%u\n",node.status);
printf("\terrors=%u\n",node.errors);
printf("\taction=%d\n",node.action);
printf("\tuseron=%u\n",node.useron);
printf("\tconn=%u\n",node.connection);
printf("\tmisc=%u\n",node.misc);
printf("\taux=%u\n",node.aux);
printf("\textaux=%"PRIu32"\n",node.extaux);
} /* debug */
} /* if(!node_num) */
......
......@@ -45,6 +45,8 @@ enum node_status { /* Node Status */
#define NODE_INVALID_STATUS 0xff /* Invalid status value */
#define NODE_CLIENT_CONNECTED(s) ((s) >= NODE_LOGON && (s) <= NODE_QUIET)
/* Bit values for node.misc */
#define NODE_ANON (1<<0) /* Anonymous User */
#define NODE_LOCK (1<<1) /* Locked for sysops only */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment