umonitor.c 35 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/* umonitor.c */

/* Synchronet for *nix node activity monitor */

/* $Id$ */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
11
 * Copyright 2004 Rob Swindell - http://www.synchro.net/copyright.html		*
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
 *																			*
 * This program 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 2			*
 * of the License, or (at your option) any later version.					*
 * See the GNU General Public License for more details: gpl.txt or			*
 * http://www.fsf.org/copyleft/gpl.html										*
 *																			*
 * Anonymous FTP access to the most recent released source is available at	*
 * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net	*
 *																			*
 * Anonymous CVS access to the development source and modification history	*
 * is available at cvs.synchro.net:/cvsroot/sbbs, example:					*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login			*
 *     (just hit return, no password is necessary)							*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src		*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * You are encouraged to submit any modifications (preferably in Unix diff	*
 * format) via e-mail to mods@synchro.net									*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

38
#include <signal.h>
deuce's avatar
deuce committed
39
#include <sys/types.h>
40
#include <time.h>
deuce's avatar
deuce committed
41
42
43
44
#include <sys/time.h>
#ifdef __QNX__
#include <string.h>
#endif
45
#include <stdio.h>
46
#include <unistd.h>
47
48

#include "ciolib.h"
49
#include "keys.h"
50
51
#define __COLORS		/* Disable the colour macros in sbbsdefs.h ToDo */
#include "sbbs.h"
52
#include "genwrap.h"
53
54
55
#include "uifc.h"
#include "sbbsdefs.h"
#include "genwrap.h"	/* stricmp */
56
#include "dirwrap.h"	/* lock/unlock/sopen */
57
#include "filewrap.h"	/* lock/unlock/sopen */
58
59
60
#include "sbbs_ini.h"	/* INI parsing */
#include "scfglib.h"	/* SCFG files */
#include "ars_defs.h"	/* needed for SCFG files */
61
#include "userdat.h"	/* getnodedat() */
62
#include "spyon.h"
63
#include "chat.h"
64

65
#define CTRL(x) (x&037)
66
67
68
69
70

/********************/
/* Global Variables */
/********************/
uifcapi_t uifc; /* User Interface (UIFC) Library API */
71
72
const char *YesStr="Yes";
const char *NoStr="No";
73
74
75
76
77
78
79
80
81
82
83
84
85
86

int lprintf(char *fmt, ...)
{
	va_list argptr;
	char sbuf[1024];
	int	len;

	va_start(argptr,fmt);
	len=vsnprintf(sbuf,sizeof(sbuf),fmt,argptr);
	sbuf[sizeof(sbuf)-1]=0;
	va_end(argptr);
	uifc.msg(sbuf);
	return(len);
}
87

88
89
90
91
void bail(int code)
{
    if(code) {
        puts("\nHit a key...");
92
        getch();
93
94
95
96
97
98
99
100
101
102
	}
    uifc.bail();

    exit(code);
}

void allocfail(uint size)
{
    printf("\7Error allocating %u bytes of memory.\n",size);
    bail(1);
103
104
}

105
106
107
108
109
110
111
112
113
114
void freeopt(char** opt)
{
	int i;

	for(i=0;i<(MAX_OPTS+1);i++)
		free(opt[i]);

	free(opt);
}

115
116
void node_toggles(scfg_t *cfg,int nodenum)  {
	int nodefile;
117
118
119
120
121
122
123
124
125
126
127
128
	char**	opt;
	int		i,j;
	node_t	node;
	int		save=0;

	if((opt=(char **)MALLOC(sizeof(char *)*(MAX_OPTS+1)))==NULL)
		allocfail(sizeof(char *)*(MAX_OPTS+1));
	for(i=0;i<(MAX_OPTS+1);i++)
		if((opt[i]=(char *)MALLOC(MAX_OPLN))==NULL)
			allocfail(MAX_OPLN);

	i=0;
129
130
131
132
133
134
135
136
137
138
139
140
141
	uifc.helpbuf=	"`Node Toggles\n"
	                "`------------`\n\n"
					"`The following are `Yes/No `options.  Hitting Enter toggles between.\n\n"
					"`Locked for SysOps only : `Locks the node so that only SysOps may \n"
					"                         logon to them.\n"
					"`Interrupt (Hangup)     : `The current user will be kicked as soon as it \n"
					"                         is safe to do so.  A brief message is given\n"
					"                         to user.\n"
					"`Re-run on logoff       : `Toggles the system to reload the configuration\n"
					"                         files when the current user logs off.\n"
					"`Down node after logoff : `Takes the node offline after current user logs\n"
					"                         off.\n\n"
					"`[Note] `These toggles take effect immediately.";
142
	while(save==0) {
143
		if(getnodedat(cfg,nodenum,&node,&nodefile)) {
144
145
146
			uifc.msg("Error reading node data!");
			break;
		}
147
148
149
		j=0;
		sprintf(opt[j++],"%-30s%3s","Locked for SysOps only",node.misc&NODE_LOCK ? YesStr : NoStr);
		sprintf(opt[j++],"%-30s%3s","Interrupt (Hangup)",node.misc&NODE_INTR ? YesStr : NoStr);
rswindell's avatar
rswindell committed
150
151
152
		sprintf(opt[j++],"%-30s%3s","Re-run on logoff",node.misc&NODE_RRUN ? YesStr : NoStr);
		sprintf(opt[j++],"%-30s%3s","Down node after logoff"
			,(node.misc&NODE_DOWN || (node.status==NODE_OFFLINE)) ? YesStr : NoStr);
153
154
		opt[j][0]=0;

155
		switch(uifc.list(WIN_MID|WIN_SAV,0,0,0,&i,0,"Node Toggles",opt)) {
156
157
158
159
160
161
162
163
			case 0:	/* Locked */
				node.misc ^= NODE_LOCK;
				break;

			case 1:	/* Interrupt */
				node.misc ^= NODE_INTR;
				break;

rswindell's avatar
rswindell committed
164
			case 2:	/* Re-run */
165
166
167
				node.misc ^= NODE_RRUN;
				break;

rswindell's avatar
rswindell committed
168
			case 3:	/* Down */
169
				if(node.status != NODE_WFC && node.status != NODE_OFFLINE)
170
					node.misc ^= NODE_DOWN;
171
				else {
172
173
174
175
176
					if(node.status!=NODE_OFFLINE)
						node.status=NODE_OFFLINE;
					else
						node.status=NODE_WFC;
				}
177
178
179
180
181
				break;

			case -1:
				save=1;
				break;
182

183
184
185
186
			default:
				uifc.msg("Option not implemented");
				continue;
		}
187
		putnodedat(cfg,nodenum,&node,nodefile);
deuce's avatar
deuce committed
188
	}
189
	freeopt(opt);
deuce's avatar
deuce committed
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
}

int dospy(int nodenum, bbs_startup_t *bbs_startup)  {
	char str[80],str2[80];
	int i;

	if(bbs_startup->temp_dir[0])
    	snprintf(str,sizeof(str),"%slocalspy%d.sock", bbs_startup->temp_dir, nodenum);
	else
		snprintf(str,sizeof(str),"%slocalspy%d.sock", bbs_startup->ctrl_dir, nodenum);
	i=spyon(str);
	switch(i) {
		case SPY_NOSOCKET:
			uifc.msg("Could not create socket");
			return(-1);
205

deuce's avatar
deuce committed
206
207
208
209
210
211
212
213
214
215
216
217
		case SPY_NOCONNECT:
			sprintf(str2,"Failed to connect to %s",str);
			uifc.msg(str2);
			return(-1);

		case SPY_SELECTFAILED:
			uifc.msg("select() failed, connection terminated.");
			return(-1);

		case SPY_SOCKETLOST:
			uifc.msg("Spy socket lost");
			return(-1);
218

deuce's avatar
deuce committed
219
220
221
		case SPY_STDINLOST:
			uifc.msg("STDIN has gone away... you probably can't close this window.  :-)");
			return(-1);
222

deuce's avatar
deuce committed
223
224
		case SPY_CLOSED:
			break;
225

deuce's avatar
deuce committed
226
227
228
229
230
231
232
233
		default:
			sprintf(str,"Unknown return code %d",i);
			uifc.msg(str);
			return(-1);
	}
	return(0);
}

234
int sendmessage(scfg_t *cfg, int nodenum,node_t *node)  {
235
236
	char str[80],str2[80];

237
	uifc.input(WIN_MID|WIN_SAV,0,0,"Telegram",str2,58,K_WRAP|K_MSG);
238
	sprintf(str,"\1n\1y\1hMessage From Sysop:\1w %s\r\n",str2);
239
	if(getnodedat(cfg,nodenum,node,NULL))
240
241
242
		return(-1);
	if(node->useron==0)
		return(-1);
243
	putsmsg(cfg, node->useron, str);
244
245
246
	return(0);
}

247
248
249
int clearerrors(scfg_t *cfg, int nodenum, node_t *node) {
	int nodefile;
	if(getnodedat(cfg,nodenum,node,&nodefile)) {
250
251
252
253
		uifc.msg("getnodedat() failed! (Nothing done)");
		return(-1);
	}
	node->errors=0;
254
	putnodedat(cfg,nodenum,node,nodefile);
255
256
257
	return(0);
}

258
259
260
261
262
/* Assumes a 12 char outstr */
char *getsizestr(char *outstr, long size, BOOL bytes) {
	if(bytes) {
		if(size < 1000) {	/* Bytes */
			snprintf(outstr,12,"%ld bytes",size);
263
			return(outstr);
264
265
266
		}
		if(size<10000) {	/* Bytes with comma */
			snprintf(outstr,12,"%ld,%03ld bytes",(size/1000),(size%1000));
267
			return(outstr);
268
269
270
271
272
		}
		size = size/1024;
	}
	if(size<1000) {	/* KB */
		snprintf(outstr,12,"%ld KB",size);
273
		return(outstr);
274
275
276
	}
	if(size<999999) { /* KB With comma */
		snprintf(outstr,12,"%ld,%03ld KB",(size/1000),(size%1000));
277
		return(outstr);
278
279
280
281
	}
	size = size/1024;
	if(size<1000) {	/* MB */
		snprintf(outstr,12,"%ld MB",size);
282
		return(outstr);
283
284
285
	}
	if(size<999999) { /* MB With comma */
		snprintf(outstr,12,"%ld,%03ld MB",(size/1000),(size%1000));
286
		return(outstr);
287
288
289
290
	}
	size = size/1024;
	if(size<1000) {	/* GB */
		snprintf(outstr,12,"%ld GB",size);
291
		return(outstr);
292
293
294
	}
	if(size<999999) { /* GB With comma */
		snprintf(outstr,12,"%ld,%03ld GB",(size/1000),(size%1000));
295
		return(outstr);
296
297
298
299
	}
	size = size/1024;
	if(size<1000) {	/* TB (Yeah, right) */
		snprintf(outstr,12,"%ld TB",size);
300
		return(outstr);
301
302
	}
	sprintf(outstr,"Plenty");
303
	return(outstr);
304
305
306
307
308
309
}

/* Assumes a 12 char outstr */
char *getnumstr(char *outstr, ulong size) {
	if(size < 1000) {
		snprintf(outstr,12,"%ld",size);
310
		return(outstr);
311
312
313
	}
	if(size<1000000) {
		snprintf(outstr,12,"%ld,%03ld",(size/1000),(size%1000));
314
		return(outstr);
315
316
317
	}
	if(size<1000000000) {
		snprintf(outstr,12,"%ld,%03ld,%03ld",(size/1000000),((size/1000)%1000),(size%1000));
318
		return(outstr);
319
320
321
322
	}
	size=size/1000000;
	if(size<1000000) {
		snprintf(outstr,12,"%ld,%03ld M",(size/1000),(size%1000));
323
		return(outstr);
324
325
326
	}
	if(size<10000000) {
		snprintf(outstr,12,"%ld,%03ld,%03ld M",(size/1000000),((size/1000)%1000),(size%1000));
327
		return(outstr);
328
329
	}
	sprintf(outstr,"Plenty");
330
	return(outstr);
331
332
}

333
int drawstats(scfg_t *cfg, int nodenum, node_t *node, int *curp, int *barp) {
334
335
336
337
338
339
340
341
	stats_t	sstats;
	stats_t	nstats;
	char	statbuf[6*78];		/* Buffer to hold the stats for passing to uifc.showbuf() */
	char	str[4][4][12];
	char	usrname[128];
	ulong	free;
	uint	i,l,m;
	time_t	t;
342
	int		shownode=1;
343
344

	if(getnodedat(cfg,nodenum,node,NULL)) {
345
346
347
348
		shownode=0;
	}
	else {
		getstats(cfg, nodenum, &nstats);
349
350
351
352
353
354
355
356
357
358
	}
	username(cfg,node->useron,usrname);

	getstats(cfg, 0, &sstats);
	t=time(NULL);
	strftime(str[0][0],12,"%b %e",localtime(&t));
	free=getfreediskspace(cfg->temp_dir,1024);
	if(free<1000) {
		free=getfreediskspace(cfg->temp_dir,0);
		getsizestr(str[0][1],free,TRUE);
359
	}
360
361
	else
		getsizestr(str[0][1],free,FALSE);
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
	if(shownode) {
		snprintf(str[1][0],12,"%s/%s",getnumstr(str[3][2],nstats.ltoday),getnumstr(str[3][3],sstats.ltoday));
		getnumstr(str[1][1],sstats.logons);
		snprintf(str[1][2],12,"%s/%s",getnumstr(str[3][2],nstats.ttoday),getnumstr(str[3][3],sstats.ttoday));
		getnumstr(str[1][3],sstats.timeon);
		snprintf(str[2][0],12,"%s/%s",getnumstr(str[3][2],sstats.etoday),getnumstr(str[3][3],getmail(cfg,0,0)));
		l=m=0;
		for(i=0;i<cfg->total_subs;i++)
			l+=getposts(cfg,i); 			/* l=total posts */
		for(i=0;i<cfg->total_dirs;i++)
			m+=getfiles(cfg,i); 			/* m=total files */
		snprintf(str[2][1],12,"%s/%s",getnumstr(str[3][2],sstats.ptoday),getnumstr(str[3][3],l));
		snprintf(str[2][2],12,"%s/%s",getnumstr(str[3][2],sstats.ftoday),getnumstr(str[3][3],getmail(cfg,1,0)));
		snprintf(str[2][3],12,"%s/%s",getnumstr(str[3][2],sstats.nusers),getnumstr(str[3][3],total_users(cfg)));
		getsizestr(str[3][0],sstats.ulb,TRUE);
		snprintf(str[3][1],12,"%s/%s",getnumstr(str[3][2],sstats.uls),getnumstr(str[3][3],m));
		getsizestr(str[3][2],sstats.dlb,TRUE);
		getnumstr(str[3][3],sstats.dls);
	}
	else {
		snprintf(str[1][0],12,"%s",getnumstr(str[3][3],sstats.ltoday));
		getnumstr(str[1][1],sstats.logons);
		snprintf(str[1][2],12,"%s",getnumstr(str[3][3],sstats.ttoday));
		getnumstr(str[1][3],sstats.timeon);
		snprintf(str[2][0],12,"%s/%s",getnumstr(str[3][2],sstats.etoday),getnumstr(str[3][3],getmail(cfg,0,0)));
		l=m=0;
		for(i=0;i<cfg->total_subs;i++)
			l+=getposts(cfg,i); 			/* l=total posts */
		for(i=0;i<cfg->total_dirs;i++)
			m+=getfiles(cfg,i); 			/* m=total files */
		snprintf(str[2][1],12,"%s/%s",getnumstr(str[3][2],sstats.ptoday),getnumstr(str[3][3],l));
		snprintf(str[2][2],12,"%s/%s",getnumstr(str[3][2],sstats.ftoday),getnumstr(str[3][3],getmail(cfg,1,0)));
		snprintf(str[2][3],12,"%s/%s",getnumstr(str[3][2],sstats.nusers),getnumstr(str[3][3],total_users(cfg)));
		getsizestr(str[3][0],sstats.ulb,TRUE);
		snprintf(str[3][1],12,"%s/%s",getnumstr(str[3][2],sstats.uls),getnumstr(str[3][3],m));
		getsizestr(str[3][2],sstats.dlb,TRUE);
		getnumstr(str[3][3],sstats.dls);
	}
deuce's avatar
deuce committed
400
401
402
403
	snprintf(statbuf,sizeof(statbuf),"`Node #`: %-3d %6s  `Space`: %s"
			"\n`Logons`: %-11s `Total`: %-11s `Timeon`: %-11s `Total`: %-11s"
			"\n`Emails`: %-11s `Posts`: %-11s `Fbacks`: %-11s `Users`: %-11s"
			"\n`Uloads`: %-11s `Files`: %-11s `Dloads`: %-11s `Files`: %-11s",
404
405
406
407
408
			nodenum,str[0][0],str[0][1],
			str[1][0],str[1][1],str[1][2],str[1][3],
			str[2][0],str[2][1],str[2][2],str[2][3],
			str[3][0],str[3][1],str[3][2],str[3][3]);

deuce's avatar
deuce committed
409
	uifc.showbuf(WIN_HLP|WIN_L2R|WIN_DYN|WIN_PACK,1,1,80,6,"Statistics",statbuf,curp,barp);
410
/* Node 5 :	Mar 11  Space: 162,024k
411
   Logons: 23/103      Total: 62,610      Timeon: 322/2430    Total: 5,321,900
412
413
414
415
416
   Emails: 4/265       Posts: 4/12811     Fbacks: 2/17	       Users: 1/592
   Uloads: 324k        Files: 1/2195      Dloads: 9,308k      Files: 52 */
	return(0);
}

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
int view_log(char *filename, char *title)
{
	char str[1024];
	int buffile;
	int j;
	char *buf;

	if(fexist(filename)) {
		if((buffile=sopen(filename,O_RDONLY,SH_DENYWR))>=0) {
			j=filelength(buffile);
			if((buf=(char *)MALLOC(j+1))!=NULL) {
				read(buffile,buf,j);
				close(buffile);
				*(buf+j)=0;
				uifc.showbuf(WIN_MID,0,0,76,uifc.scrn_len-2,title,buf,NULL,NULL);
				free(buf);
				return(0);
			}
			close(buffile);
			uifc.msg("Error allocating memory for the error log");
			return(3);
		}
		sprintf(str,"Error opening %s",title);
		uifc.msg(str);
		return(1);
	}
	sprintf(str,"%s does not exists",title);
	uifc.msg(str);
	return(2);
}

int view_logs(scfg_t *cfg)
{
	char**	opt;
	int		i;
	char	str[1024];
	struct tm tm;
	struct tm tm_yest;
	time_t	now;

	now=time(NULL);
	localtime_r(&now,&tm);
	now -= 60*60*24;
	localtime_r(&now,&tm_yest);
	if((opt=(char **)MALLOC(sizeof(char *)*(MAX_OPTS+1)))==NULL)
		allocfail(sizeof(char *)*(MAX_OPTS+1));
	for(i=0;i<(MAX_OPTS+1);i++)
		if((opt[i]=(char *)MALLOC(MAX_OPLN))==NULL)
			allocfail(MAX_OPLN);

	i=0;
468
469
	strcpy(opt[i++],"Today's callers");
	strcpy(opt[i++],"Yesterday's callers");
470
	strcpy(opt[i++],"Error log");
471
472
	strcpy(opt[i++],"Today's log");
	strcpy(opt[i++],"Yesterday's log");
473
474
475
476
477
478
	strcpy(opt[i++],"Spam log");
	strcpy(opt[i++],"SBBSEcho log");
	strcpy(opt[i++],"Guru log");
	strcpy(opt[i++],"Hack log");
	opt[i][0]=0;
	i=0;
479
480
481
482
483
484
485
486
487
488
489
	uifc.helpbuf=	"`View Logs\n"
					"`---------\n\n"
					"`Today's callers     : `View a list of Today's callers.\n"
					"`Yesterday's callers : `View a list of Yesterday's callers.\n"
					"`Error log           : `View the Error log.\n"
					"`Today's log         : `View Today's system activity.\n"
					"`Yesterday's log     : `View Yesterday's system activity.\n"
					"`Spam log            : `View the log of Spam E-Mail sent to the system.\n"
					"`SBBSEcho log        : `View the SBBSecho tosser log.\n"
					"`Guru log            : `View the transcriptions of chats with the Guru.\n"
					"`Hack log            : `View the Hack attempt log.";
490

491
	while(1) {
492
		switch(uifc.list(WIN_MID|WIN_SAV,0,0,0,&i,0,"View Logs",opt))  {
493
			case -1:
494
				freeopt(opt);
495
496
				return(0);
			case 0:
deuce's avatar
deuce committed
497
				sprintf(str,"%slogs/%2.2d%2.2d%2.2d.lol",cfg->logs_dir,tm.tm_mon+1,tm.tm_mday
498
499
500
501
					,TM_YEAR(tm.tm_year));
				view_log(str,"Todays Callers");
				break;
			case 1:
deuce's avatar
deuce committed
502
				sprintf(str,"%slogs/%2.2d%2.2d%2.2d.lol",cfg->logs_dir,tm_yest.tm_mon+1
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
					,tm_yest.tm_mday,TM_YEAR(tm_yest.tm_year));
				view_log(str,"Yesterdays Callers");
				break;
			case 2:
				sprintf(str,"%s/error.log",cfg->logs_dir);
				view_log(str,"Error Log");
				break;
			case 3:
				sprintf(str,"%slogs/%2.2d%2.2d%2.2d.log",cfg->logs_dir,tm.tm_mon+1,tm.tm_mday
					,TM_YEAR(tm.tm_year));
				view_log(str,"Todays Log");
				break;
			case 4:
				sprintf(str,"%slogs/%2.2d%2.2d%2.2d.log",cfg->logs_dir,tm_yest.tm_mon+1
					,tm_yest.tm_mday,TM_YEAR(tm_yest.tm_year));
				view_log(str,"Yesterdays Log");
				break;
			case 5:
				sprintf(str,"%sspam.log",cfg->logs_dir);
				view_log(str,"SPAM Log");
				break;
			case 6:
				sprintf(str,"%ssbbsecho.log",cfg->logs_dir);
				view_log(str,"SBBSEcho Log");
				break;
			case 7:
				sprintf(str,"%sguru.log",cfg->logs_dir);
				view_log(str,"Guru Log");
				break;
			case 8:
				sprintf(str,"%shack.log",cfg->logs_dir);
				view_log(str,"Hack Log");
				break;
		}
	}
}

int do_cmd(char *cmd)
{
	int i;
543
544
545
546
547
548
	struct text_info ti;
	char *p;

	gettextinfo(&ti);
	p=malloc(ti.screenheight*ti.screenwidth*2);
	gettext(1,1,ti.screenwidth,ti.screenheight,p);
549
	i=system(cmd);
550
551
	puttext(1,1,ti.screenwidth,ti.screenheight,p);
	free(p);
552
553
554
	return(i);
}

555
int qwk_callouts(scfg_t *cfg)
556
{
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
	char**	opt;
	int		i,j;
	char	str[1024];

	if(cfg->total_qhubs<1) {
		uifc.msg("No QWK hubs configured!");
		return(1);
	}

	if((opt=(char **)MALLOC(sizeof(char *)*(MAX_OPTS+1)))==NULL)
		allocfail(sizeof(char *)*(MAX_OPTS+1));
	for(i=0;i<(MAX_OPTS+1);i++)
		if((opt[i]=(char *)MALLOC(MAX_OPLN))==NULL)
			allocfail(MAX_OPLN);


573
574
575
576
	uifc.helpbuf=	"`QWK Callouts\n"
					"`------------\n\n"
					"Select the Hub and press enter to initiate a call out to\n"
					"the highlighted system.";
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596

	j=0;
	while(1) {
		for(i=0;i<cfg->total_qhubs;i++) {
			strcpy(opt[i],cfg->qhub[i]->id);
			sprintf(str,"%sqnet/%s.now",cfg->data_dir,cfg->qhub[i]->id);
			if(fexist(str))
				strcat(opt[i]," (pending)");
		}
		opt[i][0]=0;
		switch(uifc.list(WIN_MID|WIN_SAV,0,0,0,&j,0,"QWK Callouts",opt))  {
			case -1:
				freeopt(opt);
				return(0);
				break;
			default:
				sprintf(str,"%sqnet/%s.now",cfg->data_dir,cfg->qhub[j]->id);
				ftouch(str);
		}
	}
597
598
599
	return(0);
}

600
int run_events(scfg_t *cfg)
601
{
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
	char**	opt;
	int		i,j;
	char	str[1024];

	if((opt=(char **)MALLOC(sizeof(char *)*(MAX_OPTS+1)))==NULL)
		allocfail(sizeof(char *)*(MAX_OPTS+1));
	for(i=0;i<(MAX_OPTS+1);i++)
		if((opt[i]=(char *)MALLOC(MAX_OPLN))==NULL)
			allocfail(MAX_OPLN);

	if(cfg->total_events<1) {
		uifc.msg("No events configured!");
		return(1);
	}
	j=0;

618
619
620
	uifc.helpbuf=	"`Run Events\n"
					"`----------\n\n"
					"To run and event, highlight it and press Enter";
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639

	while(1) {
		for(i=0;i<cfg->total_events;i++) {
			strcpy(opt[i],cfg->event[i]->code);
			sprintf(str,"%s%s.now",cfg->data_dir,cfg->event[i]->code);
			if(fexist(str))
				strcat(opt[i]," (pending)");
		}
		opt[i][0]=0;
		switch(uifc.list(WIN_MID|WIN_SAV,0,0,0,&j,0,"Run Events",opt))  {
			case -1:
				freeopt(opt);
				return(0);
				break;
			default:
				sprintf(str,"%s%s.now",cfg->data_dir,cfg->event[j]->code);
				ftouch(str);
		}
	}
640
641
642
	return(0);
}

643
int recycle_servers(scfg_t *cfg)
644
{
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
	char str[1024];
	char **opt;
	int i=0;

	if((opt=(char **)MALLOC(sizeof(char *)*(MAX_OPTS+1)))==NULL)
		allocfail(sizeof(char *)*(MAX_OPTS+1));
	for(i=0;i<(MAX_OPTS+1);i++)
		if((opt[i]=(char *)MALLOC(MAX_OPLN))==NULL)
			allocfail(MAX_OPLN);

	i=0;
	strcpy(opt[i++],"FTP server");
	strcpy(opt[i++],"Mail server");
	strcpy(opt[i++],"Services");
	strcpy(opt[i++],"Telnet server");
	strcpy(opt[i++],"Web server");
	opt[i][0]=0;

663
664
665
666
667
	uifc.helpbuf=	"`Recycle Servers\n"
					"`---------------\n\n"
					"To rerun a server, highlight it and press Enter.\n"
					"This will reload the configuration files for selected\n"
					"server.";
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

	i=0;
	while(1) {
		switch(uifc.list(WIN_MID|WIN_SAV,0,0,0,&i,0,"Recycle Servers",opt))  {
			case -1:
				freeopt(opt);
				return(0);
				break;
			case 0:
				sprintf(str,"%sftpsrvr.rec",cfg->ctrl_dir);
				ftouch(str);
				break;
			case 1:
				sprintf(str,"%smailsrvr.rec",cfg->ctrl_dir);
				ftouch(str);
				break;
			case 2:
				sprintf(str,"%sservices.rec",cfg->ctrl_dir);
				ftouch(str);
				break;
			case 3:
				sprintf(str,"%stelnet.rec",cfg->ctrl_dir);
				ftouch(str);
				break;
			case 4:
				sprintf(str,"%swebsrvr.rec",cfg->ctrl_dir);
				ftouch(str);
				break;
		}
	}
698
699
700
	return(0);
}

701
702
703
704
705
706
707
708
709
710
711
712
713
714
char *geteditor(char *edit)
{
	if(getenv("EDITOR")==NULL && (getenv("VISUAL")==NULL || getenv("DISPLAY")==NULL))
		strcpy(edit,"vi");
	else {
		if(getenv("DISPLAY")!=NULL && getenv("VISUAL")!=NULL)
			strcpy(edit,getenv("VISUAL"));
		else
			strcpy(edit,getenv("EDITOR"));
	}
	return(edit);
}


715
716
717
718
719
int edit_cfg(scfg_t *cfg)
{
	char**	opt;
	int		i;
	char	cmd[1024];
720
	char	editcmd[1024];
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744

	if((opt=(char **)MALLOC(sizeof(char *)*(MAX_OPTS+1)))==NULL)
		allocfail(sizeof(char *)*(MAX_OPTS+1));
	for(i=0;i<(MAX_OPTS+1);i++)
		if((opt[i]=(char *)MALLOC(MAX_OPLN))==NULL)
			allocfail(MAX_OPLN);

	i=0;
	strcpy(opt[i++],"alias.cfg");
	strcpy(opt[i++],"attr.cfg");
	strcpy(opt[i++],"dns_blacklist.cfg");
	strcpy(opt[i++],"dnsbl_exempt.cfg");
	strcpy(opt[i++],"domains.cfg");
	strcpy(opt[i++],"mailproc.cfg");
	strcpy(opt[i++],"mime_types.cfg");
	strcpy(opt[i++],"relay.cfg");
	strcpy(opt[i++],"sbbsecho.cfg");
	strcpy(opt[i++],"services.cfg");
	strcpy(opt[i++],"ftpalias.cfg");
	strcpy(opt[i++],"sockopts.cfg");
	strcpy(opt[i++],"spambait.cfg");
	strcpy(opt[i++],"spamblock.cfg");
	strcpy(opt[i++],"twitlist.cfg");
	opt[i][0]=0;
745
	uifc.helpbuf= "Highlight desired file and hit Enter to edit it.";
746
747
748
749
	i=0;
	while(1) {
		switch(uifc.list(WIN_MID|WIN_SAV,0,0,0,&i,0,"System Options",opt))  {
			case -1:
750
				freeopt(opt);
751
				return(0);
752
				break;
753
			default:
754
				sprintf(cmd,"%s %s%s",geteditor(editcmd),cfg->ctrl_dir,opt[i]);
755
756
757
758
759
760
				do_cmd(cmd);
				break;
		}
	}
	return(0);
}
761

762
763
764
765
766
int edit_can(scfg_t *cfg)
{
	char**	opt;
	int		i;
	char	cmd[1024];
767
	char	editcmd[1024];
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785

	if((opt=(char **)MALLOC(sizeof(char *)*(MAX_OPTS+1)))==NULL)
		allocfail(sizeof(char *)*(MAX_OPTS+1));
	for(i=0;i<(MAX_OPTS+1);i++)
		if((opt[i]=(char *)MALLOC(MAX_OPLN))==NULL)
			allocfail(MAX_OPLN);

	i=0;
	strcpy(opt[i++],"email.can");
	strcpy(opt[i++],"file.can");
	strcpy(opt[i++],"host.can");
	strcpy(opt[i++],"ip.can");
	strcpy(opt[i++],"ip-silent.can");
	strcpy(opt[i++],"name.can");
	strcpy(opt[i++],"phone.can");
	strcpy(opt[i++],"rlogin.can");
	strcpy(opt[i++],"subject.can");
	opt[i][0]=0;
786
	uifc.helpbuf="Highlight desired file and hit Enter to edit it.";
787
788
789
790
	i=0;
	while(1) {
		switch(uifc.list(WIN_MID|WIN_SAV,0,0,0,&i,0,"System Options",opt))  {
			case -1:
791
				freeopt(opt);
792
				return(0);
793
				break;
794
			default:
795
				sprintf(cmd,"%s %s%s",geteditor(editcmd),cfg->text_dir,opt[i]);
796
797
798
799
800
801
				do_cmd(cmd);
				break;
		}
	}
	return(0);
}
802

803
int main(int argc, char** argv)  {
804

805
806
807
808
	char**	opt;
	char**	mopt;
	int		main_dflt=0;
	int		main_bar=0;
deuce's avatar
deuce committed
809
810
811
812
813
	char	revision[16];
	char	str[256],ctrl_dir[41],*p;
	char	title[256];
	int		i,j;
	node_t	node;
814
815
816
	int		nodefile;
	box_t	boxch;
	scfg_t	cfg;
817
	int		done;
deuce's avatar
deuce committed
818
	int		ciolib_mode=CIOLIB_MODE_AUTO;
819

deuce's avatar
deuce committed
820
821
822
	/******************/
	/* Ini file stuff */
	/******************/
823
824
825
	char	ini_file[MAX_PATH+1];
	FILE*				fp;
	bbs_startup_t		bbs_startup;
826
827

	sscanf("$Revision$", "%*s %s", revision);
828

829
    printf("\nSynchronet UNIX Monitor %s-%s  Copyright 2004 "
830
831
832
833
834
835
836
837
838
839
840
841
842
843
        "Rob Swindell\n",revision,PLATFORM_DESC);

	p=getenv("SBBSCTRL");
	if(p==NULL) {
		printf("\7\nSBBSCTRL environment variable is not set.\n");
		printf("This environment variable must be set to your CTRL directory.");
		printf("\nExample: SET SBBSCTRL=/sbbs/ctrl\n");
		exit(1); }

	sprintf(ctrl_dir,"%.40s",p);
	if(ctrl_dir[strlen(ctrl_dir)-1]!='\\'
		&& ctrl_dir[strlen(ctrl_dir)-1]!='/')
		strcat(ctrl_dir,"/");

deuce's avatar
deuce committed
844
	gethostname(str,sizeof(str)-1);
845
846

	sbbs_get_ini_fname(ini_file, ctrl_dir, str);
847
848
849
850
851
852
853
854
855
856
857

	/* Initialize BBS startup structure */
    memset(&bbs_startup,0,sizeof(bbs_startup));
    bbs_startup.size=sizeof(bbs_startup);
    strcpy(bbs_startup.ctrl_dir,ctrl_dir);

	/* Read .ini file here */
	if(ini_file[0]!=0 && (fp=fopen(ini_file,"r"))!=NULL) {
		printf("Reading %s\n",ini_file);
	}
	/* We call this function to set defaults, even if there's no .ini file */
858
	sbbs_read_ini(fp,
859
		NULL,		/* global_startup */
860
		NULL, &bbs_startup,
861
		NULL, NULL, /* ftp_startup */
862
		NULL, NULL, /* web_startup */
863
864
865
		NULL, NULL, /* mail_startup */
		NULL, NULL  /* services_startup */
		);
866
867
868
869
870
871

	/* close .ini file here */
	if(fp!=NULL)
		fclose(fp);

	chdir(bbs_startup.ctrl_dir);
872

873
	/* Read .cfg files here */
874
    memset(&cfg,0,sizeof(cfg));
875
	cfg.size=sizeof(cfg);
876
877
	SAFECOPY(cfg.ctrl_dir,bbs_startup.ctrl_dir);
	if(!load_cfg(&cfg, NULL, TRUE, str)) {
878
879
880
		printf("ERROR! %s\n",str);
		exit(1);
	}
881
	prep_dir(cfg.data_dir, cfg.temp_dir, sizeof(cfg.temp_dir));
882

883
884
885
886
    memset(&uifc,0,sizeof(uifc));

	uifc.esc_delay=500;

887
	boxch.ls=186;
888
889
890
891
892
893
894
	boxch.rs=186;
	boxch.ts=205;
	boxch.bs=205;
	boxch.tl=201;
	boxch.tr=187;
	boxch.bl=200;
	boxch.br=188;
895
896
897
898
899
900
901
902
903
904
905
906
907
908
	for(i=1;i<argc;i++) {
        if(argv[i][0]=='-'
            )
            switch(toupper(argv[i][1])) {
                case 'C':
        			uifc.mode|=UIFC_COLOR;
                    break;
                case 'L':
                    uifc.scrn_len=atoi(argv[i]+2);
                    break;
                case 'E':
                    uifc.esc_delay=atoi(argv[i]+2);
                    break;
				case 'I':
deuce's avatar
deuce committed
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
					switch(toupper(argv[i][2])) {
						case 'A':
							ciolib_mode=CIOLIB_MODE_ANSI;
							break;
						case 'C':
							ciolib_mode=CIOLIB_MODE_CURSES;
							break;
						case 0:
							printf("NOTICE: The -i option is depreciated, use -if instead\r\n");
							SLEEP(2000);
						case 'F':
							ciolib_mode=CIOLIB_MODE_CURSES_IBM;
							break;
						case 'X':
							ciolib_mode=CIOLIB_MODE_X;
							break;
						case 'W':
							ciolib_mode=CIOLIB_MODE_CONIO;
							break;
						default:
							goto USAGE;
					}
931
932
					break;
                default:
deuce's avatar
deuce committed
933
					USAGE:
934
935
936
937
                    printf("\nusage: %s [ctrl_dir] [options]"
                        "\n\noptions:\n\n"
                        "-c  =  force color mode\n"
                        "-e# =  set escape delay to #msec\n"
deuce's avatar
deuce committed
938
939
940
941
942
943
944
945
946
						"-iX =  set interface mode to X (default=auto) where X is one of:\r\n"
#ifdef __unix__
						"       X = X11 mode\r\n"
						"       C = Curses mode\r\n"
						"       F = Curses mode with forced IBM charset\r\n"
#else
						"       W = Win32 native mode\r\n"
#endif
						"       A = ANSI mode\r\n"
947
948
949
950
951
952
953
                        "-l# =  set screen lines to #\n"
						,argv[0]
                        );
        			exit(0);
           }
    }

954
	signal(SIGPIPE, SIG_IGN);
955

956
	uifc.size=sizeof(uifc);
deuce's avatar
deuce committed
957
958
959
960
961
	i=initciolib(ciolib_mode);
	if(i!=0) {
    	printf("ciolib library init returned error %d\n",i);
    	exit(1);
	}
deuce's avatar
deuce committed
962
	i=uifcini32(&uifc);  /* curses */
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
	if(i!=0) {
		printf("uifc library init returned error %d\n",i);
		exit(1);
	}

	if((opt=(char **)MALLOC(sizeof(char *)*(MAX_OPTS+1)))==NULL)
		allocfail(sizeof(char *)*(MAX_OPTS+1));
	for(i=0;i<(MAX_OPTS+1);i++)
		if((opt[i]=(char *)MALLOC(MAX_OPLN))==NULL)
			allocfail(MAX_OPLN);

	if((mopt=(char **)MALLOC(sizeof(char *)*MAX_OPTS))==NULL)
		allocfail(sizeof(char *)*MAX_OPTS);
	for(i=0;i<MAX_OPTS;i++)
		if((mopt[i]=(char *)MALLOC(MAX_OPLN))==NULL)
			allocfail(MAX_OPLN);

980
981
	sprintf(title,"Synchronet UNIX Monitor %s-%s",revision,PLATFORM_DESC);
	if(uifc.scrn(title)) {
982
983
984
985
986
		printf(" USCRN (len=%d) failed!\n",uifc.scrn_len+1);
		bail(1);
	}

	while(1) {
987
		strcpy(mopt[0],"System Options");
988
989
		for(i=1;i<=cfg.sys_nodes;i++) {
			if((j=getnodedat(&cfg,i,&node,NULL)))
990
				sprintf(mopt[i],"Error reading node data (%d)!",j);
991
			else
992
				sprintf(mopt[i],"%3d: %s",i,nodestatus(&cfg,&node,str,71));
993
		}
994
		mopt[i][0]=0;
995

996
997
		uifc.helpbuf=	"`Synchronet Monitor\n"
		                "`------------------\n"
998
		                "Welcome to the Synchronet UNIX Monitor.\n"
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
		                "Displayed on this screen are the statitics for the BBS\n"
		                "You can scroll through the list starting at \"System Options\" \n"
		                "Pressing Enter on each will give a menu of option to perform.\n"
		                "Additionally these keys are available from this screen:\n\n"
						"`CTRL-E : `Displays the error log\n"
						"`F12    : `Spys on the currently selected node\n"
						"`F11    : `Send message to the currently selected node\n"
						"`F10    : `Chats with the user on the currently selected node\n"
						"`DEL    : `Clear errors on currently selected node\n"
						"`CTRL-L : `Lock node toggle\n"
						"`CTRL-R : `Rerun node\n"
						"`CTRL-D : `Down node toggle\n"
						"`CTRL-I : `Interrupt node\n";
deuce's avatar
deuce committed
1012

1013
		drawstats(&cfg, main_dflt, &node, &main_dflt, &main_bar);
deuce's avatar
deuce committed
1014

1015
		j=uifc.list(WIN_L2R|WIN_ESC|WIN_ACT|WIN_DYN,0,5,70,&main_dflt,&main_bar
1016
1017
			,title,mopt);

deuce's avatar
deuce committed
1018
1019
1020
		if(j == -2)
			continue;

1021
		if(j==-7) {	/* CTRL-E */
1022
			sprintf(str,"%s/error.log",cfg.data_dir);
1023
			view_log(str,"Error Log");
1024
1025
			continue;
		}
1026

1027
1028
1029
1030
		if(j==0) {
			/* System Options */
			i=0;
			strcpy(opt[i++],"Run SCFG");
1031
			strcpy(opt[i++],"Run User Editor");
1032
1033
1034
1035
1036
1037
1038
			strcpy(opt[i++],"View logs");
			strcpy(opt[i++],"Force QWK Net callout");
			strcpy(opt[i++],"Run event");
			strcpy(opt[i++],"Recycle servers");
			strcpy(opt[i++],"Edit CFG files");
			strcpy(opt[i++],"Edit trashcan files");
			opt[i][0]=0;
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
			uifc.helpbuf=	"`System Options`\n"
			                "`------------`\n\n"
							"`Run SCFG              : `Run the Synchronet Configuration Utility.\n"
							"`Run User Editor       : `Call up the User Editor.\n"
							"`View logs             : `View the various system logs.\n"
							"`Force QWK Net callout : `Force a callout to QWK Net Hub.  Select which\n"
							"                        Hub from a popup list of configured Hubs.\n"
							"`Run Event             : `Call up a menu of system events that can be\n"
							"                        manually.\n"
							"`Recycle Servers       : `Have the Servers reload their configuration \n"
							"                        files.\n"
							"`Edit trashcan files   : `Edit the various .can files.  i.e.; ip.can";
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068

			done=0;
			i=0;
			while(!done) {
				switch(uifc.list(WIN_MID|WIN_SAV,0,0,0,&i,0,"System Options",opt))  {
					case -1:
						done=1;
						break;
					case 0:
						sprintf(str,"%sscfg ",cfg.exec_dir);
						for(j=1; j<argc; j++) {
							strcat(str,"'");
							strcat(str,argv[j]);
							strcat(str,"' ");
						}
						do_cmd(str);
						break;
					case 1:
1069
						sprintf(str,"%suedit ",cfg.exec_dir);
1070
1071
1072
1073
1074
1075
						for(j=1; j<argc; j++) {
							strcat(str,"'");
							strcat(str,argv[j]);
							strcat(str,"' ");
						}
						do_cmd(str);
1076
1077
						break;
					case 2:
1078
						view_logs(&cfg);
1079
1080
						break;
					case 3:
1081
						qwk_callouts(&cfg);
1082
1083
						break;
					case 4:
1084
						run_events(&cfg);
1085
1086
						break;
					case 5:
1087
						recycle_servers(&cfg);
1088
1089
						break;
					case 6:
1090
1091
1092
						edit_cfg(&cfg);
						break;
					case 7:
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
						edit_can(&cfg);
						break;
				}
			}
			continue;
		}

		if(j==-1) {
			i=0;
			strcpy(opt[0],YesStr);
			strcpy(opt[1],NoStr);
			opt[2][0]=0;
			uifc.helpbuf=	"`Exit Synchronet UNIX Monitor:`\n"
							"\n"
							"\nIf you want to exit the Synchronet UNIX monitor utility,"
							"\nselect `Yes`. Otherwise, select `No` or hit ~ ESC ~.";
			i=uifc.list(WIN_MID,0,0,0,&i,0,"Exit Synchronet Monitor",opt);
			if(!i)
				bail(0);
			continue;
		}

		/* Everything after this point is invalid for the System Options */
		if(main_dflt==0)
			continue;

1119
		if(j==-2-CIO_KEY_DC) {	/* Clear errors */
1120
			clearerrors(&cfg, main_dflt,&node);
1121
1122
1123
			continue;
		}

1124
		if(j==-2-CIO_KEY_F(10)) {	/* Chat */
1125
			if(getnodedat(&cfg,main_dflt,&node,NULL)) {
1126
1127
1128
				uifc.msg("Error reading node data!");
				continue;
			}
1129
			if((node.status==NODE_INUSE) && node.useron)
1130
				chat(&cfg,main_dflt,&node,&boxch,NULL);
1131
1132
1133
			continue;
		}

1134
		if(j==-2-CIO_KEY_F(11)) {	/* Send message */
1135
			sendmessage(&cfg, main_dflt,&node);
1136
1137
			continue;
		}
1138

1139
		if(j==-2-CIO_KEY_F(12)) {	/* Spy */
1140
			dospy(main_dflt,&bbs_startup);
1141
1142
			continue;
		}
1143

1144
		if(j==-2-CTRL('l')) {	/* Lock node */
1145
			if(getnodedat(&cfg,main_dflt,&node,&nodefile)) {
1146
1147
1148
1149
				uifc.msg("Error reading node data!");
				continue;
			}
			node.misc^=NODE_LOCK;
1150
			putnodedat(&cfg,main_dflt,&node,nodefile);
1151
			continue;
deuce's avatar
deuce committed
1152
		}
1153

1154
		if(j==-2-CTRL('r')) {	/* Rerun node */
1155
			if(getnodedat(&cfg,main_dflt,&node,&nodefile)) {
1156
1157
1158
1159
				uifc.msg("Error reading node data!");
				continue;
			}
			node.misc^=NODE_RRUN;
1160
			putnodedat(&cfg,main_dflt,&node,nodefile);
1161
1162
			continue;
		}
1163

1164
		if(j==-2-CTRL('d')) {	/* Down node */
1165
			if(getnodedat(&cfg,main_dflt,&node,&nodefile)) {
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
				uifc.msg("Error reading node data!");
				continue;
			}
			if(node.status != NODE_WFC && node.status != NODE_OFFLINE)
				node.misc ^= NODE_DOWN;
			else {
				if(node.status!=NODE_OFFLINE)
					node.status=NODE_OFFLINE;
				else
					node.status=NODE_WFC;
			}
1177
			putnodedat(&cfg,main_dflt,&node,nodefile);
1178
1179
1180
1181
			continue;
		}

		if(j==-2-CTRL('i')) {	/* Interrupt node */
1182
			if(getnodedat(&cfg,main_dflt,&node,&nodefile)) {
1183
1184
1185
1186
				uifc.msg("Error reading node data!");
				continue;
			}
			node.misc^=NODE_INTR;
1187
			putnodedat(&cfg,main_dflt,&node,nodefile);
1188
1189
			continue;
		}
1190

1191
		if(j <= -2)
1192
1193
			continue;

1194
		if(j<=cfg.sys_nodes && j>0) {
1195
1196
1197
1198
1199
1200
		  if((node.status==NODE_INUSE) && node.useron) {
      		i=0;
   			strcpy(opt[i++],"Edit User");
   			strcpy(opt[i++],"Spy on node");
			strcpy(opt[i++],"Send message to user");
			strcpy(opt[i++],"Chat with user");
1201
1202
			strcpy(opt[i++],"Node toggles");
			strcpy(opt[i++],"Clear Errors");
1203
1204
			strcpy(opt[i++],"View node log");
			strcpy(opt[i++],"View crash log");
1205

1206
1207
			opt[i][0]=0;
			i=0;
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
			uifc.helpbuf=	"`Node Options\n"
			                "`------------\n\n"
							"`Edit User            : `Call up the user editor to edit current user.\n"
							"`Spy on User          : `Spy on current user.\n"
							"`Send message to user : `Send on online message to user.\n"
							"`Chat with user       : `Initiate private split-screen chat wityh user.\n"
							"`Node Toggles         : `Call up Node Toggles menu to set various toggles\n"
							"                       for current node.\n"
							"`Clear Errors         : `Clears the error count for node.\n"
							"`View node log        : `View activity log for current node.\n"
							"`View crash log       : `View the crash log for current node.";
1219
1220
1221
			done=0;
			while(!done) {
				switch(uifc.list(WIN_MID|WIN_SAV,0,0,0,&i,0,"Node Options",opt))  {
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233

					case 0:  /* Edit Users */
						sprintf(str,"%suedit %d",cfg.exec_dir,node.useron);
						for(j=1; j<argc; j++) {
						  strcat(str,"'");
						  strcat(str,argv[j]);
						  strcat(str,"' ");
						}
						do_cmd(str);
						break;

				    case 1:	/* Spy */
1234
1235
1236
						dospy(j,&bbs_startup);
						break;

1237
1238
1239
1240
1241
1242
1243
1244
1245
					case 2:	/* Send message */
						sendmessage(&cfg, j,&node);
						break;

					case 3: /* Chat with User */
						chat(&cfg,main_dflt,&node,&boxch,NULL);
						break;

					case 4: /* Node Toggles */
1246
1247
						node_toggles(&cfg, j);
						break;
1248
1249

					case 5:
1250
1251
						clearerrors(&cfg, j,&node);
						break;
1252
1253

					case 6: /* Node log */
1254
1255
1256
1257
						sprintf(str,"%snode.log",cfg.node_path[j-1]);
						view_log(str,"Node Log");
						break;

1258
					case 7: /* Crash log */
1259
1260
1261
						sprintf(str,"%scrash.log",cfg.node_path[j-1]);
						view_log(str,"Crash Log");
						break;
1262
1263
1264

					case -1:
						done=1;
1265
						break;
1266
1267
1268

					default:
						uifc.msg("Option not implemented");
1269
						break;
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
					}
				}
            }
         }
		if(j<=cfg.sys_nodes && j>0) {
		  if(!((node.status==NODE_INUSE) && node.useron)) {

           	i=0;
			strcpy(opt[i++],"Node toggles");
			strcpy(opt[i++],"Clear Errors");
			strcpy(opt[i++],"View node log");
			strcpy(opt[i++],"View crash log");

			opt[i][0]=0;
			i=0;
			uifc.helpbuf=	"`Node Options\n"
			                "`------------\n\n"