-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanel.cgi
executable file
·99 lines (90 loc) · 2.71 KB
/
panel.cgi
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
#! /usr/bin/env python3
import os
N_SERVERS = 5
FORM_METHOD = 'GET'
FORM_ACTION = 'console.cgi'
TEST_CASE_DIR = 'test_case'
try:
test_cases = sorted(os.listdir(TEST_CASE_DIR))
except:
test_cases = []
test_case_menu = ''.join([f'<option value="{test_case}">{test_case}</option>' for test_case in test_cases])
DOMAIN = 'cs.nctu.edu.tw'
hosts = [f'nplinux{i + 1}' for i in range(12)]
host_menu = ''.join([f'<option value="{host}.{DOMAIN}">{host}</option>' for host in hosts])
print('Content-type: text/html', end='\r\n\r\n')
print('''
<!DOCTYPE html>
<html lang="en">
<head>
<title>NP Project 3 Panel</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2"
crossorigin="anonymous"
/>
<link
href="https://fonts.googleapis.com/css?family=Source+Code+Pro"
rel="stylesheet"
/>
<link
rel="icon"
type="image/png"
href="https://cdn4.iconfinder.com/data/icons/iconsimple-setting-time/512/dashboard-512.png"
/>
<style>
* {
font-family: 'Source Code Pro', monospace;
}
</style>
</head>
<body class="bg-secondary pt-5">''', end='')
print(f'''
<form action="{FORM_ACTION}" method="{FORM_METHOD}">
<table class="table mx-auto bg-light" style="width: inherit">
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">Host</th>
<th scope="col">Port</th>
<th scope="col">Input File</th>
</tr>
</thead>
<tbody>''', end='')
for i in range(N_SERVERS):
print(f'''
<tr>
<th scope="row" class="align-middle">Session {i + 1}</th>
<td>
<div class="input-group">
<select name="h{i}" class="custom-select">
<option></option>{host_menu}
</select>
<div class="input-group-append">
<span class="input-group-text">.cs.nctu.edu.tw</span>
</div>
</div>
</td>
<td>
<input name="p{i}" type="text" class="form-control" size="5" />
</td>
<td>
<select name="f{i}" class="custom-select">
<option></option>
{test_case_menu}
</select>
</td>
</tr>''', end='')
print('''
<tr>
<td colspan="3"></td>
<td>
<button type="submit" class="btn btn-info btn-block">Run</button>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>''', end='')