ResultManager/config/config.php
2019-08-08 16:58:29 +03:00

142 lines
4.5 KiB
PHP

<?php
/**
* /config/config.php
* @version 1.0
* @desc configuration file
* @author Fándly Gergő Zoltán (fandlygergo@gmail.hu, systemtest.tk)
* @copy 2017 Fándly Gergő Zoltán
* License:
Result Manager for managing results of students in bilingual school systems.
Copyright (C) 2017 Fándly Gergő Zoltán
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
**/
/*
* Includes
*/
require_once("lib/loginManager/loginManager.php");
require_once("lib/PasswordStorage.php");
require_once("lib/functions.php");
/*
* Load config file
*/
$config=parse_ini_file("config.ini", true);
/*
* Regionalization
*/
date_default_timezone_set($config['general']['timezone']);
mb_internal_encoding("UTF-8");
/*
* Load language file
*/
$lang=parse_ini_file("lang/".$config['language']['use']);
/*
* Set up DB
*/
$db=new PDO($config['database']['type'].":host=".$config['database']['host'].";dbname=".$config['database']['name'].";charset=utf8", $config['database']['user'], $config['database']['password']);
/*
* Byte order mark for utf8
*/
$BOM=chr(239).chr(187).chr(191);
/*
* Debug
*/
if($config['general']['debug']){
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
ini_set("display_errors", true);
}
/*
* Versioning
*/
const VERSION="0.7";
/*
* Set up login manager
*/
//build classes
class handler implements lmHandler{
public function handle($state, $target=0){
global $db;
switch($state){
case lmStates::LOGIN_FAILED:
functions::setError(1);
functions::safeReload();
break;
case lmStates::LOGIN_OK:
$sql=$db->prepare("SELECT id, username, fullname, accesslevel, class, perm_message FROM users WHERE id=:id");
$sql->execute(array(":id"=>$target));
$res=$sql->fetch(PDO::FETCH_ASSOC);
$_SESSION['id']=$res['id'];
$_SESSION['username']=$res['username'];
$_SESSION['fullname']=$res['fullname'];
$_SESSION['accesslevel']=$res['accesslevel'];
$_SESSION['class']=$res['class'];
$_SESSION['perm_message']=$res['perm_message'];
functions::safeReload();
break;
case lmStates::CAPTCHA_FAILED:
functions::setError(2);
functions::safeReload();
break;
case lmStates::BANNED:
functions::setError(3);
functions::safeReload();
break;
case lmStates::FORGET_DONE:
functions::setMessage(1);
functions::safeReload();
break;
case lmStates::LOGOUT_DONE:
functions::setMessage(2);
functions::safeReload();
}
return;
}
}
class password implements lmPassword{
public function verifyPassword($cleartext, $database){
if($database==""){
return false;
}
return PasswordStorage::verify_password($cleartext, $database);
}
}
class twoFactor implements lmTwoFactor{
public function secondFactor($uid){
return true;
}
}
//build login manager
$lm=new loginManager(new lmConfig($db, $config['login']['session_lifetime'], $config['login']['captcha_enable'], $config['login']['captcha_after'], $config['login']['captcha_sitekey'], $config['login']['captcha_secretkey'], $config['login']['ban_enable'], $config['login']['ban_after'], $config['login']['ban_time'], $config['login']['look'], $config['login']['remember_enable'], $config['login']['remember_time'], lmStates::AUTH_UNAME), new handler(), new password(), new twoFactor());
//init
$lm->init();
//get the current schoolyear
$schoolyear="";
if(date("m")>=$config['general']['newYearMonth']){
$schoolyear=date("Y")."-".date("Y", time()+31556926);
}
else{
$schoolyear=date("Y", time()-31556926)."-".date("Y");
}