added: TextStream<> DbTextStream<> and HtmlTextStream<> have operator<<(Space&) now
added: to db: bool DbBase::AssertValueSpace(PGresult * r, int row, int col, Space & space, bool split_single) added: environment variables for users User::env (of type Space) and User::aenv (of type Space) for admin variables (can be changed only by a super user) added: winix function 'env' for changing User::env and User::aenv ('env' winix function with a 'a' parameter) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@790 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
183
functions/env.cpp
Executable file
183
functions/env.cpp
Executable file
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "env.h"
|
||||
#include "core/log.h"
|
||||
|
||||
|
||||
namespace Fun
|
||||
{
|
||||
|
||||
Env::Env()
|
||||
{
|
||||
fun.url = L"env";
|
||||
puser = 0;
|
||||
}
|
||||
|
||||
|
||||
bool Env::HasAccess()
|
||||
{
|
||||
if( !cur->session->puser )
|
||||
return false;
|
||||
|
||||
if( cur->request->IsParam(L"a") )
|
||||
{
|
||||
// show/change admin environment variables for a user
|
||||
|
||||
if( !cur->session->puser->super_user )
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !GetUser() )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Env::Parse(const std::wstring & env_str)
|
||||
{
|
||||
space.Clear();
|
||||
conf_parser.SetSpace(space);
|
||||
conf_parser.UTF8(config->utf8);
|
||||
conf_parser.SplitSingle(true);
|
||||
|
||||
return (conf_parser.ParseString(env_str) == ConfParser::ok);
|
||||
}
|
||||
|
||||
|
||||
bool Env::EditAdminEnv(long user_id, const std::wstring & env_str)
|
||||
{
|
||||
if( Parse(env_str) )
|
||||
{
|
||||
if( db->ChangeUserAdminEnv(user_id, space) == WINIX_ERR_OK )
|
||||
{
|
||||
User * puser = system->users.GetUser(user_id);
|
||||
|
||||
if( puser )
|
||||
puser->aenv = space;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Evn: a problem with changing environment variables for user: "
|
||||
<< cur->session->puser->name << ", id: " << cur->session->puser->id << logend;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log2 << "Env: Syntax error in line: " << conf_parser.line << logend;
|
||||
slog << logerror << "Syntax error in line: " << conf_parser.line << logend;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Env::EditEnv(long user_id, const std::wstring & env_str)
|
||||
{
|
||||
if( Parse(env_str) )
|
||||
{
|
||||
if( db->ChangeUserEnv(user_id, space) == WINIX_ERR_OK )
|
||||
{
|
||||
User * puser = system->users.GetUser(user_id);
|
||||
|
||||
if( puser )
|
||||
puser->env = space;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Evn: a problem with changing admin environment variables for user: "
|
||||
<< cur->session->puser->name << ", id: " << cur->session->puser->id << logend;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log2 << "Env: Syntax error in line: " << conf_parser.line << logend;
|
||||
slog << logerror << "Syntax error in line: " << conf_parser.line << logend;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void Env::SaveEnv()
|
||||
{
|
||||
if( GetUser() )
|
||||
{
|
||||
const std::wstring & env_str = cur->request->PostVar(L"envvar");
|
||||
long user_id = GetUser()->id;
|
||||
bool status = false;
|
||||
|
||||
if( cur->request->IsParam(L"a") )
|
||||
{
|
||||
if( cur->session->puser->super_user )
|
||||
status = EditAdminEnv(user_id, env_str);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = EditEnv(user_id, env_str);
|
||||
}
|
||||
|
||||
if( status )
|
||||
system->RedirectToLastItem();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
User * Env::GetUser()
|
||||
{
|
||||
if( cur->request->id != req_id )
|
||||
{
|
||||
req_id = cur->request->id;
|
||||
puser = 0;
|
||||
|
||||
if( cur->session->puser )
|
||||
{
|
||||
if( cur->session->puser->super_user && cur->request->IsPostVar(L"userid") )
|
||||
{
|
||||
long id = Tol(cur->request->PostVar(L"userid"));
|
||||
puser = system->users.GetUser(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
puser = cur->session->puser;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return puser;
|
||||
}
|
||||
|
||||
|
||||
void Env::MakePost()
|
||||
{
|
||||
if( cur->session->puser )
|
||||
{
|
||||
if( cur->request->IsPostVar(L"changeuser") )
|
||||
{
|
||||
// show environments variables for the specified user
|
||||
if( GetUser() )
|
||||
log << log2 << "Env: changing user to: " << GetUser()->name << ", id: " << GetUser()->id << logend;
|
||||
}
|
||||
else
|
||||
{
|
||||
// save environment variables
|
||||
SaveEnv();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
Reference in New Issue
Block a user