47 lines
888 B
Go
47 lines
888 B
Go
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()
|
|
}
|