mirror of https://github.com/h44z/wg-portal.git
				
				
				
			cleanup code warnings, update RaspberryPi readme
This commit is contained in:
		
							parent
							
								
									bda8c9a3d1
								
							
						
					
					
						commit
						51fb9b4139
					
				|  | @ -4,16 +4,21 @@ This readme only contains a detailed explanation of how to set up the WireGuard | ||||||
| 
 | 
 | ||||||
| ## Setup | ## Setup | ||||||
| 
 | 
 | ||||||
| You can download prebuild binaries from the [release page](https://github.com/h44z/wg-portal/releases). If you want to build the binary yourself, | You can either download prebuild binaries from the [release page](https://github.com/h44z/wg-portal/releases) or use Docker images for ARM.  | ||||||
| use the following instructions: | If you want to build the binary yourself, use the following building instructions. | ||||||
| 
 | 
 | ||||||
| ### Building | ### Building | ||||||
| This section describes how to build the WireGuard Portal code. | This section describes how to build the WireGuard Portal code. | ||||||
| To compile the final binary, use the Makefile provided in the repository. | To compile the final binary, use the Makefile provided in the repository. | ||||||
| As WireGuard Portal is written in Go, **golang >= 1.16** must be installed prior to building. | As WireGuard Portal is written in Go, **golang >= 1.16** must be installed prior to building. | ||||||
|  | If you want to cross compile ARM binaries from AMD64 systems, install *arm-linux-gnueabi-gcc* (armv7) or *aarch64-linux-gnu-gcc* (arm64). | ||||||
| 
 | 
 | ||||||
| ``` | ``` | ||||||
| make build-cross-plat | # for 64 bit OS | ||||||
|  | make build-arm64 | ||||||
|  | 
 | ||||||
|  | # for 32 bit OS | ||||||
|  | make build-arm  | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| The compiled binary and all necessary assets will be located in the dist folder. | The compiled binary and all necessary assets will be located in the dist folder. | ||||||
|  |  | ||||||
|  | @ -85,7 +85,7 @@ services: | ||||||
| ``` | ``` | ||||||
| Please note that mapping ```/etc/wireguard``` to ```/etc/wireguard``` inside the docker, will erase your host's current configuration. | Please note that mapping ```/etc/wireguard``` to ```/etc/wireguard``` inside the docker, will erase your host's current configuration. | ||||||
| If needed, please make sure to back up your files from ```/etc/wireguard```. | If needed, please make sure to back up your files from ```/etc/wireguard```. | ||||||
| For a full list of configuration options take a look at the source file [internal/server/configuration.go](internal/server/configuration.go#L56). | For a full list of configuration options take a look at the source file [internal/server/configuration.go](internal/server/configuration.go#L58). | ||||||
| 
 | 
 | ||||||
| ### Standalone | ### Standalone | ||||||
| For a standalone application, use the Makefile provided in the repository to build the application. Go version 1.16 or higher has to be installed to build WireGuard Portal. | For a standalone application, use the Makefile provided in the repository to build the application. Go version 1.16 or higher has to be installed to build WireGuard Portal. | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ package main | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
| 	"io/ioutil" | 	"io" | ||||||
| 	"os" | 	"os" | ||||||
| 	"os/signal" | 	"os/signal" | ||||||
| 	"runtime" | 	"runtime" | ||||||
|  | @ -74,7 +74,7 @@ func setupLogger(logger *logrus.Logger) error { | ||||||
| 
 | 
 | ||||||
| 	switch level { | 	switch level { | ||||||
| 	case "off": | 	case "off": | ||||||
| 		logger.SetOutput(ioutil.Discard) | 		logger.SetOutput(io.Discard) | ||||||
| 	case "info": | 	case "info": | ||||||
| 		logger.SetLevel(logrus.InfoLevel) | 		logger.SetLevel(logrus.InfoLevel) | ||||||
| 	case "debug": | 	case "debug": | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ package ldap | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"crypto/tls" | 	"crypto/tls" | ||||||
| 	"io/ioutil" | 	"os" | ||||||
| 	"strings" | 	"strings" | ||||||
| 
 | 
 | ||||||
| 	"github.com/gin-gonic/gin" | 	"github.com/gin-gonic/gin" | ||||||
|  | @ -48,8 +48,8 @@ func (Provider) GetPriority() int { | ||||||
| 	return 1 // LDAP password provider
 | 	return 1 // LDAP password provider
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (provider Provider) SetupRoutes(routes *gin.RouterGroup) { | func (provider Provider) SetupRoutes(_ *gin.RouterGroup) { | ||||||
| 	// nothing todo here
 | 	// nothing here
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (provider Provider) Login(ctx *authentication.AuthContext) (string, error) { | func (provider Provider) Login(ctx *authentication.AuthContext) (string, error) { | ||||||
|  | @ -97,8 +97,8 @@ func (provider Provider) Login(ctx *authentication.AuthContext) (string, error) | ||||||
| 	return sr.Entries[0].GetAttributeValue(provider.config.EmailAttribute), nil | 	return sr.Entries[0].GetAttributeValue(provider.config.EmailAttribute), nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (provider Provider) Logout(context *authentication.AuthContext) error { | func (provider Provider) Logout(_ *authentication.AuthContext) error { | ||||||
| 	return nil // nothing todo here
 | 	return nil // nothing here
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (provider Provider) GetUserModel(ctx *authentication.AuthContext) (*authentication.User, error) { | func (provider Provider) GetUserModel(ctx *authentication.AuthContext) (*authentication.User, error) { | ||||||
|  | @ -159,23 +159,23 @@ func (provider Provider) open() (*ldap.Conn, error) { | ||||||
| 
 | 
 | ||||||
| 	if provider.config.LdapCertConn { | 	if provider.config.LdapCertConn { | ||||||
| 
 | 
 | ||||||
| 		cert_plain, err := ioutil.ReadFile(provider.config.LdapTlsCert) | 		certPlain, err := os.ReadFile(provider.config.LdapTlsCert) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, errors.WithMessage(err, "failed to load the certificate") | 			return nil, errors.WithMessage(err, "failed to load the certificate") | ||||||
| 
 | 
 | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		key, err := ioutil.ReadFile(provider.config.LdapTlsKey) | 		key, err := os.ReadFile(provider.config.LdapTlsKey) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, errors.WithMessage(err, "failed to load the key") | 			return nil, errors.WithMessage(err, "failed to load the key") | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		cert_x509, err := tls.X509KeyPair(cert_plain, key) | 		certX509, err := tls.X509KeyPair(certPlain, key) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, errors.WithMessage(err, "failed X509") | 			return nil, errors.WithMessage(err, "failed X509") | ||||||
| 
 | 
 | ||||||
| 		} | 		} | ||||||
| 		tlsConfig = &tls.Config{Certificates: []tls.Certificate{cert_x509}} | 		tlsConfig = &tls.Config{Certificates: []tls.Certificate{certX509}} | ||||||
| 
 | 
 | ||||||
| 	} else { | 	} else { | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -50,8 +50,8 @@ func (Provider) GetPriority() int { | ||||||
| 	return 0 // DB password provider = highest prio
 | 	return 0 // DB password provider = highest prio
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (provider Provider) SetupRoutes(routes *gin.RouterGroup) { | func (provider Provider) SetupRoutes(_ *gin.RouterGroup) { | ||||||
| 	// nothing todo here
 | 	// nothing here
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (provider Provider) Login(ctx *authentication.AuthContext) (string, error) { | func (provider Provider) Login(ctx *authentication.AuthContext) (string, error) { | ||||||
|  | @ -79,8 +79,8 @@ func (provider Provider) Login(ctx *authentication.AuthContext) (string, error) | ||||||
| 	return user.Email, nil | 	return user.Email, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (provider Provider) Logout(context *authentication.AuthContext) error { | func (provider Provider) Logout(_ *authentication.AuthContext) error { | ||||||
| 	return nil // nothing todo here
 | 	return nil // nothing here
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (provider Provider) GetUserModel(ctx *authentication.AuthContext) (*authentication.User, error) { | func (provider Provider) GetUserModel(ctx *authentication.AuthContext) (*authentication.User, error) { | ||||||
|  |  | ||||||
|  | @ -3,7 +3,6 @@ package common | ||||||
| import ( | import ( | ||||||
| 	"crypto/tls" | 	"crypto/tls" | ||||||
| 	"io" | 	"io" | ||||||
| 	"io/ioutil" |  | ||||||
| 	"time" | 	"time" | ||||||
| 
 | 
 | ||||||
| 	"github.com/pkg/errors" | 	"github.com/pkg/errors" | ||||||
|  | @ -96,7 +95,7 @@ func SendEmailWithAttachments(cfg MailConfig, sender, replyTo, subject, body, ht | ||||||
| 	email.AddAlternative(mail.TextPlain, body) | 	email.AddAlternative(mail.TextPlain, body) | ||||||
| 
 | 
 | ||||||
| 	for _, attachment := range attachments { | 	for _, attachment := range attachments { | ||||||
| 		attachmentData, err := ioutil.ReadAll(attachment.Data) | 		attachmentData, err := io.ReadAll(attachment.Data) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return errors.Wrapf(err, "failed to read attachment data for %s", attachment.Name) | 			return errors.Wrapf(err, "failed to read attachment data for %s", attachment.Name) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ package ldap | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"crypto/tls" | 	"crypto/tls" | ||||||
| 	"io/ioutil" | 	"os" | ||||||
| 
 | 
 | ||||||
| 	"github.com/go-ldap/ldap/v3" | 	"github.com/go-ldap/ldap/v3" | ||||||
| 	"github.com/pkg/errors" | 	"github.com/pkg/errors" | ||||||
|  | @ -19,23 +19,23 @@ func Open(cfg *Config) (*ldap.Conn, error) { | ||||||
| 
 | 
 | ||||||
| 	if cfg.LdapCertConn { | 	if cfg.LdapCertConn { | ||||||
| 
 | 
 | ||||||
| 		cert_plain, err := ioutil.ReadFile(cfg.LdapTlsCert) | 		certPlain, err := os.ReadFile(cfg.LdapTlsCert) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, errors.WithMessage(err, "failed to load the certificate") | 			return nil, errors.WithMessage(err, "failed to load the certificate") | ||||||
| 
 | 
 | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		key, err := ioutil.ReadFile(cfg.LdapTlsKey) | 		key, err := os.ReadFile(cfg.LdapTlsKey) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, errors.WithMessage(err, "failed to load the key") | 			return nil, errors.WithMessage(err, "failed to load the key") | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		cert_x509, err := tls.X509KeyPair(cert_plain, key) | 		certX509, err := tls.X509KeyPair(certPlain, key) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, errors.WithMessage(err, "failed X509") | 			return nil, errors.WithMessage(err, "failed X509") | ||||||
| 
 | 
 | ||||||
| 		} | 		} | ||||||
| 		tlsConfig = &tls.Config{Certificates: []tls.Certificate{cert_x509}} | 		tlsConfig = &tls.Config{Certificates: []tls.Certificate{certX509}} | ||||||
| 
 | 
 | ||||||
| 	} else { | 	} else { | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -4,8 +4,8 @@ import ( | ||||||
| 	"context" | 	"context" | ||||||
| 	"encoding/gob" | 	"encoding/gob" | ||||||
| 	"html/template" | 	"html/template" | ||||||
|  | 	"io" | ||||||
| 	"io/fs" | 	"io/fs" | ||||||
| 	"io/ioutil" |  | ||||||
| 	"math/rand" | 	"math/rand" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"net/url" | 	"net/url" | ||||||
|  | @ -110,7 +110,7 @@ func (s *Server) Setup(ctx context.Context) error { | ||||||
| 
 | 
 | ||||||
| 	// Setup http server
 | 	// Setup http server
 | ||||||
| 	gin.SetMode(gin.DebugMode) | 	gin.SetMode(gin.DebugMode) | ||||||
| 	gin.DefaultWriter = ioutil.Discard | 	gin.DefaultWriter = io.Discard | ||||||
| 	s.server = gin.New() | 	s.server = gin.New() | ||||||
| 	if logrus.GetLevel() == logrus.TraceLevel { | 	if logrus.GetLevel() == logrus.TraceLevel { | ||||||
| 		s.server.Use(ginlogrus.Logger(logrus.StandardLogger())) | 		s.server.Use(ginlogrus.Logger(logrus.StandardLogger())) | ||||||
|  |  | ||||||
|  | @ -4,7 +4,7 @@ import ( | ||||||
| 	"context" | 	"context" | ||||||
| 	"crypto/md5" | 	"crypto/md5" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io/ioutil" | 	"os" | ||||||
| 	"path" | 	"path" | ||||||
| 	"syscall" | 	"syscall" | ||||||
| 	"time" | 	"time" | ||||||
|  | @ -224,7 +224,7 @@ func (s *Server) WriteWireGuardConfigFile(device string) error { | ||||||
| 		return errors.WithMessage(err, "failed to get config file") | 		return errors.WithMessage(err, "failed to get config file") | ||||||
| 	} | 	} | ||||||
| 	filePath := path.Join(s.config.WG.ConfigDirectoryPath, dev.DeviceName+".conf") | 	filePath := path.Join(s.config.WG.ConfigDirectoryPath, dev.DeviceName+".conf") | ||||||
| 	if err := ioutil.WriteFile(filePath, cfg, 0644); err != nil { | 	if err := os.WriteFile(filePath, cfg, 0644); err != nil { | ||||||
| 		return errors.Wrap(err, "failed to write WireGuard config file") | 		return errors.Wrap(err, "failed to write WireGuard config file") | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
|  |  | ||||||
|  | @ -11,7 +11,6 @@ type UserSource string | ||||||
| const ( | const ( | ||||||
| 	UserSourceLdap     UserSource = "ldap" // LDAP / ActiveDirectory
 | 	UserSourceLdap     UserSource = "ldap" // LDAP / ActiveDirectory
 | ||||||
| 	UserSourceDatabase UserSource = "db"   // sqlite / mysql database
 | 	UserSourceDatabase UserSource = "db"   // sqlite / mysql database
 | ||||||
| 	UserSourceOIDC     UserSource = "oidc" // open id connect, TODO: implement
 |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type PrivateString string | type PrivateString string | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue