Open-Mesh Revisited

Well after my first attempts with those little white boxes, along came the OpenWRT-Linux guru of our net to point out that most of the ways i tried to tackle problems are things of the past for OpenWRT.  As a matter of fact i think that most of the problems i am trying to tackle under Linux are me own patchwork around my ignorance to some new developments or ways around things. But hey this is the deal. Attempt and right the wrongs by great collaboration and good friends. So lets say thanx to Vasilis Tsiligiannis for all the help and guidance he provided in rewriting and perfecting the script we needed.

Here i goes. This is the new custom.sh. I am putting this down for reference. It also includes some fixes that are not needed if all things have ran smoothly in the first place 🙂

#!/bin/sh
#
# custom.sh script for awmn-freespot mesh network
#
# Copyright (C) 2010 Vasilis Tsiligiannis
#
# 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 3 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, see <http://www.gnu.org/licenses/>.

BLACKLIST_SUBNETS_ADD="10.32.54.4/32 10.3.41.1/32 10.86.87.129/32 10.26.126.14/32 10.19.180.10/32"
BLACKLIST_SUBNETS_REMOVE="10.0.0.0/8"
ENABLE_ROOTPWD=0
USE_NODE_PRIVATE_SSID=1
DNSMASQ_STRICT_ORDER=1
FORCE_REBOOT=0

# Don't edit below unless you know what you're doing.
BLACKLIST_SUBNETS_FILE="/etc/blacklist/subnets"
UPDATE_MANAGEMENT_FILE="/usr/sbin/update-management.sh"
UPDATE_WIFI_FILE="/usr/sbin/update-wifi.sh"
SET_PASSWORD_FILE="/sbin/set_password"
DHCPD_INIT_FILE="/etc/init.d/dhcpd"
ROBIN_VERSION="$(cat /etc/robin_version)"

esc_patt() {
 echo "$1" | sed \
 -e 's/\//\\\//g' \
 -e 's/\./\\./g' \
 -e 's/\*/\\*/g'
}

blcklst_sub_del() {
 local blck_file="$1"
 shift
 for i in $@; do
 local esc=$(esc_patt "$i")
 grep -q "^$esc$" "$blck_file" && {
 sed -i -e '/^'"$esc"'$/ d' "$blck_file"
 uci set flags.restart.system="1"
 uci commit flags
 }
 done
}

blcklst_sub_add() {
 local blck_file="$1"
 shift
 for i in $@; do
 local esc=$(esc_patt "$i")
 grep -q "^$esc$" "$blck_file" || {
 echo "$i" >> "$blck_file"
 uci set flags.restart.system="1"
 uci commit flags
 }
 done
}

case $ROBIN_VERSION in
 "r2693"|"r2695")
 # Remove blacklisted subnets
 blcklst_sub_del "$BLACKLIST_SUBNETS_FILE" $BLACKLIST_SUBNETS_REMOVE

 # Add blacklisted subnets
 blcklst_sub_add "$BLACKLIST_SUBNETS_FILE" $BLACKLIST_SUBNETS_ADD

 # Change dropbear port
 uci set dropbear.@dropbear[0].Port=2222

 # Manipulate passpwd change
 case $ENABLE_ROOTPWD in
 "0")
 # Disable rootpwd dashboard change
 grep -q "\"enable\.rootpwd\")" "$UPDATE_MANAGEMENT_FILE" && {
 sed -i -e 's/\"enable\.rootpwd\")/\"disableDit\")/' "$UPDATE_MANAGEMENT_FILE"
 uci set flags.restart.system="1"
 uci commit flags
 }
 grep -q "^(echo -n" "$SET_PASSWORD_FILE" && {
 sed -i -e 's/^(echo -n/# (echo -n/' "$SET_PASSWORD_FILE"
 uci set flags.restart.system="1"
 uci commit flags
 }
 # Change passwd for very good reasons
 echo \
"root:###########:root:/tmp:/bin/ash
nobody:*:65534:65534:nobody:/var:/bin/false" > /etc/passwd
 ;;
 "1")
 # Enable rootpwd dashboard change
 grep -q "\"disableDit\")" "$UPDATE_MANAGEMENT_FILE" && {
 sed -i -e 's/\"disableDit\")/\"enable.rootpwd\")/' "$UPDATE_MANAGEMENT_FILE"
 uci set flags.restart.system="1"
 uci commit flags
 }
 grep -q "^# (echo -n" "$SET_PASSWORD_FILE" && {
 sed -i -e 's/^# (echo -n/(echo -n/' "$SET_PASSWORD_FILE"
 uci set flags.restart.system="1"
 uci commit flags
 }
 ;;
 esac

 # Manipulate private SSID and key
 case $USE_NODE_PRIVATE_SSID in
 "0")
 grep -q "\"private\.ssiddis\")" "$UPDATE_WIFI_FILE" && {
 sed -i -e 's/\"private\.ssiddis\")/\"private.ssid\")/' "$UPDATE_WIFI_FILE"
 uci set flags.restart.system="1"
 uci commit flags
 }
 grep -q "\"private\.keydis\")" "$UPDATE_WIFI_FILE" && {
 sed -i -e 's/\"private\.keydis\")/\"private.key\")/' "$UPDATE_WIFI_FILE"
 uci set flags.restart.system="1"
 uci commit flags
 }
 ;;
 "1")
 grep -q "\"private\.ssid\")" "$UPDATE_WIFI_FILE" && {
 sed -i -e 's/\"private\.ssid\")/\"private.ssiddis\")/' "$UPDATE_WIFI_FILE"
 uci set flags.restart.system="1"
 uci commit flags
 }
 grep -q "\"private\.key\")" "$UPDATE_WIFI_FILE" && {
 sed -i -e 's/\"private\.key\")/\"private.keydis\")/' "$UPDATE_WIFI_FILE"
 uci set flags.restart.system="1"
 uci commit flags
 }
 # Change private ssid and key
 uci set mesh.Myap.ssid=$(uci get system.@system[0].hostname 2>/dev/null)
 uci set mesh.Myap.key=$(uci get node.general.myMAC 2>/dev/null | tr -d ":")
 ;;
 esac

 # Use strict order on resolv.conf
 case $DNSMASQ_STRICT_ORDER in
 "0")
 grep -q "strict-order" "$DHCPD_INIT_FILE" && {
 sed -i -e '/strict-order/ d' "$DHCPD_INIT_FILE"
 uci set flags.restart.system="1"
 uci commit flags
 }
 ;;
 "1")
 grep -q "strict-order" "$DHCPD_INIT_FILE" || {
 sed -i -e '/bogus-priv/ a\
 echo \"strict-order\" >> $DNSMASQ_CONF' "$DHCPD_INIT_FILE"
 uci set flags.restart.system="1"
 uci commit flags
 }
 ;;
 esac

 # Fix repeaters empty password
 for i in $(ip route show | grep -e "^5\..*metric.*$" | cut -d " " -f -1); do
 (sleep 5 | echo \
"echo \"root:############:root:/tmp:/bin/ash
nobody:*:65534:65534:nobody:/var:/bin/false\" > /etc/passwd
exit") | nc "$i" 23
 done

 # Schedule reboot if configuration changed or forced reboot
 [ -z "$(uci changes 2>/dev/null)" -a "$FORCE_REBOOT" -eq 0 ] || {
 uci set flags.restart.system="1"
 uci commit
 }
 ;;
esac

Comments are closed.