|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +sysctl -w net.ipv4.conf.all.rp_filter=2 |
| 4 | + |
| 5 | +iptables --table nat --append POSTROUTING --jump MASQUERADE |
| 6 | +echo 1 > /proc/sys/net/ipv4/ip_forward |
| 7 | +for each in /proc/sys/net/ipv4/conf/* |
| 8 | +do |
| 9 | + echo 0 > $each/accept_redirects |
| 10 | + echo 0 > $each/send_redirects |
| 11 | +done |
| 12 | + |
| 13 | +if [ "$VPN_PASSWORD" = "password" ] || [ "$VPN_PASSWORD" = "" ]; then |
| 14 | + # Generate a random password |
| 15 | + P1=`cat /dev/urandom | tr -cd abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789 | head -c 3` |
| 16 | + P2=`cat /dev/urandom | tr -cd abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789 | head -c 3` |
| 17 | + P3=`cat /dev/urandom | tr -cd abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789 | head -c 3` |
| 18 | + VPN_PASSWORD="$P1$P2$P3" |
| 19 | + echo "No VPN_PASSWORD set! Generated a random password: $VPN_PASSWORD" |
| 20 | +fi |
| 21 | + |
| 22 | +if [ "$VPN_PSK" = "password" ] || [ "$VPN_PSK" = "" ]; then |
| 23 | + # Generate a random password |
| 24 | + P1=`cat /dev/urandom | tr -cd abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789 | head -c 3` |
| 25 | + P2=`cat /dev/urandom | tr -cd abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789 | head -c 3` |
| 26 | + P3=`cat /dev/urandom | tr -cd abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789 | head -c 3` |
| 27 | + VPN_PSK="$P1$P2$P3" |
| 28 | + echo "No VPN_PSK set! Generated a random PSK key: $VPN_PSK" |
| 29 | +fi |
| 30 | + |
| 31 | +cat > /etc/ipsec.secrets <<EOF |
| 32 | +# This file holds shared secrets or RSA private keys for authentication. |
| 33 | +# RSA private key for this host, authenticating it to any other host |
| 34 | +# which knows the public part. Suitable public keys, for ipsec.conf, DNS, |
| 35 | +# or configuration of other implementations, can be extracted conveniently |
| 36 | +# with "ipsec showhostkey". |
| 37 | +
|
| 38 | +: PSK "$VPN_PSK" |
| 39 | +
|
| 40 | +$VPN_USER : EAP "$VPN_PASSWORD" |
| 41 | +$VPN_USER : XAUTH "$VPN_PASSWORD" |
| 42 | +EOF |
| 43 | + |
| 44 | +if [ -f "/etc/ipsec.d/ipsec.secrets" ]; then |
| 45 | + echo "Overwriting standard /etc/ipsec.secrets with /etc/ipsec.d/ipsec.secrets" |
| 46 | + cp -f /etc/ipsec.d/ipsec.secrets /etc/ipsec.secrets |
| 47 | +fi |
| 48 | + |
| 49 | +if [ -f "/etc/ipsec.d/ipsec.conf" ]; then |
| 50 | + echo "Overwriting standard /etc/ipsec.conf with /etc/ipsec.d/ipsec.conf" |
| 51 | + cp -f /etc/ipsec.d/ipsec.conf /etc/ipsec.conf |
| 52 | +fi |
| 53 | + |
| 54 | +if [ -f "/conf/strongswan.conf" ]; then |
| 55 | + echo "Overwriting standard /etc/strongswan.conf with /etc/ipsec.d/strongswan.conf" |
| 56 | + cp -f /conf/strongswan.conf /etc/strongswan.conf |
| 57 | +fi |
| 58 | + |
| 59 | +ipsec start --nofork |
0 commit comments