Commit 9ed9018f authored by Igor Pecovnik's avatar Igor Pecovnik
Browse files

Bugfixes and showing dislaimer only when starting AP mode which is at most critical part

parent ee02d1ca
...@@ -46,6 +46,17 @@ BACKTITLE="$ARMBIAN $DISTRO $DISTROID configuration utility, http://www.armbian. ...@@ -46,6 +46,17 @@ BACKTITLE="$ARMBIAN $DISTRO $DISTROID configuration utility, http://www.armbian.
TITLE="Configuring $BOARD_NAME" TITLE="Configuring $BOARD_NAME"
#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# show disclaimer
#
function beta_disclaimer ()
{
exec 3>&1
ACKNOWLEDGEMENT=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse --title "Warning" --clear \--radiolist "\n$1.\n \n" 12 56 7 "Yes, I understand" "" off 2>&1 1>&3)
exec 3>&-
}
#-----------------------------------------------------------------------------------------------------------------------------------------# #-----------------------------------------------------------------------------------------------------------------------------------------#
# #
# show description for MOTD files # show description for MOTD files
...@@ -227,13 +238,6 @@ function connect_bt_interface () ...@@ -227,13 +238,6 @@ function connect_bt_interface ()
# #
#-----------------------------------------------------------------------------------------------------------------------------------------# #-----------------------------------------------------------------------------------------------------------------------------------------#
# Show disclaimer where you need to press SPACE to continue. To make sure warning is read.
#
#exec 3>&1
#ACKNOWLEDGEMENT=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse --title "Warning" --clear \--radiolist "\nThis configuration tool runs under superuser rights.\n \n" 10 56 7 "Yes, I understand the risks" "" off 2>&1 1>&3)
#exec 3>&-
# if [[ $ACKNOWLEDGEMENT == "" ]]; then exit; fi
dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nLoading Armbian configuration utility ... " 5 45 dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nLoading Armbian configuration utility ... " 5 45
# Main loop # Main loop
...@@ -262,8 +266,8 @@ while true; do ...@@ -262,8 +266,8 @@ while true; do
if [[ -n $DISPLAY_MANAGER ]]; then if [[ -n $DISPLAY_MANAGER ]]; then
LIST+=( "Desktop" "Disable desktop" ) LIST+=( "Desktop" "Disable desktop" )
[[ $DISPLAY_MANAGER == 'nodm' ]] && LIST+=( "Lightdm" "Enable standard login manager" ) [[ $DISPLAY_MANAGER == 'nodm' ]] && LIST+=( "Lightdm" "Switch to standard login manager" )
[[ $DISPLAY_MANAGER == 'lightdm' ]] && LIST+=( "Nodm" "Enable simple auto login manager" ) [[ $DISPLAY_MANAGER == 'lightdm' ]] && LIST+=( "Nodm" "Switch to simple auto login manager" )
else else
LIST+=( "Desktop" "Enable desktop" ) LIST+=( "Desktop" "Enable desktop" )
fi fi
...@@ -432,7 +436,7 @@ while true; do ...@@ -432,7 +436,7 @@ while true; do
dialog --title "Choose a display manager" --backtitle "$BACKTITLE" --help-button --help-label "Cancel" --yes-label "Lightdm" \ dialog --title "Choose a display manager" --backtitle "$BACKTITLE" --help-button --help-label "Cancel" --yes-label "Lightdm" \
--no-label "Nodm" --yesno "\nLightdm = full featured login display manager\nNodm = autoloading into desktop" 8 70 --no-label "Nodm" --yesno "\nLightdm = full featured login display manager\nNodm = autoloading into desktop" 8 70
exitstatus=$?; exitstatus=$?;
[[ $exitstatus = 0 ]] && systemctl start lightdm.service [[ $exitstatus = 0 ]] && apt-get -o Dpkg::Options::="--force-confold" -y -qq --no-install-recommends install lightdm-gtk-greeter lightdm >/dev/null 2>&1 && systemctl start lightdm.service
[[ $exitstatus = 1 ]] && sed -i "s/^NODM_ENABLED=.*/NODM_ENABLED=true/" /etc/default/nodm && service nodm start [[ $exitstatus = 1 ]] && sed -i "s/^NODM_ENABLED=.*/NODM_ENABLED=true/" /etc/default/nodm && service nodm start
fi fi
;; ;;
...@@ -518,124 +522,141 @@ while true; do ...@@ -518,124 +522,141 @@ while true; do
dialog --title "Hostapd service is running" --backtitle "$BACKTITLE" --help-button --help-label "Cancel" --yes-label "Stop" \ dialog --title "Hostapd service is running" --backtitle "$BACKTITLE" --help-button --help-label "Cancel" --yes-label "Stop" \
--no-label "Edit" --yesno "\nStop: stop and disable\n\nEdit: change basic parameters: SSID, password and channel" 9 70 --no-label "Edit" --yesno "\nStop: stop and disable\n\nEdit: change basic parameters: SSID, password and channel" 9 70
exitstatus=$?; exitstatus=$?;
if [[ $exitstatus = 0 ]]; then service hostapd stop ; sed -i "s/^DAEMON_CONF=.*/DAEMON_CONF=/" /etc/init.d/hostapd; \ if [[ $exitstatus = 0 ]]; then
systemctl daemon-reload; fi service hostapd stop
sed -i "s/^DAEMON_CONF=.*/DAEMON_CONF=/" /etc/init.d/hostapd
systemctl daemon-reload
rm /etc/NetworkManager/conf.d/armbian.conf
service network-manager reload
fi
if [[ $exitstatus = 1 ]]; then wlan_edit; service hostapd stop; sleep 1; service hostapd start; fi if [[ $exitstatus = 1 ]]; then wlan_edit; service hostapd stop; sleep 1; service hostapd start; fi
elif [[ -n $CURRENT_UUID ]]; then elif [[ -n $CURRENT_UUID ]]; then
dialog --title "Info" --backtitle "$BACKTITLE" --no-collapse \ dialog --title "Info" --backtitle "$BACKTITLE" --no-collapse \
--yesno "\nWireless connection is in use.\n\nDo you want to disconnect?" 9 57 --yesno "\nWireless connection is in use.\n\nDo you want to disconnect?" 9 57
[[ $? = 0 ]] && nmcli connection down uuid $CURRENT_UUID [[ $? = 0 ]] && nmcli connection down uuid $CURRENT_UUID
else else
# change special adapters to AP mode # check if user agree to enter this area
wlan_exceptions "on" beta_disclaimer "Wireless networking in Linux is problematic. Our tools make it easy for some cases but can't enable AP on every random WiFi chip. If this tool fail, check manual methods."
# check for WLAN interfaces if [[ -n $ACKNOWLEDGEMENT ]]; then
get_wlan_interface # change special adapters to AP mode
# add interface to unmanaged list wlan_exceptions "on"
echo "[keyfile]" > /etc/NetworkManager/conf.d/armbian.conf # check for WLAN interfaces
echo "unmanaged-devices=interface-name:$WIRELESS_ADAPTER" >>/etc/NetworkManager/conf.d/armbian.conf get_wlan_interface
service network-manager reload # add interface to unmanaged list
# display dialog echo "[keyfile]" > /etc/NetworkManager/conf.d/armbian.conf
dialog --backtitle "$BACKTITLE" --title "Please wait" \ echo "unmanaged-devices=interface-name:$WIRELESS_ADAPTER" >>/etc/NetworkManager/conf.d/armbian.conf
--infobox "\nWireless adapter: $WIRELESS_ADAPTER\n\nProbing nl80211 hostapd driver compatibility." 7 50 service network-manager reload
apt-get -o Dpkg::Options::="--force-confnew" -y -qq --no-install-recommends install hostapd > /dev/null # display dialog
# change to selected interface
sed -i "s/^interface=.*/interface=$WIRELESS_ADAPTER/" /etc/hostapd.conf
# add hostapd.conf to services
sed -i "s/^DAEMON_CONF=.*/DAEMON_CONF=\/etc\/hostapd.conf/" /etc/init.d/hostapd
# check both options
CHECK=$(systemctl daemon-reload;service hostapd restart;service hostapd status|grep fail)
if [[ -n "$CHECK" ]]; then
dialog --backtitle "$BACKTITLE" --title "Please wait" \ dialog --backtitle "$BACKTITLE" --title "Please wait" \
--infobox "\nWireless adapter: $WIRELESS_ADAPTER\n\nProbing Realtek hostapd driver compatibility." 7 50 --infobox "\nWireless adapter: $WIRELESS_ADAPTER\n\nProbing nl80211 hostapd driver compatibility." 7 50
apt-get -o Dpkg::Options::="--force-confnew" -y -qq --no-install-recommends install hostapd-realtek > /dev/null apt-get -o Dpkg::Options::="--force-confnew" -y -qq --no-install-recommends install hostapd > /dev/null
# change to selected interface # change to selected interface
sed -i "s/^interface=.*/interface=$WIRELESS_ADAPTER/" /etc/hostapd.conf sed -i "s/^interface=.*/interface=$WIRELESS_ADAPTER/" /etc/hostapd.conf
fi # add hostapd.conf to services
CHECK=$(systemctl daemon-reload;service hostapd restart;service hostapd status|grep fail) sed -i "s/^DAEMON_CONF=.*/DAEMON_CONF=\/etc\/hostapd.conf/" /etc/init.d/hostapd
# if both fails there is other problem # check both options
if [[ -n "$CHECK" ]]; then CHECK=$(systemctl daemon-reload;service hostapd restart;service hostapd status|grep fail)
dialog --backtitle "$BACKTITLE" --title "Warning" \ if [[ -n "$CHECK" ]]; then
--infobox "\nWireless adapter: $WIRELESS_ADAPTER\n\nNo compatible hostapd driver found." 7 39 dialog --backtitle "$BACKTITLE" --title "Please wait" \
sed -i "s/^DAEMON_CONF=.*/DAEMON_CONF=/" /etc/init.d/hostapd --infobox "\nWireless adapter: $WIRELESS_ADAPTER\n\nProbing Realtek hostapd driver compatibility." 7 50
systemctl daemon-reload;service hostapd restart apt-get -o Dpkg::Options::="--force-confnew" -y -qq --no-install-recommends install hostapd-realtek > /dev/null
sleep 3 # change to selected interface
exit sed -i "s/^interface=.*/interface=$WIRELESS_ADAPTER/" /etc/hostapd.conf
fi fi
CHECK=$(systemctl daemon-reload;service hostapd restart;service hostapd status|grep fail)
dialog --title "Choose Access Point mode for $WIRELESS_ADAPTER" --backtitle "$BACKTITLE" --help-button \ # if both fails there is other problem
--help-label "Manual" --yes-label "Bridge" --no-label "NAT" --yesno "\nBridge: wireless clients will use your routers DHCP \ if [[ -n "$CHECK" ]]; then
server\n\nNAT: with own DHCP server, out of your primary network\n\nManual: edit configuration manually" 11 70 dialog --backtitle "$BACKTITLE" --title "Warning" \
response=$? --infobox "\nWireless adapter: $WIRELESS_ADAPTER\n\nNo compatible hostapd driver found." 7 39
DEFAULT_ADAPTER=$(ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)') sed -i "s/^DAEMON_CONF=.*/DAEMON_CONF=/" /etc/init.d/hostapd
NETWORK_CONF="/etc/network/interfaces" systemctl daemon-reload;service hostapd restart
TEMP_CONF="/etc/network/interfaces.out" sleep 3
cp $NETWORK_CONF $TEMP_CONF exit
fi
case $response in
# bridge dialog --title "Choose Access Point mode for $WIRELESS_ADAPTER" --backtitle "$BACKTITLE" --help-button \
0) --help-label "Manual" --yes-label "Bridge" --no-label "NAT" --yesno "\nBridge: wireless clients will use your routers DHCP \
sed -i '/^#/ d' $TEMP_CONF server\n\nNAT: with own DHCP server, out of your primary network\n\nManual: edit configuration manually" 11 70
apt-get -qq -y --no-install-recommends install bridge-utils >> /dev/null response=$?
sed -i "s/^auto lo.*/auto lo br0/" $TEMP_CONF DEFAULT_ADAPTER=$(ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)')
# if we have dhcp on default adapter NETWORK_CONF="/etc/network/interfaces"
if [[ -n $(grep dhcp $TEMP_CONF | grep "$DEFAULT_ADAPTER" | grep -v br) ]]; then dialog --title "Network configuration" --backtitle "$BACKTITLE" --yesno "\nStart with clean config?" 7 29
sed -i "s/^iface $DEFAULT_ADAPTER inet dhcp/iface $DEFAULT_ADAPTER inet manual/" $TEMP_CONF [[ $? = 0 ]] && NETWORK_CONF="/etc/network/interfaces.default";
echo -e "\niface br0 inet dhcp\nbridge_ports $DEFAULT_ADAPTER $WIRELESS_ADAPTER" >> $TEMP_CONF
echo -e "\nauto $WIRELESS_ADAPTER\niface $WIRELESS_ADAPTER inet manual" >> $TEMP_CONF TEMP_CONF="/etc/network/interfaces.out"
#fi cp $NETWORK_CONF $TEMP_CONF
# if we have static on default adapter
#if [[ -n $(grep static $TEMP_CONF | grep "$DEFAULT_ADAPTER" | grep -v br) ]]; then case $response in
else # bridge
sed -i "s/^iface $DEFAULT_ADAPTER inet static/iface $DEFAULT_ADAPTER inet manual/" $TEMP_CONF 0)
sed -i "/^iface $DEFAULT_ADAPTER inet manual/a iface br0 inet static" $TEMP_CONF sed -i '/^#/ d' $TEMP_CONF
echo -e "bridge_ports $DEFAULT_ADAPTER $WIRELESS_ADAPTER" >> $TEMP_CONF apt-get -qq -y --no-install-recommends install bridge-utils >> /dev/null
echo -e "\nauto $WIRELESS_ADAPTER\niface $WIRELESS_ADAPTER inet manual" >> $TEMP_CONF sed -i "s/^auto lo.*/auto lo br0/" $TEMP_CONF
fi # if we have dhcp on default adapter
sed -i 's/^bridge=.*/bridge=br0/' /etc/hostapd.conf if [[ -n $(grep dhcp $TEMP_CONF | grep "$DEFAULT_ADAPTER" | grep -v br) ]]; then
;; sed -i "s/^iface $DEFAULT_ADAPTER inet dhcp/iface $DEFAULT_ADAPTER inet manual/" $TEMP_CONF
echo -e "\niface br0 inet dhcp\nbridge_ports $DEFAULT_ADAPTER $WIRELESS_ADAPTER" >> $TEMP_CONF
# NAT echo -e "\nauto $WIRELESS_ADAPTER\niface $WIRELESS_ADAPTER inet manual" >> $TEMP_CONF
1) #fi
sed -i '/^#/ d' $TEMP_CONF # if we have static on default adapter
debconf-apt-progress -- apt-get -qq -y --no-install-recommends install dnsmasq iptables #if [[ -n $(grep static $TEMP_CONF | grep "$DEFAULT_ADAPTER" | grep -v br) ]]; then
echo -e "\nallow-hotplug $WIRELESS_ADAPTER\niface $WIRELESS_ADAPTER inet static " >> $TEMP_CONF else
echo -e "\naddress 172.24.1.1\nnetmask 255.255.255.0\nnetwork 172.24.1.0\nbroadcast 172.24.1.255" >> $TEMP_CONF sed -i "s/^iface $DEFAULT_ADAPTER inet static/iface $DEFAULT_ADAPTER inet manual/" $TEMP_CONF
# create new configuration sed -i "/^iface $DEFAULT_ADAPTER inet manual/a iface br0 inet static" $TEMP_CONF
echo "interface=$WIRELESS_ADAPTER # Use interface $WIRELESS_ADAPTER" > /etc/dnsmasq.conf echo -e "bridge_ports $DEFAULT_ADAPTER $WIRELESS_ADAPTER" >> $TEMP_CONF
echo "listen-address=172.24.1.1 # Explicitly specify the address to listen on" >> /etc/dnsmasq.conf echo -e "\nauto $WIRELESS_ADAPTER\niface $WIRELESS_ADAPTER inet manual" >> $TEMP_CONF
echo "bind-interfaces # Bind to the interface to make sure we aren't sending \ fi
things elsewhere" >> /etc/dnsmasq.conf sed -i 's/^bridge=.*/bridge=br0/' /etc/hostapd.conf
echo "server=8.8.8.8 # Forward DNS requests to Google DNS" >> /etc/dnsmasq.conf ;;
echo "domain-needed # Don't forward short names" >> /etc/dnsmasq.conf
echo "bogus-priv # Never forward addresses in the non-routed address spaces" \ # NAT
>> /etc/dnsmasq.conf 1)
echo "dhcp-range=172.24.1.50,172.24.1.150,12h # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with \ sed -i '/^#/ d' $TEMP_CONF
a 12 hour lease time" >> /etc/dnsmasq.conf debconf-apt-progress -- apt-get -qq -y --no-install-recommends install dnsmasq iptables
# - Enable IPv4 forwarding echo -e "\nallow-hotplug $WIRELESS_ADAPTER\niface $WIRELESS_ADAPTER inet static " >> $TEMP_CONF
sed -i "/net.ipv4.ip_forward=/c\net.ipv4.ip_forward=1" /etc/sysctl.conf echo -e "\naddress 172.24.1.1\nnetmask 255.255.255.0\nnetwork 172.24.1.0\nbroadcast 172.24.1.255" >> $TEMP_CONF
echo 1 > /proc/sys/net/ipv4/ip_forward # create new configuration
# - Apply iptables echo "interface=$WIRELESS_ADAPTER # Use interface $WIRELESS_ADAPTER" > /etc/dnsmasq.conf
iptables -t nat -A POSTROUTING -o $DEFAULT_ADAPTER -j MASQUERADE echo "listen-address=172.24.1.1 # Explicitly specify the address to listen on" >> /etc/dnsmasq.conf
iptables -A FORWARD -i $DEFAULT_ADAPTER -o $WIRELESS_ADAPTER -m state --state RELATED,ESTABLISHED -j ACCEPT echo "bind-interfaces # Bind to the interface to make sure we aren't sending \
iptables -A FORWARD -i $WIRELESS_ADAPTER -o $DEFAULT_ADAPTER -j ACCEPT things elsewhere" >> /etc/dnsmasq.conf
# - Save IP tables, applied during ifup in /etc/network/interfaces. echo "server=8.8.8.8 # Forward DNS requests to Google DNS" >> /etc/dnsmasq.conf
iptables-save > /etc/iptables.ipv4.nat echo "domain-needed # Don't forward short names" >> /etc/dnsmasq.conf
service dnsmasq restart echo "bogus-priv # Never forward addresses in the non-routed address spaces" \
sed -i 's/^bridge=.*/#&/' /etc/hostapd.conf >> /etc/dnsmasq.conf
sed -e 's/exit 0//g' -i /etc/rc.local echo "dhcp-range=172.24.1.50,172.24.1.150,12h # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with \
echo "iptables-restore < /etc/iptables.ipv4.nat" >> /etc/rc.local a 12 hour lease time" >> /etc/dnsmasq.conf
echo "exit 0" >> /etc/rc.local # - Enable IPv4 forwarding
;; sed -i "/net.ipv4.ip_forward=/c\net.ipv4.ip_forward=1" /etc/sysctl.conf
3)exit;; echo 1 > /proc/sys/net/ipv4/ip_forward
# - Apply iptables
255) exit;; iptables -t nat -A POSTROUTING -o $DEFAULT_ADAPTER -j MASQUERADE
esac iptables -A FORWARD -i $DEFAULT_ADAPTER -o $WIRELESS_ADAPTER -m state --state RELATED,ESTABLISHED -j ACCEPT
dialog --title "Manually adjust network configuration if needed" --backtitle "$BACKTITLE" \ iptables -A FORWARD -i $WIRELESS_ADAPTER -o $DEFAULT_ADAPTER -j ACCEPT
--ok-label "Reboot to apply new settings" --no-collapse --editbox $TEMP_CONF 30 0 2> $TEMP_CONF".tmp" # - Save IP tables, applied during ifup in /etc/network/interfaces.
service hostapd stop iptables-save > /etc/iptables.ipv4.nat
if [[ $? = 0 ]]; then service dnsmasq restart
mv $TEMP_CONF $NETWORK_CONF sed -i 's/^bridge=.*/#&/' /etc/hostapd.conf
reboot sed -e 's/exit 0//g' -i /etc/rc.local
echo "iptables-restore < /etc/iptables.ipv4.nat" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
;;
3)exit;;
255) exit;;
esac
dialog --title "Manually adjust network configuration if needed" --backtitle "$BACKTITLE" \
--ok-label "Reboot to apply new settings" --no-collapse --editbox $TEMP_CONF 30 0 2> $TEMP_CONF".tmp"
response=$?
service hostapd stop
if [[ $response = 0 ]]; then
mv $TEMP_CONF /etc/network/interfaces
service networking restart
ifdown $DEFAULT_ADAPTER
ifup $DEFAULT_ADAPTER
service hostapd start
#reboot
fi
fi fi
fi fi
;; ;;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment