scfgxtrn.c 82.4 KB
Newer Older
1
2
3
4
/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
5
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
6
7
8
9
10
11
12
13
14
15
16
17
18
 *																			*
 * 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										*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/
rswindell's avatar
rswindell committed
19
20

#include "scfg.h"
21
#include "ciolib.h"	// CIO_KEY_*
rswindell's avatar
rswindell committed
22

23
char *daystr(char days);
24
25
static void hotkey_cfg(void);

26
static char* use_shell_opt = "Use Shell or New Context";
27
28
29
static char* use_shell_help =
	"`Use System Shell or New JavaScript Context to Execute:`\n"
	"\n"
30
	"If this command line requires the system command shell to execute\n"
31
32
33
	"(e.g. uses pipes/redirection or invokes a Unix shell script or\n"
	"DOS/Windows batch/command file), then set this option to ~Yes~.\n"
	"\n"
34
	"If this command line is invoking a Synchronet JavaScript module\n"
35
36
37
38
39
	"(e.g. it begins with a '`?`' character), then setting this option to ~Yes~\n"
	"will enable the creation and initialization of a new JavaScript run-time\n"
	"context for it to execute within, for every invocation."
	;
static char* use_shell_prompt = "Use System Shell or New JavaScript Context to Execute";
40
41
42
43
44
45
static char* native_help =
	"`Native Executable/Script:`\n"
	"\n"
	"If this program is `16-bit MS-DOS` executable, set this option to `No`,\n"
	"otherwise (it is a native program or script) set this option to `Yes`.\n"
	;
46

47
48
49
50
51
52
53
54
55
56
#define CUT_XTRNSEC_NUM	USHRT_MAX

static bool new_timed_event(unsigned new_event_num)
{
	event_t* new_event;
	if ((new_event = (event_t *)malloc(sizeof(*new_event))) == NULL) {
		errormsg(WHERE, ERR_ALLOC, "timed event", sizeof(*new_event));
		return false;
	}
	memset(new_event, 0, sizeof(*new_event));
57
	new_event->node = NODE_ANY;
58
	new_event->days = (uchar)0xff;
59
	new_event->errlevel = LOG_ERR;
60
61
62

	event_t** new_event_list = realloc(cfg.event, sizeof(event_t *)*(cfg.total_events + 1));
	if (new_event_list == NULL) {
63
		free(new_event);
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
		errormsg(WHERE, ERR_ALLOC, "timed event list", cfg.total_events + 1);
		return false;
	}
	cfg.event = new_event_list;

	for (unsigned u = cfg.total_events; u > new_event_num; u--)
		cfg.event[u] = cfg.event[u - 1];

	cfg.event[new_event_num] = new_event;
	cfg.total_events++;
	return true;
}

static bool new_external_program_section(unsigned new_section_num)
{
	xtrnsec_t* new_xtrnsec = malloc(sizeof(*new_xtrnsec));
	if (new_xtrnsec == NULL) {
		errormsg(WHERE, ERR_ALLOC, "external program section", sizeof(*new_xtrnsec));
		return false;
	}
	memset(new_xtrnsec, 0, sizeof(*new_xtrnsec));

	xtrnsec_t** new_xtrnsec_list = realloc(cfg.xtrnsec, sizeof(xtrnsec_t *)*(cfg.total_xtrnsecs + 1));
	if (new_xtrnsec_list == NULL) {
88
		free(new_xtrnsec);
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
		errormsg(WHERE, ERR_ALLOC, "external program section list", cfg.total_xtrnsecs + 1);
		return false;
	}
	cfg.xtrnsec = new_xtrnsec_list;
	for (unsigned u = cfg.total_xtrnsecs; u > new_section_num; u--)
		cfg.xtrnsec[u] = cfg.xtrnsec[u - 1];
	for (unsigned j = 0; j < cfg.total_xtrns; j++) {
		if (cfg.xtrn[j]->sec >= new_section_num && cfg.xtrn[j]->sec != CUT_XTRNSEC_NUM)
			cfg.xtrn[j]->sec++;
	}

	cfg.xtrnsec[new_section_num] = new_xtrnsec;
	cfg.total_xtrnsecs++;
	return true;
}

static bool new_external_program(unsigned new_xtrn_num, unsigned section)
{
	xtrn_t* new_xtrn = malloc(sizeof(*new_xtrn));
	if (new_xtrn == NULL) {
		errormsg(WHERE, ERR_ALLOC, "external program", sizeof(*new_xtrn));
		return false;
	}
	memset(new_xtrn, 0, sizeof(*new_xtrn));
	new_xtrn->sec = section;
114
	new_xtrn->misc = MULTIUSER;
115
116
117

	xtrn_t ** new_xtrn_list = realloc(cfg.xtrn, sizeof(xtrn_t *)*(cfg.total_xtrns + 1));
	if (new_xtrn_list == NULL) {
118
		free(new_xtrn);
119
120
121
122
123
124
125
126
127
128
129
130
		errormsg(WHERE, ERR_ALLOC, "external program list", cfg.total_xtrns + 1);
		return false;
	}
	cfg.xtrn = new_xtrn_list;
	for (unsigned n = cfg.total_xtrns; n > new_xtrn_num; n--)
		cfg.xtrn[n] = cfg.xtrn[n - 1];

	cfg.xtrn[new_xtrn_num] = new_xtrn;
	cfg.total_xtrns++;
	return true;
}

131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
static int next_program(const int num)
{
	for(int i = num + 1; i < cfg.total_xtrns; i++) {
		if(cfg.xtrn[i]->sec == cfg.xtrn[num]->sec)
			return i;
	}
	return num;
}

static int prev_program(const int num)
{
	for(int i = num - 1; i >= 0; i--) {
		if(cfg.xtrn[i]->sec == cfg.xtrn[num]->sec)
			return i;
	}
	return num;
}

149
150
151
152
153
154
155
156
static bool new_external_editor(unsigned new_xedit_num)
{
	xedit_t* new_xedit = malloc(sizeof(*new_xedit));
	if (new_xedit == NULL) {
		errormsg(WHERE, ERR_ALLOC, "external editor", sizeof(*new_xedit));
		return false;
	}
	memset(new_xedit, 0, sizeof(*new_xedit));
157
	new_xedit->misc |= QUOTEWRAP;
158
159
160

	xedit_t** new_xedit_list = realloc(cfg.xedit, sizeof(xedit_t *)*(cfg.total_xedits + 1));
	if (new_xedit_list == NULL) {
161
		free(new_xedit);
162
163
164
165
166
167
168
169
170
171
172
173
		errormsg(WHERE, ERR_ALLOC, "external editor list", cfg.total_xedits + 1);
		return false;
	}
	cfg.xedit = new_xedit_list;
	for (unsigned u = cfg.total_xedits; u > new_xedit_num; u--)
		cfg.xedit[u] = cfg.xedit[u - 1];

	cfg.xedit[new_xedit_num] = new_xedit;
	cfg.total_xedits++;
	return true;
}

174
175
176
177
178
179
180
181
182
183
184
185
186
187
static char* monthstr(uint16_t months)
{
	int		i;
	static	char str[256];

	if(months==0)
		return("Any");

	str[0]=0;
	for(i=0;i<12;i++) {
		if((months&(1<<i))==0)
			continue;
		if(str[0])
			strcat(str," ");
188
		SAFECAT(str,mon[i]);
189
190
191
192
193
	}
	
	return(str);
}

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
static char* mdaystr(long mdays)
{
	int		i;
	char	tmp[16];
	static	char str[256];

	if(mdays==0 || mdays==1)
		return("Any");

	str[0]=0;
	for(i=1;i<32;i++) {
		if((mdays&(1<<i))==0)
			continue;
		if(str[0])
			strcat(str," ");
		sprintf(tmp,"%u",i);
		strcat(str,tmp);
	}
	
	return(str);
}

216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
static char* dropfile(int type, ulong misc)
{
	static char str[128];
	char fname[64]="";

	switch(type) {
		case XTRN_SBBS:
			strcpy(fname,"XTRN.DAT");
			break;
		case XTRN_WWIV:
			strcpy(fname,"CHAIN.TXT");
			break;
		case XTRN_GAP:
			strcpy(fname,"DOOR.SYS");
			break;
		case XTRN_RBBS:
			strcpy(fname,"DORINFO#.DEF");
			break;
		case XTRN_RBBS1:
			strcpy(fname,"DORINFO1.DEF");
            break;
		case XTRN_WILDCAT:
			strcpy(fname,"CALLINFO.BBS");
			break;
		case XTRN_PCBOARD:
			strcpy(fname,"PCBOARD.SYS");
			break;
		case XTRN_SPITFIRE:
			strcpy(fname,"SFDOORS.DAT");
			break;
		case XTRN_UTI:
			strcpy(fname,"UTIDOOR.TXT");
			break;
		case XTRN_SR:
			strcpy(fname,"DOORFILE.SR");
			break;
		case XTRN_TRIBBS:
			strcpy(fname,"TRIBBS.SYS");
			break;
        case XTRN_DOOR32:
            strcpy(fname,"DOOR32.SYS");
            break;
	}

	if(misc&XTRN_LWRCASE)
		strlwr(fname);

	switch(type) {
		case XTRN_SBBS:
			sprintf(str,"%-15s %s","Synchronet",fname);
			break;
		case XTRN_WWIV:
			sprintf(str,"%-15s %s","WWIV",fname);
			break;
		case XTRN_GAP:
			sprintf(str,"%-15s %s","GAP",fname);
			break;
		case XTRN_RBBS:
			sprintf(str,"%-15s %s","RBBS/QuickBBS",fname);
			break;
		case XTRN_RBBS1:
			sprintf(str,"%-15s %s","RBBS/QuickBBS",fname);
            break;
		case XTRN_WILDCAT:
			sprintf(str,"%-15s %s","Wildcat",fname);
			break;
		case XTRN_PCBOARD:
			sprintf(str,"%-15s %s","PCBoard",fname);
			break;
		case XTRN_SPITFIRE:
			sprintf(str,"%-15s %s","SpitFire",fname);
			break;
		case XTRN_UTI:
			sprintf(str,"%-15s %s","MegaMail",fname);
			break;
		case XTRN_SR:
			sprintf(str,"%-15s %s","Solar Realms",fname);
			break;
		case XTRN_TRIBBS:
			sprintf(str,"%-15s %s","TriBBS",fname);
			break;
        case XTRN_DOOR32:
            sprintf(str,"%-15s %s","Mystic",fname);
            break;
		default:
			strcpy(str,"None");
			break; 
	}
	return(str);
}

rswindell's avatar
rswindell committed
307
308
309
310
311
void xprogs_cfg()
{
	static int xprogs_dflt;
	int 	i;

312
313
314
315
316
317
318
319
320
321
322
323
	while(1) {
		i=0;
		strcpy(opt[i++],"Fixed Events");
		strcpy(opt[i++],"Timed Events");
		strcpy(opt[i++],"Native Program List");
		strcpy(opt[i++],"External Editors");
		strcpy(opt[i++],"Global Hot Key Events");
		strcpy(opt[i++],"Online Programs (Doors)");
		opt[i][0]=0;
		uifc.helpbuf=
			"`Online External Programs:`\n"
			"\n"
324
325
			"From this menu, you can configure external events, external message\n"
			"editors, or online external programs (e.g. `door games`).\n"
326
327
328
329
330
331
332
333
334
		;
		switch(uifc.list(WIN_ORG|WIN_CHE|WIN_ACT,0,0,0,&xprogs_dflt,0
			,"External Programs",opt)) {
			case -1:
				i=save_changes(WIN_MID);
				if(i==-1)
					break;
				if(!i) {
					cfg.new_install=new_install;
rswindell's avatar
rswindell committed
335
336
					save_xtrn_cfg(&cfg,backup_level);
					save_main_cfg(&cfg,backup_level);
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
					refresh_cfg(&cfg);
				}
				return;
			case 0:
				fevents_cfg();
				break;
			case 1:
				tevents_cfg();
				break;
			case 2:
				natvpgm_cfg();
				break;
			case 3:
				xedit_cfg();
				break;
			case 4:
				hotkey_cfg();
				break;
			case 5:
				xtrnsec_cfg();
				break; 
358
359
		}
	}
rswindell's avatar
rswindell committed
360
361
362
363
364
365
366
}

void fevents_cfg()
{
	static int event_dflt;
	int i;

367
368
	while(1) {
		i=0;
369
370
371
		sprintf(opt[i++],"%-32.32s%s","Logon Event",cfg.sys_logon);
		sprintf(opt[i++],"%-32.32s%s","Logout Event",cfg.sys_logout);
		sprintf(opt[i++],"%-32.32s%s","Daily Event",cfg.sys_daily);
372
		opt[i][0]=0;
373
		uifc.helpbuf=
374
			"`External Events:`\n"
375
			"\n"
376
377
			"From this menu, you can configure the logon and logout events, and the\n"
			"system daily event.\n"
378
		;
379
380
		switch(uifc.list(WIN_ACT|WIN_SAV|WIN_CHE|WIN_BOT|WIN_RHT,0,0,60,&event_dflt,0
			,"Fixed Events",opt)) {
rswindell's avatar
rswindell committed
381
			case -1:
382
				return;
rswindell's avatar
rswindell committed
383
			case 0:
384
				uifc.helpbuf=
385
					"`Logon Event:`\n"
386
					"\n"
387
388
389
390
391
392
393
					"This is the command line for a program that will execute during the\n"
					"logon sequence of every user. The program cannot have user interaction.\n"
					"The program will be executed after the LOGON message is displayed and\n"
					"before the logon user list is displayed. If you wish to place a program\n"
					"in the logon sequence of users that includes interaction or requires\n"
					"account information, you probably want to use an online external\n"
					"program configured to run as a logon event.\n"
394
					SCFG_CMDLINE_PREFIX_HELP
395
					SCFG_CMDLINE_SPEC_HELP
396
				;
397
398
				uifc.input(WIN_MID|WIN_SAV,0,0,"Logon Event"
					,cfg.sys_logon,sizeof(cfg.sys_logon)-1,K_EDIT);
399
				break;
400
			case 1:
401
				uifc.helpbuf=
402
					"`Logout Event:`\n"
403
					"\n"
404
405
406
407
408
409
					"This is the command line for a program that will execute during the\n"
					"logout sequence of every user. This program cannot have user\n"
					"interaction because it is executed after carrier is dropped. If you\n"
					"wish to have a program execute before carrier is dropped, you probably\n"
					"want to use an `Online External Program` configured to run as a logoff\n"
					"event.\n"
410
					SCFG_CMDLINE_PREFIX_HELP
411
					SCFG_CMDLINE_SPEC_HELP
412
				;
413
414
				uifc.input(WIN_MID|WIN_SAV,0,0,"Logout Event"
					,cfg.sys_logout,sizeof(cfg.sys_logout)-1,K_EDIT);
rswindell's avatar
rswindell committed
415
				break;
416
			case 2:
417
				uifc.helpbuf=
418
					"`Daily Event:`\n"
419
					"\n"
420
421
					"This is the command line for a program that will run after the first\n"
					"user that logs on after midnight, logs off (regardless of what node).\n"
422
					SCFG_CMDLINE_PREFIX_HELP
423
					SCFG_CMDLINE_SPEC_HELP
424
				;
425
426
				uifc.input(WIN_MID|WIN_SAV,0,0,"Daily Event"
					,cfg.sys_daily,sizeof(cfg.sys_daily)-1,K_EDIT);
427

428
				break; 
429
430
		} 
	}
rswindell's avatar
rswindell committed
431
432
}

433
void tevents_cfg()
rswindell's avatar
rswindell committed
434
{
435
436
	static int dflt,dfltopt,bar;
	char str[81],done=0,*p;
rswindell's avatar
rswindell committed
437
	int j,k;
438
439
	uint i;
	static event_t savevent;
440

441
442
	while(1) {
		for(i=0;i<cfg.total_events && i<MAX_OPTS;i++)
443
444
			sprintf(opt[i],"%-*s  %s"
				,LEN_CODE
445
446
				,cfg.event[i]->code
				,(cfg.event[i]->misc&EVENT_DISABLED) ? "<DISABLED>" : cfg.event[i]->cmd);
447
448
449
		opt[i][0]=0;
		j=WIN_SAV|WIN_ACT|WIN_CHE|WIN_RHT;
		if(cfg.total_events)
450
			j|=WIN_DEL|WIN_COPY|WIN_CUT;
451
452
453
454
		if(cfg.total_events<MAX_OPTS)
			j|=WIN_INS|WIN_INSACT|WIN_XTR;
		if(savevent.code[0])
			j|=WIN_PASTE | WIN_PASTEXTR;
455
		uifc.helpbuf=
456
			"`Timed Events:`\n"
457
			"\n"
458
459
460
			"This is a list of the configured timed external events.\n"
			"\n"
			"To add an event hit ~ INS ~.\n"
461
			"\n"
462
463
464
			"To delete an event, select it and hit ~ DEL ~.\n"
			"\n"
			"To configure an event, select it and hit ~ ENTER ~.\n"
465
		;
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
		i=uifc.list(j,0,0,45,&dflt,&bar,"Timed Events",opt);
		if((signed)i==-1)
			return;
		int msk = i & MSK_ON;
		i &= MSK_OFF;
		if(msk == MSK_INS) {
			uifc.helpbuf=
				"`Timed Event Internal Code:`\n"
				"\n"
				"This is the internal code for the timed event.\n"
			;
			if(uifc.input(WIN_MID|WIN_SAV,0,0,"Event Internal Code",str,LEN_CODE
				,K_UPPER)<1)
				continue;
			if (!new_timed_event(i))
				continue;
			SAFECOPY(cfg.event[i]->code,str);
			uifc.changes=1;
			continue; 
485
		}
486
487
488
489
490
491
492
493
494
		if(msk == MSK_DEL || msk == MSK_CUT) {
			if(msk == MSK_CUT)
				savevent = *cfg.event[i];
			free(cfg.event[i]);
			cfg.total_events--;
			for(j=i;j<cfg.total_events;j++)
				cfg.event[j]=cfg.event[j+1];
			uifc.changes=1;
			continue; 
495
		}
496
497
		if(msk == MSK_COPY) {
			savevent=*cfg.event[i];
498
499
			continue; 
		}
500
501
502
		if(msk == MSK_PASTE) {
			if (!new_timed_event(i))
				continue;
503
504
505
			*cfg.event[i]=savevent;
			uifc.changes=1;
			continue; 
506
		}
507
508
509
510
511
512
		if (msk != 0)
			continue;
		done=0;
		while(!done) {
			k=0;
			sprintf(opt[k++],"%-32.32s%s","Internal Code",cfg.event[i]->code);
513
514
			sprintf(opt[k++],"%-32.32s%s","Start-up Directory",cfg.event[i]->dir);
			sprintf(opt[k++],"%-32.32s%s","Command Line",cfg.event[i]->cmd);
515
516
			sprintf(opt[k++],"%-32.32s%s","Enabled"
				,cfg.event[i]->misc&EVENT_DISABLED ? "No":"Yes");
517
518
519
520
521
			if(cfg.event[i]->node == NODE_ANY)
				SAFECOPY(str, "Any");
			else
				SAFEPRINTF(str, "%u", cfg.event[i]->node);
			sprintf(opt[k++],"%-32.32s%s","Execution Node", str);
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
			sprintf(opt[k++],"%-32.32s%s","Execution Months"
				,monthstr(cfg.event[i]->months));
			sprintf(opt[k++],"%-32.32s%s","Execution Days of Month"
				,mdaystr(cfg.event[i]->mdays));
			sprintf(opt[k++],"%-32.32s%s","Execution Days of Week",daystr(cfg.event[i]->days));
			if(cfg.event[i]->freq) {
				sprintf(str,"%u times a day",1440/cfg.event[i]->freq);
				sprintf(opt[k++],"%-32.32s%s","Execution Frequency",str);
			} else {
				sprintf(str,"%2.2u:%2.2u"
					,cfg.event[i]->time/60,cfg.event[i]->time%60);
				sprintf(opt[k++],"%-32.32s%s","Execution Time",str);
			}
			sprintf(opt[k++],"%-32.32s%s","Requires Exclusive Execution"
				,cfg.event[i]->misc&EVENT_EXCL ? "Yes":"No");
			sprintf(opt[k++],"%-32.32s%s","Force Users Off-line For Event"
				,cfg.event[i]->misc&EVENT_FORCE ? "Yes":"No");
539
			sprintf(opt[k++],"%-32.32s%s","Native Executable/Script"
540
				,cfg.event[i]->misc&EX_NATIVE ? "Yes" : "No");
541
			sprintf(opt[k++],"%-32.32s%s",use_shell_opt
542
543
544
545
546
				,cfg.event[i]->misc&XTRN_SH ? "Yes" : "No");
			sprintf(opt[k++],"%-32.32s%s","Background Execution"
				,cfg.event[i]->misc&EX_BG ? "Yes" : "No");
			sprintf(opt[k++],"%-32.32s%s","Always Run After Init/Re-init"
				,cfg.event[i]->misc&EVENT_INIT ? "Yes":"No");
547
548
			if(!(cfg.event[i]->misc&EX_BG))
				sprintf(opt[k++],"%-32.32s%s","Error Log Level", iniLogLevelStringList()[cfg.event[i]->errlevel]);
549
550
551
552
553
554
555
556
			opt[k][0]=0;
			uifc.helpbuf=
				"`Timed Event:`\n"
				"\n"
				"This is the configuration menu for a timed event. An event is an\n"
				"external program that performs some type of automated function on the\n"
				"system. Use this menu to configure how and when this event will be\n"
				"executed.\n"
557
558
				"\n"
				"The left and right arrow keys may be used to cycle through events.\n"
559
560
			;
			sprintf(str,"%s Timed Event",cfg.event[i]->code);
561
562
563
564
565
566
			uifc_winmode_t wmode = WIN_SAV|WIN_ACT|WIN_L2R|WIN_BOT|WIN_EXTKEYS;
			if(i > 0)
				wmode |= WIN_LEFTKEY;
			if(i + 1 < cfg.total_events)
				wmode |= WIN_RIGHTKEY;
			switch(uifc.list(wmode,0,0,70,&dfltopt,0
567
568
569
570
				,str,opt)) {
				case -1:
					done=1;
					break;
571
572
573
574
575
576
577
578
				case -CIO_KEY_LEFT-2:
					if(i > 0)
						i--;
					break;
				case -CIO_KEY_RIGHT-2:
					if(i + 1 < cfg.total_events)
						i++;
					break;
579
				case 0:
580
					SAFECOPY(str,cfg.event[i]->code);
581
582
583
584
					uifc.helpbuf=
						"`Timed Event Internal Code:`\n"
						"\n"
						"Every timed event must have its own unique internal code for Synchronet\n"
585
						"to reference it by. It is helpful if this code is an abbreviation of the\n"
586
						"command line or program name.\n"
587
588
589
590
					;
					uifc.input(WIN_MID|WIN_SAV,0,17,"Internal Code (unique)"
						,str,LEN_CODE,K_EDIT|K_UPPER);
					if(code_ok(str))
591
						SAFECOPY(cfg.event[i]->code,str);
592
593
					else {
						uifc.helpbuf=invalid_code;
594
						uifc.msg(strInvalidCode);
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
						uifc.helpbuf=0; 
					}
					break;
				case 1:
					uifc.helpbuf=
						"`Timed Event Start-up Directory:`\n"
						"\n"
						"This is the DOS drive/directory where the event program is located.\n"
						"If a path is specified here, it will be made the current directory\n"
						"before the event's command line is executed. This eliminates the need\n"
						"for batch files that just change the current drive and directory before\n"
						"executing the event.\n"
					;
					uifc.input(WIN_MID|WIN_SAV,0,10,"Directory"
						,cfg.event[i]->dir,sizeof(cfg.event[i]->dir)-1,K_EDIT);
					break;
				case 2:
					uifc.helpbuf=
						"`Timed Event Command Line:`\n"
						"\n"
						"This is the command line to execute upon this timed event.\n"
616
						SCFG_CMDLINE_PREFIX_HELP
617
						SCFG_CMDLINE_SPEC_HELP
618
619
620
621
622
623
624
625
					;
					uifc.input(WIN_MID|WIN_SAV,0,10,"Command"
						,cfg.event[i]->cmd,sizeof(cfg.event[i]->cmd)-1,K_EDIT);
					break;

				case 3:
					k=(cfg.event[i]->misc&EVENT_DISABLED) ? 1:0;
					uifc.helpbuf=
626
						"`Timed Event Enabled:`\n"
627
628
629
630
						"\n"
						"If you want disable this event from executing, set this option to ~No~.\n"
					;
					k=uifc.list(WIN_MID|WIN_SAV,0,0,0,&k,0
631
						,"Event Enabled",uifcYesNoOpts);
632
633
634
635
636
637
638
639
640
					if((k==0 && cfg.event[i]->misc&EVENT_DISABLED) 
						|| (k==1 && !(cfg.event[i]->misc&EVENT_DISABLED))) {
						cfg.event[i]->misc^=EVENT_DISABLED;
						uifc.changes=1; 
					}
					break;

				case 4:
					uifc.helpbuf=
641
						"`Timed Event Execution Node:`\n"
642
						"\n"
643
644
						"The Execution Node Number specifies the instance of Synchronet that\n"
						"will run this timed event (or `Any`).\n"
645
					;
646
647
648
649
					if(cfg.event[i]->node == NODE_ANY)
						SAFECOPY(str, "Any");
					else
						SAFEPRINTF(str, "%u", cfg.event[i]->node);
650
					if(uifc.input(WIN_MID|WIN_SAV,0,0,"Execution Node Number (or Any)"
651
						,str,3,K_EDIT) > 0) {
652
						if(IS_DIGIT(*str))
653
654
655
656
							cfg.event[i]->node=atoi(str);
						else
							cfg.event[i]->node = NODE_ANY;
					}
657
658
659
660
661
					break;
				case 5:
					uifc.helpbuf=
						"`Months to Execute Event:`\n"
						"\n"
662
663
						"Specifies the months (`Jan`-`Dec`, separated by spaces) on which to\n"
						"execute this event, or `Any` to execute event in any/all months.\n"
664
665
666
667
668
669
					;
					SAFECOPY(str,monthstr(cfg.event[i]->months));
					uifc.input(WIN_MID|WIN_SAV,0,0,"Months to Execute Event (or Any)"
						,str,50,K_EDIT);
					cfg.event[i]->months=0;
					for(p=str;*p;p++) {
670
671
672
						int num = atoi(p);
						if(num > 0) {
							cfg.event[i]->months|=(1<<(num-1));
673
							while(*p && IS_DIGIT(*p))
674
675
676
677
678
679
680
681
682
								p++;
						} else {
							for(j=0;j<12;j++)
								if(strnicmp(mon[j],p,3)==0) {
									cfg.event[i]->months|=(1<<j);
									p+=2;
									break;
								}
							p++;
683
						}
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
					}
					break;
				case 6:
					uifc.helpbuf=
						"`Days of Month to Execute Event:`\n"
						"\n"
						"Specifies the days of the month (`1-31`, separated by spaces) on which \n"
						"to execute this event, or `Any` to execute event on any and all days of\n"
						"the month.\n"
					;
					SAFECOPY(str,mdaystr(cfg.event[i]->mdays));
					uifc.input(WIN_MID|WIN_SAV,0,0,"Days of Month to Execute Event (or Any)"
						,str,16,K_EDIT);
					cfg.event[i]->mdays=0;
					for(p=str;*p;p++) {
						if(!isdigit(*p))
							continue;
						cfg.event[i]->mdays|=(1<<atoi(p));
702
						while(*p && IS_DIGIT(*p))
703
704
705
706
707
708
709
710
711
712
713
714
							p++;
					}
					break;
				case 7:
					j=0;
					while(1) {
						for(k=0;k<7;k++)
							sprintf(opt[k],"%-30s %3s"
								,wday[k],(cfg.event[i]->days&(1<<k)) ? "Yes":"No");
						strcpy(opt[k++],"All");
						strcpy(opt[k++],"None");
						opt[k][0]=0;
715
						uifc.helpbuf=
716
							"`Days of Week to Execute Event:`\n"
717
							"\n"
718
							"These are the days of the week that this event will be executed.\n"
719
						;
720
721
722
723
724
						k=uifc.list(WIN_MID|WIN_SAV|WIN_ACT,0,0,0,&j,0
							,"Days of Week to Execute Event",opt);
						if(k==-1)
							break;
						if(k==7)
725
							cfg.event[i]->days=0x7f;
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
						else if(k==8)
							cfg.event[i]->days=0;
						else
							cfg.event[i]->days^=(1<<k);
						uifc.changes=1; 
					}
					break;
				case 8:
					if(cfg.event[i]->freq==0)
						k=0;
					else
						k=1;
					uifc.helpbuf=
						"`Execute Event at a Specific Time:`\n"
						"\n"
						"If you want the system execute this event at a specific time, set\n"
						"this option to `Yes`. If you want the system to execute this event more\n"
						"than once a day at predetermined intervals, set this option to `No`.\n"
					;
					k=uifc.list(WIN_MID|WIN_SAV,0,0,0,&k,0
						,"Execute Event at a Specific Time",uifcYesNoOpts);
					if(k==0) {
						sprintf(str,"%2.2u:%2.2u",cfg.event[i]->time/60
							,cfg.event[i]->time%60);
						uifc.helpbuf=
							"`Time to Execute Event:`\n"
							"\n"
							"This is the time (in 24 hour HH:MM format) to execute the event.\n"
						;
						if(uifc.input(WIN_MID|WIN_SAV,0,0
							,"Time to Execute Event (HH:MM)"
							,str,5,K_UPPER|K_EDIT)>0) {
							cfg.event[i]->freq=0;
							cfg.event[i]->time=atoi(str)*60;
							if((p=strchr(str,':'))!=NULL)
								cfg.event[i]->time+=atoi(p+1); 
						} 
					}
					else if(k==1) {
						sprintf(str,"%u"
							,cfg.event[i]->freq && cfg.event[i]->freq<=1440
								? 1440/cfg.event[i]->freq : 0);
						uifc.helpbuf=
							"`Number of Executions Per Day:`\n"
							"\n"
							"This is the maximum number of times the system will execute this event\n"
							"per day.\n"
						;
						if(uifc.input(WIN_MID|WIN_SAV,0,0
							,"Number of Executions Per Day"
							,str,4,K_NUMBER|K_EDIT)>0) {
							cfg.event[i]->time=0;
							k=atoi(str);
							if(k && k<=1440)
								cfg.event[i]->freq=1440/k;
							else
								cfg.event[i]->freq=0;
							}
784
						}
rswindell's avatar
rswindell committed
785
					break;
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
				case 9:
					k=(cfg.event[i]->misc&EVENT_EXCL) ? 0:1;
					uifc.helpbuf=
						"`Exclusive Event Execution:`\n"
						"\n"
						"If this event must be run exclusively (all nodes inactive), set this\n"
						"option to `Yes`.\n"
					;
					k=uifc.list(WIN_MID|WIN_SAV,0,0,0,&k,0,"Exclusive Execution"
						,uifcYesNoOpts);
					if(!k && !(cfg.event[i]->misc&EVENT_EXCL)) {
						cfg.event[i]->misc|=EVENT_EXCL;
						uifc.changes=1; 
					}
					else if(k==1 && cfg.event[i]->misc&EVENT_EXCL) {
						cfg.event[i]->misc&=~EVENT_EXCL;
						uifc.changes=1; 
803
					}
rswindell's avatar
rswindell committed
804
					break;
805
806
807
808
809
810
811
812
813
814
815
816
817
				case 10:
					k=(cfg.event[i]->misc&EVENT_FORCE) ? 0:1;
					uifc.helpbuf=
						"`Force Users Off-line for Event:`\n"
						"\n"
						"If you want to have your users' on-line time reduced so the event can\n"
						"execute precisely on time, set this option to `Yes`.\n"
					;
					k=uifc.list(WIN_MID|WIN_SAV,0,0,0,&k,0
						,"Force Users Off-line for Event",uifcYesNoOpts);
					if(!k && !(cfg.event[i]->misc&EVENT_FORCE)) {
						cfg.event[i]->misc|=EVENT_FORCE;
						uifc.changes=1; 
818
					}
819
820
821
					else if(k==1 && (cfg.event[i]->misc&EVENT_FORCE)) {
						cfg.event[i]->misc&=~EVENT_FORCE;
						uifc.changes=1; 
822
					}
823
824
825
826
					break;

				case 11:
					k=(cfg.event[i]->misc&EX_NATIVE) ? 0:1;
827
					uifc.helpbuf=native_help;
828
					k=uifc.list(WIN_MID|WIN_SAV,0,0,0,&k,0
829
						,"Native Executable/Script",uifcYesNoOpts);
830
831
832
833
834
835
836
837
838
839
840
841
					if(!k && !(cfg.event[i]->misc&EX_NATIVE)) {
						cfg.event[i]->misc|=EX_NATIVE;
						uifc.changes=TRUE;
					}
					else if(k==1 && (cfg.event[i]->misc&EX_NATIVE)) {
						cfg.event[i]->misc&=~EX_NATIVE;
						uifc.changes=TRUE;
					}
					break;

				case 12:
					k=(cfg.event[i]->misc&XTRN_SH) ? 0:1;
842
					uifc.helpbuf = use_shell_help;
843
					k=uifc.list(WIN_MID|WIN_SAV,0,0,0,&k,0
844
						,use_shell_prompt, uifcYesNoOpts);
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
					if(!k && !(cfg.event[i]->misc&XTRN_SH)) {
						cfg.event[i]->misc|=XTRN_SH;
						uifc.changes=TRUE;
					}
					else if(k==1 && (cfg.event[i]->misc&XTRN_SH)) {
						cfg.event[i]->misc&=~XTRN_SH;
						uifc.changes=TRUE;
					}
					break;

				case 13:
					k=(cfg.event[i]->misc&EX_BG) ? 0:1;
					uifc.helpbuf=
						"`Execute Event in Background (Asynchronously):`\n"
						"\n"
						"If you would like this event to run simultaneously with other events,\n"
						"set this option to `Yes`. Exclusive events will not run in the background.\n"
					;
					k=uifc.list(WIN_MID|WIN_SAV,0,0,0,&k,0
						,"Background (Asynchronous) Execution",uifcYesNoOpts);
					if(!k && !(cfg.event[i]->misc&EX_BG)) {
						cfg.event[i]->misc|=EX_BG;
						uifc.changes=TRUE;
					}
					else if(k==1 && (cfg.event[i]->misc&EX_BG)) {
						cfg.event[i]->misc&=~EX_BG;
						uifc.changes=TRUE;
					}
					break;

				case 14:
					k=(cfg.event[i]->misc&EVENT_INIT) ? 0:1;
					uifc.helpbuf=
878
						"`Always Run After (re-)Initialization:`\n"
879
880
881
882
883
						"\n"
						"If you want this event to always run after the BBS is initialized or\n"
						"re-initialized, set this option to ~Yes~.\n"
					;
					k=uifc.list(WIN_MID|WIN_SAV,0,0,0,&k,0
884
						,"Always Run After (re-)Initialization",uifcYesNoOpts);
885
886
887
888
889
890
891
892
893
					if(!k && !(cfg.event[i]->misc&EVENT_INIT)) {
						cfg.event[i]->misc|=EVENT_INIT;
						uifc.changes=1; 
					}
					else if(k==1 && (cfg.event[i]->misc&EVENT_INIT)) {
						cfg.event[i]->misc&=~EVENT_INIT;
						uifc.changes=1; 
					}
					break;
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908

				case 15:
					uifc.helpbuf=
						"`Error Log Level:`\n"
						"\n"
						"Specify the log level used when reporting an error executing this event.\n"
					;
					k = cfg.event[i]->errlevel;
					k=uifc.list(WIN_MID|WIN_SAV,0,0,0,&k,0
						,"Error Log Level",iniLogLevelStringList());
					if(k > 0 && cfg.event[i]->errlevel != k) {
						cfg.event[i]->errlevel = k;
						uifc.changes = true;
					}
					break;
909
910
911
912
913
			} 
		} 
	}
}

914
915
916
917
918
const char* io_method(uint32_t mode)
{
	static char str[128];

	sprintf(str,"%s%s%s"
919
920
921
		,mode & XTRN_UART ? "UART" : (mode & XTRN_FOSSIL) ? "FOSSIL"
				: (mode & XTRN_STDIO ? "Standard"
					: mode & XTRN_CONIO ? "Console": (mode & XTRN_NATIVE ? "Socket" : "FOSSIL or UART"))
922
923
924
925
926
927
928
929
930
		,(mode & (XTRN_STDIO|WWIVCOLOR)) == (XTRN_STDIO|WWIVCOLOR) ? ", WWIV Color" : ""
		,(mode & (XTRN_STDIO|XTRN_NOECHO)) == (XTRN_STDIO|XTRN_NOECHO) ? ", No Echo" : "");
	return str;
}

void choose_io_method(uint32_t* misc)
{
	int k;

931
	switch((*misc) & (XTRN_STDIO|XTRN_UART|XTRN_FOSSIL)) {
932
933
934
935
936
937
		case XTRN_STDIO:
			k=0;
			break;
		case XTRN_UART:
			k=2;
			break;
938
939
940
		case XTRN_FOSSIL:
			k=3;
			break;
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
		default:
			k=1;
			break;
	}
	strcpy(opt[0], "Standard");
	if((*misc) & XTRN_NATIVE) {
		uifc.helpbuf=
			"`I/O Method:`\n"
			"\n"
			"Select the type of input and output to/from this program that you would\n"
			"like to have intercepted and directed to the remote user's terminal.\n"
			"\n"
			"`Standard`\n"
			"   So-called 'Standard I/O' of console mode (typically UNIX) programs.\n"
			"\n"
			"`Socket`\n"
			"   Stream (TCP) socket interface to a native (e.g. Win32 or *nix)\n"
			"   program. The socket descriptor/handle (number) is passed to the\n"
			"   program either via drop file (e.g. DOOR32.SYS) or command-line\n"
			"   option.\n"
			"\n"
			"~ Note ~\n"
			"   This setting is not applied when invoking Baja or JavaScript modules.\n"
		;
		strcpy(opt[1], "Socket");
		opt[2][0] = '\0';
	} else {
		uifc.helpbuf=
			"`I/O Method:`\n"
			"\n"
			"Select the type of input and output to/from this program that you would\n"
			"like to have intercepted and directed to the remote user's terminal.\n"
			"\n"
			"`Standard`\n"
			"   So-called 'Standard I/O' of console mode (typically UNIX) programs.\n"
			"   Int29h is intercepted for output and int16h for keyboard input.\n"
			"   Will not intercept direct screen writes or PC-BIOS int10h calls.\n"
			"\n"
			"`FOSSIL`\n"
			"   Int14h (PC-BIOS) serial communication interface to 16-bit\n"
			"   MS-DOS programs. Most traditional BBS door games will support FOSSIL.\n"
			"   The port number (contained in the DX register of int14h calls) is\n"
			"   ignored by the Synchronet FOSSIL driver.\n"
			"\n"
			"`UART`\n"
			"   Communication port I/O of 16-bit MS-DOS programs via emulation of an\n"
			"   NS8250 Universal Asynchronous Receiver/Transmitter (UART), by\n"
			"   default as an IBM-PC `COM1` port (I/O port 3F8h, IRQ 4).\n"
			"\n"
			"~ Note ~\n"
			"   This setting is not applied when invoking Baja or JavaScript modules.\n"
		;
		strcpy(opt[1], "FOSSIL or UART");
994
995
996
		strcpy(opt[2], "UART Only");
		strcpy(opt[3], "FOSSIL Only");
		opt[4][0] = '\0';
997
998
999
1000
	}
	switch(uifc.list(WIN_MID|WIN_SAV,0,0,0,&k,0,"I/O Method"
		,opt)) {
		case 0: /* Standard I/O */
For faster browsing, not all history is shown. View entire blame