From 2724aa14f35dd5ff44dd96b8bdb17965193d700c Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Sun, 27 Apr 2008 20:53:32 +0000 Subject: * Reworked Theme "Fledermaus" * Added Freifunk wizard * Added Freifunk iptables rules --- module/admin-core/contrib/init.d/luci_freifunk | 68 +++++++++++ module/admin-core/src/controller/admin/index.lua | 128 ++++++++++++++++++++- .../src/model/cbi/admin_index/freifunk.lua | 16 ++- module/admin-core/src/model/menu/00admin.lua | 1 + module/admin-core/src/view/admin_index/wizard.htm | 36 ++++++ module/admin-core/src/view/admin_system/ipkg.htm | 4 +- module/admin-core/src/view/admin_system/passwd.htm | 4 +- .../admin-core/src/view/admin_system/sshkeys.htm | 4 +- .../admin-core/src/view/admin_system/upgrade.htm | 4 +- 9 files changed, 253 insertions(+), 12 deletions(-) create mode 100644 module/admin-core/contrib/init.d/luci_freifunk create mode 100644 module/admin-core/src/view/admin_index/wizard.htm (limited to 'module/admin-core') diff --git a/module/admin-core/contrib/init.d/luci_freifunk b/module/admin-core/contrib/init.d/luci_freifunk new file mode 100644 index 0000000000..dbb346f0eb --- /dev/null +++ b/module/admin-core/contrib/init.d/luci_freifunk @@ -0,0 +1,68 @@ +#!/bin/sh /etc/rc.common +START=70 + +start() { + include /lib/network + scan_interfaces + + + ### Read interface names + config_get wanif wan ifname + config_get lanif lan ifname + config_get ffif ff ifname + + + [ -n "$ffif" ] || return 0 + + + ### Read from config + config_load freifunk + + config_get_bool internal routing internal + [ -n "$wanif" ] && config_get_bool internet routing internal + + + ### Freifunk to Freifunk + [ "$internal" -gt 0 ] && { + iptables -A forwarding_rule -i "$ffif" -o "$ffif" -j ACCEPT + } + + ### Lan to Freifunk + [ -n "$lanif" ] && { + iptables -A forwarding_rule -i "$lanif" -o "$ffif" -j ACCEPT + iptables -t nat -A postrouting_rule -i "$lanif" -o "$ffif" -j MASQUERADE + } + + ### Freifunk to Wan + [ "$internet" -gt 0 ] && { + iptables -A forwarding_rule -i "$ffif" -o "$wanif" -j ACCEPT + iptables -t nat -A postrouting_rule -i "$ffif" -o "$wanif" -j MASQUERADE + } +} + +stop() { + include /lib/network + scan_interfaces + + ### Read interface names + config_get wanif wan ifname + config_get lanif lan ifname + config_get ffif ff ifname + + [ -n "$ffif" ] || return 0 + + ### Freifunk to Freifunk + iptables -D forwarding_rule -i "$ffif" -o "$ffif" -j ACCEPT + + ### Lan to Freifunk + [ -n "$lanif" ] && { + iptables -D forwarding_rule -i "$lanif" -o "$ffif" -j ACCEPT + iptables -t nat -D postrouting_rule -i "$lanif" -o "$ffif" -j MASQUERADE + } + + ### Freifunk to Wan + [ -n "$wanif" -gt 0 ] && { + iptables -D forwarding_rule -i "$ffif" -o "$wanif" -j ACCEPT + iptables -t nat -D postrouting_rule -i "$ffif" -o "$wanif" -j MASQUERADE + } +} diff --git a/module/admin-core/src/controller/admin/index.lua b/module/admin-core/src/controller/admin/index.lua index b4a7720f8b..685478eddb 100644 --- a/module/admin-core/src/controller/admin/index.lua +++ b/module/admin-core/src/controller/admin/index.lua @@ -1 +1,127 @@ -module("ffluci.controller.admin.index", package.seeall) \ No newline at end of file +module("ffluci.controller.admin.index", package.seeall) + +function action_wizard() + if ffluci.http.formvalue("ip") then + return configure_freifunk() + end + + local ifaces = {} + local wldevs = ffluci.model.uci.show("wireless") + + if wldevs then + for k, v in pairs(wldevs.wireless) do + if v[".type"] == "wifi-device" then + table.insert(ifaces, k) + end + end + end + + ffluci.template.render("admin_index/wizard", {ifaces=ifaces}) +end + +function configure_freifunk() + local ip = ffluci.http.formvalue("ip") + local uci = ffluci.model.uci.Session() + + -- Configure FF-Interface + uci:del("network", "ff") + uci:del("network", "ffdhcp") + + uci:set("network", "ff", nil, "interface") + uci:set("network", "ff", "type", "bridge") + uci:set("network", "ff", "proto", "static") + uci:set("network", "ff", "ipaddr", ip) + uci:set("network", "ff", "netmask", uci:get("freifunk", "community", "mask")) + uci:set("network", "ff", "dns", uci:get("freifunk", "community", "dns")) + + -- Enable internal routing + uci:set("freifunk", "routing", "internal", "1") + + -- Enable internet routing + if ffluci.http.formvalue("shareinet") then + uci:set("freifunk", "routing", "internet", "1") + else + uci:set("freifunk", "routing", "internet", "0") + end + + -- Configure DHCP + if ffluci.http.formvalue("dhcp") then + local dhcpnet = uci:get("freifunk", "community", "dhcp"):match("^([0-9]+)") + local dhcpip = ip:gsub("^[0-9]+", dhcpnet) + + uci:set("network", "ffdhcp", nil, "interface") + uci:set("network", "ffdhcp", "proto", "static") + uci:set("network", "ffdhcp", "ifname", "br-ff:dhcp") + uci:set("network", "ffdhcp", "ipaddr", dhcpip) + uci:set("network", "ffdhcp", "netmask", uci:get("freifunk", "community", "dhcpmask")) + end + + -- Configure OLSR + if ffluci.http.formvalue("olsr") and uci:show("olsr") then + for k, v in pairs(uci:show("olsr").olsr) do + if v[".type"] == "Interface" or v[".type"] == "LoadPlugin" then + uci:del("olsr", "k") + end + end + + if ffluci.http.formvalue("shareinet") then + uci:set("olsr", "dyn_gw", nil, "LoadPlugin") + uci:set("olsr", "dyn_gw", "Library", "olsrd_dyn_gw.so.0.4") + end + + uci:set("olsr", "nameservice", nil, "LoadPlugin") + uci:set("olsr", "nameservice", "Library", "olsrd_nameservice.so.0.3") + uci:set("olsr", "nameservice", "name", ip:gsub("%.", "-")) + uci:set("olsr", "nameservice", "hosts_file", "/var/etc/hosts") + uci:set("olsr", "nameservice", "suffix", ".olsr") + uci:set("olsr", "nameservice", "latlon_infile", "/tmp/latlon.txt") + + uci:set("olsr", "txtinfo", nil, "LoadPlugin") + uci:set("olsr", "txtinfo", "Library", "olsrd_txtinfo.so.0.1") + uci:set("olsr", "txtinfo", "Accept", "127.0.0.1") + + local oif = uci:add("olsr", "Interface") + uci:set("olsr", oif, "Interface", "ff") + uci:set("olsr", oif, "HelloInterval", "6.0") + uci:set("olsr", oif, "HelloValidityTime", "108.0") + uci:set("olsr", oif, "TcInterval", "4.0") + uci:set("olsr", oif, "TcValidityTime", "324.0") + uci:set("olsr", oif, "MidInterval", "18.0") + uci:set("olsr", oif, "MidValidityTime", "324.0") + uci:set("olsr", oif, "HnaInterval", "18.0") + uci:set("olsr", oif, "HnaValidityTime", "108.0") + end + + -- Configure Wifi + local wifi = ffluci.http.formvalue("wifi") + local wcfg = uci:show("wireless") + if type(wifi) == "table" and wcfg then + for iface, v in pairs(wifi) do + if wcfg[iface] then + -- Cleanup + for k, v in pairs(wcfg.wireless) do + if v[".type"] == "wifi-iface" and v.device == iface then + uci:del("wireless", k) + end + end + + uci:set("wireless", iface, "disabled", "0") + uci:set("wireless", iface, "mode", "11g") + uci:set("wireless", iface, "txantenna", 1) + uci:set("wireless", iface, "rxantenna", 1) + uci:set("wireless", iface, "channel", uci:get("freifunk", "community", "channel")) + + local wif = uci:add("wireless", "wifi-iface") + uci:set("wireless", wif, "device", iface) + uci:set("wireless", wif, "network", "ff") + uci:set("wireless", wif, "mode", "adhoc") + uci:set("wireless", wif, "ssid", uci:get("freifunk", "community", "essid")) + uci:set("wireless", wif, "bssid", uci:get("freifunk", "community", "bssid")) + uci:set("wireless", wif, "txpower", 13) + end + end + end + + + ffluci.http.request_redirect("admin", "uci", "changes") +end \ No newline at end of file diff --git a/module/admin-core/src/model/cbi/admin_index/freifunk.lua b/module/admin-core/src/model/cbi/admin_index/freifunk.lua index 64e916f32b..ec4d100b87 100644 --- a/module/admin-core/src/model/cbi/admin_index/freifunk.lua +++ b/module/admin-core/src/model/cbi/admin_index/freifunk.lua @@ -1,13 +1,23 @@ -- Todo: Translate -m = Map("freifunk", "Freifunk", [[Informationen über die lokale Freifunkgemeinschaft.]]) +m = Map("freifunk", "Freifunk") -c = m:section(NamedSection, "community", "public") +s = m:section(NamedSection, "routing", "settings", "Netzverkehr") +s:option(Flag, "internal", "Freifunk zulassen", "immer aktivieren!") +s:option(Flag, "internet", "Internet zulassen") +c = m:section(NamedSection, "community", "public", "Gemeinschaft", [[Dies sind die Grundeinstellungen +für die lokale Freifunkgemeinschaft. Diese Werte wirken sich NICHT auf die Konfiguration +des Routers aus, sondern definieren nur die Vorgaben für den Freifunkassistenten.]]) c:option(Value, "name", "Gemeinschaft") c:option(Value, "homepage", "Webseite") c:option(Value, "essid", "ESSID") c:option(Value, "bssid", "BSSID") +c:option(Value, "channel", "Funkkanal") c:option(Value, "realm", "Realm") -c:option(Value, "pool", "Adressbereich") +c:option(Value, "net", "Adressbereich") +c:option(Value, "mask", "Netzmaske") +c:option(Value, "dns", "DNS-Server") +c:option(Value, "dhcp", "DHCP-Bereich") +c:option(Value, "dhcpmask", "DHCP-Maske") return m \ No newline at end of file diff --git a/module/admin-core/src/model/menu/00admin.lua b/module/admin-core/src/model/menu/00admin.lua index 7d56b8b545..8f87792cad 100644 --- a/module/admin-core/src/model/menu/00admin.lua +++ b/module/admin-core/src/model/menu/00admin.lua @@ -1,4 +1,5 @@ add("admin", "index", "Übersicht", 10) +act("wizard", "Freifunkassistent") act("contact", "Kontakt") act("luci", "Oberfläche") act("freifunk", "Freifunk") diff --git a/module/admin-core/src/view/admin_index/wizard.htm b/module/admin-core/src/view/admin_index/wizard.htm new file mode 100644 index 0000000000..8c1a0952be --- /dev/null +++ b/module/admin-core/src/view/admin_index/wizard.htm @@ -0,0 +1,36 @@ +<%+header%> +

<%:ffwizard Freifunkassistent%>

+

<%:ffwizard1 Dieser Assistent konfiguriert den Router für die Benutzung im Freifunknetz%>

+
+
+
+
+
<%:ip IP-Adresse%>:  +
+
+ <% for i, k in ipairs(ifaces) do %> +
+
<%:wificfg Drahtlosgerät einrichten%>: <%=k%>
+
+
+ <% end %> +
+
<%:cfgolsr OLSR konfigurieren%>
+
+
+
+
<%:cfgdhcp Drahtlos DHCP konfigurieren%>
+
+
+
+
<%:shareinet Internet teilen%>
+
+
+
+
+
+ + +
+
+<%+footer%> \ No newline at end of file diff --git a/module/admin-core/src/view/admin_system/ipkg.htm b/module/admin-core/src/view/admin_system/ipkg.htm index c1f6ad0be9..a385e8327e 100644 --- a/module/admin-core/src/view/admin_system/ipkg.htm +++ b/module/admin-core/src/view/admin_system/ipkg.htm @@ -10,7 +10,7 @@
-
+

@@ -18,6 +18,6 @@
<% if msg then %>
<%:error Fehler%>: <%=msg%>
<% end %> -
+
<%+footer%> \ No newline at end of file diff --git a/module/admin-core/src/view/admin_system/passwd.htm b/module/admin-core/src/view/admin_system/passwd.htm index e736204bba..10a079945e 100644 --- a/module/admin-core/src/view/admin_system/passwd.htm +++ b/module/admin-core/src/view/admin_system/passwd.htm @@ -14,7 +14,7 @@ <% end %> <% if not stat or stat == 10 then %>
-
+
<%:password Passwort%>
@@ -28,7 +28,7 @@
-
+
<% end %> diff --git a/module/admin-core/src/view/admin_system/sshkeys.htm b/module/admin-core/src/view/admin_system/sshkeys.htm index 9cf91f998c..ad80b63f0e 100644 --- a/module/admin-core/src/view/admin_system/sshkeys.htm +++ b/module/admin-core/src/view/admin_system/sshkeys.htm @@ -10,7 +10,7 @@
-
+

@@ -18,6 +18,6 @@
<% if msg then %>
<%:error Fehler%>: <%=msg%>
<% end %> -
+
<%+footer%> \ No newline at end of file diff --git a/module/admin-core/src/view/admin_system/upgrade.htm b/module/admin-core/src/view/admin_system/upgrade.htm index 35f2e81417..5980028900 100644 --- a/module/admin-core/src/view/admin_system/upgrade.htm +++ b/module/admin-core/src/view/admin_system/upgrade.htm @@ -6,7 +6,7 @@ Das Format der Firmware ist plattformabhängig.%>


<% if sysupgrade and not ret then %>
-
+
<%:fwimage Firmwareimage%>
@@ -20,7 +20,7 @@ Das Format der Firmware ist plattformabhängig.%>

-
+
<% elseif ret then %> <% if ret == 0 then %> -- cgit v1.2.3