| 1 | --[[ |
|---|
| 2 | LuCI - Lua Configuration Interface |
|---|
| 3 | |
|---|
| 4 | Copyright 2011 Jo-Philipp Wich <xm@subsignal.org> |
|---|
| 5 | |
|---|
| 6 | Licensed under the Apache License, Version 2.0 (the "License"); |
|---|
| 7 | you may not use this file except in compliance with the License. |
|---|
| 8 | You may obtain a copy of the License at |
|---|
| 9 | |
|---|
| 10 | http://www.apache.org/licenses/LICENSE-2.0 |
|---|
| 11 | ]]-- |
|---|
| 12 | |
|---|
| 13 | local map, section, net = ... |
|---|
| 14 | |
|---|
| 15 | local device, username, password |
|---|
| 16 | local ipv6, defaultroute, metric, peerdns, dns, |
|---|
| 17 | keepalive_failure, keepalive_interval, demand, mtu |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | device = section:taboption("general", Value, "device", translate("Modem device")) |
|---|
| 21 | device.rmempty = false |
|---|
| 22 | |
|---|
| 23 | local device_suggestions = nixio.fs.glob("/dev/tty*S*") |
|---|
| 24 | or nixio.fs.glob("/dev/tts/*") |
|---|
| 25 | |
|---|
| 26 | if device_suggestions then |
|---|
| 27 | local node |
|---|
| 28 | for node in device_suggestions do |
|---|
| 29 | device:value(node) |
|---|
| 30 | end |
|---|
| 31 | end |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | username = section:taboption("general", Value, "username", translate("PAP/CHAP username")) |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | password = section:taboption("general", Value, "password", translate("PAP/CHAP password")) |
|---|
| 38 | password.password = true |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | if luci.model.network:has_ipv6() then |
|---|
| 42 | |
|---|
| 43 | ipv6 = section:taboption("advanced", Flag, "ipv6", |
|---|
| 44 | translate("Enable IPv6 negotiation on the PPP link")) |
|---|
| 45 | |
|---|
| 46 | ipv6.default = ipv6.disabled |
|---|
| 47 | |
|---|
| 48 | end |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | defaultroute = section:taboption("advanced", Flag, "defaultroute", |
|---|
| 52 | translate("Use default gateway"), |
|---|
| 53 | translate("If unchecked, no default route is configured")) |
|---|
| 54 | |
|---|
| 55 | defaultroute.default = defaultroute.enabled |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | metric = section:taboption("advanced", Value, "metric", |
|---|
| 59 | translate("Use gateway metric")) |
|---|
| 60 | |
|---|
| 61 | metric.placeholder = "0" |
|---|
| 62 | metric.datatype = "uinteger" |
|---|
| 63 | metric:depends("defaultroute", defaultroute.enabled) |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | peerdns = section:taboption("advanced", Flag, "peerdns", |
|---|
| 67 | translate("Use DNS servers advertised by peer"), |
|---|
| 68 | translate("If unchecked, the advertised DNS server addresses are ignored")) |
|---|
| 69 | |
|---|
| 70 | peerdns.default = peerdns.enabled |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | dns = section:taboption("advanced", DynamicList, "dns", |
|---|
| 74 | translate("Use custom DNS servers")) |
|---|
| 75 | |
|---|
| 76 | dns:depends("peerdns", "") |
|---|
| 77 | dns.datatype = "ipaddr" |
|---|
| 78 | dns.cast = "string" |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | keepalive_failure = section:taboption("advanced", Value, "_keepalive_failure", |
|---|
| 82 | translate("LCP echo failure threshold"), |
|---|
| 83 | translate("Presume peer to be dead after given amount of LCP echo failures, use 0 to ignore failures")) |
|---|
| 84 | |
|---|
| 85 | function keepalive_failure.cfgvalue(self, section) |
|---|
| 86 | local v = m:get(section, "keepalive") |
|---|
| 87 | if v and #v > 0 then |
|---|
| 88 | return tonumber(v:match("^(%d+)[ ,]+%d+") or v) |
|---|
| 89 | end |
|---|
| 90 | end |
|---|
| 91 | |
|---|
| 92 | function keepalive_failure.write() end |
|---|
| 93 | function keepalive_failure.remove() end |
|---|
| 94 | |
|---|
| 95 | keepalive_failure.placeholder = "0" |
|---|
| 96 | keepalive_failure.datatype = "uinteger" |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | keepalive_interval = section:taboption("advanced", Value, "_keepalive_interval", |
|---|
| 100 | translate("LCP echo interval"), |
|---|
| 101 | translate("Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold")) |
|---|
| 102 | |
|---|
| 103 | function keepalive_interval.cfgvalue(self, section) |
|---|
| 104 | local v = m:get(section, "keepalive") |
|---|
| 105 | if v and #v > 0 then |
|---|
| 106 | return tonumber(v:match("^%d+[ ,]+(%d+)")) |
|---|
| 107 | end |
|---|
| 108 | end |
|---|
| 109 | |
|---|
| 110 | function keepalive_interval.write(self, section, value) |
|---|
| 111 | local f = tonumber(keepalive_failure:formvalue(section)) or 0 |
|---|
| 112 | local i = tonumber(value) or 5 |
|---|
| 113 | if i < 1 then i = 1 end |
|---|
| 114 | if f > 0 then |
|---|
| 115 | m:set(section, "keepalive", "%d %d" %{ f, i }) |
|---|
| 116 | else |
|---|
| 117 | m:del(section, "keepalive") |
|---|
| 118 | end |
|---|
| 119 | end |
|---|
| 120 | |
|---|
| 121 | keepalive_interval.remove = keepalive_interval.write |
|---|
| 122 | keepalive_interval.placeholder = "5" |
|---|
| 123 | keepalive_interval.datatype = "min(1)" |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | demand = section:taboption("advanced", Value, "demand", |
|---|
| 127 | translate("Inactivity timeout"), |
|---|
| 128 | translate("Close inactive connection after the given amount of seconds, use 0 to persist connection")) |
|---|
| 129 | |
|---|
| 130 | demand.placeholder = "0" |
|---|
| 131 | demand.datatype = "uinteger" |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | mtu = section:taboption("advanced", Value, "mtu", translate("Override MTU")) |
|---|
| 135 | mtu.placeholder = "1500" |
|---|
| 136 | mtu.datatype = "max(1500)" |
|---|