forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.vue
More file actions
158 lines (142 loc) · 6.25 KB
/
Server.vue
File metadata and controls
158 lines (142 loc) · 6.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<template>
<div>
<navigation></navigation>
<div v-if="loadingServerData">
<div class="mt-6 h-16">
<div class="spinner spinner-xl spinner-thick blue"></div>
</div>
</div>
<div class="m-6 flex flex-no-shrink rounded animate fadein" v-else>
<div class="sidebar border-grey-lighter flex-no-shrink w-1/3 max-w-xs">
<div class="mr-6">
<div class="p-6 text-center bg-white border rounded">
<h3 class="mb-2 text-blue font-medium">{{server.name}}</h3>
<span class="text-grey-dark text-sm">{{server.node}}</span>
</div>
<div class="mt-6 p-4 text-center bg-white border rounded">
<button class="btn btn-red uppercase text-xs px-4 py-2">Stop</button>
<button class="btn btn-secondary uppercase text-xs px-4 py-2">Restart</button>
<button class="btn btn-secondary uppercase text-xs px-4 py-2">Kill</button>
</div>
<div class="mt-6 p-4 bg-white border rounded">
<progress-bar title="Memory" percent="33"></progress-bar>
<progress-bar title="CPU" percent="80" class="mt-4"></progress-bar>
<progress-bar title="Disk" percent="97" class="mt-4"></progress-bar>
</div>
</div>
<div class="sidenav">
<router-link :to="{ name: 'server', params: { id: this.$route.params.id } }">
<terminal-icon style="height: 1em;"></terminal-icon>
Console
</router-link>
<router-link :to="{ name: 'server-files' }">
<folder-icon style="height: 1em;"></folder-icon>
Files
</router-link>
<router-link :to="{ name: 'server-subusers' }">
<users-icon style="height: 1em;"></users-icon>
Subusers
</router-link>
<router-link :to="{ name: 'server-schedules' }">
<calendar-icon style="height: 1em;"></calendar-icon>
Schedules
</router-link>
<router-link :to="{ name: 'server-databases' }">
<database-icon style="height: 1em;"></database-icon>
Databases
</router-link>
<router-link :to="{ name: 'server-allocations' }">
<globe-icon style="height: 1em;"></globe-icon>
Allocations
</router-link>
<router-link :to="{ name: 'server-settings' }">
<settings-icon style="height: 1em;"></settings-icon>
Settings
</router-link>
</div>
</div>
<div class="bg-white p-6 rounded border border-grey-light h-full w-full">
<router-view></router-view>
</div>
</div>
</div>
</template>
<script>
import { TerminalIcon, FolderIcon, UsersIcon, CalendarIcon, DatabaseIcon, GlobeIcon, SettingsIcon } from 'vue-feather-icons'
import Navigation from '../core/Navigation';
import ProgressBar from './components/ProgressBar';
import {mapState} from 'vuex';
import io from 'socket.io-client';
export default {
components: {
ProgressBar, Navigation, TerminalIcon, FolderIcon, UsersIcon,
CalendarIcon, DatabaseIcon, GlobeIcon, SettingsIcon
},
computed: {
...mapState('server', ['server', 'credentials']),
},
mounted: function () {
this.loadServer();
this.$on('send-command', data => {
this.socket.emit('send command', data);
});
this.$on('send-initial-log', () => {
this.socket.emit('send server log');
})
},
data: function () {
return {
socket: null,
loadingServerData: true,
};
},
methods: {
/**
* Load the core server information needed for these pages to be functional.
*/
loadServer: function () {
Promise.all([
this.$store.dispatch('server/getServer', {server: this.$route.params.id}),
this.$store.dispatch('server/getCredentials', {server: this.$route.params.id})
])
.then(() => {
this.loadingServerData = false;
this.initalizeWebsocket();
})
.catch(console.error);
},
initalizeWebsocket: function () {
this.socket = io(this.credentials.node + '/v1/ws/' + this.server.uuid, {
query: 'token=' + this.credentials.key,
});
this.socket.on('error', this._socket_error);
this.socket.on('connect', this._socket_connect);
this.socket.on('status', this._socket_status);
this.socket.on('initial status', this._socket_status);
this.socket.on('server log', this._socket_serverLog);
this.socket.on('console', this._socket_consoleLine);
},
_socket_error: function (err) {
this.$emit('socket-error', {err});
},
_socket_connect: function () {
this.$emit('socket-connected');
},
_socket_status: function (data) {
this.$emit('socket-status', {data});
},
_socket_serverLog: function (data) {
data.split(/\n/g).forEach(item => {
this.$emit('console', item);
});
},
_socket_consoleLine: function (data) {
if(data.line) {
data.line.split(/\n/g).forEach(item => {
this.$emit('console', item);
});
}
},
},
}
</script>