| 1 | <?php |
| 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
| 4 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 5 | |
| 6 | // error reporting (for testing) |
| 7 | ini_set('display_errors', 1); error_reporting(E_ALL); |
| 8 | |
| 9 | // Read DB settings |
| 10 | $dbdata = json_decode(file_get_contents('/etc/kairo/auth_db.json'), true); |
| 11 | if (!is_array($dbdata)) { trigger_error('DB configuration not found', E_USER_ERROR); } |
| 12 | $settings = json_decode(file_get_contents('/etc/kairo/auth_settings.json'), true); |
| 13 | if (!is_array($settings)) { trigger_error('Auth settings not found', E_USER_ERROR); } |
| 14 | |
| 15 | // Extended DOM document class |
| 16 | require_once('../kairo/include/cbsm/util/document.php-class'); |
| 17 | // Class for sending emails |
| 18 | require_once('../kairo/include/classes/email.php-class'); |
| 19 | // Class for sending emails |
| 20 | require_once(__DIR__.'/authutils.php-class'); |
| 21 | $utils = new AuthUtils($settings); |
| 22 | |
| 23 | bindtextdomain('kairo_auth', 'en'); // XXX: Should negotiate locale. |
| 24 | bind_textdomain_codeset('kairo_auth', 'utf-8'); |
| 25 | |
| 26 | // Connect to our MySQL DB |
| 27 | $db = new PDO($dbdata['dsn'], $dbdata['username'], $dbdata['password']); |
| 28 | |
| 29 | /* Creating the DB tables: |
| 30 | CREATE TABLE `auth_sessions` ( |
| 31 | `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT , |
| 32 | `sesskey` VARCHAR(150) NOT NULL DEFAULT '' , |
| 33 | `user` MEDIUMINT UNSIGNED NULL DEFAULT NULL , |
| 34 | `logged_in` BOOLEAN NOT NULL DEFAULT FALSE , |
| 35 | `time_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , |
| 36 | `time_expire` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , |
| 37 | PRIMARY KEY (`id`), |
| 38 | INDEX (`sesskey`), |
| 39 | INDEX (`time_expire`) |
| 40 | ); |
| 41 | CREATE TABLE `auth_users` ( |
| 42 | `id` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT , |
| 43 | `email` VARCHAR(255) NOT NULL , |
| 44 | `pwdhash` VARCHAR(255) NOT NULL , |
| 45 | `status` ENUM('unverified','ok') NOT NULL DEFAULT 'unverified' , |
| 46 | `verify_hash` VARCHAR(150) NULL DEFAULT NULL , |
| 47 | PRIMARY KEY (`id`), |
| 48 | UNIQUE (`email`) |
| 49 | ); |
| 50 | */ |
| 51 | |
| 52 | // include our OAuth2 Server object |
| 53 | require_once(__DIR__.'/server.inc.php'); |
| 54 | ?> |