Commit 74c9aad8 authored by rswindell's avatar rswindell
Browse files

Added support for configurable directory locations for log files and modified

module (.js or .bin) files.
parent 2b7fb821
......@@ -1610,7 +1610,7 @@ void sbbs_t::guruchat(char *line, char *gurubuf, int gurunum)
bprintf(text[ChatLineFmt],cfg.guru[gurunum]->name
,cfg.sys_nodes+1,':',theanswer); }
CRLF;
sprintf(str,"%sguru.log",cfg.data_dir);
sprintf(str,"%sguru.log",cfg.logs_dir);
if((file=nopen(str,O_WRONLY|O_CREAT|O_APPEND))==-1)
errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_APPEND);
else {
......
......@@ -590,9 +590,11 @@ long sbbs_t::js_execfile(char *cmd)
fname=cmdline;
/* Add extension if not specified */
if(!strchr(fname,BACKSLASH))
sprintf(path,"%s%s",cfg.exec_dir,fname);
else
if(strcspn(fname,"/\\")==strlen(fname)) {
sprintf(path,"%s%s",cfg.mods_dir,fname);
if(cfg.mods_dir[0]==0 || !fexist(path))
sprintf(path,"%s%s",cfg.exec_dir,fname);
} else
sprintf(path,"%.*s",(int)sizeof(path)-4,fname);
if(!strchr(path,'.'))
strcat(path,".js");
......@@ -659,10 +661,16 @@ long sbbs_t::js_execfile(char *cmd)
long sbbs_t::exec_bin(char *mod, csi_t *csi)
{
char str[MAX_PATH+1];
char modname[MAX_PATH+1];
int file;
csi_t bin;
#ifdef JAVASCRIPT
if(cfg.mods_dir[0]) {
sprintf(str,"%s%s.js",cfg.mods_dir,mod);
if(fexist(str))
return(js_execfile(str));
}
sprintf(str,"%s%s.js",cfg.exec_dir,mod);
if(fexist(str))
return(js_execfile(str));
......@@ -671,24 +679,30 @@ long sbbs_t::exec_bin(char *mod, csi_t *csi)
memcpy(&bin,csi,sizeof(csi_t));
clearvars(&bin);
if(!strchr(mod,'.'))
sprintf(str,"%s%s.bin",cfg.exec_dir,mod);
else
sprintf(str,"%s%s",cfg.exec_dir,mod);
SAFECOPY(modname,mod);
if(!strchr(modname,'.'))
strcat(modname,".bin");
sprintf(str,"%s%s",cfg.mods_dir,modname);
if(cfg.mods_dir[0]==0 || !fexist(str))
sprintf(str,"%s%s",cfg.exec_dir,modname);
if((file=nopen(str,O_RDONLY))==-1) {
errormsg(WHERE,ERR_OPEN,str,O_RDONLY);
return(-1); }
return(-1);
}
bin.length=filelength(file);
if((bin.cs=(uchar *)MALLOC(bin.length))==NULL) {
close(file);
errormsg(WHERE,ERR_ALLOC,str,bin.length);
return(-1); }
return(-1);
}
if(lread(file,bin.cs,bin.length)!=bin.length) {
close(file);
errormsg(WHERE,ERR_READ,str,bin.length);
FREE(bin.cs);
return(-1); }
return(-1);
}
close(file);
bin.ip=bin.cs;
......@@ -700,7 +714,8 @@ long sbbs_t::exec_bin(char *mod, csi_t *csi)
if(!(bin.misc&CS_OFFLINE_EXEC)) {
checkline();
if(!online)
break; }
break;
}
freevars(&bin);
FREE(bin.cs);
......
......@@ -241,7 +241,7 @@ int sbbs_t::exec_function(csi_t *csi)
return(0);
if(localtime_r(&now,&tm)==NULL)
return(0);
sprintf(str,"%slogs/%2.2d%2.2d%2.2d.log", cfg.data_dir
sprintf(str,"%slogs/%2.2d%2.2d%2.2d.log", cfg.logs_dir
,tm.tm_mon+1,tm.tm_mday,TM_YEAR(tm.tm_year));
printfile(str,0);
return(0);
......@@ -251,7 +251,7 @@ int sbbs_t::exec_function(csi_t *csi)
now-=(ulong)60L*24L*60L;
if(localtime_r(&now,&tm)==NULL)
return(0);
sprintf(str,"%slogs/%2.2d%2.2d%2.2d.log",cfg.data_dir
sprintf(str,"%slogs/%2.2d%2.2d%2.2d.log",cfg.logs_dir
,tm.tm_mon+1,tm.tm_mday,TM_YEAR(tm.tm_year));
printfile(str,0);
return(0);
......@@ -270,7 +270,7 @@ int sbbs_t::exec_function(csi_t *csi)
#endif
return(0);
case CS_ERROR_LOG:
sprintf(str,"%serror.log", cfg.data_dir);
sprintf(str,"%serror.log", cfg.logs_dir);
if(fexist(str)) {
bputs(text[ErrorLogHdr]);
printfile(str,0);
......@@ -310,7 +310,7 @@ int sbbs_t::exec_function(csi_t *csi)
editfile(str);
return(0);
case CS_GURU_LOG:
sprintf(str,"%sguru.log", cfg.data_dir);
sprintf(str,"%sguru.log", cfg.logs_dir);
if(fexist(str)) {
printfile(str,0);
CRLF;
......
......@@ -659,11 +659,13 @@ BOOL js_generate_index(JSContext* js_cx, JSObject* parent,
break;
}
/* Add extension if not specified */
if(!strchr(startup->html_index_script,BACKSLASH))
sprintf(spath,"%s%s",scfg.exec_dir,startup->html_index_script);
else
if(strcspn(startup->html_index_script,"/\\")==strlen(startup->html_index_script)) {
sprintf(spath,"%s%s",scfg.mods_dir,startup->html_index_script);
if(scfg.mods_dir[0]==0 || !fexist(spath))
sprintf(spath,"%s%s",scfg.exec_dir,startup->html_index_script);
} else
sprintf(spath,"%.*s",(int)sizeof(spath)-4,startup->html_index_script);
/* Add extension if not specified */
if(!strchr(spath,'.'))
strcat(spath,".js");
......
......@@ -117,9 +117,11 @@ js_load(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
return(JS_FALSE);
errno = 0;
if(!strchr(filename,BACKSLASH))
sprintf(path,"%s%s",cfg->exec_dir,filename);
else
if(strcspn(filename,"/\\")==strlen(filename)) {
sprintf(path,"%s%s",cfg->mods_dir,filename);
if(cfg->mods_dir[0]==0 || !fexist(path))
sprintf(path,"%s%s",cfg->exec_dir,filename);
} else
strcpy(path,filename);
if((script=JS_CompileFile(cx, obj, path))==NULL)
return(JS_FALSE);
......
......@@ -45,7 +45,7 @@ extern "C" BOOL DLLCALL hacklog(scfg_t* cfg, char* prot, char* user, char* text,
int file;
time_t now=time(NULL);
sprintf(fname,"%shack.log",cfg->data_dir);
sprintf(fname,"%shack.log",cfg->logs_dir);
if((file=sopen(fname,O_CREAT|O_RDWR|O_BINARY|O_APPEND,SH_DENYWR))==-1)
return(FALSE);
......@@ -78,7 +78,7 @@ extern "C" BOOL DLLCALL spamlog(scfg_t* cfg, char* prot, char* action
int file;
time_t now=time(NULL);
sprintf(fname,"%sspam.log",cfg->data_dir);
sprintf(fname,"%sspam.log",cfg->logs_dir);
if((file=sopen(fname,O_CREAT|O_RDWR|O_BINARY|O_APPEND,SH_DENYWR))==-1)
return(FALSE);
......@@ -149,7 +149,7 @@ bool sbbs_t::syslog(char* code, char *entry)
now=time(NULL);
if(localtime_r(&now,&tm)==NULL)
return(false);
sprintf(fname,"%slogs/%2.2d%2.2d%2.2d.log",cfg.data_dir,tm.tm_mon+1,tm.tm_mday
sprintf(fname,"%slogs/%2.2d%2.2d%2.2d.log",cfg.logs_dir,tm.tm_mon+1,tm.tm_mday
,TM_YEAR(tm.tm_year));
if((file=nopen(fname,O_WRONLY|O_APPEND|O_CREAT))==-1) {
lprintf("!ERRROR %d opening/creating %s",errno,fname);
......@@ -368,7 +368,7 @@ void sbbs_t::errorlog(char *text)
}
now=time(NULL);
logline("!!",text);
sprintf(str,"%serror.log",cfg.data_dir);
sprintf(str,"%serror.log",cfg.logs_dir);
if((file=nopen(str,O_WRONLY|O_CREAT|O_APPEND))==-1) {
sprintf(tmp2,"!ERROR %d opening/creating %s",errno,str);
logline("!!",tmp2);
......
......@@ -234,7 +234,7 @@ void sbbs_t::logofflist()
return;
if(localtime_r(&logontime,&tm)==NULL)
return;
sprintf(str,"%slogs/%2.2d%2.2d%2.2d.LOL",cfg.data_dir,tm.tm_mon+1,tm.tm_mday
sprintf(str,"%slogs/%2.2d%2.2d%2.2d.LOL",cfg.logs_dir,tm.tm_mon+1,tm.tm_mday
,TM_YEAR(tm.tm_year));
if((file=nopen(str,O_WRONLY|O_CREAT|O_APPEND))==-1) {
errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_APPEND);
......
......@@ -2810,7 +2810,7 @@ void sbbs_t::catsyslog(int crash)
}
now=time(NULL);
localtime_r(&now,&tm);
sprintf(str,"%slogs/%2.2d%2.2d%2.2d.log",cfg.data_dir,tm.tm_mon+1,tm.tm_mday
sprintf(str,"%slogs/%2.2d%2.2d%2.2d.log",cfg.logs_dir,tm.tm_mon+1,tm.tm_mday
,TM_YEAR(tm.tm_year));
if((file=nopen(str,O_WRONLY|O_APPEND|O_CREAT))==-1) {
errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_APPEND|O_CREAT);
......@@ -2826,7 +2826,7 @@ void sbbs_t::catsyslog(int crash)
close(file);
if(crash) {
for(i=0;i<2;i++) {
sprintf(str,"%scrash.log",i ? cfg.data_dir : cfg.node_dir);
sprintf(str,"%scrash.log",i ? cfg.logs_dir : cfg.node_dir);
if((file=nopen(str,O_WRONLY|O_APPEND|O_CREAT))==-1) {
errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_APPEND|O_CREAT);
FREE((char *)buf);
......@@ -2934,8 +2934,11 @@ void node_thread(void* arg)
if(!sbbs->main_csi.cs || curshell!=sbbs->useron.shell) {
if(sbbs->useron.shell>=sbbs->cfg.total_shells)
sbbs->useron.shell=0;
sprintf(str,"%s%s.bin",sbbs->cfg.exec_dir
sprintf(str,"%s%s.bin",sbbs->cfg.mods_dir
,sbbs->cfg.shell[sbbs->useron.shell]->code);
if(sbbs->cfg.mods_dir[0]==0 || !fexist(str))
sprintf(str,"%s%s.bin",sbbs->cfg.exec_dir
,sbbs->cfg.shell[sbbs->useron.shell]->code);
if((file=sbbs->nopen(str,O_RDONLY))==-1) {
sbbs->errormsg(WHERE,ERR_OPEN,str,O_RDONLY);
sbbs->hangup();
......@@ -3662,7 +3665,7 @@ void DLLCALL bbs_thread(void* arg)
#if defined(_WIN32) && defined(_DEBUG) && defined(_MSC_VER)
sprintf(str,"%sDEBUG.LOG",scfg.data_dir);
sprintf(str,"%sDEBUG.LOG",scfg.logs_dir);
if((debug_log=CreateFile(
str, // pointer to name of the file
GENERIC_READ|GENERIC_WRITE,
......
......@@ -4131,7 +4131,7 @@ int main(int argc, char **argv)
sprintf(cfg.cfgfile,"%ssbbsecho.cfg",scfg.ctrl_dir);
strcpy(cfg.inbound,scfg.fidofile_dir);
sprintf(cfg.areafile,"%sareas.bbs",scfg.data_dir);
sprintf(cfg.logfile,"%ssbbsecho.log",scfg.data_dir);
sprintf(cfg.logfile,"%ssbbsecho.log",scfg.logs_dir);
read_echo_cfg();
......
......@@ -537,6 +537,8 @@ typedef struct
char text_dir[LEN_DIR+1];
char exec_dir[LEN_DIR+1];
char temp_dir[LEN_DIR+1];
char mods_dir[LEN_DIR+1];
char logs_dir[LEN_DIR+1];
char node_path[MAX_NODES][LEN_DIR+1]; /* paths to all node dirs */
ushort sysop_dir; /* Destination for uploads to sysop */
ushort user_dir; /* Directory for user to user xfers */
......
......@@ -292,14 +292,17 @@ BOOL read_main_cfg(scfg_t* cfg, char* error)
get_str(cfg->logoff_mod,instream);
get_str(cfg->newuser_mod,instream);
get_str(cfg->login_mod,instream);
if(!cfg->login_mod[0]) strcpy(cfg->login_mod,"login");
if(!cfg->login_mod[0]) SAFECOPY(cfg->login_mod,"login");
get_str(cfg->logout_mod,instream);
get_str(cfg->sync_mod,instream);
get_str(cfg->expire_mod,instream);
get_int(cfg->ctrlkey_passthru,instream);
get_int(c,instream);
get_str(cfg->mods_dir,instream);
get_str(cfg->logs_dir,instream);
if(!cfg->logs_dir[0]) SAFECOPY(cfg->logs_dir,cfg->data_dir);
for(i=0;i<222;i++) /* unused - initialized to NULL */
get_int(c,instream);
for(i=0;i<158;i++) /* unused - initialized to NULL */
get_int(n,instream);
for(i=0;i<254;i++) /* unused - initialized to 0xff */
get_int(n,instream);
......@@ -775,13 +778,15 @@ void make_data_dirs(scfg_t* cfg)
md(str);
sprintf(str,"%suser/ptrs",cfg->data_dir);
md(str);
sprintf(str,"%slogs",cfg->data_dir);
md(str);
sprintf(str,"%sqnet",cfg->data_dir);
md(str);
sprintf(str,"%sfile",cfg->data_dir);
md(str);
md(cfg->logs_dir);
sprintf(str,"%slogs",cfg->logs_dir);
md(str);
#if 0
int i;
......
......@@ -321,9 +321,13 @@ BOOL DLLCALL write_main_cfg(scfg_t* cfg, int backup_level)
put_str(cfg->logout_mod,stream);
put_str(cfg->sync_mod,stream);
put_str(cfg->expire_mod,stream);
put_int(cfg->ctrlkey_passthru,stream);
put_str(cfg->mods_dir,stream);
put_str(cfg->logs_dir,stream);
put_int(c,stream);
n=0;
for(i=0;i<224;i++)
for(i=0;i<158;i++)
put_int(n,stream);
n=(ushort)0xffff;
for(i=0;i<256;i++)
......
......@@ -824,7 +824,9 @@ static void js_service_thread(void* arg)
}
/* RUN SCRIPT */
sprintf(spath,"%s%s",scfg.exec_dir,service->cmd);
sprintf(spath,"%s%s",scfg.mods_dir,service->cmd);
if(scfg.mods_dir[0]==0 || !fexist(spath))
sprintf(spath,"%s%s",scfg.exec_dir,service->cmd);
js_init_cmdline(js_cx, js_glob, spath);
......@@ -920,7 +922,10 @@ static void js_static_service_thread(void* arg)
return;
}
sprintf(spath,"%s%s",scfg.exec_dir,service->cmd);
sprintf(spath,"%s%s",scfg.mods_dir,service->cmd);
if(scfg.mods_dir[0]==0 || !fexist(spath))
sprintf(spath,"%s%s",scfg.exec_dir,service->cmd);
js_init_cmdline(js_cx, js_glob, spath);
val = BOOLEAN_TO_JSVAL(JS_FALSE);
......
......@@ -1708,7 +1708,7 @@ bool sbbs_t::exec_xtrn(uint xtrnnum)
if(online==ON_REMOTE) {
checkline();
if(!online) {
sprintf(str,"%shungup.log",cfg.data_dir);
sprintf(str,"%shungup.log",cfg.logs_dir);
if((file=nopen(str,O_WRONLY|O_CREAT|O_APPEND))==-1) {
errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_APPEND);
return(false);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment