-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogonlist.js
97 lines (85 loc) · 2.75 KB
/
logonlist.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
57
58
59
60
61
62
63
64
65
66
67
68
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
// $Id: logonlist.js,v 1.8 2020/04/27 08:16:46 rswindell Exp $
// Logon List module (replaces old hard-coded logon.lst)
// Install with 'jsexec logonlist install'
"use strict";
require("sbbsdefs.js", 'SYS_LISTLOC');
function install()
{
var maint_event = "?logonlist -m";
var cnflib = load({}, "cnflib.js");
var main_cnf = cnflib.read("main.cnf");
if(!main_cnf)
return "Failed to read main.cnf";
if(main_cnf.sys_daily == maint_event)
return true;
if(main_cnf.sys_daily)
return format("System daily event already set to: '%s'", main_cnf.sys_daily);
main_cnf.sys_daily = maint_event;
if(!cnflib.write("main.cnf", undefined, main_cnf))
return "Failed to write main.cnf";
return true;
}
if(argv.indexOf('install') >= 0)
{
var result = install();
if(result !== true)
alert(result);
exit(result === true ? 0 : 1);
}
if(!js.global.bbs) {
alert("This module must be run from the BBS");
exit(1);
}
if(!bbs.mods.logonlist_lib)
bbs.mods.logonlist_lib = load({}, 'logonlist_lib.js');
var options = load("modopts.js", "logonlist");
if(!options)
options = {};
if(options.last_few_callers === undefined)
options.last_few_callers = 4;
if(options.backup_level === undefined)
options.backup_level = 10;
if(argv.indexOf('-m') >= 0) { // maintenance (daily)
bbs.mods.logonlist_lib.maint(options.backup_level);
exit();
}
var days_ago = 0;
var day = options.today || "Today";
if(argv.indexOf('-y') >= 0)
days_ago = 1, day = options.yesterday || "Yesterday";
// Returns true on success, string on error
function print(hdr, num, days_ago)
{
var list = bbs.mods.logonlist_lib.get(num, days_ago);
if(typeof list != 'object' || !list.length)
return false;
console.print(hdr);
for(var i in list) {
var record = list[i];
var date = new Date(record.time * 1000);
console.print(format(options.last_few_callers_fmt ||
"\r\n\x01n\x01h\x01m%-3s\x01n\x01m%-6s \x01w\x01h%-25.25s \x01m%-25.25s" +
"\x01n\x01m%2u:%02u \x01h%-8.8s\x01n\x01m%4u"
,record.total ? record.node : ""
,record.total ? record.total : ""
,record.user.alias
,(system.settings & SYS_LISTLOC) ? record.user.location : record.user.note
,date.getHours()
,date.getMinutes()
,record.user.connection
,record.user.stats.logons_today
));
}
return true;
}
if(argv.indexOf('-l') >= 0) { // Last few callers?
if(!this.print(options.last_few_callers_msg || "\x01n\x01g\x01hLast few callers:\x01n\r\n"
,-options.last_few_callers))
console.print(options.first_caller_msg || "\x01n\x01g\x01hYou are the first caller of the day!");
console.crlf();
} else {
if(!this.print(format(options.logons_header_fmt || "\x01n\x01h\x01y\r\nLogons %s:\r\n", day)
,/* all: */0, days_ago))
console.print(format(options.nobody_logged_on_fmt || "\r\nNo one logged on %s.", day.toLowerCase()));
console.crlf();
}