From f7f5623c7171157ce164690bfc2a630a0637cca7 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Thu, 24 Dec 2020 09:01:00 -0800 Subject: [PATCH] Set UA and limit simultaneous downloads --- router/downloader/downloader.go | 3 +++ router/router_server_files.go | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/router/downloader/downloader.go b/router/downloader/downloader.go index c27a2cb..905bdd2 100644 --- a/router/downloader/downloader.go +++ b/router/downloader/downloader.go @@ -4,8 +4,10 @@ import ( "context" "emperror.dev/errors" "encoding/json" + "fmt" "github.com/google/uuid" "github.com/pterodactyl/wings/server" + "github.com/pterodactyl/wings/system" "io" "net/http" "net/url" @@ -109,6 +111,7 @@ func (dl *Download) Execute() error { defer dl.Cancel() req, _ := http.NewRequestWithContext(ctx, http.MethodGet, dl.req.URL.String(), nil) + req.Header.Set("User-Agent", fmt.Sprintf("Pterodactyl Panel (Wings v%s) (https://pterodactyl.io)", system.Version)) res, err := client.Do(req) if err != nil { return errors.New("downloader: failed opening request to download file") diff --git a/router/router_server_files.go b/router/router_server_files.go index 05e8ee2..8cd7a6d 100644 --- a/router/router_server_files.go +++ b/router/router_server_files.go @@ -271,6 +271,13 @@ func postServerPullRemoteFile(c *gin.Context) { WithError(c, err) return } + // Do not allow more than three simultaneous remote file downloads at one time. + if len(downloader.ByServer(s.Id())) >= 3 { + c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{ + "error": "This server has reached its limit of 3 simultaneous remote file downloads at once. Please wait for one to complete before trying again.", + }) + return + } dl := downloader.New(s, downloader.DownloadRequest{ URL: u,