-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
324 lines (311 loc) · 14.1 KB
/
app.js
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
const { createApp } = Vue
createApp({
data() {
return {
ipAddress: 'cp-demo.sedirector.net',
port: '443',
apiKey: '8aQ2DSRFqpLihtO34XiFVIpD',
servers: [],
fields: ['status', 'id', 'game', 'name', 'port', 'currentNumberOfPlayers', 'currentMap', 'uptime', 'actions'],
connected: false,
refreshInterval: null,
currentPage: 0,
pageSize: 8,
showModal: false,
currentFilter: null,
showFilters: true,
searchTerm: '',
activeFilter: null,
isFilterActive: false,
currentAction: '',
authMessage: '',
authMessageColor: 'black'
};
},
methods: {
loadCredentials() {
// Disabled for demo
/*
this.ipAddress = localStorage.getItem('ipAddress') || '';
this.port = localStorage.getItem('port') || '';
this.apiKey = localStorage.getItem('apiKey') || '';
// Check if credentials are available before calling listServers
if (this.ipAddress && this.port && this.apiKey) {
this.listServers();
}
*/
},
saveCredentials() {
localStorage.setItem('ipAddress', this.ipAddress);
localStorage.setItem('port', this.port);
localStorage.setItem('apiKey', this.apiKey);
},
removeCredentials() {
localStorage.removeItem('ipAddress');
localStorage.removeItem('port');
localStorage.removeItem('apiKey');
},
apiURL(action, serverId) {
if (serverId !== undefined) {
return `https://${this.ipAddress}:${this.port}/api/servers/${action}/${serverId}?apikey=${this.apiKey}`;
}
return `https://${this.ipAddress}:${this.port}/api/servers?apikey=${this.apiKey}`;
},
validateApiKey() {
const url = `https://${this.ipAddress}:${this.port}/api/servers?apikey=${this.apiKey}`;
// Use jQuery's ajax method to get server data
$.ajax({
url: url,
type: 'GET',
dataType: 'json',
success: (data) => {
// Handle the response from the server
if (data.success) { // Adapt condition based on your API response
this.authMessage = "Authentication Successful";
this.authMessageColor = 'green';
this.connected = true;
} else {
this.authMessage = "Authentication Failed. Wrong API Key.";
this.authMessageColor = 'red';
}
},
error: (jqXHR, textStatus, errorThrown) => {
console.error('AJAX error: ', textStatus, errorThrown);
this.authMessage = "Authentication Failed. Please check your connection details.";
this.authMessageColor = 'red';
}
});
},
searchServers() {
if (!this.searchTerm) return this.servers;
return this.servers.filter(server => {
return server.name.toLowerCase().includes(this.searchTerm.toLowerCase()) ||
server.game.toLowerCase().includes(this.searchTerm.toLowerCase()) ||
server.status.toLowerCase().includes(this.searchTerm.toLowerCase()) ||
server.port.toString().includes(this.searchTerm); // If port is a number
});
},
setFilter(filterType) {
this.currentFilter = filterType;
this.filterServers();
},
filterServers() {
// Depending on the filter type, we can apply different filtering logic
switch (this.currentFilter) {
case 'game':
this.servers.sort((a, b) => a.game.localeCompare(b.game));
break;
case 'name':
this.servers.sort((a, b) => a.name.localeCompare(b.name));
break;
case 'status':
this.servers.sort((a, b) => a.status.localeCompare(b.status));
break;
case 'port':
this.servers.sort((a, b) => a.port - b.port); // Assuming port is a number
break;
default:
// Default sort logic
this.servers.sort((a, b) => a.id - b.id); // Assuming ID is a number
break;
}
},
listServers() {
$.get(this.apiURL('', undefined), (response) => {
if (response.success) {
this.servers = response.data;
this.connected = true;
this.saveCredentials();
// Apply the current filter after fetching the list
if (this.currentFilter) {
this.filterServers();
}
}
});
},
startServer(id) {
$.get(this.apiURL('start', id), (response) => {
if (response.success) {
this.listServers();
}
});
},
stopServer(id) {
$.get(this.apiURL('stop', id), (response) => {
if (response.success) {
this.listServers();
}
});
},
restartServer(id) {
$.get(this.apiURL('restart', id), (response) => {
if (response.success) {
this.listServers();
}
});
},
updateServer(id) {
$.get(this.apiURL('update', id), (response) => {
if (response.success) {
this.listServers();
}
});
},
disconnectAndReload() {
this.removeCredentials(); // Ensure credentials are removed before reloading
window.location.reload(); // Refresh the page
},
disconnect() {
this.connected = false;
this.removeCredentials();
clearInterval(this.refreshInterval);
},
startPolling() {
if (this.refreshInterval) {
clearInterval(this.refreshInterval);
}
this.refreshInterval = setInterval(() => {
if (this.connected) {
this.listServers();
}
}, 1000);
},
nextPage() {
if (this.currentPage < Math.ceil(this.filteredServers.length / this.pageSize) - 1) {
this.currentPage++;
}
},
previousPage() {
if (this.currentPage > 0) {
this.currentPage--;
}
},
confirmAction(action) {
this.currentAction = action;
this.showModal = true;
},
executeAction() {
if (this.currentAction === 'startAll') {
this.startAllServers();
} else if (this.currentAction === 'stopAll') {
this.stopAllServers();
} else if (this.currentAction === 'restartAll') {
this.restartAllServers();
} else if (this.currentAction === 'updateAll') {
this.updateAllServers();
}
},
startAllServers() {
$.get(this.apiURL('start', 'all'), (response) => {
if (response.success) {
this.listServers();
}
});
},
stopAllServers() {
$.get(this.apiURL('stop', 'all'), (response) => {
if (response.success) {
this.listServers();
}
});
},
restartAllServers() {
$.get(this.apiURL('restart', 'all'), (response) => {
if (response.success) {
this.listServers();
}
});
},
updateAllServers() {
$.get(this.apiURL('update', 'all'), (response) => {
if (response.success) {
this.listServers();
}
});
},
shouldShowIconInActions(server) {
const statusIconMap = {
'Updating': 'https://i.ibb.co/cTtNPLB/icons8-update.gif',
'Update Starting': 'https://i.ibb.co/cTtNPLB/icons8-update.gif',
'Stopping': 'https://i.ibb.co/gMQC4c7/icons8-loading-2.gif',
'Error Starting': 'https://i.ibb.co/TLjDLt5/icons8-error.gif',
'Update Error': 'https://i.ibb.co/TLjDLt5/icons8-error.gif',
'Starting': 'https://i.ibb.co/6gCpQXx/icons8-loading-1.gif',
'Pending Update': 'https://i.ibb.co/N1VPGGK/icons8-update.gif',
};
return statusIconMap[server.status] || '';
},
getStatusIconUrl(status) {
const statusIcons = {
'Offline': 'https://i.ibb.co/VgHk2WM/offline.png',
'Running': 'https://i.ibb.co/pxtxwvz/running.png',
'Error Starting': 'https://i.ibb.co/TLjDLt5/icons8-error.gif',
'Update Error': 'https://i.ibb.co/TLjDLt5/icons8-error.gif',
'Restarting': 'https://i.ibb.co/g415yBM/restarting.png',
'Updating': 'https://i.ibb.co/cTtNPLB/icons8-update.gif',
'Update Starting': 'https://i.ibb.co/cTtNPLB/icons8-update.gif',
'Stopping': 'https://i.ibb.co/gMQC4c7/icons8-loading-2.gif',
'Starting': 'https://i.ibb.co/6gCpQXx/icons8-loading-1.gif',
'Pending Update': 'https://i.ibb.co/N1VPGGK/icons8-update.gif',
// ... other statuses
};
if (!statusIcons[status]) {
console.error('Unknown server status:', status);
return ''; // Default icon or keep it empty
}
return statusIcons[status];
}
},
computed: {
paginatedServers() {
const filteredServers = this.searchServers();
const start = this.currentPage * this.pageSize;
const end = start + this.pageSize;
return filteredServers.slice(start, end);
},
filteredServers() {
if (!this.searchTerm) return this.servers;
return this.servers.filter(server => {
return (server.name ? server.name.includes(this.searchTerm) : false) ||
(server.game ? server.game.includes(this.searchTerm) : false) ||
(server.status ? server.status.includes(this.searchTerm) : false) ||
(server.port ? server.port.includes(this.searchTerm) : false) ||
(server.serverid ? server.serverid.includes(this.searchTerm) : false);
// Add other fields as necessary
});
},
getGameIconUrl() {
const gameIconUrls = {
'Counter-Strike: Source': 'https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/240/9052fa60c496a1c03383b27687ec50f4bf0f0e10.jpg',
'Counter-Strike: Global Offensive': 'https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/730/69f7ebe2735c366c65c0b33dae00e12dc40edbe4.jpg',
'Left 4 Dead 2': 'https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/550/7d5a243f9500d2f8467312822f8af2a2928777ed.jpg',
'Age of Chivalry': 'https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/17510/c13110cfe96f0157c2ebd2e5b57a1aee6895dc95.jpg',
'Alien Swarm': 'https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/630/67126b5081b423af53f5e88e8e81d91b15daa644.jpg',
'Alien Swarm: Reactive Drop': 'https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/563560/3f30d5d196532aa1d79dbf133f067a38769178dc.jpg',
'D.I.P.R.I.P. Warm Up': 'https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/17530/3f8cb122a58b0a0a35bbdabb0d17a34e057909fc.jpg',
'Day of Defeat: Source': 'https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/300/062754bb5853b0534283ae27dc5d58200692b22d.jpg',
'Garry\'s Mod': 'https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/4000/4a6f25cfa2426445d0d9d6e233408de4d371ce8b.jpg',
'Half-Life 2: Deathmatch': 'https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/320/795e85364189511f4990861b578084deef086cb1.jpg',
'Insurgency': 'https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/222880/b072fc4239951c1952f4877edde340419438b528.jpg',
'Left 4 Dead': 'https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/500/428df26bc35b09319e31b1ffb712487b20b3245c.jpg',
'No More Room In Hell': 'https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/224260/684de0d9c5749b5ddd52f120894fd97efd620b1d.jpg',
'Synergy': 'https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/1989070/8d0699a05463f5638a1eddd0a690cfcae9cd6424.jpg',
'Team Fortress 2': 'https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/440/e3f595a92552da3d664ad00277fad2107345f743.jpg',
'Team Fortress 2 Classic': 'https://cdn.statically.io/gh/int-72h/TF2CDownloader/main/tf2c.ico',
'Zombie Panic! Source': 'https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/17500/e74eb496df79432ed99a45644ed54d1572f3e385.jpg'
};
return (gameName) => {
return gameIconUrls[gameName] || '';
};
}
},
mounted() {
this.loadCredentials();
this.startPolling();
},
beforeUnmount() {
if (this.refreshInterval) {
clearInterval(this.refreshInterval);
}
}
}).mount('#app');