ignore teporary file copies
[authserver.git] / app / authsystem.inc.php
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 /*
7   Some resources for how to store passwords:
8   - https://blog.mozilla.org/webdev/2012/06/08/lets-talk-about-password-storage/
9   - https://wiki.mozilla.org/WebAppSec/Secure_Coding_Guidelines
10   oauth-server-php: https://bshaffer.github.io/oauth2-server-php-docs/cookbook
11 */
12
13 // error reporting (for testing)
14 ini_set('display_errors', 1); error_reporting(E_ALL);
15
16 // Read DB settings
17 $dbdata = json_decode(file_get_contents('/etc/kairo/auth_db.json'), true);
18 if (!is_array($dbdata)) { trigger_error('DB configuration not found', E_USER_ERROR); }
19 $settings = json_decode(file_get_contents('/etc/kairo/auth_settings.json'), true);
20 if (!is_array($settings)) { trigger_error('Auth settings not found', E_USER_ERROR); }
21
22 // Extended DOM document class
23 require_once('../kairo-utils/document.php-class');
24 // Class for sending emails
25 require_once('../kairo-utils/email.php-class');
26 // Class for sending emails
27 require_once(__DIR__.'/authutils.php-class');
28
29 // Connect to our MySQL DB
30 $db = new PDO($dbdata['dsn'], $dbdata['username'], $dbdata['password']);
31 // Instantiate auth utils.
32 $utils = new AuthUtils($settings, $db);
33
34 // This is an array of locale tags in browser style mapping to unix system locale codes to use with gettext.
35 $supported_locales = array(
36     'en-US' => 'en_US',
37     'de' => 'de_DE',
38 );
39
40 $textdomain = 'kairo_auth';
41 $textlocale = $utils->negotiateLocale(array_keys($supported_locales));
42 putenv('LC_ALL='.$supported_locales[$textlocale]);
43 $selectedlocale = setlocale(LC_ALL, $supported_locales[$textlocale]);
44 bindtextdomain($textdomain, '../locale');
45 bind_textdomain_codeset($textdomain, 'utf-8');
46 textdomain($textdomain);
47
48 /* Creating the DB tables:
49 CREATE TABLE `auth_sessions` (
50  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT ,
51  `sesskey` VARCHAR(150) NOT NULL DEFAULT '' ,
52  `user` MEDIUMINT UNSIGNED NULL DEFAULT NULL ,
53  `logged_in` BOOLEAN NOT NULL DEFAULT FALSE ,
54  `time_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
55  `time_expire` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
56  `saved_redirect` VARCHAR(255) NOT NULL DEFAULT '' ,
57  PRIMARY KEY (`id`),
58  INDEX (`sesskey`),
59  INDEX (`time_expire`)
60 );
61 CREATE TABLE `auth_users` (
62  `id` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT ,
63  `email` VARCHAR(255) NOT NULL ,
64  `pwdhash` VARCHAR(255) NOT NULL ,
65  `status` ENUM('unverified','ok') NOT NULL DEFAULT 'unverified' ,
66  `verify_hash` VARCHAR(150) NULL DEFAULT NULL ,
67  `group_id` MEDIUMINT UNSIGNED DEFAULT '0' ,
68  PRIMARY KEY (`id`),
69  UNIQUE (`email`)
70 );
71 CREATE TABLE `auth_log` (
72  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT ,
73  `code` VARCHAR(100) NOT NULL ,
74  `info` TEXT NULL DEFAULT NULL ,
75  `ip_addr` VARCHAR(50) NULL DEFAULT NULL ,
76  `time_logged` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
77  PRIMARY KEY (`id`),
78  INDEX (`time_logged`)
79 );
80 */
81
82 // include our OAuth2 Server object
83 require_once(__DIR__.'/server.inc.php');
84 ?>