log failures and some other actions
[authserver.git] / authsystem.inc.php
CommitLineData
133aecbe 1<?php
d46a42f1
RK
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
133aecbe
RK
6// error reporting (for testing)
7ini_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);
11if (!is_array($dbdata)) { trigger_error('DB configuration not found', E_USER_ERROR); }
087085d6
RK
12$settings = json_decode(file_get_contents('/etc/kairo/auth_settings.json'), true);
13if (!is_array($settings)) { trigger_error('Auth settings not found', E_USER_ERROR); }
133aecbe
RK
14
15// Extended DOM document class
16require_once('../kairo/include/cbsm/util/document.php-class');
b19743bc
RK
17// Class for sending emails
18require_once('../kairo/include/classes/email.php-class');
d46a42f1
RK
19// Class for sending emails
20require_once(__DIR__.'/authutils.php-class');
133aecbe
RK
21
22bindtextdomain('kairo_auth', 'en'); // XXX: Should negotiate locale.
23bind_textdomain_codeset('kairo_auth', 'utf-8');
24
d26d08a1
RK
25// Connect to our MySQL DB
26$db = new PDO($dbdata['dsn'], $dbdata['username'], $dbdata['password']);
558e9862
RK
27// Instantiate auth utils.
28$utils = new AuthUtils($settings, $db);
d26d08a1
RK
29
30/* Creating the DB tables:
d46a42f1
RK
31CREATE TABLE `auth_sessions` (
32 `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT ,
33 `sesskey` VARCHAR(150) NOT NULL DEFAULT '' ,
34 `user` MEDIUMINT UNSIGNED NULL DEFAULT NULL ,
35 `logged_in` BOOLEAN NOT NULL DEFAULT FALSE ,
36 `time_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
37 `time_expire` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
38 PRIMARY KEY (`id`),
39 INDEX (`sesskey`),
40 INDEX (`time_expire`)
41);
42CREATE TABLE `auth_users` (
43 `id` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT ,
44 `email` VARCHAR(255) NOT NULL ,
45 `pwdhash` VARCHAR(255) NOT NULL ,
46 `status` ENUM('unverified','ok') NOT NULL DEFAULT 'unverified' ,
47 `verify_hash` VARCHAR(150) NULL DEFAULT NULL ,
48 PRIMARY KEY (`id`),
49 UNIQUE (`email`)
50);
558e9862
RK
51CREATE TABLE `auth_log` (
52 `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT ,
53 `code` VARCHAR(100) NOT NULL ,
54 `info` TEXT NULL DEFAULT NULL ,
55 `ip_addr` VARCHAR(50) NULL DEFAULT NULL ,
56 `time_logged` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
57 PRIMARY KEY (`id`),
58 INDEX (`time_logged`)
59);
d26d08a1
RK
60*/
61
133aecbe
RK
62// include our OAuth2 Server object
63require_once(__DIR__.'/server.inc.php');
64?>