This repository has been archived on 2024-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
orion/use.go

58 lines
1.2 KiB
Go
Raw Normal View History

package main
import (
"forge.cadoles.com/Pyxis/orion/openwrt"
)
func main() {
uci := openwrt.NewUCI()
uci.LoadWirelessConf()
wifaces := uci.GetWifiIfaces()
wDevices := uci.GetWifiDevices()
PyxisDevice := wDevices[0]
ClientDevice := wDevices[1]
for _, iface := range wifaces {
iface.Delete(uci)
}
// Main Pyxis Interface
pyxis := openwrt.NewUCIWirelessInterface()
pyxis.Name = "Pyxis-Network"
pyxis.Network = "pyxis"
pyxis.Index = 0
pyxis.Ssid = "Pyxis"
pyxis.SysDevName = "wlan0"
pyxis.Encryption = "psk2"
pyxis.Key = "xxxxxxxxx"
pyxis.Device = PyxisDevice["Device"]
pyxis.DevicePath = PyxisDevice["Path"]
pyxis.Mode = "ap"
_ = pyxis.Create(uci)
_ = pyxis.Save(uci)
// Client Interface
client := openwrt.NewUCIWirelessInterface()
client.Name = "Client-Network"
client.Index = 1
client.SysDevName = "wlan1"
client.Device = ClientDevice["Device"]
client.DevicePath = ClientDevice["Path"]
client.Mode = "sta"
_ = client.Create(uci)
_ = client.SysAdd(uci)
_ = client.Up(uci)
scan := client.Scan()
for _, elm := range scan {
if elm.Ssid == "Cadoles" {
client.Connect(uci, elm, "xxxxxx")
}
}
dhcp := openwrt.NewDhcpClient(client.SysDevName)
dhcp.AskForIP()
return
}