2012-05-22 19:28:02 +02:00
local uci = luci.model . uci.cursor ( )
local nav = require " luci.tools.ffhl-wizard.nav "
local f = SimpleForm ( " meshvpn " , " Mesh-VPN " , " Um deinen Freifunkknoten auch über das Internet mit anderen Knoten zu verbinden, muss das Mesh-VPN aktiviert werden.</p><p>Dadurch ist es möglich das Freifunknetz auch ohne WLAN Verbindung zu anderen Knoten zu nutzen. " )
f.template = " ffhl-wizard/wizardform "
meshvpn = f : field ( Flag , " meshvpn " , " Mesh-VPN aktivieren? " )
meshvpn.default = string.format ( " %d " , uci : get ( " fastd " , " ffhl_mesh_vpn " , " enabled " ) )
meshvpn.rmempty = false
2012-07-24 00:54:04 +02:00
tc = f : field ( Flag , " tc " , " Bandbreitenbegrenzung aktivieren? " )
local v = string.format ( " %d " , uci : get_first ( " ffhl " , " bandwidth " , " disabled " ) )
if v == " 1 " then v = " 0 " else v = " 1 " end
tc.default = v
tc.rmempty = false
2012-07-23 22:04:08 +02:00
upstream = f : field ( Value , " upstream " , " Upstream bandwidth (kbit/s) " )
2012-07-24 00:20:11 +02:00
upstream.value = uci : get_first ( " ffhl " , " bandwidth " , " upstream " )
downstream = f : field ( Value , " downstream " , " Downstream bandwidth (kbit/s) " )
downstream.value = uci : get_first ( " ffhl " , " bandwidth " , " downstream " )
2012-07-23 22:04:08 +02:00
2012-05-22 19:28:02 +02:00
function f . handle ( self , state , data )
2012-07-24 00:23:26 +02:00
if state == FORM_VALID then
local stat = false
uci : set ( " fastd " , " ffhl_mesh_vpn " , " enabled " , data.meshvpn )
uci : save ( " fastd " )
uci : commit ( " fastd " )
2012-07-24 00:54:04 +02:00
local v = string.format ( " %d " , data.tc )
if v == " 1 " then v = " 0 " else v = " 1 " end
2012-07-24 00:23:26 +02:00
uci : foreach ( " ffhl " , " bandwidth " , function ( s )
uci : set ( " ffhl " , s [ " .name " ] , " upstream " , data.upstream )
uci : set ( " ffhl " , s [ " .name " ] , " downstream " , data.downstream )
2012-07-24 00:54:04 +02:00
uci : set ( " ffhl " , s [ " .name " ] , " disabled " , v )
2012-07-24 00:23:26 +02:00
end
)
uci : save ( " ffhl " )
uci : commit ( " ffhl " )
if data.meshvpn == " 1 " then
2012-05-24 22:19:11 +02:00
local secret = uci : get ( " fastd " , " ffhl_mesh_vpn " , " secret " )
2012-07-24 00:23:26 +02:00
if not secret or not secret : match ( " %x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x " ) then
luci.sys . call ( " /etc/init.d/haveged start " )
local f = io.popen ( " fastd --generate-key --machine-readable " , " r " )
local secret = f : read ( " *a " )
f : close ( )
luci.sys . call ( " /etc/init.d/haveged stop " )
uci : set ( " fastd " , " ffhl_mesh_vpn " , " secret " , secret )
uci : save ( " fastd " )
uci : commit ( " fastd " )
2012-05-24 22:19:11 +02:00
end
2012-07-24 00:23:26 +02:00
luci.http . redirect ( luci.dispatcher . build_url ( " wizard " , " meshvpn " , " pubkey " ) )
else
nav.maybe_redirect_to_successor ( )
end
end
return true
2012-05-22 19:28:02 +02:00
end
return f