GhostiFi — The complete MVP database design and pseudocode

Reilly Chase
Nov 11, 2018 · 8 min read
Image for post

Overview

Image for post

The DB Schema

Server Table

The Python Backend

server_check.py

for server in servers_to_build:
thread(server.create())

for server in servers_to_destroy:
thread(server.destroy())
for server in servers_to_rebuild:
thread(server.rebuild())
server_check.py# Custom Python class called server which I will create methods “create”, “destroy”, and "rebuild_now" for
server = server(server_name, username)
# Create a server object with a server_name (g0xxx.ghostifi.net for example, and customer’s username)

server.create()
# Create a record in the database for the server and set status to Installing, this way the PHP frontend will have something to show the user while the rest of this setup completes
# Create Vultr server in NYC (by default, user can migrate later)
# create DNS entry for server on CloudFlare
# install OpenVPN
# copy ovpn file back to a location on the ghostifi.net server
# modify SSH to allow root login with password
# create a snapshot of Vultr server (stored on Vultr) to use later for future rebuilds
# return root password to database, ovpn file name, server_name, server_ip, current_location, and set status to Running
server.destroy()
# Delete the server from Vultr
# delete the ovpn file
# delete the snapshot on Vultr
# delete the CloudFlare DNS record for the server
server.rebuild_now(rebuild_now_location)
# Update database record for this server, set status to Rebuilding, this way the PHP frontend will have something to show the user while this rebuild is in progress
# Update the bandwidth in database (bandwidth_this_month += bandwidth)
# Delete the current server from Vultr
# Create a new server from the snapshot of the old server, with the location of rebuild_now_location
# Update root password, server_ip, current_location, rebuild_now_status = 0, and set status to Running in database record for this server (server table)

rebuild_daily.py

rebuild_daily.py# Rebuilds all servers that are set to "rebuild_schedule = daily"# Follows the same process as server.rebuild_now() but uses rebuild_schedule_location instead of rebuild_now_location

rebuild_weekly.py

rebuild_weekly.py# Rebuilds all servers that are set to rebuild_schedule = weekly
# Follows the same process as server.rebuild_now() but uses rebuild_schedule_location

rebuild_monthly.py

rebuild_monthly.py# Rebuilds all servers that are set to rebuild_schedule = monthly
# Follows the same process as server.rebuild_now() but uses rebuild_schedule_location

reset_bandwidth_monthly.py

reset_bandwidth.py# Resets all bandwidth_this_month values to 0

The PHP/HTML/CSS/Javascript Frontend

dashboard.php

if request is ajax:
# return json response
# get username of logged in user (from WordPress session info)
# Processes POST Ajax requests
if POST request_type=rebuild_now:
# Update server database where server=server and username=username set rebuild_location=rebuild_location and rebuild_now=1
else if POST request_type=update_schedule:
# Update server database where server=server and username=username set rebuild_schedule=rebuild_schedule, rebuild_location=rebuild_location
else if GET request request_type=servers:
# select server infos from server table where username=username
else:
# return normal dashboard UI
# get username of customer who is logged in by asking WordPress about the current session info
# query server table to find if a server row exists
# do ajax request with GET and request_type=servers to update servers list and statuses every 15 seconds

if a server row exists:

# echo a heading of “VPN Servers”
# echo an HTML table with the server info (see sketch of UI) for each server
# Create a “Rebuild” button which triggers an Ajax POST request to dashboard.php which includes: request_type=rebuild_now, rebuild_now_location,server
# Use a “Toast”/pop-up which lets the user know that the request was successful
# echo a heading of “Rebuild Scheduler”
# echo a table based off of the information gathered from the server row (server_name, rebuild_schedule_location, and rebuild_schedule) for each server
# Create a “Save” button which triggers an Ajax POST request to dashboard.php which includes: request_type=update_schedule, rebuild_schedule_location, rebuild_schedule, server
# Use a “Toast”/pop-up which lets the user know that request was successful

else:
# echo “You haven’t subscribed to any plans. Purchase The VPS VPN so that we can build it for you!”

Closing thoughts

I am also looking for feedback on the concept itself, as well as beta testers. Please sign up for the newsletter at https://ghostifi.net if you are interested.

GhostiFi

The VPS VPN

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