add luci-app-wan-mac
This commit is contained in:
parent
b74d4aa8f0
commit
fccaaca61e
17
applications/luci-app-wan-mac/Makefile
Normal file
17
applications/luci-app-wan-mac/Makefile
Normal file
@ -0,0 +1,17 @@
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_VERSION:=1.0.0-20230404
|
||||
PKG_RELEASE:=
|
||||
PKG_MAINTAINER:=jjm2473 <jjm2473@gmail.com>
|
||||
|
||||
LUCI_TITLE:=Generate MAC address for WAN
|
||||
LUCI_PKGARCH:=all
|
||||
|
||||
define Package/luci-app-wan-mac/conffiles
|
||||
/etc/config/wan_mac
|
||||
endef
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
@ -0,0 +1,118 @@
|
||||
'use strict';
|
||||
'require view';
|
||||
'require uci';
|
||||
'require form';
|
||||
'require dom';
|
||||
|
||||
var CBIMacAddress = form.Value.extend({
|
||||
renderWidget: function(section_id, option_index, cfgvalue) {
|
||||
var node = this.super('renderWidget', [section_id, option_index, cfgvalue]);
|
||||
dom.append(node, [
|
||||
E('br'),
|
||||
E('span', { 'class': 'control-group' },
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-neutral',
|
||||
'click': this.clickFn.bind(this, section_id, node)
|
||||
}, this.btnTitle)
|
||||
)
|
||||
]);
|
||||
return node;
|
||||
}
|
||||
});
|
||||
|
||||
var genMAC = function(section_id, node) {
|
||||
var getOptVal = L.bind(function(opt, default_val) {
|
||||
default_val = default_val || null;
|
||||
return this.section.formvalue(section_id, opt) || default_val;
|
||||
}, this);
|
||||
|
||||
var prefix = getOptVal('prefix');
|
||||
if (prefix === null || prefix === "") {
|
||||
alert(_('Select or input Prefix first!'));
|
||||
return;
|
||||
}
|
||||
var macb = prefix.match(/[a-fA-F0-9]{2}/g).map(function(b){return parseInt(b,16);});
|
||||
if ((macb[0] & 1) === 1) {
|
||||
alert(_('Prefix is a Multicast address!'));
|
||||
return;
|
||||
}
|
||||
while (macb.length < 5) {
|
||||
macb.push(parseInt(Math.random()*255.9));
|
||||
}
|
||||
macb[5] = (parseInt(Math.random()*15.9) << 4) + parseInt(Math.random()*8);
|
||||
|
||||
var mac = "";
|
||||
for (var i=0; i<6; ++i) {
|
||||
var b = macb[i].toString(16).toUpperCase();
|
||||
if (b.length === 1) {
|
||||
b = '0' + b;
|
||||
}
|
||||
mac = mac + ':' + b;
|
||||
}
|
||||
mac = mac.substring(1);
|
||||
/*
|
||||
var inputEl = node.querySelector('input[type="text"]');
|
||||
inputEl.value = mac;
|
||||
// this.triggerValidation(section_id);
|
||||
inputEl.dispatchEvent(new Event('input'));
|
||||
inputEl.dispatchEvent(new Event('blur'));
|
||||
*/
|
||||
dom.callClassMethod(node, "setValue", mac);
|
||||
dom.callClassMethod(node, "triggerValidation");
|
||||
};
|
||||
|
||||
return view.extend({
|
||||
load: function() {
|
||||
return Promise.all([
|
||||
uci.load('wan_mac')
|
||||
]);
|
||||
},
|
||||
|
||||
render: function() {
|
||||
|
||||
var m, s, o;
|
||||
|
||||
m = new form.Map('wan_mac', _('WAN MAC address'),
|
||||
_('Change the MAC address of WAN port. <br>Note that modifying the MAC address may cause the IP address to change.'));
|
||||
|
||||
s = m.section(form.NamedSection, 'config', 'wan_mac', _('Global Settings'));
|
||||
s.anonymous = true;
|
||||
s.addremove = false;
|
||||
|
||||
o = s.option(form.Flag, 'enabled', _('Enable'));
|
||||
o.rmempty = false;
|
||||
|
||||
s = m.section(form.NamedSection, 'config', 'wan_mac', _('MAC Address Settings'),
|
||||
_('Select a prefix and click the "Randomly Generate Using Prefix" button to generate a MAC address'));
|
||||
s.anonymous = true;
|
||||
s.addremove = false;
|
||||
|
||||
o = s.option(form.Value, 'prefix', _('MAC address prefix'), _('Supports "000000" format'))
|
||||
o.datatype = 'and(hexstring,rangelength(2,8))';
|
||||
[
|
||||
["044A6C", "Huawei"],
|
||||
["3CCD57", "Xiaomi"],
|
||||
["603A7C", "TP-LINK"],
|
||||
["00E04C", "Realtek"],
|
||||
["68ECC5", "Intel"],
|
||||
["8086F2", "Intel"],
|
||||
["3C3786", "NETGEAR"],
|
||||
["7C10C9", "ASUS"],
|
||||
["68DB54", "Phicomm"],
|
||||
["020000", "Private"],
|
||||
["021234", "Private"],
|
||||
["02AABB", "Private"],
|
||||
].forEach(function(oui){
|
||||
o.value(oui[0], oui[0] + ' (' + oui[1] + ')');
|
||||
});
|
||||
|
||||
o = s.option(CBIMacAddress, 'macaddr', _('MAC address'), _('Supports "00:00:00:00:00:00" format'))
|
||||
o.datatype = 'macaddr';
|
||||
o.rmempty = false;
|
||||
o.placeholder = '02:00:00:00:00:00';
|
||||
o.btnTitle = _('Randomly Generate Using Prefix');
|
||||
o.clickFn = genMAC;
|
||||
|
||||
return m.render();
|
||||
}
|
||||
});
|
41
applications/luci-app-wan-mac/po/zh-cn/wan_mac.po
Normal file
41
applications/luci-app-wan-mac/po/zh-cn/wan_mac.po
Normal file
@ -0,0 +1,41 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Content-Type: text/plain; charset=UTF-8"
|
||||
|
||||
msgid "Global Settings"
|
||||
msgstr "全局设置"
|
||||
|
||||
msgid "Select or input Prefix first!"
|
||||
msgstr "先选择或者输入前缀!"
|
||||
|
||||
msgid "Prefix is a Multicast address!"
|
||||
msgstr "前缀是一个多播地址!"
|
||||
|
||||
msgid "WAN MAC address"
|
||||
msgstr "WAN口MAC地址"
|
||||
|
||||
msgid ""
|
||||
"Change the MAC address of WAN port. <br>"
|
||||
"Note that modifying the MAC address may cause the IP address to change."
|
||||
msgstr "修改WAN口的MAC地址。<br>注意修改MAC地址以后可能导致IP地址变化。"
|
||||
|
||||
msgid "MAC Address Settings"
|
||||
msgstr "MAC地址设置"
|
||||
|
||||
msgid "MAC address prefix"
|
||||
msgstr "MAC地址前缀"
|
||||
|
||||
msgid "Supports \"000000\" format"
|
||||
msgstr "支持\"000000\"格式"
|
||||
|
||||
msgid "MAC address"
|
||||
msgstr "MAC地址"
|
||||
|
||||
msgid "Supports \"00:00:00:00:00:00\" format"
|
||||
msgstr "支持\"00:00:00:00:00:00\"格式"
|
||||
|
||||
msgid "Randomly Generate Using Prefix"
|
||||
msgstr "使用前缀随机生成"
|
||||
|
||||
msgid "Select a prefix and click the \"Randomly Generate Using Prefix\" button to generate a MAC address"
|
||||
msgstr "选择前缀,然后点击“使用前缀随机生成”按钮即可生成MAC地址"
|
4
applications/luci-app-wan-mac/root/etc/config/wan_mac
Normal file
4
applications/luci-app-wan-mac/root/etc/config/wan_mac
Normal file
@ -0,0 +1,4 @@
|
||||
config wan_mac 'config'
|
||||
option enabled '0'
|
||||
# option prefix ''
|
||||
# option macaddr ''
|
66
applications/luci-app-wan-mac/root/etc/init.d/wan_mac
Executable file
66
applications/luci-app-wan-mac/root/etc/init.d/wan_mac
Executable file
@ -0,0 +1,66 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=20
|
||||
USE_PROCD=1
|
||||
|
||||
boot() {
|
||||
# procd will call service_triggers
|
||||
rc_procd true
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "wan_mac"
|
||||
}
|
||||
|
||||
find_uci_section_i() {
|
||||
local key="$2"
|
||||
local value="$3"
|
||||
local testv
|
||||
config_get testv "$1" "$key"
|
||||
[[ "$value" = "$testv" ]] && echo "$1"
|
||||
}
|
||||
|
||||
find_uci_section() {
|
||||
local config="$1"
|
||||
local type="$2"
|
||||
local key="$3"
|
||||
local value="$4"
|
||||
(
|
||||
config_load "$config"
|
||||
config_foreach find_uci_section_i "$type" "$key" "$value"
|
||||
)
|
||||
}
|
||||
|
||||
generate_config() {
|
||||
local enabled
|
||||
local macaddr
|
||||
config_get_bool enabled "config" enabled 0
|
||||
config_get macaddr "config" macaddr
|
||||
local wan_dev="`uci -q get network.wan.device`"
|
||||
[[ -z "$wan_dev" ]] && {
|
||||
echo "get network.wan.device failed in uci" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
local wan_dev_s=`find_uci_section network device name "$wan_dev" | head -1`
|
||||
[[ -z "$wan_dev_s" ]] && {
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
add network device
|
||||
set network.@device[-1].name="$wan_dev"
|
||||
EOF
|
||||
wan_dev_s="@device[-1]"
|
||||
}
|
||||
if [[ "$enabled" = "1" ]]; then
|
||||
uci set "network.$wan_dev_s.macaddr=$macaddr"
|
||||
else
|
||||
uci delete "network.$wan_dev_s.macaddr"
|
||||
fi
|
||||
uci commit network
|
||||
return 0
|
||||
}
|
||||
|
||||
start_service() {
|
||||
config_load wan_mac
|
||||
generate_config && /etc/init.d/network reload
|
||||
return 0
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
{
|
||||
"admin/network/wan_mac": {
|
||||
"title": "WAN MAC",
|
||||
"order": 99,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "wan_mac"
|
||||
},
|
||||
"depends": {
|
||||
"acl": [ "luci-app-wan-mac" ],
|
||||
"uci": { "wan_mac": true }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"luci-app-wan-mac": {
|
||||
"description": "Grant access to 'WAN MAC'",
|
||||
"read": {
|
||||
"uci": [ "wan_mac" ]
|
||||
},
|
||||
"write": {
|
||||
"uci": [ "wan_mac" ]
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user