umonitor.c 19.6 KB
Newer Older
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
/* 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)		*
 *																			*
 * Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html		*
 *																			*
 * 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 "sbbs.h"
39
40
#include "conwrap.h"	/* this has to go BEFORE curses.h so getkey() can be macroed around */
#include <curses.h>
deuce's avatar
deuce committed
41
42
43
44
45
#include <sys/types.h>
#include <sys/time.h>
#ifdef __QNX__
#include <string.h>
#endif
46
#include <stdio.h>
47
#include <unistd.h>
48
#include "genwrap.h"
49
50
51
#include "uifc.h"
#include "sbbsdefs.h"
#include "genwrap.h"	/* stricmp */
52
#include "dirwrap.h"	/* lock/unlock/sopen */
53
#include "filewrap.h"	/* lock/unlock/sopen */
54
55
56
#include "sbbs_ini.h"	/* INI parsing */
#include "scfglib.h"	/* SCFG files */
#include "ars_defs.h"	/* needed for SCFG files */
57
#include "userdat.h"	/* getnodedat() */
58
#include "spyon.h"
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
enum {
	 MODE_LIST
	,MODE_ANON
	,MODE_LOCK
	,MODE_INTR
	,MODE_RRUN
	,MODE_DOWN
	,MODE_EVENT
	,MODE_NOPAGE
	,MODE_NOALERTS
	,MODE_STATUS
	,MODE_USERON
	,MODE_ACTION
	,MODE_ERRORS
	,MODE_MISC
	,MODE_CONN
	,MODE_AUX
	,MODE_EXTAUX
	};

/********************/
/* Global Variables */
/********************/
uifcapi_t uifc; /* User Interface (UIFC) Library API */
char tmp[256];
int nodefile;
86
87
const char *YesStr="Yes";
const char *NoStr="No";
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
scfg_t	cfg;

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);
}
103

104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
void bail(int code)
{
    if(code) {
        puts("\nHit a key...");
        getch(); 
	}
    uifc.bail();

    exit(code);
}

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

121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
char* itoa(int val, char* str, int radix)
{
	switch(radix) {
		case 8:
			sprintf(str,"%o",val);
			break;
		case 10:
			sprintf(str,"%u",val);
			break;
		case 16:
			sprintf(str,"%x",val);
			break;
		default:
			sprintf(str,"bad radix: %d",radix);
			break;
	}
	return(str);
}

/******************************************************************************************/
/* Returns the information for node number 'number' contained in 'node' into string 'str' */
/******************************************************************************************/
deuce's avatar
deuce committed
143
char *nodedat(char *str, int number, node_t *node)
144
145
146
{
    char hour,mer[3];
	char buf[1024];
147
	user_t	user;
148
149

	sprintf(str,"Node %2d: ",number);
deuce's avatar
deuce committed
150
	switch(node->status) {
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
		case NODE_WFC:
			strcat(str,"Waiting for call");
			break;
		case NODE_OFFLINE:
			strcat(str,"Offline");
			break;
		case NODE_NETTING:
			strcat(str,"Networking");
			break;
		case NODE_LOGON:
			strcat(str,"At logon prompt");
			break;
		case NODE_EVENT_WAITING:
			strcat(str,"Waiting for all nodes to become inactive");
			break;
		case NODE_EVENT_LIMBO:
deuce's avatar
deuce committed
167
			sprintf(buf,"Waiting for node %d to finish external event",node->aux);
168
169
170
171
172
173
174
175
			strcat(str,buf);
			break;
		case NODE_EVENT_RUNNING:
			strcat(str,"Running external event");
			break;
		case NODE_NEWUSER:
			strcat(str,"New user");
			strcat(str," applying for access ");
deuce's avatar
deuce committed
176
			if(!node->connection)
177
				strcat(str,"locally");
deuce's avatar
deuce committed
178
			else if(node->connection==0xffff)
179
180
				strcat(str,"via telnet");
			else {
deuce's avatar
deuce committed
181
				sprintf(buf,"at %ubps",node->connection);
182
183
184
185
				strcat(str,buf); }
			break;
		case NODE_QUIET:
		case NODE_INUSE:
deuce's avatar
deuce committed
186
			user.number=node->useron;
187
188
189
190
191
			getuserdat(&cfg,&user);
			if(user.alias[0])
				sprintf(buf,"%s",user.alias);
			else
				sprintf(buf,"%s",user.name);
192
193
			strcat(str,buf);
			strcat(str," ");
deuce's avatar
deuce committed
194
			switch(node->action) {
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
				case NODE_MAIN:
					strcat(str,"at main menu");
					break;
				case NODE_RMSG:
					strcat(str,"reading messages");
					break;
				case NODE_RMAL:
					strcat(str,"reading mail");
					break;
				case NODE_RSML:
					strcat(str,"reading sent mail");
					break;
				case NODE_RTXT:
					strcat(str,"reading text files");
					break;
				case NODE_PMSG:
					strcat(str,"posting message");
					break;
				case NODE_SMAL:
					strcat(str,"sending mail");
					break;
				case NODE_AMSG:
					strcat(str,"posting auto-message");
					break;
				case NODE_XTRN:
deuce's avatar
deuce committed
220
					if(!node->aux)
221
222
						strcat(str,"at external program menu");
					else
deuce's avatar
deuce committed
223
						sprintf(buf,"running external program \"%s\"",cfg.xtrn[node->aux-1]->name);
224
					strcat(str,buf);
225
226
227
228
229
230
231
232
					break;
				case NODE_DFLT:
					strcat(str,"changing defaults");
					break;
				case NODE_XFER:
					strcat(str,"at transfer menu");
					break;
				case NODE_RFSD:
deuce's avatar
deuce committed
233
					sprintf(buf,"retrieving from device #%d",node->aux);
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
					strcat(str,buf);
					break;
				case NODE_DLNG:
					strcat(str,"downloading");
					break;
				case NODE_ULNG:
					strcat(str,"uploading");
					break;
				case NODE_BXFR:
					strcat(str,"transferring bidirectional");
					break;
				case NODE_LFIL:
					strcat(str,"listing files");
					break;
				case NODE_LOGN:
					strcat(str,"logging on");
					break;
				case NODE_LCHT:
					strcat(str,"in local chat with sysop");
					break;
				case NODE_MCHT:
deuce's avatar
deuce committed
255
256
					if(node->aux) {
						sprintf(buf,"in multinode chat channel %d",node->aux&0xff);
257
						strcat(str,buf);
deuce's avatar
deuce committed
258
						if(node->aux&0x1f00) { /* password */
259
							strcat(str,"*");
deuce's avatar
deuce committed
260
							sprintf(buf," %s",unpackchatpass(tmp,node));
261
262
263
264
265
							strcat(str,buf); } }
					else
						strcat(str,"in multinode global chat channel");
					break;
				case NODE_PAGE:
deuce's avatar
deuce committed
266
					sprintf(buf,"paging node %u for private chat",node->aux);
267
268
269
					strcat(str,buf);
					break;
				case NODE_PCHT:
deuce's avatar
deuce committed
270
					sprintf(buf,"in private chat with node %u",node->aux);
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
					strcat(str,buf);
					break;
				case NODE_GCHT:
					strcat(str,"chatting with The Guru");
					break;
				case NODE_CHAT:
					strcat(str,"in chat section");
					break;
				case NODE_TQWK:
					strcat(str,"transferring QWK packet");
					break;
				case NODE_SYSP:
					strcat(str,"performing sysop activities");
					break;
				default:
deuce's avatar
deuce committed
286
					sprintf(buf,itoa(node->action,tmp,10));
287
288
					strcat(str,buf);
					break;  }
deuce's avatar
deuce committed
289
			if(!node->connection)
290
				strcat(str," locally");
deuce's avatar
deuce committed
291
			else if(node->connection==0xffff)
292
293
				strcat(str," via telnet");
			else {
deuce's avatar
deuce committed
294
				sprintf(buf," at %ubps",node->connection);
295
				strcat(str,buf); }
deuce's avatar
deuce committed
296
297
298
			if(node->action==NODE_DLNG) {
				if((node->aux/60)>=12) {
					if(node->aux/60==12)
299
300
						hour=12;
					else
deuce's avatar
deuce committed
301
						hour=(node->aux/60)-12;
302
303
					strcpy(mer,"pm"); }
				else {
deuce's avatar
deuce committed
304
					if((node->aux/60)==0)    /* 12 midnite */
305
						hour=12;
deuce's avatar
deuce committed
306
					else hour=node->aux/60;
307
308
					strcpy(mer,"am"); }
				sprintf(buf," ETA %02d:%02d %s"
deuce's avatar
deuce committed
309
					,hour,node->aux-((node->aux/60)*60),mer); 
310
311
				strcat(str,buf); }
			break; }
deuce's avatar
deuce committed
312
	if(node->misc&(NODE_LOCK|NODE_POFF|NODE_AOFF|NODE_MSGW|NODE_NMSG)) {
313
		strcat(str," (");
deuce's avatar
deuce committed
314
		if(node->misc&NODE_AOFF)
315
			strcat(str,"A");
deuce's avatar
deuce committed
316
		if(node->misc&NODE_LOCK)
317
			strcat(str,"L");
deuce's avatar
deuce committed
318
		if(node->misc&(NODE_MSGW|NODE_NMSG))
319
			strcat(str,"M");
deuce's avatar
deuce committed
320
		if(node->misc&NODE_POFF)
321
322
			strcat(str,"P");
		strcat(str,")"); }
deuce's avatar
deuce committed
323
	if(((node->misc
324
		&(NODE_ANON|NODE_UDAT|NODE_INTR|NODE_RRUN|NODE_EVENT|NODE_DOWN))
deuce's avatar
deuce committed
325
		|| node->status==NODE_QUIET)) {
326
		strcat(str," [");
deuce's avatar
deuce committed
327
		if(node->misc&NODE_ANON)
328
			strcat(str,"A");
deuce's avatar
deuce committed
329
		if(node->misc&NODE_INTR)
330
			strcat(str,"I");
deuce's avatar
deuce committed
331
		if(node->misc&NODE_RRUN)
332
			strcat(str,"R");
deuce's avatar
deuce committed
333
		if(node->misc&NODE_UDAT)
334
			strcat(str,"U");
deuce's avatar
deuce committed
335
		if(node->status==NODE_QUIET)
336
			strcat(str,"Q");
deuce's avatar
deuce committed
337
		if(node->misc&NODE_EVENT)
338
			strcat(str,"E");
deuce's avatar
deuce committed
339
		if(node->misc&NODE_DOWN)
340
			strcat(str,"D");
deuce's avatar
deuce committed
341
		if(node->misc&NODE_LCHAT)
342
343
			strcat(str,"C");
		strcat(str,"]"); }
deuce's avatar
deuce committed
344
345
	if(node->errors) {
		sprintf(buf," %d error%c",node->errors, node->errors>1 ? 's' : '\0' );
346
347
348
349
		strcat(str,buf); }
	return(str);
}

350
351
352
353
354
355
356
357
358
359
360
361
362
363
void node_toggles(int nodenum)  {
	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;
	uifc.helpbuf=	"`Node Toggles:`\n"
364
					"\nToDo: Add help (Mention that changes take effect immediately)";
365
	while(save==0) {
366
367
368
369
		if(getnodedat(&cfg,nodenum,&node,&nodefile)) {
			uifc.msg("Error reading node data!");
			break;
		}
370
371
372
373
374
375
		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);
		sprintf(opt[j++],"%-30s%3s","Page disabled",node.misc&NODE_POFF ? YesStr : NoStr);
		sprintf(opt[j++],"%-30s%3s","Activity alert disabled",node.misc&NODE_AOFF ? YesStr : NoStr);
		sprintf(opt[j++],"%-30s%3s","Re-run on logoff",node.misc&NODE_RRUN ? YesStr : NoStr);
376
		sprintf(opt[j++],"%-30s%3s","Down node after logoff",(node.misc&NODE_DOWN || (node.status==NODE_OFFLINE)) ? YesStr : NoStr);
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
		sprintf(opt[j++],"%-30s%3s","Reset private chat",node.misc&NODE_RPCHT ? YesStr : NoStr);
		opt[j][0]=0;

		switch(uifc.list(WIN_MID,0,0,0,&i,0,"Node Toggles",opt)) {
			case 0:	/* Locked */
				node.misc ^= NODE_LOCK;
				break;

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

			case 2:	/* Page disabled */
				node.misc ^= NODE_POFF;
				break;

			case 3:	/* Activity alert */
				node.misc ^= NODE_AOFF;
				break;

			case 4:	/* Re-run */
				node.misc ^= NODE_RRUN;
				break;

			case 5:	/* Down */
402
				if(node.status == NODE_INUSE || node.status==NODE_LOGON)
403
					node.misc ^= NODE_DOWN;
404
				else {
405
406
407
408
409
					if(node.status!=NODE_OFFLINE)
						node.status=NODE_OFFLINE;
					else
						node.status=NODE_WFC;
				}
410
411
412
413
414
415
416
417
418
419
420
421
422
423
				break;

			case 6:	/* Reset chat */
				node.misc ^= NODE_RPCHT;
				break;
				
			case -1:
				save=1;
				break;
				
			default:
				uifc.msg("Option not implemented");
				continue;
		}
424
		putnodedat(&cfg,nodenum,&node,nodefile);
425
426
427
	}
}

428
int main(int argc, char** argv)  {
429
430
431
432
433
	char**	opt;
	char**	mopt;
	int		main_dflt=0;
	int		main_bar=0;
	char revision[16];
434
	char str[256],str2[256],ctrl_dir[41],*p;
435
	char title[256];
436
	int i,j;
437
	node_t node;
438
439
	char	*buf;
	int		buffile;
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
/******************/
/* Ini file stuff */
/******************/
	char	host_name[128]="";
	char	ini_file[MAX_PATH+1];
	FILE*				fp;
	BOOL				run_bbs;
	bbs_startup_t		bbs_startup;
	BOOL				run_ftp;
	ftp_startup_t		ftp_startup;
	BOOL				run_web;
	web_startup_t		web_startup;
	BOOL				run_mail;
	mail_startup_t		mail_startup;
	BOOL				run_services;
	services_startup_t	services_startup;
456
457

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

459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
    printf("\nSynchronet UNIX Monitor %s-%s  Copyright 2003 "
        "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,"/");

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
	gethostname(host_name,sizeof(host_name)-1);
	sprintf(ini_file,"%s%c%s.ini",ctrl_dir,BACKSLASH,host_name);
#if defined(PREFIX)
	if(!fexistcase(ini_file))
		sprintf(ini_file,"%s/etc/sbbs.ini",PREFIX);
#endif
	if(!fexistcase(ini_file))
		sprintf(ini_file,"%s%csbbs.ini",ctrl_dir,BACKSLASH);

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

	/* Initialize FTP startup structure */
    memset(&ftp_startup,0,sizeof(ftp_startup));
    ftp_startup.size=sizeof(ftp_startup);
    strcpy(ftp_startup.index_file_name,"00index");
    strcpy(ftp_startup.ctrl_dir,ctrl_dir);

	/* Initialize Web Server startup structure */
    memset(&web_startup,0,sizeof(web_startup));
    web_startup.size=sizeof(web_startup);
    strcpy(web_startup.ctrl_dir,ctrl_dir);

	/* Initialize Mail Server startup structure */
    memset(&mail_startup,0,sizeof(mail_startup));
    mail_startup.size=sizeof(mail_startup);
    strcpy(mail_startup.ctrl_dir,ctrl_dir);

	/* Look up DNS server address */
	{
		FILE*	fp;
		char*	p;
		char	str[128];

		if((fp=fopen("/etc/resolv.conf","r"))!=NULL) {
			while(!feof(fp)) {
				if(fgets(str,sizeof(str),fp)==NULL)
					break;
				truncsp(str);
				p=str;
				while(*p && *p<=' ') p++;	/* skip white-space */
				if(strnicmp(p,"nameserver",10)!=0) /* no match */
					continue;
				p+=10;	/* skip "nameserver" */
				while(*p && *p<=' ') p++;	/* skip more white-space */
				SAFECOPY(mail_startup.dns_server,p);
				break;
			}
			fclose(fp);
		}
	}

	/* Initialize Services startup structure */
    memset(&services_startup,0,sizeof(services_startup));
    services_startup.size=sizeof(services_startup);
    strcpy(services_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 */
	sbbs_read_ini(fp, 
		&run_bbs,		&bbs_startup,
		&run_ftp,		&ftp_startup, 
		&run_web,		&web_startup,
		&run_mail,		&mail_startup, 
		&run_services,	&services_startup);

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

	chdir(bbs_startup.ctrl_dir);
	
	/* Read .cfg files here */
552
	cfg.size=sizeof(cfg);
553
554
555
556
557
	if(!read_main_cfg(&cfg, str)) {
		printf("ERROR! %s\n",str);
		exit(1);
	}

558
559
560
561
562
	if(!read_xtrn_cfg(&cfg, str)) {
		printf("ERROR! %s\n",str);
		exit(1);
	}

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
    memset(&uifc,0,sizeof(uifc));

	uifc.esc_delay=500;

	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':
					uifc.mode|=UIFC_IBM;
					break;
                default:
                    printf("\nusage: %s [ctrl_dir] [options]"
                        "\n\noptions:\n\n"
                        "-c  =  force color mode\n"
                        "-e# =  set escape delay to #msec\n"
						"-i  =  force IBM charset\n"
                        "-l# =  set screen lines to #\n"
						,argv[0]
                        );
        			exit(0);
           }
    }

	uifc.size=sizeof(uifc);
	i=uifcinic(&uifc);  /* curses */
	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);

615
616
	sprintf(title,"Synchronet UNIX Monitor %s-%s",revision,PLATFORM_DESC);
	if(uifc.scrn(title)) {
617
618
619
620
621
		printf(" USCRN (len=%d) failed!\n",uifc.scrn_len+1);
		bail(1);
	}

	while(1) {
622
623
624
625
		for(i=1;i<=cfg.sys_nodes;i++) {
			if((j=getnodedat(&cfg,i,&node,NULL)))
				sprintf(mopt[i-1],"Error reading node data (%d)!",j);
			else
deuce's avatar
deuce committed
626
				nodedat(mopt[i-1],i,&node);
627
		}
deuce's avatar
deuce committed
628
		mopt[i-1][0]=0;
629
630

		uifc.helpbuf=	"`Synchronet Monitor:`\n"
deuce's avatar
deuce committed
631
632
						"\nCTRL-E displays the error log"
						"\nToDo: Add more help.";
633
						
634
		j=uifc.list(WIN_ORG|WIN_MID|WIN_ESC|WIN_ACT|WIN_DYN,0,0,70,&main_dflt,&main_bar
635
636
637
			,title,mopt);

		if(j==-7) {	/* CTRL-E */
638
			sprintf(str,"%s/error.log",cfg.data_dir);
639
			if(fexist(str)) {
deuce's avatar
deuce committed
640
				if((buffile=sopen(str,O_RDONLY,SH_DENYWR))>=0) {
641
642
643
644
645
					j=filelength(buffile);
					if((buf=(char *)MALLOC(j+1))!=NULL) {
						read(buffile,buf,j);
						close(buffile);
						*(buf+j)=0;
646
						uifc.showbuf(buf,"Error Log",0);
647
648
649
650
						free(buf);
						continue;
					}
					close(buffile);
deuce's avatar
deuce committed
651
					uifc.msg("Error allocating memory for the error log");
652
653
					continue;
				}
deuce's avatar
deuce committed
654
				uifc.msg("Error opening error log");
655
656
657
658
659
660
661
662
			}
			else {
				uifc.msg("Error log does not exist");
			}
			continue;
		}

		if(j <= -2)
663
664
			continue;

deuce's avatar
deuce committed
665
		if(j==-1) {
666
			i=0;
667
668
			strcpy(opt[0],YesStr);
			strcpy(opt[1],NoStr);
669
670
671
672
673
			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 ~.";
deuce's avatar
deuce committed
674
			i=uifc.list(WIN_MID,0,0,0,&i,0,"Exit Synchronet Monitor",opt);
675
676
677
678
			if(!i)
				bail(0);
			continue;
		}
679
		if(j<cfg.sys_nodes && j>=0) {
680
681
682
683
			i=0;
			strcpy(opt[i++],"Spy on node");
			strcpy(opt[i++],"Node toggles");
			strcpy(opt[i++],"Clear Errors");
deuce's avatar
deuce committed
684
685
			getnodedat(&cfg,j+1,&node,NULL);
			if((node.status&NODE_INUSE) && node.useron) {
deuce's avatar
deuce committed
686
				strcpy(opt[i++],"Send message to user");
deuce's avatar
deuce committed
687
				strcpy(opt[i++],"Chat with user");
deuce's avatar
deuce committed
688
			}
689
690
691
692
			opt[i][0]=0;
			i=0;
			uifc.helpbuf=	"`Node Options:`\n"
							"\nToDo: Add help";
693
			switch(uifc.list(WIN_MID|WIN_SAV,0,0,0,&i,0,"Node Options",opt))  {
694
				case 0:	/* Spy */
695
696
697
698
					if(bbs_startup.temp_dir[0])
		    			snprintf(str,sizeof(str),"%slocalspy%d.sock", bbs_startup.temp_dir, j+1);
					else
		    			snprintf(str,sizeof(str),"%slocalspy%d.sock", bbs_startup.temp_dir, j+1);
699
					endwin();
700
					i=spyon(str);
701
					refresh();
702
703
704
705
706
707
708
709
710
					switch(i) {
						case SPY_NOSOCKET:
							uifc.msg("Could not create socket");
							break;
							
						case SPY_NOCONNECT:
							sprintf(str2,"Failed to connect to %s",str);
							uifc.msg(str2);
							break;
deuce's avatar
deuce committed
711
712
713
714

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

715
716
717
718
719
						case SPY_SOCKETLOST:
							uifc.msg("Spy socket lost");
							break;
							
						case SPY_STDINLOST:
720
							uifc.msg("STDIN has gone away... you probably can't close this window.  :-)");
721
722
723
724
725
726
727
728
729
							break;
							
						case SPY_CLOSED:
							break;
							
						default:
							sprintf(str,"Unknown return code %d",i);
							uifc.msg(str);
					}
730
731
732
733
734
735
736
					break;

				case 1: /* Node Toggles */
					node_toggles(j+1);
					break;

				case 2:
737
738
739
740
					if(getnodedat(&cfg,j+1,&node,&nodefile)) {
						uifc.msg("getnodedat() failed! (Nothing done)");
						break;
					}
741
					node.errors=0;
742
					putnodedat(&cfg,j+1,&node,nodefile);
743
744
					break;

deuce's avatar
deuce committed
745
746
747
748
749
750
751
752
753
754
				case 3:	/* Send message */
					uifc.input(WIN_MID,0,0,"Telegram",str2,58,K_WRAP|K_MSG);
					sprintf(str,"\1n\1y\1hMessage From Sysop:\1w %s",str2);
					if(getnodedat(&cfg,j+1,&node,NULL))
						break;
					if(node.useron==0)
						break;
					putsmsg(&cfg, node.useron, str);
					break;

755
756
757
758
759
760
761
				case -1:
					break;
					
				default:
					uifc.msg("Option not implemented");
					break;
			}
762
763
		}
	}
764
}