# Aruba iAP based External Captive Portal with Twilio Verify

The captive portal web server can be setup using the instructions given [here](https://gist.github.com/nasirhafeez/4e1c2c5536d313db96e2b4ce4b3b269e). The following actions are required to use the code given in this repo:
 
Copy the `.env.example` file to the upper level folder and change its name to `.env`. Set the values of the given project-wide environment variables in it.

Rename the `parameters.php.example` file to `parameters.php` and set the values of variables according to the current site.

*Install Composer*

Then run `php composer.phar install` to install the packages given in `composer.json`.

*Geolocation API*

Go to geolocation directory and run `npm install`. Then setup PM2 to start the API server:

```
npm install pm2@latest -g
pm2 start index.js
pm2 save
pm2 startup systemd
env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u root --hp /home/root
systemctl start pm2-root
```

These commands can be used to view service status:

```
pm2 list
systemctl status pm2-root
```

*OTP Verification*

Add the following table to database:

```
CREATE TABLE `otps` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `identity` varchar(80) NOT NULL,
  `otp` varchar(40) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`)
);
```

*API*

The portal supports an API to interact with the database. The API call will be made like this:

`https://wifi-ten.com/api.php?endpoint`

It has the following endpoints:

1. sites: provides list of sites in database
2. data: data of users for a particular site
3. stats: number of clients and APs on a site
4. summary: weekly, monthly and yearly clients and ad views on a site
5. bot: removing phone numbers blocked due to Anti-bot policy

Call to `sites` endpoint will be made like this:

```markdown
https://wifi-ten.com/api.php?sites
```

The `data`, `stats` and `summary` endpoints will include site name for which the API call is invoked, like this:

```markdown
https://wifi-ten.com/api.php?data=TENE1200171
```

The `bot` endpoint will include a 7-digit phone representing the last 7 digits of the phone being unblocked:

```markdown
https://wifi-ten.com/api.php?bot=1050061
```

This API also works for the backup site in the same way. In that case `wifi-ten.com` will be replaced by `bu.wifi-ten.com`