@@ -21,11 +21,13 @@ case "$BOARD" in
# Default: LAN0: WAN, LAN1: CLIENT
setupSwitch "eth0" "0t 4" "0t" "0t 5"
setupWan "eth0.2"
+ uci -q set "fff.ui.portsetup=twoport"
;;
gl-ar150)
# Default: CLIENT
setupSwitch "eth1" "0t 1" "0t"
setupWan "eth0"
+ uci -q set "fff.ui.portsetup=2ndport"
;;
tl-wdr3500-v1|\
tl-wr741nd-v2|\
@@ -85,6 +87,7 @@ case "$BOARD" in
ubnt-unifiac-lite|\
ubnt-unifiac-mesh)
setupOnePort "eth0" "CLIENT"
+ uci -q set "fff.ui.portsetup=oneport"
;;
esac
new file mode 100755
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+# This sets the port mode on second port without switch
+
+if ! [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ] ; then
+ echo "Wrong device. This is for two-port devices without switch only!"
+ exit 1
+fi
+
+LAN0MODE=$1
+
+CLIENT_PORTS="0t"
+BATMAN_PORTS="0t"
+
+if [ "$LAN0MODE" = "CLIENT" ] ; then
+ CLIENT_PORTS="$CLIENT_PORTS 1"
+elif [ "$LAN0MODE" = "BATMAN" ] ; then
+ BATMAN_PORTS="$BATMAN_PORTS 1"
+else
+ echo "Wrong port mode. Choose one of: CLIENT, BATMAN"
+ exit 1
+fi
+
+uci set "network.eth1_1.ports=$CLIENT_PORTS"
+uci set "network.eth1_3.ports=$BATMAN_PORTS"
+uci -q commit network
+
+echo "Port updated. Please reboot device!"
new file mode 100755
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+# This sets the port mode on one-port devices
+
+if ! [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] ; then
+ echo "Wrong device. This is for one-port devices only!"
+ exit 1
+fi
+
+. /lib/functions/fff/networksetup
+
+ETHMODE=$1
+
+if [ "$ETHMODE" = "WAN" ] || [ "$ETHMODE" = "CLIENT" ] || [ "$ETHMODE" = "BATMAN" ]; then
+ setupOnePort "eth0" "$ETHMODE"
+ echo "Port updated. Please reboot device!"
+else
+ echo "Wrong port mode. Choose one of: WAN, CLIENT, BATMAN"
+ exit 1
+fi
new file mode 100755
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+# This sets the port mode on CPE210 v1 and CPE510 v1
+
+if ! [ "$(uci -q get fff.ui.portsetup)" = "twoport" ] ; then
+ echo "Wrong device. This is for two-port CPE devices only!"
+ exit 1
+fi
+
+LAN0MODE=$1
+LAN1MODE=$2
+
+CLIENT_PORTS="0t"
+WAN_PORTS="0t"
+BATMAN_PORTS="0t"
+
+if [ "$LAN0MODE" = "WAN" ] ; then
+ WAN_PORTS="$WAN_PORTS 5"
+elif [ "$LAN0MODE" = "CLIENT" ] ; then
+ CLIENT_PORTS="$CLIENT_PORTS 5"
+elif [ "$LAN0MODE" = "BATMAN" ] ; then
+ BATMAN_PORTS="$BATMAN_PORTS 5"
+else
+ echo "Wrong port mode for 1st port. Choose one of: WAN, CLIENT, BATMAN"
+ exit 1
+fi
+
+if [ "$LAN1MODE" = "WAN" ] ; then
+ WAN_PORTS="$WAN_PORTS 4"
+elif [ "$LAN1MODE" = "CLIENT" ] ; then
+ CLIENT_PORTS="$CLIENT_PORTS 4"
+elif [ "$LAN1MODE" = "BATMAN" ] ; then
+ BATMAN_PORTS="$BATMAN_PORTS 4"
+else
+ echo "Wrong port mode for 2nd port. Choose one of: WAN, CLIENT, BATMAN"
+ exit 1
+fi
+
+uci set "network.eth0_1.ports=$CLIENT_PORTS"
+uci set "network.eth0_2.ports=$WAN_PORTS"
+uci set "network.eth0_3.ports=$BATMAN_PORTS"
+uci -q commit network
+
+echo "Ports updated. Please reboot device!"
@@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=fff-support
-PKG_RELEASE:=2
+PKG_RELEASE:=3
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
new file mode 100644
@@ -0,0 +1,13 @@
+#!/bin/sh
+# Copyright 2019 Adrian Schmutzler
+# License GPLv3
+
+LOCALUPGRADESCRIPT="/etc/firstbootfff"
+
+#add LOCALUPGRADESCRIPT to sysupgrade
+grep -q ^"${LOCALUPGRADESCRIPT}"$ /etc/sysupgrade.conf || echo "$LOCALUPGRADESCRIPT" >> /etc/sysupgrade.conf
+
+# process user commands
+[ -s "$LOCALCONFIGSCRIPT" ] && {
+ sh /etc/firstbootfff
+}
@@ -3,6 +3,7 @@
. /etc/firmware_release
. /lib/functions/fff/evalhoodinfo
. /lib/functions/fff/evalbytes
+. /lib/functions/fff/portorder
. /lib/functions.sh # required for config_load and config_foreach
board_name=$(uci -q get board.model.name)
@@ -187,13 +188,9 @@ fi
echo "Download-Limit: $(uci -q get 'simple-tc.example.limit_ingress') kBit/s"
echo "Upload-Limit: $(uci -q get 'simple-tc.example.limit_egress') kBit/s"
-if grep -q 'PORTORDER=' /etc/network.$board_name ; then
- portorder=$(awk -F= '/PORTORDER=/ { print $2 }' /etc/network.$board_name | sed "s/\"//g")
-fi
-
echo ""
if swconfig list | grep -q switch0 ; then
- if [ -n "$portorder" ] ; then
+ if [ -n "$PORTORDER" ] ; then
echo "-> SWITCH (tatsaechliche Portreihenfolge)"
else
echo "-> SWITCH (interne logische Portreihenfolge)"
@@ -218,7 +215,7 @@ if swconfig list | grep -q switch0 ; then
printf '%-10s%-5s%-13s%s\n' "WAN-Port: " "${link} " "- WAN " "@ $speed"
fi
- for internalport in $portorder
+ for internalport in $PORTORDER
do
line=$(swconfig dev switch0 port "$internalport" show | tr -d '\n' | tr -d '\t')
port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/')
@@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=fff-web
-PKG_RELEASE:=7
+PKG_RELEASE:=8
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
@@ -2,22 +2,27 @@
<%
board_name=$(uci -q get board.model.name)
+LOCALUPGRADESCRIPT="/etc/firstbootfff"
+
# write
if [ "$REQUEST_METHOD" = "POST" ] ; then
if [ "$POST_change_mode" != "" ] ; then
- sed -i '/^.*# set via WebUI/d' /etc/network.config
- echo "ETHMODE=\"${POST_mode}\" # set via WebUI" >> /etc/network.config
- sed -i '/^FORCEPARSE/d' /etc/network.config
- echo "FORCEPARSE='2'" >> /etc/network.config
+ if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ]; then
+ setoneport "${POST_mode}"
+ sed -i '/^setoneport.*/d' $LOCALUPGRADESCRIPT
+ echo "setoneport \"${POST_mode}\" # set via WebUI" >> $LOCALUPGRADESCRIPT
+ elif [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ]; then
+ set2ndport "${POST_mode}"
+ sed -i '/^set2ndport.*/d' $LOCALUPGRADESCRIPT
+ echo "set2ndport \"${POST_mode}\" # set via WebUI" >> $LOCALUPGRADESCRIPT
+ fi
do_reboot=1
MSG='<span class="green">Port Modus geändert! Router startet neu...</span>'
fi
if [ "$POST_change_twoport" != "" ] ; then
- sed -i '/^.*# set via WebUI/d' /etc/network.config
- echo "LAN0MODE=\"${POST_mode0}\" # set via WebUI" >> /etc/network.config
- echo "LAN1MODE=\"${POST_mode1}\" # set via WebUI" >> /etc/network.config
- sed -i '/^FORCEPARSE/d' /etc/network.config
- echo "FORCEPARSE='2'" >> /etc/network.config
+ settwoport "${POST_mode0}" "${POST_mode1}"
+ sed -i '/^settwoport.*/d' $LOCALUPGRADESCRIPT
+ echo "settwoport \"${POST_mode0}\" \"${POST_mode1}\" # set via WebUI" >> $LOCALUPGRADESCRIPT
do_reboot=1
MSG='<span class="green">Port Modus geändert! Router startet neu...</span>'
fi
@@ -108,11 +113,8 @@ format_port() {
echo "</td>"
fi
- if grep -q 'PORTORDER=' /etc/network.$board_name ; then
- portorder=$(awk -F= '/PORTORDER=/ { print $2 }' /etc/network.$board_name | sed "s/\"//g")
- fi
- for internalport in $portorder
- do
+ . /lib/functions/fff/portorder
+ for internalport in $PORTORDER ; do
line=$(swconfig dev switch0 port "$internalport" show | tr -d '\n' | tr -d '\t')
port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/')
echo "<td class=\"swport\">"
@@ -120,16 +122,12 @@ format_port() {
format_port "${line}"
echo "</td>"
done
- if [ -n "$portorder" ] ; then
- echo "<td class=\"swport\" style=\"width:4em\"></td>"
- fi
+ [ -n "$PORTORDER" ] && echo "<td class=\"swport\" style=\"width:4em\"></td>"
swconfig dev switch0 show | grep "\t*link:" | while read line ; do
line=$(echo "$line" | tr -d '\n' | tr -d '\t')
port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/')
- if echo "$portorder" | grep -q "$port" ; then
- continue
- fi
+ echo "$PORTORDER" | grep -q "$port" && continue
echo "<td class=\"swport\">"
echo "<span class=\"port\">Port #${port}</span><br />"
format_port "${line}"
@@ -141,7 +139,7 @@ format_port() {
<table>
<tr><td></td></tr>
<tr><td>
- <% if [ -n "$portorder" ] ; then %>
+ <% if [ -n "$PORTORDER" ] ; then %>
Dies zeigt die tatsächliche Zuordnung der Ports, wobei der WAN Port auf der linken Seite liegt. Die Nummerierung entspricht der internen Zuordnung!<br />
<% else %>
Die Nummerierung und Reihenfolge der Ports entspricht nicht notwendigerweise der der Netzwerkanschlüsse am Router!<br />
@@ -152,12 +150,7 @@ format_port() {
</fieldset>
</td></tr>
<% fi %>
-<% if grep -q "ONE_PORT" "/etc/network.$board_name" || grep -q "ETHPORT" "/etc/network.$board_name" ; then %>
- <%
- # Device has a port set by $ETHMODE
- . /etc/network.mode
- . /etc/network.config
- %>
+<% if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] || [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ] ; then %>
<tr><td>
<fieldset>
<legend>Ethernet Anschluss</legend>
@@ -166,10 +159,10 @@ format_port() {
<th style="width: 1em;">Anschluss Modus:</th>
<td>
<select name="mode">
- <option value="BATMAN" <% [ "$ETHMODE" = "BATMAN" ] && echo -n 'selected="selected" ' %>>BATMAN</option>
- <option value="CLIENT" <% [ "$ETHMODE" = "CLIENT" ] && echo -n 'selected="selected" ' %>>CLIENT</option>
- <% if grep -q "ONE_PORT" "/etc/network.$board_name" ; then %>
- <option value="WAN" <% [ "$ETHMODE" = "WAN" ] && echo -n 'selected="selected" ' %>>WAN</option>
+ <option value="BATMAN">BATMAN</option>
+ <option value="CLIENT">CLIENT</option>
+ <% if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] ; then %>
+ <option value="WAN">WAN</option>
<% fi %>
</select>
</td>
@@ -178,7 +171,7 @@ format_port() {
<tr><td colspan="2"></td></tr>
<tr><td colspan="2">
WAN: Knoten stellt über Ethernet Anschluss Verbindung zum Internet her.<br />
- Client: Normale Clients stellen über Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
+ CLIENT: Normale Clients stellen über Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
BATMAN: Knoten stellt über Ethernet Anschluss Verbindung zu anderen MESH Knoten her.<br /><br />
Wenn diese Einstellung verändert wird, wird eine evtl. vorhandene manuelle Netzwerkkonfiguration in der
@@ -189,12 +182,7 @@ format_port() {
</fieldset>
</td></tr>
<% fi %>
-<% if grep -q "LAN0PORT" "/etc/network.$board_name" || grep -q "LAN1PORT" "/etc/network.$board_name" ; then %>
- <%
- # Device has two ports
- . /etc/network.mode
- . /etc/network.config
- %>
+<% if [ "$(uci -q get fff.ui.portsetup)" = "twoport" ] ; then %>
<tr><td>
<fieldset>
<legend>Ethernet Anschlüsse</legend>
@@ -207,16 +195,16 @@ format_port() {
<tr>
<td>
<select name="mode0">
- <option value="BATMAN" <% [ "$LAN0MODE" = "BATMAN" ] && echo -n 'selected="selected" ' %>>BATMAN</option>
- <option value="CLIENT" <% [ "$LAN0MODE" = "CLIENT" ] && echo -n 'selected="selected" ' %>>CLIENT</option>
- <option value="WAN" <% [ "$LAN0MODE" = "WAN" ] && echo -n 'selected="selected" ' %>>WAN</option>
+ <option value="BATMAN">BATMAN</option>
+ <option value="CLIENT">CLIENT</option>
+ <option value="WAN">WAN</option>
</select>
</td>
<td>
<select name="mode1">
- <option value="BATMAN" <% [ "$LAN1MODE" = "BATMAN" ] && echo -n 'selected="selected" ' %>>BATMAN</option>
- <option value="CLIENT" <% [ "$LAN1MODE" = "CLIENT" ] && echo -n 'selected="selected" ' %>>CLIENT</option>
- <option value="WAN" <% [ "$LAN1MODE" = "WAN" ] && echo -n 'selected="selected" ' %>>WAN</option>
+ <option value="BATMAN">BATMAN</option>
+ <option value="CLIENT">CLIENT</option>
+ <option value="WAN">WAN</option>
</select>
</td>
<td><input type="submit" name="change_twoport" /></td>
@@ -224,7 +212,7 @@ format_port() {
<tr><td colspan="3"></td></tr>
<tr><td colspan="3">
WAN: Knoten stellt über Ethernet Anschluss Verbindung zum Internet her.<br />
- Client: Normale Clients stellen über Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
+ CLIENT: Normale Clients stellen über Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
BATMAN: Knoten stellt über Ethernet Anschluss Verbindung zu anderen MESH Knoten her.<br /><br />
Wenn diese Einstellung verändert wird, wird eine evtl. vorhandene manuelle Netzwerkkonfiguration in der
This patch: - provides scripts to easily change port configuration on the "special" devices - provides a file to store upgrade-safe script lines run at first boot (to be used for port adjustments) - fixes the port page in WebUI - fixes show_info With this patch, instead of specifying data in network.config and then have a script to deal with it, we define a script /etc/firstbootfff where COMMANDS can be stored. Thus, one can just make switch ports permanent by putting the uci commands there. To keep the convenient setup of one-port (and other special) devices, we implement script, e.g. setoneport "WAN" will set the port of a one-port device to WAN mode. Those scripts are used in the WebUI and may also be implemented manually in the /etc/firstbootfff file. This patch misses the selection of the current port mode in the WebUI. It would have been to much additional code. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de> --- This patch is built to reintroduce as much of the previous functionality as possible. One could however consider removing the CPE and AR150 special cases and leave only the real one-ports in the WebUI. --- .../files/etc/uci-defaults/22b-config-ports | 3 + .../fff/fff-network/files/usr/sbin/set2ndport | 28 ++++++++ .../fff/fff-network/files/usr/sbin/setoneport | 20 ++++++ .../fff/fff-network/files/usr/sbin/settwoport | 44 ++++++++++++ src/packages/fff/fff-support/Makefile | 2 +- .../files/etc/uci-defaults/90-firstbootfff | 13 ++++ .../fff/fff-support/files/usr/sbin/show_info | 9 +-- src/packages/fff/fff-web/Makefile | 2 +- .../fff/fff-web/files/www/ssl/cgi-bin/ports.html | 78 +++++++++------------- 9 files changed, 146 insertions(+), 53 deletions(-) create mode 100755 src/packages/fff/fff-network/files/usr/sbin/set2ndport create mode 100755 src/packages/fff/fff-network/files/usr/sbin/setoneport create mode 100755 src/packages/fff/fff-network/files/usr/sbin/settwoport create mode 100644 src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff