mirror of
https://github.com/h44z/wg-portal.git
synced 2026-12-05 11:46:09 +01:00
cleanup
This commit is contained in:
@@ -14,7 +14,14 @@ permissions:
|
||||
|
||||
jobs:
|
||||
build-n-push:
|
||||
name: Build and Push
|
||||
name: Build and Push (${{ matrix.target }})
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- target: standard
|
||||
suffix: ''
|
||||
- target: amneziawg
|
||||
suffix: '-amneziawg,onlatest=true'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out the repo
|
||||
@@ -55,7 +62,7 @@ jobs:
|
||||
flavor: |
|
||||
latest=auto
|
||||
prefix=
|
||||
suffix=
|
||||
suffix=${{ matrix.suffix }}
|
||||
tags: |
|
||||
type=ref,event=tag
|
||||
type=ref,event=branch
|
||||
@@ -71,6 +78,7 @@ jobs:
|
||||
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
|
||||
with:
|
||||
context: .
|
||||
target: ${{ matrix.target }}
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
@@ -80,6 +88,7 @@ jobs:
|
||||
BUILD_VERSION=${{ env.BUILD_VERSION }}
|
||||
|
||||
- name: Export binaries from images
|
||||
if: matrix.target == 'standard'
|
||||
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
|
||||
with:
|
||||
context: .
|
||||
@@ -89,45 +98,15 @@ jobs:
|
||||
build-args: |
|
||||
BUILD_VERSION=${{ env.BUILD_VERSION }}
|
||||
|
||||
- name: Extract metadata for AmneziaWG image
|
||||
id: meta-awg
|
||||
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
|
||||
with:
|
||||
images: |
|
||||
wgportal/wg-portal
|
||||
ghcr.io/${{ github.repository }}
|
||||
flavor: |
|
||||
latest=auto
|
||||
suffix=-amneziawg,onlatest=true
|
||||
tags: |
|
||||
type=ref,event=tag
|
||||
type=ref,event=branch
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=semver,pattern={{major}}
|
||||
type=semver,pattern=v{{major}}.{{minor}}
|
||||
type=semver,pattern=v{{major}}
|
||||
|
||||
- name: Build and push AmneziaWG Docker image
|
||||
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
|
||||
with:
|
||||
context: .
|
||||
target: amneziawg
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.meta-awg.outputs.tags }}
|
||||
labels: ${{ steps.meta-awg.outputs.labels }}
|
||||
annotations: ${{ steps.meta-awg.outputs.annotations }}
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||
build-args: |
|
||||
BUILD_VERSION=${{ env.BUILD_VERSION }}
|
||||
|
||||
- name: Rename binaries
|
||||
if: matrix.target == 'standard'
|
||||
run: |
|
||||
for file in binaries/linux*/wg-portal; do
|
||||
mv $file binaries/wg-portal_$(basename $(dirname $file))
|
||||
done
|
||||
|
||||
- name: Upload binaries
|
||||
if: matrix.target == 'standard'
|
||||
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
||||
with:
|
||||
name: binaries
|
||||
|
||||
@@ -95,17 +95,3 @@ func (c AmneziaWGController) SaveInterface(ctx context.Context, id domain.Interf
|
||||
}
|
||||
return c.updateLowLevelInterface(iface)
|
||||
}
|
||||
|
||||
func (c AmneziaWGController) DeleteInterface(_ context.Context, id domain.InterfaceIdentifier) error {
|
||||
link, err := c.nl.LinkByName(string(id))
|
||||
if err != nil {
|
||||
if _, ok := errors.AsType[netlink.LinkNotFoundError](err); ok {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
if link.Type() != "amneziawg" {
|
||||
return fmt.Errorf("interface %s is not an AmneziaWG kernel device", id)
|
||||
}
|
||||
return c.nl.LinkDel(link)
|
||||
}
|
||||
|
||||
@@ -404,6 +404,9 @@ func (c LocalController) deleteLowLevelInterface(id domain.InterfaceIdentifier)
|
||||
return fmt.Errorf("unable to find low level interface: %w", err)
|
||||
}
|
||||
|
||||
if c.importSource == domain.ControllerTypeAmneziaWG && link.Type() != "amneziawg" {
|
||||
return fmt.Errorf("interface %s is not an AmneziaWG kernel device", id)
|
||||
}
|
||||
err = c.nl.LinkDel(link)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete low level interface: %w", err)
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
|
||||
# Core settings
|
||||
PrivateKey = {{ .Interface.KeyPair.PrivateKey }}
|
||||
{{- if .Interface.AmneziaWG }}
|
||||
{{ .Interface.AmneziaWG.ConfigLines -}}
|
||||
{{- end }}
|
||||
{{- with .Interface.AmneziaWG }}
|
||||
{{ range $key, $value := . }}{{ $key }} = {{ $value }}
|
||||
{{ end }}{{ end }}
|
||||
Address = {{ CidrsToString .Interface.Addresses }}
|
||||
|
||||
# Misc. settings (optional)
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
|
||||
# Core settings
|
||||
PrivateKey = {{ .Peer.Interface.KeyPair.PrivateKey }}
|
||||
{{- if .Peer.Interface.AmneziaWG }}
|
||||
{{ .Peer.Interface.AmneziaWG.ConfigLines -}}
|
||||
{{- end }}
|
||||
{{- with .Peer.Interface.AmneziaWG }}
|
||||
{{ range $key, $value := . }}{{ $key }} = {{ $value }}
|
||||
{{ end }}{{ end }}
|
||||
{{- if eq .Style "wgquick"}}
|
||||
Address = {{ CidrsToString .Peer.Interface.Addresses }}
|
||||
{{- end}}
|
||||
|
||||
@@ -2,8 +2,6 @@ package domain
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"maps"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -69,12 +67,3 @@ func ParseAmneziaWGRange(value string, bits int) (uint64, uint64, error) {
|
||||
}
|
||||
return lo, hi, nil
|
||||
}
|
||||
|
||||
// ConfigLines is deterministic so saved files and QR codes use the same options.
|
||||
func (o AmneziaWGOptions) ConfigLines() string {
|
||||
var result strings.Builder
|
||||
for _, key := range slices.Sorted(maps.Keys(o)) {
|
||||
_, _ = fmt.Fprintf(&result, "%s = %s\n", key, o[key])
|
||||
}
|
||||
return result.String()
|
||||
}
|
||||
|
||||
@@ -182,19 +182,10 @@ func encodeAmneziaWGSockaddr(endpoint *net.UDPAddr) ([]byte, error) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Validate lengths before using netlink's attribute decoder, including padding
|
||||
// that would otherwise let a truncated attribute panic during decoding.
|
||||
// With an aligned buffer, a valid attribute and its padding both fit.
|
||||
func amneziaWGAttrs(data []byte) ([]syscall.NetlinkRouteAttr, error) {
|
||||
for rest := data; len(rest) != 0; {
|
||||
if len(rest) < unix.SizeofRtAttr {
|
||||
return nil, fmt.Errorf("truncated AmneziaWG attribute")
|
||||
}
|
||||
length := int(nl.NativeEndian().Uint16(rest))
|
||||
padded := (length + 3) &^ 3
|
||||
if length < unix.SizeofRtAttr || padded > len(rest) {
|
||||
return nil, fmt.Errorf("invalid AmneziaWG attribute length")
|
||||
}
|
||||
rest = rest[padded:]
|
||||
if len(data)%unix.RTA_ALIGNTO != 0 {
|
||||
return nil, fmt.Errorf("unaligned AmneziaWG attributes")
|
||||
}
|
||||
return nl.ParseRouteAttr(data)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user