Skip to content

Commit 8ff8662

Browse files
committed
updated wifi connection
1 parent 4ff2fb5 commit 8ff8662

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

Dockerfile

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,42 @@
1-
FROM golang:1.22 AS builder
1+
# Build stage
2+
FROM golang:1.23 AS buildstage
23

3-
WORKDIR /go/src/go-fula
4+
WORKDIR /go-fula
45

5-
COPY go.mod go.sum ./
6-
RUN go mod download
6+
# Copy go module files and download dependencies
7+
COPY ./go-fula/go.mod ./go-fula/go.sum ./
8+
RUN go mod download -x
79

8-
COPY . .
9-
RUN CGO_ENABLED=0 go build -o /go/bin/blox ./cmd/blox
10+
# Copy the rest of the application source code
11+
COPY ./go-fula/ .
1012

11-
FROM gcr.io/distroless/static-debian11
12-
COPY --from=builder /go/bin/blox /usr/bin/
13+
# Build binaries with CGO disabled for static binaries
14+
RUN CGO_ENABLED=0 GOOS=linux go build -o /app ./cmd/blox && \
15+
CGO_ENABLED=0 GOOS=linux go build -o /wap ./wap/cmd && \
16+
CGO_ENABLED=0 GOOS=linux go build -o /initipfs ./modules/initipfs && \
17+
CGO_ENABLED=0 GOOS=linux go build -o /initipfscluster ./modules/initipfscluster
1318

14-
ENTRYPOINT ["/usr/bin/blox"]
19+
# Final stage
20+
FROM alpine:3.17
21+
22+
# Install necessary packages
23+
RUN apk update && \
24+
apk add --no-cache hostapd iw wireless-tools networkmanager-wifi networkmanager-cli dhcp iptables curl mergerfs --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing
25+
26+
WORKDIR /
27+
28+
# Copy binaries from the build stage
29+
COPY --from=buildstage /app /app
30+
COPY --from=buildstage /wap /wap
31+
COPY --from=buildstage /initipfs /initipfs
32+
COPY --from=buildstage /initipfscluster /initipfscluster
33+
34+
# Copy and set permissions for the startup script
35+
COPY ./go-fula.sh /go-fula.sh
36+
RUN chmod +x /go-fula.sh
37+
38+
# Expose necessary ports
39+
EXPOSE 40001 5001
40+
41+
# Set the entrypoint command
42+
CMD ["/go-fula.sh"]

wap/pkg/wifi/wifi.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type Credentials struct {
6868
func CheckIfIsConnected(ctx context.Context, interfaceName string) error {
6969
switch runtime.GOOS {
7070
case "linux":
71+
// First check if connected to any WiFi network
7172
err := CheckIfIsConnectedWifi(ctx, interfaceName)
7273
if err != nil {
7374
// If not connected via WiFi, try to ping a well-known website
@@ -76,6 +77,13 @@ func CheckIfIsConnected(ctx context.Context, interfaceName string) error {
7677
return fmt.Errorf("wifi not connected and unable to reach internet: %v", err)
7778
}
7879
log.Info("Not connected to WiFi, but can access internet via other means")
80+
} else {
81+
// Check if connected to FxBlox hotspot
82+
stdout, _, err := runCommand(ctx, "nmcli -t -f NAME connection show --active")
83+
if err == nil && strings.Contains(stdout, "FxBlox") {
84+
// If connected to FxBlox hotspot, we're not connected to external WiFi
85+
return fmt.Errorf("connected to FxBlox hotspot, not external WiFi")
86+
}
7987
}
8088
return nil
8189
default:

0 commit comments

Comments
 (0)