This repository has been archived by the owner on Oct 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
144 lines (125 loc) · 5.05 KB
/
index.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
var userData
var authToken
const ipc = require("electron").ipcRenderer
ipc.send("init","webcontents")
ipc.on("auth", function(e,a){
authToken = a
$.getJSON('https://my.idley.gg/api/getUserServers?access_token='+authToken, function(data) {
userData = data;
if(data.error === undefined){
data.servers.forEach(element => {
$("#servers").append("<a class=\"panel-block is-active\" href=\"javascript:loadServerManagePage('"+element.id+"')\">"+element.name+"</a>")
});
} else {
if(data.error === "invalid_auth"){
alert("You have to login to the app again.")
}
}
})
})
function loadPteroManagePage(server_id){
ipc.send("loadPtero",{
server_id:server_id,
userData: userData
})
}
function loadServerManagePage(server_id){
const server = userData.servers.find(x => x.id === server_id);
$("body").html(`
<section class="hero is-link">
<div class="hero-body">
<p class="title">
Idley App
</p>
<p class="subtitle">
Server Management: ${server.name}
</p>
</div>
</section>
<div class="container" style="max-width: 1200px;">
<div class="container" style="width: 100%; margin: auto;">
<div class="box" style="width: 27%; margin-left: 5%; margin-top: 10px; display: inline-block;">
<p class="title">CPU</p>
<p>${server.cpu}%</p>
</div>
<div class="box" style="width: 27%; margin-left: 4%; display: inline-block;">
<p class="title">Disk</p>
<p>${server.disk}MB</p>
</div>
<div class="box" style="width: 27%; margin-left: 4%; display: inline-block;">
<p class="title">Memory</p>
<p>${server.memory}MB</p>
</div>
</div>
<form class="box" style="width: 50%; margin-left: 5%; display: inline-block;">
<div class="field">
<label class="label">Change Server CPU</label>
<div class="control">
<input class="input" id="newcpu" type="text" placeholder="New CPU" value="${server.cpu}">
</div>
</div>
<div class="field">
<label class="label">Change Memory</label>
<div class="control">
<input class="input" id="newmemory" type="text" placeholder="New Memory" value="${server.memory}">
</div>
</div>
<div class="field">
<label class="label">Change Server Disk</label>
<div class="control">
<input class="input" id="newdisk" type="text" placeholder="New Server Disk" value="${server.disk}">
</div>
</div>
<div class="field is-grouped">
<div class="control">
<button class="button is-link" type="button" onclick="updateServerSpecs('${server_id}')">Submit</button>
</div>
</div>
</form>
<div class="card" style="display: inline-block; width: 35%; vertical-align: top; margin-right: 5%; float: right;">
<header class="card-header">
<p class="card-header-title">
Manage
</p>
</header>
<div class="card-content">
<div class="content">
You can reinstall, change version of your server, or access console, file manager and sftp credentials.
</div>
</div>
<footer class="card-footer">
<a href="javascript:loadPteroManagePage('${server_id}')" class="card-footer-item">Manage at Control Panel</a>
</footer>
</div>
</div>
`)
console.log(server)
}
function updateServerSpecs(server_id){
var http = new XMLHttpRequest();
var url = 'https://my.idley.gg/api/updateServer?access_token='+authToken;
var params = `server_id=${server_id}&cpu=${$("#newcpu").val()}&disk=${$("#newdisk").val()}&memory=${$("#newmemory").val()}`;
http.open('POST', url, true);
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
var resp = JSON.parse(http.responseText)
if(resp.status === "OK"){
alert("Server successfully updated.")
$.getJSON('https://my.idley.gg/api/getUserServers?access_token='+authToken, function(data) {
userData = data;
if(data.error === undefined){
loadServerManagePage(server_id)
} else {
if(data.error === "invalid_auth"){
alert("You have to login to the app again.")
}
}
});
} else {
alert(resp.error)
}
}
}
http.send(params);
}