diff --git a/webgui/luci/Makefile b/webgui/luci/Makefile new file mode 100644 index 000000000..f7fac7740 --- /dev/null +++ b/webgui/luci/Makefile @@ -0,0 +1,2 @@ +include ../../build/config.mk +include ../../build/module.mk diff --git a/webgui/luci/community-profiles/Makefile b/webgui/luci/community-profiles/Makefile new file mode 100644 index 000000000..3129a3678 --- /dev/null +++ b/webgui/luci/community-profiles/Makefile @@ -0,0 +1,39 @@ +# Copyright (C) 2011 Manuel Munz +# This is free software, licensed under the Apache 2.0 license. + +include $(TOPDIR)/rules.mk + +PKG_NAME:=community-profiles +PKG_RELEASE:=1 + +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) + +include $(INCLUDE_DIR)/package.mk + +define Package/community-profiles + SECTION:=luci + CATEGORY:=LuCI + SUBMENU:=9. Freifunk + TITLE:=Community profiles + DEPENDS:=freifunk-common +endef + +define Package/community-profiles/description + These community profiles set defaults for various free network/freifunk communities and are used by wizards like ffwizard and meshwizard. +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) +endef + +define Build/Configure +endef + +define Build/Compile +endef + +define Package/community-profiles/install + $(CP) ./files/* $(1)/ +endef + +$(eval $(call BuildPackage,community-profiles)) diff --git a/webgui/luci/community-profiles/files/etc/config/profile_Freifunk b/webgui/luci/community-profiles/files/etc/config/profile_Freifunk new file mode 100644 index 000000000..b8f445a73 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_Freifunk @@ -0,0 +1,10 @@ +config 'community' 'profile' + option 'name' 'Freifunk' + option 'homepage' 'http://freifunk.net' + option 'ssid' 'www.freifunk.net' + option 'splash_network' '10.104.0.0/16' + option 'latitude' '52.000' + option 'longitude' '10.000' + option 'splash_prefix' '28' + option 'mesh_network' '10.0.0.0/8' + diff --git a/webgui/luci/community-profiles/files/etc/config/profile_aachen b/webgui/luci/community-profiles/files/etc/config/profile_aachen new file mode 100644 index 000000000..cc643e131 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_aachen @@ -0,0 +1,10 @@ +config 'community' 'profile' + option 'name' 'Aachen' + option 'homepage' 'http://aachen.freifunk.net' + option 'ssid' 'aachen.freifunk.net' + option 'suffix' 'ffac' + option 'latitude' '50.77900' + option 'longitude' '6.05399' + option 'mesh_network' '10.90.0.0/16' + option 'splash_network' '10.104.0.0/16' + option 'splash_prefix' '28' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_augsburg b/webgui/luci/community-profiles/files/etc/config/profile_augsburg new file mode 100644 index 000000000..d31558585 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_augsburg @@ -0,0 +1,18 @@ +config 'community' 'profile' + option 'name' 'Freifunk Augsburg' + option 'homepage' 'http://augsburg.freifunk.net' + option 'ssid' 'augsburg.freifunk.net' + option 'mesh_network' '10.11.0.0/18' + option 'splash_network' '10.104.0.0/16' + option 'latitude' '48.37071' + option 'longitude' '10.89475' + option 'suffix' 'ffa' + option 'splash_prefix' '27' + +config 'defaults' 'interface' + option 'netmask' '255.255.192.0' + +config 'defaults' 'bssidscheme' + option '1' '02:CA:FF:EE:BA:BE' + option '13' '13:CA:FF:EE:BA:BE' + diff --git a/webgui/luci/community-profiles/files/etc/config/profile_bayreuth b/webgui/luci/community-profiles/files/etc/config/profile_bayreuth new file mode 100644 index 000000000..90fccbd81 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_bayreuth @@ -0,0 +1,20 @@ +config 'community' 'profile' + option 'name' 'Freifunk Bayreuth' + option 'homepage' 'http://bayreuth.freifunk.net' + option 'ssid' 'bayreuth.freifunk.net' + option 'mesh_network' '10.195.0.0/16' + option 'splash_network' '10.104.0.0/16' + option 'latitude' '49.945812' + option 'longitude' '11.575045' + option 'suffix' 'ffbt' + option 'splash_prefix' '28' + +config 'defaults' 'interface' + option 'netmask' '255.255.192.0' + +config 'defaults' 'wifi_device' + option 'channel' '4' + +config 'defaults' 'wifi_iface' + option 'bssid' '42:CA:FF:EE:BA:BE' + diff --git a/webgui/luci/community-profiles/files/etc/config/profile_bensheim b/webgui/luci/community-profiles/files/etc/config/profile_bensheim new file mode 100644 index 000000000..48c1d47b7 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_bensheim @@ -0,0 +1,9 @@ +config 'community' 'profile' + option 'name' 'Freifunk Bensheim' + option 'homepage' 'http://bensheim.freifunk.net' + option 'ssid' 'bensheim.freifunk.net' + option 'mesh_network' '10.49.0.0/16' + option 'splash_network' '10.104.0.0/16' + option 'splash_prefix' '27' + option 'latitude' '49.63939' + option 'longitude' '8.633718' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_bergischesland b/webgui/luci/community-profiles/files/etc/config/profile_bergischesland new file mode 100644 index 000000000..0de454303 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_bergischesland @@ -0,0 +1,15 @@ +config 'community' 'profile' + option 'name' 'Piratenfreifunk Bergisches Land' + option 'homepage' 'http://www.piraten-bergisches-land.de' + option 'ssid' 'PiratenfunkBL' + option 'mesh_network' '10.3.0.0/16' + option 'splash_network' '192.168.0.0/16' + option 'splash_prefix' '27' + option 'latitude' '51.26849' + option 'longitude' '7.19476' + +config 'defaults' 'wifi_device' + option 'channel' '11' + +config 'defaults' 'wifi_iface' + option 'bssid' '02:40:00:42:42:42' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_berlin b/webgui/luci/community-profiles/files/etc/config/profile_berlin new file mode 100644 index 000000000..c41144e48 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_berlin @@ -0,0 +1,16 @@ +config 'community' 'profile' + option 'name' 'Freifunk Berlin' + option 'homepage' 'http://berlin.freifunk.net' + option 'ssid' 'olsr.freifunk.net' + option 'mesh_network' '104.0.0.0/8' + option 'splash_network' '10.104.0.0/16' + option 'splash_prefix' '27' + option 'latitude' '52.52075' + option 'longitude' '13.40948' + +config 'defaults' 'wifi_device' + option 'channel' '10' + +config 'defaults' 'interface' + option 'netmask' '255.0.0.0' + diff --git a/webgui/luci/community-profiles/files/etc/config/profile_carbodebit b/webgui/luci/community-profiles/files/etc/config/profile_carbodebit new file mode 100644 index 000000000..0b263f9c0 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_carbodebit @@ -0,0 +1,23 @@ +config 'community' 'profile' + option 'name' 'carbodebit' + option 'homepage' 'http://carbodebit.net' + option 'ssid' 'VHDCARBES' + option 'mesh_network' '10.72.1.0/24' + option 'latitude' '43.633683' + option 'longitude' '2.160894' + +config 'defaults' 'wifi_iface' + option 'bssid' 'DE:78:70:E4:FA:B8' + +config 'defaults' 'interface' + option 'netmask' '255.255.255.0' + option 'dns' '10.70.1.1 213.190.64.170 213.190.64.166' + +config 'defaults' 'wifi_device' + option 'channel' '11' + option 'country' 'FR' + option 'distance' '2000' + +config 'defaults' 'bssidscheme' + option 'all' 'DE:78:70:E4:FA:B8' + diff --git a/webgui/luci/community-profiles/files/etc/config/profile_duesseldorf b/webgui/luci/community-profiles/files/etc/config/profile_duesseldorf new file mode 100644 index 000000000..cb36aabf6 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_duesseldorf @@ -0,0 +1,15 @@ +config 'community' 'profile' + option 'name' 'Freifunk Duesseldorf' + option 'homepage' 'http://freifunk-duesseldorf.de' + option 'ssid' 'duesseldorf.freifunk.net' + option 'mesh_network' '10.40.0.0/16' + option 'splash_network' '10.104.0.0/16' + option 'splash_prefix' '27' + option 'latitude' '51.217812' + option 'longitude' '6.761564' + +config 'defaults' 'wifi_device' + option 'channel' '3' + +config 'defaults' 'wifi_iface' + option 'bssid' '02:CA:FF:EE:BA:BE' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_evernet b/webgui/luci/community-profiles/files/etc/config/profile_evernet new file mode 100644 index 000000000..05453608d --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_evernet @@ -0,0 +1,25 @@ +config 'community' 'profile' + option 'name' 'Freifunk Evernet eG' + option 'homepage' 'http://www.evernet-eg.de' + option 'ssid' 'evernet.freifunk.net' + option 'mesh_network' '10.0.0.0/8' + option 'latitude' '51.15692062509162' + option 'longitude' '10.716041922569275' + option 'suffix' 'evernet' + +config 'defaults' 'interface' + option 'netmask' '255.0.0.0' + +config 'defaults' 'bssidscheme' + option 'all' '02:CA:FF:EE:BA:BE' + +config 'defaults' 'wifi_device' + option 'channel' '13' + option 'country' 'DE' + option 'txpower' '19' + option 'beacon_int' '5000' + option 'distance' '1500' + option 'noscan' '0' + +config 'defaults' 'wifi_iface' + option 'mcast_rate' '6000' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_franken b/webgui/luci/community-profiles/files/etc/config/profile_franken new file mode 100644 index 000000000..e3761a665 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_franken @@ -0,0 +1,19 @@ +config 'community' 'profile' + option 'name' 'Freifunk Franken' + option 'homepage' 'http://franken.freifunk.net' + option 'ssid' 'franken.freifunk.net' + option 'mesh_network' '10.50.0.0/16' + option 'splash_network' '10.104.0.0/16' + option 'latitude' '49.506485' + option 'longitude' '11.013565# + option 'splash_prefix' '27' + +config 'defaults' 'interface' + option 'netmask' '255.255.0.0' + +config 'defaults' 'bssidscheme' + option '1' '02:CA:FF:EE:BA:BE' + +config 'defaults' 'luci_splash' + option 'limit_up' '40' + option 'limit_down' '40' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_gadow b/webgui/luci/community-profiles/files/etc/config/profile_gadow new file mode 100644 index 000000000..79466f181 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_gadow @@ -0,0 +1,15 @@ +config 'community' 'profile' + option 'name' 'Freifunk Gadow' + option 'homepage' 'http://gadow.freifunk.net' + option 'ssid' 'gadow.freifunk.net' + option 'mesh_network' '104.0.0.0/8' + option 'splash_network' '10.61.0.0/16' + option 'splash_prefix' '27' + option 'latitude' '53.11' + option 'longitude' '12.61' + +config 'defaults' 'interface' + option 'netmask' '255.0.0.0' + +config 'defaults' 'bssidscheme' + option '1' '02:CA:FF:EE:BA:BE' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_guifibages b/webgui/luci/community-profiles/files/etc/config/profile_guifibages new file mode 100644 index 000000000..a0fc4fc1e --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_guifibages @@ -0,0 +1,19 @@ +config 'community' 'profile' + option 'name' 'Guifi Bages' + option 'homepage' 'http://guifi.net/PlaBages' + option 'ssid' 'guifibages' + option 'mesh_network' '10.224.3.0/16' + option 'splash_network' '10.104.0.0/16' + option 'theme' 'luci-theme-freifunk-generic' + option 'latitude' '41.718437' + option 'longitude' '1.826477' + option 'suffix' 'guifibages.cat' + option 'splash_prefix' '27' + option 'extrapackages' 'luci-app-olsr-viz luci-i18n-catalan' + +config 'defaults' 'interface' + option 'netmask' '255.255.0.0' + +config 'defaults' 'bssidscheme' + option 'all' '12:34:56:78:9a:bc' + diff --git a/webgui/luci/community-profiles/files/etc/config/profile_halle b/webgui/luci/community-profiles/files/etc/config/profile_halle new file mode 100644 index 000000000..559d58141 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_halle @@ -0,0 +1,17 @@ +config 'community' 'profile' + option 'name' 'Freifunk Halle' + option 'homepage' 'http://freifunk-halle.net' + option 'ssid' 'halle.freifunk.net' + option 'mesh_network' '104.62.0.0/16' + option 'splash_network' '10.104.0.0/16' + option 'splash_prefix' '27' + option 'latitude' '51.47911' + option 'longitude' '11.96901' + +config 'defaults' 'wifi_device' + option 'channel' '13' + +config 'defaults' 'bssidscheme' + option 'all' '02:CA:FF:EE:BA:BE' + + diff --git a/webgui/luci/community-profiles/files/etc/config/profile_hamburg b/webgui/luci/community-profiles/files/etc/config/profile_hamburg new file mode 100644 index 000000000..ba1dd2170 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_hamburg @@ -0,0 +1,15 @@ +config 'community' 'profile' + option 'name' 'Freifunk Hamburg' + option 'homepage' 'http://hamburg.piratenpartei.de' + option 'ssid' 'hamburg.freifunk.net' + option 'mesh_network' '10.112.0.0/12' + option 'splash_network' '10.104.0.0/16' + option 'splash_prefix' '27' + option 'latitude' '53.56262' + option 'longitude' '10.01069' + +config 'defaults' 'interface' + option 'netmask' '255.240.0.0' + +config 'defaults' 'wifi_device' + option 'channel' '1' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_hannover b/webgui/luci/community-profiles/files/etc/config/profile_hannover new file mode 100644 index 000000000..008b6c70e --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_hannover @@ -0,0 +1,12 @@ +config 'community' 'profile' + option 'name' 'Freifunk Hannover' + option 'homepage' 'http://hannover.freifunk.net' + option 'ssid' 'hannover.freifunk.net' + option 'mesh_network' '10.2.0.0/16' + option 'splash_network' '10.104.0.0/16' + option 'splash_prefix' '27' + option 'latitude' '52.38427' + option 'longitude' '9.74359' + +config 'defaults' 'wifi_iface' + option 'bssid' 'CA:FF:EE:CA:FF:EE' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_heppenheim b/webgui/luci/community-profiles/files/etc/config/profile_heppenheim new file mode 100644 index 000000000..a8304946b --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_heppenheim @@ -0,0 +1,9 @@ +config 'community' 'profile' + option 'name' 'Freifunk Heppenheim' + option 'homepage' 'http://heppenheim.freifunk.net' + option 'ssid' 'heppenheim.freifunk.net' + option 'mesh_network' '10.48.0.0/16' + option 'splash_network' '10.104.0.0/16' + option 'splash_prefix' '27' + option 'latitude' '51.151786' + option 'longitude' '10.415039' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_jena b/webgui/luci/community-profiles/files/etc/config/profile_jena new file mode 100644 index 000000000..5741d09b2 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_jena @@ -0,0 +1,12 @@ +config 'community' 'profile' + option 'name' 'Freifunk Jena' + option 'homepage' 'http://www.freifunk-jena.de' + option 'ssid' 'www.freifunk-jena.de' + option 'mesh_network' '10.127.0.0/20' + option 'splash_network' '10.104.0.0/16' + option 'splash_prefix' '29' + option 'latitude' '50.92779' + option 'longitude' '11.58431' + +config 'defaults' 'interface' + option 'dns' '217.11.48.200 217.11.49.200 8.8.8.8' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_kiberpipa b/webgui/luci/community-profiles/files/etc/config/profile_kiberpipa new file mode 100644 index 000000000..c2a96e47c --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_kiberpipa @@ -0,0 +1,15 @@ +config 'community' 'profile' + option 'name' 'Kiberpipa.net' + option 'homepage' 'http://www.kiberpipa.net' + option 'ssid' 'open.kiberpipa.net' + option 'mesh_network' '10.14.0.0/16' + option 'splash_network' '10.14.128.0/17' + option 'splash_prefix' '27' + option 'latitude' '46.05063' + option 'longitude' '14.50402' + +config 'defaults' 'wifi_device' + option 'channel' '8' + +config 'defaults' 'interface' + option 'dns' '10.14.0.1 208.67.222.220 208.67.220.222' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_l59 b/webgui/luci/community-profiles/files/etc/config/profile_l59 new file mode 100644 index 000000000..6185f0257 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_l59 @@ -0,0 +1,12 @@ +config 'community' 'profile' + option 'name' 'Freifunk L59' + option 'homepage' 'http://freifunk.net' + option 'ssid' 'start.freifunk.net' + option 'mesh_network' '104.59.0.0/16' + option 'splash_network' '10.104.0.0/16' + option 'splash_prefix' '27' + option 'latitude' '52.26337' + option 'longitude' '10.52103' + +config 'defaults' 'bssidscheme' + option '1' '02:CA:FF:EE:BA:BE' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_leipzig b/webgui/luci/community-profiles/files/etc/config/profile_leipzig new file mode 100644 index 000000000..17f3cad41 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_leipzig @@ -0,0 +1,15 @@ +config 'community' 'profile' + option 'name' 'Freifunk Leipzig' + option 'homepage' 'http://leipzig.freifunk.net' + option 'ssid' 'leipzig.freifunk.net' + option 'mesh_network' '104.61.0.0/16' + option 'splash_network' '10.104.0.0/16' + option 'splash_prefix' '27' + option 'latitude' '51.33348' + option 'longitude' '12.40297' + +config 'defaults' 'interface' + option 'netmask' '255.0.0.0' + +config 'defaults' 'bssidscheme' + option '1' '02:CA:FF:EE:BA:BE' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_mainz b/webgui/luci/community-profiles/files/etc/config/profile_mainz new file mode 100644 index 000000000..2d086183e --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_mainz @@ -0,0 +1,15 @@ +config 'community' 'profile' + option 'name' 'Freifunk Mainz' + option 'homepage' 'http://mainz.freifunk.net' + option 'ssid' 'mainz.freifunk.net' + option 'mesh_network' '10.37.0.0/16' + option 'splash_network' '10.104.0.0/16' + option 'splash_prefix' '27' + option 'latitude' '49.99635' + option 'longitude' '8.27417' + +config 'defaults' 'wifi_iface' + option 'bssid' '02:ca:ff:ee:ba:be' + +config 'defaults' 'wifi_device' + option 'channel' '1' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_marburg b/webgui/luci/community-profiles/files/etc/config/profile_marburg new file mode 100644 index 000000000..18cff80e5 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_marburg @@ -0,0 +1,12 @@ +config 'community' 'profile' + option 'name' 'Freifunk Marburg' + option 'homepage' ' http://marburg.freifunk.de' + option 'ssid' 'marburg.freifunk.net' + option 'mesh_network' '10.128.0.0/16' + option 'splash_network' '10.104.0.0/16' + option 'splash_prefix' '29' + option 'latitude' '49.63939' + option 'longitude' '8.633718' + +config 'defaults' 'interface' + option 'dns' '8.8.8.8 212.204.49.83' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_neuss b/webgui/luci/community-profiles/files/etc/config/profile_neuss new file mode 100644 index 000000000..8e3061730 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_neuss @@ -0,0 +1,15 @@ +config 'community' 'profile' + option 'name' 'Freifunk Neuss' + option 'homepage' 'http://neuss.freifunk.net' + option 'ssid' 'neuss.freifunk.net' + option 'mesh_network' '172.28.0.0/16' + option 'splash_network' '10.104.0.0/16' + option 'splash_prefix' '27' + option 'latitude' '51.19045' + option 'longitude' '6.69471' + +config 'defaults' 'wifi_device' + option 'channel' '11' + +config 'defaults' 'wifi_iface' + option 'bssid' 'DE:AD:BE:EF:CA:FE' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_oldenburg b/webgui/luci/community-profiles/files/etc/config/profile_oldenburg new file mode 100644 index 000000000..e967fdb43 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_oldenburg @@ -0,0 +1,15 @@ +config 'community' 'profile' + option 'name' 'Freifunk Oldenburg' + option 'homepage' 'http://oldenburg.freifunk.net' + option 'ssid' 'oldenburg.freifunk.net' + option 'mesh_network' '10.18.0.0/16' + option 'splash_network' '10.104.0.0/16' + option 'splash_prefix' '27' + option 'latitude' '53.14083' + option 'longitude' '8.21314' + +config 'defaults' 'wifi_device' + option 'channel' '6' + +config 'defaults' 'wifi_iface' + option 'bssid' '02:CA:FF:EE:BA:BE' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_openwireless_bern b/webgui/luci/community-profiles/files/etc/config/profile_openwireless_bern new file mode 100644 index 000000000..810ad8f1c --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_openwireless_bern @@ -0,0 +1,18 @@ +config 'community' 'profile' + option 'name' 'Openwireless Bern' + option 'homepage' 'http://bern.openwireless.ch/' + option 'ssid' 'www.openwireless.ch' + option 'mesh_network' '10.247.0.0/16' + option 'splash_network' '10.104.0.0/16' + option 'splash_prefix' '27' + option 'latitude' '50.814788' + option 'longitude' '8.769239' + +config 'defaults' 'interface' + option 'dns' '208.67.222.222 208.67.220.220' + +config 'defaults' 'wifi_device' + option 'channel' '10' + option 'country' '756' + + diff --git a/webgui/luci/community-profiles/files/etc/config/profile_pberg b/webgui/luci/community-profiles/files/etc/config/profile_pberg new file mode 100644 index 000000000..ea2f7b081 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_pberg @@ -0,0 +1,12 @@ +config 'community' 'profile' + option 'name' 'Freifunk Berlin Prenzlauer Berg' + option 'homepage' 'http://pberg.freifunk.net' + option 'ssid' 'olsr.freifunk.net' + option 'mesh_network' '104.0.0.0/8' + option 'splash_network' '10.104.0.0/16' + option 'splash_prefix' '27' + option 'latitude' '52.5427' + option 'longitude' '13.4172' + +config 'defaults' 'wifi_device' + option 'channel' '10' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_piraten_dresden b/webgui/luci/community-profiles/files/etc/config/profile_piraten_dresden new file mode 100644 index 000000000..2af0e319d --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_piraten_dresden @@ -0,0 +1,12 @@ +config 'community' 'profile' + option 'name' 'Piratenfreifunk Dresden' + option 'homepage' 'http://www.piraten-sachsen.de/' + option 'ssid' 'dresden.freifunk.net' + option 'mesh_network' '10.12.0.0/16' + option 'splash_network' '10.104.0.0/16' + option 'splash_prefix' '27' + option 'latitude' '51.05081' + option 'longitude' '13.73420' + +config 'defaults' 'wifi_device' + option 'channel' '1' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_potsdam b/webgui/luci/community-profiles/files/etc/config/profile_potsdam new file mode 100644 index 000000000..458b18b47 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_potsdam @@ -0,0 +1,13 @@ +config 'community' 'profile' + option 'name' 'Freifunk Potsdam' + option 'homepage' 'http://potsdam.freifunk.net' + option 'ssid' 'www.freifunk-potsdam.de' + option 'mesh_network' '10.22.0.0/16' + option 'splash_network' '192.168.22.0/24' + option 'splash_prefix' '24' + option 'latitude' '52.39349' + option 'longitude' '13.06489' + +config 'defaults' 'wifi_device' + option 'channel' '13' + option 'bssid' '02:CA:FF:EE:BA:BE' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_rosbach b/webgui/luci/community-profiles/files/etc/config/profile_rosbach new file mode 100644 index 000000000..4444f7099 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_rosbach @@ -0,0 +1,15 @@ +config 'community' 'profile' + option 'name' 'Freifunk Rosbach' + option 'homepage' 'freifunk-rosbach.de' + option 'ssid' 'rosbach.freifunk.net' + option 'mesh_network' '10.212.0.0/16' + option 'splash_network' '10.104.0.0/16' + option 'splash_prefix' '27' + option 'latitude' '50.18' + option 'longitude' '8.42' + +config 'defaults' 'wifi_device' + option 'channel' '13' + +config 'defaults' 'wifi_iface' + option 'bssid' 'D2:CA:FF:EE:BA:BE' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_seefeld b/webgui/luci/community-profiles/files/etc/config/profile_seefeld new file mode 100644 index 000000000..5d03f7d04 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_seefeld @@ -0,0 +1,13 @@ +config 'community' 'profile' + option 'name' 'Freifunk Seefeld' + option 'homepage' 'http://wiki.freifunk.net/Seefeld.freifunk.net' + option 'ssid' 'seefeld.freifunk.net' + option 'mesh_network' '10.111.0.0/16' + option 'splash_network' '10.104.0.0/16' + option 'splash_prefix' '27' + option 'latitude' '48.03485' + option 'longitude' '11.21279' + +config 'defaults' 'wifi_device' + option 'channel' '1' + option 'bssid' '02:CA:FF:EE:BA:BB' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_stuttgart b/webgui/luci/community-profiles/files/etc/config/profile_stuttgart new file mode 100644 index 000000000..28d60d8df --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_stuttgart @@ -0,0 +1,13 @@ +config 'community' 'profile' + option 'name' 'Freifunk Stuttgart' + option 'homepage' 'http://freifunk-stuttgart.de' + option 'ssid' 'Freifunk Stuttgart' + option 'mesh_network' '172.21.0.0/16' + option 'splash_network' '10.104.0.0/16' + option 'latitude' '48' + option 'longitude' '9' + option 'splash_prefix' '27' + +config 'defaults' 'wifi_device' + option 'channel' '5' + option 'bssid' '52:CA:FF:EE:BA:BE' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_weimar b/webgui/luci/community-profiles/files/etc/config/profile_weimar new file mode 100644 index 000000000..65938e744 --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_weimar @@ -0,0 +1,10 @@ +config 'community' 'profile' + option 'name' 'Weimarnetz e.V.' + option 'homepage' 'http://www.weimarnetz.de' + option 'ssid' 'weimarnetz' + option 'mesh_network' '10.63.0.0/16' + option 'latitude' '50.989530' + option 'longitude' '11.338675' + +config 'defaults' 'interface' + option 'dns' '217.11.48.200 217.11.49.200 8.8.8.8' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_weinstadt b/webgui/luci/community-profiles/files/etc/config/profile_weinstadt new file mode 100644 index 000000000..51f3eab7c --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_weinstadt @@ -0,0 +1,16 @@ +config 'community' 'profile' + option 'name' 'Freifunk Weinstadt' + option 'homepage' 'http://freifunk-weinstadt.de' + option 'ssid' 'freifunk-weinstadt' + option 'mesh_network' '172.21.0.0/16' + option 'splash_network' '172.21.85.0/30' + option 'latitude' '48.81' + option 'longitude' '9.39' + option 'splash_prefix' '30' + +config 'defaults' 'wifi_device' + option 'channel' '5' + option 'bssid' '02:07:01:03:08:04' + +config 'defaults' 'bssidscheme' + option '5' '02:07:01:03:08:04' diff --git a/webgui/luci/community-profiles/files/etc/config/profile_wlanljubljana b/webgui/luci/community-profiles/files/etc/config/profile_wlanljubljana new file mode 100644 index 000000000..eeefbd22b --- /dev/null +++ b/webgui/luci/community-profiles/files/etc/config/profile_wlanljubljana @@ -0,0 +1,15 @@ +config 'community' 'profile' + option 'name' 'wlan ljubljana' + option 'homepage' 'http://wlan-lj.net' + option 'ssid' 'open.wlan-lj.net' + option 'mesh_network' '10.254.0.0/16' + option 'splash_network' '10.254.120.0/21' + option 'splash_prefix' '27' + option 'latitude' '46.05063' + option 'longitude' '14.50402' + +config 'defaults' 'wifi_device' + option 'channel' '8' + +config 'defaults' 'interface' + option 'dns' '10.254.0.1 10.254.0.2' diff --git a/webgui/luci/freifunk-common/Makefile b/webgui/luci/freifunk-common/Makefile new file mode 100644 index 000000000..c15f02dcf --- /dev/null +++ b/webgui/luci/freifunk-common/Makefile @@ -0,0 +1,42 @@ +# Copyright (C) 2011 Manuel Munz +# This is free software, licensed under the Apache 2.0 license. + +include $(TOPDIR)/rules.mk + +PKG_NAME:=freifunk-common +PKG_RELEASE:=1 + +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) + +include $(INCLUDE_DIR)/package.mk + +define Package/freifunk-common + SECTION:=luci + CATEGORY:=LuCI + SUBMENU:=9. Freifunk + TITLE:=Freifunk common files +endef + +define Package/freifunk-common/description + Common files and scripts that are needed to run free wireless mesh networks. +endef + +define Package/luci-mod-freifunk/conffiles +/etc/config/freifunk +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) +endef + +define Build/Configure +endef + +define Build/Compile +endef + +define Package/freifunk-common/install + $(CP) ./files/* $(1)/ +endef + +$(eval $(call BuildPackage,freifunk-common)) diff --git a/webgui/luci/freifunk-common/files/etc/config/freifunk b/webgui/luci/freifunk-common/files/etc/config/freifunk new file mode 100644 index 000000000..09d92d92b --- /dev/null +++ b/webgui/luci/freifunk-common/files/etc/config/freifunk @@ -0,0 +1,129 @@ +package 'freifunk' + +config 'public' 'contact' + option 'nickname' '' + option 'name' '' + option 'mail' '' + option 'phone' '' + option 'location' '' + option 'note' '' + +config 'public' 'community' + option 'name' 'Freifunk' + option 'homepage' 'http://freifunk.net' + +config 'fw_zone' 'zone_freifunk' + option 'name' 'freifunk' + option 'input' 'REJECT' + option 'forward' 'REJECT' + option 'output' 'ACCEPT' + +config 'fw_rule' 'fficmp' + option 'src' 'freifunk' + option 'target' 'ACCEPT' + option 'proto' 'icmp' + +config 'fw_rule' 'ffhttp' + option 'src' 'freifunk' + option 'target' 'ACCEPT' + option 'proto' 'tcp' + option 'dest_port' '80' + +config 'fw_rule' 'ffhttps' + option 'src' 'freifunk' + option 'target' 'ACCEPT' + option 'proto' 'tcp' + option 'dest_port' '443' + +config 'fw_rule' 'ffssh' + option 'src' 'freifunk' + option 'target' 'ACCEPT' + option 'proto' 'tcp' + option 'dest_port' '22' + +config 'fw_rule' 'ffolsr' + option 'src' 'freifunk' + option 'target' 'ACCEPT' + option 'proto' 'udp' + option 'dest_port' '698' + +config 'fw_rule' 'ffwprobe' + option 'src' 'freifunk' + option 'target' 'ACCEPT' + option 'proto' 'tcp' + option 'dest_port' '17990' + +config 'fw_rule' 'ffdns' + option 'dest_port' '53' + option 'src' 'freifunk' + option 'target' 'ACCEPT' + option 'proto' 'udp' + +config 'fw_rule' 'ffdhcp' + option 'src_port' '68' + option 'src' 'freifunk' + option 'target' 'ACCEPT' + option 'dest_port' '67' + option 'proto' 'udp' + option 'leasetime' '30m' + +config 'fw_rule' 'ffsplash' + option 'dest_port' '8082' + option 'src' 'freifunk' + option 'target' 'ACCEPT' + option 'proto' 'tcp' + +config 'fw_forwarding' 'lanfffwd' + option 'src' 'lan' + option 'dest' 'freifunk' + +config 'fw_forwarding' 'ffwanfwd' + option 'src' 'freifunk' + option 'dest' 'wan' + +config 'fw_forwarding' 'fffwd' + option 'src' 'freifunk' + option 'dest' 'freifunk' + +config 'include' 'freifunk' + option 'path' '/etc/firewall.freifunk' + +config 'defaults' 'system' + option 'zonename' 'Europe/Berlin' + option 'timezone' 'CET-1CEST,M3.5.0,M10.5.0/3' + +config 'defaults' 'wifi_device' + option 'channel' '1' + option 'diversity' '1' + option 'disabled' '0' + option 'country' 'DE' + option 'hwmode' '11g' + option 'distance' '1000' + +config 'defaults' 'wifi_iface' + option 'mode' 'adhoc' + option 'encryption' 'none' + option 'bgscan' '0' + option 'bssid' '12:CA:FF:EE:BA:BE' + option 'sw_merge' '1' + option 'mcast_rate' '5500' + option 'probereq' '1' + +config 'defaults' 'interface' + option 'netmask' '255.255.0.0' + option 'dns' '8.8.8.8 212.204.49.83 141.1.1.1' + +config 'defaults' 'alias' + option 'netmask' '255.255.255.0' + +config 'defaults' 'dhcp' + option 'leasetime' '30m' + option 'force' '1' + +config 'defaults' 'olsr_interfacedefaults' + option 'Ip4Broadcast' '255.255.255.255' + +config 'defaults' 'upgrade' + option 'repository' 'http://dev.luci.freifunk-halle.net/freifunk-snapshots' + option 'rssfeed' 'http://firmware.leipzig.freifunk.net/kamikaze/.rss.xml' + diff --git a/webgui/luci/freifunk-common/files/etc/init.d/freifunk b/webgui/luci/freifunk-common/files/etc/init.d/freifunk new file mode 100755 index 000000000..3591cafea --- /dev/null +++ b/webgui/luci/freifunk-common/files/etc/init.d/freifunk @@ -0,0 +1,25 @@ +#!/bin/sh /etc/rc.common +# Freifunk Init +# $Id: freifunk 8776 2012-06-23 09:10:06Z soma $ + +START=99 + +boot() { + test -f /etc/crontabs/root || touch /etc/crontabs/root + + grep -q 'killall -HUP dnsmasq' /etc/crontabs/root || { + echo "*/5 * * * * killall -HUP dnsmasq" >> /etc/crontabs/root + } + + grep -q '/usr/sbin/ff_olsr_watchdog' /etc/crontabs/root || { + echo "*/5 * * * * /usr/sbin/ff_olsr_watchdog" >> /etc/crontabs/root + } + + [ -d /etc/rc.local.d ] && { + for file in /etc/rc.local.d/*; do + test -f "$file" && . "$file" + done + } + + /etc/init.d/cron restart & +} diff --git a/webgui/luci/freifunk-common/files/etc/rc.local.d/01-config-migration b/webgui/luci/freifunk-common/files/etc/rc.local.d/01-config-migration new file mode 100644 index 000000000..11f1ad60b --- /dev/null +++ b/webgui/luci/freifunk-common/files/etc/rc.local.d/01-config-migration @@ -0,0 +1,51 @@ +# Fixup various configurations to remove quirks +# from former versions. + +_log() { + logger -t "Config Migration" "$1" +} + +_uci() { + uci ${2:+-c $2} get "$1" 2>/dev/null +} + + +# Splash redirector had a wrong virtual url match +# which resulted in "No such handler" + +[ "$(_uci lucid.splashredir.virtual)" == "/" ] && { + _log "Fix splash redirector configuration" + uci set lucid.splashredir.virtual='' + uci commit lucid + /etc/init.d/lucid restart +} + + +# Newer OLSR versions have the MinTCVtime hack active, +# ensure proper timings or olsrd won't start + +FIX=0 +for i in 0 1 2 3 4; do + [ -z "$(_uci olsrd.@Interface[$i].TcInterval)" ] && \ + [ -z "$(_uci olsrd.@Interface[$i].TcValidityTime)" ] || { + uci delete olsrd.@Interface[$i].TcInterval + uci delete olsrd.@Interface[$i].TcValidityTime + FIX=1 + } +done + +[ "$FIX" == 1 ] && { + _log "Fix olsrd configuration for MinTCVTime hack" + uci commit olsrd + /etc/init.d/olsrd restart +} + + +# Ensure that the community definitions are in the +# new format + +[ -z "$(_uci freifunk.leipzig.mesh_network)" ] && \ +[ -n "$(_uci freifunk.leipzig.mesh_network /rom/etc/config)" ] && { + _log "Converting freifunk configuration to new format" + cp /rom/etc/config/freifunk /etc/config/freifunk +} diff --git a/webgui/luci/freifunk-common/files/etc/uci-defaults/freifunk b/webgui/luci/freifunk-common/files/etc/uci-defaults/freifunk new file mode 100644 index 000000000..fe6586c22 --- /dev/null +++ b/webgui/luci/freifunk-common/files/etc/uci-defaults/freifunk @@ -0,0 +1,2 @@ +uci set uhttpd.main.rfc1918_filter=0 +uci commit uhttpd diff --git a/webgui/luci/freifunk-common/files/usr/bin/ffdzero b/webgui/luci/freifunk-common/files/usr/bin/ffdzero new file mode 100755 index 000000000..24e8c2e18 --- /dev/null +++ b/webgui/luci/freifunk-common/files/usr/bin/ffdzero @@ -0,0 +1,10 @@ +#!/bin/sh + +test "$1" = "-h" && echo -e "Usage:\n\t$0 -h\n\t$0 [ { ip | hostname } ]" >&2 && exit 1 + +host="${1:-leipzig.freifunk.net}" + +wget -O /dev/null http://$host/cgi-bin-dev-zero.bin +test "$?" = "1" && wget -O /dev/null http://$host/cgi-bin/dev-zero.bin +test "$?" = "1" && wget -O /dev/null http://$host/cgi-bin/luci/freifunk/status/zeroes +test "$?" = "1" && echo "$host: no zero download found..." && exit 1 diff --git a/webgui/luci/freifunk-common/files/usr/bin/neigh.sh b/webgui/luci/freifunk-common/files/usr/bin/neigh.sh new file mode 100755 index 000000000..723b813b7 --- /dev/null +++ b/webgui/luci/freifunk-common/files/usr/bin/neigh.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +wget -q -O - http://localhost:2006/neighbours|sed -e's/LinkQuality/LQ/;s/Hysteresis/Hyst./;s/Willingness/Will./' diff --git a/webgui/luci/freifunk-common/files/usr/sbin/ff_olsr_watchdog b/webgui/luci/freifunk-common/files/usr/sbin/ff_olsr_watchdog new file mode 100755 index 000000000..aa8de6162 --- /dev/null +++ b/webgui/luci/freifunk-common/files/usr/sbin/ff_olsr_watchdog @@ -0,0 +1,29 @@ +#!/usr/bin/lua + +require "os" +require "io" +require "uci" +local fs = require "nixio.fs" + +if fs.access("/var/run/olsrd.pid") then + local stamp, intv + local x = uci.cursor() + + x:foreach("olsrd", "LoadPlugin", + function(s) + if s.library == "olsrd_watchdog.so.0.1" then + intv = tonumber(s.interval) + stamp = s.file + end + end) + + if intv and fs.access(stamp) then + local systime = os.time() + local wdgtime = tonumber(io.lines(stamp)()) + + if not wdgtime or ( systime - wdgtime ) > ( intv * 2 ) then + os.execute("logger -t 'OLSR watchdog' 'Process died - restarting!'") + os.execute("/etc/init.d/olsrd restart") + end + end +end diff --git a/webgui/luci/freifunk-common/ipkg/postinst b/webgui/luci/freifunk-common/ipkg/postinst new file mode 100755 index 000000000..52bedb2d4 --- /dev/null +++ b/webgui/luci/freifunk-common/ipkg/postinst @@ -0,0 +1,6 @@ +#!/bin/sh + +[ -n "${IPKG_INSTROOT}" ] || { + /etc/init.d/freifunk enabled || /etc/init.d/freifunk enable + exit 0 +} diff --git a/webgui/luci/freifunk-firewall/Makefile b/webgui/luci/freifunk-firewall/Makefile new file mode 100644 index 000000000..eed1d7a8a --- /dev/null +++ b/webgui/luci/freifunk-firewall/Makefile @@ -0,0 +1,53 @@ +# +# Copyright (C) 2009 Jo-Philipp Wich +# +# This is free software, licensed under the Apache 2.0 license. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=freifunk-firewall +PKG_RELEASE:=2 + +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) + +include $(INCLUDE_DIR)/package.mk + +define Package/freifunk-firewall + SECTION:=luci + CATEGORY:=LuCI + SUBMENU:=9. Freifunk + TITLE:=Freifunk Firewall Addon + DEPENDS:=+firewall +endef + +define Package/freifunk-firewall/description + Various firewall extensions for Freifunk. Includes NAT fixes and advanced settings. +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) +endef + +define Build/Configure +endef + +define Build/Compile +endef + +define Package/freifunk-firewall/postinst +#!/bin/sh +[ -n "$${IPKG_INSTROOT}" ] || { + if ! grep -q /etc/firewall.freifunk /etc/config/firewall; then + uci add firewall include >/dev/null + uci set firewall.@include[-1].path=/etc/firewall.freifunk + uci commit firewall + fi +} +endef + +define Package/freifunk-firewall/install + $(CP) ./files/* $(1)/ +endef + +$(eval $(call BuildPackage,freifunk-firewall)) diff --git a/webgui/luci/freifunk-firewall/files/etc/firewall.freifunk b/webgui/luci/freifunk-firewall/files/etc/firewall.freifunk new file mode 100644 index 000000000..a26f0f853 --- /dev/null +++ b/webgui/luci/freifunk-firewall/files/etc/firewall.freifunk @@ -0,0 +1,42 @@ +#!/bin/sh +# Freifunk Firewall addons +# $Id: firewall.freifunk 7810 2011-10-28 15:15:27Z jow $ + + +# +# Apply advanced settings +# +apply_advanced() { + local tcp_ecn + local tcp_window_scaling + local accept_redirects + local accept_source_route + + config_get_bool tcp_ecn $1 tcp_ecn 1 + config_get_bool tcp_window_scaling $1 tcp_window_scaling 1 + config_get_bool accept_redirects $1 accept_redirects 0 + config_get_bool accept_source_route $1 accept_source_route 0 + + logger -t firewall.freifunk "tcp_ecn is $tcp_ecn" + logger -t firewall.freifunk "tcp_window_scaling is $tcp_window_scaling" + logger -t firewall.freifunk "accept_redirects is $accept_redirects" + logger -t firewall.freifunk "accept_source_route is $accept_source_route" + + sysctl -w net.ipv4.tcp_ecn=$tcp_ecn >/dev/null + sysctl -w net.ipv4.tcp_window_scaling=$tcp_window_scaling >/dev/null + + for f in /proc/sys/net/ipv4/conf/*/accept_redirects; do + echo $accept_redirects > $f + done + + for f in /proc/sys/net/ipv4/conf/*/accept_source_route; do + echo $accept_source_route > $f + done +} + +config_foreach apply_advanced advanced + +[ -x /etc/init.d/luci_splash ] && ( sleep 3; /etc/init.d/luci_splash restart )& + +[ -x /etc/init.d/freifunk-p2pblock ] && /etc/init.d/freifunk-p2pblock enabled && \ + ( sleep 3; /etc/init.d/freifunk-p2pblock restart )& diff --git a/webgui/luci/freifunk-firewall/files/etc/hotplug.d/firewall/23-restricted-wan b/webgui/luci/freifunk-firewall/files/etc/hotplug.d/firewall/23-restricted-wan new file mode 100644 index 000000000..d6f94ea90 --- /dev/null +++ b/webgui/luci/freifunk-firewall/files/etc/hotplug.d/firewall/23-restricted-wan @@ -0,0 +1,72 @@ +#!/bin/sh + +clear_restricted_gw() +{ + local state="$1" + local iface + local ifname + local ipaddr + local netmask + local gateway + + config_get iface "$state" iface + + if [ "$iface" = "$INTERFACE" ]; then + config_get ifname "$state" ifname + config_get ipaddr "$state" ipaddr + config_get netmask "$state" netmask + config_get gateway "$state" gateway + + logger -t firewall.freifunk "removing local restriction to $iface($gateway)" + iptables -D forwarding_rule ! -i $ifname -o $ifname -d $ipaddr/$netmask -j REJECT --reject-with icmp-host-prohibited + uci_revert_state firewall "$state" + fi +} + +get_enabled() +{ + local name + config_get name "$1" name + + if [ "$name" = "$ZONE" ]; then + config_get_bool local_restrict "$1" local_restrict + fi +} + +if [ "$ACTION" = add ]; then + local enabled + local ipaddr + local netmask + local gateway + + include /lib/network + scan_interfaces + + config_get ipaddr "$INTERFACE" ipaddr + config_get netmask "$INTERFACE" netmask + config_get gateway "$INTERFACE" gateway + + if [ -n "$gateway" ] && [ "$gateway" != 0.0.0.0 ]; then + config_load firewall + + local_restrict=0 + config_foreach get_enabled zone + + if [ "$local_restrict" = 1 ]; then + logger -t firewall.freifunk "restricting local access to $DEVICE($gateway)" + iptables -I forwarding_rule ! -i $DEVICE -o $DEVICE -d $ipaddr/$netmask -j REJECT --reject-with icmp-host-prohibited + local state="restricted_gw_${INTERFACE}" + uci_set_state firewall "$state" "" restricted_gw_state + uci_set_state firewall "$state" iface "$INTERFACE" + uci_set_state firewall "$state" ifname "$DEVICE" + uci_set_state firewall "$state" ipaddr "$ipaddr" + uci_set_state firewall "$state" netmask "$netmask" + uci_set_state firewall "$state" gateway "$gateway" + fi + fi + +elif [ "$ACTION" = remove ]; then + config_load firewall + config_foreach clear_restricted_gw restricted_gw_state +fi + diff --git a/webgui/luci/freifunk-gwcheck/Makefile b/webgui/luci/freifunk-gwcheck/Makefile new file mode 100644 index 000000000..a0945e1d8 --- /dev/null +++ b/webgui/luci/freifunk-gwcheck/Makefile @@ -0,0 +1,39 @@ +# Copyright (C) 2011 Manuel Munz +# This is free software, licensed under the Apache 2.0 license. + +include $(TOPDIR)/rules.mk + +PKG_NAME:=freifunk-gwcheck +PKG_RELEASE:=1 + +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) + +include $(INCLUDE_DIR)/package.mk + +define Package/freifunk-gwcheck + SECTION:=luci + CATEGORY:=LuCI + SUBMENU:=9. Freifunk + TITLE:=Freifunk gateway check script + DEPENDS:=firewall +ip +iptables-mod-ipopt +olsrd-mod-dyn-gw-plain +endef + +define Package/freifunk-gwcheck/description + This script periodically checks if internet is available via your own gateway. If it detects that it is broken, then the defaultroute is removed from the main table and temporarilly placed in table gw-check until your internet works again. Config file is /etc/config/freifunk-gwcheck. +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) +endef + +define Build/Configure +endef + +define Build/Compile +endef + +define Package/freifunk-gwcheck/install + $(CP) ./files/* $(1)/ +endef + +$(eval $(call BuildPackage,freifunk-gwcheck)) diff --git a/webgui/luci/freifunk-gwcheck/files/etc/config/freifunk-gwcheck b/webgui/luci/freifunk-gwcheck/files/etc/config/freifunk-gwcheck new file mode 100644 index 000000000..382747e20 --- /dev/null +++ b/webgui/luci/freifunk-gwcheck/files/etc/config/freifunk-gwcheck @@ -0,0 +1,5 @@ +config 'gwcheck' 'hosts' + list 'host' 'augsburg.freifunk.net' + list 'host' 'vpn4.leipzig.freifunk.net' + list 'host' 'luci.subsignal.org' + list 'host' 'conntest.jpod.cc' diff --git a/webgui/luci/freifunk-gwcheck/files/usr/sbin/ff_olsr_test_gw.sh b/webgui/luci/freifunk-gwcheck/files/usr/sbin/ff_olsr_test_gw.sh new file mode 100755 index 000000000..5d34d9a55 --- /dev/null +++ b/webgui/luci/freifunk-gwcheck/files/usr/sbin/ff_olsr_test_gw.sh @@ -0,0 +1,82 @@ +#!/bin/sh + +#check if dyngw_plain is installed and enabled, else exit +dyngwplainlib=`uci show olsrd |grep dyn_gw_plain |awk {' FS="."; print $1"."$2 '}` +if [ -n "$dyngwplainlib" ]; then + if [ ! "$(uci -q get $dyngwplainlib.ignore)" == 0 ]; then + exit 1 + fi +else + echo "dyngw_plain not found in olsrd config, exit" + exit 1 +fi + + +# check if we have a defaultroute with metric=0 in one of these tables: main table and gw-check table. +# If not exit here. +defroutemain="$(ip r s |grep default |grep -v metric)" +defroutegw-check="$(ip r s t gw-check |grep default |grep -v metric)" +if [ -z "$defroutegw-check" -a -z "$defroutemain" ]; then + exit 1 +fi + +# get and shuffle list of testservers +testserver="$(uci -q get freifunk-gwcheck.hosts.host)" +[ -z "$testserver" ] && echo "No testservers found, exit" && exit + +testserver="$(for t in $testserver; do echo $t; done | awk 'BEGIN { + srand(); +} +{ + l[NR] = $0; +} + +END { + for (i = 1; i <= NR; i++) { + n = int(rand() * (NR - i + 1)) + i; + print l[n]; + l[n] = l[i]; + } +}')" + +check_internet() { + for t in $testserver; do + local test + test=$(wget -q http://$t/conntest.html -O -| grep "Internet_works") + if [ "$test" == "Internet_works" ]; then + echo 0 + break + else + logger -t gw-check "Could not get test file from http://$t/conntest.html" + fi + done +} + +iw=$(check_internet) + +if [ "$iw" == 0 ]; then + # check if we have a seperate routing table for our tests. + # If yes, move defaultroute to normal table and delete table gw-check + if [ -n "$defroutegw-check" ]; then + ip r a $defroutegw-check + ip r d $defroutegw-check t gw-check + ip ru del fwmark 0x2 lookup gw-check + for host in $testserver; do + iptables -t mangle -D OUTPUT -d $host -p tcp --dport 80 -j MARK --set-mark 0x2 + done + logger -t gw-check "Internet is available again, restoring default route ( $defroutegw-check)" + fi + +else + # Check failed. If we have a defaultroute with metric=0 and it is already in table gw-check then do nothing. + # If there is a defaultroute with metric=0 then remove it from the main routing table and add to table gw-check. + if [ -z "$(ip ru s | grep gw-check)" -a -n "$defroutemain" ]; then + ip rule add fwmark 0x2 lookup gw-check + for host in $testserver; do + iptables -t mangle -I OUTPUT -d $host -p tcp --dport 80 -j MARK --set-mark 0x2 + done + ip r a $defroutemain table gw-check + ip r d $defroutemain + logger -t gw-check "Internet is not available, deactivating the default route ( $defroutemain)" + fi +fi diff --git a/webgui/luci/freifunk-gwcheck/ipkg/postinst b/webgui/luci/freifunk-gwcheck/ipkg/postinst new file mode 100644 index 000000000..1c5308ff6 --- /dev/null +++ b/webgui/luci/freifunk-gwcheck/ipkg/postinst @@ -0,0 +1,4 @@ +#!/bin/sh +[ -n "${IPKG_INSTROOT}" ] || { + ( . /etc/uci-defaults/freifunk-gwcheck ) && rm -f /etc/uci-defaults/freifunk-gwcheck +} diff --git a/webgui/luci/freifunk-gwcheck/ipkg/postrm b/webgui/luci/freifunk-gwcheck/ipkg/postrm new file mode 100644 index 000000000..18e4a07d0 --- /dev/null +++ b/webgui/luci/freifunk-gwcheck/ipkg/postrm @@ -0,0 +1,5 @@ +#!/bin/sh +[ -n "${IPKG_INSTROOT}" ] || { + sed -i '/gw-check/d' /etc/iproute2/rt_tables + sed -i '/ff_olsr_test_gw.sh/d' /etc/crontabs/root +} diff --git a/webgui/luci/freifunk-gwcheck/root/etc/uci-defaults/freifunk-gwcheck b/webgui/luci/freifunk-gwcheck/root/etc/uci-defaults/freifunk-gwcheck new file mode 100644 index 000000000..e04faa562 --- /dev/null +++ b/webgui/luci/freifunk-gwcheck/root/etc/uci-defaults/freifunk-gwcheck @@ -0,0 +1,6 @@ +#!/bin/sh +tables="/etc/iproute2/rt_tables" +grep -q "gw-check" $tables || echo "200 gw-check" >> $tables +test -f /etc/crontabs/root || touch /etc/crontabs/root +grep -q "ff_olsr_test_gw.sh" /etc/crontabs/root || echo "* * * * * /usr/sbin/ff_olsr_test_gw.sh" >> /etc/crontabs/root +/etc/init.d/cron restart diff --git a/webgui/luci/freifunk-mapupdate/Makefile b/webgui/luci/freifunk-mapupdate/Makefile new file mode 100644 index 000000000..a9281ca20 --- /dev/null +++ b/webgui/luci/freifunk-mapupdate/Makefile @@ -0,0 +1,39 @@ +# Copyright (C) 2011 Manuel Munz +# This is free software, licensed under the Apache 2.0 license. + +include $(TOPDIR)/rules.mk + +PKG_NAME:=freifunk-mapupdate +PKG_RELEASE:=1 + +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) + +include $(INCLUDE_DIR)/package.mk + +define Package/freifunk-mapupdate + SECTION:=luci + CATEGORY:=LuCI + SUBMENU:=9. Freifunk + TITLE:=Update script for freifunkmap + DEPENDS:=+olsrd-mod-nameservice +endef + +define Package/freifunk-mapupdate/description + This script updates the freifunkmap (also known as the global map, see http://map.berlin.freifunk.net) every hour. Config file is /etc/config/freifunk-mapupdate. +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) +endef + +define Build/Configure +endef + +define Build/Compile +endef + +define Package/freifunk-mapupdate/install + $(CP) ./files/* $(1)/ +endef + +$(eval $(call BuildPackage,freifunk-mapupdate)) diff --git a/webgui/luci/freifunk-mapupdate/files/etc/config/freifunk-mapupdate b/webgui/luci/freifunk-mapupdate/files/etc/config/freifunk-mapupdate new file mode 100644 index 000000000..7e98f956d --- /dev/null +++ b/webgui/luci/freifunk-mapupdate/files/etc/config/freifunk-mapupdate @@ -0,0 +1,3 @@ +config 'mapupdate' 'mapupdate' + option 'enabled' '1' + option 'mapserver' 'http://map.berlin.freifunk.net/freifunkmap.php' diff --git a/webgui/luci/freifunk-mapupdate/files/usr/sbin/ff_mapupdate.sh b/webgui/luci/freifunk-mapupdate/files/usr/sbin/ff_mapupdate.sh new file mode 100755 index 000000000..40a077f15 --- /dev/null +++ b/webgui/luci/freifunk-mapupdate/files/usr/sbin/ff_mapupdate.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +if [ ! "$(uci -q get freifunk-mapupdate.mapupdate.enabled)" == 1 ]; then + exit 1 +fi + +MAPSERVER="$(uci -q get freifunk-mapupdate.mapupdate.mapserver)" +[ -z "$MAPSERVER" ] && logger -t "freifunk-mapupdate:" "No mapserver configured" && exit 1 + +#check if nameservice plugin is installed and enabled, else exit +nslib=`uci show olsrd |grep olsrd_nameservice.so |awk {' FS="."; print $1"."$2 '}` +if [ -n "$nslib" ]; then + LATLONFILE="$(uci -q get $nslib.latlon_file)" + if [ -z "$LATLONFILE" ]; then + LATLONFILE="/var/run/latlon.js" + fi + if [ ! -p "$LATLONFILE" ]; then + logger -t "freifunk-mapupdate:" "latlon_file not found."; exit 1 + fi +else + logger -t "freifunk-mapupdate:" "nameservice plugin not found in olsrd config." + exit 1 +fi + +HOSTNAME="$(uci show system |grep hostname |cut -d "=" -f 2)" +HF_INFO="" + +# Get info for myself +SELF=$(cat $LATLONFILE |grep ^Self | sed -e 's/Self(//' -e 's/);//' -e "s/'//g") +OLSR_IP="$(echo $SELF |awk '{ FS=",";print $1 }')" +LOCATION="$(uci show system |grep .location |cut -d "=" -f 2)" +[ -n "$LOCATION" ] && NOTE="$LOCATION
" +FFNOTE="$(uci -q get freifunk.contact.note)" +[ -n "$FFNOTE" ] && NOTE="$NOTE $FFNOTE" +NOTE="

$HOSTNAME

$NOTE" +NOTE=`echo -e "$NOTE" | sed -e 's/\ /%20/g' -e 's/&/%26/g' -e 's/"/%22/g'` + +UPDATESTRING="$(echo $SELF |awk '{ FS=",";print $2 }'), $(echo $SELF |awk '{ FS=",";print $3 }')" + +# write our coordinates to mygooglemapscoords.txt to make Freifunk Firmware happy +echo "$UPDATESTRING" > /tmp/mygooglemapscoords.txt +[ ! -L /www/mygooglemapscoords.txt ] && ln -s /tmp/mygooglemapscoords.txt /www/mygooglemapscoords.txt + +# get neighbor Info (lat, lon, lq) +while read line; do + NEIGHUPD="$(echo $line |awk '{ FS=","; print $6 }'), $(echo $line |awk '{ FS=","; print $7 }'), $(echo $line |awk '{ FS=",";print $4 }')" + UPDATESTRING="${UPDATESTRING}, ${NEIGHUPD}" +done << EOF +`grep "PLink('$OLSR_IP" $LATLONFILE | sed -e 's/PLink(//' -e 's/);//' -e "s/'//g"` +EOF + +# Send UPDATESTRING +UPDATE=`echo -e "$UPDATESTRING" | sed s/\ /%20/g` +result="$(wget "$MAPSERVER?update=$UPDATE&updateiv=3600&olsrip=$OLSR_IP¬e=${NOTE}${HF_INFO}" -qO -)" + +if [ ! "$result" == "success update" ]; then + logger -t "freifunk-mapupdate:" "Update failed: $result" +fi + diff --git a/webgui/luci/freifunk-mapupdate/ipkg/postinst b/webgui/luci/freifunk-mapupdate/ipkg/postinst new file mode 100644 index 000000000..284469730 --- /dev/null +++ b/webgui/luci/freifunk-mapupdate/ipkg/postinst @@ -0,0 +1,4 @@ +#!/bin/sh +[ -n "${IPKG_INSTROOT}" ] || { + ( . /etc/uci-defaults/freifunk-mapupdate ) && rm -f /etc/uci-defaults/freifunk-mapupdate +} diff --git a/webgui/luci/freifunk-mapupdate/ipkg/postrm b/webgui/luci/freifunk-mapupdate/ipkg/postrm new file mode 100644 index 000000000..dc1a8704f --- /dev/null +++ b/webgui/luci/freifunk-mapupdate/ipkg/postrm @@ -0,0 +1,5 @@ +#!/bin/sh +[ -n "${IPKG_INSTROOT}" ] || { + sed -i '/ff_mapupdate.sh/d' /etc/crontabs/root + /etc/init.d/cron restart +} diff --git a/webgui/luci/freifunk-mapupdate/root/etc/uci-defaults/freifunk-mapupdate b/webgui/luci/freifunk-mapupdate/root/etc/uci-defaults/freifunk-mapupdate new file mode 100644 index 000000000..dee7f1bb5 --- /dev/null +++ b/webgui/luci/freifunk-mapupdate/root/etc/uci-defaults/freifunk-mapupdate @@ -0,0 +1,6 @@ +#!/bin/sh +test -f /etc/crontabs/root || touch /etc/crontabs/root +SEED="$( dd if=/dev/urandom bs=2 count=1 2>&- | hexdump | if read line; then echo 0x${line#* }; fi )" +MIN="$(( $SEED % 59 ))" +grep -q "ff_mapupdate.sh" /etc/crontabs/root || echo "$MIN * * * * /usr/sbin/ff_mapupdate.sh" >> /etc/crontabs/root +/etc/init.d/cron restart diff --git a/webgui/luci/freifunk-p2pblock/Makefile b/webgui/luci/freifunk-p2pblock/Makefile new file mode 100644 index 000000000..d264a1760 --- /dev/null +++ b/webgui/luci/freifunk-p2pblock/Makefile @@ -0,0 +1,47 @@ +# +# Copyright (C) 2009 Andreas Seidler +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=freifunk-p2pblock +PKG_RELEASE:=1 + +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) + +include $(INCLUDE_DIR)/package.mk + +define Package/freifunk-p2pblock + SECTION:=luci + CATEGORY:=LuCI + SUBMENU:=9. Freifunk + TITLE:=Freifunk p2pblock Addon + DEPENDS:=+iptables-mod-filter +iptables-mod-ipp2p +l7-protocols +iptables-mod-conntrack-extra +endef + +define Package/freifunk-p2pblock/description + Simple Addon for Freifunk which use iptables layer7-, ipp2p- and recent-modules + to block p2p/filesharing traffic +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) +endef + +define Build/Configure +endef + +define Build/Compile +endef + +define Package/freifunk-p2pblock/install + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/freifunk-p2pblock.init $(1)/etc/init.d/freifunk-p2pblock + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_DATA) ./files/freifunk-p2pblock.config $(1)/etc/config/freifunk_p2pblock +endef + +$(eval $(call BuildPackage,freifunk-p2pblock)) diff --git a/webgui/luci/freifunk-p2pblock/files/freifunk-p2pblock.config b/webgui/luci/freifunk-p2pblock/files/freifunk-p2pblock.config new file mode 100644 index 000000000..291260e37 --- /dev/null +++ b/webgui/luci/freifunk-p2pblock/files/freifunk-p2pblock.config @@ -0,0 +1,6 @@ +config 'settings' 'p2pblock' + option 'portrange' '1024:65535' + option 'layer7' 'edonkey bittorrent fasttrack' + option 'ipp2p' 'edk dc kazaa gnu bit ares soul winmx apple' + option 'blocktime' '60' + option 'whitelist' '' diff --git a/webgui/luci/freifunk-p2pblock/files/freifunk-p2pblock.init b/webgui/luci/freifunk-p2pblock/files/freifunk-p2pblock.init new file mode 100644 index 000000000..b615962b0 --- /dev/null +++ b/webgui/luci/freifunk-p2pblock/files/freifunk-p2pblock.init @@ -0,0 +1,94 @@ +#!/bin/sh /etc/rc.common + +START=82 +ME="freifunk-p2pblock" +LOCK='/var/run/p2pblock.lock' + +# helper-scripts +ipt_add() { + logger -t "$ME" "set 'iptables -I $1'" + iptables -I $1 + echo "iptables -D $1" >> $LOCK +} + +start() { + /etc/init.d/freifunk-p2pblock enabled || return + + if [ ! -s "$LOCK" ]; then + logger -s -t "$ME" 'starting p2pblock...' + + config_load network + config_get wan wan ifname + + if [ -n "$wan" ]; then + config_load freifunk_p2pblock + config_get layer7 p2pblock layer7 + config_get ipp2p p2pblock ipp2p + config_get portrange p2pblock portrange + config_get blocktime p2pblock blocktime + + # load modules + insmod ipt_ipp2p 2>&- + insmod ipt_layer7 2>&- + insmod ipt_recent ip_list_tot=400 ip_pkt_list_tot=3 2>&- + + # create new p2p-chain + iptables -N p2pblock + # pipe all incomming FORWARD with source-/destination-port 1024-65535 throu p2p-chain + ipt_add "FORWARD -i $wan -p tcp --sport $portrange --dport $portrange -j p2pblock" + ipt_add "FORWARD -i $wan -p udp --sport $portrange --dport $portrange -j p2pblock" + + # if p2p-traffic blocked 3 packages to a destination ip then block all traffic within the next 180 sec (port 1024-65535) + ipt_add "p2pblock -m recent --rdest --rcheck --name P2PBLOCK --seconds $blocktime --hitcount 3 -j DROP" + ipt_add "p2pblock -m recent --rdest --rcheck --name P2PBLOCK --seconds $blocktime --hitcount 3 -m limit --limit 1/minute -j LOG --log-prefix P2PBLOCK-DROP:" + + # create layer7-rules + for proto in $layer7; do + ipt_add "p2pblock -m layer7 --l7proto $proto -m recent --rdest --set --name P2PBLOCK" + ipt_add "p2pblock -m layer7 --l7proto $proto -m limit --limit 1/minute -j LOG --log-prefix P2PBLOCK-seen-$proto:" + done + + # create ipp2p-rules + for proto in $ipp2p; do + ipt_add "p2pblock -m ipp2p --$proto -m recent --rdest --set --name P2PBLOCK" + ipt_add "p2pblock -m ipp2p --$proto -m limit --limit 1/minute -j LOG --log-prefix P2PBLOCK-seen-$proto:" + done + + # insert whitelisted ips + for ip in $WHITELIST; do + ipt_add "p2pblock -d $ip -j RETURN" + done + + logger -s -t "$ME" 'Done.'; return 0 + else + logger -s -t "$ME" 'No wan interface present.'; return 0 + fi + else + logger -s -t "$ME" 'WARNING! already running - Aborting!'; return 2 + fi +} + +stop() { + if [ -s "$LOCK" ]; then + logger -s -t "$ME" 'stopping p2pblock...' + + # unset all rules in $LOCK-file + cat $LOCK | sed -ne '1!G;h;$p' | while read line; do + logger -t "$ME" "unset $line" + while eval $line 2>&-; do :; done + done; : > "$LOCK" + + # flush and delete the p2p-chain + iptables -F p2pblock + iptables -X p2pblock + logger -s -t "$ME" 'Done.'; return 0 + + else + logger -s -t "$ME" 'WARNING! not running - Aborting!'; return 2 + + fi +} + +restart() { + stop; sleep 1; start +} diff --git a/webgui/luci/freifunk-policyrouting/Makefile b/webgui/luci/freifunk-policyrouting/Makefile new file mode 100644 index 000000000..7abfedbd5 --- /dev/null +++ b/webgui/luci/freifunk-policyrouting/Makefile @@ -0,0 +1,39 @@ +# Copyright (C) 2011 Manuel Munz +# This is free software, licensed under the Apache 2.0 license. + +include $(TOPDIR)/rules.mk + +PKG_NAME:=freifunk-policyrouting +PKG_RELEASE:=1 + +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) + +include $(INCLUDE_DIR)/package.mk + +define Package/freifunk-policyrouting + SECTION:=luci + CATEGORY:=LuCI + SUBMENU:=9. Freifunk + TITLE:=Freifunk policy routing addon + DEPENDS:=+firewall +ip +endef + +define Package/freifunk-policyrouting/description + Allows you to send your own traffic via your own default gateway while sending traffic received from the mesh to a gateway in the mesh. +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) +endef + +define Build/Configure +endef + +define Build/Compile +endef + +define Package/freifunk-policyrouting/install + $(CP) ./files/* $(1)/ +endef + +$(eval $(call BuildPackage,freifunk-policyrouting)) diff --git a/webgui/luci/freifunk-policyrouting/files/etc/config/freifunk-policyrouting b/webgui/luci/freifunk-policyrouting/files/etc/config/freifunk-policyrouting new file mode 100644 index 000000000..ba58625bc --- /dev/null +++ b/webgui/luci/freifunk-policyrouting/files/etc/config/freifunk-policyrouting @@ -0,0 +1,6 @@ + +config 'settings' 'pr' + option 'enable' '0' + option 'strict' '1' + option 'zones' '' + diff --git a/webgui/luci/freifunk-policyrouting/files/etc/hotplug.d/firewall/24-policyrouting b/webgui/luci/freifunk-policyrouting/files/etc/hotplug.d/firewall/24-policyrouting new file mode 100644 index 000000000..014803a7d --- /dev/null +++ b/webgui/luci/freifunk-policyrouting/files/etc/hotplug.d/firewall/24-policyrouting @@ -0,0 +1,76 @@ +if [ "$ACTION" = "add" ] && [ "$INTERFACE" = "wan" ]; then + pr=`uci get freifunk-policyrouting.pr.enable` + strict=`uci get freifunk-policyrouting.pr.strict` + zones=`uci get freifunk-policyrouting.pr.zones` + + if [ $pr = "1" ]; then + + # The wan device name + if [ -n "`uci -p /var/state get network.wan.ifname`" ]; then + wandev=`uci -p /var/state get network.wan.ifname` + else + wandev=`uci -p /var/state get network.wan.device` + fi + + iptables -t mangle -D PREROUTING -j prerouting_policy > /dev/null 2>&1 + iptables -t mangle -F prerouting_policy > /dev/null 2>&1 + iptables -t mangle -N prerouting_policy > /dev/null 2>&1 + iptables -t mangle -I PREROUTING -j prerouting_policy > /dev/null 2>&1 + + # If no route is in table olsr-default, then usually the hosts local default route is used. + # If set to strict then we add a filter which prevents this + if [ "$strict" == "1" ]; then + ln=$(( `iptables -L FORWARD -v --line-numbers | grep -m 1 reject | awk {' print $1 '}` - 1 )) + if [ ! $ln -gt 0 ]; then + ln=1 + fi + if [ -z "`iptables -L |grep 'Chain forward_policy'`" ]; then + iptables -N forward_policy + fi + if [ -z "`iptables -L FORWARD -v |grep forward_policy`" ]; then + iptables -I FORWARD $ln -m mark --mark 1 -j forward_policy + fi + iptables -F forward_policy + iptables -I forward_policy -o $wandev -j REJECT --reject-with icmp-net-prohibited + fi + + # set mark 1 for all packets coming in via enabled zones + for i in $zones; do + # find out which interfaces belong to this zone + zone=`uci show firewall |grep "name=$i" |awk {' FS="."; print $1"."$2 '}` + interfaces=`uci get $zone.network` + if [ "$interfaces" == "" ]; then + interfaces=$i + fi + for int in $interfaces; do + if [ "`uci -q get network.$int.type`" == "bridge" ]; then + dev="br-$int" + else + if [ -n "`uci -p /var/state get network.$int.ifname`" ]; then + dev=`uci -p /var/state get network.$int.ifname` + else + dev=`uci -p /var/state get network.$int.device` + fi + fi + logger -t policyrouting "Add mark 1 to packages coming in via interface $dev" + iptables -t mangle -I prerouting_policy -i $dev -j MARK --set-mark 1 + done + done + else + # Cleanup policy routing stuff that might be lingering around + if [ -n "`iptables -t mangle -L PREROUTING |grep _policy`" ]; then + logger -t policyrouting "Delete prerouting_policy chain in table mangle" + iptables -t mangle -D PREROUTING -j prerouting_policy + iptables -t mangle -F prerouting_policy + iptables -t mangle -X prerouting_policy + fi + if [ -n "`iptables -L FORWARD |grep forward_policy`" ]; then + logger -t policyrouting "Delete strict forwarding rules" + iptables -D FORWARD -m mark --mark 1 -j forward_policy + iptables -F forward_policy + iptables -X forward_policy + fi + logger -t policyrouting "All firewall rules for policyrouting removed." + fi +fi + diff --git a/webgui/luci/freifunk-policyrouting/files/etc/hotplug.d/iface/30-policyrouting b/webgui/luci/freifunk-policyrouting/files/etc/hotplug.d/iface/30-policyrouting new file mode 100644 index 000000000..e3b0edeb3 --- /dev/null +++ b/webgui/luci/freifunk-policyrouting/files/etc/hotplug.d/iface/30-policyrouting @@ -0,0 +1,78 @@ +[ "$INTERFACE" != "wan" ] && exit 0 + +case $ACTION in + ifup) + pr=`uci get freifunk-policyrouting.pr.enable` + if [ $pr = "1" ]; then + logger -t policyrouting "Starting policy routing on $INTERFACE" + + # Setup new tables + tables="/etc/iproute2/rt_tables" + if [ -z "`grep "111" $tables`" ]; then + echo "111 olsr" >> $tables + fi + if [ -z "`grep "112" $tables`" ]; then + echo "112 olsr-default" >> $tables + fi + + # Make sure Rt_tables in olsrd are in place + if [ ! "`uci -q get olsrd.@olsrd[0].RtTable`" == "111" ] || [ ! "`uci -q get olsrd.@olsrd[0].RtTableDefault`" == "112" ]; then + uci set olsrd.@olsrd[0].RtTable='111' + uci set olsrd.@olsrd[0].RtTableDefault='112' + uci commit + /etc/init.d/olsrd restart + fi + + # Disable dyn_gw and dyngw_plain + dyngwlib=`uci show olsrd |grep dyn_gw.so |awk {' FS="."; print $1"."$2 '}` + if [ -n "$dyngwlib" ]; then + uci set $dyngwlib.ignore=1 + uci commit + fi + + dyngwplainlib=`uci show olsrd |grep dyn_gw_plain |awk {' FS="."; print $1"."$2 '}` + if [ -n "$dyngwplainlib" ]; then + uci set $dyngwplainlib.ignore=1 + uci commit + fi + + gw=`uci -p /var/state get network.wan.gateway` + netmask=`uci -p /var/state get network.wan.netmask` + if [ -z "$netmask" ]; then + NETMASK="255.255.255.255" + fi + + if [ -n "`uci -p /var/state get network.wan.ifname`" ]; then + device=`uci -p /var/state get network.wan.ifname` + else + device=`uci -p /var/state get network.wan.device` + fi + + eval `ipcalc.sh $gw $netmask` + + test -n "`ip r s t default`" && ip r d default t default + test -n "`ip r s |grep default`" && ip route del default + ip route add $NETWORK/$NETMASK dev $device table default + ip route add default via $gw dev $device table default + + ip rule del lookup main + ip rule add fwmark 1 lookup olsr-default + ip rule add lookup main + ip rule add lookup olsr + else + # Remove custom routing tables from olsrd + if [ "`uci -q get olsrd.@olsrd[0].RtTable`" == "111" ] || [ "`uci -q get olsrd.@olsrd[0].RtTableDefault`" == "112" ]; then + uci delete olsrd.@olsrd[0].RtTable + uci delete olsrd.@olsrd[0].RtTableDefault + uci commit + /etc/init.d/olsrd restart + fi + fi + ;; + + ifdown) + logger -t policyrouting "Deleting policy rules for $INTERFACE" + ip rule del fwmark 1 lookup olsr-default > /dev/null 2>&1 + ip rule del lookup olsr > /dev/null 2>&1 + ;; +esac diff --git a/webgui/luci/freifunk-policyrouting/files/etc/init.d/freifunk-policyrouting b/webgui/luci/freifunk-policyrouting/files/etc/init.d/freifunk-policyrouting new file mode 100755 index 000000000..00730b021 --- /dev/null +++ b/webgui/luci/freifunk-policyrouting/files/etc/init.d/freifunk-policyrouting @@ -0,0 +1,13 @@ +#!/bin/sh /etc/rc.common + +START=60 + +boot() +{ + prenabled=$(uci get freifunk-policyrouting.pr.enable) + if [ ! "$prenabled" = "1" ]; then + uci -q delete olsrd.@olsrd[0].RtTable + uci -q delete olsrd.@olsrd[0].RtTableDefault + uci commit olsrd + fi +} diff --git a/webgui/luci/freifunk-policyrouting/files/etc/rc.d/S60-freifunk-policyrouting b/webgui/luci/freifunk-policyrouting/files/etc/rc.d/S60-freifunk-policyrouting new file mode 120000 index 000000000..3c3dad87d --- /dev/null +++ b/webgui/luci/freifunk-policyrouting/files/etc/rc.d/S60-freifunk-policyrouting @@ -0,0 +1 @@ +../init.d/freifunk-policyrouting \ No newline at end of file diff --git a/webgui/luci/freifunk-policyrouting/files/etc/uci-defaults/freifunk-policyrouting b/webgui/luci/freifunk-policyrouting/files/etc/uci-defaults/freifunk-policyrouting new file mode 100644 index 000000000..a6412d4df --- /dev/null +++ b/webgui/luci/freifunk-policyrouting/files/etc/uci-defaults/freifunk-policyrouting @@ -0,0 +1,7 @@ +#!/bin/sh +uci batch <<-EOF + add ucitrack freifunk-policyrouting + add_list ucitrack.@freifunk-policyrouting[-1].affects="network" + commit ucitrack +EOF + diff --git a/webgui/luci/freifunk-watchdog/Makefile b/webgui/luci/freifunk-watchdog/Makefile new file mode 100644 index 000000000..dcc3ac4b7 --- /dev/null +++ b/webgui/luci/freifunk-watchdog/Makefile @@ -0,0 +1,53 @@ +# +# Copyright (C) 2009 Jo-Philipp Wich +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=freifunk-watchdog +PKG_RELEASE:=7 + +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) +PKG_BUILD_DEPENDS := uci + +include $(INCLUDE_DIR)/package.mk + +define Package/freifunk-watchdog + SECTION:=luci + CATEGORY:=LuCI + SUBMENU:=9. Freifunk + TITLE:=Freifunk Ad-Hoc watchdog daemon + DEPENDS:=libuci +endef + +define Package/freifunk-watchdog/description + A watchdog daemon that monitors wireless interfaces to ensure the correct bssid and channel. + The process will initiate a wireless restart as soon as it detects a bssid or channel mismatch. +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) + $(CP) ./src/* $(PKG_BUILD_DIR)/ +endef + +define Build/Configure +endef + +define Build/Compile + $(MAKE) -C $(PKG_BUILD_DIR) \ + CC="$(TARGET_CC)" \ + CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include" \ + LDFLAGS="$(TARGET_LDFLAGS)" +endef + +define Package/freifunk-watchdog/install + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/freifunk-watchdog.init $(1)/etc/init.d/freifunk-watchdog + $(INSTALL_DIR) $(1)/usr/sbin + $(INSTALL_BIN) $(PKG_BUILD_DIR)/ffwatchd $(1)/usr/sbin/ +endef + +$(eval $(call BuildPackage,freifunk-watchdog)) diff --git a/webgui/luci/freifunk-watchdog/files/freifunk-watchdog.init b/webgui/luci/freifunk-watchdog/files/freifunk-watchdog.init new file mode 100755 index 000000000..d6ede09b6 --- /dev/null +++ b/webgui/luci/freifunk-watchdog/files/freifunk-watchdog.init @@ -0,0 +1,39 @@ +#!/bin/sh /etc/rc.common + +START=99 +PID=/var/run/ffwatchd.pid +BIN=/usr/sbin/ffwatchd + +boot() +{ + # If watchdog service is enabled, install cronjob, create device node and start daemon + if /etc/init.d/freifunk-watchdog enabled 2>/dev/null; then + if ! grep -q "$BIN" /etc/crontabs/root 2>/dev/null; then + echo "* * * * * $BIN running || /etc/init.d/freifunk-watchdog restart" >> /etc/crontabs/root + fi + + mknod /dev/watchdog c 10 130 + + start + + # If service is disabled, find and remove related cronjob + elif grep -q "$BIN" /etc/crontabs/root 2>/dev/null; then + sed -i -e "\\'$BIN'd" /etc/crontabs/root + fi +} + +start() +{ + start-stop-daemon -q -b -m -p $PID -x $BIN -S +} + +stop() +{ + start-stop-daemon -q -p $PID -x $BIN -K + + if ! /etc/init.d/freifunk-watchdog enabled; then + if grep -q "$BIN" /etc/crontabs/root 2>/dev/null; then + sed -i -e "\\'$BIN'd" /etc/crontabs/root + fi + fi +} diff --git a/webgui/luci/freifunk-watchdog/src/Makefile b/webgui/luci/freifunk-watchdog/src/Makefile new file mode 100644 index 000000000..e049ebc85 --- /dev/null +++ b/webgui/luci/freifunk-watchdog/src/Makefile @@ -0,0 +1,12 @@ +WD_BINARY:=ffwatchd +WD_CFLAGS:=$(CFLAGS) -c -DBINARY=\"$(WD_BINARY)\" +WD_LDFLAGS:=$(LDFLAGS) -lm -luci + +watchdog: + $(CC) $(WD_CFLAGS) -o ucix.o ucix.c + $(CC) $(WD_CFLAGS) -o watchdog.o watchdog.c + $(CC) $(WD_LDFLAGS) -o $(WD_BINARY) watchdog.o ucix.o + +clean: + rm -f *~ $(WD_BINARY) *.o + diff --git a/webgui/luci/freifunk-watchdog/src/ucix.c b/webgui/luci/freifunk-watchdog/src/ucix.c new file mode 100644 index 000000000..44de25903 --- /dev/null +++ b/webgui/luci/freifunk-watchdog/src/ucix.c @@ -0,0 +1,102 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * Copyright (C) 2008 John Crispin + * + * Changed by Jo-Philipp Wich + */ + +#include +#include + +#include +#include +#include "ucix.h" + +static struct uci_ptr ptr; + +static inline int ucix_get_ptr(struct uci_context *ctx, const char *p, const char *s, const char *o, const char *t) +{ + memset(&ptr, 0, sizeof(ptr)); + ptr.package = p; + ptr.section = s; + ptr.option = o; + ptr.value = t; + return uci_lookup_ptr(ctx, &ptr, NULL, true); +} + +struct uci_context* ucix_init(const char *config_file) +{ + struct uci_context *ctx = uci_alloc_context(); +#ifdef uci_to_delta + uci_add_delta_path(ctx, "/var/state"); +#else + uci_add_history_path(ctx, "/var/state"); +#endif + if(uci_load(ctx, config_file, NULL) != UCI_OK) + { + return NULL; + } + return ctx; +} + +void ucix_cleanup(struct uci_context *ctx) +{ + uci_free_context(ctx); +} + +const char* ucix_get_option(struct uci_context *ctx, const char *p, const char *s, const char *o) +{ + struct uci_element *e = NULL; + const char *value = NULL; + if(ucix_get_ptr(ctx, p, s, o, NULL)) + return NULL; + if (!(ptr.flags & UCI_LOOKUP_COMPLETE)) + return NULL; + e = ptr.last; + switch (e->type) + { + case UCI_TYPE_SECTION: + value = uci_to_section(e)->type; + break; + case UCI_TYPE_OPTION: + switch(ptr.o->type) { + case UCI_TYPE_STRING: + value = ptr.o->v.string; + break; + default: + value = NULL; + break; + } + break; + default: + return 0; + } + + return value; +} + +void ucix_for_each_section_type(struct uci_context *ctx, + const char *p, const char *t, + void (*cb)(const char*, void*), void *priv) +{ + struct uci_element *e; + if(ucix_get_ptr(ctx, p, NULL, NULL, NULL)) + return; + uci_foreach_element(&ptr.p->sections, e) + if (!strcmp(t, uci_to_section(e)->type)) + cb(e->name, priv); +} + diff --git a/webgui/luci/freifunk-watchdog/src/ucix.h b/webgui/luci/freifunk-watchdog/src/ucix.h new file mode 100644 index 000000000..b1f5ec3f6 --- /dev/null +++ b/webgui/luci/freifunk-watchdog/src/ucix.h @@ -0,0 +1,29 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * Copyright (C) 2008 John Crispin + */ + +#ifndef _UCI_H__ +#define _UCI_H__ +struct uci_context* ucix_init(const char *config_file); + +void ucix_for_each_section_type(struct uci_context *ctx, + const char *p, const char *t, + void (*cb)(const char*, void*), void *priv); + +const char* ucix_get_option(struct uci_context *ctx, + const char *p, const char *s, const char *o); +#endif diff --git a/webgui/luci/freifunk-watchdog/src/watchdog.c b/webgui/luci/freifunk-watchdog/src/watchdog.c new file mode 100644 index 000000000..2d6e4a6f7 --- /dev/null +++ b/webgui/luci/freifunk-watchdog/src/watchdog.c @@ -0,0 +1,464 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * Copyright (C) 2009 Jo-Philipp Wich + */ + +#include "watchdog.h" + +/* Global watchdog fd, required by signal handler */ +int wdfd = -1; + +/* Handle finished childs */ +static void sigchld_handler(int sig) +{ + pid_t pid; + + while( (pid = waitpid(-1, NULL, WNOHANG)) > 0 ) + syslog(LOG_INFO, "Child returned (pid %d)", pid); +} + +/* Watchdog shutdown helper */ +static void shutdown_watchdog(int sig) +{ + static const char wshutdown = WATCH_SHUTDOWN; + + if( wdfd > -1 ) + { + syslog(LOG_INFO, "Stopping watchdog timer"); + write(wdfd, &wshutdown, 1); + close(wdfd); + wdfd = -1; + } + + exit(0); +} + +/* Get BSSID of given interface */ +static int iw_get_bssid(int iwfd, const char *ifname, char *bssid) +{ + struct iwreq iwrq; + + if( iw_ioctl(iwfd, ifname, SIOCGIWAP, &iwrq) >= 0 ) + { + unsigned char *addr = (unsigned char *)iwrq.u.ap_addr.sa_data; + + sprintf(bssid, "%02X:%02X:%02X:%02X:%02X:%02X", + addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); + + return 0; + } + + return -1; +} + +/* Get channel of given interface */ +static int iw_get_channel(int iwfd, const char *ifname, int *channel) +{ + int i; + char buffer[sizeof(struct iw_range)]; + double cur_freq, cmp_freq; + struct iwreq iwrq; + struct iw_range *range; + + memset(buffer, 0, sizeof(buffer)); + + iwrq.u.data.pointer = (char *)buffer; + iwrq.u.data.length = sizeof(buffer); + iwrq.u.data.flags = 0; + + if( iw_ioctl(iwfd, ifname, SIOCGIWRANGE, &iwrq) < 0) + { + *channel = -1; + return -1; + } + + range = (struct iw_range *)buffer; + + if( iw_ioctl(iwfd, ifname, SIOCGIWFREQ, &iwrq) >= 0 ) + { + cur_freq = ((double)iwrq.u.freq.m) * pow(10, iwrq.u.freq.e); + if( cur_freq < 1000.00 ) + { + *channel = (int)cur_freq; + return 0; + } + + for(i = 0; i < range->num_frequency; i++) + { + cmp_freq = ((double)range->freq[i].m) * pow(10, range->freq[i].e); + if( cmp_freq == cur_freq ) + { + *channel = (int)range->freq[i].i; + return 0; + } + } + } + + *channel = -1; + return -1; +} + +/* Get the (first) pid of given process name */ +static int find_process(const char *name) +{ + int pid = -1; + int file; + char buffer[128]; + char cmpname[128]; + DIR *dir; + struct dirent *entry; + + if( (dir = opendir("/proc")) != NULL ) + { + snprintf(cmpname, sizeof(cmpname), "Name:\t%s\n", name); + + while( (entry = readdir(dir)) != NULL ) + { + if( !strcmp(entry->d_name, "..") || !isdigit(*entry->d_name) ) + continue; + + sprintf(buffer, "/proc/%s/status", entry->d_name); + if( (file = open(buffer, O_RDONLY)) > -1 ) + { + read(file, buffer, sizeof(buffer)); + close(file); + + if( strstr(buffer, cmpname) == buffer ) + { + pid = atoi(entry->d_name); + + /* Skip myself ... */ + if( pid == getpid() ) + pid = -1; + else + break; + } + } + } + + closedir(dir); + return pid; + } + + syslog(LOG_CRIT, "Unable to open /proc: %s", + strerror(errno)); + + return -1; +} + +/* Get the 5 minute load average */ +static double find_loadavg(void) +{ + int fd; + char buffer[10]; + double load = 0.00; + + if( (fd = open("/proc/loadavg", O_RDONLY)) > -1 ) + { + if( read(fd, buffer, sizeof(buffer)) == sizeof(buffer) ) + load = atof(&buffer[5]); + + close(fd); + } + + return load; +} + +/* Check if given uci file was updated */ +static int check_uci_update(const char *config, time_t *mtime) +{ + struct stat s; + char path[128]; + + snprintf(path, sizeof(path), "/var/state/%s", config); + if( stat(path, &s) > -1 ) + { + if( (*mtime == 0) || (s.st_mtime > *mtime) ) + { + *mtime = s.st_mtime; + return 1; + } + } + + return 0; +} + +/* Add tuple */ +static void load_wifi_uci_add_iface(const char *section, struct uci_itr_ctx *itr) +{ + wifi_tuple_t *t; + const char *ucitmp; + int val = 0; + + ucitmp = ucix_get_option(itr->ctx, "wireless", section, "mode"); + if( ucitmp && !strncmp(ucitmp, "adhoc", 5) ) + { + if( (t = (wifi_tuple_t *)malloc(sizeof(wifi_tuple_t))) != NULL ) + { + ucitmp = ucix_get_option(itr->ctx, "wireless", section, "ifname"); + if(ucitmp) + { + strncpy(t->ifname, ucitmp, sizeof(t->ifname)); + val++; + } + + ucitmp = ucix_get_option(itr->ctx, "wireless", section, "bssid"); + if(ucitmp) + { + strncpy(t->bssid, ucitmp, sizeof(t->bssid)); + val++; + } + + ucitmp = ucix_get_option(itr->ctx, "wireless", section, "device"); + if(ucitmp) + { + ucitmp = ucix_get_option(itr->ctx, "wireless", ucitmp, "channel"); + if(ucitmp) + { + t->channel = atoi(ucitmp); + val++; + } + } + + if( val == 3 ) + { + syslog(LOG_INFO, "Monitoring %s: bssid=%s channel=%d", + t->ifname, t->bssid, t->channel); + + t->next = itr->list; + itr->list = t; + } + else + { + free(t); + } + } + } +} + +/* Load config */ +static wifi_tuple_t * load_wifi_uci(wifi_tuple_t *ifs, time_t *modtime) +{ + struct uci_context *ctx; + struct uci_itr_ctx itr; + wifi_tuple_t *cur, *next; + + if( check_uci_update("wireless", modtime) ) + { + syslog(LOG_INFO, "Config changed, reloading"); + + if( (ctx = ucix_init("wireless")) != NULL ) + { + if( ifs != NULL ) + { + for(cur = ifs; cur; cur = next) + { + next = cur->next; + free(cur); + } + } + + itr.list = NULL; + itr.ctx = ctx; + + ucix_for_each_section_type(ctx, "wireless", "wifi-iface", + (void *)load_wifi_uci_add_iface, &itr); + + return itr.list; + } + } + + return ifs; +} + +/* Daemon implementation */ +static int do_daemon(void) +{ + static int wdtrigger = 1; + static int wdtimeout = BASE_INTERVAL * 2; + static const char wdkeepalive = WATCH_KEEPALIVE; + + int iwfd; + int channel; + char bssid[18]; + struct sigaction sa; + + wifi_tuple_t *ifs = NULL, *curif; + time_t modtime = 0; + + int action_intv = 0; + int restart_wifi = 0; + int restart_cron = 0; + int restart_sshd = 0; + int loadavg_panic = 0; + + openlog(SYSLOG_IDENT, 0, LOG_DAEMON); + memset(&sa, 0, sizeof(sa)); + + if( (iwfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1 ) + { + syslog(LOG_ERR, "Can not open wireless control socket: %s", + strerror(errno)); + + return 1; + } + + if( (wdfd = open(WATCH_DEVICE, O_WRONLY)) > -1 ) + { + syslog(LOG_INFO, "Opened %s - polling every %i seconds", + WATCH_DEVICE, BASE_INTERVAL); + + /* Install signal handler to halt watchdog on shutdown */ + sa.sa_handler = shutdown_watchdog; + sa.sa_flags = SA_NOCLDWAIT | SA_RESTART; + sigaction(SIGHUP, &sa, NULL); + sigaction(SIGINT, &sa, NULL); + sigaction(SIGPIPE, &sa, NULL); + sigaction(SIGTERM, &sa, NULL); + sigaction(SIGUSR1, &sa, NULL); + sigaction(SIGUSR2, &sa, NULL); + + /* Set watchdog timeout to twice the interval */ + ioctl(wdfd, WDIOC_SETTIMEOUT, &wdtimeout); + } + + /* Install signal handler to reap childs */ + sa.sa_handler = sigchld_handler; + sa.sa_flags = 0; + sigaction(SIGCHLD, &sa, NULL); + + while( 1 ) + { + /* Check/increment action interval */ + if( ++action_intv >= ACTION_INTERVAL ) + { + /* Reset action interval */ + action_intv = 0; + + /* Check average load */ + if( find_loadavg() >= LOAD_TRESHOLD ) + loadavg_panic++; + else + loadavg_panic = 0; + + /* Check crond */ + if( find_process("crond") < 0 ) + restart_cron++; + else + restart_cron = 0; + + /* Check SSHd */ + if( find_process("dropbear") < 0 ) + restart_sshd++; + else + restart_sshd = 0; + + /* Check wireless interfaces */ + ifs = load_wifi_uci(ifs, &modtime); + for( curif = ifs; curif; curif = curif->next ) + { + /* Get current channel and bssid */ + if( (iw_get_bssid(iwfd, curif->ifname, bssid) == 0) && + (iw_get_channel(iwfd, curif->ifname, &channel) == 0) ) + { + /* Check BSSID */ + if( strcasecmp(bssid, curif->bssid) != 0 ) + { + syslog(LOG_WARNING, "BSSID mismatch on %s: current=%s wanted=%s", + curif->ifname, bssid, curif->bssid); + + restart_wifi++; + } + + /* Check channel */ + else if( channel != curif->channel ) + { + syslog(LOG_WARNING, "Channel mismatch on %s: current=%d wanted=%d", + curif->ifname, channel, curif->channel); + + restart_wifi++; + } + } + else + { + syslog(LOG_WARNING, "Requested interface %s not present", curif->ifname); + } + } + + + /* Wifi restart required? */ + if( restart_wifi >= HYSTERESIS ) + { + restart_wifi = 0; + syslog(LOG_WARNING, "Channel or BSSID mismatch on wireless interface, restarting"); + EXEC(WIFI_ACTION); + } + + /* Cron restart required? */ + if( restart_cron >= HYSTERESIS ) + { + restart_cron = 0; + syslog(LOG_WARNING, "The cron process died, restarting"); + EXEC(CRON_ACTION); + } + + /* SSHd restart required? */ + if( restart_sshd >= HYSTERESIS ) + { + restart_sshd = 0; + syslog(LOG_WARNING, "The ssh process died, restarting"); + EXEC(SSHD_ACTION); + } + + /* Is there a load problem? */ + if( loadavg_panic >= HYSTERESIS ) + { + syslog(LOG_EMERG, "Critical system load level, triggering reset!"); + + /* Try watchdog, fall back to reboot */ + if( wdfd > -1 ) + ioctl(wdfd, WDIOC_SETTIMEOUT, &wdtrigger); + else + EXEC(LOAD_ACTION); + } + } + + + /* Reset watchdog timer */ + if( wdfd > -1 ) + write(wdfd, &wdkeepalive, 1); + + sleep(BASE_INTERVAL); + } + + shutdown_watchdog(0); + closelog(); + + return 0; +} + + +int main(int argc, char *argv[]) +{ + /* Check if watchdog is running ... */ + if( (argc > 1) && (strcmp(argv[1], "running") == 0) ) + { + return (find_process(BINARY) == -1); + } + + /* Start daemon */ + return do_daemon(); +} diff --git a/webgui/luci/freifunk-watchdog/src/watchdog.h b/webgui/luci/freifunk-watchdog/src/watchdog.h new file mode 100644 index 000000000..71c10e9c1 --- /dev/null +++ b/webgui/luci/freifunk-watchdog/src/watchdog.h @@ -0,0 +1,127 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * Copyright (C) 2009 Jo-Philipp Wich + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ucix.h" +#include "wireless.22.h" + + +/* Watchdog poll interval */ +#define BASE_INTERVAL 5 + +/* Action interval (N * BASE_INTERVAL) */ +#define ACTION_INTERVAL 6 + +/* Hysteresis */ +#define HYSTERESIS 3 + +/* How to call myself in the logs */ +#define SYSLOG_IDENT "Freifunk Watchdog" + +/* Wifi error action */ +#define WIFI_ACTION "/sbin/wifi", "/sbin/wifi" + +/* Crond error action */ +#define CRON_ACTION "/etc/init.d/cron", "/etc/init.d/cron", "restart" + +/* SSHd error action */ +#define SSHD_ACTION "/etc/init.d/dropbear", "/etc/init.d/dropbear", "restart" + +/* Watchdog device */ +#define WATCH_DEVICE "/dev/watchdog" +#define WATCH_SHUTDOWN 'V' +#define WATCH_KEEPALIVE '\0' + +/* System load error action and treshold */ +#define LOAD_TRESHOLD 15.00 +#define LOAD_ACTION "/sbin/reboot", "/sbin/reboot" + +/* Fallback binary name (passed by makefile) */ +#ifndef BINARY +#define BINARY "ffwatchd" +#endif + + +/* ifname/bssid/channel tuples */ +struct wifi_tuple { + char ifname[16]; + char bssid[18]; + int channel; + struct wifi_tuple *next; +}; + +/* structure to hold tuple-list and uci context during iteration */ +struct uci_itr_ctx { + struct wifi_tuple *list; + struct uci_context *ctx; +}; + +typedef struct wifi_tuple wifi_tuple_t; + + +/* ioctl() helper (stolen from iwlib) */ +static inline int +iw_ioctl(int skfd, /* Socket to the kernel */ + const char * ifname, /* Device name */ + int request, /* WE ID */ + struct iwreq * pwrq) /* Fixed part of the request */ +{ + /* Set device name */ + strncpy(pwrq->ifr_ifrn.ifrn_name, ifname, 16); + + /* Do the request */ + return(ioctl(skfd, request, pwrq)); +} + +/* fork() & execl() helper */ +#define EXEC(x) \ + do { \ + switch(fork()) \ + { \ + case -1: \ + syslog(LOG_CRIT, "Unable to fork child: %s", \ + strerror(errno)); \ + break; \ + \ + case 0: \ + execl(x, NULL); \ + syslog(LOG_CRIT, "Unable to execute action: %s", \ + strerror(errno)); \ + return 1; \ + } \ + } while(0) + diff --git a/webgui/luci/freifunk-watchdog/src/wireless.22.h b/webgui/luci/freifunk-watchdog/src/wireless.22.h new file mode 100644 index 000000000..1d19243f3 --- /dev/null +++ b/webgui/luci/freifunk-watchdog/src/wireless.22.h @@ -0,0 +1,1139 @@ +/* + * This file define a set of standard wireless extensions + * + * Version : 22 16.3.07 + * + * Authors : Jean Tourrilhes - HPL - + * Copyright (c) 1997-2007 Jean Tourrilhes, All Rights Reserved. + */ + +#ifndef _LINUX_WIRELESS_H +#define _LINUX_WIRELESS_H + +/************************** DOCUMENTATION **************************/ +/* + * Initial APIs (1996 -> onward) : + * ----------------------------- + * Basically, the wireless extensions are for now a set of standard ioctl + * call + /proc/net/wireless + * + * The entry /proc/net/wireless give statistics and information on the + * driver. + * This is better than having each driver having its entry because + * its centralised and we may remove the driver module safely. + * + * Ioctl are used to configure the driver and issue commands. This is + * better than command line options of insmod because we may want to + * change dynamically (while the driver is running) some parameters. + * + * The ioctl mechanimsm are copied from standard devices ioctl. + * We have the list of command plus a structure descibing the + * data exchanged... + * Note that to add these ioctl, I was obliged to modify : + * # net/core/dev.c (two place + add include) + * # net/ipv4/af_inet.c (one place + add include) + * + * /proc/net/wireless is a copy of /proc/net/dev. + * We have a structure for data passed from the driver to /proc/net/wireless + * Too add this, I've modified : + * # net/core/dev.c (two other places) + * # include/linux/netdevice.h (one place) + * # include/linux/proc_fs.h (one place) + * + * New driver API (2002 -> onward) : + * ------------------------------- + * This file is only concerned with the user space API and common definitions. + * The new driver API is defined and documented in : + * # include/net/iw_handler.h + * + * Note as well that /proc/net/wireless implementation has now moved in : + * # net/core/wireless.c + * + * Wireless Events (2002 -> onward) : + * -------------------------------- + * Events are defined at the end of this file, and implemented in : + * # net/core/wireless.c + * + * Other comments : + * -------------- + * Do not add here things that are redundant with other mechanisms + * (drivers init, ifconfig, /proc/net/dev, ...) and with are not + * wireless specific. + * + * These wireless extensions are not magic : each driver has to provide + * support for them... + * + * IMPORTANT NOTE : As everything in the kernel, this is very much a + * work in progress. Contact me if you have ideas of improvements... + */ + +/***************************** INCLUDES *****************************/ + +/* This header is used in user-space, therefore need to be sanitised + * for that purpose. Those includes are usually not compatible with glibc. + * To know which includes to use in user-space, check iwlib.h. */ +#ifdef __KERNEL__ +#include /* for "caddr_t" et al */ +#include /* for "struct sockaddr" et al */ +#include /* for IFNAMSIZ and co... */ +#endif /* __KERNEL__ */ + +/***************************** VERSION *****************************/ +/* + * This constant is used to know the availability of the wireless + * extensions and to know which version of wireless extensions it is + * (there is some stuff that will be added in the future...) + * I just plan to increment with each new version. + */ +#define WIRELESS_EXT 22 + +/* + * Changes : + * + * V2 to V3 + * -------- + * Alan Cox start some incompatibles changes. I've integrated a bit more. + * - Encryption renamed to Encode to avoid US regulation problems + * - Frequency changed from float to struct to avoid problems on old 386 + * + * V3 to V4 + * -------- + * - Add sensitivity + * + * V4 to V5 + * -------- + * - Missing encoding definitions in range + * - Access points stuff + * + * V5 to V6 + * -------- + * - 802.11 support (ESSID ioctls) + * + * V6 to V7 + * -------- + * - define IW_ESSID_MAX_SIZE and IW_MAX_AP + * + * V7 to V8 + * -------- + * - Changed my e-mail address + * - More 802.11 support (nickname, rate, rts, frag) + * - List index in frequencies + * + * V8 to V9 + * -------- + * - Support for 'mode of operation' (ad-hoc, managed...) + * - Support for unicast and multicast power saving + * - Change encoding to support larger tokens (>64 bits) + * - Updated iw_params (disable, flags) and use it for NWID + * - Extracted iw_point from iwreq for clarity + * + * V9 to V10 + * --------- + * - Add PM capability to range structure + * - Add PM modifier : MAX/MIN/RELATIVE + * - Add encoding option : IW_ENCODE_NOKEY + * - Add TxPower ioctls (work like TxRate) + * + * V10 to V11 + * ---------- + * - Add WE version in range (help backward/forward compatibility) + * - Add retry ioctls (work like PM) + * + * V11 to V12 + * ---------- + * - Add SIOCSIWSTATS to get /proc/net/wireless programatically + * - Add DEV PRIVATE IOCTL to avoid collisions in SIOCDEVPRIVATE space + * - Add new statistics (frag, retry, beacon) + * - Add average quality (for user space calibration) + * + * V12 to V13 + * ---------- + * - Document creation of new driver API. + * - Extract union iwreq_data from struct iwreq (for new driver API). + * - Rename SIOCSIWNAME as SIOCSIWCOMMIT + * + * V13 to V14 + * ---------- + * - Wireless Events support : define struct iw_event + * - Define additional specific event numbers + * - Add "addr" and "param" fields in union iwreq_data + * - AP scanning stuff (SIOCSIWSCAN and friends) + * + * V14 to V15 + * ---------- + * - Add IW_PRIV_TYPE_ADDR for struct sockaddr private arg + * - Make struct iw_freq signed (both m & e), add explicit padding + * - Add IWEVCUSTOM for driver specific event/scanning token + * - Add IW_MAX_GET_SPY for driver returning a lot of addresses + * - Add IW_TXPOW_RANGE for range of Tx Powers + * - Add IWEVREGISTERED & IWEVEXPIRED events for Access Points + * - Add IW_MODE_MONITOR for passive monitor + * + * V15 to V16 + * ---------- + * - Increase the number of bitrates in iw_range to 32 (for 802.11g) + * - Increase the number of frequencies in iw_range to 32 (for 802.11b+a) + * - Reshuffle struct iw_range for increases, add filler + * - Increase IW_MAX_AP to 64 for driver returning a lot of addresses + * - Remove IW_MAX_GET_SPY because conflict with enhanced spy support + * - Add SIOCSIWTHRSPY/SIOCGIWTHRSPY and "struct iw_thrspy" + * - Add IW_ENCODE_TEMP and iw_range->encoding_login_index + * + * V16 to V17 + * ---------- + * - Add flags to frequency -> auto/fixed + * - Document (struct iw_quality *)->updated, add new flags (INVALID) + * - Wireless Event capability in struct iw_range + * - Add support for relative TxPower (yick !) + * + * V17 to V18 (From Jouni Malinen ) + * ---------- + * - Add support for WPA/WPA2 + * - Add extended encoding configuration (SIOCSIWENCODEEXT and + * SIOCGIWENCODEEXT) + * - Add SIOCSIWGENIE/SIOCGIWGENIE + * - Add SIOCSIWMLME + * - Add SIOCSIWPMKSA + * - Add struct iw_range bit field for supported encoding capabilities + * - Add optional scan request parameters for SIOCSIWSCAN + * - Add SIOCSIWAUTH/SIOCGIWAUTH for setting authentication and WPA + * related parameters (extensible up to 4096 parameter values) + * - Add wireless events: IWEVGENIE, IWEVMICHAELMICFAILURE, + * IWEVASSOCREQIE, IWEVASSOCRESPIE, IWEVPMKIDCAND + * + * V18 to V19 + * ---------- + * - Remove (struct iw_point *)->pointer from events and streams + * - Remove header includes to help user space + * - Increase IW_ENCODING_TOKEN_MAX from 32 to 64 + * - Add IW_QUAL_ALL_UPDATED and IW_QUAL_ALL_INVALID macros + * - Add explicit flag to tell stats are in dBm : IW_QUAL_DBM + * - Add IW_IOCTL_IDX() and IW_EVENT_IDX() macros + * + * V19 to V20 + * ---------- + * - RtNetlink requests support (SET/GET) + * + * V20 to V21 + * ---------- + * - Remove (struct net_device *)->get_wireless_stats() + * - Change length in ESSID and NICK to strlen() instead of strlen()+1 + * - Add IW_RETRY_SHORT/IW_RETRY_LONG retry modifiers + * - Power/Retry relative values no longer * 100000 + * - Add explicit flag to tell stats are in 802.11k RCPI : IW_QUAL_RCPI + * + * V21 to V22 + * ---------- + * - Prevent leaking of kernel space in stream on 64 bits. + */ + +/**************************** CONSTANTS ****************************/ + +/* -------------------------- IOCTL LIST -------------------------- */ + +/* Wireless Identification */ +#define SIOCSIWCOMMIT 0x8B00 /* Commit pending changes to driver */ +#define SIOCGIWNAME 0x8B01 /* get name == wireless protocol */ +/* SIOCGIWNAME is used to verify the presence of Wireless Extensions. + * Common values : "IEEE 802.11-DS", "IEEE 802.11-FH", "IEEE 802.11b"... + * Don't put the name of your driver there, it's useless. */ + +/* Basic operations */ +#define SIOCSIWNWID 0x8B02 /* set network id (pre-802.11) */ +#define SIOCGIWNWID 0x8B03 /* get network id (the cell) */ +#define SIOCSIWFREQ 0x8B04 /* set channel/frequency (Hz) */ +#define SIOCGIWFREQ 0x8B05 /* get channel/frequency (Hz) */ +#define SIOCSIWMODE 0x8B06 /* set operation mode */ +#define SIOCGIWMODE 0x8B07 /* get operation mode */ +#define SIOCSIWSENS 0x8B08 /* set sensitivity (dBm) */ +#define SIOCGIWSENS 0x8B09 /* get sensitivity (dBm) */ + +/* Informative stuff */ +#define SIOCSIWRANGE 0x8B0A /* Unused */ +#define SIOCGIWRANGE 0x8B0B /* Get range of parameters */ +#define SIOCSIWPRIV 0x8B0C /* Unused */ +#define SIOCGIWPRIV 0x8B0D /* get private ioctl interface info */ +#define SIOCSIWSTATS 0x8B0E /* Unused */ +#define SIOCGIWSTATS 0x8B0F /* Get /proc/net/wireless stats */ +/* SIOCGIWSTATS is strictly used between user space and the kernel, and + * is never passed to the driver (i.e. the driver will never see it). */ + +/* Spy support (statistics per MAC address - used for Mobile IP support) */ +#define SIOCSIWSPY 0x8B10 /* set spy addresses */ +#define SIOCGIWSPY 0x8B11 /* get spy info (quality of link) */ +#define SIOCSIWTHRSPY 0x8B12 /* set spy threshold (spy event) */ +#define SIOCGIWTHRSPY 0x8B13 /* get spy threshold */ + +/* Access Point manipulation */ +#define SIOCSIWAP 0x8B14 /* set access point MAC addresses */ +#define SIOCGIWAP 0x8B15 /* get access point MAC addresses */ +#define SIOCGIWAPLIST 0x8B17 /* Deprecated in favor of scanning */ +#define SIOCSIWSCAN 0x8B18 /* trigger scanning (list cells) */ +#define SIOCGIWSCAN 0x8B19 /* get scanning results */ + +/* 802.11 specific support */ +#define SIOCSIWESSID 0x8B1A /* set ESSID (network name) */ +#define SIOCGIWESSID 0x8B1B /* get ESSID */ +#define SIOCSIWNICKN 0x8B1C /* set node name/nickname */ +#define SIOCGIWNICKN 0x8B1D /* get node name/nickname */ +/* As the ESSID and NICKN are strings up to 32 bytes long, it doesn't fit + * within the 'iwreq' structure, so we need to use the 'data' member to + * point to a string in user space, like it is done for RANGE... */ + +/* Other parameters useful in 802.11 and some other devices */ +#define SIOCSIWRATE 0x8B20 /* set default bit rate (bps) */ +#define SIOCGIWRATE 0x8B21 /* get default bit rate (bps) */ +#define SIOCSIWRTS 0x8B22 /* set RTS/CTS threshold (bytes) */ +#define SIOCGIWRTS 0x8B23 /* get RTS/CTS threshold (bytes) */ +#define SIOCSIWFRAG 0x8B24 /* set fragmentation thr (bytes) */ +#define SIOCGIWFRAG 0x8B25 /* get fragmentation thr (bytes) */ +#define SIOCSIWTXPOW 0x8B26 /* set transmit power (dBm) */ +#define SIOCGIWTXPOW 0x8B27 /* get transmit power (dBm) */ +#define SIOCSIWRETRY 0x8B28 /* set retry limits and lifetime */ +#define SIOCGIWRETRY 0x8B29 /* get retry limits and lifetime */ + +/* Encoding stuff (scrambling, hardware security, WEP...) */ +#define SIOCSIWENCODE 0x8B2A /* set encoding token & mode */ +#define SIOCGIWENCODE 0x8B2B /* get encoding token & mode */ +/* Power saving stuff (power management, unicast and multicast) */ +#define SIOCSIWPOWER 0x8B2C /* set Power Management settings */ +#define SIOCGIWPOWER 0x8B2D /* get Power Management settings */ +/* Modulation bitmask */ +#define SIOCSIWMODUL 0x8B2E /* set Modulations settings */ +#define SIOCGIWMODUL 0x8B2F /* get Modulations settings */ + +/* WPA : Generic IEEE 802.11 informatiom element (e.g., for WPA/RSN/WMM). + * This ioctl uses struct iw_point and data buffer that includes IE id and len + * fields. More than one IE may be included in the request. Setting the generic + * IE to empty buffer (len=0) removes the generic IE from the driver. Drivers + * are allowed to generate their own WPA/RSN IEs, but in these cases, drivers + * are required to report the used IE as a wireless event, e.g., when + * associating with an AP. */ +#define SIOCSIWGENIE 0x8B30 /* set generic IE */ +#define SIOCGIWGENIE 0x8B31 /* get generic IE */ + +/* WPA : IEEE 802.11 MLME requests */ +#define SIOCSIWMLME 0x8B16 /* request MLME operation; uses + * struct iw_mlme */ +/* WPA : Authentication mode parameters */ +#define SIOCSIWAUTH 0x8B32 /* set authentication mode params */ +#define SIOCGIWAUTH 0x8B33 /* get authentication mode params */ + +/* WPA : Extended version of encoding configuration */ +#define SIOCSIWENCODEEXT 0x8B34 /* set encoding token & mode */ +#define SIOCGIWENCODEEXT 0x8B35 /* get encoding token & mode */ + +/* WPA2 : PMKSA cache management */ +#define SIOCSIWPMKSA 0x8B36 /* PMKSA cache operation */ + +/* -------------------- DEV PRIVATE IOCTL LIST -------------------- */ + +/* These 32 ioctl are wireless device private, for 16 commands. + * Each driver is free to use them for whatever purpose it chooses, + * however the driver *must* export the description of those ioctls + * with SIOCGIWPRIV and *must* use arguments as defined below. + * If you don't follow those rules, DaveM is going to hate you (reason : + * it make mixed 32/64bit operation impossible). + */ +#define SIOCIWFIRSTPRIV 0x8BE0 +#define SIOCIWLASTPRIV 0x8BFF +/* Previously, we were using SIOCDEVPRIVATE, but we now have our + * separate range because of collisions with other tools such as + * 'mii-tool'. + * We now have 32 commands, so a bit more space ;-). + * Also, all 'even' commands are only usable by root and don't return the + * content of ifr/iwr to user (but you are not obliged to use the set/get + * convention, just use every other two command). More details in iwpriv.c. + * And I repeat : you are not forced to use them with iwpriv, but you + * must be compliant with it. + */ + +/* ------------------------- IOCTL STUFF ------------------------- */ + +/* The first and the last (range) */ +#define SIOCIWFIRST 0x8B00 +#define SIOCIWLAST SIOCIWLASTPRIV /* 0x8BFF */ +#define IW_IOCTL_IDX(cmd) ((cmd) - SIOCIWFIRST) + +/* Odd : get (world access), even : set (root access) */ +#define IW_IS_SET(cmd) (!((cmd) & 0x1)) +#define IW_IS_GET(cmd) ((cmd) & 0x1) + +/* ----------------------- WIRELESS EVENTS ----------------------- */ +/* Those are *NOT* ioctls, do not issue request on them !!! */ +/* Most events use the same identifier as ioctl requests */ + +#define IWEVTXDROP 0x8C00 /* Packet dropped to excessive retry */ +#define IWEVQUAL 0x8C01 /* Quality part of statistics (scan) */ +#define IWEVCUSTOM 0x8C02 /* Driver specific ascii string */ +#define IWEVREGISTERED 0x8C03 /* Discovered a new node (AP mode) */ +#define IWEVEXPIRED 0x8C04 /* Expired a node (AP mode) */ +#define IWEVGENIE 0x8C05 /* Generic IE (WPA, RSN, WMM, ..) + * (scan results); This includes id and + * length fields. One IWEVGENIE may + * contain more than one IE. Scan + * results may contain one or more + * IWEVGENIE events. */ +#define IWEVMICHAELMICFAILURE 0x8C06 /* Michael MIC failure + * (struct iw_michaelmicfailure) + */ +#define IWEVASSOCREQIE 0x8C07 /* IEs used in (Re)Association Request. + * The data includes id and length + * fields and may contain more than one + * IE. This event is required in + * Managed mode if the driver + * generates its own WPA/RSN IE. This + * should be sent just before + * IWEVREGISTERED event for the + * association. */ +#define IWEVASSOCRESPIE 0x8C08 /* IEs used in (Re)Association + * Response. The data includes id and + * length fields and may contain more + * than one IE. This may be sent + * between IWEVASSOCREQIE and + * IWEVREGISTERED events for the + * association. */ +#define IWEVPMKIDCAND 0x8C09 /* PMKID candidate for RSN + * pre-authentication + * (struct iw_pmkid_cand) */ + +#define IWEVFIRST 0x8C00 +#define IW_EVENT_IDX(cmd) ((cmd) - IWEVFIRST) + +/* ------------------------- PRIVATE INFO ------------------------- */ +/* + * The following is used with SIOCGIWPRIV. It allow a driver to define + * the interface (name, type of data) for its private ioctl. + * Privates ioctl are SIOCIWFIRSTPRIV -> SIOCIWLASTPRIV + */ + +#define IW_PRIV_TYPE_MASK 0x7000 /* Type of arguments */ +#define IW_PRIV_TYPE_NONE 0x0000 +#define IW_PRIV_TYPE_BYTE 0x1000 /* Char as number */ +#define IW_PRIV_TYPE_CHAR 0x2000 /* Char as character */ +#define IW_PRIV_TYPE_INT 0x4000 /* 32 bits int */ +#define IW_PRIV_TYPE_FLOAT 0x5000 /* struct iw_freq */ +#define IW_PRIV_TYPE_ADDR 0x6000 /* struct sockaddr */ + +#define IW_PRIV_SIZE_FIXED 0x0800 /* Variable or fixed number of args */ + +#define IW_PRIV_SIZE_MASK 0x07FF /* Max number of those args */ + +/* + * Note : if the number of args is fixed and the size < 16 octets, + * instead of passing a pointer we will put args in the iwreq struct... + */ + +/* ----------------------- OTHER CONSTANTS ----------------------- */ + +/* Maximum frequencies in the range struct */ +#define IW_MAX_FREQUENCIES 32 +/* Note : if you have something like 80 frequencies, + * don't increase this constant and don't fill the frequency list. + * The user will be able to set by channel anyway... */ + +/* Maximum bit rates in the range struct */ +#define IW_MAX_BITRATES 32 + +/* Maximum tx powers in the range struct */ +#define IW_MAX_TXPOWER 8 +/* Note : if you more than 8 TXPowers, just set the max and min or + * a few of them in the struct iw_range. */ + +/* Maximum of address that you may set with SPY */ +#define IW_MAX_SPY 8 + +/* Maximum of address that you may get in the + list of access points in range */ +#define IW_MAX_AP 64 + +/* Maximum size of the ESSID and NICKN strings */ +#define IW_ESSID_MAX_SIZE 32 + +/* Modes of operation */ +#define IW_MODE_AUTO 0 /* Let the driver decides */ +#define IW_MODE_ADHOC 1 /* Single cell network */ +#define IW_MODE_INFRA 2 /* Multi cell network, roaming, ... */ +#define IW_MODE_MASTER 3 /* Synchronisation master or Access Point */ +#define IW_MODE_REPEAT 4 /* Wireless Repeater (forwarder) */ +#define IW_MODE_SECOND 5 /* Secondary master/repeater (backup) */ +#define IW_MODE_MONITOR 6 /* Passive monitor (listen only) */ + +/* Statistics flags (bitmask in updated) */ +#define IW_QUAL_QUAL_UPDATED 0x01 /* Value was updated since last read */ +#define IW_QUAL_LEVEL_UPDATED 0x02 +#define IW_QUAL_NOISE_UPDATED 0x04 +#define IW_QUAL_ALL_UPDATED 0x07 +#define IW_QUAL_DBM 0x08 /* Level + Noise are dBm */ +#define IW_QUAL_QUAL_INVALID 0x10 /* Driver doesn't provide value */ +#define IW_QUAL_LEVEL_INVALID 0x20 +#define IW_QUAL_NOISE_INVALID 0x40 +#define IW_QUAL_RCPI 0x80 /* Level + Noise are 802.11k RCPI */ +#define IW_QUAL_ALL_INVALID 0x70 + +/* Frequency flags */ +#define IW_FREQ_AUTO 0x00 /* Let the driver decides */ +#define IW_FREQ_FIXED 0x01 /* Force a specific value */ + +/* Maximum number of size of encoding token available + * they are listed in the range structure */ +#define IW_MAX_ENCODING_SIZES 8 + +/* Maximum size of the encoding token in bytes */ +#define IW_ENCODING_TOKEN_MAX 64 /* 512 bits (for now) */ + +/* Flags for encoding (along with the token) */ +#define IW_ENCODE_INDEX 0x00FF /* Token index (if needed) */ +#define IW_ENCODE_FLAGS 0xFF00 /* Flags defined below */ +#define IW_ENCODE_MODE 0xF000 /* Modes defined below */ +#define IW_ENCODE_DISABLED 0x8000 /* Encoding disabled */ +#define IW_ENCODE_ENABLED 0x0000 /* Encoding enabled */ +#define IW_ENCODE_RESTRICTED 0x4000 /* Refuse non-encoded packets */ +#define IW_ENCODE_OPEN 0x2000 /* Accept non-encoded packets */ +#define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */ +#define IW_ENCODE_TEMP 0x0400 /* Temporary key */ + +/* Power management flags available (along with the value, if any) */ +#define IW_POWER_ON 0x0000 /* No details... */ +#define IW_POWER_TYPE 0xF000 /* Type of parameter */ +#define IW_POWER_PERIOD 0x1000 /* Value is a period/duration of */ +#define IW_POWER_TIMEOUT 0x2000 /* Value is a timeout (to go asleep) */ +#define IW_POWER_SAVING 0x4000 /* Value is relative (how aggressive)*/ +#define IW_POWER_MODE 0x0F00 /* Power Management mode */ +#define IW_POWER_UNICAST_R 0x0100 /* Receive only unicast messages */ +#define IW_POWER_MULTICAST_R 0x0200 /* Receive only multicast messages */ +#define IW_POWER_ALL_R 0x0300 /* Receive all messages though PM */ +#define IW_POWER_FORCE_S 0x0400 /* Force PM procedure for sending unicast */ +#define IW_POWER_REPEATER 0x0800 /* Repeat broadcast messages in PM period */ +#define IW_POWER_MODIFIER 0x000F /* Modify a parameter */ +#define IW_POWER_MIN 0x0001 /* Value is a minimum */ +#define IW_POWER_MAX 0x0002 /* Value is a maximum */ +#define IW_POWER_RELATIVE 0x0004 /* Value is not in seconds/ms/us */ + +/* Transmit Power flags available */ +#define IW_TXPOW_TYPE 0x00FF /* Type of value */ +#define IW_TXPOW_DBM 0x0000 /* Value is in dBm */ +#define IW_TXPOW_MWATT 0x0001 /* Value is in mW */ +#define IW_TXPOW_RELATIVE 0x0002 /* Value is in arbitrary units */ +#define IW_TXPOW_RANGE 0x1000 /* Range of value between min/max */ + +/* Retry limits and lifetime flags available */ +#define IW_RETRY_ON 0x0000 /* No details... */ +#define IW_RETRY_TYPE 0xF000 /* Type of parameter */ +#define IW_RETRY_LIMIT 0x1000 /* Maximum number of retries*/ +#define IW_RETRY_LIFETIME 0x2000 /* Maximum duration of retries in us */ +#define IW_RETRY_MODIFIER 0x00FF /* Modify a parameter */ +#define IW_RETRY_MIN 0x0001 /* Value is a minimum */ +#define IW_RETRY_MAX 0x0002 /* Value is a maximum */ +#define IW_RETRY_RELATIVE 0x0004 /* Value is not in seconds/ms/us */ +#define IW_RETRY_SHORT 0x0010 /* Value is for short packets */ +#define IW_RETRY_LONG 0x0020 /* Value is for long packets */ + +/* Scanning request flags */ +#define IW_SCAN_DEFAULT 0x0000 /* Default scan of the driver */ +#define IW_SCAN_ALL_ESSID 0x0001 /* Scan all ESSIDs */ +#define IW_SCAN_THIS_ESSID 0x0002 /* Scan only this ESSID */ +#define IW_SCAN_ALL_FREQ 0x0004 /* Scan all Frequencies */ +#define IW_SCAN_THIS_FREQ 0x0008 /* Scan only this Frequency */ +#define IW_SCAN_ALL_MODE 0x0010 /* Scan all Modes */ +#define IW_SCAN_THIS_MODE 0x0020 /* Scan only this Mode */ +#define IW_SCAN_ALL_RATE 0x0040 /* Scan all Bit-Rates */ +#define IW_SCAN_THIS_RATE 0x0080 /* Scan only this Bit-Rate */ +/* struct iw_scan_req scan_type */ +#define IW_SCAN_TYPE_ACTIVE 0 +#define IW_SCAN_TYPE_PASSIVE 1 +/* Maximum size of returned data */ +#define IW_SCAN_MAX_DATA 4096 /* In bytes */ + +/* Max number of char in custom event - use multiple of them if needed */ +#define IW_CUSTOM_MAX 256 /* In bytes */ + +/* Generic information element */ +#define IW_GENERIC_IE_MAX 1024 + +/* MLME requests (SIOCSIWMLME / struct iw_mlme) */ +#define IW_MLME_DEAUTH 0 +#define IW_MLME_DISASSOC 1 +#define IW_MLME_AUTH 2 +#define IW_MLME_ASSOC 3 + +/* SIOCSIWAUTH/SIOCGIWAUTH struct iw_param flags */ +#define IW_AUTH_INDEX 0x0FFF +#define IW_AUTH_FLAGS 0xF000 +/* SIOCSIWAUTH/SIOCGIWAUTH parameters (0 .. 4095) + * (IW_AUTH_INDEX mask in struct iw_param flags; this is the index of the + * parameter that is being set/get to; value will be read/written to + * struct iw_param value field) */ +#define IW_AUTH_WPA_VERSION 0 +#define IW_AUTH_CIPHER_PAIRWISE 1 +#define IW_AUTH_CIPHER_GROUP 2 +#define IW_AUTH_KEY_MGMT 3 +#define IW_AUTH_TKIP_COUNTERMEASURES 4 +#define IW_AUTH_DROP_UNENCRYPTED 5 +#define IW_AUTH_80211_AUTH_ALG 6 +#define IW_AUTH_WPA_ENABLED 7 +#define IW_AUTH_RX_UNENCRYPTED_EAPOL 8 +#define IW_AUTH_ROAMING_CONTROL 9 +#define IW_AUTH_PRIVACY_INVOKED 10 + +/* IW_AUTH_WPA_VERSION values (bit field) */ +#define IW_AUTH_WPA_VERSION_DISABLED 0x00000001 +#define IW_AUTH_WPA_VERSION_WPA 0x00000002 +#define IW_AUTH_WPA_VERSION_WPA2 0x00000004 + +/* IW_AUTH_PAIRWISE_CIPHER and IW_AUTH_GROUP_CIPHER values (bit field) */ +#define IW_AUTH_CIPHER_NONE 0x00000001 +#define IW_AUTH_CIPHER_WEP40 0x00000002 +#define IW_AUTH_CIPHER_TKIP 0x00000004 +#define IW_AUTH_CIPHER_CCMP 0x00000008 +#define IW_AUTH_CIPHER_WEP104 0x00000010 + +/* IW_AUTH_KEY_MGMT values (bit field) */ +#define IW_AUTH_KEY_MGMT_802_1X 1 +#define IW_AUTH_KEY_MGMT_PSK 2 + +/* IW_AUTH_80211_AUTH_ALG values (bit field) */ +#define IW_AUTH_ALG_OPEN_SYSTEM 0x00000001 +#define IW_AUTH_ALG_SHARED_KEY 0x00000002 +#define IW_AUTH_ALG_LEAP 0x00000004 + +/* IW_AUTH_ROAMING_CONTROL values */ +#define IW_AUTH_ROAMING_ENABLE 0 /* driver/firmware based roaming */ +#define IW_AUTH_ROAMING_DISABLE 1 /* user space program used for roaming + * control */ + +/* SIOCSIWENCODEEXT definitions */ +#define IW_ENCODE_SEQ_MAX_SIZE 8 +/* struct iw_encode_ext ->alg */ +#define IW_ENCODE_ALG_NONE 0 +#define IW_ENCODE_ALG_WEP 1 +#define IW_ENCODE_ALG_TKIP 2 +#define IW_ENCODE_ALG_CCMP 3 +/* struct iw_encode_ext ->ext_flags */ +#define IW_ENCODE_EXT_TX_SEQ_VALID 0x00000001 +#define IW_ENCODE_EXT_RX_SEQ_VALID 0x00000002 +#define IW_ENCODE_EXT_GROUP_KEY 0x00000004 +#define IW_ENCODE_EXT_SET_TX_KEY 0x00000008 + +/* IWEVMICHAELMICFAILURE : struct iw_michaelmicfailure ->flags */ +#define IW_MICFAILURE_KEY_ID 0x00000003 /* Key ID 0..3 */ +#define IW_MICFAILURE_GROUP 0x00000004 +#define IW_MICFAILURE_PAIRWISE 0x00000008 +#define IW_MICFAILURE_STAKEY 0x00000010 +#define IW_MICFAILURE_COUNT 0x00000060 /* 1 or 2 (0 = count not supported) + */ + +/* Bit field values for enc_capa in struct iw_range */ +#define IW_ENC_CAPA_WPA 0x00000001 +#define IW_ENC_CAPA_WPA2 0x00000002 +#define IW_ENC_CAPA_CIPHER_TKIP 0x00000004 +#define IW_ENC_CAPA_CIPHER_CCMP 0x00000008 + +/* Event capability macros - in (struct iw_range *)->event_capa + * Because we have more than 32 possible events, we use an array of + * 32 bit bitmasks. Note : 32 bits = 0x20 = 2^5. */ +#define IW_EVENT_CAPA_BASE(cmd) ((cmd >= SIOCIWFIRSTPRIV) ? \ + (cmd - SIOCIWFIRSTPRIV + 0x60) : \ + (cmd - SIOCSIWCOMMIT)) +#define IW_EVENT_CAPA_INDEX(cmd) (IW_EVENT_CAPA_BASE(cmd) >> 5) +#define IW_EVENT_CAPA_MASK(cmd) (1 << (IW_EVENT_CAPA_BASE(cmd) & 0x1F)) +/* Event capability constants - event autogenerated by the kernel + * This list is valid for most 802.11 devices, customise as needed... */ +#define IW_EVENT_CAPA_K_0 (IW_EVENT_CAPA_MASK(0x8B04) | \ + IW_EVENT_CAPA_MASK(0x8B06) | \ + IW_EVENT_CAPA_MASK(0x8B1A)) +#define IW_EVENT_CAPA_K_1 (IW_EVENT_CAPA_MASK(0x8B2A)) +/* "Easy" macro to set events in iw_range (less efficient) */ +#define IW_EVENT_CAPA_SET(event_capa, cmd) (event_capa[IW_EVENT_CAPA_INDEX(cmd)] |= IW_EVENT_CAPA_MASK(cmd)) +#define IW_EVENT_CAPA_SET_KERNEL(event_capa) {event_capa[0] |= IW_EVENT_CAPA_K_0; event_capa[1] |= IW_EVENT_CAPA_K_1; } + +/* Modulations bitmasks */ +#define IW_MODUL_ALL 0x00000000 /* Everything supported */ +#define IW_MODUL_FH 0x00000001 /* Frequency Hopping */ +#define IW_MODUL_DS 0x00000002 /* Original Direct Sequence */ +#define IW_MODUL_CCK 0x00000004 /* 802.11b : 5.5 + 11 Mb/s */ +#define IW_MODUL_11B (IW_MODUL_DS | IW_MODUL_CCK) +#define IW_MODUL_PBCC 0x00000008 /* TI : 5.5 + 11 + 22 Mb/s */ +#define IW_MODUL_OFDM_A 0x00000010 /* 802.11a : 54 Mb/s */ +#define IW_MODUL_11A (IW_MODUL_OFDM_A) +#define IW_MODUL_11AB (IW_MODUL_11B | IW_MODUL_11A) +#define IW_MODUL_OFDM_G 0x00000020 /* 802.11g : 54 Mb/s */ +#define IW_MODUL_11G (IW_MODUL_11B | IW_MODUL_OFDM_G) +#define IW_MODUL_11AG (IW_MODUL_11G | IW_MODUL_11A) +#define IW_MODUL_TURBO 0x00000040 /* ATH : bonding, 108 Mb/s */ +/* In here we should define MIMO stuff. Later... */ +#define IW_MODUL_CUSTOM 0x40000000 /* Driver specific */ + +/* Bitrate flags available */ +#define IW_BITRATE_TYPE 0x00FF /* Type of value */ +#define IW_BITRATE_UNICAST 0x0001 /* Maximum/Fixed unicast bitrate */ +#define IW_BITRATE_BROADCAST 0x0002 /* Fixed broadcast bitrate */ + +/****************************** TYPES ******************************/ + +/* --------------------------- SUBTYPES --------------------------- */ +/* + * Generic format for most parameters that fit in an int + */ +struct iw_param +{ + int32_t value; /* The value of the parameter itself */ + uint8_t fixed; /* Hardware should not use auto select */ + uint8_t disabled; /* Disable the feature */ + uint16_t flags; /* Various specifc flags (if any) */ +}; + +/* + * For all data larger than 16 octets, we need to use a + * pointer to memory allocated in user space. + */ +struct iw_point +{ + void *pointer; /* Pointer to the data (in user space) */ + uint16_t length; /* number of fields or size in bytes */ + uint16_t flags; /* Optional params */ +}; + +/* + * A frequency + * For numbers lower than 10^9, we encode the number in 'm' and + * set 'e' to 0 + * For number greater than 10^9, we divide it by the lowest power + * of 10 to get 'm' lower than 10^9, with 'm'= f / (10^'e')... + * The power of 10 is in 'e', the result of the division is in 'm'. + */ +struct iw_freq +{ + int32_t m; /* Mantissa */ + int16_t e; /* Exponent */ + uint8_t i; /* List index (when in range struct) */ + uint8_t flags; /* Flags (fixed/auto) */ +}; + +/* + * Quality of the link + */ +struct iw_quality +{ + uint8_t qual; /* link quality (%retries, SNR, + %missed beacons or better...) */ + uint8_t level; /* signal level (dBm) */ + uint8_t noise; /* noise level (dBm) */ + uint8_t updated; /* Flags to know if updated */ +}; + +/* + * Packet discarded in the wireless adapter due to + * "wireless" specific problems... + * Note : the list of counter and statistics in net_device_stats + * is already pretty exhaustive, and you should use that first. + * This is only additional stats... + */ +struct iw_discarded +{ + uint32_t nwid; /* Rx : Wrong nwid/essid */ + uint32_t code; /* Rx : Unable to code/decode (WEP) */ + uint32_t fragment; /* Rx : Can't perform MAC reassembly */ + uint32_t retries; /* Tx : Max MAC retries num reached */ + uint32_t misc; /* Others cases */ +}; + +/* + * Packet/Time period missed in the wireless adapter due to + * "wireless" specific problems... + */ +struct iw_missed +{ + uint32_t beacon; /* Missed beacons/superframe */ +}; + +/* + * Quality range (for spy threshold) + */ +struct iw_thrspy +{ + struct sockaddr addr; /* Source address (hw/mac) */ + struct iw_quality qual; /* Quality of the link */ + struct iw_quality low; /* Low threshold */ + struct iw_quality high; /* High threshold */ +}; + +/* + * Optional data for scan request + * + * Note: these optional parameters are controlling parameters for the + * scanning behavior, these do not apply to getting scan results + * (SIOCGIWSCAN). Drivers are expected to keep a local BSS table and + * provide a merged results with all BSSes even if the previous scan + * request limited scanning to a subset, e.g., by specifying an SSID. + * Especially, scan results are required to include an entry for the + * current BSS if the driver is in Managed mode and associated with an AP. + */ +struct iw_scan_req +{ + uint8_t scan_type; /* IW_SCAN_TYPE_{ACTIVE,PASSIVE} */ + uint8_t essid_len; + uint8_t num_channels; /* num entries in channel_list; + * 0 = scan all allowed channels */ + uint8_t flags; /* reserved as padding; use zero, this may + * be used in the future for adding flags + * to request different scan behavior */ + struct sockaddr bssid; /* ff:ff:ff:ff:ff:ff for broadcast BSSID or + * individual address of a specific BSS */ + + /* + * Use this ESSID if IW_SCAN_THIS_ESSID flag is used instead of using + * the current ESSID. This allows scan requests for specific ESSID + * without having to change the current ESSID and potentially breaking + * the current association. + */ + uint8_t essid[IW_ESSID_MAX_SIZE]; + + /* + * Optional parameters for changing the default scanning behavior. + * These are based on the MLME-SCAN.request from IEEE Std 802.11. + * TU is 1.024 ms. If these are set to 0, driver is expected to use + * reasonable default values. min_channel_time defines the time that + * will be used to wait for the first reply on each channel. If no + * replies are received, next channel will be scanned after this. If + * replies are received, total time waited on the channel is defined by + * max_channel_time. + */ + uint32_t min_channel_time; /* in TU */ + uint32_t max_channel_time; /* in TU */ + + struct iw_freq channel_list[IW_MAX_FREQUENCIES]; +}; + +/* ------------------------- WPA SUPPORT ------------------------- */ + +/* + * Extended data structure for get/set encoding (this is used with + * SIOCSIWENCODEEXT/SIOCGIWENCODEEXT. struct iw_point and IW_ENCODE_* + * flags are used in the same way as with SIOCSIWENCODE/SIOCGIWENCODE and + * only the data contents changes (key data -> this structure, including + * key data). + * + * If the new key is the first group key, it will be set as the default + * TX key. Otherwise, default TX key index is only changed if + * IW_ENCODE_EXT_SET_TX_KEY flag is set. + * + * Key will be changed with SIOCSIWENCODEEXT in all cases except for + * special "change TX key index" operation which is indicated by setting + * key_len = 0 and ext_flags |= IW_ENCODE_EXT_SET_TX_KEY. + * + * tx_seq/rx_seq are only used when respective + * IW_ENCODE_EXT_{TX,RX}_SEQ_VALID flag is set in ext_flags. Normal + * TKIP/CCMP operation is to set RX seq with SIOCSIWENCODEEXT and start + * TX seq from zero whenever key is changed. SIOCGIWENCODEEXT is normally + * used only by an Authenticator (AP or an IBSS station) to get the + * current TX sequence number. Using TX_SEQ_VALID for SIOCSIWENCODEEXT and + * RX_SEQ_VALID for SIOCGIWENCODEEXT are optional, but can be useful for + * debugging/testing. + */ +struct iw_encode_ext +{ + uint32_t ext_flags; /* IW_ENCODE_EXT_* */ + uint8_t tx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */ + uint8_t rx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */ + struct sockaddr addr; /* ff:ff:ff:ff:ff:ff for broadcast/multicast + * (group) keys or unicast address for + * individual keys */ + uint16_t alg; /* IW_ENCODE_ALG_* */ + uint16_t key_len; + uint8_t key[0]; +}; + +/* SIOCSIWMLME data */ +struct iw_mlme +{ + uint16_t cmd; /* IW_MLME_* */ + uint16_t reason_code; + struct sockaddr addr; +}; + +/* SIOCSIWPMKSA data */ +#define IW_PMKSA_ADD 1 +#define IW_PMKSA_REMOVE 2 +#define IW_PMKSA_FLUSH 3 + +#define IW_PMKID_LEN 16 + +struct iw_pmksa +{ + uint32_t cmd; /* IW_PMKSA_* */ + struct sockaddr bssid; + uint8_t pmkid[IW_PMKID_LEN]; +}; + +/* IWEVMICHAELMICFAILURE data */ +struct iw_michaelmicfailure +{ + uint32_t flags; + struct sockaddr src_addr; + uint8_t tsc[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */ +}; + +/* IWEVPMKIDCAND data */ +#define IW_PMKID_CAND_PREAUTH 0x00000001 /* RNS pre-authentication enabled */ +struct iw_pmkid_cand +{ + uint32_t flags; /* IW_PMKID_CAND_* */ + uint32_t index; /* the smaller the index, the higher the + * priority */ + struct sockaddr bssid; +}; + +/* ------------------------ WIRELESS STATS ------------------------ */ +/* + * Wireless statistics (used for /proc/net/wireless) + */ +struct iw_statistics +{ + uint16_t status; /* Status + * - device dependent for now */ + + struct iw_quality qual; /* Quality of the link + * (instant/mean/max) */ + struct iw_discarded discard; /* Packet discarded counts */ + struct iw_missed miss; /* Packet missed counts */ +}; + +/* ------------------------ IOCTL REQUEST ------------------------ */ +/* + * This structure defines the payload of an ioctl, and is used + * below. + * + * Note that this structure should fit on the memory footprint + * of iwreq (which is the same as ifreq), which mean a max size of + * 16 octets = 128 bits. Warning, pointers might be 64 bits wide... + * You should check this when increasing the structures defined + * above in this file... + */ +union iwreq_data +{ + /* Config - generic */ + char name[16]; + /* Name : used to verify the presence of wireless extensions. + * Name of the protocol/provider... */ + + struct iw_point essid; /* Extended network name */ + struct iw_param nwid; /* network id (or domain - the cell) */ + struct iw_freq freq; /* frequency or channel : + * 0-1000 = channel + * > 1000 = frequency in Hz */ + + struct iw_param sens; /* signal level threshold */ + struct iw_param bitrate; /* default bit rate */ + struct iw_param txpower; /* default transmit power */ + struct iw_param rts; /* RTS threshold threshold */ + struct iw_param frag; /* Fragmentation threshold */ + uint32_t mode; /* Operation mode */ + struct iw_param retry; /* Retry limits & lifetime */ + + struct iw_point encoding; /* Encoding stuff : tokens */ + struct iw_param power; /* PM duration/timeout */ + struct iw_quality qual; /* Quality part of statistics */ + + struct sockaddr ap_addr; /* Access point address */ + struct sockaddr addr; /* Destination address (hw/mac) */ + + struct iw_param param; /* Other small parameters */ + struct iw_point data; /* Other large parameters */ +}; + +/* + * The structure to exchange data for ioctl. + * This structure is the same as 'struct ifreq', but (re)defined for + * convenience... + * Do I need to remind you about structure size (32 octets) ? + */ +struct iwreq +{ + union + { + char ifrn_name[16]; /* if name, e.g. "eth0" */ + } ifr_ifrn; + + /* Data part (defined just above) */ + union iwreq_data u; +}; + +/* -------------------------- IOCTL DATA -------------------------- */ +/* + * For those ioctl which want to exchange mode data that what could + * fit in the above structure... + */ + +/* + * Range of parameters + */ + +struct iw_range +{ + /* Informative stuff (to choose between different interface) */ + uint32_t throughput; /* To give an idea... */ + /* In theory this value should be the maximum benchmarked + * TCP/IP throughput, because with most of these devices the + * bit rate is meaningless (overhead an co) to estimate how + * fast the connection will go and pick the fastest one. + * I suggest people to play with Netperf or any benchmark... + */ + + /* NWID (or domain id) */ + uint32_t min_nwid; /* Minimal NWID we are able to set */ + uint32_t max_nwid; /* Maximal NWID we are able to set */ + + /* Old Frequency (backward compat - moved lower ) */ + uint16_t old_num_channels; + uint8_t old_num_frequency; + + /* Wireless event capability bitmasks */ + uint32_t event_capa[6]; + + /* signal level threshold range */ + int32_t sensitivity; + + /* Quality of link & SNR stuff */ + /* Quality range (link, level, noise) + * If the quality is absolute, it will be in the range [0 ; max_qual], + * if the quality is dBm, it will be in the range [max_qual ; 0]. + * Don't forget that we use 8 bit arithmetics... */ + struct iw_quality max_qual; /* Quality of the link */ + /* This should contain the average/typical values of the quality + * indicator. This should be the threshold between a "good" and + * a "bad" link (example : monitor going from green to orange). + * Currently, user space apps like quality monitors don't have any + * way to calibrate the measurement. With this, they can split + * the range between 0 and max_qual in different quality level + * (using a geometric subdivision centered on the average). + * I expect that people doing the user space apps will feedback + * us on which value we need to put in each driver... */ + struct iw_quality avg_qual; /* Quality of the link */ + + /* Rates */ + uint8_t num_bitrates; /* Number of entries in the list */ + int32_t bitrate[IW_MAX_BITRATES]; /* list, in bps */ + + /* RTS threshold */ + int32_t min_rts; /* Minimal RTS threshold */ + int32_t max_rts; /* Maximal RTS threshold */ + + /* Frag threshold */ + int32_t min_frag; /* Minimal frag threshold */ + int32_t max_frag; /* Maximal frag threshold */ + + /* Power Management duration & timeout */ + int32_t min_pmp; /* Minimal PM period */ + int32_t max_pmp; /* Maximal PM period */ + int32_t min_pmt; /* Minimal PM timeout */ + int32_t max_pmt; /* Maximal PM timeout */ + uint16_t pmp_flags; /* How to decode max/min PM period */ + uint16_t pmt_flags; /* How to decode max/min PM timeout */ + uint16_t pm_capa; /* What PM options are supported */ + + /* Encoder stuff */ + uint16_t encoding_size[IW_MAX_ENCODING_SIZES]; /* Different token sizes */ + uint8_t num_encoding_sizes; /* Number of entry in the list */ + uint8_t max_encoding_tokens; /* Max number of tokens */ + /* For drivers that need a "login/passwd" form */ + uint8_t encoding_login_index; /* token index for login token */ + + /* Transmit power */ + uint16_t txpower_capa; /* What options are supported */ + uint8_t num_txpower; /* Number of entries in the list */ + int32_t txpower[IW_MAX_TXPOWER]; /* list, in bps */ + + /* Wireless Extension version info */ + uint8_t we_version_compiled; /* Must be WIRELESS_EXT */ + uint8_t we_version_source; /* Last update of source */ + + /* Retry limits and lifetime */ + uint16_t retry_capa; /* What retry options are supported */ + uint16_t retry_flags; /* How to decode max/min retry limit */ + uint16_t r_time_flags; /* How to decode max/min retry life */ + int32_t min_retry; /* Minimal number of retries */ + int32_t max_retry; /* Maximal number of retries */ + int32_t min_r_time; /* Minimal retry lifetime */ + int32_t max_r_time; /* Maximal retry lifetime */ + + /* Frequency */ + uint16_t num_channels; /* Number of channels [0; num - 1] */ + uint8_t num_frequency; /* Number of entry in the list */ + struct iw_freq freq[IW_MAX_FREQUENCIES]; /* list */ + /* Note : this frequency list doesn't need to fit channel numbers, + * because each entry contain its channel index */ + + uint32_t enc_capa; /* IW_ENC_CAPA_* bit field */ + + /* More power management stuff */ + int32_t min_pms; /* Minimal PM saving */ + int32_t max_pms; /* Maximal PM saving */ + uint16_t pms_flags; /* How to decode max/min PM saving */ + + /* All available modulations for driver (hw may support less) */ + int32_t modul_capa; /* IW_MODUL_* bit field */ + + /* More bitrate stuff */ + uint32_t bitrate_capa; /* Types of bitrates supported */ +}; + +/* + * Private ioctl interface information + */ + +struct iw_priv_args +{ + uint32_t cmd; /* Number of the ioctl to issue */ + uint16_t set_args; /* Type and number of args */ + uint16_t get_args; /* Type and number of args */ + char name[16]; /* Name of the extension */ +}; + +/* ----------------------- WIRELESS EVENTS ----------------------- */ +/* + * Wireless events are carried through the rtnetlink socket to user + * space. They are encapsulated in the IFLA_WIRELESS field of + * a RTM_NEWLINK message. + */ + +/* + * A Wireless Event. Contains basically the same data as the ioctl... + */ +struct iw_event +{ + uint16_t len; /* Real lenght of this stuff */ + uint16_t cmd; /* Wireless IOCTL */ + union iwreq_data u; /* IOCTL fixed payload */ +}; + +/* Size of the Event prefix (including padding and alignement junk) */ +#define IW_EV_LCP_LEN (sizeof(struct iw_event) - sizeof(union iwreq_data)) +/* Size of the various events */ +#define IW_EV_CHAR_LEN (IW_EV_LCP_LEN + IFNAMSIZ) +#define IW_EV_UINT_LEN (IW_EV_LCP_LEN + sizeof(uint32_t)) +#define IW_EV_FREQ_LEN (IW_EV_LCP_LEN + sizeof(struct iw_freq)) +#define IW_EV_PARAM_LEN (IW_EV_LCP_LEN + sizeof(struct iw_param)) +#define IW_EV_ADDR_LEN (IW_EV_LCP_LEN + sizeof(struct sockaddr)) +#define IW_EV_QUAL_LEN (IW_EV_LCP_LEN + sizeof(struct iw_quality)) + +/* iw_point events are special. First, the payload (extra data) come at + * the end of the event, so they are bigger than IW_EV_POINT_LEN. Second, + * we omit the pointer, so start at an offset. */ +#define IW_EV_POINT_OFF (((char *) &(((struct iw_point *) NULL)->length)) - \ + (char *) NULL) +#define IW_EV_POINT_LEN (IW_EV_LCP_LEN + sizeof(struct iw_point) - \ + IW_EV_POINT_OFF) + +/* Size of the Event prefix when packed in stream */ +#define IW_EV_LCP_PK_LEN (4) +/* Size of the various events when packed in stream */ +#define IW_EV_CHAR_PK_LEN (IW_EV_LCP_PK_LEN + IFNAMSIZ) +#define IW_EV_UINT_PK_LEN (IW_EV_LCP_PK_LEN + sizeof(uint32_t)) +#define IW_EV_FREQ_PK_LEN (IW_EV_LCP_PK_LEN + sizeof(struct iw_freq)) +#define IW_EV_PARAM_PK_LEN (IW_EV_LCP_PK_LEN + sizeof(struct iw_param)) +#define IW_EV_ADDR_PK_LEN (IW_EV_LCP_PK_LEN + sizeof(struct sockaddr)) +#define IW_EV_QUAL_PK_LEN (IW_EV_LCP_PK_LEN + sizeof(struct iw_quality)) +#define IW_EV_POINT_PK_LEN (IW_EV_LCP_LEN + 4) + +#endif /* _LINUX_WIRELESS_H */ diff --git a/webgui/luci/luci/Makefile b/webgui/luci/luci/Makefile new file mode 100644 index 000000000..12f8a5724 --- /dev/null +++ b/webgui/luci/luci/Makefile @@ -0,0 +1,655 @@ +include $(TOPDIR)/rules.mk + +PKG_BRANCH:=svn-0.11 +PKG_NAME:=luci +PKG_VERSION:=inteno-1.1.3 +PKG_SOURCE_VERSION:=f88c386161ef4ca2b22225cbb759e50b3e98ae32 + +PKG_SOURCE_PROTO:=git +ifeq ($(CONFIG_PACKAGE_bcmkernel),y) +PKG_SOURCE_URL:=git@iopsys.inteno.se:luci-inteno-private.git +else +PKG_SOURCE_URL:=http://ihgsp.inteno.se/git/luci-inteno.git +endif + +PKG_RELEASE:=$(PKG_SOURCE_VERSION) +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_RELEASE).tar.gz +PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) + +PKG_BUILD_DEPENDS:=$(if $(STAGING_DIR_ROOT),lua/host) +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) +PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install + +LUA_TARGET:=source +LUCI_CFLAGS:= +LUCI_BUILD_PACKAGES:= +LUCI_SELECTED_MODULES:= + +ifeq ($(BOARD),brcm-2.4) + MAKE_FLAGS += CRAP="1" +endif + + +### Templates ### +define Package/luci/install/template + $(CP) -a $(PKG_BUILD_DIR)/$(2)/dist/* $(1)/ -R + $(CP) -a $(PKG_BUILD_DIR)/$(2)/ipkg/* $(1)/CONTROL/ 2>/dev/null || true +endef + + +### Core package ### +define Package/luci-lib-core + SECTION:=luci + CATEGORY:=LuCI + TITLE:=LuCI - Lua Configuration Interface + URL:=http://luci.subsignal.org/ + MAINTAINER:=LuCI Development Team + SUBMENU:=8. Libraries + DEPENDS:=+lua +libuci-lua +libubus-lua + TITLE:=LuCI core libraries +endef + +define Package/luci-lib-core/install + $(call Package/luci/install/template,$(1),libs/core) + $(PKG_BUILD_DIR)/build/mkversion.sh $(1)/usr/lib/lua/luci/version.lua \ + "OpenWrt Firmware" \ + "$(OPENWRTVERSION)" \ + "$(PKG_BRANCH)" \ + "$(PKG_VERSION)" +endef + +define Package/luci-lib-core/config + choice + prompt "Build Target" + default PACKAGE_luci-lib-core_source + + config PACKAGE_luci-lib-core_compile + bool "Precompiled" + + config PACKAGE_luci-lib-core_stripped + bool "Stripped" + + config PACKAGE_luci-lib-core_srcdiet + bool "Compressed Source" + + config PACKAGE_luci-lib-core_source + bool "Full Source" + + endchoice +endef + +ifneq ($(CONFIG_PACKAGE_luci-lib-core_compile),) + LUA_TARGET:=compile +endif + +ifneq ($(CONFIG_PACKAGE_luci-lib-core_stripped),) + LUA_TARGET:=strip +endif + +ifneq ($(CONFIG_PACKAGE_luci-lib-core_srcdiet),) + LUA_TARGET:=diet +endif + +ifneq ($(CONFIG_PACKAGE_luci-lib-core),) + LUCI_SELECTED_MODULES+=libs/core +endif + +LUCI_BUILD_PACKAGES += luci-lib-core + + +### Libraries ### +define library + define Package/luci-lib-$(1) + SECTION:=luci + CATEGORY:=LuCI + TITLE:=LuCI - Lua Configuration Interface + URL:=http://luci.subsignal.org/ + MAINTAINER:=LuCI Development Team + SUBMENU:=8. Libraries + TITLE:=$(if $(2),$(2),LuCI $(1) library) + $(if $(3),DEPENDS:=+luci-lib-core $(3)) + endef + + define Package/luci-lib-$(1)/install + $(call Package/luci/install/template,$$(1),libs/$(1)) + $(call Package/luci-lib-$(1)/extra-install) + endef + + ifneq ($(CONFIG_PACKAGE_luci-lib-$(1)),) + LUCI_SELECTED_MODULES+=libs/$(1) + endif + + LUCI_BUILD_PACKAGES += luci-lib-$(1) +endef + +define Package/luci-lib-web/conffiles +/etc/config/luci +endef + +define Package/luci-lib-nixio/config + choice + prompt "TLS Provider" + default PACKAGE_luci-lib-nixio_notls + + config PACKAGE_luci-lib-nixio_notls + bool "Disabled" + + config PACKAGE_luci-lib-nixio_axtls + bool "Builtin (axTLS)" + + config PACKAGE_luci-lib-nixio_cyassl + bool "CyaSSL" + select PACKAGE_libcyassl + + config PACKAGE_luci-lib-nixio_openssl + bool "OpenSSL" + select PACKAGE_libopenssl + endchoice +endef + + +NIXIO_TLS:= + +ifneq ($(CONFIG_PACKAGE_luci-lib-nixio_axtls),) + NIXIO_TLS:=axtls +endif + +ifneq ($(CONFIG_PACKAGE_luci-lib-nixio_openssl),) + NIXIO_TLS:=openssl +endif + +ifneq ($(CONFIG_PACKAGE_luci-lib-nixio_cyassl),) + NIXIO_TLS:=cyassl + LUCI_CFLAGS+=-I$(STAGING_DIR)/usr/include/cyassl +endif + + +$(eval $(call library,fastindex,Fastindex indexing module,+PACKAGE_luci-lib-fastindex:liblua)) +$(eval $(call library,httpclient,HTTP(S) client library,+luci-lib-web +luci-lib-nixio)) +$(eval $(call library,ipkg,LuCI IPKG/OPKG call abstraction library)) +$(eval $(call library,json,LuCI JSON library)) +$(eval $(call library,lucid,LuCId Full-Stack Webserver,+luci-lib-nixio +luci-lib-web +luci-lib-px5g)) +$(eval $(call library,lucid-http,LuCId HTTP Backend,+luci-lib-lucid)) +$(eval $(call library,lucid-rpc,LuCId RPC Backend,+luci-lib-lucid)) +$(eval $(call library,nixio,NIXIO POSIX library,+PACKAGE_luci-lib-nixio_openssl:libopenssl +PACKAGE_luci-lib-nixio_cyassl:libcyassl)) +$(eval $(call library,px5g,RSA/X.509 Key Generator (required for LuCId SSL support),+luci-lib-nixio)) +$(eval $(call library,sys,LuCI Linux/POSIX system library)) +$(eval $(call library,web,MVC Webframework,+luci-lib-sys +luci-lib-nixio +luci-lib-core +luci-sgi-cgi)) + + +### Protocols ### +define protocol + define Package/luci-proto-$(1) + SECTION:=luci + CATEGORY:=LuCI + TITLE:=LuCI - Lua Configuration Interface + URL:=http://luci.subsignal.org/ + MAINTAINER:=LuCI Development Team + SUBMENU:=6. Protocols + TITLE:=$(if $(2),$(2),LuCI $(1) protocol support) + DEPENDS:=$(3) + endef + + define Package/luci-proto-$(1)/install + $(call Package/luci/install/template,$$(1),protocols/$(1)) + endef + + ifneq ($(CONFIG_PACKAGE_luci-proto-$(1)),) + LUCI_SELECTED_MODULES+=protocols/$(1) + endif + + LUCI_BUILD_PACKAGES += luci-proto-$(1) +endef + +$(eval $(call protocol,core,Support for static/dhcp/none)) +$(eval $(call protocol,ppp,Support for PPP/PPPoE/PPPoA/PPtP)) +$(eval $(call protocol,ipv6,Support for DHCPv6/6in4/6to4/6rd,+PACKAGE_luci-proto-ipv6:6in4 +PACKAGE_luci-proto-ipv6:6to4 +PACKAGE_luci-proto-ipv6:6rd +PACKAGE_luci-proto-ipv6:ipv6-support)) +$(eval $(call protocol,3g,Support for 3G,+PACKAGE_luci-proto-3g:comgt)) +$(eval $(call protocol,4g,Support for 4G,+PACKAGE_luci-proto-4g:libmbim +libqmi)) +$(eval $(call protocol,relay,Support for relayd pseudo bridges,+PACKAGE_luci-proto-relay:relayd)) + + +### Community Packages ### +define Package/luci-mod-freifunk-community + SECTION:=luci + CATEGORY:=LuCI + TITLE:=LuCI - Lua Configuration Interface + URL:=http://luci.subsignal.org/ + MAINTAINER:=LuCI Development Team + SUBMENU:=9. Freifunk + TITLE:=Freifunk Community Meta-Package + DEPENDS+= \ + +luci-lib-web +luci-app-splash +luci-i18n-german \ + +PACKAGE_luci-mod-freifunk-community:olsrd +PACKAGE_luci-mod-freifunk-community:olsrd-mod-dyn-gw-plain \ + +PACKAGE_luci-mod-freifunk-community:olsrd-mod-txtinfo +PACKAGE_luci-mod-freifunk-community:olsrd-mod-nameservice \ + +PACKAGE_luci-mod-freifunk-community:olsrd-mod-watchdog +PACKAGE_luci-mod-freifunk-community:kmod-tun \ + +PACKAGE_luci-mod-freifunk-community:ip +PACKAGE_luci-mod-freifunk-community:freifunk-watchdog +luci-app-olsr \ + +luci-app-olsr-services +freifunk-gwcheck +freifunk-mapupdate +endef + +define Package/luci-mod-freifunk-community/install + $(call Package/luci/install/template,$(1),applications/freifunk-community) +endef + +ifneq ($(CONFIG_PACKAGE_luci-mod-freifunk-community),) + LUCI_SELECTED_MODULES+=applications/freifunk-community +endif + +LUCI_BUILD_PACKAGES += luci-mod-freifunk-community + + +### Modules ### +define module + define Package/luci-mod-$(1) + SECTION:=luci + CATEGORY:=LuCI + TITLE:=LuCI - Lua Configuration Interface + URL:=http://luci.subsignal.org/ + MAINTAINER:=LuCI Development Team + SUBMENU:=2. Modules + TITLE:=$(if $(2),$(2),LuCI $(1) module) + $(if $(3),DEPENDS+=$(3)) + endef + + define Package/luci-mod-$(1)/install + $(call Package/luci/install/template,$$(1),modules/$(1)) + $(call Package/luci-mod-$(1)/extra-install) + endef + + ifneq ($(CONFIG_PACKAGE_luci-mod-$(1)),) + LUCI_SELECTED_MODULES+=modules/$(1) + endif + + LUCI_BUILD_PACKAGES += luci-mod-$(1) +endef + + +define Package/luci-mod-admin-core/extra-install + touch $(1)/etc/init.d/luci_fixtime || true +endef + +$(eval $(call module,admin-core,Web UI Core module,+luci-lib-web +luci-proto-core +luci-i18n-english)) +$(eval $(call module,admin-mini,LuCI Essentials - stripped down and user-friendly,+luci-mod-admin-core @BROKEN)) +$(eval $(call module,admin-full,LuCI Administration - full-featured for full control,+luci-mod-admin-core +luci-lib-ipkg)) +$(eval $(call module,failsafe,LuCI Fail-Safe - Fail-Safe sysupgrade module,+luci-mod-admin-core)) +$(eval $(call module,rpc,LuCI RPC - JSON-RPC API,+luci-lib-json)) +$(eval $(call module,freifunk,LuCI Freifunk module,+luci-mod-admin-full +luci-lib-json +PACKAGE_luci-mod-freifunk:freifunk-firewall +freifunk-common +community-profiles)) +$(eval $(call module,niu,NIU - Next Generation Interface,+luci-mod-admin-core @BROKEN)) + + +### Applications ### +define application + define Package/luci-app-$(1) + SECTION:=luci + CATEGORY:=LuCI + TITLE:=LuCI - Lua Configuration Interface + URL:=http://luci.subsignal.org/ + MAINTAINER:=LuCI Development Team + SUBMENU:=3. Applications + TITLE:=$(if $(2),$(2),LuCI $(1) application) + DEPENDS:=$(3) + endef + + define Package/luci-app-$(1)/install + $(call Package/luci/install/template,$$(1),applications/luci-$(1)) + endef + + ifneq ($(CONFIG_PACKAGE_luci-app-$(1)),) + LUCI_SELECTED_MODULES+=applications/luci-$(1) + endif + + LUCI_BUILD_PACKAGES += luci-app-$(1) +endef + +define Package/luci-app-splash/conffiles +/etc/config/luci_splash +/usr/lib/luci-splash/splashtext.html +endef + +define Package/luci-app-statistics/conffiles +/etc/config/luci_statistics +endef + +define Package/luci-app-diag-devinfo/conffiles +/etc/config/luci_devinfo +endef + + +$(eval $(call application,siitwizard,SIIT IPv4-over-IPv6 configuration wizard,\ + +PACKAGE_luci-app-siitwizard:kmod-siit)) + +$(eval $(call application,firewall,Firewall and Portforwarding application,\ + +PACKAGE_luci-app-firewall:firewall)) + +$(eval $(call application,freifunk-policyrouting,Policy routing for mesh traffic,\ + +PACKAGE_luci-app-freifunk-policyrouting:freifunk-policyrouting)) + +$(eval $(call application,freifunk-widgets,Widgets for the Freifunk index page,\ + +PACKAGE_luci-app-freifunk-widgets:luci-mod-freifunk)) + +$(eval $(call application,meshwizard, Shellscript based wizard to setup mesh networks,\ + +PACKAGE_luci-app-freifunk-meshwizard:meshwizard)) + +$(eval $(call application,olsr,OLSR configuration and status module,\ + +olsrd-mod-txtinfo)) + +$(eval $(call application,olsr-viz,OLSR Visualisation,\ + luci-app-olsr +olsrd-mod-txtinfo)) + +$(eval $(call application,freifunk-diagnostics,Tools for network diagnosis like traceroute and ping)) + +$(eval $(call application,olsr-services,Show services announced with the nameservice plugin,\ + luci-app-olsr +olsrd-mod-nameservice)) + +$(eval $(call application,qos,Quality of Service configuration module,\ + +PACKAGE_luci-app-qos:qos-scripts)) + +$(eval $(call application,splash,Freifunk DHCP-Splash application,\ + +luci-lib-nixio +tc +kmod-sched +iptables-mod-nat-extra +iptables-mod-ipopt)) + +$(eval $(call application,statistics,LuCI Statistics Application,\ + +PACKAGE_luci-app-statistics:collectd \ + +PACKAGE_luci-app-statistics:rrdtool1 \ + +PACKAGE_luci-app-statistics:collectd-mod-rrdtool \ + +PACKAGE_luci-app-statistics:collectd-mod-iwinfo \ + +PACKAGE_luci-app-statistics:collectd-mod-interface \ + +PACKAGE_luci-app-statistics:collectd-mod-load)) \ + +PACKAGE_luci-app-statistics:collectd-mod-network)) + + +$(eval $(call application,diag-core,LuCI Diagnostics Tools (Core))) + +$(eval $(call application,diag-devinfo,LuCI Diagnostics Tools (Device Info),\ + +luci-app-diag-core \ + +PACKAGE_luci-app-diag-devinfo:smap \ + +PACKAGE_luci-app-diag-devinfo:netdiscover \ + +PACKAGE_luci-app-diag-devinfo:mac-to-devinfo \ + +PACKAGE_luci-app-diag-devinfo:httping \ + +PACKAGE_luci-app-diag-devinfo:smap-to-devinfo \ + +PACKAGE_luci-app-diag-devinfo:netdiscover-to-devinfo)) + +$(eval $(call application,commands,LuCI Shell Command Module)) + +$(eval $(call application,upnp,Universal Plug & Play configuration module,\ + +PACKAGE_luci-app-upnp:miniupnpd)) + +$(eval $(call application,ntpc,NTP time synchronisation configuration module,\ + +PACKAGE_luci-app-ntpc:ntpclient)) + +$(eval $(call application,ddns,Dynamic DNS configuration module,\ + +PACKAGE_luci-app-ddns:ddns-scripts)) + +$(eval $(call application,samba,Network Shares - Samba SMB/CIFS module,\ + +PACKAGE_luci-app-samba:samba3)) + +$(eval $(call application,mmc-over-gpio,MMC-over-GPIO configuration module,\ + +PACKAGE_luci-app-mmc-over-gpio:kmod-mmc-over-gpio)) + +$(eval $(call application,p910nd,p910nd - Printer server module,\ + +PACKAGE_luci-app-p910nd:p910nd)) + +$(eval $(call application,ushare,uShare - UPnP A/V & DLNA Media Server,\ + +PACKAGE_luci-app-ushare:ushare)) + +$(eval $(call application,hd-idle,Hard Disk Idle Spin-Down module,\ + +PACKAGE_luci-app-hd-idle:hd-idle)) + +$(eval $(call application,tinyproxy,Tinyproxy - HTTP(S)-Proxy configuration,\ + +PACKAGE_luci-app-tinyproxy:tinyproxy)) + +$(eval $(call application,polipo,LuCI Support for the Polipo Proxy,\ + +PACKAGE_luci-app-polipo:polipo)) + +$(eval $(call application,openvpn,LuCI Support for OpenVPN,\ + +PACKAGE_luci-app-openvpn:openvpn)) + +$(eval $(call application,p2pblock,LuCI Support for the Freifunk P2P-Block addon,\ + luci-app-firewall +PACKAGE_luci-app-p2pblock:freifunk-p2pblock)) + +$(eval $(call application,multiwan,LuCI Support for the OpenWrt MultiWAN agent,\ + luci-app-firewall +PACKAGE_luci-app-multiwan:multiwan)) + +$(eval $(call application,wol,LuCI Support for Wake-on-LAN,\ + +PACKAGE_luci-app-wol:etherwake)) + +$(eval $(call application,vnstat,LuCI Support for VnStat,\ + +PACKAGE_luci-app-vnstat:vnstat \ + +PACKAGE_luci-app-vnstat:vnstati)) + +$(eval $(call application,radvd,LuCI Support for Radvd,\ + +PACKAGE_luci-app-radvd:radvd)) + +$(eval $(call application,ahcp,LuCI Support for AHCPd,\ + +PACKAGE_luci-app-ahcp:ahcpd)) + +$(eval $(call application,wshaper,LuCI Support for wshaper,\ + +PACKAGE_luci-app-wshaper:wshaper)) + +$(eval $(call application,voice,LuCI Voice application,\ + +PACKAGE_luci-app-voice:voice-client)) + +$(eval $(call application,ltqtapi,Lantiq voip)) + +$(eval $(call application,minidlna,LuCI Support for miniDLNA,\ + +PACKAGE_luci-app-minidlna:minidlna)) + +$(eval $(call application,transmission,LuCI Support for Transmission,\ + +PACKAGE_luci-app-transmission:transmission-daemon)) + +$(eval $(call application,watchcat,LuCI Support for Watchcat,\ + +PACKAGE_luci-app-watchcat:watchcat)) + +$(eval $(call application,dslstats,LuCI Support for DSL Statistics,\ + +PACKAGE_luci-app-dslstats)) + +$(eval $(call application,mcpd,LuCI Support for IGMP Proxy,\ + +PACKAGE_luci-app-mcpd:mcpd)) + +$(eval $(call application,sfp,LuCI Support for SFP status,\ + +PACKAGE_luci-app-sfp:sfp)) + +$(eval $(call application,catv,LuCI Support for CATV Module,\ + +PACKAGE_luci-app-catv:catv)) + +$(eval $(call application,mount,LuCI Support for Mount Management,\ + +PACKAGE_luci-app-mount)) + +$(eval $(call application,software,LuCI Support for Package Management,\ + +PACKAGE_luci-app-software)) + +$(eval $(call application,speedtest,LuCI Speed Test application,\ + +PACKAGE_luci-app-speedtest:tptest)) + +$(eval $(call application,iup,LuCI Support for Provisioning,\ + +PACKAGE_luci-app-iup:iup)) + +$(eval $(call application,dect,LuCI Support for DECT,\ + +PACKAGE_luci-app-dect:dectmngr)) + +$(eval $(call application,snmp,LuCI Support for SNMP,\ + +PACKAGE_luci-app-snmp:snmpd)) + +$(eval $(call application,port-management,LuCI Support for Port Management,\ + +PACKAGE_luci-app-port-management)) + +$(eval $(call application,power-mgmt,LuCI Support for Power Management,\ + +PACKAGE_luci-app-power-mgmt)) + +$(eval $(call application,parental-control,LuCI Support for Parental Control,\ + +PACKAGE_luci-app-parental-control)) + +### Server Gateway Interfaces ### +define sgi + define Package/luci-sgi-$(1) + SECTION:=luci + CATEGORY:=LuCI + TITLE:=LuCI - Lua Configuration Interface + URL:=http://luci.subsignal.org/ + MAINTAINER:=LuCI Development Team + SUBMENU:=7. Server Interfaces + TITLE:=$(if $(2),$(2),LuCI $(1) server gateway interface) + DEPENDS:=$(3) + endef + + define Package/luci-sgi-$(1)/install + $(call Package/luci/install/template,$$(1),libs/sgi-$(1)) + endef + + ifneq ($(CONFIG_PACKAGE_luci-sgi-$(1)),) + LUCI_SELECTED_MODULES+=libs/sgi-$(1) + endif + + LUCI_BUILD_PACKAGES += luci-sgi-$(1) +endef + +$(eval $(call sgi,cgi,CGI Gateway behind existing Webserver)) +#$(eval $(call sgi,uhttpd,Binding for the uHTTPd server,+uhttpd +uhttpd-mod-lua)) + + +### Themes ### +define theme + define Package/luci-theme-$(1) + SECTION:=luci + CATEGORY:=LuCI + TITLE:=LuCI - Lua Configuration Interface + URL:=http://luci.subsignal.org/ + SUBMENU:=4. Themes + TITLE:=$(if $(2),$(2),LuCI $(1) theme) + MAINTAINER:=$(if $(3),$(3),LuCI Development Team ) + DEPENDS:=$(if $(filter-out base,$(1)),+luci-theme-base) $(4) + $(if $(5),DEFAULT:=PACKAGE_luci-lib-core) + endef + + define Package/luci-theme-$(1)/install + $(call Package/luci/install/template,$$(1),themes/$(1)) + endef + + ifneq ($(CONFIG_PACKAGE_luci-theme-$(1)),) + LUCI_SELECTED_MODULES+=themes/$(1) + endif + + LUCI_BUILD_PACKAGES += luci-theme-$(1) +endef + +$(eval $(call theme,base,Common base for all themes)) +$(eval $(call theme,openwrt,OpenWrt.org)) +$(eval $(call theme,bootstrap,Bootstrap Theme (default),,,1)) + +$(eval $(call theme,freifunk-bno,Freifunk Berlin Nordost Theme,\ + Stefan Pirwitz )) + +$(eval $(call theme,freifunk-generic,Freifunk Generic Theme,\ + Manuel Munz )) + +### Translations ### +define translation + define Package/luci-i18n-$(1) + SECTION:=luci + CATEGORY:=LuCI + TITLE:=LuCI - Lua Configuration Interface + URL:=http://luci.subsignal.org/ + MAINTAINER:=LuCI Development Team + SUBMENU:=5. Translations + TITLE:=$(if $(2),$(2),$(1)) + endef + + define Package/luci-i18n-$(1)/install + $(call Package/luci/install/template,$$(1),i18n/$(1)) + endef + + ifneq ($(CONFIG_PACKAGE_luci-i18n-$(1)),) + LUCI_SELECTED_MODULES+=i18n/$(1) + endif + + LUCI_BUILD_PACKAGES += luci-i18n-$(1) +endef + +$(eval $(call translation,german,German)) +$(eval $(call translation,english,English)) +$(eval $(call translation,french,French (by Florian Fainelli))) +$(eval $(call translation,italian,Italian (by Matteo Croce))) +$(eval $(call translation,russian,Russian (by Skryabin Dmitry))) +$(eval $(call translation,portuguese-brazilian,Portuguese (Brazilian) (by Carlos Cesario))) +$(eval $(call translation,chinese,Chinese (by Chinese Translators))) +$(eval $(call translation,japanese,Japanese (by Tsukasa Hamano))) +$(eval $(call translation,greek,Greek (by Vasilis Tsiligiannis))) +$(eval $(call translation,catalan,Catalan (by Eduard Duran))) +$(eval $(call translation,portuguese,Portuguese (by Jose Monteiro))) +$(eval $(call translation,spanish,Spanish (by Guillermo Javier Nardoni))) +$(eval $(call translation,vietnamese,Vietnamese (by Hong Phuc Dang))) +$(eval $(call translation,malay,Malay (by Teow Wai Chet))) +$(eval $(call translation,norwegian,Norwegian (by Lars Hardy))) +$(eval $(call translation,hebrew,Hebrew)) +$(eval $(call translation,romanian,Romanian)) +$(eval $(call translation,ukrainian,Ukrainian)) +$(eval $(call translation,hungarian,Hungarian)) +$(eval $(call translation,polish,Polish)) + + +### Collections ### +define collection + define Package/luci$(if $(1),-$(1)) + SECTION:=luci + CATEGORY:=LuCI + TITLE:=LuCI - Lua Configuration Interface + URL:=http://luci.subsignal.org/ + MAINTAINER:=LuCI Development Team + SUBMENU:=1. Collections + TITLE:=$(if $(2),$(2),LuCI $(if $(1),$(1),general) collection) + $(if $(3),DEPENDS:=$(3)) + endef + + define Package/luci$(if $(1),-$(1))/install + true + endef + + LUCI_BUILD_PACKAGES += luci$(if $(1),-$(1)) +endef + +$(eval $(call collection,,\ + Standard OpenWrt set including full admin with ppp support and the \ + bootstrap theme,\ + +lighttpd +luci-mod-admin-full +luci-theme-bootstrap \ + +luci-app-firewall +luci-proto-core +luci-proto-ppp +libiwinfo-lua)) + +$(eval $(call collection,ssl,\ + Standard OpenWrt set with HTTPS support,\ + +luci +lighttpd +px5g)) + +$(eval $(call collection,light,\ + Minimum package set using only admin mini and the bootstrap theme,\ + +lighttpd +luci-mod-admin-mini +luci-theme-bootstrap @BROKEN)) + +$(eval $(call application,ipsec,LuCI Support for IPsec,\ + +PACKAGE_luci-app-ipsec:openswan)) + + +### Compile ### +PKG_CONFIG_DEPENDS=$(patsubst %,CONFIG_PACKAGE_%,$(LUCI_BUILD_PACKAGES)) + +include $(INCLUDE_DIR)/package.mk + +ifeq ($(USELOCAL),1) + define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) + $(TAR) c -C ../../../ . \ + --exclude=.pc --exclude=.svn --exclude=.git \ + --exclude='boa-0*' --exclude='*.o' --exclude='*.so' \ + --exclude=dist | \ + tar x -C $(PKG_BUILD_DIR)/ + endef +endif + +define Build/Configure +endef + +MAKE_FLAGS += \ + MODULES="$(LUCI_SELECTED_MODULES)" \ + LUA_TARGET="$(LUA_TARGET)" \ + LUA_SHLIBS="-llua -lm -ldl -lcrypt" \ + CFLAGS="$(TARGET_CFLAGS) $(LUCI_CFLAGS) -I$(STAGING_DIR)/usr/include" \ + LDFLAGS="$(TARGET_LDFLAGS) -L$(STAGING_DIR)/usr/lib" \ + NIXIO_TLS="$(NIXIO_TLS)" OS="Linux" + + +$(foreach b,$(LUCI_BUILD_PACKAGES),$(eval $(call BuildPackage,$(b)))) diff --git a/webgui/luci/meshwizard/Makefile b/webgui/luci/meshwizard/Makefile new file mode 100644 index 000000000..ffb1911d5 --- /dev/null +++ b/webgui/luci/meshwizard/Makefile @@ -0,0 +1,39 @@ +# Copyright (C) 2011 Manuel Munz +# This is free software, licensed under the Apache 2.0 license. + +include $(TOPDIR)/rules.mk + +PKG_NAME:=meshwizard +PKG_RELEASE:=0.0.5 + +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) + +include $(INCLUDE_DIR)/package.mk + +define Package/meshwizard + SECTION:=luci + CATEGORY:=LuCI + SUBMENU:=9. Freifunk + TITLE:=Shell script based wizard for Mesh networks + DEPENDS:=+firewall +endef + +define Package/meshwizard/description + A shellscript based wizard to simplify the setup of a typical mesh node (e.g. for Freifunk.net) +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) +endef + +define Build/Configure +endef + +define Build/Compile +endef + +define Package/meshwizard/install + $(CP) ./files/* $(1)/ +endef + +$(eval $(call BuildPackage,meshwizard)) diff --git a/webgui/luci/meshwizard/files/etc/config/meshwizard b/webgui/luci/meshwizard/files/etc/config/meshwizard new file mode 100644 index 000000000..a60b0cc44 --- /dev/null +++ b/webgui/luci/meshwizard/files/etc/config/meshwizard @@ -0,0 +1,7 @@ +config 'netconfig' 'netconfig' + +config 'general' 'general' + option 'sharenet' '0' + option 'local_restrict' '1' + option 'cleanup' '1' + diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/functions.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/functions.sh new file mode 100644 index 000000000..f8271498a --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/functions.sh @@ -0,0 +1,59 @@ +uci_remove_list_element() { + local option="$1" + local value="$2" + local list="$(uci get $option)" + local elem + + uci delete $option + for elem in $list; do + if [ "$elem" != "$value" ]; then + uci add_list $option=$elem + fi + done +} + +# Takes 2 arguments +# $1 = text to be displayed in the output for this section +# $2 = section (optional) +uci_commitverbose() { + echo "+ $1" + uci changes $2 | while read line; do + echo " $line" + done + uci commit $2 +} + +set_defaults() { + for def in $(env |grep "^$1" | sed 's/ /_/g'); do + option="${def/$1/}" + a="$(echo $option |cut -d '=' -f1)" + b="$(echo $option |cut -d '=' -f2)" + b="${b//_/ }" + uci set $2.$a="$b" + done +} + +# 3 arguements: 1=config name 2=oldname 3=newname +section_rename() { + uci -q rename $1.$2=$3 && msg_rename $1.$2 $1.$3 || msg_rename_error $1.2 $1.$3 +} + +msg_missing_value() { + echo -e " \033[1mWarning:\033[0m Configuration option for $2 is missing in $1." +} + +msg_success() { + echo " Finished." +} + +msg_error() { + echo " \033[1mError: \033[0mThere was a problem." +} + +msg_rename() { + echo " Renamed unnamed section $1 to $2." +} + +msg_rename_error() { + echo " \033[1mWarning:\033[0m Could not rename $1 to $2." +} diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/check-range-in-range.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/check-range-in-range.sh new file mode 100755 index 000000000..c889c55ed --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/check-range-in-range.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# Checks whether a netrange is inside another netrange, returns 1 if true +# Takes two arguments: $1: net from which we want to know if it is inside $2 +# nets need to be given in CIDR notation + +dir=$(dirname $0) + +awk -f $dir/common.awk -f - $* <= network2) { + if (network <= broadcast2) { + if (broadcast <= broadcast2) { + print "1" + } + } + } +} +EOF diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/common.awk b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/common.awk new file mode 100644 index 000000000..5b03d06be --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/common.awk @@ -0,0 +1,20 @@ +function bitcount(c) { + c=and(rshift(c, 1),0x55555555)+and(c,0x55555555) + c=and(rshift(c, 2),0x33333333)+and(c,0x33333333) + c=and(rshift(c, 4),0x0f0f0f0f)+and(c,0x0f0f0f0f) + c=and(rshift(c, 8),0x00ff00ff)+and(c,0x00ff00ff) + c=and(rshift(c,16),0x0000ffff)+and(c,0x0000ffff) + return c +} + +function ip2int(ip) { + for (ret=0,n=split(ip,a,"\."),x=1;x<=n;x++) ret=or(lshift(ret,8),a[x]) + return ret +} + +function int2ip(ip,ret,x) { + ret=and(ip,255) + ip=rshift(ip,8) + for(;x<3;ret=and(ip,255)"."ret,ip=rshift(ip,8),x++); + return ret +} diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/gen_bssid.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/gen_bssid.sh new file mode 100755 index 000000000..8c9155e5e --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/gen_bssid.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# create essid from channel, takes two args: +# $1 = channel (integer) +# $2 = community (optional) +channel=$1 +community=$2 + +. /lib/functions.sh + + +# Try to get BSSID from profile first +config_load profile_$community +config_get bssid bssidscheme $channel +if [ -z "$bssid" ]; then + config_get bssid bssidscheme "all" +fi + +if [ -z "$bssid" ]; then + case $channel in + [1-9]) + bssid="$(printf "%X\n" $channel)2:CA:FF:EE:BA:BE" + ;; + 1[0-4]) + bssid="$(printf "%X\n" $channel)2:CA:FF:EE:BA:BE" + ;; + [3-9][0-9]) + bssid="00:$channel:CA:FF:EE:EE" + ;; + 1[0-9][0-9]) + bssid="${channel/1/01:}:CA:FF:EE:EE" + ;; + *) bssid="02:CA:FF:EE:BA:BE" + ;; + esac +fi +echo $bssid diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/gen_dhcp_ip.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/gen_dhcp_ip.sh new file mode 100755 index 000000000..e559166f4 --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/gen_dhcp_ip.sh @@ -0,0 +1,6 @@ +#!/bin/sh +# generates a dhcp-ip and netrange from a given ip/subnet +# takes 2 arguments: +# $1: Ip Address (of the Interface for which we want to generate an ip) + +echo "$1" | awk 'BEGIN { FS = "." } ; { print "6."$3"."$4".1" }' diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/initial_config.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/initial_config.sh new file mode 100755 index 000000000..a465935fc --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/initial_config.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# This is only run once (usually after flashing an image from the imagebuilder) +# It sets up the initial config for this node. + +. /lib/functions.sh +. $dir/functions.sh + +config_load system + +# Rename system config +handle_system() { + if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then + section_rename system $1 system + fi +} +config_foreach handle_system system + +if [ -n "$(uci -q get meshwizard.community)" ]; then + set_defaults "community_" freifunk.community + uci -q delete meshwizard.community +fi +[ -n "$profile_homepage" ] && uci set freifunk.community.homepage="$profile_homepage" +uci_commitverbose "Setup community" freifunk + +if [ -n "$(uci -q get meshwizard.contact)" ]; then + set_defaults "contact_" freifunk.contact + uci -q delete meshwizard.contact && uci_commitverbose "Setup contact" freifunk +fi + +if [ "$has_luci" == TRUE ]; then + set_defaults "luci_main_" luci.main + uci -q delete meshwizard.luci_main && uci_commitverbose "Setup luci" luci +fi diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/ipcalc-cidr.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/ipcalc-cidr.sh new file mode 100755 index 000000000..39d051ec1 --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/ipcalc-cidr.sh @@ -0,0 +1,41 @@ +#!/bin/sh +dir=$(dirname $0) +awk -f $dir/common.awk -f - $* <limit) end=limit + + print "IP="int2ip(ipaddr) + print "NETMASK="int2ip(netmask) + print "BROADCAST="int2ip(broadcast) + print "NETWORK="int2ip(network) + print "PREFIX="32-bitcount(compl(netmask)) + + # range calculations: + # ipcalc + + if (ARGC > 3) { + print "START="int2ip(start) + print "END="int2ip(end) + } +} +EOF diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/read_defaults.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/read_defaults.sh new file mode 100755 index 000000000..69fd48b92 --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/read_defaults.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# This reads the settings we need to have to configure everything +# Argument $1: community + +community="$1" + +# reads variables from uci files, parameter $1 is the section +get_var() { + uci -q show $1 | cut -d "." -f 2-100 |grep "\." | sed -e 's/^\([a-z_]*\)\./\1_/g' -e 's/=\(.*\)$/="\1"/g' +} + +# read default values from /etc/config/freifunk +for v in system wifi_device wifi_iface interface alias dhcp olsr_interface olsr_interfacedefaults zone_freifunk include; do + get_var freifunk.$v +done + +# now read all values from the selected community profile, will override some values from the defaults before +for v in system wifi_device wifi_iface interface alias dhcp olsr_interface olsr_interfacedefaults profile zone_freifunk include; do + get_var profile_$community.$v +done + +# read values from meshwizard +for v in system luci_main contact community wan lan general; do + get_var meshwizard.$v +done diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/rename-wifi.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/rename-wifi.sh new file mode 100755 index 000000000..872b36c46 --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/rename-wifi.sh @@ -0,0 +1,46 @@ +#!/bin/sh +# This script renames IB_wifi_ interface names into real interface names used on this system. +# E.g. wireless.IB_wifi0 would become wireless.wifi0 on madwifi and wireless.radio0 on mac80211 + +. $dir/functions.sh + +posIB=-1 + +IBwifis="$(uci show meshwizard.netconfig | grep -v 'netconfig=netconfig' | sed 's/meshwizard.netconfig\.\(IB_wifi.*\)_.*/\1/' |uniq)" +[ -z "$(echo $IBwifis |grep IB_wifi)" ] && exit + +for w in $IBwifis; do + posIB=$(( $posIB + 1 )) + export IB_wifi$posIB="$w" +done + +pos=0 +syswifis="$(uci show wireless |grep wifi-device | sed 's/wireless\.\(.*\)=.*/\1/' |uniq)" + +for s in $syswifis; do + export syswifi$pos="$s" + pos=$(( $pos + 1 )) +done + +for i in `seq 0 $posIB`; do + IBwifi=$(eval echo \$IB_wifi$i) + syswifi=$(eval echo \$syswifi$i) + + if [ -n "$syswifi" ]; then + case $IBwifi in + IB_wifi* ) + # replace IB_wifi_* with actual wifi interface names, delete old ones first + uci show meshwizard.netconfig | grep $IBwifi | while read line; do + oldline=$(echo $line | cut -d "=" -f 1) + uci set $oldline="" + newline=$(echo $line |sed "s/$IBwifi/$syswifi/g") + uci set $newline + done + ;; + esac + unset IBwifi + unset syswifi + fi +done + +uci_commitverbose "Renaming wifi-devices in /etc/config/meshwizard" meshwizard diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/restore_default_config.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/restore_default_config.sh new file mode 100755 index 000000000..3f6ce3587 --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/restore_default_config.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# This will restore default "factory" settings before running the meshwizard +# and is used when cleanup=1 +# Warning: This will reset network settings for wan and lan to defaults too. + +echo "+ Restore default config as requested with cleanup=1" +cp -f /rom/etc/config/* /etc/config/ +rm /etc/config/wireless +wifi detect > /etc/config/wireless +rm /etc/config/network +/etc/init.d/defconfig start diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_dhcp.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_dhcp.sh new file mode 100755 index 000000000..5c8863e36 --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_dhcp.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# Sets up the dhcp part of dnsmasq + +. /lib/functions.sh +. $dir/functions.sh + +net="$1" + +handle_dnsmasq() { + config_get interface "$1" interface + if [ "$interface" == "${netrenamed}dhcp" ]; then + if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then + section_rename dhcp $1 ${netrenamed}dhcp + fi + fi +} +config_load dhcp +config_foreach handle_dnsmasq dhcp + +[ "$net" == "lan" ] && uci -q delete dhcp.lan + +uci batch << EOF + set dhcp.${netrenamed}dhcp="dhcp" + set dhcp.${netrenamed}dhcp.interface="${netrenamed}dhcp" +EOF + +set_defaults "dhcp_" dhcp.${netrenamed}dhcp + +uci_commitverbose "Setup DHCP for $netrenamed" dhcp + diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_dnsmasq.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_dnsmasq.sh new file mode 100755 index 000000000..3f489545c --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_dnsmasq.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +. /lib/functions.sh +. $dir/functions.sh + +# Set dnsmasq config +handle_dhcp() { + if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then + section_rename dhcp $1 dnsmasq + fi +} + +config_load dhcp +config_foreach handle_dhcp dnsmasq + +uci batch << EOF + set dhcp.dnsmasq.local="/$profile_suffix/" + set dhcp.dnsmasq.domain="$profile_suffix" +EOF + +config_get addnhosts dnsmasq addnhosts +if [ -z "${addnhosts/\var\/etc\/hosts.olsr/}" ]; then + uci add_list dhcp.dnsmasq.addnhosts="/var/etc/hosts.olsr" +fi + +uci_commitverbose "Setup dnsmasq" dhcp diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall.sh new file mode 100755 index 000000000..723a3591d --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall.sh @@ -0,0 +1,100 @@ +#!/bin/sh +# Add "freifunk" firewall zone +# If wan/lan is used for olsr then remove these networks from wan/lan zones +# Also setup rules defined in /etc/config/freifunk and /etc/config/profile_ + +. /lib/functions.sh +. $dir/functions.sh + +wan_is_olsr=$(uci -q get meshwizard.netconfig.wan_config) +lan_is_olsr=$(uci -q get meshwizard.netconfig.lan_config) + +config_load firewall + +# Rename firewall zone for freifunk if unnamed +# If wan is used for olsr then set network for the firewall zone wan to ' ' to remove the wan interface from it, else add local restrict to it +# If lan is used for olsr then set network for the firewall zone lan to ' ' to remove the lan interface from it + +handle_fwzone() { + config_get name "$1" name + config_get network "$1" network + + if [ "$name" == "freifunk" ]; then + # rename section if unnamed + if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then + section_rename firewall $1 zone_freifunk + fi + fi + + if [ "$name" == "wan" ]; then + if [ "$wan_is_olsr" == 1 ]; then + uci set firewall.$1.network=' ' && uci_commitverbose "WAN is used for olsr, removed the wan interface from zone wan" firewall + else + uci set firewall.$1.local_restrict=1 && uci_commitverbose "Enable local_restrict for zone wan" firewall + fi + fi + + if [ "$name" == "lan" ] && [ "$lan_is_olsr" == 1 ]; then + uci set firewall.$1.network=' ' && uci_commitverbose "LAN is used for olsr, removed the lan interface from zone lan" firewall + fi +} + +config_foreach handle_fwzone zone + +uci batch << EOF + set firewall.zone_freifunk="zone" + set firewall.zone_freifunk.name="freifunk" + set firewall.zone_freifunk.input="$zone_freifunk_input" + set firewall.zone_freifunk.forward="$zone_freifunk_forward" + set firewall.zone_freifunk.output="$zone_freifunk_output" +EOF + +uci_commitverbose "Setup firewall zones" firewall + +# Usually we need to setup masquerading for lan, except lan is an olsr interface or has an olsr hna-entry + +handle_interface() { + config_get interface "$1" interface + if [ "$interface" == "lan" ]; then + no_masq_lan=1 + fi +} +config_load olsrd +config_foreach handle_interface Interface + +LANIP="$(uci -q get network.lan.ipaddr)" +if [ -n "$LANIP" ]; then + handle_hna() { + config_get netaddr "$1" netaddr + if [ "$LANIP" == "$netaddr" ]; then + no_masq_lan=1 + fi + } + config_foreach handle_hna Hna4 +fi + +currms=$(uci -q get firewall.zone_freifunk.masq_src) +if [ ! "$no_masq_lan" == "1" ] && [ ! "$(uci -q get meshwizard.netconfig.lan_config)" == 1 ]; then + uci set firewall.zone_freifunk.masq="1" + [ -z "$(echo $currms |grep lan)" ] && uci add_list firewall.zone_freifunk.masq_src="lan" +fi + + +# Rules, Forwardings, advanced config and includes + +for config in freifunk profile_$community; do + + config_load $config + + for section in advanced include fw_rule fw_forwarding; do + handle_firewall() { + local options=$(uci show $config."$1") + options=$(echo "$options" | sed -e "s/fw_//g" -e "s/^$config/firewall/g") + for o in $options; do + uci set $o + done + } + config_foreach handle_firewall $section + done +done +uci_commitverbose "Setup rules, forwardings, advanced config and includes." firewall diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall_interface.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall_interface.sh new file mode 100755 index 000000000..7f40f8714 --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall_interface.sh @@ -0,0 +1,81 @@ +#!/bin/sh +# This will add $net to the zone firewall (and remove it from other zones where it is referenced) +# It will also setup rules defined in /etc/config/freifunk and /etc/config/profile_ +# Arg $1 = $net + +net=$1 +. /lib/functions.sh +. $dir/functions.sh +config_load firewall + +# Get some variables +type="$(uci -q get wireless.$net.type)" +vap="$(uci -q get meshwizard.netconfig.$net\_vap)" +wan_is_olsr=$(uci -q get meshwizard.netconfig.wan_config) + +# Delete old firewall zone for freifunk +handle_fwzone() { + config_get name "$1" name + config_get network "$1" network + + if [ "$2" == "zoneconf" ]; then + if [ "$name" == "freifunk" ]; then + # rename section if unnamed + if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then + section_rename firewall $1 zone_freifunk + fi + else + if [ ! "$name" == "freifunk" ] && [ -n "$netrenamed" -a -n "$(echo $network | grep $netrenamed)" ]; then + echo " Removed $netrenamed from firewall zone $name." + network_new=$(echo $network | sed -e 's/'$netrenamed'//' -e 's/^ //' -e 's/ / /' -e 's/ $//') + uci set firewall.$1.network="$network_new" + fi + fi + fi +} + +config_foreach handle_fwzone zone zoneconf + +# Add $netrenamed and if needed ${netrenamed}dhcp to the "freifunk" zone +config_get network zone_freifunk network + +# remove ${netrenamed}dhcp from networks list +[ -n "$network" -a -n "$net" ] && network="${network/${netrenamed}dhcp/}" +network=$(echo $network) # Removes leading and trailing whitespaces + +[ -n "$netrenamed" ] && [ -z "$(echo $network | grep $netrenamed)" ] && network="$network $netrenamed" + +if [ "$type" == "atheros" -a "$vap" == 1 ]; then + [ -n "$netrenamed" ] && [ "$network" == "${network/${netrenamed}dhcp/}" ] && network="$network ${netrenamed}dhcp" +fi + +uci set firewall.zone_freifunk.network="$network" + +uci_commitverbose "Add '$netrenamed' to freifunk firewall zone" firewall + +currms=$(uci -q get firewall.zone_freifunk.masq_src) + +# If interfaces are outside of the mesh network they should be natted + +# Get dhcprange and meshnet +if_ip="$(uci -q get network.${netrenamed}dhcp.ipaddr)" +if_mask="$(uci -q get network.${netrenamed}dhcp.netmask)" + +[ -n "$if_ip" -a "$if_mask" ] && export $(ipcalc.sh $if_ip $if_mask) +[ -n "$NETWORK" -a "$PREFIX" ] && dhcprange="$NETWORK/$PREFIX" + +if [ -n "$dhcprange" ]; then + meshnet="$(uci get profile_$community.profile.mesh_network)" + # check if the dhcprange is inside meshnet + dhcpinmesh="$($dir/helpers/check-range-in-range.sh $dhcprange $meshnet)" + if [ ! "$dhcpinmesh" == 1 ]; then + uci set firewall.zone_freifunk.masq=1 + [ -z "$(echo $currms |grep ${netrenamed}dhcp)" ] && uci add_list firewall.zone_freifunk.masq_src="${netrenamed}dhcp" + fi +fi + +for i in IP NETMASK BROADCAST NETWORK PREFIX; do + unset $i +done + +uci_commitverbose "Setup masquerading rules for '$netrenamed'" firewall diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_lan_static.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_lan_static.sh new file mode 100755 index 000000000..172dcf138 --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_lan_static.sh @@ -0,0 +1,17 @@ +#!/bin/sh +# Setup static interface settings for lan if lan is not an olsr interface + +[ ! "$(uci -q get network.lan)" == "interface" ] && exit + +. /lib/functions.sh +. $dir/functions.sh + +uci batch << EOF + set network.lan.proto='$lan_proto' + set network.lan.ipaddr='$lan_ip4addr' + set network.lan.netmask='$lan_netmask' +EOF + +uci_commitverbose "Setup static ip settings for lan" network + +uci delete meshwizard.lan && uci commit meshwizard diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_network.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_network.sh new file mode 100755 index 000000000..40b3f2788 --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_network.sh @@ -0,0 +1,77 @@ +# setup entry in /etc/config/network for a interface +# Argument $1: network interface + +net="$1" +. /lib/functions.sh +. $dir/functions.sh + +# Setup a (new) interface section for $net + +ipaddr=$(uci get meshwizard.netconfig.$net\_ip4addr) +[ -z "$ipaddr" ] && msg_missing_value meshwizard $net\_ip4addr + +netmask=$(uci -q get meshwizard.netconfig.$net\_netmask) +[ -z "$netmask" ] && netmask="$interface_netmask" +[ -z "$netmask" ] && netmask="255.255.0.0" + +uci set network.$netrenamed="interface" +set_defaults "interface_" network.$netrenamed + +uci batch << EOF + set network.$netrenamed.proto="static" + set network.$netrenamed.ipaddr="$ipaddr" + set network.$netrenamed.netmask="$netmask" +EOF + +uci_commitverbose "Setup interface $netrenamed" network + +# setup dhcp alias/interface + +net_dhcp=$(uci -q get meshwizard.netconfig.${net}_dhcp) +if [ "$net_dhcp" == 1 ]; then + + # Load meshwizard_settings + dhcprange="$(uci -q get meshwizard.netconfig.${net}_dhcprange)" + interface_ip="$(uci -q get meshwizard.netconfig.${net}_ip4addr)" + vap=$(uci -q get meshwizard.netconfig.${net}_vap) + + # Rename config + handle_dhcpalias() { + config_get interface "$1" interface + if [ "$interface" == "$netrenamed" ]; then + if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then + section_rename network $1 ${netrenamed}dhcp + fi + fi + } + config_load network + config_foreach handle_dhcpalias alias + + # Get IP/netmask and start-ip for $net dhcp + # If no dhcprange is given in /etc/config/meshwizard we autogenerate one + + if [ -z "$dhcprange" ]; then + dhcprange="$($dir/helpers/gen_dhcp_ip.sh $interface_ip)/24" + uci set meshwizard.netconfig.${net}_dhcprange="$dhcprange" + fi + eval $(sh $dir/helpers/ipcalc-cidr.sh $dhcprange 1 0) + + # setup wifi-dhcp interface or alias + + # Setup alias for $net + + if [ "$vap" == 1 ]; then + uci set network.${netrenamed}dhcp=interface + else + uci set network.${netrenamed}dhcp=alias + uci set network.${netrenamed}dhcp.interface="$netrenamed" + fi + + uci batch <<- EOF + set network.${netrenamed}dhcp.proto=static + set network.${netrenamed}dhcp.ipaddr="$START" + set network.${netrenamed}dhcp.netmask="$NETMASK" + EOF + uci_commitverbose "Setup interface for ${netrenamed}dhcp" network + +fi diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd.sh new file mode 100755 index 000000000..d2baf8baa --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd.sh @@ -0,0 +1,60 @@ +#!/bin/sh +# Sets up olsrd + +. /lib/functions.sh +. $dir/functions.sh + +# Rename interface defaults + +handle_interfacedefaults() { + if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then + section_rename olsrd $1 InterfaceDefaults + fi +} +config_load olsrd +config_foreach handle_interfacedefaults InterfaceDefaults + +# Setup new InterfaceDefaults +uci set olsrd.InterfaceDefaults=InterfaceDefaults +set_defaults "olsr_interfacedefaults_" olsrd.InterfaceDefaults +uci_commitverbose "Setup olsr interface defaults" olsrd + +# Rename nameservice, dyngw and httpinfo plugins + +handle_plugin() { + config_get library "$1" library + if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then + new="$(echo $library | cut -d '.' -f 1)" + section_rename olsrd $1 $new + fi +} +config_foreach handle_plugin LoadPlugin + +# Setup nameservice plugin +if [ -n "$profile_suffix" ]; then + suffix=".$profile_suffix" +else + suffix=".olsr" +fi +uci batch << EOF + set olsrd.olsrd_nameservice=LoadPlugin + set olsrd.olsrd_nameservice.library="olsrd_nameservice.so.0.3" + set olsrd.olsrd_nameservice.latlon_file="/var/run/latlon.js" + set olsrd.olsrd_nameservice.hosts_file="/var/etc/hosts.olsr" + set olsrd.olsrd_nameservice.sighup_pid_file="/var/run/dnsmasq.pid" + set olsrd.olsrd_nameservice.suffix="$suffix" +EOF + +uci_commitverbose "Setup olsr nameservice plugin" olsrd + +# Setup dyngw_plain + +# If Sharing of Internet is enabled then enable dyngw_plain plugin + +if [ "$general_sharenet" == 1 ]; then + uci set olsrd.dyngw_plain=LoadPlugin + uci set olsrd.dyngw_plain.ignore=0 + uci set olsrd.dyngw_plain.library="olsrd_dyn_gw_plain.so.0.4" + + uci_commitverbose "Setup olsrd_dyngw_plain plugin" olsrd +fi diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd_interface.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd_interface.sh new file mode 100755 index 000000000..6bb490adf --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd_interface.sh @@ -0,0 +1,46 @@ +#!/bin/sh +# Sets up olsrd interfaces +# arg $1 = net + +net=$1 + +. /lib/functions.sh +. $dir/functions.sh + +# Rename interface for $netrenamed +handle_interface() { + config_get interface "$1" Interface + if [ "$interface" == "$netrenamed" ]; then + if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then + section_rename olsrd $1 $netrenamed + fi + fi +} + +config_foreach handle_interface Interface + +# Setup new interface for $netrenamed + +uci set olsrd.$netrenamed=Interface +set_defaults "olsr_interface_" olsrd.$net +uci set olsrd.$netrenamed.interface="$netrenamed" + +uci_commitverbose "Setup olsr interface for $netrenamed." olsrd + +# If dhcp-network is inside the mesh_network then add HNA for it + +dhcprange=$(uci -q get meshwizard.netconfig.$net\_dhcprange) +uci -q delete olsrd.${netrenamed}clients + +if [ -n "$dhcprange" ]; then + meshnet="$(uci get profile_$community.profile.mesh_network)" + dhcpinmesh="$($dir/helpers/check-range-in-range.sh $dhcprange $meshnet)" + + if [ "$dhcpinmesh" == 1 ] && [ -n "$meshnet" ]; then + uci set olsrd.${netrenamed}clients="Hna4" + eval $(sh $dir/helpers/ipcalc-cidr.sh $dhcprange) + uci set olsrd.${netrenamed}clients.netaddr="$NETWORK" + uci set olsrd.${netrenamed}clients.netmask="$NETMASK" + uci_commitverbose "Setup HNA for network $dhcprange" olsrd + fi +fi diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_policyrouting.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_policyrouting.sh new file mode 100755 index 000000000..f898bd684 --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_policyrouting.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +. $dir/functions.sh + +uci batch << EOF + set freifunk-policyrouting.pr.enable=1 + set freifunk-policyrouting.pr.strict=1 + set freifunk-policyrouting.pr.zones="freifunk" +EOF + +uci_commitverbose "Setup policyrouting" freifunk-policyrouting diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_splash.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_splash.sh new file mode 100755 index 000000000..9db1b5dd4 --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_splash.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# Setup_splash, takes 1 argument: 1=net + +. /lib/functions.sh +. $dir/functions.sh + +net=$1 + +if [ ! "$has_luci_splash" == TRUE ]; then + echo " Luci Splash is not installed, skipping setup of it." + exit +fi + +dhcprange=$(uci -q get meshwizard.netconfig.$net\_dhcprange) + +if [ "$(uci -q get meshwizard.netconfig.$net\_dhcp)" == 1 ] && [ -n "$dhcprange" ]; then + handle_splash() { + config_get network "$1" network + if [ "$network" == "${netrenamed}dhcp" ]; then + if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then + section_rename luci_splash $1 ${netrenamed}dhcp + fi + fi + } + config_load luci_splash + config_foreach handle_splash iface + + uci batch <<- EOF + set luci_splash.${netrenamed}dhcp="iface" + set luci_splash.${netrenamed}dhcp.network="${netrenamed}dhcp" + set luci_splash.${netrenamed}dhcp.zone="freifunk" + EOF + + uci_commitverbose "Setup dhcpsplash for ${netrenamed}dhcp" luci_splash + /etc/init.d/luci_splash enable +fi + diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_system.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_system.sh new file mode 100755 index 000000000..e9ce953f1 --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_system.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +. $dir/functions.sh + +set_defaults "system_" system.system +uci -q delete meshwizard.system && uci commit meshwizard +uci_commitverbose "System config" system diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_wan_static.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_wan_static.sh new file mode 100755 index 000000000..01352d2c1 --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_wan_static.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# Setup static interface settings for wan if wan is not an olsr interface + +[ ! "$(uci -q get network.wan)" == "interface" ] && exit + +. /lib/functions.sh +. $dir/functions.sh + +uci batch << EOF +set network.wan.proto='$wan_proto' +set network.wan.ipaddr='$wan_ip4addr' +set network.wan.netmask='$wan_netmask' +set network.wan.gateway='$wan_gateway' +set network.wan.dns='$wan_dns' +EOF + +uci_commitverbose "Setup static ip settings for wan" network + +uci delete meshwizard.wan && uci commit meshwizard + +# Firewall rules to allow incoming ssh and web + +if [ "$wan_allowssh" == 1 ]; then + uci batch <<- EOF + set firewall.wanssh=rule + set firewall.wanssh.src=wan + set firewall.wanssh.target=ACCEPT + set firewall.wanssh.proto=tcp + set firewall.wanssh.dest_port=22 + EOF + uci_commitverbose "Allow incoming connections to port 22 (ssh) on wan" firewall +fi + +if [ "$wan_allowweb" == 1 ]; then + uci batch <<- EOF + set firewall.wanweb=rule + set firewall.wanweb.src=wan + set firewall.wanweb.target=ACCEPT + set firewall.wanweb.proto=tcp + set firewall.wanweb.dest_port=80 + set firewall.wanwebhttps=rule + set firewall.wanwebhttps.src=wan + set firewall.wanwebhttps.target=ACCEPT + set firewall.wanwebhttps.proto=tcp + set firewall.wanwebhttps.dest_port=443 + EOF + uci_commitverbose "Allow incoming connections to port 80 and 443 (http and https) on wan" firewall +fi diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_wifi.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_wifi.sh new file mode 100755 index 000000000..84c5438eb --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/helpers/setup_wifi.sh @@ -0,0 +1,93 @@ +#!/bin/sh +# sets up a wifi interface for meshing +# Arguments: $1 = network interface + +net="$1" +. /lib/functions.sh +. $dir/functions.sh + +##### wifi-device ##### + +# Get the type before we delete the wifi-device +config_load wireless +config_get type $net type + +# Rename wifi-device for $net + +handle_wifidevice() { + if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then + section_rename wireless $1 $net + fi +} +config_foreach handle_wifidevice wifi-device + +# create new wifi-device for $net +uci set wireless.${net}=wifi-device + +# get and set wifi-device defaults +set_defaults "wifi_device_" wireless.${net} + +channel="$(uci -q get meshwizard.netconfig.$net\_channel)" +vap="$(uci -q get meshwizard.netconfig.$net\_vap)" + +if [ -z "$channel" -o "$channel" == "default" ]; then + channel=$wifi_device_channel +fi + +uci batch << EOF + set wireless.${net}.type="$type" + set wireless.${net}.channel="$channel" +EOF + +uci_commitverbose "Setup wifi device for $netrenamed" wireless + +##### wifi iface + +# Rename wifi-iface for $net +handle_interface() { + config_get device "$1" device + if [ "$device" == "$net" ]; then + if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then + section_rename wireless $1 ${net}_iface + fi + fi +} +config_foreach handle_interface wifi-iface + +# create new wifi-device for $net +uci set wireless.$net\_iface=wifi-iface + +# create new wifi-iface for $net from defaults +set_defaults "wifi_iface_" wireless.$net\_iface + +# overwrite defaults +bssid="$($dir/helpers/gen_bssid.sh $channel $community)" + +ssid="$profile_ssid" +if [ "$profile_ssid_scheme" == "addchannel" ]; then + ssid="$ssid - ch$channel" +fi + +uci batch << EOF + set wireless.$net\_iface.device="${net}" + set wireless.$net\_iface.network="$netrenamed" + set wireless.$net\_iface.ssid="$ssid" + set wireless.$net\_iface.bssid="$bssid" +EOF + +uci_commitverbose "Setup wifi interface for $netrenamed" wireless + +## VAP +ip4addr="$(uci get meshwizard.netconfig.$net\_ip4addr)" +if [ "$type" == "atheros" -a "$vap" == 1 ]; then + uci batch <<- EOF + set wireless.$net\_iface_dhcp="wifi-iface" + set wireless.$net\_iface_dhcp.device="$net" + set wireless.$net\_iface_dhcp.mode="ap" + set wireless.$net\_iface_dhcp.encryption="none" + set wireless.$net\_iface_dhcp.network="${netrenamed}dhcp" + set wireless.$net\_iface_dhcp.ssid="FF-AP-$ip4addr" + EOF + uci_commitverbose "Setup VAP interface for $netrenamed" wireless +fi + diff --git a/webgui/luci/meshwizard/files/usr/bin/meshwizard/wizard.sh b/webgui/luci/meshwizard/files/usr/bin/meshwizard/wizard.sh new file mode 100755 index 000000000..94a34475d --- /dev/null +++ b/webgui/luci/meshwizard/files/usr/bin/meshwizard/wizard.sh @@ -0,0 +1,99 @@ +#!/bin/sh + +# This collection of scripts will take settings from /etc/config/meshwizard, /etc/config/freifunk +# and /etc/config/profile_ and setup the router to participate in wireless mesh networks + +# Copyright 2011 Manuel Munz + +# 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 + +. /lib/functions.sh + +echo " +/* Meshwizard 0.0.4 */ +" + +# config +export dir="/usr/bin/meshwizard" +. $dir/functions.sh + +# Check which packages we have installed +export has_luci=FALSE +opkg list_installed |grep luci-mod-admin > /dev/null && export has_luci=TRUE +export has_luci_splash=FALSE +opkg list_installed |grep luci-app-splash > /dev/null && export has_luci_splash=TRUE + +# Check whether we want to cleanup/restore uci config before setting new options +cleanup=$(uci -q get meshwizard.general.cleanup) +[ "$cleanup" == 1 ] && $dir/helpers/restore_default_config.sh + +# Rename wifi interfaces +$dir/helpers/rename-wifi.sh + +# Get community +community=$(uci -q get meshwizard.community.name || uci -q get freifunk.community.name) +[ -z "$community" ] && echo "Error: Community is not set in /etc/config/freifunk, aborting now." && exit 1 +export community="$community" +echo $community + +# Get a list of networks we need to setup +networks=$(uci show meshwizard.netconfig | grep -v "netconfig=" | sed -e 's/meshwizard.netconfig\.\(.*\)\_.*/\1/' |sort|uniq) +export networks +[ -z "$networks" ] && echo "Error: No networks to setup could be found in /etc/config/meshwizard, aborting now." && exit 1 + +# Read default values (first from /etc/config/freifunk, then from /etc/config/profile_$community +# then /etc/config/meshwizard +# last will overwrite first + +$dir/helpers/read_defaults.sh $community > /tmp/meshwizard.tmp +while read line; do + export "${line//\"/}" +done < /tmp/meshwizard.tmp + +# Do config +$dir/helpers/initial_config.sh +$dir/helpers/setup_dnsmasq.sh +$dir/helpers/setup_system.sh +$dir/helpers/setup_olsrd.sh +$dir/helpers/setup_firewall.sh + +if [ "$wan_proto" == "static" ] && [ -n "$wan_ip4addr" ] && [ -n "$wan_netmask" ]; then + $dir/helpers/setup_wan_static.sh +fi + +if [ "$lan_proto" == "static" ] && [ -n "$lan_ip4addr" ] && [ -n "$lan_netmask" ]; then + $dir/helpers/setup_lan_static.sh +fi + +# Setup policyrouting if internet sharing is disabled and wan is not used for olsrd +# Always disable it first to make sure its disabled when the user decied to share his internet +uci set freifunk-policyrouting.pr.enable=0 +if [ ! "$general_sharenet" == 1 ] && [ ! "$(uci -q get meshwizard.netconfig.wan_proto)" == "olsr" ]; then + $dir/helpers/setup_policyrouting.sh +fi + +# Configure found networks +for net in $networks; do + # radioX devices need to be renamed + netrenamed="${net/radio/wireless}" + export netrenamed + $dir/helpers/setup_network.sh $net + if [ ! "$net" == "wan" ] && [ ! "$net" == "lan" ]; then + $dir/helpers/setup_wifi.sh $net + fi + $dir/helpers/setup_olsrd_interface.sh $net + + net_dhcp=$(uci -q get meshwizard.netconfig.${net}_dhcp) + if [ "$net_dhcp" == 1 ]; then + $dir/helpers/setup_dhcp.sh $net + fi + + $dir/helpers/setup_splash.sh $net + $dir/helpers/setup_firewall_interface.sh $net +done + +##### Reboot the router (because simply restarting services gave errors) + +reboot diff --git a/webgui/luci/remote-update/Makefile b/webgui/luci/remote-update/Makefile new file mode 100644 index 000000000..2bb3b24cd --- /dev/null +++ b/webgui/luci/remote-update/Makefile @@ -0,0 +1,43 @@ +# +# Copyright (C) 2009 Jo-Philipp Wich +# +# This is free software, licensed under the Apache 2.0 license. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=remote-update +PKG_RELEASE:=4 + +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) + +include $(INCLUDE_DIR)/package.mk + +define Package/remote-update + SECTION:=luci + CATEGORY:=LuCI + SUBMENU:=9. Freifunk + TITLE:=Freifunk remote update utility. + DEPENDS:=@TARGET_atheros||@TARGET_ar71xx||@TARGET_brcm_2_4 +endef + +define Package/remote-update/description + The freifunk remote-update utility uses sysupgrade to reflash the currently + running firmware while keeping most of the existing configuratio. +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) +endef + +define Build/Configure +endef + +define Build/Compile +endef + +define Package/remote-update/install + $(CP) ./files/* $(1)/ +endef + +$(eval $(call BuildPackage,remote-update)) diff --git a/webgui/luci/remote-update/files/usr/sbin/remote-update b/webgui/luci/remote-update/files/usr/sbin/remote-update new file mode 100755 index 000000000..6e45e482b --- /dev/null +++ b/webgui/luci/remote-update/files/usr/sbin/remote-update @@ -0,0 +1,306 @@ +#!/bin/sh + +local tempfile=/tmp/remote-upgrade.img +local D2='\([0-9]\{2\}\)' +local D4='\([0-9]\{4\}\)' +local NL=' +' + +find_architecture() +{ + local ifs="$IFS"; IFS="-" + set -- $(opkg list_installed kernel) + IFS="$ifs" + + echo "$3" +} + +find_image() +{ + case "$1" in + atheros) + echo "openwrt-atheros-combined.squashfs.img" + ;; + ar71xx) + echo "openwrt-ar71xx-combined.squashfs.img" + ;; + brcm) + echo "openwrt-brcm-2.4-squashfs.trx" + ;; + esac +} + +check_image() +{ + local file; for file in /lib/upgrade/*.sh; do . $file; done + if platform_check_image "$1" >/dev/null 2>/dev/null; then + return 0 + fi + return 1 +} + +find_remote_checksum() +{ + wget -qO- ${1%/*}/md5sums 2>/dev/null | \ + sed -ne '/'$2'/ { s/ .*//p }' +} + +find_local_checksum() +{ + set -- $(md5sum "$tempfile") + echo $1 +} + +find_remote_info() +{ + wget -qO- "${1%/*}/VERSION.txt" 2>/dev/null +} + +find_remote_version() +{ + find_remote_info "$1" | \ + sed -ne "s!.*$D4/$D2/$D2 $D2:$D2.*!\\1\\2\\3\\4\\5!p;t" +} + +find_local_version() +{ + if [ -f /rom/etc/banner ]; then + sed -ne "s!.*$D4/$D2/$D2 $D2:$D2.*!\\1\\2\\3\\4\\5!p;t" \ + /rom/etc/banner + else + date +"%Y%m%d%H%M" -r /bin/sh + fi +} + +stop_service() +{ + [ -x /etc/init.d/$1 ] && { + echo -n "Stopping service $1 ... " + /etc/init.d/$1 stop >/dev/null 2>/dev/null + echo "done" + } +} + +do_wait() +{ + if [ ${1:-0} -gt 0 ]; then + echo -n "${2:-Waiting} " + for i in $(seq 1 $1); do + printf "%-2dseconds" $(($1-$i)) + sleep 1 + echo -en "\b\b\b\b\b\b\b\b\b" + done + echo "${NL}" + fi +} + +version_compare() +{ + local v1="$1" + local v2="$2" + + while [ -n "$v1" -o -n "$v2" ]; do + if [ -z "${v2:0:4}" -o "${v1:0:4}" -gt "${v2:0:4}" ]; then + return 1 + elif [ -z "${v1:0:4}" -o "${v1:0:4}" -lt "${v2:0:4}" ]; then + return 2 + fi + + v1="${v1:4}" + v2="${v2:4}" + done + + return 0 +} + +usage() +{ + cat <] -c + remote-update [-v] [-y] [-u ] -w + remote-update [-d] [-n] [-v] [-y] [-s ] [-u ] + +Actions: + -h Display this help message and exit. + -c Check for firmware update and exit. + -w Fetch image and exit, do not perform flash write. + +Options: + -d Do not detach from terminal. + -n Do not backup configuration. + -v Skip verification of downloaded image. + -y Assume defaults for all questions. + + -s + Sleep given amount of seconds before starting flash write. + If ommitted and '-y' is not used, 5 seconds are assumed. + + -u + Fetch firmware image from given url. A file "md5sums" is expected + in the same remote directory. If there is no such file, use -v to + suppress verification. + +EOT + + exit 1 +} + + +while getopts "s:u:cdnvwyh" flag; do + case $flag in + s) sleeptime="$OPTARG";; + u) updateurl="$OPTARG";; + c) checkupdate=1;; + d) nodetach=1;; + n) nobackup=1;; + v) noverify=1;; + w) noflash=1;; + y) noquestions=1;; + *) usage;; + esac +done + + +local image_url="$updateurl" +local image_name="${image_url##*/}" + +[ -z "$image_url" ] && { + local arch=$(find_architecture) + local image=$(find_image "$arch") + local repo=$(uci get freifunk.upgrade.repository 2>/dev/null) + repo=${repo:-$(uci get system.upgrade.repository 2>/dev/null)} + + [ -z "$arch" ] && { + echo "Can not determine the current architecture." + exit 1 + } + + [ -z "$repo" ] && { + echo "No repository configured in 'system.upgrade.repository'." + echo "Use the '-u' flag to specify an image location." + exit 1 + } + + [ -z "$image" ] && { + echo "No suitable image for the '$arch' architecture." + echo "Your platform is not supported." + exit 1 + } + + echo "Architecture: $arch" + echo "Repository: $repo" + + image_name="$image" + image_url="${repo%/}/$arch/$image" +} + + +if [ "$checkupdate" = 1 ]; then + local v1=$(find_local_version) + local v2=$(find_remote_version "$image_url") + + [ -n "$v1" -a -n "$v2" ] && { + version_compare "$v1" "$v2" + [ $? == 2 ] && { + echo "Update available!${NL}Local: $v1${NL}Remote: $v2${NL}--" + find_remote_info "$image_url" + exit 0 + } || { + echo "Local version $v1 is up to date" + exit 2 + } + } || { + echo "No remote time stamp found." + exit 1 + } +else + if [ "$noquestions" != 1 ]; then + echo -n "${NL}About to download $image_name. Continue? [y] " + read answer + case "$answer" in + [nN]) exit 1;; + esac + fi + + echo -n "Downloading $image_name ... " + rm -f $tempfile + wget -qO $tempfile "$image_url" 2>/dev/null + [ $? == 0 ] && echo done || { + echo failed + rm -f $tempfile + exit 1 + } + + if [ "$noverify" != 1 ]; then + echo -n "Verifying $image_name ... " + + local md5_remote=$(find_remote_checksum "$image_url" "$image_name") + local md5_local=$(find_local_checksum) + + check_image "$tempfile" + local image_ok=$? + + if [ $image_ok = 0 -a -n "$md5_remote" -a -n "$md5_local" -a "$md5_remote" = "$md5_local" ]; then + echo "done" + else + if [ $image_ok != 0 ]; then + echo "unsupported image type" + else + echo "checksum mismatch! (local:${md5_local:-(none)} remote:${md5_remote:-(none)})" + fi + + local answer=n + if [ "$noquestions" != 1 ]; then + echo -n "${NL}Verification failed. Continue anyway? [n] " + read answer + fi + + case "$answer" in + [yYjJ]*) : ;; + *) + echo "Aborting." + rm -f $tempfile + exit 1 + ;; + esac + fi + fi + + if [ "$noflash" != 1 ]; then + if [ -f "$tempfile" ]; then + if [ "$noquestions" == 1 ]; then + do_wait ${sleeptime:-5} "${NL}About to start flashing, hit to abort!${NL}${NL}Starting in" + else + if [ -z "$nobackup" ]; then + echo -n "${NL}Keep configuration files? [y] " + read answer + case "$answer" in + [nN]) nobackup=1;; + esac + fi + + echo -n "${NL}About to start flashing!${NL}Hit to continue or to abort.${NL}" + read answer + fi + + for s in lucid collectd; do stop_service $s; done + + if [ "$nodetach" != 1 ]; then + echo -n "Starting sysupgrade in background ... " + /bin/busybox start-stop-daemon -S -b -x /sbin/sysupgrade -- ${nobackup:+-n} "$tempfile" + echo "done" + else + echo "Executing sysupgrade ... " + exec /sbin/sysupgrade ${nobackup:+-n} "$tempfile" + fi + else + echo "No upgrade image found!" + exit 1 + fi + else + echo "Image saved in '$tempfile'" + fi +fi