Skip to content
Snippets Groups Projects
Commit 5d1d586f authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Better access enforcement to files in batch download queues

If a file gets added to a batch download queue that a user doesn't have download-access to (at the time of batch download), deal with that gracefully and consistently.

start_batch_download():
- Now checks current user access to download the file in both single-file and batch modes
- Now performs credit-check in single-file mode (wasn't doing so previously)
- totalsize of multi-file batch download queue is now calculated again (apparently removed/broken in the new filebase conversion of v3.19), so download ETA should be calculated more accurately (?) again
- Use gettimetodl() to calculate each file's download time for multi-file downloads
- Using new putnode_download() method to write node downloading "action" and ETA-in-aux fields
- The node status wasn't being updated at all before start of download in single-file mode - fixed

create_batchdn_lst() :
- Checks each file still downloadable by the user and if not, removes from the queue (and the generated list file).
- Performs credit check and removes files that exceed available user credit
- returns true only when 1 or more files is added to the batch download list file

addtobatdl()
- Removed redundant 'D' restriction check - this is handled by can_user_download() check already.
- Use the 'reason' out parameter from can_user_download() to determine which error string to display (not always CantDownloadFromDir).
parent c0ef762a
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #3894 passed
...@@ -245,8 +245,7 @@ BOOL sbbs_t::start_batch_download() ...@@ -245,8 +245,7 @@ BOOL sbbs_t::start_batch_download()
char list[1024] = ""; char list[1024] = "";
int error; int error;
uint i,xfrprot; uint i,xfrprot;
time_t start,end,t; time_t start,end;
struct tm tm;
if(useron.rest&FLAG('D')) { /* Download restriction */ if(useron.rest&FLAG('D')) { /* Download restriction */
bputs(text[R_Download]); bputs(text[R_Download]);
...@@ -264,10 +263,28 @@ BOOL sbbs_t::start_batch_download() ...@@ -264,10 +263,28 @@ BOOL sbbs_t::start_batch_download()
str_list_t filenames = iniGetSectionList(ini, NULL); str_list_t filenames = iniGetSectionList(ini, NULL);
if(file_count == 1) { // Only one file in the queue? Perform a non-batch (e.g. XMODEM) download if(file_count == 1) { // Only one file in the queue? Perform a non-batch (e.g. XMODEM) download
const char* filename = filenames[0];
file_t f = {{}}; file_t f = {{}};
BOOL result = FALSE; BOOL result = FALSE;
if(batch_file_get(&cfg, ini, filenames[0], &f)) { if(!batch_file_load(&cfg, ini, filename, &f)) {
result = sendfile(&f, useron.prot, /* autohang: */true); bprintf(text[FileDoesNotExist], filename);
batch_file_remove(&cfg, useron.number, XFER_BATCH_DOWNLOAD, filename);
} else {
uint reason = R_Download;
if(!can_user_download(&cfg, f.dir, &useron, &client, &reason)) {
bputs(text[reason]);
batch_file_remove(&cfg, useron.number, XFER_BATCH_DOWNLOAD, filename);
}
else if(f.cost > useron.cdt + useron.freecdt)
bprintf(text[YouOnlyHaveNCredits]
,u64toac(useron.cdt + useron.freecdt, tmp));
else if(!(cfg.dir[f.dir]->misc&DIR_TFREE) && gettimetodl(&cfg, &f, cur_cps) > timeleft
&& !dir_op(f.dir) && !(useron.exempt&FLAG('T')))
bputs(text[NotEnoughTimeToDl]);
else {
putnode_downloading(getfilesize(&cfg, &f));
result = sendfile(&f, useron.prot, /* autohang: */true);
}
if(result == TRUE) if(result == TRUE)
batch_file_remove(&cfg, useron.number, XFER_BATCH_DOWNLOAD, f.name); batch_file_remove(&cfg, useron.number, XFER_BATCH_DOWNLOAD, f.name);
} }
...@@ -279,12 +296,21 @@ BOOL sbbs_t::start_batch_download() ...@@ -279,12 +296,21 @@ BOOL sbbs_t::start_batch_download()
uint64_t totalcdt = 0; uint64_t totalcdt = 0;
for(size_t i=0; filenames[i] != NULL; ++i) { for(size_t i=0; filenames[i] != NULL; ++i) {
const char* filename = filenames[i];
progress(text[Scanning], i, file_count); progress(text[Scanning], i, file_count);
file_t f = {{}}; file_t f = {{}};
if(batch_file_load(&cfg, ini, filenames[i], &f)) { if(!batch_file_load(&cfg, ini, filename, &f)) {
totalcdt += f.cost; bprintf(text[FileDoesNotExist], filename);
smb_freefilemem(&f); batch_file_remove(&cfg, useron.number, XFER_BATCH_DOWNLOAD, filename);
continue;
} }
uint reason = R_Download;
if(!can_user_download(&cfg, f.dir, &useron, &client, &reason)) {
bputs(text[reason]);
batch_file_remove(&cfg, useron.number, XFER_BATCH_DOWNLOAD, filename);
} else
totalcdt += f.cost;
smb_freefilemem(&f);
} }
bputs(text[Scanned]); bputs(text[Scanned]);
if(totalcdt > useron.cdt+useron.freecdt) { if(totalcdt > useron.cdt+useron.freecdt) {
...@@ -301,8 +327,9 @@ BOOL sbbs_t::start_batch_download() ...@@ -301,8 +327,9 @@ BOOL sbbs_t::start_batch_download()
file_t f = {{}}; file_t f = {{}};
if(!batch_file_get(&cfg, ini, filenames[i], &f)) if(!batch_file_get(&cfg, ini, filenames[i], &f))
continue; continue;
if(!(cfg.dir[f.dir]->misc&DIR_TFREE) && cur_cps) totalsize += getfilesize(&cfg, &f);
totaltime += getfilesize(&cfg, &f) / (ulong)cur_cps; if(!(cfg.dir[f.dir]->misc&DIR_TFREE))
totaltime += gettimetodl(&cfg, &f, cur_cps);
SAFECAT(list, getfilepath(&cfg, &f, path)); SAFECAT(list, getfilepath(&cfg, &f, path));
SAFECAT(list, " "); SAFECAT(list, " ");
smb_freefilemem(&f); smb_freefilemem(&f);
...@@ -393,16 +420,7 @@ BOOL sbbs_t::start_batch_download() ...@@ -393,16 +420,7 @@ BOOL sbbs_t::start_batch_download()
#endif #endif
SAFEPRINTF(str,"%sBATCHDN.LST",cfg.node_dir); SAFEPRINTF(str,"%sBATCHDN.LST",cfg.node_dir);
action=NODE_DLNG; putnode_downloading(totalsize);
t=now;
if(cur_cps)
t+=(totalsize/(ulong)cur_cps);
localtime_r(&t,&tm);
if(getnodedat(cfg.node_num,&thisnode,true)==0) {
thisnode.aux=(tm.tm_hour*60)+tm.tm_min;
thisnode.action=action;
putnodedat(cfg.node_num,&thisnode); /* calculate ETA */
}
start=time(NULL); start=time(NULL);
error=protocol(cfg.prot[xfrprot],XFER_BATCH_DOWNLOAD,str,list,false); error=protocol(cfg.prot[xfrprot],XFER_BATCH_DOWNLOAD,str,list,false);
end=time(NULL); end=time(NULL);
...@@ -429,6 +447,8 @@ bool sbbs_t::create_batchdn_lst(bool native) ...@@ -429,6 +447,8 @@ bool sbbs_t::create_batchdn_lst(bool native)
errormsg(WHERE, ERR_OPEN, path); errormsg(WHERE, ERR_OPEN, path);
return false; return false;
} }
bool result = false;
uint64_t totalcdt = 0;
const char* list_desc = "Batch Download File List"; const char* list_desc = "Batch Download File List";
bprintf(text[CreatingFileList], list_desc); bprintf(text[CreatingFileList], list_desc);
str_list_t ini = batch_list_read(&cfg, useron.number, XFER_BATCH_DOWNLOAD); str_list_t ini = batch_list_read(&cfg, useron.number, XFER_BATCH_DOWNLOAD);
...@@ -437,6 +457,12 @@ bool sbbs_t::create_batchdn_lst(bool native) ...@@ -437,6 +457,12 @@ bool sbbs_t::create_batchdn_lst(bool native)
const char* filename = filenames[i]; const char* filename = filenames[i];
file_t f = {}; file_t f = {};
f.dir = batch_file_dir(&cfg, ini, filename); f.dir = batch_file_dir(&cfg, ini, filename);
uint reason = R_Download;
if(!can_user_download(&cfg, f.dir, &useron, &client, &reason)) {
bputs(text[reason]);
batch_file_remove(&cfg, useron.number, XFER_BATCH_DOWNLOAD, filename);
continue;
}
if(!loadfile(&cfg, f.dir, filename, &f, file_detail_index)) { if(!loadfile(&cfg, f.dir, filename, &f, file_detail_index)) {
errormsg(WHERE, "loading file", filename, i); errormsg(WHERE, "loading file", filename, i);
batch_file_remove(&cfg, useron.number, XFER_BATCH_DOWNLOAD, filename); batch_file_remove(&cfg, useron.number, XFER_BATCH_DOWNLOAD, filename);
...@@ -447,6 +473,12 @@ bool sbbs_t::create_batchdn_lst(bool native) ...@@ -447,6 +473,12 @@ bool sbbs_t::create_batchdn_lst(bool native)
bprintf(text[FileDoesNotExist], path); bprintf(text[FileDoesNotExist], path);
batch_file_remove(&cfg, useron.number, XFER_BATCH_DOWNLOAD, filename); batch_file_remove(&cfg, useron.number, XFER_BATCH_DOWNLOAD, filename);
} }
else if(totalcdt + f.cost > useron.cdt + useron.freecdt) {
char tmp[128];
bprintf(text[YouOnlyHaveNCredits]
,u64toac(useron.cdt + useron.freecdt, tmp));
batch_file_remove(&cfg, useron.number, XFER_BATCH_DOWNLOAD, filename);
}
else { else {
#ifdef _WIN32 #ifdef _WIN32
if(!native) { if(!native) {
...@@ -456,6 +488,8 @@ bool sbbs_t::create_batchdn_lst(bool native) ...@@ -456,6 +488,8 @@ bool sbbs_t::create_batchdn_lst(bool native)
} }
#endif #endif
fprintf(fp, "%s\r\n", path); fprintf(fp, "%s\r\n", path);
totalcdt += f.cost;
result = true;
} }
smb_freefilemem(&f); smb_freefilemem(&f);
} }
...@@ -463,7 +497,7 @@ bool sbbs_t::create_batchdn_lst(bool native) ...@@ -463,7 +497,7 @@ bool sbbs_t::create_batchdn_lst(bool native)
iniFreeStringList(ini); iniFreeStringList(ini);
iniFreeStringList(filenames); iniFreeStringList(filenames);
bprintf(text[CreatedFileList], list_desc); bprintf(text[CreatedFileList], list_desc);
return true; return result;
} }
/****************************************************************************/ /****************************************************************************/
...@@ -668,16 +702,13 @@ bool sbbs_t::addtobatdl(file_t* f) ...@@ -668,16 +702,13 @@ bool sbbs_t::addtobatdl(file_t* f)
char str[256],tmp2[256]; char str[256],tmp2[256];
char tmp[512]; char tmp[512];
uint i; uint i;
uint reason = R_Download;
uint64_t totalcost, totalsize; uint64_t totalcost, totalsize;
uint64_t totaltime; uint64_t totaltime;
if(useron.rest&FLAG('D')) { if(!can_user_download(&cfg, f->dir, &useron, &client, &reason)) {
bputs(text[R_Download]);
return false;
}
if(!can_user_download(&cfg, f->dir, &useron, &client, /* reason */NULL)) {
bprintf(text[CantAddToQueue],f->name); bprintf(text[CantAddToQueue],f->name);
bputs(text[CantDownloadFromDir]); bputs(text[reason]);
return false; return false;
} }
if(getfilesize(&cfg, f) < 1) { if(getfilesize(&cfg, f) < 1) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment