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:
parent
fac60a197b
commit
3e328932fc
74
Makefile
74
Makefile
|
@ -1,51 +1,53 @@
|
||||||
CC = g++
|
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
|
CFLAGS = -Wall -pedantic -g -I/usr/local/include -L/usr/local/lib
|
||||||
name = cmslu.fcgi
|
name = cmslu.fcgi
|
||||||
|
|
||||||
|
export CC
|
||||||
all: $(name) $(mod_cms)
|
export CFLAGS
|
||||||
|
|
||||||
$(name): $(o)
|
|
||||||
g++ -o $(name) $(CFLAGS) $(o) -lfcgi -lpq
|
|
||||||
|
|
||||||
|
|
||||||
|
all: $(name)
|
||||||
|
|
||||||
.SUFFIXES: .cpp .o
|
|
||||||
|
|
||||||
.cpp.o:
|
|
||||||
$(CC) -c $(CFLAGS) $<
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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
|
$(name): core content confparser templates ezc
|
||||||
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
|
g++ -o $(name) $(CFLAGS) core/core.a content/content.a confparser/confparser.a templates/templates.a ../ezc/src/ezc.a -lfcgi -lpq
|
||||||
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
|
|
||||||
|
|
||||||
confparser.o: confparser/confparser.cpp confparser/confparser.h
|
|
||||||
|
|
||||||
ezc.o: ../ezc/src/ezc.cpp ../ezc/src/ezc.h
|
|
||||||
|
core: FORCE
|
||||||
|
@cd core ; $(MAKE) -e
|
||||||
|
|
||||||
|
templates: FORCE
|
||||||
|
@cd templates ; $(MAKE) -e
|
||||||
|
|
||||||
|
confparser: FORCE
|
||||||
|
@cd confparser ; $(MAKE) -e
|
||||||
|
|
||||||
|
content: FORCE
|
||||||
|
@cd content ; $(MAKE) -e
|
||||||
|
|
||||||
|
ezc: FORCE
|
||||||
|
@cd ../ezc/src ; $(MAKE) -e
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
clean:
|
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)
|
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
|
|
@ -20,27 +20,31 @@ Config::Config()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//!! czy tu w ogole mozemy uzywac log << ?
|
||||||
|
//!! przeciez jeszcze nie zostal przetworzony plik konfiguracyjny
|
||||||
|
|
||||||
|
|
||||||
void Config::ShowError()
|
void Config::ShowError()
|
||||||
{
|
{
|
||||||
|
|
||||||
switch( conf_parser.status )
|
switch( conf_parser.status )
|
||||||
{
|
{
|
||||||
case ConfParser::ok:
|
case ConfParser::ok:
|
||||||
log << log2 << "config syntax ok" << logend;
|
log << log2 << "Config: syntax ok" << logend;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ConfParser::cant_open_file:
|
case ConfParser::cant_open_file:
|
||||||
if( errors_to_stdout )
|
if( errors_to_stdout )
|
||||||
std::cout << "cant open a config file: " << data.config_file << std::endl;
|
std::cout << "Config: cant open a config file: " << data.config_file << std::endl;
|
||||||
|
|
||||||
log << log1 << "cant open a config file: " << data.config_file << logend;
|
log << log1 << "Config: cant open a config file: " << data.config_file << logend;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ConfParser::syntax_error:
|
case ConfParser::syntax_error:
|
||||||
if( errors_to_stdout )
|
if( errors_to_stdout )
|
||||||
std::cout << "syntax error a config file: line " << conf_parser.line << std::endl;
|
std::cout << "Config: syntax error, line: " << conf_parser.line << std::endl;
|
||||||
|
|
||||||
log << log1 << "config file: syntax error: line " << conf_parser.line << logend;
|
log << log1 << "Config: syntax error, line: " << conf_parser.line << logend;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,11 +60,11 @@ bool Config::ReadConfig(bool errors_to_stdout_)
|
||||||
|
|
||||||
if( data.config_file.empty() )
|
if( data.config_file.empty() )
|
||||||
{
|
{
|
||||||
log << log2 << "name of the config file is empty" << logend;
|
log << log2 << "Config: name of the config file is empty" << logend;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
log << log2 << "reading config file" << logend;
|
log << log2 << "Config: reading a config file" << logend;
|
||||||
|
|
||||||
ConfParser::Status status = conf_parser.Parse( data.config_file.c_str() );
|
ConfParser::Status status = conf_parser.Parse( data.config_file.c_str() );
|
||||||
|
|
||||||
|
@ -102,6 +106,9 @@ void Config::AssignValues()
|
||||||
data.db_user = Text("db_user");
|
data.db_user = Text("db_user");
|
||||||
data.db_pass = Text("db_pass");
|
data.db_pass = Text("db_pass");
|
||||||
data.base_url = Text("base_url");
|
data.base_url = Text("base_url");
|
||||||
|
|
||||||
|
NoLastSlash(data.base_url);
|
||||||
|
|
||||||
data.one_item_is_showed = Bool("one_item_is_showed");
|
data.one_item_is_showed = Bool("one_item_is_showed");
|
||||||
|
|
||||||
data.priv_no_user = Text("priv_no_user");
|
data.priv_no_user = Text("priv_no_user");
|
||||||
|
@ -117,11 +124,11 @@ std::string & Config::Text(const char * name)
|
||||||
|
|
||||||
if( i == conf_parser.table.end() )
|
if( i == conf_parser.table.end() )
|
||||||
{
|
{
|
||||||
log << log2 << "warning: " << name << " is not defined in the config, default will be: \"" << default_str << "\"" << logend;
|
log << log2 << "Config: warning: " << name << " is not defined in the config, default will be: \"" << default_str << "\"" << logend;
|
||||||
return default_str;
|
return default_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
//log << log3 << name << "=" << i->second << logend;
|
log << log3 << "Config: " << name << "=" << i->second << logend;
|
||||||
|
|
||||||
return i->second;
|
return i->second;
|
||||||
}
|
}
|
||||||
|
@ -135,12 +142,12 @@ int Config::Int(const char * name)
|
||||||
|
|
||||||
if( i == conf_parser.table.end() || i->second.empty() )
|
if( i == conf_parser.table.end() || i->second.empty() )
|
||||||
{
|
{
|
||||||
log << log2 << "warning: " << name << " is not defined in the config, default will be: " << default_int << logend;
|
log << log2 << "Config: warning: " << name << " is not defined in the config, default will be: " << default_int << logend;
|
||||||
return default_int;
|
return default_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
long res = (i->second[0] == '0')? strtol(i->second.c_str() + 1, 0, 8) : strtol(i->second.c_str(), 0, 10);
|
long res = (i->second[0] == '0')? strtol(i->second.c_str() + 1, 0, 8) : strtol(i->second.c_str(), 0, 10);
|
||||||
log << log3 << name << "=" << res << logend;
|
log << log3 << "Config: " << name << "=" << res << logend;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -153,7 +160,7 @@ bool Config::Bool(const char * name)
|
||||||
|
|
||||||
if( i == conf_parser.table.end() )
|
if( i == conf_parser.table.end() )
|
||||||
{
|
{
|
||||||
log << log2 << "warning: " << name << " is not defined in the config, default will be: " << (default_bool?"true":"false") << logend;
|
log << log2 << "Config: warning: " << name << " is not defined in the config, default will be: " << (default_bool?"true":"false") << logend;
|
||||||
return default_int;
|
return default_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +169,7 @@ bool Config::Bool(const char * name)
|
||||||
if( i->second == "true" || i->second == "1" || i->second == "yes" )
|
if( i->second == "true" || i->second == "1" || i->second == "yes" )
|
||||||
res = true;
|
res = true;
|
||||||
|
|
||||||
log << log3 << name << "=" << (res?"true":"false") << logend;
|
log << log3 << "Config: " << name << "=" << (res?"true":"false") << logend;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -170,13 +177,23 @@ return res;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Config::NoLastSlash(std::string & s)
|
||||||
|
{
|
||||||
|
if( s.empty() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
log << log2 << "Config: removing the last slash from: " << s << logend;
|
||||||
|
|
||||||
|
if( *(--s.end()) == '/' )
|
||||||
|
s.erase(--s.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
class Config
|
class Config
|
||||||
{
|
{
|
||||||
|
@ -44,6 +46,9 @@ private:
|
||||||
|
|
||||||
|
|
||||||
bool errors_to_stdout;
|
bool errors_to_stdout;
|
||||||
|
|
||||||
|
void NoLastSlash(std::string & s);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
570
core/content.cpp
570
core/content.cpp
|
@ -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("old_subject") != request.item.subject )
|
|
||||||
with_subject = true;
|
|
||||||
|
|
||||||
request.item.parent_id = data.dirs.GetDirId( request.PostVar("directory") ); // !! moze nie byc takiego, zglosic komunikat
|
|
||||||
request.item.type = Item::file;
|
|
||||||
PrepareUrlSubject(request.item);
|
|
||||||
|
|
||||||
Item old_item;
|
|
||||||
db.GetPriv(old_item, request.item.id);
|
|
||||||
AssertPrivileges(old_item, request.item);
|
|
||||||
|
|
||||||
if( !request.HasWriteAccess(old_item) )
|
|
||||||
throw Error(Error::permision_denied);
|
|
||||||
|
|
||||||
request.session->done_status = db.EditItemById(request.item, with_subject);
|
|
||||||
}
|
|
||||||
catch(const Error & e)
|
|
||||||
{
|
|
||||||
log << log1 << "Content: EditItem: Error: " << e << logend;
|
|
||||||
request.session->done_status = e;
|
|
||||||
}
|
|
||||||
|
|
||||||
request.session->item = request.item;
|
|
||||||
request.session->done_timer = 2;
|
|
||||||
RedirectTo(request.item);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Content::LogUser()
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
request.session->is_logged = true;
|
|
||||||
request.session->user_id = user_id;
|
|
||||||
|
|
||||||
|
|
||||||
log << log2 << "User " << login << " (id: " << user_id << ") logged" << logend;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(const Error &)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Content::MakeDirectoryStructure()
|
|
||||||
{
|
|
||||||
GetTable::size_type get_table_len = request.get_table.size();
|
|
||||||
get_index = 0;
|
|
||||||
request.dir = -1;
|
|
||||||
|
|
||||||
Item * pdir;
|
|
||||||
if( !data.dirs.GetRootDir(&pdir) )
|
|
||||||
// there is no a root dir
|
|
||||||
return;
|
|
||||||
|
|
||||||
request.dir = pdir->id;
|
|
||||||
|
|
||||||
for( ; get_index < get_table_len ; ++get_index)
|
|
||||||
{
|
|
||||||
if( !data.dirs.GetDir(request.get_table[get_index], pdir->id, &pdir) )
|
|
||||||
break;
|
|
||||||
|
|
||||||
request.cur_dir_table.push_back( *pdir );
|
|
||||||
}
|
|
||||||
|
|
||||||
request.dir = pdir->id;
|
|
||||||
data.dirs.GetDirChilds(request.dir, request.dir_table);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Request::Result Content::StandardFunction(std::string & name)
|
|
||||||
{
|
|
||||||
Request::Result res = Request::err404;
|
|
||||||
|
|
||||||
// language polish
|
|
||||||
// in the future there'll be something here
|
|
||||||
// names of functions should not begin with an underscore '_'
|
|
||||||
|
|
||||||
if( name == "dodaj" )
|
|
||||||
res = Request::add_item;
|
|
||||||
else
|
|
||||||
if( name == "edytuj" )
|
|
||||||
res = Request::edit_item;
|
|
||||||
else
|
|
||||||
if( name == "id" )
|
|
||||||
res = Request::show_item_by_id;
|
|
||||||
else
|
|
||||||
if( name == "usun" )
|
|
||||||
res = Request::del_item;
|
|
||||||
else
|
|
||||||
if( name == "potwierdz" )
|
|
||||||
res = Request::confirm;
|
|
||||||
else
|
|
||||||
if( name == "wyloguj" )
|
|
||||||
res = Request::logout;
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Content::PrepareUrlSubject(Item & item)
|
|
||||||
{
|
|
||||||
SetUrlSubjectFromSubject(item);
|
|
||||||
|
|
||||||
if( StandardFunction(item.url) != Request::err404 )
|
|
||||||
{
|
|
||||||
// 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(), '_');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Content::MakeGetCheckDir()
|
|
||||||
{
|
|
||||||
if( get_index == request.get_table.size() )
|
|
||||||
{
|
|
||||||
// request was for a directory
|
|
||||||
|
|
||||||
////
|
|
||||||
if( !request.cur_dir_table.empty() && !request.HasReadAccess(request.cur_dir_table.back()) )
|
|
||||||
{
|
|
||||||
request.result = Request::err_per_denied;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
////
|
|
||||||
|
|
||||||
|
|
||||||
db.GetItems(request.item_table, item);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// !! temporarily
|
|
||||||
long default_id = -1;
|
|
||||||
if( request.cur_dir_table.empty() )
|
|
||||||
{
|
|
||||||
//default_id = data.dirs.root.default_item;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
default_id = request.cur_dir_table.back().default_item;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if( default_id != -1 )
|
|
||||||
{
|
|
||||||
request.result = Request::show_item;
|
|
||||||
|
|
||||||
std::vector<Item>::iterator i;
|
|
||||||
for(i = request.item_table.begin() ; i != request.item_table.end() ; ++i)
|
|
||||||
{
|
|
||||||
if( i->id == default_id )
|
|
||||||
request.item_table[0] = *i;
|
|
||||||
}
|
|
||||||
|
|
||||||
request.item_table.resize(1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
|
|
||||||
if( data.one_item_is_showed &&
|
|
||||||
request.item_table.size() == 1 &&
|
|
||||||
request.item_table[0].type == Item::file )
|
|
||||||
{
|
|
||||||
request.result = Request::show_item;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
request.result = Request::show_dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// zrobic tak ze gdzie podajemy cala liste aby nie ladowac contentu z bazy danych do itemow
|
|
||||||
void Content::MakeGet()
|
|
||||||
{
|
|
||||||
MakeDirectoryStructure();
|
|
||||||
|
|
||||||
item.Clear();
|
|
||||||
|
|
||||||
// request.dir is set by MakeDirectoryStructure()
|
|
||||||
item.parent_id = request.dir;
|
|
||||||
|
|
||||||
if( MakeGetCheckDir() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
// request was for an item or a standard function
|
|
||||||
request.result = StandardFunction( request.get_table[get_index] );
|
|
||||||
|
|
||||||
if( request.result != Request::err404 )
|
|
||||||
{
|
|
||||||
// request for a standard function
|
|
||||||
++get_index;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( request.get_table[get_index].empty() )
|
|
||||||
// we do not have an empty url
|
|
||||||
// err404 at the end
|
|
||||||
return;
|
|
||||||
|
|
||||||
// if we want to search by url then request.get_table[get_index] should not be empty
|
|
||||||
item.url = request.get_table[get_index++];
|
|
||||||
db.GetItems(request.item_table, item);
|
|
||||||
|
|
||||||
if( request.item_table.empty() )
|
|
||||||
// err404 at the end
|
|
||||||
return;
|
|
||||||
|
|
||||||
////
|
|
||||||
if( request.HasReadAccess(request.item_table[0]) )// !! tymczasowo dla 0 tylko
|
|
||||||
request.result = Request::show_item;
|
|
||||||
else
|
|
||||||
request.result = Request::err_per_denied;
|
|
||||||
////
|
|
||||||
|
|
||||||
if( get_index == request.get_table.size() )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// there is a standard function at the end
|
|
||||||
request.result = StandardFunction( request.get_table[get_index++] );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Content::MakeAddItem()
|
|
||||||
{
|
|
||||||
if( !request.session->puser )
|
|
||||||
{
|
|
||||||
// not logged
|
|
||||||
request.item.Clear();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
request.item.user_id = request.session->puser->id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Content::MakeEditItem()
|
|
||||||
{
|
|
||||||
if( !request.item_table.empty() )
|
|
||||||
request.item = request.item_table[0];
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log << log1 << "Content: request.item_table should not be empty" << logend;
|
|
||||||
request.result = Request::err404;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Content::AppendCurDir(std::string & dir)
|
|
||||||
{
|
|
||||||
std::vector<Item>::size_type a;
|
|
||||||
|
|
||||||
for(a=0 ; a<request.cur_dir_table.size() ; ++a)
|
|
||||||
{
|
|
||||||
dir += request.cur_dir_table[a].url;
|
|
||||||
dir += '/';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Content::MakeShowItemById()
|
|
||||||
{
|
|
||||||
if( get_index == request.get_table.size() )
|
|
||||||
{
|
|
||||||
request.result = Request::err404;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
long id = atol( request.get_table[get_index++].c_str() );
|
|
||||||
db.GetItem(request.item_table, id);
|
|
||||||
|
|
||||||
if( request.item_table.empty() )
|
|
||||||
request.result = Request::err404;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RedirectTo(request.item_table[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Content::MakeDelItem()
|
|
||||||
{
|
|
||||||
if( request.item_table.empty() )
|
|
||||||
{
|
|
||||||
request.result = Request::err404;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if( !request.session->puser || !request.session->puser->super_user )
|
|
||||||
// !! chwilowo tylko super user moze
|
|
||||||
{
|
|
||||||
|
|
||||||
request.result = Request::err_per_denied;
|
|
||||||
request.CopyFirstItem();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if( get_index == request.get_table.size() )
|
|
||||||
{
|
|
||||||
request.CopyFirstItem();
|
|
||||||
request.session->item = request.item;
|
|
||||||
|
|
||||||
if( db.DelItem( request.item ) )
|
|
||||||
{
|
|
||||||
request.session->done = Done::deleted_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 = Done::deleted_item;
|
|
||||||
request.session->done_status = Error::db_no_item;
|
|
||||||
}
|
|
||||||
|
|
||||||
request.result = Request::redirect;
|
|
||||||
request.str = data.base_url;
|
|
||||||
AppendCurDir(request.str);
|
|
||||||
request.session->done_timer = 2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if( StandardFunction( request.get_table[get_index++] ) == Request::confirm )
|
|
||||||
{
|
|
||||||
request.result = Request::del_item_confirm;
|
|
||||||
request.CopyFirstItem();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
request.result = Request::err404;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Content::MakeLogout()
|
|
||||||
{
|
|
||||||
if( request.session->is_logged )
|
|
||||||
{
|
|
||||||
log << log2 << "User id: " << request.session->user_id << " logged out" << logend;
|
|
||||||
|
|
||||||
request.session->is_logged = false;
|
|
||||||
request.session->user_id = 0;
|
|
||||||
request.session->puser = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
request.result = Request::redirect;
|
|
||||||
std::string path;
|
|
||||||
data.dirs.MakePath(request.dir, path);
|
|
||||||
request.str = data.base_url + path;
|
|
||||||
|
|
||||||
if( !request.item_table.empty() )
|
|
||||||
request.str += request.item_table[0].url;
|
|
||||||
|
|
||||||
request.session->done = Done::loggedout;
|
|
||||||
request.session->done_timer = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Content::MakeStandardFunction()
|
|
||||||
{
|
|
||||||
if( request.result == Request::add_item )
|
|
||||||
{
|
|
||||||
MakeAddItem();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if( request.result == Request::edit_item )
|
|
||||||
{
|
|
||||||
MakeEditItem();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if( request.result == Request::show_item_by_id )
|
|
||||||
{
|
|
||||||
MakeShowItemById();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if( request.result == Request::del_item )
|
|
||||||
{
|
|
||||||
MakeDelItem();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if( request.result == Request::logout )
|
|
||||||
{
|
|
||||||
MakeLogout();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Content::MakePost()
|
|
||||||
{
|
|
||||||
if( request.IsPostVar("add_item") )
|
|
||||||
AddItem();
|
|
||||||
else
|
|
||||||
if( request.IsPostVar("edit_item") )
|
|
||||||
EditItem();
|
|
||||||
else
|
|
||||||
if( request.IsPostVar("logging") )
|
|
||||||
LogUser();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Content::Make()
|
|
||||||
{
|
|
||||||
MakePost();
|
|
||||||
|
|
||||||
if( request.result == Request::redirect )
|
|
||||||
return;
|
|
||||||
|
|
||||||
MakeGet();
|
|
||||||
MakeStandardFunction();
|
|
||||||
|
|
||||||
templates.Generate();
|
|
||||||
|
|
||||||
//request.PrintGetTable();
|
|
||||||
//request.PrintEnv();
|
|
||||||
//request.PrintIn();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Content::RedirectTo(const Item & item)
|
|
||||||
{
|
|
||||||
std::string path;
|
|
||||||
|
|
||||||
request.result = Request::redirect;
|
|
||||||
data.dirs.MakePath(item.parent_id, path);
|
|
||||||
request.str = data.base_url + path + item.url;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,79 +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.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfilecontent
|
|
||||||
#define headerfilecontent
|
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <fcgiapp.h>
|
|
||||||
|
|
||||||
#include "templates.h"
|
|
||||||
#include "request.h"
|
|
||||||
#include "error.h"
|
|
||||||
#include "misc.h"
|
|
||||||
#include "db.h"
|
|
||||||
#include "user.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Content
|
|
||||||
{
|
|
||||||
// index to request.get_table
|
|
||||||
// set after calling MakeDirectoryStructure()
|
|
||||||
// index of the last item which is not a directory (or is equal get_table.size())
|
|
||||||
GetTable::size_type get_index;
|
|
||||||
|
|
||||||
|
|
||||||
// temporarily object used for some purposes
|
|
||||||
Item item;
|
|
||||||
|
|
||||||
|
|
||||||
Templates templates;
|
|
||||||
|
|
||||||
|
|
||||||
void AssertPrivileges(Item & old_item, Item & new_item);
|
|
||||||
|
|
||||||
void AddItem();
|
|
||||||
void EditItem();
|
|
||||||
void LogUser();
|
|
||||||
|
|
||||||
void MakeDirectoryStructure();
|
|
||||||
Request::Result StandardFunction(std::string & name);
|
|
||||||
void PrepareUrlSubject(Item & item);
|
|
||||||
bool MakeGetCheckDir();
|
|
||||||
|
|
||||||
void MakeAddItem();
|
|
||||||
void MakeEditItem();
|
|
||||||
void MakeShowItemById();
|
|
||||||
void MakeDelItem();
|
|
||||||
void MakeLogout();
|
|
||||||
void MakeStandardFunction();
|
|
||||||
|
|
||||||
|
|
||||||
void AppendCurDir(std::string & dir);
|
|
||||||
|
|
||||||
void MakePost();
|
|
||||||
void MakeGet();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void RedirectTo(const Item & item);
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
bool Init();
|
|
||||||
|
|
||||||
void Make();
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "dirs.h"
|
#include "dirs.h"
|
||||||
#include "users.h"
|
#include "users.h"
|
||||||
#include "groups.h"
|
#include "groups.h"
|
||||||
|
#include "functions.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,6 +76,7 @@ public:
|
||||||
// if there is one item in a directory
|
// if there is one item in a directory
|
||||||
// it will be showed
|
// it will be showed
|
||||||
// (instead of showing directory contents)
|
// (instead of showing directory contents)
|
||||||
|
// !! wywalic to, nie bedzie uzywane
|
||||||
bool one_item_is_showed;
|
bool one_item_is_showed;
|
||||||
|
|
||||||
// string used in a place where is a user (or group) selected
|
// string used in a place where is a user (or group) selected
|
||||||
|
@ -111,6 +112,10 @@ public:
|
||||||
// groups
|
// groups
|
||||||
Groups groups;
|
Groups groups;
|
||||||
|
|
||||||
|
// functions (ls, cat, etc)
|
||||||
|
Functions functions;
|
||||||
|
|
||||||
|
|
||||||
Data();
|
Data();
|
||||||
|
|
||||||
|
|
||||||
|
|
73
core/db.cpp
73
core/db.cpp
|
@ -485,7 +485,7 @@ return result;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// !! with_subject zamienic na with_url
|
||||||
Error Db::EditItemInItem(Item & item, bool with_subject)
|
Error Db::EditItemInItem(Item & item, bool with_subject)
|
||||||
{
|
{
|
||||||
PGresult * r = 0;
|
PGresult * r = 0;
|
||||||
|
@ -634,6 +634,8 @@ return result;
|
||||||
|
|
||||||
|
|
||||||
// item.id must be set
|
// item.id must be set
|
||||||
|
// !! with_subject zamienic na with_url
|
||||||
|
// !! moze nazwa poprostu EditItem (nie trzeba tego ById) ? (sprawdzic czy nie koliduje z inna nazwa)
|
||||||
Error Db::EditItemById(Item & item, bool with_subject)
|
Error Db::EditItemById(Item & item, bool with_subject)
|
||||||
{
|
{
|
||||||
Error result = EditItemGetContentId(item);
|
Error result = EditItemGetContentId(item);
|
||||||
|
@ -760,6 +762,44 @@ void Db::GetItem(std::vector<Item> & item_table, long id)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// !! nowy interfejs
|
||||||
|
Error Db::GetItem(long parent_id, const std::string & url, Item & item)
|
||||||
|
{
|
||||||
|
PGresult * r = 0;
|
||||||
|
Error result = Error::ok;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
AssertConnection();
|
||||||
|
|
||||||
|
std::ostringstream query;
|
||||||
|
query << "select * from core.item left join core.content on item.content_id = content.id where type='1' and item.parent_id='";
|
||||||
|
query << parent_id << "' and item.url='" << Escape(url) << "';";
|
||||||
|
|
||||||
|
r = AssertQuery( query.str() );
|
||||||
|
AssertResultStatus(r, PGRES_TUPLES_OK);
|
||||||
|
|
||||||
|
int rows = PQntuples(r);
|
||||||
|
|
||||||
|
if( rows == 0 )
|
||||||
|
throw Error(Error::db_no_item);
|
||||||
|
|
||||||
|
ItemColumns col;
|
||||||
|
col.SetColumns(r);
|
||||||
|
col.SetItem(r, 0, item);
|
||||||
|
}
|
||||||
|
catch(const Error & e)
|
||||||
|
{
|
||||||
|
result = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClearResult(r);
|
||||||
|
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Db::GetPriv(Item & item, long id)
|
bool Db::GetPriv(Item & item, long id)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
@ -797,6 +837,37 @@ return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// !! to jest nowy interfejs, z jawnym podaniem id
|
||||||
|
Error Db::EditPrivById(Item & item, long id)
|
||||||
|
{
|
||||||
|
PGresult * r = 0;
|
||||||
|
Error result = Error::ok;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
AssertConnection();
|
||||||
|
std::ostringstream query;
|
||||||
|
query << "update core.item set (user_id, group_id, privileges) = (";
|
||||||
|
query << '\'' << item.user_id << "', ";
|
||||||
|
query << '\'' << item.group_id << "', ";
|
||||||
|
query << '\'' << item.privileges << "' ";
|
||||||
|
|
||||||
|
query << ") where id='" << id << "';";
|
||||||
|
|
||||||
|
r = AssertQuery(query.str());
|
||||||
|
AssertResultStatus(r, PGRES_COMMAND_OK);
|
||||||
|
}
|
||||||
|
catch(const Error & e)
|
||||||
|
{
|
||||||
|
result = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClearResult(r);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Db::DelItemDelItem(const Item & item)
|
bool Db::DelItemDelItem(const Item & item)
|
||||||
|
|
|
@ -45,11 +45,15 @@ public:
|
||||||
void GetItems(std::vector<Item> & item_table, Item & item_ref);
|
void GetItems(std::vector<Item> & item_table, Item & item_ref);
|
||||||
void GetItem(std::vector<Item> & item_table, long id);
|
void GetItem(std::vector<Item> & item_table, long id);
|
||||||
bool GetPriv(Item & item, long id);
|
bool GetPriv(Item & item, long id);
|
||||||
|
Error EditPrivById(Item & item, long id);
|
||||||
|
|
||||||
bool DelItem(const Item & item);
|
bool DelItem(const Item & item);
|
||||||
void GetDirs(DirContainer & dir_table);
|
void GetDirs(DirContainer & dir_table);
|
||||||
void GetUsers(UGContainer<User> & user_table);
|
void GetUsers(UGContainer<User> & user_table);
|
||||||
void GetGroups(UGContainer<Group> & group_table);
|
void GetGroups(UGContainer<Group> & group_table);
|
||||||
|
|
||||||
|
// !! nowy interfejs
|
||||||
|
Error GetItem(long parent_id, const std::string & url, Item & item);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -179,6 +179,18 @@ return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Dirs::GetDirChilds(long parent, std::vector<Item*> & childs_table)
|
||||||
|
{
|
||||||
|
if( parent != -1 && !IsDir(parent) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent);
|
||||||
|
|
||||||
|
for( ; i != dir_table.ParentEnd() ; i = dir_table.NextParent(i) )
|
||||||
|
childs_table.push_back( &(*i->second) );
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -213,7 +225,7 @@ DirContainer::Iterator i;
|
||||||
|
|
||||||
// with exceptions
|
// with exceptions
|
||||||
|
|
||||||
Item * Dirs::GetDir(const std::string & path)
|
Item * Dirs::GetDirT(const std::string & path)
|
||||||
{
|
{
|
||||||
Item * pitem;
|
Item * pitem;
|
||||||
|
|
||||||
|
@ -224,7 +236,7 @@ return pitem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Item * Dirs::GetDir(const std::string & name, long parent)
|
Item * Dirs::GetDirT(const std::string & name, long parent)
|
||||||
{
|
{
|
||||||
Item * pitem;
|
Item * pitem;
|
||||||
|
|
||||||
|
@ -236,7 +248,7 @@ return pitem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
long Dirs::GetDirId(const std::string & path)
|
long Dirs::GetDirIdT(const std::string & path)
|
||||||
{
|
{
|
||||||
long id;
|
long id;
|
||||||
|
|
||||||
|
@ -247,7 +259,7 @@ return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
long Dirs::GetDirId(const std::string & name, long parent)
|
long Dirs::GetDirIdT(const std::string & name, long parent)
|
||||||
{
|
{
|
||||||
long id;
|
long id;
|
||||||
|
|
||||||
|
@ -259,3 +271,67 @@ return id;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// !! nowy interfejs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Item * Dirs::GetRootDir()
|
||||||
|
{
|
||||||
|
DirContainer::Iterator root = dir_table.GetRoot();
|
||||||
|
|
||||||
|
if( root == dir_table.End() )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return &(*root);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Item * Dirs::GetDir(const std::string & name, long parent)
|
||||||
|
{
|
||||||
|
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent);
|
||||||
|
|
||||||
|
for( ; i!=dir_table.ParentEnd() ; i = dir_table.NextParent(i) )
|
||||||
|
if( i->second->url == name )
|
||||||
|
return &(*i->second);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Item * Dirs::GetDir(const std::string & path)
|
||||||
|
{
|
||||||
|
DirContainer::Iterator root = dir_table.GetRoot();
|
||||||
|
|
||||||
|
if( root == dir_table.End() )
|
||||||
|
// ops, we do not have a root dir
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
Item * pitem = &(*root);
|
||||||
|
|
||||||
|
std::string name;
|
||||||
|
const char * s = path.c_str();
|
||||||
|
|
||||||
|
while( ExtractName(s, name) )
|
||||||
|
{
|
||||||
|
pitem = GetDir(name, pitem->id);
|
||||||
|
|
||||||
|
if( !pitem )
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return pitem;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Item * Dirs::GetDir(long id)
|
||||||
|
{
|
||||||
|
DirContainer::Iterator i = dir_table.FindId(id);
|
||||||
|
|
||||||
|
if( i == dir_table.End() )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return &(*i);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
21
core/dirs.h
21
core/dirs.h
|
@ -56,17 +56,32 @@ public:
|
||||||
bool GetDirId(const std::string & path, long * id);
|
bool GetDirId(const std::string & path, long * id);
|
||||||
bool GetDirId(const std::string & name, long parent, long * id);
|
bool GetDirId(const std::string & name, long parent, long * id);
|
||||||
|
|
||||||
|
//!! ta nie bedzie chyba potrzebna
|
||||||
bool GetDirChilds(long parent, std::vector<Item> & childs_table); // only returns dir-children
|
bool GetDirChilds(long parent, std::vector<Item> & childs_table); // only returns dir-children
|
||||||
|
|
||||||
|
bool GetDirChilds(long parent, std::vector<Item*> & childs_table); // only returns dir-children
|
||||||
|
|
||||||
bool MakePath(long id, std::string & path);
|
bool MakePath(long id, std::string & path);
|
||||||
|
|
||||||
|
|
||||||
// with an Error exception
|
// with an Error exception
|
||||||
// if the path or name are invalid these methods throw an exception
|
// if the path or name are invalid these methods throw an exception
|
||||||
Item * GetDir(const std::string & path);
|
Item * GetDirT(const std::string & path);
|
||||||
|
Item * GetDirT(const std::string & name, long parent);
|
||||||
|
long GetDirIdT(const std::string & path);
|
||||||
|
long GetDirIdT(const std::string & name, long parent);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// !! nowy interfejs
|
||||||
|
|
||||||
|
// returns null if there is no a root dir
|
||||||
|
Item * GetRootDir();
|
||||||
Item * GetDir(const std::string & name, long parent);
|
Item * GetDir(const std::string & name, long parent);
|
||||||
long GetDirId(const std::string & path);
|
Item * GetDir(const std::string & path);
|
||||||
long GetDirId(const std::string & name, long parent);
|
Item * GetDir(long id);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -40,3 +40,8 @@ bool Done::operator!=(Code c) const
|
||||||
return code != c;
|
return code != c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Done::operator int()
|
||||||
|
{
|
||||||
|
return static_cast<int>( code );
|
||||||
|
}
|
||||||
|
|
|
@ -12,17 +12,18 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// what have been done
|
// what has been done
|
||||||
class Done
|
class Done
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum Code
|
enum Code
|
||||||
{
|
{
|
||||||
none,
|
none = 0,
|
||||||
added_item,
|
added_item,
|
||||||
edited_item,
|
edited_item,
|
||||||
deleted_item,
|
deleted_item,
|
||||||
|
privileged_item,
|
||||||
loggedout
|
loggedout
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,7 +34,8 @@ public:
|
||||||
bool operator==(Code c) const;
|
bool operator==(Code c) const;
|
||||||
bool operator!=(Code c) const;
|
bool operator!=(Code c) const;
|
||||||
|
|
||||||
|
operator int();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Code code;
|
Code code;
|
||||||
|
|
|
@ -63,6 +63,16 @@ bool Error::operator!=(Code c) const
|
||||||
return code != c;
|
return code != c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Error::operator==(const Error & e) const
|
||||||
|
{
|
||||||
|
return code == e.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Error::operator!=(const Error & e) const
|
||||||
|
{
|
||||||
|
return code != e.code;
|
||||||
|
}
|
||||||
|
|
||||||
std::ostream & operator<<(std::ostream & out, const Error & e)
|
std::ostream & operator<<(std::ostream & out, const Error & e)
|
||||||
{
|
{
|
||||||
|
|
17
core/error.h
17
core/error.h
|
@ -29,17 +29,21 @@ public:
|
||||||
db_incorrect_query,
|
db_incorrect_query,
|
||||||
db_incorrent_result_status,
|
db_incorrent_result_status,
|
||||||
db_no_column,
|
db_no_column,
|
||||||
db_no_item,
|
db_no_item, // !! zamienic na no_item
|
||||||
db_incorrect_login,
|
db_incorrect_login,
|
||||||
db_more_than_one_login,
|
db_more_than_one_login,
|
||||||
db_err_currval,
|
db_err_currval,
|
||||||
no_cookie,
|
no_postvar,
|
||||||
incorrect_dir,
|
incorrect_dir,
|
||||||
cant_change_user,
|
cant_change_user,
|
||||||
cant_change_group,
|
cant_change_group,
|
||||||
cant_change_privileges,
|
cant_change_privileges,
|
||||||
permision_denied,
|
permision_denied, // !! permission_denied (dwa ss)
|
||||||
|
no_root_dir,
|
||||||
|
no_function, // !! zamienic na no_function
|
||||||
|
|
||||||
|
item_required, // !! zamienic na no_item (i usunac db_no_item)
|
||||||
|
|
||||||
unknown = 1000
|
unknown = 1000
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,6 +61,8 @@ public:
|
||||||
|
|
||||||
bool operator==(Code c) const;
|
bool operator==(Code c) const;
|
||||||
bool operator!=(Code c) const;
|
bool operator!=(Code c) const;
|
||||||
|
bool operator==(const Error & e) const;
|
||||||
|
bool operator!=(const Error & e) const;
|
||||||
|
|
||||||
friend std::ostream & operator<<(std::ostream & out, const Error & e);
|
friend std::ostream & operator<<(std::ostream & out, const Error & e);
|
||||||
friend Log & operator<<(Log & out, const Error & e);
|
friend Log & operator<<(Log & out, const Error & e);
|
||||||
|
@ -70,10 +76,5 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
std::ostream & operator<<(std::ostream & out, const Error & e);
|
|
||||||
Log & operator<<(Log & out, const Error & e);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* 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 "function.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Function::Function()
|
||||||
|
{
|
||||||
|
code = none;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Function::Function(const Function & f)
|
||||||
|
{
|
||||||
|
code = f.code;
|
||||||
|
item = f.item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Function & Function::operator=(const Function & f)
|
||||||
|
{
|
||||||
|
code = f.code;
|
||||||
|
item = f.item;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* 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 headerfilefunction
|
||||||
|
#define headerfilefunction
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include "log.h"
|
||||||
|
#include "item.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Function
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
enum Code
|
||||||
|
{
|
||||||
|
none,
|
||||||
|
ls,
|
||||||
|
cat,
|
||||||
|
node,
|
||||||
|
emacs,
|
||||||
|
privileges,
|
||||||
|
rm,
|
||||||
|
login,
|
||||||
|
logout
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Code code;
|
||||||
|
Item item;
|
||||||
|
|
||||||
|
|
||||||
|
Function();
|
||||||
|
Function(const Function & f);
|
||||||
|
Function & operator=(const Function & f);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,181 @@
|
||||||
|
/*
|
||||||
|
* 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 "functionparser.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void FunctionParser::SkipEmptyString(const char * msg)
|
||||||
|
{
|
||||||
|
for( ; get_index != get_table_len && request.get_table[get_index].empty() ; ++get_index )
|
||||||
|
log << log3 << msg << logend;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void FunctionParser::ParseDirectories()
|
||||||
|
{
|
||||||
|
Item * pdir = data.dirs.GetRootDir();
|
||||||
|
|
||||||
|
if( !pdir )
|
||||||
|
{
|
||||||
|
// there is no the root dir
|
||||||
|
request.status = Error::no_root_dir;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while( true )
|
||||||
|
{
|
||||||
|
request.dir_table.push_back( pdir );
|
||||||
|
log << log3 << "FP: Directory: ";
|
||||||
|
|
||||||
|
if( pdir->parent_id == -1 )
|
||||||
|
log << "(root)" << logend;
|
||||||
|
else
|
||||||
|
log << pdir->url << logend;
|
||||||
|
|
||||||
|
SkipEmptyString("FP: Directory: skipped empty string");
|
||||||
|
|
||||||
|
if( get_index == get_table_len )
|
||||||
|
break;
|
||||||
|
|
||||||
|
pdir = data.dirs.GetDir(request.get_table[get_index], pdir->id);
|
||||||
|
|
||||||
|
if( !pdir )
|
||||||
|
break;
|
||||||
|
|
||||||
|
++get_index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void FunctionParser::ParseItem()
|
||||||
|
{
|
||||||
|
SkipEmptyString("FP: Item: skipped empty string");
|
||||||
|
|
||||||
|
if( get_index == get_table_len )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// request.dir_table has at least one element
|
||||||
|
long parent_id = request.dir_table.back()->id;
|
||||||
|
const std::string & url = request.get_table[get_index];
|
||||||
|
|
||||||
|
request.status = db.GetItem(parent_id, url, request.item);
|
||||||
|
|
||||||
|
if( request.status == Error::ok )
|
||||||
|
{
|
||||||
|
++get_index;
|
||||||
|
request.is_item = true;
|
||||||
|
log << log3 << "FP: Item: id: " << request.item.id << ", url: " << request.item.url << logend;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
log << log3 << "FP: No Item: url: " << url << logend;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void FunctionParser::ParseFunction()
|
||||||
|
{
|
||||||
|
SkipEmptyString("FP: Function: skipped empty string");
|
||||||
|
|
||||||
|
if( get_index == get_table_len )
|
||||||
|
return;
|
||||||
|
|
||||||
|
request.pfunction = data.functions.GetFunction(request.get_table[get_index]);
|
||||||
|
|
||||||
|
|
||||||
|
if( request.pfunction )
|
||||||
|
{
|
||||||
|
++get_index;
|
||||||
|
log << log3 << "FP: Function: " << request.pfunction->item.url << logend;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void FunctionParser::ParseParams()
|
||||||
|
{
|
||||||
|
while( true )
|
||||||
|
{
|
||||||
|
SkipEmptyString("FP: Params: skipped empty string");
|
||||||
|
|
||||||
|
if( get_index == get_table_len )
|
||||||
|
break;
|
||||||
|
|
||||||
|
request.param_table.push_back( &request.get_table[get_index] );
|
||||||
|
log << log3 << "FP: Params: " << request.get_table[get_index] << logend;
|
||||||
|
|
||||||
|
++get_index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void FunctionParser::Parse()
|
||||||
|
{
|
||||||
|
request.status = Error::ok;
|
||||||
|
get_index = 0;
|
||||||
|
get_table_len = request.get_table.size();
|
||||||
|
request.pfunction = 0;
|
||||||
|
request.is_item = false;
|
||||||
|
|
||||||
|
ParseDirectories();
|
||||||
|
|
||||||
|
if( request.status != Error::ok )
|
||||||
|
return;
|
||||||
|
|
||||||
|
ParseFunction();
|
||||||
|
|
||||||
|
if( !request.pfunction )
|
||||||
|
{
|
||||||
|
ParseItem();
|
||||||
|
|
||||||
|
if( request.status != Error::ok )
|
||||||
|
return;
|
||||||
|
|
||||||
|
ParseFunction();
|
||||||
|
|
||||||
|
if( !request.pfunction && get_index != get_table_len )
|
||||||
|
{
|
||||||
|
request.status = Error::no_function;
|
||||||
|
log << log3 << "FP: Parse: unknown function: \"" << request.get_table[get_index] << "\"" << logend;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ParseParams();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef headerfilefunctionparser
|
||||||
|
#define headerfilefunctionparser
|
||||||
|
|
||||||
|
#include "request.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "item.h"
|
||||||
|
#include "error.h"
|
||||||
|
#include "data.h"
|
||||||
|
#include "db.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class FunctionParser
|
||||||
|
{
|
||||||
|
GetTable::size_type get_index;
|
||||||
|
GetTable::size_type get_table_len;
|
||||||
|
|
||||||
|
void SkipEmptyString(const char * msg);
|
||||||
|
|
||||||
|
void ParseDirectories();
|
||||||
|
void ParseItem();
|
||||||
|
void ParseFunction();
|
||||||
|
void ParseParams();
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
void Parse();
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,113 @@
|
||||||
|
/*
|
||||||
|
* 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 "functions.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Functions::Clear()
|
||||||
|
{
|
||||||
|
table.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Functions::ReadFunctions()
|
||||||
|
{
|
||||||
|
Clear();
|
||||||
|
|
||||||
|
Function f;
|
||||||
|
|
||||||
|
f.item.user_id = -1;
|
||||||
|
f.item.group_id = -1;
|
||||||
|
f.item.privileges = 0644;
|
||||||
|
f.item.parent_id = -1; // !! temporarily doesn't matter
|
||||||
|
f.item.id = -1;
|
||||||
|
f.item.type = Item::file;
|
||||||
|
|
||||||
|
// in the future we will read these functions from the database
|
||||||
|
f.code = Function::ls;
|
||||||
|
f.item.url = "list";
|
||||||
|
table.insert( std::make_pair(f.item.url, f) );
|
||||||
|
|
||||||
|
f.code = Function::cat;
|
||||||
|
f.item.url = "wyswietl";
|
||||||
|
table.insert( std::make_pair(f.item.url, f) );
|
||||||
|
|
||||||
|
f.code = Function::node;
|
||||||
|
f.item.url = "node";
|
||||||
|
table.insert( std::make_pair(f.item.url, f) );
|
||||||
|
|
||||||
|
f.code = Function::emacs;
|
||||||
|
f.item.url = "edytuj";
|
||||||
|
table.insert( std::make_pair(f.item.url, f) );
|
||||||
|
|
||||||
|
f.code = Function::privileges;
|
||||||
|
f.item.url = "uprawnienia";
|
||||||
|
table.insert( std::make_pair(f.item.url, f) );
|
||||||
|
|
||||||
|
f.code = Function::rm;
|
||||||
|
f.item.url = "usun";
|
||||||
|
table.insert( std::make_pair(f.item.url, f) );
|
||||||
|
|
||||||
|
f.code = Function::logout;
|
||||||
|
f.item.url = "wyloguj";
|
||||||
|
table.insert( std::make_pair(f.item.url, f) );
|
||||||
|
|
||||||
|
f.code = Function::login;
|
||||||
|
f.item.url = "login";
|
||||||
|
table.insert( std::make_pair(f.item.url, f) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Function * Functions::GetFunction(const std::string & name)
|
||||||
|
{
|
||||||
|
Table::iterator i = table.find(name);
|
||||||
|
|
||||||
|
if( i == table.end() )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return &(i->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// !! in the future there will be a special container where we can search through the Code object
|
||||||
|
Function * Functions::GetFunction(Function::Code code)
|
||||||
|
{
|
||||||
|
Table::iterator i = table.begin();
|
||||||
|
|
||||||
|
for( ; i != table.end() ; ++i )
|
||||||
|
{
|
||||||
|
if( i->second.code == code )
|
||||||
|
return &(i->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* 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 headerfilefunctions
|
||||||
|
#define headerfilefunctions
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include "function.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Functions
|
||||||
|
{
|
||||||
|
|
||||||
|
typedef std::map<std::string, Function> Table;
|
||||||
|
Table table;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Clear();
|
||||||
|
void ReadFunctions();
|
||||||
|
|
||||||
|
Function * GetFunction(const std::string & name);
|
||||||
|
Function * GetFunction(Function::Code code);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -25,6 +25,8 @@ void Log::Init(int log_l, const std::string & log_f, bool log_std)
|
||||||
log_stdout = log_std;
|
log_stdout = log_std;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(const char * s)
|
Log & Log::operator<<(const char * s)
|
||||||
|
|
|
@ -17,9 +17,12 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
// !! dodac manipulator logsave, logi zostana zapisane pod koniec wykonywania jednego requesta (albo po kilku w zaleznosci od jakiejs opcji w konfigu)
|
||||||
|
// logsave zostanie wywolane w requestcontroller.cpp przy konczeniu wykonywania requesta
|
||||||
enum Manipulators { logend, log1, log2, log3 };
|
enum Manipulators { logend, log1, log2, log3 };
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Log
|
class Log
|
||||||
{
|
{
|
||||||
std::ostringstream buffer;
|
std::ostringstream buffer;
|
||||||
|
@ -32,7 +35,6 @@ public:
|
||||||
Log();
|
Log();
|
||||||
|
|
||||||
void Init(int log_l, const std::string & log_f, bool log_std);
|
void Init(int log_l, const std::string & log_f, bool log_std);
|
||||||
|
|
||||||
|
|
||||||
Log & operator<<(const char * s);
|
Log & operator<<(const char * s);
|
||||||
Log & operator<<(const std::string & s);
|
Log & operator<<(const std::string & s);
|
||||||
|
|
|
@ -103,7 +103,8 @@ RequestController req_controller;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
log << log2 << "checking for table consistency:" << logend;
|
log << log2 << "checking for table consistency:" << logend;
|
||||||
db.CheckAllUrlSubject();
|
// !! zrobic wyjatek dla root
|
||||||
|
//db.CheckAllUrlSubject();
|
||||||
|
|
||||||
log << log1 << "cmslu started" << logend;
|
log << log1 << "cmslu started" << logend;
|
||||||
|
|
||||||
|
|
|
@ -31,8 +31,54 @@ static char buffer[50];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SetUrlSubjectFromSubject(Item & item)
|
|
||||||
|
bool CorrectUrlChar(char c)
|
||||||
{
|
{
|
||||||
|
if( (c >= 'a' && c <='z') ||
|
||||||
|
(c >= 'A' && c <='Z') ||
|
||||||
|
(c >= '0' && c <='9') ||
|
||||||
|
(c == '(' || c == ')' || c == '.' || c == ',' || c == '_' )
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CorrectUrl(Item & item)
|
||||||
|
{
|
||||||
|
std::string::iterator i;
|
||||||
|
|
||||||
|
for(i = item.url.begin(); i!=item.url.end() ; ++i)
|
||||||
|
{
|
||||||
|
if( !CorrectUrlChar(*i) )
|
||||||
|
{
|
||||||
|
int c = ChangeLocalChar(*i);
|
||||||
|
|
||||||
|
if( CorrectUrlChar(c) )
|
||||||
|
*i = c;
|
||||||
|
else
|
||||||
|
*i = '_';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( item.url.empty() )
|
||||||
|
item.url = "bez_nazwy"; // !! wrzucic do pliku konfiguracyjnego
|
||||||
|
else
|
||||||
|
if( item.url[0] >= '0' && item.url[0] <= '9' )
|
||||||
|
// url must begin with a letter
|
||||||
|
item.url.insert(item.url.begin(), '_');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SetUrlFromSubject(Item & item)
|
||||||
|
{
|
||||||
|
item.url = item.subject;
|
||||||
|
CorrectUrl(item);
|
||||||
|
|
||||||
|
/*
|
||||||
std::string::iterator i;
|
std::string::iterator i;
|
||||||
|
|
||||||
item.url.clear();
|
item.url.clear();
|
||||||
|
@ -59,10 +105,12 @@ std::string::iterator i;
|
||||||
if( item.url[0] >= '0' && item.url[0] <= '9' )
|
if( item.url[0] >= '0' && item.url[0] <= '9' )
|
||||||
// url must begin with a letter
|
// url must begin with a letter
|
||||||
item.url.insert(item.url.begin(), '_');
|
item.url.insert(item.url.begin(), '_');
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int polish_letters_simple[] =
|
int polish_letters_simple[] =
|
||||||
{ 'a', 'A',
|
{ 'a', 'A',
|
||||||
'c', 'C',
|
'c', 'C',
|
||||||
|
@ -108,7 +156,7 @@ return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HtmlSpecial(std::ostringstream & out, const std::string & in)
|
void HtmlEscape(std::ostringstream & out, const std::string & in)
|
||||||
{
|
{
|
||||||
std::string::const_iterator i;
|
std::string::const_iterator i;
|
||||||
|
|
||||||
|
@ -128,11 +176,11 @@ std::string::const_iterator i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string HtmlSpecial(const std::string & in)
|
std::string HtmlEscape(const std::string & in)
|
||||||
{
|
{
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
|
|
||||||
HtmlSpecial(out, in);
|
HtmlEscape(out, in);
|
||||||
|
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
12
core/misc.h
12
core/misc.h
|
@ -17,16 +17,20 @@
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
|
||||||
#define MAJOR_VER 0
|
#define MAJOR_VER 0
|
||||||
#define MINOR_VER 1
|
#define MINOR_VER 2
|
||||||
#define REVISION_VER 0
|
#define REVISION_VER 0
|
||||||
|
|
||||||
|
|
||||||
void ToString(std::string & s, int value);
|
void ToString(std::string & s, int value);
|
||||||
void ToString(std::string & s, long value);
|
void ToString(std::string & s, long value);
|
||||||
void SetUrlSubjectFromSubject(Item & item);
|
|
||||||
int ChangeLocalChar(unsigned char c);
|
int ChangeLocalChar(unsigned char c);
|
||||||
void HtmlSpecial(std::ostringstream & out, const std::string & in);
|
|
||||||
std::string HtmlSpecial(const std::string & in);
|
bool CorrectUrlChar(char c);
|
||||||
|
void CorrectUrl(Item & item);
|
||||||
|
void SetUrlFromSubject(Item & item);
|
||||||
|
|
||||||
|
void HtmlEscape(std::ostringstream & out, const std::string & in);
|
||||||
|
std::string HtmlEscape(const std::string & in);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,13 +13,18 @@
|
||||||
|
|
||||||
Request::Request() : char_empty(0)
|
Request::Request() : char_empty(0)
|
||||||
{
|
{
|
||||||
|
id = 0;
|
||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Request::Clear()
|
void Request::Clear()
|
||||||
{
|
{
|
||||||
// warning: don't clear in, out, err, env
|
// warning: don't clear: in, out, err, env
|
||||||
|
|
||||||
|
// id is never 0
|
||||||
|
if( ++id == 0 )
|
||||||
|
++id;
|
||||||
|
|
||||||
get_table.clear();
|
get_table.clear();
|
||||||
post_table.clear();
|
post_table.clear();
|
||||||
|
@ -40,15 +45,22 @@ void Request::Clear()
|
||||||
|
|
||||||
session = 0;
|
session = 0;
|
||||||
|
|
||||||
result = err404; // tutaj moze cos lepszego, cos w stylu 'not implemented'
|
result = err404; // !! tutaj moze cos lepszego, cos w stylu 'not implemented'
|
||||||
|
|
||||||
dir = -1;
|
// dir = -1;
|
||||||
cur_dir_table.clear();
|
// cur_dir_table.clear();
|
||||||
item_table.clear();
|
item_table.clear();
|
||||||
dir_table.clear();
|
// dir_table2.clear();
|
||||||
|
|
||||||
item.Clear();
|
item.Clear();
|
||||||
str.clear();
|
str.clear();
|
||||||
|
|
||||||
|
dir_table.clear();
|
||||||
|
is_item = false;
|
||||||
|
pfunction = 0;
|
||||||
|
param_table.clear();
|
||||||
|
|
||||||
|
status = Error::ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -113,14 +125,29 @@ std::string & Request::PostVar(const char * var)
|
||||||
p = post_table.find(var);
|
p = post_table.find(var);
|
||||||
|
|
||||||
if( p == post_table.end() )
|
if( p == post_table.end() )
|
||||||
throw Error(Error::no_cookie);
|
{
|
||||||
|
throw Error(Error::no_postvar);
|
||||||
|
}
|
||||||
|
|
||||||
return p->second;
|
return p->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
bool Request::PostVar(const char * var, std::string & result)
|
||||||
|
{
|
||||||
|
PostTable::iterator p;
|
||||||
|
|
||||||
|
p = post_table.find(var);
|
||||||
|
|
||||||
|
if( p == post_table.end() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
result = p->second;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -197,13 +224,12 @@ void Request::ReadEnvVariables()
|
||||||
// we store that values because FCGX_GetParam has O(n) complexity
|
// we store that values because FCGX_GetParam has O(n) complexity
|
||||||
// with this variables (env_*) we have O(1)
|
// with this variables (env_*) we have O(1)
|
||||||
|
|
||||||
env_request_method = SetEnvVar("REQUEST_METHOD");
|
env_request_method = SetEnvVar("REQUEST_METHOD");
|
||||||
env_request_uri = SetEnvVar("REQUEST_URI");
|
env_request_uri = SetEnvVar("REQUEST_URI");
|
||||||
env_http_cookie = SetEnvVar("HTTP_COOKIE");
|
env_http_cookie = SetEnvVar("HTTP_COOKIE");
|
||||||
env_remote_addr = SetEnvVar("REMOTE_ADDR");
|
env_remote_addr = SetEnvVar("REMOTE_ADDR");
|
||||||
env_http_host = SetEnvVar("HTTP_HOST");
|
env_http_host = SetEnvVar("HTTP_HOST");
|
||||||
|
env_http_user_agent = SetEnvVar("HTTP_USER_AGENT");
|
||||||
log << log1 << "IP: " << env_remote_addr << logend;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -222,7 +248,7 @@ void Request::CheckMethod()
|
||||||
|
|
||||||
void Request::ReadParameters()
|
void Request::ReadParameters()
|
||||||
{
|
{
|
||||||
// some parameters (get) we have always
|
// !!some parameters (get) we have always
|
||||||
// if( method == get )
|
// if( method == get )
|
||||||
{
|
{
|
||||||
GetParser get_parser(env_request_uri, get_table);
|
GetParser get_parser(env_request_uri, get_table);
|
||||||
|
@ -240,10 +266,30 @@ void Request::ReadParameters()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Request::StandardLog()
|
||||||
|
{
|
||||||
|
time_t t = std::time(0);
|
||||||
|
std::tm * loct = std::localtime(&t);
|
||||||
|
|
||||||
|
char buffer[70];
|
||||||
|
sprintf(buffer, "%d.%02d.%02d %02d:%02d:%02d ", int(loct->tm_year + 1900),
|
||||||
|
int(loct->tm_mon + 1),
|
||||||
|
int(loct->tm_mday),
|
||||||
|
int(loct->tm_hour),
|
||||||
|
int(loct->tm_min),
|
||||||
|
int(loct->tm_sec));
|
||||||
|
|
||||||
|
log << log1 << buffer << env_remote_addr << ' ' << env_request_method << ' ' << env_request_uri << ' ' << env_http_user_agent << logend;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// reading everything
|
// reading everything
|
||||||
void Request::Read()
|
void Request::Read()
|
||||||
{
|
{
|
||||||
ReadEnvVariables();
|
ReadEnvVariables();
|
||||||
|
StandardLog();
|
||||||
CheckMethod();
|
CheckMethod();
|
||||||
ReadParameters();
|
ReadParameters();
|
||||||
}
|
}
|
||||||
|
@ -257,7 +303,7 @@ void Request::SendAll()
|
||||||
FCGX_PutS("Status: 301 Moved Permanently\r\n", out);
|
FCGX_PutS("Status: 301 Moved Permanently\r\n", out);
|
||||||
FCGX_FPrintF(out, "Location: %s\r\n", str.c_str());
|
FCGX_FPrintF(out, "Location: %s\r\n", str.c_str());
|
||||||
|
|
||||||
log << log2 << "Redirect into: " << str << logend;
|
log << log2 << "Redirect to: " << str << logend;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -288,6 +334,21 @@ void Request::SendAll()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool Request::IsParam(const char * s)
|
||||||
|
{
|
||||||
|
std::vector<std::string*>::iterator i;
|
||||||
|
|
||||||
|
for(i=param_table.begin() ; i!=param_table.end() ; ++i)
|
||||||
|
{
|
||||||
|
if( **i == s )
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Request::CanChangeUser(const Item & item, long new_user_id)
|
bool Request::CanChangeUser(const Item & item, long new_user_id)
|
||||||
{
|
{
|
||||||
if( !session )
|
if( !session )
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
#include <fcgiapp.h>
|
#include <fcgiapp.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <ctime>
|
||||||
|
#include <iomanip>
|
||||||
#include "requesttypes.h"
|
#include "requesttypes.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
|
@ -22,10 +24,18 @@
|
||||||
#include "cookieparser.h"
|
#include "cookieparser.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
#include "function.h"
|
||||||
|
|
||||||
|
|
||||||
struct Request
|
struct Request
|
||||||
{
|
{
|
||||||
|
// request id
|
||||||
|
// is incremented for each request and is never 0
|
||||||
|
// (from -1 will be incremented twice)
|
||||||
|
// it's used for some optimalization e.g. in templates
|
||||||
|
size_t id;
|
||||||
|
|
||||||
|
|
||||||
FCGX_Stream * in, * out, * err;
|
FCGX_Stream * in, * out, * err;
|
||||||
FCGX_ParamArray env; // defined as 'char **'
|
FCGX_ParamArray env; // defined as 'char **'
|
||||||
|
|
||||||
|
@ -48,6 +58,7 @@ struct Request
|
||||||
const char * env_http_cookie;
|
const char * env_http_cookie;
|
||||||
const char * env_remote_addr;
|
const char * env_remote_addr;
|
||||||
const char * env_http_host;
|
const char * env_http_host;
|
||||||
|
const char * env_http_user_agent;
|
||||||
|
|
||||||
// current session
|
// current session
|
||||||
// is set after calling session_manager.SetSession()
|
// is set after calling session_manager.SetSession()
|
||||||
|
@ -55,29 +66,51 @@ struct Request
|
||||||
|
|
||||||
|
|
||||||
// 'done_status' is set if 'done' is different than 'nothing'
|
// 'done_status' is set if 'done' is different than 'nothing'
|
||||||
Error done_status;
|
Error done_status; // !! wywalic - jest przeciez w session
|
||||||
|
|
||||||
// what to do
|
// what to do
|
||||||
enum Result { err_internal, err404, err_per_denied, show_dir, show_item, show_item_by_id, add_item, edit_item, del_item, del_item_confirm, confirm, redirect, logout } result; // zamienic na to_do
|
enum Result { err_internal, err404, err_per_denied, show_dir, show_item, show_item_by_id, add_item, edit_item, del_item, del_item_confirm, confirm, redirect, logout } result; // zamienic na to_do
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// current directory e.g. /foo/bar
|
|
||||||
std::vector<Item> cur_dir_table;
|
// !! nowe skladowe
|
||||||
|
|
||||||
|
// current directory
|
||||||
|
// !! zapewnic aby byl minimum jeden katalog (root)
|
||||||
|
|
||||||
|
// !! moze nazwac to poprostu dir?
|
||||||
|
std::vector<Item*> dir_table;
|
||||||
|
|
||||||
|
bool is_item;
|
||||||
|
|
||||||
|
// this item is used for many purposes such as editing, adding an item etc.
|
||||||
|
Item item;
|
||||||
|
|
||||||
|
// null if there is no a function
|
||||||
|
Function * pfunction;
|
||||||
|
|
||||||
|
// !! moze nazwac to poprostu param?
|
||||||
|
std::vector<std::string*> param_table;
|
||||||
|
|
||||||
|
Error status;
|
||||||
|
|
||||||
|
// ------------------
|
||||||
|
|
||||||
|
// !! stare skladowe
|
||||||
|
// current directory e.g. /foo/bar
|
||||||
|
//std::vector<Item> cur_dir_table;
|
||||||
// id of the last directory (bar) or -1
|
// id of the last directory (bar) or -1
|
||||||
long dir;
|
//long dir;
|
||||||
|
|
||||||
|
// ------------------
|
||||||
|
|
||||||
// items in the current directory
|
// items in the current directory
|
||||||
// maybe without contents?
|
// maybe without contents?
|
||||||
std::vector<Item> item_table;
|
std::vector<Item> item_table;
|
||||||
|
|
||||||
// directories in the current directory
|
// directories in the current directory
|
||||||
std::vector<Item> dir_table;
|
//std::vector<Item> dir_table2;
|
||||||
|
|
||||||
// this item is used for many purposes such as editing, adding an item etc.
|
|
||||||
Item item;
|
|
||||||
|
|
||||||
// this string is used for many purposes such as redirecting
|
// this string is used for many purposes such as redirecting
|
||||||
std::string str;
|
std::string str;
|
||||||
|
@ -91,14 +124,17 @@ struct Request
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
|
|
||||||
|
bool IsParam(const char * s);
|
||||||
|
|
||||||
void SetCookie(const char * name, const char * value);
|
void SetCookie(const char * name, const char * value);
|
||||||
void SetCookie(const char * name, long value);
|
void SetCookie(const char * name, long value);
|
||||||
|
|
||||||
bool IsPostVar(const char * var);
|
bool IsPostVar(const char * var);
|
||||||
std::string & PostVar(const char * var); // with a throw
|
std::string & PostVar(const char * var); // with a throw
|
||||||
|
//bool PostVar(const char * var, std::string & result);
|
||||||
|
|
||||||
// item_table[0] -> item
|
// item_table[0] -> item
|
||||||
|
// !! to tez nie bedzie potrzebne
|
||||||
void CopyFirstItem();
|
void CopyFirstItem();
|
||||||
|
|
||||||
|
|
||||||
|
@ -126,6 +162,9 @@ private:
|
||||||
const char char_empty;
|
const char char_empty;
|
||||||
|
|
||||||
const char * SetEnvVar(const char * var);
|
const char * SetEnvVar(const char * var);
|
||||||
|
|
||||||
|
void StandardLog();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -99,6 +99,7 @@ bool RequestController::Init()
|
||||||
data.dirs.ReadDirs();
|
data.dirs.ReadDirs();
|
||||||
data.users.ReadUsers();
|
data.users.ReadUsers();
|
||||||
data.groups.ReadGroups();
|
data.groups.ReadGroups();
|
||||||
|
data.functions.ReadFunctions();
|
||||||
//
|
//
|
||||||
|
|
||||||
if( !content.Init() )
|
if( !content.Init() )
|
||||||
|
@ -131,7 +132,7 @@ void RequestController::Loop()
|
||||||
{
|
{
|
||||||
while( FCGX_Accept(&request.in, &request.out, &request.err, &request.env) == 0 )
|
while( FCGX_Accept(&request.in, &request.out, &request.err, &request.env) == 0 )
|
||||||
{
|
{
|
||||||
log << log2 << "start request" << logend;
|
log << log2 << "---------------------------------------------------------------------------------" << logend;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -143,13 +144,15 @@ void RequestController::Loop()
|
||||||
// and then BaseUrlRedirect() will be called (for performance)
|
// and then BaseUrlRedirect() will be called (for performance)
|
||||||
if( !BaseUrlRedirect() )
|
if( !BaseUrlRedirect() )
|
||||||
{
|
{
|
||||||
session_manager.SetSession(); // setting request.session as well
|
session_manager.SetSession(); // set request.session as well
|
||||||
request.session->CheckTimers();
|
request.session->CheckTimers();
|
||||||
|
|
||||||
|
function_parser.Parse();
|
||||||
|
|
||||||
content.Make();
|
content.Make();
|
||||||
}
|
}
|
||||||
|
|
||||||
request.SendAll();
|
request.SendAll();
|
||||||
}
|
}
|
||||||
catch(const std::exception & e)
|
catch(const std::exception & e)
|
||||||
{
|
{
|
||||||
|
@ -165,10 +168,6 @@ void RequestController::Loop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
log << log2 << "end request" << logend;
|
|
||||||
log << log2 << "---------------------------------------------------------------------------------" << logend;
|
|
||||||
|
|
||||||
|
|
||||||
// !! this should be immediately after FCGX_Accept() but signals don't want to break FCGX_Accept
|
// !! this should be immediately after FCGX_Accept() but signals don't want to break FCGX_Accept
|
||||||
if( data.signal_hup )
|
if( data.signal_hup )
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "request.h"
|
#include "request.h"
|
||||||
#include "content.h"
|
#include "../content/content.h"
|
||||||
#include "sessionmanager.h"
|
#include "sessionmanager.h"
|
||||||
#include "postparser.h"
|
#include "postparser.h"
|
||||||
#include "cookieparser.h"
|
#include "cookieparser.h"
|
||||||
|
@ -34,6 +34,8 @@ class RequestController
|
||||||
|
|
||||||
bool BaseUrlRedirect();
|
bool BaseUrlRedirect();
|
||||||
|
|
||||||
|
FunctionParser function_parser;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RequestController();
|
RequestController();
|
||||||
|
|
|
@ -22,8 +22,6 @@ void Session::Clear()
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
time = 0;
|
time = 0;
|
||||||
is_logged = false;
|
|
||||||
user_id = -1;
|
|
||||||
puser = 0;
|
puser = 0;
|
||||||
done = Done::none;
|
done = Done::none;
|
||||||
done_status = Error::ok;
|
done_status = Error::ok;
|
||||||
|
@ -31,6 +29,7 @@ void Session::Clear()
|
||||||
done_timer = 0;
|
done_timer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Session::operator==(const Session & s) const
|
bool Session::operator==(const Session & s) const
|
||||||
{
|
{
|
||||||
return id == s.id;
|
return id == s.id;
|
||||||
|
|
|
@ -22,15 +22,12 @@
|
||||||
struct Session
|
struct Session
|
||||||
{
|
{
|
||||||
// 0 - means that there is no session
|
// 0 - means that there is no session
|
||||||
long id;
|
long id;
|
||||||
|
|
||||||
|
// when this session was created
|
||||||
int time;
|
int time;
|
||||||
|
|
||||||
bool is_logged;
|
|
||||||
|
|
||||||
// !! moze tutaj -1 kiedy nie zalogowany i wywalic is_logged?
|
|
||||||
long user_id; // logged user
|
|
||||||
|
|
||||||
// !! moze wywalic user_id i zostawic tylko to? kiedy nie zalogowany to bedzie tutaj 0
|
// 0 - means that nobody is logged
|
||||||
User * puser;
|
User * puser;
|
||||||
|
|
||||||
// what is done
|
// what is done
|
||||||
|
|
|
@ -1,788 +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 "templates.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace TemplatesFunctions
|
|
||||||
{
|
|
||||||
Pattern pat_index;
|
|
||||||
Pattern pat_item;
|
|
||||||
Pattern pat_dir;
|
|
||||||
Pattern pat_item_add_edit;
|
|
||||||
Pattern pat_item_del_confirm;
|
|
||||||
Pattern pat_err_404;
|
|
||||||
Pattern pat_err_per_denied;
|
|
||||||
Pattern pat_err_internal;
|
|
||||||
|
|
||||||
Functions functions;
|
|
||||||
|
|
||||||
|
|
||||||
void is_group_tv(Info & i)
|
|
||||||
{
|
|
||||||
long gid = data.groups.GetGroupId("tv");
|
|
||||||
|
|
||||||
if( request.session->puser && request.session->puser->IsMemberOf(gid) )
|
|
||||||
i.result = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void language(Info & i)
|
|
||||||
{
|
|
||||||
// at the moment only Polish language
|
|
||||||
i.out << "pl";
|
|
||||||
}
|
|
||||||
|
|
||||||
void title(Info & i)
|
|
||||||
{
|
|
||||||
i.out << "";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void charset(Info & i)
|
|
||||||
{
|
|
||||||
i.out << "iso-8859-2";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void version_major(Info & i)
|
|
||||||
{
|
|
||||||
i.out << MAJOR_VER;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void version_minor(Info & i)
|
|
||||||
{
|
|
||||||
i.out << MINOR_VER;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void version_revision(Info & i)
|
|
||||||
{
|
|
||||||
i.out << REVISION_VER;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void user_name(Info & i)
|
|
||||||
{
|
|
||||||
User * puser = data.users.GetUser(request.session->user_id);
|
|
||||||
|
|
||||||
if( puser )
|
|
||||||
i.out << puser->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void content(Info & i)
|
|
||||||
{
|
|
||||||
Pattern * p;
|
|
||||||
|
|
||||||
switch( request.result )
|
|
||||||
{
|
|
||||||
case Request::add_item:
|
|
||||||
case Request::edit_item:
|
|
||||||
p = &pat_item_add_edit;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Request::show_dir:
|
|
||||||
p = &pat_dir;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Request::show_item:
|
|
||||||
p = &pat_item;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Request::del_item_confirm:
|
|
||||||
p = &pat_item_del_confirm;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Request::err_internal:
|
|
||||||
p = &pat_err_internal;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Request::err_per_denied:
|
|
||||||
p = &pat_err_per_denied;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Request::err404:
|
|
||||||
default:
|
|
||||||
p = &pat_err_404;
|
|
||||||
}
|
|
||||||
|
|
||||||
Generator gen(i.out, *p, functions);
|
|
||||||
|
|
||||||
gen.Generate();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void base_url(Info & i)
|
|
||||||
{
|
|
||||||
i.out << data.base_url;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void current_url(Info & i)
|
|
||||||
{
|
|
||||||
i.out << request.env_request_uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void user_logged(Info & i)
|
|
||||||
{
|
|
||||||
i.result = request.session->is_logged;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void user_super_user(Info & i)
|
|
||||||
{
|
|
||||||
if( request.session->puser && request.session->puser->super_user )
|
|
||||||
i.result = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void item_id(Info & i)
|
|
||||||
{
|
|
||||||
i.out << request.item.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
void item_subject(Info & i)
|
|
||||||
{
|
|
||||||
i.out << request.item.subject;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void item_content(Info & i)
|
|
||||||
{
|
|
||||||
i.out << request.item.content;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void item_subject_escape(Info & i)
|
|
||||||
{
|
|
||||||
i.out << HtmlSpecial(request.item.subject);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void item_content_escape(Info & i)
|
|
||||||
{
|
|
||||||
i.out << HtmlSpecial(request.item.content);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void item_privileges(Info & i)
|
|
||||||
{
|
|
||||||
i.out << std::setbase(8) << request.item.privileges << std::setbase(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void item_url_subject(Info & i) // !! zmienic nazwe
|
|
||||||
{
|
|
||||||
i.out << request.item.url;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void item_dir(Info & i)
|
|
||||||
{
|
|
||||||
std::string path;
|
|
||||||
|
|
||||||
if( data.dirs.MakePath(request.item.parent_id, path) )
|
|
||||||
{
|
|
||||||
i.out << path;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
i.out << "problem with generating a path";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ---------
|
|
||||||
|
|
||||||
|
|
||||||
void old_item_id(Info & i)
|
|
||||||
{
|
|
||||||
i.out << request.session->item.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
void old_item_subject(Info & i)
|
|
||||||
{
|
|
||||||
i.out << HtmlSpecial(request.session->item.subject);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void old_item_content(Info & i)
|
|
||||||
{
|
|
||||||
//i.out << HtmlSpecial(request.session->item.content);
|
|
||||||
i.out << request.session->item.content;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void old_item_url_subject(Info & i) // zmienic nazwe !!
|
|
||||||
{
|
|
||||||
i.out << request.session->item.url;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void old_item_dir(Info & i)
|
|
||||||
{
|
|
||||||
std::string path;
|
|
||||||
|
|
||||||
if( data.dirs.MakePath(request.session->item.parent_id, path) )
|
|
||||||
{
|
|
||||||
i.out << path;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
i.out << "problem with generating a path";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ----
|
|
||||||
|
|
||||||
void full_dir(Info & i)
|
|
||||||
{
|
|
||||||
std::vector<Item>::size_type a;
|
|
||||||
|
|
||||||
for(a=0 ; a<request.cur_dir_table.size() ; ++a)
|
|
||||||
{
|
|
||||||
i.out << request.cur_dir_table[a].url << '/';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<Item>::size_type item_index, dir_index;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void dir_items(Info & i)
|
|
||||||
{
|
|
||||||
if( i.iter >= (int)request.dir_table.size() )
|
|
||||||
{
|
|
||||||
i.result = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
i.result = true;
|
|
||||||
dir_index = i.iter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void dir_subject2(Info & i)
|
|
||||||
{
|
|
||||||
if( dir_index < request.dir_table.size() )
|
|
||||||
{
|
|
||||||
if( request.dir_table[dir_index].subject.empty() )
|
|
||||||
i.out << "bez nazwy";
|
|
||||||
else
|
|
||||||
HtmlSpecial(i.out, request.dir_table[dir_index].subject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void dir_url_subject2(Info & i) // zmienic nazwe
|
|
||||||
{
|
|
||||||
if( dir_index < request.dir_table.size() )
|
|
||||||
{
|
|
||||||
HtmlSpecial(i.out, request.dir_table[dir_index].url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void items(Info & i) // zamienic na fitems !!
|
|
||||||
{
|
|
||||||
if( i.iter >= (int)request.item_table.size() )
|
|
||||||
{
|
|
||||||
i.result = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
i.result = true;
|
|
||||||
item_index = i.iter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void item_subject2(Info & i)
|
|
||||||
{
|
|
||||||
if( item_index < request.item_table.size() )
|
|
||||||
{
|
|
||||||
if( request.item_table[item_index].subject.empty() )
|
|
||||||
i.out << "bez nazwy";
|
|
||||||
else
|
|
||||||
HtmlSpecial(i.out, request.item_table[item_index].subject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void item_url_subject2(Info & i) // !! zmienic nazwe
|
|
||||||
{
|
|
||||||
if( item_index < request.item_table.size() )
|
|
||||||
HtmlSpecial(i.out, request.item_table[item_index].url);
|
|
||||||
}
|
|
||||||
|
|
||||||
void item_content2(Info & i)
|
|
||||||
{
|
|
||||||
if( item_index < request.item_table.size() )
|
|
||||||
//HtmlSpecial(i.out, request.item_table[item_index].content);
|
|
||||||
i.out << request.item_table[item_index].content;
|
|
||||||
}
|
|
||||||
|
|
||||||
void item_id2(Info & i)
|
|
||||||
{
|
|
||||||
if( item_index < request.item_table.size() )
|
|
||||||
i.out << request.item_table[item_index].id;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void incorrect_dir(Info & i)
|
|
||||||
{
|
|
||||||
if( request.session->done_status == Error::incorrect_dir )
|
|
||||||
i.result = true;
|
|
||||||
else
|
|
||||||
i.result = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<Item>::size_type current_dir_index;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void fcurrent_dir(Info & i)
|
|
||||||
{
|
|
||||||
if( i.iter < (int)request.cur_dir_table.size() )
|
|
||||||
{
|
|
||||||
current_dir_index = i.iter;
|
|
||||||
i.result = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
i.result = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void current_dir_part_link(Info & i)
|
|
||||||
{
|
|
||||||
std::vector<Item>::size_type a;
|
|
||||||
|
|
||||||
i.out << data.base_url;
|
|
||||||
|
|
||||||
for(a = 0 ; a <= current_dir_index && a < request.cur_dir_table.size() ; ++a)
|
|
||||||
{
|
|
||||||
i.out << request.cur_dir_table[a].url << '/';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void current_dir_part_url(Info & i)
|
|
||||||
{
|
|
||||||
if( current_dir_index < request.cur_dir_table.size() )
|
|
||||||
i.out << request.cur_dir_table[current_dir_index].url;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void edit_item(Info & i)
|
|
||||||
{
|
|
||||||
i.result = request.result == Request::edit_item;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void added_item(Info &i)
|
|
||||||
{
|
|
||||||
i.result = request.session->done == Done::added_item;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void edited_item(Info &i)
|
|
||||||
{
|
|
||||||
i.result = request.session->done == Done::edited_item;
|
|
||||||
}
|
|
||||||
|
|
||||||
void deleted_item(Info &i)
|
|
||||||
{
|
|
||||||
i.result = request.session->done == Done::deleted_item;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// zostawic tylko jedna funkcje done_with_errors (bedzie uzywana do roznych celow) !!
|
|
||||||
void deleted_item_errors(Info & i)
|
|
||||||
{
|
|
||||||
i.result = request.session->done_status != Error::ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void done_with_errors(Info & i)
|
|
||||||
{
|
|
||||||
i.result = request.session->done_status != Error::ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void done_status(Info & i)
|
|
||||||
{
|
|
||||||
i.out << static_cast<int>( request.session->done_status );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void fitems_in_dir(Info & i)
|
|
||||||
{
|
|
||||||
// i.out << "abc: " << variables["fitems_directory"];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void loggedout(Info & i)
|
|
||||||
{
|
|
||||||
i.result = request.session->done == Done::loggedout;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<long> fgroup_table;
|
|
||||||
size_t fgroup_index;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void fitem_group_initializing()
|
|
||||||
{
|
|
||||||
fgroup_table.clear();
|
|
||||||
|
|
||||||
if( !request.session->puser )
|
|
||||||
{
|
|
||||||
// not logged
|
|
||||||
fgroup_table.push_back(request.item.group_id);
|
|
||||||
}
|
|
||||||
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)
|
|
||||||
fgroup_table.push_back( data.groups[i].id );
|
|
||||||
|
|
||||||
// as well to -1
|
|
||||||
fgroup_table.push_back(-1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if( request.session->puser->id == request.item.user_id )
|
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
fgroup_table.push_back( request.session->puser->groups[i] );
|
|
||||||
|
|
||||||
if( request.item.group_id == request.session->puser->groups[i] )
|
|
||||||
was_current_group = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// we're showing the item.group_id if it's different
|
|
||||||
if( !was_current_group )
|
|
||||||
fgroup_table.push_back(request.item.group_id);
|
|
||||||
|
|
||||||
// switching to -1 is allowed too
|
|
||||||
fgroup_table.push_back(-1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// not the owner and not a super user -- the same as not logged
|
|
||||||
fgroup_table.push_back(request.item.group_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void fitem_group(Info & i)
|
|
||||||
{
|
|
||||||
if( i.iter == 0 )
|
|
||||||
fitem_group_initializing();
|
|
||||||
|
|
||||||
fgroup_index = i.iter;
|
|
||||||
i.result = fgroup_index < fgroup_table.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void fitem_group_name(Info & i)
|
|
||||||
{
|
|
||||||
if( fgroup_index < fgroup_table.size() )
|
|
||||||
{
|
|
||||||
long gid = fgroup_table[fgroup_index];
|
|
||||||
|
|
||||||
if( gid != -1 )
|
|
||||||
{
|
|
||||||
Group * pgroup = data.groups.GetGroup( gid );
|
|
||||||
|
|
||||||
if( pgroup )
|
|
||||||
i.out << pgroup->name;
|
|
||||||
else
|
|
||||||
i.out << "group_id: " << gid;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
i.out << data.priv_no_group;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void fitem_group_default(Info & i)
|
|
||||||
{
|
|
||||||
if( fgroup_index < fgroup_table.size() )
|
|
||||||
{
|
|
||||||
long gid = fgroup_table[fgroup_index];
|
|
||||||
|
|
||||||
if( gid == request.item.group_id )
|
|
||||||
i.result = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<long> fuser_table;
|
|
||||||
size_t fuser_index;
|
|
||||||
|
|
||||||
|
|
||||||
void fitem_user_initializing()
|
|
||||||
{
|
|
||||||
fuser_table.clear();
|
|
||||||
|
|
||||||
if( !request.session->puser )
|
|
||||||
{
|
|
||||||
// not logged
|
|
||||||
fuser_table.push_back(request.item.user_id);
|
|
||||||
}
|
|
||||||
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)
|
|
||||||
fuser_table.push_back( data.users[i].id );
|
|
||||||
|
|
||||||
// as well to -1
|
|
||||||
fuser_table.push_back(-1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// others
|
|
||||||
fuser_table.push_back(request.item.user_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void fitem_user(Info & i)
|
|
||||||
{
|
|
||||||
if( i.iter == 0 )
|
|
||||||
fitem_user_initializing();
|
|
||||||
|
|
||||||
fuser_index = i.iter;
|
|
||||||
i.result = fuser_index < fuser_table.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void fitem_user_name(Info & i)
|
|
||||||
{
|
|
||||||
if( fuser_index < fuser_table.size() )
|
|
||||||
{
|
|
||||||
long uid = fuser_table[fuser_index];
|
|
||||||
|
|
||||||
if( uid != -1 )
|
|
||||||
{
|
|
||||||
User * puser = data.users.GetUser( uid );
|
|
||||||
|
|
||||||
if( puser )
|
|
||||||
i.out << puser->name;
|
|
||||||
else
|
|
||||||
i.out << "user_id: " << uid;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
i.out << data.priv_no_user;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void fitem_user_default(Info & i)
|
|
||||||
{
|
|
||||||
if( fuser_index < fuser_table.size() )
|
|
||||||
{
|
|
||||||
long uid = fuser_table[fuser_index];
|
|
||||||
|
|
||||||
if( uid == request.item.user_id )
|
|
||||||
i.result = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace TemplatesFunctions
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Templates::CreateFunctions()
|
|
||||||
{
|
|
||||||
using namespace TemplatesFunctions;
|
|
||||||
|
|
||||||
functions.Clear();
|
|
||||||
|
|
||||||
|
|
||||||
functions.Insert("is_group_tv", is_group_tv);
|
|
||||||
|
|
||||||
functions.Insert("language", language);
|
|
||||||
functions.Insert("title", title);
|
|
||||||
functions.Insert("charset", charset);
|
|
||||||
functions.Insert("content", content);
|
|
||||||
functions.Insert("version_major", version_major);
|
|
||||||
functions.Insert("version_minor", version_minor);
|
|
||||||
functions.Insert("version_revision", version_revision);
|
|
||||||
functions.Insert("base_url", base_url);
|
|
||||||
functions.Insert("current_url", current_url);
|
|
||||||
functions.Insert("user_logged", user_logged);
|
|
||||||
functions.Insert("user_super_user", user_super_user);
|
|
||||||
|
|
||||||
|
|
||||||
functions.Insert("item_id", item_id);
|
|
||||||
functions.Insert("item_subject", item_subject);
|
|
||||||
functions.Insert("item_content", item_content);
|
|
||||||
functions.Insert("item_subject_escape", item_subject_escape);
|
|
||||||
functions.Insert("item_content_escape", item_content_escape);
|
|
||||||
functions.Insert("item_url_subject", item_url_subject);
|
|
||||||
functions.Insert("item_dir", item_dir);
|
|
||||||
functions.Insert("item_privileges", item_privileges);
|
|
||||||
|
|
||||||
functions.Insert("old_item_id", old_item_id);
|
|
||||||
functions.Insert("old_item_subject", old_item_subject);
|
|
||||||
functions.Insert("old_item_content", old_item_content);
|
|
||||||
functions.Insert("old_item_url_subject", old_item_url_subject);
|
|
||||||
functions.Insert("old_item_dir", old_item_dir);
|
|
||||||
|
|
||||||
functions.Insert("dir_items", dir_items);
|
|
||||||
functions.Insert("items", items);
|
|
||||||
functions.Insert("item_subject2", item_subject2);
|
|
||||||
functions.Insert("dir_subject2", dir_subject2);
|
|
||||||
functions.Insert("full_dir", full_dir);
|
|
||||||
functions.Insert("dir_url_subject2", dir_url_subject2);
|
|
||||||
functions.Insert("item_url_subject2", item_url_subject2);
|
|
||||||
functions.Insert("item_content2", item_content2);
|
|
||||||
functions.Insert("item_id2", item_id2);
|
|
||||||
|
|
||||||
|
|
||||||
functions.Insert("edit_item", edit_item);
|
|
||||||
|
|
||||||
|
|
||||||
functions.Insert("incorrect_dir", incorrect_dir);
|
|
||||||
|
|
||||||
functions.Insert("fcurrent_dir", fcurrent_dir);
|
|
||||||
functions.Insert("current_dir_part_link", current_dir_part_link);
|
|
||||||
functions.Insert("current_dir_part_url", current_dir_part_url);
|
|
||||||
|
|
||||||
functions.Insert("added_item", added_item);
|
|
||||||
functions.Insert("edited_item", edited_item);
|
|
||||||
functions.Insert("deleted_item", deleted_item);
|
|
||||||
functions.Insert("loggedout", loggedout);
|
|
||||||
functions.Insert("deleted_item_errors", deleted_item_errors);
|
|
||||||
|
|
||||||
|
|
||||||
functions.Insert("done_with_errors", done_with_errors);
|
|
||||||
functions.Insert("done_status", done_status);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
functions.Insert("fitems_in_dir", fitems_in_dir);
|
|
||||||
|
|
||||||
|
|
||||||
functions.Insert("user_name", user_name);
|
|
||||||
|
|
||||||
functions.Insert("fitem_group", fitem_group);
|
|
||||||
functions.Insert("fitem_group_name", fitem_group_name);
|
|
||||||
functions.Insert("fitem_group_default", fitem_group_default);
|
|
||||||
|
|
||||||
functions.Insert("fitem_user", fitem_user);
|
|
||||||
functions.Insert("fitem_user_name", fitem_user_name);
|
|
||||||
functions.Insert("fitem_user_default", fitem_user_default);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Templates::Read()
|
|
||||||
{
|
|
||||||
using namespace TemplatesFunctions;
|
|
||||||
|
|
||||||
pat_index.Directory(data.templates);
|
|
||||||
pat_index.ParseFile(data.default_index);
|
|
||||||
|
|
||||||
pat_item.Directory(data.templates);
|
|
||||||
pat_item.ParseFile("item.html");
|
|
||||||
|
|
||||||
pat_dir.Directory(data.templates);
|
|
||||||
pat_dir.ParseFile("dir.html");
|
|
||||||
|
|
||||||
pat_item_add_edit.Directory(data.templates);
|
|
||||||
pat_item_add_edit.ParseFile("item_add_edit.html");
|
|
||||||
|
|
||||||
pat_err_404.Directory(data.templates);
|
|
||||||
pat_err_404.ParseFile("err_404.html");
|
|
||||||
|
|
||||||
pat_err_per_denied.Directory(data.templates);
|
|
||||||
pat_err_per_denied.ParseFile("err_per_denied.html");
|
|
||||||
|
|
||||||
pat_item_del_confirm.Directory(data.templates);
|
|
||||||
pat_item_del_confirm.ParseFile("item_del_confirm.html");
|
|
||||||
|
|
||||||
pat_err_internal.Directory(data.templates);
|
|
||||||
pat_err_internal.ParseFile("err_internal.html");
|
|
||||||
|
|
||||||
CreateFunctions();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Templates::Generate()
|
|
||||||
{
|
|
||||||
using namespace TemplatesFunctions;
|
|
||||||
|
|
||||||
// clear some variables (indexes for example)
|
|
||||||
item_index = 0;
|
|
||||||
current_dir_index = 0;
|
|
||||||
|
|
||||||
|
|
||||||
Generator generator(request.page, pat_index, functions);
|
|
||||||
|
|
||||||
generator.Generate();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,50 +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.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfiletemplates
|
|
||||||
#define headerfiletemplates
|
|
||||||
|
|
||||||
#include <iomanip>
|
|
||||||
|
|
||||||
#include "../../ezc/src/ezc.h"
|
|
||||||
#include "data.h"
|
|
||||||
#include "request.h"
|
|
||||||
#include "item.h"
|
|
||||||
#include "db.h"
|
|
||||||
#include "error.h"
|
|
||||||
#include "user.h"
|
|
||||||
#include "group.h"
|
|
||||||
#include "users.h"
|
|
||||||
#include "groups.h"
|
|
||||||
|
|
||||||
|
|
||||||
using namespace Ezc;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Templates
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
|
|
||||||
void Read();
|
|
||||||
void Generate();
|
|
||||||
|
|
||||||
void CreateFunctions();
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -11,7 +11,6 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Users::Users()
|
Users::Users()
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
#include "ugcontainer.h"
|
#include "ugcontainer.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Users
|
class Users
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
o = templates.o sys.o item.o doc.o user.o dir.o done.o priv.o
|
||||||
|
|
||||||
|
|
||||||
|
all: templates.a
|
||||||
|
|
||||||
|
templates.a: $(o)
|
||||||
|
ar rcs templates.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,82 @@
|
||||||
|
# DO NOT DELETE
|
||||||
|
|
||||||
|
dir.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||||
|
dir.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||||
|
dir.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||||
|
dir.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||||
|
dir.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||||
|
dir.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||||
|
dir.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||||
|
dir.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||||
|
dir.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||||
|
dir.o: ../core/log.h
|
||||||
|
doc.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||||
|
doc.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||||
|
doc.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||||
|
doc.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||||
|
doc.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||||
|
doc.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||||
|
doc.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||||
|
doc.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||||
|
doc.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||||
|
doc.o: ../core/log.h
|
||||||
|
done.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||||
|
done.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||||
|
done.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||||
|
done.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||||
|
done.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||||
|
done.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||||
|
done.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||||
|
done.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||||
|
done.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||||
|
done.o: ../core/log.h
|
||||||
|
item.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||||
|
item.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||||
|
item.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||||
|
item.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||||
|
item.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||||
|
item.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||||
|
item.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||||
|
item.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||||
|
item.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||||
|
item.o: ../core/log.h
|
||||||
|
priv.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||||
|
priv.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||||
|
priv.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||||
|
priv.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||||
|
priv.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||||
|
priv.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||||
|
priv.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||||
|
priv.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||||
|
priv.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||||
|
priv.o: ../core/log.h
|
||||||
|
sys.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||||
|
sys.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||||
|
sys.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||||
|
sys.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||||
|
sys.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||||
|
sys.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||||
|
sys.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||||
|
sys.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||||
|
sys.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||||
|
sys.o: ../core/log.h
|
||||||
|
templates.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||||
|
templates.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||||
|
templates.o: ../core/db.h ../core/dircontainer.h ../core/user.h
|
||||||
|
templates.o: ../core/group.h ../core/ugcontainer.h ../core/users.h
|
||||||
|
templates.o: ../core/groups.h ../core/functions.h ../core/function.h
|
||||||
|
templates.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||||
|
templates.o: ../core/done.h ../core/getparser.h ../core/httpsimpleparser.h
|
||||||
|
templates.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
|
||||||
|
templates.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
|
||||||
|
templates.o: ../core/users.h ../core/groups.h ../core/log.h
|
||||||
|
user.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||||
|
user.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||||
|
user.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||||
|
user.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||||
|
user.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||||
|
user.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||||
|
user.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||||
|
user.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||||
|
user.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||||
|
user.o: ../core/log.h
|
|
@ -0,0 +1,104 @@
|
||||||
|
/*
|
||||||
|
* 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 "templates.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace TemplatesFunctions
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void dir(Info & i)
|
||||||
|
{
|
||||||
|
for(size_t a=0 ; a<request.dir_table.size() ; ++a)
|
||||||
|
{
|
||||||
|
HtmlEscape(i.out, request.dir_table[a]->url);
|
||||||
|
i.out << '/';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static std::vector<Item*> dir_childs_table;
|
||||||
|
static size_t dir_childs_index;
|
||||||
|
|
||||||
|
// request.id is never 0 and we can start dir_childs_reqid from 0
|
||||||
|
static size_t dir_childs_reqid = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void dir_childs_tab(Info & i)
|
||||||
|
{
|
||||||
|
if( dir_childs_reqid != request.id )
|
||||||
|
{
|
||||||
|
dir_childs_reqid = request.id;
|
||||||
|
dir_childs_table.clear();
|
||||||
|
|
||||||
|
if( !request.dir_table.empty() )
|
||||||
|
data.dirs.GetDirChilds(request.dir_table.back()->id, dir_childs_table);
|
||||||
|
}
|
||||||
|
|
||||||
|
dir_childs_index = i.iter;
|
||||||
|
i.result = dir_childs_index < dir_childs_table.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void dir_childs_tab_url(Info & i)
|
||||||
|
{
|
||||||
|
if( dir_childs_index < dir_childs_table.size() )
|
||||||
|
HtmlEscape(i.out, dir_childs_table[dir_childs_index]->url);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static size_t dir_index;
|
||||||
|
|
||||||
|
|
||||||
|
void dir_tab(Info & i)
|
||||||
|
{
|
||||||
|
dir_index = i.iter;
|
||||||
|
i.result = dir_index < request.dir_table.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void dir_tab_url(Info & i)
|
||||||
|
{
|
||||||
|
if( dir_index < request.dir_table.size() )
|
||||||
|
HtmlEscape(i.out, request.dir_table[dir_index]->url);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void dir_tab_link(Info & i)
|
||||||
|
{
|
||||||
|
i.out << data.base_url;
|
||||||
|
|
||||||
|
for(size_t a = 0 ; a <= dir_index && a < request.dir_table.size() ; ++a)
|
||||||
|
{
|
||||||
|
HtmlEscape(i.out, request.dir_table[a]->url);
|
||||||
|
i.out << '/';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace TemplatesFunctions
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
/*
|
||||||
|
* 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 "templates.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace TemplatesFunctions
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void doc_language(Info & i)
|
||||||
|
{
|
||||||
|
// at the moment only Polish language
|
||||||
|
i.out << "pl";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void doc_title(Info & i)
|
||||||
|
{
|
||||||
|
size_t a = 0;
|
||||||
|
|
||||||
|
// from 1 means skipping the root directory
|
||||||
|
for(a = 1 ; a<request.dir_table.size() ; ++a)
|
||||||
|
i.out << " / " << request.dir_table[a]->url;
|
||||||
|
|
||||||
|
if( request.is_item )
|
||||||
|
i.out << " / " << request.item.subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void doc_charset(Info & i)
|
||||||
|
{
|
||||||
|
i.out << "iso-8859-2";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void doc_base_url(Info & i)
|
||||||
|
{
|
||||||
|
i.out << data.base_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void doc_current_url(Info & i)
|
||||||
|
{
|
||||||
|
i.out << request.env_request_uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void doc_status_error(Info & i)
|
||||||
|
{
|
||||||
|
i.result = request.status != Error::ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void doc_status_code(Info & i)
|
||||||
|
{
|
||||||
|
i.out << static_cast<int>( request.status );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace TemplatesFunctions
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
/*
|
||||||
|
* 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 "templates.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace TemplatesFunctions
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void done_errors(Info & i)
|
||||||
|
{
|
||||||
|
i.result = request.session->done_status != Error::ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void done_status(Info & i)
|
||||||
|
{
|
||||||
|
i.out << static_cast<int>( request.session->done_status );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void done_status_incorrect_dir(Info & i)
|
||||||
|
{
|
||||||
|
i.result = request.session->done_status == Error::incorrect_dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void done_added_item(Info & i)
|
||||||
|
{
|
||||||
|
i.result = request.session->done == Done::added_item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void done_edited_item(Info & i)
|
||||||
|
{
|
||||||
|
i.result = request.session->done == Done::edited_item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void done_deleted_item(Info & i)
|
||||||
|
{
|
||||||
|
i.result = request.session->done == Done::deleted_item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void done_privileged_item(Info & i)
|
||||||
|
{
|
||||||
|
i.result = request.session->done == Done::privileged_item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void done_loggedout(Info & i)
|
||||||
|
{
|
||||||
|
i.result = request.session->done == Done::loggedout;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace TemplatesFunctions
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,248 @@
|
||||||
|
/*
|
||||||
|
* 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 "templates.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace TemplatesFunctions
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void item_is(Info & i)
|
||||||
|
{
|
||||||
|
i.result = request.is_item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void item_id(Info & i)
|
||||||
|
{
|
||||||
|
i.out << request.item.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void item_subject(Info & i)
|
||||||
|
{
|
||||||
|
HtmlEscape(i.out, request.item.subject);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void item_subject_noescape(Info & i)
|
||||||
|
{
|
||||||
|
i.out << request.item.subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void item_content(Info & i)
|
||||||
|
{
|
||||||
|
HtmlEscape(i.out, request.item.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void item_content_noescape(Info & i)
|
||||||
|
{
|
||||||
|
i.out << request.item.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void item_privileges(Info & i)
|
||||||
|
{
|
||||||
|
i.out << std::setbase(8) << request.item.privileges << std::setbase(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void item_dir(Info & i)
|
||||||
|
{
|
||||||
|
dir(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void item_url(Info & i)
|
||||||
|
{
|
||||||
|
HtmlEscape(i.out, request.item.url);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void item_link(Info & i)
|
||||||
|
{
|
||||||
|
HtmlEscape(i.out, data.base_url);
|
||||||
|
item_dir(i);
|
||||||
|
item_url(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void item_old_id(Info & i)
|
||||||
|
{
|
||||||
|
i.out << request.session->item.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void item_old_subject(Info & i)
|
||||||
|
{
|
||||||
|
HtmlEscape(i.out, request.session->item.subject);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void item_old_subject_noescape(Info & i)
|
||||||
|
{
|
||||||
|
i.out << request.session->item.subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void item_old_content(Info & i)
|
||||||
|
{
|
||||||
|
HtmlEscape(i.out, request.session->item.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void item_old_content_noescape(Info & i)
|
||||||
|
{
|
||||||
|
i.out << request.session->item.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void item_old_privileges(Info & i)
|
||||||
|
{
|
||||||
|
i.out << std::setbase(8) << request.session->item.privileges << std::setbase(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void item_old_dir(Info & i)
|
||||||
|
{
|
||||||
|
std::string path;
|
||||||
|
|
||||||
|
if( data.dirs.MakePath(request.session->item.parent_id, path) )
|
||||||
|
HtmlEscape(i.out, path);
|
||||||
|
else
|
||||||
|
i.out << "/the path does not exist/";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void item_old_url(Info & i)
|
||||||
|
{
|
||||||
|
HtmlEscape(i.out, request.session->item.url);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void item_old_link(Info & i)
|
||||||
|
{
|
||||||
|
HtmlEscape(i.out, data.base_url);
|
||||||
|
item_old_dir(i);
|
||||||
|
item_old_url(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static size_t item_index;
|
||||||
|
|
||||||
|
|
||||||
|
void item_tab(Info & i)
|
||||||
|
{
|
||||||
|
item_index = i.iter;
|
||||||
|
i.result = item_index < request.item_table.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void item_tab_id(Info & i)
|
||||||
|
{
|
||||||
|
if( item_index < request.item_table.size() )
|
||||||
|
i.out << request.item_table[item_index].id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void item_tab_subject(Info & i)
|
||||||
|
{
|
||||||
|
if( item_index < request.item_table.size() )
|
||||||
|
HtmlEscape(i.out, request.item_table[item_index].subject);
|
||||||
|
}
|
||||||
|
|
||||||
|
void item_tab_subject_noescape(Info & i)
|
||||||
|
{
|
||||||
|
if( item_index < request.item_table.size() )
|
||||||
|
i.out << request.item_table[item_index].subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void item_tab_content(Info & i)
|
||||||
|
{
|
||||||
|
if( item_index < request.item_table.size() )
|
||||||
|
HtmlEscape(i.out, request.item_table[item_index].content);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void item_tab_content_noescape(Info & i)
|
||||||
|
{
|
||||||
|
if( item_index < request.item_table.size() )
|
||||||
|
i.out << request.item_table[item_index].content;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void item_tab_privileges(Info & i)
|
||||||
|
{
|
||||||
|
if( item_index < request.item_table.size() )
|
||||||
|
i.out << std::setbase(8) << request.item_table[item_index].privileges << std::setbase(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void item_tab_dir(Info & i)
|
||||||
|
{
|
||||||
|
if( item_index < request.item_table.size() )
|
||||||
|
{
|
||||||
|
std::string path;
|
||||||
|
|
||||||
|
if( data.dirs.MakePath(request.item_table[item_index].parent_id, path) )
|
||||||
|
HtmlEscape(i.out, path);
|
||||||
|
else
|
||||||
|
i.out << "/the path does not exist/";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void item_tab_url(Info & i)
|
||||||
|
{
|
||||||
|
if( item_index < request.item_table.size() )
|
||||||
|
HtmlEscape(i.out, request.item_table[item_index].url);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void item_tab_link(Info & i)
|
||||||
|
{
|
||||||
|
if( item_index < request.item_table.size() )
|
||||||
|
{
|
||||||
|
HtmlEscape(i.out, data.base_url);
|
||||||
|
item_tab_dir(i);
|
||||||
|
item_tab_url(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace TemplatesFunctions
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,218 @@
|
||||||
|
/*
|
||||||
|
* 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 "templates.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace TemplatesFunctions
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
static std::vector<long> priv_user_table;
|
||||||
|
static size_t priv_user_index;
|
||||||
|
static size_t priv_user_reqid = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void priv_user_tab_init()
|
||||||
|
{
|
||||||
|
priv_user_reqid = request.id;
|
||||||
|
priv_user_table.clear();
|
||||||
|
|
||||||
|
if( !request.session->puser )
|
||||||
|
{
|
||||||
|
// not logged
|
||||||
|
priv_user_table.push_back(request.item.user_id);
|
||||||
|
}
|
||||||
|
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
|
||||||
|
priv_user_table.push_back(request.item.user_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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];
|
||||||
|
|
||||||
|
if( uid == request.item.user_id )
|
||||||
|
i.result = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static std::vector<long> priv_group_table;
|
||||||
|
static size_t priv_group_index;
|
||||||
|
static size_t priv_group_reqid = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void priv_group_tab_init()
|
||||||
|
{
|
||||||
|
priv_group_reqid = request.id;
|
||||||
|
priv_group_table.clear();
|
||||||
|
|
||||||
|
if( !request.session->puser )
|
||||||
|
{
|
||||||
|
// not logged
|
||||||
|
priv_group_table.push_back(request.item.group_id);
|
||||||
|
}
|
||||||
|
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
|
||||||
|
if( request.session->puser->id == request.item.user_id )
|
||||||
|
{
|
||||||
|
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] );
|
||||||
|
|
||||||
|
if( request.item.group_id == request.session->puser->groups[i] )
|
||||||
|
was_current_group = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we're showing the item.group_id if it's different
|
||||||
|
if( !was_current_group )
|
||||||
|
priv_group_table.push_back(request.item.group_id);
|
||||||
|
|
||||||
|
// 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
|
||||||
|
priv_group_table.push_back(request.item.group_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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];
|
||||||
|
|
||||||
|
if( gid == request.item.group_id )
|
||||||
|
i.result = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace TemplatesFunctions
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* 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 "templates.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace TemplatesFunctions
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
void sys_ver_major(Info & i)
|
||||||
|
{
|
||||||
|
i.out << MAJOR_VER;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void sys_ver_minor(Info & i)
|
||||||
|
{
|
||||||
|
i.out << MINOR_VER;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void sys_ver_revision(Info & i)
|
||||||
|
{
|
||||||
|
i.out << REVISION_VER;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace TemplatesFunctions
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,312 @@
|
||||||
|
/*
|
||||||
|
* 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 "templates.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace TemplatesFunctions
|
||||||
|
{
|
||||||
|
Ezc::Pattern pat_index;
|
||||||
|
Ezc::Pattern pat_fun_cat;
|
||||||
|
Ezc::Pattern pat_fun_ls;
|
||||||
|
Ezc::Pattern pat_fun_emacs;
|
||||||
|
Ezc::Pattern pat_fun_privileges;
|
||||||
|
Ezc::Pattern pat_fun_rm;
|
||||||
|
Ezc::Pattern pat_err_item_required;
|
||||||
|
Ezc::Pattern pat_err_404;
|
||||||
|
Ezc::Pattern pat_err_per_denied;
|
||||||
|
Ezc::Pattern pat_err_others;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Ezc::Functions functions;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// !! tymczasowa funkcja
|
||||||
|
void is_group_tv(Info & i)
|
||||||
|
{
|
||||||
|
long gid = data.groups.GetGroupId("tv");
|
||||||
|
|
||||||
|
if( request.session->puser && request.session->puser->IsMemberOf(gid) )
|
||||||
|
i.result = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Ezc::Pattern * content_for_function()
|
||||||
|
{
|
||||||
|
Ezc::Pattern * p = 0;
|
||||||
|
|
||||||
|
|
||||||
|
if( !request.pfunction )
|
||||||
|
{
|
||||||
|
log << log1 << "Templates: no function" << logend;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
switch( request.pfunction->code )
|
||||||
|
{
|
||||||
|
case Function::cat:
|
||||||
|
p = &pat_fun_cat;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Function::ls:
|
||||||
|
p = &pat_fun_ls;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Function::rm:
|
||||||
|
p = &pat_fun_rm;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Function::emacs:
|
||||||
|
p = &pat_fun_emacs;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Function::privileges:
|
||||||
|
p = &pat_fun_privileges;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void content(Info & i)
|
||||||
|
{
|
||||||
|
Ezc::Pattern * p = 0;
|
||||||
|
|
||||||
|
switch( request.status )
|
||||||
|
{
|
||||||
|
case Error::ok:
|
||||||
|
p = content_for_function();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Error::item_required:
|
||||||
|
p = &pat_err_item_required;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Error::permision_denied:
|
||||||
|
p = &pat_err_per_denied;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Error::db_no_item:
|
||||||
|
case Error::no_function:
|
||||||
|
p = &pat_err_404;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
p = &pat_err_others;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if( p )
|
||||||
|
{
|
||||||
|
Ezc::Generator gen(i.out, *p, functions);
|
||||||
|
gen.Generate();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
i.out << "<!-- there are not any patterns -->";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace TemplatesFunctions
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Templates::CreateFunctions()
|
||||||
|
{
|
||||||
|
using namespace TemplatesFunctions;
|
||||||
|
|
||||||
|
functions.Clear();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
sys
|
||||||
|
*/
|
||||||
|
functions.Insert("sys_ver_major", sys_ver_major);
|
||||||
|
functions.Insert("sys_ver_minor", sys_ver_minor);
|
||||||
|
functions.Insert("sys_ver_revision", sys_ver_revision);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
doc
|
||||||
|
*/
|
||||||
|
functions.Insert("doc_language", doc_language);
|
||||||
|
functions.Insert("doc_title", doc_title);
|
||||||
|
functions.Insert("doc_charset", doc_charset);
|
||||||
|
functions.Insert("doc_base_url", doc_base_url);
|
||||||
|
functions.Insert("doc_current_url", doc_current_url);
|
||||||
|
functions.Insert("doc_status_error", doc_status_error);
|
||||||
|
functions.Insert("doc_status_code", doc_status_code);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
item
|
||||||
|
*/
|
||||||
|
functions.Insert("item_is", item_is);
|
||||||
|
functions.Insert("item_id", item_id);
|
||||||
|
functions.Insert("item_subject", item_subject);
|
||||||
|
functions.Insert("item_subject_noescape", item_subject_noescape);
|
||||||
|
functions.Insert("item_content", item_content);
|
||||||
|
functions.Insert("item_content_noescape", item_content_noescape);
|
||||||
|
functions.Insert("item_privileges", item_privileges);
|
||||||
|
functions.Insert("item_dir", item_dir);
|
||||||
|
functions.Insert("item_url", item_url);
|
||||||
|
functions.Insert("item_link", item_link);
|
||||||
|
|
||||||
|
functions.Insert("item_old_id", item_old_id);
|
||||||
|
functions.Insert("item_old_subject", item_old_subject);
|
||||||
|
functions.Insert("item_old_subject_noescape", item_old_subject_noescape);
|
||||||
|
functions.Insert("item_old_content", item_old_content);
|
||||||
|
functions.Insert("item_old_content_noescape", item_old_content_noescape);
|
||||||
|
functions.Insert("item_old_privileges", item_old_privileges);
|
||||||
|
functions.Insert("item_old_dir", item_old_dir);
|
||||||
|
functions.Insert("item_old_url", item_old_url);
|
||||||
|
functions.Insert("item_old_link", item_old_link);
|
||||||
|
|
||||||
|
functions.Insert("item_tab", item_tab);
|
||||||
|
functions.Insert("item_tab_id", item_tab_id);
|
||||||
|
functions.Insert("item_tab_subject", item_tab_subject);
|
||||||
|
functions.Insert("item_tab_subject_noescape", item_tab_subject_noescape);
|
||||||
|
functions.Insert("item_tab_content", item_tab_content);
|
||||||
|
functions.Insert("item_tab_content_noescape", item_tab_content_noescape);
|
||||||
|
functions.Insert("item_tab_privileges", item_tab_privileges);
|
||||||
|
functions.Insert("item_tab_dir", item_tab_dir);
|
||||||
|
functions.Insert("item_tab_url", item_tab_url);
|
||||||
|
functions.Insert("item_tab_link", item_tab_link);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
dir
|
||||||
|
*/
|
||||||
|
functions.Insert("dir", dir);
|
||||||
|
|
||||||
|
functions.Insert("dir_childs_tab", dir_childs_tab);
|
||||||
|
functions.Insert("dir_childs_tab_url", dir_childs_tab_url);
|
||||||
|
|
||||||
|
functions.Insert("dir_tab", dir_tab);
|
||||||
|
functions.Insert("dir_tab_url", dir_tab_url);
|
||||||
|
functions.Insert("dir_tab_link", dir_tab_link);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
user
|
||||||
|
*/
|
||||||
|
functions.Insert("user_name", user_name);
|
||||||
|
functions.Insert("user_logged", user_logged);
|
||||||
|
functions.Insert("user_super_user", user_super_user);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
privileges
|
||||||
|
*/
|
||||||
|
functions.Insert("priv_user_tab", priv_user_tab);
|
||||||
|
functions.Insert("priv_user_tab_name", priv_user_tab_name);
|
||||||
|
functions.Insert("priv_user_tab_isdefault", priv_user_tab_isdefault);
|
||||||
|
|
||||||
|
functions.Insert("priv_group_tab", priv_group_tab);
|
||||||
|
functions.Insert("priv_group_tab_name", priv_group_tab_name);
|
||||||
|
functions.Insert("priv_group_tab_isdefault", priv_group_tab_isdefault);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
done
|
||||||
|
*/
|
||||||
|
functions.Insert("done_errors", done_errors);
|
||||||
|
functions.Insert("done_status", done_status);
|
||||||
|
functions.Insert("done_status_incorrect_dir", done_status_incorrect_dir);
|
||||||
|
functions.Insert("done_added_item", done_added_item);
|
||||||
|
functions.Insert("done_edited_item", done_edited_item);
|
||||||
|
functions.Insert("done_deleted_item", done_deleted_item);
|
||||||
|
functions.Insert("done_privileged_item", done_privileged_item);
|
||||||
|
functions.Insert("done_loggedout", done_loggedout);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
others
|
||||||
|
*/
|
||||||
|
functions.Insert("content", content);
|
||||||
|
|
||||||
|
|
||||||
|
// !! tymczasowa
|
||||||
|
functions.Insert("is_group_tv", is_group_tv);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Templates::Read()
|
||||||
|
{
|
||||||
|
using namespace TemplatesFunctions;
|
||||||
|
|
||||||
|
pat_index.Directory(data.templates);
|
||||||
|
pat_index.ParseFile(data.default_index);
|
||||||
|
|
||||||
|
pat_err_404.Directory(data.templates);
|
||||||
|
pat_err_404.ParseFile("err_404.html");
|
||||||
|
|
||||||
|
pat_err_per_denied.Directory(data.templates);
|
||||||
|
pat_err_per_denied.ParseFile("err_per_denied.html");
|
||||||
|
|
||||||
|
pat_fun_cat.Directory(data.templates);
|
||||||
|
pat_fun_cat.ParseFile("fun_cat.html");
|
||||||
|
|
||||||
|
pat_fun_ls.Directory(data.templates);
|
||||||
|
pat_fun_ls.ParseFile("fun_ls.html");
|
||||||
|
|
||||||
|
pat_fun_rm.Directory(data.templates);
|
||||||
|
pat_fun_rm.ParseFile("fun_rm.html");
|
||||||
|
|
||||||
|
pat_err_item_required.Directory(data.templates);
|
||||||
|
pat_err_item_required.ParseFile("err_item_required.html");
|
||||||
|
|
||||||
|
pat_fun_emacs.Directory(data.templates);
|
||||||
|
pat_fun_emacs.ParseFile("fun_emacs.html");
|
||||||
|
|
||||||
|
pat_fun_privileges.Directory(data.templates);
|
||||||
|
pat_fun_privileges.ParseFile("fun_privileges.html");
|
||||||
|
|
||||||
|
pat_err_others.Directory(data.templates);
|
||||||
|
pat_err_others.ParseFile("err_others.html");
|
||||||
|
|
||||||
|
CreateFunctions();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Templates::Generate()
|
||||||
|
{
|
||||||
|
using namespace TemplatesFunctions;
|
||||||
|
|
||||||
|
|
||||||
|
Ezc::Generator generator(request.page, pat_index, functions);
|
||||||
|
|
||||||
|
generator.Generate();
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,165 @@
|
||||||
|
/*
|
||||||
|
* 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 headerfiletemplates
|
||||||
|
#define headerfiletemplates
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
|
#include "../../ezc/src/ezc.h"
|
||||||
|
#include "../core/data.h"
|
||||||
|
#include "../core/request.h"
|
||||||
|
#include "../core/item.h"
|
||||||
|
#include "../core/db.h"
|
||||||
|
#include "../core/error.h"
|
||||||
|
#include "../core/user.h"
|
||||||
|
#include "../core/group.h"
|
||||||
|
#include "../core/users.h"
|
||||||
|
#include "../core/groups.h"
|
||||||
|
#include "../core/log.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace TemplatesFunctions
|
||||||
|
{
|
||||||
|
using Ezc::Info;
|
||||||
|
|
||||||
|
/*
|
||||||
|
sys
|
||||||
|
*/
|
||||||
|
void sys_ver_major(Info & i);
|
||||||
|
void sys_ver_minor(Info & i);
|
||||||
|
void sys_ver_revision(Info & i);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
doc
|
||||||
|
*/
|
||||||
|
void doc_language(Info & i);
|
||||||
|
void doc_title(Info & i);
|
||||||
|
void doc_charset(Info & i);
|
||||||
|
void doc_base_url(Info & i);
|
||||||
|
void doc_current_url(Info & i);
|
||||||
|
void doc_status_error(Info & i);
|
||||||
|
void doc_status_code(Info & i);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
item
|
||||||
|
*/
|
||||||
|
void item_is(Info & i);
|
||||||
|
void item_id(Info & i);
|
||||||
|
void item_subject(Info & i);
|
||||||
|
void item_subject_noescape(Info & i);
|
||||||
|
void item_content(Info & i);
|
||||||
|
void item_content_noescape(Info & i);
|
||||||
|
void item_privileges(Info & i);
|
||||||
|
void item_dir(Info & i); // the same as full_dir()
|
||||||
|
void item_url(Info & i);
|
||||||
|
void item_link(Info & i);
|
||||||
|
|
||||||
|
// !! wprowadzic item_old_is ?
|
||||||
|
void item_old_id(Info & i);
|
||||||
|
void item_old_subject(Info & i);
|
||||||
|
void item_old_subject_noescape(Info & i);
|
||||||
|
void item_old_content(Info & i);
|
||||||
|
void item_old_content_noescape(Info & i);
|
||||||
|
void item_old_privileges(Info & i);
|
||||||
|
void item_old_dir(Info & i);
|
||||||
|
void item_old_url(Info & i);
|
||||||
|
void item_old_link(Info & i);
|
||||||
|
|
||||||
|
void item_tab(Info & i);
|
||||||
|
void item_tab_id(Info & i);
|
||||||
|
void item_tab_subject(Info & i);
|
||||||
|
void item_tab_subject_noescape(Info & i);
|
||||||
|
void item_tab_content(Info & i);
|
||||||
|
void item_tab_content_noescape(Info & i);
|
||||||
|
void item_tab_privileges(Info & i);
|
||||||
|
void item_tab_dir(Info & i);
|
||||||
|
void item_tab_url(Info & i);
|
||||||
|
void item_tab_link(Info & i);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
dir
|
||||||
|
*/
|
||||||
|
void dir(Info & i);
|
||||||
|
|
||||||
|
void dir_childs_tab(Info & i);
|
||||||
|
void dir_childs_tab_url(Info & i);
|
||||||
|
|
||||||
|
void dir_tab(Info & i);
|
||||||
|
void dir_tab_url(Info & i);
|
||||||
|
void dir_tab_link(Info & i);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
user
|
||||||
|
*/
|
||||||
|
void user_name(Info & i);
|
||||||
|
void user_logged(Info & i);
|
||||||
|
void user_super_user(Info & i);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
privileges
|
||||||
|
*/
|
||||||
|
void priv_user_tab(Info & i);
|
||||||
|
void priv_user_tab_name(Info & i);
|
||||||
|
void priv_user_tab_isdefault(Info & i);
|
||||||
|
|
||||||
|
void priv_group_tab(Info & i);
|
||||||
|
void priv_group_tab_name(Info & i);
|
||||||
|
void priv_group_tab_isdefault(Info & i);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
done
|
||||||
|
*/
|
||||||
|
void done_errors(Info & i);
|
||||||
|
void done_status(Info & i);
|
||||||
|
void done_status_incorrect_dir(Info & i);
|
||||||
|
|
||||||
|
void done_added_item(Info & i);
|
||||||
|
void done_edited_item(Info & i);
|
||||||
|
void done_deleted_item(Info & i);
|
||||||
|
void done_privileged_item(Info & i);
|
||||||
|
void done_loggedout(Info & i);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace TemplatesFunctions
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Templates
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
void Read();
|
||||||
|
void Generate();
|
||||||
|
|
||||||
|
void CreateFunctions();
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* 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 "templates.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace TemplatesFunctions
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void user_logged(Info & i)
|
||||||
|
{
|
||||||
|
i.result = request.session->puser != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void user_name(Info & i)
|
||||||
|
{
|
||||||
|
if( !request.session->puser )
|
||||||
|
return;
|
||||||
|
|
||||||
|
i.out << request.session->puser->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void user_super_user(Info & i)
|
||||||
|
{
|
||||||
|
if( request.session->puser && request.session->puser->super_user )
|
||||||
|
i.result = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace TemplatesFunctions
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue