slog.c 3.14 KB
Newer Older
deuce's avatar
deuce committed
1 2 3 4 5 6
/* SLOG.C */

/* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */

#include <stdio.h>
#include <stdlib.h>
deuce's avatar
deuce committed
7
#include <string.h>
deuce's avatar
deuce committed
8 9 10 11 12 13 14 15
#include <fcntl.h>
#include <sys/stat.h>
#include <time.h>
#include <errno.h>

#include "sbbsdefs.h"
#include "nopen.h"
#include "dirwrap.h"
16
#include "conwrap.h"
deuce's avatar
deuce committed
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 48 49 50 51 52 53 54 55 56

/****************************************************************************/
/* Lists system statistics for everyday the bbs has been running.           */
/* Either for the current node (node=1) or the system (node=0)              */
/****************************************************************************/
int main(int argc, char **argv)
{
	char str[256],dir[256]={""},*p;
    uchar *buf;
	int i,file,pause=0,lncntr=0;
    time_t timestamp;
    long l;
    ulong   length,
            logons,
            timeon,
            posts,
            emails,
            fbacks,
            ulb,
            uls,
            dlb,
            dls;
	time_t	yesterday;
	struct tm *curdate;


printf("\nSynchronet System/Node Statistics Log Viewer v1.02\n\n");

for(i=1;i<argc;i++)
	if(!stricmp(argv[i],"/P"))
		pause=1;
	else
		strcpy(dir,argv[1]);
if(!dir[0]) {
	p=getenv("SBBSCTRL");
	if(p!=NULL)
		strcpy(dir,p); }

backslash(dir);

57
SAFEPRINTF(str,"%scsts.dab",dir);
deuce's avatar
deuce committed
58 59 60 61 62 63 64 65 66 67
if(!fexistcase(str)) {
	printf("%s does not exist\r\n",str);
	return(1); }
if((file=nopen(str,O_RDONLY))==-1) {
	printf("Error opening %s\r\n",str);
	return(1); }
length=filelength(file);
if(length<40) {
    close(file);
	return(1); }
68
if((buf=malloc(length))==0) {
deuce's avatar
deuce committed
69 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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
    close(file);
	printf("error allocating %lu bytes\r\n",length);
	return(1); }
read(file,buf,length);
close(file);
l=length-4;
while(l>-1L) {
    fbacks=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
        |((long)buf[l+3]<<24);
    l-=4;
    emails=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
        |((long)buf[l+3]<<24);
    l-=4;
    posts=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
        |((long)buf[l+3]<<24);
    l-=4;
    dlb=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
        |((long)buf[l+3]<<24);
    l-=4;
    dls=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
        |((long)buf[l+3]<<24);
    l-=4;
    ulb=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
        |((long)buf[l+3]<<24);
    l-=4;
    uls=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
        |((long)buf[l+3]<<24);
    l-=4;
    timeon=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
        |((long)buf[l+3]<<24);
    l-=4;
    logons=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
        |((long)buf[l+3]<<24);
    l-=4;
    timestamp=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
        |((long)buf[l+3]<<24);
    l-=4;
	yesterday=timestamp-(24*60*60);	/* 1 day less than stamp */
	curdate=localtime(&yesterday);
	printf("%2.2d/%2.2d/%2.2d T:%5lu   L:%3lu   P:%3lu   "
		"E:%3lu   F:%3lu   U:%6luk %3lu  D:%6luk %3lu\n"
		,curdate->tm_mon+1,curdate->tm_mday,curdate->tm_year%100,timeon,logons,posts,emails
		,fbacks,ulb/1024,uls,dlb/1024,dls);
	lncntr++;
	if(pause && lncntr>=20) {
114
		printf("More (Y/n) ? ");
115
		fflush(stdout);
116 117
		char ch = getchar();
		if(ch == CTRL_C || toupper(ch) == 'N')
deuce's avatar
deuce committed
118 119 120 121 122 123
			break;
		printf("\r");
		lncntr=0; } }
free(buf);
return(0);
}