--- sbbs/src/sbbs3/logfile.cpp 2018/04/24 16:41:23 1.1 +++ sbbs/src/sbbs3/logfile.cpp 2018/04/24 16:43:21 1.1.1.2 @@ -2,13 +2,13 @@ /* Synchronet log file routines */ -/* $Id: logfile.cpp,v 1.1 2018/04/24 16:41:23 root Exp $ */ +/* $Id: logfile.cpp,v 1.1.1.2 2018/04/24 16:43:21 root Exp $ */ /**************************************************************************** * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2011 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 * @@ -47,13 +47,13 @@ extern "C" BOOL DLLCALL hacklog(scfg_t* sprintf(fname,"%shack.log",cfg->logs_dir); - if((file=sopen(fname,O_CREAT|O_RDWR|O_BINARY|O_APPEND,SH_DENYWR,S_IREAD|S_IWRITE))==-1) + if((file=sopen(fname,O_CREAT|O_RDWR|O_BINARY|O_APPEND,SH_DENYWR,DEFFILEMODE))==-1) return(FALSE); - sprintf(hdr,"SUSPECTED %s HACK ATTEMPT from %s on %.24s\r\nUsing port %u at %s [%s]\r\nDetails: " + sprintf(hdr,"SUSPECTED %s HACK ATTEMPT for user '%s' on %.24s\r\nUsing port %u at %s [%s]\r\nDetails: " ,prot ,user - ,timestr(cfg,&now,tstr) + ,timestr(cfg,now,tstr) ,addr->sin_port ,host ,inet_ntoa(addr->sin_addr) @@ -67,6 +67,11 @@ extern "C" BOOL DLLCALL hacklog(scfg_t* return(TRUE); } +BOOL sbbs_t::hacklog(char* prot, char* text) +{ + return ::hacklog(&cfg, prot, useron.alias, text, client_name, &client_addr); +} + extern "C" BOOL DLLCALL spamlog(scfg_t* cfg, char* prot, char* action ,char* reason, char* host, char* ip_addr ,char* to, char* from) @@ -80,7 +85,7 @@ extern "C" BOOL DLLCALL spamlog(scfg_t* sprintf(fname,"%sspam.log",cfg->logs_dir); - if((file=sopen(fname,O_CREAT|O_RDWR|O_BINARY|O_APPEND,SH_DENYWR,S_IREAD|S_IWRITE))==-1) + if((file=sopen(fname,O_CREAT|O_RDWR|O_BINARY|O_APPEND,SH_DENYWR,DEFFILEMODE))==-1) return(FALSE); if(to==NULL) @@ -94,7 +99,7 @@ extern "C" BOOL DLLCALL spamlog(scfg_t* sprintf(hdr,"SUSPECTED %s SPAM %s on %.24s\r\nHost: %s [%s]\r\nFrom: %.128s %s\r\nReason: " ,prot ,action - ,timestr(cfg,&now,tstr) + ,timestr(cfg,now,tstr) ,host ,ip_addr ,from @@ -110,12 +115,26 @@ extern "C" BOOL DLLCALL spamlog(scfg_t* return(TRUE); } -void sbbs_t::logentry(char *code, char *entry) +extern "C" int DLLCALL errorlog(scfg_t* cfg, const char* host, const char* text) +{ + FILE* fp; + char buf[128]; + char path[MAX_PATH+1]; + + sprintf(path,"%serror.log",cfg->logs_dir); + if((fp=fnopen(NULL,path,O_WRONLY|O_CREAT|O_APPEND))==NULL) + return -1; + fprintf(fp,"%s %s\r\n%s\r\n\r\n", timestr(cfg,time(NULL),buf), host==NULL ? "":host, text); + fclose(fp); + return 0; +} + +void sbbs_t::logentry(const char *code, const char *entry) { char str[512]; now=time(NULL); - sprintf(str,"Node %2d %s\r\n %s",cfg.node_num,timestr(&now),entry); + sprintf(str,"Node %2d %s\r\n %s",cfg.node_num,timestr(now),entry); logline(code,str); } @@ -127,18 +146,22 @@ void sbbs_t::log(char *str) if(logfile_fp==NULL || online==ON_LOCAL) return; if(logcol>=78 || (78-logcol)9 && (long)access!=-1 && (short)access!=-1 && (char)access!=-1) - bprintf(" (0x%lX)",access); - if(cfg.sys_misc&SM_ERRALARM) { - sbbs_beep(500,220); sbbs_beep(250,220); - sbbs_beep(500,220); sbbs_beep(250,220); - sbbs_beep(500,220); sbbs_beep(250,220); - nosound(); } - bputs("\r\n\r\nThe sysop has been notified. "); - getkey(0); + int savatr=curatr; + lprintf(LOG_ERR,"Node %d !%s",cfg.node_num, str); + attr(cfg.color[clr_err]); + bprintf("\7\r\n!ERROR %s %s\r\n", action, object); /* tell user about error */ + bputs("\r\nThe sysop has been notified.\r\n"); + pause(); + attr(savatr); CRLF; } - sprintf(str,"\r\n source: %s\r\n line: %d\r\n action: %s\r\n" - " object: %s\r\n access: %ld" - ,src,line,action,object,access); - if(access>9 && (long)access!=-1 && (short)access!=-1 && (char)access!=-1) { - sprintf(tmp," (0x%lX)",access); - strcat(str,tmp); } - if(extinfo!=NULL) { - sprintf(tmp,"\r\n info: %s",extinfo); - strcat(str,tmp); - } - if(errno) { - sprintf(tmp,"\r\n errno: %d (%s)",errno,strerror(errno)); - strcat(str,tmp); - errno=0; - } -#if defined(_WIN32) - if(GetLastError()!=0) { - sprintf(tmp,"\r\n WinError: %d (0x%X)",GetLastError(), GetLastError()); - strcat(str,tmp); - } -#endif - errorlog(str); - errormsg_inside=false; -} - -/*****************************************************************************/ -/* Error logging to NODE.LOG and DATA\ERROR.LOG function */ -/*****************************************************************************/ -void sbbs_t::errorlog(char *text) -{ - char hdr[256],str[256],tmp2[256]; - int file; - - if(errorlog_inside) /* let's not go recursive on this puppy */ - return; - errorlog_inside=1; + safe_snprintf(str,sizeof(str),"ERROR %s %s", action, object); if(cfg.node_num>0) { getnodedat(cfg.node_num,&thisnode,1); if(thisnode.errors