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-0013d4bc506epull/3/head 0.2.0
parent
fac60a197b
commit
3e328932fc
@ -1,51 +1,53 @@
|
||||
CC = g++
|
||||
o = data.o content.o log.o sessionmanager.o requestcontroller.o dircontainer.o session.o main.o done.o request.o misc.o templates.o httpsimpleparser.o db.o error.o db_itemcolumns.o users.o config.o dirs.o groups.o confparser.o ezc.o
|
||||
CFLAGS = -Wall -pedantic -g -I/usr/local/include -L/usr/local/lib
|
||||
name = cmslu.fcgi
|
||||
|
||||
export CC
|
||||
export CFLAGS
|
||||
|
||||
all: $(name) $(mod_cms)
|
||||
|
||||
$(name): $(o)
|
||||
g++ -o $(name) $(CFLAGS) $(o) -lfcgi -lpq
|
||||
all: $(name)
|
||||
|
||||
|
||||
|
||||
|
||||
.SUFFIXES: .cpp .o
|
||||
$(name): core content confparser templates ezc
|
||||
g++ -o $(name) $(CFLAGS) core/core.a content/content.a confparser/confparser.a templates/templates.a ../ezc/src/ezc.a -lfcgi -lpq
|
||||
|
||||
.cpp.o:
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
|
||||
|
||||
core: FORCE
|
||||
@cd core ; $(MAKE) -e
|
||||
|
||||
data.o: core/data.cpp core/data.h core/misc.h core/log.h core/item.h core/error.h core/dirs.h core/db.h core/dircontainer.h core/user.h core/group.h core/ugcontainer.h core/users.h core/groups.h
|
||||
content.o: core/content.cpp core/content.h core/templates.h core/../../ezc/src/ezc.h core/data.h core/misc.h core/log.h core/item.h core/error.h core/dirs.h core/db.h core/dircontainer.h core/user.h core/group.h core/ugcontainer.h core/users.h core/groups.h core/request.h core/requesttypes.h core/session.h core/done.h core/getparser.h core/httpsimpleparser.h core/postparser.h core/cookieparser.h
|
||||
log.o: core/log.cpp core/log.h
|
||||
sessionmanager.o: core/sessionmanager.cpp core/sessionmanager.h core/request.h core/requesttypes.h core/log.h core/session.h core/error.h core/item.h core/done.h core/user.h core/getparser.h core/httpsimpleparser.h core/postparser.h core/cookieparser.h core/data.h core/misc.h core/dirs.h core/db.h core/dircontainer.h core/group.h core/ugcontainer.h core/users.h core/groups.h
|
||||
requestcontroller.o: core/requestcontroller.cpp core/requestcontroller.h core/data.h core/misc.h core/log.h core/item.h core/error.h core/dirs.h core/db.h core/dircontainer.h core/user.h core/group.h core/ugcontainer.h core/users.h core/groups.h core/request.h core/requesttypes.h core/session.h core/done.h core/getparser.h core/httpsimpleparser.h core/postparser.h core/cookieparser.h core/content.h core/templates.h core/../../ezc/src/ezc.h core/sessionmanager.h
|
||||
dircontainer.o: core/dircontainer.cpp core/dircontainer.h core/item.h core/log.h
|
||||
session.o: core/session.cpp core/session.h core/requesttypes.h core/error.h core/log.h core/item.h core/done.h core/user.h
|
||||
main.o: core/main.cpp core/requestcontroller.h core/data.h core/misc.h core/log.h core/item.h core/error.h core/dirs.h core/db.h core/dircontainer.h core/user.h core/group.h core/ugcontainer.h core/users.h core/groups.h core/request.h core/requesttypes.h core/session.h core/done.h core/getparser.h core/httpsimpleparser.h core/postparser.h core/cookieparser.h core/content.h core/templates.h core/../../ezc/src/ezc.h core/sessionmanager.h core/config.h core/../confparser/confparser.h
|
||||
done.o: core/done.cpp core/done.h
|
||||
request.o: core/request.cpp core/request.h core/requesttypes.h core/log.h core/session.h core/error.h core/item.h core/done.h core/user.h core/getparser.h core/httpsimpleparser.h core/postparser.h core/cookieparser.h
|
||||
misc.o: core/misc.cpp core/misc.h core/log.h core/item.h
|
||||
templates.o: core/templates.cpp core/templates.h core/../../ezc/src/ezc.h core/data.h core/misc.h core/log.h core/item.h core/error.h core/dirs.h core/db.h core/dircontainer.h core/user.h core/group.h core/ugcontainer.h core/users.h core/groups.h core/request.h core/requesttypes.h core/session.h core/done.h core/getparser.h core/httpsimpleparser.h core/postparser.h core/cookieparser.h
|
||||
httpsimpleparser.o: core/httpsimpleparser.cpp core/httpsimpleparser.h
|
||||
db.o: core/db.cpp core/db.h core/log.h core/item.h core/misc.h core/error.h core/dircontainer.h core/user.h core/group.h core/ugcontainer.h
|
||||
error.o: core/error.cpp core/error.h core/log.h
|
||||
db_itemcolumns.o: core/db_itemcolumns.cpp core/db.h core/log.h core/item.h core/misc.h core/error.h core/dircontainer.h core/user.h core/group.h core/ugcontainer.h
|
||||
users.o: core/users.cpp core/users.h core/user.h core/db.h core/log.h core/item.h core/misc.h core/error.h core/dircontainer.h core/group.h core/ugcontainer.h
|
||||
config.o: core/config.cpp core/config.h core/../confparser/confparser.h core/error.h core/log.h core/data.h core/misc.h core/item.h core/dirs.h core/db.h core/dircontainer.h core/user.h core/group.h core/ugcontainer.h core/users.h core/groups.h
|
||||
dirs.o: core/dirs.cpp core/dirs.h core/item.h core/error.h core/log.h core/db.h core/misc.h core/dircontainer.h core/user.h core/group.h core/ugcontainer.h
|
||||
groups.o: core/groups.cpp core/groups.h core/group.h core/db.h core/log.h core/item.h core/misc.h core/error.h core/dircontainer.h core/user.h core/ugcontainer.h
|
||||
templates: FORCE
|
||||
@cd templates ; $(MAKE) -e
|
||||
|
||||
confparser.o: confparser/confparser.cpp confparser/confparser.h
|
||||
confparser: FORCE
|
||||
@cd confparser ; $(MAKE) -e
|
||||
|
||||
content: FORCE
|
||||
@cd content ; $(MAKE) -e
|
||||
|
||||
ezc: FORCE
|
||||
@cd ../ezc/src ; $(MAKE) -e
|
||||
|
||||
ezc.o: ../ezc/src/ezc.cpp ../ezc/src/ezc.h
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
@cd core ; $(MAKE) -e clean
|
||||
@cd templates ; $(MAKE) -e clean
|
||||
@cd confparser ; $(MAKE) -e clean
|
||||
@cd content ; $(MAKE) -e clean
|
||||
@cd ../ezc/src ; $(MAKE) -e clean
|
||||
rm -f $(name)
|
||||
|
||||
|
||||
|
||||
FORCE:
|
||||
|
||||
|
||||
|
||||
depend:
|
||||
cd core ; $(MAKE) -e depend
|
||||
cd templates ; $(MAKE) -e depend
|
||||
cd confparser ; $(MAKE) -e depend
|
||||
cd content ; $(MAKE) -e depend
|
||||
cd ../ezc/src ; $(MAKE) -e depend
|
||||
|
@ -0,0 +1,29 @@
|
||||
o = confparser.o
|
||||
|
||||
|
||||
|
||||
all: confparser.a
|
||||
|
||||
|
||||
confparser.a: $(o)
|
||||
ar rcs confparser.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
|
||||
|
@ -0,0 +1,3 @@
|
||||
# DO NOT DELETE
|
||||
|
||||
confparser.o: confparser.h
|
@ -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
|
@ -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
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -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
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -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 &)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,26 @@
|
||||
o = data.o log.o sessionmanager.o requestcontroller.o dircontainer.o session.o main.o done.o request.o misc.o httpsimpleparser.o db.o error.o db_itemcolumns.o users.o config.o dirs.o groups.o function.o functionparser.o functions.o
|
||||
|
||||
|
||||
|
||||
all: core.a
|
||||
|
||||
core.a: $(o)
|
||||
ar rcs core.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
|
@ -0,0 +1,61 @@
|
||||
# DO NOT DELETE
|
||||
|
||||
config.o: config.h ../confparser/confparser.h error.h log.h data.h misc.h
|
||||
config.o: item.h dirs.h db.h dircontainer.h user.h group.h ugcontainer.h
|
||||
config.o: users.h groups.h functions.h function.h
|
||||
data.o: data.h misc.h log.h item.h error.h dirs.h db.h dircontainer.h user.h
|
||||
data.o: group.h ugcontainer.h users.h groups.h functions.h function.h
|
||||
db.o: db.h log.h item.h misc.h error.h dircontainer.h user.h group.h
|
||||
db.o: ugcontainer.h
|
||||
db_itemcolumns.o: db.h log.h item.h misc.h error.h dircontainer.h user.h
|
||||
db_itemcolumns.o: group.h ugcontainer.h
|
||||
dircontainer.o: dircontainer.h item.h log.h
|
||||
dirs.o: dirs.h item.h error.h log.h db.h misc.h dircontainer.h user.h group.h
|
||||
dirs.o: ugcontainer.h
|
||||
done.o: done.h
|
||||
error.o: error.h log.h
|
||||
function.o: function.h log.h item.h
|
||||
functionparser.o: functionparser.h request.h requesttypes.h log.h session.h
|
||||
functionparser.o: error.h item.h done.h user.h getparser.h httpsimpleparser.h
|
||||
functionparser.o: postparser.h cookieparser.h function.h data.h misc.h dirs.h
|
||||
functionparser.o: db.h dircontainer.h group.h ugcontainer.h users.h groups.h
|
||||
functionparser.o: functions.h
|
||||
functions.o: functions.h function.h log.h item.h
|
||||
groups.o: groups.h group.h db.h log.h item.h misc.h error.h dircontainer.h
|
||||
groups.o: user.h ugcontainer.h
|
||||
httpsimpleparser.o: httpsimpleparser.h
|
||||
log.o: log.h
|
||||
main.o: requestcontroller.h data.h misc.h log.h item.h error.h dirs.h db.h
|
||||
main.o: dircontainer.h user.h group.h ugcontainer.h users.h groups.h
|
||||
main.o: functions.h function.h request.h requesttypes.h session.h done.h
|
||||
main.o: getparser.h httpsimpleparser.h postparser.h cookieparser.h
|
||||
main.o: ../content/content.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||
main.o: ../core/data.h ../core/request.h ../core/item.h ../core/db.h
|
||||
main.o: ../core/error.h ../core/user.h ../core/group.h ../core/users.h
|
||||
main.o: ../core/groups.h ../core/log.h ../core/misc.h ../core/function.h
|
||||
main.o: ../core/functionparser.h sessionmanager.h config.h
|
||||
main.o: ../confparser/confparser.h
|
||||
misc.o: misc.h log.h item.h
|
||||
request.o: request.h requesttypes.h log.h session.h error.h item.h done.h
|
||||
request.o: user.h getparser.h httpsimpleparser.h postparser.h cookieparser.h
|
||||
request.o: function.h
|
||||
requestcontroller.o: requestcontroller.h data.h misc.h log.h item.h error.h
|
||||
requestcontroller.o: dirs.h db.h dircontainer.h user.h group.h ugcontainer.h
|
||||
requestcontroller.o: users.h groups.h functions.h function.h request.h
|
||||
requestcontroller.o: requesttypes.h session.h done.h getparser.h
|
||||
requestcontroller.o: httpsimpleparser.h postparser.h cookieparser.h
|
||||
requestcontroller.o: ../content/content.h ../templates/templates.h
|
||||
requestcontroller.o: ../../ezc/src/ezc.h ../core/data.h ../core/request.h
|
||||
requestcontroller.o: ../core/item.h ../core/db.h ../core/error.h
|
||||
requestcontroller.o: ../core/user.h ../core/group.h ../core/users.h
|
||||
requestcontroller.o: ../core/groups.h ../core/log.h ../core/misc.h
|
||||
requestcontroller.o: ../core/function.h ../core/functionparser.h
|
||||
requestcontroller.o: sessionmanager.h
|
||||
session.o: session.h requesttypes.h error.h log.h item.h done.h user.h
|
||||
sessionmanager.o: sessionmanager.h request.h requesttypes.h log.h session.h
|
||||
sessionmanager.o: error.h item.h done.h user.h getparser.h httpsimpleparser.h
|
||||
sessionmanager.o: postparser.h cookieparser.h function.h data.h misc.h dirs.h
|
||||
sessionmanager.o: db.h dircontainer.h group.h ugcontainer.h users.h groups.h
|
||||
sessionmanager.o: functions.h
|
||||
users.o: users.h user.h db.h log.h item.h misc.h error.h dircontainer.h
|
||||
users.o: group.h ugcontainer.h
|
@ -1,570 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::AddItem()
|
||||
{
|
||||
try
|
||||
{
|
||||
request.session->done = Done::added_item;
|
||||
|
||||
if( !request.session->puser || !request.session->puser->super_user )
|
||||
// !! chwilowo tylko super user moze
|
||||
throw Error(Error::permision_denied);
|
||||
|
||||
request.item.user_id = data.users.GetUserId( request.PostVar("user") );
|
||||
request.item.group_id = data.groups.GetGroupId( request.PostVar("group") );
|
||||
request.item.privileges = strtol( request.PostVar("privileges").c_str() , 0, 8);
|
||||
request.item.subject = request.PostVar("subject");
|
||||
request.item.content = request.PostVar("content");
|
||||
request.item.parent_id = data.dirs.GetDirId( request.PostVar("directory") );
|
||||
request.item.type = Item::file;
|
||||
PrepareUrlSubject(request.item);
|
||||
|
||||
request.session->done_status = db.AddItem(request.item);
|
||||
request.session->done_timer = 2;
|
||||
request.session->item = request.item;
|
||||
|
||||
RedirectTo(request.item);
|
||||
|
||||
}
|
||||
catch(const Error & e)
|
||||
{
|
||||
log << log1 << "Content: AddItem: Error: " << e << logend;
|
||||
request.session->done_status = e;
|
||||
request.session->done_timer = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::AssertPrivileges(Item & old_item, Item & new_item)
|
||||
{
|
||||
if( !request.CanChangeUser(old_item, new_item.user_id) )
|
||||
throw Error(Error::cant_change_user);
|
||||
|
||||
if( !request.CanChangeGroup(old_item, new_item.group_id) )
|
||||
throw Error(Error::cant_change_group);
|
||||
|
||||
if( !request.CanChangePrivileges(old_item, new_item.privileges) )
|
||||
throw Error(Error::cant_change_privileges);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::EditItem()
|
||||
{
|
||||
try
|
||||
{
|
||||
request.session->done = Done::edited_item;
|
||||
|
||||
request.item.id = atol( request.PostVar("id").c_str() );
|
||||
request.item.user_id = data.users.GetUserId( request.PostVar("user") );
|
||||
request.item.group_id = data.groups.GetGroupId( request.PostVar("group") );
|
||||
request.item.privileges = strtol( request.PostVar("privileges").c_str() , 0, 8);
|
||||
request.item.subject = request.PostVar("subject");
|
||||
request.item.content = request.PostVar("content");
|
||||
|
||||
bool with_subject = false;
|
||||
|
||||
if( request.PostVar(& |