add use_internal_session_mechanism and use_internal_loggin_mechanism config options

This commit is contained in:
Tomasz Sowa 2022-07-26 21:54:33 +02:00
parent c85a724fec
commit 9e6a5b2d37
5 changed files with 115 additions and 66 deletions

View File

@ -191,6 +191,9 @@ void Config::AssignValues()
templates_request_status = Text(L"templates_request_status", L"request_status.html"); templates_request_status = Text(L"templates_request_status", L"request_status.html");
template_only_root_use_template_fun = Bool(L"template_only_root_use_template_fun", false); template_only_root_use_template_fun = Bool(L"template_only_root_use_template_fun", false);
use_internal_session_mechanism = Bool(L"use_internal_session_mechanism", true);
use_internal_loggin_mechanism = Bool(L"use_internal_loggin_mechanism", true);
http_session_id_name = Text(L"http_session_id_name", L"session_id"); http_session_id_name = Text(L"http_session_id_name", L"session_id");
db_conn_string = Text(L"db_conn_string"); db_conn_string = Text(L"db_conn_string");
db_host = Text(L"db_host"); db_host = Text(L"db_host");

View File

@ -267,6 +267,18 @@ public:
// if a migration fails then stop winix // if a migration fails then stop winix
bool db_stop_if_migration_fails; bool db_stop_if_migration_fails;
// use internal session mechanism
// default: true
// if false then we do not load/save and create internal sessions
// but there always be the temporary session object for a request
// also we do not load 'who' winix function
bool use_internal_session_mechanism;
// use internal loggin mechanism
// default: true
// if false then we do not load 'login' and 'logout' winix functions
// and the system will not allow to login through its api
bool use_internal_loggin_mechanism;
// the name of the cookie which has the session identifier // the name of the cookie which has the session identifier
std::wstring http_session_id_name; std::wstring http_session_id_name;

View File

@ -475,6 +475,8 @@ Session * SessionManager::PrepareSession()
{ {
session = nullptr; session = nullptr;
if( config->use_internal_session_mechanism )
{
if( !IsIPBanned() ) if( !IsIPBanned() )
{ {
CookieTab::iterator i = cur->request->cookie_tab.find(config->http_session_id_name); CookieTab::iterator i = cur->request->cookie_tab.find(config->http_session_id_name);
@ -502,6 +504,7 @@ Session * SessionManager::PrepareSession()
CreateSession(); CreateSession();
} }
} }
}
if( !session ) if( !session )
{ {
@ -516,6 +519,8 @@ Session * SessionManager::PrepareSession()
Session * SessionManager::CheckIfFunctionRequireSession() Session * SessionManager::CheckIfFunctionRequireSession()
{ {
if( config->use_internal_session_mechanism )
{
if( cur->request->function && cur->request->function->need_session ) if( cur->request->function && cur->request->function->need_session )
{ {
if( session == &temporary_session ) if( session == &temporary_session )
@ -527,6 +532,7 @@ Session * SessionManager::CheckIfFunctionRequireSession()
} }
} }
} }
}
return session; return session;
} }
@ -652,6 +658,8 @@ void SessionManager::LoadSessions()
SessionParser sp; SessionParser sp;
SessionContainer::Iterator i; SessionContainer::Iterator i;
if( config->use_internal_session_mechanism )
{
if( !config->session_file.empty() ) if( !config->session_file.empty() )
{ {
sp.set_dependency(this); sp.set_dependency(this);
@ -681,6 +689,7 @@ SessionContainer::Iterator i;
// FIXME this log is not printed, why? // FIXME this log is not printed, why?
main_log << log1 << "SM: session_file config parameter is empty, not loading sessions" << logend; main_log << log1 << "SM: session_file config parameter is empty, not loading sessions" << logend;
} }
}
cur->session = &temporary_session; cur->session = &temporary_session;
} }
@ -693,6 +702,11 @@ void SessionManager::SaveSessions()
{ {
char file_path[WINIX_OS_PATH_SIZE]; char file_path[WINIX_OS_PATH_SIZE];
if( !config->use_internal_session_mechanism )
{
return;
}
if( config->session_file.empty() ) if( config->session_file.empty() )
{ {
main_log << log1 << "SM: session_file config parameter is empty, not saving sessions - sessions lost" << logend; main_log << log1 << "SM: session_file config parameter is empty, not saving sessions - sessions lost" << logend;

View File

@ -5,7 +5,7 @@
*/ */
/* /*
* Copyright (c) 2008-2021, Tomasz Sowa * Copyright (c) 2008-2022, Tomasz Sowa
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -264,6 +264,11 @@ return puser;
bool Users::LoginUser(long user_id, bool remember_me, bool use_ses_log) bool Users::LoginUser(long user_id, bool remember_me, bool use_ses_log)
{ {
Config * config = get_config();
if( !config || !config->use_internal_loggin_mechanism )
return false;
if( !LoginUserCheckSession(use_ses_log) ) if( !LoginUserCheckSession(use_ses_log) )
return false; return false;
@ -343,6 +348,10 @@ return how_many;
void Users::LogoutCurrentUser() void Users::LogoutCurrentUser()
{ {
Config * config = get_config();
if( config && config->use_internal_loggin_mechanism )
{
Log * log = get_logger(); Log * log = get_logger();
Session * session = get_session(); Session * session = get_session();
@ -363,6 +372,7 @@ void Users::LogoutCurrentUser()
session->puser = 0; session->puser = 0;
session->remember_me = false; session->remember_me = false;
}
} }

View File

@ -244,8 +244,13 @@ void Functions::CreateFunctions()
Add(fun_imgcrop); Add(fun_imgcrop);
Add(fun_last); Add(fun_last);
Add(fun_locale); Add(fun_locale);
if( config->use_internal_loggin_mechanism )
{
Add(fun_login); Add(fun_login);
Add(fun_logout); Add(fun_logout);
}
Add(fun_ln); Add(fun_ln);
Add(fun_ls); Add(fun_ls);
Add(fun_ipban); Add(fun_ipban);
@ -273,7 +278,12 @@ void Functions::CreateFunctions()
Add(fun_uname); Add(fun_uname);
Add(fun_upload); Add(fun_upload);
Add(fun_uptime); Add(fun_uptime);
if( config->use_internal_session_mechanism )
{
Add(fun_who); Add(fun_who);
}
Add(fun_vim); Add(fun_vim);
plugin->Call(WINIX_CREATE_FUNCTIONS); plugin->Call(WINIX_CREATE_FUNCTIONS);