home *** CD-ROM | disk | FTP | other *** search
- #include "vars.h"
- #pragma hdrstop
-
-
- #include <dir.h>
-
- /* Uncomment the correct one for you. It will probably be __423__ for */
- /* most everyone out there for now (as of date of writting */
- // #define __423__
- #define __424__
-
-
- #define SETREC(f,i) sh_lseek(f,((long) (i))*((long)sizeof(uploadsrec)),SEEK_SET);
-
- void upload(int dn)
- {
- directoryrec d;
- uploadsrec u,u1;
- int i,i1,i2,i3,i4,ok,xfer,f, key;
- char s[255],s1[81],*ss;
- long l;
- double ti;
-
-
- listbatch();
- nl();
-
- existprint("TRY2UL");
-
- outstr("2B3) 1Batch upload <Just hit Enter>");
- nl();
- outstr("2S3) 1Single (one at a time) upload");
- nl();
- outstr("2Q3) 1Quit");
- nl();
- nl();
-
- outstr("1Your choice : ");
-
- key=onek("QB\rS"); /* <CR> and B for batch, Q to abort, S for single */
-
- switch(key)
- {
- case 'Q':
- return;
-
- case 'B':
- case '\r':
- batchdl(2);
- return;
-
- case 'S':
- dliscan1(dn);
- d=directories[dn];
- if (numf>=d.maxfiles) {
- nl();
- nl();
- pl(get_string(755));
- nl();
- return;
- }
- if ((d.mask & mask_no_uploads) && (!dcs())) {
- nl();
- nl();
- pl(get_string(756));
- nl();
- return;
- }
- nl();
- l=(long)freek1(d.path);
- sprintf(s,"%s - %ldk %s.",get_string(757), l, get_string(758));
- pl(s);
- nl();
- if (l<100) {
- pl(get_string(759));
- nl();
- return;
- }
- prt(2,get_string(44));
- input(s,12);
- if (!okfn(s))
- s[0]=0;
- #ifdef __423__ /* 423 specific */
- #ifdef OPT_FAST_SEARCH
- else {
- if (!is_uploadable(s)) {
- if (so()) {
- nl();
- prt(5,get_string(1322));
- if (!yn()) {
- s[0]=0;
- }
- } else {
- s[0]=0;
- nl();
- pl(get_string(1323));
- }
- }
- }
- #endif
- #else /* 424 specific */
- else {
- if (!is_uploadable(s)) {
- if (so()) {
- nl();
- prt(5,get_string(1322));
- if (!yn()) {
- s[0]=0;
- }
- } else {
- s[0]=0;
- nl();
- pl(get_string(1323));
- }
- }
- }
- #endif
- align(s);
- if (strchr(s,'?')) {
- return;
- }
- if (d.mask & mask_archive) {
- ok=0;
- s1[0]=0;
- for (i=0; i<4; i++) {
- if (syscfg.arcs[i].extension[0] && syscfg.arcs[i].extension[0]!=' ') {
- if (s1[0])
- strcat(s1,", ");
- strcat(s1,syscfg.arcs[i].extension);
- if (strcmp(s+9,syscfg.arcs[i].extension)==0)
- ok=1;
- }
- }
- if (!ok) {
- nl();
- pl(get_string(760));
- pl(get_string(761));
- pl(s1);
- nl();
- return;
- }
- }
- strcpy(u.filename,s);
- u.ownerusr=usernum;
- u.ownersys=0;
- u.numdloads=0;
- u.filetype=0;
- u.mask=0;
- strcpy(u.upby,nam(&thisuser,usernum));
- strcpy(u.date,date());
- nl();
- ok=1;
- xfer=1;
- if (check_batch_queue(u.filename))
- {
- ok=0;
- nl();
- pl(get_string(762));
- nl();
- }
- else
- {
- sprintf(s1,"%s '%s' %s %s? ",get_string(757), s,get_string(763),d.name);
- if (strcmp(s,get_string(1310)))
- prt(5,s1);
- else
- ok=0;
- }
- if ((ok) && (yn())) {
- sprintf(s1,"%s%s",d.path,s);
- if (exist(s1)) {
- if (dcs()) {
- xfer=0;
- nl();
- nl();
- pl(get_string(764));
- prt(5,get_string(765));
- if (yn()==0)
- ok=0;
- } else {
- nl();
- nl();
- pl(get_string(766));
- nl();
- ok=0;
- }
- } else
- if (!incom) {
- nl();
- pl(get_string(767));
- pl(get_string(768));
- nl();
- ok=0;
- }
- if ((d.mask & mask_PD) && (ok)) {
- nl();
- prt(5,get_string(769));
- if (!yn()) {
- nl();
- pl(get_string(770));
- pl(get_string(771));
- pl(get_string(772));
- pl(get_string(773));
- pl(get_string(774));
- nl();
- sprintf(s,get_stringx(1,41),u.filename);
- add_ass(5,s);
- ok=0;
- } else
- u.mask=mask_PD;
- }
- #ifdef __423__ /* 423 specific */
- #ifndef OPT_FAST_SEARCH
- if (ok) {
- nl();
- pl(get_string(775));
- nl();
- i2=0;
- for (i=0; (i<num_dirs) && (udir[i].subnum!=-1); i++) {
- strcpy(s,get_string(776));
- strcat(s,directories[udir[i].subnum].name);
- for (i3=i4=strlen(s); i3<i2; i3++) {
- s[i3]=' ';
- s[i3+1]=0;
- }
- i2=i4;
- npr("%s\r",s);
-
- dliscan1(udir[i].subnum);
- i1=recno(u.filename);
- if (i1>=0) {
- nl();
- outstr(get_string(777));
- pl(directories[udir[i].subnum].name);
- if (dcs()) {
- nl();
- prt(5,get_string(778));
- if (!yn()) {
- ok=0;
- break;
- }
- nl();
- } else {
- ok=0;
- break;
- }
- }
- }
- for (i1=0; i1<i2; i1++)
- s[i1]=' ';
- s[i1]=0;
- npr("%s\r",s);
- if (ok)
- dliscan1(dn);
- nl();
- }
- #endif
- #else /* 424 specific */
- if (ok && (!(sysinfo.flags & OP_FLAGS_FAST_SEARCH)))
- {
- nl();
- pl(get_string(775));
- nl();
- i2=0;
- for (i=0; (i<num_dirs) && (udir[i].subnum!=-1); i++) {
- strcpy(s,get_string(776));
- strcat(s,directories[udir[i].subnum].name);
- for (i3=i4=strlen(s); i3<i2; i3++) {
- s[i3]=' ';
- s[i3+1]=0;
- }
- i2=i4;
- npr("%s\r",s);
-
- dliscan1(udir[i].subnum);
- i1=recno(u.filename);
- if (i1>=0) {
- nl();
- outstr(get_string(777));
- pl(directories[udir[i].subnum].name);
- if (dcs()) {
- nl();
- prt(5,get_string(778));
- if (!yn()) {
- ok=0;
- break;
- }
- nl();
- } else {
- ok=0;
- break;
- }
- }
- }
- for (i1=0; i1<i2; i1++)
- s[i1]=' ';
- s[i1]=0;
- npr("%s\r",s);
- if (ok)
- dliscan1(dn);
- nl();
- }
- #endif /* end of 424 specific */
- if (ok) {
- nl();
- pl(get_string(779));
- outstr(": ");
- inputl(u.description,58);
- nl();
- ss=NULL;
- modify_extended_description(&ss, directories[dn].name,u.filename);
- if (ss) {
- add_extended_description(u.filename,ss);
- u.mask |= mask_extended;
- farfree(ss);
- }
- nl();
- if (xfer) {
- write_inst(INST_LOC_UPLOAD,udir[curdir].subnum,INST_FLAGS_ONLINE);
- ti=timer();
- receive_file(s1,&ok,&u.filetype, u.filename, dn);
- ti=timer()-ti;
- if (ti<0)
- ti += 24.0*3600.0;
- thisuser.extratime += ti;
- }
- if (ok) {
- if (ok==1) {
- f=sh_open1(s1,O_RDONLY | O_BINARY);
- if (f<0) {
- ok=0;
- nl();
- nl();
- pl(get_string(780));
- nl();
- if (u.mask & mask_extended)
- delete_extended_description(u.filename);
- }
- if (ok && syscfg.upload_c[0]) {
- sh_close(f);
- pl(get_string(26));
- if (check_ul_event(dn,&u)) {
- if (u.mask & mask_extended)
- delete_extended_description(u.filename);
- ok=0;
- } else {
- f=sh_open1(s1,O_RDONLY | O_BINARY);
- }
- }
- }
- if (ok) {
- if (ok==1) {
- l=filelength(f);
- u.numbytes=l;
- sh_close(f);
- ++thisuser.uploaded;
- #ifdef __423__ /* 423 specific */
- #ifdef OPT_FAST_SEARCH
- modify_database(u.filename,1);
- #endif
- #ifdef OPT_PACKSCAN_FREQ
- remotenotify(u.filename,u.description);
- #endif
- #else /* 424 specific */
- modify_database(u.filename,1);
- if (sysinfo.flags & OP_FLAGS_PACKSCAN_FREQ)
- remotenotify(u.filename,u.description);
- #endif /* end 424 specific */
-
- thisuser.uk += bytes_to_k(u.numbytes);
-
-
- get_file_idz(&u,dn);
- } else
- u.numbytes=0;
- time(&l);
- u.daten=l;
- f=sh_open(dlfn,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
- for (i=numf; i>=1; i--) {
- SETREC(f,i);
- sh_read(f,(void *)&u1,sizeof(uploadsrec));
- SETREC(f,i+1);
- sh_write(f,(void *)&u1,sizeof(uploadsrec));
- }
- SETREC(f,1);
- sh_write(f,(void *)&u,sizeof(uploadsrec));
- ++numf;
- SETREC(f,0);
- sh_read(f, &u1, sizeof(uploadsrec));
- u1.numbytes=numf;
- u1.daten=l;
- dir_dates[dn]=l;
- SETREC(f,0);
- sh_write(f,(void *)&u1,sizeof(uploadsrec));
- f=sh_close(f);
- if (ok==1) {
- lock_status();
- ++status.uptoday;
- ++status.filechange[filechange_upload];
- save_status();
- sprintf(s,get_stringx(1,42),u.filename,directories[dn].name);
- sysoplog(s);
- nl();
- nl();
- pl(get_string(781));
- nl();
- outstr(get_string(782));
- npr("%-6.3f\r\n", ratio());
- nl();
- nl();
- if (useron)
- topscreen();
- }
- }
- } else {
- nl();
- nl();
- pl(get_string(783));
- nl();
- if (u.mask & mask_extended)
- delete_extended_description(u.filename);
- }
- }
- }
- break;
- }
-
- }
-
-
- int try_to_ul(char *fn)
- {
-
- int ac=0;
- char src[201], dest[201];
-
-
- if ((uconfsub[1].confnum!=-1) && (okconf(&thisuser)))
- { ac=1; tmp_disable_conf(1); }
-
- if(!try_to_ul_wh(fn))
- {
- if(ac)
- tmp_disable_conf(0);
- return 0; /* success */
- }
-
- // see if 'try2ul' already exist off the upload dir, if not, creat it
- sprintf(dest,"%sTRY2UL", syscfg.dloadsdir);
- if(chdir(dest))
- {
- cd_to(cdir); /* get back to our bbs dir */
- mkdir(dest); /* creat the \DLOADS\TRY2UL directory */
- }
- cd_to(cdir); /* ensure we are in the correct directory */
-
-
- ansic(2);
- pl("Your file had problems, it is being moved to a special dir for sysop review");
-
-
- sprintf(src, "Failed to upload %s, moving to TRY2UL dir", fn);
- sysoplog(src);
-
-
- sprintf(src,"%s%s",syscfgovr.batchdir, fn);
- sprintf(dest,"%sTRY2UL\\%s", syscfg.dloadsdir, fn);
-
-
- if(exist(dest)) /* this is iffy <sp?/who cares>, I chooose to */
- unlink(dest); /* remove duplicates in the try2ul dir, so keep */
- /* it clean and up to date */
-
- copyfile(src, dest, 1); /* copy file from batch dir, over to try2ul dir */
-
-
- if (useron)
- topscreen();
-
-
- if(ac)
- tmp_disable_conf(0);
-
- return 1; /* return failure, removes ul k credits etc... */
- }
-
-
- int try_to_ul_wh(char *fn)
- {
- directoryrec d;
- char s[101], s1[101], s2[101], *ss;
- int i, i1, i2, i3, i4, done=0, key, ok, dn=0, f; // upload to sysop dir
- long l;
- uploadsrec u, u1;
-
-
-
- unalign(fn);
- strip_string(fn);
-
- strcpy(s, fn);
- if (!okfn(fn))
- {
- t2u_error(fn, "Bad filename"); /* bad filename */
- return(1);
- }
-
- CLS();
- nln(3);
-
- if ((thisuser.restrict & (restrict_validate | restrict_upload)) || (syscfg.sysconfig & sysconfig_all_sysop))
- {
- if (syscfg.newuploads<num_dirs)
- dn=syscfg.newuploads;
- else
- dn=0;
- }
- else
- {
- int done=0, x;
- char temp[10];
-
- while(!done) /* The hangup check is below */
- {
- if(hangup) /* right here, so uploads get uploaded even on hangup */
- {
- if (syscfg.newuploads<num_dirs)
- dn=syscfg.newuploads;
- else
- dn=0;
- done=1;
- }
- else
- {
- wait_sec_or_hit(1);
-
- nl();
- npr("Upload %s to which dir? <CR>=0 ?=List ", fn);
- nl();
-
- mpl(5);
- input(temp, 5);
-
- strip_string(temp);
-
- if(temp[0]=='?')
- dirlist();
- else if(!temp[0])
- {
- dn=0;
- done=1;
- }
- else
- {
- x=atoi(temp);
-
- if(udir[x].subnum>=0)
- {
- dliscan1(udir[x].subnum);
- d=directories[dn];
-
- if((d.mask & mask_no_uploads) && (!dcs()))
- {
- pl("Can't upload there...");
- pausescr();
- }
- else
- {
- dn=udir[x].subnum;
- done=1;
- }
- }
- }
- }
- }
- }
-
- dliscan1(dn);
- d=directories[dn];
- if (numf>=d.maxfiles)
- {
- t2u_error(fn, get_string(755));
- return 1;
- }
- if ((d.mask & mask_no_uploads) && (!dcs()))
- {
- t2u_error(fn, get_string(756));
- return 1;
- }
-
-
-
- #ifdef __423__ /* 423 specific */
- #ifdef OPT_FAST_SEARCH
- if (!is_uploadable(s))
- {
- if (so())
- {
- nl();
- prt(5,get_string(1322));
- if (!yn())
- {
- t2u_error(fn, get_string(1323));
- return 1;
- }
- }
- else
- {
- t2u_error(fn, get_string(1323));
- return 1;
- }
- }
- #endif
- #else
- if (!is_uploadable(s))
- {
- if (so())
- {
- nl();
- prt(5,get_string(1322));
- if (!yn())
- {
- t2u_error(fn, get_string(1323));
- return 1;
- }
- }
- else
- {
- t2u_error(fn, get_string(1323));
- return 1;
- }
- }
- #endif
-
- align(s);
- if (strchr(s,'?'))
- {
- t2u_error(fn, "Contains wildcards");
- return 1;
- }
- if (d.mask & mask_archive)
- {
- ok=0;
- s1[0]=0;
- for (i=0; i<4; i++)
- {
- if (syscfg.arcs[i].extension[0] && syscfg.arcs[i].extension[0]!=' ')
- {
- if (s1[0])
- strcat(s1,", ");
- strcat(s1,syscfg.arcs[i].extension);
- if (strcmp(s+9,syscfg.arcs[i].extension)==0)
- ok=1;
- }
- }
- if(!ok)
- {
- nl();
- pl(get_string(760));
- pl(get_string(761));
- pl(s1);
- nl();
-
- t2u_error(fn, "Unsupported archive");
- return 1;
- }
- }
-
-
- strcpy(u.filename,s);
- u.ownerusr=usernum;
- u.ownersys=0;
- u.numdloads=0;
- u.filetype=0;
- u.mask=0;
- strncpy(u.upby,nam(&thisuser,usernum), 44);
- u.upby[44]=0;
- strcpy(u.date,date());
-
- sprintf(s1,"%s%s",d.path,s);
- if (exist(s1))
- {
- if (dcs())
- {
- nl();
- nl();
- pl(get_string(764));
- prt(5,get_string(765));
- if (yn()==0)
- {
- t2u_error(fn, get_string(766));
- return 1;
- }
- }
- else
- {
- t2u_error(fn, get_string(766));
- return 1;
- }
- }
-
-
- #ifdef __423__ /* 423 specific */
- #ifndef OPT_FAST_SEARCH
- nl();
- pl(get_string(775));
- nl();
- i2=0;
-
- for (i=0; (i<num_dirs) && (udir[i].subnum!=-1); i++)
- {
- strcpy(s1,get_string(776));
- strcat(s1,directories[udir[i].subnum].name);
-
- for (i3=i4=strlen(s1); i3<i2; i3++)
- {
- s1[i3]=' ';
- s1[i3+1]=0;
- }
-
- i2=i4;
- outstr(s1);
- outchr('\r');
-
- dliscan1(udir[i].subnum);
- i1=recno(u.filename);
- if (i1>=0)
- {
- nl();
- outstr(get_string(777));
- pl(directories[udir[i].subnum].name);
-
- if (dcs())
- {
- nl();
- prt(5,get_string(778));
- if (!yn())
- {
- t2u_error(fn, get_string(766));
- return 1;
- }
- nl();
- }
- else
- {
- t2u_error(fn, get_string(766));
- return 1;
- }
- }
- }
-
-
- for (i1=0; i1<i2; i1++)
- s1[i1]=' ';
- s1[i1]=0;
- npr("%s\r",s1);
-
- dliscan1(dn);
- nl();
- #endif
- #else /* 424 specific */
- if (ok && (!(sysinfo.flags & OP_FLAGS_FAST_SEARCH)))
- {
- nl();
- pl(get_string(775));
- nl();
- i2=0;
-
- for (i=0; (i<num_dirs) && (udir[i].subnum!=-1); i++)
- {
- strcpy(s1,get_string(776));
- strcat(s1,directories[udir[i].subnum].name);
-
- for (i3=i4=strlen(s1); i3<i2; i3++)
- {
- s1[i3]=' ';
- s1[i3+1]=0;
- }
-
- i2=i4;
- outstr(s1);
- outchr('\r');
-
- dliscan1(udir[i].subnum);
- i1=recno(u.filename);
- if (i1>=0)
- {
- nl();
- outstr(get_string(777));
- pl(directories[udir[i].subnum].name);
-
- if (dcs())
- {
- nl();
- prt(5,get_string(778));
- if (!yn())
- {
- t2u_error(fn, get_string(766));
- return 1;
- }
- nl();
- }
- else
- {
- t2u_error(fn, get_string(766));
- return 1;
- }
- }
- }
-
-
- for (i1=0; i1<i2; i1++)
- s1[i1]=' ';
- s1[i1]=0;
- npr("%s\r",s1);
-
- dliscan1(dn);
- nl();
- }
- #endif /* end of 424 specific */
-
- // Copy file from batch dir to new dir
- sprintf(s1,"%s%s",syscfgovr.batchdir, fn);
- sprintf(s2,"%s%s", d.path, fn);
-
- if(exist(s2))
- unlink(s2);
-
- movefile(s1,s2, 1); /* s1 and s2 should remain set, they are used below */
- strcpy(u.description, "NO DESCRIPTION GIVEN");
-
-
- // Now get the file_id.diz
- get_file_idz(&u,dn);
-
-
- done=0;
- while(!done && !hangup)
- {
- int abort=0;
-
- CLS();
- nl();
- npr("1Upload going to 3%s", d.name);
- nln(2);
-
- npr(" 1Filename 8: 7%s", fn);
- nl();
- npr("2A5] 1Description 8: 7%s", u.description);
- nl();
- pl("2B5] 1Modify extended description");
- nl();
- print_extended(u.filename, &abort, 10, 0);
- npr("2<5CR2> 1to continue, 3Q1 to abort upload: ");
- mpl(1);
-
- key=onek("\rQABC");
-
- switch(key)
- {
- case 'Q':
- outstr("Are you sure, file will be lost? ");
- if(yn())
- {
- t2u_error(fn, "Changed mind");
- movefile(s2, s1, 1); /* move file back to batch dir */
- return 1;
- }
- break;
-
- case 'A':
- nl();
- pl(get_string(779));
- outstr(": ");
- inputl(u.description,58);
- break;
-
- case 'B':
- nl();
-
- ss=read_extended_description(u.filename);
- prt(5,get_string(834));
- if (yn())
- {
- nl();
- if (ss)
- {
- prt(5,get_string(835));
- if (yn())
- {
- farfree(ss);
- delete_extended_description(u.filename);
- u.mask &= ~mask_extended;
- }
- else
- {
- u.mask |= mask_extended;
- modify_extended_description(&ss,
- directories[udir[curdir].subnum].name,u.filename);
- if (ss)
- {
- delete_extended_description(u.filename);
- add_extended_description(u.filename,ss);
- farfree(ss);
- }
- }
- }
- else
- {
- modify_extended_description(&ss,
- directories[udir[curdir].subnum].name,u.filename);
- if (ss)
- {
- add_extended_description(u.filename,ss);
- farfree(ss);
- u.mask |= mask_extended;
- }
- else
- u.mask &= ~mask_extended;
- }
- }
- else if (ss)
- {
- farfree(ss);
- u.mask |= mask_extended;
- }
- else
- u.mask &= ~mask_extended;
-
- break;
-
- case '\r':
- nl();
- done=1;
- }
- }
-
- nln(3);
-
-
- // Ok to upload, save file in database, update user info etc...
-
- sprintf(s1,"%s%s",d.path,s);
- f=sh_open1(s1,O_RDONLY | O_BINARY);
-
- if (f<0) /* dos error, file not found */
- {
- if (u.mask & mask_extended)
- delete_extended_description(u.filename);
-
- t2u_error(fn, get_string(780));
- return 1;
- }
-
- if (syscfg.upload_c[0])
- {
- sh_close(f);
- pl(get_string(26));
- if (check_ul_event(dn,&u))
- {
- if (u.mask & mask_extended)
- delete_extended_description(u.filename);
-
- t2u_error(fn, "Failed upload event");
- return 1;
- }
- else
- f=sh_open1(s1,O_RDONLY | O_BINARY);
- }
-
- l=filelength(f);
- u.numbytes=l;
- f=sh_close(f);
- ++thisuser.uploaded;
-
- // Move files and add file to database
- time(&l);
- u.daten=l;
- f=sh_open(dlfn,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
- for (i=numf; i>=1; i--)
- {
- SETREC(f,i);
- sh_read(f,(void *)&u1,sizeof(uploadsrec));
- SETREC(f,i+1);
- sh_write(f,(void *)&u1,sizeof(uploadsrec));
- }
-
- SETREC(f,1);
- sh_write(f,(void *)&u,sizeof(uploadsrec));
- ++numf;
- SETREC(f,0);
- sh_read(f, &u1, sizeof(uploadsrec));
- u1.numbytes=numf;
- u1.daten=l;
- dir_dates[dn]=l;
- SETREC(f,0);
- sh_write(f,(void *)&u1,sizeof(uploadsrec));
- f=sh_close(f);
- // Done putting file in database and updating record 0
-
-
- #ifdef __423__ /* 423 specific */
- #ifdef OPT_FAST_SEARCH
- modify_database(u.filename,1);
- #endif
- #ifdef OPT_PACKSCAN_FREQ
- remotenotify(u.filename,u.description);
- #endif
- #else /* 424 specific */
- modify_database(u.filename,1);
- if (sysinfo.flags & OP_FLAGS_PACKSCAN_FREQ)
- remotenotify(u.filename,u.description);
- #endif /* end of 424 specific */
-
-
- thisuser.uk += bytes_to_k(u.numbytes);
-
- lock_status();
- ++status.uptoday;
- ++status.filechange[filechange_upload];
- save_status();
- sprintf(s,get_stringx(1,42),u.filename,directories[dn].name);
- sysoplog(s);
-
-
- return 0; // This means success
- }
-
-
- void t2u_error(char *fn, char *msg)
- {
- char temp[201];
-
- nln(2);
-
- sprintf(temp,"** %s failed T2U qualifications", fn);
- pl(temp);
- sysoplog(temp);
-
- sprintf(temp, "** Reason : %s", msg);
- pl(temp);
- sysoplog(temp);
- }
-
-