Merge branch 'pterodactyl:develop' into develop
This commit is contained in:
commit
93c5999cb0
1
.github/FUNDING.yaml
vendored
Normal file
1
.github/FUNDING.yaml
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
github: [matthewpi]
|
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
|
@ -1,2 +0,0 @@
|
||||||
github: [ DaneEveritt ]
|
|
||||||
custom: [ "https://paypal.me/PterodactylSoftware" ]
|
|
|
@ -1,4 +1,5 @@
|
||||||
name: CodeQL
|
name: CodeQL
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
|
@ -7,24 +8,35 @@ on:
|
||||||
branches:
|
branches:
|
||||||
- develop
|
- develop
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 9 * * 4'
|
- cron: "0 9 * * 4"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
analyze:
|
analyze:
|
||||||
name: Analyze
|
name: Analyze
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
actions: read
|
actions: read
|
||||||
contents: read
|
contents: read
|
||||||
security-events: write
|
security-events: write
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
language: [ 'go' ]
|
language:
|
||||||
|
- go
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- name: Code Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v1
|
uses: github/codeql-action/init@v2
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
- uses: github/codeql-action/autobuild@v1
|
|
||||||
- uses: github/codeql-action/analyze@v1
|
- name: Autobuild
|
||||||
|
uses: github/codeql-action/autobuild@v2
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v2
|
|
@ -1,58 +1,72 @@
|
||||||
name: Publish Docker Image
|
name: Docker
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- develop
|
- develop
|
||||||
tags:
|
tags:
|
||||||
- 'v*'
|
- "v*"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
push:
|
build-and-push:
|
||||||
name: Push
|
name: Build and Push
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
# Always run against a tag, even if the commit into the tag has [docker skip] within the commit message.
|
# Always run against a tag, even if the commit into the tag has [docker skip] within the commit message.
|
||||||
if: "!contains(github.ref, 'develop') || (!contains(github.event.head_commit.message, 'skip docker') && !contains(github.event.head_commit.message, 'docker skip'))"
|
if: "!contains(github.ref, 'develop') || (!contains(github.event.head_commit.message, 'skip docker') && !contains(github.event.head_commit.message, 'docker skip'))"
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Code Checkout
|
- name: Code Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Docker Meta
|
- name: Docker Meta
|
||||||
id: docker_meta
|
id: docker_meta
|
||||||
uses: crazy-max/ghaction-docker-meta@v1
|
uses: crazy-max/ghaction-docker-meta@v1
|
||||||
with:
|
with:
|
||||||
images: ghcr.io/pterodactyl/wings
|
images: ghcr.io/pterodactyl/wings
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v1
|
uses: docker/setup-qemu-action@v2
|
||||||
|
|
||||||
- name: Install buildx
|
- name: Install buildx
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v2
|
||||||
with:
|
|
||||||
version: v0.5.1
|
|
||||||
- name: Login to GitHub Container Registry
|
- name: Login to GitHub Container Registry
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.repository_owner }}
|
||||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
|
||||||
- name: Get Build Information
|
- name: Get Build Information
|
||||||
id: build_info
|
id: build_info
|
||||||
run: |
|
run: |
|
||||||
echo "::set-output name=version_tag::${GITHUB_REF/refs\/tags\/v/}"
|
echo "::set-output name=version_tag::${GITHUB_REF/refs\/tags\/v/}"
|
||||||
echo "::set-output name=short_sha::$(git rev-parse --short HEAD)"
|
echo "::set-output name=short_sha::$(git rev-parse --short HEAD)"
|
||||||
- name: Release Production Build
|
|
||||||
|
- name: Build and push (latest)
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v2
|
||||||
if: "!contains(github.ref, 'develop')"
|
if: "!contains(github.ref, 'develop')"
|
||||||
with:
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./Dockerfile
|
||||||
|
push: true
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
build-args: |
|
build-args: |
|
||||||
VERSION=${{ steps.build_info.outputs.version_tag }}
|
VERSION=${{ steps.build_info.outputs.version_tag }}
|
||||||
labels: ${{ steps.docker_meta.outputs.labels }}
|
labels: ${{ steps.docker_meta.outputs.labels }}
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
push: true
|
|
||||||
tags: ${{ steps.docker_meta.outputs.tags }}
|
tags: ${{ steps.docker_meta.outputs.tags }}
|
||||||
- name: Release Development Build
|
|
||||||
|
- name: Build and push (develop)
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v2
|
||||||
if: "contains(github.ref, 'develop')"
|
if: "contains(github.ref, 'develop')"
|
||||||
with:
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./Dockerfile
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
build-args: |
|
build-args: |
|
||||||
VERSION=dev-${{ steps.build_info.outputs.short_sha }}
|
VERSION=dev-${{ steps.build_info.outputs.short_sha }}
|
||||||
labels: ${{ steps.docker_meta.outputs.labels }}
|
labels: ${{ steps.docker_meta.outputs.labels }}
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
|
||||||
tags: ${{ steps.docker_meta.outputs.tags }}
|
tags: ${{ steps.docker_meta.outputs.tags }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
|
@ -1,4 +1,5 @@
|
||||||
name: Run Tests
|
name: Push
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
|
@ -6,24 +7,29 @@ on:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- develop
|
- develop
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build-and-test:
|
||||||
|
name: Build and Test
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ ubuntu-20.04 ]
|
os: [ubuntu-20.04]
|
||||||
go: [ '^1.17' ]
|
go: ["1.18.8", "1.19.3"]
|
||||||
goos: [ linux ]
|
goos: [linux]
|
||||||
goarch: [ amd64, arm64 ]
|
goarch: [amd64, arm64]
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
steps:
|
steps:
|
||||||
- name: Code Checkout
|
- name: Setup Go
|
||||||
uses: actions/checkout@v2
|
uses: actions/setup-go@v3
|
||||||
- name: Setup Go v${{ matrix.go }}
|
|
||||||
uses: actions/setup-go@v2
|
|
||||||
with:
|
with:
|
||||||
go-version: ${{ matrix.go }}
|
go-version: ${{ matrix.go }}
|
||||||
- name: Print Environment
|
|
||||||
|
- name: Code Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Gather environment variables
|
||||||
id: env
|
id: env
|
||||||
run: |
|
run: |
|
||||||
printf "Go Executable Path: $(which go)\n"
|
printf "Go Executable Path: $(which go)\n"
|
||||||
|
@ -33,22 +39,27 @@ jobs:
|
||||||
printf "\n\nSystem Environment:\n\n"
|
printf "\n\nSystem Environment:\n\n"
|
||||||
env
|
env
|
||||||
printf "Git Version: $(git version)\n\n"
|
printf "Git Version: $(git version)\n\n"
|
||||||
echo "::set-output name=version_tag::${GITHUB_REF/refs\/tags\//}"
|
echo "version_tag=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
|
||||||
echo "::set-output name=short_sha::$(git rev-parse --short HEAD)"
|
echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
|
||||||
echo "::set-output name=go_cache::$(go env GOCACHE)"
|
echo "go_cache=$(go env GOCACHE)" >> $GITHUB_OUTPUT
|
||||||
echo "::set-output name=go_mod_cache::$(go env GOMODCACHE)"
|
echo "go_mod_cache=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Build Cache
|
- name: Build Cache
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
key: ${{ runner.os }}-go${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-go${{ matrix.go }}-
|
${{ runner.os }}-go-
|
||||||
path: |
|
path: |
|
||||||
${{ steps.env.outputs.go_cache }}
|
${{ steps.env.outputs.go_cache }}
|
||||||
${{ steps.env.outputs.go_mod_cache }}
|
${{ steps.env.outputs.go_mod_cache }}
|
||||||
- name: Get Dependencies
|
|
||||||
|
- name: go mod download
|
||||||
|
env:
|
||||||
|
CGO_ENABLED: 0
|
||||||
run: |
|
run: |
|
||||||
go get -v -t -d ./...
|
go mod download
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
env:
|
env:
|
||||||
GOOS: ${{ matrix.goos }}
|
GOOS: ${{ matrix.goos }}
|
||||||
|
@ -56,21 +67,34 @@ jobs:
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
SRC_PATH: github.com/pterodactyl/wings
|
SRC_PATH: github.com/pterodactyl/wings
|
||||||
run: |
|
run: |
|
||||||
go build -v -trimpath -ldflags="-s -w -X ${SRC_PATH}/system.Version=dev-${GIT_COMMIT:0:7}" -o build/wings_${GOOS}_${GOARCH} wings.go
|
go build -v -trimpath -ldflags="-s -w -X ${SRC_PATH}/system.Version=dev-${GIT_COMMIT:0:7}" -o dist/wings ${SRC_PATH}
|
||||||
go build -v -trimpath -ldflags="-X ${SRC_PATH}/system.Version=dev-${GIT_COMMIT:0:7}" -o build/wings_${GOOS}_${GOARCH}_debug wings.go
|
go build -v -trimpath -ldflags="-X ${SRC_PATH}/system.Version=dev-${GIT_COMMIT:0:7}" -o dist/wings_debug ${SRC_PATH}
|
||||||
upx build/wings_${GOOS}_${{ matrix.goarch }}
|
chmod 755 dist/*
|
||||||
chmod +x build/*
|
|
||||||
- name: Tests
|
- name: go test
|
||||||
run: go test -race ./...
|
if: ${{ matrix.goarch == 'amd64' }}
|
||||||
|
env:
|
||||||
|
CGO_ENABLED: 0
|
||||||
|
run: |
|
||||||
|
go test $(go list ./...)
|
||||||
|
|
||||||
|
- name: go test -race
|
||||||
|
if: ${{ matrix.goarch == 'amd64' }}
|
||||||
|
env:
|
||||||
|
CGO_ENABLED: 1
|
||||||
|
run: |
|
||||||
|
go test -race $(go list ./...)
|
||||||
|
|
||||||
- name: Upload Release Artifact
|
- name: Upload Release Artifact
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v2
|
||||||
if: ${{ github.ref == 'refs/heads/develop' || github.event_name == 'pull_request' }}
|
if: ${{ github.ref == 'refs/heads/develop' || github.event_name == 'pull_request' }}
|
||||||
with:
|
with:
|
||||||
name: wings_linux_${{ matrix.goarch }}
|
name: wings_linux_${{ matrix.goarch }}
|
||||||
path: build/wings_linux_${{ matrix.goarch }}
|
path: dist/wings
|
||||||
|
|
||||||
- name: Upload Debug Artifact
|
- name: Upload Debug Artifact
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v2
|
||||||
if: ${{ github.ref == 'refs/heads/develop' || github.event_name == 'pull_request' }}
|
if: ${{ github.ref == 'refs/heads/develop' || github.event_name == 'pull_request' }}
|
||||||
with:
|
with:
|
||||||
name: wings_linux_${{ matrix.goarch }}_debug
|
name: wings_linux_${{ matrix.goarch }}_debug
|
||||||
path: build/wings_linux_${{ matrix.goarch }}_debug
|
path: dist/wings_debug
|
|
@ -1,41 +1,50 @@
|
||||||
name: Create Release
|
name: Release
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- 'v*'
|
- "v*"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
|
name: Release
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Code Checkout
|
- name: Code Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
- uses: actions/setup-go@v2
|
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: '^1.17'
|
go-version: "1.18.8"
|
||||||
- name: Build
|
|
||||||
|
- name: Build release binaries
|
||||||
env:
|
env:
|
||||||
|
CGO_ENABLED: 0
|
||||||
REF: ${{ github.ref }}
|
REF: ${{ github.ref }}
|
||||||
run: |
|
run: |
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X github.com/pterodactyl/wings/system.Version=${REF:11}" -o build/wings_linux_amd64 -v wings.go
|
GOARCH=amd64 go build -o dist/wings_linux_amd64 -v -trimpath -ldflags="-s -w -X github.com/pterodactyl/wings/system.Version=${REF:11}" github.com/pterodactyl/wings
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w -X github.com/pterodactyl/wings/system.Version=${REF:11}" -o build/wings_linux_arm64 -v wings.go
|
GOARCH=arm64 go build -o dist/wings_linux_ard64 -v -trimpath -ldflags="-s -w -X github.com/pterodactyl/wings/system.Version=${REF:11}" github.com/pterodactyl/wings
|
||||||
- name: Test
|
|
||||||
run: go test ./...
|
|
||||||
- name: Compress binary and make it executable
|
- name: Compress binary and make it executable
|
||||||
run: |
|
run: |
|
||||||
upx build/wings_linux_amd64 && chmod +x build/wings_linux_amd64
|
chmod 755 dist/wings_linux_amd64 dist/wings_linux_arm64
|
||||||
upx build/wings_linux_arm64 && chmod +x build/wings_linux_arm64
|
|
||||||
- name: Extract changelog
|
- name: Extract changelog
|
||||||
env:
|
env:
|
||||||
REF: ${{ github.ref }}
|
REF: ${{ github.ref }}
|
||||||
run: |
|
run: |
|
||||||
sed -n "/^## ${REF:10}/,/^## /{/^## /b;p}" CHANGELOG.md > ./RELEASE_CHANGELOG
|
sed -n "/^## ${REF:10}/,/^## /{/^## /b;p}" CHANGELOG.md > ./RELEASE_CHANGELOG
|
||||||
echo ::set-output name=version_name::`sed -nr "s/^## (${REF:10} .*)$/\1/p" CHANGELOG.md`
|
echo "version_name=`sed -nr "s/^## (${REF:10} .*)$/\1/p" CHANGELOG.md`" > $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Create checksum and add to changelog
|
- name: Create checksum and add to changelog
|
||||||
run: |
|
run: |
|
||||||
SUM=`cd build && sha256sum wings_linux_amd64`
|
SUM=`cd build && sha256sum wings_linux_amd64`
|
||||||
SUM2=`cd build && sha256sum wings_linux_arm64`
|
SUM2=`cd build && sha256sum wings_linux_arm64`
|
||||||
echo -e "\n#### SHA256 Checksum\n\`\`\`\n$SUM\n$SUM2\n\`\`\`\n" >> ./RELEASE_CHANGELOG
|
echo -e "\n#### SHA256 Checksum\n\`\`\`\n$SUM\n$SUM2\n\`\`\`\n" >> ./RELEASE_CHANGELOG
|
||||||
echo -e "$SUM\n$SUM2" > checksums.txt
|
echo -e "$SUM\n$SUM2" > checksums.txt
|
||||||
|
|
||||||
- name: Create release branch
|
- name: Create release branch
|
||||||
env:
|
env:
|
||||||
REF: ${{ github.ref }}
|
REF: ${{ github.ref }}
|
||||||
|
@ -49,7 +58,8 @@ jobs:
|
||||||
git add system/const.go
|
git add system/const.go
|
||||||
git commit -m "bump version for release"
|
git commit -m "bump version for release"
|
||||||
git push
|
git push
|
||||||
- name: Create Release
|
|
||||||
|
- name: Create release
|
||||||
id: create_release
|
id: create_release
|
||||||
uses: actions/create-release@v1
|
uses: actions/create-release@v1
|
||||||
env:
|
env:
|
||||||
|
@ -60,7 +70,8 @@ jobs:
|
||||||
body_path: ./RELEASE_CHANGELOG
|
body_path: ./RELEASE_CHANGELOG
|
||||||
draft: true
|
draft: true
|
||||||
prerelease: ${{ contains(github.ref, 'beta') || contains(github.ref, 'alpha') }}
|
prerelease: ${{ contains(github.ref, 'beta') || contains(github.ref, 'alpha') }}
|
||||||
- name: Upload amd64 Binary
|
|
||||||
|
- name: Upload amd64 binary
|
||||||
uses: actions/upload-release-asset@v1
|
uses: actions/upload-release-asset@v1
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
@ -69,7 +80,8 @@ jobs:
|
||||||
asset_path: build/wings_linux_amd64
|
asset_path: build/wings_linux_amd64
|
||||||
asset_name: wings_linux_amd64
|
asset_name: wings_linux_amd64
|
||||||
asset_content_type: application/octet-stream
|
asset_content_type: application/octet-stream
|
||||||
- name: Upload arm64 Binary
|
|
||||||
|
- name: Upload arm64 binary
|
||||||
uses: actions/upload-release-asset@v1
|
uses: actions/upload-release-asset@v1
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
@ -78,6 +90,7 @@ jobs:
|
||||||
asset_path: build/wings_linux_arm64
|
asset_path: build/wings_linux_arm64
|
||||||
asset_name: wings_linux_arm64
|
asset_name: wings_linux_arm64
|
||||||
asset_content_type: application/octet-stream
|
asset_content_type: application/octet-stream
|
||||||
|
|
||||||
- name: Upload checksum
|
- name: Upload checksum
|
||||||
uses: actions/upload-release-asset@v1
|
uses: actions/upload-release-asset@v1
|
||||||
env:
|
env:
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -23,6 +23,8 @@
|
||||||
# ignore configuration file
|
# ignore configuration file
|
||||||
/config.yml
|
/config.yml
|
||||||
/config*.yml
|
/config*.yml
|
||||||
|
/config.yaml
|
||||||
|
/config*.yaml
|
||||||
|
|
||||||
# Ignore Vagrant stuff
|
# Ignore Vagrant stuff
|
||||||
/.vagrant
|
/.vagrant
|
||||||
|
|
20
CHANGELOG.md
20
CHANGELOG.md
|
@ -1,5 +1,25 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v1.7.2
|
||||||
|
### Fixed
|
||||||
|
* The S3 backup driver now supports Cloudflare R2
|
||||||
|
|
||||||
|
### Added
|
||||||
|
* During a server transfer, there is a new "Archiving" status that outputs the progress of creating the server transfer archive.
|
||||||
|
* Adds a configuration option to control the list of trusted proxies that can be used to determine the client IP address.
|
||||||
|
* Adds a configuration option to control the Docker username space setting when Wings creates containers.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
* Releases are now built using `Go 1.18` — the minimum version required to build Wings is now `Go 1.18`.
|
||||||
|
|
||||||
|
## v1.7.1
|
||||||
|
### Fixed
|
||||||
|
* YAML parser has been updated to fix some strange issues
|
||||||
|
|
||||||
|
### Added
|
||||||
|
* Added `Force Outgoing IP` option for servers to ensure outgoing traffic uses the server's IP address
|
||||||
|
* Adds an option to control the level of gzip compression for backups
|
||||||
|
|
||||||
## v1.7.0
|
## v1.7.0
|
||||||
### Fixed
|
### Fixed
|
||||||
* Fixes multi-platform support for Wings' Docker image.
|
* Fixes multi-platform support for Wings' Docker image.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# Stage 1 (Build)
|
# Stage 1 (Build)
|
||||||
FROM golang:1.17-alpine AS builder
|
FROM golang:1.18-alpine AS builder
|
||||||
|
|
||||||
ARG VERSION
|
ARG VERSION
|
||||||
RUN apk add --update --no-cache git make
|
RUN apk add --update --no-cache git make
|
||||||
|
|
3
Makefile
3
Makefile
|
@ -14,9 +14,6 @@ rmdebug:
|
||||||
go build -gcflags "all=-N -l" -ldflags="-X github.com/pterodactyl/wings/system.Version=$(GIT_HEAD)" -race
|
go build -gcflags "all=-N -l" -ldflags="-X github.com/pterodactyl/wings/system.Version=$(GIT_HEAD)" -race
|
||||||
sudo dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ./wings -- --debug --ignore-certificate-errors --config config.yml
|
sudo dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ./wings -- --debug --ignore-certificate-errors --config config.yml
|
||||||
|
|
||||||
compress:
|
|
||||||
upx --brute build/wings_*
|
|
||||||
|
|
||||||
cross-build: clean build compress
|
cross-build: clean build compress
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|
|
@ -14,7 +14,7 @@ dependencies, and allowing users to authenticate with the same credentials they
|
||||||
|
|
||||||
## Sponsors
|
## Sponsors
|
||||||
I would like to extend my sincere thanks to the following sponsors for helping find Pterodactyl's developement.
|
I would like to extend my sincere thanks to the following sponsors for helping find Pterodactyl's developement.
|
||||||
[Interested in becoming a sponsor?](https://github.com/sponsors/DaneEveritt)
|
[Interested in becoming a sponsor?](https://github.com/sponsors/matthewpi)
|
||||||
|
|
||||||
| Company | About |
|
| Company | About |
|
||||||
| ------- | ----- |
|
| ------- | ----- |
|
||||||
|
|
|
@ -58,14 +58,14 @@ func newDiagnosticsCommand() *cobra.Command {
|
||||||
return command
|
return command
|
||||||
}
|
}
|
||||||
|
|
||||||
// diagnosticsCmdRun collects diagnostics about wings, it's configuration and the node.
|
// diagnosticsCmdRun collects diagnostics about wings, its configuration and the node.
|
||||||
// We collect:
|
// We collect:
|
||||||
// - wings and docker versions
|
// - wings and docker versions
|
||||||
// - relevant parts of daemon configuration
|
// - relevant parts of daemon configuration
|
||||||
// - the docker debug output
|
// - the docker debug output
|
||||||
// - running docker containers
|
// - running docker containers
|
||||||
// - logs
|
// - logs
|
||||||
func diagnosticsCmdRun(cmd *cobra.Command, args []string) {
|
func diagnosticsCmdRun(*cobra.Command, []string) {
|
||||||
questions := []*survey.Question{
|
questions := []*survey.Question{
|
||||||
{
|
{
|
||||||
Name: "IncludeEndpoints",
|
Name: "IncludeEndpoints",
|
||||||
|
|
|
@ -81,7 +81,7 @@ func init() {
|
||||||
rootCommand.Flags().Bool("pprof", false, "if the pprof profiler should be enabled. The profiler will bind to localhost:6060 by default")
|
rootCommand.Flags().Bool("pprof", false, "if the pprof profiler should be enabled. The profiler will bind to localhost:6060 by default")
|
||||||
rootCommand.Flags().Int("pprof-block-rate", 0, "enables block profile support, may have performance impacts")
|
rootCommand.Flags().Int("pprof-block-rate", 0, "enables block profile support, may have performance impacts")
|
||||||
rootCommand.Flags().Int("pprof-port", 6060, "If provided with --pprof, the port it will run on")
|
rootCommand.Flags().Int("pprof-port", 6060, "If provided with --pprof, the port it will run on")
|
||||||
rootCommand.Flags().Bool("auto-tls", false, "pass in order to have wings generate and manage it's own SSL certificates using Let's Encrypt")
|
rootCommand.Flags().Bool("auto-tls", false, "pass in order to have wings generate and manage its own SSL certificates using Let's Encrypt")
|
||||||
rootCommand.Flags().String("tls-hostname", "", "required with --auto-tls, the FQDN for the generated SSL certificate")
|
rootCommand.Flags().String("tls-hostname", "", "required with --auto-tls, the FQDN for the generated SSL certificate")
|
||||||
rootCommand.Flags().Bool("ignore-certificate-errors", false, "ignore certificate verification errors when executing API calls")
|
rootCommand.Flags().Bool("ignore-certificate-errors", false, "ignore certificate verification errors when executing API calls")
|
||||||
|
|
||||||
|
@ -111,7 +111,6 @@ func rootCmdRun(cmd *cobra.Command, _ []string) {
|
||||||
log.WithField("error", err).Fatal("failed to configure system directories for pterodactyl")
|
log.WithField("error", err).Fatal("failed to configure system directories for pterodactyl")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.WithField("username", config.Get().System.User).Info("checking for pterodactyl system user")
|
|
||||||
if err := config.EnsurePterodactylUser(); err != nil {
|
if err := config.EnsurePterodactylUser(); err != nil {
|
||||||
log.WithField("error", err).Fatal("failed to create pterodactyl system user")
|
log.WithField("error", err).Fatal("failed to create pterodactyl system user")
|
||||||
}
|
}
|
||||||
|
@ -163,7 +162,7 @@ func rootCmdRun(cmd *cobra.Command, _ []string) {
|
||||||
ticker := time.NewTicker(time.Minute)
|
ticker := time.NewTicker(time.Minute)
|
||||||
// Every minute, write the current server states to the disk to allow for a more
|
// Every minute, write the current server states to the disk to allow for a more
|
||||||
// seamless hard-reboot process in which wings will re-sync server states based
|
// seamless hard-reboot process in which wings will re-sync server states based
|
||||||
// on it's last tracked state.
|
// on its last tracked state.
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -364,7 +363,7 @@ func rootCmdRun(cmd *cobra.Command, _ []string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if main http server should run with TLS. Otherwise reset the TLS
|
// Check if main http server should run with TLS. Otherwise, reset the TLS
|
||||||
// config on the server and then serve it over normal HTTP.
|
// config on the server and then serve it over normal HTTP.
|
||||||
if api.Ssl.Enabled {
|
if api.Ssl.Enabled {
|
||||||
if err := s.ListenAndServeTLS(api.Ssl.CertificateFile, api.Ssl.KeyFile); err != nil {
|
if err := s.ListenAndServeTLS(api.Ssl.CertificateFile, api.Ssl.KeyFile); err != nil {
|
||||||
|
|
|
@ -16,8 +16,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
|
"github.com/acobaugh/osrelease"
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/cobaugh/osrelease"
|
|
||||||
"github.com/creasty/defaults"
|
"github.com/creasty/defaults"
|
||||||
"github.com/gbrlsnchs/jwt/v3"
|
"github.com/gbrlsnchs/jwt/v3"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
|
@ -91,6 +91,9 @@ type ApiConfiguration struct {
|
||||||
|
|
||||||
// The maximum size for files uploaded through the Panel in MB.
|
// The maximum size for files uploaded through the Panel in MB.
|
||||||
UploadLimit int64 `default:"100" json:"upload_limit" yaml:"upload_limit"`
|
UploadLimit int64 `default:"100" json:"upload_limit" yaml:"upload_limit"`
|
||||||
|
|
||||||
|
// A list of IP address of proxies that may send a X-Forwarded-For header to set the true clients IP
|
||||||
|
TrustedProxies []string `json:"trusted_proxies" yaml:"trusted_proxies"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoteQueryConfiguration defines the configuration settings for remote requests
|
// RemoteQueryConfiguration defines the configuration settings for remote requests
|
||||||
|
@ -149,9 +152,23 @@ type SystemConfiguration struct {
|
||||||
// Definitions for the user that gets created to ensure that we can quickly access
|
// Definitions for the user that gets created to ensure that we can quickly access
|
||||||
// this information without constantly having to do a system lookup.
|
// this information without constantly having to do a system lookup.
|
||||||
User struct {
|
User struct {
|
||||||
Uid int
|
// Rootless controls settings related to rootless container daemons.
|
||||||
Gid int
|
Rootless struct {
|
||||||
}
|
// Enabled controls whether rootless containers are enabled.
|
||||||
|
Enabled bool `yaml:"enabled" default:"false"`
|
||||||
|
// ContainerUID controls the UID of the user inside the container.
|
||||||
|
// This should likely be set to 0 so the container runs as the user
|
||||||
|
// running Wings.
|
||||||
|
ContainerUID int `yaml:"container_uid" default:"0"`
|
||||||
|
// ContainerGID controls the GID of the user inside the container.
|
||||||
|
// This should likely be set to 0 so the container runs as the user
|
||||||
|
// running Wings.
|
||||||
|
ContainerGID int `yaml:"container_gid" default:"0"`
|
||||||
|
} `yaml:"rootless"`
|
||||||
|
|
||||||
|
Uid int `yaml:"uid"`
|
||||||
|
Gid int `yaml:"gid"`
|
||||||
|
} `yaml:"user"`
|
||||||
|
|
||||||
// The amount of time in seconds that can elapse before a server's disk space calculation is
|
// The amount of time in seconds that can elapse before a server's disk space calculation is
|
||||||
// considered stale and a re-check should occur. DANGER: setting this value too low can seriously
|
// considered stale and a re-check should occur. DANGER: setting this value too low can seriously
|
||||||
|
@ -219,6 +236,15 @@ type Backups struct {
|
||||||
//
|
//
|
||||||
// Defaults to 0 (unlimited)
|
// Defaults to 0 (unlimited)
|
||||||
WriteLimit int `default:"0" yaml:"write_limit"`
|
WriteLimit int `default:"0" yaml:"write_limit"`
|
||||||
|
|
||||||
|
// CompressionLevel determines how much backups created by wings should be compressed.
|
||||||
|
//
|
||||||
|
// "none" -> no compression will be applied
|
||||||
|
// "best_speed" -> uses gzip level 1 for fast speed
|
||||||
|
// "best_compression" -> uses gzip level 9 for minimal disk space useage
|
||||||
|
//
|
||||||
|
// Defaults to "best_speed" (level 1)
|
||||||
|
CompressionLevel string `default:"best_speed" yaml:"compression_level"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Transfers struct {
|
type Transfers struct {
|
||||||
|
@ -413,6 +439,19 @@ func EnsurePterodactylUser() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _config.System.User.Rootless.Enabled {
|
||||||
|
log.Info("rootless mode is enabled, skipping user creation...")
|
||||||
|
u, err := user.Current()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_config.System.Username = u.Username
|
||||||
|
_config.System.User.Uid = system.MustInt(u.Uid)
|
||||||
|
_config.System.User.Gid = system.MustInt(u.Gid)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.WithField("username", _config.System.Username).Info("checking for pterodactyl system user")
|
||||||
u, err := user.Lookup(_config.System.Username)
|
u, err := user.Lookup(_config.System.Username)
|
||||||
// If an error is returned but it isn't the unknown user error just abort
|
// If an error is returned but it isn't the unknown user error just abort
|
||||||
// the process entirely. If we did find a user, return it immediately.
|
// the process entirely. If we did find a user, return it immediately.
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/goccy/go-json"
|
"github.com/goccy/go-json"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -78,6 +79,30 @@ type DockerConfiguration struct {
|
||||||
Overhead Overhead `json:"overhead" yaml:"overhead"`
|
Overhead Overhead `json:"overhead" yaml:"overhead"`
|
||||||
|
|
||||||
UsePerformantInspect bool `default:"true" json:"use_performant_inspect" yaml:"use_performant_inspect"`
|
UsePerformantInspect bool `default:"true" json:"use_performant_inspect" yaml:"use_performant_inspect"`
|
||||||
|
|
||||||
|
// Sets the user namespace mode for the container when user namespace remapping option is
|
||||||
|
// enabled.
|
||||||
|
//
|
||||||
|
// If the value is blank, the daemon's user namespace remapping configuration is used,
|
||||||
|
// if the value is "host", then the pterodactyl containers are started with user namespace
|
||||||
|
// remapping disabled
|
||||||
|
UsernsMode string `default:"" json:"userns_mode" yaml:"userns_mode"`
|
||||||
|
|
||||||
|
LogConfig struct {
|
||||||
|
Type string `default:"local" json:"type" yaml:"type"`
|
||||||
|
Config map[string]string `default:"{\"max-size\":\"5m\",\"max-file\":\"1\",\"compress\":\"false\",\"mode\":\"non-blocking\"}" json:"config" yaml:"config"`
|
||||||
|
} `json:"log_config" yaml:"log_config"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c DockerConfiguration) ContainerLogConfig() container.LogConfig {
|
||||||
|
if c.LogConfig.Type == "" {
|
||||||
|
return container.LogConfig{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return container.LogConfig{
|
||||||
|
Type: c.LogConfig.Type,
|
||||||
|
Config: c.LogConfig.Config,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegistryConfiguration defines the authentication credentials for a given
|
// RegistryConfiguration defines the authentication credentials for a given
|
||||||
|
|
|
@ -12,6 +12,11 @@ import (
|
||||||
// Defines the allocations available for a given server. When using the Docker environment
|
// Defines the allocations available for a given server. When using the Docker environment
|
||||||
// driver these correspond to mappings for the container that allow external connections.
|
// driver these correspond to mappings for the container that allow external connections.
|
||||||
type Allocations struct {
|
type Allocations struct {
|
||||||
|
// ForceOutgoingIP causes a dedicated bridge network to be created for the
|
||||||
|
// server with a special option, causing Docker to SNAT outgoing traffic to
|
||||||
|
// the DefaultMapping's IP. This is important to servers which rely on external
|
||||||
|
// services that check the IP of the server (Source Engine servers, for example).
|
||||||
|
ForceOutgoingIP bool `json:"force_outgoing_ip"`
|
||||||
// Defines the default allocation that should be used for this server. This is
|
// Defines the default allocation that should be used for this server. This is
|
||||||
// what will be used for {SERVER_IP} and {SERVER_PORT} when modifying configuration
|
// what will be used for {SERVER_IP} and {SERVER_PORT} when modifying configuration
|
||||||
// files or the startup arguments for a server.
|
// files or the startup arguments for a server.
|
||||||
|
|
|
@ -8,6 +8,7 @@ type Settings struct {
|
||||||
Mounts []Mount
|
Mounts []Mount
|
||||||
Allocations Allocations
|
Allocations Allocations
|
||||||
Limits Limits
|
Limits Limits
|
||||||
|
Labels map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Defines the actual configuration struct for the environment with all of the settings
|
// Defines the actual configuration struct for the environment with all of the settings
|
||||||
|
@ -68,6 +69,14 @@ func (c *Configuration) Mounts() []Mount {
|
||||||
return c.settings.Mounts
|
return c.settings.Mounts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Labels returns the container labels associated with this instance.
|
||||||
|
func (c *Configuration) Labels() map[string]string {
|
||||||
|
c.mu.RLock()
|
||||||
|
defer c.mu.RUnlock()
|
||||||
|
|
||||||
|
return c.settings.Labels
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the environment variables associated with this instance.
|
// Returns the environment variables associated with this instance.
|
||||||
func (c *Configuration) EnvironmentVariables() []string {
|
func (c *Configuration) EnvironmentVariables() []string {
|
||||||
c.mu.RLock()
|
c.mu.RLock()
|
||||||
|
|
|
@ -41,12 +41,12 @@ func ConfigureDocker(ctx context.Context) error {
|
||||||
nw := config.Get().Docker.Network
|
nw := config.Get().Docker.Network
|
||||||
resource, err := cli.NetworkInspect(ctx, nw.Name, types.NetworkInspectOptions{})
|
resource, err := cli.NetworkInspect(ctx, nw.Name, types.NetworkInspectOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if client.IsErrNotFound(err) {
|
if !client.IsErrNotFound(err) {
|
||||||
log.Info("creating missing pterodactyl0 interface, this could take a few seconds...")
|
return err
|
||||||
if err := createDockerNetwork(ctx, cli); err != nil {
|
}
|
||||||
return err
|
|
||||||
}
|
log.Info("creating missing pterodactyl0 interface, this could take a few seconds...")
|
||||||
} else {
|
if err := createDockerNetwork(ctx, cli); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/docker/docker/errdefs"
|
"github.com/docker/docker/errdefs"
|
||||||
"github.com/goccy/go-json"
|
"github.com/goccy/go-json"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/config"
|
"github.com/pterodactyl/wings/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ import (
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/api/types/mount"
|
"github.com/docker/docker/api/types/mount"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/docker/docker/daemon/logger/local"
|
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/config"
|
"github.com/pterodactyl/wings/config"
|
||||||
"github.com/pterodactyl/wings/environment"
|
"github.com/pterodactyl/wings/environment"
|
||||||
|
@ -43,17 +42,13 @@ func (nw noopWriter) Write(b []byte) (int, error) {
|
||||||
//
|
//
|
||||||
// Calling this function will poll resources for the container in the background
|
// Calling this function will poll resources for the container in the background
|
||||||
// until the container is stopped. The context provided to this function is used
|
// until the container is stopped. The context provided to this function is used
|
||||||
// for the purposes of attaching to the container, a seecond context is created
|
// for the purposes of attaching to the container, a second context is created
|
||||||
// within the function for managing polling.
|
// within the function for managing polling.
|
||||||
func (e *Environment) Attach(ctx context.Context) error {
|
func (e *Environment) Attach(ctx context.Context) error {
|
||||||
if e.IsAttached() {
|
if e.IsAttached() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := e.followOutput(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
opts := types.ContainerAttachOptions{
|
opts := types.ContainerAttachOptions{
|
||||||
Stdin: true,
|
Stdin: true,
|
||||||
Stdout: true,
|
Stdout: true,
|
||||||
|
@ -90,20 +85,13 @@ func (e *Environment) Attach(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Block the completion of this routine until the container is no longer running. This allows
|
if err := system.ScanReader(e.stream.Reader, func(v []byte) {
|
||||||
// the pollResources function to run until it needs to be stopped. Because the container
|
e.logCallbackMx.Lock()
|
||||||
// can be polled for resource usage, even when stopped, we need to have this logic present
|
defer e.logCallbackMx.Unlock()
|
||||||
// in order to cancel the context and therefore stop the routine that is spawned.
|
e.logCallback(v)
|
||||||
//
|
}); err != nil && err != io.EOF {
|
||||||
// For now, DO NOT use client#ContainerWait from the Docker package. There is a nasty
|
log.WithField("error", err).WithField("container_id", e.Id).Warn("error processing scanner line in console output")
|
||||||
// bug causing containers to hang on deletion and cause servers to lock up on the system.
|
return
|
||||||
//
|
|
||||||
// This weird code isn't intuitive, but it keeps the function from ending until the container
|
|
||||||
// is stopped and therefore the stream reader ends up closed.
|
|
||||||
// @see https://github.com/moby/moby/issues/41827
|
|
||||||
c := new(noopWriter)
|
|
||||||
if _, err := io.Copy(c, e.stream.Reader); err != nil {
|
|
||||||
e.log().WithField("error", err).Error("could not copy from environment stream to noop writer")
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -147,10 +135,12 @@ func (e *Environment) InSituUpdate() error {
|
||||||
// currently available for it. If the container already exists it will be
|
// currently available for it. If the container already exists it will be
|
||||||
// returned.
|
// returned.
|
||||||
func (e *Environment) Create() error {
|
func (e *Environment) Create() error {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
// If the container already exists don't hit the user with an error, just return
|
// If the container already exists don't hit the user with an error, just return
|
||||||
// the current information about it which is what we would do when creating the
|
// the current information about it which is what we would do when creating the
|
||||||
// container anyways.
|
// container anyways.
|
||||||
if _, err := e.ContainerInspect(context.Background()); err == nil {
|
if _, err := e.ContainerInspect(ctx); err == nil {
|
||||||
return nil
|
return nil
|
||||||
} else if !client.IsErrNotFound(err) {
|
} else if !client.IsErrNotFound(err) {
|
||||||
return errors.Wrap(err, "environment/docker: failed to inspect container")
|
return errors.Wrap(err, "environment/docker: failed to inspect container")
|
||||||
|
@ -161,21 +151,30 @@ func (e *Environment) Create() error {
|
||||||
return errors.WithStackIf(err)
|
return errors.WithStackIf(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg := config.Get()
|
||||||
a := e.Configuration.Allocations()
|
a := e.Configuration.Allocations()
|
||||||
|
|
||||||
evs := e.Configuration.EnvironmentVariables()
|
evs := e.Configuration.EnvironmentVariables()
|
||||||
for i, v := range evs {
|
for i, v := range evs {
|
||||||
// Convert 127.0.0.1 to the pterodactyl0 network interface if the environment is Docker
|
// Convert 127.0.0.1 to the pterodactyl0 network interface if the environment is Docker
|
||||||
// so that the server operates as expected.
|
// so that the server operates as expected.
|
||||||
if v == "SERVER_IP=127.0.0.1" {
|
if v == "SERVER_IP=127.0.0.1" {
|
||||||
evs[i] = "SERVER_IP=" + config.Get().Docker.Network.Interface
|
evs[i] = "SERVER_IP=" + cfg.Docker.Network.Interface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Merge user-provided labels with system labels
|
||||||
|
confLabels := e.Configuration.Labels()
|
||||||
|
labels := make(map[string]string, 2+len(confLabels))
|
||||||
|
|
||||||
|
for key := range confLabels {
|
||||||
|
labels[key] = confLabels[key]
|
||||||
|
}
|
||||||
|
labels["Service"] = "Pterodactyl"
|
||||||
|
labels["ContainerType"] = "server_process"
|
||||||
|
|
||||||
conf := &container.Config{
|
conf := &container.Config{
|
||||||
Hostname: e.Id,
|
Hostname: e.Id,
|
||||||
Domainname: config.Get().Docker.Domainname,
|
Domainname: cfg.Docker.Domainname,
|
||||||
User: strconv.Itoa(config.Get().System.User.Uid) + ":" + strconv.Itoa(config.Get().System.User.Gid),
|
|
||||||
AttachStdin: true,
|
AttachStdin: true,
|
||||||
AttachStdout: true,
|
AttachStdout: true,
|
||||||
AttachStderr: true,
|
AttachStderr: true,
|
||||||
|
@ -184,13 +183,44 @@ func (e *Environment) Create() error {
|
||||||
ExposedPorts: a.Exposed(),
|
ExposedPorts: a.Exposed(),
|
||||||
Image: strings.TrimPrefix(e.meta.Image, "~"),
|
Image: strings.TrimPrefix(e.meta.Image, "~"),
|
||||||
Env: e.Configuration.EnvironmentVariables(),
|
Env: e.Configuration.EnvironmentVariables(),
|
||||||
Labels: map[string]string{
|
Labels: labels,
|
||||||
"Service": "Pterodactyl",
|
|
||||||
"ContainerType": "server_process",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpfsSize := strconv.Itoa(int(config.Get().Docker.TmpfsSize))
|
// Set the user running the container properly depending on what mode we are operating in.
|
||||||
|
if cfg.System.User.Rootless.Enabled {
|
||||||
|
conf.User = fmt.Sprintf("%d:%d", cfg.System.User.Rootless.ContainerUID, cfg.System.User.Rootless.ContainerGID)
|
||||||
|
} else {
|
||||||
|
conf.User = strconv.Itoa(cfg.System.User.Uid) + ":" + strconv.Itoa(cfg.System.User.Gid)
|
||||||
|
}
|
||||||
|
|
||||||
|
networkMode := container.NetworkMode(cfg.Docker.Network.Mode)
|
||||||
|
if a.ForceOutgoingIP {
|
||||||
|
e.log().Debug("environment/docker: forcing outgoing IP address")
|
||||||
|
networkName := strings.ReplaceAll(e.Id, "-", "")
|
||||||
|
networkMode = container.NetworkMode(networkName)
|
||||||
|
|
||||||
|
if _, err := e.client.NetworkInspect(ctx, networkName, types.NetworkInspectOptions{}); err != nil {
|
||||||
|
if !client.IsErrNotFound(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := e.client.NetworkCreate(ctx, networkName, types.NetworkCreate{
|
||||||
|
Driver: "bridge",
|
||||||
|
EnableIPv6: false,
|
||||||
|
Internal: false,
|
||||||
|
Attachable: false,
|
||||||
|
Ingress: false,
|
||||||
|
ConfigOnly: false,
|
||||||
|
Options: map[string]string{
|
||||||
|
"encryption": "false",
|
||||||
|
"com.docker.network.bridge.default_bridge": "false",
|
||||||
|
"com.docker.network.host_ipv4": a.DefaultMapping.Ip,
|
||||||
|
},
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
hostConf := &container.HostConfig{
|
hostConf := &container.HostConfig{
|
||||||
PortBindings: a.DockerBindings(),
|
PortBindings: a.DockerBindings(),
|
||||||
|
@ -202,28 +232,20 @@ func (e *Environment) Create() error {
|
||||||
// Configure the /tmp folder mapping in containers. This is necessary for some
|
// Configure the /tmp folder mapping in containers. This is necessary for some
|
||||||
// games that need to make use of it for downloads and other installation processes.
|
// games that need to make use of it for downloads and other installation processes.
|
||||||
Tmpfs: map[string]string{
|
Tmpfs: map[string]string{
|
||||||
"/tmp": "rw,exec,nosuid,size=" + tmpfsSize + "M",
|
"/tmp": "rw,exec,nosuid,size=" + strconv.Itoa(int(cfg.Docker.TmpfsSize)) + "M",
|
||||||
},
|
},
|
||||||
|
|
||||||
// Define resource limits for the container based on the data passed through
|
// Define resource limits for the container based on the data passed through
|
||||||
// from the Panel.
|
// from the Panel.
|
||||||
Resources: e.Configuration.Limits().AsContainerResources(),
|
Resources: e.Configuration.Limits().AsContainerResources(),
|
||||||
|
|
||||||
DNS: config.Get().Docker.Network.Dns,
|
DNS: cfg.Docker.Network.Dns,
|
||||||
|
|
||||||
// Configure logging for the container to make it easier on the Daemon to grab
|
// Configure logging for the container to make it easier on the Daemon to grab
|
||||||
// the server output. Ensure that we don't use too much space on the host machine
|
// the server output. Ensure that we don't use too much space on the host machine
|
||||||
// since we only need it for the last few hundred lines of output and don't care
|
// since we only need it for the last few hundred lines of output and don't care
|
||||||
// about anything else in it.
|
// about anything else in it.
|
||||||
LogConfig: container.LogConfig{
|
LogConfig: cfg.Docker.ContainerLogConfig(),
|
||||||
Type: local.Name,
|
|
||||||
Config: map[string]string{
|
|
||||||
"max-size": "5m",
|
|
||||||
"max-file": "1",
|
|
||||||
"compress": "false",
|
|
||||||
"mode": "non-blocking",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
SecurityOpt: []string{"no-new-privileges"},
|
SecurityOpt: []string{"no-new-privileges"},
|
||||||
ReadonlyRootfs: true,
|
ReadonlyRootfs: true,
|
||||||
|
@ -231,10 +253,11 @@ func (e *Environment) Create() error {
|
||||||
"setpcap", "mknod", "audit_write", "net_raw", "dac_override",
|
"setpcap", "mknod", "audit_write", "net_raw", "dac_override",
|
||||||
"fowner", "fsetid", "net_bind_service", "sys_chroot", "setfcap",
|
"fowner", "fsetid", "net_bind_service", "sys_chroot", "setfcap",
|
||||||
},
|
},
|
||||||
NetworkMode: container.NetworkMode(config.Get().Docker.Network.Mode),
|
NetworkMode: networkMode,
|
||||||
|
UsernsMode: container.UsernsMode(cfg.Docker.UsernsMode),
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := e.client.ContainerCreate(context.Background(), conf, hostConf, nil, nil, e.Id); err != nil {
|
if _, err := e.client.ContainerCreate(ctx, conf, hostConf, nil, nil, e.Id); err != nil {
|
||||||
return errors.Wrap(err, "environment/docker: failed to create container")
|
return errors.Wrap(err, "environment/docker: failed to create container")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,59 +335,6 @@ func (e *Environment) Readlog(lines int) ([]string, error) {
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attaches to the log for the container. This avoids us missing crucial output
|
|
||||||
// that happens in the split seconds before the code moves from 'Starting' to
|
|
||||||
// 'Attaching' on the process.
|
|
||||||
func (e *Environment) followOutput() error {
|
|
||||||
if exists, err := e.Exists(); !exists {
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return errors.New(fmt.Sprintf("no such container: %s", e.Id))
|
|
||||||
}
|
|
||||||
|
|
||||||
opts := types.ContainerLogsOptions{
|
|
||||||
ShowStderr: true,
|
|
||||||
ShowStdout: true,
|
|
||||||
Follow: true,
|
|
||||||
Since: time.Now().Format(time.RFC3339),
|
|
||||||
}
|
|
||||||
|
|
||||||
reader, err := e.client.ContainerLogs(context.Background(), e.Id, opts)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
go e.scanOutput(reader)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Environment) scanOutput(reader io.ReadCloser) {
|
|
||||||
defer reader.Close()
|
|
||||||
|
|
||||||
if err := system.ScanReader(reader, func(v []byte) {
|
|
||||||
e.logCallbackMx.Lock()
|
|
||||||
defer e.logCallbackMx.Unlock()
|
|
||||||
e.logCallback(v)
|
|
||||||
}); err != nil && err != io.EOF {
|
|
||||||
log.WithField("error", err).WithField("container_id", e.Id).Warn("error processing scanner line in console output")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return here if the server is offline or currently stopping.
|
|
||||||
if e.State() == environment.ProcessStoppingState || e.State() == environment.ProcessOfflineState {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close the current reader before starting a new one, the defer will still run,
|
|
||||||
// but it will do nothing if we already closed the stream.
|
|
||||||
_ = reader.Close()
|
|
||||||
|
|
||||||
// Start following the output of the server again.
|
|
||||||
go e.followOutput()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pulls the image from Docker. If there is an error while pulling the image
|
// Pulls the image from Docker. If there is an error while pulling the image
|
||||||
// from the source but the image already exists locally, we will report that
|
// from the source but the image already exists locally, we will report that
|
||||||
// error to the logger but continue with the process.
|
// error to the logger but continue with the process.
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/environment"
|
"github.com/pterodactyl/wings/environment"
|
||||||
"github.com/pterodactyl/wings/events"
|
"github.com/pterodactyl/wings/events"
|
||||||
"github.com/pterodactyl/wings/remote"
|
"github.com/pterodactyl/wings/remote"
|
||||||
|
@ -95,7 +96,7 @@ func (e *Environment) SetStream(s *types.HijackedResponse) {
|
||||||
e.mu.Unlock()
|
e.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsAttached determine if the this process is currently attached to the
|
// IsAttached determines if this process is currently attached to the
|
||||||
// container instance by checking if the stream is nil or not.
|
// container instance by checking if the stream is nil or not.
|
||||||
func (e *Environment) IsAttached() bool {
|
func (e *Environment) IsAttached() bool {
|
||||||
e.mu.RLock()
|
e.mu.RLock()
|
||||||
|
|
|
@ -39,7 +39,7 @@ func (e *Environment) OnBeforeStart(ctx context.Context) error {
|
||||||
//
|
//
|
||||||
// This won't actually run an installation process however, it is just here to ensure the
|
// This won't actually run an installation process however, it is just here to ensure the
|
||||||
// environment gets created properly if it is missing and the server is started. We're making
|
// environment gets created properly if it is missing and the server is started. We're making
|
||||||
// an assumption that all of the files will still exist at this point.
|
// an assumption that all the files will still exist at this point.
|
||||||
if err := e.Create(); err != nil {
|
if err := e.Create(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ func (e *Environment) Start(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we cannot start & attach to the container in 30 seconds something has gone
|
// If we cannot start & attach to the container in 30 seconds something has gone
|
||||||
// quite sideways and we should stop trying to avoid a hanging situation.
|
// quite sideways, and we should stop trying to avoid a hanging situation.
|
||||||
actx, cancel := context.WithTimeout(ctx, time.Second*30)
|
actx, cancel := context.WithTimeout(ctx, time.Second*30)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,11 @@ func calculateDockerAbsoluteCpu(pStats types.CPUStats, stats types.CPUStats) flo
|
||||||
|
|
||||||
percent := 0.0
|
percent := 0.0
|
||||||
if systemDelta > 0.0 && cpuDelta > 0.0 {
|
if systemDelta > 0.0 && cpuDelta > 0.0 {
|
||||||
percent = (cpuDelta / systemDelta) * cpus * 100.0
|
percent = (cpuDelta / systemDelta) * 100.0
|
||||||
|
|
||||||
|
if cpus > 0 {
|
||||||
|
percent *= cpus
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return math.Round(percent*1000) / 1000
|
return math.Round(percent*1000) / 1000
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
"github.com/goccy/go-json"
|
"github.com/goccy/go-json"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/system"
|
"github.com/pterodactyl/wings/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
127
go.mod
127
go.mod
|
@ -1,129 +1,124 @@
|
||||||
module github.com/pterodactyl/wings
|
module github.com/pterodactyl/wings
|
||||||
|
|
||||||
go 1.17
|
go 1.18
|
||||||
|
|
||||||
require (
|
require (
|
||||||
emperror.dev/errors v0.8.1
|
emperror.dev/errors v0.8.1
|
||||||
github.com/AlecAivazis/survey/v2 v2.3.4
|
github.com/AlecAivazis/survey/v2 v2.3.6
|
||||||
github.com/Jeffail/gabs/v2 v2.6.1
|
github.com/Jeffail/gabs/v2 v2.6.1
|
||||||
github.com/NYTimes/logrotate v1.0.0
|
github.com/NYTimes/logrotate v1.0.0
|
||||||
|
github.com/acobaugh/osrelease v0.1.0
|
||||||
github.com/apex/log v1.9.0
|
github.com/apex/log v1.9.0
|
||||||
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
|
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
|
||||||
github.com/beevik/etree v1.1.0
|
github.com/beevik/etree v1.1.0
|
||||||
github.com/buger/jsonparser v1.1.1
|
github.com/buger/jsonparser v1.1.1
|
||||||
github.com/cenkalti/backoff/v4 v4.1.2
|
github.com/cenkalti/backoff/v4 v4.1.3
|
||||||
github.com/cobaugh/osrelease v0.0.0-20181218015638-a93a0a55a249
|
github.com/creasty/defaults v1.6.0
|
||||||
github.com/creasty/defaults v1.5.2
|
github.com/docker/docker v20.10.18+incompatible
|
||||||
github.com/docker/docker v20.10.14+incompatible
|
|
||||||
github.com/docker/go-connections v0.4.0
|
github.com/docker/go-connections v0.4.0
|
||||||
github.com/fatih/color v1.13.0
|
github.com/fatih/color v1.13.0
|
||||||
github.com/franela/goblin v0.0.0-20200825194134-80c0062ed6cd
|
github.com/franela/goblin v0.0.0-20200825194134-80c0062ed6cd
|
||||||
github.com/gabriel-vasile/mimetype v1.4.0
|
github.com/gabriel-vasile/mimetype v1.4.1
|
||||||
github.com/gammazero/workerpool v1.1.2
|
github.com/gammazero/workerpool v1.1.3
|
||||||
github.com/gbrlsnchs/jwt/v3 v3.0.1
|
github.com/gbrlsnchs/jwt/v3 v3.0.1
|
||||||
github.com/gin-gonic/gin v1.7.7
|
github.com/gin-gonic/gin v1.8.1
|
||||||
|
github.com/glebarez/sqlite v1.4.8
|
||||||
|
github.com/go-co-op/gocron v1.17.0
|
||||||
|
github.com/goccy/go-json v0.9.11
|
||||||
github.com/google/uuid v1.3.0
|
github.com/google/uuid v1.3.0
|
||||||
github.com/gorilla/websocket v1.5.0
|
github.com/gorilla/websocket v1.5.0
|
||||||
github.com/iancoleman/strcase v0.2.0
|
github.com/iancoleman/strcase v0.2.0
|
||||||
github.com/icza/dyno v0.0.0-20210726202311-f1bafe5d9996
|
github.com/icza/dyno v0.0.0-20220812133438-f0b6f8a18845
|
||||||
github.com/juju/ratelimit v1.0.1
|
github.com/juju/ratelimit v1.0.2
|
||||||
github.com/karrick/godirwalk v1.16.1
|
github.com/karrick/godirwalk v1.17.0
|
||||||
|
github.com/klauspost/compress v1.15.11
|
||||||
github.com/klauspost/pgzip v1.2.5
|
github.com/klauspost/pgzip v1.2.5
|
||||||
github.com/magiconair/properties v1.8.6
|
github.com/magiconair/properties v1.8.6
|
||||||
github.com/mattn/go-colorable v0.1.12
|
github.com/mattn/go-colorable v0.1.13
|
||||||
github.com/mholt/archiver/v3 v3.5.1
|
github.com/mholt/archiver/v4 v4.0.0-alpha.7
|
||||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||||
github.com/pkg/sftp v1.13.4
|
github.com/pkg/sftp v1.13.5
|
||||||
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
|
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
|
||||||
github.com/spf13/cobra v1.4.0
|
github.com/spf13/cobra v1.5.0
|
||||||
github.com/stretchr/testify v1.7.5
|
github.com/stretchr/testify v1.8.0
|
||||||
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064
|
golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
|
golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0
|
||||||
gopkg.in/ini.v1 v1.66.4
|
gopkg.in/ini.v1 v1.67.0
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
gopkg.in/yaml.v2 v2.4.0
|
||||||
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
|
gorm.io/gorm v1.23.10
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/glebarez/sqlite v1.4.6
|
|
||||||
github.com/go-co-op/gocron v1.15.0
|
|
||||||
github.com/goccy/go-json v0.9.6
|
|
||||||
github.com/klauspost/compress v1.15.1
|
|
||||||
gorm.io/gorm v1.23.8
|
|
||||||
)
|
|
||||||
|
|
||||||
require golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
|
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
|
||||||
github.com/Microsoft/go-winio v0.5.2 // indirect
|
github.com/Microsoft/go-winio v0.6.0 // indirect
|
||||||
github.com/Microsoft/hcsshim v0.9.2 // indirect
|
github.com/Microsoft/hcsshim v0.9.4 // indirect
|
||||||
github.com/andybalholm/brotli v1.0.4 // indirect
|
github.com/andybalholm/brotli v1.0.4 // indirect
|
||||||
github.com/beorn7/perks v1.0.1 // indirect
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||||
github.com/containerd/containerd v1.6.2 // indirect
|
|
||||||
github.com/containerd/fifo v1.0.0 // indirect
|
github.com/containerd/fifo v1.0.0 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/docker/distribution v2.8.1+incompatible // indirect
|
github.com/docker/distribution v2.8.1+incompatible // indirect
|
||||||
github.com/docker/go-metrics v0.0.1 // indirect
|
github.com/docker/go-metrics v0.0.1 // indirect
|
||||||
github.com/docker/go-units v0.4.0 // indirect
|
github.com/docker/go-units v0.5.0 // indirect
|
||||||
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect
|
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect
|
||||||
github.com/fsnotify/fsnotify v1.5.1 // indirect
|
github.com/fsnotify/fsnotify v1.5.4 // indirect
|
||||||
github.com/gammazero/deque v0.1.1 // indirect
|
github.com/gammazero/deque v0.2.0 // indirect
|
||||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
github.com/glebarez/go-sqlite v1.17.3 // indirect
|
github.com/glebarez/go-sqlite v1.19.1 // indirect
|
||||||
github.com/go-playground/locales v0.14.0 // indirect
|
github.com/go-playground/locales v0.14.0 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.0 // indirect
|
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||||
github.com/go-playground/validator/v10 v10.10.1 // indirect
|
github.com/go-playground/validator/v10 v10.11.1 // indirect
|
||||||
github.com/gogo/protobuf v1.3.2 // indirect
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
github.com/golang/protobuf v1.5.2 // indirect
|
github.com/golang/protobuf v1.5.2 // indirect
|
||||||
github.com/golang/snappy v0.0.4 // indirect
|
github.com/golang/snappy v0.0.4 // indirect
|
||||||
github.com/gorilla/mux v1.7.4 // indirect
|
github.com/inconshreveable/mousetrap v1.0.1 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
github.com/jinzhu/now v1.1.5 // indirect
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
|
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
|
||||||
github.com/kr/fs v0.1.0 // indirect
|
github.com/kr/fs v0.1.0 // indirect
|
||||||
github.com/leodido/go-urn v1.2.1 // indirect
|
github.com/leodido/go-urn v1.2.1 // indirect
|
||||||
github.com/magefile/mage v1.13.0 // indirect
|
github.com/magefile/mage v1.14.0 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
github.com/mattn/go-isatty v0.0.16 // indirect
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
|
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
|
||||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
|
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
|
||||||
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
|
github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
github.com/morikuni/aec v1.0.0 // indirect
|
github.com/morikuni/aec v1.0.0 // indirect
|
||||||
github.com/nwaples/rardecode v1.1.3 // indirect
|
github.com/nwaples/rardecode/v2 v2.0.0-beta.2 // indirect
|
||||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||||
github.com/opencontainers/image-spec v1.0.2 // indirect
|
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
|
||||||
github.com/pierrec/lz4/v4 v4.1.14 // indirect
|
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
|
||||||
|
github.com/pierrec/lz4/v4 v4.1.17 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/prometheus/client_golang v1.12.1 // indirect
|
github.com/prometheus/client_golang v1.13.0 // indirect
|
||||||
github.com/prometheus/client_model v0.2.0 // indirect
|
github.com/prometheus/client_model v0.2.0 // indirect
|
||||||
github.com/prometheus/common v0.32.1 // indirect
|
github.com/prometheus/common v0.37.0 // indirect
|
||||||
github.com/prometheus/procfs v0.7.3 // indirect
|
github.com/prometheus/procfs v0.8.0 // indirect
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
|
github.com/remyoudompheng/bigfft v0.0.0-20220927061507-ef77025ab5aa // indirect
|
||||||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||||
github.com/sirupsen/logrus v1.8.1 // indirect
|
github.com/sirupsen/logrus v1.9.0 // indirect
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
|
github.com/therootcompany/xz v1.0.1 // indirect
|
||||||
github.com/ugorji/go/codec v1.2.7 // indirect
|
github.com/ugorji/go/codec v1.2.7 // indirect
|
||||||
github.com/ulikunitz/xz v0.5.10 // indirect
|
github.com/ulikunitz/xz v0.5.10 // indirect
|
||||||
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
|
go.uber.org/atomic v1.10.0 // indirect
|
||||||
go.uber.org/atomic v1.9.0 // indirect
|
|
||||||
go.uber.org/multierr v1.8.0 // indirect
|
go.uber.org/multierr v1.8.0 // indirect
|
||||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
|
golang.org/x/net v0.0.0-20221004154528-8021a29435af // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec // indirect
|
||||||
|
golang.org/x/term v0.0.0-20220919170432-7a66f970e087 // indirect
|
||||||
golang.org/x/text v0.3.7 // indirect
|
golang.org/x/text v0.3.7 // indirect
|
||||||
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 // indirect
|
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
golang.org/x/tools v0.1.12 // indirect
|
||||||
google.golang.org/genproto v0.0.0-20220324131243-acbaeb5b85eb // indirect
|
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
|
||||||
google.golang.org/grpc v1.45.0 // indirect
|
google.golang.org/protobuf v1.28.1 // indirect
|
||||||
google.golang.org/protobuf v1.28.0 // indirect
|
modernc.org/libc v1.20.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
modernc.org/mathutil v1.5.0 // indirect
|
||||||
modernc.org/libc v1.16.17 // indirect
|
modernc.org/memory v1.4.0 // indirect
|
||||||
modernc.org/mathutil v1.4.1 // indirect
|
modernc.org/sqlite v1.19.1 // indirect
|
||||||
modernc.org/memory v1.1.1 // indirect
|
|
||||||
modernc.org/sqlite v1.17.3 // indirect
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
"github.com/asaskevich/govalidator"
|
"github.com/asaskevich/govalidator"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/remote"
|
"github.com/pterodactyl/wings/remote"
|
||||||
"github.com/pterodactyl/wings/server"
|
"github.com/pterodactyl/wings/server"
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,7 +2,9 @@ package cron
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/internal/database"
|
"github.com/pterodactyl/wings/internal/database"
|
||||||
"github.com/pterodactyl/wings/internal/models"
|
"github.com/pterodactyl/wings/internal/models"
|
||||||
"github.com/pterodactyl/wings/server"
|
"github.com/pterodactyl/wings/server"
|
||||||
|
|
|
@ -2,13 +2,15 @@ package cron
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
log2 "github.com/apex/log"
|
log2 "github.com/apex/log"
|
||||||
"github.com/go-co-op/gocron"
|
"github.com/go-co-op/gocron"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/config"
|
"github.com/pterodactyl/wings/config"
|
||||||
"github.com/pterodactyl/wings/server"
|
"github.com/pterodactyl/wings/server"
|
||||||
"github.com/pterodactyl/wings/system"
|
"github.com/pterodactyl/wings/system"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const ErrCronRunning = errors.Sentinel("cron: job already running")
|
const ErrCronRunning = errors.Sentinel("cron: job already running")
|
||||||
|
|
|
@ -2,12 +2,14 @@ package cron
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/internal/database"
|
"github.com/pterodactyl/wings/internal/database"
|
||||||
"github.com/pterodactyl/wings/internal/models"
|
"github.com/pterodactyl/wings/internal/models"
|
||||||
"github.com/pterodactyl/wings/server"
|
"github.com/pterodactyl/wings/server"
|
||||||
"github.com/pterodactyl/wings/system"
|
"github.com/pterodactyl/wings/system"
|
||||||
"reflect"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type sftpCron struct {
|
type sftpCron struct {
|
||||||
|
|
|
@ -1,19 +1,23 @@
|
||||||
package database
|
package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
"github.com/glebarez/sqlite"
|
"github.com/glebarez/sqlite"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"gorm.io/gorm/logger"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/config"
|
"github.com/pterodactyl/wings/config"
|
||||||
"github.com/pterodactyl/wings/internal/models"
|
"github.com/pterodactyl/wings/internal/models"
|
||||||
"github.com/pterodactyl/wings/system"
|
"github.com/pterodactyl/wings/system"
|
||||||
"gorm.io/gorm"
|
|
||||||
"gorm.io/gorm/logger"
|
|
||||||
"path/filepath"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var o system.AtomicBool
|
var (
|
||||||
var db *gorm.DB
|
o system.AtomicBool
|
||||||
|
db *gorm.DB
|
||||||
|
)
|
||||||
|
|
||||||
// Initialize configures the local SQLite database for Wings and ensures that the models have
|
// Initialize configures the local SQLite database for Wings and ensures that the models have
|
||||||
// been fully migrated.
|
// been fully migrated.
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/pterodactyl/wings/system"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
|
||||||
|
"github.com/pterodactyl/wings/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Event string
|
type Event string
|
||||||
|
|
|
@ -2,6 +2,7 @@ package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
"github.com/goccy/go-json"
|
"github.com/goccy/go-json"
|
||||||
)
|
)
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
"github.com/icza/dyno"
|
"github.com/icza/dyno"
|
||||||
"github.com/magiconair/properties"
|
"github.com/magiconair/properties"
|
||||||
"gopkg.in/ini.v1"
|
"gopkg.in/ini.v1"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/config"
|
"github.com/pterodactyl/wings/config"
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,13 +4,14 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pterodactyl/wings/internal/models"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pterodactyl/wings/internal/models"
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/cenkalti/backoff/v4"
|
"github.com/cenkalti/backoff/v4"
|
||||||
|
|
|
@ -3,10 +3,11 @@ package remote
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pterodactyl/wings/internal/models"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/pterodactyl/wings/internal/models"
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
|
|
|
@ -2,11 +2,12 @@ package remote
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/apex/log"
|
|
||||||
"github.com/goccy/go-json"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/apex/log"
|
||||||
|
"github.com/goccy/go-json"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/parser"
|
"github.com/pterodactyl/wings/parser"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -156,9 +157,15 @@ type BackupRemoteUploadResponse struct {
|
||||||
PartSize int64 `json:"part_size"`
|
PartSize int64 `json:"part_size"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BackupRequest struct {
|
type BackupPart struct {
|
||||||
Checksum string `json:"checksum"`
|
ETag string `json:"etag"`
|
||||||
ChecksumType string `json:"checksum_type"`
|
PartNumber int `json:"part_number"`
|
||||||
Size int64 `json:"size"`
|
}
|
||||||
Successful bool `json:"successful"`
|
|
||||||
|
type BackupRequest struct {
|
||||||
|
Checksum string `json:"checksum"`
|
||||||
|
ChecksumType string `json:"checksum_type"`
|
||||||
|
Size int64 `json:"size"`
|
||||||
|
Successful bool `json:"successful"`
|
||||||
|
Parts []BackupPart `json:"parts"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
"github.com/pterodactyl/wings/config"
|
||||||
"github.com/pterodactyl/wings/remote"
|
"github.com/pterodactyl/wings/remote"
|
||||||
"github.com/pterodactyl/wings/router/middleware"
|
"github.com/pterodactyl/wings/router/middleware"
|
||||||
wserver "github.com/pterodactyl/wings/server"
|
wserver "github.com/pterodactyl/wings/server"
|
||||||
|
@ -15,6 +16,7 @@ func Configure(m *wserver.Manager, client remote.Client) *gin.Engine {
|
||||||
|
|
||||||
router := gin.New()
|
router := gin.New()
|
||||||
router.Use(gin.Recovery())
|
router.Use(gin.Recovery())
|
||||||
|
router.SetTrustedProxies(config.Get().Api.TrustedProxies)
|
||||||
router.Use(middleware.AttachRequestID(), middleware.CaptureErrors(), middleware.SetAccessControlHeaders())
|
router.Use(middleware.AttachRequestID(), middleware.CaptureErrors(), middleware.SetAccessControlHeaders())
|
||||||
router.Use(middleware.AttachServerManager(m), middleware.AttachApiClient(client))
|
router.Use(middleware.AttachServerManager(m), middleware.AttachApiClient(client))
|
||||||
// @todo log this into a different file so you can setup IP blocking for abusive requests and such.
|
// @todo log this into a different file so you can setup IP blocking for abusive requests and such.
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/router/downloader"
|
"github.com/pterodactyl/wings/router/downloader"
|
||||||
"github.com/pterodactyl/wings/router/middleware"
|
"github.com/pterodactyl/wings/router/middleware"
|
||||||
"github.com/pterodactyl/wings/router/tokens"
|
"github.com/pterodactyl/wings/router/tokens"
|
||||||
|
@ -180,7 +181,7 @@ func postServerReinstall(c *gin.Context) {
|
||||||
c.Status(http.StatusAccepted)
|
c.Status(http.StatusAccepted)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deletes a server from the wings daemon and dissociate it's objects.
|
// Deletes a server from the wings daemon and dissociate its objects.
|
||||||
func deleteServer(c *gin.Context) {
|
func deleteServer(c *gin.Context) {
|
||||||
s := middleware.ExtractServer(c)
|
s := middleware.ExtractServer(c)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ package router
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"github.com/pterodactyl/wings/internal/models"
|
|
||||||
"io"
|
"io"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -14,13 +13,13 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/config"
|
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
|
|
||||||
|
"github.com/pterodactyl/wings/config"
|
||||||
|
"github.com/pterodactyl/wings/internal/models"
|
||||||
"github.com/pterodactyl/wings/router/downloader"
|
"github.com/pterodactyl/wings/router/downloader"
|
||||||
"github.com/pterodactyl/wings/router/middleware"
|
"github.com/pterodactyl/wings/router/middleware"
|
||||||
"github.com/pterodactyl/wings/router/tokens"
|
"github.com/pterodactyl/wings/router/tokens"
|
||||||
|
@ -441,7 +440,7 @@ func postServerDecompressFiles(c *gin.Context) {
|
||||||
s := middleware.ExtractServer(c)
|
s := middleware.ExtractServer(c)
|
||||||
lg := middleware.ExtractLogger(c).WithFields(log.Fields{"root_path": data.RootPath, "file": data.File})
|
lg := middleware.ExtractLogger(c).WithFields(log.Fields{"root_path": data.RootPath, "file": data.File})
|
||||||
lg.Debug("checking if space is available for file decompression")
|
lg.Debug("checking if space is available for file decompression")
|
||||||
err := s.Filesystem().SpaceAvailableForDecompression(data.RootPath, data.File)
|
err := s.Filesystem().SpaceAvailableForDecompression(context.Background(), data.RootPath, data.File)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if filesystem.IsErrorCode(err, filesystem.ErrCodeUnknownArchive) {
|
if filesystem.IsErrorCode(err, filesystem.ErrCodeUnknownArchive) {
|
||||||
lg.WithField("error", err).Warn("failed to decompress file: unknown archive format")
|
lg.WithField("error", err).Warn("failed to decompress file: unknown archive format")
|
||||||
|
@ -453,7 +452,7 @@ func postServerDecompressFiles(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
lg.Info("starting file decompression")
|
lg.Info("starting file decompression")
|
||||||
if err := s.Filesystem().DecompressFile(data.RootPath, data.File); err != nil {
|
if err := s.Filesystem().DecompressFile(context.Background(), data.RootPath, data.File); err != nil {
|
||||||
// If the file is busy for some reason just return a nicer error to the user since there is not
|
// If the file is busy for some reason just return a nicer error to the user since there is not
|
||||||
// much we specifically can do. They'll need to stop the running server process in order to overwrite
|
// much we specifically can do. They'll need to stop the running server process in order to overwrite
|
||||||
// a file like this.
|
// a file like this.
|
||||||
|
@ -602,7 +601,7 @@ func postServerUploadFiles(c *gin.Context) {
|
||||||
NewServerError(err, s).Abort(c)
|
NewServerError(err, s).Abort(c)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
s.SaveActivity(s.NewRequestActivity(token.UserUuid, c.Request.RemoteAddr), server.ActivityFileUploaded, models.ActivityMeta{
|
s.SaveActivity(s.NewRequestActivity(token.UserUuid, c.ClientIP()), server.ActivityFileUploaded, models.ActivityMeta{
|
||||||
"file": header.Filename,
|
"file": header.Filename,
|
||||||
"directory": filepath.Clean(directory),
|
"directory": filepath.Clean(directory),
|
||||||
})
|
})
|
||||||
|
|
|
@ -32,7 +32,7 @@ func getServerWebsocket(c *gin.Context) {
|
||||||
ctx, cancel := context.WithCancel(c.Request.Context())
|
ctx, cancel := context.WithCancel(c.Request.Context())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
handler, err := websocket.GetHandler(s, c.Writer, c.Request)
|
handler, err := websocket.GetHandler(s, c.Writer, c.Request, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
NewServerError(err, s).Abort(c)
|
NewServerError(err, s).Abort(c)
|
||||||
return
|
return
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
|
@ -20,7 +19,6 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/juju/ratelimit"
|
"github.com/juju/ratelimit"
|
||||||
"github.com/mholt/archiver/v3"
|
|
||||||
"github.com/mitchellh/colorstring"
|
"github.com/mitchellh/colorstring"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/config"
|
"github.com/pterodactyl/wings/config"
|
||||||
|
@ -30,19 +28,9 @@ import (
|
||||||
"github.com/pterodactyl/wings/router/tokens"
|
"github.com/pterodactyl/wings/router/tokens"
|
||||||
"github.com/pterodactyl/wings/server"
|
"github.com/pterodactyl/wings/server"
|
||||||
"github.com/pterodactyl/wings/server/filesystem"
|
"github.com/pterodactyl/wings/server/filesystem"
|
||||||
"github.com/pterodactyl/wings/system"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Number of ticks in the progress bar
|
const progressWidth = 25
|
||||||
const ticks = 25
|
|
||||||
|
|
||||||
// 100% / number of ticks = percentage represented by each tick
|
|
||||||
const tickPercentage = 100 / ticks
|
|
||||||
|
|
||||||
type downloadProgress struct {
|
|
||||||
size int64
|
|
||||||
progress int64
|
|
||||||
}
|
|
||||||
|
|
||||||
// Data passed over to initiate a server transfer.
|
// Data passed over to initiate a server transfer.
|
||||||
type serverTransferRequest struct {
|
type serverTransferRequest struct {
|
||||||
|
@ -95,7 +83,7 @@ func getServerArchive(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute sha1 checksum.
|
// Compute sha256 checksum.
|
||||||
h := sha256.New()
|
h := sha256.New()
|
||||||
f, err := os.Open(archivePath)
|
f, err := os.Open(archivePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -184,11 +172,35 @@ func postServerArchive(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the disk usage of the server (used to calculate the progress of the archive process)
|
||||||
|
rawSize, err := s.Filesystem().DiskUsage(true)
|
||||||
|
if err != nil {
|
||||||
|
sendTransferLog("Failed to get disk usage for server, aborting transfer..")
|
||||||
|
l.WithField("error", err).Error("failed to get disk usage for server")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Create an archive of the entire server's data directory.
|
// Create an archive of the entire server's data directory.
|
||||||
a := &filesystem.Archive{
|
a := &filesystem.Archive{
|
||||||
BasePath: s.Filesystem().Path(),
|
BasePath: s.Filesystem().Path(),
|
||||||
|
Progress: filesystem.NewProgress(rawSize),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send the archive progress to the websocket every 3 seconds.
|
||||||
|
ctx2, cancel := context.WithCancel(s.Context())
|
||||||
|
defer cancel()
|
||||||
|
go func(ctx context.Context, p *filesystem.Progress, t *time.Ticker) {
|
||||||
|
defer t.Stop()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
case <-t.C:
|
||||||
|
sendTransferLog("Archiving " + p.Progress(progressWidth))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}(ctx2, a.Progress, time.NewTicker(5*time.Second))
|
||||||
|
|
||||||
// Attempt to get an archive of the server.
|
// Attempt to get an archive of the server.
|
||||||
if err := a.Create(getArchivePath(s.ID())); err != nil {
|
if err := a.Create(getArchivePath(s.ID())); err != nil {
|
||||||
sendTransferLog("An error occurred while archiving the server: " + err.Error())
|
sendTransferLog("An error occurred while archiving the server: " + err.Error())
|
||||||
|
@ -196,6 +208,12 @@ func postServerArchive(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cancel the progress ticker.
|
||||||
|
cancel()
|
||||||
|
|
||||||
|
// Show 100% completion.
|
||||||
|
sendTransferLog("Archiving " + a.Progress.Progress(progressWidth))
|
||||||
|
|
||||||
sendTransferLog("Successfully created archive, attempting to notify panel..")
|
sendTransferLog("Successfully created archive, attempting to notify panel..")
|
||||||
l.Info("successfully created server transfer archive, notifying panel..")
|
l.Info("successfully created server transfer archive, notifying panel..")
|
||||||
|
|
||||||
|
@ -223,12 +241,6 @@ func postServerArchive(c *gin.Context) {
|
||||||
c.Status(http.StatusAccepted)
|
c.Status(http.StatusAccepted)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *downloadProgress) Write(v []byte) (int, error) {
|
|
||||||
n := len(v)
|
|
||||||
atomic.AddInt64(&w.progress, int64(n))
|
|
||||||
return n, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log helper function to attach all errors and info output to a consistently formatted
|
// Log helper function to attach all errors and info output to a consistently formatted
|
||||||
// log string for easier querying.
|
// log string for easier querying.
|
||||||
func (str serverTransferRequest) log() *log.Entry {
|
func (str serverTransferRequest) log() *log.Entry {
|
||||||
|
@ -321,7 +333,7 @@ func postTransfer(c *gin.Context) {
|
||||||
manager := middleware.ExtractManager(c)
|
manager := middleware.ExtractManager(c)
|
||||||
u, err := uuid.Parse(data.ServerID)
|
u, err := uuid.Parse(data.ServerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
WithError(c, err)
|
_ = WithError(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Force the server ID to be a valid UUID string at this point. If it is not an error
|
// Force the server ID to be a valid UUID string at this point. If it is not an error
|
||||||
|
@ -331,11 +343,12 @@ func postTransfer(c *gin.Context) {
|
||||||
|
|
||||||
data.log().Info("handling incoming server transfer request")
|
data.log().Info("handling incoming server transfer request")
|
||||||
go func(data *serverTransferRequest) {
|
go func(data *serverTransferRequest) {
|
||||||
|
ctx := context.Background()
|
||||||
hasError := true
|
hasError := true
|
||||||
|
|
||||||
// Create a new server installer. This will only configure the environment and not
|
// Create a new server installer. This will only configure the environment and not
|
||||||
// run the installer scripts.
|
// run the installer scripts.
|
||||||
i, err := installer.New(context.Background(), manager, data.Server)
|
i, err := installer.New(ctx, manager, data.Server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = data.sendTransferStatus(manager.Client(), false)
|
_ = data.sendTransferStatus(manager.Client(), false)
|
||||||
data.log().WithField("error", err).Error("failed to validate received server data")
|
data.log().WithField("error", err).Error("failed to validate received server data")
|
||||||
|
@ -407,25 +420,23 @@ func postTransfer(c *gin.Context) {
|
||||||
sendTransferLog("Writing archive to disk...")
|
sendTransferLog("Writing archive to disk...")
|
||||||
data.log().Info("writing transfer archive to disk...")
|
data.log().Info("writing transfer archive to disk...")
|
||||||
|
|
||||||
// Copy the file.
|
progress := filesystem.NewProgress(size)
|
||||||
progress := &downloadProgress{size: size}
|
progress.SetWriter(file)
|
||||||
ticker := time.NewTicker(3 * time.Second)
|
|
||||||
go func(progress *downloadProgress, t *time.Ticker) {
|
// Send the archive progress to the websocket every 3 seconds.
|
||||||
for range ticker.C {
|
ctx2, cancel := context.WithCancel(ctx)
|
||||||
// p = 100 (Downloaded)
|
defer cancel()
|
||||||
// size = 1000 (Content-Length)
|
go func(ctx context.Context, p *filesystem.Progress, t *time.Ticker) {
|
||||||
// p / size = 0.1
|
defer t.Stop()
|
||||||
// * 100 = 10% (Multiply by 100 to get a percentage of the download)
|
for {
|
||||||
// 10% / tickPercentage = (10% / (100 / 25)) (Divide by tick percentage to get the number of ticks)
|
select {
|
||||||
// 2.5 (Number of ticks as a float64)
|
case <-ctx.Done():
|
||||||
// 2 (convert to an integer)
|
return
|
||||||
p := atomic.LoadInt64(&progress.progress)
|
case <-t.C:
|
||||||
// We have to cast these numbers to float in order to get a float result from the division.
|
sendTransferLog("Downloading " + p.Progress(progressWidth))
|
||||||
width := ((float64(p) / float64(size)) * 100) / tickPercentage
|
}
|
||||||
bar := strings.Repeat("=", int(width)) + strings.Repeat(" ", ticks-int(width))
|
|
||||||
sendTransferLog("Downloading [" + bar + "] " + system.FormatBytes(p) + " / " + system.FormatBytes(progress.size))
|
|
||||||
}
|
}
|
||||||
}(progress, ticker)
|
}(ctx2, progress, time.NewTicker(5*time.Second))
|
||||||
|
|
||||||
var reader io.Reader
|
var reader io.Reader
|
||||||
downloadLimit := float64(config.Get().System.Transfers.DownloadLimit) * 1024 * 1024
|
downloadLimit := float64(config.Get().System.Transfers.DownloadLimit) * 1024 * 1024
|
||||||
|
@ -437,19 +448,17 @@ func postTransfer(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := make([]byte, 1024*4)
|
buf := make([]byte, 1024*4)
|
||||||
if _, err := io.CopyBuffer(file, io.TeeReader(reader, progress), buf); err != nil {
|
if _, err := io.CopyBuffer(progress, reader, buf); err != nil {
|
||||||
ticker.Stop()
|
|
||||||
_ = file.Close()
|
_ = file.Close()
|
||||||
|
|
||||||
sendTransferLog("Failed while writing archive file to disk: " + err.Error())
|
sendTransferLog("Failed while writing archive file to disk: " + err.Error())
|
||||||
data.log().WithField("error", err).Error("failed to copy archive file to disk")
|
data.log().WithField("error", err).Error("failed to copy archive file to disk")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ticker.Stop()
|
cancel()
|
||||||
|
|
||||||
// Show 100% completion.
|
// Show 100% completion.
|
||||||
humanSize := system.FormatBytes(progress.size)
|
sendTransferLog("Downloading " + progress.Progress(progressWidth))
|
||||||
sendTransferLog("Downloading [" + strings.Repeat("=", ticks) + "] " + humanSize + " / " + humanSize)
|
|
||||||
|
|
||||||
if err := file.Close(); err != nil {
|
if err := file.Close(); err != nil {
|
||||||
data.log().WithField("error", err).Error("unable to close archive file on local filesystem")
|
data.log().WithField("error", err).Error("unable to close archive file on local filesystem")
|
||||||
|
@ -486,7 +495,7 @@ func postTransfer(c *gin.Context) {
|
||||||
|
|
||||||
sendTransferLog("Server environment has been created, extracting transfer archive..")
|
sendTransferLog("Server environment has been created, extracting transfer archive..")
|
||||||
data.log().Info("server environment configured, extracting transfer archive")
|
data.log().Info("server environment configured, extracting transfer archive")
|
||||||
if err := archiver.NewTarGz().Unarchive(data.path(), i.Server().Filesystem().Path()); err != nil {
|
if err := i.Server().Filesystem().DecompressFileUnsafe(ctx, "/", data.path()); err != nil {
|
||||||
// Un-archiving failed, delete the server's data directory.
|
// Un-archiving failed, delete the server's data directory.
|
||||||
if err := os.RemoveAll(i.Server().Filesystem().Path()); err != nil && !os.IsNotExist(err) {
|
if err := os.RemoveAll(i.Server().Filesystem().Path()); err != nil && !os.IsNotExist(err) {
|
||||||
data.log().WithField("error", err).Warn("failed to delete local server files directory")
|
data.log().WithField("error", err).Warn("failed to delete local server files directory")
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
"github.com/goccy/go-json"
|
"github.com/goccy/go-json"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/events"
|
"github.com/pterodactyl/wings/events"
|
||||||
"github.com/pterodactyl/wings/system"
|
"github.com/pterodactyl/wings/system"
|
||||||
|
|
||||||
|
|
|
@ -3,18 +3,21 @@ package websocket
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pterodactyl/wings/internal/models"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pterodactyl/wings/internal/models"
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/gbrlsnchs/jwt/v3"
|
"github.com/gbrlsnchs/jwt/v3"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/goccy/go-json"
|
"github.com/goccy/go-json"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/system"
|
"github.com/pterodactyl/wings/system"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/config"
|
"github.com/pterodactyl/wings/config"
|
||||||
|
@ -79,7 +82,7 @@ func NewTokenPayload(token []byte) (*tokens.WebsocketPayload, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetHandler returns a new websocket handler using the context provided.
|
// GetHandler returns a new websocket handler using the context provided.
|
||||||
func GetHandler(s *server.Server, w http.ResponseWriter, r *http.Request) (*Handler, error) {
|
func GetHandler(s *server.Server, w http.ResponseWriter, r *http.Request, c *gin.Context) (*Handler, error) {
|
||||||
upgrader := websocket.Upgrader{
|
upgrader := websocket.Upgrader{
|
||||||
// Ensure that the websocket request is originating from the Panel itself,
|
// Ensure that the websocket request is originating from the Panel itself,
|
||||||
// and not some other location.
|
// and not some other location.
|
||||||
|
@ -111,7 +114,7 @@ func GetHandler(s *server.Server, w http.ResponseWriter, r *http.Request) (*Hand
|
||||||
Connection: conn,
|
Connection: conn,
|
||||||
jwt: nil,
|
jwt: nil,
|
||||||
server: s,
|
server: s,
|
||||||
ra: s.NewRequestActivity("", r.RemoteAddr),
|
ra: s.NewRequestActivity("", c.ClientIP()),
|
||||||
uuid: u,
|
uuid: u,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,121 +0,0 @@
|
||||||
Name: ptero-wings
|
|
||||||
Version: 1.5.3
|
|
||||||
Release: 1%{?dist}
|
|
||||||
Summary: The server control plane for Pterodactyl Panel. Written from the ground-up with security, speed, and stability in mind.
|
|
||||||
BuildArch: x86_64
|
|
||||||
License: MIT
|
|
||||||
URL: https://github.com/pterodactyl/wings
|
|
||||||
Source0: https://github.com/pterodactyl/wings/releases/download/v%{version}/wings_linux_amd64
|
|
||||||
|
|
||||||
%if 0%{?rhel} && 0%{?rhel} <= 8
|
|
||||||
BuildRequires: systemd
|
|
||||||
%else
|
|
||||||
BuildRequires: systemd-rpm-macros
|
|
||||||
%endif
|
|
||||||
|
|
||||||
|
|
||||||
%description
|
|
||||||
Wings is Pterodactyl's server control plane, built for the rapidly
|
|
||||||
changing gaming industry and designed to be highly performant and
|
|
||||||
secure. Wings provides an HTTP API allowing you to interface directly
|
|
||||||
with running server instances, fetch server logs, generate backups,
|
|
||||||
and control all aspects of the server lifecycle.
|
|
||||||
|
|
||||||
In addition, Wings ships with a built-in SFTP server allowing your
|
|
||||||
system to remain free of Pterodactyl specific dependencies, and
|
|
||||||
allowing users to authenticate with the same credentials they would
|
|
||||||
normally use to access the Panel.
|
|
||||||
|
|
||||||
%prep
|
|
||||||
|
|
||||||
%build
|
|
||||||
#nothing required
|
|
||||||
|
|
||||||
%install
|
|
||||||
mkdir -p %{buildroot}%{_bindir}
|
|
||||||
mkdir -p %{buildroot}%{_unitdir}
|
|
||||||
cp %{_sourcedir}/wings_linux_amd64 %{buildroot}%{_bindir}/wings
|
|
||||||
|
|
||||||
cat > %{buildroot}%{_unitdir}/wings.service << EOF
|
|
||||||
[Unit]
|
|
||||||
Description=Pterodactyl Wings Daemon
|
|
||||||
After=docker.service
|
|
||||||
Requires=docker.service
|
|
||||||
PartOf=docker.service
|
|
||||||
StartLimitIntervalSec=600
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
WorkingDirectory=/etc/pterodactyl
|
|
||||||
ExecStart=/usr/bin/wings
|
|
||||||
ExecReload=/bin/kill -HUP $MAINPID
|
|
||||||
Restart=on-failure
|
|
||||||
StartLimitInterval=180
|
|
||||||
StartLimitBurst=30
|
|
||||||
RestartSec=5s
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
||||||
EOF
|
|
||||||
|
|
||||||
%files
|
|
||||||
%attr(0755, root, root) %{_prefix}/bin/wings
|
|
||||||
%attr(0644, root, root) %{_unitdir}/wings.service
|
|
||||||
|
|
||||||
%post
|
|
||||||
|
|
||||||
# Reload systemd
|
|
||||||
systemctl daemon-reload
|
|
||||||
|
|
||||||
# Create the required directory structure
|
|
||||||
mkdir -p /etc/pterodactyl
|
|
||||||
mkdir -p /var/lib/pterodactyl/{archives,backups,volumes}
|
|
||||||
mkdir -p /var/log/pterodactyl/install
|
|
||||||
|
|
||||||
%preun
|
|
||||||
|
|
||||||
systemctl is-active %{name} >/dev/null 2>&1
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
systemctl stop %{name}
|
|
||||||
fi
|
|
||||||
|
|
||||||
systemctl is-enabled %{name} >/dev/null 2>&1
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
systemctl disable %{name}
|
|
||||||
fi
|
|
||||||
|
|
||||||
%postun
|
|
||||||
rm -rf /var/log/pterodactyl
|
|
||||||
|
|
||||||
%verifyscript
|
|
||||||
|
|
||||||
wings --version
|
|
||||||
|
|
||||||
%changelog
|
|
||||||
* Wed Oct 27 2021 Capitol Hosting Solutions Systems Engineering <syseng@chs.gg> - 1.5.3-1
|
|
||||||
- specfile by Capitol Hosting Solutions, Upstream by Pterodactyl
|
|
||||||
- Rebased for https://github.com/pterodactyl/wings/releases/tag/v1.5.3
|
|
||||||
- Fixes improper event registration and error handling during socket authentication that would cause the incorrect error message to be returned to the client, or no error in some scenarios. Event registration is now delayed until the socket is fully authenticated to ensure needless listeners are not registed.
|
|
||||||
- Fixes dollar signs always being evaluated as environment variables with no way to escape them. They can now be escaped as $$ which will transform into a single dollar sign.
|
|
||||||
- A websocket connection to a server will be closed by Wings if there is a send error encountered and the client will be left to handle reconnections, rather than simply logging the error and continuing to listen for new events.
|
|
||||||
|
|
||||||
* Sun Sep 12 2021 Capitol Hosting Solutions Systems Engineering <syseng@chs.gg> - 1.5.0-1
|
|
||||||
- specfile by Capitol Hosting Solutions, Upstream by Pterodactyl
|
|
||||||
- Rebased for https://github.com/pterodactyl/wings/releases/tag/v1.5.0
|
|
||||||
- Fixes a race condition when setting the application name in the console output for a server.
|
|
||||||
- Fixes a server being reinstalled causing the file_denylist parameter for an Egg to be ignored until Wings is restarted.
|
|
||||||
- Fixes YAML file parser not correctly setting boolean values.
|
|
||||||
- Fixes potential issue where the underlying websocket connection is closed but the parent request context is not yet canceled causing a write over a closed connection.
|
|
||||||
- Fixes race condition when closing all active websocket connections when a server is deleted.
|
|
||||||
- Fixes logic to determine if a server's context is closed out and send a websocket close message to connected clients. Previously this fired off whenever the request itself was closed, and not when the server context was closed.
|
|
||||||
- Exposes 8080 in the wings Dockerfile to better support reverse proxy tools.
|
|
||||||
- Releases are now built using Go 1.17 — the minimum version required to build Wings remains Go 1.16.
|
|
||||||
- Simplifed the logic powering server updates to only pull information from the Panel rather than trying to accept updated values. All parts of Wings needing the most up-to-date server details should call Server#Sync() to fetch the latest stored build information.
|
|
||||||
- Installer#New() no longer requires passing all of the server data as a byte slice, rather a new Installer#ServerDetails struct is exposed which can be passed and accepts a UUID and if the server should be started after the installer finishes.
|
|
||||||
- Removes complicated (and unused) logic during the server installation process that was a hold-over from legacy Wings architectures.
|
|
||||||
- Removes the PATCH /api/servers/:server endpoint — if you were previously using this API call it should be replaced with POST /api/servers/:server/sync.
|
|
||||||
|
|
||||||
* Wed Aug 25 2021 Capitol Hosting Solutions Systems Engineering <syseng@chs.gg> - 1.4.7-1
|
|
||||||
- specfile by Capitol Hosting Solutions, Upstream by Pterodactyl
|
|
||||||
- Rebased for https://github.com/pterodactyl/wings/releases/tag/v1.4.7
|
|
||||||
- SFTP access is now properly denied if a server is suspended.
|
|
||||||
- Correctly uses start_on_completion and crash_detection_enabled for servers.
|
|
|
@ -2,10 +2,12 @@ package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/internal/database"
|
"github.com/pterodactyl/wings/internal/database"
|
||||||
"github.com/pterodactyl/wings/internal/models"
|
"github.com/pterodactyl/wings/internal/models"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const ActivityPowerPrefix = "server:power."
|
const ActivityPowerPrefix = "server:power."
|
||||||
|
|
|
@ -24,7 +24,6 @@ func (s *Server) notifyPanelOfBackup(uuid string, ad *backup.ArchiveDetails, suc
|
||||||
"backup": uuid,
|
"backup": uuid,
|
||||||
"error": err,
|
"error": err,
|
||||||
}).Error("failed to notify panel of backup status due to wings error")
|
}).Error("failed to notify panel of backup status due to wings error")
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +126,7 @@ func (s *Server) RestoreBackup(b backup.BackupInterface, reader io.ReadCloser) (
|
||||||
defer func() {
|
defer func() {
|
||||||
s.Config().SetSuspended(false)
|
s.Config().SetSuspended(false)
|
||||||
if reader != nil {
|
if reader != nil {
|
||||||
reader.Close()
|
_ = reader.Close()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
// Send an API call to the Panel as soon as this function is done running so that
|
// Send an API call to the Panel as soon as this function is done running so that
|
||||||
|
@ -142,7 +141,7 @@ func (s *Server) RestoreBackup(b backup.BackupInterface, reader io.ReadCloser) (
|
||||||
// instance, otherwise you'll likely hit all types of write errors due to the
|
// instance, otherwise you'll likely hit all types of write errors due to the
|
||||||
// server being suspended.
|
// server being suspended.
|
||||||
if s.Environment.State() != environment.ProcessOfflineState {
|
if s.Environment.State() != environment.ProcessOfflineState {
|
||||||
if err = s.Environment.WaitForStop(s.Context(), time.Minute*2, false); err != nil {
|
if err = s.Environment.WaitForStop(s.Context(), 2*time.Minute, false); err != nil {
|
||||||
if !client.IsErrNotFound(err) {
|
if !client.IsErrNotFound(err) {
|
||||||
return errors.WrapIf(err, "server/backup: restore: failed to wait for container stop")
|
return errors.WrapIf(err, "server/backup: restore: failed to wait for container stop")
|
||||||
}
|
}
|
||||||
|
@ -152,14 +151,19 @@ func (s *Server) RestoreBackup(b backup.BackupInterface, reader io.ReadCloser) (
|
||||||
// Attempt to restore the backup to the server by running through each entry
|
// Attempt to restore the backup to the server by running through each entry
|
||||||
// in the file one at a time and writing them to the disk.
|
// in the file one at a time and writing them to the disk.
|
||||||
s.Log().Debug("starting file writing process for backup restoration")
|
s.Log().Debug("starting file writing process for backup restoration")
|
||||||
err = b.Restore(s.Context(), reader, func(file string, r io.Reader, mode fs.FileMode, atime, mtime time.Time) error {
|
err = b.Restore(s.Context(), reader, func(file string, info fs.FileInfo, r io.ReadCloser) error {
|
||||||
|
defer r.Close()
|
||||||
s.Events().Publish(DaemonMessageEvent, "(restoring): "+file)
|
s.Events().Publish(DaemonMessageEvent, "(restoring): "+file)
|
||||||
|
|
||||||
if err := s.Filesystem().Writefile(file, r); err != nil {
|
if err := s.Filesystem().Writefile(file, r); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := s.Filesystem().Chmod(file, mode); err != nil {
|
if err := s.Filesystem().Chmod(file, info.Mode()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
atime := info.ModTime()
|
||||||
|
mtime := atime
|
||||||
return s.Filesystem().Chtimes(file, atime, mtime)
|
return s.Filesystem().Chtimes(file, atime, mtime)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -8,16 +8,21 @@ import (
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"time"
|
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
|
"github.com/mholt/archiver/v4"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/config"
|
"github.com/pterodactyl/wings/config"
|
||||||
"github.com/pterodactyl/wings/remote"
|
"github.com/pterodactyl/wings/remote"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var format = archiver.CompressedArchive{
|
||||||
|
Compression: archiver.Gz{},
|
||||||
|
Archival: archiver.Tar{},
|
||||||
|
}
|
||||||
|
|
||||||
type AdapterType string
|
type AdapterType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -27,12 +32,12 @@ const (
|
||||||
|
|
||||||
// RestoreCallback is a generic restoration callback that exists for both local
|
// RestoreCallback is a generic restoration callback that exists for both local
|
||||||
// and remote backups allowing the files to be restored.
|
// and remote backups allowing the files to be restored.
|
||||||
type RestoreCallback func(file string, r io.Reader, mode fs.FileMode, atime, mtime time.Time) error
|
type RestoreCallback func(file string, info fs.FileInfo, r io.ReadCloser) error
|
||||||
|
|
||||||
// noinspection GoNameStartsWithPackageName
|
// noinspection GoNameStartsWithPackageName
|
||||||
type BackupInterface interface {
|
type BackupInterface interface {
|
||||||
// SetClient sets the API request client on the backup interface.
|
// SetClient sets the API request client on the backup interface.
|
||||||
SetClient(c remote.Client)
|
SetClient(remote.Client)
|
||||||
// Identifier returns the UUID of this backup as tracked by the panel
|
// Identifier returns the UUID of this backup as tracked by the panel
|
||||||
// instance.
|
// instance.
|
||||||
Identifier() string
|
Identifier() string
|
||||||
|
@ -41,7 +46,7 @@ type BackupInterface interface {
|
||||||
WithLogContext(map[string]interface{})
|
WithLogContext(map[string]interface{})
|
||||||
// Generate creates a backup in whatever the configured source for the
|
// Generate creates a backup in whatever the configured source for the
|
||||||
// specific implementation is.
|
// specific implementation is.
|
||||||
Generate(ctx context.Context, basePath string, ignore string) (*ArchiveDetails, error)
|
Generate(context.Context, string, string) (*ArchiveDetails, error)
|
||||||
// Ignored returns the ignored files for this backup instance.
|
// Ignored returns the ignored files for this backup instance.
|
||||||
Ignored() string
|
Ignored() string
|
||||||
// Checksum returns a SHA1 checksum for the generated backup.
|
// Checksum returns a SHA1 checksum for the generated backup.
|
||||||
|
@ -53,13 +58,13 @@ type BackupInterface interface {
|
||||||
// to store it until it is moved to the final spot.
|
// to store it until it is moved to the final spot.
|
||||||
Path() string
|
Path() string
|
||||||
// Details returns details about the archive.
|
// Details returns details about the archive.
|
||||||
Details(ctx context.Context) (*ArchiveDetails, error)
|
Details(context.Context, []remote.BackupPart) (*ArchiveDetails, error)
|
||||||
// Remove removes a backup file.
|
// Remove removes a backup file.
|
||||||
Remove() error
|
Remove() error
|
||||||
// Restore is called when a backup is ready to be restored to the disk from
|
// Restore is called when a backup is ready to be restored to the disk from
|
||||||
// the given source. Not every backup implementation will support this nor
|
// the given source. Not every backup implementation will support this nor
|
||||||
// will every implementation require a reader be provided.
|
// will every implementation require a reader be provided.
|
||||||
Restore(ctx context.Context, reader io.Reader, callback RestoreCallback) error
|
Restore(context.Context, io.Reader, RestoreCallback) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type Backup struct {
|
type Backup struct {
|
||||||
|
@ -119,8 +124,8 @@ func (b *Backup) Checksum() ([]byte, error) {
|
||||||
|
|
||||||
// Details returns both the checksum and size of the archive currently stored on
|
// Details returns both the checksum and size of the archive currently stored on
|
||||||
// the disk to the caller.
|
// the disk to the caller.
|
||||||
func (b *Backup) Details(ctx context.Context) (*ArchiveDetails, error) {
|
func (b *Backup) Details(ctx context.Context, parts []remote.BackupPart) (*ArchiveDetails, error) {
|
||||||
ad := ArchiveDetails{ChecksumType: "sha1"}
|
ad := ArchiveDetails{ChecksumType: "sha1", Parts: parts}
|
||||||
g, ctx := errgroup.WithContext(ctx)
|
g, ctx := errgroup.WithContext(ctx)
|
||||||
|
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
|
@ -162,9 +167,10 @@ func (b *Backup) log() *log.Entry {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArchiveDetails struct {
|
type ArchiveDetails struct {
|
||||||
Checksum string `json:"checksum"`
|
Checksum string `json:"checksum"`
|
||||||
ChecksumType string `json:"checksum_type"`
|
ChecksumType string `json:"checksum_type"`
|
||||||
Size int64 `json:"size"`
|
Size int64 `json:"size"`
|
||||||
|
Parts []remote.BackupPart `json:"parts"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToRequest returns a request object.
|
// ToRequest returns a request object.
|
||||||
|
@ -174,5 +180,6 @@ func (ad *ArchiveDetails) ToRequest(successful bool) remote.BackupRequest {
|
||||||
ChecksumType: ad.ChecksumType,
|
ChecksumType: ad.ChecksumType,
|
||||||
Size: ad.Size,
|
Size: ad.Size,
|
||||||
Successful: successful,
|
Successful: successful,
|
||||||
|
Parts: ad.Parts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,10 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
"github.com/mholt/archiver/v3"
|
"github.com/juju/ratelimit"
|
||||||
|
"github.com/mholt/archiver/v4"
|
||||||
|
|
||||||
|
"github.com/pterodactyl/wings/config"
|
||||||
"github.com/pterodactyl/wings/remote"
|
"github.com/pterodactyl/wings/remote"
|
||||||
"github.com/pterodactyl/wings/server/filesystem"
|
"github.com/pterodactyl/wings/server/filesystem"
|
||||||
)
|
)
|
||||||
|
@ -69,7 +71,7 @@ func (b *LocalBackup) Generate(ctx context.Context, basePath, ignore string) (*A
|
||||||
}
|
}
|
||||||
b.log().Info("created backup successfully")
|
b.log().Info("created backup successfully")
|
||||||
|
|
||||||
ad, err := b.Details(ctx)
|
ad, err := b.Details(ctx, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WrapIf(err, "backup: failed to get archive details for local backup")
|
return nil, errors.WrapIf(err, "backup: failed to get archive details for local backup")
|
||||||
}
|
}
|
||||||
|
@ -79,16 +81,27 @@ func (b *LocalBackup) Generate(ctx context.Context, basePath, ignore string) (*A
|
||||||
// Restore will walk over the archive and call the callback function for each
|
// Restore will walk over the archive and call the callback function for each
|
||||||
// file encountered.
|
// file encountered.
|
||||||
func (b *LocalBackup) Restore(ctx context.Context, _ io.Reader, callback RestoreCallback) error {
|
func (b *LocalBackup) Restore(ctx context.Context, _ io.Reader, callback RestoreCallback) error {
|
||||||
return archiver.Walk(b.Path(), func(f archiver.File) error {
|
f, err := os.Open(b.Path())
|
||||||
select {
|
if err != nil {
|
||||||
case <-ctx.Done():
|
return err
|
||||||
// Stop walking if the context is canceled.
|
}
|
||||||
return archiver.ErrStopWalk
|
|
||||||
default:
|
var reader io.Reader = f
|
||||||
if f.IsDir() {
|
// Steal the logic we use for making backups which will be applied when restoring
|
||||||
return nil
|
// this specific backup. This allows us to prevent overloading the disk unintentionally.
|
||||||
}
|
if writeLimit := int64(config.Get().System.Backups.WriteLimit * 1024 * 1024); writeLimit > 0 {
|
||||||
return callback(filesystem.ExtractNameFromArchive(f), f, f.Mode(), f.ModTime(), f.ModTime())
|
reader = ratelimit.Reader(f, ratelimit.NewBucketWithRate(float64(writeLimit), writeLimit))
|
||||||
|
}
|
||||||
|
if err := format.Extract(ctx, reader, nil, func(ctx context.Context, f archiver.File) error {
|
||||||
|
r, err := f.Open()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
})
|
defer r.Close()
|
||||||
|
|
||||||
|
return callback(filesystem.ExtractNameFromArchive(f), f.FileInfo, r)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package backup
|
package backup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/tar"
|
|
||||||
"compress/gzip"
|
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -13,13 +11,12 @@ import (
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
"github.com/cenkalti/backoff/v4"
|
"github.com/cenkalti/backoff/v4"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/server/filesystem"
|
|
||||||
|
|
||||||
"github.com/juju/ratelimit"
|
"github.com/juju/ratelimit"
|
||||||
|
"github.com/mholt/archiver/v4"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/config"
|
"github.com/pterodactyl/wings/config"
|
||||||
"github.com/pterodactyl/wings/remote"
|
"github.com/pterodactyl/wings/remote"
|
||||||
|
"github.com/pterodactyl/wings/server/filesystem"
|
||||||
)
|
)
|
||||||
|
|
||||||
type S3Backup struct {
|
type S3Backup struct {
|
||||||
|
@ -71,10 +68,11 @@ func (s *S3Backup) Generate(ctx context.Context, basePath, ignore string) (*Arch
|
||||||
}
|
}
|
||||||
defer rc.Close()
|
defer rc.Close()
|
||||||
|
|
||||||
if err := s.generateRemoteRequest(ctx, rc); err != nil {
|
parts, err := s.generateRemoteRequest(ctx, rc)
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ad, err := s.Details(ctx)
|
ad, err := s.Details(ctx, parts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WrapIf(err, "backup: failed to get archive details after upload")
|
return nil, errors.WrapIf(err, "backup: failed to get archive details after upload")
|
||||||
}
|
}
|
||||||
|
@ -95,50 +93,35 @@ func (s *S3Backup) Restore(ctx context.Context, r io.Reader, callback RestoreCal
|
||||||
if writeLimit := int64(config.Get().System.Backups.WriteLimit * 1024 * 1024); writeLimit > 0 {
|
if writeLimit := int64(config.Get().System.Backups.WriteLimit * 1024 * 1024); writeLimit > 0 {
|
||||||
reader = ratelimit.Reader(r, ratelimit.NewBucketWithRate(float64(writeLimit), writeLimit))
|
reader = ratelimit.Reader(r, ratelimit.NewBucketWithRate(float64(writeLimit), writeLimit))
|
||||||
}
|
}
|
||||||
gr, err := gzip.NewReader(reader)
|
if err := format.Extract(ctx, reader, nil, func(ctx context.Context, f archiver.File) error {
|
||||||
if err != nil {
|
r, err := f.Open()
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer gr.Close()
|
|
||||||
tr := tar.NewReader(gr)
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
return nil
|
|
||||||
default:
|
|
||||||
// Do nothing, fall through to the next block of code in this loop.
|
|
||||||
}
|
|
||||||
header, err := tr.Next()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == io.EOF {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if header.Typeflag == tar.TypeReg {
|
defer r.Close()
|
||||||
if err := callback(header.Name, tr, header.FileInfo().Mode(), header.AccessTime, header.ModTime); err != nil {
|
|
||||||
return err
|
return callback(filesystem.ExtractNameFromArchive(f), f.FileInfo, r)
|
||||||
}
|
}); err != nil {
|
||||||
}
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generates the remote S3 request and begins the upload.
|
// Generates the remote S3 request and begins the upload.
|
||||||
func (s *S3Backup) generateRemoteRequest(ctx context.Context, rc io.ReadCloser) error {
|
func (s *S3Backup) generateRemoteRequest(ctx context.Context, rc io.ReadCloser) ([]remote.BackupPart, error) {
|
||||||
defer rc.Close()
|
defer rc.Close()
|
||||||
|
|
||||||
s.log().Debug("attempting to get size of backup...")
|
s.log().Debug("attempting to get size of backup...")
|
||||||
size, err := s.Backup.Size()
|
size, err := s.Backup.Size()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
s.log().WithField("size", size).Debug("got size of backup")
|
s.log().WithField("size", size).Debug("got size of backup")
|
||||||
|
|
||||||
s.log().Debug("attempting to get S3 upload urls from Panel...")
|
s.log().Debug("attempting to get S3 upload urls from Panel...")
|
||||||
urls, err := s.client.GetBackupRemoteUploadURLs(context.Background(), s.Backup.Uuid, size)
|
urls, err := s.client.GetBackupRemoteUploadURLs(context.Background(), s.Backup.Uuid, size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
s.log().Debug("got S3 upload urls from the Panel")
|
s.log().Debug("got S3 upload urls from the Panel")
|
||||||
s.log().WithField("parts", len(urls.Parts)).Info("attempting to upload backup to s3 endpoint...")
|
s.log().WithField("parts", len(urls.Parts)).Info("attempting to upload backup to s3 endpoint...")
|
||||||
|
@ -156,22 +139,26 @@ func (s *S3Backup) generateRemoteRequest(ctx context.Context, rc io.ReadCloser)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to upload the part.
|
// Attempt to upload the part.
|
||||||
if _, err := uploader.uploadPart(ctx, part, partSize); err != nil {
|
etag, err := uploader.uploadPart(ctx, part, partSize)
|
||||||
|
if err != nil {
|
||||||
s.log().WithField("part_id", i+1).WithError(err).Warn("failed to upload part")
|
s.log().WithField("part_id", i+1).WithError(err).Warn("failed to upload part")
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
uploader.uploadedParts = append(uploader.uploadedParts, remote.BackupPart{
|
||||||
|
ETag: etag,
|
||||||
|
PartNumber: i + 1,
|
||||||
|
})
|
||||||
s.log().WithField("part_id", i+1).Info("successfully uploaded backup part")
|
s.log().WithField("part_id", i+1).Info("successfully uploaded backup part")
|
||||||
}
|
}
|
||||||
|
|
||||||
s.log().WithField("parts", len(urls.Parts)).Info("backup has been successfully uploaded")
|
s.log().WithField("parts", len(urls.Parts)).Info("backup has been successfully uploaded")
|
||||||
|
|
||||||
return nil
|
return uploader.uploadedParts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type s3FileUploader struct {
|
type s3FileUploader struct {
|
||||||
io.ReadCloser
|
io.ReadCloser
|
||||||
client *http.Client
|
client *http.Client
|
||||||
|
uploadedParts []remote.BackupPart
|
||||||
}
|
}
|
||||||
|
|
||||||
// newS3FileUploader returns a new file uploader instance.
|
// newS3FileUploader returns a new file uploader instance.
|
||||||
|
|
|
@ -46,6 +46,9 @@ type Configuration struct {
|
||||||
// server process.
|
// server process.
|
||||||
EnvVars environment.Variables `json:"environment"`
|
EnvVars environment.Variables `json:"environment"`
|
||||||
|
|
||||||
|
// Labels is a map of container labels that should be applied to the running server process.
|
||||||
|
Labels map[string]string `json:"labels"`
|
||||||
|
|
||||||
Allocations environment.Allocations `json:"allocations"`
|
Allocations environment.Allocations `json:"allocations"`
|
||||||
Build environment.Limits `json:"build"`
|
Build environment.Limits `json:"build"`
|
||||||
CrashDetectionEnabled bool `json:"crash_detection_enabled"`
|
CrashDetectionEnabled bool `json:"crash_detection_enabled"`
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mitchellh/colorstring"
|
"github.com/mitchellh/colorstring"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/config"
|
"github.com/pterodactyl/wings/config"
|
||||||
"github.com/pterodactyl/wings/system"
|
"github.com/pterodactyl/wings/system"
|
||||||
)
|
)
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
|
@ -17,6 +18,7 @@ import (
|
||||||
ignore "github.com/sabhiram/go-gitignore"
|
ignore "github.com/sabhiram/go-gitignore"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/config"
|
"github.com/pterodactyl/wings/config"
|
||||||
|
"github.com/pterodactyl/wings/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
const memory = 4 * 1024
|
const memory = 4 * 1024
|
||||||
|
@ -28,6 +30,108 @@ var pool = sync.Pool{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TarProgress .
|
||||||
|
type TarProgress struct {
|
||||||
|
*tar.Writer
|
||||||
|
p *Progress
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTarProgress .
|
||||||
|
func NewTarProgress(w *tar.Writer, p *Progress) *TarProgress {
|
||||||
|
if p != nil {
|
||||||
|
p.w = w
|
||||||
|
}
|
||||||
|
return &TarProgress{
|
||||||
|
Writer: w,
|
||||||
|
p: p,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *TarProgress) Write(v []byte) (int, error) {
|
||||||
|
if p.p == nil {
|
||||||
|
return p.Writer.Write(v)
|
||||||
|
}
|
||||||
|
return p.p.Write(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Progress is used to track the progress of any I/O operation that are being
|
||||||
|
// performed.
|
||||||
|
type Progress struct {
|
||||||
|
// written is the total size of the files that have been written to the writer.
|
||||||
|
written int64
|
||||||
|
// Total is the total size of the archive in bytes.
|
||||||
|
total int64
|
||||||
|
// w .
|
||||||
|
w io.Writer
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewProgress .
|
||||||
|
func NewProgress(total int64) *Progress {
|
||||||
|
return &Progress{total: total}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetWriter sets the writer progress will forward writes to.
|
||||||
|
// NOTE: This function is not thread safe.
|
||||||
|
func (p *Progress) SetWriter(w io.Writer) {
|
||||||
|
p.w = w
|
||||||
|
}
|
||||||
|
|
||||||
|
// Written returns the total number of bytes written.
|
||||||
|
// This function should be used when the progress is tracking data being written.
|
||||||
|
func (p *Progress) Written() int64 {
|
||||||
|
return atomic.LoadInt64(&p.written)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Total returns the total size in bytes.
|
||||||
|
func (p *Progress) Total() int64 {
|
||||||
|
return atomic.LoadInt64(&p.total)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write totals the number of bytes that have been written to the writer.
|
||||||
|
func (p *Progress) Write(v []byte) (int, error) {
|
||||||
|
n := len(v)
|
||||||
|
atomic.AddInt64(&p.written, int64(n))
|
||||||
|
if p.w != nil {
|
||||||
|
return p.w.Write(v)
|
||||||
|
}
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Progress returns a formatted progress string for the current progress.
|
||||||
|
func (p *Progress) Progress(width int) string {
|
||||||
|
// current = 100 (Progress, dynamic)
|
||||||
|
// total = 1000 (Content-Length, dynamic)
|
||||||
|
// width = 25 (Number of ticks to display, static)
|
||||||
|
// widthPercentage = 100 / width (What percentage does each tick represent, static)
|
||||||
|
//
|
||||||
|
// percentageDecimal = current / total = 0.1
|
||||||
|
// percentage = percentageDecimal * 100 = 10%
|
||||||
|
// ticks = percentage / widthPercentage = 2.5
|
||||||
|
//
|
||||||
|
// ticks is a float64, so we cast it to an int which rounds it down to 2.
|
||||||
|
|
||||||
|
// Values are cast to floats to prevent integer division.
|
||||||
|
current := p.Written()
|
||||||
|
total := p.Total()
|
||||||
|
// width := is passed as a parameter
|
||||||
|
widthPercentage := float64(100) / float64(width)
|
||||||
|
percentageDecimal := float64(current) / float64(total)
|
||||||
|
percentage := percentageDecimal * 100
|
||||||
|
ticks := int(percentage / widthPercentage)
|
||||||
|
|
||||||
|
// Ensure that we never get a negative number of ticks, this will prevent strings#Repeat
|
||||||
|
// from panicking. A negative number of ticks is likely to happen when the total size is
|
||||||
|
// inaccurate, such as when we are going off of rough disk usage calculation.
|
||||||
|
if ticks < 0 {
|
||||||
|
ticks = 0
|
||||||
|
} else if ticks > width {
|
||||||
|
ticks = width
|
||||||
|
}
|
||||||
|
|
||||||
|
bar := strings.Repeat("=", ticks) + strings.Repeat(" ", width-ticks)
|
||||||
|
return "[" + bar + "] " + system.FormatBytes(current) + " / " + system.FormatBytes(total)
|
||||||
|
}
|
||||||
|
|
||||||
type Archive struct {
|
type Archive struct {
|
||||||
// BasePath is the absolute path to create the archive from where Files and Ignore are
|
// BasePath is the absolute path to create the archive from where Files and Ignore are
|
||||||
// relative to.
|
// relative to.
|
||||||
|
@ -40,10 +144,13 @@ type Archive struct {
|
||||||
// Files specifies the files to archive, this takes priority over the Ignore option, if
|
// Files specifies the files to archive, this takes priority over the Ignore option, if
|
||||||
// unspecified, all files in the BasePath will be archived unless Ignore is set.
|
// unspecified, all files in the BasePath will be archived unless Ignore is set.
|
||||||
Files []string
|
Files []string
|
||||||
|
|
||||||
|
// Progress wraps the writer of the archive to pass through the progress tracker.
|
||||||
|
Progress *Progress
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create creates an archive at dst with all of the files defined in the
|
// Create creates an archive at dst with all the files defined in the
|
||||||
// included files struct.
|
// included Files array.
|
||||||
func (a *Archive) Create(dst string) error {
|
func (a *Archive) Create(dst string) error {
|
||||||
f, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
|
f, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -62,8 +169,21 @@ func (a *Archive) Create(dst string) error {
|
||||||
writer = f
|
writer = f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Choose which compression level to use based on the compression_level configuration option
|
||||||
|
var compressionLevel int
|
||||||
|
switch config.Get().System.Backups.CompressionLevel {
|
||||||
|
case "none":
|
||||||
|
compressionLevel = pgzip.NoCompression
|
||||||
|
case "best_compression":
|
||||||
|
compressionLevel = pgzip.BestCompression
|
||||||
|
case "best_speed":
|
||||||
|
fallthrough
|
||||||
|
default:
|
||||||
|
compressionLevel = pgzip.BestSpeed
|
||||||
|
}
|
||||||
|
|
||||||
// Create a new gzip writer around the file.
|
// Create a new gzip writer around the file.
|
||||||
gw, _ := pgzip.NewWriterLevel(writer, pgzip.BestSpeed)
|
gw, _ := pgzip.NewWriterLevel(writer, compressionLevel)
|
||||||
_ = gw.SetConcurrency(1<<20, 1)
|
_ = gw.SetConcurrency(1<<20, 1)
|
||||||
defer gw.Close()
|
defer gw.Close()
|
||||||
|
|
||||||
|
@ -71,11 +191,13 @@ func (a *Archive) Create(dst string) error {
|
||||||
tw := tar.NewWriter(gw)
|
tw := tar.NewWriter(gw)
|
||||||
defer tw.Close()
|
defer tw.Close()
|
||||||
|
|
||||||
|
pw := NewTarProgress(tw, a.Progress)
|
||||||
|
|
||||||
// Configure godirwalk.
|
// Configure godirwalk.
|
||||||
options := &godirwalk.Options{
|
options := &godirwalk.Options{
|
||||||
FollowSymbolicLinks: false,
|
FollowSymbolicLinks: false,
|
||||||
Unsorted: true,
|
Unsorted: true,
|
||||||
Callback: a.callback(tw),
|
Callback: a.callback(pw),
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're specifically looking for only certain files, or have requested
|
// If we're specifically looking for only certain files, or have requested
|
||||||
|
@ -84,7 +206,7 @@ func (a *Archive) Create(dst string) error {
|
||||||
if len(a.Files) == 0 && len(a.Ignore) > 0 {
|
if len(a.Files) == 0 && len(a.Ignore) > 0 {
|
||||||
i := ignore.CompileIgnoreLines(strings.Split(a.Ignore, "\n")...)
|
i := ignore.CompileIgnoreLines(strings.Split(a.Ignore, "\n")...)
|
||||||
|
|
||||||
options.Callback = a.callback(tw, func(_ string, rp string) error {
|
options.Callback = a.callback(pw, func(_ string, rp string) error {
|
||||||
if i.MatchesPath(rp) {
|
if i.MatchesPath(rp) {
|
||||||
return godirwalk.SkipThis
|
return godirwalk.SkipThis
|
||||||
}
|
}
|
||||||
|
@ -92,7 +214,7 @@ func (a *Archive) Create(dst string) error {
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
} else if len(a.Files) > 0 {
|
} else if len(a.Files) > 0 {
|
||||||
options.Callback = a.withFilesCallback(tw)
|
options.Callback = a.withFilesCallback(pw)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recursively walk the path we are archiving.
|
// Recursively walk the path we are archiving.
|
||||||
|
@ -101,9 +223,9 @@ func (a *Archive) Create(dst string) error {
|
||||||
|
|
||||||
// Callback function used to determine if a given file should be included in the archive
|
// Callback function used to determine if a given file should be included in the archive
|
||||||
// being generated.
|
// being generated.
|
||||||
func (a *Archive) callback(tw *tar.Writer, opts ...func(path string, relative string) error) func(path string, de *godirwalk.Dirent) error {
|
func (a *Archive) callback(tw *TarProgress, opts ...func(path string, relative string) error) func(path string, de *godirwalk.Dirent) error {
|
||||||
return func(path string, de *godirwalk.Dirent) error {
|
return func(path string, de *godirwalk.Dirent) error {
|
||||||
// Skip directories because we walking them recursively.
|
// Skip directories because we are walking them recursively.
|
||||||
if de.IsDir() {
|
if de.IsDir() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -125,7 +247,7 @@ func (a *Archive) callback(tw *tar.Writer, opts ...func(path string, relative st
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pushes only files defined in the Files key to the final archive.
|
// Pushes only files defined in the Files key to the final archive.
|
||||||
func (a *Archive) withFilesCallback(tw *tar.Writer) func(path string, de *godirwalk.Dirent) error {
|
func (a *Archive) withFilesCallback(tw *TarProgress) func(path string, de *godirwalk.Dirent) error {
|
||||||
return a.callback(tw, func(p string, rp string) error {
|
return a.callback(tw, func(p string, rp string) error {
|
||||||
for _, f := range a.Files {
|
for _, f := range a.Files {
|
||||||
// If the given doesn't match, or doesn't have the same prefix continue
|
// If the given doesn't match, or doesn't have the same prefix continue
|
||||||
|
@ -146,9 +268,9 @@ func (a *Archive) withFilesCallback(tw *tar.Writer) func(path string, de *godirw
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds a given file path to the final archive being created.
|
// Adds a given file path to the final archive being created.
|
||||||
func (a *Archive) addToArchive(p string, rp string, w *tar.Writer) error {
|
func (a *Archive) addToArchive(p string, rp string, w *TarProgress) error {
|
||||||
// Lstat the file, this will give us the same information as Stat except that it will not
|
// Lstat the file, this will give us the same information as Stat except that it will not
|
||||||
// follow a symlink to it's target automatically. This is important to avoid including
|
// follow a symlink to its target automatically. This is important to avoid including
|
||||||
// files that exist outside the server root unintentionally in the backup.
|
// files that exist outside the server root unintentionally in the backup.
|
||||||
s, err := os.Lstat(p)
|
s, err := os.Lstat(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -173,7 +295,7 @@ func (a *Archive) addToArchive(p string, rp string, w *tar.Writer) error {
|
||||||
// it doesn't work.
|
// it doesn't work.
|
||||||
target, err = os.Readlink(s.Name())
|
target, err = os.Readlink(s.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Ignore the not exist errors specifically, since theres nothing important about that.
|
// Ignore the not exist errors specifically, since there is nothing important about that.
|
||||||
if !os.IsNotExist(err) {
|
if !os.IsNotExist(err) {
|
||||||
log.WithField("path", rp).WithField("readlink_err", err.Error()).Warn("failed reading symlink for target path; skipping...")
|
log.WithField("path", rp).WithField("readlink_err", err.Error()).Warn("failed reading symlink for target path; skipping...")
|
||||||
}
|
}
|
||||||
|
|
48
server/filesystem/archive_test.go
Normal file
48
server/filesystem/archive_test.go
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
package filesystem
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/franela/goblin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestProgress(t *testing.T) {
|
||||||
|
g := Goblin(t)
|
||||||
|
|
||||||
|
g.Describe("Progress", func() {
|
||||||
|
g.It("properly initializes", func() {
|
||||||
|
total := int64(1000)
|
||||||
|
p := NewProgress(total)
|
||||||
|
g.Assert(p).IsNotNil()
|
||||||
|
g.Assert(p.Total()).Equal(total)
|
||||||
|
g.Assert(p.Written()).Equal(int64(0))
|
||||||
|
})
|
||||||
|
|
||||||
|
g.It("increments written when Write is called", func() {
|
||||||
|
v := []byte("hello")
|
||||||
|
p := NewProgress(1000)
|
||||||
|
_, err := p.Write(v)
|
||||||
|
g.Assert(err).IsNil()
|
||||||
|
g.Assert(p.Written()).Equal(int64(len(v)))
|
||||||
|
})
|
||||||
|
|
||||||
|
g.It("renders a progress bar", func() {
|
||||||
|
v := bytes.Repeat([]byte{' '}, 100)
|
||||||
|
p := NewProgress(1000)
|
||||||
|
_, err := p.Write(v)
|
||||||
|
g.Assert(err).IsNil()
|
||||||
|
g.Assert(p.Written()).Equal(int64(len(v)))
|
||||||
|
g.Assert(p.Progress(25)).Equal("[== ] 100 B / 1000 B")
|
||||||
|
})
|
||||||
|
|
||||||
|
g.It("renders a progress bar when written exceeds total", func() {
|
||||||
|
v := bytes.Repeat([]byte{' '}, 1001)
|
||||||
|
p := NewProgress(1000)
|
||||||
|
_, err := p.Write(v)
|
||||||
|
g.Assert(err).IsNil()
|
||||||
|
g.Assert(p.Written()).Equal(int64(len(v)))
|
||||||
|
g.Assert(p.Progress(25)).Equal("[=========================] 1001 B / 1000 B")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
|
@ -4,9 +4,9 @@ import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
gzip2 "github.com/klauspost/compress/gzip"
|
iofs "io/fs"
|
||||||
zip2 "github.com/klauspost/compress/zip"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -16,7 +16,9 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
"github.com/mholt/archiver/v3"
|
gzip2 "github.com/klauspost/compress/gzip"
|
||||||
|
zip2 "github.com/klauspost/compress/zip"
|
||||||
|
"github.com/mholt/archiver/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CompressFiles compresses all of the files matching the given paths in the
|
// CompressFiles compresses all of the files matching the given paths in the
|
||||||
|
@ -72,7 +74,7 @@ func (fs *Filesystem) CompressFiles(dir string, paths []string) (os.FileInfo, er
|
||||||
|
|
||||||
// SpaceAvailableForDecompression looks through a given archive and determines
|
// SpaceAvailableForDecompression looks through a given archive and determines
|
||||||
// if decompressing it would put the server over its allocated disk space limit.
|
// if decompressing it would put the server over its allocated disk space limit.
|
||||||
func (fs *Filesystem) SpaceAvailableForDecompression(dir string, file string) error {
|
func (fs *Filesystem) SpaceAvailableForDecompression(ctx context.Context, dir string, file string) error {
|
||||||
// Don't waste time trying to determine this if we know the server will have the space for
|
// Don't waste time trying to determine this if we know the server will have the space for
|
||||||
// it since there is no limit.
|
// it since there is no limit.
|
||||||
if fs.MaxDisk() <= 0 {
|
if fs.MaxDisk() <= 0 {
|
||||||
|
@ -88,69 +90,104 @@ func (fs *Filesystem) SpaceAvailableForDecompression(dir string, file string) er
|
||||||
// waiting an unnecessary amount of time on this call.
|
// waiting an unnecessary amount of time on this call.
|
||||||
dirSize, err := fs.DiskUsage(false)
|
dirSize, err := fs.DiskUsage(false)
|
||||||
|
|
||||||
var size int64
|
fsys, err := archiver.FileSystem(source)
|
||||||
// Walk over the archive and figure out just how large the final output would be from unarchiving it.
|
|
||||||
err = archiver.Walk(source, func(f archiver.File) error {
|
|
||||||
if atomic.AddInt64(&size, f.Size())+dirSize > fs.MaxDisk() {
|
|
||||||
return newFilesystemError(ErrCodeDiskSpace, nil)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if IsUnknownArchiveFormatError(err) {
|
if errors.Is(err, archiver.ErrNoMatch) {
|
||||||
return newFilesystemError(ErrCodeUnknownArchive, err)
|
return newFilesystemError(ErrCodeUnknownArchive, err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return err
|
|
||||||
|
var size int64
|
||||||
|
return iofs.WalkDir(fsys, ".", func(path string, d iofs.DirEntry, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
// Stop walking if the context is canceled.
|
||||||
|
return ctx.Err()
|
||||||
|
default:
|
||||||
|
info, err := d.Info()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if atomic.AddInt64(&size, info.Size())+dirSize > fs.MaxDisk() {
|
||||||
|
return newFilesystemError(ErrCodeDiskSpace, nil)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// DecompressFile will decompress a file in a given directory by using the
|
// DecompressFile will decompress a file in a given directory by using the
|
||||||
// archiver tool to infer the file type and go from there. This will walk over
|
// archiver tool to infer the file type and go from there. This will walk over
|
||||||
// all of the files within the given archive and ensure that there is not a
|
// all the files within the given archive and ensure that there is not a
|
||||||
// zip-slip attack being attempted by validating that the final path is within
|
// zip-slip attack being attempted by validating that the final path is within
|
||||||
// the server data directory.
|
// the server data directory.
|
||||||
func (fs *Filesystem) DecompressFile(dir string, file string) error {
|
func (fs *Filesystem) DecompressFile(ctx context.Context, dir string, file string) error {
|
||||||
source, err := fs.SafePath(filepath.Join(dir, file))
|
source, err := fs.SafePath(filepath.Join(dir, file))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Ensure that the source archive actually exists on the system.
|
return fs.DecompressFileUnsafe(ctx, dir, source)
|
||||||
if _, err := os.Stat(source); err != nil {
|
}
|
||||||
|
|
||||||
|
// DecompressFileUnsafe will decompress any file on the local disk without checking
|
||||||
|
// if it is owned by the server. The file will be SAFELY decompressed and extracted
|
||||||
|
// into the server's directory.
|
||||||
|
func (fs *Filesystem) DecompressFileUnsafe(ctx context.Context, dir string, file string) error {
|
||||||
|
// Ensure that the archive actually exists on the system.
|
||||||
|
if _, err := os.Stat(file); err != nil {
|
||||||
return errors.WithStack(err)
|
return errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Walk all of the files in the archiver file and write them to the disk. If any
|
f, err := os.Open(file)
|
||||||
// directory is encountered it will be skipped since we handle creating any missing
|
|
||||||
// directories automatically when writing files.
|
|
||||||
err = archiver.Walk(source, func(f archiver.File) error {
|
|
||||||
if f.IsDir() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
p := filepath.Join(dir, ExtractNameFromArchive(f))
|
|
||||||
// If it is ignored, just don't do anything with the file and skip over it.
|
|
||||||
if err := fs.IsIgnored(p); err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if err := fs.Writefile(p, f); err != nil {
|
|
||||||
return wrapError(err, source)
|
|
||||||
}
|
|
||||||
// Update the file permissions to the one set in the archive.
|
|
||||||
if err := fs.Chmod(p, f.Mode()); err != nil {
|
|
||||||
return wrapError(err, source)
|
|
||||||
}
|
|
||||||
// Update the file modification time to the one set in the archive.
|
|
||||||
if err := fs.Chtimes(p, f.ModTime(), f.ModTime()); err != nil {
|
|
||||||
return wrapError(err, source)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if IsUnknownArchiveFormatError(err) {
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Identify the type of archive we are dealing with.
|
||||||
|
format, input, err := archiver.Identify(filepath.Base(file), f)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, archiver.ErrNoMatch) {
|
||||||
return newFilesystemError(ErrCodeUnknownArchive, err)
|
return newFilesystemError(ErrCodeUnknownArchive, err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Decompress and extract archive
|
||||||
|
if ex, ok := format.(archiver.Extractor); ok {
|
||||||
|
return ex.Extract(ctx, input, nil, func(ctx context.Context, f archiver.File) error {
|
||||||
|
if f.IsDir() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
p := filepath.Join(dir, ExtractNameFromArchive(f))
|
||||||
|
// If it is ignored, just don't do anything with the file and skip over it.
|
||||||
|
if err := fs.IsIgnored(p); err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
r, err := f.Open()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer r.Close()
|
||||||
|
if err := fs.Writefile(p, r); err != nil {
|
||||||
|
return wrapError(err, file)
|
||||||
|
}
|
||||||
|
// Update the file permissions to the one set in the archive.
|
||||||
|
if err := fs.Chmod(p, f.Mode()); err != nil {
|
||||||
|
return wrapError(err, file)
|
||||||
|
}
|
||||||
|
// Update the file modification time to the one set in the archive.
|
||||||
|
if err := fs.Chtimes(p, f.ModTime(), f.ModTime()); err != nil {
|
||||||
|
return wrapError(err, file)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package filesystem
|
package filesystem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -28,7 +29,7 @@ func TestFilesystem_DecompressFile(t *testing.T) {
|
||||||
g.Assert(err).IsNil()
|
g.Assert(err).IsNil()
|
||||||
|
|
||||||
// decompress
|
// decompress
|
||||||
err = fs.DecompressFile("/", "test."+ext)
|
err = fs.DecompressFile(context.Background(), "/", "test."+ext)
|
||||||
g.Assert(err).IsNil()
|
g.Assert(err).IsNil()
|
||||||
|
|
||||||
// make sure everything is where it is supposed to be
|
// make sure everything is where it is supposed to be
|
||||||
|
|
|
@ -71,7 +71,7 @@ func (fs *Filesystem) HasSpaceAvailable(allowStaleValue bool) bool {
|
||||||
// If space is -1 or 0 just return true, means they're allowed unlimited.
|
// If space is -1 or 0 just return true, means they're allowed unlimited.
|
||||||
//
|
//
|
||||||
// Technically we could skip disk space calculation because we don't need to check if the
|
// Technically we could skip disk space calculation because we don't need to check if the
|
||||||
// server exceeds it's limit but because this method caches the disk usage it would be best
|
// server exceeds its limit but because this method caches the disk usage it would be best
|
||||||
// to calculate the disk usage and always return true.
|
// to calculate the disk usage and always return true.
|
||||||
if fs.MaxDisk() == 0 {
|
if fs.MaxDisk() == 0 {
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
|
@ -122,15 +121,6 @@ func IsErrorCode(err error, code ErrorCode) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsUnknownArchiveFormatError checks if the error is due to the archive being
|
|
||||||
// in an unexpected file format.
|
|
||||||
func IsUnknownArchiveFormatError(err error) bool {
|
|
||||||
if err != nil && strings.HasPrefix(err.Error(), "format ") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewBadPathResolution returns a new BadPathResolution error.
|
// NewBadPathResolution returns a new BadPathResolution error.
|
||||||
func NewBadPathResolution(path string, resolved string) error {
|
func NewBadPathResolution(path string, resolved string) error {
|
||||||
return errors.WithStackDepth(&Error{code: ErrCodePathResolution, path: path, resolved: resolved}, 1)
|
return errors.WithStackDepth(&Error{code: ErrCodePathResolution, path: path, resolved: resolved}, 1)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
@ -18,6 +19,7 @@ import (
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/api/types/mount"
|
"github.com/docker/docker/api/types/mount"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/config"
|
"github.com/pterodactyl/wings/config"
|
||||||
"github.com/pterodactyl/wings/environment"
|
"github.com/pterodactyl/wings/environment"
|
||||||
"github.com/pterodactyl/wings/remote"
|
"github.com/pterodactyl/wings/remote"
|
||||||
|
@ -418,7 +420,12 @@ func (ip *InstallationProcess) Execute() (string, error) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpfsSize := strconv.Itoa(int(config.Get().Docker.TmpfsSize))
|
cfg := config.Get()
|
||||||
|
if cfg.System.User.Rootless.Enabled {
|
||||||
|
conf.User = fmt.Sprintf("%d:%d", cfg.System.User.Rootless.ContainerUID, cfg.System.User.Rootless.ContainerGID)
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpfsSize := strconv.Itoa(int(cfg.Docker.TmpfsSize))
|
||||||
hostConf := &container.HostConfig{
|
hostConf := &container.HostConfig{
|
||||||
Mounts: []mount.Mount{
|
Mounts: []mount.Mount{
|
||||||
{
|
{
|
||||||
|
@ -438,17 +445,11 @@ func (ip *InstallationProcess) Execute() (string, error) {
|
||||||
Tmpfs: map[string]string{
|
Tmpfs: map[string]string{
|
||||||
"/tmp": "rw,exec,nosuid,size=" + tmpfsSize + "M",
|
"/tmp": "rw,exec,nosuid,size=" + tmpfsSize + "M",
|
||||||
},
|
},
|
||||||
DNS: config.Get().Docker.Network.Dns,
|
DNS: cfg.Docker.Network.Dns,
|
||||||
LogConfig: container.LogConfig{
|
LogConfig: cfg.Docker.ContainerLogConfig(),
|
||||||
Type: "local",
|
|
||||||
Config: map[string]string{
|
|
||||||
"max-size": "5m",
|
|
||||||
"max-file": "1",
|
|
||||||
"compress": "false",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Privileged: true,
|
Privileged: true,
|
||||||
NetworkMode: container.NetworkMode(config.Get().Docker.Network.Mode),
|
NetworkMode: container.NetworkMode(cfg.Docker.Network.Mode),
|
||||||
|
UsernsMode: container.UsernsMode(cfg.Docker.UsernsMode),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the root directory for the server exists properly before attempting
|
// Ensure the root directory for the server exists properly before attempting
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/events"
|
"github.com/pterodactyl/wings/events"
|
||||||
"github.com/pterodactyl/wings/system"
|
"github.com/pterodactyl/wings/system"
|
||||||
|
|
||||||
|
|
|
@ -205,6 +205,7 @@ func (m *Manager) InitServer(data remote.ServerConfigurationResponse) (*Server,
|
||||||
Mounts: s.Mounts(),
|
Mounts: s.Mounts(),
|
||||||
Allocations: s.cfg.Allocations,
|
Allocations: s.cfg.Allocations,
|
||||||
Limits: s.cfg.Build,
|
Limits: s.cfg.Build,
|
||||||
|
Labels: s.cfg.Labels,
|
||||||
}
|
}
|
||||||
|
|
||||||
envCfg := environment.NewConfiguration(settings, s.GetEnvironmentVariables())
|
envCfg := environment.NewConfiguration(settings, s.GetEnvironmentVariables())
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/config"
|
"github.com/pterodactyl/wings/config"
|
||||||
"github.com/pterodactyl/wings/environment"
|
"github.com/pterodactyl/wings/environment"
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/franela/goblin"
|
. "github.com/franela/goblin"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/system"
|
"github.com/pterodactyl/wings/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package sftp
|
||||||
import (
|
import (
|
||||||
"emperror.dev/errors"
|
"emperror.dev/errors"
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
|
|
||||||
"github.com/pterodactyl/wings/internal/database"
|
"github.com/pterodactyl/wings/internal/database"
|
||||||
"github.com/pterodactyl/wings/internal/models"
|
"github.com/pterodactyl/wings/internal/models"
|
||||||
)
|
)
|
||||||
|
|
|
@ -23,7 +23,7 @@ type SinkPool struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSinkPool returns a new empty SinkPool. A sink pool generally lives with a
|
// NewSinkPool returns a new empty SinkPool. A sink pool generally lives with a
|
||||||
// server instance for it's full lifetime.
|
// server instance for its full lifetime.
|
||||||
func NewSinkPool() *SinkPool {
|
func NewSinkPool() *SinkPool {
|
||||||
return &SinkPool{}
|
return &SinkPool{}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user