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
|
|
|
|
*
|
2010-02-28 22:33:06 +01:00
|
|
|
* Copyright (c) 2008-2010, Tomasz Sowa
|
2008-12-30 02:05:03 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "templates.h"
|
2009-04-21 22:50:55 +02:00
|
|
|
#include "../core/data.h"
|
|
|
|
#include "../core/request.h"
|
|
|
|
#include "../core/misc.h"
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
priv_user_reqid = request.id;
|
|
|
|
priv_user_table.clear();
|
|
|
|
|
|
|
|
if( !request.session->puser )
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
if( request.session->puser->super_user )
|
|
|
|
{
|
|
|
|
// super user is allowed to change to any user
|
|
|
|
for(size_t i=0 ; i<data.users.Size() ; ++i)
|
|
|
|
priv_user_table.push_back( data.users[i].id );
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
{
|
|
|
|
if( request.is_item )
|
|
|
|
priv_user_tab_init(request.item);
|
|
|
|
else
|
|
|
|
priv_user_tab_init(*request.dir_table.back());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
void priv_user_tab(Info & i)
|
|
|
|
{
|
|
|
|
if( priv_user_reqid != request.id )
|
|
|
|
priv_user_tab_init();
|
|
|
|
|
|
|
|
priv_user_index = i.iter;
|
|
|
|
i.result = priv_user_index < priv_user_table.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
User * puser = data.users.GetUser( uid );
|
|
|
|
|
|
|
|
if( puser )
|
|
|
|
HtmlEscape(i.out, puser->name);
|
|
|
|
else
|
|
|
|
i.out << "user_id: " << uid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HtmlEscape(i.out, data.priv_no_user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void priv_user_tab_isdefault(Info & i)
|
|
|
|
{
|
|
|
|
if( priv_user_index < priv_user_table.size() )
|
|
|
|
{
|
|
|
|
long uid = priv_user_table[priv_user_index];
|
|
|
|
|
2009-06-05 22:29:06 +02:00
|
|
|
if( request.is_item )
|
|
|
|
{
|
|
|
|
if( uid == request.item.user_id )
|
|
|
|
i.result = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( uid == request.dir_table.back()->user_id )
|
|
|
|
i.result = true;
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
priv_group_reqid = request.id;
|
|
|
|
priv_group_table.clear();
|
|
|
|
|
|
|
|
if( !request.session->puser )
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
if( request.session->puser->super_user )
|
|
|
|
{
|
|
|
|
// super user is allowed to change to any group
|
|
|
|
for(size_t i=0 ; i<data.groups.Size() ; ++i)
|
|
|
|
priv_group_table.push_back( data.groups[i].id );
|
|
|
|
|
|
|
|
// as well to nogroup (-1)
|
|
|
|
priv_group_table.push_back(-1);
|
|
|
|
}
|
|
|
|
else
|
2009-06-05 22:29:06 +02:00
|
|
|
if( request.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
|
|
|
|
for(size_t i=0 ; i<request.session->puser->groups.size() ; ++i)
|
|
|
|
{
|
|
|
|
priv_group_table.push_back( request.session->puser->groups[i] );
|
|
|
|
|
2009-06-05 22:29:06 +02:00
|
|
|
if( item.group_id == request.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()
|
|
|
|
{
|
|
|
|
if( request.is_item )
|
|
|
|
priv_group_tab_init(request.item);
|
|
|
|
else
|
|
|
|
priv_group_tab_init(*request.dir_table.back());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
void priv_group_tab(Info & i)
|
|
|
|
{
|
|
|
|
if( priv_group_reqid != request.id )
|
|
|
|
priv_group_tab_init();
|
|
|
|
|
|
|
|
priv_group_index = i.iter;
|
|
|
|
i.result = priv_group_index < priv_group_table.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
Group * pgroup = data.groups.GetGroup( gid );
|
|
|
|
|
|
|
|
if( pgroup )
|
|
|
|
HtmlEscape(i.out, pgroup->name);
|
|
|
|
else
|
|
|
|
i.out << "group_id: " << gid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HtmlEscape(i.out, data.priv_no_group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void priv_group_tab_isdefault(Info & i)
|
|
|
|
{
|
|
|
|
if( priv_group_index < priv_group_table.size() )
|
|
|
|
{
|
|
|
|
long gid = priv_group_table[priv_group_index];
|
|
|
|
|
2009-06-05 22:29:06 +02:00
|
|
|
if( request.is_item )
|
|
|
|
{
|
|
|
|
if( gid == request.item.group_id )
|
|
|
|
i.result = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( gid == request.dir_table.back()->group_id )
|
|
|
|
i.result = true;
|
|
|
|
}
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-05 22:29:06 +02:00
|
|
|
void priv_privileges(Info & i)
|
|
|
|
{
|
|
|
|
if( request.is_item )
|
|
|
|
i.out << std::setbase(8) << request.item.privileges << std::setbase(10);
|
|
|
|
else
|
|
|
|
i.out << std::setbase(8) << request.dir_table.back()->privileges << std::setbase(10);
|
|
|
|
}
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2010-02-16 01:37:00 +01:00
|
|
|
void priv_privileges_for_files(Info & i)
|
|
|
|
{
|
|
|
|
//!! bedzie uzyte umask
|
|
|
|
i.out << std::setbase(8) << (int)0644 << std::setbase(10);
|
|
|
|
}
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2010-02-16 01:37:00 +01:00
|
|
|
void priv_privileges_for_dirs(Info & i)
|
|
|
|
{
|
|
|
|
//!! bedzie uzyte umask
|
|
|
|
i.out << std::setbase(8) << (int)0755 << std::setbase(10);
|
|
|
|
}
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
|
2010-02-16 19:34:41 +01:00
|
|
|
void priv_show_form_chown(Info & i)
|
|
|
|
{
|
|
|
|
i.result = (request.pfunction->code == FUN_PRIV || request.pfunction->code == FUN_CHOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void priv_show_form_chmod(Info & i)
|
|
|
|
{
|
|
|
|
i.result = (request.pfunction->code == FUN_PRIV || request.pfunction->code == FUN_CHMOD);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
} // namespace TemplatesFunctions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|