diff --git a/package/lean/fogvdn/Makefile b/package/lean/fogvdn/Makefile new file mode 100644 index 000000000..3c4d29e4b --- /dev/null +++ b/package/lean/fogvdn/Makefile @@ -0,0 +1,53 @@ +include $(TOPDIR)/rules.mk +include $(INCLUDE_DIR)/target.mk + +PKG_NAME:=fogvdn +PKG_VERSION:=1 +PKG_RELEASE:=1 +PKG_HASH:=skip + +ifeq ($(ARCH),x86_64) + PKG_ARCH:=X64 +else ifeq ($(ARCH),arm) + PKG_ARCH:=ARM +else ifeq ($(ARCH),aarch64) + PKG_ARCH:=ARM64 +endif + +PKG_SOURCE:=fogvdn_PEAR_$(PKG_ARCH)_LINUX_latest.tar.gz +PKG_SOURCE_URL:=https://download.openfogos.com/release/ + +include $(INCLUDE_DIR)/package.mk + +PKG_UNPACK:=$(HOST_TAR) -C $(PKG_BUILD_DIR)/root --strip-components=1 -xzf $(DL_DIR)/$(PKG_SOURCE) + +define Package/fogvdn + SECTION:=net + CATEGORY:=Network + TITLE:=OpenFog Pear P2P CDN + DEPENDS:=@(aarch64||arm||x86_64) \ + +bash +getopt +jq +ntpdate +whereis \ + +smartmontools +zoneinfo-all +coreutils \ + +coreutils-install +coreutils-df +coreutils-nohup +endef + +define Package/fogvdn/description +OpenFog Pear Peer-to-Peer Content Delivery Network +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR)/root + $(PKG_UNPACK) +endef + +define Build/Configure +endef + +define Build/Compile +endef + +define Package/fogvdn/install + $(CP) $(PKG_BUILD_DIR)/root/* $(1)/ +endef + +$(eval $(call BuildPackage,fogvdn)) diff --git a/package/lean/luci-app-fogvdn/Makefile b/package/lean/luci-app-fogvdn/Makefile new file mode 100644 index 000000000..f2c02036c --- /dev/null +++ b/package/lean/luci-app-fogvdn/Makefile @@ -0,0 +1,17 @@ +# +# Copyright (C) 2008-2014 The LuCI Team +# +# This is free software, licensed under the Apache License, Version 2.0 . +# +include $(TOPDIR)/rules.mk +include $(INCLUDE_DIR)/package.mk + +LLUCI_TITLE:=Luci for OpenFog Pear P2P CDN +LUCI_PKGARCH:=all +PKG_VERSION:=7 +PKG_RELEASE:=1 +LUCI_DEPENDS:=+luci-compat +fogvdn +jq +lsblk + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/package/lean/luci-app-fogvdn/luasrc/controller/pearpcdn.lua b/package/lean/luci-app-fogvdn/luasrc/controller/pearpcdn.lua new file mode 100644 index 000000000..6193558ea --- /dev/null +++ b/package/lean/luci-app-fogvdn/luasrc/controller/pearpcdn.lua @@ -0,0 +1,30 @@ +module("luci.controller.pearpcdn", package.seeall) +fs = require "nixio.fs" +I18N = require "luci.i18n" +translate = I18N.translate +json = require "luci.jsonc" +function index() + entry({"admin", "pcdn"}, firstchild(), _("PCDN"), 28).dependent = true + entry({"admin", "pcdn","pear_pcdn"}, cbi("pearpcdn/fogvdn"),_("FOGVDN"),1).dependent = true + entry({"admin", "pcdn","pear_pcdn", "get_act_status"}, call("get_act_status"),nil).leaf = true +end + +function get_act_status() + data = {} + data["status"] = "0" + + --pid file + pid_file="/run/pear_restart.pid" + --if not exist, return 0 + if fs.access(pid_file) then + --if dir /proc/pid exist, return 1 + --trim \n + pid = fs.readfile(pid_file) + pid = string.gsub(pid, "\n", "") + if fs.access("/proc/"..pid) then + data["status"] = "1" + end + end + luci.http.prepare_content("application/json") + luci.http.write_json(data) +end diff --git a/package/lean/luci-app-fogvdn/luasrc/model/cbi/pearpcdn/fogvdn.lua b/package/lean/luci-app-fogvdn/luasrc/model/cbi/pearpcdn/fogvdn.lua new file mode 100644 index 000000000..466478187 --- /dev/null +++ b/package/lean/luci-app-fogvdn/luasrc/model/cbi/pearpcdn/fogvdn.lua @@ -0,0 +1,208 @@ +uci = require "luci.model.uci".cursor() +local fs = require "nixio.fs" +local json = require "luci.jsonc" +m = Map("fogvdn", translate("FOGVDN Node")) +s = m:section(NamedSection, "main", "main", translate("Main")) + +act_status = s:option(DummyValue, "act_status", translate("Status")) +act_status.template = "pcdn/act_status" + +enabled = s:option(Flag, "enable", translate("Enable")) +enabled.default = 0 + +node_info_file = "/etc/pear/pear_monitor/node_info.json" +if fs.access(node_info_file) then + local node_info = fs.readfile(node_info_file) + node_info = json.parse(node_info) + for k,v in pairs(node_info) do + +node_info_file = "/etc/pear/pear_monitor/node_info.json" +if fs.access(node_info_file) then + local node_info = fs.readfile(node_info_file) + node_info = json.parse(node_info) + for k,v in pairs(node_info) do + if k == "node_id" then + option = s:option(DummyValue, "_"..k,translate(k)) + option.value = v + end + end +end + +storage_info_file = "/etc/pear/pear_monitor/storage_info.json" +if fs.access(storage_info_file) then + local storage_info = fs.readfile(storage_info_file) + storage_info = json.parse(storage_info) + for k,v in pairs(storage_info) do + if k == "os_drive_serial" then + option = s:option(DummyValue, "_"..k,translate(k)) + option.value = v + end + end +end + option = s:option(DummyValue, "_"..k,translate(k)) + option.value = v + end + end +end + +openfog_link=s:option(DummyValue, "openfog_link", translate("")) +openfog_link.description = translate("OpenFogOS Official Website") + +s = m:section(TypedSection, "instance", translate("Settings")) +s.anonymous = true +s.description = translate("Fogvdn Settings") + +username = s:option(Value, "username", translate("username")) +username.description = translate("") + +region = s:option(Value, "region", translate("Region")) +region.optional = true +region.template="cbi/city" + +isp = s:option(Value, "isp", translate("ISP")) +isp.optional = true +isp:value("电信", translate("China Telecom")) +isp:value("移动", translate("China Mobile")) +isp:value("联通", translate("China Unicom")) + +per_line_up_bw = s:option(Value, "per_line_up_bw", translate("Per Line Up BW")) +per_line_up_bw.template = "cbi/digitonlyvalue" +per_line_up_bw.datatype = "uinteger" + +per_line_down_bw = s:option(Value, "per_line_down_bw", translate("Per Line Down BW")) +per_line_down_bw.template = "cbi/digitonlyvalue" +per_line_down_bw.datatype = "uinteger" + +limited_memory = s:option(Value, "limited_memory", translate("Limited Memory")) +limited_memory.optional = true +limited_memory.template = "cbi/digitonlyvalue" +limited_memory.datatype = "range(0, 100)" +-- 0-100% +limited_storage = s:option(Value, "limited_storage", translate("Limited Storage")) +limited_storage.optional = true +limited_storage.template = "cbi/digitonlyvalue" +limited_storage.datatype = "range(0, 100)" +-- 0-100% + +limited_area = s:option(Value, "limited_area", translate("Limited Area")) +limited_area.default = "2" +limited_area:value("-1", "不设置:若不确定运营商对流量出省的限制情况,建议选择该项") +limited_area:value("0", "全国调度:流量将会向全国调度,出省比例较高,可能会导致运营商的限制") +limited_area:value("1", "本省调度:流量只会向所在省份内调度,是比较安全的调度模式,但跑量可能会降低") +limited_area:value("2", "大区调度:流量只会向所在大区内调度,出省比例较低,是安全性和跑量之间较为均衡的模式") +-- 限制地区 -1 不设置(采用openfogos默认) 0 全国调度,1 省份调度,2 大区调度 + +nics = s:option(DynamicList,"nics",translate("netdev")) +-- uci:foreach("multiwan","multiwan",function (instance) +-- nics:value(instance["tag"]) +-- end +-- ) +--list /sys/class/net, filter bridge device +cmd="/usr/share/pcdn/check_netdev get_netdevs" +json_dump=luci.sys.exec(cmd) +devs=json.parse(json_dump) +for k,v in pairs(devs) do + nics:value(k,k.." ["..v.."]") +end + +storage = s:option(DynamicList, "storage", translate("Storage")) +storage.default = "/opt/openfogos" +storage.description = translate("Warnning: System directory is not allowed!") +--filter start with /etc /usr /root /var /tmp /dev /proc /sys /overlay /rom and root +mount_point = {} +cmd="/usr/share/pcdn/check_mount_ponit mount_point" +json_dump=luci.sys.exec(cmd) +mount_point=json.parse(json_dump) +for k,v in pairs(mount_point) do + storage:value(k,k.."("..v..")") +end + +btn = s:option(Button, "_filter", "") +btn.inputtitle = "应用最佳存储设置" +btn.description = "为避免木桶效应,点击估算最佳设置" +btn.inputstyle = "apply" + +-- 获取表中元素的索引 +table.indexOf = function(tbl, value) + for i, v in ipairs(tbl) do + if v == value then return i end + end + return -1 +end + +-- 拷贝表 +table.copy = function(tbl) + local copy = {} + for k, v in pairs(tbl) do + copy[k] = v + end + return copy +end + +-- 解析并转换大小单位 +function parseSize(size) + if type(size) ~= "string" then return 0 end + + local unit = {"B", "K", "M", "G", "T"} + + local num, u = string.match(size, "^(%d+%.?%d*)([KMGT]?)$") + if not num then return 0 end + + local i = table.indexOf(unit, u) + + -- 如果没有找到单位,默认为字节 + if i == -1 then + return tonumber(num) + else + return tonumber(num) * (1024 ^ i) + end +end + +-- 获取最佳存储方案 +function getOptimalSolution(numsObjArray) + if type(numsObjArray) ~= "table" or #numsObjArray == 0 then return {} end + + -- 拷贝并按大小排序 + local nums = {} + for _, v in ipairs(numsObjArray) do + table.insert(nums, {name = v.name, size = v.size}) + end + table.sort(nums, function(a, b) + return parseSize(a.size) < parseSize(b.size) + end) + + local max = 0 + local optimal = {} + + while #nums > 0 do + local temp = parseSize(nums[1].size) * #nums + if temp > max then + max = temp + optimal = table.copy(nums) + end + table.remove(nums, 1) -- 移除第一个元素 + end + + -- 提取名称并排序 + local result = {} + for _, v in ipairs(optimal) do + table.insert(result, v.name) + end + table.sort(result) + + return result +end + +function btn.write(self, section) + local numsObjArray = {} + + for k,v in pairs(mount_point) do + table.insert(numsObjArray, {name = k, size = v}) + end + + local optimalStorage = getOptimalSolution(numsObjArray) + + self.map:set(section, "storage", optimalStorage) +end + +return m diff --git a/package/lean/luci-app-fogvdn/luasrc/view/cbi/city.htm b/package/lean/luci-app-fogvdn/luasrc/view/cbi/city.htm new file mode 100644 index 000000000..d305016bb --- /dev/null +++ b/package/lean/luci-app-fogvdn/luasrc/view/cbi/city.htm @@ -0,0 +1,5738 @@ +<%+cbi/valueheader%> + + +/> + +<%+cbi/valuefooter%> diff --git a/package/lean/luci-app-fogvdn/luasrc/view/cbi/digitonlyvalue.htm b/package/lean/luci-app-fogvdn/luasrc/view/cbi/digitonlyvalue.htm new file mode 100644 index 000000000..977fd51dc --- /dev/null +++ b/package/lean/luci-app-fogvdn/luasrc/view/cbi/digitonlyvalue.htm @@ -0,0 +1,23 @@ +<%+cbi/valueheader%> + 0, "data-choices", { self.keylist, self.vallist }) + %> /> + <% if self.password then %><% end %> + +<%+cbi/valuefooter%> diff --git a/package/lean/luci-app-fogvdn/luasrc/view/cbi/network_wanlist.htm b/package/lean/luci-app-fogvdn/luasrc/view/cbi/network_wanlist.htm new file mode 100644 index 000000000..33f0000b0 --- /dev/null +++ b/package/lean/luci-app-fogvdn/luasrc/view/cbi/network_wanlist.htm @@ -0,0 +1,87 @@ +<%+cbi/valueheader%> + +<%- + local utl = require "luci.util" + local nwm = require "luci.model.network".init() + local uci = require "luci.model.uci".cursor() + local net, iface + local networks = nwm:get_networks() + local value = self:formvalue(section) + + self.cast = nil + + if not value or value == "-" then + value = self:cfgvalue(section) or self.default + end + + local checked = { } + for value in utl.imatch(value) do + checked[value] = true + end + +-%> + + + +<%+cbi/valuefooter%> diff --git a/package/lean/luci-app-fogvdn/luasrc/view/pcdn/act_status.htm b/package/lean/luci-app-fogvdn/luasrc/view/pcdn/act_status.htm new file mode 100644 index 000000000..a32ffe49a --- /dev/null +++ b/package/lean/luci-app-fogvdn/luasrc/view/pcdn/act_status.htm @@ -0,0 +1,27 @@ +<%+cbi/valueheader%> + +<%:Please Wait%> + + +<%+cbi/valuefooter%> diff --git a/package/lean/luci-app-fogvdn/po/zh-Hans/fogvdn.po b/package/lean/luci-app-fogvdn/po/zh-Hans/fogvdn.po new file mode 100644 index 000000000..2c2aaf609 --- /dev/null +++ b/package/lean/luci-app-fogvdn/po/zh-Hans/fogvdn.po @@ -0,0 +1,77 @@ +msgid "FOGVDN" +msgstr "OpenFog" + +msgid "FOGVDN Node" +msgstr "OpenFog 节点" + +msgid "OpenFogOS" +msgstr "OpenFogOS" + +msgid "Main" +msgstr "主设置" + +msgid "Fogvdn Settings" +msgstr "OpenFog 设置" + +msgid "username" +msgstr "用户名" + +msgid "Region" +msgstr "地区" + +msgid "ISP" +msgstr "运营商" + +msgid "Per Line Up BW" +msgstr "每条线路上行带宽(Mbps)" + +msgid "Per Line Down BW" +msgstr "每条线路下行带宽(Mbps)" + +msgid "Limited Memory" +msgstr "内存限制(%)" + +msgid "Limited Storage" +msgstr "存储限制(%)" + +msgid "Limited Area" +msgstr "地区限制" + +msgid "netdev" +msgstr "网络设备" + +msgid "Storage" +msgstr "存储" + +msgid "Warnning: System directory is not allowed! " +msgstr "警告: 系统目录不允许使用! " + +msgid "Please Wait" +msgstr "请稍等" + +msgid "Running" +msgstr "运行中" + +msgid "Not Running" +msgstr "未运行" + +msgid "" +msgstr "" + +msgid "" +msgstr "" + +msgid "China Telecom" +msgstr "中国电信" + +msgid "China Unicom" +msgstr "中国联通" + +msgid "China Mobile" +msgstr "中国移动" + +msgid "OpenFogOS Official Website" +msgstr "OpenFogOS 官网" + +msgid "Warnning: System directory is not allowed!" +msgstr "警告: 请勿使用系统目录! " diff --git a/package/lean/luci-app-fogvdn/po/zh-cn/fogvdn.po b/package/lean/luci-app-fogvdn/po/zh-cn/fogvdn.po new file mode 100644 index 000000000..2c2aaf609 --- /dev/null +++ b/package/lean/luci-app-fogvdn/po/zh-cn/fogvdn.po @@ -0,0 +1,77 @@ +msgid "FOGVDN" +msgstr "OpenFog" + +msgid "FOGVDN Node" +msgstr "OpenFog 节点" + +msgid "OpenFogOS" +msgstr "OpenFogOS" + +msgid "Main" +msgstr "主设置" + +msgid "Fogvdn Settings" +msgstr "OpenFog 设置" + +msgid "username" +msgstr "用户名" + +msgid "Region" +msgstr "地区" + +msgid "ISP" +msgstr "运营商" + +msgid "Per Line Up BW" +msgstr "每条线路上行带宽(Mbps)" + +msgid "Per Line Down BW" +msgstr "每条线路下行带宽(Mbps)" + +msgid "Limited Memory" +msgstr "内存限制(%)" + +msgid "Limited Storage" +msgstr "存储限制(%)" + +msgid "Limited Area" +msgstr "地区限制" + +msgid "netdev" +msgstr "网络设备" + +msgid "Storage" +msgstr "存储" + +msgid "Warnning: System directory is not allowed! " +msgstr "警告: 系统目录不允许使用! " + +msgid "Please Wait" +msgstr "请稍等" + +msgid "Running" +msgstr "运行中" + +msgid "Not Running" +msgstr "未运行" + +msgid "" +msgstr "" + +msgid "" +msgstr "" + +msgid "China Telecom" +msgstr "中国电信" + +msgid "China Unicom" +msgstr "中国联通" + +msgid "China Mobile" +msgstr "中国移动" + +msgid "OpenFogOS Official Website" +msgstr "OpenFogOS 官网" + +msgid "Warnning: System directory is not allowed!" +msgstr "警告: 请勿使用系统目录! " diff --git a/package/lean/luci-app-fogvdn/root/etc/config/fogvdn b/package/lean/luci-app-fogvdn/root/etc/config/fogvdn new file mode 100644 index 000000000..cb180bf82 --- /dev/null +++ b/package/lean/luci-app-fogvdn/root/etc/config/fogvdn @@ -0,0 +1,5 @@ +config main 'main' + option enable '0' + +config instance + list storage '/opt/openfogos' diff --git a/package/lean/luci-app-fogvdn/root/etc/init.d/fogvdn b/package/lean/luci-app-fogvdn/root/etc/init.d/fogvdn new file mode 100755 index 000000000..79688250c --- /dev/null +++ b/package/lean/luci-app-fogvdn/root/etc/init.d/fogvdn @@ -0,0 +1,136 @@ +#!/bin/sh /etc/rc.common + +USE_PROCD=1 +START=99 +STOP=1 + +CONFIG_PATH=/etc/pear/pear_monitor +target_config_path=${CONFIG_PATH}/config.json + + +function run_instance() +{ + if [ -f $target_config_path ];then + user_marked=$(cat $target_config_path |jq .user_marked) + if [ -n "$user_marked" ] && [ "$user_marked" != "null" ];then + json="$(cat $target_config_path)" + else + json="{}" + fi + else + json="{}" + fi + + config_get username $1 username + config_get isp $1 isp + config_get region $1 region + config_get per_line_up_bw $1 per_line_up_bw null + config_get per_line_down_bw $1 per_line_down_bw null + config_get limited_memory $1 limited_memory null + config_get limited_storage $1 limited_storage null + config_get limited_area $1 limited_area null + country="中国" + province=$(echo $region | awk -F'-' '{print $1}') + city=$(echo $region | awk -F'-' '{print $2}') + mtime=$(date +%s) + json=$(echo "$json" | jq --arg username "$username" \ + --arg isp "$isp" \ + --arg country "$country" \ + --arg province "$province" \ + --arg city "$city" \ + --argjson per_line_up_bw "$per_line_up_bw" \ + --argjson per_line_down_bw "$per_line_down_bw" \ + --argjson limited_memory "$limited_memory" \ + --argjson limited_storage "$limited_storage" \ + --argjson limited_area "$limited_area" \ + --argjson mtime "$mtime" \ + '.user_marked.username = $username | + .user_marked.isp = $isp | + .user_marked.country = $country | + .user_marked.province = $province | + .user_marked.city = $city | + .user_marked.per_line_up_bw = $per_line_up_bw | + .user_marked.per_line_down_bw = $per_line_down_bw | + .user_marked.limited_memory = $limited_memory | + .user_marked.limited_storage = $limited_storage | + .user_marked.limited_area = $limited_area | + .user_marked.mtime = $mtime | + del(.user_marked[] | select(. == null))' + ) + json=$(echo "$json" | jq '.storage = []') + json=$(echo "$json" | jq '.nics = []') + config_list_foreach $1 storage storage_hd + config_list_foreach $1 nics nics_hd + # Save modified JSON back to target_config_path + echo "$json" > $target_config_path + instance=$1 + /etc/init.d/openfog.sh stop + procd_open_instance ${instance}_check_alive + procd_set_param command "/usr/share/pcdn/check_alive.sh" + procd_set_param respawn + procd_close_instance +} + +function storage_hd() +{ + json=$(echo "$json" | jq --arg item "$1" '.storage += [$item]') + [ ! -d "$1" ] && mkdir -p $1 +} + +function nics_hd() +{ +# config=$1 +# # check if vw$config exists +# config_1=$(uci get network.vw$config) +# # check if $config exists +# config_2=$(uci get network.$config) +# if [ -z "$config_1" ] && [ -z "$config_2" ];then +# res=$(echo $json | jq '.nics | index(["'${config}'"])') +# [ "$res" == "null" ] && json=$(echo "$json" | jq --arg item "$config" '.nics += [$item]') +# return +# fi +# if [ "$config_1" != "interface" ];then +# config=$config +# else +# config=vw$config +# fi +# l2_device=$(uci get network.$config.ifname) +# proto=$(uci get network.$config.proto) +# if [ "$proto" == "pppoe" ];then +# nic_name=pppoe-$config +# else +# nic_name=$l2_device +# fi + nic_name=$1 + res=$(echo $json | jq '.nics | index(["'${nic_name}'"])') + [ "$res" == "null" ] && json=$(echo "$json" | jq --arg item "$nic_name" '.nics += [$item]') +} + +function stop_instance() +{ + instance=$1 + service_stop ${instance}_check_alive +} + +start_service() +{ + config_load fogvdn + config_get enable main enable + [ "$enable" == "1" ] && config_foreach run_instance instance || stop +} + +stop_service() +{ + config_foreach stop_instance instance + /etc/init.d/openfog.sh stop +} + +service_triggers() { + procd_add_reload_trigger "fogvdn" +} + +reload_servie() +{ + stop + start +} diff --git a/package/lean/luci-app-fogvdn/root/etc/uci-defaults/30-run_post_update_cmd b/package/lean/luci-app-fogvdn/root/etc/uci-defaults/30-run_post_update_cmd new file mode 100755 index 000000000..aea5fe2b1 --- /dev/null +++ b/package/lean/luci-app-fogvdn/root/etc/uci-defaults/30-run_post_update_cmd @@ -0,0 +1,3 @@ +#!/bin/sh +mkdir /run +/etc/pear/pear_update/post_command.sh diff --git a/package/lean/luci-app-fogvdn/root/etc/uci-defaults/luci-fogvdn b/package/lean/luci-app-fogvdn/root/etc/uci-defaults/luci-fogvdn new file mode 100644 index 000000000..69aeb8b64 --- /dev/null +++ b/package/lean/luci-app-fogvdn/root/etc/uci-defaults/luci-fogvdn @@ -0,0 +1,7 @@ +#!/bin/sh +rm -f /tmp/luci-indexcache +#uci track +cfg_id=$(uci add ucitrack fogvdn) +uci set ucitrack.$cfg_id.init="fogvdn" +uci commit ucitrack +exit 0 diff --git a/package/lean/luci-app-fogvdn/root/usr/share/pcdn/check_alive.sh b/package/lean/luci-app-fogvdn/root/usr/share/pcdn/check_alive.sh new file mode 100755 index 000000000..3dad4005c --- /dev/null +++ b/package/lean/luci-app-fogvdn/root/usr/share/pcdn/check_alive.sh @@ -0,0 +1,17 @@ +#!/bin/sh +pid_file="/run/pear_restart.pid" +while true; do + if [ -f $pid_file ]; then + pid=$(cat $pid_file) + if [ -n "$pid" ]; then + if [ ! -d /proc/$pid ]; then + logger -t "fogvdn" "fogvdn is not running, restart it" + /etc/init.d/openfog.sh start + fi + fi + else + logger -t "fogvdn" "pid file not found, restart it" + /etc/init.d/openfog.sh start + fi + sleep 10 +done diff --git a/package/lean/luci-app-fogvdn/root/usr/share/pcdn/check_mount_ponit b/package/lean/luci-app-fogvdn/root/usr/share/pcdn/check_mount_ponit new file mode 100755 index 000000000..c505a52f6 --- /dev/null +++ b/package/lean/luci-app-fogvdn/root/usr/share/pcdn/check_mount_ponit @@ -0,0 +1,57 @@ +#!/bin/sh +# 脚本功能:json方式返回 大于某个容量的磁盘挂载点及其大小 +. /usr/share/libubox/jshn.sh + +get_disk_info() { + disk_info=$(lsblk |grep disk) + IFS=$'\n' + for disk in `echo -e "$disk_info"`; do + disk_name=$(echo $disk |awk '{print $1}') + disk_capacity=$(echo $disk |awk '{print $4}') + json_add_string "$disk_name" "$disk_capacity" + done +} + +get_part_info() { + part_info=$(lsblk |grep part) + IFS=$'\n' + for part in `echo -e "$part_info"`; do + part_name=$(echo $part |awk '{print $1}') + part_capacity=$(echo $part |awk '{print $4}') + json_add_string "$part_name" "$part_capacity" + done +} + +get_mount_point_info() { + mount_point_info=$(lsblk -o SIZE,MOUNTPOINT |grep -v MOUNTPOINT) + #filter /rom /overlay [SWAP] + mount_point_info=$(echo -e "$mount_point_info" |grep -v -E "/rom|/overlay|\[SWAP\]") + #filter capacity that unit is M or K + mount_point_info=$(echo -e "$mount_point_info" |grep -v -E "M|K") + + IFS=$'\n' + #filter start with /mnt + for mount_point in `echo -e "$mount_point_info"`; do + mount_point_name=$(echo $mount_point |awk '{print $2}') + mount_point_capacity=$(echo $mount_point |awk '{print $1}') + if [ -z "$mount_point_capacity" ] || [ -z "$mount_point_name" ]; then + continue + fi + + json_add_string "$mount_point_name/openfogos" "$mount_point_capacity" + done +} + +json_init +case $1 in + disk) + get_disk_info + ;; + part) + get_part_info + ;; + mount_point) + get_mount_point_info + ;; +esac +json_dump diff --git a/package/lean/luci-app-fogvdn/root/usr/share/pcdn/check_netdev b/package/lean/luci-app-fogvdn/root/usr/share/pcdn/check_netdev new file mode 100755 index 000000000..1d37d66e5 --- /dev/null +++ b/package/lean/luci-app-fogvdn/root/usr/share/pcdn/check_netdev @@ -0,0 +1,37 @@ +#!/bin/sh +# 脚本功能:json方式返回 网络物理设备 +. /usr/share/libubox/jshn.sh + +function get_netdevs() +{ + # 过滤条件:无ip, bridge, wlan, lo 设备 + for netdev in `ls /sys/class/net`;do + if [ -d "/sys/class/net/$netdev" ] && [ -n "$netdev" ];then + filter=0 + unset DEVTYPE + . /sys/class/net/$netdev/uevent + cdir4=`ip addr show dev $netdev|grep "inet " | grep -E -o '([0-9]{1,3}\.){3}[0-9]{1,3}/[0-9]{1,2}' | sed ':a;N;$!ba;s/\n/;/g'` + + [ -z "$cdir4" ] && filter=1 + [ "$DEVTYPE" == "bridge" ] && filter=1 + [ "$DEVTYPE" == "wlan" ] && filter=1 + [ "$netdev" == "lo" ] && filter=1 + if [ "$filter" -eq 0 ];then + macaddr=`cat /sys/class/net/$netdev/address` + #format $netdev (ip:cdir4 mac:address) + netdev_info="IP: $cdir4;" + [ -n "$macaddr" ] && netdev_info="$netdev_info MAC:$macaddr" + [ -n "$DEVTYPE" ] && netdev_info="$netdev_info TYPE:$DEVTYPE" + json_add_string $netdev "$netdev_info" + fi + fi + done +} + +json_init +case $1 in + get_netdevs) + get_netdevs + ;; +esac +json_dump diff --git a/package/lean/luci-app-fogvdn/root/usr/share/rpcd/acl.d/luci-app-fogvdn.json b/package/lean/luci-app-fogvdn/root/usr/share/rpcd/acl.d/luci-app-fogvdn.json new file mode 100644 index 000000000..a914458af --- /dev/null +++ b/package/lean/luci-app-fogvdn/root/usr/share/rpcd/acl.d/luci-app-fogvdn.json @@ -0,0 +1,17 @@ +{ + "luci-app-fogvdn": { + "description": "Grant UCI access for luci-app-fogvdn", + "read": { + "file": { + "/etc/pear/pear_monitor/*": [ "read" ] + }, + "uci": ["fogvdn"] + }, + "write": { + "file": { + "/etc/pear/pear_monitor/*": [ "write" ] + }, + "uci": ["fogvdn"] + } + } +}