-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker.html
378 lines (322 loc) · 15.2 KB
/
docker.html
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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Docker Manager</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
<style>
.loader {
border: 4px solid #f3f3f3;
border-radius: 50%;
border-top: 4px solid #3498db;
width: 30px;
height: 30px;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
@-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</head>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.15/dist/tailwind.min.css" rel="stylesheet">
<style>
nav {
width: 100%;
padding: 10px 0;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
nav ul {
list-style: none;
padding: 0;
margin: 0;
display: flex;
justify-content: left;
}
nav ul li {
margin: 0 15px;
}
nav ul li a {
color: rgb(255, 255, 255);
text-decoration: none;
font-size: 18px;
transition: color 0.3s ease;
}
nav ul li a:hover {
color: #d0d0d0;
}
</style>
</head>
<nav>
<ul>
<li><a href="index.html">Retun To Home</a></li>
</ul>
</nav>
<body class="bg-black text-blue-500 font-mono">
<header class="bg-gray-900 text-blue text-center py-6 border-b border-gray-700">
<h1 class="text-4xl font-bold">Docker Manager</h1>
</header>
<main class="container mx-auto mt-10 px-4">
<!-- Docker Images Section -->
<section class="bg-gray-800 shadow-lg rounded-lg p-8 mb-10">
<h2 class="text-3xl font-semibold mb-6">Pulled Images</h2>
<div class="flex flex-col md:flex-row items-center md:justify-between mb-6 space-y-4 md:space-y-0">
<input type="text" id="imageName" class="border border-gray-600 bg-gray-700 p-3 rounded w-full md:w-auto text-green-500 placeholder-gray-500" placeholder="Enter Image Name">
<div class="flex space-x-4">
<button id="pullImage" onclick="PullImage()" class="bg-green-600 text-white p-3 rounded hover:bg-green-700">Pull Image</button>
<button id="getAllImages" onclick="GetAllImages()" class="bg-gray-700 text-white p-3 rounded hover:bg-gray-600">Get All Images</button>
<button id="showRunningContainers" onclick="getAllRunningContainers()" class="bg-gray-700 text-white p-3 rounded hover:bg-gray-600">Show Running Containers</button>
<button id="showAllContainers" onclick="getAllContainers()" class="bg-gray-700 text-white p-3 rounded hover:bg-gray-600">Show All Containers</button>
<button id="liveUpdateBtn" onclick="toggleLiveUpdate()" class="bg-red-500 text-white p-3 rounded hover:bg-red-600">Live Update</button>
</div>
</div>
<div id="loading" class="loader mx-auto" style="display: none;"></div>
<div id="getOutput" class="border border-gray-600 p-4 rounded h-64 overflow-auto bg-gray-900 text-white"></div>
</section>
<section class="mt-10">
<div class="bg-gray-800 shadow-lg rounded-lg p-8 mb-10">
<h2 class="text-2xl font-semibold mb-6">Inspect Container</h2>
<input type="text" id="inspectContainer" class="border border-gray-600 bg-gray-700 p-3 rounded w-full mb-4 text-green-500 placeholder-gray-500" placeholder="Enter Container ID">
<button id="inspectContainerBtn" onclick="InspectContainer()" class="bg-blue-600 text-white p-3 rounded w-60 hover:bg-blue-700">Inspect Container</button>
<div id="inspectOutput" class="border border-gray-600 p-4 rounded mt-4 h-32 overflow-auto bg-gray-900 text-white"></div>
</div>
</section>
<!-- Container Management Section -->
<section class="grid grid-cols-1 md:grid-cols-3 gap-10">
<div class="bg-gray-800 shadow-lg rounded-lg p-8">
<h2 class="text-2xl font-semibold mb-6">Launch a Container</h2>
<input type="text" id="launchAnContainer" class="border border-gray-600 bg-gray-700 p-3 rounded w-full mb-4 text-green-500 placeholder-gray-500" placeholder="Enter Container Name">
<button id="launchContainer" onclick="launchAnContainer()" class="bg-green-600 text-white p-3 rounded w-60 hover:bg-green-700">Launch a Container</button>
</div>
<div class="bg-gray-800 shadow-lg rounded-lg p-8 ">
<h2 class="text-2xl font-semibold mb-6">Start Container</h2>
<input type="text" id="containerNameStart" class="border border-gray-600 bg-gray-700 p-3 rounded w-full mb-4 text-green-500 placeholder-gray-500" placeholder="Enter Container Name">
<button id="startContainer" onclick="StartContainer()" class="bg-green-600 text-white p-3 rounded w-60 hover:bg-green-700">Start Container</button>
</div>
<div class="bg-gray-800 shadow-lg rounded-lg p-8 ">
<h2 class="text-2xl font-semibold mb-6">Stop Container</h2>
<input type="text" id="containerNameStop" class="border border-gray-600 bg-gray-700 p-3 rounded w-full mb-4 text-green-500 placeholder-gray-500" placeholder="Enter Container Name">
<button id="stopContainer" onclick="StopContainer()" class="bg-red-600 text-white p-3 rounded w-60 hover:bg-red-700">Stop Container</button>
</div>
<div class="bg-gray-800 shadow-lg rounded-lg p-8 mb-10">
<h2 class="text-2xl font-semibold mb-6">Volume List</h2>
<button id="dockervolume" onclick="dockervolume()" class="bg-green-600 text-white p-3 rounded w-60 hover:bg-green-700">Docker Volume</button>
</div>
<div></div>
<div class="bg-gray-800 shadow-lg rounded-lg p-8 mb-10">
<h2 class="text-2xl font-semibold mb-6">Network</h2>
<button id="startContainer" onclick="dockernetwork()" class="bg-green-600 text-white p-3 rounded w-60 hover:bg-green-700">Docker Network</button>
</div>
</section>
</main>
<script>
// Variable to store live update interval
let liveUpdateInterval;
// Function to start or stop live update
function toggleLiveUpdate() {
if (liveUpdateInterval) {
clearInterval(liveUpdateInterval);
liveUpdateInterval = null;
document.getElementById('liveUpdateBtn').textContent = 'Live Update';
} else {
liveUpdateInterval = setInterval(getAllRunningContainers, 5000); // Fetch every 5 seconds
document.getElementById('liveUpdateBtn').textContent = 'Stop Update';
}
}
// Function to show loader
function showLoader() {
document.getElementById("loading").style.display = "block";
}
// Function to hide loader
function hideLoader() {
document.getElementById("loading").style.display = "none";
}
// Function to fetch all Docker images
function GetAllImages() {
showLoader();
const url = "/cgi-bin/docker.py?cmd=docker%20images";
const xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
hideLoader();
if (xhr.status == 200) {
document.getElementById("getOutput").innerHTML = xhr.responseText;
} else {
console.log(xhr.response);
document.getElementById("getOutput").innerHTML = "Something went wrong";
}
}
};
xhr.send();
}
// Function to fetch all running Docker containers
function getAllRunningContainers() {
showLoader();
const url = "/cgi-bin/docker.py?cmd=docker%20ps";
const xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
hideLoader();
if (xhr.status == 200) {
document.getElementById("getOutput").innerHTML = xhr.responseText;
} else {
console.log(xhr.response);
document.getElementById("getOutput").innerHTML = "Something went wrong";
}
}
};
xhr.send();
}
// Function to fetch all Docker containers
function getAllContainers() {
showLoader();
const url = "/cgi-bin/docker.py?cmd=docker%20ps%20-a";
const xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
hideLoader();
if (xhr.status == 200) {
document.getElementById("getOutput").innerHTML = xhr.responseText;
} else {
console.log(xhr.response);
document.getElementById("getOutput").innerHTML = "Something went wrong";
}
}
};
xhr.send();
}
// Function to launch a Docker container
function launchAnContainer() {
showLoader();
const containerName = document.getElementById("launchAnContainer").value;
const url = `/cgi-bin/docker.py?cmd=docker%20run%20-dit%20${containerName}`;
const xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
hideLoader();
if (xhr.status == 200) {
document.getElementById("getOutput").innerHTML = xhr.responseText;
} else {
console.log(xhr.response);
document.getElementById("getOutput").innerHTML = "Something went wrong";
}
}
};
xhr.send();
}
// Function to start a Docker container
function StartContainer() {
showLoader();
const containerName = document.getElementById("containerNameStart").value;
const url = `/cgi-bin/docker.py?cmd=docker%20start%20${containerName}`;
const xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
hideLoader();
if (xhr.status == 200) {
document.getElementById("getOutput").innerHTML = xhr.responseText;
} else {
console.log(xhr.response);
document.getElementById("getOutput").innerHTML = "Something went wrong";
}
}
};
xhr.send();
}
//--------------------------------------------------------------------------------------------
function dockervolume() {
showLoader();
const containerName = document.getElementById("containerNameStart").value;
const url = `/cgi-bin/docker.py?cmd=docker%20volume%20ls`;
const xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
hideLoader();
if (xhr.status == 200) {
document.getElementById("getOutput").innerHTML = xhr.responseText;
} else {
console.log(xhr.response);
document.getElementById("getOutput").innerHTML = "Something went wrong";
}
}
};
xhr.send();
}
function dockernetwork() {
showLoader();
const containerName = document.getElementById("containerNameStart").value;
const url = `/cgi-bin/docker.py?cmd=docker%20network%20ls`;
const xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
hideLoader();
if (xhr.status == 200) {
document.getElementById("getOutput").innerHTML = xhr.responseText;
} else {
console.log(xhr.response);
document.getElementById("getOutput").innerHTML = "Something went wrong";
}
}
};
xhr.send();
}
//--------------------------------------------------------------------------------
// Function to stop a Docker container
function StopContainer() {
showLoader();
const containerName = document.getElementById("containerNameStop").value;
const url = `/cgi-bin/docker.py?cmd=docker%20stop%20${containerName}`;
const xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
hideLoader();
if (xhr.status == 200) {
document.getElementById("getOutput").innerHTML = xhr.responseText;
} else {
console.log(xhr.response);
document.getElementById("getOutput").innerHTML = "Something went wrong";
}
}
};
xhr.send();
}
function InspectContainer() {
const containerID = document.getElementById("inspectContainer").value.trim();
if (!containerID) {
alert("Please enter a container ID.");
return;
}
showLoader();
const url = `/cgi-bin/docker_handler.py?cmd=inspect&id=${containerID}`;
const xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
hideLoader();
if (xhr.status == 200) {
document.getElementById("inspectOutput").innerHTML = xhr.responseText;
} else {
document.getElementById("inspectOutput").innerHTML = "Error inspecting container.";
}
}
};
xhr.send();
}
// Initial fetch of running containers when the page loads
getAllRunningContainers();
</script>
</body>
</html>