-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
index.cgi
executable file
·73 lines (55 loc) · 2.03 KB
/
index.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
#!/bin/bash
print_user_table()
{
# name,begin,end,status
# ariya,Jul 21 11:15:44 2020 GMT,Jul 6 11:15:44 2023 GMT,VALID
echo '<form method="post"><table>'
echo '<tr><th colspan=5>Existing users</th></tr>
<tr><th>Username</th><th>Valid from</th><th>Valid to</th><th>Status</th><th>Config</th></tr>'
ovpn_listclients | tail -n +2 | while IFS=, read -r name valid_from valid_to status; do
echo "<tr><td>$name</td><td>$valid_from</td><td>$valid_to</td><td>$status</td>
<td><a href=\"user_config.cgi?username=$name\">DOWNLOAD_CONFIG</a></td>
</tr>"
done
echo '</table>
<br/><br/>
<div id="popup">
<table
<tr><th colspan=2>User management</th></tr>
<tr><td>Action</td>
<td><select id="action" name="action">
<option value="add">add</option>
<option value="del">delete</option>
<option value="renew">renew</option>
</select></td>
</tr>
<tr><td>Username</td>
<td><input type="text" id="username" name="username"/></td>
</tr>
<tr><td>CA passphrase*</td>
<td><input type="password" id="capassphrase" name="capassphrase"/></td>
</tr>
<tr><td colspan=2><button type="submit" onclick="done()">Do it!</button></td></tr>
</table>
</div>
<div>* Global passphrase for the user management, can be found in keepassxc pwd db</div>
</form>'
}
MY_PATH=$(readlink -f "$BASH_SOURCE")
MYDIR=$(dirname "$MY_PATH")
. "$MYDIR/defs"
read -t 5 POST_STRING
action=$(parse_post_arg "action")
username=$(parse_post_arg "username")
capassphrase=$(parse_post_arg "capassphrase")
export EASYRSA_PASSIN="pass:$capassphrase"
export EASYRSA_BATCH=1
case "$action" in
del) echo "$capassphrase" | ovpn_revokeclient "$username" remove 1>&2 && message="<h2>User $username removed</h2>";;
add) echo "$capassphrase" | easyrsa build-client-full "$username" nopass 1>&2 && message="<h2>Succesfully created user $username<h2>";;
renew) echo "$capassphrase" | easyrsa renew "$username" 1>&2 && message="<h2>Certificate of user $username renewed</h2>";;
esac
echo "$HEAD"
print_user_table
echo "$message"
echo "$END"