First commit with new code!

main
Jason Hawks 1 year ago
parent 6d5d6cf3a2
commit 7589d7c5a0

@ -224,12 +224,12 @@ ctrl.addremove = false
btnStart = ctrl:option(Button, "_btn_start", translate("Enable Easy Mesh")) btnStart = ctrl:option(Button, "_btn_start", translate("Enable Easy Mesh"))
function btnStart.write() function btnStart.write()
io.popen("/easymesh/easymesh.sh") io.popen("/easymesh/easymesh.sh start")
end end
btnStop = ctrl:option(Button, "_btn_stop", translate("Disable Easy Mesh")) btnStop = ctrl:option(Button, "_btn_stop", translate("Disable Easy Mesh"))
function btnStop.write() function btnStop.write()
io.popen("/easymesh/easymesh.sh") io.popen("/easymesh/easymesh.sh stop")
end end
function o.write(self, section, value) function o.write(self, section, value)

@ -1,383 +1,452 @@
#!/bin/bash #!/bin/bash
load_easymesh_config() { clear_old_networks() {
enable=$(uci -q get easymesh.config.enabled) # Get the mesh name from UCI config
mesh_bat0=$(uci -q get network.bat0) MESH_NAME=$(uci -q get easymesh.config.mesh_id)
ap_mode=$(uci -q get easymesh.config.ap_mode)
lan=$(uci -q get network.lan.ifname) # Get all the radios and go through them one by one to remove old networks and interfaces with the same mesh name
ipaddr=$(uci -q get easymesh.config.ipaddr) for CURRENT_RADIO in $(uci -X show wireless | grep wifi-device | awk -F'[.=]' '{print $2}'); do
netmask=$(uci -q get easymesh.config.netmask) echo "Clearing old networks for radio: $CURRENT_RADIO"
gateway=$(uci -q get easymesh.config.gateway)
dns=$(uci -q get easymesh.config.dns) # Use awk to parse the 'uci show wireless' output and find the matching section
ap_ipaddr=$(uci -q get network.lan.ipaddr) matched_section=$(uci show wireless | awk -F. -v radio="$CURRENT_RADIO" -v ssid="$MESH_NAME" '
#ap_ipaddr1=$(sed -n '1p' /etc/easymesh 2>/dev/null) $0 ~ /^wireless\.wifinet[0-9]+\.device=/ && $3 ~ radio { device_section=$2 }
apRadio=$(uci -q get easymesh.config.apRadio) $0 ~ /^wireless\.wifinet[0-9]+\.ssid=/ && $3 ~ ssid && device_section == $2 { print $2; exit }
kvr=$(uci -q get easymesh.config.kvr) ')
iapp=$(uci -q get easymesh.config.iapp)
brlan=$(uci -q get network.@device[0].name) # Check if a matching section was found
role=$(uci -q get easymesh.config.role) if [ -n "$matched_section" ]; then
backbone=$(uci get easymesh.@easymesh[0].backbone) echo "The matching wireless interface section is: $matched_section - deleting it"
apname=$(uci get easymesh.@easymesh[0].apname) uci delete wireless.$matched_section
appass=$(uci get easymesh.@easymesh[0].appass) fi
# On a single line, print all of the variables to a file
printf "enable: $enable\nmesh_bat0: $mesh_bat0\nap_mode: $ap_mode\nlan: $lan\nipaddr: $ipaddr\nnetmask: $netmask\ngateway: $gateway\ndns: $dns\nap_ipaddr: $ap_ipaddr\nap_ipaddr1: $ap_ipaddr1\napRadio: $apRadio\nkvr: $kvr\niapp: $iapp\nbrlan: $brlan\nrole: $role\nbackbone: $backbone\napname: $apname\nappass: $appass" > /root/.easymesh
}
stop_node() { # Find and delete existing mesh network interfaces with the specified MESH_NAME on the current radio
cp /etc/config/wireless.meshbak /etc/config/wireless EXISTING_MESH=$(uci show wireless | grep -w "mesh_id='$MESH_NAME'" | grep ".$CURRENT_RADIO." | cut -d'.' -f1-2)
cp /etc/config/network.meshbak /etc/config/network for section in $EXISTING_MESH; do
cp /etc/config/dhcp.meshbak /etc/config/dhcp uci delete $section
echo "The matching wireless interface section is: $section - deleting it"
done
/etc/init.d/network restart # Commit changes to wireless
/etc/init.d/system reload uci commit
done
} }
# ap_mode_stop() { create_bat0() {
# ap_ipaddr=$(uci -q get network.lan.ipaddr) # Check if bat0 already exists
# ap_ipaddr1=$(sed -n '1p' /etc/easymesh 2>/dev/null) if uci -q get network.bat0 >/dev/null; then
# dns1=$(sed -n '2p' /etc/easymesh 2>/dev/null) echo "bat0 interface already exists."
# if [ "$ap_ipaddr" = "$ap_ipaddr1" ]; then else
# uci -q delete network.lan.gateway uci set network.bat0=interface
# uci -q del_list network.lan.dns=$dns1 uci set network.bat0.proto='batadv'
# uci commit network uci set network.bat0.routing_algo='BATMAN_IV'
uci set network.bat0.aggregated_ogms='1'
uci set network.bat0.ap_isolation='0'
uci set network.bat0.bonding='1'
uci set network.bat0.bridge_loop_avoidance='1'
uci set network.bat0.distributed_arp_table='1'
uci set network.bat0.fragmentation='1'
uci set network.bat0.hop_penalty='30'
uci set network.bat0.isolation_mark='0x00000000/0x00000000'
uci set network.bat0.log_level='0'
uci set network.bat0.multicast_fanout='16'
uci set network.bat0.multicast_mode='1'
uci set network.bat0.network_coding='0'
uci set network.bat0.orig_interval='1000'
echo "bat0 interface has been created."
# Set the bat0 role
BAT_ROLE=$(uci -q get easymesh.config.role)
if [ "${BAT_ROLE}" == "server" ]; then
uci set network.bat0.gw_mode='server'
elif [ "${BAT_ROLE}" == "client" ]; then
uci set network.bat0.gw_mode='client'
else
uci set network.bat0.gw_mode='off'
fi
# echo "" >/etc/easymesh # Get the current list of ports for the 'br-lan' interface
LAN_PORTS=$(uci -q get network.@device[0].ports)
# Check if 'bat0' is already in the list of ports for 'br-lan'
if echo "$LAN_PORTS" | grep -q 'bat0'; then
uci del_list network.@device[0].ports='bat0'
echo "Old bat0 interface deleted from lan network."
fi
# uci -q delete dhcp.lan.dynamicdhcp # Add 'bat0' to the list of ports for 'br-lan'
# uci -q delete dhcp.lan.ignore uci add_list network.@device[0].ports='bat0'
# uci commit dhcp echo "bat0 has been added to the lan network."
# /etc/init.d/odhcpd enable && /etc/init.d/odhcpd start
# /etc/init.d/firewall enable && /etc/init.d/firewall start >/dev/null 2>&1
# fi
# }
add_wifi_mesh() {
mesh_nwi_mesh=$(uci -q get network.nwi_mesh_${apall})
mesh_apRadio=$(uci -q get wireless.mesh_${apall}.device)
mesh_mesh=$(uci -q get wireless.mesh_${apall})
mesh_id=$(uci -q get easymesh.config.mesh_id)
mobility_domain=$(uci -q get easymesh.config.mobility_domain)
key=$(uci -q get easymesh.config.key)
encryption=$(uci -q get easymesh.config.encryption)
# Print out all the variables
printf "mesh_nwi_mesh: $mesh_nwi_mesh\nmesh_apRadio: $mesh_apRadio\nmesh_mesh: $mesh_mesh\nmesh_id: $mesh_id\nmobility_domain: $mobility_domain\nkey: $key\nencryption: $encryption" > /root/.newmesh
if [ "$mesh_nwi_mesh" != "interface" ]; then
uci set network.nwi_mesh_$apall=interface
uci set network.nwi_mesh_$apall.proto='batadv_hardif'
uci set network.nwi_mesh_$apall.master='bat0'
uci set network.nwi_mesh_$apall.mtu='1536'
# adding batman to the 'lan' zone in fw
uci del_list firewall.lan.network="bat0"
uci add_list firewall.lan.network='bat0'
uci del_list firewall.lan.network="nwi_mesh_$apall"
uci add_list firewall.lan.network="nwi_mesh_$apall"
uci commit network uci commit network
uci commit firewall
/etc/init.d/firewall restart
fi fi
}
if [ "$mesh_mesh" != "wifi-iface" ]; then find_radios() {
uci set wireless.mesh_$apall=wifi-iface # Get the radio to be used for mesh from the config
uci set wireless.mesh_$apall.device=$apall AP_RADIO=$(uci -q get easymesh.config.apRadio)
uci set wireless.mesh_$apall.ifname=mesh_${apall}
uci set wireless.mesh_$apall.network=nwi_mesh_${apall}
uci set wireless.mesh_$apall.mode='mesh'
uci set wireless.mesh_$apall.mesh_id=$mesh_id
uci set wireless.mesh_$apall.mesh_fwding='1'
uci set wireless.mesh_$apall.mesh_ttl='1'
uci set wireless.mesh_$apall.mcast_rate='24000'
uci set wireless.mesh_$apall.disabled='0'
uci commit wireless
fi
if [ "$mesh_mesh" = "wifi-iface" ]; then # Check if AP_RADIO is empty, if so exit
if [ "$mesh_apRadio" != "$apall" ]; then if [ -z "$AP_RADIO" ]; then
uci set wireless.mesh_$apall.device=$apall echo "No radio specified in the config, exiting."
uci commit wireless exit 1
fi
fi fi
if [ "$encryption" != 1 ]; then # Check to make sure if "all" is passed or a single radio
apnum="${mesh_apRadio#radio}" if [ "$AP_RADIO" == "all" ]; then
apnum=$((apnum + 1)) # Get the list of wifi devices
found=0 WIFI_RADIOS=$(uci -X show wireless | awk -F'[.=]' '/wifi-device/ {print $2}' | tr '\n' ' ')
# Check all existing wifinetX and remove if SSID matches with $mesh_id and mode is 'ap'
while uci get wireless.wifinet$apnum > /dev/null 2>&1; do
existing_ssid=$(uci get wireless.wifinet$apnum.ssid 2> /dev/null)
existing_mode=$(uci get wireless.wifinet$apnum.mode 2> /dev/null)
if [ "$existing_ssid" = "$mesh_id" ] && [ "$existing_mode" = "ap" ]; then
if [ $found -eq 0 ]; then
found=1
else else
uci delete wireless.wifinet$apnum # Set the radio to the one passed in the config
WIFI_RADIOS=$AP_RADIO
fi fi
fi }
apnum=$((apnum + 1))
process_radios() {
# Check if WIFI_RADIOS contains more than one radio
if [[ $WIFI_RADIOS =~ [[:space:]] ]]; then
# Loop through all the radios and set them up
for radio in $WIFI_RADIOS; do
echo "Multiple Radio Setup, Current Radio: $radio"
setup_mesh_radio $radio
done done
else
echo "Calling Single Radio Setup: $WIFI_RADIOS"
setup_mesh_radio $WIFI_RADIOS
fi
}
# This is called from the process_radios function and is passed the radio to be used for mesh
setup_mesh_radio() {
CURRENT_RADIO=$1
echo "Setting up radio: $CURRENT_RADIO"
# Get the mesh name from UCI config
MESH_NAME=$(uci -q get easymesh.config.mesh_id)
# Commit changes to wireless
uci commit wireless uci commit wireless
if [ $found -eq 0 ]; then uci set network.nwi_mesh_$CURRENT_RADIO=interface
uci set wireless.mesh_$apall.encryption='none' uci set network.nwi_mesh_$CURRENT_RADIO.proto='batadv_hardif'
# uci set wireless.mesh_$apall.disabled='0' uci set network.nwi_mesh_$CURRENT_RADIO.master='bat0'
uci set wireless.wifinet$apnum=wifi-iface uci set network.nwi_mesh_$CURRENT_RADIO.device='bat0'
uci set wireless.wifinet$apnum.device=$mesh_apRadio uci set network.nwi_mesh_$CURRENT_RADIO.mtu='1536'
uci set wireless.wifinet$apnum.mode='ap'
uci set wireless.wifinet$apnum.ssid=$mesh_id uci set wireless.mesh_$CURRENT_RADIO=wifi-iface
uci set wireless.wifinet$apnum.encryption='none' uci set wireless.mesh_$CURRENT_RADIO.device=$CURRENT_RADIO
uci set wireless.wifinet$apnum.key=$key uci set wireless.mesh_$CURRENT_RADIO.ifname=mesh_$CURRENT_RADIO
uci set wireless.wifinet$apnum.ieee80211r='1' uci set wireless.mesh_$CURRENT_RADIO.network=nwi_mesh_$CURRENT_RADIO
uci set wireless.wifinet$apnum.mobility_domain=$mobility_domain uci set wireless.mesh_$CURRENT_RADIO.mode='mesh'
uci set wireless.wifinet$apnum.ft_over_ds='0' uci set wireless.mesh_$CURRENT_RADIO.mesh_id=$MESH_NAME
uci set wireless.wifinet$apnum.ft_psk_generate_local='1' uci set wireless.mesh_$CURRENT_RADIO.mesh_fwding='0'
uci set wireless.wifinet$apnum.network='lan' uci set wireless.mesh_$CURRENT_RADIO.mesh_rssi_threshold='0'
uci set wireless.wifinet$apnum.disabled=0 uci set wireless.mesh_$CURRENT_RADIO.mesh_ttl='1'
uci set wireless.mesh_$CURRENT_RADIO.mcast_rate='24000'
uci set wireless.mesh_$CURRENT_RADIO.disabled='0'
uci commit wireless uci commit wireless
# Extact the radio number from the radio name
RADIO_NUM="${CURRENT_RADIO#radio}"
# Get the mobility domain from the config
MOBILITY_DOMAIN=$(uci -q get easymesh.config.mobility_domain)
# If mobility domain is empty, set it to a random 4 digit hex number, then set it in the config
if [ -z "$MOBILITY_DOMAIN" ]; then
MOBILITY_DOMAIN=$(hexdump -n 2 -e '2/1 "%02x"' /dev/urandom)
uci set easymesh.config.mobility_domain=$MOBILITY_DOMAIN
uci commit easymesh
fi fi
# Get the encryption enabled from the config
ENCRYPTION_ENABLED=$(uci -q get easymesh.config.encryption)
# Setup the interface for the mesh network
uci set wireless.mesh_$CURRENT_RADIO.disabled='0'
uci set wireless.wifinet$RADIO_NUM=wifi-iface
uci set wireless.wifinet$RADIO_NUM.device=$CURRENT_RADIO
uci set wireless.wifinet$RADIO_NUM.mode='ap'
uci set wireless.wifinet$RADIO_NUM.ssid=$MESH_NAME
uci set wireless.wifinet$RADIO_NUM.ieee80211r='1'
uci set wireless.wifinet$RADIO_NUM.mobility_domain=$MOBILITY_DOMAIN
uci set wireless.wifinet$RADIO_NUM.ft_over_ds='0'
uci set wireless.wifinet$RADIO_NUM.ft_psk_generate_local='0'
uci set wireless.wifinet$RADIO_NUM.network='lan'
uci set wireless.wifinet$RADIO_NUM.disabled=0
# Get the encryption key from the config
NETWORK_KEY=$(uci -q get easymesh.config.key)
# Check if encryption is enabled and if the key is not empty
if [ "$ENCRYPTION_ENABLED" = 1 ] && [ ! -z $NETWORK_KEY ]; then
uci set wireless.mesh_$CURRENT_RADIO.encryption='sae'
uci set wireless.mesh_$CURRENT_RADIO.key=$NETWORK_KEY
uci set wireless.wifinet$RADIO_NUM.encryption='sae-mixed'
uci set wireless.wifinet$RADIO_NUM.key=$NETWORK_KEY
else else
apnum="${mesh_apRadio#radio}" uci set wireless.mesh_$CURRENT_RADIO.encryption='none'
apnum=$((apnum + 1)) uci set wireless.wifinet$RADIO_NUM.encryption='none'
found=0 [ -z $NETWORK_KEY ] && echo "Encryption key is empty, so encryption was disabled."
# Check all existing wifinetX and remove if SSID matches with $mesh_id and mode is 'ap'
while uci get wireless.wifinet$apnum > /dev/null 2>&1; do
existing_ssid=$(uci get wireless.wifinet$apnum.ssid 2> /dev/null)
existing_mode=$(uci get wireless.wifinet$apnum.mode 2> /dev/null)
if [ "$existing_ssid" = "$mesh_id" ] && [ "$existing_mode" = "ap" ]; then
if [ $found -eq 0 ]; then
found=1
else
uci delete wireless.wifinet$apnum
fi fi
fi
apnum=$((apnum + 1))
done
uci commit wireless
if [ $found -eq 0 ]; then # Commit our block of changes to wireless
uci set wireless.mesh_$apall.encryption='sae'
# uci set wireless.mesh_$apall.disabled='0'
uci set wireless.mesh_$apall.key=$key
uci set wireless.wifinet$apnum=wifi-iface
uci set wireless.wifinet$apnum.device=$apall
uci set wireless.wifinet$apnum.mode='ap'
uci set wireless.wifinet$apnum.ssid=$mesh_id
uci set wireless.wifinet$apnum.encryption='sae-mixed'
uci set wireless.wifinet$apnum.key=$key
uci set wireless.wifinet$apnum.ieee80211r='1'
uci set wireless.wifinet$apnum.mobility_domain=$mobility_domain
uci set wireless.wifinet$apnum.ft_over_ds='0'
uci set wireless.wifinet$apnum.ft_psk_generate_local='1'
uci set wireless.wifinet$apnum.network='lan'
uci set wireless.wifinet$apnum.disabled=0
uci commit wireless uci commit wireless
fi
fi
}
add_kvr() { # Check if we need to setup kvr
kvr=$(uci -q get easymesh.config.kvr) ENABLE_KVR=$(uci -q get easymesh.config.kvr)
mobility_domain=$(uci -q get easymesh.config.mobility_domain)
iapp=$(uci -q get easymesh.config.iapp) if [ "$ENABLE_KVR" = 1 ]; then
for apall in $(uci -X show wireless | grep wifi-device | awk -F'[.=]' '{print $2}'); do uci set wireless.wifinet$RADIO_NUM.ieee80211k='1'
if [ "$kvr" = 1 ]; then uci set wireless.wifinet$RADIO_NUM.rrm_neighbor_report='1'
uci set wireless.default_$apall.ieee80211k='1' uci set wireless.wifinet$RADIO_NUM.rrm_beacon_report='1'
uci set wireless.default_$apall.rrm_neighbor_report='1' uci set wireless.wifinet$RADIO_NUM.ieee80211v='1'
uci set wireless.default_$apall.rrm_beacon_report='1' uci set wireless.wifinet$RADIO_NUM.bss_transition='1'
uci set wireless.default_$apall.ieee80211v='1' uci set wireless.wifinet$RADIO_NUM.ieee80211r='1'
uci set wireless.default_$apall.bss_transition='1' uci set wireless.wifinet$RADIO_NUM.ft_over_ds='1'
uci set wireless.default_$apall.ieee80211r='1' uci set wireless.wifinet$RADIO_NUM.ft_psk_generate_local='1'
uci set wireless.default_$apall.encryption='sae'
uci set wireless.default_$apall.mobility_domain=$mobility_domain
uci set wireless.default_$apall.ft_over_ds='1'
uci set wireless.default_$apall.ft_psk_generate_local='1'
uci commit wireless uci commit wireless
else else
uci -q delete wireless.default_$apall.ieee80211k uci -q delete wireless.wifinet$RADIO_NUM.ieee80211k
uci -q delete wireless.default_$apall.ieee80211v uci -q delete wireless.wifinet$RADIO_NUM.ieee80211v
uci -q delete wireless.default_$apall.ieee80211r uci -q delete wireless.wifinet$RADIO_NUM.ieee80211r
uci commit wireless uci commit wireless
fi fi
if [ "$iapp" = 1 ]; then
uci set wireless.default_$apall.iapp_interface='br-lan' # Check if we need to setup iapp
ENABLE_IAPP=$(uci -q get easymesh.config.iapp)
if [ "$ENABLE_IAPP" = 1 ]; then
# Get the LAN interface name
LAN_NAME=$(uci -q get network.@device[0].name)
# If LAN_NAME is not empty, set the iapp interface
if [ ! -z "$LAN_NAME" ]; then
uci set wireless.wifinet$RADIO_NUM.iapp_interface="$LAN_NAME"
uci commit wireless uci commit wireless
fi
else else
uci -q delete wireless.default_$apall.iapp_interface uci -q delete wireless.wifinet$RADIO_NUM.iapp_interface
uci commit wireless uci commit wireless
fi fi
done
}
add_dawn() {
kvr=$(uci -q get easymesh.config.kvr)
rssi_val=$(uci -q get easymesh.config.rssi_val)
low_rssi_val=$(uci -q get easymesh.config.low_rssi_val)
if [ "$kvr" = 1 ]; then # If KVR is enabled, setup DAWN
uci set dawn.@metric[0].rssi_val=$rssi_val if [ "$ENABLE_KVR" = 1 ]; then
uci set dawn.@metric[0].low_rssi_val=$low_rssi_val RSSI=$(uci -q get easymesh.config.rssi_val)
LOW_RSSI=$(uci -q get easymesh.config.low_rssi_val)
uci set dawn.@metric[0].rssi_val=$RSSI
uci set dawn.@metric[0].low_rssi_val=$LOW_RSSI
uci commit dawn uci commit dawn
/etc/init.d/dawn enable && /etc/init.d/dawn start /etc/init.d/dawn enable && /etc/init.d/dawn start
else else
/etc/init.d/dawn stop && /etc/init.d/dawn disable /etc/init.d/dawn stop && /etc/init.d/dawn disable
fi fi
# Commit our block of changes to the configs
uci commit
} }
set_easymesh() { restart_and_reload() {
if [ "$enable" = 1 ]; then # Enable all the radios and commit the changes at once
if [ "$mesh_bat0" != "interface" ]; then for radio in $(uci -X show wireless | grep wifi-device | awk -F'[.=]' '{print $2}'); do
uci set network.bat0=interface echo "Enabling $radio..."
uci set network.bat0.proto='batadv' uci set wireless.$radio.disabled=0
uci set network.bat0.routing_algo='BATMAN_IV' done
uci set network.bat0.aggregated_ogms='1' uci commit
uci set network.bat0.ap_isolation='0' echo "All radios enabled."
uci set network.bat0.bonding='1'
uci set network.bat0.bridge_loop_avoidance='1'
uci set network.bat0.distributed_arp_table='1'
uci set network.bat0.fragmentation='1'
# uci set network.bat0.gw_bandwidth='10000/2000'
# uci set network.bat0.gw_sel_class='20'
uci set network.bat0.hop_penalty='30'
uci set network.bat0.isolation_mark='0x00000000/0x00000000'
uci set network.bat0.log_level='0'
uci set network.bat0.multicast_fanout='16'
uci set network.bat0.multicast_mode='1'
uci set network.bat0.network_coding='0'
uci set network.bat0.orig_interval='1000'
if [ "$role" = "server" ]; then # Apply the wireless configuration changes
uci set network.bat0.gw_mode='server' wifi reload
elif [ "$role" = "client" ]; then echo "Wireless interfaces reloaded."
uci set network.bat0.gw_mode='client'
else # Apply network configuration changes
uci set network.bat0.gw_mode='off' # Note: Only use reload_config if you have made changes to the network config
# and need to apply them. Otherwise, you can skip this step.
reload_config
echo "Network configuration reloaded."
/etc/init.d/network reload
/etc/init.d/network restart
}
disable_easymesh() {
# Delete the bat0 interface
if [ "$(uci -q get network.bat0)" = "interface" ]; then
uci del network.bat0
fi fi
if [ "$brlan" = "br-lan" ]; then # Get the current list of ports for the 'br-lan' interface
uci add_list network.@device[0].ports='bat0' LAN_PORTS=$(uci -q get network.@device[0].ports)
else # Check if 'bat0' is already in the list of ports for 'br-lan'
uci set network.lan.ifname="${lan} bat0" if echo "$LAN_PORTS" | grep -q 'bat0'; then
uci del_list network.@device[0].ports='bat0'
echo "Old bat0 interface deleted from lan network."
fi fi
# Get the list of wifi devices
WIFI_RADIOS=$(uci -X show wireless | awk -F'[.=]' '/wifi-device/ {print $2}' | tr '\n' ' ')
# Loop through all the radios and delete the network interfaces
for CURRENT_RADIO in $WIFI_RADIOS; do
echo "Handling removal of mesh networks for: $CURRENT_RADIO"
if [ "$(uci -q get network.nwi_mesh_$CURRENT_RADIO)" = "interface" ]; then
uci del network.nwi_mesh_$CURRENT_RADIO
uci commit network uci commit network
fi # end [ "$mesh_bat0" != "interface" ]
# When this is called, the add_wifi_mesh function does not load variables properly
if [ "$apRadio" = "all" ]; then
for apall in $(uci -X show wireless | grep wifi-device | awk -F'[.=]' '{print $2}'); do
add_wifi_mesh
add_kvr
add_dawn
done
else
apall=$apRadio
add_wifi_mesh
add_kvr
add_dawn
fi fi
done
uci commit
if [ "$ap_mode" = 1 ]; then reload_config
# Backup Configurations if your scared echo "Network configuration reloaded."
/etc/init.d/network reload
/etc/init.d/network restart
}
set_apmode() {
AP_MODE=$(uci -q get easymesh.config.ap_mode)
if [ "$AP_MODE" = 1 ]; then
# Set a flag to indicate that we are in AP mode
# When we go to disable easymesh, we will check this flag and if it was set we restore settings
uci set easymesh.config.ap_mode_enabled=1
# Backup our configs
rm /etc/config/*.meshbak
cp /etc/config/wireless /etc/config/wireless.meshbak cp /etc/config/wireless /etc/config/wireless.meshbak
cp /etc/config/network /etc/config/network.meshbak cp /etc/config/network /etc/config/network.meshbak
cp /etc/config/dhcp /etc/config/dhcp.meshbak cp /etc/config/dhcp /etc/config/dhcp.meshbak
# Generate a random IP in the same subnet for fun # Generate a random IP in the same subnet for fun
ip_base=$(echo "$dns" | cut -d'.' -f1-3) # Get the first three octets of the DNS IP # ip_base=$(echo "$dns" | cut -d'.' -f1-3) # Get the first three octets of the DNS IP
last_octet=$((RANDOM % 254 + 1)) # Generate a random value for the last octet between 1 and 254 # last_octet=$((RANDOM % 254 + 1)) # Generate a random value for the last octet between 1 and 254
nodeip="${ip_base}.${last_octet}" # Concatenate the base IP with the new last octet # nodeip="${ip_base}.${last_octet}" # Concatenate the base IP with the new last octet
# random static IP just in case # Disabling and stopping services not needed
#uci set network.lan.ipaddr=$nodeip # Set the randomly chosen IP for service in firewall dnsmasq odhcpd; do
if /etc/init.d/$service enabled; then
# Do not need these running echo "Disabling and stopping $service..."
for i in firewall dnsmasq odhcpd; do /etc/init.d/$service disable
if /etc/init.d/"$i" enabled; then /etc/init.d/$service stop
/etc/init.d/"$i" disable else
/etc/init.d/"$i" stop echo "$service is not enabled, skipping..."
fi fi
done done
# Set LAN interface to DHCP client # Set LAN interface to DHCP client
uci del network.lan.ipaddr
uci del network.lan.netmask
uci set network.lan.proto='dhcp' uci set network.lan.proto='dhcp'
uci delete network.wan uci del network.wan
uci delete network.wan6 uci del network.wan6
uci delete network.lan.ipaddr
uci delete network.lan.netmask
# Set netmask and gateway (assuming $netmask and $dns didn't break more stuff) # Fix firewall to be disabled
# Comment out because we want to pull this from dhcp uci del firewall.lan.network
# uci set network.lan.netmask=$netmask uci del firewall.wan.network
# uci set network.lan.gateway=$dns
uci set system.@system[0].hostname=$gateway
# Configure LAN bridge and add ethernet interfaces to the bridge
uci del network.@device[0].ports
uci add_list network.@device[0].ports='bat0'
uci add_list network.@device[0].ports='eth0'
uci add_list network.@device[0].ports='lan1'
uci add_list network.@device[0].ports='lan2'
uci add_list network.@device[0].ports='wan'
uci set network.lan.type='bridge'
# Make sure the Wi-Fi is part of the lan
uci set wireless.wifinet1.network='lan nwi_mesh_${apall} wwan'
# Commit all changes
uci commit
# Restart the network to apply changes
/etc/init.d/network restart
/etc/init.d/system reload
# restart wifi # Fix dhcp to be disabled
wifi reload uci set dhcp.lan.ignore='1'
wifi up uci del dhcp.wan
# Removing firewall configuration # Fix this for proper variable name
mv /etc/config/firewall /etc/config/firewall.unused HOSTNAME=$(uci -q get easymesh.config.gateway)
# Set netmask and gateway (assuming $netmask and $dns didn't break more stuff)
uci set system.@system[0].hostname=$HOSTNAME
else # Retrieve the list of ports for network.@device[0]
stop_node LAN_PORTS=$(uci get network.@device[0].ports)
fi # end if [ "$ap_mode" = 1 ]
else
# Disable the ap_mode settings
stop_node
if [ "$mesh_bat0" = "interface" ]; then # Check if 'wan' is already in the list of ports
uci -q delete network.bat0 if echo "$LAN_PORTS" | grep -q -w 'wan'; then
if [ "$brlan" = "br-lan" ]; then echo "'wan' is already in the list of ports for lan."
uci -q del_list network.@device[0].ports='bat0'
else else
sed -i 's/ bat0//' /etc/config/network echo "'wan' is not in the list. Adding it to lan ports..."
fi uci add_list network.@device[0].ports='wan'
uci commit network
fi fi
for apall in $(uci -X show wireless | grep wifi-device | awk -F'[.=]' '{print $2}'); do # Find all radios we are using in our setup
mesh_nwi_mesh=$(uci -q get network.nwi_mesh_${apall}) find_radios
mesh_mesh=$(uci -q get wireless.mesh_${apall})
#### COME BACK TO THIS ####
# # Check if WIFI_RADIOS contains more than one radio
# if [[ $WIFI_RADIOS =~ [[:space:]] ]]; then
# # Loop through all the radios add nwimesh to the that network
# for cur_radio in $WIFI_RADIOS; do
# echo "Multiple Radio Setup, Current Radio: $radio"
# # Extact the radio number from the radio name
# wifi_num="${cur_radio#radio}"
# uci set wireless.wifinet${wifi_num}.network="lan nwi_mesh_${cur_radio}"
# done
# else
# echo "Calling Single Radio Setup: $WIFI_RADIOS"
# # Extact the radio number from the radio name
# wifi_num="${WIFI_RADIOS#radio}"
# uci set wireless.wifinet${wifi_num}.network="lan nwi_mesh_${WIFI_RADIOS}"
# fi
if [ "$mesh_nwi_mesh" = "interface" ]; then uci commit
uci -q delete network.nwi_mesh_$apall # Tell openwrt to reload the configs
uci commit network reload_config
fi else
# Set a flag to indicate that we are in AP mode
uci set easymesh.config.ap_mode_enabled=0
if [ "$mesh_mesh" = "wifi-iface" ]; then # Restore our configs
uci -q delete wireless.mesh_$apall [ -f /etc/config/wireless.meshbak ] && {
uci commit wireless mv /etc/config/wireless /etc/config/wireless.dumbap
cp /etc/config/wireless.meshbak /etc/config/wireless
}
[ -f /etc/config/network.meshbak ] && {
mv /etc/config/network /etc/config/network.dumbap
cp /etc/config/network.meshbak /etc/config/network
}
[ -f /etc/config/dhcp.meshbak ] && {
mv /etc/config/dhcp /etc/config/dhcp.dumbap
cp /etc/config/dhcp.meshbak /etc/config/dhcp
}
# Enable and start services not needed
for service in firewall dnsmasq odhcpd; do
if /etc/init.d/$service disabled; then
echo "Enabling and starting $service..."
/etc/init.d/$service enable
/etc/init.d/$service start
else
echo "$service is not disabled, skipping..."
fi fi
done done
reload_config
/etc/init.d/network reload
fi fi
}
/etc/init.d/network restart # ENABLED=$(uci -q get easymesh.config.enabled)
} # end set_easymesh() # if [ "$ENABLED" = 1 ]; then
# clear_old_networks
# create_bat0
# find_radios
# process_radios
# restart_and_reload
# else
# clear_old_networks
# disable_easymesh
# fi
# Call our functions set above # We accept the parameters: start, stop and apmode
load_easymesh_config # start: Enables easymesh
set_easymesh # stop: Disables easymesh
# apmode: Sets the device to AP mode
if [ "$1" = "start" ]; then
clear_old_networks
create_bat0
find_radios
process_radios
restart_and_reload
elif [ "$1" = "stop" ]; then
clear_old_networks
disable_easymesh
# elif [ "$1" = "apmode" ]; then
# set_apmode
else
echo "Invalid parameter passed."
fi

Loading…
Cancel
Save