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.
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
......@@ -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
# Main loop
......@@ -262,8 +266,8 @@ while true; do
if [[ -n $DISPLAY_MANAGER ]]; then
LIST+=( "Desktop" "Disable desktop" )
[[ $DISPLAY_MANAGER == 'nodm' ]] && LIST+=( "Lightdm" "Enable standard login manager" )
[[ $DISPLAY_MANAGER == 'lightdm' ]] && LIST+=( "Nodm" "Enable simple auto login manager" )
[[ $DISPLAY_MANAGER == 'nodm' ]] && LIST+=( "Lightdm" "Switch to standard login manager" )
[[ $DISPLAY_MANAGER == 'lightdm' ]] && LIST+=( "Nodm" "Switch to simple auto login manager" )
else
LIST+=( "Desktop" "Enable desktop" )
fi
......@@ -432,7 +436,7 @@ while true; do
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
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
fi
;;
......@@ -518,124 +522,141 @@ while true; do
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
exitstatus=$?;
if [[ $exitstatus = 0 ]]; then service hostapd stop ; sed -i "s/^DAEMON_CONF=.*/DAEMON_CONF=/" /etc/init.d/hostapd; \
systemctl daemon-reload; fi
if [[ $exitstatus = 0 ]]; then
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
elif [[ -n $CURRENT_UUID ]]; then
dialog --title "Info" --backtitle "$BACKTITLE" --no-collapse \
--yesno "\nWireless connection is in use.\n\nDo you want to disconnect?" 9 57
[[ $? = 0 ]] && nmcli connection down uuid $CURRENT_UUID
else
# change special adapters to AP mode
wlan_exceptions "on"
# check for WLAN interfaces
get_wlan_interface
# add interface to unmanaged list
echo "[keyfile]" > /etc/NetworkManager/conf.d/armbian.conf
echo "unmanaged-devices=interface-name:$WIRELESS_ADAPTER" >>/etc/NetworkManager/conf.d/armbian.conf
service network-manager reload
# display dialog
dialog --backtitle "$BACKTITLE" --title "Please wait" \
--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 > /dev/null
# 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
# check if user agree to enter this area
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."
if [[ -n $ACKNOWLEDGEMENT ]]; then
# change special adapters to AP mode
wlan_exceptions "on"
# check for WLAN interfaces
get_wlan_interface
# add interface to unmanaged list
echo "[keyfile]" > /etc/NetworkManager/conf.d/armbian.conf
echo "unmanaged-devices=interface-name:$WIRELESS_ADAPTER" >>/etc/NetworkManager/conf.d/armbian.conf
service network-manager reload
# display dialog
dialog --backtitle "$BACKTITLE" --title "Please wait" \
--infobox "\nWireless adapter: $WIRELESS_ADAPTER\n\nProbing Realtek hostapd driver compatibility." 7 50
apt-get -o Dpkg::Options::="--force-confnew" -y -qq --no-install-recommends install hostapd-realtek > /dev/null
--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 > /dev/null
# change to selected interface
sed -i "s/^interface=.*/interface=$WIRELESS_ADAPTER/" /etc/hostapd.conf
fi
CHECK=$(systemctl daemon-reload;service hostapd restart;service hostapd status|grep fail)
# if both fails there is other problem
if [[ -n "$CHECK" ]]; then
dialog --backtitle "$BACKTITLE" --title "Warning" \
--infobox "\nWireless adapter: $WIRELESS_ADAPTER\n\nNo compatible hostapd driver found." 7 39
sed -i "s/^DAEMON_CONF=.*/DAEMON_CONF=/" /etc/init.d/hostapd
systemctl daemon-reload;service hostapd restart
sleep 3
exit
fi
dialog --title "Choose Access Point mode for $WIRELESS_ADAPTER" --backtitle "$BACKTITLE" --help-button \
--help-label "Manual" --yes-label "Bridge" --no-label "NAT" --yesno "\nBridge: wireless clients will use your routers DHCP \
server\n\nNAT: with own DHCP server, out of your primary network\n\nManual: edit configuration manually" 11 70
response=$?
DEFAULT_ADAPTER=$(ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)')
NETWORK_CONF="/etc/network/interfaces"
TEMP_CONF="/etc/network/interfaces.out"
cp $NETWORK_CONF $TEMP_CONF
case $response in
# bridge
0)
sed -i '/^#/ d' $TEMP_CONF
apt-get -qq -y --no-install-recommends install bridge-utils >> /dev/null
sed -i "s/^auto lo.*/auto lo br0/" $TEMP_CONF
# if we have dhcp on default adapter
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
echo -e "\nauto $WIRELESS_ADAPTER\niface $WIRELESS_ADAPTER inet manual" >> $TEMP_CONF
#fi
# if we have static on default adapter
#if [[ -n $(grep static $TEMP_CONF | grep "$DEFAULT_ADAPTER" | grep -v br) ]]; then
else
sed -i "s/^iface $DEFAULT_ADAPTER inet static/iface $DEFAULT_ADAPTER inet manual/" $TEMP_CONF
sed -i "/^iface $DEFAULT_ADAPTER inet manual/a iface br0 inet static" $TEMP_CONF
echo -e "bridge_ports $DEFAULT_ADAPTER $WIRELESS_ADAPTER" >> $TEMP_CONF
echo -e "\nauto $WIRELESS_ADAPTER\niface $WIRELESS_ADAPTER inet manual" >> $TEMP_CONF
fi
sed -i 's/^bridge=.*/bridge=br0/' /etc/hostapd.conf
;;
# NAT
1)
sed -i '/^#/ d' $TEMP_CONF
debconf-apt-progress -- apt-get -qq -y --no-install-recommends install dnsmasq iptables
echo -e "\nallow-hotplug $WIRELESS_ADAPTER\niface $WIRELESS_ADAPTER inet static " >> $TEMP_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
# create new configuration
echo "interface=$WIRELESS_ADAPTER # Use interface $WIRELESS_ADAPTER" > /etc/dnsmasq.conf
echo "listen-address=172.24.1.1 # Explicitly specify the address to listen on" >> /etc/dnsmasq.conf
echo "bind-interfaces # Bind to the interface to make sure we aren't sending \
things elsewhere" >> /etc/dnsmasq.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" \
>> /etc/dnsmasq.conf
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 \
a 12 hour lease time" >> /etc/dnsmasq.conf
# - Enable IPv4 forwarding
sed -i "/net.ipv4.ip_forward=/c\net.ipv4.ip_forward=1" /etc/sysctl.conf
echo 1 > /proc/sys/net/ipv4/ip_forward
# - Apply iptables
iptables -t nat -A POSTROUTING -o $DEFAULT_ADAPTER -j MASQUERADE
iptables -A FORWARD -i $DEFAULT_ADAPTER -o $WIRELESS_ADAPTER -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i $WIRELESS_ADAPTER -o $DEFAULT_ADAPTER -j ACCEPT
# - Save IP tables, applied during ifup in /etc/network/interfaces.
iptables-save > /etc/iptables.ipv4.nat
service dnsmasq restart
sed -i 's/^bridge=.*/#&/' /etc/hostapd.conf
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"
service hostapd stop
if [[ $? = 0 ]]; then
mv $TEMP_CONF $NETWORK_CONF
reboot
# 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" \
--infobox "\nWireless adapter: $WIRELESS_ADAPTER\n\nProbing Realtek hostapd driver compatibility." 7 50
apt-get -o Dpkg::Options::="--force-confnew" -y -qq --no-install-recommends install hostapd-realtek > /dev/null
# change to selected interface
sed -i "s/^interface=.*/interface=$WIRELESS_ADAPTER/" /etc/hostapd.conf
fi
CHECK=$(systemctl daemon-reload;service hostapd restart;service hostapd status|grep fail)
# if both fails there is other problem
if [[ -n "$CHECK" ]]; then
dialog --backtitle "$BACKTITLE" --title "Warning" \
--infobox "\nWireless adapter: $WIRELESS_ADAPTER\n\nNo compatible hostapd driver found." 7 39
sed -i "s/^DAEMON_CONF=.*/DAEMON_CONF=/" /etc/init.d/hostapd
systemctl daemon-reload;service hostapd restart
sleep 3
exit
fi
dialog --title "Choose Access Point mode for $WIRELESS_ADAPTER" --backtitle "$BACKTITLE" --help-button \
--help-label "Manual" --yes-label "Bridge" --no-label "NAT" --yesno "\nBridge: wireless clients will use your routers DHCP \
server\n\nNAT: with own DHCP server, out of your primary network\n\nManual: edit configuration manually" 11 70
response=$?
DEFAULT_ADAPTER=$(ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)')
NETWORK_CONF="/etc/network/interfaces"
dialog --title "Network configuration" --backtitle "$BACKTITLE" --yesno "\nStart with clean config?" 7 29
[[ $? = 0 ]] && NETWORK_CONF="/etc/network/interfaces.default";
TEMP_CONF="/etc/network/interfaces.out"
cp $NETWORK_CONF $TEMP_CONF
case $response in
# bridge
0)
sed -i '/^#/ d' $TEMP_CONF
apt-get -qq -y --no-install-recommends install bridge-utils >> /dev/null
sed -i "s/^auto lo.*/auto lo br0/" $TEMP_CONF
# if we have dhcp on default adapter
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
echo -e "\nauto $WIRELESS_ADAPTER\niface $WIRELESS_ADAPTER inet manual" >> $TEMP_CONF
#fi
# if we have static on default adapter
#if [[ -n $(grep static $TEMP_CONF | grep "$DEFAULT_ADAPTER" | grep -v br) ]]; then
else
sed -i "s/^iface $DEFAULT_ADAPTER inet static/iface $DEFAULT_ADAPTER inet manual/" $TEMP_CONF
sed -i "/^iface $DEFAULT_ADAPTER inet manual/a iface br0 inet static" $TEMP_CONF
echo -e "bridge_ports $DEFAULT_ADAPTER $WIRELESS_ADAPTER" >> $TEMP_CONF
echo -e "\nauto $WIRELESS_ADAPTER\niface $WIRELESS_ADAPTER inet manual" >> $TEMP_CONF
fi
sed -i 's/^bridge=.*/bridge=br0/' /etc/hostapd.conf
;;
# NAT
1)
sed -i '/^#/ d' $TEMP_CONF
debconf-apt-progress -- apt-get -qq -y --no-install-recommends install dnsmasq iptables
echo -e "\nallow-hotplug $WIRELESS_ADAPTER\niface $WIRELESS_ADAPTER inet static " >> $TEMP_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
# create new configuration
echo "interface=$WIRELESS_ADAPTER # Use interface $WIRELESS_ADAPTER" > /etc/dnsmasq.conf
echo "listen-address=172.24.1.1 # Explicitly specify the address to listen on" >> /etc/dnsmasq.conf
echo "bind-interfaces # Bind to the interface to make sure we aren't sending \
things elsewhere" >> /etc/dnsmasq.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" \
>> /etc/dnsmasq.conf
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 \
a 12 hour lease time" >> /etc/dnsmasq.conf
# - Enable IPv4 forwarding
sed -i "/net.ipv4.ip_forward=/c\net.ipv4.ip_forward=1" /etc/sysctl.conf
echo 1 > /proc/sys/net/ipv4/ip_forward
# - Apply iptables
iptables -t nat -A POSTROUTING -o $DEFAULT_ADAPTER -j MASQUERADE
iptables -A FORWARD -i $DEFAULT_ADAPTER -o $WIRELESS_ADAPTER -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i $WIRELESS_ADAPTER -o $DEFAULT_ADAPTER -j ACCEPT
# - Save IP tables, applied during ifup in /etc/network/interfaces.
iptables-save > /etc/iptables.ipv4.nat
service dnsmasq restart
sed -i 's/^bridge=.*/#&/' /etc/hostapd.conf
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
;;
......
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