Bob Mottram 9 lat temu
rodzic
commit
af37d67bb2
2 zmienionych plików z 121 dodań i 5 usunięć
  1. 24
    5
      src/freedombone-controlpanel
  2. 97
    0
      src/freedombone-wifi

+ 24
- 5
src/freedombone-controlpanel Wyświetl plik

@@ -64,11 +64,15 @@ WIFI_INTERFACE=wlan0
64 64
 WIFI_SSID=
65 65
 WIFI_TYPE='wpa2-psk'
66 66
 WIFI_PASSPHRASE=
67
+WIFI_HOTSPOT='no'
67 68
 
68 69
 USB_DRIVE=sdb
69 70
 # get default USB from config file
70 71
 CONFIGURATION_FILE=/root/${PROJECT_NAME}.cfg
71 72
 if [ -f $CONFIGURATION_FILE ]; then
73
+    if grep -q "WIFI_HOTSPOT=" $CONFIGURATION_FILE; then
74
+        WIFI_HOTSPOT=$(cat $CONFIGURATION_FILE | grep "WIFI_HOTSPOT=" | awk -F '=' '{print $2}')
75
+    fi
72 76
     if grep -q "WIFI_INTERFACE=" $CONFIGURATION_FILE; then
73 77
         WIFI_INTERFACE=$(cat $CONFIGURATION_FILE | grep "WIFI_INTERFACE=" | awk -F '=' '{print $2}')
74 78
     fi
@@ -1672,6 +1676,7 @@ Enter a static local IP address for this system.\n\nIt will typically be 192.168
1672 1676
 }
1673 1677
 
1674 1678
 function wifi_settings {
1679
+    PREV_WIFI_HOTSPOT=$WIFI_HOTSPOT
1675 1680
     PREV_WIFI_INTERFACE=$WIFI_INTERFACE
1676 1681
     PREV_WIFI_SSID=$WIFI_SSID
1677 1682
     PREV_WIFI_TYPE=$WIFI_TYPE
@@ -1681,11 +1686,12 @@ function wifi_settings {
1681 1686
     trap "rm -f $data" 0 1 2 5 15
1682 1687
     dialog --backtitle $"Freedombone Control Panel" \
1683 1688
            --title $"Wifi Settings" \
1684
-           --form $"\nIf you wish to use wifi rather than wired ethernet then enter the details below, otherwise just select Ok:" 15 55 5 \
1689
+           --form $"\nIf you wish to use wifi rather than wired ethernet then enter the details below, otherwise just select Ok:" 16 55 6 \
1685 1690
            $"Interface:" 1 1 "$WIFI_INTERFACE" 1 16 16 15 \
1686 1691
            $"SSID:" 2 1 "$WIFI_SSID" 2 16 30 30 \
1687 1692
            $"Type:" 3 1 "$WIFI_TYPE" 3 16 16 15 \
1688 1693
            $"Passphrase:" 4 1 "$WIFI_PASSPHRASE" 4 16 30 30 \
1694
+           $"Hotspot:" 5 1 "$WIFI_HOTSPOT" 5 16 16 15 \
1689 1695
            2> $data
1690 1696
     sel=$?
1691 1697
     case $sel in
@@ -1696,6 +1702,7 @@ function wifi_settings {
1696 1702
     NEW_WIFI_SSID=$(cat $data | sed -n 2p)
1697 1703
     NEW_WIFI_TYPE=$(cat $data | sed -n 3p)
1698 1704
     NEW_WIFI_PASSPHRASE=$(cat $data | sed -n 4p)
1705
+    NEW_WIFI_HOTSPOT=$(cat $data | sed -n 5p)
1699 1706
 
1700 1707
     if [[ $NEW_WIFI_TYPE != 'none' && $NEW_WIFI_TYPE != 'wpa2-psk' ]]; then
1701 1708
         return
@@ -1707,10 +1714,17 @@ function wifi_settings {
1707 1714
         fi
1708 1715
         if [ ${#NEW_WIFI_PASSPHRASE} -lt 2 ]; then
1709 1716
             return
1710
-        fi  
1711
-        ${PROJECT_NAME}-wifi -i $NEW_WIFI_INTERFACE -s $NEW_WIFI_SSID -t $NEW_WIFI_TYPE -p $NEW_WIFI_PASSPHRASE
1717
+        fi
1718
+
1719
+        HOTSPOT='no'
1720
+        if [[ $NEW_WIFI_HOTSPOT == $'Y' || $NEW_WIFI_HOTSPOT == $'yes' || $NEW_WIFI_HOTSPOT == $'y' ]]; then
1721
+            apt-get -y install hostapd bridge-utils
1722
+            HOTSPOT='yes'
1723
+        fi
1724
+        
1725
+        ${PROJECT_NAME}-wifi -i $NEW_WIFI_INTERFACE -s $NEW_WIFI_SSID -t $NEW_WIFI_TYPE -p $NEW_WIFI_PASSPHRASE --hotspot $HOTSPOT
1712 1726
     else
1713
-        ${PROJECT_NAME}-wifi -i $NEW_WIFI_INTERFACE -s $NEW_WIFI_SSID -t $NEW_WIFI_TYPE     
1727
+        ${PROJECT_NAME}-wifi -i $NEW_WIFI_INTERFACE -s $NEW_WIFI_SSID -t $NEW_WIFI_TYPE --hotspot $HOTSPOT
1714 1728
     fi
1715 1729
 
1716 1730
     if [[ $PREV_WIFI_INTERFACE != $NEW_WIFI_INTERFACE || $PREV_WIFI_SSID != $NEW_WIFI_SSID || $PREV_WIFI_TYPE != $NEW_WIFI_TYPE || $PREV_WIFI_PASSPHRASE != $NEW_WIFI_PASSPHRASE ]]; then
@@ -1750,8 +1764,13 @@ function wifi_settings {
1750 1764
         else
1751 1765
             sed -i "s|WIFI_PASSPHRASE=.*|WIFI_PASSPHRASE=$WIFI_PASSPHRASE|g" $CONFIGURATION_FILE
1752 1766
         fi
1767
+        if ! grep -q "WIFI_HOTSPOT=" $CONFIGURATION_FILE; then
1768
+            echo "WIFI_HOTSPOT=$WIFI_HOTSPOT" >> $CONFIGURATION_FILE
1769
+        else
1770
+            sed -i "s|WIFI_HOTSPOT=.*|WIFI_HOTSPOT=$WIFI_HOTSPOT|g" $CONFIGURATION_FILE
1771
+        fi
1753 1772
         
1754
-        systemctl restart networking
1773
+        systemctl restart network-manager
1755 1774
     fi  
1756 1775
 }
1757 1776
 

+ 97
- 0
src/freedombone-wifi Wyświetl plik

@@ -40,6 +40,7 @@ WIFI_INTERFACE=wlan0
40 40
 WIFI_TYPE='wpa2-psk'
41 41
 WIFI_SSID=
42 42
 WIFI_PASSPHRASE=
43
+WIFI_HOTSPOT='no'
43 44
 
44 45
 function wifi_get_psk {
45 46
     ssid=$1
@@ -49,6 +50,90 @@ function wifi_get_psk {
49 50
     echo $psk
50 51
 }
51 52
 
53
+function hotspot_off {
54
+    if [ ! -f /etc/hostapd/hostapd.conf ]; then
55
+        return
56
+    fi
57
+    systemctl stop hostapd
58
+
59
+    rm /etc/hostapd/hostapd.conf
60
+
61
+    if [ -f /etc/network/interfaces_old ]; then
62
+        cp /etc/network/interfaces_old /etc/network/interfaces
63
+    else
64
+        echo '# interfaces(5) file used by ifup(8) and ifdown(8)' > /etc/network/interfaces
65
+        echo '# Include files from /etc/network/interfaces.d:' >> /etc/network/interfaces
66
+        echo 'source-directory /etc/network/interfaces.d' >> /etc/network/interfaces
67
+    fi
68
+    
69
+    systemctl restart network-manager
70
+}
71
+
72
+function hotspot_on {
73
+    if [ ! -f /etc/default/hostapd ]; then
74
+        echo $'/etc/default/hostapd was not found'
75
+        exit 67241
76
+    fi
77
+    if [ ${#WIFI_PASSPHRASE} -lt 8 ]; then
78
+        echo $'Wifi hotspot passphrase is too short'
79
+        exit 25719
80
+    fi
81
+    
82
+    sed -i 's|#DAEMON_CONF=.*|DAEMON_CONF="/etc/hostapd/hostapd.conf"|g' /etc/default/hostapd
83
+
84
+    echo '### Wireless network name ###' > /etc/hostapd/hostapd.conf
85
+    echo "interface=$WIFI_INTERFACE" >> /etc/hostapd/hostapd.conf
86
+    echo '' >> /etc/hostapd/hostapd.conf
87
+    echo '### Set your bridge name ###' >> /etc/hostapd/hostapd.conf
88
+    echo 'bridge=br0' >> /etc/hostapd/hostapd.conf
89
+    echo '' >> /etc/hostapd/hostapd.conf
90
+    echo 'driver=nl80211' >> /etc/hostapd/hostapd.conf
91
+    echo "country_code=UK" >> /etc/hostapd/hostapd.conf
92
+    echo "ssid=$WIFI_SSID" >> /etc/hostapd/hostapd.conf
93
+    echo 'hw_mode=g' >> /etc/hostapd/hostapd.conf
94
+    echo 'channel=6' >> /etc/hostapd/hostapd.conf
95
+    echo 'wpa=2' >> /etc/hostapd/hostapd.conf
96
+    echo "wpa_passphrase=$WIFI_PASSPHRASE" >> /etc/hostapd/hostapd.conf
97
+    echo '' >> /etc/hostapd/hostapd.conf
98
+    echo '## Key management algorithms ##' >> /etc/hostapd/hostapd.conf
99
+    echo 'wpa_key_mgmt=WPA-PSK' >> /etc/hostapd/hostapd.conf
100
+    echo '' >> /etc/hostapd/hostapd.conf
101
+    echo '## Set cipher suites (encryption algorithms) ##' >> /etc/hostapd/hostapd.conf
102
+    echo '## TKIP = Temporal Key Integrity Protocol' >> /etc/hostapd/hostapd.conf
103
+    echo '## CCMP = AES in Counter mode with CBC-MAC' >> /etc/hostapd/hostapd.conf
104
+    echo 'wpa_pairwise=TKIP' >> /etc/hostapd/hostapd.conf
105
+    echo 'rsn_pairwise=CCMP' >> /etc/hostapd/hostapd.conf
106
+    echo '' >> /etc/hostapd/hostapd.conf
107
+    echo '## Shared Key Authentication ##'
108
+    echo 'auth_algs=1'
109
+    echo '' >> /etc/hostapd/hostapd.conf
110
+    echo '## Accept all MAC address ###' >> /etc/hostapd/hostapd.conf
111
+    echo 'macaddr_acl=0' >> /etc/hostapd/hostapd.conf
112
+
113
+    if ! grep -q "# Hotspot" /etc/network/interfaces; then
114
+        cp /etc/network/interfaces /etc/network/interfaces_old
115
+    fi
116
+    
117
+    echo '# Hotspot' > /etc/network/interfaces
118
+    echo 'auto lo br0' >> /etc/network/interfaces
119
+    echo 'iface lo inet loopback' >> /etc/network/interfaces
120
+    echo '' >> /etc/network/interfaces
121
+    echo "# wireless $WIFI_INTERFACE" >> /etc/network/interfaces
122
+    echo "allow-hotplug $WIFI_INTERFACE" >> /etc/network/interfaces
123
+    echo "iface $WIFI_INTERFACE inet manual" >> /etc/network/interfaces
124
+    echo '' >> /etc/network/interfaces
125
+    echo '# eth0 connected to the ISP router' >> /etc/network/interfaces
126
+    echo 'allow-hotplug eth0' >> /etc/network/interfaces
127
+    echo 'iface eth0 inet manual' >> /etc/network/interfaces
128
+    echo '' >> /etc/network/interfaces
129
+    echo '# Setup bridge' >> /etc/network/interfaces
130
+    echo 'iface br0 inet static' >> /etc/network/interfaces
131
+    echo "    bridge_ports $WIFI_INTERFACE eth0" >> /etc/network/interfaces
132
+
133
+    systemctl restart network-manager
134
+    systemctl restart hostapd
135
+}
136
+
52 137
 function wifi_wpa2_psk {
53 138
     ssid=$1
54 139
     passphrase=$2
@@ -77,6 +162,7 @@ function show_help {
77 162
     echo $'  -t --type [wpa2-psk|none]        Security type'
78 163
     echo $'  -s --ssid [id]                   Set SSID'
79 164
     echo $'  -p --passphrase [text]           Set passphrase'
165
+    echo $'     --hotspot [yes|no]            Create a hotspot'
80 166
     echo ''
81 167
     exit 0
82 168
 }
@@ -105,6 +191,10 @@ do
105 191
             shift
106 192
             WIFI_PASSPHRASE=${1}            
107 193
             ;;
194
+        --hostpot)
195
+            shift
196
+            WIFI_HOTSPOT=${1}            
197
+            ;;
108 198
         *)
109 199
             # unknown option
110 200
             ;;
@@ -117,6 +207,13 @@ if [ ! $WIFI_SSID ]; then
117 207
     exit 1
118 208
 fi
119 209
 
210
+if [[ $WIFI_HOTSPOT != 'no' ]]; then
211
+    hotspot_on
212
+    exit 0
213
+else
214
+    hotspot_off
215
+fi
216
+
120 217
 if [[ $WIFI_TYPE != 'none' ]]; then
121 218
     if [ ! $WIFI_PASSPHRASE ]; then
122 219
         echo $'No wifi passphrase was given'