本帖最后由 a798047000 于 2021-2-1 13:10 编辑
修改 /usr/libexec/rpcd/luci 添加如下代码
- getCoreInfo = {
- call = function()
- local sys = require “luci.sys”
- local rv = {}
- local freqs = string.split(string.trim(sys.exec(“cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq”)),”\n”)
- local temps = string.split(string.trim(sys.exec(“sensors | grep ‘Core’ | cut -c10-24″)),”\n”)
- local i
- for i = 1, #freqs do
- local freq = string.trim(freqs[i])
- local temp = string.trim(temps[i])
- rv[#rv + 1] = {
- core = “Core ” .. i,
- freq = string.format(“%.2f”, freq / 1000) .. ” MHz”,
- temp = temp
- }
- end
- return {coreinfo = rv}
- end
- },
- getDiskInfo = {
- call = function()
- local sys = require “luci.sys”
- local rv = {}
- local lines = string.split(string.trim(sys.exec(“/bin/df -h | sed ‘s/\\s\\+/ /g’ | uniq”)),”\n”)
- local i
- for i = 2, #lines do
- local tokens = string.split(lines[i], ” “)
- local block = string.trim(tokens[1])
- — ignore block not start with /
- if (string.sub(block, 1, 1) == “/”) then
- rv[#rv + 1] = {
- block = block,
- size = string.trim(tokens[2]),
- used = string.trim(tokens[3]),
- available = string.trim(tokens[4]),
- used_percent = string.trim(tokens[5]),
- mounte_point = string.trim(tokens[6])
- }
- end
- end
- return {diskinfo = rv}
- end
- },
- getETHInfo = {
- call = function()
- local sys = require “luci.sys”
- local rv = {}
- local ethinfo = sys.exec(“/usr/bin/ethinfo”)
- local lines = string.split(string.trim(ethinfo), “\n”)
- local i
- for i = 1, #lines do
- local line = string.trim(lines[i])
- if line == “” then
- else
- local tokens
- tokens = string.split(line, ” “)
- rv[#rv + 1] = {
- name = tokens[1],
- status = tokens[2],
- speed = tokens[3],
- duplex = tokens[4]
- }
- end
- end
- return {ethinfo = rv}
- end
- }
复制代码
安装 lm-sensors 执行命令
- opkg update
- opkg install lm-sensors
复制代码
添加文件 /usr/bin/ethinfo 写入
- #!/bin/sh
- a=$(ip address | grep ^[0-9] | awk -F: ‘{print $2}’ | sed “s/ //g” | grep ‘^[e]’ | grep -v “@” | grep -v “\.”)
- b=$(echo “$a” | wc -l)
- for i in $(seq 1 $b)
- do
- c=$(echo “$a” | sed -n ${i}p)
- d=$(ethtool $c)
- e=$(echo “$d” | grep “Link detected” | awk -F: ‘{printf $2}’ | sed ‘s/^[ \t]*//g’)
- f=$(echo “$d” | grep “Speed” | awk -F: ‘{printf $2}’ | sed ‘s/^[ \t]*//g’ | tr -d “Unknown!”)
- [ -z “$f” ] && f=”-“
- g=$(echo “$d” | grep “Duplex” | awk -F: ‘{printf $2}’ | sed ‘s/^[ \t]*//g’)
- [ “$g” != “Full” -a “$g” != “Half” ] && g=”-“
- echo “$c $e $f $g”
- done
复制代码
并给执行权限,执行
- chmod 755 /usr/bin/ethinfo
复制代码
修改 /usr/share/rpcd/acl.d/luci-base.json 找到
- “luci”: [ “getConntrackList”, “getInitList”, “getLocaltime”, “getProcessList”, “getRealtimeStats”, “getTimezones”, “getLEDs”, “getUSBDevices”, “getSwconfigFeatures”, “getSwconfigPortState”, “getBlockDevices”, “getMountPoints” ],
复制代码
添加 “getCoreInfo”, “getETHInfo”, “getDiskInfo” 改完后是这样的
- “luci”: [ “getConntrackList”, “getInitList”, “getLocaltime”, “getProcessList”, “getRealtimeStats”, “getTimezones”, “getLEDs”, “getUSBDevices”, “getSwconfigFeatures”, “getSwconfigPortState”, “getBlockDevices”, “getMountPoints”, “getCoreInfo”, “getETHInfo”, “getDiskInfo” ],
复制代码
然后将压缩包内的3个文件放入 /www/luci-static/resources/view/status/include/
最后别忘了重启 rpcd 和 uhttpd (或nginx,如果你用nginx替代了uhttpd的话) 服务
- service rpcd restart
- service uhttpd restart
复制代码
最终效果如图
以上方案是直接修改系统文件实现的,没有改源码重新编译,如果想要在源码内修改,可以找到源码下相应的路径和文件,修改即可
由于我这里是直接修改系统文件的,因此没有国际化(翻译),中文文本是直接以unicode编码写到js文件里的
如果需要加入源码编译,建议将对应文本改为英文,然后在po文件内添加相应的翻译文本即可
此帖部分代码来自于 https://www.right.com.cn/forum/thread-1358471-1-1.html 感谢!
多说一句,如果更新了luci-base包,可能会导致修改失效,这主要是因为更新的包覆盖了修改后的文件,这时一般只需要重新在rpc中添加lua方法,然后再json中注册,重启rpcd,就能重新work。如果不行,那就对照教程完整的再来一次吧。 |