diff --git a/cmd/wg-portal/assets/css/custom.css b/cmd/wg-portal/assets/css/custom.css
index 5a7d603..78572ca 100644
--- a/cmd/wg-portal/assets/css/custom.css
+++ b/cmd/wg-portal/assets/css/custom.css
@@ -100,4 +100,8 @@
.text-blue {
color: #0057bb;
+}
+
+.text-large {
+ font-size: 150%;
}
\ No newline at end of file
diff --git a/cmd/wg-portal/assets/tpl/admin_create_interface.gohtml b/cmd/wg-portal/assets/tpl/admin_create_interface.gohtml
new file mode 100644
index 0000000..4cb32f7
--- /dev/null
+++ b/cmd/wg-portal/assets/tpl/admin_create_interface.gohtml
@@ -0,0 +1,24 @@
+
+
+
+
+
{{with eq $.Session.LoggedIn true}}{{with eq $.Session.IsAdmin true}}
{{with startsWith $.Route "/admin/"}}
+
+ {{with $.Interfaces}}
{{end}}
+ {{end}}
{{end}}{{end}}
{{if eq $.Session.LoggedIn true}}
diff --git a/cmd/wg-portal/ui/handler.go b/cmd/wg-portal/ui/handler.go
index 1f4206d..02475be 100644
--- a/cmd/wg-portal/ui/handler.go
+++ b/cmd/wg-portal/ui/handler.go
@@ -188,6 +188,9 @@
admin.Use(csrfMiddleware)
admin.Use(h.authenticationMiddleware("admin"))
admin.GET("/", h.handleAdminIndexGet())
+ admin.GET("/interface/new", h.handleAdminNewGet())
+ admin.GET("/interface/create", h.handleAdminCreateGet())
+ admin.GET("/interface/import", h.handleAdminImportGet())
admin.GET("/users", h.handleAdminUserIndexGet())
// User routes
diff --git a/cmd/wg-portal/ui/pages_admin.go b/cmd/wg-portal/ui/pages_admin.go
index ae0c238..3a4c4c5 100644
--- a/cmd/wg-portal/ui/pages_admin.go
+++ b/cmd/wg-portal/ui/pages_admin.go
@@ -19,52 +19,22 @@
return
}
- _, err = h.backend.GetInterface(currentSession.InterfaceIdentifier)
- if err != nil {
- h.HandleError(c, http.StatusInternalServerError, err,
- fmt.Sprintf("failed to load selected interface %s", currentSession.InterfaceIdentifier))
- return
+ var iface *persistence.InterfaceConfig
+ if currentSession.InterfaceIdentifier != "" {
+ iface, err = h.backend.GetInterface(currentSession.InterfaceIdentifier)
+ if err != nil {
+ h.HandleError(c, http.StatusInternalServerError, err,
+ fmt.Sprintf("failed to load selected interface %s", currentSession.InterfaceIdentifier))
+ return
+ }
}
c.HTML(http.StatusOK, "admin_index.gohtml", gin.H{
- "Route": c.Request.URL.Path,
- "Alerts": h.session.GetFlashes(c),
- "Session": currentSession,
- "Static": h.getStaticData(),
- "Interface": persistence.InterfaceConfig{
- BaseModel: persistence.BaseModel{},
- Identifier: "wg0",
- KeyPair: persistence.KeyPair{},
- ListenPort: 0,
- AddressStr: "",
- DnsStr: "",
- DnsSearchStr: "",
- Mtu: 0,
- FirewallMark: 0,
- RoutingTable: "",
- PreUp: "",
- PostUp: "",
- PreDown: "",
- PostDown: "",
- SaveConfig: false,
- Enabled: false,
- DisplayName: "wgX descr",
- Type: persistence.InterfaceTypeServer,
- DriverType: "",
- PeerDefNetworkStr: "",
- PeerDefDnsStr: "",
- PeerDefDnsSearchStr: "",
- PeerDefEndpoint: "",
- PeerDefAllowedIPsStr: "",
- PeerDefMtu: 0,
- PeerDefPersistentKeepalive: 0,
- PeerDefFirewallMark: 0,
- PeerDefRoutingTable: "",
- PeerDefPreUp: "",
- PeerDefPostUp: "",
- PeerDefPreDown: "",
- PeerDefPostDown: "",
- },
+ "Route": c.Request.URL.Path,
+ "Alerts": h.session.GetFlashes(c),
+ "Session": currentSession,
+ "Static": h.getStaticData(),
+ "Interface": iface,
"InterfacePeers": []persistence.PeerConfig{},
"PagedInterfacePeers": []persistence.PeerConfig{
{
@@ -112,3 +82,98 @@
})
}
}
+
+func (h *handler) handleAdminNewGet() gin.HandlerFunc {
+ return func(c *gin.Context) {
+ currentSession := h.session.GetData(c)
+
+ interfaces, err := h.backend.GetInterfaces()
+ if err != nil {
+ h.HandleError(c, http.StatusInternalServerError, err, "failed to load available interfaces")
+ return
+ }
+
+ importableInterfaces, err := h.backend.GetImportableInterfaces()
+ if err != nil {
+ h.HandleError(c, http.StatusInternalServerError, err, "failed to get importable interfaces")
+ return
+ }
+
+ var iface *persistence.InterfaceConfig
+ if currentSession.InterfaceIdentifier != "" {
+ iface, err = h.backend.GetInterface(currentSession.InterfaceIdentifier)
+ if err != nil {
+ h.HandleError(c, http.StatusInternalServerError, err,
+ fmt.Sprintf("failed to load selected interface %s", currentSession.InterfaceIdentifier))
+ return
+ }
+ }
+
+ c.HTML(http.StatusOK, "admin_new_interface.gohtml", gin.H{
+ "Route": c.Request.URL.Path,
+ "Alerts": h.session.GetFlashes(c),
+ "Session": currentSession,
+ "Static": h.getStaticData(),
+ "Interface": iface,
+ "Interfaces": interfaces,
+ "ImportableInterfaces": importableInterfaces,
+ })
+ }
+}
+
+func (h *handler) handleAdminCreateGet() gin.HandlerFunc {
+ return func(c *gin.Context) {
+ currentSession := h.session.GetData(c)
+
+ interfaces, err := h.backend.GetInterfaces()
+ if err != nil {
+ h.HandleError(c, http.StatusInternalServerError, err, "failed to load available interfaces")
+ return
+ }
+
+ c.HTML(http.StatusOK, "admin_create_interface.gohtml", gin.H{
+ "Route": c.Request.URL.Path,
+ "Alerts": h.session.GetFlashes(c),
+ "Session": currentSession,
+ "Static": h.getStaticData(),
+ "Interface": nil,
+ "Interfaces": interfaces,
+ })
+ }
+}
+
+func (h *handler) handleAdminImportGet() gin.HandlerFunc {
+ return func(c *gin.Context) {
+ currentSession := h.session.GetData(c)
+
+ interfaces, err := h.backend.GetInterfaces()
+ if err != nil {
+ h.HandleError(c, http.StatusInternalServerError, err, "failed to load available interfaces")
+ return
+ }
+
+ if currentSession.InterfaceIdentifier == "" && len(interfaces) > 0 {
+ currentSession.InterfaceIdentifier = interfaces[0].Identifier
+ h.session.SetData(c, currentSession)
+ }
+
+ var iface *persistence.InterfaceConfig
+ if currentSession.InterfaceIdentifier != "" {
+ iface, err = h.backend.GetInterface(currentSession.InterfaceIdentifier)
+ if err != nil {
+ h.HandleError(c, http.StatusInternalServerError, err,
+ fmt.Sprintf("failed to load selected interface %s", currentSession.InterfaceIdentifier))
+ return
+ }
+ }
+
+ c.HTML(http.StatusOK, "admin_import_interface.gohtml", gin.H{
+ "Route": c.Request.URL.Path,
+ "Alerts": h.session.GetFlashes(c),
+ "Session": currentSession,
+ "Static": h.getStaticData(),
+ "Interface": iface,
+ "Interfaces": interfaces,
+ })
+ }
+}
diff --git a/cmd/wg-portal/ui/pages_core.go b/cmd/wg-portal/ui/pages_core.go
index 52ca9ae..5e39a0a 100644
--- a/cmd/wg-portal/ui/pages_core.go
+++ b/cmd/wg-portal/ui/pages_core.go
@@ -169,6 +169,16 @@
authSession.Firstname = user.Firstname
authSession.Lastname = user.Lastname
authSession.Email = user.Email
+
+ interfaces, err := h.backend.GetInterfaces()
+ if err != nil {
+ h.HandleError(c, http.StatusInternalServerError, err, "failed to load available interfaces")
+ return
+ }
+ if len(interfaces) != 0 {
+ authSession.InterfaceIdentifier = interfaces[0].Identifier
+ }
+
h.session.SetData(c, authSession)
nextUrl := "/"
@@ -267,6 +277,15 @@
return
}
+ interfaces, err := h.backend.GetInterfaces()
+ if err != nil {
+ h.HandleError(c, http.StatusInternalServerError, err, "failed to load available interfaces")
+ return
+ }
+ if len(interfaces) != 0 {
+ sessionData.InterfaceIdentifier = interfaces[0].Identifier
+ }
+
h.session.SetData(c, sessionData)
nextUrl := "/"
diff --git a/internal/wireguard/wireguard.go b/internal/wireguard/wireguard.go
index fb10659..2e4add1 100644
--- a/internal/wireguard/wireguard.go
+++ b/internal/wireguard/wireguard.go
@@ -356,6 +356,8 @@
}
cfg, err := m.convertWireGuardInterface(devices[d])
+ cfg.ImportLocation = "interface" // TODO: interface, file, ... ?
+ cfg.ImportType = "unknown"
if err != nil {
return nil, errors.WithMessagef(err, "failed to convert WireGuard interface %s", device.Name)
}