also integrate Pwiki for those endpoints that do not actually output HTML but just...
[authserver.git] / app / 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
77f0f9ff
RK
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
133aecbe
RK
13// error reporting (for testing)
14ini_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);
18if (!is_array($dbdata)) { trigger_error('DB configuration not found', E_USER_ERROR); }
087085d6
RK
19$settings = json_decode(file_get_contents('/etc/kairo/auth_settings.json'), true);
20if (!is_array($settings)) { trigger_error('Auth settings not found', E_USER_ERROR); }
133aecbe
RK
21
22// Extended DOM document class
4e765d99 23require_once('../php-utility-classes/classes/document.php-class');
b19743bc 24// Class for sending emails
4e765d99 25require_once('../php-utility-classes/classes/email.php-class');
d46a42f1
RK
26// Class for sending emails
27require_once(__DIR__.'/authutils.php-class');
133aecbe 28
d26d08a1
RK
29// Connect to our MySQL DB
30$db = new PDO($dbdata['dsn'], $dbdata['username'], $dbdata['password']);
558e9862
RK
31// Instantiate auth utils.
32$utils = new AuthUtils($settings, $db);
d26d08a1 33
9cab985c
RK
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
8b69f29c 40$textdomain = 'kairo_auth';
9cab985c
RK
41$textlocale = $utils->negotiateLocale(array_keys($supported_locales));
42putenv('LC_ALL='.$supported_locales[$textlocale]);
43$selectedlocale = setlocale(LC_ALL, $supported_locales[$textlocale]);
8b69f29c
RK
44bindtextdomain($textdomain, '../locale');
45bind_textdomain_codeset($textdomain, 'utf-8');
46textdomain($textdomain);
47
7be13777
RK
48// Sanitize settings.
49$settings['piwik_enabled'] = (@$settings['piwik_enabled']) ? true : false;
50$settings['piwik_site_id'] = intval(@$settings['piwik_site_id']);
426f76b2
RK
51$settings['piwik_url'] = strlen(@$settings['piwik_url']) ? $settings['piwik_url'] : '/piwik/';
52$settings['piwik_tracker_path'] = strlen(@$settings['piwik_tracker_path']) ? $settings['piwik_tracker_path'] : '../vendor/piwik/piwik-php-tracker/';
7be13777 53
d26d08a1 54/* Creating the DB tables:
d46a42f1
RK
55CREATE TABLE `auth_sessions` (
56 `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT ,
57 `sesskey` VARCHAR(150) NOT NULL DEFAULT '' ,
58 `user` MEDIUMINT UNSIGNED NULL DEFAULT NULL ,
59 `logged_in` BOOLEAN NOT NULL DEFAULT FALSE ,
60 `time_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
61 `time_expire` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
409b55f4 62 `saved_redirect` VARCHAR(255) NOT NULL DEFAULT '' ,
d46a42f1
RK
63 PRIMARY KEY (`id`),
64 INDEX (`sesskey`),
65 INDEX (`time_expire`)
66);
67CREATE TABLE `auth_users` (
68 `id` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT ,
69 `email` VARCHAR(255) NOT NULL ,
70 `pwdhash` VARCHAR(255) NOT NULL ,
71 `status` ENUM('unverified','ok') NOT NULL DEFAULT 'unverified' ,
72 `verify_hash` VARCHAR(150) NULL DEFAULT NULL ,
60e46184 73 `group_id` MEDIUMINT UNSIGNED DEFAULT '0' ,
d46a42f1
RK
74 PRIMARY KEY (`id`),
75 UNIQUE (`email`)
76);
558e9862
RK
77CREATE TABLE `auth_log` (
78 `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT ,
79 `code` VARCHAR(100) NOT NULL ,
80 `info` TEXT NULL DEFAULT NULL ,
81 `ip_addr` VARCHAR(50) NULL DEFAULT NULL ,
82 `time_logged` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
83 PRIMARY KEY (`id`),
84 INDEX (`time_logged`)
85);
d26d08a1
RK
86*/
87
133aecbe
RK
88// include our OAuth2 Server object
89require_once(__DIR__.'/server.inc.php');
90?>