From dd2b44e99d6561c4964216fbd96a160907c4870a Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Fri, 16 Aug 2019 02:50:43 +0000 Subject: [PATCH] New module for logon list / last-few-callers. Install (for daily maintenance) with: 'jsexec logonlist install' --- exec/logon.js | 14 +++---- exec/logonlist.js | 93 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 exec/logonlist.js diff --git a/exec/logon.js b/exec/logon.js index 1398b903c6..b5ba86de3c 100644 --- a/exec/logon.js +++ b/exec/logon.js @@ -7,8 +7,11 @@ // @format.tab-size 4, @format.use-tabs true require("sbbsdefs.js", 'SS_RLOGIN'); +require("nodedefs.js", 'NODE_QUIET'); if(!bbs.mods.avatar_lib) bbs.mods.avatar_lib = load({}, 'avatar_lib.js'); +if(!bbs.mods.logonlist_lib) + bbs.mods.logonlist_lib = load({}, 'logonlist_lib.js'); load("fonts.js", "preload", "default"); if(!bbs.mods.userprops) bbs.mods.userprops = load({}, "userprops.js"); @@ -158,14 +161,9 @@ if(user.security.level==99 /* Sysop logging on */ // Last few callers console.aborted=false; console.clear(LIGHTGRAY); -logonlst=system.data_dir + "logon.lst" -if(file_size(logonlst)<1) - printf("\1n\1g\1hYou are the first caller of the day!\r\n"); -else { - printf("\1n\1g\1hLast few callers:\1n\r\n"); - console.printtail(logonlst, options.last_few_callers, P_NOATCODES|P_TRUNCATE|P_NOABORT); -} -console.crlf(); +bbs.exec("?logonlist -l"); +if(bbs.node_status != NODE_QUIET && ((system.settings&SYS_SYSSTAT) || !user.is_sysop)) + bbs.mods.logonlist_lib.add(); // Auto-message auto_msg=system.data_dir + "msgs/auto.msg" diff --git a/exec/logonlist.js b/exec/logonlist.js new file mode 100644 index 0000000000..85cca33aaa --- /dev/null +++ b/exec/logonlist.js @@ -0,0 +1,93 @@ +// $Id$ + +// Logon List module (replaces old hard-coded logon.lst) +// Install with 'jsexec logonlist install' + +"use strict"; + +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(); +} + +require("text.js", 'LastFewCallersFmt'); +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(bbs.text(LastFewCallersFmt) + ,record.node + ,record.total + ,record.user.alias + ,record.user.location + ,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.noone_logged_on_fmt || "\r\nNo one logged on %s.", day.toLowerCase())); + console.crlf(); +} -- GitLab