diff --git a/luci-app-nyn/Makefile b/luci-app-nyn/Makefile new file mode 100644 index 0000000..5988f8f --- /dev/null +++ b/luci-app-nyn/Makefile @@ -0,0 +1,9 @@ +include $(TOPDIR)/rules.mk + +LUCI_TITLE:=LuCI support for NYN 802.1x Authentication Client +LUCI_DEPENDS:=+nyn +luci-base + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature + diff --git a/luci-app-nyn/luasrc/controller/nyn.lua b/luci-app-nyn/luasrc/controller/nyn.lua new file mode 100644 index 0000000..5cfa638 --- /dev/null +++ b/luci-app-nyn/luasrc/controller/nyn.lua @@ -0,0 +1,44 @@ +-- /usr/lib/lua/luci/controller/nyn.lua +module("luci.controller.nyn", package.seeall) + +function index() + if not nixio.fs.access("/etc/config/nyn") then + return + end + + -- Menu + entry({"admin", "network", "nyn"}, firstchild(), _("NyN-Client"), 60).dependent = false + + -- Settings + entry({"admin", "network", "nyn", "config"}, cbi("nyn"), _("Settings"), 1).leaf = true + + -- Status API + entry({"admin", "network", "nyn", "get_status"}, call("act_status")).leaf = true +end + +function act_status() + local sys = require "luci.sys" + local util = require "luci.util" + local status = {} + + -- Get status + status.running = (sys.call("pgrep -f nyn >/dev/null") == 0) + + -- Get process info + if status.running then + status.process_info = util.trim(sys.exec("ps | grep -v grep | grep nyn")) + end + + -- Get log + local log_file = "/tmp/nyn.log" + if nixio.fs.access(log_file) then + status.log = util.trim(sys.exec("tail -20 " .. log_file)) + else + status.log = util.trim(sys.exec("logread | grep nyn | tail -10")) + end + + luci.http.prepare_content("application/json") + luci.http.write_json(status) +end + + diff --git a/luci-app-nyn/luasrc/model/cbi/nyn.lua b/luci-app-nyn/luasrc/model/cbi/nyn.lua new file mode 100644 index 0000000..fc13baa --- /dev/null +++ b/luci-app-nyn/luasrc/model/cbi/nyn.lua @@ -0,0 +1,56 @@ +-- /usr/lib/lua/luci/model/cbi/nyn.lua + +local m, s, o +local sys = require "luci.sys" + +m = Map("nyn", translate("NYN 802.1x Authentication Client"), + translate("Configure 802.1x authentication for network access using NYN client")) + +-- Authentication Settings +s = m:section(TypedSection, "auth", translate("Authentication Settings")) +s.anonymous = true +s.addremove = false + +-- Service Status +o = s:option(DummyValue, "_status", translate("Current Status")) +o.rawhtml = true +o.cfgvalue = function() + local sys = require "luci.sys" + local running = sys.call("pgrep nyn >/dev/null") == 0 + + if running then + return "✔ 正在运行中" + else + return "✘ 未运行" + end +end + +-- Enable/Disable +o = s:option(Flag, "enabled", translate("Enable Service")) +o.rmempty = false + +-- Username +o = s:option(Value, "user", translate("Username"), translate("802.1x authentication username")) +o.rmempty = false + +-- Password +o = s:option(Value, "password", translate("Password"), translate("802.1x authentication password")) +o.password = true +o.rmempty = false + +-- Network Device +o = s:option(ListValue, "device", translate("Network Device"), translate("Network device to use for authentication")) +o.rmempty = false +o:value("eth0", "eth0") +o:value("eth1", "eth1") +o:value("wan", "WAN") + +-- Add network interface +local interfaces = sys.net.devices() +for _, iface in ipairs(interfaces) do + if iface ~= "lo" then + o:value(iface, iface) + end +end + +return m diff --git a/nyn/Makefile b/nyn/Makefile new file mode 100644 index 0000000..ef50f49 --- /dev/null +++ b/nyn/Makefile @@ -0,0 +1,66 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=nyn +PKG_VERSION:=0.0.3 +PKG_RELEASE:=1 + +PKG_MAINTAINER:=Dichgrem +PKG_LICENSE:=MIT + +include $(INCLUDE_DIR)/package.mk + +define Package/nyn + SECTION:=net + CATEGORY:=Network + TITLE:=NYN 802.1x Authentication Client + URL:=https://github.com/diredocks/nyn + DEPENDS:=+libpcap +endef + +define Package/nyn/description + A 802.1x authentication client for OpenWrt routers. + Cross-compiled with musl toolchain for optimal compatibility. +endef + +define Package/nyn/conffiles +/etc/config/nyn +/etc/nyn/config.toml +endef + +define Build/Prepare +endef + +define Build/Configure +endef + +define Build/Compile +endef + +define Package/nyn/install + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_DIR) $(1)/etc/nyn + + # Install precompiled binary based on architecture + $(if $(CONFIG_TARGET_x86_64),$(INSTALL_BIN) ./files/bin/nyn-x86_64 $(1)/usr/bin/nyn) + $(if $(CONFIG_TARGET_armvirt_64),$(INSTALL_BIN) ./files/bin/nyn-aarch64 $(1)/usr/bin/nyn) + $(if $(CONFIG_TARGET_bcm27xx_bcm2711),$(INSTALL_BIN) ./files/bin/nyn-aarch64 $(1)/usr/bin/nyn) + $(if $(CONFIG_TARGET_ath79_generic),$(INSTALL_BIN) ./files/bin/nyn-mips64 $(1)/usr/bin/nyn) + $(if $(CONFIG_TARGET_ramips_mt7621),$(INSTALL_BIN) ./files/bin/nyn-mips64 $(1)/usr/bin/nyn) + $(if $(CONFIG_TARGET_mediatek_mt7622),$(INSTALL_BIN) ./files/bin/nyn-aarch64 $(1)/usr/bin/nyn) + $(if $(CONFIG_TARGET_rockchip_armv8),$(INSTALL_BIN) ./files/bin/nyn-aarch64 $(1)/usr/bin/nyn) + # Fallback - try to detect architecture + $(if $(findstring arm,$(ARCH)),$(INSTALL_BIN) ./files/bin/nyn-armv7 $(1)/usr/bin/nyn) + $(if $(findstring aarch64,$(ARCH)),$(INSTALL_BIN) ./files/bin/nyn-aarch64 $(1)/usr/bin/nyn) + $(if $(findstring mips,$(ARCH)),$(INSTALL_BIN) ./files/bin/nyn-mips64 $(1)/usr/bin/nyn) + $(if $(findstring x86_64,$(ARCH)),$(INSTALL_BIN) ./files/bin/nyn-x86_64 $(1)/usr/bin/nyn) + $(if $(findstring i386,$(ARCH)),$(INSTALL_BIN) ./files/bin/nyn-i686 $(1)/usr/bin/nyn) + + $(INSTALL_BIN) ./files/usr/bin/nyn-device-info $(1)/usr/bin/ + $(INSTALL_CONF) ./files/etc/config/nyn $(1)/etc/config/ + $(INSTALL_CONF) ./files/etc/nyn/config.toml $(1)/etc/nyn/ + $(INSTALL_BIN) ./files/etc/init.d/nyn $(1)/etc/init.d/ +endef + +$(eval $(call BuildPackage,nyn)) diff --git a/nyn/files/bin/nyn-aarch64 b/nyn/files/bin/nyn-aarch64 new file mode 100644 index 0000000..de35d12 Binary files /dev/null and b/nyn/files/bin/nyn-aarch64 differ diff --git a/nyn/files/bin/nyn-armv7 b/nyn/files/bin/nyn-armv7 new file mode 100644 index 0000000..cfc838d Binary files /dev/null and b/nyn/files/bin/nyn-armv7 differ diff --git a/nyn/files/bin/nyn-i686 b/nyn/files/bin/nyn-i686 new file mode 100644 index 0000000..30b5318 Binary files /dev/null and b/nyn/files/bin/nyn-i686 differ diff --git a/nyn/files/bin/nyn-mips64 b/nyn/files/bin/nyn-mips64 new file mode 100644 index 0000000..cb3a19b Binary files /dev/null and b/nyn/files/bin/nyn-mips64 differ diff --git a/nyn/files/bin/nyn-riscv64 b/nyn/files/bin/nyn-riscv64 new file mode 100644 index 0000000..8f9568a Binary files /dev/null and b/nyn/files/bin/nyn-riscv64 differ diff --git a/nyn/files/bin/nyn-x86_64 b/nyn/files/bin/nyn-x86_64 new file mode 100644 index 0000000..c1b7f35 Binary files /dev/null and b/nyn/files/bin/nyn-x86_64 differ diff --git a/nyn/files/etc/config/nyn b/nyn/files/etc/config/nyn new file mode 100644 index 0000000..6850b33 --- /dev/null +++ b/nyn/files/etc/config/nyn @@ -0,0 +1,16 @@ +config general 'general' + option enabled '0' + option timeout '1' + option retry '5' + option schedule_callback '0' + +config crypto 'crypto' + option win_ver 'r70393861' + option client_key 'Oly5D62FaE94W7' + option client_version '' + +config auth 'auth' + option user '' + option password '' + option device 'eth0' + option hardware_description '' diff --git a/nyn/files/etc/init.d/nyn b/nyn/files/etc/init.d/nyn new file mode 100644 index 0000000..7b7a3c8 --- /dev/null +++ b/nyn/files/etc/init.d/nyn @@ -0,0 +1,41 @@ +#!/bin/sh /etc/rc.common + +START=99 +USE_PROCD=1 + +CONFIG=/etc/nyn/config.toml + +start_service() { + generate_config + + procd_open_instance + procd_set_param command /usr/bin/nyn -config "$CONFIG" + procd_set_param respawn + procd_close_instance +} + +stop_service() { + procd_kill nyn +} + +generate_config() { + mkdir -p /etc/nyn + + cat >"$CONFIG" </dev/null 2>&1; then + nyn -mode info 2>/dev/null | grep -E "(Found|device|hardware_description)" | while read line; do + echo "$line" + done +else + echo "NYN binary not found. Showing available network interfaces:" + for dev in /sys/class/net/*; do + if [ -d "$dev" ]; then + iface=$(basename "$dev") + if [ "$iface" != "lo" ]; then + echo "Device: $iface" + if [ -f "$dev/address" ]; then + echo " MAC: $(cat "$dev/address")" + fi + if [ -f "$dev/operstate" ]; then + echo " State: $(cat "$dev/operstate")" + fi + echo "" + fi + fi + done +fi