Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

newuser.cpp 14.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/* newuser.cpp */

/* Synchronet new user routine */

/* $Id$ */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
11
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 *																			*
 * 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"
39
#include "petdefs.h"
40 41 42 43 44 45 46
#include "cmdshell.h"

/****************************************************************************/
/* This function is invoked when a user enters "NEW" at the NN: prompt		*/
/* Prompts user for personal information and then sends feedback to sysop.  */
/* Called from function waitforcall											*/
/****************************************************************************/
rswindell's avatar
rswindell committed
47
BOOL sbbs_t::newuser()
48
{
49 50
	char	c,str[512];
	char 	tmp[512];
51
	uint	i;
52
	long	kmode;
53
	bool	usa;
54

55
	bputs(text[StartingNewUserRegistration]);
56 57 58
	getnodedat(cfg.node_num,&thisnode,0);
	if(thisnode.misc&NODE_LOCK) {
		bputs(text[NodeLocked]);
59
		logline(LOG_WARNING,"N!","New user locked node logon attempt");
60
		hangup();
rswindell's avatar
rswindell committed
61 62
		return(FALSE); 
	}
63 64 65 66

	if(cfg.sys_misc&SM_CLOSED) {
		bputs(text[NoNewUsers]);
		hangup();
rswindell's avatar
rswindell committed
67 68
		return(FALSE); 
	}
69 70
	getnodedat(cfg.node_num,&thisnode,1);
	thisnode.status=NODE_NEWUSER;
71
	thisnode.connection=node_connection;
72 73 74 75 76 77 78 79 80
	putnodedat(cfg.node_num,&thisnode);
	memset(&useron,0,sizeof(user_t));	  /* Initialize user info to null */
	if(cfg.new_pass[0] && online==ON_REMOTE) {
		c=0;
		while(++c<4) {
			bputs(text[NewUserPasswordPrompt]);
			getstr(str,40,K_UPPER);
			if(!strcmp(str,cfg.new_pass))
				break;
81
			SAFEPRINTF(tmp,"NUP Attempted: '%s'",str);
82
			logline(LOG_NOTICE,"N!",tmp); 
rswindell's avatar
rswindell committed
83
		}
84
		if(c==4) {
85
			menu("../nupguess", P_NOABORT|P_NOERROR);
86
			hangup();
rswindell's avatar
rswindell committed
87 88 89
			return(FALSE); 
		} 
	}
90 91 92

	/* Sets defaults per sysop config */
	useron.misc|=(cfg.new_misc&~(DELETED|INACTIVE|QUIET|NETMAIL));
93
	useron.qwk=QWK_DEFAULT;
94
	useron.firston=useron.laston=useron.pwmod=time32(NULL);
95 96
	if(cfg.new_expire) {
		now=time(NULL);
97
		useron.expire=(time32_t)(now+((long)cfg.new_expire*24L*60L*60L)); 
rswindell's avatar
rswindell committed
98
	} else
99
		useron.expire=0;
100
	useron.sex=' ';
101
	useron.prot=cfg.new_prot;
102
	SAFECOPY(useron.comp,client_name);	/* hostname or CID name */
deuce's avatar
deuce committed
103 104
	SAFECOPY(useron.ipaddr,cid);			/* IP address or CID number */
	if((i=userdatdupe(0,U_IPADDR,LEN_IPADDR,cid, /* del */true))!=0) {	/* Duplicate IP address */
105
		SAFEPRINTF2(useron.comment,"Warning: same IP address as user #%d %s"
106
			,i,username(&cfg,i,str));
107
		logline(LOG_NOTICE,"N!",useron.comment); 
108 109
	}

110 111
	SAFECOPY(useron.alias,"New");     /* just for status line */
	SAFECOPY(useron.modem,connection);
112
	if(!lastuser(&cfg)) {	/* Automatic sysop access for first user */
113 114 115
		bprintf("Creating sysop account... System password required.\r\n");
		if(!chksyspass())
			return(FALSE); 
116 117 118
		useron.level=99;
		useron.exempt=useron.flags1=useron.flags2=0xffffffffUL;
		useron.flags3=useron.flags4=0xffffffffUL;
rswindell's avatar
rswindell committed
119 120
		useron.rest=0L; 
	} else {
121 122 123 124 125 126
		useron.level=cfg.new_level;
		useron.flags1=cfg.new_flags1;
		useron.flags2=cfg.new_flags2;
		useron.flags3=cfg.new_flags3;
		useron.flags4=cfg.new_flags4;
		useron.rest=cfg.new_rest;
rswindell's avatar
rswindell committed
127 128
		useron.exempt=cfg.new_exempt; 
	}
129 130 131 132 133 134

	useron.cdt=cfg.new_cdt;
	useron.min=cfg.new_min;
	useron.freecdt=cfg.level_freecdtperday[useron.level];

	if(cfg.total_fcomps)
135
		SAFECOPY(useron.tmpext,cfg.fcomp[0]->ext);
136
	else
137
		SAFECOPY(useron.tmpext,"ZIP");
138 139 140 141

	useron.shell=cfg.new_shell;

	useron.alias[0]=0;
142

143
	kmode=(cfg.uq&UQ_NOEXASC)|K_EDIT|K_AUTODEL|K_TRIM;
144 145 146
	if(!(cfg.uq&UQ_NOUPRLWR))
		kmode|=K_UPRLWR;

147
	while(online) {
148

149
		if(autoterm || (text[AutoTerminalQ][0] && yesno(text[AutoTerminalQ]))) {
150 151 152 153 154 155
			useron.misc|=AUTOTERM;
			useron.misc|=autoterm; 
		} else
			useron.misc&=~AUTOTERM;

		if(!(useron.misc&AUTOTERM)) {
156
			if(text[AnsiTerminalQ][0] && yesno(text[AnsiTerminalQ]))
157 158 159 160 161 162 163
				useron.misc|=ANSI; 
			else
				useron.misc&=~ANSI;
		}

		if(useron.misc&ANSI) {
			useron.rows=0;	/* Auto-rows */
164
			if(!(cfg.uq&UQ_COLORTERM) || useron.misc&(RIP|WIP|HTML) || yesno(text[ColorTerminalQ]))
165 166 167 168 169
				useron.misc|=COLOR; 
			else
				useron.misc&=~COLOR;
		}
		else
170 171 172 173
			useron.rows = TERM_ROWS_DEFAULT;

		while(text[HitYourBackspaceKey][0] && !(useron.misc&(PETSCII|SWAP_DELETE)) && online) {
			bputs(text[HitYourBackspaceKey]);
174
			uchar key = getkey(K_NONE);
175 176 177 178 179 180 181 182
			bprintf(text[CharacterReceivedFmt], key, key);
			if(key == '\b')
				break;
			if(key == DEL) {
				if(text[SwapDeleteKeyQ][0] == 0 || yesno(text[SwapDeleteKeyQ]))
					useron.misc |= SWAP_DELETE;
			}
			else if(key == PETSCII_DELETE)
rswindell's avatar
rswindell committed
183
				useron.misc |= (AUTOTERM|PETSCII|COLOR);
184 185 186 187 188 189 190
			else {
				bprintf(text[InvalidBackspaceKeyFmt], key, key);
				if(text[ContinueQ][0] && !yesno(text[ContinueQ]))
					return FALSE;
			}
		}

191 192 193
		if(useron.misc&PETSCII) {
			autoterm |= PETSCII;
			outcom(PETSCII_UPPERLOWER);
rswindell's avatar
rswindell committed
194
			bputs(text[PetTerminalDetected]);
195
		} else {
196 197 198 199 200
			if(!yesno(text[ExAsciiTerminalQ]))
				useron.misc|=NO_EXASCII;
			else
				useron.misc&=~NO_EXASCII;
		}
201

202
		if(rlogin_name[0])
203 204 205 206 207 208 209 210 211
			SAFECOPY(useron.alias,rlogin_name);

		while(online) {
			if(cfg.uq&UQ_ALIASES)
				bputs(text[EnterYourAlias]);
			else
				bputs(text[EnterYourRealName]);
			getstr(useron.alias,LEN_ALIAS,kmode);
			truncsp(useron.alias);
212
			if (!check_name(&cfg,useron.alias)
213 214
				|| (!(cfg.uq&UQ_ALIASES) && !strchr(useron.alias,' '))) {
				bputs(text[YouCantUseThatName]);
215
				if(text[ContinueQ][0] && !yesno(text[ContinueQ]))
216
					return(FALSE);
217
				continue;
rswindell's avatar
rswindell committed
218
			}
219
			break; 
220
		}
rswindell's avatar
rswindell committed
221
		if(!online) return(FALSE);
222
		if((cfg.uq&UQ_ALIASES) && (cfg.uq&UQ_REALNAME)) {
223 224
			while(online) {
				bputs(text[EnterYourRealName]);
225 226
				getstr(useron.name,LEN_NAME,kmode);
				if (!check_name(&cfg,useron.name)
227
					|| !strchr(useron.name,' ')
228
					|| ((cfg.uq&UQ_DUPREAL)
229
						&& userdatdupe(useron.number,U_NAME,LEN_NAME,useron.name)))
230 231
					bputs(text[YouCantUseThatName]);
				else
rswindell's avatar
rswindell committed
232
					break; 
233
				if(text[ContinueQ][0] && !yesno(text[ContinueQ]))
234
					return(FALSE);
rswindell's avatar
rswindell committed
235 236
			} 
		}
237 238
		else if(cfg.uq&UQ_COMPANY) {
				bputs(text[EnterYourCompany]);
rswindell's avatar
rswindell committed
239 240
				getstr(useron.name,LEN_NAME,(cfg.uq&UQ_NOEXASC)|K_EDIT|K_AUTODEL); 
		}
241
		if(!useron.name[0])
242
			SAFECOPY(useron.name,useron.alias);
rswindell's avatar
rswindell committed
243
		if(!online) return(FALSE);
244
		if(!useron.handle[0])
245
			SAFECOPY(useron.handle,useron.alias);
246
		while((cfg.uq&UQ_HANDLE) && online) {
247 248 249 250
			bputs(text[EnterYourHandle]);
			if(!getstr(useron.handle,LEN_HANDLE
				,K_LINE|K_EDIT|K_AUTODEL|(cfg.uq&UQ_NOEXASC))
				|| strchr(useron.handle,0xff)
251
				|| ((cfg.uq&UQ_DUPHAND)
252
					&& userdatdupe(0,U_HANDLE,LEN_HANDLE,useron.handle))
253
				|| trashcan(useron.handle,"name"))
254 255
				bputs(text[YouCantUseThatName]);
			else
rswindell's avatar
rswindell committed
256
				break; 
257
			if(text[ContinueQ][0] && !yesno(text[ContinueQ]))
258
				return(FALSE);
rswindell's avatar
rswindell committed
259 260
		}
		if(!online) return(FALSE);
261 262 263
		if(cfg.uq&UQ_ADDRESS)
			while(online) { 	   /* Get address and zip code */
				bputs(text[EnterYourAddress]);
264
				if(getstr(useron.address,LEN_ADDRESS,kmode))
rswindell's avatar
rswindell committed
265 266 267
					break; 
			}
		if(!online) return(FALSE);
268
		while((cfg.uq&UQ_LOCATION) && online) {
269
			bputs(text[EnterYourCityState]);
270
			if(getstr(useron.location,LEN_LOCATION,kmode)
271
				&& ((cfg.uq&UQ_NOCOMMAS) || strchr(useron.location,',')))
272
				break;
273
			bputs(text[CommaInLocationRequired]);
rswindell's avatar
rswindell committed
274 275
			useron.location[0]=0; 
		}
276 277 278 279 280
		if(cfg.uq&UQ_ADDRESS)
			while(online) {
				bputs(text[EnterYourZipCode]);
				if(getstr(useron.zipcode,LEN_ZIPCODE
					,K_UPPER|(cfg.uq&UQ_NOEXASC)|K_EDIT|K_AUTODEL))
rswindell's avatar
rswindell committed
281 282 283
					break; 
			}
		if(!online) return(FALSE);
284
		if(cfg.uq&UQ_PHONE) {
285 286 287 288 289
			if(text[CallingFromNorthAmericaQ][0])
				usa=yesno(text[CallingFromNorthAmericaQ]);
			else
				usa=false;
			while(online && text[EnterYourPhoneNumber][0]) {
290 291 292 293
				bputs(text[EnterYourPhoneNumber]);
				if(!usa) {
					if(getstr(useron.phone,LEN_PHONE
						,K_UPPER|K_LINE|(cfg.uq&UQ_NOEXASC)|K_EDIT|K_AUTODEL)<5)
rswindell's avatar
rswindell committed
294 295
						continue; 
				}
296 297 298
				else {
					if(gettmplt(useron.phone,cfg.sys_phonefmt
						,K_LINE|(cfg.uq&UQ_NOEXASC)|K_EDIT)<strlen(cfg.sys_phonefmt))
rswindell's avatar
rswindell committed
299 300
						continue; 
				}
301
				if(!trashcan(useron.phone,"phone"))
rswindell's avatar
rswindell committed
302 303 304 305
					break; 
			} 
		}
		if(!online) return(FALSE);
306 307
		if(cfg.uq&UQ_SEX) {
			bputs(text[EnterYourSex]);
rswindell's avatar
rswindell committed
308 309
			useron.sex=(char)getkeys("MF",0); 
		}
310
		while((cfg.uq&UQ_BIRTH) && online) {
311 312
			bprintf(text[EnterYourBirthday]
				,cfg.sys_misc&SM_EURODATE ? "DD/MM/YY" : "MM/DD/YY");
313
			if(gettmplt(useron.birth,"nn/nn/nn",K_EDIT)==8 && getage(&cfg,useron.birth))
rswindell's avatar
rswindell committed
314 315 316
				break; 
		}
		if(!online) return(FALSE);
317
		while(!(cfg.uq&UQ_NONETMAIL) && online) {
318 319 320 321 322
			bputs(text[EnterNetMailAddress]);
			if(getstr(useron.netmail,LEN_NETMAIL,K_EDIT|K_AUTODEL|K_LINE)
				&& !trashcan(useron.netmail,"email"))
				break;
		}
323
		if(useron.netmail[0] && cfg.sys_misc&SM_FWDTONET && text[ForwardMailQ][0] && yesno(text[ForwardMailQ]))
324 325 326
			useron.misc|=NETMAIL;
		else 
			useron.misc&=~NETMAIL;
327
		if(text[UserInfoCorrectQ][0]==0 || yesno(text[UserInfoCorrectQ]))
rswindell's avatar
rswindell committed
328 329 330
			break; 
	}
	if(!online) return(FALSE);
331
	SAFEPRINTF(str,"New user: %s",useron.alias);
332
	logline("N",str);
rswindell's avatar
rswindell committed
333
	if(!online) return(FALSE);
334 335 336
	menu("../sbbs", P_NOABORT|P_NOERROR);
	menu("../system", P_NOABORT|P_NOERROR);
	menu("../newuser", P_NOABORT|P_NOERROR);
337 338
	answertime=time(NULL);		/* could take 10 minutes to get this far */

339 340
	/* Default editor (moved here, after terminal type setup Jan-2003) */
	for(i=0;i<cfg.total_xedits;i++)
rswindell's avatar
rswindell committed
341
		if(!stricmp(cfg.xedit[i]->code,cfg.new_xedit) && chk_ar(cfg.xedit[i]->ar,&useron,&client))
342 343 344 345
			break;
	if(i<cfg.total_xedits)
		useron.xedit=i+1;

346
	if(cfg.total_xedits && (cfg.uq&UQ_XEDIT) && text[UseExternalEditorQ][0]) {
347
		if(yesno(text[UseExternalEditorQ])) {
348
			for(i=0;i<cfg.total_xedits;i++)
349
				uselect(1,i,text[ExternalEditorHeading],cfg.xedit[i]->name,cfg.xedit[i]->ar);
350 351 352 353
			if((int)(i=uselect(0,useron.xedit ? useron.xedit-1 : 0,0,0,0))>=0)
				useron.xedit=i+1; 
		} else
			useron.xedit=0;
rswindell's avatar
rswindell committed
354
	}
355

356
	if(cfg.total_shells>1 && (cfg.uq&UQ_CMDSHELL)) {
357
		for(i=0;i<cfg.total_shells;i++)
358
			uselect(1,i,text[CommandShellHeading],cfg.shell[i]->name,cfg.shell[i]->ar);
359
		if((int)(i=uselect(0,useron.shell,0,0,0))>=0)
rswindell's avatar
rswindell committed
360 361
			useron.shell=i; 
	}
362

deuce's avatar
deuce committed
363
	if(rlogin_pass[0] && chkpass(rlogin_pass,&useron,true)) {
364
		CRLF;
365
		SAFECOPY(useron.pass, rlogin_pass);
366
		strupr(useron.pass);	/* passwords are case insensitive, but assumed (in some places) to be uppercase in the user database */
367 368
	}
	else {
369
		c=0;
370 371 372 373 374 375
		while(c<LEN_PASS) { 				/* Create random password */
			useron.pass[c]=sbbs_random(43)+'0';
			if(isalnum(useron.pass[c]))
				c++; 
		}
		useron.pass[c]=0;
376

377 378
		bprintf(text[YourPasswordIs],useron.pass);

379
		if(cfg.sys_misc&SM_PWEDIT && text[NewPasswordQ][0] && yesno(text[NewPasswordQ]))
380 381 382 383 384
			while(online) {
				bputs(text[NewPassword]);
				getstr(str,LEN_PASS,K_UPPER|K_LINE);
				truncsp(str);
				if(chkpass(str,&useron,true)) {
385
					SAFECOPY(useron.pass,str);
386 387
					CRLF;
					bprintf(text[YourPasswordIs],useron.pass);
rswindell's avatar
rswindell committed
388 389 390 391
					break; 
				}
				CRLF; 
			}
392 393

		c=0;
394
		while(online) {
395
			bputs(text[NewUserPasswordVerify]);
396 397
			console|=CON_R_ECHOX;
			str[0]=0;
398
			getstr(str,LEN_PASS*2,K_UPPER);
399 400
			console&=~(CON_R_ECHOX|CON_L_ECHOX);
			if(!strcmp(str,useron.pass)) break;
401
			if(cfg.sys_misc&SM_ECHO_PW) 
402
				SAFEPRINTF2(tmp,"FAILED Password verification: '%s' instead of '%s'"
403
					,str
404 405
					,useron.pass);
			else
406
				SAFECOPY(tmp,"FAILED Password verification");
407
			logline(LOG_NOTICE,nulstr,tmp);
408
			if(++c==4) {
409
				logline(LOG_NOTICE,"N!","Couldn't figure out password.");
rswindell's avatar
rswindell committed
410 411
				hangup(); 
			}
412
			bputs(text[IncorrectPassword]);
rswindell's avatar
rswindell committed
413 414
			bprintf(text[YourPasswordIs],useron.pass); 
		}
415
	}
416

rswindell's avatar
rswindell committed
417
	if(!online) return(FALSE);
418 419 420 421 422 423
	if(cfg.new_magic[0]) {
		bputs(text[MagicWordPrompt]);
		str[0]=0;
		getstr(str,50,K_UPPER);
		if(strcmp(str,cfg.new_magic)) {
			bputs(text[FailedMagicWord]);
424
			SAFEPRINTF(tmp,"failed magic word: '%s'",str);
425
			logline("N!",tmp);
rswindell's avatar
rswindell committed
426 427 428 429
			hangup(); 
		}
		if(!online) return(FALSE); 
	}
430 431 432

	bputs(text[CheckingSlots]);

433
	if((i=newuserdat(&cfg,&useron))!=0) {
434
		SAFEPRINTF(str,"user record #%u",useron.number);
435 436
		errormsg(WHERE,ERR_CREATE,str,i);
		hangup();
rswindell's avatar
rswindell committed
437
		return(FALSE); 
438
	}
439
	SAFEPRINTF2(str,"Created user record #%u: %s",useron.number,useron.alias);
440
	logline(nulstr,str);
441
	if(cfg.new_sif[0]) {
442
		SAFEPRINTF2(str,"%suser/%4.4u.dat",cfg.data_dir,useron.number);
rswindell's avatar
rswindell committed
443 444
		create_sif_dat(cfg.new_sif,str); 
	}
445 446 447
	if(!(cfg.uq&UQ_NODEF))
		maindflts(&useron);

448
	delallmail(useron.number, MAIL_ANY);
449 450

	if(useron.number!=1 && cfg.node_valuser) {
451
		menu("../feedback", P_NOABORT|P_NOERROR);
452
		safe_snprintf(str,sizeof(str),text[NewUserFeedbackHdr]
453 454
			,nulstr,getage(&cfg,useron.birth),useron.sex,useron.birth
			,useron.name,useron.phone,useron.comp,useron.modem);
455
		email(cfg.node_valuser,str,"New User Validation",WM_SUBJ_RO|WM_FORCEFWD);
456 457 458
		if(!useron.fbacks && !useron.emails) {
			if(online) {						/* didn't hang up */
				bprintf(text[NoFeedbackWarning],username(&cfg,cfg.node_valuser,tmp));
459
				email(cfg.node_valuser,str,"New User Validation",WM_SUBJ_RO|WM_FORCEFWD);
460 461 462
				} /* give 'em a 2nd try */
			if(!useron.fbacks && !useron.emails) {
        		bprintf(text[NoFeedbackWarning],username(&cfg,cfg.node_valuser,tmp));
463
				logline(LOG_NOTICE,"N!","Aborted feedback");
464 465 466 467
				hangup();
				putuserrec(&cfg,useron.number,U_COMMENT,60,"Didn't leave feedback");
				putuserrec(&cfg,useron.number,U_MISC,8
					,ultoa(useron.misc|DELETED,tmp,16));
468
				putusername(&cfg,useron.number,nulstr);
rswindell's avatar
rswindell committed
469
				return(FALSE); 
470 471 472
			} 
		} 
	}
473 474

	answertime=starttime=time(NULL);	  /* set answertime to now */
475

476 477 478 479
#ifdef JAVASCRIPT
	js_create_user_objects();
#endif

480 481 482 483 484 485
	if(cfg.newuser_mod[0])
		exec_bin(cfg.newuser_mod,&main_csi);
	user_event(EVENT_NEWUSER);
	getuserdat(&cfg,&useron);	// In case event(s) modified user data
	logline("N+","Successful new user logon");
	sys_status|=SS_NEWUSER;
rswindell's avatar
rswindell committed
486 487

	return(TRUE);
488
}