Report hotspot config
This commit is contained in:
parent
17d665e21a
commit
c443fce24f
8 changed files with 244 additions and 160 deletions
|
|
@ -4,6 +4,8 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/nemunaire/repeater/internal/models"
|
||||
)
|
||||
|
|
@ -36,12 +38,74 @@ rsn_pairwise=CCMP
|
|||
|
||||
// Start starts the hotspot
|
||||
func Start() error {
|
||||
cmd := exec.Command("systemctl", "start", "hostapd")
|
||||
cmd := exec.Command("/etc/init.d/hostapd", "start")
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
// Stop stops the hotspot
|
||||
func Stop() error {
|
||||
cmd := exec.Command("systemctl", "stop", "hostapd")
|
||||
cmd := exec.Command("/etc/init.d/hostapd", "stop")
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
// Status checks if the hotspot is running.
|
||||
// Returns nil if the service is running, or an error if it's stopped or crashed.
|
||||
func Status() error {
|
||||
cmd := exec.Command("/etc/init.d/hostapd", "status")
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
// GetDetailedStatus retrieves detailed status information from hostapd_cli.
|
||||
// Returns nil if hostapd is not running or if there's an error.
|
||||
func GetDetailedStatus() *models.HotspotStatus {
|
||||
cmd := exec.Command("hostapd_cli", "status")
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
status := &models.HotspotStatus{}
|
||||
lines := strings.Split(string(output), "\n")
|
||||
|
||||
for _, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "" || strings.HasPrefix(line, "Selected interface") {
|
||||
continue
|
||||
}
|
||||
|
||||
parts := strings.SplitN(line, "=", 2)
|
||||
if len(parts) != 2 {
|
||||
continue
|
||||
}
|
||||
|
||||
key := strings.TrimSpace(parts[0])
|
||||
value := strings.TrimSpace(parts[1])
|
||||
|
||||
switch key {
|
||||
case "state":
|
||||
status.State = value
|
||||
case "channel":
|
||||
if ch, err := strconv.Atoi(value); err == nil {
|
||||
status.Channel = ch
|
||||
}
|
||||
case "freq":
|
||||
if freq, err := strconv.Atoi(value); err == nil {
|
||||
status.Frequency = freq
|
||||
}
|
||||
case "ssid[0]":
|
||||
status.SSID = value
|
||||
case "bssid[0]":
|
||||
status.BSSID = value
|
||||
case "num_sta[0]":
|
||||
if num, err := strconv.Atoi(value); err == nil {
|
||||
status.NumStations = num
|
||||
}
|
||||
case "hw_mode":
|
||||
status.HWMode = value
|
||||
case "country_code":
|
||||
status.CountryCode = value
|
||||
}
|
||||
}
|
||||
|
||||
return status
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue