uedit.c 32.8 KB
Newer Older
1
/* uedit.c */
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

/* Synchronet for *nix user editor */

/* $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.	*
 ****************************************************************************/

#include "sbbs.h"
#include "conwrap.h"	/* this has to go BEFORE curses.h so getkey() can be macroed around */
#include <curses.h>
#include <sys/types.h>
#include <time.h>
#include <sys/time.h>
#ifdef __QNX__
#include <string.h>
#endif
#include <stdio.h>
#include <unistd.h>
#include "genwrap.h"
#include "uifc.h"
#include "sbbsdefs.h"
#include "genwrap.h"	/* stricmp */
#include "dirwrap.h"	/* lock/unlock/sopen */
#include "filewrap.h"	/* lock/unlock/sopen */
#include "sbbs_ini.h"	/* INI parsing */
#include "scfglib.h"	/* SCFG files */
#include "ars_defs.h"	/* needed for SCFG files */
#include "userdat.h"	/* getnodedat() */

#define CTRL(x) (x&037)

/********************/
/* Global Variables */
/********************/
uifcapi_t uifc; /* User Interface (UIFC) Library API */
deuce's avatar
deuce committed
66
67
68
char *YesStr="Yes";
char *NoStr="No";
int 		modified=0;
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

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

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

void freeopt(char** opt)
{
	int i;

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

	free(opt);
}

deuce's avatar
deuce committed
111
112
113
114
115
116
117
118
119
int confirm(char *prompt)
{
	int i=0;
	char *opt[3]={
		 YesStr
		,NoStr
		,""
	};

deuce's avatar
deuce committed
120
	i=uifc.list(WIN_MID|WIN_ACT|WIN_SAV,0,0,0,&i,0,prompt,opt);
deuce's avatar
deuce committed
121
122
	if(i==0)
		return(1);
123
124
125
	if(i==-1)
		return(-1);
	return(0);
deuce's avatar
deuce committed
126
127
128
129
}

int check_save(scfg_t *cfg,user_t *user)
{
130
131
	int i;

deuce's avatar
deuce committed
132
	if(modified) {
133
134
		i=confirm("Save Changes?");
		if(i==1) {
deuce's avatar
deuce committed
135
136
137
			putuserdat(cfg,user);
		}
	}
138
	return(i);
deuce's avatar
deuce committed
139
140
}

deuce's avatar
deuce committed
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/****************************************************************************/
/* Takes a string in the format HH:MM:SS and returns in seconds             */
/****************************************************************************/
time_t DLLCALL strtosec(char *str)
{
	char *p1;
	char *p2;
	long int hour=0;
	long int min=0;
	long int sec2=0;
	time_t	sec=0;

	hour=strtol(str,&p1,10);
	if(hour<0 || hour > 24)
		return(-1);
	if(*p1==':') {
		p1++;
		min=strtol(p1,&p2,10);
		if(min<0 || min > 59)
			return(-1);
		if(*p2==':') {
			p2++;
			sec2=strtol(p2,&p1,10);
			if(sec2 < 0 || sec2 > 59)
				return(-1);
		}
	}

	sec=hour*60*60;
	sec+=min*60;
	sec+=sec2;
	return(sec);
}

deuce's avatar
deuce committed
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* Edit terminal settings
 *       Auto-Detect
 *       Extended ASCII
 *       ANSI
 *       Color
 *       RIP
 *       WIP
 *       Pause
 *       Hot Keys
 *       Spinning Cursor
 *       Number of Rows
 */
int edit_terminal(scfg_t *cfg, user_t *user)
{
deuce's avatar
deuce committed
189
190
191
192
193
194
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
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
	int 	i,j;
	char 	**opt;
	char	str[256];

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

	j=0;
	while(1) {
		i=0;
		sprintf(opt[i++],"Auto-detect:     %s",user->misc & AUTOTERM?"Yes":"No");
		sprintf(opt[i++],"Extended ASCII:  %s",user->misc & NO_EXASCII?"No":"Yes");
		sprintf(opt[i++],"ANSI:            %s",user->misc & ANSI?"Yes":"No");
		sprintf(opt[i++],"Colour:          %s",user->misc & COLOR?"Yes":"No");
		sprintf(opt[i++],"RIP:             %s",user->misc & RIP?"Yes":"No");
		sprintf(opt[i++],"WIP:             %s",user->misc & WIP?"Yes":"No");
		sprintf(opt[i++],"Pause:           %s",user->misc & UPAUSE?"Yes":"No");
		sprintf(opt[i++],"Hot Keys:        %s",user->misc & COLDKEYS?"No":"Yes");
		sprintf(opt[i++],"Spinning Cursor: %s",user->misc & SPIN?"Yes":"No");
		sprintf(str,"%u",user->rows);
		sprintf(opt[i++],"Number of Rows:  %s",user->rows?str:"Auto");
		opt[i][0]=0;
		switch(uifc.list(WIN_MID|WIN_ACT|WIN_SAV,0,0,0,&j,0,"Terminal Settings",opt)) {
			case -1:
				freeopt(opt);
				return(0);
				break;
			case 0:
				/* Auto-detect */
				user->misc ^= AUTOTERM;
				break;
			case 1:
				/* EX-ASCII */
				user->misc ^= NO_EXASCII;
				break;
			case 2:
				/* ANSI */
				user->misc ^= ANSI;
				break;
			case 3:
				/* Colour */
				user->misc ^= COLOR;
				break;
			case 4:
				/* RIP */
				user->misc ^= RIP;
				break;
			case 5:
				/* WIP */
				user->misc ^= WIP;
				break;
			case 6:
				/* Pause */
				user->misc ^= UPAUSE;
				break;
			case 7:
				/* Hot Keys */
				user->misc ^= COLDKEYS;
				break;
			case 8:
				/* Spinning Cursor */
				user->misc ^= SPIN;
				break;
			case 9:
				/* Rows */
				sprintf(str,"%u",user->rows);
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Rows",str,3,K_EDIT|K_NUMBER);
				if(uifc.changes) {
					modified=1;
					user->rows=strtoul(str,NULL,10);
				}
				break;
		}
	}	
deuce's avatar
deuce committed
266
267
268
269
270
271
272
273
274
275
276
277
	return(0);
}

/* Edit Logon settings
 *       Ask for New Message Scan
 *       Ask for Your Message Scan
 *       Remember Current Sub-board
 *       Quiet Mode (Q exempt)
 *       Auto-Login via IP (V exempt)
 */
int edit_logon(scfg_t *cfg, user_t *user)
{
deuce's avatar
deuce committed
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
	int 	i,j;
	char 	**opt;

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

	j=0;
	while(1) {
		i=0;
		sprintf(opt[i++],"Ask for New Message Scan:    %s",user->misc & ASK_NSCAN?"Yes":"No");
		sprintf(opt[i++],"Ask for Your Message Scan:   %s",user->misc & ASK_SSCAN?"Yes":"No");
		sprintf(opt[i++],"Remember Current Sub:        %s",user->misc & CURSUB?"Yes":"No");
		sprintf(opt[i++],"Quiet Mode: (Q exempt)       %s",user->misc & QUIET?"Yes":"No");
		sprintf(opt[i++],"Auto-Login via IP (V exempt) %s",user->misc & AUTOLOGON?"Yes":"No");
		opt[i][0]=0;
		switch(uifc.list(WIN_MID|WIN_ACT|WIN_SAV,0,0,0,&j,0,"Logon Settings",opt)) {
			case -1:
				freeopt(opt);
				return(0);
				break;
			case 0:
				/* Ask New MSG Scan */
				user->misc ^= ASK_NSCAN;
				break;
			case 1:
				/* Ask YOUR MSG scan */
				user->misc ^= ASK_SSCAN;
				break;
			case 2:
				/* Remember Curr Sub */
				user->misc ^= CURSUB;
				break;
			case 3:
				/* Quiet Mode */
				user->misc ^= QUIET;
				break;
			case 4:
				/* Auto-Login by IP */
				user->misc ^= AUTOLOGON;
				break;
		}
	}
deuce's avatar
deuce committed
323
324
325
326
327
328
329
330
331
332
333
334
	return(0);
}

/* Edit Chat Settings
 *       Multinode Chat Echo
 *       Multinode Chat Actions
 *       Available for Internode chat
 *       Multinode Activity Alerts
 *       Split-screen Private Chat
 */
int edit_chat(scfg_t *cfg, user_t *user)
{
deuce's avatar
deuce committed
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
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
400
401
402
403
404
405
406
407
	int 	i,j;
	char 	**opt;

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

	j=0;
	while(1) {
		i=0;
		sprintf(opt[i++],"Chat Echo:                 %s",user->chat & CHAT_ECHO?"Yes":"No");
		sprintf(opt[i++],"Chat Actions:              %s",user->chat & CHAT_ACTION?"Yes":"No");
		sprintf(opt[i++],"Available for Chat:        %s",user->chat & CHAT_NOPAGE?"No":"Yes");
		sprintf(opt[i++],"Activity Alerts            %s",user->chat & CHAT_NOACT?"No":"Yes");
		sprintf(opt[i++],"Split-Screen Private Chat: %s",user->chat & CHAT_SPLITP?"Yes":"No");
		opt[i][0]=0;
		switch(uifc.list(WIN_MID|WIN_ACT|WIN_SAV,0,0,0,&j,0,"Chat Settings",opt)) {
			case -1:
				freeopt(opt);
				return(0);
				break;
			case 0:
				/* Chat Echo */
				user->chat ^= CHAT_ECHO;
				break;
			case 1:
				/* Chat Actions */
				user->chat ^= CHAT_ACTION;
				break;
			case 2:
				/* Availabe for Chat */
				user->chat ^= CHAT_NOPAGE;
				break;
			case 3:
				/* Activity Alerts */
				user->chat ^= CHAT_NOACT;
				break;
			case 4:
				/* Split-Screen Priv Chat */
				user->chat ^= CHAT_SPLITP;
				break;
		}
	}
	return(0);
}

/* Pick Command Shell */
int edit_shell(scfg_t *cfg, user_t *user)
{
	int 	i,j;
	char 	**opt;

	if((opt=(char **)MALLOC(sizeof(char *)*(MAX_OPTS+1)))==NULL)
		allocfail(sizeof(char *)*(MAX_OPTS+1));


	for(i=0;i<cfg->total_shells;i++) {
		opt[i]=cfg->shell[i]->name;
	}
	opt[i]="";
	j=user->shell-1;
	switch(uifc.list(WIN_MID|WIN_SAV,0,0,0,&j,0,"Shell",opt)) {
		case -1:
			break;
		default:
			if(user->shell != j+1)
				modified=1;
			user->shell=j+1;
			break;
	}
	free(opt);
deuce's avatar
deuce committed
408
409
410
411
412
413
414
415
416
	return(0);
}

/* Edit Command Shell
 *       Name
 *       Expert Mode
 */
int edit_cmd(scfg_t *cfg, user_t *user)
{
deuce's avatar
deuce committed
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
	int 	i,j;
	char 	**opt;

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

	j=0;
	while(1) {
		i=0;
		sprintf(opt[i++],"Command Shell: %s",cfg->shell[user->shell]->name);
		sprintf(opt[i++],"Expert Mode:   %s",user->misc & EXPERT?"Yes":"No");
		opt[i][0]=0;
		switch(uifc.list(WIN_MID|WIN_ACT|WIN_SAV,0,0,0,&j,0,"Command Shell",opt)) {
			case -1:
				freeopt(opt);
				return(0);
				break;
			case 0:
				/* Command Shell */
				edit_shell(cfg,user);
				break;
			case 1:
				/* Expoert Mode */
				user->misc ^= EXPERT;
				break;
		}
	}

deuce's avatar
deuce committed
448
449
450
	return(0);
}

deuce's avatar
deuce committed
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
/* Edit "Extended comment" */
int edit_comment(scfg_t *cfg, user_t *user)
{
	return(0);
}

/* MSG and File settings
 *      - Message Options
 *      - QWK Message Packet
 *      - File Options
 */
int edit_msgfile(scfg_t *cfg, user_t *user)
{
	return(0);
}

/* Settings
 *     - Terminal Settings
 *     - Logon Toggles
 *     - Chat Toggles
 *     - Command Shell
 */
int edit_settings(scfg_t *cfg, user_t *user)
{
deuce's avatar
deuce committed
475
476
477
478
479
480
481
482
483
	char *opt[5]={
		 "Terminal Settings"
		,"Logon Toggles"
		,"Chat Toggles"
		,"Command Shell"
		,""};
	int i=0;

	while(1) {
deuce's avatar
deuce committed
484
		switch(uifc.list(WIN_BOT|WIN_RHT|WIN_ACT,0,0,0,&i,0,"Settings",opt)) {
deuce's avatar
deuce committed
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
			case -1:
				return(0);
				break;
			case 0:
				/* Terminal Settings */
				edit_terminal(cfg,user);
				break;
			case 1:
				/* Logon Toggles */
				edit_logon(cfg,user);
				break;
			case 2:
				/* Chat Toggles */
				edit_chat(cfg,user);
				break;
			case 3:
				/* Command Shell */
				edit_cmd(cfg,user);
				break;
		}
	}
deuce's avatar
deuce committed
506
507
508
509
510
511
512
513
514
515
516
517
518
519
	return(0);
}

/* Statistics
 *     First On
 *     Last On
 *     Total Logons
 *     Todays Logons
 *     Total Posts
 *     Todays Posts
 *     Total Uploads
 *     Todays Uploads
 *     Total Time On
 *     Todays Time On
deuce's avatar
deuce committed
520
 *     Last Call Time On
deuce's avatar
deuce committed
521
522
523
524
525
526
527
528
529
530
 *     Extra
 *     Total Downloads
 *     Bytes
 *     Leech
 *     Total Email
 *     Todays Email
 *     Email to Sysop
 */
int edit_stats(scfg_t *cfg, user_t *user)
{
deuce's avatar
deuce committed
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
	int 	i,j;
	char 	**opt;
	char	str[256];
	time_t	temptime,temptime2;

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

	j=0;
	while(1) {
		i=0;
		sprintf(opt[i++],"First On:          %s",user->firston?timestr(cfg, &user->firston, str):"Never");
		sprintf(opt[i++],"Last On:           %s",user->laston?timestr(cfg, &user->laston, str):"Never");
		sprintf(opt[i++],"Logon Time:        %s",user->laston?timestr(cfg, &user->logontime, str):"Not On");
		sprintf(opt[i++],"Total Logons:      %hu",user->logons);
		sprintf(opt[i++],"Todays Logons:     %hu",user->ltoday);
		sprintf(opt[i++],"Total Posts:       %hu",user->posts);
		sprintf(opt[i++],"Todays Posts:      %hu",user->ptoday);
		sprintf(opt[i++],"Total Email:       %hu",user->emails);
		sprintf(opt[i++],"Todays Email:      %hu",user->etoday);
		sprintf(opt[i++],"Email To Sysop:    %hu",user->fbacks);
		sprintf(opt[i++],"Total Time On:     %hu",user->timeon);
		sprintf(opt[i++],"Time On Today:     %hu",user->ttoday);
		sprintf(opt[i++],"Time On Last Call: %hu",user->tlast);
		sprintf(opt[i++],"Extra Time Today:  %hu",user->textra);
		sprintf(opt[i++],"Total Downloads:   %hu",user->dls);
		sprintf(opt[i++],"Downloaded Bytes:  %lu",user->dlb);
		sprintf(opt[i++],"Total Uploads:     %hu",user->uls);
		sprintf(opt[i++],"Uploaded Bytes:    %lu",user->ulb);
		sprintf(opt[i++],"Leech:             %u",user->leech);
deuce's avatar
deuce committed
564
		switch(uifc.list(WIN_MID|WIN_ACT,0,0,0,&j,0,"Statistics",opt)) {
deuce's avatar
deuce committed
565
566
567
568
569
570
571
572
			case -1:
				freeopt(opt);
				return(0);
				break;
			case 0:
				/* First On */
				temptime=user->firston;
				unixtodstr(cfg,temptime,str);
deuce's avatar
deuce committed
573
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"First On Date",str,8,K_EDIT);
deuce's avatar
deuce committed
574
575
576
				user->firston=dstrtounix(cfg, str);
				temptime2=temptime-user->firston;
				sectostr(temptime2,str);
deuce's avatar
deuce committed
577
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"First On Time",str,8,K_EDIT);
deuce's avatar
deuce committed
578
579
580
581
582
583
584
585
586
587
				temptime2=strtosec(str);
				if(temptime2!=-1)
					user->firston += temptime2;
				if(temptime!=user->firston)
					modified=1;
				break;
			case 1:
				/* Last On */
				temptime=user->laston;
				unixtodstr(cfg,temptime,str);
deuce's avatar
deuce committed
588
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Last On Date",str,8,K_EDIT);
deuce's avatar
deuce committed
589
590
591
				user->laston=dstrtounix(cfg, str);
				temptime2=temptime-user->laston;
				sectostr(temptime2,str);
deuce's avatar
deuce committed
592
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Last On Time",str,8,K_EDIT);
deuce's avatar
deuce committed
593
594
595
596
597
598
599
600
601
602
				temptime2=strtosec(str);
				if(temptime2!=-1)
					user->laston += temptime2;
				if(temptime!=user->laston)
					modified=1;
				break;
			case 2:
				/* Logon Time */
				temptime=user->logontime;
				unixtodstr(cfg,temptime,str);
deuce's avatar
deuce committed
603
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Logon Date",str,8,K_EDIT);
deuce's avatar
deuce committed
604
605
606
				user->logontime=dstrtounix(cfg, str);
				temptime2=temptime-user->logontime;
				sectostr(temptime2,str);
deuce's avatar
deuce committed
607
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Logon Time",str,8,K_EDIT);
deuce's avatar
deuce committed
608
609
610
611
612
613
614
615
616
				temptime2=strtosec(str);
				if(temptime2!=-1)
					user->logontime += temptime2;
				if(temptime!=user->logontime)
					modified=1;
				break;
			case 3:
				/* Total Logons */
				sprintf(str,"%hu",user->logons);
deuce's avatar
deuce committed
617
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Total Logons",str,5,K_EDIT|K_NUMBER);
deuce's avatar
deuce committed
618
619
620
621
622
623
624
625
				if(uifc.changes) {
					modified=1;
					user->logons=strtoul(str,NULL,10);
				}
				break;
			case 4:
				/* Todays Logons */
				sprintf(str,"%hu",user->ltoday);
deuce's avatar
deuce committed
626
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Todays Logons",str,5,K_EDIT|K_NUMBER);
deuce's avatar
deuce committed
627
628
629
630
631
632
633
634
				if(uifc.changes) {
					modified=1;
					user->ltoday=strtoul(str,NULL,10);
				}
				break;
			case 5:
				/* Total Posts */
				sprintf(str,"%hu",user->posts);
deuce's avatar
deuce committed
635
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Total Posts",str,5,K_EDIT|K_NUMBER);
deuce's avatar
deuce committed
636
637
638
639
640
641
642
643
				if(uifc.changes) {
					modified=1;
					user->posts=strtoul(str,NULL,10);
				}
				break;
			case 6:
				/* Todays Posts */
				sprintf(str,"%hu",user->ptoday);
deuce's avatar
deuce committed
644
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Todays Posts",str,5,K_EDIT|K_NUMBER);
deuce's avatar
deuce committed
645
646
647
648
649
650
651
652
				if(uifc.changes) {
					modified=1;
					user->ptoday=strtoul(str,NULL,10);
				}
				break;
			case 7:
				/* Total Emails */
				sprintf(str,"%hu",user->emails);
deuce's avatar
deuce committed
653
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Total Emails",str,5,K_EDIT|K_NUMBER);
deuce's avatar
deuce committed
654
655
656
657
658
659
660
661
				if(uifc.changes) {
					modified=1;
					user->emails=strtoul(str,NULL,10);
				}
				break;
			case 8:
				/* Todays Emails */
				sprintf(str,"%hu",user->etoday);
deuce's avatar
deuce committed
662
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Todays Emails",str,5,K_EDIT|K_NUMBER);
deuce's avatar
deuce committed
663
664
665
666
667
668
669
670
				if(uifc.changes) {
					modified=1;
					user->etoday=strtoul(str,NULL,10);
				}
				break;
			case 9:
				/* Emails to Sysop */
				sprintf(str,"%hu",user->fbacks);
deuce's avatar
deuce committed
671
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Emails to Sysop",str,5,K_EDIT|K_NUMBER);
deuce's avatar
deuce committed
672
673
674
675
676
677
678
679
				if(uifc.changes) {
					modified=1;
					user->fbacks=strtoul(str,NULL,10);
				}
				break;
			case 10:
				/* Total Time On */
				sprintf(str,"%hu",user->timeon);
deuce's avatar
deuce committed
680
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Total Time On",str,5,K_EDIT|K_NUMBER);
deuce's avatar
deuce committed
681
682
683
684
685
686
687
688
				if(uifc.changes) {
					modified=1;
					user->timeon=strtoul(str,NULL,10);
				}
				break;
			case 11:
				/* Time On Today */
				sprintf(str,"%hu",user->ttoday);
deuce's avatar
deuce committed
689
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Time On Today",str,5,K_EDIT|K_NUMBER);
deuce's avatar
deuce committed
690
691
692
693
694
695
696
697
				if(uifc.changes) {
					modified=1;
					user->ttoday=strtoul(str,NULL,10);
				}
				break;
			case 12:
				/* Time On Last Call */
				sprintf(str,"%hu",user->tlast);
deuce's avatar
deuce committed
698
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Time On Last Call",str,5,K_EDIT|K_NUMBER);
deuce's avatar
deuce committed
699
700
701
702
703
704
705
706
				if(uifc.changes) {
					modified=1;
					user->tlast=strtoul(str,NULL,10);
				}
				break;
			case 13:
				/* Extra Time Today */
				sprintf(str,"%hu",user->textra);
deuce's avatar
deuce committed
707
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Extra Time Today",str,5,K_EDIT|K_NUMBER);
deuce's avatar
deuce committed
708
709
710
711
712
713
714
715
				if(uifc.changes) {
					modified=1;
					user->textra=strtoul(str,NULL,10);
				}
				break;
			case 14:
				/* Total Downloads */
				sprintf(str,"%hu",user->dls);
deuce's avatar
deuce committed
716
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Total Downloads",str,5,K_EDIT|K_NUMBER);
deuce's avatar
deuce committed
717
718
719
720
721
722
723
724
				if(uifc.changes) {
					modified=1;
					user->dls=strtoul(str,NULL,10);
				}
				break;
			case 15:
				/* Downloaded Bytes */
				sprintf(str,"%lu",user->dlb);
deuce's avatar
deuce committed
725
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Downloaded Bytes",str,10,K_EDIT|K_NUMBER);
deuce's avatar
deuce committed
726
727
728
729
730
731
732
733
				if(uifc.changes) {
					modified=1;
					user->dlb=strtoul(str,NULL,10);
				}
				break;
			case 16:
				/* Total Uploads */
				sprintf(str,"%hu",user->uls);
deuce's avatar
deuce committed
734
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Total Uploads",str,5,K_EDIT|K_NUMBER);
deuce's avatar
deuce committed
735
736
737
738
739
740
741
742
				if(uifc.changes) {
					modified=1;
					user->uls=strtoul(str,NULL,10);
				}
				break;
			case 17:
				/* Uploaded Bytes */
				sprintf(str,"%lu",user->ulb);
deuce's avatar
deuce committed
743
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Uploaded Bytes",str,10,K_EDIT|K_NUMBER);
deuce's avatar
deuce committed
744
745
746
747
748
749
750
751
				if(uifc.changes) {
					modified=1;
					user->ulb=strtoul(str,NULL,10);
				}
				break;
			case 18:
				/* Leech Counter */
				sprintf(str,"%u",user->leech);
deuce's avatar
deuce committed
752
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Leech Counter",str,3,K_EDIT|K_NUMBER);
deuce's avatar
deuce committed
753
754
755
756
757
758
759
				if(uifc.changes) {
					modified=1;
					user->leech=strtoul(str,NULL,10);
				}
				break;
		}
	}
deuce's avatar
deuce committed
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
	return(0);
}

/* Security settings
 *     Level
 *     Expiration
 *     Flag Set 1
 *     Flag Set 2
 *     Flag Set 3
 *     Flag Set 4
 *     Exemptions
 *     Restrictions
 *     Credits
 *     Free Credits
 *     Minutes
 */
int edit_security(scfg_t *cfg, user_t *user)
{
778
779
	int 	i,j;
	char 	**opt;
780
	char	str[256];
781
782
783
784
785
786
787

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

788
789
790
	j=0;
	while(1) {
		i=0;
deuce's avatar
deuce committed
791
		sprintf(opt[i++],"Level:        %d",user->level);
792
793
794
795
796
797
798
		sprintf(opt[i++],"Expiration:   %s",user->expire?unixtodstr(cfg, user->expire, str):"Never");
		sprintf(opt[i++],"Flag Set 1:   %s",ltoaf(user->flags1,str));
		sprintf(opt[i++],"Flag Set 2:   %s",ltoaf(user->flags2,str));
		sprintf(opt[i++],"Flag Set 3:   %s",ltoaf(user->flags3,str));
		sprintf(opt[i++],"Flag Set 4:   %s",ltoaf(user->flags4,str));
		sprintf(opt[i++],"Exemptions:   %s",ltoaf(user->exempt,str));
		sprintf(opt[i++],"Restrictions: %s",ltoaf(user->rest,str));
deuce's avatar
deuce committed
799
800
801
		sprintf(opt[i++],"Credits:      %lu",user->cdt);
		sprintf(opt[i++],"Free Credits: %lu",user->freecdt);
		sprintf(opt[i++],"Minutes:      %lu",user->min);
802
		opt[i][0]=0;
deuce's avatar
deuce committed
803
		switch(uifc.list(WIN_MID|WIN_ACT,0,0,0,&j,0,"Security Settings",opt)) {
804
805
806
807
808
809
810
			case -1:
				freeopt(opt);
				return(0);
				break;
			case 0:
				/* Level */
				sprintf(str,"%d",user->level);
deuce's avatar
deuce committed
811
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Level",str,2,K_EDIT|K_NUMBER);
812
813
814
815
816
817
818
819
				if(uifc.changes) {
					modified=1;
					user->level=atoi(str);
				}
				break;
			case 1:
				/* Expiration */
				unixtodstr(cfg,user->expire,str);
deuce's avatar
deuce committed
820
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Expiration",str,8,K_EDIT);
821
822
823
824
825
826
827
828
				if(uifc.changes && dstrtounix(cfg, str)!=user->expire) {
					modified=1;
					user->expire=dstrtounix(cfg, str);
				}
				break;
			case 2:
				/* Flag Set 1 */
				ltoaf(user->flags1,str);
deuce's avatar
deuce committed
829
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Flag Set 1",str,26,K_EDIT|K_UPPER|K_ALPHA);
830
831
832
833
834
835
836
837
				if(uifc.changes) {
					modified=1;
					user->flags1=aftol(str);
				}
				break;
			case 3:
				/* Flag Set 2 */
				ltoaf(user->flags2,str);
deuce's avatar
deuce committed
838
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Flag Set 2",str,26,K_EDIT|K_UPPER|K_ALPHA);
839
840
841
842
843
844
845
846
				if(uifc.changes) {
					modified=1;
					user->flags2=aftol(str);
				}
				break;
			case 4:
				/* Flag Set 3 */
				ltoaf(user->flags3,str);
deuce's avatar
deuce committed
847
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Flag Set 3",str,26,K_EDIT|K_UPPER|K_ALPHA);
848
849
850
851
852
853
854
855
				if(uifc.changes) {
					modified=1;
					user->flags3=aftol(str);
				}
				break;
			case 5:
				/* Flag Set 4 */
				ltoaf(user->flags4,str);
deuce's avatar
deuce committed
856
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Flag Set 4",str,26,K_EDIT|K_UPPER|K_ALPHA);
857
858
859
860
861
862
863
864
				if(uifc.changes) {
					modified=1;
					user->flags4=aftol(str);
				}
				break;
			case 6:
				/* Exemptions */
				ltoaf(user->exempt,str);
deuce's avatar
deuce committed
865
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Exemptions",str,26,K_EDIT|K_UPPER|K_ALPHA);
866
867
868
869
870
871
872
873
				if(uifc.changes) {
					modified=1;
					user->exempt=aftol(str);
				}
				break;
			case 7:
				/* Restrictions */
				ltoaf(user->rest,str);
deuce's avatar
deuce committed
874
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Restrictions",str,26,K_EDIT|K_UPPER|K_ALPHA);
875
876
877
878
879
880
881
882
				if(uifc.changes) {
					modified=1;
					user->rest=aftol(str);
				}
				break;
			case 8:
				/* Credits */
				sprintf(str,"%lu",user->cdt);
deuce's avatar
deuce committed
883
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Credits",str,10,K_EDIT|K_NUMBER);
884
885
886
887
888
889
890
891
				if(uifc.changes) {
					modified=1;
					user->cdt=strtoul(str,NULL,10);
				}
				break;
			case 9:
				/* Free Credits */
				sprintf(str,"%lu",user->freecdt);
deuce's avatar
deuce committed
892
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Free Credits",str,10,K_EDIT|K_NUMBER);
893
894
895
896
897
898
899
900
				if(uifc.changes) {
					modified=1;
					user->freecdt=strtoul(str,NULL,10);
				}
				break;
			case 10:
				/* Minutes */
				sprintf(str,"%lu",user->min);
deuce's avatar
deuce committed
901
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Minutes",str,10,K_EDIT|K_NUMBER);
902
903
904
905
906
907
908
909
				if(uifc.changes) {
					modified=1;
					user->min=strtoul(str,NULL,10);
				}
				break;
		}
	}

deuce's avatar
deuce committed
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
	return(0);
}

/*
 * Personal settings... 
 *     Real Name
 *     Computer
 *     NetMail
 *     Phone
 *     Note
 *     Comment
 *     Gender
 *     Connection
 *     Handle
 *     Password
 *     Address 1
 *     Address 2
 *     Postal/ZIP?
 */
int edit_personal(scfg_t *cfg, user_t *user)
{
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
	int 	i,j;
	char 	**opt;
	char	onech[2];

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

	j=0;
	while(1) {
		i=0;
		sprintf(opt[i++],"Real Name:  %s",user->name);
		sprintf(opt[i++],"Computer:   %s",user->comp);
		sprintf(opt[i++],"NetMail:    %s",user->netmail);
		sprintf(opt[i++],"Phone:      %s",user->phone);
		sprintf(opt[i++],"Note:       %s",user->note);
		sprintf(opt[i++],"Comment:    %s",user->comment);
		sprintf(opt[i++],"Gender:     %c",user->sex);
		sprintf(opt[i++],"Connection: %s",user->modem);
		sprintf(opt[i++],"Handle:     %s",user->alias);
		sprintf(opt[i++],"Password:   %s",user->pass);
		sprintf(opt[i++],"Location:   %s",user->location);
		sprintf(opt[i++],"Address:    %s",user->address);
		sprintf(opt[i++],"Postal/Zip: %s",user->zipcode);
957
		opt[i][0]=0;
958
		uifc.changes=FALSE;
deuce's avatar
deuce committed
959
		switch(uifc.list(WIN_MID|WIN_ACT,0,0,0,&j,0,"Personal Settings",opt)) {
960
961
962
963
964
			case -1:
				freeopt(opt);
				return(0);
			case 0:
				/* Real Name */
deuce's avatar
deuce committed
965
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Real Name",user->name,LEN_NAME,K_EDIT);
966
967
968
969
970
				if(uifc.changes)
					modified=1;
				break;
			case 1:
				/* Computer */
deuce's avatar
deuce committed
971
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Computer",user->comp,LEN_COMP,K_EDIT);
972
973
974
975
976
				if(uifc.changes)
					modified=1;
				break;
			case 2:
				/* NetMail */
deuce's avatar
deuce committed
977
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"NetMail Address",user->netmail,LEN_NETMAIL,K_EDIT);
978
979
980
981
982
				if(uifc.changes)
					modified=1;
				break;
			case 3:
				/* Phone */
deuce's avatar
deuce committed
983
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Phone",user->phone,LEN_PHONE,K_EDIT);
984
985
986
987
988
				if(uifc.changes)
					modified=1;
				break;
			case 4:
				/* Note */
deuce's avatar
deuce committed
989
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Note",user->note,LEN_NOTE,K_EDIT);
990
991
992
993
994
				if(uifc.changes)
					modified=1;
				break;
			case 5:
				/* Comment */
deuce's avatar
deuce committed
995
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Comment",user->comment,LEN_COMMENT,K_EDIT);
996
997
998
999
1000
1001
				if(uifc.changes)
					modified=1;
				break;
			case 6:
				/* Gender */
				sprintf(onech,"%c",user->sex);
deuce's avatar
deuce committed
1002
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Gender",onech,1,K_UPPER|K_ALPHA|K_EDIT);
1003
1004
1005
1006
1007
1008
1009
				if(onech[0]!=user->sex && (onech[0]=='M' || onech[0]=='F')) {
					modified=1;
					user->sex=onech[0];
				}
				break;
			case 7:
				/* Connection */
deuce's avatar
deuce committed
1010
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Connection",user->modem,LEN_MODEM,K_EDIT);
1011
1012
1013
1014
1015
				if(uifc.changes)
					modified=1;
				break;
			case 8:
				/* Handle */
deuce's avatar
deuce committed
1016
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Handle",user->alias,LEN_ALIAS,K_EDIT);
1017
1018
1019
1020
1021
				if(uifc.changes)
					modified=1;
				break;
			case 9:
				/* Password */
deuce's avatar
deuce committed
1022
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Password",user->pass,LEN_PASS,K_EDIT);
1023
1024
1025
				if(uifc.changes)
					modified=1;
				break;
deuce's avatar
deuce committed
1026
			case 10:
1027
				/* Location */
deuce's avatar
deuce committed
1028
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Location",user->location,LEN_LOCATION,K_EDIT);
1029
1030
1031
				if(uifc.changes)
					modified=1;
				break;
deuce's avatar
deuce committed
1032
			case 11:
1033
				/* Address */
deuce's avatar
deuce committed
1034
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Address",user->address,LEN_ADDRESS,K_EDIT);
1035
1036
1037
				if(uifc.changes)
					modified=1;
				break;
deuce's avatar
deuce committed
1038
			case 12:
1039
				/* Postal/Zip */
deuce's avatar
deuce committed
1040
				uifc.input(WIN_MID|WIN_ACT|WIN_SAV,0,0,"Postal/Zip Code",user->zipcode,LEN_ZIPCODE,K_EDIT);
1041
1042
1043
1044
1045
1046
				if(uifc.changes)
					modified=1;
				break;
		}
	}

deuce's avatar
deuce committed
1047
1048
1049
1050
1051
1052
	return(0);
}

/*
 * This is where the good stuff happens
 */
1053
1054
int edit_user(scfg_t *cfg, int usernum)
{
deuce's avatar
deuce committed
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
	char**	opt;
	int 	i,j;
	user_t	user;

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

	user.number=usernum;
	getuserdat(cfg,&user);

	modified=0;
1069
	j=0;
deuce's avatar
deuce committed
1070
	while(1) {
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
		i=0;
		strcpy(opt[i++],"Reload");
		if (user.misc & DELETED)
			strcpy(opt[i++],"Undelete");
		else
			strcpy(opt[i++],"Delete");
		if (user.misc & INACTIVE)
			strcpy(opt[i++],"Activate");
		else
			strcpy(opt[i++],"Deactivate");
		strcpy(opt[i++],"Personal");
		strcpy(opt[i++],"Security");
		strcpy(opt[i++],"Statistics");
		strcpy(opt[i++],"Settings");
		strcpy(opt[i++],"MSG/File Settings");
		strcpy(opt[i++],"Extended Comment");
		opt[i][0]=0;

deuce's avatar
deuce committed
1089
		switch(uifc.list(WIN_ORG|WIN_ACT,0,0,0,&j,0,"Edit User",opt)) {
deuce's avatar
deuce committed
1090
1091
			case -1:
				if(modified) {
1092
					i=check_save(cfg,&user);
1093
				}
1094
				if(i!=-1) {
1095
1096
					freeopt(opt);
					return(0);
deuce's avatar
deuce committed
1097
1098
1099
1100
				}
				break;

			case 0:
1101
				if(modified && confirm("This will undo any changes you have made.  Continue?")==1) {
deuce's avatar
deuce committed
1102
					getuserdat(cfg,&user);
1103
					modified=0;
deuce's avatar
deuce committed
1104
				}
1105
1106
				modified=0;
				break;
deuce's avatar
deuce committed
1107
1108

			case 1:
1109
				user.misc ^= DELETED;
deuce's avatar
deuce committed
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
				modified=1;
				break;

			case 2:
				user.misc ^= INACTIVE;
				modified=1;
				break;

			case 3:
				edit_personal(cfg,&user);
				break;

			case 4:
				edit_security(cfg,&user);
				break;

			case 5:
				edit_stats(cfg,&user);
				break;

			case 6:
				edit_settings(cfg,&user);
				break;

			case 7:
				edit_msgfile(cfg,&user);
				break;

			case 8:
				edit_comment(cfg,&user);
				break;

			default:
				break;
		}
	}
	
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
	return(0);
}

int main(int argc, char** argv)  {
	char**	opt;
	char**	mopt;
	int		main_dflt=0;
	int		main_bar=0;
	char	revision[16];
	char	str[256],ctrl_dir[41],*p;
	char	title[256];
	int		i,j;
	scfg_t	cfg;
	int		done;
	int		last;
	user_t	user;
	/******************/
	/* Ini file stuff */
	/******************/
	char	ini_file[MAX_PATH+1];
	FILE*				fp;
	bbs_startup_t		bbs_startup;

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

    printf("\nSynchronet User Editor %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,"/");

	gethostname(str,sizeof(str)-1);

	sbbs_get_ini_fname(ini_file, ctrl_dir, str);

	/* 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 */
	sbbs_read_ini(fp, 
		NULL, &bbs_startup, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

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

	chdir(bbs_startup.ctrl_dir);
	
	/* Read .cfg files here */
    memset(&cfg,0,sizeof(cfg));
	cfg.size=sizeof(cfg);
	SAFECOPY(cfg.ctrl_dir,bbs_startup.ctrl_dir);
	if(!load_cfg(&cfg, NULL, TRUE, str)) {
		printf("ERROR! %s\n",str);
		exit(1);
	}
	prep_dir(cfg.data_dir, cfg.temp_dir, sizeof(cfg.temp_dir));

    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':
					/* Set up ex-ascii codes */
					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);
           }
    }

	signal(SIGPIPE, SIG_IGN);   

	uifc.size=sizeof(uifc);
#ifdef USE_CURSES
	i=uifcinic(&uifc);  /* curses */
#else
	i=uifcini32(&uifc);  /* curses */
#endif
	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);

	sprintf(title,"Synchronet User Editor %s-%s",revision,PLATFORM_DESC);
	if(uifc.scrn(title)) {
		printf(" USCRN (len=%d) failed!\n",uifc.scrn_len+1);
		bail(1);
	}

	strcpy(mopt[0],"New User");
	strcpy(mopt[1],"Find User");
	strcpy(mopt[2],"User List");
	mopt[3][0]=0;

	uifc.helpbuf=	"`User Editor:`\n"
					"\nToDo: Add Help";

	while(1) {
deuce's avatar
deuce committed
1294
		j=uifc.list(WIN_L2R|WIN_ESC|WIN_ACT|WIN_DYN|WIN_ORG,0,5,70,&main_dflt,&main_bar
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
			,title,mopt);

		if(j == -2)
			continue;

		if(j==-8) {	/* CTRL-F */
			/* Find User */
			continue;
		}
		
		if(j==-2-KEY_F(4)) {	/* Find? */
			continue;
		}

		if(j <= -2)
			continue;

		if(j==-1) {
			uifc.helpbuf=	"`Exit Synchronet User Editor:`\n"
							"\n"
							"\nIf you want to exit the Synchronet user editor,"
							"\nselect `Yes`. Otherwise, select `No` or hit ~ ESC ~.";
deuce's avatar
deuce committed
1317
			if(confirm("Exit Synchronet User Editor")==1)
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
				bail(0);
			continue;
		}

		if(j==0) {
			/* New User */
		}
		if(j==1) {
			/* Find User */
		}
		if(j==2) {
			/* User List */
			done=0;
			while(!done) {
				last=lastuser(&cfg);
				for(i=1; i<=last; i++) {
					user.number=i;
					getuserdat(&cfg,&user);
					sprintf(opt[i-1],"%s (%s)",user.name,user.alias);
				}
				opt[i-1][0]=0;
				i=0;
deuce's avatar
deuce committed
1340
				switch(uifc.list(WIN_ORG|WIN_MID|WIN_ACT,0,0,0,&i,0,"Select User",opt)) {
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
					case -1:
						done=1;
						break;
					default:
						edit_user(&cfg, i+1);
						break;
				}
			}
		}
	}
}