mirror of
https://github.com/unraid/webgui.git
synced 2026-05-21 13:49:32 -05:00
@@ -83,7 +83,7 @@ function update_wifi(load) {
|
||||
var wifi = JSON.parse(text);
|
||||
$('#connected').html(wifi.active);
|
||||
$('#my_networks').html(wifi.saved);
|
||||
if (wifi.other.length) $('#other_networks').html(wifi.other);
|
||||
if (typeof wifi.other == 'string') $('#other_networks').html(wifi.other);
|
||||
}
|
||||
});
|
||||
timers.wifi = setTimeout(update_wifi,6000);
|
||||
|
||||
@@ -20,7 +20,13 @@ if (isset($_POST['listen'])) {
|
||||
die(exec("$docroot/webGui/scripts/show_interfaces")?:_('Any'));
|
||||
}
|
||||
|
||||
function port($eth) {
|
||||
// Helper function to normalize bitrate values
|
||||
function normalizeBitrate($rate) {
|
||||
$parts = explode(' ', $rate);
|
||||
return intval($parts[0] ?? 0).' '.($parts[1] ?? 'Bit/s');
|
||||
}
|
||||
|
||||
function isPort($eth) {
|
||||
$sys = "/sys/class/net";
|
||||
if (substr($eth,0,4) == 'wlan') return $eth;
|
||||
$x = preg_replace('/[^0-9]/', '', $eth) ?: '0';
|
||||
@@ -31,7 +37,7 @@ exec("grep -Po 'nameserver \K\S+' /etc/resolv.conf 2>/dev/null",$ns);
|
||||
$eth = $_POST['port'] ?? '';
|
||||
$vlan = $_POST['vlan'] ?? '';
|
||||
$wlan0 = $eth == 'wlan0';
|
||||
$port = port($eth).($vlan ? ".$vlan" : "");
|
||||
$port = isPort($eth).($vlan ? ".$vlan" : "");
|
||||
$v6on = trim(file_get_contents("/proc/sys/net/ipv6/conf/$port/disable_ipv6"))==='0';
|
||||
$none = _('None');
|
||||
$error = "<span class='red-text'>"._('Missing')."</span>";
|
||||
@@ -56,6 +62,8 @@ if ($wlan0) {
|
||||
$signal = explode(': ', $speed[2])[1];
|
||||
$rxrate = explode(': ', $speed[3])[1];
|
||||
$txrate = explode(': ', $speed[4])[1];
|
||||
$rxrate = normalizeBitrate($rxrate);
|
||||
$txrate = normalizeBitrate($txrate);
|
||||
$tmp = '/var/tmp/attr';
|
||||
$band = [];
|
||||
$attr = is_readable($tmp) ? (array)parse_ini_file($tmp,true) : [];
|
||||
|
||||
@@ -33,6 +33,10 @@ $_SERVER['REQUEST_URI'] = 'settings';
|
||||
require_once "$docroot/webGui/include/Translations.php";
|
||||
require_once "$docroot/webGui/include/Helpers.php";
|
||||
|
||||
function escapeSSID($text) {
|
||||
return str_replace('"', '\"', $text);
|
||||
}
|
||||
|
||||
function scanWifi($port) {
|
||||
$wlan = [];
|
||||
exec("iw ".escapeshellarg($port)." scan | grep -P '^BSS|freq:|signal:|SSID:|Authentication suites:' | sed -r ':a;N;\$!ba;s/\\n\\s+/ /g'", $scan);
|
||||
@@ -135,7 +139,7 @@ case 'list':
|
||||
case 'join':
|
||||
if (is_readable($ssl)) extract(parse_ini_file($ssl));
|
||||
$token = parse_ini_file($var)['csrf_token'];
|
||||
$ssid = str_replace('"', '\"', rawurldecode($_POST['ssid']));
|
||||
$ssid = escapeSSID(rawurldecode($_POST['ssid']));
|
||||
$drop = $_POST['task'] == 1;
|
||||
$manual = $_POST['task'] == 3;
|
||||
$user = _var($wifi[$ssid],'USERNAME') && isset($cipher, $key, $iv) ? openssl_decrypt($wifi[$ssid]['USERNAME'], $cipher, $key, 0, $iv) : _var($wifi[$ssid],'USERNAME');
|
||||
@@ -161,7 +165,7 @@ case 'join':
|
||||
$ieee1 = strpos($attr3,'IEEE') !== false;
|
||||
$ieee2 = strpos($safe,'IEEE') !== false;
|
||||
$hide0 = ($manual || !$ieee2) && !$ieee1 && $safe != 'auto' ? 'hide' : '';
|
||||
$hide1 = $safe == 'open' || $attr3 == 'open' || !$attr3 ? 'hide' : '';
|
||||
$hide1 = !$manual && ($safe == 'open' || $attr3 == 'open' || !$attr3) ? 'hide' : '';
|
||||
$hide2 = $dhcp4 == 'no' ? '' : 'hide';
|
||||
$hide3 = $dns4 == 'no' ? 'hide' : '';
|
||||
$hide4 = $dhcp6 == 'no' ? '' : 'hide';
|
||||
@@ -229,7 +233,7 @@ case 'join':
|
||||
echo "</form>";
|
||||
break;
|
||||
case 'forget':
|
||||
$ssid = str_replace('"', '\"', rawurldecode($_POST['ssid']));
|
||||
$ssid = escapeSSID(rawurldecode($_POST['ssid']));
|
||||
if ($wifi[$ssid]['GROUP'] == 'active') exec("/etc/rc.d/rc.wireless stop &>/dev/null &");
|
||||
unset($wifi[$ssid]);
|
||||
saveWifi();
|
||||
|
||||
@@ -32,9 +32,26 @@ $dockernet = "172.31";
|
||||
$t1 = '10'; // 10 sec timeout
|
||||
$t2 = '15'; // 15 sec timeout
|
||||
|
||||
function isPort($dev) {
|
||||
return file_exists("/sys/class/net/$dev");
|
||||
}
|
||||
|
||||
function carrier($dev, $loop=3) {
|
||||
if (!isPort($dev)) return false;
|
||||
try {
|
||||
for ($n=0; $n<$loop; $n++) {
|
||||
if (@file_get_contents("/sys/class/net/$dev/carrier") == 1) return true;
|
||||
if ($loop > 1) sleep(1);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function thisNet() {
|
||||
$sys = '/sys/class/net';
|
||||
$dev = file_exists("$sys/br0") ? 'br0' : (file_exists("$sys/bond0") ? 'bond0' : 'eth0');
|
||||
$dev = isPort('br0') ? 'br0' : (isPort('bond0') ? 'bond0' : 'eth0');
|
||||
if (!carrier($dev) && carrier('wlan0', 1)) $dev = 'wlan0';
|
||||
$ip4 = exec("ip -4 -br addr show dev $dev | awk '{print \$3;exit}'");
|
||||
$net = exec("ip -4 route show $ip4 dev $dev | awk '{print \$1;exit}'");
|
||||
$gw = exec("ip -4 route show default dev $dev | awk '{print \$3;exit}'");
|
||||
@@ -131,10 +148,12 @@ function addDocker($vtun) {
|
||||
$error = dockerNet($vtun);
|
||||
}
|
||||
if (!$error && !isNet($network)) {
|
||||
[$device,$thisnet,$gateway] = thisNet();
|
||||
exec("ip -4 rule add from $network table $index");
|
||||
exec("ip -4 route add unreachable default table $index");
|
||||
exec("ip -4 route add $thisnet via $gateway dev $device table $index");
|
||||
[$device, $thisnet, $gateway] = thisNet();
|
||||
if (!empty($device) && !empty($thisnet) && !empty($gateway)) {
|
||||
exec("ip -4 rule add from $network table $index");
|
||||
exec("ip -4 route add unreachable default table $index");
|
||||
exec("ip -4 route add $thisnet via $gateway dev $device table $index");
|
||||
}
|
||||
}
|
||||
return $error;
|
||||
}
|
||||
@@ -260,12 +279,14 @@ function parseInput($vtun, &$input, &$x) {
|
||||
// add WG routing for docker containers. Only IPv4 supported
|
||||
[$index, $network] = newNet($vtun);
|
||||
[$device, $thisnet, $gateway] = thisNet();
|
||||
$conf[] = "PostUp=ip -4 route flush table $index";
|
||||
$conf[] = "PostUp=ip -4 route add default via $tunip dev $vtun table $index";
|
||||
$conf[] = "PostUp=ip -4 route add $thisnet via $gateway dev $device table $index";
|
||||
$conf[] = "PostDown=ip -4 route flush table $index";
|
||||
$conf[] = "PostDown=ip -4 route add unreachable default table $index";
|
||||
$conf[] = "PostDown=ip -4 route add $thisnet via $gateway dev $device table $index";
|
||||
if (!empty($device) && !empty($thisnet) && !empty($gateway)) {
|
||||
$conf[] = "PostUp=ip -4 route flush table $index";
|
||||
$conf[] = "PostUp=ip -4 route add default via $tunip dev $vtun table $index";
|
||||
$conf[] = "PostUp=ip -4 route add $thisnet via $gateway dev $device table $index";
|
||||
$conf[] = "PostDown=ip -4 route flush table $index";
|
||||
$conf[] = "PostDown=ip -4 route add unreachable default table $index";
|
||||
$conf[] = "PostDown=ip -4 route add $thisnet via $gateway dev $device table $index";
|
||||
}
|
||||
}
|
||||
$conf[] = "\n[Peer]";
|
||||
// add peers, this is only used for peer sections
|
||||
@@ -307,9 +328,9 @@ function parseInput($vtun, &$input, &$x) {
|
||||
$protocol = $value;
|
||||
$user[] = "$id:0=\"$value\"";
|
||||
switch ($protocol) {
|
||||
case '46': $var['default'] = "AllowedIPs=$default4, $default6"; break;
|
||||
case '6' : $var['default'] = "AllowedIPs=$default6"; break;
|
||||
default : $var['default'] = "AllowedIPs=$default4"; break;
|
||||
case '46': $var['default'] = "AllowedIPs=$default4, $default6"; break;
|
||||
case '6' : $var['default'] = "AllowedIPs=$default6"; break;
|
||||
default : $var['default'] = "AllowedIPs=$default4"; break;
|
||||
}
|
||||
break;
|
||||
case 'TYPE':
|
||||
|
||||
+73
-61
@@ -35,77 +35,87 @@ TMP=/var/tmp/network.tmp
|
||||
# run & log functions
|
||||
. /etc/rc.d/rc.runlog
|
||||
|
||||
# wait for interface to go up
|
||||
carrier(){
|
||||
cat $SYSTEM/$1/carrier 2>/dev/null
|
||||
local n e
|
||||
[[ -e $SYSTEM/$1 ]] && e=${2:-10} || return 1
|
||||
for ((n=0; n<$e; n++)); do
|
||||
[[ $(cat $SYSTEM/$1/carrier 2>/dev/null) == 1 ]] && return 0
|
||||
[[ $e -gt 1 ]] && sleep 1
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# determine active port name
|
||||
[[ -e $SYSTEM/bond0 ]] && PORT=bond0 || PORT=eth0
|
||||
[[ -e $SYSTEM/br0 ]] && PORT=br0
|
||||
[[ $(carrier $PORT) != 1 && -e $SYSTEM/wlan0 && $(carrier wlan0) == 1 ]] && PORT=wlan0
|
||||
# initialize docker settings
|
||||
docker_read_options(){
|
||||
# determine active port name
|
||||
[[ -e $SYSTEM/bond0 ]] && PORT=bond0 || PORT=eth0
|
||||
[[ -e $SYSTEM/br0 ]] && PORT=br0
|
||||
[[ ! $(carrier $PORT) && $(carrier wlan0 1) ]] && PORT=wlan0
|
||||
|
||||
# Set defaults used by the docker daemon
|
||||
if [[ -f $DOCKER_CFG ]]; then
|
||||
for NIC in $NICS; do
|
||||
if [[ ${NIC:0:3} == eth ]]; then
|
||||
if [[ -e $SYSTEM/${NIC/eth/br} ]]; then
|
||||
NIC=${NIC/eth/br}
|
||||
elif [[ -e $SYSTEM/${NIC/eth/bond} ]]; then
|
||||
NIC=${NIC/eth/bond}
|
||||
# Set defaults used by the docker daemon
|
||||
if [[ -f $DOCKER_CFG ]]; then
|
||||
for NIC in $NICS; do
|
||||
if [[ ${NIC:0:3} == eth ]]; then
|
||||
if [[ -e $SYSTEM/${NIC/eth/br} ]]; then
|
||||
NIC=${NIC/eth/br}
|
||||
elif [[ -e $SYSTEM/${NIC/eth/bond} ]]; then
|
||||
NIC=${NIC/eth/bond}
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
CFG=($(grep -Pom2 "_SUBNET_|_${NIC^^}(_[0-9]+)?=" $DOCKER_CFG))
|
||||
if [[ ${CFG[0]} == _SUBNET_ && -z ${CFG[1]} ]]; then
|
||||
# interface has changed, update configuration
|
||||
X=${NIC//[^0-9]/}
|
||||
sed -ri "s/_(BR|BOND|ETH|WLAN)$X(_[0-9]+)?=/_${NIC^^}\2=/; s/(br|bond|eth|wlan)$X(\.[0-9]+)? /$NIC\2 /g" $DOCKER_CFG
|
||||
fi
|
||||
done
|
||||
# Read (updated) Unraid docker configuration file
|
||||
. $DOCKER_CFG
|
||||
fi
|
||||
|
||||
# set storage driver to overlay2 if config value is found, otherwise fall back to native FS driver
|
||||
if [[ $(awk -F'"' '/^DOCKER_BACKINGFS=/{print $2}' $DOCKER_CFG 2>/dev/null) == overlay2 ]]; then
|
||||
DOCKER_OPTS="$DOCKER_OPTS --storage-driver=overlay2"
|
||||
else
|
||||
BACKINGFS=$(findmnt --output FSTYPE --noheadings $DOCKER_ROOT)
|
||||
if [[ $BACKINGFS == btrfs ]]; then
|
||||
DOCKER_OPTS="$DOCKER_OPTS --storage-driver=btrfs"
|
||||
elif [[ $BACKINGFS == xfs ]]; then
|
||||
DOCKER_OPTS="$DOCKER_OPTS --storage-driver=overlay2"
|
||||
elif [[ $BACKINGFS == zfs ]]; then
|
||||
DOCKER_OPTS="$DOCKER_OPTS --storage-driver=zfs"
|
||||
CFG=($(grep -Pom2 "_SUBNET_|_${NIC^^}(_[0-9]+)?=" $DOCKER_CFG))
|
||||
if [[ ${CFG[0]} == _SUBNET_ && -z ${CFG[1]} ]]; then
|
||||
# interface has changed, update configuration
|
||||
X=${NIC//[^0-9]/}
|
||||
sed -ri "s/_(BR|BOND|ETH|WLAN)$X(_[0-9]+)?=/_${NIC^^}\2=/; s/(br|bond|eth|wlan)$X(\.[0-9]+)? /$NIC\2 /g" $DOCKER_CFG
|
||||
fi
|
||||
done
|
||||
# Read (updated) Unraid docker configuration file
|
||||
. $DOCKER_CFG
|
||||
fi
|
||||
fi
|
||||
|
||||
# Less verbose logging by default
|
||||
DOCKER_OPTS="--log-level=fatal $DOCKER_OPTS"
|
||||
# set storage driver to overlay2 if config value is found, otherwise fall back to native FS driver
|
||||
if [[ $(awk -F'"' '/^DOCKER_BACKINGFS=/{print $2}' $DOCKER_CFG 2>/dev/null) == overlay2 ]]; then
|
||||
DOCKER_OPTS="$DOCKER_OPTS --storage-driver=overlay2"
|
||||
else
|
||||
BACKINGFS=$(findmnt --output FSTYPE --noheadings $DOCKER_ROOT)
|
||||
if [[ $BACKINGFS == btrfs ]]; then
|
||||
DOCKER_OPTS="$DOCKER_OPTS --storage-driver=btrfs"
|
||||
elif [[ $BACKINGFS == xfs ]]; then
|
||||
DOCKER_OPTS="$DOCKER_OPTS --storage-driver=overlay2"
|
||||
elif [[ $BACKINGFS == zfs ]]; then
|
||||
DOCKER_OPTS="$DOCKER_OPTS --storage-driver=zfs"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Enable global docker LOG rotation
|
||||
if [[ $DOCKER_LOG_ROTATION == yes ]]; then
|
||||
[[ -z $DOCKER_LOG_SIZE ]] && DOCKER_LOG_SIZE=10m
|
||||
[[ -z $DOCKER_LOG_FILES ]] && DOCKER_LOG_FILES=1
|
||||
DOCKER_OPTS="--log-opt max-size=$DOCKER_LOG_SIZE --log-opt max-file=$DOCKER_LOG_FILES $DOCKER_OPTS"
|
||||
fi
|
||||
# Less verbose logging by default
|
||||
DOCKER_OPTS="--log-level=fatal $DOCKER_OPTS"
|
||||
|
||||
# Adjust MTU size if non-default
|
||||
MTU=$(ip link show $PORT | grep -Po 'mtu \K\d+')
|
||||
[[ -n $MTU && $MTU -ne 1500 ]] && DOCKER_OPTS="--mtu=$MTU $DOCKER_OPTS"
|
||||
# Enable global docker LOG rotation
|
||||
if [[ $DOCKER_LOG_ROTATION == yes ]]; then
|
||||
[[ -z $DOCKER_LOG_SIZE ]] && DOCKER_LOG_SIZE=10m
|
||||
[[ -z $DOCKER_LOG_FILES ]] && DOCKER_LOG_FILES=1
|
||||
DOCKER_OPTS="--log-opt max-size=$DOCKER_LOG_SIZE --log-opt max-file=$DOCKER_LOG_FILES $DOCKER_OPTS"
|
||||
fi
|
||||
|
||||
# Enable IPv6 for docker bridge network
|
||||
if [[ -n $(ip -6 route show default dev $PORT) ]]; then
|
||||
DOCKER0='fd17::/64'
|
||||
DOCKER_OPTS="--ipv6 --fixed-cidr-v6=$DOCKER0 $DOCKER_OPTS"
|
||||
IPV6_FORWARD=${IPV6_FORWARD:=accept}
|
||||
# create IPv6 NAT rule for docker0
|
||||
[[ -z $(ip6tables -t nat -S | grep -o "$DOCKER0") ]] && run ip6tables -t nat -A POSTROUTING -s $DOCKER0 ! -o docker0 -j MASQUERADE
|
||||
else
|
||||
# ipv6 disabled
|
||||
[[ -d $CONF6/docker0 ]] && echo 1 > $CONF6/docker0/disable_ipv6
|
||||
fi
|
||||
# Adjust MTU size if non-default
|
||||
MTU=$(ip link show $PORT | grep -Po 'mtu \K\d+')
|
||||
[[ -n $MTU && $MTU -ne 1500 ]] && DOCKER_OPTS="--mtu=$MTU $DOCKER_OPTS"
|
||||
|
||||
export DOCKER_RAMDISK=true
|
||||
# Enable IPv6 for docker bridge network
|
||||
if [[ -n $(ip -6 route show default dev $PORT) ]]; then
|
||||
DOCKER0='fd17::/64'
|
||||
DOCKER_OPTS="--ipv6 --fixed-cidr-v6=$DOCKER0 $DOCKER_OPTS"
|
||||
IPV6_FORWARD=${IPV6_FORWARD:=accept}
|
||||
# create IPv6 NAT rule for docker0
|
||||
[[ -z $(ip6tables -t nat -S | grep -o "$DOCKER0") ]] && run ip6tables -t nat -A POSTROUTING -s $DOCKER0 ! -o docker0 -j MASQUERADE
|
||||
else
|
||||
# ipv6 disabled
|
||||
[[ -d $CONF6/docker0 ]] && echo 1 > $CONF6/docker0/disable_ipv6
|
||||
fi
|
||||
|
||||
export DOCKER_RAMDISK=true
|
||||
}
|
||||
|
||||
# Get docker daemon PID (if existing)
|
||||
docker_pid(){
|
||||
@@ -254,7 +264,7 @@ docker_network_start(){
|
||||
fi
|
||||
X=${NIC//[^0-9]/}
|
||||
REF=$(grep -Pom1 "<Network>\K(br|bond|eth|wlan)$X" $XMLFILE)
|
||||
[[ $X == 0 && $(carrier $NIC) != 1 ]] && continue
|
||||
[[ $X == 0 && ! $(carrier $NIC 1) ]] && continue
|
||||
[[ $X == 0 && $NIC != wlan0 ]] && MAIN=$NIC
|
||||
[[ $NIC == wlan0 && -n $MAIN ]] && continue
|
||||
if [[ -n $REF && $REF != $NIC ]]; then
|
||||
@@ -636,6 +646,7 @@ docker_status(){
|
||||
|
||||
case "$1" in
|
||||
'start')
|
||||
docker_read_options
|
||||
docker_service_start
|
||||
docker_network_start
|
||||
docker_container_start &>/dev/null &
|
||||
@@ -655,6 +666,7 @@ case "$1" in
|
||||
docker_network_stop
|
||||
docker_service_stop
|
||||
sleep 1
|
||||
docker_read_options
|
||||
docker_service_start
|
||||
docker_network_start
|
||||
docker_container_start &>/dev/null &
|
||||
|
||||
+60
-50
@@ -15,8 +15,8 @@ STARTWIFI="/usr/local/emhttp/webGui/scripts/wireless"
|
||||
WPA="/etc/wpa_supplicant.conf"
|
||||
|
||||
# system network references
|
||||
SYSTEM=/sys/class/net
|
||||
CONF6=/proc/sys/net/ipv6/conf
|
||||
SYSTEM="/sys/class/net"
|
||||
CONF6="/proc/sys/net/ipv6/conf"
|
||||
|
||||
# run & log functions
|
||||
. /etc/rc.d/rc.runlog
|
||||
@@ -31,43 +31,63 @@ PORT=${PORT:-wlan0}
|
||||
# translate security to informational text
|
||||
trans(){
|
||||
case "$1" in
|
||||
"open") echo "Open network" ;;
|
||||
"PSK") echo "WPA2 Personal" ;;
|
||||
"IEEE-802.1X/SHA-256") echo "WPA3 Enterprise" ;;
|
||||
"IEEE-802.1X") echo "WPA2 Enterprise" ;;
|
||||
"SAE") echo "WPA3 Personal" ;;
|
||||
"IEEE 802.1X") echo "WPA2 Enterprise" ;;
|
||||
"IEEE 802.1X/SHA-256") echo "WPA3 Enterprise" ;;
|
||||
"PSK") echo "WPA2 Personal" ;;
|
||||
"WEP") echo "WEP (decprecated)" ;;
|
||||
"open") echo "Open network" ;;
|
||||
"FT/IEEE-802.1X" | "FT/SAE" | "FT/PSK") echo "Roaming Profile" ;;
|
||||
*) echo "$1" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# function to remove leading zeros in IPv4 address
|
||||
# set security priority
|
||||
priority(){
|
||||
case "$1" in
|
||||
"IEEE-802.1X/SHA-256") echo 25 ;;
|
||||
"FT/IEEE-802.1X") echo 18 ;;
|
||||
"IEEE-802.1X") echo 15 ;;
|
||||
"FT/SAE") echo 12 ;;
|
||||
"SAE") echo 10 ;;
|
||||
"FT/PSK") echo 8 ;;
|
||||
"PSK") echo 6 ;;
|
||||
"WEP") echo 4 ;;
|
||||
"open") echo 2 ;;
|
||||
*) echo 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# remove leading zeros in IPv4 address
|
||||
unzero(){
|
||||
local M Q
|
||||
echo -n $(for Q in ${1//./ }; do printf "$M%x" "0x$Q"; M=.; done)
|
||||
}
|
||||
|
||||
# function to remove leading zeros in IPv6 address
|
||||
# remove leading zeros in IPv6 address
|
||||
unzero6(){
|
||||
local A M Q
|
||||
A=${1/::/:-:}
|
||||
echo -n $(for Q in ${A//:/ }; do [[ $Q != - ]] && printf "$M%x" "0x$Q" || printf ":"; M=:; done)
|
||||
}
|
||||
|
||||
# function to convert text to hex
|
||||
# convert text to hex
|
||||
hex(){
|
||||
echo -n $1 | od -An -tx1 | tr -d ' \n'
|
||||
}
|
||||
|
||||
# function to wait for carrier of interface
|
||||
carrier_up(){
|
||||
local n
|
||||
for n in {1..10}; do
|
||||
[[ $(cat $SYSTEM/$1/carrier 2>/dev/null) == 1 ]] && return 0 || sleep 1
|
||||
# wait for interface to go up
|
||||
carrier(){
|
||||
local n e
|
||||
[[ -e $SYSTEM/$1 ]] && e=${2:-10} || return 1
|
||||
for ((n=0; n<$e; n++)); do
|
||||
[[ $(cat $SYSTEM/$1/carrier 2>/dev/null) == 1 ]] && return 0
|
||||
[[ $e -gt 1 ]] && sleep 1
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# function to enable/disable ipv6 assignment per interface
|
||||
# enable/disable ipv6 assignment per interface
|
||||
ipv6_addr(){
|
||||
if [[ -d $CONF6/$1 ]]; then
|
||||
echo $2 >$CONF6/$1/accept_ra
|
||||
@@ -76,7 +96,7 @@ ipv6_addr(){
|
||||
fi
|
||||
}
|
||||
|
||||
# function to assign IP address
|
||||
# assign IP address
|
||||
ipaddr_up(){
|
||||
# disable IPv6 per interface when IPv4 only
|
||||
[[ $IP == ipv4 ]] && DISABLE6=1 || DISABLE6=0
|
||||
@@ -89,7 +109,7 @@ ipaddr_up(){
|
||||
[[ $DNS == yes ]] && OPTIONS="$OPTIONS -C resolv.conf"
|
||||
[[ $IP == ipv4 ]] && OPTIONS="$OPTIONS -4"
|
||||
[[ $IP == ipv6 ]] && OPTIONS="$OPTIONS -6"
|
||||
if carrier_up $PORT; then
|
||||
if carrier $PORT; then
|
||||
# interface is UP
|
||||
log "interface $PORT is UP, polling up to 60 sec for DHCP $IP server"
|
||||
if ! run timeout 60 dhcpcd -w $OPTIONS $PORT; then
|
||||
@@ -103,7 +123,7 @@ ipaddr_up(){
|
||||
fi
|
||||
elif [[ $DHCP == no ]]; then
|
||||
# bring up interface using static IP address
|
||||
if carrier_up $PORT; then STATE="UP"; else STATE="DOWN"; fi
|
||||
if carrier $PORT; then STATE="UP"; else STATE="DOWN"; fi
|
||||
log "interface $PORT is $STATE, setting static $IP address"
|
||||
ipv6_addr $PORT 0 1
|
||||
if [[ $IP == ipv4 ]]; then
|
||||
@@ -124,7 +144,7 @@ ipaddr_up(){
|
||||
fi
|
||||
}
|
||||
|
||||
# function to release IP address
|
||||
# release IP address
|
||||
ipaddr_down(){
|
||||
if [[ $DHCP == yes ]]; then
|
||||
# release DHCP assigned address and default route
|
||||
@@ -153,38 +173,42 @@ ipaddr_down(){
|
||||
# WPA3 Enterprise OK
|
||||
|
||||
wpa_configuration(){
|
||||
log "wpa_configuration: $(trans "$1")"
|
||||
if [[ ! -e $WPA ]]; then
|
||||
echo "bgscan=\"\"" >$WPA
|
||||
echo "ctrl_interface=/run/wpa_supplicant" >>$WPA
|
||||
[[ -n $CC ]] && echo "country=${CC,,}" >>$WPA
|
||||
fi
|
||||
if [[ $1 == "PSK" ]]; then
|
||||
if [[ $1 =~ "PSK" ]]; then
|
||||
PSK=$(wpa_passphrase "$SSID" "$PASSWORD" 2>/dev/null | grep -Pom1 '^\s+psk=\K.+')
|
||||
[[ -z $PSK ]] && PSK="\"$PASSWORD\""
|
||||
fi
|
||||
[[ -z $2 && $1 == "SAE" ]] && echo "sae_pwe=1" >>$WPA
|
||||
echo "network={" >>$WPA
|
||||
echo "ssid=\"$SSID\"" >>$WPA
|
||||
echo "scan_ssid=1" >>$WPA
|
||||
[[ $1 == "open" ]] && echo "key_mgmt=NONE" >>$WPA
|
||||
[[ $1 == "PSK" ]] && echo "key_mgmt=WPA-PSK" >>$WPA
|
||||
[[ $1 == "FT/PSK" ]] && echo "key_mgmt=FT-PSK" >>$WPA
|
||||
[[ $1 == "SAE" ]] && echo "key_mgmt=SAE" >>$WPA
|
||||
[[ $1 == "IEEE 802.1X" ]] && echo "key_mgmt=WPA-EAP" >>$WPA
|
||||
[[ $1 == "IEEE 802.1X/SHA-256" ]] && echo "key_mgmt=WPA-EAP-SHA256" >>$WPA
|
||||
[[ $1 == "PSK" ]] && echo "psk=$PSK" >>$WPA
|
||||
[[ $1 == "SAE" ]] && echo "sae_password=\"$PASSWORD\"" >>$WPA
|
||||
[[ $1 == "FT/SAE" ]] && echo "key_mgmt=FT-SAE" >>$WPA
|
||||
[[ $1 == "IEEE-802.1X" ]] && echo "key_mgmt=WPA-EAP" >>$WPA
|
||||
[[ $1 == "FT/IEEE-802.1X" ]] && echo "key_mgmt=FT-EAP" >>$WPA
|
||||
[[ $1 == "IEEE-802.1X/SHA-256" ]] && echo "key_mgmt=WPA-EAP-SHA256" >>$WPA
|
||||
[[ $1 =~ "PSK" ]] && echo "psk=$PSK" >>$WPA
|
||||
[[ $1 =~ "SAE" ]] && echo "sae_password=\"$PASSWORD\"" >>$WPA
|
||||
[[ $1 =~ "IEEE" ]] && echo "eap=PEAP" >>$WPA
|
||||
[[ $1 =~ "IEEE" ]] && echo "identity=\"$USERNAME\"" >>$WPA
|
||||
[[ $1 =~ "IEEE" ]] && echo "password=\"$PASSWORD\"" >>$WPA
|
||||
[[ $1 == "IEEE 802.1X" ]] && echo "ieee80211w=1" >>$WPA
|
||||
[[ $1 == "SAE" || $1 == "IEEE 802.1X/SHA-256" ]] && echo "ieee80211w=2" >>$WPA
|
||||
[[ $1 == "IEEE-802.1X" || $1 == "FT/IEEE-802.1X" ]] && echo "ieee80211w=1" >>$WPA
|
||||
[[ $1 =~ "SAE" || $1 == "IEEE-802.1X/SHA-256" ]] && echo "ieee80211w=2" >>$WPA
|
||||
[[ $1 =~ "IEEE" ]] && echo "phase2=\"auth=MSCHAPV2\"" >>$WPA
|
||||
[[ -n $2 ]] && echo "priority=$2" >>$WPA
|
||||
echo "priority=$(priority "$1")" >>$WPA
|
||||
echo "}" >>$WPA
|
||||
}
|
||||
|
||||
wifi_running(){
|
||||
sleep 0.1
|
||||
[[ $(cat $SYSTEM/$PORT/carrier 2>/dev/null) == 1 ]]
|
||||
carrier $PORT 1
|
||||
}
|
||||
|
||||
wifi_start(){
|
||||
@@ -211,11 +235,11 @@ wifi_start(){
|
||||
$OPENSSL load
|
||||
# start active SSID
|
||||
$STARTWIFI
|
||||
if ! carrier_up $PORT; then
|
||||
if ! wifi_running; then
|
||||
# try the saved SSIDs
|
||||
for SSID in $(grep -P '^\[.+\]$' $CFG | sed 1d | sed -r 's/\[|\]/"/g'); do
|
||||
[[ -n $SSID ]] && $STARTWIFI "$SSID" || break
|
||||
if carrier_up $PORT; then break; fi
|
||||
if wifi_running; then break; fi
|
||||
done
|
||||
fi
|
||||
if wifi_running; then REPLY="Started"; else REPLY="Failed"; fi
|
||||
@@ -269,31 +293,17 @@ wifi_join(){
|
||||
sed -ri "s/^(PASSWORD=\").+$/\1$ENCRYPT2\"/" $CFG
|
||||
fi
|
||||
SECURITY=${SECURITY:-$ATTR3}
|
||||
# replace space in enterprise security type
|
||||
SECURITY=${SECURITY//IEEE 802/IEEE-802}
|
||||
# regulatory region
|
||||
REGION=$(grep -Pom1 '^REGION="\K[^"]+' $CFG)
|
||||
REGION_XX=$(grep -Pom1 '^REGION_XX="\K[^"]+' $CFG)
|
||||
[[ $REGION == '00' ]] && CC=$REGION_XX || CC=$REGION
|
||||
[[ -n $(pgrep wpa_supplicant) ]] && pkill wpa_supplicant
|
||||
rm -f $WPA
|
||||
if [[ $SECURITY == "auto" ]]; then
|
||||
log "wpa_configuration: Automatic detection"
|
||||
wpa_configuration "IEEE 802.1X/SHA-256" 25
|
||||
wpa_configuration "IEEE 802.1X" 18
|
||||
wpa_configuration "SAE" 15
|
||||
wpa_configuration "PSK" 12
|
||||
wpa_configuration "open" 10
|
||||
elif [[ $SECURITY == "IEEE 802.1X IEEE 802.1X/SHA-256" ]]; then
|
||||
log "wpa_configuration: WPA2/WPA3 Enterprise"
|
||||
wpa_configuration "IEEE 802.1X/SHA-256" 25
|
||||
wpa_configuration "IEEE 802.1X" 18
|
||||
elif [[ $SECURITY == "PSK SAE" ]]; then
|
||||
log "wpa_configuration: WPA2/WPA3 Personal"
|
||||
wpa_configuration "SAE" 15
|
||||
wpa_configuration "PSK" 12
|
||||
else
|
||||
log "wpa_configuration: $(trans "$SECURITY")"
|
||||
wpa_configuration "$SECURITY"
|
||||
fi
|
||||
# list of possible security types when "auto"
|
||||
[[ $SECURITY == "auto" ]] && SECURITY="IEEE-802.1X/SHA-256 FT/IEEE-802.1X IEEE-802.1X FT/SAE SAE FT/PSK PSK open"
|
||||
for TYPE in $SECURITY; do wpa_configuration "$TYPE"; done
|
||||
run wpa_supplicant -B -q -i $PORT -c $WPA
|
||||
# IPv4 address assignment
|
||||
IP=ipv4
|
||||
|
||||
Reference in New Issue
Block a user