diff --git a/package/lean/luci-app-arpbind/Makefile b/package/lean/luci-app-arpbind/Makefile new file mode 100755 index 000000000..7b95a3d4b --- /dev/null +++ b/package/lean/luci-app-arpbind/Makefile @@ -0,0 +1,15 @@ +# +# Copyright (C) 2008-2014 The LuCI Team +# +# This is free software, licensed under the Apache License, Version 2.0 . +# + +include $(TOPDIR)/rules.mk + +LUCI_TITLE:=ARP Binding +LUCI_DEPENDS:=+ip-full + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature + diff --git a/package/lean/luci-app-arpbind/luasrc/controller/arpbind.lua b/package/lean/luci-app-arpbind/luasrc/controller/arpbind.lua new file mode 100644 index 000000000..2358fa50a --- /dev/null +++ b/package/lean/luci-app-arpbind/luasrc/controller/arpbind.lua @@ -0,0 +1,13 @@ +--[[ + 静态ARP绑定 Luci页面 Controller + Copyright (C) 2015 GuoGuo +]]-- + +module("luci.controller.arpbind", package.seeall) + +function index() + if not nixio.fs.access("/etc/config/arpbind") then + return + end + entry({"admin", "network", "arpbind"}, cbi("arpbind"), _("IP/MAC Binding"), 45).dependent = true +end diff --git a/package/lean/luci-app-arpbind/luasrc/model/cbi/arpbind.lua b/package/lean/luci-app-arpbind/luasrc/model/cbi/arpbind.lua new file mode 100644 index 000000000..0caaa0930 --- /dev/null +++ b/package/lean/luci-app-arpbind/luasrc/model/cbi/arpbind.lua @@ -0,0 +1,36 @@ +--[[ + 静态ARP绑定 Luci页面 CBI page + Copyright (C) 2015 GuoGuo +]]-- + +local sys = require "luci.sys" +local ifaces = sys.net:devices() + +m = Map("arpbind", translate("IP/MAC Binding"), + translatef("ARP is used to convert a network address (e.g. an IPv4 address) to a physical address such as a MAC address.Here you can add some static ARP binding rules.")) + +s = m:section(TypedSection, "arpbind", translate("Rules")) +s.template = "cbi/tblsection" +s.anonymous = true +s.addremove = true + +a = s:option(Value, "ipaddr", translate("IP Address")) +a.datatype = "ipaddr" +a.optional = false + +a = s:option(Value, "macaddr", translate("MAC Address")) +a.datatype = "macaddr" +a.optional = false + +a = s:option(ListValue, "ifname", translate("Interface")) +for _, iface in ipairs(ifaces) do + if iface ~= "lo" then + a:value(iface) + end +end +a.default = "br-lan" +a.rmempty = false + +return m + + diff --git a/package/lean/luci-app-arpbind/po/zh-cn/arpbind.po b/package/lean/luci-app-arpbind/po/zh-cn/arpbind.po new file mode 100644 index 000000000..bcc53625f --- /dev/null +++ b/package/lean/luci-app-arpbind/po/zh-cn/arpbind.po @@ -0,0 +1,21 @@ +msgid "" +msgstr "" +"Project-Id-Version: Luci ARP Bind\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-06-23 20:16+0800\n" +"PO-Revision-Date: 2015-06-23 20:17+0800\n" +"Last-Translator: 981213 \n" +"Language-Team: PandoraBox Team\n" +"Language: zh_CN\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: Poedit 1.8.1\n" +"X-Poedit-SourceCharset: UTF-8\n" + +msgid "IP/MAC Binding" +msgstr "IP/MAC绑定" + +msgid "ARP is used to convert a network address (e.g. an IPv4 address) to a physical address such as a MAC address.Here you can add some static ARP binding rules." +msgstr "ARP协议是用于实现网络地址到物理地址转换的协议。在这里,你可以设置静态ARP绑定规则。" diff --git a/package/lean/luci-app-arpbind/root/etc/hotplug.d/iface/50-arpbind b/package/lean/luci-app-arpbind/root/etc/hotplug.d/iface/50-arpbind new file mode 100644 index 000000000..e3ee499ca --- /dev/null +++ b/package/lean/luci-app-arpbind/root/etc/hotplug.d/iface/50-arpbind @@ -0,0 +1,2 @@ +#!/bin/sh +[ "$ACTION" = "ifup" ] && /etc/init.d/arpbind start diff --git a/package/lean/luci-app-arpbind/root/etc/init.d/arpbind b/package/lean/luci-app-arpbind/root/etc/init.d/arpbind new file mode 100755 index 000000000..7e1048dab --- /dev/null +++ b/package/lean/luci-app-arpbind/root/etc/init.d/arpbind @@ -0,0 +1,55 @@ +#!/bin/sh /etc/rc.common +# OpenWrt 静态ARP绑定 启动脚本 +# Copyright (C) 2015 GuoGuo + +. /lib/functions.sh +. /lib/functions/network.sh + +#清除单接口ARP +#参数:$1:接口名称 +if_clean_arp() +{ + [ -z "$1" ] && return + ip link set arp off dev $1 + ip link set arp on dev $1 +} + +#清除系统所有ARP +#参数:无 +clean_arp() +{ + for i in $(ls /sys/class/net) + do + if_clean_arp $i + done +} + +#添加静态ARP绑定 +#参数:$1:IP地址 $2:MAC地址 $3:接口名称 +add_arp() +{ + [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] && return + echo "Adding ARP:IP Addr:$1 MAC Addr:$2 Interface:$3" + ip neigh add $1 lladdr $2 nud permanent dev $3 +} + +arpconf_foreach() +{ + config_get ipaddr "$1" 'ipaddr' + config_get macaddr "$1" 'macaddr' + config_get ifname "$1" 'ifname' + [ -z "$ifname" ] && return + add_arp $ipaddr $macaddr $ifname +} + +start() +{ + config_load 'arpbind' + config_foreach arpconf_foreach 'arpbind' +} + +stop() +{ + clean_arp +} + diff --git a/package/lean/luci-app-arpbind/root/etc/uci-defaults/luci-arpbind b/package/lean/luci-app-arpbind/root/etc/uci-defaults/luci-arpbind new file mode 100755 index 000000000..b0f06852a --- /dev/null +++ b/package/lean/luci-app-arpbind/root/etc/uci-defaults/luci-arpbind @@ -0,0 +1,12 @@ +#!/bin/sh +touch /etc/config/arpbind + +uci -q batch <<-EOF >/dev/null + delete ucitrack.@arpbind[-1] + add ucitrack arpbind + set ucitrack.@arpbind[-1].init=arpbind + commit ucitrack +EOF + +rm -f /tmp/luci-indexcache +exit 0