-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode-hub-docker
More file actions
431 lines (408 loc) · 34 KB
/
code-hub-docker
File metadata and controls
431 lines (408 loc) · 34 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
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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
set $server_files_location "/etc/code-server-hub";
set $server_service_name "cshubD";
set $server_service_name_full "Personal Container ";
set $py3 "/usr/bin/python3";
listen 2087 ssl;
listen [::]:2087 ssl;
ssl_certificate '/etc/code-server-hub/cert/ssl.pem';
ssl_certificate_key '/etc/code-server-hub/cert/ssl.key';
server_name default_server;
location /.well-known/Meteor.jpg {
content_by_lua_block {
if string.find(package.path, ngx.var.server_files_location .. "/util/?.lua",1,true) == nil then
package.path = package.path .. ";" .. ngx.var.server_files_location .. "/util/?.lua"
end
ngx.header.content_type = 'text/plain'
local url_tool = require 'url_tool'
local prefix = ngx.var.server_files_location .. '/util/anime_pic'
local python_get_img = io.popen(ngx.var.py3 .. ' "' .. ngx.var.server_files_location .. '/util/get_pic_anime.py" "' .. prefix .. '" 2>&1', "r")
local img_path = python_get_img:read("*all")
local img_name = url_tool.getname(img_path, prefix)
if img_name ~= nil then
ngx.header.location = "/.well-known/Meteor" .. img_name
ngx.status = 302
else
ngx.status = 500
ngx.say(img_path)
end
}
}
location /.well-known/Meteor {
alias ${server_files_location}/util/anime_pic;
}
# Managing requests to verify letsencrypt host
location /.well-known {
alias /var/www/html/.well-known;
}
client_max_body_size 0;
# Set this and add to line 140 if you set cockpit under some subpath . ex: 14: set $cockpit_addr "/cockpit";140:location ~ "/(cockpit).*" {
set $cockpit_addr "";
set $jupyter_addr "";
set $cockpit_addr_internal "https://127.0.0.1:9090";
set $jupyter_addr_internal "https://127.0.0.1:8000";
set $server_salt "1!2@3%=我是鹽";
set $server_sal2 "3%2@1!=我是糖";
# Managing literal requests to the front end
location / {
auth_pam "uU86bq7aCRrTz0bT5fYbhKAX";
auth_pam_service_name "login";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
set $server_auth_base64 "bm9sb2dpbjpOb3RTZXRZZXQ=";
set $server_sock_url "Not_Set_Yet";
rewrite_by_lua_block {
if string.find(package.path, ngx.var.server_files_location .. "/util/?.lua",1,true) == nil then
package.path = package.path .. ";" .. ngx.var.server_files_location .. "/util/?.lua"
end
if ngx.var.http_authorization and ngx.var.remote_user then
local md5 = require('md5')
local tmp = ngx.var.http_authorization
tmp = tmp:sub(tmp:find(' ')+1)
tmp = ngx.decode_base64(tmp)
remote_user = tmp:sub(0,tmp:find(":")-1)
remote_password = tmp:sub(tmp:find(':')+1)
server_auth = remote_user .. ":" .. md5.sumhexa(ngx.var.server_salt .. remote_password)
server_sock_name = remote_user .. "/" .. md5.sumhexa(ngx.var.server_sal2 .. remote_password)
server_sock_path = ngx.var.server_files_location .. "/sock/" .. ngx.var.server_service_name .. "/" .. server_sock_name .. ".sock"
server_sock_url = "http://unix:" .. server_sock_path
ngx.var.server_sock_url = server_sock_url
ngx.var.server_auth_base64 = ngx.encode_base64( server_auth )
fp = io.popen("python3 " .. ngx.var.server_files_location .. "/util/create_login.py","w")
fp:write(server_sock_path)
fp:close()
end
}
proxy_set_header Authorization "Basic ${server_auth_base64}";
proxy_pass $server_sock_url;
proxy_redirect http://$host/login https://$http_host/302-code-server.html;
# websocket headers
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
# if proxy_pass to workspace failed, spawn workspace
error_page 502 =404 /502-server_conn_err.html;
}
location = /502-server_conn_err.html {
auth_pam "uU86bq7aCRrTz0bT5fYbhKAX";
auth_pam_service_name "login";
return 404 '<!DOCTYPE html><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <style>*{font-family: Arial, "文泉驛正黑", "WenQuanYi Zen Hei", "儷黑 Pro", "LiHei Pro", "微軟正黑體", "Microsoft JhengHei", "標楷體", DFKai-SB, sans-serif;}.MainTitle{text-shadow: -1px -1px 0 #000,1px -1px 0 #000,-1px 1px 0 #000,1px 1px 0 #000,2px 2px 2px black;} body{background: url("/.well-known/Meteor.jpg") no-repeat fixed; background-position: center top; background-size: cover;}.buttonRed{display: inline-block; padding: 15px 25px; font-size: 24px; cursor: pointer; text-align: center; text-decoration: none; outline: none; color: #fff; background-color: #f22424; border: 10px; border-radius: 15px; box-shadow: 0 9px #999;}.buttonRed:hover{background-color: #d12626}.buttonRed:active{background-color: #d12626; box-shadow: 0 5px #666; transform: translateY(4px);}.button{display: inline-block; padding: 15px 25px; font-size: 24px; cursor: pointer; text-align: center; text-decoration: none; outline: none; color: #fff; background-color: #4CAF50; border: 10px; border-radius: 15px; box-shadow: 0 9px #999;}.button:hover{background-color: #3e8e41}.button:active{background-color: #3e8e41; box-shadow: 0 5px #666; transform: translateY(4px);}.buttonGray{display: inline-block; padding: 15px 25px; font-size: 24px; cursor: pointer; text-align: center; text-decoration: none; outline: none; color: #fff; background-color: #525252; border: 10px; border-radius: 15px; box-shadow: 0 9px #999;}.buttonGray:hover{background-color: #525252}</style> </head> <body><a href="https://github.com/HuJK/Code-Server-Hub/blob/master/util/sites/README.md"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://raw.githubusercontent.com/HuJK/Code-Server-Hub/refs/heads/master/util/sites/readme.png" alt="Usage Doc"></a> <center> <h1 style="color:white" class=MainTitle>${server_service_name_full}Control Panel</h1> </center> <center> <input type="button" class="button" value="Start Container" onclick="window.location.href=\'/200-server_spawn.html\'" style="width:200px;height:60px;font-size:20px;"> <input type="button" class="buttonRed" value="Factory Reset" onclick="window.location.href=\'/200-delete-confirm.html\'" style="width:200px;height:60px;font-size:20px;"> <input type="button" class="buttonRed" value="Log out" onclick="window.location.href=\'/200-logout.html\'" style="width:120px;height:60px;font-size:20px;"> </center> <hr style="visibility: hidden;"/> <center> <input type="button" class="buttonGray" value="VS code" style="width:120px;height:60px;font-size:20px;" onclick="alert(\'Your container aren\\\'t start yet.\')" > <input type="button" class="buttonGray" value="Jupyter" style="width:120px;height:60px;font-size:20px;" onclick="alert(\'Your container aren\\\'t start yet.\')" > </body></html>';
}
location = /200-server_spawn.html {
default_type 'text/html';
add_header "Content-Type" "text/html" always;
auth_pam "uU86bq7aCRrTz0bT5fYbhKAX";
auth_pam_service_name "login";
content_by_lua_block {
if string.find(package.path, ngx.var.server_files_location .. "/util/?.lua",1,true) == nil then
package.path = package.path .. ";" .. ngx.var.server_files_location .. "/util/?.lua"
end
local md5 = require 'md5'
if ngx.var.http_authorization then
local tmp = ngx.var.http_authorization
tmp = tmp:sub(tmp:find(' ')+1)
tmp = ngx.decode_base64(tmp)
remote_user = tmp:sub(0,tmp:find(":")-1)
remote_password = tmp:sub(tmp:find(':')+1)
server_auth_py = md5.sumhexa(ngx.var.server_salt .. remote_password)
server_sock_name = remote_user .. "/" .. md5.sumhexa(ngx.var.server_sal2 .. remote_password)
server_sock_path = ngx.var.server_files_location .. "/sock/" .. ngx.var.server_service_name .. "/" .. server_sock_name .. ".sock"
server_envs_path = ngx.var.server_files_location .. "/envs/" .. ngx.var.server_service_name .. "-" .. remote_user .. ".envs"
response = ngx.location.capture('/')
ngx.log(ngx.STDERR, "response.status=" .. tostring(response.status))
if response.status >= 400 then
local ngx_pipe = require "ngx.pipe"
local current_timestamp = os.date("!%Y-%m-%dT%H:%M:%SZ")
local fp = io.popen("python3 " .. ngx.var.server_files_location .. "/util/create_docker.py " .. remote_user .. " " .. server_sock_path .. " " .. server_envs_path .. " " .. server_auth_py .. " 2>&1","r")
local py_output = fp:read("*all")
fp:close()
ngx.say('<head><style>code {display: block; /* fixes a strange ie margin bug */font-family: Courier New;font-size: 11pt;overflow:auto;background: #f0f0f0 url(data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAASwCAYAAAAt7rCDAAAABHNCSVQICAgIfAhkiAAAAQJJREFUeJzt0kEKhDAMBdA4zFmbM+W0upqFOhXrDILwsimFR5pfMrXW5jhZr7PwRlxVX8//jNHrGhExjXzdu9c5IiIz+7iqVmB7Hwp4OMa2nhhwN/PRGEMBh3Zjt6KfpzPztxW9MSAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzB8HS+J9kUTvzEDMwAAAABJRU5ErkJggg==) left top repeat-y;border: 10px solid white;padding: 10px 10px 10px 21px;max-height:1000px;line-height: 1.2em;}</style></head>')
ngx.say('<body>')
ngx.say("<center><h1>Starting workspace</h1></center>")
ngx.say("<p>You can create " .. ngx.var.server_service_name_full .. " manully by this command: <br><code>python3 " .. ngx.var.server_files_location .. "/util/create_docker.py " .. remote_user .. " " .. server_sock_path .. " " .. server_envs_path .. " " .. server_auth_py .. "</code><br></p>")
ngx.say("<p>You can enter shell of " .. ngx.var.server_service_name_full .. " by this command: <br><code>docker exec -it docker-" .. remote_user .. " bash</code><br></p>")
ngx.say("<hr />")
fp_dlog = io.popen("docker logs docker-" .. remote_user .. " --since " .. current_timestamp,"r")
ngx.say("<br> ".. ngx.var.server_service_name_full .. " spawning logs from " .. current_timestamp .. " :<code id=log_content>" .. py_output:gsub("\n", "<br>") .. "</code><br>")
ngx.say('<script>var timestamp="' .. current_timestamp .. '";function update(){var http_check_ready=new XMLHttpRequest;var http_get_logs=new XMLHttpRequest;http_check_ready.onreadystatechange=function(){if(http_check_ready.readyState===4&&http_check_ready.status===0||http_check_ready.status<400&&http_check_ready.status>=200){window.location.replace("/200-panel.html")}};http_get_logs.onreadystatechange=function(){if(http_get_logs.readyState==XMLHttpRequest.DONE){log_content=http_get_logs.responseText;if(log_content.replace(/\\s/g,"").length>0){document.getElementById("log_content").innerHTML=log_content.replaceAll("\\n","<br>")}}};http_get_logs.open("GET","/200-server_logs.txt?current_timestamp="+timestamp,true);http_check_ready.open("GET","/",true);http_get_logs.send();http_check_ready.send()}window.onload=function(){update();setInterval((function(){update()}),1e3)};</script>')
ngx.say('</body>')
else
ngx.redirect("/")
end
else
ngx.say("Need auth info!")
end
}
}
location = /200-server_logs.txt {
default_type 'text/plain';
add_header "Content-Type" "text/plain" always;
auth_pam "uU86bq7aCRrTz0bT5fYbhKAX";
auth_pam_service_name "login";
content_by_lua_block {
if string.find(package.path, ngx.var.server_files_location .. "/util/?.lua",1,true) == nil then
package.path = package.path .. ";" .. ngx.var.server_files_location .. "/util/?.lua"
end
local md5 = require 'md5'
if ngx.var.http_authorization then
local tmp = ngx.var.http_authorization
tmp = tmp:sub(tmp:find(' ')+1)
tmp = ngx.decode_base64(tmp)
remote_user = tmp:sub(0,tmp:find(":")-1)
local args, err = ngx.req.get_uri_args()
local current_timestamp = args["current_timestamp"]
fp_dlog = io.popen("docker logs docker-" .. remote_user .. " --since " .. current_timestamp,"r")
local log_txt = fp_dlog:read("*all")
fp_dlog:close()
ngx.say(log_txt)
else
ngx.say("Need auth info!")
end
}
}
set $panelHTML '<!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <style> * { font-family: Arial, "文泉驛正黑", "WenQuanYi Zen Hei", "儷黑 Pro", "LiHei Pro", "微軟正黑體", "Microsoft JhengHei", "標楷體", DFKai-SB, sans-serif; } .MainTitle{text-shadow: -1px -1px 0 #000,1px -1px 0 #000,-1px 1px 0 #000,1px 1px 0 #000,2px 2px 2px black;} body {background: url("/.well-known/Meteor.jpg") no-repeat fixed;background-position: center top;background-size:cover;} .buttonRed { display: inline-block; padding: 15px 25px; font-size: 24px; cursor: pointer; text-align: center; text-decoration: none; outline: none; color: #fff; background-color: #f22424; border: 10px; border-radius: 15px; box-shadow: 0 9px #999; } .buttonRed:hover { background-color: #d12626 } .buttonRed:active { background-color: #d12626; box-shadow: 0 5px #666; transform: translateY(4px); } .button { display: inline-block; padding: 15px 25px; font-size: 24px; cursor: pointer; text-align: center; text-decoration: none; outline: none; color: #fff; background-color: #4CAF50; border: 10px; border-radius: 15px; box-shadow: 0 9px #999; } .button:hover { background-color: #3e8e41 } .button:active { background-color: #3e8e41; box-shadow: 0 5px #666; transform: translateY(4px); } .buttonGray { display: inline-block; padding: 15px 25px; font-size: 24px; cursor: pointer; text-align: center; text-decoration: none; outline: none; color: #fff; background-color: #525252; border: 10px; border-radius: 15px; box-shadow: 0 9px #999; } .buttonGray:hover { background-color: #525252 } </style></head><body><a href="https://github.com/HuJK/Code-Server-Hub/blob/master/util/sites/README.md"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://raw.githubusercontent.com/HuJK/Code-Server-Hub/refs/heads/master/util/sites/readme.png" alt="Usage Doc"></a> <center> <h1 style="color:white" class=MainTitle>${server_service_name_full} Control Panel</h1></center> <center> <input type="button" class="buttonRed" value="Stop Container" onclick="window.location.href=\'/200-shutdown.html\'" style="width:200px;height:60px;font-size:20px;"> <input type="button" class="buttonGray" value="Factory Reset" onclick="alert(\'You can\\\'t reset your container while it\\\'s running.\\nPlease stop it first.\')" style="width:200px;height:60px;font-size:20px;" > <input type="button" class="buttonRed" value="Log out" onclick="window.location.href=\'/200-logout.html\'" style="width:120px;height:60px;font-size:20px;"> </center> <hr style="visibility: hidden;" /> <center> <input type="button" class="button" value="VS code" onclick="window.open(\'/\')" style="width:120px;height:60px;font-size:20px;"> <input type="button" class="button" value="Jupyter" onclick="window.open(\'/jupyterlab/\')" style="width:120px;height:60px;font-size:20px;"> </center> <hr style="visibility: hidden;" /></body></html>';
location = /200-panel.html {
auth_pam "uU86bq7aCRrTz0bT5fYbhKAX";
auth_pam_service_name "login";
content_by_lua_block {
response = ngx.location.capture('/')
if response.status >= 400 then
ngx.redirect("/502-server_conn_err.html")
else
ngx.say(ngx.var.panelHTML)
end
}
}
location = /200-delete.html {
auth_pam "Secure Area";
auth_pam_service_name "delete";
access_by_lua_block {
if string.find(package.path, ngx.var.server_files_location .. "/util/?.lua",1,true) == nil then
package.path = package.path .. ";" .. ngx.var.server_files_location .. "/util/?.lua"
end
local md5 = require 'md5'
if ngx.var.http_authorization and ngx.var.remote_user then
local tmp = ngx.var.http_authorization
tmp = tmp:sub(tmp:find(' ')+1)
tmp = ngx.decode_base64(tmp)
remote_user = tmp:sub(0,tmp:find(":")-1)
remote_password = tmp:sub(tmp:find(':')+1)
server_auth_py = md5.sumhexa(ngx.var.server_salt .. remote_password)
server_sock_name = remote_user .. "/" .. md5.sumhexa(ngx.var.server_sal2 .. remote_password)
server_sock_path = ngx.var.server_files_location .. "/sock/" .. ngx.var.server_service_name .. "/" .. server_sock_name .. ".sock"
server_envs_path = ngx.var.server_files_location .. "/envs/" .. ngx.var.server_service_name .. "-" .. remote_user .. ".envs"
ngx.req.read_body()
local args = ngx.req.get_post_args()
if args["username"] == remote_user and args["password"] == remote_password then
fp = io.popen("python3 " .. ngx.var.server_files_location .. "/util/delete_docker.py " .. remote_user .. " " .. server_sock_path .. " " .. server_envs_path ,"w")
fp:write(remote_password)
fp:close()
ngx.say('Success')
else
ngx.status = 403
ngx.say('Wrong credential')
end
end
}
}
location = /200-delete-confirm.html {
auth_pam "Secure Area";
auth_pam_service_name "delete";
access_by_lua_block {
if string.find(package.path, ngx.var.server_files_location .. "/util/?.lua",1,true) == nil then
package.path = package.path .. ";" .. ngx.var.server_files_location .. "/util/?.lua"
end
local md5 = require 'md5'
if ngx.var.http_authorization and ngx.var.remote_user then
local tmp = ngx.var.http_authorization
tmp = tmp:sub(tmp:find(' ')+1)
tmp = ngx.decode_base64(tmp)
remote_user = tmp:sub(0,tmp:find(":")-1)
remote_password = tmp:sub(tmp:find(':')+1)
server_auth_py = md5.sumhexa(ngx.var.server_salt .. remote_password)
ngx_say = '<!DOCTYPE html><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> '
ngx_say = ngx_say .. ' <style>*{font-family: Arial, "文泉驛正黑", "WenQuanYi Zen Hei", "儷黑 Pro", "LiHei Pro", "微軟正黑體", "Microsoft JhengHei", "標楷體", DFKai-SB, sans-serif;} '
ngx_say = ngx_say .. '.MainTitle{text-shadow: -1px -1px 0 #000,1px -1px 0 #000,-1px 1px 0 #000,1px 1px 0 #000,2px 2px 2px black;} body{background: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url("/.well-known/Meteor.jpg") no-repeat fixed; background-position: center top; background-size: cover;}.buttonRed{display: inline-block; padding: 15px 25px; font-size: 24px; cursor: pointer; text-align: center; text-decoration: none; outline: none; color: #fff; background-color: #f22424; border: 10px; border-radius: 15px; box-shadow: 0 9px #999;}.button{display: inline-block; padding: 15px 25px; font-size: 24px; cursor: pointer; text-align: center; text-decoration: none; outline: none; color: #fff; background-color: #4CAF50; border: 10px; border-radius: 15px; box-shadow: 0 9px #999;}.buttonGray{display: inline-block; padding: 15px 25px; font-size: 24px; cursor: pointer; text-align: center; text-decoration: none; outline: none; color: #fff; background-color: #525252; border: 10px; border-radius: 15px; box-shadow: 0 9px #999;}.buttonGray:hover{background-color: #525252} .alert * {-webkit-tap-highlight-color: transparent;-webkit-touch-callout: none;-ms-touch-action: none;}.alert *:focus {outline: 0}.alert {position: fixed;top: 0%;left: 50%;margin-left: -350px;margin-top: 80px;width: 700px;text-align: center;font-family: -apple-system, SF UI Text, Helvetica Neue, Helvetica, Arial, sans-serif;font-size: 18px;line-height: 1.4;border-radius: 13px;overflow: hidden;z-index: 9999999999999999999999998;background-color: rgba(255, 255, 255, 0.9);}.alert .inner {padding: 15px;}.alert .title {font-weight: 500;font-size: 30px;color: red;}.alert .text {margin-top: 5px;font-size: 20px;}.alert .btnline{display: flex;justify-content: space-around;}.alert .boderline{border-top: #c4c4c4 1px solid ;}.alert .iosbutton {position: relative;height: 55px;line-height: 55px;font-size: 24px;color: #007aff;border-radius: 0 0 13px 13px;overflow: hidden;cursor: pointer;}.alert .iosbutton:after {content: ""position: absolute;left: 0;top: 0;height: 1px;width: 100%;display: block;z-index: 9999999999999999999999999;}'
ngx_say = ngx_say .. 'input.dialog-input[type] { box-sizing: border-box; margin: 0; margin-top: 15px; border-radius: 4px; -webkit-appearance: none; -moz-appearance: none; appearance: none; width: 100%; display: block; font-family: inherit; box-shadow: none; font-size: 14px; height: 32px; background-color: #fff; border: 1px solid rgba(0,0,0,0.3)}.dialog-input-double input.dialog-input { border-radius: var(--f7-dialog-input-border-radius) var(--f7-dialog-input-border-radius) 0 0}'
ngx_say = ngx_say .. '.dialog-input-double+.dialog-input-double input.dialog-input { border-radius: 0 0 4px 4px} </style> </head> <body><a href="https://github.com/HuJK/Code-Server-Hub/blob/master/util/sites/README.md"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://raw.githubusercontent.com/HuJK/Code-Server-Hub/refs/heads/master/util/sites/readme.png" alt="Usage Doc"></a> <div><div class="alert"> <div class="inner"> <div class="title">Warning</div> <div class="text"> Are you sure you want to <span style="color:CRIMSON">factory reset</span> your container?<br>All data will be destroyed except <span style="color:green">/home/' .. remote_user .. ' /data</span>.<br>Input your credentials to confirm. </div> <div><input type="text" name="dialog-username" placeholder="Username" class="dialog-input" id="usernm"> <input id="pwdd" type="password" name="dialog-password" placeholder="Password" class="dialog-input"> </div> </div><div class="boderline"></div> <div class="btnline"> <div class="iosbutton" onclick="window.location.href=\'/\'">Cancel</div> <div class="iosbutton" onclick="var xhr = new XMLHttpRequest(); xhr.open(\'POST\', \'/200-delete.html\',true ) ; xhr.onload = function() { if (xhr.status === 200) {alert (xhr.responseText);window.location.href=\'/\'} else {alert (xhr.responseText)} }; xhr.send([encodeURIComponent(\'username\')+\'=\'+encodeURIComponent(document.getElementById(\'usernm\').value),encodeURIComponent(\'password\')+\'=\'+encodeURIComponent( document.getElementById(\'pwdd\').value)].join(\'&\'))">OK</div> </div></div></div> <center> <h1 style="color:white" class=MainTitle>' .. ngx.var.server_service_name_full .. 'Control Panel</h1> </center> <center> <input type="button" class="button" value="Start Container" style="width:200px;height:60px;font-size:20px;" disabled> <input type="button" class="buttonRed" value="Factory Reset" style="width:200px;height:60px;font-size:20px;" disabled> <input type="button" class="buttonRed" value="Log out" style="width:120px;height:60px;font-size:20px;" disabled> </center> <hr style="visibility: hidden;"/> <center> <input type="button" class="buttonGray" value="VS code" style="width:120px;height:60px;font-size:20px;" disabled> <input type="button" class="buttonGray" value="Jupyter" style="width:120px;height:60px;font-size:20px;" disabled> </body></html>'
ngx.say(ngx_say)
end
}
}
location = /200-shutdown.html {
auth_pam "uU86bq7aCRrTz0bT5fYbhKAX";
auth_pam_service_name "login";
access_by_lua_block {
if string.find(package.path, ngx.var.server_files_location .. "/util/?.lua",1,true) == nil then
package.path = package.path .. ";" .. ngx.var.server_files_location .. "/util/?.lua"
end
local md5 = require 'md5'
if ngx.var.http_authorization and ngx.var.remote_user then
local tmp = ngx.var.http_authorization
tmp = tmp:sub(tmp:find(' ')+1)
tmp = ngx.decode_base64(tmp)
remote_user = tmp:sub(0,tmp:find(":")-1)
remote_password = tmp:sub(tmp:find(':')+1)
server_auth_py = md5.sumhexa(ngx.var.server_salt .. remote_password)
server_sock_name = remote_user .. "/" .. md5.sumhexa(ngx.var.server_sal2 .. remote_password)
server_sock_path = ngx.var.server_files_location .. "/sock/" .. ngx.var.server_service_name .. "/" .. server_sock_name .. ".sock"
server_envs_path = ngx.var.server_files_location .. "/envs/" .. ngx.var.server_service_name .. "-" .. remote_user .. ".envs"
fp = io.popen("python3 " .. ngx.var.server_files_location .. "/util/close_docker.py " .. remote_user .. " " .. server_sock_path .. " " .. server_envs_path ,"w")
fp:write(remote_password)
fp:close()
ngx.say('<!DOCTYPE html><html><body><script>setTimeout(function(){document.homepage.submit();},100);</script><p>Success.<br/>Redirect to / after 0.1 seconds.</p><form name="homepage" action="' .. "/" .. '" method="get"></form></body></html>')
end
}
}
location = /200-logout.html {
add_header Set-Cookie "cockpit=disabled; Path=/; Secure; HttpOnly" ;
return 200 '<!DOCTYPE html><html><body><script>setTimeout(function(){document.homepage.submit();},100);</script><p>Logout. Back to homepage after 0.1 seconds.</p><form name="homepage" action="/401-logout.html" method="get"></form></body></html>';
}
location ~ "^/(cockpit|system|storage|network|docker|users|apps|updates|dashboard).*" {
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass $cockpit_addr_internal;
proxy_set_header Host $http_host ;
gzip off;
}
location = /302-cockpit.html {
add_header "Content-Type" "text/html" always;
auth_pam "uU86bq7aCRrTz0bT5fYbhKAX";
auth_pam_service_name "login";
set $setcookie00 "nil";
set $SetCookie11 "nil";
access_by_lua_block {
local tmp = ngx.var.http_authorization
tmp = tmp:sub(tmp:find(' ')+1)
tmp = ngx.decode_base64(tmp)
remote_user = tmp:sub(0,tmp:find(":")-1)
remote_password = tmp:sub(tmp:find(':')+1)
if string.find(package.path, ngx.var.server_files_location .. "/util/?.lua",1,true) == nil then
package.path = package.path .. ";" .. ngx.var.server_files_location .. "/util/?.lua"
end
local url_tool = require('url_tool')
ngx.req.set_header("Content-Type", "application/x-www-form-urlencoded")
response = ngx.location.capture(ngx.var.cockpit_addr .. '/cockpit/login')
if response.status < 400 then
ngx.var.setcookie00 = url_tool.serialize(response.header["set-cookie"])
ngx.var.SetCookie11 = url_tool.serialize(response.header["Set-Cookie"])
end
}
header_filter_by_lua_block {
if string.find(package.path, ngx.var.server_files_location .. "/util/?.lua",1,true) == nil then
package.path = package.path .. ";" .. ngx.var.server_files_location .. "/util/?.lua"
end
local url_tool = require('url_tool')
if ngx.var.setcookie00 ~= "nil" then
ngx.header["set-cookie"] = url_tool.unserialize(ngx.var.setcookie00)
else
ngx.header["Set-Cookie"] = url_tool.unserialize(ngx.var.SetCookie11)
end
}
content_by_lua_block {
if ngx.var.setcookie00 ~= "nil" or ngx.var.setcookie11 ~= "nil" then
ngx.say('<!DOCTYPE html><html><body><script>setTimeout(function(){document.homepage.submit();},100);</script><p>Retrieve cookie success.<br/>Redirect to ' .. ngx.var.cockpit_addr .. "/system" .. ' after 0.1 seconds.</p><form name="homepage" action="' .. ngx.var.cockpit_addr .. "/system" .. '" method="get"></form></body></html>')
else
ngx.status = 404
ngx.say("Unable to connect to " .. ngx.var.cockpit_addr_internal)
end
}
}
location = /302-account.html {
add_header "Content-Type" "text/html" always;
auth_pam "uU86bq7aCRrTz0bT5fYbhKAX";
auth_pam_service_name "login";
set $setcookie00 "nil";
set $SetCookie11 "nil";
access_by_lua_block {
local tmp = ngx.var.http_authorization
tmp = tmp:sub(tmp:find(' ')+1)
tmp = ngx.decode_base64(tmp)
remote_user = tmp:sub(0,tmp:find(":")-1)
remote_password = tmp:sub(tmp:find(':')+1)
if string.find(package.path, ngx.var.server_files_location .. "/util/?.lua",1,true) == nil then
package.path = package.path .. ";" .. ngx.var.server_files_location .. "/util/?.lua"
end
local url_tool = require('url_tool')
ngx.req.set_header("Content-Type", "application/x-www-form-urlencoded")
response = ngx.location.capture(ngx.var.cockpit_addr .. '/cockpit/login')
if response.status < 400 then
ngx.var.setcookie00 = url_tool.serialize(response.header["set-cookie"])
ngx.var.SetCookie11 = url_tool.serialize(response.header["Set-Cookie"])
end
}
header_filter_by_lua_block {
if string.find(package.path, ngx.var.server_files_location .. "/util/?.lua",1,true) == nil then
package.path = package.path .. ";" .. ngx.var.server_files_location .. "/util/?.lua"
end
local url_tool = require('url_tool')
if ngx.var.setcookie00 ~= "nil" then
ngx.header["set-cookie"] = url_tool.unserialize(ngx.var.setcookie00)
else
ngx.header["Set-Cookie"] = url_tool.unserialize(ngx.var.SetCookie11)
end
}
content_by_lua_block {
local tmp = ngx.var.http_authorization
tmp = tmp:sub(tmp:find(' ')+1)
tmp = ngx.decode_base64(tmp)
remote_user = tmp:sub(0,tmp:find(":")-1)
remote_password = tmp:sub(tmp:find(':')+1)
if ngx.var.setcookie00 ~= "nil" or ngx.var.setcookie11 ~= "nil" then
ngx.say('<!DOCTYPE html><html><body><script>setTimeout(function(){document.homepage.submit();},100);</script><p>Retrieve cookie success.<br/>Redirect to ' .. ngx.var.cockpit_addr .. "/users#/" .. remote_user .. ' after 0.1 seconds.</p><form name="homepage" action="' .. ngx.var.cockpit_addr .. "/users#/" .. remote_user .. '" method="get"></form></body></html>')
else
ngx.status = 404
ngx.say("Unable to connect to " .. ngx.var.cockpit_addr_internal)
end
}
}
location = /401-logout.html {
auth_pam "uU86bq7aCRrTz0bT5fYbhKAX";
auth_pam_service_name "login";
access_by_lua_block {
if string.find(package.path, ngx.var.server_files_location .. "/util/?.lua",1,true) == nil then
package.path = package.path .. ";" .. ngx.var.server_files_location .. "/util/?.lua"
end
if ngx.var.http_authorization and ngx.var.remote_user then
local md5 = require('md5')
local tmp = ngx.var.http_authorization
tmp = tmp:sub(tmp:find(' ')+1)
tmp = ngx.decode_base64(tmp)
remote_user = tmp:sub(0,tmp:find(":")-1)
remote_password = tmp:sub(tmp:find(':')+1)
server_sock_name = remote_user .. "/" .. md5.sumhexa(ngx.var.server_sal2 .. remote_password)
user_lgin_tokn_path = ngx.var.server_files_location .. "/sock/" .. ngx.var.server_service_name .. "/" .. server_sock_name .. ".login"
lginfile = io.open(user_lgin_tokn_path, "r")
if lginfile ~= nil then
login_status = "1"
lginfile:close()
os.remove(user_lgin_tokn_path)
else
login_status = "0"
end
if login_status == "0" then
ngx.redirect("/")
end
end
}
try_files DUMMY @return401;
error_page 401 =200 @return200;
}
location @test {
return 200 "testttt";
}
location @return401 {
set $www_auth_str 'Basic Realm=uU86bq7aCRrTz0bT5fYbhKAX';
add_header 'WWW-Authenticate' $www_auth_str always;
return 401 '<!DOCTYPE html><html><body><script>setTimeout(function(){document.homepage.submit();},100);</script><p>Logout. Back to homepage after 0.1 seconds.</p><form name="homepage" action="/" method="get"></form></body></html>';
}
location @return200 {
return 200 '<!DOCTYPE html><html><body><script>setTimeout(function(){document.homepage.submit();},100);</script><p>Logout. Back to homepage after 0.1 seconds.</p><form name="homepage" action="/" method="get"></form></body></html>';
}
}