mirror of
https://github.com/rsyslog/loganalyzer.git
synced 2025-09-26 03:09:21 +02:00
Started implementing userdb system. But it isn't fully operateable yet.
This commit is contained in:
parent
e941100192
commit
07f9244647
@ -37,7 +37,11 @@ if ( !defined('IN_PHPLOGCON') )
|
|||||||
}
|
}
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
// --- Database options
|
// --- UserDB options
|
||||||
|
/* If UserDB is enabled, all options will and have to be configured in the database.
|
||||||
|
* All Options below the UserDB options here will not be used, unless a setting
|
||||||
|
* is missing in the database.
|
||||||
|
*/
|
||||||
$CFG['UserDBEnabled'] = false;
|
$CFG['UserDBEnabled'] = false;
|
||||||
$CFG['UserDBServer'] = "";
|
$CFG['UserDBServer'] = "";
|
||||||
$CFG['UserDBPort'] = 3306;
|
$CFG['UserDBPort'] = 3306;
|
||||||
@ -45,6 +49,7 @@ $CFG['UserDBName'] = "";
|
|||||||
$CFG['UserDBPref'] = "";
|
$CFG['UserDBPref'] = "";
|
||||||
$CFG['UserDBUser'] = "";
|
$CFG['UserDBUser'] = "";
|
||||||
$CFG['UserDBPass'] = "";
|
$CFG['UserDBPass'] = "";
|
||||||
|
$CFG['UserDBLoginRequired'] = false;
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
// --- Misc Options
|
// --- Misc Options
|
||||||
|
@ -90,11 +90,23 @@ function InitBasicPhpLogCon()
|
|||||||
|
|
||||||
// Start the PHP Session
|
// Start the PHP Session
|
||||||
StartPHPSession();
|
StartPHPSession();
|
||||||
|
|
||||||
// Init View Configs prior loading config.php!
|
// Init View Configs prior loading config.php!
|
||||||
InitViewConfigs();
|
InitViewConfigs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function InitUserSystemPhpLogCon()
|
||||||
|
{
|
||||||
|
// global vars needed
|
||||||
|
global $CFG, $gl_root_path, $content;
|
||||||
|
|
||||||
|
if ( isset($CFG['UserDBEnabled']) && $CFG['UserDBEnabled'] )
|
||||||
|
{
|
||||||
|
// Include User Functions
|
||||||
|
include($gl_root_path . 'include/functions_users.php');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function InitPhpLogConConfigFile($bHandleMissing = true)
|
function InitPhpLogConConfigFile($bHandleMissing = true)
|
||||||
{
|
{
|
||||||
// Needed to make global
|
// Needed to make global
|
||||||
@ -106,7 +118,13 @@ function InitPhpLogConConfigFile($bHandleMissing = true)
|
|||||||
include_once($gl_root_path . 'config.php');
|
include_once($gl_root_path . 'config.php');
|
||||||
|
|
||||||
// Easier DB Access
|
// Easier DB Access
|
||||||
define('DB_CONFIG', $CFG['UserDBPref'] . "config");
|
define('DB_CONFIG', $CFG['UserDBPref'] . "config");
|
||||||
|
define('DB_GROUPS', $CFG['UserDBPref'] . "groups");
|
||||||
|
define('DB_GROUPMEMBERS', $CFG['UserDBPref'] . "groupmembers");
|
||||||
|
define('DB_SEARCHES', $CFG['UserDBPref'] . "searches");
|
||||||
|
define('DB_SOURCES', $CFG['UserDBPref'] . "sources");
|
||||||
|
define('DB_USERS', $CFG['UserDBPref'] . "users");
|
||||||
|
define('DB_VIEWS', $CFG['UserDBPref'] . "views");
|
||||||
|
|
||||||
// Legacy support for old columns definition format!
|
// Legacy support for old columns definition format!
|
||||||
if ( isset($CFG['Columns']) && is_array($CFG['Columns']) )
|
if ( isset($CFG['Columns']) && is_array($CFG['Columns']) )
|
||||||
@ -175,6 +193,9 @@ function InitPhpLogCon()
|
|||||||
// Will init the config file!
|
// Will init the config file!
|
||||||
InitPhpLogConConfigFile();
|
InitPhpLogConConfigFile();
|
||||||
|
|
||||||
|
// Init UserDB related stuff!
|
||||||
|
InitUserSystemPhpLogCon();
|
||||||
|
|
||||||
// Moved here, because we do not need if GZIP needs to be enabled before the config is loaded!
|
// Moved here, because we do not need if GZIP needs to be enabled before the config is loaded!
|
||||||
InitRuntimeInformations();
|
InitRuntimeInformations();
|
||||||
|
|
||||||
@ -502,11 +523,13 @@ function InitConfigurationValues()
|
|||||||
$result = DB_Query("SELECT * FROM " . DB_CONFIG);
|
$result = DB_Query("SELECT * FROM " . DB_CONFIG);
|
||||||
$rows = DB_GetAllRows($result, true, true);
|
$rows = DB_GetAllRows($result, true, true);
|
||||||
|
|
||||||
|
// Read results from DB and overwrite in $CFG Array!
|
||||||
if ( isset($rows ) )
|
if ( isset($rows ) )
|
||||||
{
|
{
|
||||||
for($i = 0; $i < count($rows); $i++)
|
for($i = 0; $i < count($rows); $i++)
|
||||||
$content[ $rows[$i]['name'] ] = $rows[$i]['value'];
|
$CFG[ $rows[$i]['name'] ] = $rows[$i]['value'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// General defaults
|
// General defaults
|
||||||
// --- Language Handling
|
// --- Language Handling
|
||||||
if ( !isset($content['gen_lang']) ) { $content['gen_lang'] = $CFG['ViewDefaultLanguage'] /*"en"*/; }
|
if ( !isset($content['gen_lang']) ) { $content['gen_lang'] = $CFG['ViewDefaultLanguage'] /*"en"*/; }
|
||||||
@ -931,7 +954,9 @@ function CreateTopLevelDomainSearch()
|
|||||||
$szTLDDomains .= "aero|asia|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel|cTLD|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw";
|
$szTLDDomains .= "aero|asia|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel|cTLD|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw";
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- BEGIN Usermanagement Function ---
|
/*
|
||||||
|
* This Functions starts the main PHP Session if necessary
|
||||||
|
*/
|
||||||
function StartPHPSession()
|
function StartPHPSession()
|
||||||
{
|
{
|
||||||
global $RUNMODE;
|
global $RUNMODE;
|
||||||
@ -946,116 +971,4 @@ function StartPHPSession()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function CheckForUserLogin( $isloginpage, $isUpgradePage = false )
|
|
||||||
{
|
|
||||||
global $content;
|
|
||||||
|
|
||||||
if ( isset($_SESSION['SESSION_LOGGEDIN']) )
|
|
||||||
{
|
|
||||||
if ( !$_SESSION['SESSION_LOGGEDIN'] )
|
|
||||||
RedirectToUserLogin();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$content['SESSION_LOGGEDIN'] = "true";
|
|
||||||
$content['SESSION_USERNAME'] = $_SESSION['SESSION_USERNAME'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// New, Check for database Version and may redirect to updatepage!
|
|
||||||
if ( isset($content['database_forcedatabaseupdate']) &&
|
|
||||||
$content['database_forcedatabaseupdate'] == "yes" &&
|
|
||||||
$isUpgradePage == false
|
|
||||||
)
|
|
||||||
RedirectToDatabaseUpgrade();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( $isloginpage == false )
|
|
||||||
RedirectToUserLogin();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function CreateUserName( $username, $password, $access_level )
|
|
||||||
{
|
|
||||||
$md5pass = md5($password);
|
|
||||||
$result = DB_Query("SELECT username FROM " . STATS_USERS . " WHERE username = '" . $username . "'");
|
|
||||||
$rows = DB_GetAllRows($result, true);
|
|
||||||
if ( isset($rows) )
|
|
||||||
{
|
|
||||||
DieWithFriendlyErrorMsg( "User $username already exists!" );
|
|
||||||
|
|
||||||
// User not created!
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Create User
|
|
||||||
$result = DB_Query("INSERT INTO " . STATS_USERS . " (username, password, access_level) VALUES ('$username', '$md5pass', $access_level)");
|
|
||||||
DB_FreeQuery($result);
|
|
||||||
|
|
||||||
// Success
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function CheckUserLogin( $username, $password )
|
|
||||||
{
|
|
||||||
global $content, $CFG;
|
|
||||||
|
|
||||||
// TODO: SessionTime and AccessLevel check
|
|
||||||
|
|
||||||
$md5pass = md5($password);
|
|
||||||
$sqlselect = "SELECT access_level FROM " . STATS_USERS . " WHERE username = '" . $username . "' and password = '" . $md5pass . "'";
|
|
||||||
$result = DB_Query($sqlselect);
|
|
||||||
$rows = DB_GetAllRows($result, true);
|
|
||||||
if ( isset($rows) )
|
|
||||||
{
|
|
||||||
$_SESSION['SESSION_LOGGEDIN'] = true;
|
|
||||||
$_SESSION['SESSION_USERNAME'] = $username;
|
|
||||||
$_SESSION['SESSION_ACCESSLEVEL'] = $rows[0]['access_level'];
|
|
||||||
|
|
||||||
$content['SESSION_LOGGEDIN'] = "true";
|
|
||||||
$content['SESSION_USERNAME'] = $username;
|
|
||||||
|
|
||||||
// Success !
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( $CFG['MiscShowDebugMsg'] == 1 )
|
|
||||||
DieWithFriendlyErrorMsg( "Debug Error: Could not login user '" . $username . "' <br><br><B>Sessionarray</B> <pre>" . var_export($_SESSION, true) . "</pre><br><B>SQL Statement</B>: " . $sqlselect );
|
|
||||||
|
|
||||||
// Default return false
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function DoLogOff()
|
|
||||||
{
|
|
||||||
global $content;
|
|
||||||
|
|
||||||
unset( $_SESSION['SESSION_LOGGEDIN'] );
|
|
||||||
unset( $_SESSION['SESSION_USERNAME'] );
|
|
||||||
unset( $_SESSION['SESSION_ACCESSLEVEL'] );
|
|
||||||
|
|
||||||
// Redir to Index Page
|
|
||||||
RedirectPage( "index.php");
|
|
||||||
}
|
|
||||||
|
|
||||||
function RedirectToUserLogin()
|
|
||||||
{
|
|
||||||
// TODO Referer
|
|
||||||
header("Location: login.php?referer=" . $_SERVER['PHP_SELF']);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
function RedirectToDatabaseUpgrade()
|
|
||||||
{
|
|
||||||
// TODO Referer
|
|
||||||
header("Location: upgrade.php"); // ?referer=" . $_SERVER['PHP_SELF']);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
// --- END Usermanagement Function ---
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
@ -216,20 +216,7 @@
|
|||||||
|
|
||||||
// Loop through views now and copy into content array!
|
// Loop through views now and copy into content array!
|
||||||
foreach ( $CFG['Views'] as $key => $view )
|
foreach ( $CFG['Views'] as $key => $view )
|
||||||
{
|
|
||||||
$content['Views'][$key] = $view;
|
$content['Views'][$key] = $view;
|
||||||
|
|
||||||
/*
|
|
||||||
// Set View from session if available!
|
|
||||||
if ( isset($_SESSION['currentSourceID']) )
|
|
||||||
{
|
|
||||||
$currentSourceID = $_SESSION['currentSourceID'];
|
|
||||||
|
|
||||||
if ( isset($_SESSION[$currentSourceID . "-View"]) && )
|
|
||||||
$content['Views'][$key]['selected'] = "selected";
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -45,7 +45,7 @@ $errdesc = "";
|
|||||||
$errno = 0;
|
$errno = 0;
|
||||||
|
|
||||||
// --- Current Database Version, this is important for automated database Updates!
|
// --- Current Database Version, this is important for automated database Updates!
|
||||||
$content['database_internalversion'] = "1"; // Whenever incremented, a database upgrade is needed
|
$content['database_internalversion'] = "0"; // Whenever incremented, a database upgrade is needed
|
||||||
$content['database_installedversion'] = "0"; // 0 is default which means Prior Versioning Database
|
$content['database_installedversion'] = "0"; // 0 is default which means Prior Versioning Database
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
@ -54,9 +54,9 @@ function DB_Connect()
|
|||||||
global $link_id, $CFG;
|
global $link_id, $CFG;
|
||||||
|
|
||||||
//TODO: Check variables first
|
//TODO: Check variables first
|
||||||
$link_id = mysql_connect($CFG['DBServer'],$CFG['User'],$CFG['Pass']);
|
$link_id = mysql_connect($CFG['UserDBServer'],$CFG['UserDBUser'],$CFG['UserDBPass']);
|
||||||
if (!$link_id)
|
if (!$link_id)
|
||||||
DB_PrintError("Link-ID == false, connect to ".$CFG['DBServer']." failed", true);
|
DB_PrintError("Link-ID == false, connect to ".$CFG['UserDBServer']." failed", true);
|
||||||
|
|
||||||
// --- Now, check Mysql DB Version!
|
// --- Now, check Mysql DB Version!
|
||||||
$strmysqlver = mysql_get_server_info();
|
$strmysqlver = mysql_get_server_info();
|
||||||
@ -78,10 +78,12 @@ function DB_Connect()
|
|||||||
}
|
}
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
$db_selected = mysql_select_db($CFG['DBName'], $link_id);
|
$db_selected = mysql_select_db($CFG['UserDBName'], $link_id);
|
||||||
if(!$db_selected)
|
if(!$db_selected)
|
||||||
DB_PrintError("Cannot use database '" . $CFG['DBName'] . "'", true);
|
DB_PrintError("Cannot use database '" . $CFG['UserDBName'] . "'", true);
|
||||||
// :D Success connecting to db
|
// :D Success connecting to db
|
||||||
|
|
||||||
|
// TODO Do some more validating on the database
|
||||||
}
|
}
|
||||||
|
|
||||||
function DB_Disconnect()
|
function DB_Disconnect()
|
||||||
@ -283,25 +285,23 @@ function DB_Exec($query)
|
|||||||
function WriteConfigValue($szValue)
|
function WriteConfigValue($szValue)
|
||||||
{
|
{
|
||||||
// --- Abort in this case!
|
// --- Abort in this case!
|
||||||
global $CFG;
|
global $CFG, $content;
|
||||||
if ( $CFG['UserDBEnabled'] == false )
|
if ( $CFG['UserDBEnabled'] == false )
|
||||||
return;
|
return;
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
global $content;
|
|
||||||
|
|
||||||
$result = DB_Query("SELECT name FROM " . STATS_CONFIG . " WHERE name = '" . $szValue . "'");
|
$result = DB_Query("SELECT name FROM " . STATS_CONFIG . " WHERE name = '" . $szValue . "'");
|
||||||
$rows = DB_GetAllRows($result, true);
|
$rows = DB_GetAllRows($result, true);
|
||||||
if ( !isset($rows) )
|
if ( !isset($rows) )
|
||||||
{
|
{
|
||||||
// New Entry
|
// New Entry
|
||||||
$result = DB_Query("INSERT INTO " . STATS_CONFIG . " (name, value) VALUES ( '" . $szValue . "', '" . $content[$szValue] . "')");
|
$result = DB_Query("INSERT INTO " . STATS_CONFIG . " (name, value) VALUES ( '" . $szValue . "', '" . $CFG[$szValue] . "')");
|
||||||
DB_FreeQuery($result);
|
DB_FreeQuery($result);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Update Entry
|
// Update Entry
|
||||||
$result = DB_Query("UPDATE " . STATS_CONFIG . " SET value = '" . $content[$szValue] . "' WHERE name = '" . $szValue . "'");
|
$result = DB_Query("UPDATE " . STATS_CONFIG . " SET value = '" . $CFG[$szValue] . "' WHERE name = '" . $szValue . "'");
|
||||||
DB_FreeQuery($result);
|
DB_FreeQuery($result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -337,4 +337,4 @@ function GetRowsAffected()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
160
src/include/functions_users.php
Normal file
160
src/include/functions_users.php
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
*********************************************************************
|
||||||
|
* -> www.phplogcon.org <- *
|
||||||
|
* ----------------------------------------------------------------- *
|
||||||
|
* UserDB needed functions *
|
||||||
|
* *
|
||||||
|
* -> *
|
||||||
|
* *
|
||||||
|
* All directives are explained within this file *
|
||||||
|
*
|
||||||
|
* Copyright (C) 2008 Adiscon GmbH.
|
||||||
|
*
|
||||||
|
* This file is part of phpLogCon.
|
||||||
|
*
|
||||||
|
* PhpLogCon 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.
|
||||||
|
*
|
||||||
|
* PhpLogCon 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 phpLogCon. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* A copy of the GPL can be found in the file "COPYING" in this
|
||||||
|
* distribution.
|
||||||
|
*********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
// --- Avoid directly accessing this file!
|
||||||
|
if ( !defined('IN_PHPLOGCON') )
|
||||||
|
{
|
||||||
|
die('Hacking attempt');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
// ---
|
||||||
|
|
||||||
|
// --- Basic Includes
|
||||||
|
//include($gl_root_path . 'include/constants_general.php');
|
||||||
|
///include($gl_root_path . 'include/constants_logstream.php');
|
||||||
|
// ---
|
||||||
|
|
||||||
|
// --- BEGIN Usermanagement Function ---
|
||||||
|
function CheckForUserLogin( $isloginpage, $isUpgradePage = false )
|
||||||
|
{
|
||||||
|
global $content;
|
||||||
|
|
||||||
|
if ( isset($_SESSION['SESSION_LOGGEDIN']) )
|
||||||
|
{
|
||||||
|
if ( !$_SESSION['SESSION_LOGGEDIN'] )
|
||||||
|
RedirectToUserLogin();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$content['SESSION_LOGGEDIN'] = "true";
|
||||||
|
$content['SESSION_USERNAME'] = $_SESSION['SESSION_USERNAME'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// New, Check for database Version and may redirect to updatepage!
|
||||||
|
if ( isset($content['database_forcedatabaseupdate']) &&
|
||||||
|
$content['database_forcedatabaseupdate'] == "yes" &&
|
||||||
|
$isUpgradePage == false
|
||||||
|
)
|
||||||
|
RedirectToDatabaseUpgrade();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( $isloginpage == false )
|
||||||
|
RedirectToUserLogin();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function CreateUserName( $username, $password, $access_level )
|
||||||
|
{
|
||||||
|
$md5pass = md5($password);
|
||||||
|
$result = DB_Query("SELECT username FROM " . STATS_USERS . " WHERE username = '" . $username . "'");
|
||||||
|
$rows = DB_GetAllRows($result, true);
|
||||||
|
if ( isset($rows) )
|
||||||
|
{
|
||||||
|
DieWithFriendlyErrorMsg( "User $username already exists!" );
|
||||||
|
|
||||||
|
// User not created!
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Create User
|
||||||
|
$result = DB_Query("INSERT INTO " . STATS_USERS . " (username, password, access_level) VALUES ('$username', '$md5pass', $access_level)");
|
||||||
|
DB_FreeQuery($result);
|
||||||
|
|
||||||
|
// Success
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function CheckUserLogin( $username, $password )
|
||||||
|
{
|
||||||
|
global $content, $CFG;
|
||||||
|
|
||||||
|
// TODO: SessionTime and AccessLevel check
|
||||||
|
|
||||||
|
$md5pass = md5($password);
|
||||||
|
$sqlselect = "SELECT access_level FROM " . STATS_USERS . " WHERE username = '" . $username . "' and password = '" . $md5pass . "'";
|
||||||
|
$result = DB_Query($sqlselect);
|
||||||
|
$rows = DB_GetAllRows($result, true);
|
||||||
|
if ( isset($rows) )
|
||||||
|
{
|
||||||
|
$_SESSION['SESSION_LOGGEDIN'] = true;
|
||||||
|
$_SESSION['SESSION_USERNAME'] = $username;
|
||||||
|
$_SESSION['SESSION_ACCESSLEVEL'] = $rows[0]['access_level'];
|
||||||
|
|
||||||
|
$content['SESSION_LOGGEDIN'] = "true";
|
||||||
|
$content['SESSION_USERNAME'] = $username;
|
||||||
|
|
||||||
|
// Success !
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( $CFG['MiscShowDebugMsg'] == 1 )
|
||||||
|
DieWithFriendlyErrorMsg( "Debug Error: Could not login user '" . $username . "' <br><br><B>Sessionarray</B> <pre>" . var_export($_SESSION, true) . "</pre><br><B>SQL Statement</B>: " . $sqlselect );
|
||||||
|
|
||||||
|
// Default return false
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function DoLogOff()
|
||||||
|
{
|
||||||
|
global $content;
|
||||||
|
|
||||||
|
unset( $_SESSION['SESSION_LOGGEDIN'] );
|
||||||
|
unset( $_SESSION['SESSION_USERNAME'] );
|
||||||
|
unset( $_SESSION['SESSION_ACCESSLEVEL'] );
|
||||||
|
|
||||||
|
// Redir to Index Page
|
||||||
|
RedirectPage( "index.php");
|
||||||
|
}
|
||||||
|
|
||||||
|
function RedirectToUserLogin()
|
||||||
|
{
|
||||||
|
// TODO Referer
|
||||||
|
header("Location: login.php?referer=" . $_SERVER['PHP_SELF']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function RedirectToDatabaseUpgrade()
|
||||||
|
{
|
||||||
|
// TODO Referer
|
||||||
|
header("Location: upgrade.php"); // ?referer=" . $_SERVER['PHP_SELF']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
// --- END Usermanagement Function ---
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
Loading…
x
Reference in New Issue
Block a user