Skip to content

Commit 3c46052

Browse files
committed
added commands to add/del user and set/unset psk
1 parent 2385501 commit 3c46052

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

Dockerfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ ADD xl2tpd.conf /etc/xl2tpd/xl2tpd.conf
3939
ADD options.xl2tpd /etc/ppp/options.xl2tpd
4040

4141
ADD run.sh /run.sh
42+
ADD vpn_adduser /usr/local/bin/vpn_adduser
43+
ADD vpn_deluser /usr/local/bin/vpn_deluser
44+
ADD vpn_setpsk /usr/local/bin/vpn_setpsk
45+
ADD vpn_unsetpsk /usr/local/bin/vpn_unsetpsk
4246

4347
# The password is later on replaced with a random string
4448
ENV VPN_USER user
@@ -49,4 +53,4 @@ VOLUME ["/etc/ipsec.d"]
4953

5054
EXPOSE 4500/udp 500/udp 1701/udp
5155

52-
CMD ["/run.sh"]
56+
CMD ["/run.sh"]

vpn_adduser

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
3+
vpn_user=$1
4+
vpn_password=$2
5+
6+
if [ -z ${vpn_user} ] || [ -z ${vpn_password} ]; then
7+
echo "Usage: $0 user password"
8+
exit 1
9+
fi
10+
11+
vpn_deluser ${vpn_user}
12+
13+
cat >> /etc/ipsec.d/l2tp-secrets <<EOF
14+
"${vpn_user}" "*" "${vpn_password}" "*"
15+
EOF
16+
17+
cat >> /etc/ipsec.d/ipsec.secrets <<EOF
18+
${vpn_user} : EAP "${vpn_password}"
19+
${vpn_user} : XAUTH "${vpn_password}"
20+
EOF

vpn_deluser

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
vpn_user=$1
4+
5+
if [ -z ${vpn_user} ]; then
6+
echo "Usage: $0 user"
7+
exit 1
8+
fi
9+
10+
touch /etc/ipsec.d/ipsec.secrets
11+
touch /etc/ipsec.d/l2tp-secrets
12+
13+
sed -i "/${vpn_user} :/d" /etc/ipsec.d/ipsec.secrets
14+
sed -i "/\"${vpn_user}\" \"*\"/d" /etc/ipsec.d/l2tp-secrets

vpn_setpsk

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
psk=$1
4+
5+
if [ -z ${psk} ]; then
6+
echo "Usage: $0 psk"
7+
exit 1
8+
fi
9+
10+
vpn_unsetpsk
11+
12+
touch /etc/ipsec.d/ipsec.secrets
13+
cat >> /etc/ipsec.d/ipsec.secrets <<EOF
14+
: PSK "${psk}"
15+
EOF

vpn_unsetpsk

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
touch /etc/ipsec.d/ipsec.secrets
4+
sed '/: PSK/d' /etc/ipsec.d/ipsec.secrets

0 commit comments

Comments
 (0)