Add ability to create archives of servers, add GET and POST /api/servers/:server/archive routes to get and request an archive of a server
This commit is contained in:
		
							parent
							
								
									5fd138e188
								
							
						
					
					
						commit
						3dba11ac6f
					
				|  | @ -122,3 +122,27 @@ func (r *PanelRequest) SendInstallationStatus(uuid string, successful bool) (*Re | |||
| 
 | ||||
| 	return nil, nil | ||||
| } | ||||
| 
 | ||||
| type archiveRequest struct { | ||||
| 	Successful bool `json:"successful"` | ||||
| } | ||||
| 
 | ||||
| func (r *PanelRequest) SendArchiveStatus(uuid string, successful bool) (*RequestError, error) { | ||||
| 	b, err := json.Marshal(archiveRequest{Successful: successful}) | ||||
| 	if err != nil { | ||||
| 		return nil, errors.WithStack(err) | ||||
| 	} | ||||
| 
 | ||||
| 	resp, err := r.Post(fmt.Sprintf("/servers/%s/archive", uuid), b) | ||||
| 	if err != nil { | ||||
| 		return nil, errors.WithStack(err) | ||||
| 	} | ||||
| 	defer resp.Body.Close() | ||||
| 
 | ||||
| 	r.Response = resp | ||||
| 	if r.HasError() { | ||||
| 		return r.Error(), nil | ||||
| 	} | ||||
| 
 | ||||
| 	return nil, nil | ||||
| } | ||||
|  |  | |||
							
								
								
									
										9
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								go.mod
									
									
									
									
									
								
							|  | @ -35,8 +35,9 @@ require ( | |||
| 	github.com/imdario/mergo v0.3.8 | ||||
| 	github.com/julienschmidt/httprouter v1.2.0 | ||||
| 	github.com/magiconair/properties v1.8.1 | ||||
| 	github.com/mattn/go-shellwords v1.0.10 // indirect | ||||
| 	github.com/mholt/archiver/v3 v3.3.0 | ||||
| 	github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db | ||||
| 	github.com/olebedev/emitter v0.0.0-20190110104742-e8d1457e6aee | ||||
| 	github.com/onsi/ginkgo v1.8.0 // indirect | ||||
| 	github.com/onsi/gomega v1.5.0 // indirect | ||||
| 	github.com/opencontainers/go-digest v1.0.0-rc1 // indirect | ||||
|  | @ -47,18 +48,18 @@ require ( | |||
| 	github.com/pterodactyl/sftp-server v1.1.1 | ||||
| 	github.com/remeh/sizedwaitgroup v0.0.0-20180822144253-5e7302b12cce | ||||
| 	github.com/sirupsen/logrus v1.0.5 // indirect | ||||
| 	github.com/smartystreets/goconvey v1.6.4 // indirect | ||||
| 	go.uber.org/atomic v1.5.1 // indirect | ||||
| 	go.uber.org/multierr v1.4.0 // indirect | ||||
| 	go.uber.org/zap v1.13.0 | ||||
| 	golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413 | ||||
| 	golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413 // indirect | ||||
| 	golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f // indirect | ||||
| 	golang.org/x/net v0.0.0-20190923162816-aa69164e4478 | ||||
| 	golang.org/x/net v0.0.0-20190923162816-aa69164e4478 // indirect | ||||
| 	golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect | ||||
| 	golang.org/x/sys v0.0.0-20191206220618-eeba5f6aabab // indirect | ||||
| 	golang.org/x/text v0.3.2 // indirect | ||||
| 	golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect | ||||
| 	golang.org/x/tools v0.0.0-20191206204035-259af5ff87bd // indirect | ||||
| 	golang.org/x/tools/gopls v0.1.7 // indirect | ||||
| 	gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect | ||||
| 	gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect | ||||
| 	gopkg.in/ini.v1 v1.51.0 | ||||
|  |  | |||
							
								
								
									
										67
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										67
									
								
								go.sum
									
									
									
									
									
								
							|  | @ -8,13 +8,12 @@ github.com/Microsoft/go-winio v0.4.7 h1:vOvDiY/F1avSWlCWiKJjdYKz2jVjTK3pWPHndeG4 | |||
| github.com/Microsoft/go-winio v0.4.7/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA= | ||||
| github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw= | ||||
| github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk= | ||||
| github.com/andybalholm/brotli v0.0.0-20190621154722-5f990b63d2d6 h1:bZ28Hqta7TFAK3Q08CMvv8y3/8ATaEqv2nGoc6yff6c= | ||||
| github.com/andybalholm/brotli v0.0.0-20190621154722-5f990b63d2d6/go.mod h1:+lx6/Aqd1kLJ1GQfkvOnaZ1WGmLpMpbprPuIOOZX30U= | ||||
| github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA= | ||||
| github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= | ||||
| github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs= | ||||
| github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A= | ||||
| github.com/buger/jsonparser v0.0.0-20181023193515-52c6e1462ebd/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s= | ||||
| github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23 h1:D21IyuvjDCshj1/qq+pCNd3VZOAEI9jy6Bi131YlXgI= | ||||
| github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s= | ||||
| github.com/buger/jsonparser v0.0.0-20191204142016-1a29609e0929 h1:MW/JDk68Rny52yI0M0N+P8lySNgB+NhpI/uAmhgOhUM= | ||||
| github.com/buger/jsonparser v0.0.0-20191204142016-1a29609e0929/go.mod h1:tgcrVJ81GPSF0mz+0nu1Xaz0fazGPrmmJfJtxjbHhUQ= | ||||
| github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448 h1:PUD50EuOMkXVcpBIA/R95d56duJR9VxhwncsFbNnxW4= | ||||
|  | @ -22,6 +21,7 @@ github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv | |||
| github.com/creasty/defaults v1.3.0 h1:uG+RAxYbJgOPCOdKEcec9ZJXeva7Y6mj/8egdzwmLtw= | ||||
| github.com/creasty/defaults v1.3.0/go.mod h1:CIEEvs7oIVZm30R8VxtFJs+4k201gReYyuYHJxZc68I= | ||||
| github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||
| github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||||
| github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||
| github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug= | ||||
| github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= | ||||
|  | @ -31,6 +31,9 @@ github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKoh | |||
| github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= | ||||
| github.com/docker/go-units v0.3.3 h1:Xk8S3Xj5sLGlG5g67hJmYMmUgXv5N4PhkjJHHqrwnTk= | ||||
| github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= | ||||
| github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q= | ||||
| github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo= | ||||
| github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY= | ||||
| github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= | ||||
| github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= | ||||
| github.com/gabriel-vasile/mimetype v0.1.4 h1:5mcsq3+DXypREUkW+1juhjeKmE/XnWgs+paHMJn7lf8= | ||||
|  | @ -41,14 +44,20 @@ github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= | |||
| github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= | ||||
| github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= | ||||
| github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= | ||||
| github.com/golang/gddo v0.0.0-20190419222130-af0f2af80721 h1:KRMr9A3qfbVM7iV/WcLY/rL5LICqwMHLhwRXKu99fXw= | ||||
| github.com/golang/gddo v0.0.0-20190419222130-af0f2af80721/go.mod h1:xEhNfoBDX1hzLm2Nf80qUvZ2sVwoMZ8d6IE2SrsQfh4= | ||||
| github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= | ||||
| github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= | ||||
| github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= | ||||
| github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= | ||||
| github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= | ||||
| github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= | ||||
| github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= | ||||
| github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= | ||||
| github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= | ||||
| github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= | ||||
| github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= | ||||
| github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||||
| github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= | ||||
| github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= | ||||
| github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= | ||||
| github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= | ||||
| github.com/gotestyourself/gotestyourself v2.2.0+incompatible h1:AQwinXlbQR2HvPjQZOmDhRqsv5mZf+Jb1RnSLxcqZcI= | ||||
|  | @ -59,10 +68,18 @@ github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334 h1:VHgatEHNcBFE | |||
| github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE= | ||||
| github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ= | ||||
| github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= | ||||
| github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= | ||||
| github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= | ||||
| github.com/julienschmidt/httprouter v1.2.0 h1:TDTW5Yz1mjftljbcKqRcrYhd4XeOoI98t+9HbQbYf7g= | ||||
| github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= | ||||
| github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= | ||||
| github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= | ||||
| github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= | ||||
| github.com/klauspost/compress v1.9.2 h1:LfVyl+ZlLlLDeQ/d2AqfGIIH4qEDu0Ed2S5GyhCWIWY= | ||||
| github.com/klauspost/compress v1.9.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= | ||||
| github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= | ||||
| github.com/klauspost/pgzip v1.2.1 h1:oIPZROsWuPHpOdMVWLuJZXwgjhrW8r1yEX8UqMyeNHM= | ||||
| github.com/klauspost/pgzip v1.2.1/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs= | ||||
| github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8= | ||||
| github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= | ||||
| github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= | ||||
|  | @ -74,10 +91,14 @@ github.com/magefile/mage v1.9.0 h1:t3AU2wNwehMCW97vuqQLtw6puppWXHO+O2MHo5a50XE= | |||
| github.com/magefile/mage v1.9.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= | ||||
| github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= | ||||
| github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= | ||||
| github.com/mattn/go-shellwords v1.0.10 h1:Y7Xqm8piKOO3v10Thp7Z36h4FYFjt5xB//6XvOrs2Gw= | ||||
| github.com/mattn/go-shellwords v1.0.10/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y= | ||||
| github.com/mholt/archiver/v3 v3.3.0 h1:vWjhY8SQp5yzM9P6OJ/eZEkmi3UAbRrxCq48MxjAzig= | ||||
| github.com/mholt/archiver/v3 v3.3.0/go.mod h1:YnQtqsp+94Rwd0D/rk5cnLrxusUBUXg+08Ebtr1Mqao= | ||||
| github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= | ||||
| github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= | ||||
| github.com/olebedev/emitter v0.0.0-20190110104742-e8d1457e6aee h1:IquUs3fIykn10zWDIyddanhpTqBvAHMaPnFhQuyYw5U= | ||||
| github.com/olebedev/emitter v0.0.0-20190110104742-e8d1457e6aee/go.mod h1:eT2/Pcsim3XBjbvldGiJBvvgiqZkAFyiOJJsDKXs/ts= | ||||
| github.com/nwaples/rardecode v1.0.0 h1:r7vGuS5akxOnR4JQSkko62RJ1ReCMXxQRPtxsiFMBOs= | ||||
| github.com/nwaples/rardecode v1.0.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0= | ||||
| github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= | ||||
| github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w= | ||||
| github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= | ||||
|  | @ -89,6 +110,8 @@ github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVo | |||
| github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= | ||||
| github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= | ||||
| github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= | ||||
| github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I= | ||||
| github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= | ||||
| github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= | ||||
| github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | ||||
| github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= | ||||
|  | @ -97,11 +120,8 @@ github.com/pkg/sftp v1.8.3 h1:9jSe2SxTM8/3bXZjtqnkgTBW+lA8db0knZJyns7gpBA= | |||
| github.com/pkg/sftp v1.8.3/go.mod h1:NxmoDg/QLVWluQDUYG7XBZTLUpKeFa8e3aMf1BfjyHk= | ||||
| github.com/pkg/sftp v1.10.1 h1:VasscCm72135zRysgrJDKsntdmPN+OuU3+nnHYA9wyc= | ||||
| github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= | ||||
| github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||||
| github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||||
| github.com/pterodactyl/sftp-server v1.0.4 h1:hPUaUQvA6U/R8/bybQFDMBDcZaqqj+kufGBQZ3esP5M= | ||||
| github.com/pterodactyl/sftp-server v1.0.4/go.mod h1:0LKDl+f1qY2TH9+B5jxdROktW0+10UM1qJ472iWbyvQ= | ||||
| github.com/pterodactyl/sftp-server v1.1.0 h1:NcYh+UqEH8pfvFsee6yt7eb08RLLidw6q+cNOCdh/V0= | ||||
| github.com/pterodactyl/sftp-server v1.1.0/go.mod h1:b1VVWYv0RF9rxSZQqaD/rYXriiRMNPsbV//CKMXR4ag= | ||||
| github.com/pterodactyl/sftp-server v1.1.1 h1:IjuOy21BNZxfejKnXG1RgLxXAYylDqBVpbKZ6+fG5FQ= | ||||
| github.com/pterodactyl/sftp-server v1.1.1/go.mod h1:b1VVWYv0RF9rxSZQqaD/rYXriiRMNPsbV//CKMXR4ag= | ||||
| github.com/remeh/sizedwaitgroup v0.0.0-20180822144253-5e7302b12cce h1:aP+C+YbHZfOQlutA4p4soHi7rVUqHQdWEVMSkHfDTqY= | ||||
|  | @ -109,10 +129,19 @@ github.com/remeh/sizedwaitgroup v0.0.0-20180822144253-5e7302b12cce/go.mod h1:3j2 | |||
| github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= | ||||
| github.com/sirupsen/logrus v1.0.5 h1:8c8b5uO0zS4X6RPl/sd1ENwSkIc0/H2PaHxE3udaE8I= | ||||
| github.com/sirupsen/logrus v1.0.5/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc= | ||||
| github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= | ||||
| github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= | ||||
| github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= | ||||
| github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= | ||||
| github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||||
| github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | ||||
| github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= | ||||
| github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= | ||||
| github.com/uber-go/zap v1.9.1/go.mod h1:GY+83l3yxBcBw2kmHu/sAWwItnTn+ynxHCRo+WiIQOY= | ||||
| github.com/ulikunitz/xz v0.5.6 h1:jGHAfXawEGZQ3blwU5wnWKQJvAraT7Ftq9EXjnXYgt8= | ||||
| github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8= | ||||
| github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo= | ||||
| github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos= | ||||
| go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4= | ||||
| go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= | ||||
| go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= | ||||
|  | @ -131,17 +160,12 @@ go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU= | |||
| go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= | ||||
| golang.org/x/crypto v0.0.0-20181025213731-e84da0312774/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= | ||||
| golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||||
| golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480 h1:O5YqonU5IWby+w98jVUG9h7zlCWCcH4RHyPVReBmhzk= | ||||
| golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= | ||||
| golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= | ||||
| golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= | ||||
| golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= | ||||
| golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392 h1:ACG4HJsFiNMf47Y4PeRoebLNy/2lXT9EtprMuTFWt1M= | ||||
| golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= | ||||
| golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413 h1:ULYEB3JvPRE/IfO+9uO7vKV/xzVTO7XPAwm8xbf4w2g= | ||||
| golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= | ||||
| golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= | ||||
| golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= | ||||
| golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= | ||||
| golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= | ||||
| golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNTEKDvWeuc1yieZ8qUzUE= | ||||
|  | @ -157,30 +181,26 @@ golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLL | |||
| golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= | ||||
| golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||||
| golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||||
| golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= | ||||
| golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||||
| golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs= | ||||
| golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||||
| golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||||
| golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e h1:nFYrTHrdrAOpShe27kaFHjsqYSEQ0KWqdWLu3xuZJts= | ||||
| golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPTs2tR8uOySCbBP7BN/M= | ||||
| golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20191206220618-eeba5f6aabab h1:FvshnhkKW+LO3HWHodML8kuVX8rnJTxKm9dFPuI68UM= | ||||
| golang.org/x/sys v0.0.0-20191206220618-eeba5f6aabab/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= | ||||
| golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||||
| golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= | ||||
| golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= | ||||
| golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ= | ||||
| golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= | ||||
| golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||||
| golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||||
| golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= | ||||
| golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= | ||||
| golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= | ||||
| golang.org/x/tools v0.0.0-20190710153321-831012c29e42/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= | ||||
| golang.org/x/tools v0.0.0-20190918214516-5a1a30219888/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= | ||||
| golang.org/x/tools v0.0.0-20190925020647-22afafe3322a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= | ||||
| golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= | ||||
| golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs= | ||||
| golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= | ||||
|  | @ -188,7 +208,6 @@ golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtn | |||
| golang.org/x/tools v0.0.0-20191206204035-259af5ff87bd h1:Zc7EU2PqpsNeIfOoVA7hvQX4cS3YDJEs5KlfatT3hLo= | ||||
| golang.org/x/tools v0.0.0-20191206204035-259af5ff87bd/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= | ||||
| golang.org/x/tools/gopls v0.1.3/go.mod h1:vrCQzOKxvuiZLjCKSmbbov04oeBQQOb4VQqwYK2PWIY= | ||||
| golang.org/x/tools/gopls v0.1.7/go.mod h1:PE3vTwT0ejw3a2L2fFgSJkxlEbA8Slbk+Lsy9hTmbG8= | ||||
| golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc= | ||||
| golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||||
| gopkg.in/airbrake/gobrake.v2 v2.0.9 h1:7z2uVWwn7oVeeugY1DtlPAy5H+KYgB1KeKTnqjNatLo= | ||||
|  |  | |||
							
								
								
									
										88
									
								
								http.go
									
									
									
									
									
								
							
							
						
						
									
										88
									
								
								http.go
									
									
									
									
									
								
							|  | @ -9,6 +9,7 @@ import ( | |||
| 	"github.com/gorilla/websocket" | ||||
| 	"github.com/julienschmidt/httprouter" | ||||
| 	"github.com/pkg/errors" | ||||
| 	"github.com/pterodactyl/wings/api" | ||||
| 	"github.com/pterodactyl/wings/config" | ||||
| 	"github.com/pterodactyl/wings/installer" | ||||
| 	"github.com/pterodactyl/wings/server" | ||||
|  | @ -18,6 +19,7 @@ import ( | |||
| 	"os" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| 	"time" | ||||
| ) | ||||
| 
 | ||||
| // Retrieves a server out of the collection by UUID.
 | ||||
|  | @ -60,7 +62,7 @@ func (rt *Router) AttachAccessControlHeaders(w http.ResponseWriter, r *http.Requ | |||
| 	return w, r, ps | ||||
| } | ||||
| 
 | ||||
| // Authenticates the request token aganist the given permission string, ensuring that
 | ||||
| // Authenticates the request token against the given permission string, ensuring that
 | ||||
| // if it is a server permission, the token has control over that server. If it is a global
 | ||||
| // token, this will ensure that the request is using a properly signed global token.
 | ||||
| func (rt *Router) AuthenticateToken(h httprouter.Handle) httprouter.Handle { | ||||
|  | @ -207,7 +209,7 @@ func (rt *Router) routeServerPower(w http.ResponseWriter, r *http.Request, ps ht | |||
| 					zap.String("action", "restart"), | ||||
| 				) | ||||
| 			} | ||||
| 			break; | ||||
| 			break | ||||
| 		case "kill": | ||||
| 			if err := s.Environment.Terminate(os.Kill); err != nil { | ||||
| 				zap.S().Errorw( | ||||
|  | @ -265,7 +267,7 @@ func (rt *Router) routeServerFileRead(w http.ResponseWriter, r *http.Request, ps | |||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	f, err := os.OpenFile(cleaned, os.O_RDONLY, 0) | ||||
| 	f, err := os.Open(cleaned) | ||||
| 	if err != nil { | ||||
| 		if !os.IsNotExist(err) { | ||||
| 			zap.S().Errorw("failed to open file for reading", zap.String("path", ps.ByName("path")), zap.String("server", s.Uuid), zap.Error(err)) | ||||
|  | @ -465,7 +467,7 @@ func (rt *Router) routeServerUpdate(w http.ResponseWriter, r *http.Request, ps h | |||
| 	w.WriteHeader(http.StatusNoContent) | ||||
| } | ||||
| 
 | ||||
| func (rt *Router) routeCreateServer(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { | ||||
| func (rt *Router) routeCreateServer(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||||
| 	defer r.Body.Close() | ||||
| 
 | ||||
| 	inst, err := installer.New(rt.ReaderToBytes(r.Body)) | ||||
|  | @ -510,7 +512,7 @@ func (rt *Router) routeServerReinstall(w http.ResponseWriter, r *http.Request, p | |||
| 	w.WriteHeader(http.StatusAccepted) | ||||
| } | ||||
| 
 | ||||
| func (rt *Router) routeSystemInformation(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { | ||||
| func (rt *Router) routeSystemInformation(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||||
| 	defer r.Body.Close() | ||||
| 
 | ||||
| 	s, err := GetSystemInformation() | ||||
|  | @ -572,6 +574,79 @@ func (rt *Router) routeServerDelete(w http.ResponseWriter, r *http.Request, ps h | |||
| 	w.WriteHeader(http.StatusAccepted) | ||||
| } | ||||
| 
 | ||||
| func (rt *Router) routeRequestServerArchive(w http.ResponseWriter, _ *http.Request, ps httprouter.Params) { | ||||
| 	s := rt.GetServer(ps.ByName("server")) | ||||
| 
 | ||||
| 	go func() { | ||||
| 		start := time.Now() | ||||
| 
 | ||||
| 		if err := s.Archiver.Archive(); err != nil { | ||||
| 			zap.S().Errorw("failed to get archive for server", zap.String("server", s.Uuid), zap.Error(err)) | ||||
| 			return | ||||
| 		} | ||||
| 
 | ||||
| 		zap.S().Debugw("successfully created archive for server", zap.String("server", s.Uuid), zap.Duration("time", time.Now().Sub(start).Round(time.Microsecond))) | ||||
| 
 | ||||
| 		r := api.NewRequester() | ||||
| 		rerr, err := r.SendArchiveStatus(s.Uuid, true) | ||||
| 		if rerr != nil || err != nil { | ||||
| 			if err != nil { | ||||
| 				zap.S().Errorw("failed to notify panel with archive status", zap.String("server", s.Uuid), zap.Error(err)) | ||||
| 				return | ||||
| 			} | ||||
| 
 | ||||
| 			zap.S().Errorw("panel returned an error when sending the archive status", zap.String("server", s.Uuid), zap.Error(errors.New(rerr.String()))) | ||||
| 			return | ||||
| 		} | ||||
| 
 | ||||
| 		zap.S().Debugw("successfully notified panel about archive status", zap.String("server", s.Uuid)) | ||||
| 	}() | ||||
| 
 | ||||
| 	w.WriteHeader(http.StatusAccepted) | ||||
| } | ||||
| 
 | ||||
| func (rt *Router) routeGetServerArchive(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { | ||||
| 	s := rt.GetServer(ps.ByName("server")) | ||||
| 
 | ||||
| 	st, err := s.Archiver.Stat() | ||||
| 	if err != nil { | ||||
| 		if !os.IsNotExist(err) { | ||||
| 			zap.S().Errorw("failed to stat archive for reading", zap.String("server", s.Uuid), zap.Error(err)) | ||||
| 			http.Error(w, "failed to stat archive", http.StatusInternalServerError) | ||||
| 			return | ||||
| 		} | ||||
| 
 | ||||
| 		http.NotFound(w, r) | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	checksum, err := s.Archiver.Checksum() | ||||
| 	if err != nil { | ||||
| 		zap.S().Errorw("failed to calculate checksum", zap.String("server", s.Uuid), zap.Error(err)) | ||||
| 		http.Error(w, "failed to calculate checksum", http.StatusInternalServerError) | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	file, err := os.Open(s.Archiver.ArchivePath()) | ||||
| 	if err != nil { | ||||
| 		if !os.IsNotExist(err) { | ||||
| 			zap.S().Errorw("failed to open archive for reading", zap.String("server", s.Uuid), zap.Error(err)) | ||||
| 		} | ||||
| 
 | ||||
| 		http.Error(w, "failed to open archive", http.StatusInternalServerError) | ||||
| 		return | ||||
| 	} | ||||
| 	defer file.Close() | ||||
| 
 | ||||
| 	w.Header().Set("X-Checksum", checksum) | ||||
| 	w.Header().Set("X-Mime-Type", st.Mimetype) | ||||
| 	w.Header().Set("Content-Length", strconv.Itoa(int(st.Info.Size()))) | ||||
| 	w.Header().Set("Content-Disposition", "attachment; filename="+s.Archiver.ArchiveName()) | ||||
| 	w.Header().Set("Content-Type", "application/octet-stream") | ||||
| 
 | ||||
| 	bufio.NewReader(file).WriteTo(w) | ||||
| } | ||||
| 
 | ||||
| func (rt *Router) ReaderToBytes(r io.Reader) []byte { | ||||
| 	buf := bytes.Buffer{} | ||||
| 	buf.ReadFrom(r) | ||||
|  | @ -608,5 +683,8 @@ func (rt *Router) ConfigureRouter() *httprouter.Router { | |||
| 	router.PATCH("/api/servers/:server", rt.AuthenticateRequest(rt.routeServerUpdate)) | ||||
| 	router.DELETE("/api/servers/:server", rt.AuthenticateRequest(rt.routeServerDelete)) | ||||
| 
 | ||||
| 	router.POST("/api/servers/:server/archive", rt.AuthenticateRequest(rt.routeRequestServerArchive)) | ||||
| 	router.GET("/api/servers/:server/archive", rt.AuthenticateRequest(rt.routeGetServerArchive)) | ||||
| 
 | ||||
| 	return router | ||||
| } | ||||
|  |  | |||
							
								
								
									
										75
									
								
								server/archiver.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								server/archiver.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,75 @@ | |||
| package server | ||||
| 
 | ||||
| import ( | ||||
| 	"crypto/sha256" | ||||
| 	"encoding/hex" | ||||
| 	"github.com/mholt/archiver/v3" | ||||
| 	"github.com/pterodactyl/wings/config" | ||||
| 	"io" | ||||
| 	"io/ioutil" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| ) | ||||
| 
 | ||||
| // Archiver represents a Server Archiver.
 | ||||
| type Archiver struct { | ||||
| 	Server *Server | ||||
| } | ||||
| 
 | ||||
| // ArchivePath returns the path to the server's archive.
 | ||||
| func (a *Archiver) ArchivePath() string { | ||||
| 	return filepath.Join(config.Get().System.Data, ".archives", a.ArchiveName()) | ||||
| } | ||||
| 
 | ||||
| // ArchiveName returns the name of the server's archive.
 | ||||
| func (a *Archiver) ArchiveName() string { | ||||
| 	return a.Server.Uuid + ".tar.gz" | ||||
| } | ||||
| 
 | ||||
| // Exists returns a boolean based off if the archive exists.
 | ||||
| func (a *Archiver) Exists() bool { | ||||
| 	if _, err := os.Stat(a.ArchivePath()); os.IsNotExist(err) { | ||||
| 		return false | ||||
| 	} | ||||
| 
 | ||||
| 	return true | ||||
| } | ||||
| 
 | ||||
| // Stat .
 | ||||
| func (a *Archiver) Stat() (*Stat, error) { | ||||
| 	return a.Server.Filesystem.unsafeStat(a.ArchivePath()) | ||||
| } | ||||
| 
 | ||||
| // Archive creates an archive of the server.
 | ||||
| func (a *Archiver) Archive() error { | ||||
| 	path := a.Server.Filesystem.Path() | ||||
| 
 | ||||
| 	// Get the list of root files and directories to archive.
 | ||||
| 	var files []string | ||||
| 	fileInfo, err := ioutil.ReadDir(path) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| 	for _, file := range fileInfo { | ||||
| 		files = append(files, filepath.Join(path, file.Name())) | ||||
| 	} | ||||
| 
 | ||||
| 	return archiver.NewTarGz().Archive(files, a.ArchivePath()) | ||||
| } | ||||
| 
 | ||||
| // Checksum computes a SHA256 checksum of the server's archive.
 | ||||
| func (a *Archiver) Checksum() (string, error) { | ||||
| 	file, err := os.Open(a.ArchivePath()) | ||||
| 	if err != nil { | ||||
| 		return "", err | ||||
| 	} | ||||
| 	defer file.Close() | ||||
| 
 | ||||
| 	hash := sha256.New() | ||||
| 	if _, err := io.Copy(hash, file); err != nil { | ||||
| 		return "", err | ||||
| 	} | ||||
| 
 | ||||
| 	return hex.EncodeToString(hash.Sum(nil)), nil | ||||
| } | ||||
|  | @ -299,14 +299,18 @@ func (fs *Filesystem) Stat(p string) (*Stat, error) { | |||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	s, err := os.Stat(cleaned) | ||||
| 	return fs.unsafeStat(cleaned) | ||||
| } | ||||
| 
 | ||||
| func (fs *Filesystem) unsafeStat(p string) (*Stat, error) { | ||||
| 	s, err := os.Stat(p) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	var m = "inode/directory" | ||||
| 	if !s.IsDir() { | ||||
| 		m, _, err = mimetype.DetectFile(cleaned) | ||||
| 		m, _, err = mimetype.DetectFile(p) | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
|  |  | |||
|  | @ -27,11 +27,11 @@ func GetServers() *Collection { | |||
| // High level definition for a server instance being controlled by Wings.
 | ||||
| type Server struct { | ||||
| 	// The unique identifier for the server that should be used when referencing
 | ||||
| 	// it aganist the Panel API (and internally). This will be used when naming
 | ||||
| 	// it against the Panel API (and internally). This will be used when naming
 | ||||
| 	// docker containers as well as in log output.
 | ||||
| 	Uuid string `json:"uuid"` | ||||
| 
 | ||||
| 	// Wether or not the server is in a suspended state. Suspended servers cannot
 | ||||
| 	// Whether or not the server is in a suspended state. Suspended servers cannot
 | ||||
| 	// be started or modified except in certain scenarios by an admin user.
 | ||||
| 	Suspended bool `json:"suspended"` | ||||
| 
 | ||||
|  | @ -45,6 +45,7 @@ type Server struct { | |||
| 	// server process.
 | ||||
| 	EnvVars map[string]string `json:"environment" yaml:"environment"` | ||||
| 
 | ||||
| 	Archiver       Archiver       `json:"-" yaml:"-"` | ||||
| 	CrashDetection CrashDetection `json:"crash_detection" yaml:"crash_detection"` | ||||
| 	Build          BuildSettings  `json:"build"` | ||||
| 	Allocations    Allocations    `json:"allocations"` | ||||
|  | @ -205,7 +206,7 @@ func (s *Server) Init() { | |||
| 	s.mutex = &sync.Mutex{} | ||||
| } | ||||
| 
 | ||||
| // Initalizes a server using a data byte array. This will be marshaled into the
 | ||||
| // Initializes a server using a data byte array. This will be marshaled into the
 | ||||
| // given struct using a YAML marshaler. This will also configure the given environment
 | ||||
| // for a server.
 | ||||
| func FromConfiguration(data []byte, cfg *config.SystemConfiguration) (*Server, error) { | ||||
|  | @ -231,6 +232,9 @@ func FromConfiguration(data []byte, cfg *config.SystemConfiguration) (*Server, e | |||
| 	} | ||||
| 
 | ||||
| 	s.Cache = cache.New(time.Minute*10, time.Minute*15) | ||||
| 	s.Archiver = Archiver{ | ||||
| 		Server: s, | ||||
| 	} | ||||
| 	s.Filesystem = Filesystem{ | ||||
| 		Configuration: cfg, | ||||
| 		Server:        s, | ||||
|  |  | |||
							
								
								
									
										2
									
								
								wings.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								wings.go
									
									
									
									
									
								
							|  | @ -54,7 +54,7 @@ func main() { | |||
| 	config.Set(c) | ||||
| 	config.SetDebugViaFlag(debug) | ||||
| 
 | ||||
| 	zap.S().Infof("checking for pterodactyl system user \"%s\"", c.System.User) | ||||
| 	zap.S().Infof("checking for pterodactyl system user \"%s\"", c.System.Username) | ||||
| 	if su, err := c.EnsurePterodactylUser(); err != nil { | ||||
| 		zap.S().Panicw("failed to create pterodactyl system user", zap.Error(err)) | ||||
| 		return | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user