Monthly Archives: September 2018

How to set up a private L2TP VPN server for your iOS or MacOS devices on DigitalOcean

Step 1. Sign up for DigitalOcean

You can get free $10 in credits if you sign up through this link: https://m.do.co/c/ecbd53848776

Step 2. Create a new droplet

Choose the newest Ubuntu distribution. (currently 18.04)
You can choose the smallest standard droplet which costs $5/mo. It is perfectly enough for your private VPN server. You don’t need to change anything else, although you can choose which region you would like to use.

Step 3. Log in to the droplet

You can use your favourite ssh client or you can open the console directly through the web interface.

Step 4. Install Docker on Ubuntu

If you succesfully logged in to your droplet you need to run the following commands to install docker and the vpn container on your system.

# install neccessary packages and docker's gpg key
apt-get update
apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
apt-key fingerprint 0EBFCD88
# add docker repository
add-apt-repository \
   "deb https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
apt-get update
# install docker community edition
apt-get install docker-ce

Step 5. Install the vpn server Docker container

docker pull hwdsl2/ipsec-vpn-server

Step 6. Set up your password in an env file

Replace the words between brackets with your desired passwords. You can check your passwords later if your run “docker logs vpn-server”

cat << EOF >.env
VPN_IPSEC_PSK=[your_ipsec_pre_shared_key]
VPN_USER=[your_vpn_username]
VPN_PASSWORD=[your_vpn_password]
EOF

Step 7. Load the af_key kernel module

modprobe af_key

Step 8. Start the Docker container

docker run \
    --name vpn-server \
    --env-file .env \
    --restart=always \
    -p 500:500/udp \
    -p 4500:4500/udp \
    -v /lib/modules:/lib/modules:ro \
    -d --privileged \
    hwdsl2/ipsec-vpn-server

Step 9. Set up your device

You need to set up a new L2TP type VPN connection on iOS or MacOS.

Your server will be your DigitalOcean droplet’s public IP which is visible on DigitalOcean’s dashboard.
The account will be what you set as VPN_USER
The secret will be the VPN_IPSEC_PSK’s value
The password is what is in the VPN_PASSWORD variable

Missing spaces in laravel mail subject

Laravel uses swiftmailer, which by default, encodes e-mail headers with Qp (quoted-printable) encoding. It works perfectly fine with most of e-mail clients, but there are some of them which seems that couldn’t implement correctly this encoding.

On these clients (for example, outlook connector for mdaemon or yahoo mail which i’m aware of), the space characters are missing in the subject.

In Qp encoding you can represent a space character with an underscore character. (see RFC 2047) Thats what these e-mail clients somehow did not implement correctly. Instead of showing a space character, they simply ignore the underscore character and print the subject without that part.

Fortunately, you can configure swiftmailer to use base64 encoding instead of Qp encoding in the headers, which is essentially solves the problem.

The best way to do it in Laravel, is to create a new MailServiceProvider class in the app folder and register it instead of laravel’s default MailServiceProvider. Then in your newly created MailServiceProvider class, you can simply override SwiftMailer’s default settings.

The MailServiceProvider class in the app folder:


It overrides the original MailServiceProvider’s registerSwiftMailer method, with a new one which configures SwiftMailer’s dependency injection to use the base64 header encoder class.
After this step, if you set the provider in the config/app.php file, your e-mail’s headers will be encoded as base64.

That will be solve this weird problem with these exotic e-mail clients. The space characters will be rendered correctly.