Report hotspot config
This commit is contained in:
parent
17d665e21a
commit
c443fce24f
8 changed files with 244 additions and 160 deletions
|
|
@ -82,11 +82,11 @@ func ConfigureHotspot(c *gin.Context) {
|
|||
|
||||
// ToggleHotspot handles hotspot enable/disable
|
||||
func ToggleHotspot(c *gin.Context, status *models.SystemStatus) {
|
||||
status.HotspotEnabled = !status.HotspotEnabled
|
||||
enabled := status.HotspotEnabled
|
||||
// Determine current state
|
||||
isEnabled := status.HotspotStatus != nil && status.HotspotStatus.State == "ENABLED"
|
||||
|
||||
var err error
|
||||
if enabled {
|
||||
if !isEnabled {
|
||||
err = hotspot.Start()
|
||||
logging.AddLog("Hotspot", "Hotspot activé")
|
||||
} else {
|
||||
|
|
@ -100,7 +100,10 @@ func ToggleHotspot(c *gin.Context, status *models.SystemStatus) {
|
|||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"enabled": enabled})
|
||||
// Update status immediately
|
||||
status.HotspotStatus = hotspot.GetDetailedStatus()
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"enabled": !isEnabled})
|
||||
}
|
||||
|
||||
// GetDevices returns connected devices
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/nemunaire/repeater/internal/api"
|
||||
"github.com/nemunaire/repeater/internal/config"
|
||||
"github.com/nemunaire/repeater/internal/device"
|
||||
"github.com/nemunaire/repeater/internal/hotspot"
|
||||
"github.com/nemunaire/repeater/internal/logging"
|
||||
"github.com/nemunaire/repeater/internal/models"
|
||||
"github.com/nemunaire/repeater/internal/wifi"
|
||||
|
|
@ -32,7 +33,7 @@ func New(assets embed.FS) *App {
|
|||
Status: models.SystemStatus{
|
||||
Connected: false,
|
||||
ConnectedSSID: "",
|
||||
HotspotEnabled: true,
|
||||
HotspotStatus: nil,
|
||||
ConnectedCount: 0,
|
||||
DataUsage: 0.0,
|
||||
Uptime: 0,
|
||||
|
|
@ -131,6 +132,9 @@ func (a *App) periodicStatusUpdate() {
|
|||
a.Status.ConnectedSSID = wifi.GetConnectedSSID()
|
||||
a.Status.Uptime = getSystemUptime()
|
||||
|
||||
// Get detailed hotspot status
|
||||
a.Status.HotspotStatus = hotspot.GetDetailedStatus()
|
||||
|
||||
// Get network data usage for WiFi interface
|
||||
if a.Config != nil {
|
||||
rxBytes, txBytes := getInterfaceBytes(a.Config.WifiInterface)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,11 +26,23 @@ type HotspotConfig struct {
|
|||
Channel int `json:"channel"`
|
||||
}
|
||||
|
||||
// HotspotStatus represents detailed hotspot status
|
||||
type HotspotStatus struct {
|
||||
State string `json:"state"` // ENABLED, DISABLED, etc.
|
||||
SSID string `json:"ssid"` // Current SSID being broadcast
|
||||
BSSID string `json:"bssid"` // MAC address of the AP
|
||||
Channel int `json:"channel"` // Current channel
|
||||
Frequency int `json:"frequency"` // Frequency in MHz
|
||||
NumStations int `json:"numStations"` // Number of connected stations
|
||||
HWMode string `json:"hwMode"` // Hardware mode (g, a, n, ac, etc.)
|
||||
CountryCode string `json:"countryCode"` // Country code
|
||||
}
|
||||
|
||||
// SystemStatus represents overall system status
|
||||
type SystemStatus struct {
|
||||
Connected bool `json:"connected"`
|
||||
ConnectedSSID string `json:"connectedSSID"`
|
||||
HotspotEnabled bool `json:"hotspotEnabled"`
|
||||
HotspotStatus *HotspotStatus `json:"hotspotStatus,omitempty"` // Detailed hotspot status
|
||||
ConnectedCount int `json:"connectedCount"`
|
||||
DataUsage float64 `json:"dataUsage"`
|
||||
Uptime int64 `json:"uptime"`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue