mirror of
https://github.com/coolsnowwolf/luci.git
synced 2025-05-01 03:39:36 +08:00
luci-proto-3x: import from base
This commit is contained in:
parent
d34fb3704e
commit
b783e2c10d
17
protocols/luci-proto-3x/Makefile
Normal file
17
protocols/luci-proto-3x/Makefile
Normal file
@ -0,0 +1,17 @@
|
||||
#
|
||||
# Copyright (C) 2007-2013 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=Support for 3x
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
@ -0,0 +1,11 @@
|
||||
'use strict';'require rpc';'require uci';'require form';'require network';var callFileList=rpc.declare({object:'file',method:'list',params:['path'],expect:{entries:[]},filter:function(list,params){var rv=[];for(var i=0;i<list.length;i++)
|
||||
if(list[i].name.match(/^tty[A-Z]/)||list[i].name.match(/^cdc-wdm/)||list[i].name.match(/^[0-9]+$/))
|
||||
rv.push(params.path+list[i].name);return rv.sort();}});network.registerPatternVirtual(/^3x-.+$/);function write_keepalive(section_id,value){var f_opt=this.map.lookupOption('_keepalive_failure',section_id),i_opt=this.map.lookupOption('_keepalive_interval',section_id),f=(f_opt!=null)?+f_opt[0].formvalue(section_id):null,i=(i_opt!=null)?+i_opt[0].formvalue(section_id):null;if(f==null||f==''||isNaN(f))
|
||||
f=0;if(i==null||i==''||isNaN(i)||i<1)
|
||||
i=1;if(f>0)
|
||||
uci.set('network',section_id,'keepalive','%d %d'.format(f,i));else
|
||||
uci.unset('network',section_id,'keepalive');}
|
||||
return network.registerProtocol('3x',{getI18n:function(){return _('UMTS/GPRS/EV-DO');},getIfname:function(){return this._ubus('l3_device')||'3x-%s'.format(this.sid);},getOpkgPackage:function(){return'comgt';},isFloating:function(){return true;},isVirtual:function(){return true;},getDevices:function(){return null;},containsDevice:function(ifname){return(network.getIfnameOf(ifname)==this.getIfname());},renderFormOptions:function(s){var o;o=s.taboption('general',form.Value,'device',_('Modem device'));o.rmempty=false;o.load=function(section_id){return callFileList('/dev/').then(L.bind(function(devices){for(var i=0;i<devices.length;i++)
|
||||
this.value(devices[i]);return callFileList('/dev/tts/');},this)).then(L.bind(function(devices){for(var i=0;i<devices.length;i++)
|
||||
this.value(devices[i]);return form.Value.prototype.load.apply(this,[section_id]);},this));};o=s.taboption('general',form.Value,'service',_('Service Type'));o.value('',_('-- Please choose --'));o.value('umts','UMTS/GPRS');o.value('umts_only',_('UMTS only'));o.value('gprs_only',_('GPRS only'));o.value('evdo','CDMA/EV-DO');s.taboption('general',form.Value,'apn',_('APN'));s.taboption('general',form.Value,'pincode',_('PIN'));s.taboption('general',form.Value,'username',_('PAP/CHAP username'));o=s.taboption('general',form.Value,'password',_('PAP/CHAP password'));o.password=true;o=s.taboption('general',form.Value,'dialnumber',_('Dial number'));o.placeholder='*99***1#';if(L.hasSystemFeature('ipv6')){o=s.taboption('advanced',form.ListValue,'ipv6',_('Obtain IPv6-Address'));o.value('auto',_('Automatic'));o.value('0',_('Disabled'));o.value('1',_('Manual'));o.default='auto';}
|
||||
o=s.taboption('advanced',form.Value,'delay',_('Modem init timeout'),_('Maximum amount of seconds to wait for the modem to become ready'));o.placeholder='10';o.datatype='min(1)';o=s.taboption('advanced',form.Flag,'defaultroute',_('Use default gateway'),_('If unchecked, no default route is configured'));o.default=o.enabled;o=s.taboption('advanced',form.Value,'metric',_('Use gateway metric'));o.placeholder='0';o.datatype='uinteger';o.depends('defaultroute','1');o=s.taboption('advanced',form.Flag,'peerdns',_('Use DNS servers advertised by peer'),_('If unchecked, the advertised DNS server addresses are ignored'));o.default=o.enabled;o=s.taboption('advanced',form.DynamicList,'dns',_('Use custom DNS servers'));o.depends('peerdns','0');o.datatype='ipaddr';o=s.taboption('advanced',form.Value,'_keepalive_failure',_('LCP echo failure threshold'),_('Presume peer to be dead after given amount of LCP echo failures, use 0 to ignore failures'));o.placeholder='0';o.datatype='uinteger';o.write=write_keepalive;o.remove=write_keepalive;o.cfgvalue=function(section_id){var v=uci.get('network',section_id,'keepalive');if(typeof(v)=='string'&&v!=''){var m=v.match(/^(\d+)[ ,]\d+$/);return m?m[1]:v;}};o=s.taboption('advanced',form.Value,'_keepalive_interval',_('LCP echo interval'),_('Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold'));o.placeholder='5';o.datatype='min(1)';o.write=write_keepalive;o.remove=write_keepalive;o.cfgvalue=function(section_id){var v=uci.get('network',section_id,'keepalive');if(typeof(v)=='string'&&v!=''){var m=v.match(/^\d+[ ,](\d+)$/);return m?m[1]:v;}};o=s.taboption('advanced',form.Value,'demand',_('Inactivity timeout'),_('Close inactive connection after the given amount of seconds, use 0 to persist connection'));o.placeholder='0';o.datatype='uinteger';}});
|
@ -0,0 +1,128 @@
|
||||
-- Copyright 2011 Jo-Philipp Wich <jow@openwrt.org>
|
||||
-- Licensed to the public under the Apache License 2.0.
|
||||
|
||||
local map, section, net = ...
|
||||
|
||||
local device, apn, service, pincode, username, password, dialnumber
|
||||
local ipv6, maxwait, defaultroute, metric, peerdns, dns,
|
||||
keepalive_failure, keepalive_interval, demand
|
||||
|
||||
device = section:taboption("general", Value, "device", translate("Modem device"))
|
||||
device.rmempty = false
|
||||
|
||||
local device_suggestions = nixio.fs.glob("/dev/tty[A-Z]*")
|
||||
or nixio.fs.glob("/dev/tts/*")
|
||||
|
||||
if device_suggestions then
|
||||
local node
|
||||
for node in device_suggestions do
|
||||
device:value(node)
|
||||
end
|
||||
end
|
||||
|
||||
service = section:taboption("general", Value, "service", translate("Service Type"))
|
||||
service:value("", translate("-- Please choose --"))
|
||||
service:value("umts", "UMTS/GPRS")
|
||||
service:value("umts_only", translate("UMTS only"))
|
||||
service:value("gprs_only", translate("GPRS only"))
|
||||
service:value("evdo", "CDMA/EV-DO")
|
||||
|
||||
apn = section:taboption("general", Value, "apn", translate("APN"))
|
||||
|
||||
pincode = section:taboption("general", Value, "pincode", translate("PIN"))
|
||||
|
||||
username = section:taboption("general", Value, "username", translate("PAP/CHAP username"))
|
||||
|
||||
password = section:taboption("general", Value, "password", translate("PAP/CHAP password"))
|
||||
password.password = true
|
||||
|
||||
dialnumber = section:taboption("general", Value, "dialnumber", translate("Dial number"))
|
||||
dialnumber.placeholder = "*99***1#"
|
||||
|
||||
if luci.model.network:has_ipv6() then
|
||||
ipv6 = section:taboption("advanced", Flag, "ipv6",
|
||||
translate("Enable IPv6 negotiation on the PPP link"))
|
||||
ipv6.default = ipv6.disabled
|
||||
end
|
||||
|
||||
maxwait = section:taboption("advanced", Value, "maxwait",
|
||||
translate("Modem init timeout"),
|
||||
translate("Maximum amount of seconds to wait for the modem to become ready"))
|
||||
|
||||
maxwait.placeholder = "20"
|
||||
maxwait.datatype = "min(1)"
|
||||
|
||||
defaultroute = section:taboption("advanced", Flag, "defaultroute",
|
||||
translate("Use default gateway"),
|
||||
translate("If unchecked, no default route is configured"))
|
||||
defaultroute.default = defaultroute.enabled
|
||||
|
||||
metric = section:taboption("advanced", Value, "metric",
|
||||
translate("Use gateway metric"))
|
||||
|
||||
metric.placeholder = "0"
|
||||
metric.datatype = "uinteger"
|
||||
metric:depends("defaultroute", defaultroute.enabled)
|
||||
|
||||
peerdns = section:taboption("advanced", Flag, "peerdns",
|
||||
translate("Use DNS servers advertised by peer"),
|
||||
translate("If unchecked, the advertised DNS server addresses are ignored"))
|
||||
|
||||
peerdns.default = peerdns.enabled
|
||||
|
||||
dns = section:taboption("advanced", DynamicList, "dns",
|
||||
translate("Use custom DNS servers"))
|
||||
|
||||
dns:depends("peerdns", "")
|
||||
dns.datatype = "ipaddr"
|
||||
dns.cast = "string"
|
||||
|
||||
keepalive_failure = section:taboption("advanced", Value, "_keepalive_failure",
|
||||
translate("LCP echo failure threshold"),
|
||||
translate("Presume peer to be dead after given amount of LCP echo failures, use 0 to ignore failures"))
|
||||
|
||||
function keepalive_failure.cfgvalue(self, section)
|
||||
local v = m:get(section, "keepalive")
|
||||
if v and #v > 0 then
|
||||
return tonumber(v:match("^(%d+)[ ,]+%d+") or v)
|
||||
end
|
||||
end
|
||||
|
||||
function keepalive_failure.write() end
|
||||
function keepalive_failure.remove() end
|
||||
|
||||
keepalive_failure.placeholder = "0"
|
||||
keepalive_failure.datatype = "uinteger"
|
||||
|
||||
keepalive_interval = section:taboption("advanced", Value, "_keepalive_interval",
|
||||
translate("LCP echo interval"),
|
||||
translate("Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold"))
|
||||
|
||||
function keepalive_interval.cfgvalue(self, section)
|
||||
local v = m:get(section, "keepalive")
|
||||
if v and #v > 0 then
|
||||
return tonumber(v:match("^%d+[ ,]+(%d+)"))
|
||||
end
|
||||
end
|
||||
|
||||
function keepalive_interval.write(self, section, value)
|
||||
local f = tonumber(keepalive_failure:formvalue(section)) or 0
|
||||
local i = tonumber(value) or 5
|
||||
if i < 1 then i = 1 end
|
||||
if f > 0 then
|
||||
m:set(section, "keepalive", "%d %d" %{ f, i })
|
||||
else
|
||||
m:del(section, "keepalive")
|
||||
end
|
||||
end
|
||||
|
||||
keepalive_interval.remove = keepalive_interval.write
|
||||
keepalive_interval.placeholder = "5"
|
||||
keepalive_interval.datatype = "min(1)"
|
||||
|
||||
demand = section:taboption("advanced", Value, "demand",
|
||||
translate("Inactivity timeout"),
|
||||
translate("Close inactive connection after the given amount of seconds, use 0 to persist connection"))
|
||||
|
||||
demand.placeholder = "0"
|
||||
demand.datatype = "uinteger"
|
49
protocols/luci-proto-3x/luasrc/model/network/proto_3x.lua
Normal file
49
protocols/luci-proto-3x/luasrc/model/network/proto_3x.lua
Normal file
@ -0,0 +1,49 @@
|
||||
-- Copyright 2018 Florian Eckert <fe@dev.tdt.de>
|
||||
-- Licensed to the public under the Apache License 2.0.
|
||||
|
||||
local netmod = luci.model.network
|
||||
local interface = luci.model.network.interface
|
||||
|
||||
local proto = netmod:register_protocol("3x")
|
||||
|
||||
function proto.get_i18n(self)
|
||||
return luci.i18n.translate("UMTS/GPRS/EV-DO")
|
||||
end
|
||||
|
||||
function proto.ifname(self)
|
||||
return "3x-" .. self.sid
|
||||
end
|
||||
|
||||
function proto.get_interface(self)
|
||||
return interface(self:ifname(), self)
|
||||
end
|
||||
|
||||
function proto.is_installed(self)
|
||||
return nixio.fs.access("/lib/netifd/proto/3x.sh")
|
||||
end
|
||||
|
||||
function proto.opkg_package(self)
|
||||
return "comgt"
|
||||
end
|
||||
|
||||
function proto.is_floating(self)
|
||||
return true
|
||||
end
|
||||
|
||||
function proto.is_virtual(self)
|
||||
return true
|
||||
end
|
||||
|
||||
function proto.get_interfaces(self)
|
||||
return nil
|
||||
end
|
||||
|
||||
function proto.contains_interface(self, ifc)
|
||||
if self:is_floating() then
|
||||
return (netmod:ifnameof(ifc) == self:ifname())
|
||||
else
|
||||
return netmod.protocol.contains_interface(self, ifc)
|
||||
end
|
||||
end
|
||||
|
||||
netmod:register_pattern_virtual("^3x%-%w")
|
Loading…
Reference in New Issue
Block a user