Initial commit
This commit is contained in:
commit
0475eb7e59
43
bash-completion/Makefile
Normal file
43
bash-completion/Makefile
Normal file
@ -0,0 +1,43 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=bash-completion
|
||||
PKG_VERSION:=2.14.0
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
|
||||
PKG_SOURCE_URL:=https://github.com/scop/bash-completion/releases/download/$(PKG_VERSION)
|
||||
PKG_HASH:=5c7494f968280832d6adb5aa19f745a56f1a79df311e59338c5efa6f7285e168
|
||||
|
||||
PKG_MAINTAINER:=sbwml <admin@cooluc.com>
|
||||
PKG_LICENSE:=GPL-2.0
|
||||
PKG_LICENSE_FILES:=COPYING
|
||||
|
||||
PKG_INSTALL:=1
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/bash-completion
|
||||
SECTION:=utils
|
||||
CATEGORY:=Utilities
|
||||
SUBMENU:=Shells
|
||||
TITLE:=Programmable completion functions for bash
|
||||
URL:=https://github.com/scop/bash-completion
|
||||
DEPENDS:=+bash
|
||||
endef
|
||||
|
||||
define Package/bash-completion/description
|
||||
bash-completion is a collection of command line command completions for the Bash shell,
|
||||
collection of helper functions to assist in creating new completions,
|
||||
and set of facilities for loading completions automatically on demand, as well as installing them.
|
||||
endef
|
||||
|
||||
define Package/bash-completion/install
|
||||
$(INSTALL_DIR) $(1)/etc/profile.d
|
||||
$(CP) $(PKG_INSTALL_DIR)/etc/profile.d/* $(1)/etc/profile.d/
|
||||
$(INSTALL_DIR) $(1)/usr/share/bash-completion
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/share/bash-completion/* $(1)/usr/share/bash-completion/
|
||||
$(INSTALL_DIR) $(1)/etc/bash_completion.d
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,bash-completion))
|
57
coremark/Makefile
Normal file
57
coremark/Makefile
Normal file
@ -0,0 +1,57 @@
|
||||
#
|
||||
# Copyright (C) 2018 Lim Guo Wei
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=coremark
|
||||
PKG_VERSION:=2023.01.25~d5fad6bd
|
||||
PKG_RELEASE:=1
|
||||
|
||||
ifeq ($(CONFIG_USE_MUSL),y)
|
||||
PKG_LIBC:=musl
|
||||
else
|
||||
PKG_LIBC:=glibc
|
||||
endif
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/coremark
|
||||
SECTION:=utils
|
||||
CATEGORY:=Utilities
|
||||
TITLE:=CoreMark Embedded Microprocessor Benchmark
|
||||
DEPENDS:=@(aarch64||x86_64)
|
||||
URL:=https://github.com/eembc/coremark
|
||||
endef
|
||||
|
||||
define Package/coremark/description
|
||||
Embedded Microprocessor Benchmark
|
||||
endef
|
||||
|
||||
define Package/coremark/conffiles
|
||||
/etc/bench.log
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
endef
|
||||
|
||||
define Package/coremark/install
|
||||
$(INSTALL_DIR) $(1)/bin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_LIBC)/coremark.$(ARCH) $(1)/bin/coremark
|
||||
$(INSTALL_DIR) $(1)/etc
|
||||
$(INSTALL_BIN) ./coremark.sh $(1)/etc/
|
||||
$(INSTALL_DIR) $(1)/etc/uci-defaults
|
||||
$(INSTALL_BIN) ./coremark $(1)/etc/uci-defaults/xxx-coremark
|
||||
endef
|
||||
|
||||
define Package/coremark/postinst
|
||||
#!/bin/sh
|
||||
[ -n "$${IPKG_INSTROOT}" ] || sed -i '/coremark/d' /etc/crontabs/root
|
||||
[ -n "$${IPKG_INSTROOT}" ] || echo "0 4 * * * /etc/coremark.sh" >> /etc/crontabs/root
|
||||
[ -n "$${IPKG_INSTROOT}" ] || crontab /etc/crontabs/root
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,coremark))
|
7
coremark/coremark
Executable file
7
coremark/coremark
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
sed -i '/coremark/d' /etc/crontabs/root
|
||||
echo "0 4 * * * /etc/coremark.sh" >> /etc/crontabs/root
|
||||
crontab /etc/crontabs/root
|
||||
|
||||
touch /etc/bench.log
|
12
coremark/coremark.sh
Executable file
12
coremark/coremark.sh
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
/bin/coremark > /tmp/coremark.log
|
||||
|
||||
cat /tmp/coremark.log | grep "CoreMark 1.0" | cut -d "/" -f 1 > /etc/bench.log
|
||||
sed -i 's/CoreMark 1.0/ (CpuMark/g' /etc/bench.log
|
||||
echo " Scores)" >> /etc/bench.log
|
||||
|
||||
if [ -f "/etc/bench.log" ]; then
|
||||
sed -i '/coremark/d' /etc/crontabs/root
|
||||
crontab /etc/crontabs/root
|
||||
fi
|
BIN
coremark/src/glibc/coremark.aarch64
Normal file
BIN
coremark/src/glibc/coremark.aarch64
Normal file
Binary file not shown.
BIN
coremark/src/glibc/coremark.x86_64
Normal file
BIN
coremark/src/glibc/coremark.x86_64
Normal file
Binary file not shown.
BIN
coremark/src/musl/coremark.aarch64
Normal file
BIN
coremark/src/musl/coremark.aarch64
Normal file
Binary file not shown.
BIN
coremark/src/musl/coremark.x86_64
Normal file
BIN
coremark/src/musl/coremark.x86_64
Normal file
Binary file not shown.
56
ddns-scripts-aliyun/Makefile
Normal file
56
ddns-scripts-aliyun/Makefile
Normal file
@ -0,0 +1,56 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=ddns-scripts-aliyun
|
||||
PKG_VERSION:=1.0.3
|
||||
PKG_RELEASE:=6
|
||||
|
||||
PKG_LICENSE:=GPLv2
|
||||
PKG_MAINTAINER:=Sense <sensec@gmail.com>
|
||||
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/$(PKG_NAME)
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
SUBMENU:=IP Addresses and Names
|
||||
TITLE:=DDNS extension for AliYun.com
|
||||
PKGARCH:=all
|
||||
DEPENDS:=+ddns-scripts +curl +jsonfilter +openssl-util
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/description
|
||||
Dynamic DNS Client scripts extension for AliYun.com
|
||||
endef
|
||||
|
||||
define Build/Configure
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
$(CP) ./*.sh $(PKG_BUILD_DIR)
|
||||
# remove comments, white spaces and empty lines
|
||||
for FILE in `find $(PKG_BUILD_DIR) -type f`; do \
|
||||
$(SED) 's/^[[:space:]]*//' \
|
||||
-e '/^#[[:space:]]\|^#$$$$/d' \
|
||||
-e 's/[[:space:]]#[[:space:]].*$$$$//' \
|
||||
-e 's/[[:space:]]*$$$$//' \
|
||||
-e '/^\/\/[[:space:]]/d' \
|
||||
-e '/^[[:space:]]*$$$$/d' $$$$FILE; \
|
||||
done
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib/ddns
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/update_aliyun_com.sh $(1)/usr/lib/ddns
|
||||
$(INSTALL_DIR) $(1)/usr/share/ddns/default
|
||||
$(INSTALL_DATA) ./aliyun.com.json $(1)/usr/share/ddns/default
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/prerm
|
||||
#!/bin/sh
|
||||
[ -z "$${IPKG_INSTROOT}" ] && /etc/init.d/ddns stop >/dev/null 2>&1
|
||||
exit 0 # suppress errors
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,$(PKG_NAME)))
|
2
ddns-scripts-aliyun/README.md
Normal file
2
ddns-scripts-aliyun/README.md
Normal file
@ -0,0 +1,2 @@
|
||||
# ddns-scripts-aliyun
|
||||
基于https://github.com/sensec/ddns-scripts_aliyun 改进,将wget替换为curl,并且完善了逻辑判断,日志可以显示更新失败时的原因
|
9
ddns-scripts-aliyun/aliyun.com.json
Normal file
9
ddns-scripts-aliyun/aliyun.com.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "aliyun.com",
|
||||
"ipv4": {
|
||||
"url": "update_aliyun_com.sh"
|
||||
},
|
||||
"ipv6": {
|
||||
"url": "update_aliyun_com.sh"
|
||||
}
|
||||
}
|
205
ddns-scripts-aliyun/update_aliyun_com.sh
Normal file
205
ddns-scripts-aliyun/update_aliyun_com.sh
Normal file
@ -0,0 +1,205 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# 用于阿里云解析的DNS更新脚本
|
||||
# 阿里云解析API文档 https://help.aliyun.com/document_detail/29739.html
|
||||
#
|
||||
# 本脚本由 dynamic_dns_functions.sh 内的函数 send_update() 调用
|
||||
#
|
||||
# 需要在 /etc/config/ddns 中设置的选项
|
||||
# option username - 阿里云API访问账号 Access Key ID。可通过 aliyun.com 帐号管理的 accesskeys 获取, 或者访问 https://ak-console.aliyun.com
|
||||
# option password - 阿里云API访问密钥 Access Key Secret
|
||||
# option domain - 完整的域名。建议主机与域名之间使用 @符号 分隔,否则将以第一个 .符号 之前的内容作为主机名
|
||||
#
|
||||
|
||||
# 检查传入参数
|
||||
[ -z "$username" ] && write_log 14 "Configuration error! The 'username' that holds the Alibaba Cloud API access account cannot be empty"
|
||||
[ -z "$password" ] && write_log 14 "Configuration error! The 'password' that holds the Alibaba Cloud API access account cannot be empty"
|
||||
|
||||
# 检查外部调用工具
|
||||
[ -n "$CURL_SSL" ] || write_log 13 "Alibaba Cloud API communication require cURL with SSL support. Please install"
|
||||
[ -n "$CURL_PROXY" ] || write_log 13 "cURL: libcurl compiled without Proxy support"
|
||||
command -v sed >/dev/null 2>&1 || write_log 13 "Sed support is required to use Alibaba Cloud API, please install first"
|
||||
command -v openssl >/dev/null 2>&1 || write_log 13 "Openssl-util support is required to use Alibaba Cloud API, please install first"
|
||||
|
||||
# 变量声明
|
||||
local __HOST __DOMAIN __TYPE __CMDBASE __RECID __TTL
|
||||
|
||||
# 从 $domain 分离主机和域名
|
||||
[ "${domain:0:2}" = "@." ] && domain="${domain/./}" # 主域名处理
|
||||
[ "$domain" = "${domain/@/}" ] && domain="${domain/./@}" # 未找到分隔符,兼容常用域名格式
|
||||
__HOST="${domain%%@*}"
|
||||
__DOMAIN="${domain#*@}"
|
||||
[ -z "$__HOST" -o "$__HOST" = "$__DOMAIN" ] && __HOST=@
|
||||
|
||||
# 设置记录类型
|
||||
[ $use_ipv6 = 0 ] && __TYPE=A || __TYPE=AAAA
|
||||
|
||||
# 构造基本通信命令
|
||||
build_command(){
|
||||
__CMDBASE="$CURL -Ss"
|
||||
# 绑定用于通信的主机/IP
|
||||
if [ -n "$bind_network" ];then
|
||||
local __DEVICE
|
||||
network_get_physdev __DEVICE $bind_network || write_log 13 "Can not detect local device using 'network_get_physdev $bind_network' - Error: '$?'"
|
||||
write_log 7 "Force communication via device '$__DEVICE'"
|
||||
__CMDBASE="$__CMDBASE --interface $__DEVICE"
|
||||
fi
|
||||
# 强制设定IP版本
|
||||
if [ $force_ipversion = 1 ];then
|
||||
[ $use_ipv6 = 0 ] && __CMDBASE="$__CMDBASE -4" || __CMDBASE="$__CMDBASE -6"
|
||||
fi
|
||||
# 设置CA证书参数
|
||||
if [ $use_https = 1 ];then
|
||||
if [ "$cacert" = IGNORE ];then
|
||||
__CMDBASE="$__CMDBASE --insecure"
|
||||
elif [ -f "$cacert" ];then
|
||||
__CMDBASE="$__CMDBASE --cacert $cacert"
|
||||
elif [ -d "$cacert" ];then
|
||||
__CMDBASE="$__CMDBASE --capath $cacert"
|
||||
elif [ -n "$cacert" ];then
|
||||
write_log 14 "No valid certificate(s) found at '$cacert' for HTTPS communication"
|
||||
fi
|
||||
fi
|
||||
# 如果没有设置,禁用代理 (这可能是 .wgetrc 或环境设置错误)
|
||||
[ -z "$proxy" ] && __CMDBASE="$__CMDBASE --noproxy '*'"
|
||||
}
|
||||
|
||||
# 百分号编码
|
||||
percentEncode(){
|
||||
if [ -z "${1//[A-Za-z0-9_.~-]/}" ];then
|
||||
echo -n "$1"
|
||||
else
|
||||
local string=$1;local i=0;local ret chr
|
||||
while [ $i -lt ${#string} ];do
|
||||
chr=${string:$i:1}
|
||||
[ -z "${chr#[^A-Za-z0-9_.~-]}" ] && chr=$(printf '%%%02X' "'$chr")
|
||||
ret="$ret$chr"
|
||||
i=$(( $i + 1 ))
|
||||
done
|
||||
echo -n "$ret"
|
||||
fi
|
||||
}
|
||||
|
||||
# 用于阿里云API的通信函数
|
||||
aliyun_transfer(){
|
||||
__CNT=0;__URLARGS=
|
||||
[ $# = 0 ] && write_log 12 "'aliyun_transfer()' Error - wrong number of parameters"
|
||||
# 添加请求参数
|
||||
for string in $*;do
|
||||
case "${string%%=*}" in
|
||||
Format|Version|AccessKeyId|SignatureMethod|Timestamp|SignatureVersion|SignatureNonce|Signature);; # 过滤公共参数
|
||||
*)__URLARGS="$__URLARGS&"$(percentEncode "${string%%=*}")"="$(percentEncode "${string#*=}");;
|
||||
esac
|
||||
done
|
||||
__URLARGS="${__URLARGS:1}"
|
||||
# 附加公共参数
|
||||
string="Format=JSON";__URLARGS="$__URLARGS&"$(percentEncode "${string%%=*}")"="$(percentEncode "${string#*=}")
|
||||
string="Version=2015-01-09";__URLARGS="$__URLARGS&"$(percentEncode "${string%%=*}")"="$(percentEncode "${string#*=}")
|
||||
string="AccessKeyId=$username";__URLARGS="$__URLARGS&"$(percentEncode "${string%%=*}")"="$(percentEncode "${string#*=}")
|
||||
string="SignatureMethod=HMAC-SHA1";__URLARGS="$__URLARGS&"$(percentEncode "${string%%=*}")"="$(percentEncode "${string#*=}")
|
||||
string="Timestamp="$(date -u '+%Y-%m-%dT%H:%M:%SZ');__URLARGS="$__URLARGS&"$(percentEncode "${string%%=*}")"="$(percentEncode "${string#*=}")
|
||||
string="SignatureVersion=1.0";__URLARGS="$__URLARGS&"$(percentEncode "${string%%=*}")"="$(percentEncode "${string#*=}")
|
||||
string="SignatureNonce="$(cat '/proc/sys/kernel/random/uuid');__URLARGS="$__URLARGS&"$(percentEncode "${string%%=*}")"="$(percentEncode "${string#*=}")
|
||||
string="Line=default";__URLARGS="$__URLARGS&"$(percentEncode "${string%%=*}")"="$(percentEncode "${string#*=}")
|
||||
# 对请求参数进行排序,用于生成签名
|
||||
string=$(echo -n "$__URLARGS" | sed 's/\'"&"'/\n/g' | sort | sed ':label; N; s/\n/\'"&"'/g; b label')
|
||||
# 构造用于计算签名的字符串
|
||||
string="GET&"$(percentEncode "/")"&"$(percentEncode "$string")
|
||||
# 字符串计算签名值
|
||||
local signature=$(echo -n "$string" | openssl dgst -sha1 -hmac "$password&" -binary | openssl base64)
|
||||
# 附加签名参数
|
||||
string="Signature=$signature";__URLARGS="$__URLARGS&"$(percentEncode "${string%%=*}")"="$(percentEncode "${string#*=}")
|
||||
__A="$__CMDBASE 'https://alidns.aliyuncs.com/?$__URLARGS'"
|
||||
write_log 7 "#> $__A"
|
||||
while ! __TMP=`eval $__A 2>&1`;do
|
||||
write_log 3 "[$__TMP]"
|
||||
if [ $VERBOSE -gt 1 ];then
|
||||
write_log 4 "Transfer failed - detailed mode: $VERBOSE - Do not try again after an error"
|
||||
return 1
|
||||
fi
|
||||
__CNT=$(( $__CNT + 1 ))
|
||||
[ $retry_count -gt 0 -a $__CNT -gt $retry_count ] && write_log 14 "Transfer failed after $retry_count retries"
|
||||
write_log 4 "Transfer failed - $__CNT Try again in $RETRY_SECONDS seconds"
|
||||
sleep $RETRY_SECONDS &
|
||||
PID_SLEEP=$!
|
||||
wait $PID_SLEEP
|
||||
PID_SLEEP=0
|
||||
done
|
||||
__ERR=`jsonfilter -s "$__TMP" -e "@.Code"`
|
||||
[ -z "$__ERR" ] && return 0
|
||||
case $__ERR in
|
||||
LastOperationNotFinished)printf "%s\n" " $(date +%H%M%S) : 最后一次操作未完成,2秒后重试" >> $LOGFILE;return 1;;
|
||||
InvalidTimeStamp.Expired)printf "%s\n" " $(date +%H%M%S) : 时间戳错误,2秒后重试" >> $LOGFILE;return 1;;
|
||||
InvalidAccessKeyId.NotFound)__ERR="无效AccessKey ID";;
|
||||
SignatureDoesNotMatch)__ERR="无效AccessKey Secret";;
|
||||
InvalidDomainName.NoExist)__ERR="无效域名";;
|
||||
esac
|
||||
local A="$(date +%H%M%S) ERROR : [$__ERR] - 终止进程"
|
||||
logger -p user.err -t ddns-scripts[$$] $SECTION_ID: ${A:15}
|
||||
printf "%s\n" " $A" >> $LOGFILE
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 添加解析记录
|
||||
add_domain(){
|
||||
while ! aliyun_transfer "Action=AddDomainRecord" "DomainName=$__DOMAIN" "RR=$__HOST" "Type=$__TYPE" "Value=$__IP";do
|
||||
sleep 2
|
||||
done
|
||||
printf "%s\n" " $(date +%H%M%S) : 添加解析记录成功: [$([ "$__HOST" = @ ] || echo $__HOST.)$__DOMAIN],[IP:$__IP]" >> $LOGFILE
|
||||
}
|
||||
|
||||
# 启用解析记录
|
||||
enable_domain(){
|
||||
while ! aliyun_transfer "Action=SetDomainRecordStatus" "RecordId=$__RECID" "Status=Enable";do
|
||||
sleep 2
|
||||
done
|
||||
printf "%s\n" " $(date +%H%M%S) : 启用解析记录成功" >> $LOGFILE
|
||||
}
|
||||
|
||||
# 修改解析记录
|
||||
update_domain(){
|
||||
while ! aliyun_transfer "Action=UpdateDomainRecord" "RecordId=$__RECID" "RR=$__HOST" "Type=$__TYPE" "Value=$__IP" "TTL=$__TTL";do
|
||||
sleep 2
|
||||
done
|
||||
printf "%s\n" " $(date +%H%M%S) : 修改解析记录成功: [$([ "$__HOST" = @ ] || echo $__HOST.)$__DOMAIN],[IP:$__IP],[TTL:$__TTL]" >> $LOGFILE
|
||||
}
|
||||
|
||||
# 获取子域名解析记录列表
|
||||
describe_domain(){
|
||||
ret=0
|
||||
while ! aliyun_transfer "Action=DescribeSubDomainRecords" "SubDomain=$__HOST.$__DOMAIN" "Type=$__TYPE";do
|
||||
sleep 2
|
||||
done
|
||||
__TMP=`jsonfilter -s "$__TMP" -e "@.DomainRecords.Record[@]"`
|
||||
if [ -z "$__TMP" ];then
|
||||
printf "%s\n" " $(date +%H%M%S) : 解析记录不存在: [$([ "$__HOST" = @ ] || echo $__HOST.)$__DOMAIN]" >> $LOGFILE
|
||||
ret=1
|
||||
else
|
||||
__STATUS=`jsonfilter -s "$__TMP" -e "@.Status"`
|
||||
__RECIP=`jsonfilter -s "$__TMP" -e "@.Value"`
|
||||
if [ "$__STATUS" != ENABLE ];then
|
||||
printf "%s\n" " $(date +%H%M%S) : 解析记录被禁用" >> $LOGFILE
|
||||
ret=$(( $ret | 2 ))
|
||||
fi
|
||||
if [ "$__RECIP" != "$__IP" ];then
|
||||
__TTL=`jsonfilter -s "$__TMP" -e "@.TTL"`
|
||||
printf "%s\n" " $(date +%H%M%S) : 解析记录需要更新: [解析记录IP:$__RECIP] [本地IP:$__IP]" >> $LOGFILE
|
||||
ret=$(( $ret | 4 ))
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
build_command
|
||||
describe_domain
|
||||
if [ $ret = 0 ];then
|
||||
printf "%s\n" " $(date +%H%M%S) : 解析记录不需要更新: [解析记录IP:$__RECIP] [本地IP:$__IP]" >> $LOGFILE
|
||||
elif [ $ret = 1 ];then
|
||||
sleep 3
|
||||
add_domain
|
||||
else
|
||||
__RECID=`jsonfilter -s "$__TMP" -e "@.RecordId"`
|
||||
[ $(( $ret & 2 )) -ne 0 ] && sleep 3 && enable_domain
|
||||
[ $(( $ret & 4 )) -ne 0 ] && sleep 3 && update_domain
|
||||
fi
|
||||
|
||||
return 0
|
78
filebrowser/Makefile
Normal file
78
filebrowser/Makefile
Normal file
@ -0,0 +1,78 @@
|
||||
#
|
||||
# Copyright (C) 2015-2016 OpenWrt.org
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v3.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_ARCH_filebrowser:=$(ARCH)
|
||||
|
||||
PKG_NAME:=filebrowser
|
||||
PKG_VERSION:=2.31.2
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
|
||||
PKG_CONFIG_DEPENDS:=CONFIG_FILEBROWSER_COMPRESS_UPX
|
||||
|
||||
ifeq ($(ARCH),x86_64)
|
||||
PKG_ARCH:=amd64
|
||||
endif
|
||||
|
||||
ifeq ($(ARCH),aarch64)
|
||||
PKG_ARCH:=arm64
|
||||
endif
|
||||
|
||||
ifeq ($(ARCH),arm)
|
||||
PKG_ARCH:=armv7
|
||||
endif
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/$(PKG_NAME)
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
SUBMENU:=Web Servers/Proxies
|
||||
TITLE:=filebrowser
|
||||
DEPENDS:=@(arm||aarch64||x86_64)
|
||||
URL:=https://filebrowser.org/
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/description
|
||||
File Browser is a create-your-own-cloud-kind of software where you can install it on a server
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/config
|
||||
config FILEBROWSER_COMPRESS_UPX
|
||||
bool "Compress executable files with UPX"
|
||||
default n
|
||||
endef
|
||||
|
||||
define Download/$(PKG_NAME)
|
||||
URL:=https://github.com/filebrowser/filebrowser/releases/download/v$(PKG_VERSION)
|
||||
URL_FILE:=linux-$(PKG_ARCH)-filebrowser.tar.gz
|
||||
FILE:=filebrowser-$(PKG_VERSION)-$(PKG_ARCH)_static.tar.gz
|
||||
HASH:=skip
|
||||
endef
|
||||
|
||||
define Build/Configure
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
( \
|
||||
pushd $(PKG_BUILD_DIR) ; \
|
||||
tar zxvf $(DL_DIR)/filebrowser-$(PKG_VERSION)-$(PKG_ARCH)_static.tar.gz -C . ; \
|
||||
popd ; \
|
||||
)
|
||||
ifneq ($(CONFIG_FILEBROWSER_COMPRESS_UPX),)
|
||||
$(STAGING_DIR_HOST)/bin/upx --lzma --best $(PKG_BUILD_DIR)/filebrowser
|
||||
endif
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/install
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/filebrowser $(1)/usr/sbin/filebrowser
|
||||
endef
|
||||
|
||||
$(eval $(call Download,$(PKG_NAME)))
|
||||
$(eval $(call BuildPackage,$(PKG_NAME)))
|
30
fw_download_tool/Makefile
Normal file
30
fw_download_tool/Makefile
Normal file
@ -0,0 +1,30 @@
|
||||
#
|
||||
# Copyright (C) 2015-2016 OpenWrt.org
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v3.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=fw_download_tool
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_LICENSE:=GPL-3.0
|
||||
PKG_LICENSE_FILE:=COPYING
|
||||
PKG_MAINTAINER:=sbwml <admin@cooluc.com>
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/$(PKG_NAME)
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
TITLE:=Firmware downloader
|
||||
DEPENDS:=+libcurl
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/fw_download_tool $(1)/usr/bin/fw_download_tool
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,$(PKG_NAME)))
|
674
fw_download_tool/src/COPYING
Normal file
674
fw_download_tool/src/COPYING
Normal file
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
8
fw_download_tool/src/Makefile
Normal file
8
fw_download_tool/src/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
CC = gcc
|
||||
CFLAGS += -lcurl
|
||||
|
||||
program: fw_download_tool.c
|
||||
$(CC) $(CFLAGS) -o fw_download_tool fw_download_tool.c
|
||||
|
||||
clean:
|
||||
rm -f fw_download_tool
|
240
fw_download_tool/src/fw_download_tool.c
Normal file
240
fw_download_tool/src/fw_download_tool.c
Normal file
@ -0,0 +1,240 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* OpenWrt OTA lightweight downloader - by sbwml
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <curl/curl.h>
|
||||
|
||||
static int progressCallback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
|
||||
{
|
||||
double progress = 0.0;
|
||||
if (dltotal > 0.0)
|
||||
{
|
||||
progress = (dlnow / dltotal) * 100.0;
|
||||
}
|
||||
|
||||
printf("%.2f%%\r", progress);
|
||||
fflush(stdout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
long parseTimeout(const char *timeoutStr)
|
||||
{
|
||||
long timeout = 0;
|
||||
int len = strlen(timeoutStr);
|
||||
if (len > 1)
|
||||
{
|
||||
char unit = timeoutStr[len - 1];
|
||||
char *endptr;
|
||||
long value = strtol(timeoutStr, &endptr, 10);
|
||||
if (endptr == timeoutStr)
|
||||
{
|
||||
fprintf(stderr, "Invalid timeout value: %s\n", timeoutStr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (unit)
|
||||
{
|
||||
case 's':
|
||||
timeout = value;
|
||||
break;
|
||||
case 'm':
|
||||
timeout = value * 60;
|
||||
break;
|
||||
case 'h':
|
||||
timeout = value * 60 * 60;
|
||||
break;
|
||||
case 'd':
|
||||
timeout = value * 60 * 60 * 24;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Invalid timeout unit: %c\n", unit);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
timeout = strtol(timeoutStr, NULL, 10);
|
||||
}
|
||||
|
||||
return timeout;
|
||||
}
|
||||
|
||||
int downloadFile(const char *url, const char *outputPath, const char *userAgent, long timeout, int skipSSL, int followRedirects, int useIPv4, int useIPv6)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
FILE *fp;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if (curl)
|
||||
{
|
||||
fp = fopen(outputPath, "wb");
|
||||
if (fp == NULL)
|
||||
{
|
||||
fprintf(stderr, "Failed to open file for writing\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
|
||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progressCallback);
|
||||
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, NULL);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent);
|
||||
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
|
||||
|
||||
if (timeout > 0)
|
||||
{
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
|
||||
}
|
||||
|
||||
if (skipSSL)
|
||||
{
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||
}
|
||||
|
||||
if (followRedirects)
|
||||
{
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
}
|
||||
|
||||
if (useIPv4)
|
||||
{
|
||||
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||
}
|
||||
else if (useIPv6)
|
||||
{
|
||||
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6);
|
||||
}
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
if (res != CURLE_OK)
|
||||
{
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
|
||||
fclose(fp);
|
||||
remove(outputPath);
|
||||
return 255;
|
||||
}
|
||||
|
||||
curl_easy_cleanup(curl);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *url;
|
||||
const char *outputPath = NULL;
|
||||
const char *userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36";
|
||||
long timeout = 0;
|
||||
int skipSSL = 0;
|
||||
int followRedirects = 0;
|
||||
int useIPv4 = 0;
|
||||
int useIPv6 = 0;
|
||||
|
||||
int i;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s <url> [-o <output_path>] [-u <user_agent>] [-t <timeout>] [-k] [-L] [-4] [-6]\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
url = argv[1];
|
||||
|
||||
for (i = 2; i < argc; i++)
|
||||
{
|
||||
if (strcmp(argv[i], "-o") == 0)
|
||||
{
|
||||
if (i + 1 < argc)
|
||||
{
|
||||
outputPath = argv[i + 1];
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Invalid arguments. Use -o to specify the output path.\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (strcmp(argv[i], "-u") == 0)
|
||||
{
|
||||
if (i + 1 < argc)
|
||||
{
|
||||
userAgent = argv[i + 1];
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Invalid arguments. Use -u to specify the User-Agent.\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (strcmp(argv[i], "-t") == 0)
|
||||
{
|
||||
if (i + 1 < argc)
|
||||
{
|
||||
const char *timeoutStr = argv[i + 1];
|
||||
i++;
|
||||
timeout = parseTimeout(timeoutStr);
|
||||
if (timeout < 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Invalid arguments. Use -t to specify the timeout.\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (strcmp(argv[i], "-k") == 0)
|
||||
{
|
||||
skipSSL = 1;
|
||||
}
|
||||
else if (strcmp(argv[i], "-L") == 0)
|
||||
{
|
||||
followRedirects = 1;
|
||||
}
|
||||
else if (strcmp(argv[i], "-4") == 0)
|
||||
{
|
||||
useIPv4 = 1;
|
||||
}
|
||||
else if (strcmp(argv[i], "-6") == 0)
|
||||
{
|
||||
useIPv6 = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Invalid arguments.\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (outputPath == NULL)
|
||||
{
|
||||
outputPath = "/tmp/firmware.img.part";
|
||||
}
|
||||
|
||||
int result = downloadFile(url, outputPath, userAgent, timeout, skipSSL, followRedirects, useIPv4, useIPv6);
|
||||
if (result != 0)
|
||||
{
|
||||
fprintf(stderr, "Download failed.\n");
|
||||
remove(outputPath);
|
||||
return 255;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
45
gowebdav/Makefile
Normal file
45
gowebdav/Makefile
Normal file
@ -0,0 +1,45 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#
|
||||
# Copyright (C) 2021 ImmortalWrt.org
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=gowebdav
|
||||
PKG_VERSION:=0.0.8
|
||||
PKG_RELEASE:=$(AUTORELEASE)
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=https://codeload.github.com/sbwml/gowebdav/tar.gz/v$(PKG_VERSION)?
|
||||
PKG_HASH:=0f689c745127163d88c7743e3217ad8bf55c5adf90da6ff4ddb3896bba23b055
|
||||
|
||||
PKG_MAINTAINER:=Tianling Shen <cnsztl@immortalwrt.org>
|
||||
|
||||
PKG_BUILD_DEPENDS:=golang/host
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
PKG_USE_MIPS16:=0
|
||||
|
||||
GO_PKG:=github.com/sbwml/gowebdav
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
include $(TOPDIR)/feeds/packages/lang/golang/golang-package.mk
|
||||
|
||||
define Package/gowebdav
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
SUBMENU:=File Transfer
|
||||
TITLE:=A simple WebDav server written in Go
|
||||
URL:=https://github.com/1715173329/gowebdav
|
||||
DEPENDS:=$(GO_ARCH_DEPENDS)
|
||||
endef
|
||||
|
||||
define Package/gowebdav/install
|
||||
$(call GoPackage/Package/Install/Bin,$(1))
|
||||
|
||||
$(INSTALL_DIR) $(1)/etc/config
|
||||
$(INSTALL_CONF) $(CURDIR)/files/gowebdav.config $(1)/etc/config/gowebdav
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) $(CURDIR)/files/gowebdav.init $(1)/etc/init.d/gowebdav
|
||||
endef
|
||||
|
||||
$(eval $(call GoBinPackage,gowebdav))
|
||||
$(eval $(call BuildPackage,gowebdav))
|
11
gowebdav/files/gowebdav.config
Normal file
11
gowebdav/files/gowebdav.config
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
config gowebdav 'config'
|
||||
option enable '0'
|
||||
option listen_port '6086'
|
||||
option root_dir '/mnt'
|
||||
option read_only '0'
|
||||
option show_hidden '0'
|
||||
option allow_wan '0'
|
||||
option use_https '0'
|
||||
option cert_cer ''
|
||||
option cert_key ''
|
88
gowebdav/files/gowebdav.init
Executable file
88
gowebdav/files/gowebdav.init
Executable file
@ -0,0 +1,88 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2021 ImmortalWrt
|
||||
|
||||
START=99
|
||||
USE_PROCD=1
|
||||
PROG=/usr/bin/gowebdav
|
||||
|
||||
get_config() {
|
||||
config_load gowebdav
|
||||
config_get "enable" "config" "enable" "0"
|
||||
config_get "listen_port" "config" "listen_port" "6086"
|
||||
config_get "username" "config" "username"
|
||||
config_get "password" "config" "password"
|
||||
config_get "root_dir" "config" "root_dir" "/mnt"
|
||||
config_get "read_only" "config" "read_only" "0"
|
||||
config_get "show_hidden" "config" "show_hidden" "0"
|
||||
config_get "allow_wan" "config" "allow_wan" "0"
|
||||
config_get "use_https" "config" "use_https" "0"
|
||||
config_get "cert_cer" "config" "cert_cer"
|
||||
config_get "cert_key" "config" "cert_key"
|
||||
config_load network
|
||||
config_get "lan_addr" "lan" "ipaddr" "0.0.0.0"
|
||||
}
|
||||
|
||||
set_firewall() {
|
||||
if [ "$set_type" = "allow" ]; then
|
||||
uci -q delete firewall.gowebdav
|
||||
uci set firewall.gowebdav=rule
|
||||
uci set firewall.gowebdav.name="gowebdav"
|
||||
uci set firewall.gowebdav.target="ACCEPT"
|
||||
uci set firewall.gowebdav.src="wan"
|
||||
uci set firewall.gowebdav.proto="tcp"
|
||||
uci set firewall.gowebdav.dest_port="$listen_port"
|
||||
uci set firewall.gowebdav.enabled="1"
|
||||
uci commit firewall
|
||||
/etc/init.d/firewall reload >/dev/null 2>&1
|
||||
elif [ "$set_type" = "deny" ]; then
|
||||
uci -q delete firewall.gowebdav
|
||||
uci commit firewall
|
||||
/etc/init.d/firewall reload >/dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
start_service() {
|
||||
get_config
|
||||
|
||||
[ "$enable" -ne "1" ] && return 1
|
||||
mkdir -p $root_dir
|
||||
|
||||
if [ "$allow_wan" -eq "1" ]; then
|
||||
listen_addr=
|
||||
set_type="allow"
|
||||
else
|
||||
listen_addr=$lan_addr
|
||||
set_type="deny"
|
||||
fi
|
||||
set_firewall
|
||||
|
||||
{ [ -n "$username" ] && [ -n "$password" ]; } && auth_arg="-user $username -password $password"
|
||||
[ "$read_only" -eq "1" ] && readonly_arg="-read-only"
|
||||
[ "$show_hidden" -eq "1" ] && showhidden_arg="-show-hidden"
|
||||
{ [ "$use_https" -eq "1" ] && [ -e "$cert_cer" ] && [ -e "$cert_key" ]; } && https_arg="-https-mode -https-cert-file $cert_cer -https-key-file $cert_key"
|
||||
|
||||
procd_open_instance gowebdav
|
||||
procd_set_param command $PROG
|
||||
procd_append_param command -dir "$root_dir" -port "$listen_addr:$listen_port" $auth_arg $readonly_arg $showhidden_arg $https_arg
|
||||
procd_set_param stdout 1
|
||||
procd_set_param stderr 1
|
||||
procd_set_param respawn
|
||||
procd_close_instance gowebdav
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "gowebdav"
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
stop
|
||||
sleep 1
|
||||
start
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
get_config
|
||||
pgrep -f /usr/bin/gowebdav | xargs kill -9 >/dev/null 2>&1
|
||||
set_type="deny"
|
||||
set_firewall
|
||||
}
|
42
lshw/Makefile
Normal file
42
lshw/Makefile
Normal file
@ -0,0 +1,42 @@
|
||||
#
|
||||
# Copyright (C) 2007-2016 OpenWrt.org
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=lshw
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_SOURCE_PROTO:=git
|
||||
PKG_SOURCE_URL:=https://github.com/lyonel/lshw.git
|
||||
PKG_SOURCE_DATE:=2023-03-20
|
||||
PKG_SOURCE_VERSION:=b4e067307906ec6f277cce5c8a882f5edd03cbbc
|
||||
PKG_MIRROR_HASH:=947b521cbeabd991480e3f952dc148eef07d03cc5d797a3fb438c2978092e8bb
|
||||
|
||||
PKG_MAINTAINER:=sbwml <admin@cooluc.com>
|
||||
PKG_LICENSE:=GPL-2.0
|
||||
PKG_LICENSE_FILES:=LICENSE
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/$(PKG_NAME)
|
||||
SECTION:=utils
|
||||
CATEGORY:=Utilities
|
||||
TITLE:=lshw
|
||||
URL:=http://lshw.ezix.org
|
||||
DEPENDS:=+libstdcpp
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/description
|
||||
HardWare LiSter for Linux
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/lshw $(1)/usr/bin/lshw
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,$(PKG_NAME)))
|
18
luci-app-autoreboot/Makefile
Normal file
18
luci-app-autoreboot/Makefile
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (C) 2016 Openwrt.org
|
||||
#
|
||||
# This is free software, licensed under the Apache License, Version 2.0 .
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=LuCI support for Scheduled Reboot
|
||||
LUCI_DEPENDS:=+luci
|
||||
LUCI_PKGARCH:=all
|
||||
|
||||
PKG_NAME:=luci-app-autoreboot
|
||||
PKG_VERSION:=1.0
|
||||
PKG_RELEASE:=8
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
9
luci-app-autoreboot/luasrc/controller/autoreboot.lua
Normal file
9
luci-app-autoreboot/luasrc/controller/autoreboot.lua
Normal file
@ -0,0 +1,9 @@
|
||||
module("luci.controller.autoreboot",package.seeall)
|
||||
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/autoreboot") then
|
||||
return
|
||||
end
|
||||
|
||||
entry({"admin", "system", "autoreboot"}, cbi("autoreboot"), _("Scheduled Reboot"),88)
|
||||
end
|
40
luci-app-autoreboot/luasrc/model/cbi/autoreboot.lua
Normal file
40
luci-app-autoreboot/luasrc/model/cbi/autoreboot.lua
Normal file
@ -0,0 +1,40 @@
|
||||
require("luci.sys")
|
||||
|
||||
m = Map("autoreboot")
|
||||
m.title = translate("Scheduled Reboot")
|
||||
m.description = translate("Scheduled reboot Setting")
|
||||
|
||||
s = m:section(TypedSection, "login")
|
||||
s.addremove = false
|
||||
s.anonymous = true
|
||||
|
||||
enable = s:option(Flag,"enable" ,translate("Enable"))
|
||||
enable.rmempty = false
|
||||
enable.default = 0
|
||||
|
||||
week = s:option(ListValue, "week", translate("Week Day"))
|
||||
week:value(7, translate("Everyday"))
|
||||
week:value(1, translate("Monday"))
|
||||
week:value(2, translate("Tuesday"))
|
||||
week:value(3, translate("Wednesday"))
|
||||
week:value(4, translate("Thursday"))
|
||||
week:value(5, translate("Friday"))
|
||||
week:value(6, translate("Saturday"))
|
||||
week:value(0, translate("Sunday"))
|
||||
week.default = 0
|
||||
|
||||
hour = s:option(Value, "hour", translate("Hour"))
|
||||
hour.datatype = "range(0,23)"
|
||||
hour.rmempty = false
|
||||
|
||||
pass = s:option(Value, "minute", translate("Minute"))
|
||||
pass.datatype = "range(0,59)"
|
||||
pass.rmempty = false
|
||||
|
||||
|
||||
local e = luci.http.formvalue("cbi.apply")
|
||||
if e then
|
||||
io.popen("/etc/init.d/autoreboot restart")
|
||||
end
|
||||
|
||||
return m
|
20
luci-app-autoreboot/po/zh_Hans/autoreboot.po
Normal file
20
luci-app-autoreboot/po/zh_Hans/autoreboot.po
Normal file
@ -0,0 +1,20 @@
|
||||
msgid "Scheduled Reboot"
|
||||
msgstr "定时重启"
|
||||
|
||||
msgid "Scheduled reboot Setting"
|
||||
msgstr "定时重启设置"
|
||||
|
||||
msgid "Week Day"
|
||||
msgstr "星期"
|
||||
|
||||
msgid "Everyday"
|
||||
msgstr "每天"
|
||||
|
||||
msgid "Day"
|
||||
msgstr "天"
|
||||
|
||||
msgid "Hour"
|
||||
msgstr "小时"
|
||||
|
||||
msgid "Minute"
|
||||
msgstr "分钟"
|
6
luci-app-autoreboot/root/etc/config/autoreboot
Normal file
6
luci-app-autoreboot/root/etc/config/autoreboot
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
config login
|
||||
option minute '0'
|
||||
option hour '5'
|
||||
option week '3'
|
||||
option enable '0'
|
39
luci-app-autoreboot/root/etc/init.d/autoreboot
Executable file
39
luci-app-autoreboot/root/etc/init.d/autoreboot
Executable file
@ -0,0 +1,39 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=90
|
||||
|
||||
run_reboot()
|
||||
{
|
||||
local enable
|
||||
config_get_bool enable $1 enable
|
||||
|
||||
if [ $enable = 1 ]; then
|
||||
local minute
|
||||
local hour
|
||||
config_get week $1 week
|
||||
config_get minute $1 minute
|
||||
config_get hour $1 hour
|
||||
[ $week = 7 ] && week="*"
|
||||
sed -i '/reboot/d' /etc/crontabs/root >/dev/null 2>&1
|
||||
echo "$minute $hour * * $week /bin/sync && /sbin/reboot" >> /etc/crontabs/root
|
||||
/etc/init.d/cron restart
|
||||
fi
|
||||
}
|
||||
|
||||
start()
|
||||
{
|
||||
config_load autoreboot
|
||||
config_foreach run_reboot login
|
||||
}
|
||||
|
||||
stop()
|
||||
{
|
||||
sed -i '/reboot/d' /etc/crontabs/root >/dev/null 2>&1
|
||||
/etc/init.d/cron restart
|
||||
}
|
||||
|
||||
restart()
|
||||
{
|
||||
stop
|
||||
start
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"luci-app-autoreboot": {
|
||||
"description": "Grant UCI access for luci-app-autoreboot",
|
||||
"read": {
|
||||
"uci": [ "autoreboot" ]
|
||||
},
|
||||
"write": {
|
||||
"uci": [ "autoreboot" ]
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"config": "autoreboot",
|
||||
"init": "autoreboot"
|
||||
}
|
20
luci-app-cpufreq/Makefile
Normal file
20
luci-app-cpufreq/Makefile
Normal file
@ -0,0 +1,20 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#
|
||||
# Copyright (C) 2021 ImmortalWrt.org
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=LuCI for CPU Freq Setting
|
||||
LUCI_DEPENDS:=@TARGET_rockchip +irqbalance +luci-compat +kmod-hwmon-pwmfan
|
||||
|
||||
PKG_NAME:=luci-app-cpufreq
|
||||
PKG_VERSION:=1.1
|
||||
PKG_RELEASE:=1
|
||||
|
||||
define Package/$(PKG_NAME)/conffiles
|
||||
/etc/config/cpufreq
|
||||
endef
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
25
luci-app-cpufreq/luasrc/controller/cpufreq.lua
Normal file
25
luci-app-cpufreq/luasrc/controller/cpufreq.lua
Normal file
@ -0,0 +1,25 @@
|
||||
module("luci.controller.cpufreq", package.seeall)
|
||||
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/cpufreq") or not nixio.fs.access("/etc/config/irqbalance") then
|
||||
return
|
||||
end
|
||||
|
||||
local page = entry({"admin", "system", "cpufreq"}, alias("admin", "system", "cpufreq", "cpufreq"), _("CPU Freq"), 90)
|
||||
page.dependent = true
|
||||
page.acl_depends = { "luci-app-cpufreq" }
|
||||
|
||||
entry({"admin", "system", "cpufreq", "cpufreq"}, cbi("cpufreq/cpufreq"), _("CPU Setting"), 1).leaf = true
|
||||
entry({"admin", "system", "cpufreq", "pwmfan"}, cbi("cpufreq/pwmfan"), _("PWM Fan Controller"), 2).leaf = true
|
||||
entry({"admin", "system", "cpufreq", "irqbalance"}, cbi("cpufreq/irqbalance"), _("Irqbalance"), 3).leaf = true
|
||||
entry({"admin", "system", "cpufreq", "mglru"}, cbi("cpufreq/mglru"), _("Multi-Gen LRU"), 4).leaf = true
|
||||
|
||||
entry({"admin", "system", "cpufreq", "irq_status"}, call("irq_status")).leaf = true
|
||||
end
|
||||
|
||||
function irq_status()
|
||||
local log_data={}
|
||||
log_data.syslog=luci.sys.exec("cat /proc/interrupts | egrep '^[ ]*(CPU|[0-9]*:)'")
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(log_data)
|
||||
end
|
68
luci-app-cpufreq/luasrc/model/cbi/cpufreq/cpufreq.lua
Normal file
68
luci-app-cpufreq/luasrc/model/cbi/cpufreq/cpufreq.lua
Normal file
@ -0,0 +1,68 @@
|
||||
local fs = require "nixio.fs"
|
||||
|
||||
function string.split(input, delimiter)
|
||||
input = tostring(input)
|
||||
delimiter = tostring(delimiter)
|
||||
if (delimiter=='') then return false end
|
||||
local pos,arr = 0, {}
|
||||
for st,sp in function() return string.find(input, delimiter, pos, true) end do
|
||||
table.insert(arr, string.sub(input, pos, st - 1))
|
||||
pos = sp + 1
|
||||
end
|
||||
table.insert(arr, string.sub(input, pos))
|
||||
return arr
|
||||
end
|
||||
|
||||
mp = Map("cpufreq", translate("CPU Freq Settings"))
|
||||
mp.description = translate("Set CPU Scaling Governor to Max Performance or Balance Mode")
|
||||
|
||||
s = mp:section(NamedSection, "cpufreq", "settings")
|
||||
s.anonymouse = true
|
||||
|
||||
local policy_nums = luci.sys.exec("echo -n $(find /sys/devices/system/cpu/cpufreq/policy* -maxdepth 0 | grep -Eo '[0-9]+')")
|
||||
for _, policy_num in ipairs(string.split(policy_nums, " ")) do
|
||||
if not fs.access("/sys/devices/system/cpu/cpufreq/policy" .. policy_num .. "/scaling_available_frequencies") then return end
|
||||
|
||||
cpu_freqs = fs.readfile("/sys/devices/system/cpu/cpufreq/policy" .. policy_num .. "/scaling_available_frequencies")
|
||||
cpu_freqs = string.sub(cpu_freqs, 1, -3)
|
||||
|
||||
cpu_governors = fs.readfile("/sys/devices/system/cpu/cpufreq/policy" .. policy_num .. "/scaling_available_governors")
|
||||
cpu_governors = string.sub(cpu_governors, 1, -3)
|
||||
|
||||
|
||||
freq_array = string.split(cpu_freqs, " ")
|
||||
governor_array = string.split(cpu_governors, " ")
|
||||
|
||||
s:tab(policy_num, translate("Policy " .. policy_num))
|
||||
|
||||
governor = s:taboption(policy_num, ListValue, "governor" .. policy_num, translate("CPU Scaling Governor"))
|
||||
for _, e in ipairs(governor_array) do
|
||||
if e ~= "" then governor:value(e, translate(e, string.upper(e))) end
|
||||
end
|
||||
|
||||
minfreq = s:taboption(policy_num, ListValue, "minfreq" .. policy_num, translate("Min Idle CPU Freq"))
|
||||
for _, e in ipairs(freq_array) do
|
||||
if e ~= "" then minfreq:value(e) end
|
||||
end
|
||||
|
||||
maxfreq = s:taboption(policy_num, ListValue, "maxfreq" .. policy_num, translate("Max Turbo Boost CPU Freq"))
|
||||
for _, e in ipairs(freq_array) do
|
||||
if e ~= "" then maxfreq:value(e) end
|
||||
end
|
||||
|
||||
sdfactor = s:taboption(policy_num, Value, "sdfactor" .. policy_num, translate("CPU Switching Sampling rate"))
|
||||
sdfactor.datatype="range(1,100000)"
|
||||
sdfactor.description = translate("The sampling rate determines how frequently the governor checks to tune the CPU (ms)")
|
||||
sdfactor.placeholder = 10
|
||||
sdfactor.default = 10
|
||||
sdfactor:depends("governor" .. policy_num, "ondemand")
|
||||
|
||||
upthreshold = s:taboption(policy_num, Value, "upthreshold" .. policy_num, translate("CPU Switching Threshold"))
|
||||
upthreshold.datatype="range(1,99)"
|
||||
upthreshold.description = translate("Kernel make a decision on whether it should increase the frequency (%)")
|
||||
upthreshold.placeholder = 50
|
||||
upthreshold.default = 50
|
||||
upthreshold:depends("governor" .. policy_num, "ondemand")
|
||||
end
|
||||
|
||||
return mp
|
35
luci-app-cpufreq/luasrc/model/cbi/cpufreq/irqbalance.lua
Normal file
35
luci-app-cpufreq/luasrc/model/cbi/cpufreq/irqbalance.lua
Normal file
@ -0,0 +1,35 @@
|
||||
-- Copyright 2022 wulishui <wulishui@gmail.com>
|
||||
-- Licensed to the public under the Apache License 2.0.
|
||||
local utl = require "luci.util"
|
||||
local sys = require "luci.sys"
|
||||
local m, s
|
||||
local button = ""
|
||||
|
||||
if luci.sys.call("pidof irqbalance >/dev/null") == 0 then
|
||||
status = translate("<b><font color=\"green\">RUNNING</font></b>")
|
||||
else
|
||||
status = translate("<b><font color=\"red\">NOT RUNNING</font></b>")
|
||||
end
|
||||
|
||||
m = Map("irqbalance", translate("Irqbalance"), translatef("Irqbalance is a Linux daemon that distributes interrupts over multiple logical CPUs. This design intent being to improve overall performance which can result in a balanced load and power consumption.</br>For more information, visiting: https://openwrt.org/docs/guide-user/services/irqbalance") .. button .. "<br /><br />" .. translate("Running Status").. " : " .. status .. "<br />")
|
||||
|
||||
s = m:section(TypedSection, "irqbalance", translate("Settings"))
|
||||
s.anonymous = true
|
||||
|
||||
enabled = s:option(Flag, "enabled", translate("Enable"))
|
||||
enabled.rmempty = false
|
||||
|
||||
deepestcache = s:option(Value, "deepestcache", translate("Level at which irqbalance partitions cache domains"))
|
||||
deepestcache.placeholder='2'
|
||||
deepestcache.rmempty = true
|
||||
|
||||
interval = s:option(Value, "interval", translate("Interval (Seconds)"))
|
||||
interval.placeholder='10'
|
||||
interval.rmempty = true
|
||||
|
||||
banirq = s:option(DynamicList, "banirq", translate("Ignore (ID of irq)"))
|
||||
banirq.rmempty = true
|
||||
|
||||
m:section(SimpleSection).template = "cpufreq/irq_status"
|
||||
|
||||
return m
|
16
luci-app-cpufreq/luasrc/model/cbi/cpufreq/mglru.lua
Normal file
16
luci-app-cpufreq/luasrc/model/cbi/cpufreq/mglru.lua
Normal file
@ -0,0 +1,16 @@
|
||||
mp = Map("cpufreq", translate("Multi-Gen LRU"))
|
||||
mp.description = translate("The multi-gen LRU is an alternative LRU implementation that optimizes page reclaim and improves performance under memory pressure. Page reclaim decides the kernel's caching policy and ability to overcommit memory. It directly impacts the kswapd CPU usage and RAM efficiency.")
|
||||
|
||||
s = mp:section(NamedSection, "cpufreq", "settings")
|
||||
s.anonymouse = true
|
||||
|
||||
o = s:option(Flag, "mglru_enabled", translate("Enabled"))
|
||||
o.default = true
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "mglru_min_ttl_ms", translate("Thrashing prevention (ms)"), translate("Set the thrashing prevention vaule to prevent the working set of N milliseconds from getting evicted. The OOM killer is triggered if this working set cannot be kept in memory. (0 means disabled, Default value 1000)"))
|
||||
o.datatype = "and(uinteger,min(0))"
|
||||
o.default = "1000"
|
||||
o.rmempty = false
|
||||
|
||||
return mp
|
27
luci-app-cpufreq/luasrc/model/cbi/cpufreq/pwmfan.lua
Normal file
27
luci-app-cpufreq/luasrc/model/cbi/cpufreq/pwmfan.lua
Normal file
@ -0,0 +1,27 @@
|
||||
fan = Map("cpufreq", translate("PWM Fan Controller"))
|
||||
fan.description = translate("Smart control PWM fan start/stop and fan speed based on CPU temperature.")
|
||||
|
||||
s = fan:section(NamedSection, "cpufreq", "settings")
|
||||
s.addremove = false
|
||||
s.anonymous = true
|
||||
|
||||
o = s:option(Flag, "pwm_fan", translate("Enabled"))
|
||||
o.rmefanty = false
|
||||
|
||||
o = s:option(Value, "pwm_fan_threshold", translate("Fan temperature activation (°C)"))
|
||||
o.datatype = "and(uinteger,min(1),max(100))"
|
||||
o.default = "35"
|
||||
|
||||
o = s:option(Flag, "pwm_fan_strict", translate("Fan always on"))
|
||||
o.default = true
|
||||
|
||||
o = s:option(ListValue, "pwm_fan_enforce_level", translate("Fan speed"))
|
||||
o:value("auto", translate("Auto"))
|
||||
o:value("1", translate("Level 1"))
|
||||
o:value("2", translate("Level 2"))
|
||||
o:value("3", translate("Level 3"))
|
||||
o:value("4", translate("Level 4"))
|
||||
o.default = "auto"
|
||||
o:depends("pwm_fan_strict", true)
|
||||
|
||||
return fan
|
37
luci-app-cpufreq/luasrc/view/cpufreq/irq_status.htm
Normal file
37
luci-app-cpufreq/luasrc/view/cpufreq/irq_status.htm
Normal file
@ -0,0 +1,37 @@
|
||||
<style type="text/css">
|
||||
<%
|
||||
local dsp = require "luci.dispatcher"
|
||||
-%>
|
||||
fieldset > fieldset, .cbi-section > .cbi-section {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
box-shadow: none;
|
||||
background: #000000d9;
|
||||
color: #dacb02;
|
||||
border-radius: 10px;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
<div class="cbi-map">
|
||||
<fieldset class="cbi-section">
|
||||
<fieldset class="cbi-section-node">
|
||||
<div id="log_text"></div>
|
||||
</fieldset>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
var log_id=document.getElementById('log_text');
|
||||
XHR.poll(2,'<%=luci.dispatcher.build_url("admin", "system", "cpufreq", "irq_status")%>',null,function(x,data){
|
||||
if (log_id&&data){
|
||||
log_id.innerHTML=String.format(
|
||||
'<pre>%s</pre>',
|
||||
data.syslog || '<%:No data.%>'
|
||||
);
|
||||
}else if (log_id){
|
||||
log_id.innerHTML='<strong><%:Read error, please refresh or wait.%></strong>';
|
||||
}
|
||||
});
|
||||
//]]></script>
|
107
luci-app-cpufreq/po/zh_Hans/cpufreq.po
Normal file
107
luci-app-cpufreq/po/zh_Hans/cpufreq.po
Normal file
@ -0,0 +1,107 @@
|
||||
msgid "CPU Freq"
|
||||
msgstr "CPU 性能调节"
|
||||
|
||||
msgid "CPU Freq Settings"
|
||||
msgstr "CPU 性能调节设置"
|
||||
|
||||
msgid "CPU Setting"
|
||||
msgstr "CPU 设置"
|
||||
|
||||
msgid "Set CPU Scaling Governor to Max Performance or Balance Mode"
|
||||
msgstr "设置路由器的 CPU 性能模式(省电/性能/均衡)"
|
||||
|
||||
msgid "CPU Scaling Governor"
|
||||
msgstr "CPU 工作模式"
|
||||
|
||||
msgid "CPU Freq from 48000 to 716000 (Khz)"
|
||||
msgstr "CPU 频率范围为 48000 到 716000 (Khz)"
|
||||
|
||||
msgid "Min Idle CPU Freq"
|
||||
msgstr "待机 CPU 最小频率"
|
||||
|
||||
msgid "Max Turbo Boost CPU Freq"
|
||||
msgstr "最大 Turbo Boost CPU 频率"
|
||||
|
||||
msgid "CPU Switching Sampling rate"
|
||||
msgstr "CPU 切换周期"
|
||||
|
||||
msgid "The sampling rate determines how frequently the governor checks to tune the CPU (ms)"
|
||||
msgstr "CPU 检查切换的周期 (ms)。注意:过于频繁的切换频率会引起网络延迟抖动"
|
||||
|
||||
msgid "CPU Switching Threshold"
|
||||
msgstr "CPU 切换频率触发阈值"
|
||||
|
||||
msgid "Kernel make a decision on whether it should increase the frequency (%)"
|
||||
msgstr "当 CPU 占用率超过 (%) 的情况下触发内核切换频率"
|
||||
|
||||
msgid "PWM Fan Controller"
|
||||
msgstr "PWM 风扇控制"
|
||||
|
||||
msgid "Smart control PWM fan start/stop and fan speed based on CPU temperature."
|
||||
msgstr "通过 CPU 温度值智能控制 PWM 风扇启停、转速。"
|
||||
|
||||
msgid "Fan temperature activation (°C)"
|
||||
msgstr "风扇启停温度 (°C)"
|
||||
|
||||
msgid "Fan always on"
|
||||
msgstr "风扇常转"
|
||||
|
||||
msgid "Fan speed"
|
||||
msgstr "风扇转速"
|
||||
|
||||
msgid "Auto"
|
||||
msgstr "自动"
|
||||
|
||||
msgid "Level 1"
|
||||
msgstr "等级 1"
|
||||
|
||||
msgid "Level 2"
|
||||
msgstr "等级 2"
|
||||
|
||||
msgid "Level 3"
|
||||
msgstr "等级 3"
|
||||
|
||||
msgid "Level 4"
|
||||
msgstr "等级 4"
|
||||
|
||||
msgid "Irqbalance"
|
||||
msgstr "中断均衡器"
|
||||
|
||||
msgid "<b><font color=\"green\">RUNNING</font></b>"
|
||||
msgstr "<b><font color=\"green\">运行中</font></b>"
|
||||
|
||||
msgid "<b><font color=\"red\">NOT RUNNING</font></b>"
|
||||
msgstr "<b><font color=\"red\">未运行</font></b>"
|
||||
|
||||
msgid "No data."
|
||||
msgstr "没有数据。"
|
||||
|
||||
msgid "Read error, please refresh or wait."
|
||||
msgstr "读取错误,请刷新或稍等。"
|
||||
|
||||
msgid "Irqbalance is a Linux daemon that distributes interrupts over multiple logical CPUs. This design intent being to improve overall performance which can result in a balanced load and power consumption.</br>For more information, visiting: https://openwrt.org/docs/guide-user/services/irqbalance"
|
||||
msgstr "Irqbalance 是一个 Linux 守护进程,它在多个逻辑 CPU 上分配中断。此设计旨在提高整体性能,从而实现平衡的负载和功耗。访问 https://openwrt.org/docs/guide-user/services/irqbalance 可获取更多信息。"
|
||||
|
||||
msgid "Level at which irqbalance partitions cache domains"
|
||||
msgstr "缓存域级别"
|
||||
|
||||
msgid "Interval (Seconds)"
|
||||
msgstr "间隔(秒)"
|
||||
|
||||
msgid "Ignore (ID of irq)"
|
||||
msgstr "忽略(中断ID)"
|
||||
|
||||
msgid "Multi-Gen LRU"
|
||||
msgstr "Multi-Gen LRU"
|
||||
|
||||
msgid "The multi-gen LRU is an alternative LRU implementation that optimizes page reclaim and improves performance under memory pressure. Page reclaim decides the kernel's caching policy and ability to overcommit memory. It directly impacts the kswapd CPU usage and RAM efficiency."
|
||||
msgstr "Multi-Gen LRU 是一种替代 LRU 实现,优化页面回收并在内存压力下提高性能,页面回收决定内核的缓存策略和超额提交内存的能力,它直接影响 kswapd CPU 使用率和 RAM 效率。"
|
||||
|
||||
msgid "Enabled"
|
||||
msgstr "启用"
|
||||
|
||||
msgid "Thrashing prevention (ms)"
|
||||
msgstr "预防颠簸(毫秒)"
|
||||
|
||||
msgid "Set the thrashing prevention vaule to prevent the working set of N milliseconds from getting evicted. The OOM killer is triggered if this working set cannot be kept in memory. (0 means disabled, Default value 1000)"
|
||||
msgstr "设置预防颠簸值以防止 N 毫秒的工作集被驱逐,如果无法将此工作集保留在内存中,则会触发 OOM killer。(0 表示禁用,默认值 1000)"
|
8
luci-app-cpufreq/root/etc/config/cpufreq
Normal file
8
luci-app-cpufreq/root/etc/config/cpufreq
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
config settings 'cpufreq'
|
||||
option mglru_enabled '1'
|
||||
option mglru_min_ttl_ms '1000'
|
||||
option pwm_fan '1'
|
||||
option pwm_fan_threshold '35'
|
||||
option pwm_fan_strict '1'
|
||||
option pwm_fan_enforce_level 'auto'
|
55
luci-app-cpufreq/root/etc/init.d/cpufreq
Executable file
55
luci-app-cpufreq/root/etc/init.d/cpufreq
Executable file
@ -0,0 +1,55 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=15
|
||||
USE_PROCD=1
|
||||
|
||||
config_get_cpufreq() {
|
||||
config_get "cpufreq" "$1"
|
||||
}
|
||||
|
||||
start_service() {
|
||||
config_load "cpufreq"
|
||||
|
||||
# Multi-Gen LRU
|
||||
if [ -e /sys/kernel/mm/lru_gen/enabled ]; then
|
||||
if [ "$(config_get_cpufreq "mglru_enabled")" = 1 ]; then
|
||||
echo y >/sys/kernel/mm/lru_gen/enabled
|
||||
config_get_cpufreq "mglru_min_ttl_ms" > /sys/kernel/mm/lru_gen/min_ttl_ms
|
||||
else
|
||||
echo n >/sys/kernel/mm/lru_gen/enabled
|
||||
fi
|
||||
fi
|
||||
|
||||
# cpufreq
|
||||
for i in $(find /sys/devices/system/cpu/cpufreq/policy* -maxdepth 0 | grep -Eo '[0-9]+')
|
||||
do
|
||||
[ -z "$(config_get_cpufreq "governor$i")" ] && return
|
||||
|
||||
config_get_cpufreq "governor$i" > "/sys/devices/system/cpu/cpufreq/policy$i/scaling_governor"
|
||||
config_get_cpufreq "minfreq$i" > "/sys/devices/system/cpu/cpufreq/policy$i/scaling_min_freq"
|
||||
config_get_cpufreq "maxfreq$i" > "/sys/devices/system/cpu/cpufreq/policy$i/scaling_max_freq"
|
||||
if [ "$(config_get_cpufreq "governor$i")" = "ondemand" ]; then
|
||||
config_get_cpufreq "sdfactor$i" > "/sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor"
|
||||
config_get_cpufreq "upthreshold$i" > "/sys/devices/system/cpu/cpufreq/ondemand/up_threshold"
|
||||
fi
|
||||
done
|
||||
|
||||
# pwm-fan
|
||||
if [ "$(config_get_cpufreq "pwm_fan")" = 1 ]; then
|
||||
procd_open_instance pwm-fan
|
||||
procd_set_param command /usr/sbin/rockchip-pwm-fan
|
||||
procd_append_param command -t "$(config_get_cpufreq "pwm_fan_threshold")"
|
||||
[ "$(config_get_cpufreq "pwm_fan_strict")" != 1 ] && procd_append_param command -s
|
||||
[ -n "$(config_get_cpufreq "pwm_fan_enforce_level")" ] && [ "$(config_get_cpufreq "pwm_fan_enforce_level")" != "auto" ] && procd_append_param command -k "$(config_get_cpufreq "pwm_fan_enforce_level")"
|
||||
procd_set_param stdout 0
|
||||
procd_set_param stderr 0
|
||||
procd_set_param respawn
|
||||
procd_close_instance pwm-fan
|
||||
else
|
||||
echo 0 > /sys/devices/virtual/thermal/cooling_device0/cur_state
|
||||
fi
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "cpufreq"
|
||||
}
|
48
luci-app-cpufreq/root/etc/uci-defaults/10-cpufreq
Executable file
48
luci-app-cpufreq/root/etc/uci-defaults/10-cpufreq
Executable file
@ -0,0 +1,48 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Multi-Gen LRU
|
||||
if [ -z $(uci -q get cpufreq.cpufreq.mglru_enabled) ]; then
|
||||
uci -q set cpufreq.cpufreq.mglru_enabled="1"
|
||||
uci -q set cpufreq.cpufreq.mglru_min_ttl_ms="1000"
|
||||
uci -q commit cpufreq
|
||||
fi
|
||||
|
||||
# Cpufreq
|
||||
if [ -z $(uci -q get cpufreq.cpufreq.governor0) ]; then
|
||||
|
||||
uci_write_config() {
|
||||
uci -q set cpufreq.cpufreq.governor$1="$2"
|
||||
uci -q set cpufreq.cpufreq.minfreq$1="$3"
|
||||
uci -q set cpufreq.cpufreq.maxfreq$1="$4"
|
||||
[ -n "$5" ] && uci -q set cpufreq.cpufreq.sdfactor$1="$5"
|
||||
[ -n "$6" ] && uci -q set cpufreq.cpufreq.upthreshold$1="$6"
|
||||
uci -q commit cpufreq
|
||||
}
|
||||
|
||||
CPU_FREQS="$(cat '/sys/devices/system/cpu/cpufreq/policy0/scaling_available_frequencies')"
|
||||
CPU_POLICYS="$(find '/sys/devices/system/cpu/cpufreq/policy'* -maxdepth 0 | grep -Eo '[0-9]+')"
|
||||
source "/etc/openwrt_release"
|
||||
case "$DISTRIB_TARGET" in
|
||||
"rockchip/armv8")
|
||||
uci_write_config 0 schedutil $(echo $CPU_FREQS | awk '{print $2}') $(echo $CPU_FREQS | awk '{print $NF}')
|
||||
# big.Little
|
||||
if echo "$CPU_POLICYS" | grep -q "4"; then
|
||||
CPU_FREQS_PERFORMANCE="$(cat "/sys/devices/system/cpu/cpufreq/policy${CPU_POLICYS}/scaling_available_frequencies")"
|
||||
uci_write_config 4 schedutil $(echo $CPU_FREQS_PERFORMANCE | awk '{print $2}') $(echo $CPU_FREQS_PERFORMANCE | awk '{print $NF}')
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
fi
|
||||
|
||||
[ -f "/etc/config/ucitrack" ] && {
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@cpufreq[-1]
|
||||
add ucitrack cpufreq
|
||||
set ucitrack.@cpufreq[-1].init=cpufreq
|
||||
commit ucitrack
|
||||
EOF
|
||||
}
|
||||
|
||||
rm -f /tmp/luci-indexcache*
|
||||
exit 0
|
BIN
luci-app-cpufreq/root/usr/sbin/rockchip-pwm-fan
Executable file
BIN
luci-app-cpufreq/root/usr/sbin/rockchip-pwm-fan
Executable file
Binary file not shown.
@ -0,0 +1,11 @@
|
||||
{
|
||||
"luci-app-cpufreq": {
|
||||
"description": "Grant UCI access for luci-app-cpufreq",
|
||||
"read": {
|
||||
"uci": [ "cpufreq" ]
|
||||
},
|
||||
"write": {
|
||||
"uci": [ "cpufreq" ]
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"config": "cpufreq",
|
||||
"init": "cpufreq"
|
||||
}
|
47
luci-app-diskman/Makefile
Normal file
47
luci-app-diskman/Makefile
Normal file
@ -0,0 +1,47 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-diskman
|
||||
PKG_VERSION:=v0.2.13
|
||||
PKG_RELEASE:=2
|
||||
|
||||
PKG_MAINTAINER:=lisaac <lisaac.cn@gmail.com>
|
||||
PKG_LICENSE:=AGPL-3.0
|
||||
|
||||
LUCI_TITLE:=Disk Manager interface for LuCI
|
||||
|
||||
LUCI_DEPENDS:=+e2fsprogs +parted +smartmontools +blkid +swap-utils \
|
||||
+PACKAGE_$(PKG_NAME)_INCLUDE_btrfs_progs:btrfs-progs \
|
||||
+PACKAGE_$(PKG_NAME)_INCLUDE_lsblk:lsblk \
|
||||
+PACKAGE_$(PKG_NAME)_INCLUDE_mdadm:mdadm \
|
||||
+PACKAGE_$(PKG_NAME)_INCLUDE_kmod_md_raid456:mdadm \
|
||||
+PACKAGE_$(PKG_NAME)_INCLUDE_kmod_md_raid456:kmod-md-raid456 \
|
||||
+PACKAGE_$(PKG_NAME)_INCLUDE_kmod_md_linears:mdadm \
|
||||
+PACKAGE_$(PKG_NAME)_INCLUDE_kmod_md_linears:kmod-md-linear
|
||||
|
||||
define Package/$(PKG_NAME)/config
|
||||
config PACKAGE_$(PKG_NAME)_INCLUDE_btrfs_progs
|
||||
bool "Include btrfs-progs"
|
||||
default y
|
||||
|
||||
config PACKAGE_$(PKG_NAME)_INCLUDE_lsblk
|
||||
bool "Include lsblk"
|
||||
default y
|
||||
|
||||
config PACKAGE_$(PKG_NAME)_INCLUDE_mdadm
|
||||
bool "Include mdadm"
|
||||
default n
|
||||
|
||||
config PACKAGE_$(PKG_NAME)_INCLUDE_kmod_md_raid456
|
||||
depends on PACKAGE_$(PKG_NAME)_INCLUDE_mdadm
|
||||
bool "Include kmod-md-raid456"
|
||||
default n
|
||||
|
||||
config PACKAGE_$(PKG_NAME)_INCLUDE_kmod_md_linears
|
||||
depends on PACKAGE_$(PKG_NAME)_INCLUDE_mdadm
|
||||
bool "Include kmod-md-linear"
|
||||
default n
|
||||
endef
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
151
luci-app-diskman/luasrc/controller/diskman.lua
Normal file
151
luci-app-diskman/luasrc/controller/diskman.lua
Normal file
@ -0,0 +1,151 @@
|
||||
--[[
|
||||
LuCI - Lua Configuration Interface
|
||||
Copyright 2019 lisaac <https://github.com/lisaac/luci-app-diskman>
|
||||
]]--
|
||||
|
||||
require "luci.util"
|
||||
module("luci.controller.diskman",package.seeall)
|
||||
|
||||
function index()
|
||||
-- check all used executables in disk management are existed
|
||||
local CMD = {"parted", "blkid", "smartctl"}
|
||||
local executables_all_existed = true
|
||||
for _, cmd in ipairs(CMD) do
|
||||
local command = luci.sys.exec("/usr/bin/which " .. cmd)
|
||||
if not command:match(cmd) then
|
||||
executables_all_existed = false
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not executables_all_existed then return end
|
||||
-- entry(path, target, title, order)
|
||||
-- set leaf attr to true to pass argument throughe url (e.g. admin/system/disk/partition/sda)
|
||||
entry({"admin", "system", "diskman"}, alias("admin", "system", "diskman", "disks"), _("Disk Man"), 55)
|
||||
entry({"admin", "system", "diskman", "disks"}, form("diskman/disks"), nil).leaf = true
|
||||
entry({"admin", "system", "diskman", "partition"}, form("diskman/partition"), nil).leaf = true
|
||||
entry({"admin", "system", "diskman", "btrfs"}, form("diskman/btrfs"), nil).leaf = true
|
||||
entry({"admin", "system", "diskman", "format_partition"}, call("format_partition"), nil).leaf = true
|
||||
entry({"admin", "system", "diskman", "get_disk_info"}, call("get_disk_info"), nil).leaf = true
|
||||
entry({"admin", "system", "diskman", "mk_p_table"}, call("mk_p_table"), nil).leaf = true
|
||||
entry({"admin", "system", "diskman", "smartdetail"}, call("smart_detail"), nil).leaf = true
|
||||
entry({"admin", "system", "diskman", "smartattr"}, call("smart_attr"), nil).leaf = true
|
||||
end
|
||||
|
||||
function format_partition()
|
||||
local partation_name = luci.http.formvalue("partation_name")
|
||||
local fs = luci.http.formvalue("file_system")
|
||||
if not partation_name then
|
||||
luci.http.status(500, "Partition NOT found!")
|
||||
luci.http.write_json("Partition NOT found!")
|
||||
return
|
||||
elseif not nixio.fs.access("/dev/"..partation_name) then
|
||||
luci.http.status(500, "Partition NOT found!")
|
||||
luci.http.write_json("Partition NOT found!")
|
||||
return
|
||||
elseif not fs then
|
||||
luci.http.status(500, "no file system")
|
||||
luci.http.write_json("no file system")
|
||||
return
|
||||
end
|
||||
local dm = require "luci.model.diskman"
|
||||
code, msg = dm.format_partition(partation_name, fs)
|
||||
luci.http.status(code, msg)
|
||||
luci.http.write_json(msg)
|
||||
end
|
||||
|
||||
function get_disk_info(dev)
|
||||
if not dev then
|
||||
luci.http.status(500, "no device")
|
||||
luci.http.write_json("no device")
|
||||
return
|
||||
elseif not nixio.fs.access("/dev/"..dev) then
|
||||
luci.http.status(500, "no device")
|
||||
luci.http.write_json("no device")
|
||||
return
|
||||
end
|
||||
local dm = require "luci.model.diskman"
|
||||
local device_info = dm.get_disk_info(dev)
|
||||
luci.http.status(200, "ok")
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(device_info)
|
||||
end
|
||||
|
||||
function mk_p_table()
|
||||
local p_table = luci.http.formvalue("p_table")
|
||||
local dev = luci.http.formvalue("dev")
|
||||
if not dev then
|
||||
luci.http.status(500, "no device")
|
||||
luci.http.write_json("no device")
|
||||
return
|
||||
elseif not nixio.fs.access("/dev/"..dev) then
|
||||
luci.http.status(500, "no device")
|
||||
luci.http.write_json("no device")
|
||||
return
|
||||
end
|
||||
local dm = require "luci.model.diskman"
|
||||
if p_table == "GPT" or p_table == "MBR" then
|
||||
p_table = p_table == "MBR" and "msdos" or "gpt"
|
||||
local res = luci.sys.call(dm.command.parted .. " -s /dev/" .. dev .. " mktable ".. p_table)
|
||||
if res == 0 then
|
||||
luci.http.status(200, "ok")
|
||||
else
|
||||
luci.http.status(500, "command exec error")
|
||||
end
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json({code=res})
|
||||
else
|
||||
luci.http.status(404, "not support")
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json({code="1"})
|
||||
end
|
||||
end
|
||||
|
||||
function smart_detail(dev)
|
||||
luci.template.render("diskman/smart_detail", {dev=dev})
|
||||
end
|
||||
|
||||
function smart_attr(dev)
|
||||
local attr = { }
|
||||
local dm = require "luci.model.diskman"
|
||||
local cmd = io.popen(dm.command.smartctl .. " -H -A -i /dev/%s" % dev)
|
||||
if cmd then
|
||||
local content = cmd:read("*all")
|
||||
local ln
|
||||
cmd:close()
|
||||
if content:match("NVMe Version:")then
|
||||
for ln in string.gmatch(content,'[^\r\n]+') do
|
||||
if ln:match("^(.-):%s+(.+)") then
|
||||
local key, value = ln:match("^(.-):%s+(.+)")
|
||||
attr[#attr+1]= {
|
||||
key = key,
|
||||
value = value
|
||||
}
|
||||
end
|
||||
end
|
||||
else
|
||||
for ln in string.gmatch(content,'[^\r\n]+') do
|
||||
if ln:match("^.*%d+%s+.+%s+.+%s+.+%s+.+%s+.+%s+.+%s+.+%s+.+%s+.+") then
|
||||
local id,attrbute,flag,value,worst,thresh,type,updated,raw = ln:match("^%s*(%d+)%s+([%a%p]+)%s+(%w+)%s+(%d+)%s+(%d+)%s+(%d+)%s+([%a%p]+)%s+(%a+)%s+[%w%p]+%s+(.+)")
|
||||
id= "%x" % id
|
||||
if not id:match("^%w%w") then
|
||||
id = "0%s" % id
|
||||
end
|
||||
attr[#attr+1]= {
|
||||
id = id:upper(),
|
||||
attrbute = attrbute,
|
||||
flag = flag,
|
||||
value = value,
|
||||
worst = worst,
|
||||
thresh = thresh,
|
||||
type = type,
|
||||
updated = updated,
|
||||
raw = raw
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(attr)
|
||||
end
|
210
luci-app-diskman/luasrc/model/cbi/diskman/btrfs.lua
Normal file
210
luci-app-diskman/luasrc/model/cbi/diskman/btrfs.lua
Normal file
@ -0,0 +1,210 @@
|
||||
--[[
|
||||
LuCI - Lua Configuration Interface
|
||||
Copyright 2019 lisaac <https://github.com/lisaac/luci-app-diskman>
|
||||
]]--
|
||||
|
||||
require "luci.util"
|
||||
require("luci.tools.webadmin")
|
||||
local dm = require "luci.model.diskman"
|
||||
local uuid = arg[1]
|
||||
|
||||
if not uuid then luci.http.redirect(luci.dispatcher.build_url("admin/system/diskman")) end
|
||||
|
||||
-- mount subv=/ to tempfs
|
||||
mount_point = "/tmp/.btrfs_tmp"
|
||||
nixio.fs.mkdirr(mount_point)
|
||||
luci.util.exec(dm.command.umount .. " "..mount_point .. " >/dev/null 2>&1")
|
||||
luci.util.exec(dm.command.mount .. " -t btrfs -o subvol=/ UUID="..uuid.." "..mount_point)
|
||||
|
||||
m = SimpleForm("btrfs", translate("Btrfs"), translate("Manage Btrfs"))
|
||||
m.template = "diskman/cbi/xsimpleform"
|
||||
m.redirect = luci.dispatcher.build_url("admin/system/diskman")
|
||||
m.submit = false
|
||||
m.reset = false
|
||||
|
||||
-- info
|
||||
local btrfs_info = dm.get_btrfs_info(mount_point)
|
||||
local table_btrfs_info = m:section(Table, {btrfs_info}, translate("Btrfs Info"))
|
||||
table_btrfs_info:option(DummyValue, "uuid", translate("UUID"))
|
||||
table_btrfs_info:option(DummyValue, "members", translate("Members"))
|
||||
table_btrfs_info:option(DummyValue, "data_raid_level", translate("Data"))
|
||||
table_btrfs_info:option(DummyValue, "metadata_raid_lavel", translate("Metadata"))
|
||||
table_btrfs_info:option(DummyValue, "size_formated", translate("Size"))
|
||||
table_btrfs_info:option(DummyValue, "used_formated", translate("Used"))
|
||||
table_btrfs_info:option(DummyValue, "free_formated", translate("Free Space"))
|
||||
table_btrfs_info:option(DummyValue, "usage", translate("Usage"))
|
||||
local v_btrfs_label = table_btrfs_info:option(Value, "label", translate("Label"))
|
||||
local value_btrfs_label = ""
|
||||
v_btrfs_label.write = function(self, section, value)
|
||||
value_btrfs_label = value or ""
|
||||
end
|
||||
local btn_update_label = table_btrfs_info:option(Button, "_update_label")
|
||||
btn_update_label.inputtitle = translate("Update")
|
||||
btn_update_label.inputstyle = "edit"
|
||||
btn_update_label.write = function(self, section, value)
|
||||
local cmd = dm.command.btrfs .. " filesystem label " .. mount_point .. " " .. value_btrfs_label
|
||||
local res = luci.util.exec(cmd)
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin/system/diskman/btrfs/" .. uuid))
|
||||
end
|
||||
-- subvolume
|
||||
local subvolume_list = dm.get_btrfs_subv(mount_point)
|
||||
subvolume_list["_"] = { ID = 0 }
|
||||
table_subvolume = m:section(Table, subvolume_list, translate("SubVolumes"))
|
||||
table_subvolume:option(DummyValue, "id", translate("ID"))
|
||||
table_subvolume:option(DummyValue, "top_level", translate("Top Level"))
|
||||
table_subvolume:option(DummyValue, "uuid", translate("UUID"))
|
||||
table_subvolume:option(DummyValue, "otime", translate("Otime"))
|
||||
table_subvolume:option(DummyValue, "snapshots", translate("Snapshots"))
|
||||
local v_path = table_subvolume:option(Value, "path", translate("Path"))
|
||||
v_path.forcewrite = true
|
||||
v_path.render = function(self, section, scope)
|
||||
if subvolume_list[section].ID == 0 then
|
||||
self.template = "cbi/value"
|
||||
self.placeholder = "/my_subvolume"
|
||||
self.forcewrite = true
|
||||
Value.render(self, section, scope)
|
||||
else
|
||||
self.template = "cbi/dvalue"
|
||||
DummyValue.render(self, section, scope)
|
||||
end
|
||||
end
|
||||
local value_path
|
||||
v_path.write = function(self, section, value)
|
||||
value_path = value
|
||||
end
|
||||
local btn_set_default = table_subvolume:option(Button, "_subv_set_default", translate("Set Default"))
|
||||
btn_set_default.forcewrite = true
|
||||
btn_set_default.inputstyle = "edit"
|
||||
btn_set_default.template = "diskman/cbi/disabled_button"
|
||||
btn_set_default.render = function(self, section, scope)
|
||||
if subvolume_list[section].default_subvolume then
|
||||
self.view_disabled = true
|
||||
self.inputtitle = translate("Set Default")
|
||||
elseif subvolume_list[section].ID == 0 then
|
||||
self.template = "cbi/dvalue"
|
||||
else
|
||||
self.inputtitle = translate("Set Default")
|
||||
self.view_disabled = false
|
||||
end
|
||||
Button.render(self, section, scope)
|
||||
end
|
||||
btn_set_default.write = function(self, section, value)
|
||||
local cmd
|
||||
if value == translate("Set Default") then
|
||||
cmd = dm.command.btrfs .. " subvolume set-default " .. mount_point..subvolume_list[section].path
|
||||
else
|
||||
cmd = dm.command.btrfs .. " subvolume set-default " .. mount_point.."/"
|
||||
end
|
||||
local res = luci.util.exec(cmd.. " 2>&1")
|
||||
if res and (res:match("ERR") or res:match("not enough arguments")) then
|
||||
m.errmessage = res
|
||||
else
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin/system/diskman/btrfs/" .. uuid))
|
||||
end
|
||||
end
|
||||
local btn_remove = table_subvolume:option(Button, "_subv_remove")
|
||||
btn_remove.template = "diskman/cbi/disabled_button"
|
||||
btn_remove.forcewrite = true
|
||||
btn_remove.render = function(self, section, scope)
|
||||
if subvolume_list[section].ID == 0 then
|
||||
btn_remove.inputtitle = translate("Create")
|
||||
btn_remove.inputstyle = "add"
|
||||
self.view_disabled = false
|
||||
elseif subvolume_list[section].path == "/" or subvolume_list[section].default_subvolume then
|
||||
btn_remove.inputtitle = translate("Delete")
|
||||
btn_remove.inputstyle = "remove"
|
||||
self.view_disabled = true
|
||||
else
|
||||
btn_remove.inputtitle = translate("Delete")
|
||||
btn_remove.inputstyle = "remove"
|
||||
self.view_disabled = false
|
||||
end
|
||||
Button.render(self, section, scope)
|
||||
end
|
||||
|
||||
btn_remove.write = function(self, section, value)
|
||||
local cmd
|
||||
if value == translate("Delete") then
|
||||
cmd = dm.command.btrfs .. " subvolume delete " .. mount_point .. subvolume_list[section].path
|
||||
elseif value == translate("Create") then
|
||||
if value_path and value_path:match("^/") then
|
||||
cmd = dm.command.btrfs .. " subvolume create " .. mount_point .. value_path
|
||||
else
|
||||
m.errmessage = translate("Please input Subvolume Path, Subvolume must start with '/'")
|
||||
return
|
||||
end
|
||||
end
|
||||
local res = luci.util.exec(cmd.. " 2>&1")
|
||||
if res and (res:match("ERR") or res:match("not enough arguments")) then
|
||||
m.errmessage = luci.util.pcdata(res)
|
||||
else
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin/system/diskman/btrfs/" .. uuid))
|
||||
end
|
||||
end
|
||||
-- snapshot
|
||||
-- local snapshot_list = dm.get_btrfs_subv(mount_point, 1)
|
||||
-- table_snapshot = m:section(Table, snapshot_list, translate("Snapshots"))
|
||||
-- table_snapshot:option(DummyValue, "id", translate("ID"))
|
||||
-- table_snapshot:option(DummyValue, "top_level", translate("Top Level"))
|
||||
-- table_snapshot:option(DummyValue, "uuid", translate("UUID"))
|
||||
-- table_snapshot:option(DummyValue, "otime", translate("Otime"))
|
||||
-- table_snapshot:option(DummyValue, "path", translate("Path"))
|
||||
-- local snp_remove = table_snapshot:option(Button, "_snp_remove")
|
||||
-- snp_remove.inputtitle = translate("Delete")
|
||||
-- snp_remove.inputstyle = "remove"
|
||||
-- snp_remove.write = function(self, section, value)
|
||||
-- local cmd = dm.command.btrfs .. " subvolume delete " .. mount_point .. snapshot_list[section].path
|
||||
-- local res = luci.util.exec(cmd.. " 2>&1")
|
||||
-- if res and (res:match("ERR") or res:match("not enough arguments")) then
|
||||
-- m.errmessage = luci.util.pcdata(res)
|
||||
-- else
|
||||
-- luci.http.redirect(luci.dispatcher.build_url("admin/system/diskman/btrfs/" .. uuid))
|
||||
-- end
|
||||
-- end
|
||||
|
||||
-- new snapshots
|
||||
local s_snapshot = m:section(SimpleSection, translate("New Snapshot"))
|
||||
local value_sorce, value_dest, value_readonly
|
||||
local v_sorce = s_snapshot:option(Value, "_source", translate("Source Path"), translate("The source path for create the snapshot"))
|
||||
v_sorce.placeholder = "/data"
|
||||
v_sorce.forcewrite = true
|
||||
v_sorce.write = function(self, section, value)
|
||||
value_sorce = value
|
||||
end
|
||||
|
||||
local v_readonly = s_snapshot:option(Flag, "_readonly", translate("Readonly"), translate("The path where you want to store the snapshot"))
|
||||
v_readonly.forcewrite = true
|
||||
v_readonly.rmempty = false
|
||||
v_readonly.disabled = 0
|
||||
v_readonly.enabled = 1
|
||||
v_readonly.default = 1
|
||||
v_readonly.write = function(self, section, value)
|
||||
value_readonly = value
|
||||
end
|
||||
local v_dest = s_snapshot:option(Value, "_dest", translate("Destination Path (optional)"))
|
||||
v_dest.forcewrite = true
|
||||
v_dest.placeholder = "/.snapshot/202002051538"
|
||||
v_dest.write = function(self, section, value)
|
||||
value_dest = value
|
||||
end
|
||||
local btn_snp_create = s_snapshot:option(Button, "_snp_create")
|
||||
btn_snp_create.title = " "
|
||||
btn_snp_create.inputtitle = translate("New Snapshot")
|
||||
btn_snp_create.inputstyle = "add"
|
||||
btn_snp_create.write = function(self, section, value)
|
||||
if value_sorce and value_sorce:match("^/") then
|
||||
if not value_dest then value_dest = "/.snapshot"..value_sorce.."/"..os.date("%Y%m%d%H%M%S") end
|
||||
nixio.fs.mkdirr(mount_point..value_dest:match("(.-)[^/]+$"))
|
||||
local cmd = dm.command.btrfs .. " subvolume snapshot" .. (value_readonly == 1 and " -r " or " ") .. mount_point..value_sorce .. " " .. mount_point..value_dest
|
||||
local res = luci.util.exec(cmd .. " 2>&1")
|
||||
if res and (res:match("ERR") or res:match("not enough arguments")) then
|
||||
m.errmessage = luci.util.pcdata(res)
|
||||
else
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin/system/diskman/btrfs/" .. uuid))
|
||||
end
|
||||
else
|
||||
m.errmessage = translate("Please input Source Path of snapshot, Source Path must start with '/'")
|
||||
end
|
||||
end
|
||||
|
||||
return m
|
360
luci-app-diskman/luasrc/model/cbi/diskman/disks.lua
Normal file
360
luci-app-diskman/luasrc/model/cbi/diskman/disks.lua
Normal file
@ -0,0 +1,360 @@
|
||||
--[[
|
||||
LuCI - Lua Configuration Interface
|
||||
Copyright 2019 lisaac <https://github.com/lisaac/luci-app-diskman>
|
||||
]]--
|
||||
|
||||
require "luci.util"
|
||||
require("luci.tools.webadmin")
|
||||
local dm = require "luci.model.diskman"
|
||||
|
||||
-- Use (non-UCI) SimpleForm since we have no related config file
|
||||
m = SimpleForm("diskman", translate("DiskMan"), translate("Manage Disks over LuCI."))
|
||||
m.template = "diskman/cbi/xsimpleform"
|
||||
m:append(Template("diskman/disk_info"))
|
||||
-- disable submit and reset button
|
||||
m.submit = false
|
||||
m.reset = false
|
||||
-- rescan disks
|
||||
rescan = m:section(SimpleSection)
|
||||
rescan_button = rescan:option(Button, "_rescan")
|
||||
rescan_button.inputtitle= translate("Rescan Disks")
|
||||
rescan_button.template = "diskman/cbi/inlinebutton"
|
||||
rescan_button.inputstyle = "add"
|
||||
rescan_button.forcewrite = true
|
||||
rescan_button.write = function(self, section, value)
|
||||
luci.util.exec("echo '- - -' | tee /sys/class/scsi_host/host*/scan > /dev/null")
|
||||
if dm.command.mdadm then
|
||||
luci.util.exec(dm.command.mdadm .. " --assemble --scan")
|
||||
end
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin/system/diskman"))
|
||||
end
|
||||
|
||||
-- disks
|
||||
local disks = dm.list_devices()
|
||||
d = m:section(Table, disks, translate("Disks"))
|
||||
d.config = "disk"
|
||||
-- option(type, id(key of table), text)
|
||||
d:option(DummyValue, "path", translate("Path"))
|
||||
d:option(DummyValue, "model", translate("Model"))
|
||||
d:option(DummyValue, "sn", translate("Serial Number"))
|
||||
d:option(DummyValue, "size_formated", translate("Size"))
|
||||
d:option(DummyValue, "temp", translate("Temp"))
|
||||
-- d:option(DummyValue, "sec_size", translate("Sector Size "))
|
||||
d:option(DummyValue, "p_table", translate("Partition Table"))
|
||||
d:option(DummyValue, "sata_ver", translate("SATA Version"))
|
||||
-- d:option(DummyValue, "rota_rate", translate("Rotation Rate"))
|
||||
d:option(DummyValue, "health_status", translate("Health") .. "<br/>" .. translate("Status"))
|
||||
-- d:option(DummyValue, "status", translate("Status"))
|
||||
|
||||
local btn_eject = d:option(Button, "_eject")
|
||||
btn_eject.template = "diskman/cbi/disabled_button"
|
||||
btn_eject.inputstyle = "remove"
|
||||
btn_eject.inputtitle = translate("Eject")
|
||||
btn_eject.forcewrite = true
|
||||
btn_eject.write = function(self, section, value)
|
||||
local dev = section
|
||||
local disk_info = dm.get_disk_info(dev, true)
|
||||
if disk_info.p_table:match("Raid") then
|
||||
m.errmessage = translate("Unsupported raid reject!")
|
||||
return
|
||||
end
|
||||
for i, p in ipairs(disk_info.partitions) do
|
||||
if p.mount_point ~= "-" then
|
||||
m.errmessage = p.name .. translate("is in use! please unmount it first!")
|
||||
return
|
||||
end
|
||||
end
|
||||
if disk_info.type:match("md") then
|
||||
luci.util.exec(dm.command.mdadm .. " --stop /dev/" .. dev)
|
||||
luci.util.exec(dm.command.mdadm .. " --remove /dev/" .. dev)
|
||||
for _, disk in ipairs(disk_info.members) do
|
||||
luci.util.exec(dm.command.mdadm .. " --zero-superblock " .. disk)
|
||||
end
|
||||
dm.gen_mdadm_config()
|
||||
else
|
||||
luci.util.exec("echo 1 > /sys/block/" .. dev .. "/device/delete")
|
||||
end
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin/system/diskman"))
|
||||
end
|
||||
|
||||
d.extedit = luci.dispatcher.build_url("admin/system/diskman/partition/%s")
|
||||
|
||||
-- raid devices
|
||||
if dm.command.mdadm then
|
||||
local raid_devices = dm.list_raid_devices()
|
||||
-- raid_devices = diskmanager.getRAIDdevices()
|
||||
if next(raid_devices) ~= nil then
|
||||
local r = m:section(Table, raid_devices, translate("RAID Devices"))
|
||||
r.config = "_raid"
|
||||
r:option(DummyValue, "path", translate("Path"))
|
||||
r:option(DummyValue, "level", translate("RAID mode"))
|
||||
r:option(DummyValue, "size_formated", translate("Size"))
|
||||
r:option(DummyValue, "p_table", translate("Partition Table"))
|
||||
r:option(DummyValue, "status", translate("Status"))
|
||||
r:option(DummyValue, "members_str", translate("Members"))
|
||||
r:option(DummyValue, "active", translate("Active"))
|
||||
r.extedit = luci.dispatcher.build_url("admin/system/diskman/partition/%s")
|
||||
end
|
||||
end
|
||||
|
||||
-- btrfs devices
|
||||
if dm.command.btrfs then
|
||||
btrfs_devices = dm.list_btrfs_devices()
|
||||
if next(btrfs_devices) ~= nil then
|
||||
local table_btrfs = m:section(Table, btrfs_devices, translate("Btrfs"))
|
||||
table_btrfs:option(DummyValue, "uuid", translate("UUID"))
|
||||
table_btrfs:option(DummyValue, "label", translate("Label"))
|
||||
table_btrfs:option(DummyValue, "members", translate("Members"))
|
||||
-- sieze is error, since there is RAID
|
||||
-- table_btrfs:option(DummyValue, "size_formated", translate("Size"))
|
||||
table_btrfs:option(DummyValue, "used_formated", translate("Usage"))
|
||||
table_btrfs.extedit = luci.dispatcher.build_url("admin/system/diskman/btrfs/%s")
|
||||
end
|
||||
end
|
||||
|
||||
-- mount point
|
||||
local mount_point = dm.get_mount_points()
|
||||
local _mount_point = {}
|
||||
table.insert( mount_point, { device = 0 } )
|
||||
local table_mp = m:section(Table, mount_point, translate("Mount Point"))
|
||||
local v_device = table_mp:option(Value, "device", translate("Device"))
|
||||
v_device.render = function(self, section, scope)
|
||||
if mount_point[section].device == 0 then
|
||||
self.template = "cbi/value"
|
||||
self.forcewrite = true
|
||||
for dev, info in pairs(disks) do
|
||||
for i, v in ipairs(info.partitions) do
|
||||
self:value("/dev/".. v.name, "/dev/".. v.name .. " ".. v.size_formated)
|
||||
end
|
||||
end
|
||||
Value.render(self, section, scope)
|
||||
else
|
||||
self.template = "cbi/dvalue"
|
||||
DummyValue.render(self, section, scope)
|
||||
end
|
||||
end
|
||||
v_device.write = function(self, section, value)
|
||||
_mount_point.device = value and value:gsub("%s+", "") or ""
|
||||
end
|
||||
local v_fs = table_mp:option(Value, "fs", translate("File System"))
|
||||
v_fs.render = function(self, section, scope)
|
||||
if mount_point[section].device == 0 then
|
||||
self.template = "cbi/value"
|
||||
self:value("auto", "auto")
|
||||
self.default = "auto"
|
||||
self.forcewrite = true
|
||||
Value.render(self, section, scope)
|
||||
else
|
||||
self.template = "cbi/dvalue"
|
||||
DummyValue.render(self, section, scope)
|
||||
end
|
||||
end
|
||||
v_fs.write = function(self, section, value)
|
||||
_mount_point.fs = value and value:gsub("%s+", "") or ""
|
||||
end
|
||||
local v_mount_option = table_mp:option(Value, "mount_options", translate("Mount Options"))
|
||||
v_mount_option.render = function(self, section, scope)
|
||||
if mount_point[section].device == 0 then
|
||||
self.template = "cbi/value"
|
||||
self.placeholder = "rw,noauto"
|
||||
self.forcewrite = true
|
||||
Value.render(self, section, scope)
|
||||
else
|
||||
self.template = "cbi/dvalue"
|
||||
local mp = mount_point[section].mount_options
|
||||
mount_point[section].mount_options = nil
|
||||
local length = 0
|
||||
for k in mp:gmatch("([^,]+)") do
|
||||
mount_point[section].mount_options = mount_point[section].mount_options and (mount_point[section].mount_options .. ",") or ""
|
||||
if length > 20 then
|
||||
mount_point[section].mount_options = mount_point[section].mount_options.. " <br>"
|
||||
length = 0
|
||||
end
|
||||
mount_point[section].mount_options = mount_point[section].mount_options .. k
|
||||
length = length + #k
|
||||
end
|
||||
self.rawhtml = true
|
||||
-- mount_point[section].mount_options = #mount_point[section].mount_options > 50 and mount_point[section].mount_options:sub(1,50) .. "..." or mount_point[section].mount_options
|
||||
DummyValue.render(self, section, scope)
|
||||
end
|
||||
end
|
||||
v_mount_option.write = function(self, section, value)
|
||||
_mount_point.mount_options = value and value:gsub("%s+", "") or ""
|
||||
end
|
||||
local v_mount_point = table_mp:option(Value, "mount_point", translate("Mount Point"))
|
||||
v_mount_point.render = function(self, section, scope)
|
||||
if mount_point[section].device == 0 then
|
||||
self.template = "cbi/value"
|
||||
self.placeholder = "/media/diskX"
|
||||
self.forcewrite = true
|
||||
Value.render(self, section, scope)
|
||||
else
|
||||
self.template = "cbi/dvalue"
|
||||
local new_mp = ""
|
||||
local v_mp_d
|
||||
for v_mp_d in self["section"]["data"][section]["mount_point"]:gmatch('[^/]+') do
|
||||
if #v_mp_d > 12 then
|
||||
new_mp = new_mp .. "/" .. v_mp_d:sub(1,7) .. ".." .. v_mp_d:sub(-4)
|
||||
else
|
||||
new_mp = new_mp .."/".. v_mp_d
|
||||
end
|
||||
end
|
||||
self["section"]["data"][section]["mount_point"] = '<span title="'..self["section"]["data"][section]["mount_point"] .. '" >'..new_mp..'</span>'
|
||||
self.rawhtml = true
|
||||
DummyValue.render(self, section, scope)
|
||||
end
|
||||
end
|
||||
v_mount_point.write = function(self, section, value)
|
||||
_mount_point.mount_point = value
|
||||
end
|
||||
local btn_umount = table_mp:option(Button, "_mount", translate("Mount"))
|
||||
btn_umount.forcewrite = true
|
||||
btn_umount.render = function(self, section, scope)
|
||||
if mount_point[section].device == 0 then
|
||||
self.inputtitle = translate("Mount")
|
||||
btn_umount.inputstyle = "add"
|
||||
else
|
||||
self.inputtitle = translate("Umount")
|
||||
btn_umount.inputstyle = "remove"
|
||||
end
|
||||
Button.render(self, section, scope)
|
||||
end
|
||||
btn_umount.write = function(self, section, value)
|
||||
local res
|
||||
if value == translate("Mount") then
|
||||
if not _mount_point.mount_point or not _mount_point.device then return end
|
||||
luci.util.exec("mkdir -p ".. _mount_point.mount_point)
|
||||
res = luci.util.exec(dm.command.mount .. " ".. _mount_point.device .. (_mount_point.fs and (" -t ".. _mount_point.fs )or "") .. (_mount_point.mount_options and (" -o " .. _mount_point.mount_options.. " ") or " ").._mount_point.mount_point .. " 2>&1")
|
||||
elseif value == translate("Umount") then
|
||||
res = luci.util.exec(dm.command.umount .. " "..mount_point[section].mount_point .. " 2>&1")
|
||||
end
|
||||
if res:match("^mount:") or res:match("^umount:") then
|
||||
m.errmessage = luci.util.pcdata(res)
|
||||
else
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin/system/diskman"))
|
||||
end
|
||||
end
|
||||
|
||||
if dm.command.mdadm or dm.command.btrfs then
|
||||
local creation_section = m:section(TypedSection, "_creation")
|
||||
creation_section.cfgsections=function()
|
||||
return {translate("Creation")}
|
||||
end
|
||||
creation_section:tab("raid", translate("RAID"), translate("RAID Creation"))
|
||||
creation_section:tab("btrfs", translate("Btrfs"), translate("Multiple Devices Btrfs Creation"))
|
||||
|
||||
-- raid functions
|
||||
if dm.command.mdadm then
|
||||
|
||||
local rname, rmembers, rlevel
|
||||
local r_name = creation_section:taboption("raid", Value, "_rname", translate("Raid Name"))
|
||||
r_name.placeholder = dm.find_free_md_device()
|
||||
r_name.write = function(self, section, value)
|
||||
rname = value
|
||||
end
|
||||
local r_level = creation_section:taboption("raid", ListValue, "_rlevel", translate("Raid Level"))
|
||||
local valid_raid = luci.util.exec("grep -m1 'Personalities :' /proc/mdstat")
|
||||
if valid_raid:match("%[linear%]") then
|
||||
r_level:value("linear", "Linear")
|
||||
end
|
||||
if valid_raid:match("%[raid5%]") then
|
||||
r_level:value("5", "Raid 5")
|
||||
end
|
||||
if valid_raid:match("%[raid6%]") then
|
||||
r_level:value("6", "Raid 6")
|
||||
end
|
||||
if valid_raid:match("%[raid1%]") then
|
||||
r_level:value("1", "Raid 1")
|
||||
end
|
||||
if valid_raid:match("%[raid0%]") then
|
||||
r_level:value("0", "Raid 0")
|
||||
end
|
||||
if valid_raid:match("%[raid10%]") then
|
||||
r_level:value("10", "Raid 10")
|
||||
end
|
||||
r_level.write = function(self, section, value)
|
||||
rlevel = value
|
||||
end
|
||||
local r_member = creation_section:taboption("raid", DynamicList, "_rmember", translate("Raid Member"))
|
||||
for dev, info in pairs(disks) do
|
||||
if not info.inuse and #info.partitions == 0 then
|
||||
r_member:value(info.path, info.path.. " ".. info.size_formated)
|
||||
end
|
||||
for i, v in ipairs(info.partitions) do
|
||||
if not v.inuse then
|
||||
r_member:value("/dev/".. v.name, "/dev/".. v.name .. " ".. v.size_formated)
|
||||
end
|
||||
end
|
||||
end
|
||||
r_member.write = function(self, section, value)
|
||||
rmembers = value
|
||||
end
|
||||
local r_create = creation_section:taboption("raid", Button, "_rcreate")
|
||||
r_create.render = function(self, section, scope)
|
||||
self.title = " "
|
||||
self.inputtitle = translate("Create Raid")
|
||||
self.inputstyle = "add"
|
||||
Button.render(self, section, scope)
|
||||
end
|
||||
r_create.write = function(self, section, value)
|
||||
-- mdadm --create --verbose /dev/md0 --level=stripe --raid-devices=2 /dev/sdb6 /dev/sdc5
|
||||
local res = dm.create_raid(rname, rlevel, rmembers)
|
||||
if res and res:match("^ERR") then
|
||||
m.errmessage = luci.util.pcdata(res)
|
||||
return
|
||||
end
|
||||
dm.gen_mdadm_config()
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin/system/diskman"))
|
||||
end
|
||||
end
|
||||
|
||||
-- btrfs
|
||||
if dm.command.btrfs then
|
||||
local blabel, bmembers, blevel
|
||||
local btrfs_label = creation_section:taboption("btrfs", Value, "_blabel", translate("Btrfs Label"))
|
||||
btrfs_label.write = function(self, section, value)
|
||||
blabel = value
|
||||
end
|
||||
local btrfs_level = creation_section:taboption("btrfs", ListValue, "_blevel", translate("Btrfs Raid Level"))
|
||||
btrfs_level:value("single", "Single")
|
||||
btrfs_level:value("raid0", "Raid 0")
|
||||
btrfs_level:value("raid1", "Raid 1")
|
||||
btrfs_level:value("raid10", "Raid 10")
|
||||
btrfs_level.write = function(self, section, value)
|
||||
blevel = value
|
||||
end
|
||||
|
||||
local btrfs_member = creation_section:taboption("btrfs", DynamicList, "_bmember", translate("Btrfs Member"))
|
||||
for dev, info in pairs(disks) do
|
||||
if not info.inuse and #info.partitions == 0 then
|
||||
btrfs_member:value(info.path, info.path.. " ".. info.size_formated)
|
||||
end
|
||||
for i, v in ipairs(info.partitions) do
|
||||
if not v.inuse then
|
||||
btrfs_member:value("/dev/".. v.name, "/dev/".. v.name .. " ".. v.size_formated)
|
||||
end
|
||||
end
|
||||
end
|
||||
btrfs_member.write = function(self, section, value)
|
||||
bmembers = value
|
||||
end
|
||||
local btrfs_create = creation_section:taboption("btrfs", Button, "_bcreate")
|
||||
btrfs_create.render = function(self, section, scope)
|
||||
self.title = " "
|
||||
self.inputtitle = translate("Create Btrfs")
|
||||
self.inputstyle = "add"
|
||||
Button.render(self, section, scope)
|
||||
end
|
||||
btrfs_create.write = function(self, section, value)
|
||||
-- mkfs.btrfs -L label -d blevel /dev/sda /dev/sdb
|
||||
local res = dm.create_btrfs(blabel, blevel, bmembers)
|
||||
if res and res:match("^ERR") then
|
||||
m.errmessage = luci.util.pcdata(res)
|
||||
return
|
||||
end
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin/system/diskman"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return m
|
366
luci-app-diskman/luasrc/model/cbi/diskman/partition.lua
Normal file
366
luci-app-diskman/luasrc/model/cbi/diskman/partition.lua
Normal file
@ -0,0 +1,366 @@
|
||||
--[[
|
||||
LuCI - Lua Configuration Interface
|
||||
Copyright 2019 lisaac <https://github.com/lisaac/luci-app-diskman>
|
||||
]]--
|
||||
|
||||
require "luci.util"
|
||||
require("luci.tools.webadmin")
|
||||
local dm = require "luci.model.diskman"
|
||||
local dev = arg[1]
|
||||
|
||||
if not dev then
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin/system/diskman"))
|
||||
elseif not nixio.fs.access("/dev/"..dev) then
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin/system/diskman"))
|
||||
end
|
||||
|
||||
m = SimpleForm("partition", translate("Partition Management"), translate("Partition Disk over LuCI."))
|
||||
m.template = "diskman/cbi/xsimpleform"
|
||||
m.redirect = luci.dispatcher.build_url("admin/system/diskman")
|
||||
m:append(Template("diskman/partition_info"))
|
||||
-- disable submit and reset button
|
||||
m.submit = false
|
||||
m.reset = false
|
||||
|
||||
local disk_info = dm.get_disk_info(dev, true)
|
||||
local format_cmd = dm.get_format_cmd()
|
||||
|
||||
s = m:section(Table, {disk_info}, translate("Device Info"))
|
||||
-- s:option(DummyValue, "key")
|
||||
-- s:option(DummyValue, "value")
|
||||
s:option(DummyValue, "path", translate("Path"))
|
||||
s:option(DummyValue, "model", translate("Model"))
|
||||
s:option(DummyValue, "sn", translate("Serial Number"))
|
||||
s:option(DummyValue, "size_formated", translate("Size"))
|
||||
s:option(DummyValue, "sec_size", translate("Sector Size"))
|
||||
local dv_p_table = s:option(ListValue, "p_table", translate("Partition Table"))
|
||||
dv_p_table.render = function(self, section, scope)
|
||||
-- create table only if not used by raid and no partitions on disk
|
||||
if not disk_info.p_table:match("Raid") and (#disk_info.partitions == 0 or (#disk_info.partitions == 1 and disk_info.partitions[1].number == -1) or (disk_info.p_table:match("LOOP") and not disk_info.partitions[1].inuse)) then
|
||||
self:value(disk_info.p_table, disk_info.p_table)
|
||||
self:value("GPT", "GPT")
|
||||
self:value("MBR", "MBR")
|
||||
self.default = disk_info.p_table
|
||||
ListValue.render(self, section, scope)
|
||||
else
|
||||
self.template = "cbi/dvalue"
|
||||
DummyValue.render(self, section, scope)
|
||||
end
|
||||
end
|
||||
if disk_info.type:match("md") then
|
||||
s:option(DummyValue, "level", translate("Level"))
|
||||
s:option(DummyValue, "members_str", translate("Members"))
|
||||
else
|
||||
s:option(DummyValue, "temp", translate("Temp"))
|
||||
s:option(DummyValue, "sata_ver", translate("SATA Version"))
|
||||
s:option(DummyValue, "rota_rate", translate("Rotation Rate"))
|
||||
end
|
||||
s:option(DummyValue, "status", translate("Status"))
|
||||
local btn_health = s:option(Button, "health", translate("Health"))
|
||||
btn_health.render = function(self, section, scope)
|
||||
if disk_info.health then
|
||||
self.inputtitle = disk_info.health
|
||||
if disk_info.health == "PASSED" then
|
||||
self.inputstyle = "add"
|
||||
else
|
||||
self.inputstyle = "remove"
|
||||
end
|
||||
Button.render(self, section, scope)
|
||||
else
|
||||
self.template = "cbi/dvalue"
|
||||
DummyValue.render(self, section, scope)
|
||||
end
|
||||
end
|
||||
|
||||
local btn_eject = s:option(Button, "_eject")
|
||||
btn_eject.template = "diskman/cbi/disabled_button"
|
||||
btn_eject.inputstyle = "remove"
|
||||
btn_eject.render = function(self, section, scope)
|
||||
for i, p in ipairs(disk_info.partitions) do
|
||||
if p.mount_point ~= "-" then
|
||||
self.view_disabled = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if disk_info.p_table:match("Raid") then
|
||||
self.view_disabled = true
|
||||
end
|
||||
if disk_info.type:match("md") then
|
||||
btn_eject.inputtitle = translate("Remove")
|
||||
else
|
||||
btn_eject.inputtitle = translate("Eject")
|
||||
end
|
||||
Button.render(self, section, scope)
|
||||
end
|
||||
btn_eject.forcewrite = true
|
||||
btn_eject.write = function(self, section, value)
|
||||
for i, p in ipairs(disk_info.partitions) do
|
||||
if p.mount_point ~= "-" then
|
||||
m.errmessage = p.name .. translate("is in use! please unmount it first!")
|
||||
return
|
||||
end
|
||||
end
|
||||
if disk_info.type:match("md") then
|
||||
luci.util.exec(dm.command.mdadm .. " --stop /dev/" .. dev)
|
||||
luci.util.exec(dm.command.mdadm .. " --remove /dev/" .. dev)
|
||||
for _, disk in ipairs(disk_info.members) do
|
||||
luci.util.exec(dm.command.mdadm .. " --zero-superblock " .. disk)
|
||||
end
|
||||
dm.gen_mdadm_config()
|
||||
else
|
||||
luci.util.exec("echo 1 > /sys/block/" .. dev .. "/device/delete")
|
||||
end
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin/system/diskman"))
|
||||
end
|
||||
-- eject: echo 1 > /sys/block/(device)/device/delete
|
||||
-- rescan: echo '- - -' | tee /sys/class/scsi_host/host*/scan > /dev/null
|
||||
|
||||
|
||||
-- partitions info
|
||||
if not disk_info.p_table:match("Raid") then
|
||||
s_partition_table = m:section(Table, disk_info.partitions, translate("Partitions Info"), translate("Default 2048 sector alignment, support +size{b,k,m,g,t} in End Sector"))
|
||||
|
||||
-- s_partition_table:option(DummyValue, "number", translate("Number"))
|
||||
s_partition_table:option(DummyValue, "name", translate("Name"))
|
||||
local val_sec_start = s_partition_table:option(Value, "sec_start", translate("Start Sector"))
|
||||
val_sec_start.render = function(self, section, scope)
|
||||
-- could create new partition
|
||||
if disk_info.partitions[section].number == -1 and disk_info.partitions[section].size > 1 * 1024 * 1024 then
|
||||
self.template = "cbi/value"
|
||||
Value.render(self, section, scope)
|
||||
else
|
||||
self.template = "cbi/dvalue"
|
||||
DummyValue.render(self, section, scope)
|
||||
end
|
||||
end
|
||||
local val_sec_end = s_partition_table:option(Value, "sec_end", translate("End Sector"))
|
||||
val_sec_end.render = function(self, section, scope)
|
||||
-- could create new partition
|
||||
if disk_info.partitions[section].number == -1 and disk_info.partitions[section].size > 1 * 1024 * 1024 then
|
||||
self.template = "cbi/value"
|
||||
Value.render(self, section, scope)
|
||||
else
|
||||
self.template = "cbi/dvalue"
|
||||
DummyValue.render(self, section, scope)
|
||||
end
|
||||
end
|
||||
val_sec_start.forcewrite = true
|
||||
val_sec_start.write = function(self, section, value)
|
||||
disk_info.partitions[section]._sec_start = value
|
||||
end
|
||||
val_sec_end.forcewrite = true
|
||||
val_sec_end.write = function(self, section, value)
|
||||
disk_info.partitions[section]._sec_end = value
|
||||
end
|
||||
s_partition_table:option(DummyValue, "size_formated", translate("Size"))
|
||||
if disk_info.p_table == "MBR" then
|
||||
s_partition_table:option(DummyValue, "type", translate("Type"))
|
||||
end
|
||||
s_partition_table:option(DummyValue, "used_formated", translate("Used"))
|
||||
s_partition_table:option(DummyValue, "free_formated", translate("Free Space"))
|
||||
s_partition_table:option(DummyValue, "usage", translate("Usage"))
|
||||
local dv_mount_point = s_partition_table:option(DummyValue, "mount_point", translate("Mount Point"))
|
||||
dv_mount_point.rawhtml = true
|
||||
dv_mount_point.render = function(self, section, scope)
|
||||
local new_mp = ""
|
||||
local v_mp_d
|
||||
for line in self["section"]["data"][section]["mount_point"]:gmatch("[^%s]+") do
|
||||
if line == '-' then
|
||||
new_mp = line
|
||||
break
|
||||
end
|
||||
for v_mp_d in line:gmatch('[^/]+') do
|
||||
if #v_mp_d > 12 then
|
||||
new_mp = new_mp .. "/" .. v_mp_d:sub(1,7) .. ".." .. v_mp_d:sub(-4)
|
||||
else
|
||||
new_mp = new_mp .."/".. v_mp_d
|
||||
end
|
||||
end
|
||||
new_mp = '<span title="'.. line .. '" >' ..new_mp ..'</span>' .. "<br/>"
|
||||
end
|
||||
self["section"]["data"][section]["mount_point"] = new_mp
|
||||
DummyValue.render(self, section, scope)
|
||||
end
|
||||
local val_fs = s_partition_table:option(Value, "fs", translate("File System"))
|
||||
val_fs.forcewrite = true
|
||||
val_fs.partitions = disk_info.partitions
|
||||
for k, v in pairs(format_cmd) do
|
||||
val_fs.format_cmd = val_fs.format_cmd and (val_fs.format_cmd .. "," .. k) or k
|
||||
end
|
||||
|
||||
val_fs.write = function(self, section, value)
|
||||
disk_info.partitions[section]._fs = value
|
||||
end
|
||||
val_fs.render = function(self, section, scope)
|
||||
-- use listvalue when partition not mounted
|
||||
if disk_info.partitions[section].mount_point == "-" and disk_info.partitions[section].number ~= -1 and disk_info.partitions[section].type ~= "extended" then
|
||||
self.template = "diskman/cbi/format_button"
|
||||
self.inputstyle = "reset"
|
||||
self.inputtitle = disk_info.partitions[section].fs == "raw" and translate("Format") or disk_info.partitions[section].fs
|
||||
Button.render(self, section, scope)
|
||||
-- self:reset_values()
|
||||
-- self.keylist = {}
|
||||
-- self.vallist = {}
|
||||
-- for k, v in pairs(format_cmd) do
|
||||
-- self:value(k,k)
|
||||
-- end
|
||||
-- self.default = disk_info.partitions[section].fs
|
||||
else
|
||||
-- self:reset_values()
|
||||
-- self.keylist = {}
|
||||
-- self.vallist = {}
|
||||
self.template = "cbi/dvalue"
|
||||
DummyValue.render(self, section, scope)
|
||||
end
|
||||
end
|
||||
-- btn_format = s_partition_table:option(Button, "_format")
|
||||
-- btn_format.template = "diskman/cbi/format_button"
|
||||
-- btn_format.partitions = disk_info.partitions
|
||||
-- btn_format.render = function(self, section, scope)
|
||||
-- if disk_info.partitions[section].mount_point == "-" and disk_info.partitions[section].number ~= -1 and disk_info.partitions[section].type ~= "extended" then
|
||||
-- self.inputtitle = translate("Format")
|
||||
-- self.template = "diskman/cbi/disabled_button"
|
||||
-- self.view_disabled = false
|
||||
-- self.inputstyle = "reset"
|
||||
-- for k, v in pairs(format_cmd) do
|
||||
-- self:depends("val_fs", "k")
|
||||
-- end
|
||||
-- -- elseif disk_info.partitions[section].mount_point ~= "-" and disk_info.partitions[section].number ~= -1 then
|
||||
-- -- self.inputtitle = "Format"
|
||||
-- -- self.template = "diskman/cbi/disabled_button"
|
||||
-- -- self.view_disabled = true
|
||||
-- -- self.inputstyle = "reset"
|
||||
-- else
|
||||
-- self.inputtitle = ""
|
||||
-- self.template = "cbi/dvalue"
|
||||
-- end
|
||||
-- Button.render(self, section, scope)
|
||||
-- end
|
||||
-- btn_format.forcewrite = true
|
||||
-- btn_format.write = function(self, section, value)
|
||||
-- local partition_name = "/dev/".. disk_info.partitions[section].name
|
||||
-- if not nixio.fs.access(partition_name) then
|
||||
-- m.errmessage = translate("Partition NOT found!")
|
||||
-- return
|
||||
-- end
|
||||
-- local fs = disk_info.partitions[section]._fs
|
||||
-- if not format_cmd[fs] then
|
||||
-- m.errmessage = translate("Filesystem NOT support!")
|
||||
-- return
|
||||
-- end
|
||||
-- local cmd = format_cmd[fs].cmd .. " " .. format_cmd[fs].option .. " " .. partition_name
|
||||
-- local res = luci.util.exec(cmd .. " 2>&1")
|
||||
-- if res and res:lower():match("error+") then
|
||||
-- m.errmessage = luci.util.pcdata(res)
|
||||
-- else
|
||||
-- luci.http.redirect(luci.dispatcher.build_url("admin/system/diskman/partition/" .. dev))
|
||||
-- end
|
||||
-- end
|
||||
|
||||
local btn_action = s_partition_table:option(Button, "_action")
|
||||
btn_action.forcewrite = true
|
||||
btn_action.template = "diskman/cbi/disabled_button"
|
||||
btn_action.render = function(self, section, scope)
|
||||
-- if partition is mounted or the size < 1mb, then disable the add action
|
||||
if disk_info.partitions[section].mount_point ~= "-" or (disk_info.partitions[section].type ~= "extended" and disk_info.partitions[section].number == -1 and disk_info.partitions[section].size <= 1 * 1024 * 1024) then
|
||||
self.view_disabled = true
|
||||
-- self.inputtitle = ""
|
||||
-- self.template = "cbi/dvalue"
|
||||
elseif disk_info.partitions[section].type == "extended" and next(disk_info.partitions[section]["logicals"]) ~= nil then
|
||||
self.view_disabled = true
|
||||
else
|
||||
-- self.template = "diskman/cbi/disabled_button"
|
||||
self.view_disabled = false
|
||||
end
|
||||
if disk_info.partitions[section].number ~= -1 then
|
||||
self.inputtitle = translate("Remove")
|
||||
self.inputstyle = "remove"
|
||||
else
|
||||
self.inputtitle = translate("New")
|
||||
self.inputstyle = "add"
|
||||
end
|
||||
Button.render(self, section, scope)
|
||||
end
|
||||
btn_action.write = function(self, section, value)
|
||||
if value == translate("New") then
|
||||
local start_sec = disk_info.partitions[section]._sec_start and tonumber(disk_info.partitions[section]._sec_start) or tonumber(disk_info.partitions[section].sec_start)
|
||||
local end_sec = disk_info.partitions[section]._sec_end
|
||||
|
||||
if start_sec then
|
||||
-- for sector alignment
|
||||
local align = tonumber(disk_info.phy_sec) / tonumber(disk_info.logic_sec)
|
||||
align = (align < 2048) and 2048
|
||||
if start_sec < 2048 then
|
||||
start_sec = "2048" .. "s"
|
||||
elseif math.fmod( start_sec, align ) ~= 0 then
|
||||
start_sec = tostring(start_sec + align - math.fmod( start_sec, align )) .. "s"
|
||||
else
|
||||
start_sec = start_sec .. "s"
|
||||
end
|
||||
else
|
||||
m.errmessage = translate("Invalid Start Sector!")
|
||||
return
|
||||
end
|
||||
-- support +size format for End sector
|
||||
local end_size, end_unit = end_sec:match("^+(%d-)([bkmgtsBKMGTS])$")
|
||||
if tonumber(end_size) and end_unit then
|
||||
local unit ={
|
||||
B=1,
|
||||
S=512,
|
||||
K=1024,
|
||||
M=1048576,
|
||||
G=1073741824,
|
||||
T=1099511627776
|
||||
}
|
||||
end_unit = end_unit:upper()
|
||||
end_sec = tostring(tonumber(end_size) * unit[end_unit] / unit["S"] + tonumber(start_sec:sub(1,-2)) - 1 ) .. "s"
|
||||
elseif tonumber(end_sec) then
|
||||
end_sec = end_sec .. "s"
|
||||
else
|
||||
m.errmessage = translate("Invalid End Sector!")
|
||||
return
|
||||
end
|
||||
local part_type = "primary"
|
||||
|
||||
if disk_info.p_table == "MBR" and disk_info["extended_partition_index"] then
|
||||
if tonumber(disk_info.partitions[disk_info["extended_partition_index"]].sec_start) <= tonumber(start_sec:sub(1,-2)) and tonumber(disk_info.partitions[disk_info["extended_partition_index"]].sec_end) >= tonumber(end_sec:sub(1,-2)) then
|
||||
part_type = "logical"
|
||||
if tonumber(start_sec:sub(1,-2)) - tonumber(disk_info.partitions[section].sec_start) < 2048 then
|
||||
start_sec = tonumber(start_sec:sub(1,-2)) + 2048
|
||||
start_sec = start_sec .."s"
|
||||
end
|
||||
end
|
||||
elseif disk_info.p_table == "GPT" then
|
||||
-- AUTOMATIC FIX GPT PARTITION TABLE
|
||||
-- Not all of the space available to /dev/sdb appears to be used, you can fix the GPT to use all of the space (an extra 16123870 blocks) or continue with the current setting?
|
||||
local cmd = ' printf "ok\nfix\n" | parted ---pretend-input-tty /dev/'.. dev ..' print'
|
||||
luci.util.exec(cmd .. " 2>&1")
|
||||
end
|
||||
|
||||
-- partiton
|
||||
local cmd = dm.command.parted .. " -s -a optimal /dev/" .. dev .. " mkpart " .. part_type .." " .. start_sec .. " " .. end_sec
|
||||
local res = luci.util.exec(cmd .. " 2>&1")
|
||||
if res and res:lower():match("error+") then
|
||||
m.errmessage = luci.util.pcdata(res)
|
||||
else
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin/system/diskman/partition/" .. dev))
|
||||
end
|
||||
elseif value == translate("Remove") then
|
||||
-- remove partition
|
||||
local number = tostring(disk_info.partitions[section].number)
|
||||
if (not number) or (number == "") then
|
||||
m.errmessage = translate("Partition not exists!")
|
||||
return
|
||||
end
|
||||
local cmd = dm.command.parted .. " -s /dev/" .. dev .. " rm " .. number
|
||||
local res = luci.util.exec(cmd .. " 2>&1")
|
||||
if res and res:lower():match("error+") then
|
||||
m.errmessage = luci.util.pcdata(res)
|
||||
else
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin/system/diskman/partition/" .. dev))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return m
|
746
luci-app-diskman/luasrc/model/diskman.lua
Normal file
746
luci-app-diskman/luasrc/model/diskman.lua
Normal file
@ -0,0 +1,746 @@
|
||||
--[[
|
||||
LuCI - Lua Configuration Interface
|
||||
Copyright 2019 lisaac <https://github.com/lisaac/luci-app-diskman>
|
||||
]]--
|
||||
|
||||
require "luci.util"
|
||||
local ver = require "luci.version"
|
||||
|
||||
local CMD = {"parted", "mdadm", "blkid", "smartctl", "df", "btrfs", "lsblk"}
|
||||
|
||||
local d = {command ={}}
|
||||
for _, cmd in ipairs(CMD) do
|
||||
local command = luci.sys.exec("/usr/bin/which " .. cmd)
|
||||
d.command[cmd] = command:match("^.+"..cmd) or nil
|
||||
end
|
||||
|
||||
d.command.mount = nixio.fs.access("/usr/bin/mount") and "/usr/bin/mount" or "/bin/mount"
|
||||
d.command.umount = nixio.fs.access("/usr/bin/umount") and "/usr/bin/umount" or "/bin/umount"
|
||||
|
||||
local proc_mounts = nixio.fs.readfile("/proc/mounts") or ""
|
||||
local mounts = luci.util.exec(d.command.mount .. " 2>/dev/null") or ""
|
||||
local swaps = nixio.fs.readfile("/proc/swaps") or ""
|
||||
local df = luci.sys.exec(d.command.df .. " 2>/dev/null") or ""
|
||||
|
||||
function byte_format(byte)
|
||||
local suff = {"B", "KB", "MB", "GB", "TB"}
|
||||
for i=1, 5 do
|
||||
if byte > 1024 and i < 5 then
|
||||
byte = byte / 1024
|
||||
else
|
||||
return string.format("%.2f %s", byte, suff[i])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local get_smart_info = function(device)
|
||||
local section
|
||||
local smart_info = {}
|
||||
for _, line in ipairs(luci.util.execl(d.command.smartctl .. " -H -A -i -n standby -f brief /dev/" .. device)) do
|
||||
local attrib, val
|
||||
if section == 1 then
|
||||
attrib, val = line:match "^(.-):%s+(.+)"
|
||||
elseif section == 2 and smart_info.nvme_ver then
|
||||
attrib, val = line:match("^(.-):%s+(.+)")
|
||||
if not smart_info.health then smart_info.health = line:match(".-overall%-health.-: (.+)") end
|
||||
elseif section == 2 then
|
||||
attrib, val = line:match("^([0-9 ]+)%s+[^ ]+%s+[POSRCK-]+%s+[0-9-]+%s+[0-9-]+%s+[0-9-]+%s+[0-9-]+%s+([0-9-]+)")
|
||||
if not smart_info.health then smart_info.health = line:match(".-overall%-health.-: (.+)") end
|
||||
else
|
||||
attrib = line:match "^=== START OF (.*) SECTION ==="
|
||||
if attrib and attrib:match("INFORMATION") then
|
||||
section = 1
|
||||
elseif attrib and attrib:match("SMART DATA") then
|
||||
section = 2
|
||||
elseif not smart_info.status then
|
||||
val = line:match "^Device is in (.*) mode"
|
||||
if val then smart_info.status = val end
|
||||
end
|
||||
end
|
||||
|
||||
if not attrib then
|
||||
if section ~= 2 then section = 0 end
|
||||
elseif (attrib == "Power mode is") or
|
||||
(attrib == "Power mode was") then
|
||||
smart_info.status = val:match("(%S+)")
|
||||
-- elseif attrib == "Sector Sizes" then
|
||||
-- -- 512 bytes logical, 4096 bytes physical
|
||||
-- smart_info.phy_sec = val:match "([0-9]*) bytes physical"
|
||||
-- smart_info.logic_sec = val:match "([0-9]*) bytes logical"
|
||||
-- elseif attrib == "Sector Size" then
|
||||
-- -- 512 bytes logical/physical
|
||||
-- smart_info.phy_sec = val:match "([0-9]*)"
|
||||
-- smart_info.logic_sec = smart_info.phy_sec
|
||||
elseif attrib == "Serial Number" then
|
||||
smart_info.sn = val
|
||||
elseif attrib == "194" or attrib == "Temperature" then
|
||||
if val ~= "-" then
|
||||
smart_info.temp = (val:match("(%d+)") or "?") .. "°C"
|
||||
end
|
||||
elseif attrib == "Rotation Rate" then
|
||||
smart_info.rota_rate = val
|
||||
elseif attrib == "SATA Version is" then
|
||||
smart_info.sata_ver = val
|
||||
elseif attrib == "NVMe Version" then
|
||||
smart_info.nvme_ver = val
|
||||
end
|
||||
end
|
||||
return smart_info
|
||||
end
|
||||
|
||||
local parse_parted_info = function(keys, line)
|
||||
-- parse the output of parted command (machine parseable format)
|
||||
-- /dev/sda:5860533168s:scsi:512:4096:gpt:ATA ST3000DM001-1ER1:;
|
||||
-- 1:34s:2047s:2014s:free;
|
||||
-- 1:2048s:1073743872s:1073741825s:ext4:primary:;
|
||||
local result = {}
|
||||
local values = {}
|
||||
|
||||
for value in line:gmatch("(.-)[:;]") do table.insert(values, value) end
|
||||
for i = 1,#keys do
|
||||
result[keys[i]] = values[i] or ""
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
local is_raid_member = function(partition)
|
||||
-- check if inuse as raid member
|
||||
if nixio.fs.access("/proc/mdstat") then
|
||||
for _, result in ipairs(luci.util.execl("grep md /proc/mdstat | sed 's/[][]//g'")) do
|
||||
local md, buf
|
||||
md, buf = result:match("(md.-):(.+)")
|
||||
if buf:match(partition) then
|
||||
return "Raid Member: ".. md
|
||||
end
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local get_mount_point = function(partition)
|
||||
local mount_point
|
||||
for m in mounts:gmatch("/dev/"..partition.." on ([^ ]*)") do
|
||||
mount_point = (mount_point and (mount_point .. " ") or "") .. m
|
||||
end
|
||||
if mount_point then return mount_point end
|
||||
-- result = luci.sys.exec('cat /proc/mounts | awk \'{if($1=="/dev/'.. partition ..'") print $2}\'')
|
||||
-- if result ~= "" then return result end
|
||||
|
||||
if swaps:match("\n/dev/" .. partition .."%s") then return "swap" end
|
||||
-- result = luci.sys.exec("cat /proc/swaps | grep /dev/" .. partition)
|
||||
-- if result ~= "" then return "swap" end
|
||||
|
||||
return is_raid_member(partition)
|
||||
|
||||
end
|
||||
|
||||
-- return used, free, usage
|
||||
local get_partition_usage = function(partition)
|
||||
if not nixio.fs.access("/dev/"..partition) then return false end
|
||||
local used, free, usage = df:match("\n/dev/" .. partition .. "%s+%d+%s+(%d+)%s+(%d+)%s+(%d+)%%%s-")
|
||||
|
||||
usage = usage and (usage .. "%") or "-"
|
||||
used = used and (tonumber(used) * 1024) or 0
|
||||
free = free and (tonumber(free) * 1024) or 0
|
||||
|
||||
return used, free, usage
|
||||
end
|
||||
|
||||
local get_parted_info = function(device)
|
||||
if not device then return end
|
||||
local result = {partitions={}}
|
||||
local DEVICE_INFO_KEYS = { "path", "size", "type", "logic_sec", "phy_sec", "p_table", "model", "flags" }
|
||||
local PARTITION_INFO_KEYS = { "number", "sec_start", "sec_end", "size", "fs", "tag_name", "flags" }
|
||||
local partition_temp
|
||||
local partitions_temp = {}
|
||||
local disk_temp
|
||||
|
||||
for line in luci.util.execi(d.command.parted .. " -s -m /dev/" .. device .. " unit s print free", "r") do
|
||||
if line:find("^/dev/"..device..":.+") then
|
||||
disk_temp = parse_parted_info(DEVICE_INFO_KEYS, line)
|
||||
disk_temp.partitions = {}
|
||||
if disk_temp["size"] then
|
||||
local length = disk_temp["size"]:gsub("^(%d+)s$", "%1")
|
||||
local newsize = tostring(tonumber(length)*tonumber(disk_temp["logic_sec"]))
|
||||
disk_temp["size"] = newsize
|
||||
end
|
||||
if disk_temp["p_table"] == "msdos" then
|
||||
disk_temp["p_table"] = "MBR"
|
||||
else
|
||||
disk_temp["p_table"] = disk_temp["p_table"]:upper()
|
||||
end
|
||||
elseif line:find("^%d-:.+") then
|
||||
partition_temp = parse_parted_info(PARTITION_INFO_KEYS, line)
|
||||
-- use human-readable form instead of sector number
|
||||
if partition_temp["size"] then
|
||||
local length = partition_temp["size"]:gsub("^(%d+)s$", "%1")
|
||||
local newsize = (tonumber(length) * tonumber(disk_temp["logic_sec"]))
|
||||
partition_temp["size"] = newsize
|
||||
partition_temp["size_formated"] = byte_format(newsize)
|
||||
end
|
||||
partition_temp["number"] = tonumber(partition_temp["number"]) or -1
|
||||
if partition_temp["fs"] == "free" then
|
||||
partition_temp["number"] = -1
|
||||
partition_temp["fs"] = "Free Space"
|
||||
partition_temp["name"] = "-"
|
||||
elseif device:match("sd") or device:match("sata") or device:match("vd") then
|
||||
partition_temp["name"] = device..partition_temp["number"]
|
||||
elseif device:match("mmcblk") or device:match("md") or device:match("nvme") then
|
||||
partition_temp["name"] = device.."p"..partition_temp["number"]
|
||||
end
|
||||
if partition_temp["number"] > 0 and partition_temp["fs"] == "" and d.command.lsblk then
|
||||
partition_temp["fs"] = (luci.util.exec(d.command.lsblk .. " /dev/" .. partition_temp["name"] .. " -no fstype") or ""):match("([^%s]+)") or ""
|
||||
end
|
||||
partition_temp["fs"] = partition_temp["fs"] == "" and "raw" or partition_temp["fs"]
|
||||
partition_temp["sec_start"] = partition_temp["sec_start"] and partition_temp["sec_start"]:sub(1,-2)
|
||||
partition_temp["sec_end"] = partition_temp["sec_end"] and partition_temp["sec_end"]:sub(1,-2)
|
||||
partition_temp["mount_point"] = partition_temp["name"]~="-" and get_mount_point(partition_temp["name"]) or "-"
|
||||
if partition_temp["mount_point"]~="-" then
|
||||
partition_temp["used"], partition_temp["free"], partition_temp["usage"] = get_partition_usage(partition_temp["name"])
|
||||
partition_temp["used_formated"] = partition_temp["used"] and byte_format(partition_temp["used"]) or "-"
|
||||
partition_temp["free_formated"] = partition_temp["free"] and byte_format(partition_temp["free"]) or "-"
|
||||
else
|
||||
partition_temp["used"], partition_temp["free"], partition_temp["usage"] = 0,0,"-"
|
||||
partition_temp["used_formated"] = "-"
|
||||
partition_temp["free_formated"] = "-"
|
||||
end
|
||||
-- if disk_temp["p_table"] == "MBR" and (partition_temp["number"] < 4) and (partition_temp["number"] > 0) then
|
||||
-- local real_size_sec = tonumber(nixio.fs.readfile("/sys/block/"..device.."/"..partition_temp["name"].."/size")) * tonumber(disk_temp.phy_sec)
|
||||
-- if real_size_sec ~= partition_temp["size"] then
|
||||
-- disk_temp["extended_partition_index"] = partition_temp["number"]
|
||||
-- partition_temp["type"] = "extended"
|
||||
-- partition_temp["size"] = real_size_sec
|
||||
-- partition_temp["fs"] = "-"
|
||||
-- partition_temp["logicals"] = {}
|
||||
-- else
|
||||
-- partition_temp["type"] = "primary"
|
||||
-- end
|
||||
-- end
|
||||
|
||||
table.insert(partitions_temp, partition_temp)
|
||||
end
|
||||
end
|
||||
if disk_temp and disk_temp["p_table"] == "MBR" then
|
||||
for i, p in ipairs(partitions_temp) do
|
||||
if disk_temp["extended_partition_index"] and p["number"] > 4 then
|
||||
if tonumber(p["sec_end"]) <= tonumber(partitions_temp[disk_temp["extended_partition_index"]]["sec_end"]) and tonumber(p["sec_start"]) >= tonumber(partitions_temp[disk_temp["extended_partition_index"]]["sec_start"]) then
|
||||
p["type"] = "logical"
|
||||
table.insert(partitions_temp[disk_temp["extended_partition_index"]]["logicals"], i)
|
||||
end
|
||||
elseif (p["number"] <= 4) and (p["number"] > 0) then
|
||||
local s = nixio.fs.readfile("/sys/block/"..device.."/"..p["name"].."/size")
|
||||
if s then
|
||||
local real_size_sec = tonumber(s) * tonumber(disk_temp.logic_sec)
|
||||
-- if size not equal, it's an extended
|
||||
if real_size_sec ~= p["size"] then
|
||||
disk_temp["extended_partition_index"] = i
|
||||
p["type"] = "extended"
|
||||
p["size"] = real_size_sec
|
||||
p["fs"] = "-"
|
||||
p["logicals"] = {}
|
||||
else
|
||||
p["type"] = "primary"
|
||||
end
|
||||
else
|
||||
-- if not found in "/sys/block"
|
||||
p["type"] = "primary"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
result = disk_temp or result
|
||||
result.partitions = partitions_temp
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
local mddetail = function(mdpath)
|
||||
local detail = {}
|
||||
local path = mdpath:match("^/dev/md%d+$")
|
||||
if path then
|
||||
local mdadm = io.popen(d.command.mdadm .. " --detail "..path, "r")
|
||||
for line in mdadm:lines() do
|
||||
local key, value = line:match("^%s*(.+) : (.+)")
|
||||
if key then
|
||||
detail[key] = value
|
||||
end
|
||||
end
|
||||
mdadm:close()
|
||||
end
|
||||
return detail
|
||||
end
|
||||
|
||||
-- return {{device="", mount_points="", fs="", mount_options="", dump="", pass=""}..}
|
||||
d.get_mount_points = function()
|
||||
local mount
|
||||
local res = {}
|
||||
local h ={"device", "mount_point", "fs", "mount_options", "dump", "pass"}
|
||||
for mount in proc_mounts:gmatch("[^\n]+") do
|
||||
local device = mount:match("^([^%s]+)%s+.+")
|
||||
-- only show /dev/xxx device
|
||||
if device and device:match("/dev/") then
|
||||
res[#res+1] = {}
|
||||
local i = 0
|
||||
for v in mount:gmatch("[^%s]+") do
|
||||
i = i + 1
|
||||
res[#res][h[i]] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
d.get_disk_info = function(device, wakeup)
|
||||
--[[ return:
|
||||
{
|
||||
path, model, sn, size, size_mounted, flags, type, temp, p_table, logic_sec, phy_sec, sec_size, sata_ver, rota_rate, status, health,
|
||||
partitions = {
|
||||
1 = { number, name, sec_start, sec_end, size, size_mounted, fs, tag_name, type, flags, mount_point, usage, used, free, used_formated, free_formated},
|
||||
2 = { number, name, sec_start, sec_end, size, size_mounted, fs, tag_name, type, flags, mount_point, usage, used, free, used_formated, free_formated},
|
||||
...
|
||||
}
|
||||
--raid devices only
|
||||
level, members, members_str
|
||||
}
|
||||
--]]
|
||||
if not device then return end
|
||||
local disk_info
|
||||
local smart_info = get_smart_info(device)
|
||||
|
||||
-- check if divice is the member of raid
|
||||
smart_info["p_table"] = is_raid_member(device..'0')
|
||||
-- if status is not active(standby), only check smart_info.
|
||||
-- if only weakup == true, weakup the disk and check parted_info.
|
||||
if smart_info.status ~= "STANDBY" or wakeup or (smart_info["p_table"] and not smart_info["p_table"]:match("Raid")) or device:match("^md") then
|
||||
disk_info = get_parted_info(device)
|
||||
disk_info["sec_size"] = disk_info["logic_sec"] .. "/" .. disk_info["phy_sec"]
|
||||
disk_info["size_formated"] = byte_format(tonumber(disk_info["size"]))
|
||||
-- if status is standby, after get part info, the disk is weakuped, then get smart_info again for more informations
|
||||
if smart_info.status ~= "ACTIVE" then smart_info = get_smart_info(device) end
|
||||
else
|
||||
disk_info = {}
|
||||
end
|
||||
|
||||
for k, v in pairs(smart_info) do
|
||||
disk_info[k] = v
|
||||
end
|
||||
|
||||
if disk_info.type and disk_info.type:match("md") then
|
||||
local raid_info = d.list_raid_devices()[disk_info["path"]:match("/dev/(.+)")]
|
||||
for k, v in pairs(raid_info) do
|
||||
disk_info[k] = v
|
||||
end
|
||||
end
|
||||
return disk_info
|
||||
end
|
||||
|
||||
d.list_raid_devices = function()
|
||||
local fs = require "nixio.fs"
|
||||
|
||||
local raid_devices = {}
|
||||
if not fs.access("/proc/mdstat") then return raid_devices end
|
||||
local mdstat = io.open("/proc/mdstat", "r")
|
||||
for line in mdstat:lines() do
|
||||
|
||||
-- md1 : active raid1 sdb2[1] sda2[0]
|
||||
-- md127 : active raid5 sdh1[6] sdg1[4] sdf1[3] sde1[2] sdd1[1] sdc1[0]
|
||||
local device_info = {}
|
||||
local mdpath, list = line:match("^(md%d+) : (.+)")
|
||||
if mdpath then
|
||||
local members = {}
|
||||
for member in string.gmatch(list, "%S+") do
|
||||
member_path = member:match("^(%S+)%[%d+%]")
|
||||
if member_path then
|
||||
member = '/dev/'..member_path
|
||||
end
|
||||
table.insert(members, member)
|
||||
end
|
||||
local active = table.remove(members, 1)
|
||||
local level = "-"
|
||||
if active == "active" then
|
||||
level = table.remove(members, 1)
|
||||
end
|
||||
|
||||
local size = tonumber(fs.readfile(string.format("/sys/class/block/%s/size", mdpath)))
|
||||
local ss = tonumber(fs.readfile(string.format("/sys/class/block/%s/queue/logical_block_size", mdpath)))
|
||||
|
||||
device_info["path"] = "/dev/"..mdpath
|
||||
device_info["size"] = size*ss
|
||||
device_info["size_formated"] = byte_format(size*ss)
|
||||
device_info["active"] = active:upper()
|
||||
device_info["level"] = level
|
||||
device_info["members"] = members
|
||||
device_info["members_str"] = table.concat(members, ", ")
|
||||
|
||||
-- Get more info from output of mdadm --detail
|
||||
local detail = mddetail(device_info["path"])
|
||||
device_info["status"] = detail["State"]:upper()
|
||||
|
||||
raid_devices[mdpath] = device_info
|
||||
end
|
||||
end
|
||||
mdstat:close()
|
||||
|
||||
return raid_devices
|
||||
end
|
||||
|
||||
-- Collect Devices information
|
||||
--[[ return:
|
||||
{
|
||||
sda={
|
||||
path, model, inuse, size_formated,
|
||||
partitions={
|
||||
{ name, inuse, size_formated }
|
||||
...
|
||||
}
|
||||
}
|
||||
..
|
||||
}
|
||||
--]]
|
||||
d.list_devices = function()
|
||||
local fs = require "nixio.fs"
|
||||
|
||||
-- get all device names (sdX and mmcblkX)
|
||||
local target_devnames = {}
|
||||
for dev in fs.dir("/dev") do
|
||||
if dev:match("^sd[a-z]$")
|
||||
or dev:match("^mmcblk%d+$")
|
||||
or dev:match("^sata[a-z]$")
|
||||
or dev:match("^nvme%d+n%d+$")
|
||||
or dev:match("^vd[a-z]$")
|
||||
then
|
||||
table.insert(target_devnames, dev)
|
||||
end
|
||||
end
|
||||
|
||||
local devices = {}
|
||||
for i, bname in pairs(target_devnames) do
|
||||
local device_info = {}
|
||||
local device = "/dev/" .. bname
|
||||
local size = tonumber(fs.readfile(string.format("/sys/class/block/%s/size", bname)) or "0")
|
||||
local ss = tonumber(fs.readfile(string.format("/sys/class/block/%s/queue/logical_block_size", bname)) or "0")
|
||||
local model = fs.readfile(string.format("/sys/class/block/%s/device/model", bname))
|
||||
local partitions = {}
|
||||
for part in nixio.fs.glob("/sys/block/" .. bname .."/" .. bname .. "*") do
|
||||
local pname = nixio.fs.basename(part)
|
||||
local psize = byte_format(tonumber(nixio.fs.readfile(part .. "/size"))*ss)
|
||||
local mount_point = get_mount_point(pname)
|
||||
if mount_point then device_info["inuse"] = true end
|
||||
table.insert(partitions, {name = pname, size_formated = psize, inuse = mount_point})
|
||||
end
|
||||
|
||||
device_info["path"] = device
|
||||
device_info["size_formated"] = byte_format(size*ss)
|
||||
device_info["model"] = model
|
||||
device_info["partitions"] = partitions
|
||||
-- true or false
|
||||
device_info["inuse"] = device_info["inuse"] or get_mount_point(bname)
|
||||
|
||||
local udevinfo = {}
|
||||
if luci.sys.exec("which udevadm") ~= "" then
|
||||
local udevadm = io.popen("udevadm info --query=property --name="..device)
|
||||
for attr in udevadm:lines() do
|
||||
local k, v = attr:match("(%S+)=(%S+)")
|
||||
udevinfo[k] = v
|
||||
end
|
||||
udevadm:close()
|
||||
|
||||
device_info["info"] = udevinfo
|
||||
if udevinfo["ID_MODEL"] then device_info["model"] = udevinfo["ID_MODEL"] end
|
||||
end
|
||||
devices[bname] = device_info
|
||||
end
|
||||
-- luci.util.perror(luci.util.serialize_json(devices))
|
||||
return devices
|
||||
end
|
||||
|
||||
-- get formart cmd
|
||||
d.get_format_cmd = function()
|
||||
local AVAILABLE_FMTS = {
|
||||
btrfs = { cmd = "mkfs.btrfs", option = "-f" },
|
||||
exfat = { cmd = "mkfs.exfat", option = "" },
|
||||
ext2 = { cmd = "mkfs.ext2", option = "-F -E lazy_itable_init=1" },
|
||||
ext3 = { cmd = "mkfs.ext3", option = "-F -E lazy_itable_init=1" },
|
||||
ext4 = { cmd = "mkfs.ext4", option = "-F -E lazy_itable_init=1" },
|
||||
f2fs = { cmd = "mkfs.f2fs", option = "-f" },
|
||||
fat32 = { cmd = "mkfs.fat", option = "-F 32" },
|
||||
hfs = { cmd = "mkfs.hfs", option = "-h" },
|
||||
hfsplus = { cmd = "mkfs.hfs", option = "" },
|
||||
ntfs = { cmd = "mkntfs", option = "-f" },
|
||||
swap = { cmd = "mkswap", option = "" },
|
||||
xfs = { cmd = "mkfs.xfs", option = "-f -m bigtime=1" }
|
||||
}
|
||||
result = {}
|
||||
for fmt, obj in pairs(AVAILABLE_FMTS) do
|
||||
local cmd = luci.sys.exec("/usr/bin/which " .. obj["cmd"])
|
||||
if cmd:match(obj["cmd"]) then
|
||||
result[fmt] = { cmd = cmd:match("^.+"..obj["cmd"]) ,option = obj["option"] }
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
d.find_free_md_device = function()
|
||||
for num=0,127 do
|
||||
local md = io.open("/dev/md"..tostring(num), "r")
|
||||
if md == nil then
|
||||
return "/dev/md"..tostring(num)
|
||||
else
|
||||
io.close(md)
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
d.create_raid = function(rname, rlevel, rmembers)
|
||||
local mb = {}
|
||||
for _, v in ipairs(rmembers) do
|
||||
mb[v]=v
|
||||
end
|
||||
rmembers = {}
|
||||
for _, v in pairs(mb) do
|
||||
table.insert(rmembers, v)
|
||||
end
|
||||
if type(rname) == "string" then
|
||||
if rname:match("^md%d-%s+") then
|
||||
rname = "/dev/"..rname:match("^(md%d-)%s+")
|
||||
elseif rname:match("^/dev/md%d-%s+") then
|
||||
rname = "/dev/"..rname:match("^(/dev/md%d-)%s+")
|
||||
elseif not rname:match("/") then
|
||||
rname = "/dev/md/".. rname
|
||||
else
|
||||
return "ERR: Invalid raid name"
|
||||
end
|
||||
else
|
||||
rname = d.find_free_md_device()
|
||||
if rname == nil then return "ERR: Cannot find free md device" end
|
||||
end
|
||||
|
||||
if rlevel == "5" or rlevel == "6" then
|
||||
if #rmembers < 3 then return "ERR: Not enough members" end
|
||||
end
|
||||
if rlevel == "10" then
|
||||
if #rmembers < 4 then return "ERR: Not enough members" end
|
||||
end
|
||||
if #rmembers < 2 then return "ERR: Not enough members" end
|
||||
local cmd = d.command.mdadm .. " --create "..rname.." --run --assume-clean --homehost=any --level=" .. rlevel .. " --raid-devices=" .. #rmembers .. " " .. table.concat(rmembers, " ")
|
||||
local res = luci.util.exec(cmd)
|
||||
return res
|
||||
end
|
||||
|
||||
d.gen_mdadm_config = function()
|
||||
if not nixio.fs.access("/etc/config/mdadm") then return end
|
||||
local uci = require "luci.model.uci"
|
||||
local x = uci.cursor()
|
||||
-- delete all array sections
|
||||
x:foreach("mdadm", "array", function(s) x:delete("mdadm",s[".name"]) end)
|
||||
local cmd = d.command.mdadm .. " -D -s"
|
||||
--ARRAY /dev/md1 metadata=1.2 name=any:1 UUID=f998ae14:37621b27:5c49e850:051f6813
|
||||
--ARRAY /dev/md3 metadata=1.2 name=any:3 UUID=c068c141:4b4232ca:f48cbf96:67d42feb
|
||||
for _, v in ipairs(luci.util.execl(cmd)) do
|
||||
local device, uuid = v:match("^ARRAY%s-([^%s]+)%s-[^%s]-%s-[^%s]-%s-UUID=([^%s]+)%s-")
|
||||
if device and uuid then
|
||||
local section_name = x:add("mdadm", "array")
|
||||
x:set("mdadm", section_name, "device", device)
|
||||
x:set("mdadm", section_name, "uuid", uuid)
|
||||
end
|
||||
end
|
||||
x:commit("mdadm")
|
||||
-- enable mdadm
|
||||
luci.util.exec("/etc/init.d/mdadm enable")
|
||||
end
|
||||
|
||||
-- list btrfs filesystem device
|
||||
-- {uuid={uuid, label, members, size, used}...}
|
||||
d.list_btrfs_devices = function()
|
||||
local btrfs_device = {}
|
||||
if not d.command.btrfs then return btrfs_device end
|
||||
local line, _uuid
|
||||
for _, line in ipairs(luci.util.execl(d.command.btrfs .. " filesystem show -d --raw"))
|
||||
do
|
||||
local label, uuid = line:match("^Label:%s+([^%s]+)%s+uuid:%s+([^%s]+)")
|
||||
if label and uuid then
|
||||
_uuid = uuid
|
||||
local _label = label:match("^'([^']+)'")
|
||||
btrfs_device[_uuid] = {label = _label or label, uuid = uuid}
|
||||
-- table.insert(btrfs_device, {label = label, uuid = uuid})
|
||||
end
|
||||
local used = line:match("Total devices[%w%s]+used%s+(%d+)$")
|
||||
if used then
|
||||
btrfs_device[_uuid]["used"] = tonumber(used)
|
||||
btrfs_device[_uuid]["used_formated"] = byte_format(tonumber(used))
|
||||
end
|
||||
local size, device = line:match("devid[%w.%s]+size%s+(%d+)[%w.%s]+path%s+([^%s]+)$")
|
||||
if size and device then
|
||||
btrfs_device[_uuid]["size"] = btrfs_device[_uuid]["size"] and btrfs_device[_uuid]["size"] + tonumber(size) or tonumber(size)
|
||||
btrfs_device[_uuid]["size_formated"] = byte_format(btrfs_device[_uuid]["size"])
|
||||
btrfs_device[_uuid]["members"] = btrfs_device[_uuid]["members"] and btrfs_device[_uuid]["members"]..", "..device or device
|
||||
end
|
||||
end
|
||||
return btrfs_device
|
||||
end
|
||||
|
||||
d.create_btrfs = function(blabel, blevel, bmembers)
|
||||
-- mkfs.btrfs -L label -d blevel /dev/sda /dev/sdb
|
||||
if not d.command.btrfs or type(bmembers) ~= "table" or next(bmembers) == nil then return "ERR no btrfs support or no members" end
|
||||
local label = blabel and " -L " .. blabel or ""
|
||||
local cmd = "mkfs.btrfs -f " .. label .. " -d " .. blevel .. " " .. table.concat(bmembers, " ")
|
||||
return luci.util.exec(cmd)
|
||||
end
|
||||
|
||||
-- get btrfs info
|
||||
-- {uuid, label, members, data_raid_level,metadata_raid_lavel, size, used, size_formated, used_formated, free, free_formated, usage}
|
||||
d.get_btrfs_info = function(m_point)
|
||||
local btrfs_info = {}
|
||||
if not m_point or not d.command.btrfs then return btrfs_info end
|
||||
local cmd = d.command.btrfs .. " filesystem show --raw " .. m_point
|
||||
local _, line, uuid, _label, members
|
||||
for _, line in ipairs(luci.util.execl(cmd)) do
|
||||
if not uuid and not _label then
|
||||
_label, uuid = line:match("^Label:%s+([^%s]+)%s+uuid:%s+([^s]+)")
|
||||
else
|
||||
local mb = line:match("%s+devid.+path%s+([^%s]+)")
|
||||
if mb then
|
||||
members = members and (members .. ", ".. mb) or mb
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not _label or not uuid then return btrfs_info end
|
||||
local label = _label:match("^'([^']+)'")
|
||||
cmd = d.command.btrfs .. " filesystem usage -b " .. m_point
|
||||
local used, free, data_raid_level, metadata_raid_lavel
|
||||
for _, line in ipairs(luci.util.execl(cmd)) do
|
||||
if not used then
|
||||
used = line:match("^%s+Used:%s+(%d+)")
|
||||
elseif not free then
|
||||
free = line:match("^%s+Free %(estimated%):%s+(%d+)")
|
||||
elseif not data_raid_level then
|
||||
data_raid_level = line:match("^Data,%s-(%w+)")
|
||||
elseif not metadata_raid_lavel then
|
||||
metadata_raid_lavel = line:match("^Metadata,%s-(%w+)")
|
||||
end
|
||||
end
|
||||
if used and free and data_raid_level and metadata_raid_lavel then
|
||||
used = tonumber(used)
|
||||
free = tonumber(free)
|
||||
btrfs_info = {
|
||||
uuid = uuid,
|
||||
label = label,
|
||||
data_raid_level = data_raid_level,
|
||||
metadata_raid_lavel = metadata_raid_lavel,
|
||||
used = used,
|
||||
free = free,
|
||||
size = used + free,
|
||||
size_formated = byte_format(used + free),
|
||||
used_formated = byte_format(used),
|
||||
free_formated = byte_format(free),
|
||||
members = members,
|
||||
usage = string.format("%.2f",(used / (free+used) * 100)) .. "%"
|
||||
}
|
||||
end
|
||||
return btrfs_info
|
||||
end
|
||||
|
||||
-- get btrfs subvolume
|
||||
-- {id={id, gen, top_level, path, snapshots, otime, default_subvolume}...}
|
||||
d.get_btrfs_subv = function(m_point, snapshot)
|
||||
local subvolume = {}
|
||||
if not m_point or not d.command.btrfs then return subvolume end
|
||||
|
||||
-- get default subvolume
|
||||
local cmd = d.command.btrfs .. " subvolume get-default " .. m_point
|
||||
local res = luci.util.exec(cmd)
|
||||
local default_subvolume_id = res:match("^ID%s+([^%s]+)")
|
||||
|
||||
-- get the root subvolume
|
||||
if not snapshot then
|
||||
local _, line, section_snap, _uuid, _otime, _id, _snap
|
||||
cmd = d.command.btrfs .. " subvolume show ".. m_point
|
||||
for _, line in ipairs(luci.util.execl(cmd)) do
|
||||
if not section_snap then
|
||||
if not _uuid then
|
||||
_uuid = line:match("^%s-UUID:%s+([^%s]+)")
|
||||
elseif not _otime then
|
||||
_otime = line:match("^%s+Creation time:%s+(.+)")
|
||||
elseif not _id then
|
||||
_id = line:match("^%s+Subvolume ID:%s+([^%s]+)")
|
||||
elseif line:match("^%s+(Snapshot%(s%):)") then
|
||||
section_snap = true
|
||||
end
|
||||
else
|
||||
local snapshot = line:match("^%s+(.+)")
|
||||
if snapshot then
|
||||
_snap = _snap and (_snap ..", /".. snapshot) or ("/"..snapshot)
|
||||
end
|
||||
end
|
||||
end
|
||||
if _uuid and _otime and _id then
|
||||
subvolume["0".._id] = {id = _id , uuid = _uuid, otime = _otime, snapshots = _snap, path = "/"}
|
||||
if default_subvolume_id == _id then
|
||||
subvolume["0".._id].default_subvolume = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- get subvolume of btrfs
|
||||
cmd = d.command.btrfs .. " subvolume list -gcu" .. (snapshot and "s " or " ") .. m_point
|
||||
for _, line in ipairs(luci.util.execl(cmd)) do
|
||||
-- ID 259 gen 11 top level 258 uuid 26ae0c59-199a-cc4d-bd58-644eb4f65d33 path 1a/2b'
|
||||
local id, gen, top_level, uuid, path, otime, otime2
|
||||
if snapshot then
|
||||
id, gen, top_level, otime, otime2, uuid, path = line:match("^ID%s+([^%s]+)%s+gen%s+([^%s]+)%s+cgen.-top level%s+([^%s]+)%s+otime%s+([^%s]+)%s+([^%s]+)%s+uuid%s+([^%s]+)%s+path%s+([^%s]+)%s-$")
|
||||
else
|
||||
id, gen, top_level, uuid, path = line:match("^ID%s+([^%s]+)%s+gen%s+([^%s]+)%s+cgen.-top level%s+([^%s]+)%s+uuid%s+([^%s]+)%s+path%s+([^%s]+)%s-$")
|
||||
end
|
||||
if id and gen and top_level and uuid and path then
|
||||
subvolume[id] = {id = id, gen = gen, top_level = top_level, otime = (otime and otime or "") .." ".. (otime2 and otime2 or ""), uuid = uuid, path = '/'.. path}
|
||||
if not snapshot then
|
||||
-- use btrfs subv show to get snapshots
|
||||
local show_cmd = d.command.btrfs .. " subvolume show "..m_point.."/"..path
|
||||
local __, line_show, section_snap
|
||||
for __, line_show in ipairs(luci.util.execl(show_cmd)) do
|
||||
if not section_snap then
|
||||
local create_time = line_show:match("^%s+Creation time:%s+(.+)")
|
||||
if create_time then
|
||||
subvolume[id]["otime"] = create_time
|
||||
elseif line_show:match("^%s+(Snapshot%(s%):)") then
|
||||
section_snap = "true"
|
||||
end
|
||||
else
|
||||
local snapshot = line_show:match("^%s+(.+)")
|
||||
subvolume[id]["snapshots"] = subvolume[id]["snapshots"] and (subvolume[id]["snapshots"] .. ", /".. snapshot) or ("/"..snapshot)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if subvolume[default_subvolume_id] then
|
||||
subvolume[default_subvolume_id].default_subvolume = 1
|
||||
end
|
||||
-- if m_point == "/tmp/.btrfs_tmp" then
|
||||
-- luci.util.exec("umount " .. m_point)
|
||||
-- end
|
||||
return subvolume
|
||||
end
|
||||
|
||||
d.format_partition = function(partition, fs)
|
||||
local partition_name = "/dev/".. partition
|
||||
if not nixio.fs.access(partition_name) then
|
||||
return 500, "Partition NOT found!"
|
||||
end
|
||||
|
||||
local format_cmd = d.get_format_cmd()
|
||||
if not format_cmd[fs] then
|
||||
return 500, "Filesystem NOT support!"
|
||||
end
|
||||
local cmd = format_cmd[fs].cmd .. " " .. format_cmd[fs].option .. " " .. partition_name
|
||||
local res = luci.util.exec(cmd .. " 2>&1")
|
||||
if res and res:lower():match("error+") then
|
||||
return 500, res
|
||||
else
|
||||
return 200, "OK"
|
||||
end
|
||||
end
|
||||
|
||||
return d
|
@ -0,0 +1,7 @@
|
||||
<%+cbi/valueheader%>
|
||||
<% if self:cfgvalue(section) ~= false then %>
|
||||
<input class="cbi-button cbi-button-<%=self.inputstyle or "button" %>" type="submit"<%= attr("name", cbid) .. attr("id", cbid) .. attr("value", self.inputtitle or self.title)%> <% if self.view_disabled then %> disabled <% end %>/>
|
||||
<% else %>
|
||||
-
|
||||
<% end %>
|
||||
<%+cbi/valuefooter%>
|
@ -0,0 +1,7 @@
|
||||
<%+cbi/valueheader%>
|
||||
<% if self:cfgvalue(section) ~= false then %>
|
||||
<input class="cbi-button cbi-button-<%=self.inputstyle or "button" %>" onclick="event.preventDefault();partition_format('<%=self.partitions[section].name%>', '<%=self.format_cmd%>', '<%=self.inputtitle%>');" type="submit"<%= attr("name", cbid) .. attr("id", cbid) .. attr("value", self.inputtitle or self.title)%> <% if self.view_disabled then %> disabled <% end %>/>
|
||||
<% else %>
|
||||
-
|
||||
<% end %>
|
||||
<%+cbi/valuefooter%>
|
@ -0,0 +1,7 @@
|
||||
<div style="display: inline-block;">
|
||||
<% if self:cfgvalue(section) ~= false then %>
|
||||
<input class="cbi-button cbi-button-<%=self.inputstyle or "button" %>" type="submit"" <% if self.disable then %>disabled <% end %><%= attr("name", cbid) .. attr("id", cbid) .. attr("value", self.inputtitle or self.title)%> />
|
||||
<% else %>
|
||||
-
|
||||
<% end %>
|
||||
</div>
|
37
luci-app-diskman/luasrc/view/diskman/cbi/xnullsection.htm
Normal file
37
luci-app-diskman/luasrc/view/diskman/cbi/xnullsection.htm
Normal file
@ -0,0 +1,37 @@
|
||||
<div class="cbi-section" id="cbi-<%=self.config%>-section">
|
||||
<% if self.title and #self.title > 0 then -%>
|
||||
<legend><%=self.title%></legend>
|
||||
<%- end %>
|
||||
<% if self.description and #self.description > 0 then -%>
|
||||
<div class="cbi-section-descr"><%=self.description%></div>
|
||||
<%- end %>
|
||||
<div class="cbi-section-node">
|
||||
<div id="cbi-<%=self.config%>-<%=tostring(self):sub(8)%>">
|
||||
<% self:render_children(1, scope or {}) %>
|
||||
</div>
|
||||
<% if self.error and self.error[1] then -%>
|
||||
<div class="cbi-section-error">
|
||||
<ul><% for _, e in ipairs(self.error[1]) do -%>
|
||||
<li>
|
||||
<%- if e == "invalid" then -%>
|
||||
<%:One or more fields contain invalid values!%>
|
||||
<%- elseif e == "missing" then -%>
|
||||
<%:One or more required fields have no value!%>
|
||||
<%- else -%>
|
||||
<%=pcdata(e)%>
|
||||
<%- end -%>
|
||||
</li>
|
||||
<%- end %></ul>
|
||||
</div>
|
||||
<%- end %>
|
||||
</div>
|
||||
</div>
|
||||
<%-
|
||||
if type(self.hidden) == "table" then
|
||||
for k, v in pairs(self.hidden) do
|
||||
-%>
|
||||
<input type="hidden" id="<%=k%>" name="<%=k%>" value="<%=pcdata(v)%>" />
|
||||
<%-
|
||||
end
|
||||
end
|
||||
%>
|
87
luci-app-diskman/luasrc/view/diskman/cbi/xsimpleform.htm
Normal file
87
luci-app-diskman/luasrc/view/diskman/cbi/xsimpleform.htm
Normal file
@ -0,0 +1,87 @@
|
||||
<% if not self.embedded then %>
|
||||
<form method="post" enctype="multipart/form-data" action="<%=REQUEST_URI%>"<%=
|
||||
attr("data-strings", luci.util.serialize_json({
|
||||
label = {
|
||||
choose = translate('-- Please choose --'),
|
||||
custom = translate('-- custom --'),
|
||||
},
|
||||
path = {
|
||||
resource = resource,
|
||||
browser = url("admin/filebrowser")
|
||||
}
|
||||
}))
|
||||
%>>
|
||||
<input type="hidden" name="token" value="<%=token%>" />
|
||||
<input type="hidden" name="cbi.submit" value="1" /><%
|
||||
end
|
||||
|
||||
%><div class="cbi-map" id="cbi-<%=self.config%>"><%
|
||||
|
||||
if self.title and #self.title > 0 then
|
||||
%><h2 name="content"><%=self.title%></h2><%
|
||||
end
|
||||
|
||||
if self.description and #self.description > 0 then
|
||||
%><div class="cbi-map-descr"><%=self.description%></div><%
|
||||
end
|
||||
|
||||
if self.message then
|
||||
%><div class="alert-message notice"><%=self.message%></div><%
|
||||
end
|
||||
|
||||
if self.errmessage then
|
||||
%><div class="alert-message warning"><%=self.errmessage%></div><%
|
||||
end
|
||||
|
||||
self:render_children()
|
||||
|
||||
%></div><%
|
||||
|
||||
if not self.embedded then
|
||||
if type(self.hidden) == "table" then
|
||||
local k, v
|
||||
for k, v in pairs(self.hidden) do
|
||||
%><input type="hidden" id="<%=k%>" name="<%=k%>" value="<%=pcdata(v)%>" /><%
|
||||
end
|
||||
end
|
||||
|
||||
local display_back = (self.redirect)
|
||||
local display_cancel = (self.cancel ~= false and self.on_cancel)
|
||||
local display_skip = (self.flow and self.flow.skip)
|
||||
local display_submit = (self.submit ~= false)
|
||||
local display_reset = (self.reset ~= false)
|
||||
|
||||
if display_back or display_cancel or display_skip or display_submit or display_reset then
|
||||
%><div class="cbi-page-actions"><%
|
||||
|
||||
if display_back then
|
||||
%><input class="btn cbi-button cbi-button-link" type="button" value="<%:Back to Overview%>" onclick="location.href='<%=pcdata(self.redirect)%>'" /> <%
|
||||
end
|
||||
|
||||
if display_cancel then
|
||||
local label = pcdata(self.cancel or translate("Cancel"))
|
||||
%><input class="btn cbi-button cbi-button-link" type="button" value="<%=label%>" onclick="cbi_submit(this, 'cbi.cancel')" /> <%
|
||||
end
|
||||
|
||||
if display_skip then
|
||||
%><input class="btn cbi-button cbi-button-neutral" type="button" value="<%:Skip%>" onclick="cbi_submit(this, 'cbi.skip')" /> <%
|
||||
end
|
||||
|
||||
if display_submit then
|
||||
local label = pcdata(self.submit or translate("Submit"))
|
||||
%><input class="btn cbi-button cbi-button-save" type="submit" value="<%=label%>" /> <%
|
||||
end
|
||||
|
||||
if display_reset then
|
||||
local label = pcdata(self.reset or translate("Reset"))
|
||||
%><input class="btn cbi-button cbi-button-reset" type="reset" value="<%=label%>" /> <%
|
||||
end
|
||||
|
||||
%></div><%
|
||||
end
|
||||
|
||||
%></form><%
|
||||
end
|
||||
%>
|
||||
|
||||
<script type="text/javascript">cbi_init();</script>
|
110
luci-app-diskman/luasrc/view/diskman/disk_info.htm
Normal file
110
luci-app-diskman/luasrc/view/diskman/disk_info.htm
Normal file
@ -0,0 +1,110 @@
|
||||
<script type="text/javascript">
|
||||
window.onload = function () {
|
||||
//disk partition info
|
||||
let p_colors = ["#c0c0ff", "#fbbd00", "#e97c30", "#a0e0a0", "#e0c0ff"]
|
||||
let lines = document.querySelectorAll('[id^=cbi-disk-]')
|
||||
lines.forEach((item) => {
|
||||
let dev = item.id.match(/cbi-disk-(.*)/)[1]
|
||||
if (dev == "table") { return }
|
||||
XHR.get('<%=luci.dispatcher.build_url("admin/system/diskman/get_disk_info")%>/' + dev, null, (x, disk_info) => {
|
||||
// handle disk info
|
||||
item.childNodes.forEach((cell) => {
|
||||
if (cell && cell.attributes) {
|
||||
if (cell.getAttribute("data-name") == "sn" || cell.childNodes[1] && cell.childNodes[1].id.match(/sn/)) {
|
||||
cell.innerText = disk_info.sn || "-"
|
||||
} else if (cell.getAttribute("data-name") == "temp" || cell.childNodes[1] && cell.childNodes[1].id.match(/temp/)) {
|
||||
cell.innerText = disk_info.temp || "-"
|
||||
} else if (cell.getAttribute("data-name") == "p_table" || cell.childNodes[1] && cell.childNodes[1].id.match(/p_table/)) {
|
||||
cell.innerText = disk_info.p_table || "-"
|
||||
} else if (cell.getAttribute("data-name") == "sata_ver" || cell.childNodes[1] && cell.childNodes[1].id.match(/sata_ver/)) {
|
||||
cell.innerText = disk_info.sata_ver || "-"
|
||||
} else if (cell.getAttribute("data-name") == "health_status" || cell.childNodes[1] && cell.childNodes[1].id.match(/health_status/)) {
|
||||
cell.innerText = (disk_info.health || "-") + "\n" + (disk_info.status || "-")
|
||||
} else if (cell.getAttribute("data-name") == "health" || cell.childNodes[1] && cell.childNodes[1].id.match(/health/)) {
|
||||
cell.innerText = disk_info.health || "-"
|
||||
} else if (cell.getAttribute("data-name") == "status" || cell.childNodes[1] && cell.childNodes[1].id.match(/status/)) {
|
||||
cell.innerText = disk_info.status || "-"
|
||||
}
|
||||
}
|
||||
})
|
||||
// handle partitons info
|
||||
if (disk_info.partitions && disk_info.partitions.length > 0) {
|
||||
let partitons_div
|
||||
if (item.nodeName == "TR") {
|
||||
partitons_div = '<tr width="100%" style="white-space:nowrap;"><td style="margin:0px; padding:0px; border:0px; white-space:nowrap;" colspan="15">'
|
||||
} else if (item.nodeName == "DIV") {
|
||||
partitons_div = '<div class="tr cbi-section-table-row cbi-rowstyle-1"><div style="white-space:nowrap; position:absolute; width:100%">'
|
||||
}
|
||||
let expand = 0
|
||||
let need_expand = 0
|
||||
disk_info.partitions.forEach((part) => {
|
||||
let p = part.size / disk_info.size * 100
|
||||
if (p <= 8) {
|
||||
expand += 8
|
||||
need_expand += p
|
||||
part.part_percent = 8
|
||||
}
|
||||
})
|
||||
let n = 0
|
||||
disk_info.partitions.forEach((part) => {
|
||||
let p = part.size / disk_info.size * 100
|
||||
if (p > 8) {
|
||||
part.part_percent = p * (100 - expand) / (100 - need_expand)
|
||||
}
|
||||
let part_percent = part.part_percent + '%'
|
||||
let p_color = p_colors[n++]
|
||||
if (n > 4) { n = 0 }
|
||||
let inline_txt = (part.name != '-' && part.name || '') + ' ' + (part.fs != 'Free Space' && part.fs || '') + ' ' + part.size_formated + ' ' + (part.useage != '-' && part.useage || '')
|
||||
let partiton_div = '<div title="' + inline_txt + '" style="color: #525F7F; display:inline-block; text-align:center;background-color:' + p_color + '; width:' + part_percent + '">' + inline_txt + '</div>'
|
||||
partitons_div += partiton_div
|
||||
})
|
||||
if (item.nodeName == "TR") {
|
||||
partitons_div += '</td></tr>'
|
||||
} else if (item.nodeName == "DIV") {
|
||||
partitons_div += '</div><div> </div></div>'
|
||||
}
|
||||
item.insertAdjacentHTML('afterend', partitons_div);
|
||||
}
|
||||
})
|
||||
})
|
||||
//raid table
|
||||
lines = document.querySelectorAll('[id^=cbi-_raid-]')
|
||||
lines.forEach((item) => {
|
||||
let dev = item.id.match(/cbi-_raid-(.*)/)[1]
|
||||
if (dev == "table") { return }
|
||||
console.log(dev)
|
||||
XHR.get('<%=luci.dispatcher.build_url("admin/system/diskman/get_disk_info")%>/' + dev, null, (x, disk_info) => {
|
||||
// handle raid info
|
||||
item.childNodes.forEach((cell) => {
|
||||
if (cell && cell.attributes) {
|
||||
if (cell.getAttribute("data-name") == "p_table" || cell.childNodes[1] && cell.childNodes[1].id.match(/p_table/)) {
|
||||
cell.innerText = disk_info.p_table || "-"
|
||||
}
|
||||
}
|
||||
})
|
||||
// handle partitons info
|
||||
let partitons_div
|
||||
if (item.nodeName == "TR") {
|
||||
partitons_div = '<tr width="100%" style="white-space:nowrap;"><td style="margin:0px; padding:0px; border:0px; white-space:nowrap;" colspan="15">'
|
||||
} else if (item.nodeName == "DIV") {
|
||||
partitons_div = '<div class="tr cbi-section-table-row cbi-rowstyle-1"><div style="white-space:nowrap; position:absolute; width:100%">'
|
||||
}
|
||||
let n = 0
|
||||
disk_info.partitions.forEach((part) => {
|
||||
let part_percent = part.size / disk_info.size * 100 + '%'
|
||||
let p_color = p_colors[n++]
|
||||
if (n > 4) { n = 0 }
|
||||
let inline_txt = (part.name != '-' && part.name || '') + ' ' + (part.fs != 'Free Space' && part.fs || '') + ' ' + part.size_formated + ' ' + (part.useage != '-' && part.useage || '')
|
||||
let partiton_div = '<div title="' + inline_txt + '" style="display:inline-block; text-align:center;background-color:' + p_color + '; width:' + part_percent + '">' + inline_txt + '</div>'
|
||||
partitons_div += partiton_div
|
||||
})
|
||||
if (item.nodeName == "TR") {
|
||||
partitons_div += '</td></tr>'
|
||||
} else if (item.nodeName == "DIV") {
|
||||
partitons_div += '</div><div> </div></div>'
|
||||
}
|
||||
item.insertAdjacentHTML('afterend', partitons_div);
|
||||
})
|
||||
})
|
||||
}
|
||||
</script>
|
145
luci-app-diskman/luasrc/view/diskman/partition_info.htm
Normal file
145
luci-app-diskman/luasrc/view/diskman/partition_info.htm
Normal file
@ -0,0 +1,145 @@
|
||||
<style type="text/css">
|
||||
#dialog_format {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
display: none;
|
||||
z-index: 20000;
|
||||
}
|
||||
|
||||
#dialog_format .dialog_box {
|
||||
position: relative;
|
||||
background: rgba(255, 255, 255);
|
||||
top: 35%;
|
||||
width: 40%;
|
||||
min-width: 20em;
|
||||
margin: auto;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
height:auto;
|
||||
align-items: center;
|
||||
border-radius: 0.375rem;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
#dialog_format .dialog_box {
|
||||
background: #222222 !important;
|
||||
}
|
||||
}
|
||||
|
||||
#dialog_format .dialog_line {
|
||||
margin-top: .5em;
|
||||
margin-bottom: .5em;
|
||||
margin-left: 2em;
|
||||
margin-right: 2em;
|
||||
}
|
||||
|
||||
#dialog_format .dialog_box>h4,
|
||||
#dialog_format .dialog_box>p,
|
||||
#dialog_format .dialog_box>div {
|
||||
flex-basis: 100%;
|
||||
}
|
||||
|
||||
#dialog_format .dialog_box>img {
|
||||
margin-right: 1em;
|
||||
flex-basis: 32px;
|
||||
}
|
||||
|
||||
body.dialog-format-active {
|
||||
overflow: hidden;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
body.dialog-format-active #dialog_format {
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
function show_detail(dev, e) {
|
||||
e.preventDefault()
|
||||
window.open('<%=luci.dispatcher.build_url("admin/system/diskman/smartdetail")%>/' + dev,
|
||||
'newwindow', 'height=480,width=800,top=100,left=200,toolbar=no,menubar=no,scrollbars=yes, resizable=no,location=no, status=no')
|
||||
}
|
||||
window.onload = function () {
|
||||
// handle partition table
|
||||
const init_pt_btn = function() {
|
||||
const btn_p_table = document.getElementById("widget.cbid.table.1.p_table") || document.getElementById("cbid.table.1.p_table")
|
||||
if (!btn_p_table) {
|
||||
setTimeout(init_pt_btn, 500);
|
||||
return;
|
||||
}
|
||||
if (btn_p_table.type == 'hidden')
|
||||
return;
|
||||
const btn_p_table_raw_index = btn_p_table.selectedIndex
|
||||
const val_name = document.getElementById("cbi-table-1-path").innerText.split('/').pop()
|
||||
btn_p_table.onchange = function () {
|
||||
let btn_p_table_index = btn_p_table.selectedIndex
|
||||
if (btn_p_table_index != btn_p_table_raw_index) {
|
||||
if (confirm("<%:Warnning !! \nTHIS WILL OVERWRITE EXISTING PARTITIONS!! \nModify the partition table?%>")) {
|
||||
let p_table = btn_p_table.options[btn_p_table_index].value
|
||||
XHR.get('<%=luci.dispatcher.build_url("admin/system/diskman/mk_p_table")%>', { dev: val_name, p_table: p_table }, (x, res) => {
|
||||
if (res.code == 0) {
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
init_pt_btn();
|
||||
// handle smartinfo
|
||||
const url = location.href.split('/')
|
||||
const dev = url[url.length - 1]
|
||||
const btn_smart_detail = document.getElementById("cbi-table-1-health")
|
||||
btn_smart_detail.children[0].onclick = show_detail.bind(this, dev)
|
||||
}
|
||||
function close_dialog() {
|
||||
document.body.classList.remove('dialog-format-active')
|
||||
document.documentElement.style.overflowY = 'scroll'
|
||||
}
|
||||
function do_format(partation_name){
|
||||
let fs = document.getElementById("filesystem_list").value
|
||||
let status = document.getElementById("format-status")
|
||||
if(!fs) {
|
||||
status.innerHTML = "<%:Please select file system!%>"
|
||||
return
|
||||
}
|
||||
status.innerHTML = "<%:Formatting..%>"
|
||||
let b = document.getElementById('btn_format')
|
||||
b.disabled = true
|
||||
let xhr = new XHR()
|
||||
xhr.post('<%=luci.dispatcher.build_url("admin/system/diskman/format_partition")%>', { partation_name: partation_name, file_system: fs }, (x, res) => {
|
||||
if (x.status == 200) {
|
||||
status.innerHTML = x.statusText
|
||||
location.reload();
|
||||
}else{
|
||||
status.innerHTML = x.statusText
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function clear_text(){
|
||||
let s = document.getElementById('format-status')
|
||||
s.innerHTML = ""
|
||||
let b = document.getElementById('btn_format')
|
||||
b.disabled = false
|
||||
}
|
||||
|
||||
function partition_format(partition_name, format_cmd, current_fs){
|
||||
let list = ''
|
||||
format_cmd.split(",").forEach(e => {
|
||||
list = list + '<option value="'+e+'">'+e+'</option>'
|
||||
});
|
||||
document.getElementById('dialog_format') || document.body.insertAdjacentHTML("beforeend", '<div id="dialog_format"><div class="dialog_box"><div class="dialog_line"></div><div class="dialog_line"><span><%:Format partation:%> <b>'+partition_name+'</b></span><br><span id="format-status" style="color: red;"></span></div><div class="dialog_line"><select id="filesystem_list" class="cbi-input-select" onchange="clear_text()">'+list+'</select></div><div class="dialog_line" style="text-align: right;"><input type="button" class="cbi-button cbi-button-apply" id="btn_format" type="submit" value="<%:Format%>" onclick="do_format(`'+partition_name+'`)" /> <input type="button"class="cbi-button cbi-button-reset" type="reset" value="<%:Cancel%>" onclick="close_dialog()" /></div><div class="dialog_line"></div></div></div>>')
|
||||
document.body.classList.add('dialog-format-active')
|
||||
document.documentElement.style.overflowY = 'hidden'
|
||||
let fs_list = document.getElementById("filesystem_list")
|
||||
fs_list.value = current_fs
|
||||
}
|
||||
</script>
|
78
luci-app-diskman/luasrc/view/diskman/smart_detail.htm
Normal file
78
luci-app-diskman/luasrc/view/diskman/smart_detail.htm
Normal file
@ -0,0 +1,78 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>S.M.A.R.T detail of <%=dev%></title>
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
let formData = new FormData()
|
||||
let xhr = new XMLHttpRequest()
|
||||
xhr.open("GET", '<%=luci.dispatcher.build_url("admin", "system", "diskman", "smartattr", dev)%>', true)
|
||||
xhr.onload = function () {
|
||||
let st = JSON.parse(xhr.responseText)
|
||||
let tb = document.getElementById('smart_attr_table');
|
||||
if (st && tb) {
|
||||
/* clear all rows */
|
||||
while (tb.rows.length > 1)
|
||||
tb.deleteRow(1);
|
||||
|
||||
for (var i = 0; i < st.length; i++) {
|
||||
var tr = tb.insertRow(-1);
|
||||
tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
|
||||
var td = null
|
||||
<% if dev: match("nvme") then %>
|
||||
tr.insertCell(-1).innerHTML = st[i].key;
|
||||
tr.insertCell(-1).innerHTML = st[i].value;
|
||||
<% else %>
|
||||
tr.insertCell(-1).innerHTML = st[i].id;
|
||||
tr.insertCell(-1).innerHTML = st[i].attrbute;
|
||||
tr.insertCell(-1).innerHTML = st[i].flag;
|
||||
tr.insertCell(-1).innerHTML = st[i].value;
|
||||
tr.insertCell(-1).innerHTML = st[i].worst;
|
||||
tr.insertCell(-1).innerHTML = st[i].thresh;
|
||||
tr.insertCell(-1).innerHTML = st[i].type;
|
||||
tr.insertCell(-1).innerHTML = st[i].updated;
|
||||
tr.insertCell(-1).innerHTML = st[i].raw;
|
||||
if ((st[i].id == '05' || st[i].id == 'C5') && st[i].raw != '0') {
|
||||
tr.style.cssText = "background-color:red !important;";
|
||||
}
|
||||
<% end %>
|
||||
}
|
||||
if (tb.rows.length == 1) {
|
||||
var tr = tb.insertRow(-1);
|
||||
tr.className = 'cbi-section-table-row';
|
||||
var td = tr.insertCell(-1);
|
||||
td.colSpan = 4;
|
||||
td.innerHTML = '<em><br /><%:No Attrbute to display.%></em>';
|
||||
}
|
||||
}
|
||||
}
|
||||
xhr.send(formData)
|
||||
//]]></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="maincontainer">
|
||||
<fieldset class="cbi-section">
|
||||
<legend><%:S.M.A.R.T Attrbutes%>: /dev/<%=dev%></legend>
|
||||
<table class="cbi-section-table" id="smart_attr_table">
|
||||
<tr class="cbi-section-table-titles">
|
||||
<% if dev:match("nvme") then %>
|
||||
<!-- <th class="cbi-section-table-cell"><%:KEY%></th>
|
||||
<th class="cbi-section-table-cell"><%:VALUE%></th> -->
|
||||
<% else %>
|
||||
<th class="cbi-section-table-cell"><%:ID%></th>
|
||||
<th class="cbi-section-table-cell"><%:Attrbute%></th>
|
||||
<th class="cbi-section-table-cell"><%:Flag%></th>
|
||||
<th class="cbi-section-table-cell"><%:Value%></th>
|
||||
<th class="cbi-section-table-cell"><%:Worst%></th>
|
||||
<th class="cbi-section-table-cell"><%:Thresh%></th>
|
||||
<th class="cbi-section-table-cell"><%:Type%></th>
|
||||
<th class="cbi-section-table-cell"><%:Updated%></th>
|
||||
<th class="cbi-section-table-cell"><%:Raw%></th>
|
||||
<% end %>
|
||||
</tr>
|
||||
<tr class="cbi-section-table-row">
|
||||
<td colspan="4"><em><br /><%:Collecting data...%></em></td>
|
||||
</tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
242
luci-app-diskman/po/zh_Hans/diskman.po
Normal file
242
luci-app-diskman/po/zh_Hans/diskman.po
Normal file
@ -0,0 +1,242 @@
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=UTF-8\n"
|
||||
|
||||
msgid "DiskMan"
|
||||
msgstr "DiskMan 磁盘管理"
|
||||
|
||||
msgid "Manage Disks over LuCI."
|
||||
msgstr "通过 LuCI 管理磁盘"
|
||||
|
||||
msgid "Rescan Disks"
|
||||
msgstr "重新扫描磁盘"
|
||||
|
||||
msgid "Disks"
|
||||
msgstr "磁盘"
|
||||
|
||||
msgid "Path"
|
||||
msgstr "路径"
|
||||
|
||||
msgid "Serial Number"
|
||||
msgstr "序列号"
|
||||
|
||||
msgid "Temp"
|
||||
msgstr "温度"
|
||||
|
||||
msgid "Partition Table"
|
||||
msgstr "分区表"
|
||||
|
||||
msgid "SATA Version"
|
||||
msgstr "SATA 版本"
|
||||
|
||||
msgid "Health"
|
||||
msgstr "健康"
|
||||
|
||||
msgid "File System"
|
||||
msgstr "文件系统"
|
||||
|
||||
msgid "Mount Options"
|
||||
msgstr "挂载选项"
|
||||
|
||||
msgid "Mount"
|
||||
msgstr "挂载"
|
||||
|
||||
msgid "Umount"
|
||||
msgstr "卸载"
|
||||
|
||||
msgid "Eject"
|
||||
msgstr "弹出"
|
||||
|
||||
msgid "New"
|
||||
msgstr "新建"
|
||||
|
||||
msgid "Remove"
|
||||
msgstr "移除"
|
||||
|
||||
msgid "Format"
|
||||
msgstr "格式化"
|
||||
|
||||
msgid "Start Sector"
|
||||
msgstr "起始扇区"
|
||||
|
||||
msgid "End Sector"
|
||||
msgstr "中止扇区"
|
||||
|
||||
msgid "Usage"
|
||||
msgstr "用量"
|
||||
|
||||
msgid "Used"
|
||||
msgstr "已使用"
|
||||
|
||||
msgid "Free Space"
|
||||
msgstr "空闲空间"
|
||||
|
||||
msgid "Model"
|
||||
msgstr "型号"
|
||||
|
||||
msgid "Size"
|
||||
msgstr "容量"
|
||||
|
||||
msgid "Status"
|
||||
msgstr "状态"
|
||||
|
||||
msgid "Mount Point"
|
||||
msgstr "挂载点"
|
||||
|
||||
msgid "Sector Size"
|
||||
msgstr "扇区/物理扇区大小"
|
||||
|
||||
msgid "Rotation Rate"
|
||||
msgstr "转速"
|
||||
|
||||
msgid "RAID Devices"
|
||||
msgstr "RAID 设备"
|
||||
|
||||
msgid "RAID mode"
|
||||
msgstr "RAID 模式"
|
||||
|
||||
msgid "Members"
|
||||
msgstr "成员"
|
||||
|
||||
msgid "Active"
|
||||
msgstr "活动"
|
||||
|
||||
msgid "RAID Creation"
|
||||
msgstr "RAID 创建"
|
||||
|
||||
msgid "Raid Name"
|
||||
msgstr "RAID 名称"
|
||||
|
||||
msgid "Raid Level"
|
||||
msgstr "RAID 级别"
|
||||
|
||||
msgid "Raid Member"
|
||||
msgstr "磁盘阵列成员"
|
||||
|
||||
msgid "Create Raid"
|
||||
msgstr "创建 RAID"
|
||||
|
||||
msgid "Partition Management"
|
||||
msgstr "分区管理"
|
||||
|
||||
msgid "Partition Disk over LuCI."
|
||||
msgstr "通过LuCI分区磁盘。"
|
||||
|
||||
msgid "Device Info"
|
||||
msgstr "设备信息"
|
||||
|
||||
msgid "Disk Man"
|
||||
msgstr "磁盘管理"
|
||||
|
||||
msgid "Partitions Info"
|
||||
msgstr "分区信息"
|
||||
|
||||
msgid "Default 2048 sector alignment, support +size{b,k,m,g,t} in End Sector"
|
||||
msgstr "默认2048扇区对齐,【中止扇区】支持 +容量{b,k,m,g,t} 格式,例:+500m +10g +1t"
|
||||
|
||||
msgid "Multiple Devices Btrfs Creation"
|
||||
msgstr "Btrfs 阵列创建"
|
||||
|
||||
msgid "Label"
|
||||
msgstr "卷标"
|
||||
|
||||
msgid "Btrfs Label"
|
||||
msgstr "Btrfs 卷标"
|
||||
|
||||
msgid "Btrfs Raid Level"
|
||||
msgstr "Btrfs Raid 级别"
|
||||
|
||||
msgid "Btrfs Member"
|
||||
msgstr "Btrfs 阵列成员"
|
||||
|
||||
msgid "Create Btrfs"
|
||||
msgstr "创建 Btrfs"
|
||||
|
||||
msgid "New Snapshot"
|
||||
msgstr "新建快照"
|
||||
|
||||
msgid "SubVolumes"
|
||||
msgstr "子卷"
|
||||
|
||||
msgid "Top Level"
|
||||
msgstr "父ID"
|
||||
|
||||
msgid "Manage Btrfs"
|
||||
msgstr "Btrfs 管理"
|
||||
|
||||
msgid "Otime"
|
||||
msgstr "创建时间"
|
||||
|
||||
msgid "Snapshots"
|
||||
msgstr "快照"
|
||||
|
||||
msgid "Set Default"
|
||||
msgstr "默认子卷"
|
||||
|
||||
msgid "Source Path"
|
||||
msgstr "源目录"
|
||||
|
||||
msgid "Readonly"
|
||||
msgstr "只读"
|
||||
|
||||
msgid "Delete"
|
||||
msgstr "删除"
|
||||
|
||||
msgid "Create"
|
||||
msgstr "创建"
|
||||
|
||||
msgid "Destination Path (optional)"
|
||||
msgstr "目标目录(可选)"
|
||||
|
||||
msgid "Metadata"
|
||||
msgstr "元数据"
|
||||
|
||||
msgid "Data"
|
||||
msgstr "数据"
|
||||
|
||||
msgid "Btrfs Info"
|
||||
msgstr "Btrfs 信息"
|
||||
|
||||
msgid "The source path for create the snapshot"
|
||||
msgstr "创建快照的源数据目录"
|
||||
|
||||
msgid "The path where you want to store the snapshot"
|
||||
msgstr "存放快照数据目录"
|
||||
|
||||
msgid "Please input Source Path of snapshot, Source Path must start with '/'"
|
||||
msgstr "请输入快照源路径,源路径必须以'/'开头"
|
||||
|
||||
msgid "Please input Subvolume Path, Subvolume must start with '/'"
|
||||
msgstr "请输入子卷路径,子卷路径必须以'/'开头"
|
||||
|
||||
msgid "is in use! please unmount it first!"
|
||||
msgstr "正在被使用!请先卸载!"
|
||||
|
||||
msgid "Partition NOT found!"
|
||||
msgstr "分区未找到!"
|
||||
|
||||
msgid "Filesystem NOT support!"
|
||||
msgstr "文件系统不支持!"
|
||||
|
||||
msgid "Invalid Start Sector!"
|
||||
msgstr "无效的起始扇区!"
|
||||
|
||||
msgid "Invalid End Sector"
|
||||
msgstr "无效的终止扇区!"
|
||||
|
||||
msgid "Partition not exists!"
|
||||
msgstr "分区不存在!"
|
||||
|
||||
msgid "Creation"
|
||||
msgstr "创建"
|
||||
|
||||
msgid "Please select file system!"
|
||||
msgstr "请选择文件系统!"
|
||||
|
||||
msgid "Format partation:"
|
||||
msgstr "格式化分区:"
|
||||
|
||||
msgid "Formatting.."
|
||||
msgstr "正在格式化..."
|
||||
|
||||
msgid "Warnning !! \nTHIS WILL OVERWRITE EXISTING PARTITIONS!! \nModify the partition table?"
|
||||
msgstr "警告!!\n此操作会覆盖现有分区\n确定修改分区表?"
|
10
luci-app-eqos/Makefile
Normal file
10
luci-app-eqos/Makefile
Normal file
@ -0,0 +1,10 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=LuCI support for Easy QoS
|
||||
LUCI_DEPENDS:=+tc +kmod-sched-core +kmod-ifb
|
||||
|
||||
PKG_MAINTAINER:=Jianhui Zhao <jianhuizhao329@gmail.com>
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
67
luci-app-eqos/htdocs/luci-static/resources/view/eqos.js
Normal file
67
luci-app-eqos/htdocs/luci-static/resources/view/eqos.js
Normal file
@ -0,0 +1,67 @@
|
||||
'use strict';
|
||||
'require form';
|
||||
'require network';
|
||||
'require uci';
|
||||
'require view';
|
||||
|
||||
return view.extend({
|
||||
load: function() {
|
||||
return Promise.all([
|
||||
uci.load('eqos'),
|
||||
network.getHostHints()
|
||||
]);
|
||||
},
|
||||
|
||||
render: function(data) {
|
||||
var m, s, o;
|
||||
|
||||
m = new form.Map('eqos', _('EQoS'),
|
||||
_('Network speed control service. Not compatible with Software flow offloading.'));
|
||||
|
||||
s = m.section(form.NamedSection, 'config', 'eqos');
|
||||
|
||||
o = s.option(form.Flag, 'enabled', _('Enable'));
|
||||
o.default = o.disabled;
|
||||
o.rmempty = false;
|
||||
|
||||
o = s.option(form.Value, 'download', _('Download speed (Mbit/s)'),
|
||||
_('Total download bandwidth.'));
|
||||
o.datatype = 'and(uinteger,min(1))';
|
||||
o.rmempty = false;
|
||||
|
||||
o = s.option(form.Value, 'upload', _('Upload speed (Mbit/s)'),
|
||||
_('Total upload bandwidth.'));
|
||||
o.datatype = 'and(uinteger,min(1))';
|
||||
o.rmempty = false;
|
||||
|
||||
s = m.section(form.TableSection, 'device', _('Speed limit based on IP address'));
|
||||
s.addremove = true;
|
||||
s.anonymous = true;
|
||||
s.sortable = true;
|
||||
|
||||
o = s.option(form.Flag, 'enabled', _('Enable'));
|
||||
o.default = o.enabled;
|
||||
|
||||
o = s.option(form.Value, 'ip', _('IP address'));
|
||||
o.datatype = 'ip4addr';
|
||||
for (var i of Object.entries(data[1]?.hosts))
|
||||
for (var v in i[1].ipaddrs)
|
||||
if (i[1].ipaddrs[v]) {
|
||||
var ip_addr = i[1].ipaddrs[v], ip_host = i[1].name;
|
||||
o.value(ip_addr, ip_host ? String.format('%s (%s)', ip_host, ip_addr) : ip_addr)
|
||||
}
|
||||
o.rmempty = false;
|
||||
|
||||
o = s.option(form.Value, 'download', _('Download speed (Mbit/s)'));
|
||||
o.datatype = 'and(uinteger,min(1))';
|
||||
o.rmempty = false;
|
||||
|
||||
o = s.option(form.Value, 'upload', _('Upload speed (Mbit/s)'));
|
||||
o.datatype = 'and(uinteger,min(1))';
|
||||
o.rmempty = false;
|
||||
|
||||
o = s.option(form.Value, 'comment', _('Comment'));
|
||||
|
||||
return m.render();
|
||||
}
|
||||
});
|
50
luci-app-eqos/po/templates/eqos.pot
Normal file
50
luci-app-eqos/po/templates/eqos.pot
Normal file
@ -0,0 +1,50 @@
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=UTF-8"
|
||||
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:64
|
||||
msgid "Comment"
|
||||
msgstr ""
|
||||
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:28
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:56
|
||||
msgid "Download speed (Mbit/s)"
|
||||
msgstr ""
|
||||
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:18
|
||||
#: applications/luci-app-eqos/root/usr/share/luci/menu.d/luci-app-eqos.json:3
|
||||
msgid "EQoS"
|
||||
msgstr ""
|
||||
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:24
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:43
|
||||
msgid "Enable"
|
||||
msgstr ""
|
||||
|
||||
#: applications/luci-app-eqos/root/usr/share/rpcd/acl.d/luci-app-eqos.json:3
|
||||
msgid "Grant UCI access for luci-app-eqos"
|
||||
msgstr ""
|
||||
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:46
|
||||
msgid "IP address"
|
||||
msgstr ""
|
||||
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:19
|
||||
msgid "Network speed control service."
|
||||
msgstr ""
|
||||
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:38
|
||||
msgid "Speed limit based on IP address"
|
||||
msgstr ""
|
||||
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:29
|
||||
msgid "Total download bandwidth."
|
||||
msgstr ""
|
||||
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:34
|
||||
msgid "Total upload bandwidth."
|
||||
msgstr ""
|
||||
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:33
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:60
|
||||
msgid "Upload speed (Mbit/s)"
|
||||
msgstr ""
|
58
luci-app-eqos/po/zh_Hans/eqos.po
Normal file
58
luci-app-eqos/po/zh_Hans/eqos.po
Normal file
@ -0,0 +1,58 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: LuCi Chinese Translation\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"Language: zh_Hans\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=1; plural=0;\n"
|
||||
"X-Generator: Pootle 2.0.6\n"
|
||||
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:64
|
||||
msgid "Comment"
|
||||
msgstr "注释"
|
||||
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:28
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:56
|
||||
msgid "Download speed (Mbit/s)"
|
||||
msgstr "下载速度 (Mbit/s)"
|
||||
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:18
|
||||
#: applications/luci-app-eqos/root/usr/share/luci/menu.d/luci-app-eqos.json:3
|
||||
msgid "EQoS"
|
||||
msgstr "网速控制"
|
||||
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:24
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:43
|
||||
msgid "Enable"
|
||||
msgstr "启用"
|
||||
|
||||
#: applications/luci-app-eqos/root/usr/share/rpcd/acl.d/luci-app-eqos.json:3
|
||||
msgid "Grant UCI access for luci-app-eqos"
|
||||
msgstr "授予 luci-app-eqos 访问 UCI 配置的权限"
|
||||
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:46
|
||||
msgid "IP address"
|
||||
msgstr "IP 地址"
|
||||
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:19
|
||||
msgid "Network speed control service. Not compatible with Software flow offloading."
|
||||
msgstr "网速控制服务。(与软件流量分载不兼容)"
|
||||
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:38
|
||||
msgid "Speed limit based on IP address"
|
||||
msgstr "基于 IP 限速"
|
||||
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:29
|
||||
msgid "Total download bandwidth."
|
||||
msgstr "总下载带宽。"
|
||||
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:34
|
||||
msgid "Total upload bandwidth."
|
||||
msgstr "总上传带宽。"
|
||||
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:33
|
||||
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:60
|
||||
msgid "Upload speed (Mbit/s)"
|
||||
msgstr "上传速度 (Mbit/s)"
|
12
luci-app-eqos/root/etc/config/eqos
Normal file
12
luci-app-eqos/root/etc/config/eqos
Normal file
@ -0,0 +1,12 @@
|
||||
# The bandwidth unit is Mbit/s
|
||||
config eqos 'config'
|
||||
option enabled 0
|
||||
option download 100
|
||||
option upload 20
|
||||
|
||||
# Limiting the bandwidth of a single Device
|
||||
#config device
|
||||
# option ip "192.168.1.100"
|
||||
# option download 10
|
||||
# option upload 5
|
||||
# option comment "test"
|
5
luci-app-eqos/root/etc/hotplug.d/iface/10-eqos
Executable file
5
luci-app-eqos/root/etc/hotplug.d/iface/10-eqos
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
[ "$ACTION" = "ifup" ] || exit 0
|
||||
[ "$INTERFACE" = "lan" ] || exit 0
|
||||
|
||||
/etc/init.d/eqos start
|
83
luci-app-eqos/root/etc/init.d/eqos
Executable file
83
luci-app-eqos/root/etc/init.d/eqos
Executable file
@ -0,0 +1,83 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
|
||||
START=50
|
||||
USE_PROCD=1
|
||||
|
||||
disable_offload() {
|
||||
if [ $(uci -q show firewall.@defaults[0] | grep -c flow_offloading) -ge 1 ]; then
|
||||
echo flow_offloading > /etc/.eqos_offload
|
||||
uci -q del firewall.@defaults[0].flow_offloading
|
||||
uci commit firewall
|
||||
/etc/init.d/firewall reload >/dev/null 2>&1
|
||||
elif [ $(uci -q show firewall.@defaults[0] | grep -c shortcut_fe) -ge 1 ]; then
|
||||
uci -q get firewall.@defaults[0].shortcut_fe_module > /etc/.eqos_offload
|
||||
uci -q del firewall.@defaults[0].shortcut_fe
|
||||
uci -q del firewall.@defaults[0].shortcut_fe_module
|
||||
uci commit firewall
|
||||
/etc/init.d/firewall reload >/dev/null 2>&1
|
||||
/etc/init.d/shortcut-fe restart
|
||||
fi
|
||||
}
|
||||
|
||||
enable_offload() {
|
||||
offload_mode=$(cat /etc/.eqos_offload)
|
||||
rm -f /etc/.eqos_offload
|
||||
if [ "$offload_mode" = "flow_offloading" ]; then
|
||||
uci set firewall.@defaults[0].flow_offloading='1'
|
||||
uci commit firewall
|
||||
/etc/init.d/firewall reload >/dev/null 2>&1
|
||||
else
|
||||
uci set firewall.@defaults[0].shortcut_fe='1'
|
||||
uci set firewall.@defaults[0].shortcut_fe_module="$offload_mode"
|
||||
uci commit firewall
|
||||
/etc/init.d/firewall reload >/dev/null 2>&1
|
||||
/etc/init.d/shortcut-fe restart
|
||||
fi
|
||||
}
|
||||
|
||||
parse_device() {
|
||||
local cfg="$1"
|
||||
|
||||
local enabled
|
||||
config_get_bool enabled "$cfg" "enabled" "1"
|
||||
[ "$enabled" -eq "1" ] || return 1
|
||||
|
||||
local ip download upload
|
||||
config_get ip "$cfg" "ip"
|
||||
config_get download "$cfg" "download"
|
||||
config_get upload "$cfg" "upload"
|
||||
|
||||
eqos add "$ip" "$download" "$upload"
|
||||
}
|
||||
|
||||
start_service() {
|
||||
config_load "eqos"
|
||||
|
||||
local enabled
|
||||
config_get_bool enabled "config" "enabled" "0"
|
||||
[ "$enabled" -eq "1" ] || return 1
|
||||
disable_offload
|
||||
|
||||
local download upload
|
||||
config_get download "config" "download"
|
||||
config_get upload "config" "upload"
|
||||
|
||||
eqos start "$download" "$upload"
|
||||
|
||||
config_foreach parse_device "device"
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
eqos stop
|
||||
[ -f "/etc/.eqos_offload" ] && enable_offload
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
stop
|
||||
start
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "eqos"
|
||||
}
|
60
luci-app-eqos/root/usr/sbin/eqos
Executable file
60
luci-app-eqos/root/usr/sbin/eqos
Executable file
@ -0,0 +1,60 @@
|
||||
#!/bin/sh
|
||||
|
||||
dev=br-lan
|
||||
|
||||
stop_qos() {
|
||||
tc qdisc del dev $dev root 2>/dev/null
|
||||
tc qdisc del dev $dev ingress 2>/dev/null
|
||||
tc qdisc del dev ${dev}-ifb root 2>/dev/null
|
||||
ip link del dev ${dev}-ifb 2>/dev/null
|
||||
}
|
||||
|
||||
start_qos() {
|
||||
local dl=$1
|
||||
local up=$2
|
||||
|
||||
tc qdisc add dev $dev root handle 1: htb
|
||||
tc class add dev $dev parent 1: classid 1:1 htb rate ${dl}mbit
|
||||
|
||||
ip link add dev ${dev}-ifb name ${dev}-ifb type ifb
|
||||
ip link set dev ${dev}-ifb up
|
||||
|
||||
tc qdisc add dev ${dev}-ifb root handle 1: htb
|
||||
tc class add dev ${dev}-ifb parent 1: classid 1:1 htb rate ${up}mbit
|
||||
|
||||
tc qdisc add dev $dev ingress
|
||||
tc filter add dev $dev parent ffff: protocol ip u32 match u32 0 0 flowid 1:1 action mirred egress redirect dev ${dev}-ifb
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
"stop")
|
||||
stop_qos
|
||||
;;
|
||||
"start")
|
||||
stop_qos
|
||||
start_qos $2 $3
|
||||
;;
|
||||
"add")
|
||||
ip="$2"
|
||||
dl="$3"
|
||||
up="$4"
|
||||
|
||||
cnt=$(tc class show dev $dev | wc -l)
|
||||
|
||||
tc class add dev $dev parent 1:1 classid 1:1$cnt htb rate ${dl}mbit ceil ${dl}mbit
|
||||
tc filter add dev $dev parent 1:0 protocol ip u32 match ip dst $ip flowid 1:1$cnt
|
||||
|
||||
tc class add dev ${dev}-ifb parent 1:1 classid 1:1$cnt htb rate ${up}mbit ceil ${up}mbit
|
||||
tc filter add dev ${dev}-ifb parent 1:0 protocol ip u32 match ip src $ip flowid 1:1$cnt
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 <command> [options]"
|
||||
echo "Commands:"
|
||||
echo " start dl_rate up_rate #Total bandwidth (Mbit/s)"
|
||||
echo " stop"
|
||||
echo " add ip dl_rate up_rate #Limiting the bandwidth of a single IP (Mbit/s)"
|
||||
echo "Example:"
|
||||
echo " $0 start 30 20 # Total bandwidth: down 30Mbit/s up 20Mbit/s"
|
||||
echo " $0 add 192.168.22.12 10 2 # down 10Mbit/s up 2Mbit/s"
|
||||
;;
|
||||
esac
|
13
luci-app-eqos/root/usr/share/luci/menu.d/luci-app-eqos.json
Normal file
13
luci-app-eqos/root/usr/share/luci/menu.d/luci-app-eqos.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"admin/network/eqos": {
|
||||
"title": "EQoS",
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "eqos"
|
||||
},
|
||||
"depends": {
|
||||
"acl": [ "luci-app-eqos" ],
|
||||
"uci": { "eqos": true }
|
||||
}
|
||||
}
|
||||
}
|
11
luci-app-eqos/root/usr/share/rpcd/acl.d/luci-app-eqos.json
Normal file
11
luci-app-eqos/root/usr/share/rpcd/acl.d/luci-app-eqos.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"luci-app-eqos": {
|
||||
"description": "Grant UCI access for luci-app-eqos",
|
||||
"read": {
|
||||
"uci": [ "eqos" ]
|
||||
},
|
||||
"write": {
|
||||
"uci": [ "eqos" ]
|
||||
}
|
||||
}
|
||||
}
|
24
luci-app-filebrowser-go/Makefile
Normal file
24
luci-app-filebrowser-go/Makefile
Normal file
@ -0,0 +1,24 @@
|
||||
# Copyright (C) 2018-2020 Lienol <lawlienol@gmail.com>
|
||||
#
|
||||
# This is free software, licensed under the Apache License, Version 2.0 .
|
||||
#
|
||||
# Improve by xiaozhuai <xiaozhuai7@gmail.com>
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-filebrowser-go
|
||||
PKG_VERSION:=1.1
|
||||
PKG_RELEASE:=2
|
||||
|
||||
LUCI_TITLE:=LuCI support for FileBrowser
|
||||
LUCI_PKGARCH:=all
|
||||
LUCI_DEPENDS:=+filebrowser +luci-compat
|
||||
|
||||
define Package/$(PKG_NAME)/conffiles
|
||||
/etc/filebrowser.db
|
||||
endef
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
41
luci-app-filebrowser-go/luasrc/controller/filebrowser.lua
Normal file
41
luci-app-filebrowser-go/luasrc/controller/filebrowser.lua
Normal file
@ -0,0 +1,41 @@
|
||||
-- Copyright 2018-2020 Lienol <lawlienol@gmail.com>
|
||||
-- Improve by xiaozhuai <xiaozhuai7@gmail.com>
|
||||
module("luci.controller.filebrowser", package.seeall)
|
||||
|
||||
local http = require "luci.http"
|
||||
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/filebrowser") then
|
||||
return
|
||||
end
|
||||
|
||||
local page = entry({"admin", "services", "filebrowser"}, alias("admin", "services", "filebrowser", "settings"), _("File Browser"), 100)
|
||||
page.dependent = true
|
||||
page.acl_depends = { "luci-app-filebrowser-go" }
|
||||
|
||||
entry({"admin", "services", "filebrowser", "settings"}, cbi("filebrowser/settings"), _("Settings"), 1).leaf = true
|
||||
entry({"admin", "services", "filebrowser", "log"}, cbi("filebrowser/log"), _("Log"), 2).leaf = true
|
||||
entry({"admin", "services", "filebrowser", "check"}, call("action_check")).leaf = true
|
||||
entry({"admin", "services", "filebrowser", "status"}, call("act_status")).leaf = true
|
||||
entry({"admin", "services", "filebrowser", "get_log"}, call("get_log")).leaf = true
|
||||
entry({"admin", "services", "filebrowser", "clear_log"}, call("clear_log")).leaf = true
|
||||
end
|
||||
|
||||
function http_write_json(content)
|
||||
http.prepare_content("application/json")
|
||||
http.write_json(content or {code = 1})
|
||||
end
|
||||
|
||||
function act_status()
|
||||
local e = {}
|
||||
e.running = luci.sys.call("pgrep filebrowser >/dev/null") == 0
|
||||
http_write_json(e)
|
||||
end
|
||||
|
||||
function get_log()
|
||||
luci.http.write(luci.sys.exec("[ -f '/var/log/filebrowser.log' ] && cat /var/log/filebrowser.log"))
|
||||
end
|
||||
|
||||
function clear_log()
|
||||
luci.sys.call("echo '' > /var/log/filebrowser.log")
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
m = Map("filebrowser")
|
||||
|
||||
m:append(Template("filebrowser/filebrowser_log"))
|
||||
|
||||
return m
|
@ -0,0 +1,47 @@
|
||||
m = Map("filebrowser")
|
||||
m.title = translate("File Browser")
|
||||
m.description = translate("File explorer is software that creates your own cloud that you can install on a server, point it to a path, and then access your files through a beautiful web interface. You have many features available!")
|
||||
|
||||
m:section(SimpleSection).template = "filebrowser/filebrowser_status"
|
||||
|
||||
s = m:section(TypedSection, "global")
|
||||
s.anonymous = true
|
||||
s.addremove = false
|
||||
|
||||
o = s:option(Flag, "enable", translate("Enable"))
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "address", translate("Listen address"))
|
||||
o.default = "0.0.0.0"
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "port", translate("Listen port"))
|
||||
o.datatype = "port"
|
||||
o.default = 8088
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "database", translate("Database path"))
|
||||
o.default = "/etc/filebrowser.db"
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "username", translate("Initial username"))
|
||||
o.default = "admin"
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "password", translate("Initial password"))
|
||||
o.default = "admin"
|
||||
o.rmempty = false
|
||||
o.password = true
|
||||
|
||||
o = s:option(Value, "ssl_cert", translate("SSL cert"))
|
||||
o.default = ""
|
||||
|
||||
o = s:option(Value, "ssl_key", translate("SSL key"))
|
||||
o.default = ""
|
||||
|
||||
o = s:option(Value, "root_path", translate("Root path"))
|
||||
o.description = translate("Point to a path to access your files in the web interface, default is /")
|
||||
o.default = "/"
|
||||
o.rmempty = false
|
||||
|
||||
return m
|
@ -0,0 +1,28 @@
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
function clear_log(btn) {
|
||||
XHR.get('<%=url([[admin]], [[services]], [[filebrowser]], [[clear_log]])%>', null,
|
||||
function(x, data) {
|
||||
if(x && x.status == 200) {
|
||||
var log_textarea = document.getElementById('log_textarea');
|
||||
log_textarea.innerHTML = "";
|
||||
log_textarea.scrollTop = log_textarea.scrollHeight;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
XHR.poll(3, '<%=url([[admin]], [[services]], [[filebrowser]], [[get_log]])%>', null,
|
||||
function(x, data) {
|
||||
if(x && x.status == 200) {
|
||||
var log_textarea = document.getElementById('log_textarea');
|
||||
log_textarea.innerHTML = x.responseText;
|
||||
log_textarea.scrollTop = log_textarea.scrollHeight;
|
||||
}
|
||||
}
|
||||
);
|
||||
//]]>
|
||||
</script>
|
||||
<fieldset class="cbi-section" id="_log_fieldset">
|
||||
<input class="cbi-button cbi-input-remove" type="button" onclick="clear_log()" value="<%:Clear logs%>" style="margin-left: 10px; margin-top: 10px;">
|
||||
<textarea id="log_textarea" class="cbi-input-textarea" style="width: calc(100% - 20px); margin: 10px;" data-update="change" rows="5" wrap="off" readonly="readonly"></textarea>
|
||||
</fieldset>
|
@ -0,0 +1,22 @@
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
XHR.poll(3, '<%=url([[admin]], [[services]], [[filebrowser]], [[status]])%>', null,
|
||||
function(x, data) {
|
||||
var tb = document.getElementById('filebrowser_status');
|
||||
if (data && tb) {
|
||||
if (data.running) {
|
||||
tb.innerHTML = '<em style=\"color:green\"><b><%:File Browser%> <%:RUNNING%></b></em>' + "<input class=\"cbi-button-reload mar-10\" type=\"button\" value=\" <%:Enter interface%> \" onclick=\"window.open('//" + window.location.hostname + ":" + <%=luci.sys.exec("uci -q get filebrowser.@global[0].port"):gsub("^%s*(.-)%s*$", "%1")%> + "/')\"/>";
|
||||
} else {
|
||||
tb.innerHTML = '<em style=\"color:red\"><b><%:File Browser%> <%:NOT RUNNING%></b></em>';
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
//]]>
|
||||
</script>
|
||||
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
|
||||
<fieldset class="cbi-section">
|
||||
<p id="filebrowser_status">
|
||||
<em><%:Collecting data...%></em>
|
||||
</p>
|
||||
</fieldset>
|
56
luci-app-filebrowser-go/po/zh-cn/filebrowser.po
Normal file
56
luci-app-filebrowser-go/po/zh-cn/filebrowser.po
Normal file
@ -0,0 +1,56 @@
|
||||
msgid "File Browser"
|
||||
msgstr "文件浏览器"
|
||||
|
||||
msgid "File explorer is software that creates your own cloud that you can install on a server, point it to a path, and then access your files through a beautiful web interface. You have many features available!"
|
||||
msgstr "文件浏览器是一种创建你自己的云的软件,你可以在服务器上安装它,将它指向一个路径,然后通过一个漂亮的web界面访问你的文件。您有许多可用的特性!"
|
||||
|
||||
msgid "Settings"
|
||||
msgstr "设置"
|
||||
|
||||
msgid "Log"
|
||||
msgstr "日志"
|
||||
|
||||
msgid "RUNNING"
|
||||
msgstr "运行中"
|
||||
|
||||
msgid "NOT RUNNING"
|
||||
msgstr "未运行"
|
||||
|
||||
msgid "Enter interface"
|
||||
msgstr "进入界面"
|
||||
|
||||
msgid "Enable"
|
||||
msgstr "启用"
|
||||
|
||||
msgid "Listen address"
|
||||
msgstr "监听地址"
|
||||
|
||||
msgid "Listen port"
|
||||
msgstr "监听端口"
|
||||
|
||||
msgid "Initial username"
|
||||
msgstr "初始账户"
|
||||
|
||||
msgid "Initial password"
|
||||
msgstr "初始密码"
|
||||
|
||||
msgid "SSL cert"
|
||||
msgstr "SSL 证书"
|
||||
|
||||
msgid "SSL key"
|
||||
msgstr "SSL 私钥"
|
||||
|
||||
msgid "Database path"
|
||||
msgstr "数据库路径"
|
||||
|
||||
msgid "Root path"
|
||||
msgstr "指向路径"
|
||||
|
||||
msgid "Point to a path to access your files in the web interface, default is /"
|
||||
msgstr "指向一个路径,可在web界面访问你的文件,默认为 /"
|
||||
|
||||
msgid "Logs"
|
||||
msgstr "日志"
|
||||
|
||||
msgid "Clear logs"
|
||||
msgstr "清空日志"
|
1
luci-app-filebrowser-go/po/zh_Hans
Symbolic link
1
luci-app-filebrowser-go/po/zh_Hans
Symbolic link
@ -0,0 +1 @@
|
||||
zh-cn
|
12
luci-app-filebrowser-go/root/etc/config/filebrowser
Normal file
12
luci-app-filebrowser-go/root/etc/config/filebrowser
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
config global
|
||||
option address '0.0.0.0'
|
||||
option port '8088'
|
||||
option database '/etc/filebrowser.db'
|
||||
option username 'admin'
|
||||
option password 'admin'
|
||||
option ssl_cert ''
|
||||
option ssl_key ''
|
||||
option root_path '/'
|
||||
option enable '0'
|
||||
|
47
luci-app-filebrowser-go/root/etc/init.d/filebrowser
Executable file
47
luci-app-filebrowser-go/root/etc/init.d/filebrowser
Executable file
@ -0,0 +1,47 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2018-2022 Lienol <lawlienol@gmail.com>
|
||||
# Improve by xiaozhuai <xiaozhuai7@gmail.com>
|
||||
|
||||
START=99
|
||||
USE_PROCD=1
|
||||
PROG=/usr/sbin/filebrowser
|
||||
LOG_PATH="/var/log/filebrowser.log"
|
||||
|
||||
get_config() {
|
||||
config_get_bool enable $1 enable 1
|
||||
config_get address $1 address "0.0.0.0"
|
||||
config_get port $1 port 8088
|
||||
config_get database $1 database "/etc/filebrowser.db"
|
||||
config_get username $1 username "admin"
|
||||
config_get password $1 password "admin"
|
||||
config_get ssl_cert $1 ssl_cert ""
|
||||
config_get ssl_key $1 ssl_key ""
|
||||
config_get root_path $1 root_path "/"
|
||||
}
|
||||
|
||||
start_service() {
|
||||
config_load filebrowser
|
||||
config_foreach get_config global
|
||||
[ $enable != 1 ] && return 1
|
||||
rm -f $LOG_PATH
|
||||
ssl_params=""
|
||||
[ -n "$ssl_cert" ] && [ -n "$ssl_key" ] && ssl_params="-t $ssl_cert -k $ssl_key"
|
||||
password=$($PROG hash "$password")
|
||||
procd_open_instance filebrowser
|
||||
procd_set_param command $PROG
|
||||
procd_append_param command -a $address -p $port -r $root_path -d "$database" --username $username --password $password $ssl_params -l $LOG_PATH
|
||||
procd_set_param stdout 0
|
||||
procd_set_param stderr 0
|
||||
procd_set_param respawn
|
||||
procd_close_instance filebrowser
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "filebrowser"
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
stop
|
||||
sleep 1
|
||||
start
|
||||
}
|
11
luci-app-filebrowser-go/root/etc/uci-defaults/luci-filebrowser
Executable file
11
luci-app-filebrowser-go/root/etc/uci-defaults/luci-filebrowser
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@filebrowser[-1]
|
||||
add ucitrack filebrowser
|
||||
set ucitrack.@filebrowser[-1].init=filebrowser
|
||||
commit ucitrack
|
||||
EOF
|
||||
|
||||
rm -f /tmp/luci-indexcache
|
||||
exit 0
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"luci-app-filebrowser-go": {
|
||||
"description": "Grant UCI access for luci-app-filebrowser",
|
||||
"read": {
|
||||
"uci": [ "filebrowser" ]
|
||||
},
|
||||
"write": {
|
||||
"uci": [ "filebrowser" ]
|
||||
}
|
||||
}
|
||||
}
|
22
luci-app-gowebdav/Makefile
Normal file
22
luci-app-gowebdav/Makefile
Normal file
@ -0,0 +1,22 @@
|
||||
# Copyright (C) 2016 Openwrt.org
|
||||
#
|
||||
# This is a free software, use it under GNU General Public License v3.0.
|
||||
#
|
||||
# Created By ImmortalWrt
|
||||
# https://github.com/project-openwrt
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-gowebdav
|
||||
PKG_VERSION:=1.0
|
||||
PKG_RELEASE:=1
|
||||
|
||||
LUCI_TITLE:=LuCI support for GoWebDav
|
||||
LUCI_DEPENDS:=+gowebdav
|
||||
LUCI_PKGARCH:=all
|
||||
|
||||
PKG_MAINTAINER:=CN_SZTL <cnsztl@immortalwrt.org>
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
22
luci-app-gowebdav/luasrc/controller/gowebdav.lua
Normal file
22
luci-app-gowebdav/luasrc/controller/gowebdav.lua
Normal file
@ -0,0 +1,22 @@
|
||||
module("luci.controller.gowebdav", package.seeall)
|
||||
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/gowebdav") then
|
||||
return
|
||||
end
|
||||
|
||||
entry({"admin", "nas"}, firstchild(), _("NAS"), 45).dependent = false
|
||||
|
||||
local page = entry({"admin", "nas", "gowebdav"}, cbi("gowebdav"), _("GoWebDav"), 100)
|
||||
page.dependent = true
|
||||
page.acl_depends = { "luci-app-gowebdav" }
|
||||
|
||||
entry({"admin", "nas", "gowebdav", "status"}, call("act_status")).leaf = true
|
||||
end
|
||||
|
||||
function act_status()
|
||||
local e = {}
|
||||
e.running = luci.sys.call("pgrep gowebdav >/dev/null") == 0
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(e)
|
||||
end
|
60
luci-app-gowebdav/luasrc/model/cbi/gowebdav.lua
Normal file
60
luci-app-gowebdav/luasrc/model/cbi/gowebdav.lua
Normal file
@ -0,0 +1,60 @@
|
||||
-- Created By ImmortalWrt
|
||||
-- https://github.com/immortalwrt
|
||||
|
||||
m = Map("gowebdav", translate("GoWebDav"))
|
||||
m.description = translate("GoWebDav is a tiny, simple, fast WevDav server.")
|
||||
|
||||
m:section(SimpleSection).template = "gowebdav/gowebdav_status"
|
||||
|
||||
s = m:section(TypedSection, "gowebdav")
|
||||
s.addremove = false
|
||||
s.anonymous = true
|
||||
|
||||
o = s:option(Flag, "enable", translate("Enable"))
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "listen_port", translate("Listen Port"))
|
||||
o.placeholder = 6086
|
||||
o.default = 6086
|
||||
o.datatype = "port"
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "username", translate("Username"))
|
||||
o.description = translate("Leave blank to disable auth.")
|
||||
o.datatype = "string"
|
||||
|
||||
o = s:option(Value, "password", translate("Password"))
|
||||
o.description = translate("Leave blank to disable auth.")
|
||||
o.datatype = "string"
|
||||
o.password = true
|
||||
|
||||
o = s:option(Value, "root_dir", translate("Root Directory"))
|
||||
o.placeholder = "/mnt"
|
||||
o.default = "/mnt"
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Flag, "read_only", translate("Read-Only Mode"))
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Flag, "show_hidden", translate("Show Hidden Files"))
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Flag, "allow_wan", translate("Allow Access From Internet"))
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Flag, "use_https", translate("Use HTTPS instead of HTTP"))
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "cert_cer", translate("Path to Certificate"))
|
||||
o.datatype = "file"
|
||||
o:depends("use_https", 1)
|
||||
|
||||
o = s:option(Value, "cert_key", translate("Path to Certificate Key"))
|
||||
o.datatype = "file"
|
||||
o:depends("use_https", 1)
|
||||
|
||||
o = s:option(Button, "download_reg", translate("Download Reg File"))
|
||||
o.template = "gowebdav/download_reg"
|
||||
o.description = translate("Windows doesn't allow HTTP auth by default, you need to import this reg key to enable it (Reboot needed).")
|
||||
|
||||
return m
|
15
luci-app-gowebdav/luasrc/view/gowebdav/download_reg.htm
Normal file
15
luci-app-gowebdav/luasrc/view/gowebdav/download_reg.htm
Normal file
@ -0,0 +1,15 @@
|
||||
<%+cbi/valueheader%>
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
function download(filename, reg) {
|
||||
var element = document.createElement('a');
|
||||
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(reg));
|
||||
element.setAttribute('download', filename);
|
||||
element.style.display = 'none';
|
||||
document.body.appendChild(element);
|
||||
element.click();
|
||||
document.body.removeChild(element);
|
||||
};
|
||||
//]]>
|
||||
</script>
|
||||
<input type="button" class="btn cbi-button cbi-button-reload" value="<%:Click Download%>" onclick='download("allow_http.reg","Windows Registry Editor Version 5.00\r\n\r\n[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\WebClient\\Parameters]\r\n\"BasicAuthLevel\"=dword:00000002\r\n\"FileSizeLimitInBytes\"=dword:ffffffff")' />
|
||||
<%+cbi/valuefooter%>
|
27
luci-app-gowebdav/luasrc/view/gowebdav/gowebdav_status.htm
Normal file
27
luci-app-gowebdav/luasrc/view/gowebdav/gowebdav_status.htm
Normal file
@ -0,0 +1,27 @@
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
XHR.poll(1, '<%=url([[admin]], [[nas]], [[gowebdav]], [[status]])%>', null,
|
||||
function(x, data) {
|
||||
var tb = document.getElementById('gowebdav_status');
|
||||
if (data && tb) {
|
||||
if (data.running) {
|
||||
var links = '<em style=\"color:green\"><b>GoWebDav <%:RUNNING%></b></em><input class="cbi-button cbi-button-reload mar-10" type="button" value="<%:Open Web Interface%>" onclick="openwebui();" />';
|
||||
tb.innerHTML = links;
|
||||
} else {
|
||||
tb.innerHTML = '<em style=\"color:red\"><b>GoWebDav <%:NOT RUNNING%></b></em>';
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
function openwebui() {
|
||||
var url = window.location.hostname+":<%=luci.sys.exec("uci -q get gowebdav.config.listen_port"):gsub("^%s*(.-)%s*$", "%1")%>";
|
||||
window.open('http://'+url,'target','');
|
||||
};
|
||||
//]]>
|
||||
</script>
|
||||
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
|
||||
<fieldset class="cbi-section">
|
||||
<p id="gowebdav_status">
|
||||
<em><%:Collecting data...%></em>
|
||||
</p>
|
||||
</fieldset>
|
53
luci-app-gowebdav/po/zh_Hans/gowebdav.po
Normal file
53
luci-app-gowebdav/po/zh_Hans/gowebdav.po
Normal file
@ -0,0 +1,53 @@
|
||||
msgid "GoWebDav"
|
||||
msgstr "GoWebDav"
|
||||
|
||||
msgid "GoWebDav is a tiny, simple, fast WevDav server."
|
||||
msgstr "GoWebDav 是一个轻巧、简单、快速的 WebDav 服务端程序。"
|
||||
|
||||
msgid "Enable"
|
||||
msgstr "启用"
|
||||
|
||||
msgid "Listen Port"
|
||||
msgstr "监听端口"
|
||||
|
||||
msgid "Username"
|
||||
msgstr "用户名"
|
||||
|
||||
msgid "Password"
|
||||
msgstr "密码"
|
||||
|
||||
msgid "Leave blank to disable auth."
|
||||
msgstr "留空以禁用身份验证。"
|
||||
|
||||
msgid "Root Directory"
|
||||
msgstr "开放目录"
|
||||
|
||||
msgid "Read-Only Mode"
|
||||
msgstr "只读模式"
|
||||
|
||||
msgid "Show Hidden Files"
|
||||
msgstr "显示隐藏文件"
|
||||
|
||||
msgid "Download Reg File"
|
||||
msgstr "下载注册表文件"
|
||||
|
||||
msgid "Click Download"
|
||||
msgstr "点击下载"
|
||||
|
||||
msgid "Windows doesn't allow HTTP auth by default, you need to import this reg key to enable it (Reboot needed)."
|
||||
msgstr "Windows 系统默认不允许 HTTP 鉴权,您需要手动导入注册表文件以开启此功能(需重启)。"
|
||||
|
||||
msgid "Allow Access From Internet"
|
||||
msgstr "允许从外网访问"
|
||||
|
||||
msgid "Use HTTPS instead of HTTP"
|
||||
msgstr "使用 HTTPS 模式"
|
||||
|
||||
msgid "Path to Certificate"
|
||||
msgstr "证书位置"
|
||||
|
||||
msgid "Path to Certificate Key"
|
||||
msgstr "密钥位置"
|
||||
|
||||
msgid "Open Web Interface"
|
||||
msgstr "打开 Web 界面"
|
17
luci-app-gowebdav/root/etc/uci-defaults/luci-gowebdav
Executable file
17
luci-app-gowebdav/root/etc/uci-defaults/luci-gowebdav
Executable file
@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@gowebdav[-1]
|
||||
add ucitrack gowebdav
|
||||
set ucitrack.@gowebdav[-1].init=gowebdav
|
||||
commit ucitrack
|
||||
delete firewall.gowebdav
|
||||
set firewall.gowebdav=include
|
||||
set firewall.gowebdav.type=script
|
||||
set firewall.gowebdav.path=/var/etc/gowebdav.include
|
||||
set firewall.gowebdav.reload=1
|
||||
commit firewall
|
||||
EOF
|
||||
|
||||
rm -f /tmp/luci-indexcache
|
||||
exit 0
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"luci-app-gowebdav": {
|
||||
"description": "Grant UCI access for luci-app-gowebdav",
|
||||
"read": {
|
||||
"uci": [ "gowebdav" ]
|
||||
},
|
||||
"write": {
|
||||
"uci": [ "gowebdav" ]
|
||||
}
|
||||
}
|
||||
}
|
18
luci-app-netdata/Makefile
Normal file
18
luci-app-netdata/Makefile
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (C) 2016 Openwrt.org
|
||||
#
|
||||
# This is free software, licensed under the Apache License, Version 2.0 .
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=LuCI support for Netdata
|
||||
LUCI_DEPENDS:=+netdata
|
||||
LUCI_PKGARCH:=all
|
||||
|
||||
PKG_NAME:=luci-app-netdata
|
||||
PKG_VERSION:=1.0
|
||||
PKG_RELEASE:=3
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
6
luci-app-netdata/luasrc/controller/netdata.lua
Normal file
6
luci-app-netdata/luasrc/controller/netdata.lua
Normal file
@ -0,0 +1,6 @@
|
||||
module("luci.controller.netdata", package.seeall)
|
||||
|
||||
function index()
|
||||
|
||||
entry({"admin", "status", "netdata"}, template("netdata/netdata"), _("NetData"), 10).leaf = true
|
||||
end
|
9
luci-app-netdata/luasrc/view/netdata/netdata.htm
Normal file
9
luci-app-netdata/luasrc/view/netdata/netdata.htm
Normal file
@ -0,0 +1,9 @@
|
||||
<%+header%>
|
||||
<div class="cbi-map">
|
||||
<h2 name="content"><%=translate("NetData")%></h2>
|
||||
<iframe id="netdata" style="width: 100%; min-height: 1200px; border: none; border-radius: 3px;"></iframe>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
document.getElementById("netdata").src = "//" + window.location.hostname + ":19999";
|
||||
</script>
|
||||
<%+footer%>
|
5
luci-app-netdata/po/zh_Hans/netdata.po
Normal file
5
luci-app-netdata/po/zh_Hans/netdata.po
Normal file
@ -0,0 +1,5 @@
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=UTF-8"
|
||||
|
||||
msgid "NetData"
|
||||
msgstr "实时监控"
|
16
luci-app-netspeedtest/Makefile
Normal file
16
luci-app-netspeedtest/Makefile
Normal file
@ -0,0 +1,16 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_NAME:=luci-app-netspeedtest
|
||||
PKG_VERSION:=1.0
|
||||
|
||||
LUCI_TITLE:=LuCI Net Speedtest
|
||||
LUCI_DEPENDS:=+iperf3 +speedtest-cli +curl +jsonfilter +taskset +bash
|
||||
|
||||
define Package/$(LUCI_NAME)/conffiles
|
||||
/etc/config/netspeedtest
|
||||
/etc/speedtest
|
||||
endef
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
@ -0,0 +1,105 @@
|
||||
'use strict';
|
||||
'require view';
|
||||
'require poll';
|
||||
'require fs';
|
||||
'require rpc';
|
||||
'require uci';
|
||||
'require ui';
|
||||
'require form';
|
||||
|
||||
var conf = 'netspeedtest';
|
||||
var instance = 'iperf3';
|
||||
|
||||
var callServiceList = rpc.declare({
|
||||
object: 'service',
|
||||
method: 'list',
|
||||
params: ['name'],
|
||||
expect: { '': {} }
|
||||
});
|
||||
|
||||
function getServiceStatus() {
|
||||
return L.resolveDefault(callServiceList(conf), {})
|
||||
.then(function (res) {
|
||||
var isrunning = false;
|
||||
try {
|
||||
isrunning = res[conf]['instances'][instance]['running'];
|
||||
} catch (e) { }
|
||||
return isrunning;
|
||||
});
|
||||
}
|
||||
|
||||
return view.extend({
|
||||
// handleSaveApply: null,
|
||||
// handleSave: null,
|
||||
// handleReset: null,
|
||||
|
||||
load: function() {
|
||||
return Promise.all([
|
||||
getServiceStatus(),
|
||||
uci.load('netspeedtest')
|
||||
]);
|
||||
},
|
||||
|
||||
poll_status: function(nodes, stat) {
|
||||
var isRunning = stat[0],
|
||||
view = nodes.querySelector('#service_status');
|
||||
|
||||
if (isRunning) {
|
||||
view.innerHTML = "<span style=\"color:green;font-weight:bold\">" + instance + " - " + _("RUNNING") + "</span>";
|
||||
} else {
|
||||
view.innerHTML = "<span style=\"color:red;font-weight:bold\">" + instance + " - " + _("NOT RUNNING") + "</span>";
|
||||
}
|
||||
return;
|
||||
},
|
||||
|
||||
render: function(res) {
|
||||
var isRunning = res[0];
|
||||
|
||||
var m, s, o;
|
||||
|
||||
m = new form.Map('netspeedtest', _('iPerf3 Bandwidth Performance Test'),
|
||||
_('iPerf3 is a tool for active measurements of the maximum achievable bandwidth on IP networks.'));
|
||||
|
||||
s = m.section(form.NamedSection, '_status');
|
||||
s.anonymous = true;
|
||||
s.render = function (section_id) {
|
||||
return E('div', { class: 'cbi-section' }, [
|
||||
E('div', { id: 'service_status' }, _('Collecting data ...'))
|
||||
]);
|
||||
};
|
||||
|
||||
s = m.section(form.NamedSection, 'config', 'netspeedtest');
|
||||
s.anonymous = true;
|
||||
|
||||
o = s.option(form.Flag, 'iperf3_enabled', _('Enable'));
|
||||
o.default = o.disabled;
|
||||
o.rmempty = false;
|
||||
|
||||
s = m.section(form.TypedSection, '_cmd_ref');
|
||||
s.anonymous = true;
|
||||
s.render = function (section_id) {
|
||||
return E('div', { 'class': 'cbi-section' }, [
|
||||
E('h3', {}, _('iPerf3 Common commands reference')),
|
||||
E('pre', {}, [
|
||||
" -c, --client <host>\n\
|
||||
-u, --udp UDP mode\n\
|
||||
-b, --bandwidth <number>[KMG] target bandwidth in bits/sec (0 for unlimited)\n\
|
||||
-t, --time <number> time in seconds to transmit for (default 10 secs)\n\
|
||||
-i, --interval <number> seconds between periodic bandwidth reports\n\
|
||||
-P, --parallel <number> number of parallel client streams to run\n\
|
||||
-R, --reverse run in reverse mode (server sends, client receives)\n"
|
||||
])
|
||||
]);
|
||||
};
|
||||
|
||||
return m.render()
|
||||
.then(L.bind(function(m, nodes) {
|
||||
poll.add(L.bind(function() {
|
||||
return Promise.all([
|
||||
getServiceStatus()
|
||||
]).then(L.bind(this.poll_status, this, nodes));
|
||||
}, this), 3);
|
||||
return nodes;
|
||||
}, this, m));
|
||||
}
|
||||
});
|
File diff suppressed because one or more lines are too long
59
luci-app-netspeedtest/po/zh_Hans/netspeedtest.po
Normal file
59
luci-app-netspeedtest/po/zh_Hans/netspeedtest.po
Normal file
@ -0,0 +1,59 @@
|
||||
msgid "iPerf3 Server"
|
||||
msgstr "iPerf3 服务器"
|
||||
|
||||
msgid "iPerf3 Bandwidth Performance Test"
|
||||
msgstr "iPerf3 带宽性能测试"
|
||||
|
||||
msgid "iPerf3 Common commands reference"
|
||||
msgstr "iPerf3 常用命令参考"
|
||||
|
||||
msgid "iPerf3 is a tool for active measurements of the maximum achievable bandwidth on IP networks."
|
||||
msgstr "iPerf3 是一种主动测量 IP 网络最大可达带宽的工具。"
|
||||
|
||||
msgid "Collecting data ..."
|
||||
msgstr "正在收集数据..."
|
||||
|
||||
msgid "NOT RUNNING"
|
||||
msgstr "未运行"
|
||||
|
||||
msgid "RUNNING"
|
||||
msgstr "运行中"
|
||||
|
||||
msgid "Enable"
|
||||
msgstr "启用"
|
||||
|
||||
msgid "No result."
|
||||
msgstr "无结果."
|
||||
|
||||
msgid "Ookla SpeedTest"
|
||||
msgstr ""
|
||||
|
||||
msgid "Speedtest by Ookla"
|
||||
msgstr ""
|
||||
|
||||
msgid "Speedtest CLI"
|
||||
msgstr ""
|
||||
|
||||
msgid "Speedtest® CLI"
|
||||
msgstr ""
|
||||
|
||||
msgid "Installed"
|
||||
msgstr "已安装"
|
||||
|
||||
msgid "Not Installed"
|
||||
msgstr "未安装"
|
||||
|
||||
msgid "SpeedTest"
|
||||
msgstr "网速测试"
|
||||
|
||||
msgid "Internet Speedtest"
|
||||
msgstr "互联网测速"
|
||||
|
||||
msgid "Start Test"
|
||||
msgstr "启动测试"
|
||||
|
||||
msgid "Test failed."
|
||||
msgstr "测试失败."
|
||||
|
||||
msgid "Testing in progress..."
|
||||
msgstr "测试进行中..."
|
31
luci-app-netspeedtest/root/etc/init.d/netspeedtest
Executable file
31
luci-app-netspeedtest/root/etc/init.d/netspeedtest
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=99
|
||||
USE_PROCD=1
|
||||
|
||||
get_config() {
|
||||
config_load netspeedtest
|
||||
config_get "iperf3_enabled" "config" "iperf3_enabled" "0"
|
||||
}
|
||||
|
||||
start_service() {
|
||||
get_config
|
||||
[ "$iperf3_enabled" -ne "1" ] && return 1
|
||||
procd_open_instance "iperf3"
|
||||
procd_set_param command /usr/bin/taskset -c 0-1 /usr/bin/iperf3
|
||||
procd_append_param command -s
|
||||
procd_set_param respawn
|
||||
procd_set_param stdout 0
|
||||
procd_set_param stderr 0
|
||||
procd_close_instance "iperf3"
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "netspeedtest"
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
stop
|
||||
sleep 1
|
||||
start
|
||||
}
|
6
luci-app-netspeedtest/root/etc/uci-defaults/99_netspeedtest
Executable file
6
luci-app-netspeedtest/root/etc/uci-defaults/99_netspeedtest
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
touch /etc/config/netspeedtest
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set netspeedtest.config=netspeedtest
|
||||
commit netspeedtest
|
||||
EOF
|
40
luci-app-netspeedtest/root/usr/lib/netspeedtest/speedtest
Executable file
40
luci-app-netspeedtest/root/usr/lib/netspeedtest/speedtest
Executable file
@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
mkdir -p /etc/speedtest
|
||||
|
||||
export HOME='/etc/speedtest'
|
||||
SPEEDTEST_CLI='/usr/bin/speedtest'
|
||||
SPEEDTEST_RESULT='/etc/speedtest/speedtest_result'
|
||||
|
||||
[ -n "$(pgrep -f "$SPEEDTEST_CLI")" ] && exit 1
|
||||
|
||||
LOCAL_IP=$(curl -s -4 --connect-timeout 3 http://ip.3322.net)
|
||||
|
||||
BAIDU_SK="LHHGlmhcb4ENvIXpR9QQ2tBYa6ooUowX hYCENCEx1nXO0Nt46ldexfG9oI49xBGh 0kKZnWWhXEPfzIkklmzAa3dZ"
|
||||
if [ -n "$LOCAL_IP" ]; then
|
||||
for SK in $BAIDU_SK
|
||||
do
|
||||
INFO=$(curl -sk --connect-timeout 3 "https://api.map.baidu.com/location/ip?ip="$LOCAL_IP"&coor=bd09ll&ak=$SK")
|
||||
if [ "$(echo $INFO | jsonfilter -e "@['status']")" = 0 ]; then
|
||||
status=0
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ "$status" = 0 ]; then
|
||||
lon=$(echo $INFO | jsonfilter -e "@['content']['point']['x']")
|
||||
lat=$(echo $INFO | jsonfilter -e "@['content']['point']['y']")
|
||||
server_id=$(curl -sk --connect-timeout 3 "https://www.speedtest.net/api/ios-config.php?lon=$lon&lat=$lat" | grep "server url" | head -n1 | sed 's/.*id="//;s/".*//')
|
||||
[ -n "$server_id" ] && ARG="-s $server_id"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Testing" > "$SPEEDTEST_RESULT"
|
||||
|
||||
RUNTEST=$($SPEEDTEST_CLI --accept-gdpr --accept-license --progress=no $ARG 2>&1)
|
||||
if [ $(echo $RUNTEST | grep -c "No servers defined") -ge 1 ] || [ $(echo $RUNTEST | grep -c "error") -ge 1 ]; then
|
||||
RUNTEST=$($SPEEDTEST_CLI --accept-gdpr --accept-license --progress=no 2>&1)
|
||||
fi
|
||||
|
||||
RESULT=$(echo "$RUNTEST" | grep "Result URL" | awk '{print $NF}')
|
||||
|
||||
[ -n "$RESULT" ] && echo "$RESULT" > "$SPEEDTEST_RESULT" || echo "Test failed" > "$SPEEDTEST_RESULT"
|
@ -0,0 +1,29 @@
|
||||
{
|
||||
"admin/network/netspeedtest": {
|
||||
"title": "SpeedTest",
|
||||
"order": 55,
|
||||
"action": {
|
||||
"type": "firstchild"
|
||||
},
|
||||
"depends": {
|
||||
"acl": [ "luci-app-netspeedtest" ],
|
||||
"uci": { "netspeedtest": true }
|
||||
}
|
||||
},
|
||||
"admin/network/netspeedtest/iperf3": {
|
||||
"title": "iPerf3 Server",
|
||||
"order": 1,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "netspeedtest/iperf3"
|
||||
}
|
||||
},
|
||||
"admin/network/netspeedtest/speedtest": {
|
||||
"title": "Internet Speedtest",
|
||||
"order": 2,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "netspeedtest/speedtest"
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user