diff --git a/.github/stale.yml b/.github/stale.yml index a1b7aa1..2a79225 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -1,19 +1,57 @@ -# Number of days of inactivity before an issue becomes stale +# Configuration for probot-stale - https://github.com/probot/stale + +# Number of days of inactivity before an Issue or Pull Request becomes stale daysUntilStale: 60 -# Number of days of inactivity before a stale issue is closed + +# Number of days of inactivity before an Issue or Pull Request with the stale label is closed. +# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale. daysUntilClose: 7 -# Issues with these labels will never be considered stale -exemptLabels: - - pinned - - security - - enhancement - - feature request -# Label to use when marking an issue as stale -staleLabel: wontfix -# Comment to post when marking an issue as stale. Set to `false` to disable + +# Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled) +onlyLabels: [] + +# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable +exemptLabels: [] + +# Set to true to ignore issues in a project (defaults to false) +exemptProjects: false + +# Set to true to ignore issues in a milestone (defaults to false) +exemptMilestones: false + +# Set to true to ignore issues with an assignee (defaults to false) +exemptAssignees: false + +# Label to use when marking as stale +staleLabel: stale + +# Comment to post when marking as stale. Set to `false` to disable markComment: > This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. -# Comment to post when closing a stale issue. Set to `false` to disable -closeComment: true + +# Comment to post when closing a stale Issue or Pull Request. +# closeComment: > +# Your comment here. + +# Limit the number of actions per hour, from 1-30. Default is 30 +limitPerRun: 30 + +# Limit to only `issues` or `pulls` +# only: issues + +# Optionally, specify configuration settings that are specific to just 'issues' or 'pulls': +# pulls: +# daysUntilStale: 30 +# markComment: > +# This pull request has been automatically marked as stale because it has not had +# recent activity. It will be closed if no further activity occurs. Thank you +# for your contributions. + +issues: + exemptLabels: + - enhancement + - feature request + - documentation + - bug diff --git a/Dockerfile b/Dockerfile index 1b24728..7b3e5e4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,10 @@ # Build stage FROM golang:1.16.7-alpine3.14 as builder LABEL maintainer="Khanh Ngo
- -
+
+ +
+
+
+
+ +
+
@@ -46,9 +54,9 @@ function renderClientList(data) { ${obj.Client.name} ${obj.Client.email} - ${obj.Client.created_at} + ${prettyDateTime(obj.Client.created_at)} - ${obj.Client.updated_at} + ${prettyDateTime(obj.Client.updated_at)} ${obj.Client.use_server_dns ? 'DNS enabled' : 'DNS disabled'} IP Allocation` @@ -63,3 +71,10 @@ function renderClientList(data) { $('#client-list').append(html); }); } + +function prettyDateTime(timeStr) { + const dt = new Date(timeStr); + const offsetMs = dt.getTimezoneOffset() * 60 * 1000; + const dateLocal = new Date(dt.getTime() - offsetMs); + return dateLocal.toISOString().slice(0, 19).replace(/-/g, "/").replace("T", " "); +} diff --git a/docker-compose.yaml b/docker-compose.yaml index ffcd9b1..814a671 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -10,7 +10,7 @@ services: network_mode: host environment: - SENDGRID_API_KEY - - EMAIL_FROM + - EMAIL_FROM_ADDRESS - EMAIL_FROM_NAME - SESSION_SECRET - WGUI_USERNAME=alpha diff --git a/handler/routes.go b/handler/routes.go index 8e8289f..156e701 100644 --- a/handler/routes.go +++ b/handler/routes.go @@ -24,6 +24,13 @@ import ( "github.com/ngoduykhanh/wireguard-ui/util" ) +// Health check handler +func Health() echo.HandlerFunc { + return func(c echo.Context) error { + return c.String(http.StatusOK, "ok") + } +} + // LoginPage handler func LoginPage() echo.HandlerFunc { return func(c echo.Context) error { @@ -346,7 +353,7 @@ func DownloadClient(db store.IStore) echo.HandlerFunc { reader := strings.NewReader(config) // set response header for downloading - c.Response().Header().Set(echo.HeaderContentDisposition, "attachment; filename=wg0.conf") + c.Response().Header().Set(echo.HeaderContentDisposition, fmt.Sprintf("attachment; filename=%s.conf", clientData.Client.Name)) return c.Stream(http.StatusOK, "text/plain", reader) } } @@ -621,7 +628,11 @@ func SuggestIPAllocation(db store.IStore) echo.HandlerFunc { fmt.Sprintf("Cannot suggest ip allocation: failed to get available ip from network %s", cidr), }) } - suggestedIPs = append(suggestedIPs, fmt.Sprintf("%s/32", ip)) + if (strings.Contains(ip, ":")) { + suggestedIPs = append(suggestedIPs, fmt.Sprintf("%s/128", ip)) + } else { + suggestedIPs = append(suggestedIPs, fmt.Sprintf("%s/32", ip)) + } } return c.JSON(http.StatusOK, suggestedIPs) diff --git a/main.go b/main.go index fe1ba68..8cf5dc9 100644 --- a/main.go +++ b/main.go @@ -34,7 +34,7 @@ var ( const ( defaultEmailSubject = "Your wireguard configuration" defaultEmailContent = `Hi,
-

in this email you can file your personal configuration for our wireguard server.

+

In this email you can find your personal configuration for our wireguard server.

Best

` @@ -43,6 +43,7 @@ const ( func init() { // command-line flags and env variables + flag.BoolVar(&flagDisableLogin, "disable-login", util.LookupEnvOrBool("DISABLE_LOGIN", flagDisableLogin), "Disable authentication on the app. This is potentially dangerous.") flag.StringVar(&flagBindAddress, "bind-address", util.LookupEnvOrString("BIND_ADDRESS", flagBindAddress), "Address:Port to which the app will be bound.") flag.StringVar(&flagSendgridApiKey, "sendgrid-api-key", util.LookupEnvOrString("SENDGRID_API_KEY", flagSendgridApiKey), "Your sendgrid api key.") flag.StringVar(&flagEmailFrom, "email-from", util.LookupEnvOrString("EMAIL_FROM_ADDRESS", flagEmailFrom), "'From' email address.") @@ -104,6 +105,7 @@ func main() { sendmail := emailer.NewSendgridApiMail(util.SendgridApiKey, util.EmailFromName, util.EmailFrom) + app.GET("/_health", handler.Health()) app.GET("/logout", handler.Logout(), handler.ValidSession) app.POST("/new-client", handler.NewClient(db), handler.ValidSession) app.POST("/update-client", handler.UpdateClient(db), handler.ValidSession) diff --git a/prepare_assets.sh b/prepare_assets.sh index 31dd1bb..66a66b3 100755 --- a/prepare_assets.sh +++ b/prepare_assets.sh @@ -4,7 +4,9 @@ set -e DIR=$(dirname "$0") # install node modules -yarn install --pure-lockfile --production +YARN=yarn +[ -x /usr/bin/lsb_release ] && [ -n "`lsb_release -i | grep Debian`" ] && YARN=yarnpkg +$YARN install --pure-lockfile --production # Copy admin-lte dist mkdir -p "${DIR}/assets/dist/js" "${DIR}/assets/dist/css" && \ diff --git a/templates/base.html b/templates/base.html index 6b09a32..6705c6d 100644 --- a/templates/base.html +++ b/templates/base.html @@ -44,17 +44,17 @@ -
-
- -
- -
-
-
+ + + + + + + + + + + +
+
+
+

Help

+
+ +
+
+
1. Endpoint Address
+
The public IP address of your Wireguard server that the client will connect to. Click on + Suggest button to auto detect the public IP address of your server.
+
2. DNS Servers
+
The DNS servers will be set to client config.
+
3. MTU
+
The MTU will be set to server config. By default it is 1420. You might want + to adjust the MTU size if your connection (e.g PPPoE, 3G, satellite network, etc) has a low MTU.
+
Leave blank to omit this setting in the Server config.
+
4. Persistent Keepalive
+
By default, WireGuard peers remain silent while they do not need to communicate, + so peers located behind a NAT and/or firewall may be unreachable from other peers + until they reach out to other peers themselves. Adding PersistentKeepalive + can ensure that the connection remains open.
+
Leave blank to omit this setting in the Client config.
+
5. Wireguard Config File Path
+
The path of your Wireguard server config file. Please make sure the parent directory + exists and is writable.
+
+
+
+ +
@@ -172,12 +203,10 @@ Global Settings $("#frm_global_settings").validate({ rules: { mtu: { - required: true, digits: true, range: [68, 65535] }, persistent_keepalive: { - required: true, digits: true }, config_file_path: { @@ -186,12 +215,10 @@ Global Settings }, messages: { mtu: { - required: "Please enter a MTU value", digits: "MTU must be an integer", range: "MTU must be in range 68..65535" }, persistent_keepalive: { - required: "Please enter a Persistent Keepalive value", digits: "Persistent keepalive must be an integer" }, config_file_path: { diff --git a/templates/login.html b/templates/login.html index 9bfaeb5..81f2b15 100644 --- a/templates/login.html +++ b/templates/login.html @@ -57,7 +57,7 @@
- +
@@ -91,6 +91,11 @@
{{ if .error }} @@ -41,8 +55,8 @@ Connected Peers {{ $peer.Name }} {{ $peer.Email }} {{ $peer.PublicKey }} - {{ $peer.ReceivedBytes }} - {{ $peer.TransmitBytes }} + + {{ $peer.Connected }} {{ $peer.LastHandshakeTime }} diff --git a/templates/wg.conf b/templates/wg.conf index af685cf..a8f82cb 100644 --- a/templates/wg.conf +++ b/templates/wg.conf @@ -1,5 +1,5 @@ # This file was generated using wireguard-ui (https://github.com/ngoduykhanh/wireguard-ui) -# Please don't modify it manually, otherwise your change might got replaced. +# Please don't modify it manually, otherwise your change might get replaced. # Address updated at: {{ .serverConfig.Interface.UpdatedAt }} # Private Key updated at: {{ .serverConfig.KeyPair.UpdatedAt }} @@ -7,7 +7,7 @@ Address = {{$first :=true}}{{range .serverConfig.Interface.Addresses }}{{if $first}}{{$first = false}}{{else}},{{end}}{{.}}{{end}} ListenPort = {{ .serverConfig.Interface.ListenPort }} PrivateKey = {{ .serverConfig.KeyPair.PrivateKey }} -MTU = {{ .globalSettings.MTU }} +{{if .globalSettings.MTU}}MTU = {{ .globalSettings.MTU }}{{end}} PostUp = {{ .serverConfig.Interface.PostUp }} PostDown = {{ .serverConfig.Interface.PostDown }} diff --git a/util/util.go b/util/util.go index 7c85e52..2269537 100644 --- a/util/util.go +++ b/util/util.go @@ -41,12 +41,15 @@ func BuildClientConfig(client model.Client, server model.Server, setting model.G if n, err := strconv.Atoi(split[1]); err == nil { desiredPort = n } else { - log.Error("Endpoint appears to be incorrectly formated: ", err) + log.Error("Endpoint appears to be incorrectly formatted: ", err) } } peerEndpoint := fmt.Sprintf("Endpoint = %s:%d", desiredHost, desiredPort) - peerPersistentKeepalive := fmt.Sprintf("PersistentKeepalive = %d", setting.PersistentKeepalive) + peerPersistentKeepalive := "" + if setting.PersistentKeepalive > 0 { + peerPersistentKeepalive = fmt.Sprintf("PersistentKeepalive = %d", setting.PersistentKeepalive) + } // build the config as string strConfig := "[Interface]\n" + @@ -380,7 +383,7 @@ func LookupEnvOrBool(key string, defaultVal bool) bool { if val, ok := os.LookupEnv(key); ok { v, err := strconv.ParseBool(val) if err != nil { - fmt.Fprintf(os.Stderr, "LookupEnvOrInt[%s]: %v\n", key, err) + fmt.Fprintf(os.Stderr, "LookupEnvOrBool[%s]: %v\n", key, err) } return v }