applications/luci-ffwizard: initial

This commit is contained in:
Patrick Grimm 2011-01-09 17:18:07 +00:00
parent ea7a4bee18
commit 3010388ce9
9 changed files with 1974 additions and 0 deletions

View file

@ -0,0 +1,4 @@
PO =
include ../../build/config.mk
include ../../build/module.mk

View file

@ -0,0 +1,20 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<head>
<title>OpenStreetMap</title>
<script type="text/javascript" src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript" src="http://www.openstreetmap.org/openlayers/OpenStreetMap.js"></script>
<script type="text/javascript" src="osm.js"></script>
</head>
<body onload="init();drawmap();" style="padding:0px; margin:0px">
<div id="map"></div>
<div style="position:absolute; bottom:0%; width:100%; background:url('cbi/black_60.png'); font-size:10px; color:#fff;z-index:1000">
Map by <a href="http://www.openstreetmap.org" title="www.openstreetmap.org" style="color:#fff;" >openstreetmap.org</a>, License CC-BY-SA
&nbsp;&nbsp;&nbsp;&nbsp;
<span id="osm">
Latitude: <input id="osmlat" name="osmlat" type="text" size="20" style="font-size:10px;">
Longitude: <input id="osmlon" name="osmlon" type="text" size="20" style="font-size:10px;">
</span>
</div>
</body>

View file

@ -0,0 +1,130 @@
var map;
var layer_mapnik;
var layer_tah;
var layer_markers;
var PI = Math.PI;
var latfield = '';
var lonfield = '';
var latfield_id='';
var lonfield_id='';
var centerlon = 10;
var centerlat = 52;
var zoom = 6;
function lon2merc(lon) {
return 20037508.34 * lon / 180;
}
function lat2merc(lat) {
lat = Math.log(Math.tan( (90 + lat) * PI / 360)) / PI;
return 20037508.34 * lat;
}
function merc2lon(lon) {
return lon*180/20037508.34;
};
function merc2lat(lat) {
return Math.atan(Math.exp(lat*PI/20037508.34))*360/PI-90;
};
OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
defaultHandlerOptions: {
'single': true,
'double': false,
'pixelTolerance': 0,
'stopSingle': false,
'stopDouble': false
},
initialize: function(options) {
this.handlerOptions = OpenLayers.Util.extend(
{}, this.defaultHandlerOptions
);
OpenLayers.Control.prototype.initialize.apply(
this, arguments
);
this.handler = new OpenLayers.Handler.Click(
this, {
'click': this.trigger
}, this.handlerOptions
);
},
trigger: function(e) {
var lonlat = map.getLonLatFromViewPortPx(e.xy);
lat=merc2lat(lonlat.lat);
lon=merc2lon(lonlat.lon);
if(parent.document.getElementById(latfield_id)==null){
latfield=document.getElementById('osmlat');
}else{
latfield=parent.document.getElementById(latfield_id);
}
if(parent.document.getElementById(lonfield_id)==null){
lonfield=document.getElementById('osmlon');
}else{
lonfield=parent.document.getElementById(lonfield_id);
}
latfield.value = lat;
lonfield.value = lon;
}
});
function init(){
var field = window.name.substring(0, window.name.lastIndexOf("."));
if(parent.document.getElementById(field+".latfield")!=null){
latfield_id = parent.document.getElementById(field+".latfield").value;
document.getElementById('osm').style.display="none";
}
if(parent.document.getElementById(field+".lonfield")!=null){
lonfield_id = parent.document.getElementById(field+".lonfield").value;
}
if(parent.document.getElementById(field+".centerlat")!=null){
centerlat =parseFloat(parent.document.getElementById(field+".centerlat").value);
}
if(parent.document.getElementById(field+".centerlon")!=null){
centerlon = parseFloat(parent.document.getElementById(field+".centerlon").value);
}
if(parent.document.getElementById(field+".zoom")!=null){
zoom = parseFloat(parent.document.getElementById(field+".zoom").value);
}
}
function drawmap() {
OpenLayers.Lang.setCode('de');
mapdiv=document.getElementById('map');
mapdiv.style.height=window.innerHeight+"px";
mapdiv.style.width=window.innerWidth+"px";
map = new OpenLayers.Map('map', {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
controls: [
new OpenLayers.Control.MouseDefaults(),
new OpenLayers.Control.PanZoomBar()],
maxExtent:
new OpenLayers.Bounds(-20037508.34,-20037508.34, 20037508.34, 20037508.34),
numZoomLevels: 18,
maxResolution: 156543,
units: 'meters'
});
layer_mapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
map.addLayers([layer_mapnik]);
var y =lat2merc(centerlat);
var x =lon2merc(centerlon);
map.setCenter(new OpenLayers.LonLat(x, y), zoom);
// Check for geolocation support
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
var y =lat2merc(position.coords.latitude);
var x =lon2merc(position.coords.longitude);
map.setCenter(new OpenLayers.LonLat(x, y), '17');
});
}
var click = new OpenLayers.Control.Click();
map.addControl(click);
click.activate();
}

View file

@ -0,0 +1,23 @@
--[[
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
Copyright 2011 Patrick Grimm <patrick@pberg.freifunk.net>
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
$Id$
]]--
module "luci.controller.ffwizard"
function index()
entry({"admin", "freifunk", "ffwizard"}, form("ffwizard"), "Freifunkassistent", 1)
assign({"mini", "freifunk", "ffwizard"}, {"admin", "freifunk", "ffwizard"}, "Freifunkassistent", 1)
end

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,149 @@
--[[
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
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
$Id$
]]--
local uci = require "luci.model.uci"
local util = require "luci.util"
local table = require "table"
local type = type
module "luci.tools.ffwizard"
-- Deletes all references of a wifi device
function wifi_delete_ifaces(device)
local cursor = uci.cursor()
cursor:delete_all("wireless", "wifi-iface", {device=device})
cursor:save("wireless")
end
-- Deletes a network interface and all occurences of it in firewall zones and dhcp
function network_remove_interface(iface)
local cursor = uci.cursor()
if not cursor:delete("network", iface) then
return false
end
local aliases = {iface}
cursor:foreach("network", "alias",
function(section)
if section.interface == iface then
table.insert(aliases, section[".name"])
end
end)
-- Delete Aliases and Routes
cursor:delete_all("network", "route", {interface=iface})
cursor:delete_all("network", "alias", {interface=iface})
-- Delete DHCP sections
cursor:delete_all("dhcp", "dhcp",
function(section)
return util.contains(aliases, section.interface)
end)
-- Remove OLSR sections
cursor:delete_all("olsrd", "Interface", {Interface=iface})
-- Remove Splash sections
cursor:delete_all("luci-splash", "iface", {network=iface})
cursor:save("network")
cursor:save("olsr")
cursor:save("dhcp")
cursor:save("luci-splash")
end
-- Creates a firewall zone
function firewall_create_zone(zone, input, output, forward, masq)
local cursor = uci.cursor()
if not firewall_find_zone(zone) then
local stat = cursor:section("firewall", "zone", nil, {
input = input,
output = output,
forward = forward,
masq = masq and "1",
name = zone
})
cursor:save("firewall")
return stat
end
end
-- Adds interface to zone, creates zone on-demand
function firewall_zone_add_interface(name, interface)
local cursor = uci.cursor()
local zone = firewall_find_zone(name)
local net = cursor:get("firewall", zone, "network")
local old = net or (cursor:get("network", name) and name)
cursor:set("firewall", zone, "network", (old and old .. " " or "") .. interface)
cursor:save("firewall")
end
-- Removes interface from zone
function firewall_zone_remove_interface(name, interface)
local cursor = uci.cursor()
local zone = firewall_find_zone(name)
if zone then
local net = cursor:get("firewall", zone, "network")
local new = remove_list_entry(net, interface)
if new then
if #new > 0 then
cursor:set("firewall", zone, "network", new)
else
cursor:delete("firewall", zone, "network")
end
cursor:save("firewall")
end
end
end
-- Finds the firewall zone with given name
function firewall_find_zone(name)
local find
uci.cursor():foreach("firewall", "zone",
function (section)
if section.name == name then
find = section[".name"]
end
end)
return find
end
-- Helpers --
-- Removes a listentry, handles real and pseduo lists transparently
function remove_list_entry(value, entry)
if type(value) == "nil" then
return nil
end
local result = type(value) == "table" and value or util.split(value, " ")
local key = util.contains(result, entry)
while key do
table.remove(result, key)
key = util.contains(result, entry)
end
result = type(value) == "table" and result or table.concat(result, " ")
return result ~= value and result
end

View file

@ -0,0 +1,116 @@
<%#
cc-by-sa Andreas Pittrich <andreas.pittrich@web.de>
in behalf of the german pirate party (Piratenpartei)
www.piratenpartei.de
$Id$
-%>
<%+cbi/valueheader%>
<script type="text/javascript">
function set_lat_lon() {
var net
var entry
var lon
var lat
var zoom
net = document.getElementById('cbid.ffwizward.1.net').value;
if (!net){
return
}
lon = document.getElementById('cbid.ffwizward.1.latlon.centerlon');
lat = document.getElementById('cbid.ffwizward.1.latlon.centerlat');
zoom = document.getElementById('cbid.ffwizward.1.latlon.zoom');
if ( !lon.value || lon.value == '' || lon.value == 0 || lon.value == 10 ) {
for ( var i = 0 ; true ; i++ ) {
if (i == cbi_d.length) {
break;
}
if (cbi_d[i].id == 'cbi-ffwizward-1-net_lon') {
entry = cbi_d[i];
for (var j=0; true; j++) {
if ( entry.node.children[0].children[j] ){
if ( entry.node.children[0].children[j].value == net ) {
lon.value = entry.node.children[0].children[j].text;
zoom.value = '14';
break;
}
} else {
break;
}
}
break;
}
}
}
if ( !lat.value || lat.value == '' || lat.value == 0 || lat.value == 52 ) {
for (var i=0; true; i++) {
if (i == cbi_d.length) {
break;
}
if (cbi_d[i].id == 'cbi-ffwizward-1-net_lat') {
entry = cbi_d[i];
for (var j=0; true; j++) {
if ( entry.node.children[0].children[j] ){
if ( entry.node.children[0].children[j].value == net ) {
lat.value = entry.node.children[0].children[j].text;
break;
}
} else {
break;
}
}
break;
}
}
}
}
</script>
<% if self:cfgvalue(section) ~= false then %>
<% if self.latfield and self.lonfield then %>
<input type="hidden" <%= attr("value", string.format('cbid.%s.%s.%s', self.config, section, self.latfield))..attr("id", cbid..".latfield")..attr("name", cbid..".latfield")%>/>
<input type="hidden" <%= attr("value", string.format('cbid.%s.%s.%s', self.config, section, self.lonfield))..attr("id", cbid..".lonfield")..attr("name", cbid..".lonfield")%>/>
<% end %>
<input type="hidden" <%= attr("value", self.centerlat)..attr("id", cbid..".centerlat")..attr("name", cbid..".centerlat")%>/>
<input type="hidden" <%= attr("value", self.centerlon)..attr("id", cbid..".centerlon")..attr("name", cbid..".centerlon")%>/>
<input type="hidden" <%= attr("value", self.zoom)..attr("id", cbid..".zoom")..attr("name", cbid..".zoom")%>/>
<% end %>
<% if self.popup then %>
<input class="cbi-input-button" type="button"<%= attr("name", cbid..".button")..attr("id", cbid..".button")..attr("value", self.displaytext)%>
onclick="
popup=window.open('/luci-static/resources/OSMLatLon.htm', '<%=cbid%>.window', 'innerWidth=<%=self.width%>, innerHeight=<%=self.height%>, location=no, menubar=no, scrollbars=no, status=no, toolbar=no');
popup.focus();
"
/>
</div>
<div>
<% else %>
<input class="cbi-input-button" type="button"<%= attr("name", cbid..".displayosm")..attr("id", cbid..".displayosm")..attr("value", self.displaytext)%>
onclick="
set_lat_lon();
document.getElementById('<%=cbid..".hideosm"%>').style.display='inline';
document.getElementById('<%=cbid..".displayosm"%>').style.display='none';
for(var i = 0; Math.min(i, window.frames.length)!=window.frames.lengths; i++){
if(frames[i].name=='<%=cbid..".iframe"%>'){
document.getElementById('<%=cbid..".iframediv"%>').style.display='block';
frames[i].location.href='/luci-static/resources/OSMLatLon.htm';
}
}
"
/>
<input class="cbi-input-button" style="display:none" type="button"<%= attr("name", cbid..".hideosm")..attr("id", cbid..".hideosm")..attr("value", self.hidetext)%>
onclick="
document.getElementById('<%=cbid..".displayosm"%>').style.display='inline';
document.getElementById('<%=cbid..".hideosm"%>').style.display='none';
document.getElementById('<%=cbid..".iframediv"%>').style.display='none';
"
/>
</div>
<div class="cbi-value-osmiframesection" id="<%=cbid..".iframediv"%>" style="display:none">
<iframe src="" <%= attr("id", cbid..".iframe")..attr("name", cbid..".iframe")..attr("width", self.width)..attr("height", self.height)%> frameborder="0" scrolling="no"></iframe>
<%end%>
<%+cbi/valuefooter%>

View file

@ -0,0 +1,80 @@
#!/bin/sh
set_default_config()
{
local cfg="$1"
config_get type "$cfg" "type"
case $type in
atheros)
uci set freifunk.wifi_device.channel=1
uci set freifunk.wifi_device.diversity=0
uci set freifunk.wifi_device.txantenna=1
uci set freifunk.wifi_device.rxantenna=1
uci set freifunk.wifi_device.disabled=0
uci set freifunk.wifi_device.txpower=""
uci set freifunk.wifi_device.country=276
uci set freifunk.wifi_device.regdomain="0x37"
uci set freifunk.wifi_device.outdoor="1"
uci set freifunk.wifi_device.hwmode=11g
uci set freifunk.wifi_device.distance=1000
uci set freifunk.wifi_iface=defaults
uci set freifunk.wifi_iface.mode=adhoc
uci set freifunk.wifi_iface.bssid="02:CA:FF:EE:BA:BE"
uci set freifunk.wifi_iface.sw_merge=1
uci set freifunk.wifi_iface.mcast_rate=5500
uci set freifunk.wifi_iface.probereq=1
uci commit freifunk
;;
mac80211)
uci set freifunk.wifi_device.channel=1
uci set freifunk.wifi_device.diversity=""
uci set freifunk.wifi_device.disabled=0
uci set freifunk.wifi_device.txpower=""
uci set freifunk.wifi_device.country=DE
uci set freifunk.wifi_device.distance=1000
uci set freifunk.wifi_device.htmode='HT40-'
uci set freifunk.wifi_device.hwmode=11ng
uci set freifunk.wifi_iface=defaults
uci set freifunk.wifi_iface.mode=adhoc
uci set freifunk.wifi_iface.bssid="02:CA:FF:EE:BA:BE"
uci set freifunk.wifi_iface.sw_merge=""
uci commit freifunk
;;
broadcom)
uci set freifunk.wifi_device.channel=1
uci set freifunk.wifi_device.diversity=""
uci set freifunk.wifi_device.disabled=0
uci set freifunk.wifi_device.txpower=""
uci set freifunk.wifi_device.country=DE
uci set freifunk.wifi_device.txantenna=0
uci set freifunk.wifi_device.rxantenna=0
uci set freifunk.wifi_device.hwmode=11g
uci set freifunk.wifi_device.distance=1000
uci set freifunk.wifi_iface=defaults
uci set freifunk.wifi_iface.encryption=none
uci set freifunk.wifi_iface.mode=adhoc
uci set freifunk.wifi_iface.bssid="02:CA:FF:EE:BA:BE"
uci set freifunk.wifi_iface.sw_merge=""
uci commit freifunk
;;
esac
}
(
while true ; do
sleep 30
wifie=0
config_load wireless && wifie=1
if [ $wifie -eq 1 ] ; then
config_foreach set_default_config wifi-device
uci set freifunk.interface.dns="88.198.178.18 141.54.1.1 212.204.49.83 8.8.8.8 8.8.4.4"
uci commit freifunk
exit 0
fi
done
) >/dev/null &

View file

@ -321,6 +321,9 @@ endef
$(eval $(call application,ffwizard-leipzig,Freifunk Leipzig configuration wizard))
$(eval $(call application,ffwizard,Freifunk configuration wizard,
+PACKAGE_luci-mod-freifunk))
$(eval $(call application,siitwizard,SIIT IPv4-over-IPv6 configuration wizard,\
+PACKAGE_luci-app-siitwizard:kmod-siit))