>From 9a9dc70152468dd745fe0cd9dd94d1b498b87598 Mon Sep 17 00:00:00 2001
From: Matthew Fatheree <matthew.fathe...@belkin.com>
Date: Sun, 4 May 2014 23:47:45 +0700
Subject: [PATCH 29/30] mamba mvebu: support macclone

Support to change/restore the WAN's MAC address via WebUI

Signed-off-by: Matthew Fatheree <matthew.fathe...@belkin.com>
---
 .../files/usr/lib/lua/luci/controller/macclone.lua |    6 ++
 .../files/usr/lib/lua/luci/model/cbi/macclone.lua  |   92 ++++++++++++++++++++
 2 files changed, 98 insertions(+)
 create mode 100644 
package/linksys-base-files/files/usr/lib/lua/luci/controller/macclone.lua
 create mode 100644 
package/linksys-base-files/files/usr/lib/lua/luci/model/cbi/macclone.lua

diff --git 
a/package/linksys-base-files/files/usr/lib/lua/luci/controller/macclone.lua 
b/package/linksys-base-files/files/usr/lib/lua/luci/controller/macclone.lua
new file mode 100644
index 0000000..97245d9
--- /dev/null
+++ b/package/linksys-base-files/files/usr/lib/lua/luci/controller/macclone.lua
@@ -0,0 +1,6 @@
+module("luci.controller.macclone", package.seeall)
+
+function index()
+       entry({"admin", "network", "MacClone"}, cbi("macclone"), _("MAC Address 
Clone"), 90)
+       entry({"mini", "network", "MacClone"}, cbi("macclone"), _("MAC Address 
Clone"), 90)
+end
diff --git 
a/package/linksys-base-files/files/usr/lib/lua/luci/model/cbi/macclone.lua 
b/package/linksys-base-files/files/usr/lib/lua/luci/model/cbi/macclone.lua
new file mode 100644
index 0000000..b01d94b
--- /dev/null
+++ b/package/linksys-base-files/files/usr/lib/lua/luci/model/cbi/macclone.lua
@@ -0,0 +1,92 @@
+--Create Form
+m = SimpleForm("macclone", translate("MAC Address Clone"),
+       translate("Some ISPs will require you to register your MAC address. If 
you do not wish to re-register your MAC address, you can have the router clone 
the MAC address that is registered with your ISP."))
+s = m:section(SimpleSection)
+
+--Translate submit button to "Clone Mac...", hidden reset button
+m.submit = translate("Clone Mac...")
+m.reset  = false
+
+--Show texbox "Curent WAN MAC"
+curentmac             = s:option(Value, "curentmac", translate("Current WAN 
MAC"))
+curentmac.datatype    = "macaddr"
+curentmac.placeholder = "00:00:00:00:00:00"
+
+--Show button "Restore Original MAC Address"
+ori_mac            = s:option(Button, "ori_mac", translate(" "))
+ori_mac.inputtitle = translate("Restore Original MAC Address")
+ori_mac.inputstyle = "apply"
+ori_mac.rmempty    = false
+
+--Get WAN interface name
+cmd    = "uci -P/var/state get network.wan.ifname"
+f      = io.popen(cmd)
+wan_if = f:read()
+f:close()
+
+--Get current MAC
+cmd     = "uci show network.wan | grep .macaddr | awk -F'=' '{print $2}'"
+f       = io.popen(cmd)
+cur_mac = f:read()
+f:close()
+if cur_mac == nil then
+    cmd     =  "ifconfig "..wan_if.." | grep HWaddr | awk -F'HWaddr ' '{print 
$2}'"
+    f       = io.popen(cmd)
+    cur_mac = f:read()
+       if cur_mac then
+               curentmac:value("", cur_mac.."(Original MAC)")
+       end
+    f:close()
+else
+    curentmac:value("", cur_mac.."(Has changed)")
+end
+
+--Mac Clone
+function curentmac.write(self)
+       local mac = luci.http.formvalue("cbid.macclone.1.curentmac")
+       if mac and mac ~= cur_mac then
+               cmd       = "uci set network.wan.macaddr="..mac.." && uci 
commit network && /etc/init.d/network restart"
+               p         = io.popen(cmd)
+               p:close()
+               m.message = "Clone MAC("..mac..") successfully"
+               cur_mac   = mac
+               curentmac:value("", mac.."(Has changed)")
+    else
+        m.message     = "Clone MAC unsuccessfully"
+       end
+end
+
+--Restore original MAC
+function ori_mac.write(self)
+       --Check macaddr set to /etc/config/network
+    cmd           = "uci show network.wan | grep .macaddr | awk -F'=' '{print 
$2}'"
+    local p       = io.popen(cmd)
+    local mac     = p:read()
+    p:close()
+
+    if mac then
+               --Remove macaddr from /etc/config/network
+        cmd       = "uci delete network.wan.macaddr && uci commit network && 
/etc/init.d/network restart"
+        p         = io.popen(cmd)
+        p:close()
+
+        --Get original Mac
+        cmd           =  "ifconfig "..wan_if.." | grep HWaddr | awk -F'HWaddr 
' '{print $2}'"
+        p             = io.popen(cmd)
+        local ori_mac = p:read()
+               p:close()
+
+               --Show Mac to text box
+               if ori_mac then
+                       m.message = "Restore original MAC successfully"
+                       curentmac:value("", ori_mac.."(Original MAC)")
+            cur_mac   = ori_mac
+               else
+                       m.message = "Restore original MAC unsuccessfully"
+               end
+    else
+        m.message     = "Current Mac is original"
+       end
+end
+
+return m
--
1.7.9.5



__________________________________________________________________ Confidential 
This e-mail and any files transmitted with it are the property of Belkin 
International, Inc. and/or its affiliates, are confidential, and are intended 
solely for the use of the individual or entity to whom this e-mail is 
addressed. If you are not one of the named recipients or otherwise have reason 
to believe that you have received this e-mail in error, please notify the 
sender and delete this message immediately from your computer. Any other use, 
retention, dissemination, forwarding, printing or copying of this e-mail is 
strictly prohibited. Pour la version française: 
http://www.belkin.com/email-notice/French.html Für die deutsche Übersetzung: 
http://www.belkin.com/email-notice/German.html 
__________________________________________________________________
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to