Migrate to a better architectured project

This commit is contained in:
nemunaire 2025-10-28 19:23:27 +07:00
commit b1b9eaa028
21 changed files with 2712 additions and 1540 deletions

View file

@ -0,0 +1,47 @@
package hotspot
import (
"fmt"
"os"
"os/exec"
"github.com/nemunaire/repeater/internal/models"
)
const (
AP_INTERFACE = "wlan1"
HOSTAPD_CONF = "/etc/hostapd/hostapd.conf"
)
// Configure updates the hotspot configuration
func Configure(config models.HotspotConfig) error {
hostapdConfig := fmt.Sprintf(`interface=%s
driver=nl80211
ssid=%s
hw_mode=g
channel=%d
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=%s
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
`, AP_INTERFACE, config.SSID, config.Channel, config.Password)
return os.WriteFile(HOSTAPD_CONF, []byte(hostapdConfig), 0644)
}
// Start starts the hotspot
func Start() error {
cmd := exec.Command("systemctl", "start", "hostapd")
return cmd.Run()
}
// Stop stops the hotspot
func Stop() error {
cmd := exec.Command("systemctl", "stop", "hostapd")
return cmd.Run()
}