Merge ~morphis/snappy-hwe-snaps/+git/wifi-ap:improve-wizard into ~snappy-hwe-team/snappy-hwe-snaps/+git/wifi-ap:master

Proposed by Simon Fels
Status: Merged
Approved by: Simon Fels
Approved revision: 492e3263bfee589b41777790e700bf5f653b5077
Merged at revision: 4d85a3cf2dcbc9fcb749320a45bf64549c3c7251
Proposed branch: ~morphis/snappy-hwe-snaps/+git/wifi-ap:improve-wizard
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/wifi-ap:master
Diff against target: 274 lines (+89/-28)
5 files modified
bin/ap.sh (+16/-9)
bin/helper.sh (+6/-0)
cmd/client/cmd_config.go (+16/-9)
cmd/client/cmd_wizard.go (+47/-10)
snapcraft.yaml (+4/-0)
Reviewer Review Type Date Requested Status
System Enablement Bot continuous-integration Approve
Konrad Zapałowicz (community) Approve
Review via email: mp+308686@code.launchpad.net

Description of the change

Improve several things

 * Better wording for the wizard
 * Add support for disabling connection sharing
 * A few script improvements

To post a comment you must log in.
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Konrad Zapałowicz (kzapalowicz) wrote :

Lgtm

review: Approve
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Matteo Croce (teknoraver) :
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Simon Fels (morphis) :
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/bin/ap.sh b/bin/ap.sh
index 6c26b30..89750fa 100755
--- a/bin/ap.sh
+++ b/bin/ap.sh
@@ -38,9 +38,10 @@ if ! ifconfig $WIFI_INTERFACE ; then
38 exit 138 exit 1
39fi39fi
4040
41shutdown() {41cleanup_on_exit() {
42 DNSMASQ_PID=$(cat $SNAP_DATA/dnsmasq.pid)42 DNSMASQ_PID=$(cat $SNAP_DATA/dnsmasq.pid)
43 kill -TERM $DNSMASQ_PID43 # If dnsmasq is already gone don't error out here
44 kill -TERM $DNSMASQ_PID || true
44 wait $DNSMASQ_PID45 wait $DNSMASQ_PID
4546
46 iface=$WIFI_INTERFACE47 iface=$WIFI_INTERFACE
@@ -48,7 +49,7 @@ shutdown() {
48 iface=$DEFAULT_ACCESS_POINT_INTERFACE49 iface=$DEFAULT_ACCESS_POINT_INTERFACE
49 fi50 fi
5051
51 if [ "$SHARE_NETWORK_INTERFACE" != "none" ] ; then52 if [ $SHARE_DISABLED -eq 0 ] ; then
52 # flush forwarding rules out53 # flush forwarding rules out
53 iptables --table nat --delete POSTROUTING --out-interface $SHARE_NETWORK_INTERFACE -j MASQUERADE54 iptables --table nat --delete POSTROUTING --out-interface $SHARE_NETWORK_INTERFACE -j MASQUERADE
54 iptables --delete FORWARD --in-interface $iface -j ACCEPT55 iptables --delete FORWARD --in-interface $iface -j ACCEPT
@@ -58,6 +59,13 @@ shutdown() {
58 if [ "$WIFI_INTERFACE_MODE" == "virtual" ] ; then59 if [ "$WIFI_INTERFACE_MODE" == "virtual" ] ; then
59 $SNAP/bin/iw dev $iface del60 $SNAP/bin/iw dev $iface del
60 fi61 fi
62
63 if [ is_nm_running ] ; then
64 # Hand interface back to network-manager. This will also trigger the
65 # auto connection process inside network-manager to get connected
66 # with the previous network.
67 $SNAP/bin/nmcli d set $iface managed yes
68 fi
61}69}
6270
63iface=$WIFI_INTERFACE71iface=$WIFI_INTERFACE
@@ -88,8 +96,7 @@ if [ "$WIFI_INTERFACE_MODE" = "direct" ] ; then
88fi96fi
8997
9098
91nm_status=`$SNAP/bin/nmcli -t -f RUNNING general`99if [ is_nm_running ] ; then
92if [ "$nm_status" = "running" ] ; then
93 # Prevent network-manager from touching the interface we want to use. If100 # Prevent network-manager from touching the interface we want to use. If
94 # network-manager was configured to use the interface its nothing we want101 # network-manager was configured to use the interface its nothing we want
95 # to prevent here as this is how the user configured the system.102 # to prevent here as this is how the user configured the system.
@@ -106,7 +113,7 @@ if [ $? -ne 0 ] ; then
106 $SNAP/bin/iw dev $iface del113 $SNAP/bin/iw dev $iface del
107 fi114 fi
108115
109 if [ "$nm_status" = "running" ] ; then116 if [ is_nm_running ] ; then
110 # Hand interface back to network-manager. This will also trigger the117 # Hand interface back to network-manager. This will also trigger the
111 # auto connection process inside network-manager to get connected118 # auto connection process inside network-manager to get connected
112 # with the previous network.119 # with the previous network.
@@ -120,7 +127,7 @@ fi
120ifconfig $iface $WIFI_ADDRESS netmask $WIFI_NETMASK127ifconfig $iface $WIFI_ADDRESS netmask $WIFI_NETMASK
121sleep 2128sleep 2
122129
123if [ "$SHARE_NETWORK_INTERFACE" != "none" ] ; then130if [ $SHARE_DISABLED -eq 0 ] ; then
124 # Enable NAT to forward our network connection131 # Enable NAT to forward our network connection
125 iptables --table nat --append POSTROUTING --out-interface $SHARE_NETWORK_INTERFACE -j MASQUERADE132 iptables --table nat --append POSTROUTING --out-interface $SHARE_NETWORK_INTERFACE -j MASQUERADE
126 iptables --append FORWARD --in-interface $iface -j ACCEPT133 iptables --append FORWARD --in-interface $iface -j ACCEPT
@@ -198,9 +205,9 @@ function exit_handler() {
198 # Wait until hostapd is correctly terminated before we continue205 # Wait until hostapd is correctly terminated before we continue
199 # doing anything206 # doing anything
200 wait $HOSTAPD_PID207 wait $HOSTAPD_PID
201 shutdown208 cleanup_on_exit
202 exit 0209 exit 0
203}210}
204211
205wait $HOSTAPD_PID212wait $HOSTAPD_PID
206shutdown
207\ No newline at end of file213\ No newline at end of file
214cleanup_on_exit
diff --git a/bin/helper.sh b/bin/helper.sh
index df56715..5ad68f5 100644
--- a/bin/helper.sh
+++ b/bin/helper.sh
@@ -50,3 +50,9 @@ generate_dnsmasq_config() {
50 EOF50 EOF
51 } > $151 } > $1
52}52}
53
54is_nm_running() {
55 nm_status=`$SNAP/bin/nmcli -t -f RUNNING general`
56 [ "$nm_status" = "running" ] && return 1
57 return 0
58}
diff --git a/cmd/client/cmd_config.go b/cmd/client/cmd_config.go
index c801b47..8a82f4a 100644
--- a/cmd/client/cmd_config.go
+++ b/cmd/client/cmd_config.go
@@ -20,6 +20,7 @@ import (
20 "encoding/json"20 "encoding/json"
21 "fmt"21 "fmt"
22 "os"22 "os"
23 "sort"
23)24)
2425
25type setCommand struct{}26type setCommand struct{}
@@ -44,21 +45,27 @@ func (cmd *setCommand) Execute(args []string) error {
44type getCommand struct{}45type getCommand struct{}
4546
46func (cmd *getCommand) Execute(args []string) error {47func (cmd *getCommand) Execute(args []string) error {
47 if len(args) != 1 {
48 return fmt.Errorf("usage: %s get <key>\n", os.Args[0])
49 }
50
51 response, err := sendHTTPRequest(getServiceConfigurationURI(), "GET", nil)48 response, err := sendHTTPRequest(getServiceConfigurationURI(), "GET", nil)
52 if err != nil {49 if err != nil {
53 return err50 return err
54 }51 }
5552
56 wantedKey := args[0]53 if len(args) == 1 {
5754 wantedKey := args[0]
58 if val, ok := response.Result[wantedKey]; ok {55 if val, ok := response.Result[wantedKey]; ok {
59 fmt.Fprintf(os.Stdout, "%s\n", val)56 fmt.Fprintf(os.Stdout, "%s\n", val)
57 } else {
58 return fmt.Errorf("Config item '%s' does not exist", wantedKey)
59 }
60 } else {60 } else {
61 return fmt.Errorf("Config item '%s' does not exist", wantedKey)61 sortedKeys := make([]string, 0, len(response.Result))
62 for key, _ := range response.Result {
63 sortedKeys = append(sortedKeys, key)
64 }
65 sort.Strings(sortedKeys)
66 for n := range sortedKeys {
67 fmt.Fprintf(os.Stdout, "%s: %s\n", sortedKeys[n], response.Result[sortedKeys[n]])
68 }
62 }69 }
6370
64 return nil71 return nil
diff --git a/cmd/client/cmd_wizard.go b/cmd/client/cmd_wizard.go
index 0837135..5ba1357 100644
--- a/cmd/client/cmd_wizard.go
+++ b/cmd/client/cmd_wizard.go
@@ -63,9 +63,19 @@ type wizardStep func(map[string]string, *bufio.Reader) error
63var allSteps = [...]wizardStep{63var allSteps = [...]wizardStep{
64 // determine the WiFi interface64 // determine the WiFi interface
65 func(configuration map[string]string, reader *bufio.Reader) error {65 func(configuration map[string]string, reader *bufio.Reader) error {
66 fmt.Println("What is the name of the wireless interface you want to use?")
67 ifaces := findExistingInterfaces(true)66 ifaces := findExistingInterfaces(true)
68 fmt.Print("Available interfaces are: " + strings.Join(ifaces, ", ") + ": ")67 if len(ifaces) == 0 {
68 return fmt.Errorf("There are no valid wireless network interfaces available")
69 } else if len(ifaces) == 1 {
70 fmt.Println("Automatically selected only available wireless network interface " + ifaces[0])
71 return nil
72 }
73 fmt.Print("Which wireless interface you want to use? ")
74 ifacesVerb := "are"
75 if len(ifaces) == 1 {
76 ifacesVerb = "is"
77 }
78 fmt.Printf("Available %s %s:", ifacesVerb, strings.Join(ifaces, ", "))
69 iface := readUserInput(reader)79 iface := readUserInput(reader)
70 if re := regexp.MustCompile("^[[:alnum:]]+$"); !re.MatchString(iface) {80 if re := regexp.MustCompile("^[[:alnum:]]+$"); !re.MatchString(iface) {
71 return fmt.Errorf("Invalid interface name '%s' given", iface)81 return fmt.Errorf("Invalid interface name '%s' given", iface)
@@ -77,7 +87,7 @@ var allSteps = [...]wizardStep{
7787
78 // Ask for WiFi ESSID88 // Ask for WiFi ESSID
79 func(configuration map[string]string, reader *bufio.Reader) error {89 func(configuration map[string]string, reader *bufio.Reader) error {
80 fmt.Print("Insert the ESSID of your access point: ")90 fmt.Print("Which SSID you want to use for the access point: ")
81 iface := readUserInput(reader)91 iface := readUserInput(reader)
82 if len(iface) == 0 || len(iface) > 31 {92 if len(iface) == 0 || len(iface) > 31 {
83 return fmt.Errorf("ESSID length must be between 1 and 31 characters")93 return fmt.Errorf("ESSID length must be between 1 and 31 characters")
@@ -89,7 +99,7 @@ var allSteps = [...]wizardStep{
8999
90 // Select WiFi encryption type100 // Select WiFi encryption type
91 func(configuration map[string]string, reader *bufio.Reader) error {101 func(configuration map[string]string, reader *bufio.Reader) error {
92 fmt.Print("Do you want to protect your network with a WPA2 password? (y/n) ")102 fmt.Print("Do you want to protect your network with a WPA2 password instead of staying open for everyone? (y/n) ")
93 switch resp := strings.ToLower(readUserInput(reader)); resp {103 switch resp := strings.ToLower(readUserInput(reader)); resp {
94 case "y":104 case "y":
95 configuration["wifi.security"] = "wpa2"105 configuration["wifi.security"] = "wpa2"
@@ -107,7 +117,7 @@ var allSteps = [...]wizardStep{
107 if configuration["wifi.security"] == "open" {117 if configuration["wifi.security"] == "open" {
108 return nil118 return nil
109 }119 }
110 fmt.Print("Insert your WPA2 passphrase: ")120 fmt.Print("Please enter the WPA2 passphrase: ")
111 key := readUserInput(reader)121 key := readUserInput(reader)
112 if len(key) < 8 || len(key) > 63 {122 if len(key) < 8 || len(key) > 63 {
113 return fmt.Errorf("WPA2 passphrase must be between 8 and 63 characters")123 return fmt.Errorf("WPA2 passphrase must be between 8 and 63 characters")
@@ -151,9 +161,10 @@ var allSteps = [...]wizardStep{
151 }161 }
152162
153 fmt.Printf("How many host do you want your DHCP pool to hold to? (1-%d) ", maxpoolsize)163 fmt.Printf("How many host do you want your DHCP pool to hold to? (1-%d) ", maxpoolsize)
154 inputhost, err := strconv.ParseUint(readUserInput(reader), 10, 8)164 input := readUserInput(reader)
165 inputhost, err := strconv.ParseUint(input, 10, 8)
155 if err != nil {166 if err != nil {
156 return err167 return fmt.Errorf("Invalid answer: %s", input)
157 }168 }
158 if byte(inputhost) > maxpoolsize {169 if byte(inputhost) > maxpoolsize {
159 return fmt.Errorf("%d is bigger than the maximum pool size %d", inputhost, maxpoolsize)170 return fmt.Errorf("%d is bigger than the maximum pool size %d", inputhost, maxpoolsize)
@@ -172,11 +183,38 @@ var allSteps = [...]wizardStep{
172 return nil183 return nil
173 },184 },
174185
186 // Enable or disable connection sharing
187 func(configuration map[string]string, reader *bufio.Reader) error {
188 fmt.Print("Do you want to enable connection sharing? (y/n) ")
189 switch resp := strings.ToLower(readUserInput(reader)); resp {
190 case "y":
191 configuration["share.disabled"] = "0"
192 case "n":
193 configuration["share.disabled"] = "1"
194 default:
195 return fmt.Errorf("Invalid answer: %s", resp)
196 }
197
198 return nil
199 },
200
175 // Select the wired interface to share201 // Select the wired interface to share
176 func(configuration map[string]string, reader *bufio.Reader) error {202 func(configuration map[string]string, reader *bufio.Reader) error {
177 fmt.Println("What is the wired interface do you want to share?")203 if configuration["share.disabled"] == "1" {
204 return nil
205 }
178 ifaces := findExistingInterfaces(false)206 ifaces := findExistingInterfaces(false)
179 fmt.Print("Available interfaces are: " + strings.Join(ifaces, ", ") + ": ")207 if len(ifaces) == 0 {
208 fmt.Println("No network interface available which's connection can be shared. Disabling connection sharing.")
209 configuration["share.disabled"] = "1"
210 return nil
211 }
212 ifacesVerb := "are"
213 if len(ifaces) == 1 {
214 ifacesVerb = "is"
215 }
216 fmt.Println("Which network interface you want to use for connection sharing?")
217 fmt.Printf("Available %s %s: ", ifacesVerb, strings.Join(ifaces, ", "))
180 iface := readUserInput(reader)218 iface := readUserInput(reader)
181 if re := regexp.MustCompile("^[[:alnum:]]+$"); !re.MatchString(iface) {219 if re := regexp.MustCompile("^[[:alnum:]]+$"); !re.MatchString(iface) {
182 return fmt.Errorf("Invalid interface name '%s' given", iface)220 return fmt.Errorf("Invalid interface name '%s' given", iface)
@@ -236,7 +274,6 @@ func (cmd *wizardCommand) Execute(args []string) error {
236 }274 }
237 }275 }
238276
239 // fmt.Println("configuration: ", configuration)
240 return applyConfiguration(configuration)277 return applyConfiguration(configuration)
241}278}
242279
diff --git a/snapcraft.yaml b/snapcraft.yaml
index c742c14..5252576 100644
--- a/snapcraft.yaml
+++ b/snapcraft.yaml
@@ -23,6 +23,10 @@ apps:
23 command: bin/client config23 command: bin/client config
24 plugs:24 plugs:
25 - network25 - network
26 setup-wizard:
27 command: bin/client wizard
28 plugs:
29 - network
26 management-service:30 management-service:
27 command: bin/service31 command: bin/service
28 daemon: simple32 daemon: simple

Subscribers

People subscribed via source and target branches

to all changes: