upload.cpp 18.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
/* upload.cpp */

/* Synchronet file upload-related routines */

/* $Id$ */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
 * Copyright 2000 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"

/****************************************************************************/
/* Adds file data in 'f' to DIR#.DAT and DIR#.IXB   and updates user        */
/* info for uploader. Must have .name, .desc and .dir fields filled prior   */
/* to a call to this function.                                              */
/* Returns 1 if file uploaded sucessfully, 0 if not.                        */
/****************************************************************************/
bool sbbs_t::uploadfile(file_t *f)
{
48 49 50 51
	char path[256],str[256],fname[25];
	char ext[F_EXBSIZE+1];
	char desc[F_EXBSIZE+1];
	char tmp[128];
52 53 54 55 56
	int  file;
    uint i;
    long length;
	FILE *stream;

57
	// f->misc=0; Removed AUG-22-2001 - broken anonymous uploads
58 59 60 61 62 63 64 65 66
	curdirnum=f->dir;
	if(findfile(&cfg,f->dir,f->name)) {
		errormsg(WHERE,ERR_CHK,f->name,f->dir);
		return(0); }
	sprintf(path,"%s%s",f->altpath>0 && f->altpath<=cfg.altpaths
		? cfg.altpath[f->altpath-1]
		: cfg.dir[f->dir]->path,unpadfname(f->name,fname));
	if(!fexist(path)) {
		bprintf(text[FileNotReceived],f->name);
67 68 69
		sprintf(str,"%s attempted to upload %s to %s %s (Not received)"
			,useron.alias
			,f->name
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
			,cfg.lib[cfg.dir[f->dir]->lib]->sname,cfg.dir[f->dir]->sname);
		logline("U!",str);
		return(0); }
	strcpy(tmp,f->name);
	truncsp(tmp);
	for(i=0;i<cfg.total_ftests;i++)
		if(cfg.ftest[i]->ext[0]=='*' || !strcmp(tmp+9,cfg.ftest[i]->ext)) {
			if(!chk_ar(cfg.ftest[i]->ar,&useron))
				continue;
			attr(LIGHTGRAY);
			bputs(cfg.ftest[i]->workstr);

			sprintf(sbbsfilename,"SBBSFILENAME=%.12s",unpadfname(f->name,fname));
			putenv(sbbsfilename);
			sprintf(sbbsfiledesc,"SBBSFILEDESC=%.*s",LEN_FDESC,f->desc);
			putenv(sbbsfiledesc);
			sprintf(str,"%sSBBSFILE.NAM",cfg.node_dir);
			if((stream=fopen(str,"w"))!=NULL) {
				fwrite(fname,1,strlen(fname),stream);
				fclose(stream); }
			sprintf(str,"%sSBBSFILE.DES",cfg.node_dir);
			if((stream=fopen(str,"w"))!=NULL) {
				fwrite(f->desc,1,strlen(f->desc),stream);
				fclose(stream); }
			if(external(cmdstr(cfg.ftest[i]->cmd,path,f->desc,NULL),0)) { /* EX_OUTL */
				bprintf(text[FileHadErrors],f->name,cfg.ftest[i]->ext);
				if(SYSOP) {
					if(!yesno(text[DeleteFileQ])) return(0); }
				remove(path);
99 100 101
				sprintf(str,"%s attempted to upload %s to %s %s (%s Errors)"
					,useron.alias
					,f->name
102 103 104 105
					,cfg.lib[cfg.dir[f->dir]->lib]->sname,cfg.dir[f->dir]->sname,cfg.ftest[i]->ext);
				logline("U!",str);
				return(0); }
			else {
106
				sprintf(str,"%ssbbsfile.nam",cfg.node_dir);
107 108 109 110 111 112 113 114 115 116 117 118
				if((stream=fopen(str,"r"))!=NULL) {
					if(fgets(str,128,stream)) {
						truncsp(str);
						strupr(str);
						padfname(str,f->name);
						strcpy(tmp,f->name);
						truncsp(tmp);
						sprintf(path,"%s%s",f->altpath>0 && f->altpath<=cfg.altpaths
							? cfg.altpath[f->altpath-1] : cfg.dir[f->dir]->path
							,unpadfname(f->name,fname)); }
					fclose(stream);
					}
119
				sprintf(str,"%ssbbsfile.des",cfg.node_dir);
120 121 122 123 124 125 126 127 128 129
				if((stream=fopen(str,"r"))!=NULL) {
					if(fgets(str,128,stream)) {
						truncsp(str);
						sprintf(f->desc,"%.*s",LEN_FDESC,str); }
					fclose(stream); }
				CRLF; } }

	if((length=flength(path))<=0L) {
		bprintf(text[FileZeroLength],f->name);
		remove(path);
130 131 132
		sprintf(str,"%s attempted to upload %s to %s %s (Zero length)"
			,useron.alias
			,f->name
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
			,cfg.lib[cfg.dir[f->dir]->lib]->sname,cfg.dir[f->dir]->sname);
		logline("U!",str);
		return(0); }
	if(cfg.dir[f->dir]->misc&DIR_DIZ) {
		for(i=0;i<cfg.total_fextrs;i++)
			if(!stricmp(cfg.fextr[i]->ext,tmp+9) && chk_ar(cfg.fextr[i]->ar,&useron))
				break;
		if(i<cfg.total_fextrs) {
			sprintf(str,"%sFILE_ID.DIZ",cfg.temp_dir);
			remove(str);
			external(cmdstr(cfg.fextr[i]->cmd,path,"FILE_ID.DIZ",NULL),EX_OUTL);
			if(!fexist(str)) {
				sprintf(str,"%sDESC.SDI",cfg.temp_dir);
				remove(str);
				external(cmdstr(cfg.fextr[i]->cmd,path,"DESC.SDI",NULL),EX_OUTL); }
			if((file=nopen(str,O_RDONLY))!=-1) {
149 150 151
				memset(ext,0,F_EXBSIZE+1);
				read(file,ext,F_EXBSIZE);
				for(i=F_EXBSIZE;i;i--)
152 153 154 155 156 157
					if(ext[i-1]>SP)
						break;
				ext[i]=0;
				if(!f->desc[0]) {
					strcpy(desc,ext);
					strip_exascii(desc);
158
					prep_file_desc(desc);
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
					for(i=0;desc[i];i++)
						if(isalnum(desc[i]))
							break;
					sprintf(f->desc,"%.*s",LEN_FDESC,desc+i); }
				close(file);
				remove(str);
				f->misc|=FM_EXTDESC; } } }

	logon_ulb+=length;  /* Update 'this call' stats */
	logon_uls++;
	if(cfg.dir[f->dir]->misc&DIR_AONLY)  /* Forced anonymous */
		f->misc|=FM_ANON;
	f->cdt=length;
	f->dateuled=time(NULL);
	f->timesdled=0;
	f->datedled=0L;
	f->opencount=0;
	strcpy(f->uler,useron.alias);
	bprintf(text[FileNBytesReceived],f->name,ultoac(length,tmp));
	if(!f->desc[0])
		sprintf(f->desc,"%.*s",LEN_FDESC,text[NoDescription]);
	if(!addfiledat(&cfg,f))
		return(0);

	if(f->misc&FM_EXTDESC)
184
		putextdesc(&cfg,f->dir,f->datoffset,ext);
185

186 187 188
	sprintf(str,"%s uploaded %s to %s %s"
		,useron.alias
		,f->name,cfg.lib[cfg.dir[f->dir]->lib]->sname
189 190
		,cfg.dir[f->dir]->sname);
	if(cfg.dir[f->dir]->upload_sem[0])
191 192
		if((file=nopen(cmdstr(cfg.dir[f->dir]->upload_sem,nulstr,nulstr,NULL)
			,O_WRONLY|O_CREAT|O_TRUNC))!=-1)
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
			close(file);
	logline("U+",str);
	/**************************/
	/* Update Uploader's Info */
	/**************************/
	useron.uls=(ushort)adjustuserrec(&cfg,useron.number,U_ULS,5,1);
	useron.ulb=(ushort)adjustuserrec(&cfg,useron.number,U_ULB,10,length);
	if(cfg.dir[f->dir]->up_pct && cfg.dir[f->dir]->misc&DIR_CDTUL) { /* credit for upload */
		if(cfg.dir[f->dir]->misc&DIR_CDTMIN && cur_cps)    /* Give min instead of cdt */
			useron.min=adjustuserrec(&cfg,useron.number,U_MIN,10
				,((ulong)(length*(cfg.dir[f->dir]->up_pct/100.0))/cur_cps)/60);
		else
			useron.cdt=adjustuserrec(&cfg,useron.number,U_CDT,10
				,(ulong)(f->cdt*(cfg.dir[f->dir]->up_pct/100.0))); }

	return(true);
}


/****************************************************************************/
/* Update the upload date for the file 'f'                                  */
/****************************************************************************/
void sbbs_t::update_uldate(file_t* f)
{
	char str[256],fname[13];
	int i,file;
	long l,length;

	/*******************/
	/* Update IXB File */
	/*******************/
224
	sprintf(str,"%s%s.ixb",cfg.dir[f->dir]->data_dir,cfg.dir[f->dir]->code);
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
	if((file=nopen(str,O_RDWR))==-1) {
		errormsg(WHERE,ERR_OPEN,str,O_RDWR);
		return; }
	length=filelength(file);
	if(length%F_IXBSIZE) {
		close(file);
		errormsg(WHERE,ERR_LEN,str,length);
		return; }
	strcpy(fname,f->name);
	for(i=8;i<12;i++)   /* Turn FILENAME.EXT into FILENAMEEXT */
		fname[i]=fname[i+1];
	for(l=0;l<length;l+=F_IXBSIZE) {
		read(file,str,F_IXBSIZE);      /* Look for the filename in the IXB file */
		str[11]=0;
		if(!strcmp(fname,str)) break; }
	if(l>=length) {
		close(file);
		errormsg(WHERE,ERR_CHK,f->name,length);
		return; }
	lseek(file,l+14,SEEK_SET);
	write(file,&f->dateuled,4);
	close(file);

	/*******************************************/
	/* Update last upload date/time stamp file */
	/*******************************************/
251
	sprintf(str,"%s%s.dab",cfg.dir[f->dir]->data_dir,cfg.dir[f->dir]->code);
252 253 254 255 256 257 258 259 260 261 262
	if((file=nopen(str,O_WRONLY|O_CREAT))==-1)
		errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT);
	else {
		write(file,&f->dateuled,4);
		close(file); 
	}
}

/****************************************************************************/
/* Uploads files                                                            */
/****************************************************************************/
263
bool sbbs_t::upload(uint dirnum)
264 265 266
{
	char	str[256],src[256]={""},descbeg[25]={""},descend[25]={""},path[256]
				,fname[13],keys[256],ch,*p;
267
	char 	tmp[512];
268 269 270 271 272 273 274 275
    time_t	start,end;
    uint	i,j,k,destuser[MAX_USERXFER],destusers=0;
	int		file;
	ulong	space;
    file_t	f;
    user_t	user;
    node_t	node;

276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
	/* Security Checks */
	if(useron.rest&FLAG('U')) {
		bputs(text[R_Upload]);
		return(false); 
	}
	if(dirnum==INVALID_DIR) {
		bputs(text[CantUploadHere]);
		return(false);
	}
	if(!chk_ar(cfg.dir[dirnum]->ul_ar,&useron)) {
		bputs(dirnum==cfg.user_dir ? text[CantUploadToUser] : 
			dirnum==cfg.sysop_dir ? text[CantUploadToSysop] : text[CantUploadHere]);
		return(false); 
	}
	if(getfiles(&cfg,dirnum)>=cfg.dir[dirnum]->maxfiles) {
		bputs(dirnum==cfg.user_dir ? text[UserDirFull] : text[DirFull]);
		return(false);
	}

295 296 297 298 299 300 301 302 303 304 305 306
	if(sys_status&SS_EVENT && online==ON_REMOTE && !dir_op(dirnum))
		bprintf(text[UploadBeforeEvent],timeleft/60);
	if(altul)
		strcpy(path,cfg.altpath[altul-1]);
	else
		strcpy(path,cfg.dir[dirnum]->path);


	/* get free disk space */
	space=getfreediskspace(path);
	if(space<(ulong)cfg.min_dspace*1024L) {
		bputs(text[LowDiskSpace]);
307
		sprintf(str,"Diskspace is low: %s (%lu bytes)",path,space);
308 309
		errorlog(str);
		if(!dir_op(dirnum))
310 311
			return(false); 
	}
312 313 314 315 316 317 318
	bprintf(text[DiskNBytesFree],ultoac(space,tmp));

	f.dir=curdirnum=dirnum;
	f.misc=0;
	f.altpath=altul;
	bputs(text[Filename]);
	if(!getstr(fname,12,K_UPPER) || strchr(fname,'?') || strchr(fname,'*')
319
		|| !checkfname(fname) || (trashcan(fname,"file") && !dir_op(dirnum))) {
320 321
		if(fname[0])
			bputs(text[BadFilename]);
322 323
		return(false); 
	}
324 325 326 327 328 329 330
	if(dirnum==cfg.sysop_dir)
		sprintf(str,text[UploadToSysopDirQ],fname);
	else if(dirnum==cfg.user_dir)
		sprintf(str,text[UploadToUserDirQ],fname);
	else
		sprintf(str,text[UploadToCurDirQ],fname,cfg.lib[cfg.dir[dirnum]->lib]->sname
			,cfg.dir[dirnum]->sname);
331
	if(!yesno(str)) return(false);
332 333 334 335 336 337
	action=NODE_ULNG;
	padfname(fname,f.name);
	sprintf(str,"%s%s",path,fname);
	if(fexist(str)) {   /* File is on disk */
		if(!dir_op(dirnum) && online!=ON_LOCAL) {		 /* local users or sysops */
			bprintf(text[FileAlreadyThere],fname);
338
			return(false); }
339
		if(!yesno(text[FileOnDiskAddQ]))
340
			return(false); }
341 342 343 344
	else if(online==ON_LOCAL) {
		bputs(text[FileNotOnDisk]);
		bputs(text[EnterPath]);
		if(!getstr(tmp,60,K_LINE|K_UPPER))
345
			return(false);
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
		backslash(tmp);
		sprintf(src,"%s%s",tmp,fname); }
	strcpy(str,cfg.dir[dirnum]->exts);
	strcpy(tmp,f.name);
	truncsp(tmp);
	j=strlen(str);
	for(i=0;i<j;i+=ch+1) { /* Check extension of upload with allowable exts */
		p=strchr(str+i,',');
		if(p!=NULL)
			*p=0;
		ch=strlen(str+i);
		if(!strcmp(tmp+9,str+i))
			break; }
	if(j && i>=j) {
		bputs(text[TheseFileExtsOnly]);
		bputs(cfg.dir[dirnum]->exts);
		CRLF;
363
		if(!dir_op(dirnum)) return(false); }
364 365 366 367 368 369 370 371 372 373 374
	bputs(text[SearchingForDupes]);
	for(i=k=0;i<usrlibs;i++)
		for(j=0;j<usrdirs[i];j++,k++) {
			outchar('.');
			if(k && !(k%5))
				bputs("\b\b\b\b\b     \b\b\b\b\b");
			if((usrdir[i][j]==dirnum || cfg.dir[usrdir[i][j]]->misc&DIR_DUPES)
				&& findfile(&cfg,usrdir[i][j],f.name)) {
				bputs(text[SearchedForDupes]);
				bprintf(text[FileAlreadyOnline],f.name);
				if(!dir_op(dirnum))
375
					return(false); 	 /* File is in database for another dir */
376
				if(usrdir[i][j]==dirnum)
377
					return(false); } } /* don't allow duplicates */
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
	bputs(text[SearchedForDupes]);
	if(dirnum==cfg.user_dir) {  /* User to User transfer */
		bputs(text[EnterAfterLastDestUser]);
		while((!dir_op(dirnum) && destusers<cfg.max_userxfer) || destusers<MAX_USERXFER) {
			bputs(text[SendFileToUser]);
			if(!getstr(str,LEN_ALIAS,K_UPRLWR))
				break;
			if((user.number=finduser(str))!=0) {
				if(!dir_op(dirnum) && user.number==useron.number) {
					bputs(text[CantSendYourselfFiles]);
					continue; }
				for(i=0;i<destusers;i++)
					if(user.number==destuser[i])
						break;
				if(i<destusers) {
					bputs(text[DuplicateUser]);
					continue; }
				getuserdat(&cfg,&user);
				if((user.rest&(FLAG('T')|FLAG('D')))
					|| !chk_ar(cfg.lib[cfg.dir[cfg.user_dir]->lib]->ar,&user)
					|| !chk_ar(cfg.dir[cfg.user_dir]->dl_ar,&user)) {
					bprintf(text[UserWontBeAbleToDl],user.alias); }
				else {
					bprintf(text[UserAddedToDestList],user.alias);
					destuser[destusers++]=user.number; } }
			else {
				CRLF; } }
		if(!destusers)
406
			return(false); }
407 408 409 410 411
	if(cfg.dir[dirnum]->misc&DIR_RATE) {
		SYNC;
		bputs(text[RateThisFile]);
		ch=getkey(K_ALPHA);
		if(!isalpha(ch) || sys_status&SS_ABORT)
412
			return(false);
413 414 415 416 417 418 419 420 421 422 423 424
		CRLF;
		sprintf(descbeg,text[Rated],toupper(ch)); }
	if(cfg.dir[dirnum]->misc&DIR_ULDATE) {
		now=time(NULL);
		if(descbeg[0])
			strcat(descbeg," ");
		sprintf(str,"%s  ",unixtodstr(&cfg,now,tmp));
		strcat(descbeg,str); }
	if(cfg.dir[dirnum]->misc&DIR_MULT) {
		SYNC;
		if(!noyes(text[MultipleDiskQ])) {
			bputs(text[HowManyDisksTotal]);
425
			if((int)(i=getnum(99))<2)
426
				return(false);
427
			bputs(text[NumberOfFile]);
428
			if((int)(j=getnum(i))<1)
429
				return(false);
430 431 432 433 434 435 436 437 438 439 440 441 442 443
			if(j==1)
				upload_lastdesc[0]=0;
			if(i>9)
				sprintf(descend,text[FileOneOfTen],j,i);
			else
				sprintf(descend,text[FileOneOfTwo],j,i); }
		else
			upload_lastdesc[0]=0; }
	else
		upload_lastdesc[0]=0;
	bputs(text[EnterDescNow]);
	i=LEN_FDESC-(strlen(descbeg)+strlen(descend));
	getstr(upload_lastdesc,i,K_LINE|K_EDIT|K_AUTODEL);
	if(sys_status&SS_ABORT)
444
		return(false);
445 446 447 448 449 450 451 452 453 454 455 456 457
	if(descend[0])      /* end of desc specified, so pad desc with spaces */
		sprintf(f.desc,"%s%-*s%s",descbeg,i,upload_lastdesc,descend);
	else                /* no end specified, so string ends at desc end */
		sprintf(f.desc,"%s%s",descbeg,upload_lastdesc);

	if(cfg.dir[dirnum]->misc&DIR_ANON && !(cfg.dir[dirnum]->misc&DIR_AONLY)
		&& (dir_op(dirnum) || useron.exempt&FLAG('A'))) {
		if(!noyes(text[AnonymousQ]))
			f.misc|=FM_ANON; }
	sprintf(str,"%s%s",path,fname);
	if(src[0]) {    /* being copied from another local dir */
		bprintf(text[RetrievingFile],fname);
		if(mv(src,str,1))
458
			return(false);
459 460 461
		CRLF; }
	if(fexist(str)) {   /* File is on disk */
		if(!uploadfile(&f))
462
			return(false); }
463
	else {
464
		menu("ulprot");
465 466 467 468 469 470 471 472 473 474 475 476 477
		SYNC;
		strcpy(keys,"Q");
		if(dirnum==cfg.user_dir || !cfg.max_batup)  /* no batch user to user xfers */
			mnemonics(text[ProtocolOrQuit]);
		else {
			mnemonics(text[ProtocolBatchOrQuit]);
			strcat(keys,"B"); }
		for(i=0;i<cfg.total_prots;i++)
			if(cfg.prot[i]->ulcmd[0] && chk_ar(cfg.prot[i]->ar,&useron)) {
				sprintf(tmp,"%c",cfg.prot[i]->mnemonic);
				strcat(keys,tmp); }
		ch=(char)getkeys(keys,0);
		if(ch=='Q')
478
			return(false);
479 480 481 482 483 484 485
		if(ch=='B') {
			if(batup_total>=cfg.max_batup)
				bputs(text[BatchUlQueueIsFull]);
			else {
				for(i=0;i<batup_total;i++)
					if(!strcmp(batup_name[i],f.name)) {
						bprintf(text[FileAlreadyInQueue],f.name);
486
						return(false); }
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
				strcpy(batup_name[batup_total],f.name);
				strcpy(batup_desc[batup_total],f.desc);
				batup_dir[batup_total]=dirnum;
				batup_misc[batup_total]=f.misc;
				batup_alt[batup_total]=altul;
				batup_total++;
				bprintf(text[FileAddedToUlQueue]
					,f.name,batup_total,cfg.max_batup); } }
		else {
			for(i=0;i<cfg.total_prots;i++)
				if(cfg.prot[i]->ulcmd[0] && cfg.prot[i]->mnemonic==ch
					&& chk_ar(cfg.prot[i]->ar,&useron))
					break;
			if(i<cfg.total_prots) {
				start=time(NULL);
rswindell's avatar
rswindell committed
502
				protocol(cmdstr(cfg.prot[i]->ulcmd,str,nulstr,NULL),true);
503 504 505 506 507 508
				end=time(NULL);
				if(!(cfg.dir[dirnum]->misc&DIR_ULTIME)) /* Don't deduct upload time */
					starttime+=end-start;
				ch=uploadfile(&f);
				autohangup();
				if(!ch)  /* upload failed, don't process user to user xfer */
509
					return(false); } } }
510
	if(dirnum==cfg.user_dir) {  /* Add files to XFER.IXT in INDX dir */
511
		sprintf(str,"%sxfer.ixt",cfg.data_dir);
512 513
		if((file=nopen(str,O_WRONLY|O_CREAT|O_APPEND))==-1) {
			errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_APPEND);
514
			return(false); }
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
		for(j=0;j<destusers;j++) {
			for(i=1;i<=cfg.sys_nodes;i++) { /* Tell user, if online */
				getnodedat(i,&node,0);
				if(node.useron==destuser[j] && !(node.misc&NODE_POFF)
					&& (node.status==NODE_INUSE || node.status==NODE_QUIET)) {
					sprintf(str,text[UserToUserXferNodeMsg],cfg.node_num,useron.alias);
					putnmsg(i,str);
					break; } }
			if(i>cfg.sys_nodes) {   /* User not online */
				sprintf(str,text[UserSentYouFile],useron.alias);
				putsmsg(&cfg,destuser[j],str); }
			sprintf(str,"%4.4u %12.12s %4.4u\r\n"
				,destuser[j],f.name,useron.number);
			write(file,str,strlen(str)); }
		close(file); 
	}
531
	return(true);
532 533 534 535 536 537 538 539 540
}

/****************************************************************************/
/* Checks directory for 'dir' and prompts user to enter description for     */
/* the files that aren't in the database.                                   */
/* Returns 1 if the user aborted, 0 if not.                                 */
/****************************************************************************/
bool sbbs_t::bulkupload(uint dirnum)
{
541 542 543
    char	str[MAX_PATH+1];
	char	path[MAX_PATH+1];
	char	spath[MAX_PATH+1];
544
    file_t	f;
545 546
	DIR*	dir;
	DIRENT*	dirent;
547 548 549 550 551 552 553 554 555

	memset(&f,0,sizeof(file_t));
	f.dir=dirnum;
	f.altpath=altul;
	bprintf(text[BulkUpload],cfg.lib[cfg.dir[dirnum]->lib]->sname,cfg.dir[dirnum]->sname);
	strcpy(path,altul>0 && altul<=cfg.altpaths ? cfg.altpath[altul-1]
		: cfg.dir[dirnum]->path);
	action=NODE_ULNG;
	SYNC;
556
	dir=opendir(path);
557
	while(dir!=NULL && (dirent=readdir(dir))!=NULL && !msgabort()) {
558
		if(getfiles(&cfg,dirnum)>=cfg.dir[dirnum]->maxfiles) {
559 560
			bputs(text[DirFull]);
			break; 
561
		}
562 563 564 565 566 567 568 569 570
		sprintf(str,"%s%s",path,dirent->d_name);
		if(isdir(str))
			continue;
#ifdef _WIN32
		GetShortPathName(str,spath,sizeof(spath));
#else
		strcpy(spath,str);
#endif
		padfname(getfname(spath),str);
571

572 573 574 575 576 577 578 579 580 581 582 583 584
		if(findfile(&cfg,f.dir,str)==0) {
			strcpy(f.name,str);
			f.cdt=flength(spath);
			bprintf(text[BulkUploadDescPrompt],f.name,f.cdt);
			getstr(f.desc,LEN_FDESC,K_LINE);
			if(sys_status&SS_ABORT)
				break;
			uploadfile(&f); 
		}
	}
	closedir(dir);
	if(sys_status&SS_ABORT)
		return(true);
585 586 587
	return(false);
}