Skip to content

Commit

Permalink
CI: sync code
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Dec 18, 2024
1 parent bfcb768 commit 5b8acb1
Show file tree
Hide file tree
Showing 18 changed files with 654 additions and 0 deletions.
18 changes: 18 additions & 0 deletions luci/luci-app-nfs/Makefile
Original file line number Diff line number Diff line change
@@ -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 nfs
LUCI_DEPENDS:=+nfs-utils +nfs-kernel-server +nfs-kernel-server-utils +mount-utils
LUCI_PKGARCH:=all

PKG_NAME:=luci-app-nfs
PKG_VERSION:=1.1
PKG_RELEASE:=1

include $(TOPDIR)/feeds/luci/luci.mk

# call BuildPackage - OpenWrt buildroot signature
10 changes: 10 additions & 0 deletions luci/luci-app-nfs/luasrc/controller/nfs.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module("luci.controller.nfs", package.seeall)

function index()
if not nixio.fs.access("/etc/config/nfs") then
return
end

entry({"admin", "nas"}, firstchild(), "NAS", 44).dependent = false
entry({"admin", "nas", "nfs"}, cbi("nfs"), _("NFS Manage"), 5).dependent = true
end
70 changes: 70 additions & 0 deletions luci/luci-app-nfs/luasrc/model/cbi/nfs.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
local fs = require "nixio.fs"

m = Map("nfs", translate("NFS Manage"))

-- NFS Share --
s = m:section(TypedSection, "share", translate("Shared Directories"))
s.anonymous = true
s.addremove = true
s.template = "cbi/tblsection"

en = s:option(Flag, "enabled", translate("Enable"))
en.rmempty = false
en.default = "1"

ph1 = s:option(Value, "path", translate("Path"))
ph1.placeholder = "/mnt"
ph1.rmempty = false
ph1.optional = false

ct = s:option(Value, "clients", translate("Clients"))
ct.placeholder = "192.168.1.0/24"
ct.rmempty = false
ct.optional = false

op = s:option(Value, "options", translate("options"))
op.placeholder = "rw,sync,root_squash,all_squash,insecure,no_subtree_check"
op.rmempty = false
op.optional = false

-- NFS Mount --
c = m:section(TypedSection, "mount", translate("Mounted Points"))
c.anonymous = true
c.addremove = true
c.template = "cbi/tblsection"

en = c:option(Flag, "enabled", translate("Enable"))
en.default = "1"
en.rmempty = false

sr = c:option(Value, "source", translate("source"))
sr.placeholder = "192.168.1.1:/mnt/*"
sr.rmempty = false
sr.optional = false

ph2 = c:option(Value, "target", translate("target"))
ph2.placeholder = "/mnt/nfs/*"
ph2.rmempty = false
ph2.optional = false

op = c:option(Value, "options", translate("options"))
op.placeholder = "rw,nolock"
op.rmempty = false
op.optional = false

de = c:option(Value, "delay", translate("delay"))
de.placeholder = "5"
de.rmempty = false
de.optional = false

if nixio.fs.access("/etc/config/fstab") then
ph1.titleref = luci.dispatcher.build_url("admin", "system", "fstab")
ph2.titleref = luci.dispatcher.build_url("admin", "system", "fstab")
end

local apply = luci.http.formvalue("cbi.apply")
if apply then
io.popen("/etc/init.d/nfs reload")
end

return m
32 changes: 32 additions & 0 deletions luci/luci-app-nfs/po/zh_Hans/nfs.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
msgid ""
msgstr ""

msgid "NFS Manage"
msgstr "NFS 管理"

msgid "Shared Directories"
msgstr "共享目录"

msgid "Enable"
msgstr "启用"

msgid "Path"
msgstr "路径"

msgid "Clients"
msgstr "允许的客户端"

msgid "Mounted Points"
msgstr "已挂载的目录"

msgid "source"
msgstr "源目录"

msgid "target"
msgstr "挂载到"

msgid "options"
msgstr "选项"

msgid "delay"
msgstr "延迟时间"
6 changes: 6 additions & 0 deletions luci/luci-app-nfs/root/etc/config/nfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

config share
option enabled '0'
option path '/mnt'
option clients '*'
option options 'rw,sync,root_squash,all_squash,insecure,no_subtree_check'
75 changes: 75 additions & 0 deletions luci/luci-app-nfs/root/etc/init.d/nfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/sh /etc/rc.common
START=45
STOP=99
NAME="nfs"

nfs_share() {

local enabled path clients options
config_get_bool enabled "$1" enabled 0
for opt in path clients options
do
config_get "$opt" "$1" "$opt"
done

if [ "$enabled" = 1 ]; then
grep -qs $path /etc/exports
if [ $? -ne 0 ]; then
echo -e "$path\t$clients($options)" >>/etc/exports
exportfs -r
fi
elif [ "$enabled" = 0 ]; then
exportfs -u | grep -qs $path
if [ $? -eq 0 ]; then
exportfs -u $clients:$path
fi
fi
exportfs -r
}

nfs_share_stop() {
exportfs -au &>/dev/null
}

nfs_mount() {

local enabled target source options delay
config_get_bool enabled "$1" enabled 0
for opt in target source options delay
do
config_get "$opt" "$1" "$opt"
done

if [ "$enabled" = 1 ]; then
if [ "$delay" -a $delay -gt 0 ]; then
logger "NetMount: Sleep $delay seconds before mount"
sleep $delay
fi
grep -qs $target /proc/mounts
if [ $? -ne 0 ]; then
mkdir -p $target
logger "NetMount: Mounting $source in $target"
mount -t nfs -o $options $source $target
fi
elif [ "$enabled" = 0 ]; then
if grep -qs $target /proc/mounts; then
umount -fr $target
sleep $delay
fi
fi
}

start() {
config_load "$NAME"
config_foreach nfs_share share
config_foreach nfs_mount mount
}

stop() {
nfs_share_stop
}

restart() {
echo > /etc/exports
start
}
14 changes: 14 additions & 0 deletions luci/luci-app-nfs/root/etc/uci-defaults/luci-nfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

uci -q batch <<-EOF >/dev/null
delete ucitrack.@nfs[-1]
add ucitrack nfs
set ucitrack.@nfs[-1].init=nfs
commit ucitrack
EOF

/etc/init.d/nfs enable && /etc/init.d/nfs restart

rm -f /tmp/luci-indexcache

exit 0
24 changes: 24 additions & 0 deletions luci/luci-app-socat/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (C) 2020 Lienol <[email protected]>
#
# This is free software, licensed under the GNU General Public License v3.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=luci-app-socat
PKG_VERSION:=20200824
PKG_RELEASE:=5

PKG_MAINTAINER:=Lienol <[email protected]>

LUCI_TITLE:=LuCI support for Socat
LUCI_DEPENDS:=+socat
LUCI_PKGARCH:=all

define Package/$(PKG_NAME)/conffiles
/etc/config/socat
endef

include $(TOPDIR)/feeds/luci/luci.mk

# call BuildPackage - OpenWrt buildroot signature
22 changes: 22 additions & 0 deletions luci/luci-app-socat/luasrc/controller/socat.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- Copyright 2020 Lienol <[email protected]>

module("luci.controller.socat", package.seeall)

function index()
if not nixio.fs.access("/etc/config/socat") then
return
end

entry({"admin", "network", "socat"}, alias("admin", "network", "socat", "index"), _("Socat"), 100).dependent = true
entry({"admin", "network", "socat", "index"}, cbi("socat/index")).leaf = true
entry({"admin", "network", "socat", "config"}, cbi("socat/config")).leaf = true
entry({"admin", "network", "socat", "status"}, call("act_status")).leaf = true
end

function act_status()
local e = {}
e.index = luci.http.formvalue("index")
e.status = luci.sys.call(string.format("ps -w | grep -v 'grep' | grep '/var/etc/socat/%s' >/dev/null", luci.http.formvalue("id"))) == 0
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
82 changes: 82 additions & 0 deletions luci/luci-app-socat/luasrc/model/cbi/socat/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
local d = require "luci.dispatcher"

m = Map("socat", translate("Socat Config"))
m.redirect = d.build_url("admin", "network", "socat")

s = m:section(NamedSection, arg[1], "config", "")
s.addremove = false
s.dynamic = false

o = s:option(Flag, "enable", translate("Enable"))
o.default = "1"
o.rmempty = false

o = s:option(Value, "remarks", translate("Remarks"))
o.default = translate("Remarks")
o.rmempty = false

o = s:option(ListValue, "protocol", translate("Protocol"))
o:value("port_forwards", translate("Port Forwards"))

o = s:option(ListValue, "family", translate("Restrict to address family"))
o:value("", translate("IPv4 and IPv6"))
o:value("4", translate("IPv4 only"))
o:value("6", translate("IPv6 only"))
o:depends("protocol", "port_forwards")

o = s:option(ListValue, "proto", translate("Protocol"))
o:value("tcp", "TCP")
o:value("udp", "UDP")
o:depends("protocol", "port_forwards")

o = s:option(Value, "listen_port", translate("Listen port"))
o.datatype = "portrange"
o.rmempty = false
o:depends("protocol", "port_forwards")

o = s:option(Flag, "reuseaddr", "reuseaddr", translate("Bind to a port local"))
o.default = "1"
o.rmempty = false

o = s:option(ListValue, "dest_proto", translate("Destination Protocol"))
o:value("tcp4", "IPv4-TCP")
o:value("udp4", "IPv4-UDP")
o:value("tcp6", "IPv6-TCP")
o:value("udp6", "IPv6-UDP")
o:depends("protocol", "port_forwards")

dest_ipv4 = s:option(Value, "dest_ipv4", translate("Destination address"))
luci.sys.net.ipv4_hints(function(ip, name)
dest_ipv4:value(ip, "%s (%s)" %{ ip, name })
end)
function dest_ipv4.cfgvalue(self, section)
return m:get(section, "dest_ip")
end
function dest_ipv4.write(self, section, value)
m:set(section, "dest_ip", value)
end
dest_ipv4:depends("dest_proto", "tcp4")
dest_ipv4:depends("dest_proto", "udp4")

dest_ipv6 = s:option(Value, "dest_ipv6", translate("Destination address"))
luci.sys.net.ipv6_hints(function(ip, name)
dest_ipv6:value(ip, "%s (%s)" %{ ip, name })
end)
function dest_ipv6.cfgvalue(self, section)
return m:get(section, "dest_ip")
end
function dest_ipv6.write(self, section, value)
m:set(section, "dest_ip", value)
end
dest_ipv6:depends("dest_proto", "tcp6")
dest_ipv6:depends("dest_proto", "udp6")

o = s:option(Value, "dest_port", translate("Destination port"))
o.datatype = "portrange"
o.rmempty = false

o = s:option(Flag, "firewall_accept", translate("Open firewall port"))
o.default = "1"
o.rmempty = false

return m
Loading

0 comments on commit 5b8acb1

Please sign in to comment.