forked from freifunk-franken/firmware
Compare commits
9 Commits
master
...
autol3comp
Author | SHA1 | Date |
---|---|---|
Christian Dresel | c082735105 | |
Christian Dresel | b252c84143 | |
Christian Dresel | 896bf3e8f1 | |
Christian Dresel | 495db7f257 | |
Christian Dresel | d26134f1d5 | |
Christian Dresel | 1deeac8f30 | |
Christian Dresel | 5f22c2131c | |
Christian Dresel | 8581bd76c4 | |
Christian Dresel | b94f2ee10e |
|
@ -0,0 +1,32 @@
|
|||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=fff-autol3
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_BUILD_DIR:=$(BUILD_DIR)/fff-autol3
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/fff-autol3
|
||||
SECTION:=base
|
||||
CATEGORY:=Freifunk
|
||||
TITLE:=Freifunk-Franken layer3 automatic ipv4 configuration
|
||||
URL:=https://www.freifunk-franken.de
|
||||
DEPENDS:= \
|
||||
+fff-layer3-config
|
||||
|
||||
endef
|
||||
|
||||
define Package/fff-autol3/description
|
||||
This package load automatic ipv4 over mqtt
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
# nothing
|
||||
endef
|
||||
|
||||
define Package/fff-autol3/install
|
||||
$(CP) ./files/* $(1)/
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,fff-autol3))
|
|
@ -0,0 +1,6 @@
|
|||
if ! uci -q get fff.autol3 > /dev/null ; then
|
||||
uci set fff.autol3=autol3
|
||||
uci commit fff
|
||||
fi
|
||||
|
||||
exit 0;
|
|
@ -0,0 +1,64 @@
|
|||
#!/bin/sh
|
||||
|
||||
# first check is fff.autol3.ipv6 enabled
|
||||
if [ -z $(uci -q get fff.autol3.ipv6) ] ; then
|
||||
exit;
|
||||
fi
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
MACADDR=$(cat /sys/class/net/br-client/address | /bin/sed 's/://g')
|
||||
MQTTSERVER=$(uci -q get fff.mqtt.server)
|
||||
ASSIGNEROWN=$(uci -q get fff.autol3.ipv6assigner)
|
||||
IPOWN=$(uci -q get fff.autol3.ipv6address)
|
||||
|
||||
asknew() {
|
||||
# Load Blocklist
|
||||
ipv6assignerblock=$(uci get fff.autol3.ipv6assignerblock)
|
||||
for ipv6assignerblock in $ipv6assignerblock; do
|
||||
block="$block -T /ipv6/usethis/+/$ipv6assignerblock"
|
||||
done
|
||||
echo $block
|
||||
mosquitto_pub -h $MQTTSERVER -p 1883 -t '/ipv6/asknew' -m "$MACADDR"
|
||||
# use the first income message
|
||||
# cancel after 5 second, after this time we don't get any IP address
|
||||
autol3config=$(mosquitto_sub -h $MQTTSERVER -p 1883 -t '/ipv6/usethis/#' -C 1 $block)
|
||||
if [ -z "$autol3config" ] ; then
|
||||
echo "No IP get"
|
||||
exit 1;
|
||||
fi
|
||||
json_load "$autol3config"
|
||||
json_get_var assigner assigner
|
||||
json_get_var ip ip
|
||||
uci set fff.autol3.ipv6address=$ip
|
||||
uci set fff.autol3.ipv6assigner=$assigner
|
||||
uci set fff.autol3.autoconfigl3=1
|
||||
uci commit fff
|
||||
uci del gateway.@client[0].ip6addr
|
||||
uci add_list gateway.@client[0].ip6addr=$ip
|
||||
uci commit gateway
|
||||
# call canusethis that assigner know we use the ipv6
|
||||
canusethis
|
||||
}
|
||||
|
||||
canusethis() {
|
||||
mosquitto_pub -h $MQTTSERVER -p 1883 -t /ipv6/canusethis/$ASSIGNEROWN -m "{ \"mac\":\"$MACADDR\", \"ip\":\"$IPOWN\" }"
|
||||
canusethisanswer=$(mosquitto_sub -h $MQTTSERVER -p 1883 -t /ipv6/canusethisanswer/$MACADDR -C 1 -W 5)
|
||||
# check if we get answer, if no load asknew again and get new ip address
|
||||
if [ -z $canusethisanswer ] ; then
|
||||
uci del fff.autol3.ipv6address
|
||||
uci del fff.autol3.ipv6assigner
|
||||
uci commit fff
|
||||
uci del gateway.@client[0].ip6addr
|
||||
uci commit gateway
|
||||
asknew
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -n $(uci -q get fff.autol3.ipv6address) ] ; then
|
||||
canusethis
|
||||
fi
|
||||
|
||||
if [ -n $(uci -q get fff.autol3) ] && [ -z $(uci -q get fff.autol3.ipv6address) ] ; then
|
||||
asknew
|
||||
fi
|
|
@ -0,0 +1,75 @@
|
|||
#!/bin/sh
|
||||
|
||||
# first check is fff.autol3.ipv4 enabled
|
||||
if [ -z $(uci -q get fff.autol3.ipv4) ] ; then
|
||||
exit;
|
||||
fi
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
MACADDR=$(cat /sys/class/net/br-client/address | /bin/sed 's/://g')
|
||||
MQTTSERVER=$(uci -q get fff.mqtt.server)
|
||||
ASSIGNEROWN=$(uci -q get fff.autol3.ipv4assigner)
|
||||
IPOWN=$(uci -q get fff.autol3.ipv4address)
|
||||
|
||||
asknew() {
|
||||
# Load Blocklist
|
||||
ipv6assignerblock=$(uci get fff.autol3.ipv6assignerblock)
|
||||
for ipv6assignerblock in $ipv6assignerblock; do
|
||||
block="$block -T /ipv6/usethis/+/$ipv6assignerblock"
|
||||
done
|
||||
mosquitto_pub -h $MQTTSERVER -p 1883 -t '/ipv4/asknew' -m "$MACADDR"
|
||||
# use the first income message
|
||||
# cancel after 5 second, after this time we don't get any IP address
|
||||
autol3config=$(mosquitto_sub -h $MQTTSERVER -p 1883 -t '/ipv4/usethis/#' -C 1 $block)
|
||||
if [ -z "$autol3config" ] ; then
|
||||
echo "No IP get"
|
||||
exit 1;
|
||||
fi
|
||||
json_load "$autol3config"
|
||||
json_get_var assigner assigner
|
||||
json_get_var ip ip
|
||||
ip=$(echo $ip | sed 's/\/.*//')
|
||||
uci del gateway.meta.peer_ip
|
||||
uci del gateway.@client[0].nat
|
||||
uci del gateway.@client[0].ipaddr
|
||||
uci del gateway.@client[0].dhcp_start
|
||||
uci set gateway.meta.peer_ip=$ip
|
||||
uci set gateway.@client[0].nat='1'
|
||||
uci set gateway.@client[0].ipaddr='192.168.0.1/16'
|
||||
uci set gateway.@client[0].dhcp_start='192.168.1.1'
|
||||
uci commit gateway
|
||||
uci set fff.autol3.ipv4address=$ip
|
||||
uci set fff.autol3.ipv4assigner=$assigner
|
||||
uci set fff.autol3.autoconfigl3=1
|
||||
uci commit fff
|
||||
# call canusethis that the assigner know we use this ipv4
|
||||
canusethis
|
||||
}
|
||||
|
||||
canusethis() {
|
||||
mosquitto_pub -h $MQTTSERVER -p 1883 -t /ipv4/canusethis/$ASSIGNEROWN -m "{ \"mac\":\"$MACADDR\", \"ip\":\"$IPOWN/32\" }"
|
||||
canusethisanswer=$(mosquitto_sub -h $MQTTSERVER -p 1883 -t /ipv4/canusethisanswer/$MACADDR -C 1 -W 5)
|
||||
# check if we get answer, if no load asknew again and get new ip address
|
||||
if [ -z $canusethisanswer ] ; then
|
||||
uci del fff.autol3.ipv4address
|
||||
uci del fff.autol3.ipv4assigner
|
||||
uci set fff.autol3.autoconfigl3=1
|
||||
uci commit fff
|
||||
uci del gateway.meta.peer_ip
|
||||
uci del gateway.@client[0].nat
|
||||
uci del gateway.@client[0].ipaddr
|
||||
uci del gateway.@client[0].dhcp_start
|
||||
uci commit gateway
|
||||
asknew
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -n $(uci -q get fff.autol3) ] && [ -z $(uci -q get fff.autol3.ipv4address) ] ; then
|
||||
asknew
|
||||
fi
|
||||
|
||||
if [ -n $(uci -q get fff.autol3.ipv4address) ] ; then
|
||||
canusethis
|
||||
fi
|
||||
|
|
@ -0,0 +1 @@
|
|||
2-57/5 * * * * /usr/sbin/autoconfigl3
|
|
@ -0,0 +1,22 @@
|
|||
#!/bin/sh
|
||||
|
||||
for f in /usr/lib/autol3.d/*.sh; do
|
||||
. $f
|
||||
if [ $? -ne 0 ]; then
|
||||
debug "Error when executing subscript $f, exiting!"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -n "$(uci -q get fff.autol3.autoconfigl3)" ] ; then
|
||||
if yes | configure-layer3 -c; then
|
||||
configure-layer3 -a
|
||||
else
|
||||
configure-layer3 -r
|
||||
fi
|
||||
uci del fff.autol3.autoconfigl3
|
||||
uci commit fff
|
||||
# we call the script itself again here
|
||||
# because if reconfigure we must say the assigner what ip
|
||||
. /usr/sbin/autoconfigl3
|
||||
fi
|
|
@ -19,6 +19,7 @@ define Package/fff-layer3
|
|||
+fff-layer3-config \
|
||||
+fff-network \
|
||||
+fff-ra \
|
||||
+fff-web-autol3 \
|
||||
+fff-wireguard \
|
||||
+arptables \
|
||||
+bmon \
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=fff-web-autol3
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_BUILD_DIR:=$(BUILD_DIR)/fff-web-autol3
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/fff-web-autol3
|
||||
SECTION:=base
|
||||
CATEGORY:=Freifunk
|
||||
TITLE:=Freifunk-Franken layer3 autol3 webui
|
||||
URL:=https://www.freifunk-franken.de
|
||||
DEPENDS:= \
|
||||
+fff-autol3 \
|
||||
+fff-web-ui
|
||||
|
||||
endef
|
||||
|
||||
define Package/fff-web-autol3/description
|
||||
Webui for autol3
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
# nothing
|
||||
endef
|
||||
|
||||
define Package/fff-web-autol3/install
|
||||
$(CP) ./files/* $(1)/
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,fff-web-autol3))
|
|
@ -0,0 +1 @@
|
|||
autol3,Automatische Layer 3 Einstellungen
|
|
@ -0,0 +1,128 @@
|
|||
#!/usr/bin/haserl
|
||||
|
||||
<%in /www/include/header %>
|
||||
<%in /www/include/helpers %>
|
||||
<% show_msg %>
|
||||
|
||||
<%
|
||||
|
||||
if [ -n "${POST_save}" ] ; then
|
||||
if [ -n "${POST_autol3v4}" ] ; then
|
||||
uci set fff.autol3.ipv4=1
|
||||
else
|
||||
uci del fff.autol3.ipv4
|
||||
fi
|
||||
if [ -n "${POST_autol3v6}" ] ; then
|
||||
uci set fff.autol3.ipv6=1
|
||||
else
|
||||
uci del fff.autol3.ipv6
|
||||
fi
|
||||
uci commit fff
|
||||
fi
|
||||
if [ $(uci -q get fff.autol3.ipv6) ] ; then
|
||||
autol3v6="checked"
|
||||
fi
|
||||
if [ $(uci -q get fff.autol3.ipv4) ] ; then
|
||||
autol3v4="checked"
|
||||
fi
|
||||
ASSIGNER6OWN=$(uci -q get fff.autol3.ipv6assigner)
|
||||
IP6OWN=$(uci -q get fff.autol3.ipv6address)
|
||||
ASSIGNER4OWN=$(uci -q get fff.autol3.ipv4assigner)
|
||||
IP4OWN=$(uci -q get fff.autol3.ipv4address)
|
||||
|
||||
if [ -n "${POST_blockv6}" ] ; then
|
||||
uci add_list fff.autol3.ipv6assignerblock=$ASSIGNER6OWN
|
||||
uci commit fff
|
||||
fi
|
||||
if [ -n "${POST_blockv4}" ] ; then
|
||||
uci add_list fff.autol3.ipv4assignerblock=$ASSIGNER6OWN
|
||||
uci commit fff
|
||||
fi
|
||||
|
||||
if [ -n "${POST_reloadv4}" ] ; then
|
||||
uci del fff.autol3.ipv4address
|
||||
uci del fff.autol3.ipv4assigner
|
||||
uci commit fff
|
||||
autov4
|
||||
fi
|
||||
if [ -n "${POST_reloadv6}" ] ; then
|
||||
uci del fff.autol3.ipv6address
|
||||
uci del fff.autol3.ipv6assigner
|
||||
uci commit fff
|
||||
autov6
|
||||
fi
|
||||
|
||||
if [ -n "${POST_removev6block}" ] ; then
|
||||
uci del_list fff.autol3.ipv6assignerblock=${POST_blockv6}
|
||||
uci commit fff
|
||||
fi
|
||||
if [ -n "${POST_removev4block}" ] ; then
|
||||
uci del_list fff.autol3.ipv4assignerblock=${POST_blockv4}
|
||||
uci commit fff
|
||||
fi
|
||||
%>
|
||||
|
||||
<form method="post">
|
||||
|
||||
<fieldset style="min-height: 7em;" class="smallinput">
|
||||
<legend>AutoL3</legend>
|
||||
<table>
|
||||
<tr><th>IPv4 Adresse automatisch beziehen:</th><td><input type="checkbox" id="autol3v4" name="autol3v4" <%= $autol3v4 %>></td><td>Wenn du diesen Haken setzt, wird automatisch eine IPv4 Adresse bezogen und NAT aktiviert</td></tr>
|
||||
<tr><th>IPv6 Adresse automatisch beziehen:</th><td><input type="checkbox" id="autol3v6" name="autol3v6" <%= $autol3v6 %>></td><td>bla</td></tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
<input type="submit" value="speichern" name="save" style="margin-top: 5px; margin-left: 3px;" />
|
||||
</form>
|
||||
<form method="post">
|
||||
<table>
|
||||
<tr><td>
|
||||
<fieldset style="min-height: 7em;" class="smallinput">
|
||||
<legend>IPv6 Konfiguration</legend>
|
||||
<table>
|
||||
<tr><th>Assigner:</th><td><td><%= $ASSIGNER6OWN %></td></tr>
|
||||
<tr><th>IP-Adresse:</th><td></td><td><%= $IP6OWN %></td></tr>
|
||||
</table>
|
||||
<input type="submit" value="Konfiguration neu laden" name="reloadv6" style="margin-top: 5px; margin-left: 3px;" />
|
||||
<input type="submit" value="Aktuellen Assigner sperren" name="blockv6" style="margin-top: 5px; margin-left: 3px;" />
|
||||
</fieldset>
|
||||
</td><td>
|
||||
<fieldset style="min-height: 7em;" class="smallinput">
|
||||
<legend>IPv4 Konfiguration</legend>
|
||||
<table>
|
||||
<tr><th>Assigner:</th><td><td><%= $ASSIGNER4OWN %></td></tr>
|
||||
<tr><th>IP-Adresse:</th><td></td><td><%= $IP4OWN %></td></tr>
|
||||
</table>
|
||||
<input type="submit" value="Konfiguration neu laden" name="reloadv4" style="margin-top: 5px; margin-left: 3px;" />
|
||||
<input type="submit" value="Aktuellen Assigner sperren" name="blockv4" style="margin-top: 5px; margin-left: 3px;" />
|
||||
</fieldset>
|
||||
</td></tr>
|
||||
</form>
|
||||
<form method="post">
|
||||
<tr><td>
|
||||
<fieldset style="min-height: 7em;" class="smallinput">
|
||||
<legend>IPv6 Blockliste</legend>
|
||||
<table>
|
||||
<%
|
||||
ipv6assignerblock=$(uci get fff.autol3.ipv6assignerblock)
|
||||
for ipv6assignerblock in $ipv6assignerblock; do
|
||||
echo "<tr><td>"$ipv6assignerblock":</td><td><input type=\"hidden\" name=\"blockv6\" value=\"$ipv6assignerblock\" /><input type=\"submit\" value=\"entfernen\" name=\"removev6block\" style=\"margin-top: 5px; margin-left: 3px;\" /></td></tr>"
|
||||
done
|
||||
%>
|
||||
</table>
|
||||
</fieldset>
|
||||
</td><td>
|
||||
<fieldset style="min-height: 7em;" class="smallinput">
|
||||
<legend>IPv4 Blockliste</legend>
|
||||
<table>
|
||||
<%
|
||||
ipv4assignerblock=$(uci get fff.autol3.ipv4assignerblock)
|
||||
for ipv4assignerblock in $ipv4assignerblock; do
|
||||
echo "<tr><td>"$ipv4assignerblock":</td><td><input type=\"hidden\" name=\"blockv4\" value=\"$ipv4assignerblock\" /><input type=\"submit\" value=\"entfernen\" name=\"removev4block\" style=\"margin-top: 5px; margin-left: 3px;\" /></td></tr>"
|
||||
done
|
||||
%>
|
||||
</table>
|
||||
</fieldset>
|
||||
</td></tr>
|
||||
</form>
|
||||
</table>
|
||||
<%in /www/include/footer %>
|
Loading…
Reference in New Issue