🌴 Sync 2026-03-05 23:51:42

This commit is contained in:
github-actions[bot] committed 2026-03-05 23:51:42 +08:00
1 parent 97c049ed0a
commit 0acff03804
14253 files changed
+3893239

No files matched your search

@@ -0,0 +1,19 @@
#!/bin/sh
#
# (c) 2025-2026 by Rafał Wabik (IceG) <https://github.com/4IceG>
#
# From eko.one.pl forum
#
DB=/tmp/easyconfig_statistics.json
SDB=/usr/lib/easyconfig/
CURRENT_YEAR=$(date +"%Y")
PREVIOUS_YEAR=$((CURRENT_YEAR - 1))
NEW_ST="easyconfig_statistics_${PREVIOUS_YEAR}.json"
mv "$DB" "$NEW_ST$SDB"
sleep 5
echo "{}" > /tmp/easyconfig_statistics.json
exit 0
@@ -0,0 +1,117 @@
#!/bin/sh
#
# (c) 2024 Cezary Jackiewicz <cezary@eko.one.pl>
#
# (c) 2024-2026 modified by Rafał Wabik (IceG) <https://github.com/4IceG>
#
# From eko.one.pl forum
#
TIMEISVALID=""
grep -q "time is valid" /tmp/state/dnsmasqsec 2>/dev/null && TIMEISVALID="yes"
[ -e /dev/rtc0 ] && TIMEISVALID="yes"
[ -z "$TIMEISVALID" ] && exit 0
DB=/tmp/easyconfig_statistics.json
SDB=/usr/lib/easyconfig/easyconfig_statistics.json.gz
LOCK=/var/lock/easyconfig_statistics.lock
lock $LOCK
MBACKUP=$(uci -q get easyconfig_transfer.traffic.external_backup)
MBACKUPATH=$(uci -q get easyconfig_transfer.traffic.external_path)
EXTERNAL_JSON="$MBACKUPATH/easyconfig_statistics.json"
if [ ! -e "$DB" ]; then
if [ "$MBACKUP" = "1" ] && [ -n "$MBACKUPATH" ] && [ -e "$EXTERNAL_JSON" ] && [ -e "$SDB" ]; then
TMP_GZ=/tmp/easyconfig_statistics_gz_tmp.json
zcat "$SDB" > "$TMP_GZ" 2>/dev/null
if [ -e "$TMP_GZ" ]; then
EXT_SIZE=$(wc -c < "$EXTERNAL_JSON")
GZ_SIZE=$(wc -c < "$TMP_GZ")
if [ "$EXT_SIZE" -gt "$GZ_SIZE" ]; then
cp "$EXTERNAL_JSON" "$DB"
else
cp "$TMP_GZ" "$DB"
easyconfig_statistics.uc "init" "init" 0 0 0 "" 0
fi
rm -f "$TMP_GZ"
else
cp "$EXTERNAL_JSON" "$DB"
fi
elif [ "$MBACKUP" = "1" ] && [ -n "$MBACKUPATH" ] && [ -e "$EXTERNAL_JSON" ]; then
cp "$EXTERNAL_JSON" "$DB"
elif [ -e "$SDB" ]; then
zcat "$SDB" > "$DB"
easyconfig_statistics.uc "init" "init" 0 0 0 "" 0
else
mkdir -p $(dirname "$SDB")
echo "{}" > "$DB"
fi
else
if [ "$MBACKUP" = "1" ] && [ -n "$MBACKUPATH" ] && [ -e "$EXTERNAL_JSON" ]; then
EXT_SIZE=$(wc -c < "$EXTERNAL_JSON")
DB_SIZE=$(wc -c < "$DB")
if [ "$EXT_SIZE" -gt "$DB_SIZE" ]; then
cp "$EXTERNAL_JSON" "$DB"
fi
fi
fi
# lan
BRIDGE=$(ubus call network.interface.lan status | jsonfilter -q -e @.l3_device)
if [ -e /sys/class/net/$BRIDGE/bridge ]; then
for I in /sys/class/net/$BRIDGE/lower_*; do
IFNAME=${I##*lower_}
if [ -e $I/phy80211 ]; then
STATIONS=$(iw dev "$IFNAME" station dump | awk -v IFNAME="$IFNAME" '{if($1 == "Station") {MAC=$2;station[MAC]=1} if($0 ~ /rx bytes:/) {rx[MAC]=$3} if($0 ~ /tx bytes:/) {tx[MAC]=$3} if($0 ~ /connected time:/) {connected[MAC]=$3}} END {for (w in station) {printf "%s;%s;%s;%s;%s\n", w, IFNAME, tx[w], rx[w], connected[w]}}')
for S in $STATIONS; do
DHCPNAME=$(awk '/'$(echo "$S" | cut -f1 -d";")'/{if ($4 != "*") {print $4}}' /tmp/dhcp.leases)
# easyconfig_statistics.uc $(echo "$S" | cut -f1 -d";") $(echo "$S" | cut -f2 -d";") $(echo "$S" | cut -f3 -d";") $(echo "$S" | cut -f4 -d";") $(echo "$S" | cut -f5 -d";") "$DHCPNAME" 2
easyconfig_statistics.uc ${S//;/ } "$DHCPNAME" 2
done
else
PORTID=$(printf "%d" $(cat /sys/class/net/$BRIDGE/brif/$IFNAME/port_no))
STATIONS=$(brctl showmacs $BRIDGE 2>/dev/null | awk '/^\s*'$PORTID'\s.*no/{print $2}')
for S in $STATIONS; do
DHCPNAME=$(awk '/'$S'/{if ($4 != "*") {print $4}}' /tmp/dhcp.leases)
easyconfig_statistics.uc "$S" "$IFNAME" 0 0 999 "$DHCPNAME" 1
done
fi
done
fi
# wan
WNAME=$(uci -q get easyconfig_transfer.global.network)
IFNAME=$(ubus call network.interface.$WNAME status | jsonfilter -q -e @.l3_device)
[ -n "$IFNAME" ] && easyconfig_statistics.uc "wan" "$IFNAME" $(cat /sys/class/net/$IFNAME/statistics/tx_bytes) $(cat /sys/class/net/$IFNAME/statistics/rx_bytes) 999 "" 0
PERIOD=$(uci -q get easyconfig_transfer.global.datarec_period)
[ -z "$PERIOD" ] && PERIOD=0
if [ "$PERIOD" = "0" ]; then
lock -u $LOCK
exit 0
fi
NOW=$(date +%s)
if [ -e "$SDB" ]; then
DBTS=$(date +%s -r "$SDB")
WRITETS=$((DBTS + (PERIOD * 60)))
else
WRITETS=$((NOW - 1))
fi
if [ $WRITETS -le $NOW ]; then
gzip -k "$DB"
mv "$DB.gz" "$SDB"
sync
fi
if [ "$MBACKUP" = "1" ]; then
sleep 10
cp "$DB" "$MBACKUPATH/easyconfig_statistics.json"
fi
lock -u $LOCK
exit 0
@@ -0,0 +1,151 @@
#!/usr/bin/ucode
'use strict';
//
// (c) 2023 Cezary Jackiewicz <cezary@eko.one.pl>
//
// (c) 2025-2026 modified by Rafał Wabik (IceG) <https://github.com/4IceG>
//
// From eko.one.pl forum
//
import { readfile, writefile } from "fs";
let filename = `/tmp/easyconfig_statistics.json`;
let MAC = shift(ARGV);
let IFNAME = shift(ARGV);
let TX = shift(ARGV);
let RX = shift(ARGV);
let CONNECTED = shift(ARGV);
let DHCPNAME = shift(ARGV);
let TYPE = shift(ARGV);
if (!MAC || !IFNAME || !TYPE) {
warn("Usage: easyconfig_statistics.uc <MAC> <IFNAME> <TX> <RX> <CONNECTED> <DHCPNAME> <TYPE>\n");
exit(1);
}
// compatibility with old scripts
MAC = replace(MAC, /:/g, "_");
if (!CONNECTED) CONNECTED = 0;
if (!TX) TX = 0;
if (!RX) RX = 0;
TX = int(TX);
RX = int(RX);
TYPE = int(TYPE);
CONNECTED = int(CONNECTED);
let ts = localtime();
let day = sprintf("%04d%02d%02d", ts.year, ts.mon, ts.mday);
let hour = sprintf("%02d", ts.hour);
let ts_now = sprintf("%04d%02d%02d%02d%02d", ts.year, ts.mon, ts.mday, ts.hour, ts.min);
let db = {};
let content = readfile(filename);
if (content) {
try { db = json(content); }
catch { db = {}; }
}
let tmp = null;
if (IFNAME == "init") {
for (let key1 in db) {
if (type(db[key1]) == "object") {
for (let key2 in db[key1]) {
if (type(db[key1][key2]) == "object") {
db[key1][key2].last_tx = 0;
db[key1][key2].last_rx = 0;
}
}
}
}
writefile(filename, db);
exit(0)
}
if (IFNAME == "delete") {
tmp = db[MAC];
if (tmp) {
delete db[MAC];
writefile(filename, db);
}
exit(0)
}
tmp = db[MAC];
if (!tmp) {
db[MAC] = {};
db[MAC].first_seen = ts_now;
}
if (DHCPNAME)
db[MAC].dhcpname = DHCPNAME;
db[MAC].type = TYPE;
tmp = db[MAC][IFNAME];
if (!tmp) {
db[MAC][IFNAME] = {};
db[MAC][IFNAME].last_tx = 0;
db[MAC][IFNAME].last_rx = 0;
db[MAC][IFNAME].first_seen = ts_now;
}
let last_tx = int(db[MAC][IFNAME].last_tx);
let last_rx = int(db[MAC][IFNAME].last_rx);
tmp = db[MAC][IFNAME][day];
if (!tmp) {
db[MAC][IFNAME][day] = {};
db[MAC][IFNAME][day].total_tx = 0;
db[MAC][IFNAME][day].total_rx = 0;
db[MAC][IFNAME][day].hours = {};
}
if (!db[MAC][IFNAME][day].hours)
db[MAC][IFNAME][day].hours = {};
let total_tx = int(db[MAC][IFNAME][day].total_tx);
let total_rx = int(db[MAC][IFNAME][day].total_rx);
let dtx = TX - last_tx;
if (dtx < 0) dtx = TX;
let drx = RX - last_rx;
if (drx < 0) drx = RX;
if (CONNECTED <= 60) {
dtx = TX;
drx = RX;
}
db[MAC][IFNAME][day].total_tx = total_tx + dtx;
db[MAC][IFNAME][day].total_rx = total_rx + drx;
// Dodaj statystyki godzinowe tylko jeśli był jakiś ruch danych
if (dtx > 0 || drx > 0) {
if (!db[MAC][IFNAME][day].hours[hour]) {
db[MAC][IFNAME][day].hours[hour] = {
total_tx: 0,
total_rx: 0
};
}
let hour_tx = int(db[MAC][IFNAME][day].hours[hour].total_tx);
let hour_rx = int(db[MAC][IFNAME][day].hours[hour].total_rx);
db[MAC][IFNAME][day].hours[hour].total_tx = hour_tx + dtx;
db[MAC][IFNAME][day].hours[hour].total_rx = hour_rx + drx;
}
db[MAC][IFNAME].last_tx = TX;
db[MAC][IFNAME].last_rx = RX;
db[MAC][IFNAME].last_seen = ts_now;
db[MAC].last_seen = ts_now;
writefile(filename, db);
exit(0);
@@ -0,0 +1,33 @@
{
"admin/network/transfer": {
"title": "Transfer statistics",
"order": 60,
"action": {
"type": "alias",
"path": "admin/network/transfer/details"
},
"depends": {
"acl": [ "luci-app-easyconfig-transfer" ]
}
},
"admin/network/transfer/details": {
"title": "Transfer statistics",
"order": 10,
"action": {
"type": "view",
"path": "transfer/details"
}
},
"admin/network/transfer/config": {
"title": "Configuration",
"order": 20,
"action": {
"type": "view",
"path": "transfer/config"
}
}
}
@@ -0,0 +1,62 @@
{
"luci-app-easyconfig-transfer": {
"description": "Grant access to LuCI app easyconfig transfer",
"read": {
"cgi-io": [ "exec", "download" ],
"ubus": {
"luci-rpc": [ "getDHCPLeases" ],
"file": [ "read" ]
},
"file": {
"/bin/cp": [ "exec" ],
"/bin/lock": [ "exec" ],
"/bin/mkdir": [ "exec" ],
"/bin/rm": [ "exec" ],
"/bin/gzip -t /tmp/easyconfig_statistics.json.gz": [ "exec" ],
"/bin/gzip -d /tmp/easyconfig_statistics.json.gz": [ "exec" ],
"/bin/gzip -k /tmp/easyconfig_statistics.json": [ "exec" ],
"/usr/bin/easyconfig_statistics.uc": [ "exec" ],
"/usr/bin/easyconfig_statistics.sh": [ "exec" ],
"/usr/bin/auto_reset_statistics.sh": [ "exec" ],
"/sbin/transfer2cron.sh": [ "exec" ],
"/sbin/backup2cron.sh": [ "exec" ],
"/sbin/ar2cron.sh": [ "exec" ],
"/tmp/easyconfig_statistics.json": [ "read" ],
"/tmp/easyconfig_statistics_gz_tmp.json": [ "read" ],
"/tmp/dhcp.leases": [ "read" ],
"/usr/lib/easyconfig/easyconfig_statistics.json.gz": [ "read" ],
"/usr/lib/easyconfig/easyconfig_statistics.json": [ "read" ],
"/var/lock/easyconfig_statistics.lock": [ "read" ],
"/etc/config/easyconfig_transfer": [ "read" ],
"/mnt/easyconfig_statistics.json": [ "read" ]
},
"uci": [ "easyconfig_transfer" ]
},
"write": {
"cgi-io": [ "exec", "upload" ],
"file": {
"/bin/cp": [ "exec" ],
"/bin/mkdir": [ "exec" ],
"/bin/rm": [ "exec" ],
"/usr/bin/easyconfig_statistics.uc": [ "exec" ],
"/usr/bin/easyconfig_statistics.sh": [ "exec" ],
"/usr/bin/auto_reset_statistics.sh": [ "exec" ],
"/sbin/transfer2cron.sh": [ "exec" ],
"/sbin/backup2cron.sh": [ "exec" ],
"/sbin/ar2cron.sh": [ "exec" ],
"/tmp/easyconfig_statistics.json": [ "write" ],
"/tmp/easyconfig_statistics.json.gz": [ "write" ],
"/tmp/easyconfig_statistics_gz_tmp.json": [ "write" ],
"/usr/lib/easyconfig/easyconfig_statistics.json.gz": [ "write" ],
"/usr/lib/easyconfig/easyconfig_statistics.json": [ "write" ],
"/var/lock/easyconfig_statistics.lock": [ "write" ],
"/etc/config/easyconfig_transfer": [ "write" ],
"/mnt/easyconfig_statistics.json": [ "write" ]
},
"ubus": {
"file": [ "remove", "write" ]
},
"uci": [ "easyconfig_transfer" ]
}
}
}