2020-04-18 11:17:49 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-04-23 13:01:40 +02:00
|
|
|
"fmt"
|
|
|
|
|
2020-04-18 11:17:49 +02:00
|
|
|
"github.com/ngoduykhanh/wireguard-ui/handler"
|
|
|
|
"github.com/ngoduykhanh/wireguard-ui/router"
|
2020-04-23 13:01:40 +02:00
|
|
|
"github.com/ngoduykhanh/wireguard-ui/util"
|
2020-04-18 11:17:49 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2020-04-23 13:01:40 +02:00
|
|
|
// initialize DB
|
|
|
|
err := util.InitDB()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Print("Cannot init database: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// register routes
|
2020-04-18 11:17:49 +02:00
|
|
|
app := router.New()
|
|
|
|
|
2020-04-19 10:50:59 +02:00
|
|
|
app.GET("/", handler.WireGuardClients())
|
2020-04-24 06:22:50 +02:00
|
|
|
app.GET("/login", handler.LoginPage())
|
2020-04-24 13:14:54 +02:00
|
|
|
app.POST("/login", handler.Login())
|
|
|
|
app.GET("/logout", handler.Logout())
|
2020-04-18 11:17:49 +02:00
|
|
|
app.POST("/new-client", handler.NewClient())
|
2020-04-22 12:11:28 +02:00
|
|
|
app.POST("/client/set-status", handler.SetClientStatus())
|
2020-04-18 11:17:49 +02:00
|
|
|
app.POST("/remove-client", handler.RemoveClient())
|
2020-04-19 10:50:59 +02:00
|
|
|
app.GET("/wg-server", handler.WireGuardServer())
|
|
|
|
app.POST("wg-server/interfaces", handler.WireGuardServerInterfaces())
|
2020-04-19 19:15:25 +02:00
|
|
|
app.POST("wg-server/keypair", handler.WireGuardServerKeyPair())
|
2020-04-20 04:54:41 +02:00
|
|
|
app.GET("/global-settings", handler.GlobalSettings())
|
|
|
|
app.POST("/global-settings", handler.GlobalSettingSubmit())
|
2020-04-20 11:50:50 +02:00
|
|
|
app.GET("/api/machine-ips", handler.MachineIPAddresses())
|
2020-04-20 19:26:49 +02:00
|
|
|
app.GET("/api/suggest-client-ips", handler.SuggestIPAllocation())
|
2020-04-23 04:29:44 +02:00
|
|
|
app.GET("/api/apply-wg-config", handler.ApplyServerConfig())
|
2020-04-24 19:33:22 +02:00
|
|
|
app.Logger.Fatal(app.Start("0.0.0.0:5000"))
|
2020-04-18 11:17:49 +02:00
|
|
|
}
|