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:
File diff suppressed because it is too large
Load Diff
@@ -1 +1 @@
|
||||
o = adduser.o cat.o chmod.o chown.o ckeditor.o cp.o default.o download.o emacs.o functionbase.o functionparser.o functions.o last.o ln.o login.o logout.o ls.o man.o meta.o mkdir.o mount.o mv.o nicedit.o node.o passwd.o priv.o privchanger.o reload.o rm.o run.o sort.o specialdefault.o stat.o subject.o template.o tinymce.o uname.o upload.o uptime.o vim.o who.o
|
||||
o = adduser.o cat.o chmod.o chown.o ckeditor.o cp.o default.o download.o emacs.o env.o functionbase.o functionparser.o functions.o last.o ln.o login.o logout.o ls.o man.o meta.o mkdir.o mount.o mv.o nicedit.o node.o passwd.o priv.o privchanger.o reload.o rm.o run.o sort.o specialdefault.o stat.o subject.o template.o tinymce.o uname.o upload.o uptime.o vim.o who.o
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2011, Tomasz Sowa
|
||||
* Copyright (c) 2008-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -106,7 +106,7 @@ void AddUser::MakePost()
|
||||
up.pass = pass;
|
||||
system->crypt.PassHashCrypt(up);
|
||||
|
||||
cur->request->status = db->AddUser(user, up.pass, up.pass_encrypted, up.pass_type, up.pass_hash_salted);
|
||||
cur->request->status = db->AddUser(user, up);
|
||||
|
||||
if( cur->request->status == WINIX_ERR_OK )
|
||||
{
|
||||
|
||||
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
|
||||
|
||||
53
functions/env.h
Executable file
53
functions/env.h
Executable file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_functions_env
|
||||
#define headerfile_winix_functions_env
|
||||
|
||||
#include "functionbase.h"
|
||||
#include "core/confparser.h"
|
||||
|
||||
|
||||
namespace Fun
|
||||
{
|
||||
|
||||
|
||||
class Env : public FunctionBase
|
||||
{
|
||||
public:
|
||||
|
||||
Env();
|
||||
|
||||
bool EditAdminEnv(long user_id, const std::wstring & env_str);
|
||||
bool EditEnv(long user_id, const std::wstring & env_str);
|
||||
|
||||
bool HasAccess();
|
||||
void MakePost();
|
||||
|
||||
// used mainly by templates
|
||||
// can return a null pointer
|
||||
User * GetUser();
|
||||
|
||||
private:
|
||||
|
||||
ConfParser conf_parser;
|
||||
Space space;
|
||||
User * puser;
|
||||
size_t req_id;
|
||||
|
||||
bool Parse(const std::wstring & env_str);
|
||||
void SaveEnv();
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010-2011, Tomasz Sowa
|
||||
* Copyright (c) 2010-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -185,6 +185,7 @@ void Functions::CreateFunctions()
|
||||
Add(fun_default);
|
||||
Add(fun_download);
|
||||
Add(fun_emacs);
|
||||
Add(fun_env);
|
||||
Add(fun_last);
|
||||
Add(fun_login);
|
||||
Add(fun_logout);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* Copyright (c) 2010-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "default.h"
|
||||
#include "download.h"
|
||||
#include "emacs.h"
|
||||
#include "env.h"
|
||||
#include "last.h"
|
||||
#include "login.h"
|
||||
#include "logout.h"
|
||||
@@ -70,6 +71,7 @@ public:
|
||||
Fun::Default fun_default;
|
||||
Fun::Download fun_download;
|
||||
Fun::Emacs fun_emacs;
|
||||
Fun::Env fun_env;
|
||||
Fun::Last fun_last;
|
||||
Fun::Login fun_login;
|
||||
Fun::Logout fun_logout;
|
||||
|
||||
Reference in New Issue
Block a user