2020-04-18 09:17:49 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-04-23 11:01:40 +00:00
|
|
|
"fmt"
|
2020-05-21 08:51:24 +00:00
|
|
|
rice "github.com/GeertJohan/go.rice"
|
|
|
|
"github.com/labstack/echo/v4"
|
2020-04-18 09:17:49 +00:00
|
|
|
"github.com/ngoduykhanh/wireguard-ui/handler"
|
|
|
|
"github.com/ngoduykhanh/wireguard-ui/router"
|
2020-04-23 11:01:40 +00:00
|
|
|
"github.com/ngoduykhanh/wireguard-ui/util"
|
2020-05-21 08:51:24 +00:00
|
|
|
"net/http"
|
2020-06-01 06:03:10 +00:00
|
|
|
"time"
|
2020-04-18 09:17:49 +00:00
|
|
|
)
|
|
|
|
|
2020-06-01 06:03:10 +00:00
|
|
|
var appVersion = "development"
|
|
|
|
var gitCommit = "N/A"
|
|
|
|
var gitRef = "N/A"
|
|
|
|
var buildTime = fmt.Sprintf(time.Now().UTC().Format("01-02-2006 15:04:05"))
|
|
|
|
|
2020-04-18 09:17:49 +00:00
|
|
|
func main() {
|
2020-06-01 06:03:10 +00:00
|
|
|
// print app information
|
|
|
|
fmt.Println("Wireguard UI")
|
|
|
|
fmt.Println("App Version\t:", appVersion)
|
|
|
|
fmt.Println("Git Commit\t:", gitCommit)
|
|
|
|
fmt.Println("Git Ref\t\t:", gitRef)
|
|
|
|
fmt.Println("Build Time\t:", buildTime)
|
|
|
|
fmt.Println("Git Repo\t:", "https://github.com/ngoduykhanh/wireguard-ui")
|
|
|
|
|
2020-04-23 11:01:40 +00:00
|
|
|
// initialize DB
|
|
|
|
err := util.InitDB()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Print("Cannot init database: ", err)
|
|
|
|
}
|
|
|
|
|
2020-05-21 08:51:24 +00:00
|
|
|
// create rice box for embedded template
|
|
|
|
tmplBox := rice.MustFindBox("templates")
|
|
|
|
|
|
|
|
// rice file server for assets. "assets" is the folder where the files come from.
|
|
|
|
assetHandler := http.FileServer(rice.MustFindBox("assets").HTTPBox())
|
|
|
|
|
2020-04-23 11:01:40 +00:00
|
|
|
// register routes
|
2020-05-21 08:51:24 +00:00
|
|
|
app := router.New(tmplBox)
|
2020-04-18 09:17:49 +00:00
|
|
|
|
2020-04-19 08:50:59 +00:00
|
|
|
app.GET("/", handler.WireGuardClients())
|
2020-04-24 04:22:50 +00:00
|
|
|
app.GET("/login", handler.LoginPage())
|
2020-04-24 11:14:54 +00:00
|
|
|
app.POST("/login", handler.Login())
|
|
|
|
app.GET("/logout", handler.Logout())
|
2020-04-18 09:17:49 +00:00
|
|
|
app.POST("/new-client", handler.NewClient())
|
2020-04-22 10:11:28 +00:00
|
|
|
app.POST("/client/set-status", handler.SetClientStatus())
|
2020-04-18 09:17:49 +00:00
|
|
|
app.POST("/remove-client", handler.RemoveClient())
|
2020-04-25 09:58:14 +00:00
|
|
|
app.GET("/download", handler.DownloadClient())
|
2020-04-19 08:50:59 +00:00
|
|
|
app.GET("/wg-server", handler.WireGuardServer())
|
|
|
|
app.POST("wg-server/interfaces", handler.WireGuardServerInterfaces())
|
2020-04-19 17:15:25 +00:00
|
|
|
app.POST("wg-server/keypair", handler.WireGuardServerKeyPair())
|
2020-04-20 02:54:41 +00:00
|
|
|
app.GET("/global-settings", handler.GlobalSettings())
|
|
|
|
app.POST("/global-settings", handler.GlobalSettingSubmit())
|
2020-04-20 09:50:50 +00:00
|
|
|
app.GET("/api/machine-ips", handler.MachineIPAddresses())
|
2020-04-20 17:26:49 +00:00
|
|
|
app.GET("/api/suggest-client-ips", handler.SuggestIPAllocation())
|
2020-05-21 08:51:24 +00:00
|
|
|
app.GET("/api/apply-wg-config", handler.ApplyServerConfig(tmplBox))
|
|
|
|
|
|
|
|
// servers other static files
|
|
|
|
app.GET("/static/*", echo.WrapHandler(http.StripPrefix("/static/", assetHandler)))
|
|
|
|
|
2020-04-24 17:33:22 +00:00
|
|
|
app.Logger.Fatal(app.Start("0.0.0.0:5000"))
|
2020-04-18 09:17:49 +00:00
|
|
|
}
|