<%# Opennet Firmware Copyright 2010 Rene Ejury Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -%> <%+header%>

<%:Opennet ID%>

<%+cbi/apply_xhr%> <% local uci = require "luci.model.uci" local cursor = uci.cursor() local form_id = luci.http.formvalue("form_id") local on_id = cursor:get("on-core", "settings", "on_id") local devices = { "on_eth_", "on_wifi_" } if (form_id) then function split(str) local t = { } str:gsub("%d+", function (w) table.insert(t, w) end) return t end local t = split(form_id) local replace_id = false if #t == 1 then t[2] = t[1] t[1] = "1" replace_id = true elseif #t == 2 then replace_id = true elseif form_id:match("^(%d+)%.(%d+)%.(%d+)%.(%d+)$") then t[1] = t[3] t[2] = t[4] replace_id = true end if replace_id then on_ipschema = cursor:get("on-core", "defaults", "on_ipschema") on_netmask = cursor:get("on-core", "defaults", "on_netmask") local addrcount = 0 local on_base_address for index = 1, #devices do local count = 0 while (cursor:get_all("network", devices[index]..count)) do if (cursor:get("network", devices[index]..count, "ifname") ~= "none") then on_ipaddr = luci.sys.exec("on_id_1="..t[1].."; on_id_2="..t[2].."; no="..addrcount.."; eval echo "..on_ipschema) if addrcount == 0 then on_base_address = on_ipaddr end cursor:set("network", devices[index]..count, "proto", "static") cursor:set("network", devices[index]..count, "ipaddr", on_ipaddr) cursor:set("network", devices[index]..count, "netmask", on_netmask) addrcount = addrcount + 1 end count = count + 1 end end olsrd = cursor:get_all("olsrd") for k, v in pairs(olsrd) do if v.RtTableDefault then -- just to find the right section, it also contains RtTableDefault cursor:set("olsrd", k, "MainIp", on_base_address) break end end free_ipschema = cursor:get("on-wifidog", "defaults", "free_ipschema") free_netmask = cursor:get("on-wifidog", "defaults", "free_netmask") if free_ipschema then free_ipaddr = luci.sys.exec("on_id_1="..t[1].."; on_id_2="..t[2].."; no=0; eval echo "..free_ipschema) cursor:set("network", "free", "proto", "static") cursor:set("network", "free", "ipaddr", free_ipaddr) cursor:set("network", "free", "netmask", free_netmask) end redirects = cursor:get_all("firewall") for k, v in pairs(redirects) do if v.src == "opennet" and v.proto == "udp" and v.src_dport == "67" and v.target == "DNAT" and v.src_port == "67" then cursor:set("firewall", k, "dest_ip", free_ipaddr) cursor:set("firewall", k, "src_dip", on_base_address) end end cursor:set("on-core", "settings", "on_id", t[1].."."..t[2]) cursor:foreach("system", "system", function(s) cursor:set("system", s[".name"], "hostname", "AP-"..t[1].."-"..t[2]) end) cursor:commit("network") cursor:commit("firewall") cursor:commit("olsrd") cursor:commit("on-core") cursor:commit("system") configs = { "network", "olsrd", "firewall", "on-core", "system" } cbi_apply_xhr('uci-apply', configs) else form_id = on_id end else form_id = on_id end %>

<%:Opennet-ID / Network ID%>

<% print(luci.i18n.string([[Great that you decided to take part in Opennet. Get the address of you Access-Point yourself, make an entry in the Opennet-Wiki and aquire a free IP-Address. (Please take care of the information at Mitmachen).]])) %>

<% print(luci.i18n.string([[Please enter your Opennet-ID (1.X or 2.X etc.) or the IP-Address of your first Opennet-Network-Interface, any change will reconfigure your network settings immediately.]])) %>

<%:related network addresses%>

<% for index = 1, #devices do local count = 0 while (cursor:get_all("network", devices[index]..count)) do local v = cursor:get_all("network", devices[index]..count) %> <% count = count + 1 end end local free = cursor:get_all("network", "free") if free then %> <% end %>

<%=v[".name"]%>

<%=v.ipaddr%> / <%=v.netmask%>

<%=free[".name"]%>

<%=free.ipaddr%> / <%=free.netmask%>
<%+footer%>