luci-base: tweak dispatcher logging to post under correct facility
authorPaul Donald <[email protected]>
Tue, 8 Jul 2025 12:27:05 +0000 (14:27 +0200)
committerPaul Donald <[email protected]>
Wed, 9 Jul 2025 16:18:00 +0000 (18:18 +0200)
Previously we might see:

... daemon.err uhttpd[5153]: [info] luci: accepted login on / for root from x.x.x.x

Now:

... authpriv.info dispatcher.uc: luci: accepted login on / for root from x.x.x.x

Signed-off-by: Paul Donald <[email protected]>
modules/luci-base/Makefile
modules/luci-base/ucode/dispatcher.uc

index d9832e3393b1a036a3a1e5cf22093aa6b8e3141f..7f5d1809fbc4df656da11644c1d57bda8a2068cd 100644 (file)
@@ -21,6 +21,7 @@ LUCI_DEPENDS:=\
        +cgi-io \
        +ucode \
        +ucode-mod-fs \
+       +ucode-mod-log \
        +ucode-mod-uci \
        +ucode-mod-ubus \
        +ucode-mod-math \
index 2cb8cc2f6cf185d310356b1535d6bb6f78f38447..09e53b885a0f72483b0ceb330069a6022bce2f35 100644 (file)
@@ -6,6 +6,7 @@ import { striptags, entityencode } from 'html';
 import { connect } from 'ubus';
 import { cursor } from 'uci';
 import { rand } from 'math';
+import { openlog, syslog, closelog, LOG_INFO, LOG_WARNING, LOG_AUTHPRIV } from 'log';
 
 import { hash, load_catalog, change_catalog, translate, ntranslate, getuid } from 'luci.core';
 import { revision as luciversion, branch as luciname } from 'luci.version';
@@ -485,10 +486,6 @@ function randomid(num_bytes) {
        return join('', bytes);
 }
 
-function syslog(prio, msg) {
-       warn(sprintf("[%s] %s\n", prio, msg));
-}
-
 function session_setup(user, pass, path) {
        let timeout = uci.get('luci', 'sauth', 'sessiontime');
        let login = ubus.call("session", "login", {
@@ -497,19 +494,22 @@ function session_setup(user, pass, path) {
                timeout:  timeout ? +timeout : null
        });
 
+       openlog('dispatcher.uc');
        if (type(login?.ubus_rpc_session) == 'string') {
                ubus.call("session", "set", {
                        ubus_rpc_session: login.ubus_rpc_session,
                        values: { token: randomid(16) }
                });
-               syslog("info", sprintf("luci: accepted login on /%s for %s from %s",
+               syslog(LOG_INFO|LOG_AUTHPRIV, sprintf("luci: accepted login on /%s for %s from %s",
                        join('/', path), user || "?", http.getenv("REMOTE_ADDR") || "?"));
 
                return session_retrieve(login.ubus_rpc_session);
        }
 
-       syslog("info", sprintf("luci: failed login on /%s for %s from %s",
+       syslog(LOG_WARNING|LOG_AUTHPRIV, sprintf("luci: failed login on /%s for %s from %s",
                join('/', path), user || "?", http.getenv("REMOTE_ADDR") || "?"));
+
+       closelog();
 }
 
 function check_authentication(method) {