added: created directory 'content' which has Content:: files
added: created directory 'templates' which has Templates:: and TemplatesFunctions:: files
changed: content.cpp split into many files (directory 'content')
changed: templates.cpp split into many files (directory 'templates')
added: full permissions
changed: building of the program (GNU make is used now)
Makefile and Makefile.dep added into directories
added: a parser 'FunctionParser'
is used to parse the GET string
it recognizes directories, items, functions, functions parameters
added: other classes: Function, Functions
added: function: ls, privileges
changed: function 'id' to 'node'
changed: version: to 0.2.0
added/changed: a lot of work have been done
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@469 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
26
content/Makefile
Executable file
26
content/Makefile
Executable file
@@ -0,0 +1,26 @@
|
||||
o = content.o privileges.o emacs.o login.o rm.o cat.o logout.o ls.o node.o
|
||||
|
||||
|
||||
all: content.a
|
||||
|
||||
content.a: $(o)
|
||||
ar rcs content.a $(o)
|
||||
|
||||
|
||||
.SUFFIXES: .cpp .o
|
||||
|
||||
.cpp.o:
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
|
||||
|
||||
depend:
|
||||
makedepend -Y. -f- *.cpp > Makefile.dep
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f *.a
|
||||
|
||||
|
||||
|
||||
include Makefile.dep
|
||||
108
content/Makefile.dep
Executable file
108
content/Makefile.dep
Executable file
@@ -0,0 +1,108 @@
|
||||
# DO NOT DELETE
|
||||
|
||||
cat.o: content.h ../templates/templates.h ../../ezc/src/ezc.h ../core/data.h
|
||||
cat.o: ../core/misc.h ../core/log.h ../core/item.h ../core/error.h
|
||||
cat.o: ../core/dirs.h ../core/db.h ../core/dircontainer.h ../core/user.h
|
||||
cat.o: ../core/group.h ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
cat.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
cat.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
cat.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||
cat.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
cat.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
cat.o: ../core/log.h ../core/misc.h ../core/function.h
|
||||
cat.o: ../core/functionparser.h ../core/request.h ../core/data.h
|
||||
content.o: content.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||
content.o: ../core/data.h ../core/misc.h ../core/log.h ../core/item.h
|
||||
content.o: ../core/error.h ../core/dirs.h ../core/db.h ../core/dircontainer.h
|
||||
content.o: ../core/user.h ../core/group.h ../core/ugcontainer.h
|
||||
content.o: ../core/users.h ../core/groups.h ../core/functions.h
|
||||
content.o: ../core/function.h ../core/request.h ../core/requesttypes.h
|
||||
content.o: ../core/session.h ../core/done.h ../core/getparser.h
|
||||
content.o: ../core/httpsimpleparser.h ../core/postparser.h
|
||||
content.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
content.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
content.o: ../core/log.h ../core/misc.h ../core/function.h
|
||||
content.o: ../core/functionparser.h ../core/request.h ../core/data.h
|
||||
emacs.o: content.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||
emacs.o: ../core/data.h ../core/misc.h ../core/log.h ../core/item.h
|
||||
emacs.o: ../core/error.h ../core/dirs.h ../core/db.h ../core/dircontainer.h
|
||||
emacs.o: ../core/user.h ../core/group.h ../core/ugcontainer.h ../core/users.h
|
||||
emacs.o: ../core/groups.h ../core/functions.h ../core/function.h
|
||||
emacs.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||
emacs.o: ../core/done.h ../core/getparser.h ../core/httpsimpleparser.h
|
||||
emacs.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
|
||||
emacs.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
|
||||
emacs.o: ../core/users.h ../core/groups.h ../core/log.h ../core/misc.h
|
||||
emacs.o: ../core/function.h ../core/functionparser.h ../core/request.h
|
||||
emacs.o: ../core/data.h
|
||||
login.o: content.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||
login.o: ../core/data.h ../core/misc.h ../core/log.h ../core/item.h
|
||||
login.o: ../core/error.h ../core/dirs.h ../core/db.h ../core/dircontainer.h
|
||||
login.o: ../core/user.h ../core/group.h ../core/ugcontainer.h ../core/users.h
|
||||
login.o: ../core/groups.h ../core/functions.h ../core/function.h
|
||||
login.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||
login.o: ../core/done.h ../core/getparser.h ../core/httpsimpleparser.h
|
||||
login.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
|
||||
login.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
|
||||
login.o: ../core/users.h ../core/groups.h ../core/log.h ../core/misc.h
|
||||
login.o: ../core/function.h ../core/functionparser.h ../core/request.h
|
||||
login.o: ../core/data.h
|
||||
logout.o: content.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||
logout.o: ../core/data.h ../core/misc.h ../core/log.h ../core/item.h
|
||||
logout.o: ../core/error.h ../core/dirs.h ../core/db.h ../core/dircontainer.h
|
||||
logout.o: ../core/user.h ../core/group.h ../core/ugcontainer.h
|
||||
logout.o: ../core/users.h ../core/groups.h ../core/functions.h
|
||||
logout.o: ../core/function.h ../core/request.h ../core/requesttypes.h
|
||||
logout.o: ../core/session.h ../core/done.h ../core/getparser.h
|
||||
logout.o: ../core/httpsimpleparser.h ../core/postparser.h
|
||||
logout.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
logout.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
logout.o: ../core/log.h ../core/misc.h ../core/function.h
|
||||
logout.o: ../core/functionparser.h ../core/request.h ../core/data.h
|
||||
ls.o: content.h ../templates/templates.h ../../ezc/src/ezc.h ../core/data.h
|
||||
ls.o: ../core/misc.h ../core/log.h ../core/item.h ../core/error.h
|
||||
ls.o: ../core/dirs.h ../core/db.h ../core/dircontainer.h ../core/user.h
|
||||
ls.o: ../core/group.h ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
ls.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
ls.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
ls.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||
ls.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
ls.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
ls.o: ../core/log.h ../core/misc.h ../core/function.h
|
||||
ls.o: ../core/functionparser.h ../core/request.h ../core/data.h
|
||||
node.o: content.h ../templates/templates.h ../../ezc/src/ezc.h ../core/data.h
|
||||
node.o: ../core/misc.h ../core/log.h ../core/item.h ../core/error.h
|
||||
node.o: ../core/dirs.h ../core/db.h ../core/dircontainer.h ../core/user.h
|
||||
node.o: ../core/group.h ../core/ugcontainer.h ../core/users.h
|
||||
node.o: ../core/groups.h ../core/functions.h ../core/function.h
|
||||
node.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||
node.o: ../core/done.h ../core/getparser.h ../core/httpsimpleparser.h
|
||||
node.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
|
||||
node.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
|
||||
node.o: ../core/users.h ../core/groups.h ../core/log.h ../core/misc.h
|
||||
node.o: ../core/function.h ../core/functionparser.h ../core/request.h
|
||||
node.o: ../core/data.h
|
||||
privileges.o: content.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||
privileges.o: ../core/data.h ../core/misc.h ../core/log.h ../core/item.h
|
||||
privileges.o: ../core/error.h ../core/dirs.h ../core/db.h
|
||||
privileges.o: ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||
privileges.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
privileges.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
privileges.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
privileges.o: ../core/getparser.h ../core/httpsimpleparser.h
|
||||
privileges.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
|
||||
privileges.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
|
||||
privileges.o: ../core/users.h ../core/groups.h ../core/log.h ../core/misc.h
|
||||
privileges.o: ../core/function.h ../core/functionparser.h ../core/request.h
|
||||
privileges.o: ../core/data.h
|
||||
rm.o: content.h ../templates/templates.h ../../ezc/src/ezc.h ../core/data.h
|
||||
rm.o: ../core/misc.h ../core/log.h ../core/item.h ../core/error.h
|
||||
rm.o: ../core/dirs.h ../core/db.h ../core/dircontainer.h ../core/user.h
|
||||
rm.o: ../core/group.h ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
rm.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
rm.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
rm.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||
rm.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
rm.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
rm.o: ../core/log.h ../core/misc.h ../core/function.h
|
||||
rm.o: ../core/functionparser.h ../core/request.h ../core/data.h
|
||||
38
content/cat.cpp
Executable file
38
content/cat.cpp
Executable file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "content.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::FunCat()
|
||||
{
|
||||
if( !request.is_item )
|
||||
{
|
||||
log << log1 << "Content: Cat function requires an item" << logend;
|
||||
request.status = Error::item_required;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if( !request.HasReadAccess(request.item) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
256
content/content.cpp
Executable file
256
content/content.cpp
Executable file
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "content.h"
|
||||
|
||||
|
||||
|
||||
|
||||
bool Content::Init()
|
||||
{
|
||||
templates.Read();
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool Content::DirsHaveReadExecPerm()
|
||||
{
|
||||
std::vector<Item*>::iterator i;
|
||||
|
||||
for(i = request.dir_table.begin() ; i!=request.dir_table.end() ; ++i)
|
||||
{
|
||||
if( !request.HasReadExecAccess(**i) )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::SetDefaultFunction()
|
||||
{
|
||||
if( request.is_item )
|
||||
{
|
||||
request.pfunction = data.functions.GetFunction(Function::cat);
|
||||
|
||||
if( request.pfunction )
|
||||
log << log3 << "Content: default function: " << request.pfunction->item.url << logend;
|
||||
}
|
||||
else
|
||||
{
|
||||
long default_item = request.dir_table.back()->default_item;
|
||||
|
||||
if( default_item == -1 )
|
||||
{
|
||||
request.pfunction = data.functions.GetFunction(Function::ls);
|
||||
|
||||
if( request.pfunction )
|
||||
log << log3 << "Content: default function: " << request.pfunction->item.url << logend;
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log3 << "Content: Default item: id: " << default_item << logend;
|
||||
RedirectTo(default_item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::MakeStandardFunction()
|
||||
{
|
||||
if( !request.pfunction )
|
||||
SetDefaultFunction();
|
||||
|
||||
if( request.result == Request::redirect )
|
||||
return;
|
||||
|
||||
|
||||
if( !request.pfunction )
|
||||
{
|
||||
log << log1 << "Content: no function (neither cat nor ls)" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if( request.pfunction->code == Function::logout )
|
||||
FunLogout();
|
||||
else
|
||||
if( request.pfunction->code == Function::cat )
|
||||
FunCat();
|
||||
else
|
||||
if( request.pfunction->code == Function::ls )
|
||||
FunLs();
|
||||
else
|
||||
if( request.pfunction->code == Function::emacs )
|
||||
FunEmacs();
|
||||
else
|
||||
if( request.pfunction->code == Function::privileges )
|
||||
FunPrivileges();
|
||||
else
|
||||
if( request.pfunction->code == Function::rm )
|
||||
FunRm();
|
||||
else
|
||||
if( request.pfunction->code == Function::node )
|
||||
FunNode();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::MakePost()
|
||||
{
|
||||
if( !request.pfunction )
|
||||
{
|
||||
log << log1 << "Content: MakePost: no function" << logend;
|
||||
request.status = Error::no_function;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
switch( request.pfunction->code )
|
||||
{
|
||||
case Function::emacs:
|
||||
PostFunEmacs();
|
||||
break;
|
||||
|
||||
case Function::privileges:
|
||||
PostFunPrivileges();
|
||||
break;
|
||||
|
||||
case Function::login:
|
||||
PostFunLogin();
|
||||
break;
|
||||
|
||||
default:
|
||||
log << log1 << "Content: unknown post function" << logend;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::Make()
|
||||
{
|
||||
if( request.dir_table.empty() )
|
||||
{
|
||||
log << log1 << "Content: there is no a root dir" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
// request.status can be changed by function_parser
|
||||
if( request.status == Error::ok )
|
||||
{
|
||||
if( DirsHaveReadExecPerm() )
|
||||
{
|
||||
if( request.method == Request::post )
|
||||
MakePost();
|
||||
|
||||
if( request.result == Request::redirect )
|
||||
return;
|
||||
|
||||
if( request.status == Error::ok )
|
||||
MakeStandardFunction();
|
||||
}
|
||||
else
|
||||
request.status = Error::permision_denied;
|
||||
}
|
||||
|
||||
if( request.result == Request::redirect )
|
||||
return;
|
||||
|
||||
templates.Generate();
|
||||
|
||||
|
||||
//request.PrintGetTable();
|
||||
//request.PrintEnv();
|
||||
//request.PrintIn();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// !! mozna zrobic jakas obsluge kiedy nie mozemy sie redirectnac, np gdy wystapil blad
|
||||
// !! moze zwracac jakas wartosc?
|
||||
void Content::RedirectTo(const Item & item)
|
||||
{
|
||||
std::string path;
|
||||
|
||||
request.result = Request::redirect;
|
||||
request.str = data.base_url;
|
||||
|
||||
|
||||
if( item.type == Item::dir )
|
||||
{
|
||||
// item_id is pointing to a directory
|
||||
data.dirs.MakePath(item.id, path);
|
||||
request.str += path;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !data.dirs.MakePath(item.parent_id, path) )
|
||||
log << log1 << "Content: Can't redirect: no dirs for item id: " << item.id << logend;
|
||||
|
||||
request.str += path;
|
||||
request.str += item.url;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::RedirectTo(long item_id)
|
||||
{
|
||||
std::string path;
|
||||
Item * pdir;
|
||||
|
||||
request.result = Request::redirect;
|
||||
request.str = data.base_url;
|
||||
pdir = data.dirs.GetDir(item_id);
|
||||
|
||||
|
||||
if( pdir )
|
||||
{
|
||||
// item_id is pointing to a directory
|
||||
data.dirs.MakePath(pdir->id, path);
|
||||
request.str += path;
|
||||
}
|
||||
else
|
||||
{
|
||||
// !! zrobic nowy interfejs
|
||||
// !! GetItem pozamieniac na GetFile
|
||||
db.GetItem(request.item_table, item_id);
|
||||
|
||||
if( !request.item_table.empty() )
|
||||
{
|
||||
if( !data.dirs.MakePath(request.item_table[0].parent_id, path) )
|
||||
log << log1 << "Content: Can't redirect: no dirs for item id: " << request.item_table[0].id << ", requested directory id: " << request.item_table[0].parent_id << logend;
|
||||
|
||||
request.str += path + request.item_table[0].url;
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Content: Can't redirect: no such item: id: " << item_id << logend;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
73
content/content.h
Executable file
73
content/content.h
Executable file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilecontent
|
||||
#define headerfilecontent
|
||||
|
||||
#include <cstdlib>
|
||||
#include <fcgiapp.h>
|
||||
|
||||
#include "../templates/templates.h"
|
||||
#include "../core/request.h"
|
||||
#include "../core/error.h"
|
||||
#include "../core/misc.h"
|
||||
#include "../core/db.h"
|
||||
#include "../core/user.h"
|
||||
#include "../core/function.h"
|
||||
#include "../core/functionparser.h"
|
||||
|
||||
|
||||
|
||||
class Content
|
||||
{
|
||||
Templates templates;
|
||||
|
||||
|
||||
|
||||
|
||||
void PrepareUrl(Item & item);
|
||||
|
||||
|
||||
void SetDefaultFunction();
|
||||
bool DirsHaveReadExecPerm();
|
||||
|
||||
void MakeStandardFunction();
|
||||
|
||||
|
||||
|
||||
void MakePost();
|
||||
|
||||
void FunCat();
|
||||
void FunLogout();
|
||||
void FunLs();
|
||||
void FunEmacs();
|
||||
void FunPrivileges();
|
||||
void FunRm();
|
||||
void FunNode();
|
||||
|
||||
void PostFunLogin();
|
||||
void PostFunEmacsAdd();
|
||||
void PostFunEmacsEdit(bool with_url);
|
||||
void PostFunEmacs();
|
||||
void PostFunPrivileges();
|
||||
|
||||
void RedirectTo(const Item & item);
|
||||
void RedirectTo(long item_id);
|
||||
|
||||
public:
|
||||
|
||||
bool Init();
|
||||
|
||||
void Make();
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
133
content/emacs.cpp
Executable file
133
content/emacs.cpp
Executable file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "content.h"
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::PrepareUrl(Item & item)
|
||||
{
|
||||
CorrectUrl(item);
|
||||
|
||||
if( data.functions.GetFunction(item.url) )
|
||||
{
|
||||
// the name provided by an user is the same as a name of a function
|
||||
// we add one underscore character at the beginning
|
||||
|
||||
// names of functions should not begin with an underscore '_'
|
||||
// and we can simply add one '_' at the beginning
|
||||
// and the name will be unique
|
||||
item.url.insert(item.url.begin(), '_');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::PostFunEmacsAdd()
|
||||
{
|
||||
request.session->done = Done::added_item;
|
||||
|
||||
request.is_item = true;
|
||||
|
||||
request.item.user_id = request.session->puser ? request.session->puser->id : -1;
|
||||
request.item.group_id = -1;
|
||||
request.item.privileges = 0644; // !! tymczasowo, bedzie uzyte umask
|
||||
request.item.parent_id = request.dir_table.back()->id;
|
||||
request.item.type = Item::file;
|
||||
|
||||
if( !request.HasWriteAccess(*request.dir_table.back() ) )
|
||||
throw Error(Error::permision_denied);
|
||||
|
||||
request.session->done_status = db.AddItem(request.item);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::PostFunEmacsEdit(bool with_url)
|
||||
{
|
||||
request.session->done = Done::edited_item;
|
||||
|
||||
if( !request.HasWriteAccess(request.item) )
|
||||
throw Error(Error::permision_denied);
|
||||
|
||||
request.session->done_status = db.EditItemById(request.item, with_url);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::PostFunEmacs()
|
||||
{
|
||||
try
|
||||
{
|
||||
// these old values are ignored (if exists)
|
||||
request.item.url = request.PostVar("url");
|
||||
request.item.subject = request.PostVar("subject");
|
||||
request.item.content = request.PostVar("content");
|
||||
|
||||
bool with_url = false;
|
||||
|
||||
if( !request.is_item || request.PostVar("old_url") != request.item.url )
|
||||
with_url = true;
|
||||
|
||||
PrepareUrl(request.item);
|
||||
|
||||
if( request.is_item )
|
||||
PostFunEmacsEdit(with_url);
|
||||
else
|
||||
PostFunEmacsAdd();
|
||||
}
|
||||
catch(const Error & e)
|
||||
{
|
||||
request.session->done_status = e;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if( request.session->done_status == Error::ok )
|
||||
{
|
||||
request.session->item = request.item;
|
||||
request.session->done_timer = 2;
|
||||
RedirectTo(request.item);
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Content: PostFunEmacs: Error: " << request.session->done_status << logend;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::FunEmacs()
|
||||
{
|
||||
if( !request.is_item )
|
||||
{
|
||||
// adding a new item
|
||||
if( !request.HasReadWriteAccess(*request.dir_table.back()) )
|
||||
request.status = Error::permision_denied;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// editing an existing item
|
||||
if( !request.HasReadWriteAccess(request.item) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
51
content/login.cpp
Executable file
51
content/login.cpp
Executable file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "content.h"
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::PostFunLogin()
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string & login = request.PostVar("login");
|
||||
std::string & pass = request.PostVar("password");
|
||||
long user_id;
|
||||
|
||||
if( db.CheckUser(login, pass, user_id) )
|
||||
{
|
||||
request.session->puser = data.users.GetUser(user_id);
|
||||
|
||||
if( !request.session->puser )
|
||||
{
|
||||
log << log1 << "Content: user: " << login << " is in the database but is not in data.users" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
log << log2 << "User " << login << " (id: " << user_id << ") logged" << logend;
|
||||
|
||||
if( request.is_item )
|
||||
{
|
||||
RedirectTo(request.item);
|
||||
}
|
||||
else
|
||||
{
|
||||
RedirectTo(*request.dir_table.back());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(const Error &)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
45
content/logout.cpp
Executable file
45
content/logout.cpp
Executable file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "content.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::FunLogout()
|
||||
{
|
||||
if( request.session->puser )
|
||||
{
|
||||
log << log2 << "User: " << request.session->puser->name << ", id: " << request.session->puser->id << " logged out" << logend;
|
||||
|
||||
request.session->puser = 0;
|
||||
}
|
||||
|
||||
request.result = Request::redirect;
|
||||
std::string path;
|
||||
|
||||
data.dirs.MakePath(request.dir_table.back()->id, path);
|
||||
|
||||
request.str = data.base_url + path;
|
||||
|
||||
if( request.is_item )
|
||||
request.str += request.item.url;
|
||||
|
||||
request.session->done = Done::loggedout;
|
||||
request.session->done_timer = 2;
|
||||
}
|
||||
|
||||
|
||||
47
content/ls.cpp
Executable file
47
content/ls.cpp
Executable file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "content.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::FunLs()
|
||||
{
|
||||
if( request.is_item )
|
||||
{
|
||||
// we're showing only the item
|
||||
request.item_table.push_back( request.item );
|
||||
return;
|
||||
}
|
||||
|
||||
// we're showing the whole directory
|
||||
Item item_ref;
|
||||
|
||||
item_ref.parent_id = request.dir_table.back()->id;
|
||||
|
||||
// !! zrobic inna metode, inny interfejs (jako parametr niech bierze parent_id), i zeby nie odczytywala contentu i subjectu (a moze tylko subject? przyda sie przy ls -l)
|
||||
db.GetItems(request.item_table, item_ref);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
30
content/node.cpp
Executable file
30
content/node.cpp
Executable file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "content.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::FunNode()
|
||||
{
|
||||
if( request.param_table.empty() )
|
||||
{
|
||||
//request.status = Error
|
||||
//!!zglosic 404
|
||||
return;
|
||||
}
|
||||
|
||||
long id = atol( request.param_table[0]->c_str() );
|
||||
|
||||
RedirectTo(id);
|
||||
}
|
||||
|
||||
83
content/privileges.cpp
Executable file
83
content/privileges.cpp
Executable file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "content.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::PostFunPrivileges()
|
||||
{
|
||||
// !! narazie tylko dla plikow
|
||||
if( !request.is_item )
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
long user_id = data.users.GetUserId( request.PostVar("user") );
|
||||
long group_id = data.groups.GetGroupId( request.PostVar("group") );
|
||||
int privileges = strtol( request.PostVar("privileges").c_str() , 0, 8);
|
||||
|
||||
if( !request.CanChangeUser(request.item, user_id) )
|
||||
throw Error(Error::cant_change_user);
|
||||
|
||||
if( !request.CanChangeGroup(request.item, group_id) )
|
||||
throw Error(Error::cant_change_group);
|
||||
|
||||
if( !request.CanChangePrivileges(request.item, privileges) )
|
||||
throw Error(Error::cant_change_privileges);
|
||||
|
||||
request.item.user_id = user_id;
|
||||
request.item.group_id = group_id;
|
||||
request.item.privileges = privileges;
|
||||
|
||||
request.session->done = Done::privileged_item;
|
||||
request.session->done_status = db.EditPrivById(request.item, request.item.id);
|
||||
}
|
||||
catch(const Error & e)
|
||||
{
|
||||
log << log1 << "Content: FunChmod: Error: " << e << logend;
|
||||
request.session->done_status = e;
|
||||
}
|
||||
|
||||
if( request.session->done_status == Error::ok )
|
||||
{
|
||||
request.session->item = request.item;
|
||||
request.session->done_timer = 2;
|
||||
RedirectTo(request.item);
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Content: PostFunPrivileges: Error: " << static_cast<int>(request.session->done_status) << logend;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::FunPrivileges()
|
||||
{
|
||||
if( !request.is_item )
|
||||
{
|
||||
// !! chwilowi tylko dla plikow
|
||||
request.status == Error::item_required;
|
||||
return;
|
||||
}
|
||||
|
||||
// you must be an owner of the item (or a superuser)
|
||||
// !! moze wykorzystac request.CanChangeUser() ?
|
||||
if( !request.session->puser || (!request.session->puser->super_user && request.session->puser->id != request.item.user_id) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
69
content/rm.cpp
Executable file
69
content/rm.cpp
Executable file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "content.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::FunRm()
|
||||
{
|
||||
// !! narazie usuwanie tylko dla plikow
|
||||
|
||||
if( !request.is_item )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
return;
|
||||
}
|
||||
|
||||
if( !request.HasWriteAccess(*request.dir_table.back()) || !request.HasWriteAccess(request.item) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if( request.param_table.empty() )
|
||||
{
|
||||
// we'll put some information about the deleted item (on the next page)
|
||||
request.session->item = request.item;
|
||||
|
||||
// !! zmienic interfejs dla db.DelItem
|
||||
if( db.DelItem( request.item ) )
|
||||
{
|
||||
request.session->done_status = Error::ok;
|
||||
log << log2 << "Content: deleted item: subject: " << request.item.subject << ", id: " << request.item.id << logend;
|
||||
}
|
||||
else
|
||||
{
|
||||
request.session->done_status = Error::db_no_item;
|
||||
}
|
||||
|
||||
request.session->done = Done::deleted_item;
|
||||
request.result = Request::redirect;
|
||||
|
||||
RedirectTo(*request.dir_table.back());
|
||||
|
||||
request.session->done_timer = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( request.IsParam("potwierdz") )
|
||||
{
|
||||
//request.result = Request::del_item_confirm;
|
||||
}
|
||||
else
|
||||
request.result = Request::err404;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user