Readers will learn how to customize the UniFi portal in order for each guest to login using a unique username and password, checked against a database (e.g., MySQL)
Attached is a very rudimentary custom portal. It's written in HTML and PHP and was configured on a Ubuntu 12.04 x64 server. You will obviously need your appropriate web server (Apache2), PHP5, curl packages, and MySQL server packages.
The attachment includes the following files:
- .htaccess - Specifies the order of which index.* file to use
- auth.php - This is where the meat of the functionality is. It cleans up any input and calls a pair of functions that are in the config.php.inc
- config.php.inc - This is where are the credentials and functions are stored. The auth_user function is the check against the MySQL database for user existence, password validation, and optionally, email validation. The sendAuthorization function notifies UniFi to authorize the user IF the user has passed the auth_user function.
- index.php - The HTML form that prompts for username, password, and email.
- hotspot.sql - The MySQL structure for simple ID, username, password, and email columns. Note that the way the structure and the code is written, passwords are stored in the database as plain text. You can modify to hash the passwords for security reasons if you prefer
There are also comments all over the place to aide someone in figuring out what the code is doing where. This is obviously a very stripped down front end:
The main pieces are the auth_user and the sendAuthorization functions which are found in config.php.inc You can build whatever you need to off of those.
If putting this on Ubuntu or Debian (assuming the standard paths):
- Install prerequisites (MySQL Server, Apache2, PHP5, curl, php5-curl, etc)
- mkdir -p /var/www/guest/s/default/
- cd /var/www/guest/s/default
- Download the attached file to this location
- Extract the .zip file with `unzip -xvf MySQL\ Custom\ Portal Example.zip` (You may need to install the unzip package)
- Import hotspot.sql
- Create/grant user privileges on the hotspot database
- Modify config.php.inc with the appropriate credentials
The process of installing most of these required packages is outlined on this site.
It's important to note that you cannot include folders in your External Portal option, just an IP address. You can either modify the default Apache2 index.html file to redirect to the appropriate path, or create a symlink to the guest/s/default/index.php file.
Last, setup UniFi to point to the IP of the portal server. You can test authentication by inserting a dummy account in to the MySQL database.
Optional: If you're not familiar with MySQL, you may want to download a front-end for it, such as phpmyadmin (apt-get install phpmyadmin <- for Debian based distributions). This will vastly help when adding/modifying/deleting users. Alternatively, you can create your own PHP page to modify users.
It's also worth noting that you can expand on this quite a bit. For example, you could add code to the PHP and columns to MySQL to log authentications, the user's MAC address, time of last authentication, etc.
Disclaimer: Ubiquiti will not support this code. It is provided simply as an example of a rudimentary, functioning external portal.