GhostiFi — The server.create() function

Reilly Chase
Nov 19, 2018 · 3 min read


As promised in my initial blog post, I am continuing to publish the entire development process of GhostiFi, from concept, to sketch, to pseudocode, to actual code.

In this post (part 6), I will be sharing how I turned the server.create() pseudocode into actual Python:

8 “mini” functions

Rather than writing all the steps of server.create() into one function, I created 8 smaller, reusable chunks of code, and then ran them all within the server.create() function.

_create_vps() — Creates a Vultr VPS
— Gets Vultr VPS status for up to 500 seconds, waiting for it to finish installing before moving on
— Creates an A record at CloudFlare DNS
— Installs OpenVPN from GhostiFi’s public Github repo
— SFTPs into the VPS and copies the OVPN file output from the OpenVPN script to the GhostiFi webserver to be served from the user dashboard later
— Creates a VPS snapshot on Vultr, will use this later for rebuilds
— Gets the VPS root password and stores it for later, to be given to the user in the GhostiFi dashboard
_send_email(targets, msg_txt, subject)
— Sends a notification email when the VPS VPN has finished setting up

Making the OpenVPN install script

One of the more challenging parts of this function was figuring out how to automate the OpenVPN installation. I was able to find a popular OpenVPN installation Github repo here:

So I used that as a starting point.

The contributors had already optimized the security settings, so I left everything as they had recommended. I only modified the script to remove the need for user input, and change the default OpenVPN server port from 1194 to 443, in order to potentially help GhostiFi users get around some of the more restrictive firewalls out there.

When finished, I uploaded it to a GhostiFi public Github repo: New GhostiFi servers will pull the latest version from there when they are built.


Output of function building a new server
OVPN file copied from VPS back to GhostiFi webserver
Info stored back to the database after server is created
VPS VPN setup complete notification email

At this point, after a user purchases a GhostiFi subscription, the VPS will be built, OpenVPN installed, and info stored back to the database.

There is no user dashboard/frontend yet, and no way to rebuild or destroy servers. Lot of work to be done still, but this is a big milestone!

Closing thoughts

I hope this was helpful for anyone who is an aspiring programmer or entrepreneur to see my thought process in how I went about turning a sketched design of a user interface for my product idea into a step-by-step process that any programmer might be able to understand and turn into code.

If you have any feedback on how I could improve this design please let me know in the comments section!

If you want to know when I release another post about building GhostiFi, you can follow me on Twitter: @_rchase_ or Medium: Reilly Chase



Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store