Commit 4132f4bb authored by Rob Swindell's avatar Rob Swindell 💬
Browse files

Updated to read csts.tab instead of csts.dab

Also changed output to reflect slog.c more closely. I suppose only one of
of these 2 "utilities" to read csts.tab should exist at some point. :-)

Also added suport for "-r" and "-t" to be more modern and *nixy.
parent 066327b7
load("file_size.js");
function isoTime(val)
{
var str = format("%.4s-%.2s-%.2sT00:00", val.substring(0,4), val.substring(4,6), val.substring(6));
var d = new Date(str);
return d.valueOf() / 1000;
}
(function() {
writeln("\r\nSynchronet System/Node Statistics Log Viewer\n");
var sfile = new File(system.ctrl_dir + "csts.dab");
var sfile = new File(system.ctrl_dir + "csts.tab");
var list = [];
var reverse = false;
var show_totals = false;
......@@ -15,15 +24,18 @@
var total_posts = 0;
var total_emails = 0;
var total_fbacks = 0;
var total_nusers = 0;
while(argv.length > 0) {
switch(argv.shift().toUpperCase()) {
case "/REVERSE":
case "/R":
case "-R":
reverse = true;
break;
case "/TOTALS":
case "/T":
case "-T":
show_totals = true;
break;
}
......@@ -33,60 +45,65 @@
writeln("* " + sfile.name + " does not exist");
return false;
}
if(!sfile.open('r+b')) {
if(!sfile.open('r')) {
writeln("* error opening " + sfile.name);
return false;
}
while(sfile.position <= file_size(sfile.name) - 40) {
var timestamp = sfile.readBin();
var logons = sfile.readBin();
var timeon = sfile.readBin();
var uls = sfile.readBin();
var ulb = sfile.readBin();
var dls = sfile.readBin();
var dlb = sfile.readBin();
var posts = sfile.readBin();
var emails = sfile.readBin();
var fbacks = sfile.readBin();
var lines = sfile.readAll();
sfile.close();
for(var l = 1; l < lines.length; l++) {
var line = lines[l];
var field = line.split('\t');
var timestamp = isoTime(field[0]);
var logons = parseInt(field[1], 10);
var timeon = parseInt(field[2], 10);
var uls = parseInt(field[3], 10);
var ulb = parseInt(field[4], 10);
var dls = parseInt(field[5], 10);
var dlb = parseInt(field[6], 10);
var posts = parseInt(field[7], 10);
var emails = parseInt(field[8], 10);
var fbacks = parseInt(field[9], 10);
var nusers = parseInt(field[10], 10);
if(show_totals) {
total_logons += logons;
total_timeon += timeon;
total_uls += uls;
total_ulb += uls;
total_dls += uls;
total_dlb += uls;
total_ulb += ulb;
total_dls += dls;
total_dlb += dlb;
total_posts += posts;
total_emails += emails;
total_fbacks += fbacks;
total_nusers += nusers;
}
list.unshift(
strftime("%x",timestamp-(24*60*60)) +
format(" T:%5lu L:%3lu P:%3lu E:%3lu F:%3lu U:%6luk %3lu D:%6luk %3lu",
timeon,logons,posts,emails,fbacks,ulb/1024,uls,dlb/1024,dls)
strftime("%x",timestamp-(24*60*60)) +
format(" T:%4lu L:%3lu P:%3lu E:%3lu F:%3lu U:%5s %5lu D:%5s %5lu N:%2u",
timeon,logons,posts,emails,fbacks,file_size_str(ulb, 1, 0),uls,file_size_str(dlb, 1, 0),dls,nusers)
);
}
sfile.close();
if(reverse)
if(reverse)
list.reverse();
for each(var i in list)
for each(var i in list)
writeln(i);
if(show_totals) {
writeln("");
writeln(format("%-*s: %d",20,"Total Time",total_timeon));
writeln(format("%-*s: %d",20,"Total Logons",total_logons));
writeln(format("%-*s: %d - %dk",20,"Total U/L",total_uls, total_ulb));
writeln(format("%-*s: %d - %dk",20,"Total D/L",total_dls, total_dlb));
writeln(format("%-*s: %d - %s",20,"Total U/L",total_uls, file_size_str(total_ulb, 1, 0)));
writeln(format("%-*s: %d - %s",20,"Total D/L",total_dls, file_size_str(total_dlb, 1, 0)));
writeln(format("%-*s: %d",20,"Total Posts",total_posts));
writeln(format("%-*s: %d",20,"Total E-Mails",total_emails));
writeln(format("%-*s: %d",20,"Total Feedback",total_fbacks));
writeln(format("%-*s: %u",20,"Total New users", total_nusers));
}
writeln("");
......
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