2008-12-30 02:05:03 +01:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2008-12-30 02:05:03 +01:00
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
2012-01-25 00:03:36 +01:00
|
|
|
* Copyright (c) 2008-2012, Tomasz Sowa
|
2008-12-30 02:05:03 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "templates.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
#include "core/request.h"
|
|
|
|
#include "core/misc.h"
|
|
|
|
#include "functions/functions.h"
|
2009-04-21 22:50:55 +02:00
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
namespace TemplatesFunctions
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
static std::vector<long> priv_user_table;
|
|
|
|
static size_t priv_user_index;
|
|
|
|
static size_t priv_user_reqid = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-06-05 22:29:06 +02:00
|
|
|
void priv_user_tab_init(Item & item)
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
priv_user_reqid = cur->request->id;
|
2008-12-30 02:05:03 +01:00
|
|
|
priv_user_table.clear();
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( !cur->session->puser )
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
|
|
|
// not logged
|
2009-06-05 22:29:06 +02:00
|
|
|
priv_user_table.push_back(item.user_id);
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
else
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->session->puser->super_user )
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
|
|
|
// super user is allowed to change to any user
|
2012-03-09 03:36:25 +01:00
|
|
|
for(Users::Iterator i=system->users.Begin() ; i != system->users.End() ; ++i)
|
|
|
|
priv_user_table.push_back(i->id);
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
// as well to nobody (-1)
|
|
|
|
priv_user_table.push_back(-1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// others
|
2009-06-05 22:29:06 +02:00
|
|
|
priv_user_table.push_back(item.user_id);
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-05 22:29:06 +02:00
|
|
|
void priv_user_tab_init()
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->is_item )
|
|
|
|
priv_user_tab_init(cur->request->item);
|
2009-06-05 22:29:06 +02:00
|
|
|
else
|
2011-01-23 15:15:30 +01:00
|
|
|
priv_user_tab_init(*cur->request->dir_tab.back());
|
2009-06-05 22:29:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
void priv_user_tab(Info & i)
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( priv_user_reqid != cur->request->id )
|
2008-12-30 02:05:03 +01:00
|
|
|
priv_user_tab_init();
|
|
|
|
|
|
|
|
priv_user_index = i.iter;
|
2010-05-30 23:07:46 +02:00
|
|
|
i.res = priv_user_index < priv_user_table.size();
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void priv_user_tab_name(Info & i)
|
|
|
|
{
|
|
|
|
if( priv_user_index < priv_user_table.size() )
|
|
|
|
{
|
|
|
|
long uid = priv_user_table[priv_user_index];
|
|
|
|
|
|
|
|
if( uid != -1 )
|
|
|
|
{
|
2010-08-10 18:12:50 +02:00
|
|
|
User * puser = system->users.GetUser( uid );
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
if( puser )
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
i.out << puser->name;
|
2008-12-30 02:05:03 +01:00
|
|
|
else
|
|
|
|
i.out << "user_id: " << uid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
i.out << config->priv_no_user;
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void priv_user_tab_isdefault(Info & i)
|
|
|
|
{
|
|
|
|
if( priv_user_index < priv_user_table.size() )
|
|
|
|
{
|
|
|
|
long uid = priv_user_table[priv_user_index];
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->is_item )
|
2009-06-05 22:29:06 +02:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( uid == cur->request->item.user_id )
|
2010-05-30 23:07:46 +02:00
|
|
|
i.res = true;
|
2009-06-05 22:29:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( uid == cur->request->dir_tab.back()->user_id )
|
2010-05-30 23:07:46 +02:00
|
|
|
i.res = true;
|
2009-06-05 22:29:06 +02:00
|
|
|
}
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static std::vector<long> priv_group_table;
|
|
|
|
static size_t priv_group_index;
|
|
|
|
static size_t priv_group_reqid = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-06-05 22:29:06 +02:00
|
|
|
void priv_group_tab_init(Item & item)
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
priv_group_reqid = cur->request->id;
|
2008-12-30 02:05:03 +01:00
|
|
|
priv_group_table.clear();
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( !cur->session->puser )
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
|
|
|
// not logged
|
2009-06-05 22:29:06 +02:00
|
|
|
priv_group_table.push_back(item.group_id);
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
else
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->session->puser->super_user )
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
|
|
|
// super user is allowed to change to any group
|
2012-03-09 03:36:25 +01:00
|
|
|
for(Groups::Iterator i=system->groups.Begin() ; i != system->groups.End() ; ++i)
|
|
|
|
priv_group_table.push_back(i->id);
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
// as well to nogroup (-1)
|
|
|
|
priv_group_table.push_back(-1);
|
|
|
|
}
|
|
|
|
else
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->session->puser->id == item.user_id )
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
|
|
|
bool was_current_group = false;
|
|
|
|
// owner of the item -- is allowed to change only to a group in which he belongs to
|
2011-01-23 15:15:30 +01:00
|
|
|
for(size_t i=0 ; i<cur->session->puser->groups.size() ; ++i)
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
2012-03-09 03:36:25 +01:00
|
|
|
priv_group_table.push_back(cur->session->puser->groups[i]);
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( item.group_id == cur->session->puser->groups[i] )
|
2008-12-30 02:05:03 +01:00
|
|
|
was_current_group = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we're showing the item.group_id if it's different
|
|
|
|
if( !was_current_group )
|
2009-06-05 22:29:06 +02:00
|
|
|
priv_group_table.push_back(item.group_id);
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
// switching to -1 is allowed too
|
|
|
|
priv_group_table.push_back(-1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// not the owner and not a super user -- the same as not logged
|
2009-06-05 22:29:06 +02:00
|
|
|
priv_group_table.push_back(item.group_id);
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-05 22:29:06 +02:00
|
|
|
void priv_group_tab_init()
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->is_item )
|
|
|
|
priv_group_tab_init(cur->request->item);
|
2009-06-05 22:29:06 +02:00
|
|
|
else
|
2011-01-23 15:15:30 +01:00
|
|
|
priv_group_tab_init(*cur->request->dir_tab.back());
|
2009-06-05 22:29:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
void priv_group_tab(Info & i)
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( priv_group_reqid != cur->request->id )
|
2008-12-30 02:05:03 +01:00
|
|
|
priv_group_tab_init();
|
|
|
|
|
|
|
|
priv_group_index = i.iter;
|
2010-05-30 23:07:46 +02:00
|
|
|
i.res = priv_group_index < priv_group_table.size();
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void priv_group_tab_name(Info & i)
|
|
|
|
{
|
|
|
|
if( priv_group_index < priv_group_table.size() )
|
|
|
|
{
|
|
|
|
long gid = priv_group_table[priv_group_index];
|
|
|
|
|
|
|
|
if( gid != -1 )
|
|
|
|
{
|
2010-08-10 18:12:50 +02:00
|
|
|
Group * pgroup = system->groups.GetGroup( gid );
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
if( pgroup )
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
i.out << pgroup->name;
|
2008-12-30 02:05:03 +01:00
|
|
|
else
|
|
|
|
i.out << "group_id: " << gid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
i.out << config->priv_no_group;
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void priv_group_tab_isdefault(Info & i)
|
|
|
|
{
|
|
|
|
if( priv_group_index < priv_group_table.size() )
|
|
|
|
{
|
|
|
|
long gid = priv_group_table[priv_group_index];
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->is_item )
|
2009-06-05 22:29:06 +02:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( gid == cur->request->item.group_id )
|
2010-05-30 23:07:46 +02:00
|
|
|
i.res = true;
|
2009-06-05 22:29:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( gid == cur->request->dir_tab.back()->group_id )
|
2010-05-30 23:07:46 +02:00
|
|
|
i.res = true;
|
2009-06-05 22:29:06 +02:00
|
|
|
}
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-05 22:29:06 +02:00
|
|
|
void priv_privileges(Info & i)
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->is_item )
|
|
|
|
i.out << Toa(cur->request->item.privileges, 8);
|
2009-06-05 22:29:06 +02:00
|
|
|
else
|
2011-01-23 15:15:30 +01:00
|
|
|
i.out << Toa(cur->request->dir_tab.back()->privileges, 8);
|
2009-06-05 22:29:06 +02:00
|
|
|
}
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2010-02-16 01:37:00 +01:00
|
|
|
void priv_privileges_for_files(Info & i)
|
|
|
|
{
|
2012-01-25 00:03:36 +01:00
|
|
|
i.out << Toa(system->NewFilePrivileges(), 8);
|
2010-02-16 01:37:00 +01:00
|
|
|
}
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2010-02-16 01:37:00 +01:00
|
|
|
void priv_privileges_for_dirs(Info & i)
|
|
|
|
{
|
2012-01-25 00:03:36 +01:00
|
|
|
i.out << Toa(system->NewDirPrivileges(), 8);
|
2010-02-16 01:37:00 +01:00
|
|
|
}
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
|
2010-02-16 19:34:41 +01:00
|
|
|
void priv_show_form_chown(Info & i)
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
i.res = (cur->request->function == &functions->fun_priv || cur->request->function == &functions->fun_chown);
|
2010-02-16 19:34:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void priv_show_form_chmod(Info & i)
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
i.res = (cur->request->function == &functions->fun_priv || cur->request->function == &functions->fun_chmod);
|
2010-02-16 19:34:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
} // namespace TemplatesFunctions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|