Skip to content

Commit

Permalink
Fix minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlgo11 committed Sep 19, 2021
1 parent 598343b commit 3edd157
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ vendor
*.lock
public/img/bg.*
public/img/bg-*.*
*.env
33 changes: 14 additions & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,18 @@ services:

php:
build: .
environment:
MYSQL_HOST: db
MYSQL_PORT: 3306
MYSQL_USER: guest-portal
MYSQL_PASSWORD: guest-portal
MYSQL_DATABASE: guest-portal
UNIFI_USER: guest-portal
UNIFI_PASSWORD: password
UNIFI_URL: https://192.168.0.1
UNIFI_SITE: default
UNIFI_VERSION: 6.0.43
UNIFI_VERIFY_CERT: 0
restart: unless-stopped
container_name: guest-portal_php
volumes:
- "./:/var/www:ro"
- "./:/var/www"
env_file:
- mysql.env
- unifi.env

nginx:
image: nginx
restart: unless-stopped
container_name: guest-portal_nginx
user: nginx
volumes:
- "./resources/nginx.conf:/etc/nginx/nginx.conf:ro"
Expand All @@ -33,14 +27,15 @@ services:

db:
image: linuxserver/mariadb:alpine
restart: unless-stopped
container_name: guest-portal_db
volumes:
- mysql:/var/lib/mysql
- ./resources/db-template.sql:/docker-entrypoint-initdb.d/db.sql
- "mysql:/var/lib/mysql"
- "./resources/db-template.sql:/config/initdb.d/db.sql"
environment:
MYSQL_RANDOM_ROOT_PASSWORD: 1
MYSQL_USER: guest-portal
MYSQL_PASSWORD: guest-portal
MYSQL_DATABASE: guest-portal
MYSQL_ROOT_PASSWORD: password
env_file:
- mysql.env

volumes:
mysql:
3 changes: 1 addition & 2 deletions src/Database.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Carlgo11\Guest_Portal;

use DateTime;
Expand All @@ -19,7 +18,7 @@ public function __construct()
{
if (!function_exists('mysqli_connect')) throw new Exception("MySQLi not enabled on the server");
$this->mysql = mysqli_init();
if ($this->mysql->real_connect($_ENV['MYSQL_HOST'], $_ENV['MYSQL_USER'], $_ENV['MYSQL_PASSWORD'], $_ENV['MYSQL_DATABASE'], $_ENV['MYSQL_PORT']) !== FALSE)
if ($this->mysql->real_connect($_ENV['MYSQL_HOST'], $_ENV['MYSQL_USER'], $_ENV['MYSQL_PASSWORD'], $_ENV['MYSQL_DATABASE'], $_ENV['MYSQL_PORT']) === FALSE)
throw new Exception("Could not connect to database.");
}

Expand Down
14 changes: 6 additions & 8 deletions src/GuestPortal.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace Carlgo11\Guest_Portal;


use DateTime;
use Exception;

Expand All @@ -28,12 +26,12 @@ public function useVoucher(Voucher $voucher, string $mac, string $ap = NULL): bo
require_once __DIR__ . '/UniFi.php';
$uniFi = new UniFi();
if (!$uniFi->isOnline($mac)) throw new Exception('Client not connected to guest wifi');
if ($uniFi->authorizeGuest($mac, $voucher, $ap)) {
$db = new Database();
if ($uses = $voucher->uses < 2) $db->removeVoucher($voucher);
else $db->updateUses($voucher, $uses - 1);
return true;
}
if ($uniFi->authorizeGuest($mac, $voucher, $ap)) {
$db = new Database();
if ($uses = $voucher->uses < 2) $db->removeVoucher($voucher);
else $db->updateUses($voucher, $uses - 1);
return true;
}
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/UniFi.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use UniFi_API\Client as UniFi_API;

require_once __DIR__ . '/../../../../vendor/autoload.php';
require_once __DIR__ . '/../vendor/autoload.php';

class UniFi
{
Expand Down

0 comments on commit 3edd157

Please sign in to comment.