diff --git a/.gitignore b/.gitignore index 79cae65..e35c5e4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ vendor *.lock public/img/bg.* public/img/bg-*.* +*.env \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 86b10f8..3b16370 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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" @@ -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: diff --git a/src/Database.php b/src/Database.php index 54ecb03..947ac9d 100644 --- a/src/Database.php +++ b/src/Database.php @@ -1,6 +1,5 @@ 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."); } diff --git a/src/GuestPortal.php b/src/GuestPortal.php index 7d4799e..02714e0 100644 --- a/src/GuestPortal.php +++ b/src/GuestPortal.php @@ -1,9 +1,7 @@ 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; } diff --git a/src/UniFi.php b/src/UniFi.php index eee9ace..8be6513 100644 --- a/src/UniFi.php +++ b/src/UniFi.php @@ -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 {