the first part of reimplementing has been done
now we have app object and singletons are only: log logn plugin and app git-svn-id: svn://ttmath.org/publicrep/winix/trunk@628 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -1,128 +1,261 @@
|
||||
# DO NOT DELETE
|
||||
|
||||
Kopia config.o: ../core/log.h ../core/request.h requesttypes.h session.h
|
||||
Kopia config.o: item.h error.h log.h user.h plugindata.h rebus.h thread.h
|
||||
Kopia config.o: compress.h acceptencodingparser.h acceptbaseparser.h
|
||||
Kopia config.o: htmlfilter.h postmultiparser.h config.h confparser.h ticket.h
|
||||
Kopia config.o: ../core/config.h ../core/db.h group.h dircontainer.h
|
||||
Kopia config.o: ugcontainer.h
|
||||
acceptbaseparser.o: acceptbaseparser.h
|
||||
app.o: app.h config.h confparser.h system.h dirs.h item.h dircontainer.h db.h
|
||||
app.o: user.h group.h thread.h error.h log.h ugcontainer.h ticket.h request.h
|
||||
app.o: requesttypes.h session.h plugindata.h rebus.h compress.h
|
||||
app.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
|
||||
app.o: postmultiparser.h mounts.h mount.h users.h lastcontainer.h groups.h
|
||||
app.o: loadavg.h sessionmanager.h sessioncontainer.h notify.h
|
||||
app.o: ../templatesnotify/templatesnotify.h ../../ezc/src/ezc.h
|
||||
app.o: ../core/mount.h ../core/locale.h ../core/config.h ../templates/misc.h
|
||||
app.o: ../templates/localefilter.h ../core/locale.h ../functions/functions.h
|
||||
app.o: ../functions/functionbase.h ../core/item.h ../core/db.h
|
||||
app.o: ../core/request.h ../core/system.h ../core/notify.h
|
||||
app.o: ../functions/functionparser.h ../functions/adduser.h
|
||||
app.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
|
||||
app.o: ../functions/chown.h ../functions/cp.h ../functions/createthread.h
|
||||
app.o: ../functions/createticket.h ../functions/default.h
|
||||
app.o: ../functions/download.h ../functions/editticket.h ../functions/emacs.h
|
||||
app.o: ../functions/last.h ../functions/login.h ../functions/logout.h
|
||||
app.o: ../functions/ls.h ../functions/mkdir.h ../functions/mv.h
|
||||
app.o: ../functions/node.h ../functions/priv.h ../functions/reload.h
|
||||
app.o: ../functions/rm.h ../functions/run.h ../functions/subject.h
|
||||
app.o: ../functions/funthread.h ../core/thread.h ../functions/funticket.h
|
||||
app.o: ../functions/uname.h ../functions/upload.h ../functions/who.h
|
||||
app.o: ../templates/templates.h ../templates/patterncacher.h ../core/item.h
|
||||
app.o: misc.h ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
|
||||
app.o: ../core/log.h ../templates/indexpatterns.h ../core/sessionmanager.h
|
||||
app.o: plugin.h pluginmsg.h
|
||||
bbcodeparser.o: bbcodeparser.h htmlfilter.h
|
||||
compress.o: compress.h log.h
|
||||
config.o: config.h ../confparser/confparser.h log.h data.h dirs.h item.h
|
||||
config.o: dircontainer.h users.h user.h ugcontainer.h groups.h group.h
|
||||
config.o: functions.h function.h lastcontainer.h mounts.h mount.h error.h
|
||||
config.o: rebus.h loadavg.h plugin.h request.h requesttypes.h session.h
|
||||
config.o: plugindata.h thread.h compress.h acceptencodingparser.h
|
||||
config.o: acceptbaseparser.h htmlfilter.h postmultiparser.h ticket.h
|
||||
config.o: pluginmsg.h misc.h
|
||||
data.o: data.h dirs.h item.h dircontainer.h users.h user.h ugcontainer.h
|
||||
data.o: log.h groups.h group.h functions.h function.h lastcontainer.h
|
||||
data.o: mounts.h mount.h error.h rebus.h loadavg.h
|
||||
config.o: config.h confparser.h log.h plugin.h pluginmsg.h plugindata.h
|
||||
config.o: request.h requesttypes.h session.h item.h error.h user.h rebus.h
|
||||
config.o: thread.h compress.h acceptencodingparser.h acceptbaseparser.h
|
||||
config.o: htmlfilter.h postmultiparser.h ticket.h system.h dirs.h
|
||||
config.o: dircontainer.h db.h group.h ugcontainer.h mounts.h mount.h users.h
|
||||
config.o: lastcontainer.h groups.h loadavg.h sessionmanager.h
|
||||
config.o: sessioncontainer.h ../functions/functions.h
|
||||
config.o: ../functions/functionbase.h ../core/item.h ../core/db.h
|
||||
config.o: ../core/request.h ../core/config.h ../core/system.h
|
||||
config.o: ../core/notify.h ../../ezc/src/ezc.h ../functions/functionparser.h
|
||||
config.o: ../functions/adduser.h ../functions/cat.h ../functions/chmod.h
|
||||
config.o: ../functions/privchanger.h ../functions/chown.h ../functions/cp.h
|
||||
config.o: ../functions/createthread.h ../functions/createticket.h
|
||||
config.o: ../functions/default.h ../functions/download.h
|
||||
config.o: ../functions/editticket.h ../functions/emacs.h ../functions/last.h
|
||||
config.o: ../functions/login.h ../functions/logout.h ../functions/ls.h
|
||||
config.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
|
||||
config.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
|
||||
config.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
|
||||
config.o: ../core/thread.h ../functions/funticket.h ../functions/uname.h
|
||||
config.o: ../functions/upload.h ../functions/who.h ../templates/templates.h
|
||||
config.o: ../templates/patterncacher.h ../core/item.h misc.h
|
||||
config.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
|
||||
config.o: ../core/log.h ../templates/indexpatterns.h
|
||||
config.o: ../templates/localefilter.h ../core/locale.h ../core/locale.h
|
||||
config.o: ../core/sessionmanager.h
|
||||
confparser.o: confparser.h misc.h item.h
|
||||
db.o: db.h item.h user.h group.h thread.h error.h log.h dircontainer.h
|
||||
db.o: ugcontainer.h ticket.h misc.h
|
||||
db_itemcolumns.o: db.h item.h user.h group.h thread.h error.h log.h
|
||||
db_itemcolumns.o: dircontainer.h ugcontainer.h ticket.h
|
||||
dircontainer.o: dircontainer.h item.h log.h
|
||||
dirs.o: dirs.h item.h dircontainer.h error.h log.h db.h user.h group.h
|
||||
dirs.o: thread.h ugcontainer.h ticket.h data.h users.h groups.h functions.h
|
||||
dirs.o: function.h lastcontainer.h mounts.h mount.h rebus.h loadavg.h
|
||||
dirs.o: request.h requesttypes.h session.h plugindata.h compress.h
|
||||
dirs.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
|
||||
dirs.o: postmultiparser.h
|
||||
function.o: function.h item.h
|
||||
functioncodeparser.o: functioncodeparser.h item.h function.h log.h
|
||||
functionparser.o: functionparser.h requesttypes.h log.h item.h error.h data.h
|
||||
functionparser.o: dirs.h dircontainer.h users.h user.h ugcontainer.h groups.h
|
||||
functionparser.o: group.h functions.h function.h lastcontainer.h mounts.h
|
||||
functionparser.o: mount.h rebus.h loadavg.h db.h thread.h ticket.h request.h
|
||||
functionparser.o: session.h plugindata.h compress.h acceptencodingparser.h
|
||||
functionparser.o: acceptbaseparser.h htmlfilter.h postmultiparser.h
|
||||
functions.o: functions.h function.h item.h
|
||||
dirs.o: dirs.h item.h dircontainer.h db.h user.h group.h thread.h error.h
|
||||
dirs.o: log.h ugcontainer.h ticket.h request.h requesttypes.h session.h
|
||||
dirs.o: plugindata.h rebus.h compress.h acceptencodingparser.h
|
||||
dirs.o: acceptbaseparser.h htmlfilter.h postmultiparser.h config.h
|
||||
dirs.o: confparser.h
|
||||
groups.o: groups.h group.h ugcontainer.h log.h db.h item.h user.h thread.h
|
||||
groups.o: error.h dircontainer.h ticket.h
|
||||
htmlfilter.o: htmlfilter.h
|
||||
httpsimpleparser.o: httpsimpleparser.h
|
||||
lastcontainer.o: lastcontainer.h log.h
|
||||
loadavg.o: loadavg.h log.h
|
||||
locale.o: locale.h ../confparser/confparser.h log.h
|
||||
locale.o: locale.h confparser.h log.h
|
||||
log.o: log.h
|
||||
misc.o: misc.h item.h log.h data.h dirs.h dircontainer.h users.h user.h
|
||||
misc.o: ugcontainer.h groups.h group.h functions.h function.h lastcontainer.h
|
||||
misc.o: mounts.h mount.h error.h rebus.h loadavg.h
|
||||
misc.o: misc.h item.h log.h
|
||||
mount.o: mount.h
|
||||
mountparser.o: mountparser.h mount.h item.h error.h log.h data.h dirs.h
|
||||
mountparser.o: dircontainer.h users.h user.h ugcontainer.h groups.h group.h
|
||||
mountparser.o: functions.h function.h lastcontainer.h mounts.h rebus.h
|
||||
mountparser.o: loadavg.h misc.h
|
||||
mounts.o: mounts.h mount.h error.h log.h data.h dirs.h item.h dircontainer.h
|
||||
mounts.o: users.h user.h ugcontainer.h groups.h group.h functions.h
|
||||
mounts.o: function.h lastcontainer.h rebus.h loadavg.h request.h
|
||||
mounts.o: requesttypes.h session.h plugindata.h thread.h compress.h
|
||||
mountparser.o: mountparser.h mount.h item.h error.h log.h dirs.h
|
||||
mountparser.o: dircontainer.h db.h user.h group.h thread.h ugcontainer.h
|
||||
mountparser.o: ticket.h request.h requesttypes.h session.h plugindata.h
|
||||
mountparser.o: rebus.h compress.h acceptencodingparser.h acceptbaseparser.h
|
||||
mountparser.o: htmlfilter.h postmultiparser.h config.h confparser.h misc.h
|
||||
mounts.o: mounts.h mount.h error.h log.h dirs.h item.h dircontainer.h db.h
|
||||
mounts.o: user.h group.h thread.h ugcontainer.h ticket.h request.h
|
||||
mounts.o: requesttypes.h session.h plugindata.h rebus.h compress.h
|
||||
mounts.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
|
||||
mounts.o: postmultiparser.h ticket.h mountparser.h db.h
|
||||
notify.o: log.h notify.h ../templatesnotify/templatesnotify.h ../core/mount.h
|
||||
notify.o: ../core/locale.h ../confparser/confparser.h ../templates/misc.h
|
||||
notify.o: ../templates/localefilter.h ../../ezc/src/ezc.h data.h dirs.h
|
||||
notify.o: item.h dircontainer.h users.h user.h ugcontainer.h groups.h group.h
|
||||
notify.o: functions.h function.h lastcontainer.h mounts.h mount.h error.h
|
||||
notify.o: rebus.h loadavg.h misc.h request.h requesttypes.h session.h
|
||||
notify.o: plugindata.h thread.h compress.h acceptencodingparser.h
|
||||
notify.o: acceptbaseparser.h htmlfilter.h postmultiparser.h ticket.h
|
||||
plugin.o: plugin.h request.h requesttypes.h session.h item.h error.h log.h
|
||||
plugin.o: user.h rebus.h plugindata.h function.h thread.h compress.h
|
||||
plugin.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
|
||||
plugin.o: postmultiparser.h ticket.h data.h dirs.h dircontainer.h users.h
|
||||
plugin.o: ugcontainer.h groups.h group.h functions.h lastcontainer.h mounts.h
|
||||
plugin.o: mount.h loadavg.h pluginmsg.h
|
||||
plugindata.o: plugindata.h plugin.h request.h requesttypes.h session.h item.h
|
||||
plugindata.o: error.h log.h user.h rebus.h function.h thread.h compress.h
|
||||
plugindata.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
|
||||
plugindata.o: postmultiparser.h ticket.h data.h dirs.h dircontainer.h users.h
|
||||
plugindata.o: ugcontainer.h groups.h group.h functions.h lastcontainer.h
|
||||
plugindata.o: mounts.h mount.h loadavg.h pluginmsg.h
|
||||
postmultiparser.o: postmultiparser.h error.h log.h requesttypes.h data.h
|
||||
postmultiparser.o: dirs.h item.h dircontainer.h users.h user.h ugcontainer.h
|
||||
postmultiparser.o: groups.h group.h functions.h function.h lastcontainer.h
|
||||
postmultiparser.o: mounts.h mount.h rebus.h loadavg.h
|
||||
rebus.o: log.h rebus.h misc.h item.h
|
||||
mounts.o: postmultiparser.h config.h confparser.h mountparser.h
|
||||
notify.o: log.h notify.h ../templatesnotify/templatesnotify.h
|
||||
notify.o: ../../ezc/src/ezc.h ../core/mount.h ../core/locale.h confparser.h
|
||||
notify.o: ../core/config.h ../templates/misc.h ../templates/localefilter.h
|
||||
notify.o: ../core/locale.h request.h requesttypes.h session.h item.h error.h
|
||||
notify.o: user.h plugindata.h rebus.h thread.h compress.h
|
||||
notify.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
|
||||
notify.o: postmultiparser.h config.h ticket.h system.h dirs.h dircontainer.h
|
||||
notify.o: db.h group.h ugcontainer.h mounts.h mount.h users.h lastcontainer.h
|
||||
notify.o: groups.h loadavg.h misc.h
|
||||
plugin.o: plugin.h pluginmsg.h log.h plugindata.h config.h confparser.h
|
||||
plugin.o: request.h requesttypes.h session.h item.h error.h user.h rebus.h
|
||||
plugin.o: thread.h compress.h acceptencodingparser.h acceptbaseparser.h
|
||||
plugin.o: htmlfilter.h postmultiparser.h ticket.h system.h dirs.h
|
||||
plugin.o: dircontainer.h db.h group.h ugcontainer.h mounts.h mount.h users.h
|
||||
plugin.o: lastcontainer.h groups.h loadavg.h sessionmanager.h
|
||||
plugin.o: sessioncontainer.h ../functions/functions.h
|
||||
plugin.o: ../functions/functionbase.h ../core/item.h ../core/db.h
|
||||
plugin.o: ../core/request.h ../core/config.h ../core/system.h
|
||||
plugin.o: ../core/notify.h ../../ezc/src/ezc.h ../functions/functionparser.h
|
||||
plugin.o: ../functions/adduser.h ../functions/cat.h ../functions/chmod.h
|
||||
plugin.o: ../functions/privchanger.h ../functions/chown.h ../functions/cp.h
|
||||
plugin.o: ../functions/createthread.h ../functions/createticket.h
|
||||
plugin.o: ../functions/default.h ../functions/download.h
|
||||
plugin.o: ../functions/editticket.h ../functions/emacs.h ../functions/last.h
|
||||
plugin.o: ../functions/login.h ../functions/logout.h ../functions/ls.h
|
||||
plugin.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
|
||||
plugin.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
|
||||
plugin.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
|
||||
plugin.o: ../core/thread.h ../functions/funticket.h ../functions/uname.h
|
||||
plugin.o: ../functions/upload.h ../functions/who.h ../templates/templates.h
|
||||
plugin.o: ../templates/patterncacher.h ../core/item.h misc.h
|
||||
plugin.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
|
||||
plugin.o: ../core/log.h ../templates/indexpatterns.h
|
||||
plugin.o: ../templates/localefilter.h ../core/locale.h ../core/locale.h
|
||||
plugin.o: ../core/sessionmanager.h
|
||||
plugindata.o: plugindata.h plugin.h pluginmsg.h log.h config.h confparser.h
|
||||
plugindata.o: request.h requesttypes.h session.h item.h error.h user.h
|
||||
plugindata.o: rebus.h thread.h compress.h acceptencodingparser.h
|
||||
plugindata.o: acceptbaseparser.h htmlfilter.h postmultiparser.h ticket.h
|
||||
plugindata.o: system.h dirs.h dircontainer.h db.h group.h ugcontainer.h
|
||||
plugindata.o: mounts.h mount.h users.h lastcontainer.h groups.h loadavg.h
|
||||
plugindata.o: sessionmanager.h sessioncontainer.h ../functions/functions.h
|
||||
plugindata.o: ../functions/functionbase.h ../core/item.h ../core/db.h
|
||||
plugindata.o: ../core/request.h ../core/config.h ../core/system.h
|
||||
plugindata.o: ../core/notify.h ../../ezc/src/ezc.h
|
||||
plugindata.o: ../functions/functionparser.h ../functions/adduser.h
|
||||
plugindata.o: ../functions/cat.h ../functions/chmod.h
|
||||
plugindata.o: ../functions/privchanger.h ../functions/chown.h
|
||||
plugindata.o: ../functions/cp.h ../functions/createthread.h
|
||||
plugindata.o: ../functions/createticket.h ../functions/default.h
|
||||
plugindata.o: ../functions/download.h ../functions/editticket.h
|
||||
plugindata.o: ../functions/emacs.h ../functions/last.h ../functions/login.h
|
||||
plugindata.o: ../functions/logout.h ../functions/ls.h ../functions/mkdir.h
|
||||
plugindata.o: ../functions/mv.h ../functions/node.h ../functions/priv.h
|
||||
plugindata.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
|
||||
plugindata.o: ../functions/subject.h ../functions/funthread.h
|
||||
plugindata.o: ../core/thread.h ../functions/funticket.h ../functions/uname.h
|
||||
plugindata.o: ../functions/upload.h ../functions/who.h
|
||||
plugindata.o: ../templates/templates.h ../templates/patterncacher.h
|
||||
plugindata.o: ../core/item.h misc.h ../templates/ckeditorgetparser.h
|
||||
plugindata.o: ../core/httpsimpleparser.h ../core/log.h
|
||||
plugindata.o: ../templates/indexpatterns.h ../templates/localefilter.h
|
||||
plugindata.o: ../core/locale.h ../core/locale.h ../core/sessionmanager.h
|
||||
postmultiparser.o: postmultiparser.h error.h log.h requesttypes.h config.h
|
||||
postmultiparser.o: confparser.h
|
||||
rebus.o: log.h rebus.h misc.h item.h request.h requesttypes.h session.h
|
||||
rebus.o: error.h user.h plugindata.h thread.h compress.h
|
||||
rebus.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
|
||||
rebus.o: postmultiparser.h config.h confparser.h ticket.h
|
||||
request.o: request.h requesttypes.h session.h item.h error.h log.h user.h
|
||||
request.o: rebus.h plugindata.h function.h thread.h compress.h
|
||||
request.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
|
||||
request.o: postmultiparser.h ticket.h getparser.h httpsimpleparser.h
|
||||
request.o: postparser.h cookieparser.h data.h dirs.h dircontainer.h users.h
|
||||
request.o: ugcontainer.h groups.h group.h functions.h lastcontainer.h
|
||||
request.o: mounts.h mount.h loadavg.h plugin.h pluginmsg.h misc.h db.h
|
||||
requestcontroller.o: requestcontroller.h ../content/content.h ../core/item.h
|
||||
requestcontroller.o: ../templates/templates.h ../../ezc/src/ezc.h
|
||||
requestcontroller.o: ../templates/patterncacher.h misc.h item.h
|
||||
requestcontroller.o: ../templates/ckeditorgetparser.h
|
||||
requestcontroller.o: ../core/httpsimpleparser.h ../core/log.h
|
||||
requestcontroller.o: ../core/locale.h ../confparser/confparser.h
|
||||
requestcontroller.o: ../templates/indexpatterns.h ../templates/localefilter.h
|
||||
requestcontroller.o: ../core/thread.h ../core/ticket.h ../core/db.h user.h
|
||||
requestcontroller.o: group.h thread.h error.h log.h dircontainer.h
|
||||
requestcontroller.o: ugcontainer.h ticket.h sessionmanager.h
|
||||
requestcontroller.o: sessioncontainer.h session.h rebus.h plugindata.h
|
||||
requestcontroller.o: functionparser.h requesttypes.h data.h dirs.h users.h
|
||||
requestcontroller.o: groups.h functions.h function.h lastcontainer.h mounts.h
|
||||
requestcontroller.o: mount.h loadavg.h request.h compress.h
|
||||
requestcontroller.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
|
||||
requestcontroller.o: postmultiparser.h postparser.h httpsimpleparser.h
|
||||
requestcontroller.o: cookieparser.h notify.h
|
||||
requestcontroller.o: ../templatesnotify/templatesnotify.h ../core/mount.h
|
||||
requestcontroller.o: ../templates/misc.h
|
||||
session.o: session.h item.h error.h log.h user.h rebus.h plugindata.h
|
||||
request.o: plugindata.h rebus.h thread.h compress.h acceptencodingparser.h
|
||||
request.o: acceptbaseparser.h htmlfilter.h postmultiparser.h config.h
|
||||
request.o: confparser.h ticket.h getparser.h httpsimpleparser.h postparser.h
|
||||
request.o: cookieparser.h plugin.h pluginmsg.h system.h dirs.h dircontainer.h
|
||||
request.o: db.h group.h ugcontainer.h mounts.h mount.h users.h
|
||||
request.o: lastcontainer.h groups.h loadavg.h sessionmanager.h
|
||||
request.o: sessioncontainer.h ../functions/functions.h
|
||||
request.o: ../functions/functionbase.h ../core/item.h ../core/db.h
|
||||
request.o: ../core/request.h ../core/config.h ../core/system.h
|
||||
request.o: ../core/notify.h ../../ezc/src/ezc.h ../functions/functionparser.h
|
||||
request.o: ../functions/adduser.h ../functions/cat.h ../functions/chmod.h
|
||||
request.o: ../functions/privchanger.h ../functions/chown.h ../functions/cp.h
|
||||
request.o: ../functions/createthread.h ../functions/createticket.h
|
||||
request.o: ../functions/default.h ../functions/download.h
|
||||
request.o: ../functions/editticket.h ../functions/emacs.h ../functions/last.h
|
||||
request.o: ../functions/login.h ../functions/logout.h ../functions/ls.h
|
||||
request.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
|
||||
request.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
|
||||
request.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
|
||||
request.o: ../core/thread.h ../functions/funticket.h ../functions/uname.h
|
||||
request.o: ../functions/upload.h ../functions/who.h ../templates/templates.h
|
||||
request.o: ../templates/patterncacher.h ../core/item.h misc.h
|
||||
request.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
|
||||
request.o: ../core/log.h ../templates/indexpatterns.h
|
||||
request.o: ../templates/localefilter.h ../core/locale.h ../core/locale.h
|
||||
request.o: ../core/sessionmanager.h ../functions/functionbase.h
|
||||
session.o: session.h item.h error.h log.h user.h plugindata.h rebus.h
|
||||
sessioncontainer.o: sessioncontainer.h session.h item.h error.h log.h user.h
|
||||
sessioncontainer.o: rebus.h plugindata.h data.h dirs.h dircontainer.h users.h
|
||||
sessioncontainer.o: ugcontainer.h groups.h group.h functions.h function.h
|
||||
sessioncontainer.o: lastcontainer.h mounts.h mount.h loadavg.h
|
||||
sessioncontainer.o: plugindata.h rebus.h lastcontainer.h
|
||||
sessionmanager.o: sessionmanager.h sessioncontainer.h session.h item.h
|
||||
sessionmanager.o: error.h log.h user.h rebus.h plugindata.h request.h
|
||||
sessionmanager.o: requesttypes.h function.h thread.h compress.h
|
||||
sessionmanager.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
|
||||
sessionmanager.o: postmultiparser.h ticket.h data.h dirs.h dircontainer.h
|
||||
sessionmanager.o: users.h ugcontainer.h groups.h group.h functions.h
|
||||
sessionmanager.o: lastcontainer.h mounts.h mount.h loadavg.h sessionparser.h
|
||||
sessionmanager.o: plugin.h pluginmsg.h
|
||||
sessionmanager.o: error.h log.h user.h plugindata.h rebus.h lastcontainer.h
|
||||
sessionmanager.o: config.h confparser.h request.h requesttypes.h thread.h
|
||||
sessionmanager.o: compress.h acceptencodingparser.h acceptbaseparser.h
|
||||
sessionmanager.o: htmlfilter.h postmultiparser.h ticket.h system.h dirs.h
|
||||
sessionmanager.o: dircontainer.h db.h group.h ugcontainer.h mounts.h mount.h
|
||||
sessionmanager.o: users.h groups.h loadavg.h sessionparser.h plugin.h
|
||||
sessionmanager.o: pluginmsg.h ../functions/functions.h
|
||||
sessionmanager.o: ../functions/functionbase.h ../core/item.h ../core/db.h
|
||||
sessionmanager.o: ../core/request.h ../core/config.h ../core/system.h
|
||||
sessionmanager.o: ../core/notify.h ../../ezc/src/ezc.h
|
||||
sessionmanager.o: ../functions/functionparser.h ../functions/adduser.h
|
||||
sessionmanager.o: ../functions/cat.h ../functions/chmod.h
|
||||
sessionmanager.o: ../functions/privchanger.h ../functions/chown.h
|
||||
sessionmanager.o: ../functions/cp.h ../functions/createthread.h
|
||||
sessionmanager.o: ../functions/createticket.h ../functions/default.h
|
||||
sessionmanager.o: ../functions/download.h ../functions/editticket.h
|
||||
sessionmanager.o: ../functions/emacs.h ../functions/last.h
|
||||
sessionmanager.o: ../functions/login.h ../functions/logout.h
|
||||
sessionmanager.o: ../functions/ls.h ../functions/mkdir.h ../functions/mv.h
|
||||
sessionmanager.o: ../functions/node.h ../functions/priv.h
|
||||
sessionmanager.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
|
||||
sessionmanager.o: ../functions/subject.h ../functions/funthread.h
|
||||
sessionmanager.o: ../core/thread.h ../functions/funticket.h
|
||||
sessionmanager.o: ../functions/uname.h ../functions/upload.h
|
||||
sessionmanager.o: ../functions/who.h ../templates/templates.h
|
||||
sessionmanager.o: ../templates/patterncacher.h ../core/item.h misc.h
|
||||
sessionmanager.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
|
||||
sessionmanager.o: ../core/log.h ../templates/indexpatterns.h
|
||||
sessionmanager.o: ../templates/localefilter.h ../core/locale.h
|
||||
sessionmanager.o: ../core/locale.h ../core/sessionmanager.h
|
||||
sessionparser.o: sessionparser.h session.h item.h error.h log.h user.h
|
||||
sessionparser.o: rebus.h plugindata.h sessioncontainer.h data.h dirs.h
|
||||
sessionparser.o: dircontainer.h users.h ugcontainer.h groups.h group.h
|
||||
sessionparser.o: functions.h function.h lastcontainer.h mounts.h mount.h
|
||||
sessionparser.o: loadavg.h
|
||||
users.o: users.h user.h ugcontainer.h log.h db.h item.h group.h thread.h
|
||||
users.o: error.h dircontainer.h ticket.h
|
||||
sessionparser.o: plugindata.h rebus.h sessioncontainer.h lastcontainer.h
|
||||
sessionparser.o: users.h ugcontainer.h request.h requesttypes.h thread.h
|
||||
sessionparser.o: compress.h acceptencodingparser.h acceptbaseparser.h
|
||||
sessionparser.o: htmlfilter.h postmultiparser.h config.h confparser.h
|
||||
sessionparser.o: ticket.h db.h group.h dircontainer.h
|
||||
system.o: system.h dirs.h item.h dircontainer.h db.h user.h group.h thread.h
|
||||
system.o: error.h log.h ugcontainer.h ticket.h request.h requesttypes.h
|
||||
system.o: session.h plugindata.h rebus.h compress.h acceptencodingparser.h
|
||||
system.o: acceptbaseparser.h htmlfilter.h postmultiparser.h config.h
|
||||
system.o: confparser.h mounts.h mount.h users.h lastcontainer.h groups.h
|
||||
system.o: loadavg.h misc.h notify.h ../templatesnotify/templatesnotify.h
|
||||
system.o: ../../ezc/src/ezc.h ../core/mount.h ../core/locale.h
|
||||
system.o: ../core/config.h ../templates/misc.h ../templates/localefilter.h
|
||||
system.o: ../core/locale.h ../functions/functions.h
|
||||
system.o: ../functions/functionbase.h ../core/item.h ../core/db.h
|
||||
system.o: ../core/request.h ../core/system.h ../core/notify.h
|
||||
system.o: ../functions/functionparser.h ../functions/adduser.h
|
||||
system.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
|
||||
system.o: ../functions/chown.h ../functions/cp.h ../functions/createthread.h
|
||||
system.o: ../functions/createticket.h ../functions/default.h
|
||||
system.o: ../functions/download.h ../functions/editticket.h
|
||||
system.o: ../functions/emacs.h ../functions/last.h ../functions/login.h
|
||||
system.o: ../functions/logout.h ../functions/ls.h ../functions/mkdir.h
|
||||
system.o: ../functions/mv.h ../functions/node.h ../functions/priv.h
|
||||
system.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
|
||||
system.o: ../functions/subject.h ../functions/funthread.h ../core/thread.h
|
||||
system.o: ../functions/funticket.h ../functions/uname.h ../functions/upload.h
|
||||
system.o: ../functions/who.h ../templates/templates.h
|
||||
system.o: ../templates/patterncacher.h ../core/item.h
|
||||
system.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
|
||||
system.o: ../core/log.h ../templates/indexpatterns.h ../core/sessionmanager.h
|
||||
users.o: users.h user.h ugcontainer.h log.h lastcontainer.h request.h
|
||||
users.o: requesttypes.h session.h item.h error.h plugindata.h rebus.h
|
||||
users.o: thread.h compress.h acceptencodingparser.h acceptbaseparser.h
|
||||
users.o: htmlfilter.h postmultiparser.h config.h confparser.h ticket.h db.h
|
||||
users.o: group.h dircontainer.h
|
||||
|
||||
@@ -1 +1 @@
|
||||
o = acceptbaseparser.o bbcodeparser.o compress.o config.o data.o db.o db_itemcolumns.o dircontainer.o dirs.o function.o functioncodeparser.o functionparser.o functions.o groups.o htmlfilter.o httpsimpleparser.o lastcontainer.o loadavg.o locale.o log.o misc.o mount.o mountparser.o mounts.o notify.o plugin.o plugindata.o postmultiparser.o rebus.o request.o requestcontroller.o session.o sessioncontainer.o sessionmanager.o sessionparser.o users.o
|
||||
o = Kopia config.o acceptbaseparser.o app.o bbcodeparser.o compress.o config.o confparser.o db.o db_itemcolumns.o dircontainer.o dirs.o groups.o htmlfilter.o httpsimpleparser.o lastcontainer.o loadavg.o locale.o log.o misc.o mount.o mountparser.o mounts.o notify.o plugin.o plugindata.o postmultiparser.o rebus.o request.o session.o sessioncontainer.o sessionmanager.o sessionparser.o system.o users.o
|
||||
|
||||
398
core/app.cpp
Executable file
398
core/app.cpp
Executable file
@@ -0,0 +1,398 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "app.h"
|
||||
#include "plugin.h"
|
||||
|
||||
|
||||
|
||||
App::App()
|
||||
{
|
||||
stdout_is_closed = false;
|
||||
last_sessions_save = time(0);
|
||||
|
||||
plugin.SetDb(&db);
|
||||
plugin.SetConfig(&config);
|
||||
plugin.SetRequest(&request);
|
||||
plugin.SetSystem(&system);
|
||||
plugin.SetFunctions(&functions);
|
||||
plugin.SetTemplates(&templates);
|
||||
plugin.SetSessionManager(&session_manager);
|
||||
|
||||
request.SetConfig(&config);
|
||||
|
||||
functions.SetConfig(&config);
|
||||
functions.SetRequest(&request);
|
||||
functions.SetDb(&db);
|
||||
functions.SetSystem(&system);
|
||||
functions.SetTemplates(&templates);
|
||||
functions.SetNotify(¬ify);
|
||||
|
||||
system.SetConfig(&config);
|
||||
system.SetRequest(&request);
|
||||
system.SetDb(&db);
|
||||
system.SetFunctions(&functions); // !! czy model musi cos wiedziec o funkcjach?
|
||||
system.SetTemplates(&templates);
|
||||
|
||||
templates_notify.SetConfig(&config);
|
||||
|
||||
notify.SetRequest(&request);
|
||||
notify.SetConfig(&config);
|
||||
notify.SetSystem(&system);
|
||||
notify.SetTemplatesNotify(&templates_notify);
|
||||
|
||||
templates.SetConfig(&config);
|
||||
templates.SetRequest(&request);
|
||||
templates.SetDb(&db);
|
||||
templates.SetSystem(&system);
|
||||
templates.SetFunctions(&functions);
|
||||
templates.SetSessionManager(&session_manager);
|
||||
|
||||
session_manager.SetLastContainer(&system.users.last);
|
||||
session_manager.SetConfig(&config);
|
||||
session_manager.SetRequest(&request);
|
||||
session_manager.SetSystem(&system);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool App::CreateFCGISocket()
|
||||
{
|
||||
const char * sock = config.fcgi_socket.c_str();
|
||||
|
||||
unlink(sock);
|
||||
|
||||
|
||||
|
||||
int s = FCGX_OpenSocket(sock, 10);
|
||||
|
||||
if( s < 0 )
|
||||
{
|
||||
log << log1 << "An error during creating a socket" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
chmod(sock, config.fcgi_socket_chmod);
|
||||
|
||||
passwd * pw = getpwnam(config.fcgi_socket_user.c_str());
|
||||
|
||||
if( !pw )
|
||||
{
|
||||
log << log1 << "There is no user: " << config.fcgi_socket_user << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
group * gr = getgrnam(config.fcgi_socket_group.c_str());
|
||||
|
||||
if( !gr )
|
||||
{
|
||||
log << log1 << "There is no group: " << config.fcgi_socket_group << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
chown(sock, pw->pw_uid, gr->gr_gid);
|
||||
|
||||
|
||||
if( setuid(pw->pw_uid) < 0 )
|
||||
{
|
||||
log << log1 << "I can't change the user into: " << config.fcgi_socket_user << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
if( setgid(gr->gr_gid) < 0 )
|
||||
{
|
||||
int e = errno;
|
||||
|
||||
log << log1 << "I can't change the group into: " << config.fcgi_socket_group << " " << gr->gr_gid << logend;
|
||||
log << log1 << "errno: " << e << logend;
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
dup2(s, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool App::Init()
|
||||
{
|
||||
request.Init();
|
||||
|
||||
if( !CreateFCGISocket() )
|
||||
return false;
|
||||
|
||||
system.Init();
|
||||
|
||||
functions.Create();
|
||||
|
||||
// !! teraz mamy dwa katalogi z templetami
|
||||
// !! o co chodzilo?
|
||||
if( !notify.Init() )
|
||||
return false;
|
||||
|
||||
|
||||
templates.ReadIndexFileNames();
|
||||
templates.ReadTemplates();
|
||||
templates.CreateFunctions();
|
||||
|
||||
|
||||
session_manager.LoadSessions();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void App::Close()
|
||||
{
|
||||
session_manager.SaveSessions();
|
||||
session_manager.DeleteAllPluginsData();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool App::BaseUrlRedirect()
|
||||
{
|
||||
if( request.role == Request::responder )
|
||||
{
|
||||
if( config.base_url_http_host.empty() )
|
||||
return false;
|
||||
|
||||
if( config.base_url_http_host == request.env_http_host )
|
||||
return false;
|
||||
|
||||
request.redirect_to = config.base_url + request.env_request_uri;
|
||||
}
|
||||
else
|
||||
{
|
||||
// authorizer
|
||||
|
||||
if( config.base_url_auth_http_host.empty() )
|
||||
return false;
|
||||
|
||||
if( config.base_url_auth_http_host == request.env_http_host )
|
||||
return false;
|
||||
|
||||
request.redirect_to = config.base_url_auth + request.env_request_uri;
|
||||
}
|
||||
|
||||
log << log3 << "RC: BaseUrlRedirect from: " << request.env_http_host << logend;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void App::ProcessRequest()
|
||||
{
|
||||
request.Clear();
|
||||
request.Read();
|
||||
|
||||
// when BaseUrlRedirect() return true we didn't have to set everything in request.Read()
|
||||
// in the future request.Read() can be split and at the beginning only environment variables will be read
|
||||
// and then BaseUrlRedirect() will be called (for performance)
|
||||
if( !BaseUrlRedirect() )
|
||||
{
|
||||
session_manager.DeleteOldSessions();
|
||||
session_manager.SetSession(); // set request.session as well
|
||||
|
||||
// !! tutaj dodac to ustawianie request.session
|
||||
|
||||
functions.Parse();
|
||||
|
||||
system.mounts.CalcCurMount();
|
||||
|
||||
ReadAdditionalInfo();
|
||||
Make();
|
||||
}
|
||||
|
||||
request.SendAll(); // !! czemu request sam sie chce wyslac? wrzucic to tutaj do app
|
||||
notify.ItemChanged(request.notify_code);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void App::Start()
|
||||
{
|
||||
while( FCGX_Accept(&request.in, &request.out, &request.err, &request.env) == 0 )
|
||||
{
|
||||
system.load_avg.StartRequest();
|
||||
log << log2 << "---------------------------------------------------------------------------------" << logend;
|
||||
|
||||
try
|
||||
{
|
||||
ProcessRequest();
|
||||
}
|
||||
catch(const std::logic_error & e)
|
||||
{
|
||||
log << log1 << "std logic exception: " << e.what() << logend;
|
||||
}
|
||||
catch(const std::exception & e)
|
||||
{
|
||||
log << log1 << "std exception: " << e.what() << logend;
|
||||
}
|
||||
catch(const Error & e)
|
||||
{
|
||||
log << log1 << "exception: Error: " << e << logend;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
log << log1 << "uncaught unknown exception" << logend;
|
||||
}
|
||||
|
||||
SaveSessionsIfNeeded();
|
||||
|
||||
// !! this should be immediately after FCGX_Accept() but signals don't want to break FCGX_Accept
|
||||
//if( signal_hup )
|
||||
if( false )
|
||||
{
|
||||
log << logsave;
|
||||
FCGX_Finish();
|
||||
return;
|
||||
}
|
||||
|
||||
request.ClearPostFileTmp();
|
||||
system.load_avg.StopRequest();
|
||||
log << logsave;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void App::SaveSessionsIfNeeded()
|
||||
{
|
||||
time_t t = time(0);
|
||||
|
||||
if( last_sessions_save + 86400 > t )
|
||||
return;
|
||||
|
||||
// saving once a day for safety
|
||||
last_sessions_save = t;
|
||||
session_manager.SaveSessions();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// !! zmienic na lepsza nazwe
|
||||
void App::MakePage()
|
||||
{
|
||||
bool sent = false;
|
||||
|
||||
if( !request.redirect_to.empty() || !request.x_sendfile.empty() )
|
||||
return;
|
||||
|
||||
|
||||
if( request.is_item && request.item.auth == Item::auth_none &&
|
||||
request.item.content_type == Item::ct_raw && request.status == WINIX_ERR_OK && request.pfunction )
|
||||
{
|
||||
if( request.pfunction->fun.url == "cat" )
|
||||
{
|
||||
request.page << request.item.content;
|
||||
sent = true;
|
||||
}
|
||||
else
|
||||
if( request.pfunction->fun.url == "run" )
|
||||
{
|
||||
templates.GenerateRunRaw();
|
||||
sent = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( !sent )
|
||||
{
|
||||
templates.Generate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void App::Make()
|
||||
{
|
||||
if( request.dir_table.empty() )
|
||||
{
|
||||
log << log1 << "Content: there is no a root dir (dir_table is empty)" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
// request->status can be changed by function_parser
|
||||
if( request.status == WINIX_ERR_OK )
|
||||
{
|
||||
if( system.DirsHaveReadExecPerm() )
|
||||
{
|
||||
if( request.method == Request::post )
|
||||
functions.MakePost();
|
||||
|
||||
if( request.redirect_to.empty() && request.status == WINIX_ERR_OK )
|
||||
functions.MakeGet();
|
||||
}
|
||||
else
|
||||
request.status = WINIX_ERR_PERMISSION_DENIED;
|
||||
}
|
||||
|
||||
if( request.session->spam_score > 0 )
|
||||
log << log1 << "App: spam score: " << request.session->spam_score << logend;
|
||||
|
||||
if( request.IsParam("noredirect") )
|
||||
request.redirect_to.clear();
|
||||
|
||||
if( !request.redirect_to.empty() )
|
||||
return;
|
||||
|
||||
if( request.dir_table.empty() )
|
||||
{
|
||||
log << log1 << "App: there is no a root dir (dir_table is empty -- after calling a function)" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.Call(WINIX_CONTENT_MAKE);
|
||||
MakePage();
|
||||
|
||||
// !! dodac parametr do konfiga wlaczajacy te informacje
|
||||
//request->PrintGetTable();
|
||||
//request->PrintEnv();
|
||||
//request->PrintIn();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// !! dac lepsza nazwe i czy napewno w app to ma byc?
|
||||
void App::ReadAdditionalInfo()
|
||||
{
|
||||
if( request.dir_table.empty() )
|
||||
return;
|
||||
|
||||
if( system.mounts.pmount->type == Mount::thread )
|
||||
{
|
||||
if( db.GetThreadByDirId(request.dir_table.back()->id, request.thread) == WINIX_ERR_OK )
|
||||
request.is_thread = true;
|
||||
}
|
||||
else
|
||||
if( system.mounts.pmount->type == Mount::ticket )
|
||||
{
|
||||
if( db.GetTicketByDirId(request.dir_table.back()->id, request.ticket) == WINIX_ERR_OK )
|
||||
{
|
||||
request.is_ticket = true;
|
||||
|
||||
if( !request.is_item && (!request.pfunction || request.pfunction->fun.url == "ticket") )
|
||||
{
|
||||
db.GetItemById(request.ticket.item_id, request.item);
|
||||
// don't set request->is_item here
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
111
core/app.h
Executable file
111
core/app.h
Executable file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilecmslucoreapp
|
||||
#define headerfilecmslucoreapp
|
||||
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "system.h"
|
||||
#include "mounts.h"
|
||||
#include "request.h"
|
||||
#include "sessionmanager.h"
|
||||
#include "notify.h"
|
||||
#include "db.h"
|
||||
#include "functions/functions.h"
|
||||
#include "templates/templates.h"
|
||||
#include "templatesnotify/templatesnotify.h"
|
||||
|
||||
|
||||
|
||||
|
||||
class App
|
||||
{
|
||||
public:
|
||||
|
||||
App();
|
||||
|
||||
bool Init();
|
||||
void Start();
|
||||
void Close();
|
||||
|
||||
|
||||
|
||||
// configuration read from a config file
|
||||
Config config;
|
||||
|
||||
// current request
|
||||
Request request;
|
||||
|
||||
// users sessions
|
||||
SessionManager session_manager;
|
||||
|
||||
// notifications (by emails)
|
||||
Notify notify;
|
||||
|
||||
// database
|
||||
Db db;
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
model
|
||||
*/
|
||||
|
||||
// file system
|
||||
System system;
|
||||
|
||||
// false at the beginning
|
||||
bool stdout_is_closed;
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
controller
|
||||
*/
|
||||
|
||||
// functions (ls, cat, emacs, ...)
|
||||
Functions functions;
|
||||
|
||||
|
||||
/*
|
||||
view
|
||||
*/
|
||||
|
||||
Templates templates;
|
||||
TemplatesNotify templates_notify;
|
||||
|
||||
|
||||
private:
|
||||
bool CreateFCGISocket();
|
||||
void ProcessRequest();
|
||||
bool BaseUrlRedirect();
|
||||
void DeleteAllPluginsData();
|
||||
void MakePage();
|
||||
void Make();
|
||||
void ReadAdditionalInfo();
|
||||
void SaveSessionsIfNeeded(); // !! wywalic do managara sesji??
|
||||
|
||||
// !! dodac do session managera?
|
||||
time_t last_sessions_save;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
216
core/config.cpp
216
core/config.cpp
@@ -9,7 +9,6 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
#include "data.h"
|
||||
#include "plugin.h"
|
||||
#include "misc.h"
|
||||
|
||||
@@ -17,10 +16,6 @@
|
||||
|
||||
Config::Config()
|
||||
{
|
||||
default_str.clear();
|
||||
default_int = 0;
|
||||
default_bool = false;
|
||||
|
||||
errors_to_stdout = true;
|
||||
}
|
||||
|
||||
@@ -33,7 +28,7 @@ Config::Config()
|
||||
void Config::ShowError()
|
||||
{
|
||||
|
||||
switch( conf_parser.status )
|
||||
switch( parser.status )
|
||||
{
|
||||
case ConfParser::ok:
|
||||
log << log2 << "Config: syntax ok" << logend;
|
||||
@@ -41,16 +36,16 @@ void Config::ShowError()
|
||||
|
||||
case ConfParser::cant_open_file:
|
||||
if( errors_to_stdout )
|
||||
std::cout << "Config: cant open a config file: " << data.config_file << std::endl;
|
||||
std::cout << "Config: cant open a config file: " << config_file << std::endl;
|
||||
|
||||
log << log1 << "Config: cant open a config file: " << data.config_file << logend;
|
||||
log << log1 << "Config: cant open a config file: " << config_file << logend;
|
||||
break;
|
||||
|
||||
case ConfParser::syntax_error:
|
||||
if( errors_to_stdout )
|
||||
std::cout << "Config: syntax error, line: " << conf_parser.line << std::endl;
|
||||
std::cout << "Config: syntax error, line: " << parser.line << std::endl;
|
||||
|
||||
log << log1 << "Config: syntax error, line: " << conf_parser.line << logend;
|
||||
log << log1 << "Config: syntax error, line: " << parser.line << logend;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -60,11 +55,11 @@ void Config::ShowError()
|
||||
|
||||
|
||||
|
||||
bool Config::ReadConfig(bool errors_to_stdout_)
|
||||
bool Config::ReadConfig(bool errors_to_stdout_, bool stdout_is_closed)
|
||||
{
|
||||
errors_to_stdout = errors_to_stdout_;
|
||||
|
||||
if( data.config_file.empty() )
|
||||
if( config_file.empty() )
|
||||
{
|
||||
log << log2 << "Config: name of the config file is empty" << logend;
|
||||
return false;
|
||||
@@ -72,14 +67,14 @@ bool Config::ReadConfig(bool errors_to_stdout_)
|
||||
|
||||
log << log2 << "Config: reading a config file" << logend;
|
||||
|
||||
conf_parser.SplitSingle(true);
|
||||
ConfParser::Status status = conf_parser.Parse( data.config_file );
|
||||
parser.SplitSingle(true);
|
||||
ConfParser::Status status = parser.Parse( config_file );
|
||||
|
||||
|
||||
if( status == ConfParser::ok )
|
||||
{
|
||||
AssignValues();
|
||||
data.SetAdditionalVariables();
|
||||
AssignValues(stdout_is_closed);
|
||||
SetAdditionalVariables();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -92,177 +87,148 @@ bool Config::ReadConfig(bool errors_to_stdout_)
|
||||
|
||||
|
||||
|
||||
void Config::AssignValues()
|
||||
void Config::AssignValues(bool stdout_is_closed)
|
||||
{
|
||||
data.log_file = Text("log_file");
|
||||
data.log_notify_file = Text("log_notify_file");
|
||||
data.fcgi_socket = Text("fcgi_socket");
|
||||
data.fcgi_socket_chmod = Int("fcgi_socket_chmod", 0770);
|
||||
data.fcgi_socket_user = Text("fcgi_socket_user");
|
||||
data.fcgi_socket_group = Text("fcgi_socket_group");
|
||||
data.log_level = Int("log_level", 1);
|
||||
data.log_request = Int("log_request", 1);
|
||||
log_file = Text("log_file");
|
||||
log_notify_file = Text("log_notify_file");
|
||||
fcgi_socket = Text("fcgi_socket");
|
||||
fcgi_socket_chmod = Int("fcgi_socket_chmod", 0770);
|
||||
fcgi_socket_user = Text("fcgi_socket_user");
|
||||
fcgi_socket_group = Text("fcgi_socket_group");
|
||||
log_level = Int("log_level", 1);
|
||||
log_request = Int("log_request", 1);
|
||||
log_stdout = Bool("log_stdout", false);
|
||||
|
||||
if( !data.stdout_is_closed )
|
||||
data.log_stdout = Bool("log_stdout", false);
|
||||
else
|
||||
data.log_stdout = false;
|
||||
post_file_max = Int("post_file_max", 8388608); // 8 MB
|
||||
auth_simplefs_dir = Text("auth_simplefs_dir");
|
||||
auth_hashfs_dir = Text("auth_hashfs_dir");
|
||||
auth_tmp_dir = Text("auth_tmp_dir");
|
||||
|
||||
templates_dir = Text("templates_dir");
|
||||
templates_dir_default = Text("templates_dir_default");
|
||||
http_session_id_name = Text("http_session_id_name");
|
||||
db_database = Text("db_database");
|
||||
db_user = Text("db_user");
|
||||
db_pass = Text("db_pass");
|
||||
item_url_empty = Text("item_url_empty");
|
||||
|
||||
base_server = Text("base_server");
|
||||
base_url = Text("base_url");
|
||||
base_url_auth = Text("base_url_auth");
|
||||
base_url_static = Text("base_url_static");
|
||||
base_url_common = Text("base_url_common");
|
||||
|
||||
NoLastSlash(base_server);
|
||||
NoLastSlash(base_url);
|
||||
NoLastSlash(base_url_auth);
|
||||
NoLastSlash(base_url_static);
|
||||
NoLastSlash(base_url_common);
|
||||
|
||||
priv_no_user = Text("priv_no_user", "-- no user --");
|
||||
priv_no_group = Text("priv_no_group", "-- no group --");
|
||||
|
||||
data.post_file_max = Int("post_file_max", 8388608); // 8 MB
|
||||
data.auth_simplefs_dir = Text("auth_simplefs_dir");
|
||||
data.auth_hashfs_dir = Text("auth_hashfs_dir");
|
||||
data.auth_tmp_dir = Text("auth_tmp_dir");
|
||||
session_max_idle = Int("session_max_idle", 10800); // 3h
|
||||
session_remember_max_idle = Int("session_remember_max_idle", 16070400); // 3 months
|
||||
session_file = Text("session_file");
|
||||
|
||||
data.templates_dir = Text("templates_dir");
|
||||
data.templates_dir_default = Text("templates_dir_default");
|
||||
data.http_session_id_name = Text("http_session_id_name");
|
||||
data.db_database = Text("db_database");
|
||||
data.db_user = Text("db_user");
|
||||
data.db_pass = Text("db_pass");
|
||||
data.item_url_empty = Text("item_url_empty");
|
||||
compression = Bool("compression", true);
|
||||
html_filter = Bool("html_filter", true);
|
||||
|
||||
data.base_server = Text("base_server");
|
||||
data.base_url = Text("base_url");
|
||||
data.base_url_auth = Text("base_url_auth");
|
||||
data.base_url_static = Text("base_url_static");
|
||||
data.base_url_common = Text("base_url_common");
|
||||
locale_str = Text("locale", "en");
|
||||
locale_dir = Text("locale_dir");
|
||||
locale_dir_default = Text("locale_dir_default");
|
||||
|
||||
NoLastSlash(data.base_server);
|
||||
NoLastSlash(data.base_url);
|
||||
NoLastSlash(data.base_url_auth);
|
||||
NoLastSlash(data.base_url_static);
|
||||
NoLastSlash(data.base_url_common);
|
||||
title_separator = Text("title_separator", " / ");
|
||||
|
||||
data.priv_no_user = Text("priv_no_user", "-- no user --");
|
||||
data.priv_no_group = Text("priv_no_group", "-- no group --");
|
||||
|
||||
data.session_max_idle = Int("session_max_idle", 10800); // 3h
|
||||
data.session_remember_max_idle = Int("session_remember_max_idle", 16070400); // 3 months
|
||||
data.session_file = Text("session_file");
|
||||
|
||||
data.compression = Bool("compression", true);
|
||||
data.html_filter = Bool("html_filter", true);
|
||||
|
||||
data.locale_str = Text("locale", "en");
|
||||
data.locale_dir = Text("locale_dir");
|
||||
data.locale_dir_default = Text("locale_dir_default");
|
||||
|
||||
data.title_separator = Text("title_separator", " / ");
|
||||
|
||||
|
||||
ListText(data.plugin_file, "plugins");
|
||||
parser.ListText("plugins", plugin_file);
|
||||
}
|
||||
|
||||
|
||||
void Config::SetAdditionalVariables()
|
||||
{
|
||||
SetHttpHost(base_url, base_url_http_host);
|
||||
SetHttpHost(base_url_auth, base_url_auth_http_host);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Config::SetHttpHost(const std::string & in, std::string & out)
|
||||
{
|
||||
if( strncmp(in.c_str(), "http://", 7) == 0 )
|
||||
out = in.substr(7);
|
||||
else
|
||||
if( strncmp(in.c_str(), "https://", 8) == 0 )
|
||||
out = in.substr(8);
|
||||
else
|
||||
out.clear(); // if empty the RequestController::BaseUrlRedirect() returns false and no redirecting will be done
|
||||
}
|
||||
|
||||
|
||||
std::string Config::Text(const char * name)
|
||||
{
|
||||
return Text(std::string(name), default_str);
|
||||
return parser.Text(name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string Config::Text(const char * name, const char * def)
|
||||
{
|
||||
return Text(std::string(name), std::string(def));
|
||||
return parser.Text(name, def);
|
||||
}
|
||||
|
||||
|
||||
std::string Config::Text(const std::string & name, const std::string & def)
|
||||
{
|
||||
ConfParser::TableSingle::iterator i = conf_parser.table_single.find(name);
|
||||
|
||||
if( i == conf_parser.table_single.end() )
|
||||
return def;
|
||||
|
||||
return i->second;
|
||||
return parser.Text(name, def);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int Config::Int(const char * name)
|
||||
{
|
||||
return Int(std::string(name), default_int);
|
||||
return parser.Int(name);
|
||||
}
|
||||
|
||||
|
||||
int Config::Int(const char * name, int def)
|
||||
{
|
||||
return Int(std::string(name), def);
|
||||
return parser.Int(name, def);
|
||||
}
|
||||
|
||||
|
||||
int Config::Int(const std::string & name, int def)
|
||||
{
|
||||
ConfParser::TableSingle::iterator i = conf_parser.table_single.find(name);
|
||||
|
||||
if( i == conf_parser.table_single.end() || i->second.empty() )
|
||||
return def;
|
||||
|
||||
long res = (i->second[0] == '0')? strtol(i->second.c_str() + 1, 0, 8) : strtol(i->second.c_str(), 0, 10);
|
||||
|
||||
return res;
|
||||
return parser.Int(name, def);
|
||||
}
|
||||
|
||||
|
||||
bool Config::Bool(const char * name)
|
||||
{
|
||||
return Bool(std::string(name), default_bool);
|
||||
return parser.Bool(name);
|
||||
}
|
||||
|
||||
|
||||
bool Config::Bool(const char * name, bool def)
|
||||
{
|
||||
return Bool(std::string(name), def);
|
||||
return parser.Bool(name, def);
|
||||
}
|
||||
|
||||
|
||||
bool Config::Bool(const std::string & name, bool def)
|
||||
{
|
||||
ConfParser::TableSingle::iterator i = conf_parser.table_single.find(name);
|
||||
|
||||
if( i == conf_parser.table_single.end() || i->second.empty() )
|
||||
return def;
|
||||
|
||||
bool res = false;
|
||||
|
||||
if( EqualNoCase(i->second.c_str(), "true") ||
|
||||
EqualNoCase(i->second.c_str(), "yes") ||
|
||||
EqualNoCase(i->second.c_str(), "1")
|
||||
)
|
||||
res = true;
|
||||
|
||||
return res;
|
||||
return parser.Bool(name, def);
|
||||
}
|
||||
|
||||
|
||||
// in lists we don't use default values
|
||||
void Config::ListText(std::vector<std::string> & list, const char * name)
|
||||
|
||||
void Config::ListText(const char * name, std::vector<std::string> & list)
|
||||
{
|
||||
ListText(list, std::string(name));
|
||||
parser.ListText(name, list);
|
||||
}
|
||||
|
||||
|
||||
void Config::ListText(std::vector<std::string> & list, const std::string & name)
|
||||
void Config::ListText(const std::string & name, std::vector<std::string> & list)
|
||||
{
|
||||
list.clear();
|
||||
|
||||
ConfParser::TableSingle::iterator i = conf_parser.table_single.find(name);
|
||||
|
||||
if( i != conf_parser.table_single.end() )
|
||||
{
|
||||
list.push_back(i->second);
|
||||
return;
|
||||
}
|
||||
|
||||
ConfParser::Table::iterator z = conf_parser.table.find(name);
|
||||
|
||||
if( z != conf_parser.table.end() )
|
||||
{
|
||||
list = z->second;
|
||||
return;
|
||||
}
|
||||
parser.ListText(name, list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
142
core/config.h
142
core/config.h
@@ -11,43 +11,157 @@
|
||||
#define headerfilecmslucoreconfig
|
||||
|
||||
#include <string>
|
||||
#include "../confparser/confparser.h"
|
||||
#include "confparser.h"
|
||||
|
||||
|
||||
|
||||
|
||||
class Config
|
||||
{
|
||||
|
||||
public:
|
||||
Config();
|
||||
bool ReadConfig(bool errors_to_stdout_);
|
||||
|
||||
// name of the config file (full path can be)
|
||||
std::string config_file;
|
||||
|
||||
// log file name, log file name for notifications (sending emails, etc)
|
||||
std::string log_file, log_notify_file;
|
||||
|
||||
// 1 - minimum
|
||||
// 2 - (default)
|
||||
// 3 - maximum - all logs
|
||||
int log_level;
|
||||
|
||||
// logging to stdout too
|
||||
bool log_stdout;
|
||||
|
||||
// how many requests should be logged in the same time
|
||||
// default: 1
|
||||
int log_request;
|
||||
|
||||
// fast cgi: socket (unix domain)
|
||||
std::string fcgi_socket;
|
||||
|
||||
// fast cgi: socket permissions
|
||||
int fcgi_socket_chmod;
|
||||
|
||||
// fast cgi: owner of the socket
|
||||
std::string fcgi_socket_user;
|
||||
|
||||
// fast cgi: group of the socket
|
||||
std::string fcgi_socket_group;
|
||||
|
||||
std::string templates_dir;
|
||||
std::string templates_dir_default; // templates from winix
|
||||
|
||||
std::string db_database;
|
||||
std::string db_user;
|
||||
std::string db_pass;
|
||||
|
||||
std::string http_session_id_name;
|
||||
|
||||
// when the HOST_HTTP environment variable doesn't point into 'base_url' (the part 'http://' and the last slash is removed)
|
||||
// the server will redirect into 'base_url' + 'REQUEST_URI'
|
||||
// it's useful when you want to redirect from 'mydomain.tld' into 'www.mydomain.tld' etc.
|
||||
bool base_url_redirect;
|
||||
|
||||
// string used in a place where is a user (or group) selected
|
||||
std::string priv_no_user;
|
||||
std::string priv_no_group;
|
||||
|
||||
// time in seconds when the user will be automatically logged out (iddle time)
|
||||
int session_max_idle;
|
||||
|
||||
// time in seconds when the user will be automatically logged out (when he selected 'remember me' option)
|
||||
// this time is usually greater than session_max_idle
|
||||
int session_remember_max_idle;
|
||||
|
||||
// this file is used when the program is starting and ending
|
||||
std::string session_file;
|
||||
|
||||
// allow the html ouput to be compressed
|
||||
bool compression;
|
||||
|
||||
// plugins
|
||||
std::vector<std::string> plugin_file;
|
||||
|
||||
// the html code is cleaned by our filter
|
||||
bool html_filter;
|
||||
|
||||
// the url of a new empty item (if there is not the subject too)
|
||||
std::string item_url_empty;
|
||||
|
||||
// maximum length of a file send by post multipart form
|
||||
// 0 - not used
|
||||
int post_file_max;
|
||||
|
||||
// directories for static files
|
||||
std::string auth_simplefs_dir;
|
||||
std::string auth_hashfs_dir;
|
||||
|
||||
// temporary directory for static content used by the upload function
|
||||
// should be on the same partition as auth_simplefs_dir and auth_hashfs_dir
|
||||
std::string auth_tmp_dir;
|
||||
|
||||
// default locale: en pl
|
||||
std::string locale_str;
|
||||
|
||||
// directory with locale files
|
||||
std::string locale_dir;
|
||||
|
||||
// directory with default locale files (those from winix)
|
||||
std::string locale_dir_default;
|
||||
|
||||
// the main address of the server (e.g. someserver.com) (without the 'www' part etc)
|
||||
std::string base_server;
|
||||
|
||||
// the main address of the site (e.g. http://www.someserver.com)
|
||||
std::string base_url;
|
||||
|
||||
// static content authorized by winix
|
||||
std::string base_url_auth;
|
||||
|
||||
// static content not authorized by winix
|
||||
std::string base_url_static;
|
||||
|
||||
// additional static server for common content (not authorized)
|
||||
std::string base_url_common;
|
||||
|
||||
// separator used in <title> html tag
|
||||
std::string title_separator;
|
||||
|
||||
|
||||
// based on base_url
|
||||
// set by SetAdditionalVariables()
|
||||
// without the first part http:// (or https://) or the whole string is empty
|
||||
std::string base_url_http_host;
|
||||
std::string base_url_auth_http_host;
|
||||
|
||||
|
||||
Config();
|
||||
bool ReadConfig(bool errors_to_stdout_, bool stdout_is_closed = true);
|
||||
|
||||
std::string Text(const char * name);
|
||||
std::string Text(const char * name, const char * def);
|
||||
std::string Text(const std::string & name, const std::string & def);
|
||||
|
||||
int Int(const char *);
|
||||
int Int(const char * name, int def);
|
||||
int Int(const std::string & name, int def);
|
||||
|
||||
bool Bool(const char *);
|
||||
bool Bool(const char * name, bool def);
|
||||
bool Bool(const std::string & name, bool def);
|
||||
|
||||
void ListText(std::vector<std::string> & list, const char * name);
|
||||
void ListText(std::vector<std::string> & list, const std::string & name);
|
||||
void ListText(const char * name, std::vector<std::string> & list);
|
||||
void ListText(const std::string & name, std::vector<std::string> & list);
|
||||
|
||||
void NoLastSlash(std::string & s);
|
||||
void NoFirstHttp(std::string & s);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
ConfParser conf_parser;
|
||||
void ShowError();
|
||||
void AssignValues();
|
||||
void AssignValues(bool stdout_is_closed);
|
||||
void SetHttpHost(const std::string & in, std::string & out);
|
||||
void SetAdditionalVariables();
|
||||
|
||||
ConfParser parser;
|
||||
|
||||
std::string default_str;
|
||||
int default_int;
|
||||
@@ -58,7 +172,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
extern Config config;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
541
core/confparser.cpp
Executable file
541
core/confparser.cpp
Executable file
@@ -0,0 +1,541 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "confparser.h"
|
||||
#include "misc.h"
|
||||
|
||||
|
||||
|
||||
ConfParser::ConfParser()
|
||||
{
|
||||
// you can change this separators to what you want
|
||||
// you shoud not use only white characters here (as expected by IsWhite() method)
|
||||
// and new line characters ('\n')
|
||||
separator = '=';
|
||||
commentary = '#';
|
||||
list_start = '(';
|
||||
list_end = ')';
|
||||
list_delimiter = ',';
|
||||
split_single = false;
|
||||
skip_empty = false;
|
||||
|
||||
default_str = "";
|
||||
default_int = 0;
|
||||
default_bool = false;
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::SplitSingle(bool split)
|
||||
{
|
||||
split_single = split;
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::SkipEmpty(bool skip)
|
||||
{
|
||||
skip_empty = skip;
|
||||
}
|
||||
|
||||
|
||||
ConfParser::Status ConfParser::Parse(const char * file_name)
|
||||
{
|
||||
line = 1;
|
||||
table.clear();
|
||||
table_single.clear();
|
||||
|
||||
file.clear();
|
||||
file.open( file_name );
|
||||
|
||||
if( file )
|
||||
{
|
||||
status = ParseFile();
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
status = cant_open_file;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ConfParser::Status ConfParser::Parse(const std::string & file_name)
|
||||
{
|
||||
return Parse(file_name.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
ConfParser::Status ConfParser::ParseFile()
|
||||
{
|
||||
ReadChar();
|
||||
SkipWhiteLines();
|
||||
|
||||
while( lastc != -1 )
|
||||
{
|
||||
if( !ReadVariable() )
|
||||
return syntax_error;
|
||||
|
||||
if( lastc != separator )
|
||||
return syntax_error;
|
||||
|
||||
if( !ReadValue() )
|
||||
return syntax_error;
|
||||
|
||||
AddOption();
|
||||
SkipWhite();
|
||||
|
||||
if( lastc != -1 && lastc != '\n' )
|
||||
return syntax_error; // some characters have left at the end of an option
|
||||
|
||||
SkipWhiteLines();
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ConfParser::IsVariableChar(int c)
|
||||
{
|
||||
if( (c>='a' && c<='z') ||
|
||||
(c>='A' && c<='Z') ||
|
||||
(c>='0' && c<='9') ||
|
||||
c=='.' || c==',' || c=='_' )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConfParser::AddOption()
|
||||
{
|
||||
if( value.empty() && skip_empty )
|
||||
{
|
||||
DeleteFromTable(variable);
|
||||
DeleteFromTableSingle(variable);
|
||||
return;
|
||||
}
|
||||
|
||||
if( split_single && value.size() == 1 )
|
||||
{
|
||||
table_single[variable] = value[0];
|
||||
DeleteFromTable(variable);
|
||||
}
|
||||
else
|
||||
{
|
||||
table[variable] = value;
|
||||
DeleteFromTableSingle(variable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConfParser::DeleteFromTable(const std::string & var)
|
||||
{
|
||||
Table::iterator i = table.find(var);
|
||||
|
||||
if( i != table.end() )
|
||||
table.erase(i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConfParser::DeleteFromTableSingle(const std::string & var)
|
||||
{
|
||||
TableSingle::iterator i = table_single.find(var);
|
||||
|
||||
if( i != table_single.end() )
|
||||
table_single.erase(i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ConfParser::ReadVariable()
|
||||
{
|
||||
variable.clear();
|
||||
SkipWhite();
|
||||
|
||||
while( IsVariableChar(lastc) )
|
||||
{
|
||||
variable += lastc;
|
||||
ReadChar();
|
||||
}
|
||||
|
||||
SkipWhite();
|
||||
|
||||
return !variable.empty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ConfParser::ReadValue()
|
||||
{
|
||||
value.clear();
|
||||
ReadChar(); // skipping separator '='
|
||||
SkipWhite();
|
||||
|
||||
if( lastc == list_start )
|
||||
return ReadValueList();
|
||||
else
|
||||
return ReadValueNoList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ConfParser::ReadValueList()
|
||||
{
|
||||
ReadChar(); // skipping first list character '('
|
||||
SkipWhiteLines(); // lists can be split into several lines
|
||||
|
||||
while( lastc != -1 && lastc != list_end )
|
||||
{
|
||||
if( !ReadValueNoList(true) )
|
||||
return false;
|
||||
|
||||
if( lastc == list_delimiter )
|
||||
ReadChar();
|
||||
|
||||
SkipWhiteLines();
|
||||
}
|
||||
|
||||
if( lastc != list_end )
|
||||
return false;
|
||||
|
||||
ReadChar(); // skipping last list character ')'
|
||||
SkipWhite();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ConfParser::ReadValueNoList(bool use_list_delimiter)
|
||||
{
|
||||
bool res;
|
||||
|
||||
value_item.clear();
|
||||
|
||||
if( lastc == '"' )
|
||||
{
|
||||
res = ReadValueQuoted(); // quoted value
|
||||
|
||||
if( res )
|
||||
value.push_back(value_item);
|
||||
}
|
||||
else
|
||||
{
|
||||
res = ReadValueSimple(use_list_delimiter);
|
||||
|
||||
if( res && !value_item.empty() )
|
||||
value.push_back(value_item);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ConfParser::ReadValueQuoted()
|
||||
{
|
||||
ReadChar(); // skipping the first quote
|
||||
|
||||
while( lastc != '"' && lastc != -1 )
|
||||
{
|
||||
if( lastc == '\\' )
|
||||
ReadChar();
|
||||
|
||||
value_item += lastc;
|
||||
ReadChar();
|
||||
}
|
||||
|
||||
if( lastc != '"' )
|
||||
return false;
|
||||
|
||||
ReadChar(); // skipping the last quote
|
||||
SkipWhite();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ConfParser::ReadValueSimple(bool use_list_delimiter)
|
||||
{
|
||||
int list_delimiter1 = -1;
|
||||
int list_delimiter2 = -1;
|
||||
|
||||
if( use_list_delimiter )
|
||||
{
|
||||
list_delimiter1 = list_delimiter;
|
||||
list_delimiter2 = list_end;
|
||||
}
|
||||
|
||||
while( lastc!=-1 && lastc!='\n' && lastc!=commentary &&
|
||||
lastc!=list_delimiter1 && lastc!=list_delimiter2 )
|
||||
{
|
||||
value_item += lastc;
|
||||
ReadChar();
|
||||
}
|
||||
|
||||
Trim(value_item);
|
||||
SkipWhite();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int ConfParser::ReadChar()
|
||||
{
|
||||
lastc = file.get();
|
||||
|
||||
if( lastc == '\n' )
|
||||
++line;
|
||||
|
||||
return lastc;
|
||||
}
|
||||
|
||||
|
||||
bool ConfParser::IsWhite(int c)
|
||||
{
|
||||
// dont use '\n' here
|
||||
// 13 (\r) is at the end of a line in a dos file \r\n
|
||||
// 160 is an unbreakable space
|
||||
if( c==' ' || c=='\t' || c==13 || c==160 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConfParser::SkipWhite()
|
||||
{
|
||||
while( IsWhite(lastc) || lastc == commentary )
|
||||
{
|
||||
if( lastc == commentary )
|
||||
SkipLine();
|
||||
else
|
||||
ReadChar();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::SkipWhiteLines()
|
||||
{
|
||||
while( IsWhite(lastc) || lastc == commentary || lastc=='\n' )
|
||||
{
|
||||
if( lastc == commentary )
|
||||
SkipLine();
|
||||
else
|
||||
ReadChar();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::SkipLine()
|
||||
{
|
||||
while( lastc != -1 && lastc != '\n' )
|
||||
ReadChar();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConfParser::Trim(std::string & s)
|
||||
{
|
||||
std::string::size_type i;
|
||||
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
// looking for white characters at the end
|
||||
for(i=s.size()-1 ; i>0 && IsWhite(s[i]) ; --i);
|
||||
|
||||
if( i==0 && IsWhite(s[i]) )
|
||||
{
|
||||
// the whole string has white characters
|
||||
s.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// deleting white characters at the end
|
||||
if( i != s.size() - 1 )
|
||||
s.erase(i+1, std::string::npos);
|
||||
|
||||
// looking for white characters at the beginning
|
||||
for(i=0 ; i<s.size() && IsWhite(s[i]) ; ++i);
|
||||
|
||||
// deleting white characters at the beginning
|
||||
if( i != 0 )
|
||||
s.erase(0, i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
std::string ConfParser::Text(const char * name)
|
||||
{
|
||||
return Text(std::string(name), default_str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string ConfParser::Text(const char * name, const char * def)
|
||||
{
|
||||
return Text(std::string(name), std::string(def));
|
||||
}
|
||||
|
||||
|
||||
std::string ConfParser::Text(const std::string & name, const std::string & def)
|
||||
{
|
||||
TableSingle::iterator i = table_single.find(name);
|
||||
|
||||
if( i == table_single.end() )
|
||||
{
|
||||
Table::iterator t = table.find(name);
|
||||
|
||||
if( t == table.end() || t->second.empty() )
|
||||
return def;
|
||||
|
||||
return t->second[0];
|
||||
}
|
||||
|
||||
return i->second;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int ConfParser::Int(const char * name)
|
||||
{
|
||||
return Int(std::string(name), default_int);
|
||||
}
|
||||
|
||||
|
||||
int ConfParser::Int(const char * name, int def)
|
||||
{
|
||||
return Int(std::string(name), def);
|
||||
}
|
||||
|
||||
|
||||
int ConfParser::ToInt(const std::string & value)
|
||||
{
|
||||
long res = (value[0] == '0')? strtol(value.c_str() + 1, 0, 8) : strtol(value.c_str(), 0, 10);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
int ConfParser::Int(const std::string & name, int def)
|
||||
{
|
||||
TableSingle::iterator i = table_single.find(name);
|
||||
|
||||
if( i == table_single.end() )
|
||||
{
|
||||
Table::iterator t = table.find(name);
|
||||
|
||||
if( t == table.end() || t->second.empty() )
|
||||
return def;
|
||||
|
||||
return ToInt(t->second[0]);
|
||||
}
|
||||
|
||||
return ToInt(i->second);
|
||||
}
|
||||
|
||||
|
||||
bool ConfParser::Bool(const char * name)
|
||||
{
|
||||
return Bool(std::string(name), default_bool);
|
||||
}
|
||||
|
||||
|
||||
bool ConfParser::Bool(const char * name, bool def)
|
||||
{
|
||||
return Bool(std::string(name), def);
|
||||
}
|
||||
|
||||
|
||||
bool ConfParser::ToBool(const std::string & value)
|
||||
{
|
||||
return ( EqualNoCase(value.c_str(), "true") ||
|
||||
EqualNoCase(value.c_str(), "yes") ||
|
||||
EqualNoCase(value.c_str(), "1")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
bool ConfParser::Bool(const std::string & name, bool def)
|
||||
{
|
||||
TableSingle::iterator i = table_single.find(name);
|
||||
|
||||
if( i == table_single.end() )
|
||||
{
|
||||
Table::iterator t = table.find(name);
|
||||
|
||||
if( t == table.end() || t->second.empty() )
|
||||
return def;
|
||||
|
||||
return ToBool(t->second[0]);
|
||||
}
|
||||
|
||||
return ToBool(i->second);
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::SetDefaultText(const std::string & def)
|
||||
{
|
||||
default_str = def;
|
||||
}
|
||||
|
||||
void ConfParser::SetDefaultInt(int def)
|
||||
{
|
||||
default_int = def;
|
||||
}
|
||||
|
||||
void ConfParser::SetDefaultBool(bool def)
|
||||
{
|
||||
default_bool = def;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// in lists we don't use default values
|
||||
void ConfParser::ListText(const char * name, std::vector<std::string> & list)
|
||||
{
|
||||
ListText(std::string(name), list);
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::ListText(const std::string & name, std::vector<std::string> & list)
|
||||
{
|
||||
list.clear();
|
||||
|
||||
ConfParser::TableSingle::iterator i = table_single.find(name);
|
||||
|
||||
if( i != table_single.end() )
|
||||
{
|
||||
list.push_back(i->second);
|
||||
return;
|
||||
}
|
||||
|
||||
ConfParser::Table::iterator z = table.find(name);
|
||||
|
||||
if( z != table.end() )
|
||||
{
|
||||
list = z->second;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
356
core/confparser.h
Executable file
356
core/confparser.h
Executable file
@@ -0,0 +1,356 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfileconfparser
|
||||
#define headerfileconfparser
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
A parser for parsing config files.
|
||||
|
||||
A config file can look like this:
|
||||
variable1 = value 1
|
||||
variable2 = " value 2 "
|
||||
variable3 = (value 1, value 2)
|
||||
variable4 = (" value 1 " , "value2", value 3)
|
||||
|
||||
sample of use:
|
||||
ConfParser parser;
|
||||
parser.Parse("/path/to/config");
|
||||
|
||||
if( parser.status == ConfParser::ok )
|
||||
{
|
||||
// the whole config we have in parser.table (parser.table_single)
|
||||
}
|
||||
|
||||
config syntax:
|
||||
option = list
|
||||
|
||||
list can consists of any number of items, if you're using more than one item you should
|
||||
use brackets ()
|
||||
|
||||
for one item the brackets can be ommited:
|
||||
option = value
|
||||
white characters at the beginning of the value (and at the end) will be trimmed,
|
||||
or you can use quotes:
|
||||
option = "value"
|
||||
option2 = "value with spaces at the end "
|
||||
|
||||
the form without quotes:
|
||||
option = value
|
||||
should be written in one line, so this is not allowed:
|
||||
option =
|
||||
value
|
||||
you can use a new line characters only between brackets and quotes:
|
||||
option = "this is
|
||||
a multiline string"
|
||||
option = ( value1,
|
||||
value2 )
|
||||
|
||||
but there is one requirement: the first character " or ( should be in the same line,
|
||||
so this is not allowed
|
||||
option =
|
||||
"this is wrong"
|
||||
but this is ok:
|
||||
option = "
|
||||
that is ok"
|
||||
|
||||
empty lists:
|
||||
option = ()
|
||||
this creates an empty list: parser.table['option'].empty() == true
|
||||
|
||||
option =
|
||||
this creates an empty list too (the same as previously)
|
||||
|
||||
option = ""
|
||||
but this doesn't create an empty list, it creates a list with one (empty) item
|
||||
|
||||
commentaries:
|
||||
# this is a commentary (until the end of the line)
|
||||
option = value # this is a commentary too
|
||||
|
||||
commentaries are treated as white characters, other example:
|
||||
option = ( # this is my list
|
||||
"value 1" # this is a value one
|
||||
value 2 # and this is a value two
|
||||
) # end of my list
|
||||
|
||||
overwriting:
|
||||
option1 = some value
|
||||
option1 = other value
|
||||
# always the last option is used so option1 is "other value"
|
||||
|
||||
list delimiter:
|
||||
option1 = (value1, value2, value3)
|
||||
option2 = ("value1", "value2", "value3")
|
||||
above we're using a comma ',' as a list delimiter but when using quotes (second line)
|
||||
the commas can be omitted:
|
||||
option2 = ("value1" "value2" "value3")
|
||||
|
||||
white characters:
|
||||
the name of an option cannot consist of white characters
|
||||
some option = value # this is wrong
|
||||
some_option = value # this is ok
|
||||
|
||||
which characters are allowed in an option name is defined by IsVariableChar() method
|
||||
|
||||
you can use white characters in values
|
||||
option = value with spaces or tabs
|
||||
white characters at the beginning and at the end will be trimmed,
|
||||
so if you want them use quotes:
|
||||
option = " other value with spaces "
|
||||
|
||||
special characters in quoted strings:
|
||||
option = "this is a string with \" a quote inside"
|
||||
the option will be: this is a string with " a quote inside
|
||||
\\ - means one \
|
||||
basically: \char produces char
|
||||
so:
|
||||
"\a" gives "a"
|
||||
"\\" gives "\"
|
||||
"\Z" gives "Z" and so on
|
||||
|
||||
|
||||
*/
|
||||
class ConfParser
|
||||
{
|
||||
public:
|
||||
|
||||
ConfParser();
|
||||
|
||||
|
||||
/*
|
||||
status of parsing
|
||||
*/
|
||||
enum Status { ok, cant_open_file, syntax_error };
|
||||
|
||||
|
||||
/*
|
||||
the last status of parsing, set by Parse() methods
|
||||
*/
|
||||
Status status;
|
||||
|
||||
|
||||
/*
|
||||
the main methods used to parse
|
||||
file_name is the path to a file
|
||||
*/
|
||||
Status Parse(const char * file_name);
|
||||
Status Parse(const std::string & file_name);
|
||||
|
||||
|
||||
/*
|
||||
a number of a line in which there is a syntax_error
|
||||
*/
|
||||
int line;
|
||||
|
||||
|
||||
/*
|
||||
this is the table which represents your config file
|
||||
in the Table map: the first (key) is your 'option' and the second is 'list'
|
||||
*/
|
||||
typedef std::vector<std::string> Value;
|
||||
typedef std::map<std::string, Value> Table;
|
||||
Table table;
|
||||
|
||||
|
||||
/*
|
||||
if your config file consists mainly of single forms such as:
|
||||
option = value
|
||||
option2 = value2
|
||||
then you can call SplitSingle(true) for not inserting single values to
|
||||
previous 'table' but instead to 'table_single'
|
||||
table_single as the second parameter takes only std::string (instead of the whole std::vector)
|
||||
so you can save a little memory from not using std::vector
|
||||
*/
|
||||
typedef std::map<std::string, std::string> TableSingle;
|
||||
TableSingle table_single;
|
||||
|
||||
|
||||
/*
|
||||
if your list consists of only one item, e.g:
|
||||
option1 = value 1
|
||||
option2 = "value 2"
|
||||
option3 = ( "value 3" )
|
||||
then if you call SplitSingle(true) then such values will be stored in
|
||||
'table_single' instead of 'table' map
|
||||
default: false
|
||||
*/
|
||||
void SplitSingle(bool split);
|
||||
|
||||
|
||||
/*
|
||||
if true then empty lists, e.g:
|
||||
option =
|
||||
option2 = ()
|
||||
will be omitted (not inserted to 'table' or 'table_single')
|
||||
default: false
|
||||
*/
|
||||
void SkipEmpty(bool skip);
|
||||
|
||||
|
||||
/*
|
||||
those methods are used to extract information from table or table_single
|
||||
as a parameter they take the name of an option
|
||||
and a default value (if there is no such a parameter),
|
||||
they return appropriate value (either text, int or boolean)
|
||||
(in lists they return the first item if exists)
|
||||
*/
|
||||
std::string Text(const char * name);
|
||||
std::string Text(const char * name, const char * def);
|
||||
std::string Text(const std::string & name, const std::string & def);
|
||||
int Int(const char *);
|
||||
int Int(const char * name, int def);
|
||||
int Int(const std::string & name, int def);
|
||||
bool Bool(const char *);
|
||||
bool Bool(const char * name, bool def);
|
||||
bool Bool(const std::string & name, bool def);
|
||||
|
||||
|
||||
/*
|
||||
some default values
|
||||
used in Text() Int() or Bool() when you don't explicitly set the default value
|
||||
|
||||
if you don't set it directly then:
|
||||
default text is: "" (empty)
|
||||
default int is: 0
|
||||
default bool is: false
|
||||
*/
|
||||
void SetDefaultText(const std::string & def);
|
||||
void SetDefaultInt(int def);
|
||||
void SetDefaultBool(bool def);
|
||||
|
||||
|
||||
/*
|
||||
those methods are used to extract lists
|
||||
note: if there is one option in table_single they will return it
|
||||
*/
|
||||
void ListText(const char * name, std::vector<std::string> & list);
|
||||
void ListText(const std::string & name, std::vector<std::string> & list);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/*
|
||||
last read variable (option)
|
||||
*/
|
||||
std::string variable;
|
||||
|
||||
|
||||
/*
|
||||
last read list item
|
||||
*/
|
||||
std::string value_item;
|
||||
|
||||
|
||||
/*
|
||||
last read list
|
||||
*/
|
||||
Value value;
|
||||
|
||||
|
||||
/*
|
||||
separator between a variable and a value, default: '='
|
||||
*/
|
||||
int separator;
|
||||
|
||||
|
||||
/*
|
||||
commentary char, default: '#'
|
||||
*/
|
||||
int commentary;
|
||||
|
||||
|
||||
/*
|
||||
list starting character, default: '('
|
||||
*/
|
||||
int list_start;
|
||||
|
||||
|
||||
/*
|
||||
list ending character, default: ')'
|
||||
*/
|
||||
int list_end;
|
||||
|
||||
|
||||
/*
|
||||
list delimiter, default: ','
|
||||
*/
|
||||
int list_delimiter;
|
||||
|
||||
|
||||
/*
|
||||
last read char
|
||||
*/
|
||||
int lastc;
|
||||
|
||||
|
||||
/*
|
||||
current file
|
||||
*/
|
||||
std::ifstream file;
|
||||
|
||||
|
||||
/*
|
||||
if true then lists with one item will be put into 'table_single' table
|
||||
default: false
|
||||
*/
|
||||
bool split_single;
|
||||
|
||||
|
||||
/*
|
||||
if true then empty lists, e.g:
|
||||
option =
|
||||
option2 = ()
|
||||
will be omitted (not inserted to 'table' or 'table_single')
|
||||
default: false
|
||||
*/
|
||||
bool skip_empty;
|
||||
|
||||
|
||||
|
||||
std::string default_str;
|
||||
int default_int;
|
||||
bool default_bool;
|
||||
|
||||
int ToInt(const std::string & value);
|
||||
bool ToBool(const std::string & value);
|
||||
|
||||
Status ParseFile();
|
||||
void AddOption();
|
||||
|
||||
void DeleteFromTable(const std::string & var);
|
||||
void DeleteFromTableSingle(const std::string & var);
|
||||
|
||||
bool ReadVariable();
|
||||
bool ReadValue();
|
||||
bool ReadValueList();
|
||||
bool ReadValueNoList(bool use_list_delimiter = false);
|
||||
bool ReadValueQuoted();
|
||||
bool ReadValueSimple(bool use_list_delimiter = false);
|
||||
|
||||
int ReadChar();
|
||||
bool IsWhite(int c);
|
||||
bool IsVariableChar(int c);
|
||||
void SkipWhite();
|
||||
void SkipWhiteLines();
|
||||
void SkipLine();
|
||||
void Trim(std::string & s);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "data.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Data::Data()
|
||||
{
|
||||
signal_hup = false;
|
||||
stdout_is_closed = false;
|
||||
how_many_logged = 0;
|
||||
|
||||
// the rest will be read from a config file
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Data::SetAdditionalVariables()
|
||||
{
|
||||
SetHttpHost(base_url, base_url_http_host);
|
||||
SetHttpHost(base_url_auth, base_url_auth_http_host);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Data::SetHttpHost(const std::string & in, std::string & out)
|
||||
{
|
||||
if( strncmp(in.c_str(), "http://", 7) == 0 )
|
||||
out = in.substr(7);
|
||||
else
|
||||
if( strncmp(in.c_str(), "https://", 8) == 0 )
|
||||
out = in.substr(8);
|
||||
else
|
||||
out.clear(); // if empty the RequestController::BaseUrlRedirect() returns false and no redirecting will be done
|
||||
}
|
||||
213
core/data.h
213
core/data.h
@@ -1,213 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilecmslucoredata
|
||||
#define headerfilecmslucoredata
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <string.h>
|
||||
|
||||
#include "dirs.h"
|
||||
#include "users.h"
|
||||
#include "groups.h"
|
||||
#include "functions.h"
|
||||
#include "lastcontainer.h"
|
||||
#include "mounts.h"
|
||||
#include "rebus.h"
|
||||
#include "loadavg.h"
|
||||
|
||||
|
||||
class Data
|
||||
{
|
||||
public:
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// members read from a config file
|
||||
|
||||
// name of the config file (full path can be)
|
||||
std::string config_file;
|
||||
|
||||
// log file name, log file name for notifications (sending emails, etc)
|
||||
std::string log_file, log_notify_file;
|
||||
|
||||
// 1 - minimum
|
||||
// 2 - (default)
|
||||
// 3 - maximum - all logs
|
||||
int log_level;
|
||||
|
||||
// logging to stdout too
|
||||
bool log_stdout;
|
||||
|
||||
// how many requests should be logged in the same time
|
||||
// default: 1
|
||||
int log_request;
|
||||
|
||||
// fast cgi: socket (unix domain)
|
||||
std::string fcgi_socket;
|
||||
|
||||
// fast cgi: socket permissions
|
||||
int fcgi_socket_chmod;
|
||||
|
||||
// fast cgi: owner of the socket
|
||||
std::string fcgi_socket_user;
|
||||
|
||||
// fast cgi: group of the socket
|
||||
std::string fcgi_socket_group;
|
||||
|
||||
std::string templates_dir;
|
||||
std::string templates_dir_default; // templates from winix
|
||||
|
||||
std::string db_database;
|
||||
std::string db_user;
|
||||
std::string db_pass;
|
||||
|
||||
std::string http_session_id_name;
|
||||
|
||||
// when the HOST_HTTP environment variable doesn't point into 'base_url' (the part 'http://' and the last slash is removed)
|
||||
// the server will redirect into 'base_url' + 'REQUEST_URI'
|
||||
// it's useful when you want to redirect from 'mydomain.tld' into 'www.mydomain.tld' etc.
|
||||
bool base_url_redirect;
|
||||
|
||||
// string used in a place where is a user (or group) selected
|
||||
std::string priv_no_user;
|
||||
std::string priv_no_group;
|
||||
|
||||
// time in seconds when the user will be automatically logged out (iddle time)
|
||||
int session_max_idle;
|
||||
|
||||
// time in seconds when the user will be automatically logged out (when he selected 'remember me' option)
|
||||
// this time is usually greater than session_max_idle
|
||||
int session_remember_max_idle;
|
||||
|
||||
// this file is used when the program is starting and ending
|
||||
std::string session_file;
|
||||
|
||||
// allow the html ouput to be compressed
|
||||
bool compression;
|
||||
|
||||
// plugins
|
||||
std::vector<std::string> plugin_file;
|
||||
|
||||
// the html code is cleaned by our filter
|
||||
bool html_filter;
|
||||
|
||||
// the url of a new empty item (if there is not the subject too)
|
||||
std::string item_url_empty;
|
||||
|
||||
// maximum length of a file send by post multipart form
|
||||
// 0 - not used
|
||||
int post_file_max;
|
||||
|
||||
// directories for static files
|
||||
std::string auth_simplefs_dir;
|
||||
std::string auth_hashfs_dir;
|
||||
|
||||
// temporary directory for static content used by the upload function
|
||||
// should be on the same partition as auth_simplefs_dir and auth_hashfs_dir
|
||||
std::string auth_tmp_dir;
|
||||
|
||||
// default locale: en pl
|
||||
std::string locale_str;
|
||||
|
||||
// directory with locale files
|
||||
std::string locale_dir;
|
||||
|
||||
// directory with default locale files (those from winix)
|
||||
std::string locale_dir_default;
|
||||
|
||||
// the main address of the server (e.g. someserver.com) (without the 'www' part etc)
|
||||
std::string base_server;
|
||||
|
||||
// the main address of the site (e.g. http://www.someserver.com)
|
||||
std::string base_url;
|
||||
|
||||
// static content authorized by winix
|
||||
std::string base_url_auth;
|
||||
|
||||
// static content not authorized by winix
|
||||
std::string base_url_static;
|
||||
|
||||
// additional static server for common content (not authorized)
|
||||
std::string base_url_common;
|
||||
|
||||
// separator used in <title> html tag
|
||||
std::string title_separator;
|
||||
|
||||
|
||||
|
||||
// end config members
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// false at the beginning
|
||||
bool stdout_is_closed;
|
||||
|
||||
// true if there was SIGHUP signal
|
||||
volatile bool signal_hup;
|
||||
|
||||
// contains current directories tree
|
||||
Dirs dirs;
|
||||
|
||||
// based on base_url
|
||||
// set by SetAdditionalVariables()
|
||||
// without the first part http:// (or https://) or the whole string is empty
|
||||
std::string base_url_http_host;
|
||||
std::string base_url_auth_http_host;
|
||||
|
||||
|
||||
|
||||
// call this method after the config file is read
|
||||
void SetAdditionalVariables();
|
||||
|
||||
|
||||
|
||||
// users
|
||||
Users users;
|
||||
|
||||
// groups
|
||||
Groups groups;
|
||||
|
||||
// functions (ls, cat, etc)
|
||||
Functions functions;
|
||||
|
||||
// for 'last' function
|
||||
LastContainer last;
|
||||
|
||||
// mount points
|
||||
Mounts mounts;
|
||||
|
||||
// rebus (captcha)
|
||||
Rebus rebus;
|
||||
|
||||
// the time when the winix starts
|
||||
time_t system_start;
|
||||
|
||||
// how many logged users
|
||||
long how_many_logged;
|
||||
|
||||
// load averages
|
||||
LoadAvg load_avg;
|
||||
|
||||
Data();
|
||||
|
||||
|
||||
private:
|
||||
void SetHttpHost(const std::string & in, std::string & out);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
extern Data data;
|
||||
|
||||
|
||||
#endif
|
||||
@@ -10,9 +10,19 @@
|
||||
#include "dirs.h"
|
||||
#include "error.h"
|
||||
#include "log.h"
|
||||
#include "db.h"
|
||||
#include "data.h"
|
||||
#include "request.h"
|
||||
|
||||
|
||||
|
||||
void Dirs::SetDb(Db * pdb)
|
||||
{
|
||||
db = pdb;
|
||||
}
|
||||
|
||||
|
||||
void Dirs::SetRequest(Request * prequest)
|
||||
{
|
||||
request = prequest;
|
||||
}
|
||||
|
||||
|
||||
void Dirs::Clear()
|
||||
@@ -21,6 +31,12 @@ void Dirs::Clear()
|
||||
}
|
||||
|
||||
|
||||
bool Dirs::HasReadExecAccessForRoot(const Item & item)
|
||||
{
|
||||
// there must be at least one 'x' (for the root)
|
||||
return (item.privileges & 01111) != 0; // !! in the future there'll be another 'x'
|
||||
}
|
||||
|
||||
|
||||
void Dirs::CheckRootDir()
|
||||
{
|
||||
@@ -28,11 +44,11 @@ void Dirs::CheckRootDir()
|
||||
|
||||
if( i != dir_table.End() )
|
||||
{
|
||||
if( !request.HasReadExecAccessForRoot(*i) )
|
||||
if( !HasReadExecAccessForRoot(*i) )
|
||||
{
|
||||
i->privileges = 0755;
|
||||
log << log1 << "Dirs: there is no access for root (admin) to the root dir, setting 0755 for root dir" << logend;
|
||||
db.EditPrivById(*i, i->id);
|
||||
db->EditPrivById(*i, i->id);
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -52,7 +68,7 @@ void Dirs::CheckRootDir()
|
||||
|
||||
// !! upewnic sie ze baza nie zmieni url (gdyby wczesniej juz byl w bazie pusty url)
|
||||
// !! zrobic jakis wyjatek do wprowadzania roota?
|
||||
if( db.AddItem(root) == WINIX_ERR_OK )
|
||||
if( db->AddItem(root) == WINIX_ERR_OK )
|
||||
{
|
||||
dir_table.PushBack(root);
|
||||
}
|
||||
@@ -65,7 +81,7 @@ void Dirs::ReadDirs()
|
||||
{
|
||||
Clear();
|
||||
|
||||
db.GetDirs(dir_table);
|
||||
db->GetDirs(dir_table);
|
||||
CheckRootDir();
|
||||
dir_table.FindSpecialFolders();
|
||||
}
|
||||
@@ -301,7 +317,7 @@ size_t Dirs::AnalyzeDir(Item * pdir, const std::string & path, long & dir_id, st
|
||||
for( ; i<path.size() && path[i] != '/' ; ++i)
|
||||
analyze_temp += path[i];
|
||||
|
||||
pdir = data.dirs.GetDir(analyze_temp, pdir->id);
|
||||
pdir = GetDir(analyze_temp, pdir->id);
|
||||
|
||||
if( !pdir )
|
||||
return old_i; // analyze_temp is not a directory
|
||||
@@ -327,7 +343,7 @@ size_t Dirs::AnalyzeDir(Item * pdir, const std::string & path, long & dir_id, st
|
||||
*/
|
||||
int Dirs::AnalyzePath(const std::string & path, long & dir_id, std::string & dir, std::string & file)
|
||||
{
|
||||
Item * pdir = data.dirs.GetRootDir();
|
||||
Item * pdir = GetRootDir();
|
||||
dir = '/';
|
||||
file.clear();
|
||||
|
||||
@@ -386,13 +402,30 @@ void Dirs::SplitPath(const std::string & path, std::string & dir, std::string &
|
||||
}
|
||||
|
||||
|
||||
|
||||
// !! dodac kasowanie z bazy
|
||||
bool Dirs::DelDir(long dir_id)
|
||||
{
|
||||
return dir_table.DelById(dir_id);
|
||||
}
|
||||
|
||||
|
||||
Error Dirs::AddDirectory(Item & item, bool add_to_dir_table)
|
||||
{
|
||||
if( item.type != Item::dir )
|
||||
return WINIX_ERR_DIR_EXPECTED;
|
||||
|
||||
Error status = db->AddItem(item);
|
||||
|
||||
if( status == WINIX_ERR_OK )
|
||||
{
|
||||
Item * pdir = AddDir(item);
|
||||
|
||||
if( add_to_dir_table && request->dir_table.back()->id == item.parent_id )
|
||||
request->dir_table.push_back(pdir);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
15
core/dirs.h
15
core/dirs.h
@@ -17,6 +17,8 @@
|
||||
|
||||
#include "item.h"
|
||||
#include "dircontainer.h"
|
||||
#include "db.h"
|
||||
#include "request.h"
|
||||
|
||||
|
||||
// we do not support '..' in a path (for simplicity and security reasons)
|
||||
@@ -28,7 +30,9 @@ public:
|
||||
|
||||
void Clear();
|
||||
void ReadDirs();
|
||||
|
||||
|
||||
void SetRequest(Request * prequest);
|
||||
void SetDb(Db * pdb);
|
||||
|
||||
// these methods return false if there is no such a dir
|
||||
bool IsDir(long dir_id);
|
||||
@@ -47,6 +51,7 @@ public:
|
||||
|
||||
|
||||
// these methods return null if there is no such a dir
|
||||
// !! zmienic nazwy wskazujace ze operujemy tylko na lokalnej tablicy
|
||||
Item * GetRootDir();
|
||||
Item * GetEtcDir();
|
||||
Item * GetDir(const std::string & name, long parent);
|
||||
@@ -56,16 +61,22 @@ public:
|
||||
|
||||
void CheckRootDir();
|
||||
|
||||
|
||||
// !! jak juz wczesniejsze nazwy beda zmienione to tutaj damy AddDir()
|
||||
Error AddDirectory(Item & item, bool add_to_dir_table = false);
|
||||
|
||||
private:
|
||||
|
||||
Request * request;
|
||||
Db * db;
|
||||
|
||||
DirContainer dir_table;
|
||||
|
||||
size_t AnalyzeDir(Item * pdir, const std::string & path, long & dir_id, std::string & dir);
|
||||
std::string analyze_temp;
|
||||
|
||||
bool ExtractName(const char * & s, std::string & name);
|
||||
|
||||
bool HasReadExecAccessForRoot(const Item & item);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -64,9 +64,11 @@
|
||||
#define WINIX_ERR_DB_MORE_THAN_ONE_LOGIN 105
|
||||
#define WINIX_ERR_DB_ERR_CURRVAL 106
|
||||
|
||||
#define WINIX_ERR_FILE_EXPECTED 107
|
||||
#define WINIX_ERR_DIR_EXPECTED 108
|
||||
|
||||
//#define WINIX_ERR_UNKNOWN 1000
|
||||
|
||||
#define WINIX_NOTHING_TO_DO 109
|
||||
|
||||
typedef int Error;
|
||||
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "function.h"
|
||||
|
||||
|
||||
|
||||
Function::Function()
|
||||
{
|
||||
code = FUN_NONE;
|
||||
}
|
||||
|
||||
void Function::Clear()
|
||||
{
|
||||
code = FUN_NONE;
|
||||
item.Clear();
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilecmslucorefunction
|
||||
#define headerfilecmslucorefunction
|
||||
|
||||
#include <iostream>
|
||||
#include "item.h"
|
||||
|
||||
|
||||
#define FUN_NONE 0
|
||||
#define FUN_LS 1
|
||||
#define FUN_CAT 2
|
||||
#define FUN_NODE 3
|
||||
#define FUN_EMACS 4
|
||||
#define FUN_MKDIR 5
|
||||
#define FUN_DEFAULT 6
|
||||
#define FUN_PRIV 7
|
||||
#define FUN_RM 8
|
||||
#define FUN_LOGIN 9
|
||||
#define FUN_LOGOUT 10
|
||||
#define FUN_RUN 11
|
||||
#define FUN_WHO 12
|
||||
#define FUN_LAST 13
|
||||
#define FUN_CREATETHREAD 14
|
||||
#define FUN_THREAD 15
|
||||
#define FUN_RELOAD 16
|
||||
#define FUN_UPLOAD 17
|
||||
#define FUN_CREATETICKET 18
|
||||
#define FUN_EDITTICKET 19
|
||||
#define FUN_TICKET 20
|
||||
#define FUN_UPTIME 21
|
||||
#define FUN_MV 23
|
||||
#define FUN_UNAME 24
|
||||
#define FUN_CHMOD 25
|
||||
#define FUN_CHOWN 26
|
||||
#define FUN_CKEDITOR 27
|
||||
#define FUN_DOWNLOAD 28
|
||||
#define FUN_ADDUSER 29
|
||||
#define FUN_SUBJECT 30
|
||||
#define FUN_CP 31
|
||||
#define FUN_TINYMCE 32
|
||||
|
||||
|
||||
|
||||
class Function
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
int code;
|
||||
Item item;
|
||||
|
||||
void Clear();
|
||||
|
||||
Function();
|
||||
Function(const Function & f);
|
||||
Function & operator=(const Function & f);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "functioncodeparser.h"
|
||||
#include "function.h"
|
||||
#include "log.h"
|
||||
|
||||
|
||||
|
||||
bool FunctionCodeParser::ContentHasOneRow(const Item & item)
|
||||
{
|
||||
for(size_t i=0 ; i<item.content.size() ; ++i)
|
||||
if( item.content[i] == '\n' )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int FunctionCodeParser::ParseValue(const char * s)
|
||||
{
|
||||
if( strncmp(s, "[fun:", 5) != 0 )
|
||||
return FUN_NONE;
|
||||
|
||||
const char * send;
|
||||
int result = strtol(s+5, (char**)&send, 10);
|
||||
|
||||
if( send==s+5 || strcmp(send, "]") != 0 )
|
||||
return FUN_NONE;
|
||||
|
||||
log << log2 << "FCP: function code: " << result << logend;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int FunctionCodeParser::Parse(const Item & item)
|
||||
{
|
||||
// format: [fun:1]
|
||||
// minimum size: 7 characters
|
||||
if( item.content.size() < 7 )
|
||||
return FUN_NONE;
|
||||
|
||||
if( !ContentHasOneRow(item) )
|
||||
return FUN_NONE;
|
||||
|
||||
return ParseValue(item.content.c_str());
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilecmslucorefunctioncodeparser
|
||||
#define headerfilecmslucorefunctioncodeparser
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "item.h"
|
||||
|
||||
|
||||
class FunctionCodeParser
|
||||
{
|
||||
bool ContentHasOneRow(const Item & item);
|
||||
int ParseValue(const char * s);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
int Parse(const Item & item);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,230 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "functionparser.h"
|
||||
#include "log.h"
|
||||
#include "item.h"
|
||||
#include "error.h"
|
||||
#include "data.h"
|
||||
#include "db.h"
|
||||
#include "request.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 = WINIX_ERR_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 == WINIX_ERR_OK )
|
||||
{
|
||||
if( request.role == Request::authorizer && request.item.auth == Item::auth_none )
|
||||
{
|
||||
log << log1 << "FP: item.url: " << url << " exists but has not a static content (authorizer role)" << logend;
|
||||
request.status = WINIX_ERR_NO_ITEM;
|
||||
return;
|
||||
}
|
||||
|
||||
++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(const std::string & par)
|
||||
{
|
||||
Param param;
|
||||
size_t i;
|
||||
|
||||
if( par.empty() )
|
||||
return;
|
||||
|
||||
// looking for the first colon ':'
|
||||
for(i=0 ; i<par.size() && par[i] != ':' ; ++i);
|
||||
|
||||
if( i == par.size() )
|
||||
{
|
||||
// there is no a colon
|
||||
param.name = par;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( i > 0 )
|
||||
param.name = par.substr(0, i);
|
||||
|
||||
if( i < par.size() - 1 )
|
||||
param.value = par.substr(i+1);
|
||||
}
|
||||
|
||||
request.param_table.push_back(param);
|
||||
|
||||
log << log3 << "FP: Param: name=" << param.name;
|
||||
|
||||
if( !param.value.empty() )
|
||||
log << ", value=" << param.value;
|
||||
|
||||
log << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FunctionParser::ParseParams()
|
||||
{
|
||||
for( ; true ; ++get_index )
|
||||
{
|
||||
SkipEmptyString("FP: Params: skipped empty string");
|
||||
|
||||
if( get_index == get_table_len )
|
||||
break;
|
||||
|
||||
ParseParams(request.get_table[get_index]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FunctionParser::Parse()
|
||||
{
|
||||
request.status = WINIX_ERR_OK;
|
||||
get_index = 0;
|
||||
get_table_len = request.get_table.size();
|
||||
request.pfunction = 0;
|
||||
request.is_item = false;
|
||||
|
||||
ParseDirectories();
|
||||
|
||||
if( request.status != WINIX_ERR_OK )
|
||||
return;
|
||||
|
||||
ParseFunction();
|
||||
|
||||
if( !request.pfunction )
|
||||
{
|
||||
ParseItem();
|
||||
|
||||
if( request.status != WINIX_ERR_OK )
|
||||
return;
|
||||
|
||||
ParseFunction();
|
||||
|
||||
if( !request.pfunction && get_index != get_table_len )
|
||||
{
|
||||
request.status = WINIX_ERR_NO_FUNCTION;
|
||||
log << log3 << "FP: Parse: unknown function: \"" << request.get_table[get_index] << "\"" << logend;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ParseParams();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilecmslucorefunctionparser
|
||||
#define headerfilecmslucorefunctionparser
|
||||
|
||||
#include "requesttypes.h"
|
||||
|
||||
|
||||
class FunctionParser
|
||||
{
|
||||
GetTable::size_type get_index;
|
||||
GetTable::size_type get_table_len;
|
||||
|
||||
void SkipEmptyString(const char * msg);
|
||||
|
||||
void ParseDirectories();
|
||||
void ParseItem();
|
||||
bool IsAppFunction();
|
||||
void ParseFunction();
|
||||
void ParseParams(const std::string & par);
|
||||
void ParseParams();
|
||||
|
||||
public:
|
||||
|
||||
|
||||
void Parse();
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "functions.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Functions::Clear()
|
||||
{
|
||||
table.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Functions::AddFun(int code, const char * url)
|
||||
{
|
||||
fun.code = code;
|
||||
fun.item.url = url;
|
||||
table.insert( std::make_pair(fun.item.url, fun) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
// in the future we will read these functions from the database
|
||||
void Functions::ReadFunctions()
|
||||
{
|
||||
Clear();
|
||||
|
||||
fun.item.user_id = -1;
|
||||
fun.item.group_id = -1;
|
||||
fun.item.privileges = 0755;
|
||||
fun.item.parent_id = -1; // !! temporarily doesn't matter
|
||||
fun.item.id = -1;
|
||||
fun.item.type = Item::file;
|
||||
|
||||
|
||||
AddFun(FUN_LS, "ls");
|
||||
AddFun(FUN_CAT, "cat");
|
||||
AddFun(FUN_NODE, "node");
|
||||
AddFun(FUN_EMACS, "emacs");
|
||||
AddFun(FUN_MKDIR, "mkdir");
|
||||
AddFun(FUN_DEFAULT, "default");
|
||||
AddFun(FUN_PRIV, "priv");
|
||||
AddFun(FUN_RM, "rm");
|
||||
AddFun(FUN_LOGOUT, "logout");
|
||||
AddFun(FUN_LOGIN, "login");
|
||||
AddFun(FUN_RUN, "run");
|
||||
AddFun(FUN_WHO, "who");
|
||||
AddFun(FUN_LAST, "last");
|
||||
AddFun(FUN_CREATETHREAD, "createthread");
|
||||
AddFun(FUN_THREAD, "thread");
|
||||
AddFun(FUN_UPLOAD, "upload");
|
||||
AddFun(FUN_CREATETICKET, "createticket");
|
||||
AddFun(FUN_EDITTICKET, "editticket");
|
||||
AddFun(FUN_TICKET, "ticket");
|
||||
AddFun(FUN_UPTIME, "uptime");
|
||||
AddFun(FUN_MV, "mv");
|
||||
AddFun(FUN_UNAME, "uname");
|
||||
AddFun(FUN_CHMOD, "chmod");
|
||||
AddFun(FUN_CHOWN, "chown");
|
||||
AddFun(FUN_CKEDITOR, "ckeditor");
|
||||
AddFun(FUN_DOWNLOAD, "download");
|
||||
AddFun(FUN_ADDUSER, "adduser");
|
||||
AddFun(FUN_SUBJECT, "subject");
|
||||
AddFun(FUN_CP, "cp");
|
||||
AddFun(FUN_TINYMCE, "tinymce");
|
||||
|
||||
|
||||
// functions which need more privileges
|
||||
fun.item.privileges = 0700;
|
||||
|
||||
AddFun(FUN_RELOAD, "reload");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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(int code)
|
||||
{
|
||||
Table::iterator i = table.begin();
|
||||
|
||||
for( ; i != table.end() ; ++i )
|
||||
{
|
||||
if( i->second.code == code )
|
||||
return &(i->second);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilecmslucorefunctions
|
||||
#define headerfilecmslucorefunctions
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "function.h"
|
||||
|
||||
|
||||
|
||||
class Functions
|
||||
{
|
||||
|
||||
typedef std::map<std::string, Function> Table;
|
||||
Table table;
|
||||
|
||||
Function fun;
|
||||
|
||||
void AddFun(int code, const char * url);
|
||||
|
||||
public:
|
||||
|
||||
|
||||
void Clear();
|
||||
void ReadFunctions();
|
||||
|
||||
Function * GetFunction(const std::string & name);
|
||||
Function * GetFunction(int code);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
|
||||
#include "groups.h"
|
||||
#include "db.h"
|
||||
|
||||
|
||||
|
||||
@@ -25,11 +24,11 @@ void Groups::Clear()
|
||||
}
|
||||
|
||||
|
||||
void Groups::ReadGroups()
|
||||
void Groups::ReadGroups(Db * db)
|
||||
{
|
||||
Clear();
|
||||
|
||||
db.GetGroups(table);
|
||||
db->GetGroups(table);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
#include "group.h"
|
||||
#include "ugcontainer.h"
|
||||
#include "db.h"
|
||||
|
||||
|
||||
|
||||
class Groups
|
||||
@@ -29,7 +31,7 @@ public:
|
||||
|
||||
Groups();
|
||||
void Clear();
|
||||
void ReadGroups();
|
||||
void ReadGroups(Db * db);
|
||||
Group * GetGroup(long group_id);
|
||||
Group * GetGroup(const std::string & name);
|
||||
long GetGroupId(const std::string & name);
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
#ifndef headerfilecmslucorelocale
|
||||
#define headerfilecmslucorelocale
|
||||
|
||||
#include "../confparser/confparser.h"
|
||||
#include "confparser.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
// !! locale nie powinny byc w templates?
|
||||
class Locale
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include "misc.h"
|
||||
#include "log.h"
|
||||
#include "data.h"
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -100,17 +100,18 @@ void CorrectUrlOnlyAllowedChar(std::string & url)
|
||||
|
||||
if( url.empty() || url == "." )
|
||||
{
|
||||
if( data.item_url_empty.empty() )
|
||||
// !! brakuje config->
|
||||
//if( config->item_url_empty.empty() )
|
||||
url = "unnamed";
|
||||
else
|
||||
{
|
||||
url = data.item_url_empty;
|
||||
//else
|
||||
//{
|
||||
// url = config->item_url_empty;
|
||||
|
||||
CorrectUrlDots(url);
|
||||
CorrectUrlChars(url);
|
||||
ToSmall(url);
|
||||
// CorrectUrlDots(url);
|
||||
// CorrectUrlChars(url);
|
||||
// ToSmall(url);
|
||||
// we don't trim here and the string will not be empty
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
if( url[0] >= '0' && url[0] <= '9' )
|
||||
|
||||
@@ -8,11 +8,16 @@
|
||||
*/
|
||||
|
||||
#include "mountparser.h"
|
||||
#include "data.h"
|
||||
#include "log.h"
|
||||
#include "misc.h"
|
||||
|
||||
|
||||
void MountParser::SetDirs(Dirs * pdirs)
|
||||
{
|
||||
dirs = pdirs;
|
||||
}
|
||||
|
||||
|
||||
bool MountParser::IsWhite(int c)
|
||||
{
|
||||
if( c==' ' || c=='\t' || c==13 || c==160 )
|
||||
@@ -229,7 +234,7 @@ void MountParser::ReadMountPoint()
|
||||
{
|
||||
ReadWord(temp);
|
||||
|
||||
pdir = data.dirs.GetDir(temp);
|
||||
pdir = dirs->GetDir(temp);
|
||||
|
||||
if( pdir )
|
||||
{
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "mount.h"
|
||||
#include "item.h"
|
||||
#include "error.h"
|
||||
#include "dirs.h"
|
||||
|
||||
|
||||
|
||||
@@ -27,10 +28,12 @@ class MountParser
|
||||
public:
|
||||
|
||||
Error Parse(const std::string & input, std::map<long, Mount> & output);
|
||||
|
||||
void SetDirs(Dirs * pdirs);
|
||||
|
||||
private:
|
||||
|
||||
Dirs * dirs;
|
||||
|
||||
bool IsWhite(int c);
|
||||
void SkipWhite();
|
||||
void SkipLine();
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
|
||||
#include "mounts.h"
|
||||
#include "data.h"
|
||||
#include "request.h"
|
||||
#include "log.h"
|
||||
#include "mountparser.h"
|
||||
@@ -23,12 +22,29 @@ Mounts::Mounts()
|
||||
}
|
||||
|
||||
|
||||
void Mounts::SetDirs(Dirs * pdirs)
|
||||
{
|
||||
dirs = pdirs;
|
||||
}
|
||||
|
||||
|
||||
void Mounts::SetDb(Db * pdb)
|
||||
{
|
||||
db = pdb;
|
||||
}
|
||||
|
||||
void Mounts::SetRequest(Request * prequest)
|
||||
{
|
||||
request = prequest;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// reading from 'mounts'
|
||||
Error Mounts::ReadMounts(const std::string & mounts)
|
||||
{
|
||||
MountParser mp;
|
||||
mp.SetDirs(dirs);
|
||||
Error err = mp.Parse(mounts, mount_tab);
|
||||
|
||||
if( err != WINIX_ERR_OK )
|
||||
@@ -49,7 +65,7 @@ Error Mounts::ReadMounts()
|
||||
{
|
||||
static std::string file = "fstab";
|
||||
|
||||
Item * etc = data.dirs.GetEtcDir();
|
||||
Item * etc = dirs->GetEtcDir();
|
||||
|
||||
if( !etc )
|
||||
{
|
||||
@@ -58,7 +74,7 @@ Error Mounts::ReadMounts()
|
||||
}
|
||||
|
||||
Item fstab;
|
||||
Error err = db.GetItem(etc->id, file, fstab);
|
||||
Error err = db->GetItem(etc->id, file, fstab);
|
||||
|
||||
if( err == WINIX_ERR_NO_ITEM )
|
||||
{
|
||||
@@ -82,7 +98,7 @@ void Mounts::MountCmsForRoot()
|
||||
mount.type = Mount::cms;
|
||||
mount.fs = Mount::simplefs;
|
||||
|
||||
Item * proot = data.dirs.GetRootDir();
|
||||
Item * proot = dirs->GetRootDir();
|
||||
|
||||
if( proot )
|
||||
mount.dir_id = proot->id;
|
||||
@@ -105,10 +121,10 @@ std::vector<Item*>::reverse_iterator i;
|
||||
|
||||
// when the program starts (when the dir_table is empty()
|
||||
// we don't want to call MountCmsForRoot()
|
||||
if( request.dir_table.empty() )
|
||||
if( request->dir_table.empty() )
|
||||
return;
|
||||
|
||||
for(i = request.dir_table.rbegin() ; i!=request.dir_table.rend() ; ++i)
|
||||
for(i = request->dir_table.rbegin() ; i!=request->dir_table.rend() ; ++i)
|
||||
{
|
||||
std::map<long, Mount>::iterator m = mount_tab.find( (*i)->id );
|
||||
|
||||
@@ -135,7 +151,7 @@ Mount * Mounts::CalcMount(long dir_id)
|
||||
{
|
||||
while( true )
|
||||
{
|
||||
Item * pdir = data.dirs.GetDir(dir_id);
|
||||
Item * pdir = dirs->GetDir(dir_id);
|
||||
|
||||
if( !pdir )
|
||||
return 0;
|
||||
|
||||
@@ -16,12 +16,20 @@
|
||||
#include <string>
|
||||
#include "mount.h"
|
||||
#include "error.h"
|
||||
#include "dirs.h"
|
||||
#include "db.h"
|
||||
#include "request.h"
|
||||
|
||||
|
||||
|
||||
class Mounts
|
||||
{
|
||||
public:
|
||||
|
||||
void SetDirs(Dirs * pdirs);
|
||||
void SetDb(Db * pdb);
|
||||
void SetRequest(Request * prequest);
|
||||
|
||||
// dir_id, mount_point
|
||||
typedef std::map<long, Mount> MountTab;
|
||||
|
||||
@@ -41,6 +49,10 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
Dirs * dirs;
|
||||
Db * db;
|
||||
Request * request;
|
||||
|
||||
MountTab mount_tab;
|
||||
|
||||
void MountCmsForRoot();
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
#include "log.h"
|
||||
#include "notify.h"
|
||||
#include "data.h"
|
||||
#include "misc.h"
|
||||
#include "request.h"
|
||||
|
||||
@@ -26,6 +25,30 @@ Notify * Notify::obj;
|
||||
|
||||
|
||||
|
||||
void Notify::SetRequest(Request * prequest)
|
||||
{
|
||||
request = prequest;
|
||||
}
|
||||
|
||||
|
||||
void Notify::SetConfig(Config * pconfig)
|
||||
{
|
||||
config = pconfig;
|
||||
}
|
||||
|
||||
|
||||
void Notify::SetSystem(System * psystem)
|
||||
{
|
||||
system = psystem;
|
||||
}
|
||||
|
||||
void Notify::SetTemplatesNotify(TemplatesNotify * ptemplates_notify)
|
||||
{
|
||||
templates_notify = ptemplates_notify;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
methods for the second thread
|
||||
@@ -71,10 +94,10 @@ void Notify::SendEmail(NotifyMsg & n)
|
||||
TemplatesNotifyFunctions::notify_msg = &n;
|
||||
|
||||
obj->Lock(); // templates can be reloaded from the first thread
|
||||
obj->templates_notify.Generate(n.lang);
|
||||
obj->templates_notify->Generate(n.lang);
|
||||
obj->Unlock();
|
||||
|
||||
SendEmail(n.email, obj->templates_notify.notify_str.str());
|
||||
SendEmail(n.email, obj->templates_notify->notify_str.str());
|
||||
}
|
||||
|
||||
|
||||
@@ -142,7 +165,7 @@ void Notify::ReadTemplates()
|
||||
// the second thread can use our templates and we must Lock()
|
||||
// (the second thread is using Lock() too)
|
||||
Lock();
|
||||
templates_notify.Read();
|
||||
templates_notify->Read();
|
||||
Unlock();
|
||||
}
|
||||
|
||||
@@ -150,7 +173,7 @@ void Notify::ReadTemplates()
|
||||
|
||||
bool Notify::Init()
|
||||
{
|
||||
templates_notify.CreateFunctions();
|
||||
templates_notify->CreateFunctions();
|
||||
|
||||
|
||||
int t = pthread_create(&thread, 0, ThreadRoutine, (void*)this);
|
||||
@@ -188,9 +211,9 @@ void Notify::CreateItemDir(std::string & dir, bool clear)
|
||||
if( clear )
|
||||
dir.clear();
|
||||
|
||||
for(size_t a=0 ; a<request.dir_table.size() ; ++a)
|
||||
for(size_t a=0 ; a<request->dir_table.size() ; ++a)
|
||||
{
|
||||
dir += request.dir_table[a]->url;
|
||||
dir += request->dir_table[a]->url;
|
||||
dir += '/';
|
||||
}
|
||||
}
|
||||
@@ -198,9 +221,9 @@ void Notify::CreateItemDir(std::string & dir, bool clear)
|
||||
|
||||
void Notify::CreateItemLink(std::string & link)
|
||||
{
|
||||
link = data.base_url;
|
||||
link = config->base_url;
|
||||
CreateItemDir(link, false);
|
||||
link += request.item.url;
|
||||
link += request->item.url;
|
||||
}
|
||||
|
||||
|
||||
@@ -213,8 +236,8 @@ Users::Iterator i;
|
||||
return;
|
||||
|
||||
n.notify_code = notify_code;
|
||||
n.current_mount_type = data.mounts.pmount->type;
|
||||
n.doc_base_url = data.base_url;
|
||||
n.current_mount_type = system->mounts.pmount->type;
|
||||
n.doc_base_url = config->base_url;
|
||||
CreateItemDir(n.item_dir);
|
||||
CreateItemLink(n.item_link);
|
||||
|
||||
@@ -225,17 +248,17 @@ Users::Iterator i;
|
||||
{
|
||||
// don't clear notify_pool here -- it is used (and will be cleared) by the second thread
|
||||
|
||||
for(i=data.users.Begin() ; i != data.users.End() ; ++i)
|
||||
for(i=system->users.Begin() ; i != system->users.End() ; ++i)
|
||||
{
|
||||
sending = false;
|
||||
|
||||
if( data.mounts.pmount->type == Mount::thread )
|
||||
if( system->mounts.pmount->type == Mount::thread )
|
||||
{
|
||||
if( (i->thread_notify & notify_code) != 0 )
|
||||
sending = true;
|
||||
}
|
||||
else
|
||||
if( data.mounts.pmount->type == Mount::cms )
|
||||
if( system->mounts.pmount->type == Mount::cms )
|
||||
{
|
||||
if( (i->cms_notify & notify_code) != 0 )
|
||||
sending = true;
|
||||
@@ -244,7 +267,7 @@ Users::Iterator i;
|
||||
if( sending )
|
||||
{
|
||||
n.email = i->email;
|
||||
n.lang = Locale::StrToLang(data.locale_str);// !! bedzie osobno dla kazdego uzytkownika
|
||||
n.lang = Locale::StrToLang(config->locale_str);// !! bedzie osobno dla kazdego uzytkownika
|
||||
|
||||
if( n.lang == Locale::lang_unknown )
|
||||
n.lang = Locale::lang_en;
|
||||
|
||||
@@ -13,7 +13,12 @@
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include "../templatesnotify/templatesnotify.h"
|
||||
#include "templatesnotify/templatesnotify.h"
|
||||
|
||||
#include "request.h"
|
||||
#include "config.h"
|
||||
#include "system.h"
|
||||
#include "users.h"
|
||||
|
||||
|
||||
#define WINIX_NOTIFY_ITEM_ADD 1
|
||||
@@ -30,6 +35,11 @@ public:
|
||||
Notify();
|
||||
~Notify();
|
||||
|
||||
void SetRequest(Request * prequest);
|
||||
void SetConfig(Config * pconfig);
|
||||
void SetSystem(System * psystem);
|
||||
void SetTemplatesNotify(TemplatesNotify * ptemplates_notify);
|
||||
|
||||
void ReadTemplates();
|
||||
|
||||
bool Init();
|
||||
@@ -43,6 +53,10 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
Request * request;
|
||||
Config * config;
|
||||
System * system;
|
||||
TemplatesNotify * templates_notify;
|
||||
|
||||
static void * ThreadRoutine(void * arg);
|
||||
bool Lock();
|
||||
@@ -66,12 +80,12 @@ private:
|
||||
std::list<NotifyMsg> notify_pool;
|
||||
static Notify * obj;
|
||||
std::string command;
|
||||
TemplatesNotify templates_notify;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
extern Notify notify;
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -30,6 +30,15 @@ size_t i;
|
||||
Plugin::Plugin()
|
||||
{
|
||||
current_plugin = -1;
|
||||
request = 0;
|
||||
|
||||
db = 0;
|
||||
config = 0;
|
||||
request = 0;
|
||||
system = 0;
|
||||
functions = 0;
|
||||
templates = 0;
|
||||
session_manager = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +48,67 @@ Plugin::~Plugin()
|
||||
}
|
||||
|
||||
|
||||
void Plugin::SetDb(Db * pdb)
|
||||
{
|
||||
db = pdb;
|
||||
}
|
||||
|
||||
void Plugin::SetConfig(Config * pconfig)
|
||||
{
|
||||
config = pconfig;
|
||||
}
|
||||
|
||||
|
||||
void Plugin::SetRequest(Request * prequest)
|
||||
{
|
||||
request = prequest;
|
||||
}
|
||||
|
||||
|
||||
void Plugin::SetSystem(System * psystem)
|
||||
{
|
||||
system = psystem;
|
||||
}
|
||||
|
||||
|
||||
void Plugin::SetFunctions(Functions * pfunctions)
|
||||
{
|
||||
functions = pfunctions;
|
||||
}
|
||||
|
||||
|
||||
void Plugin::SetTemplates(Templates * ptemplates)
|
||||
{
|
||||
templates = ptemplates;
|
||||
}
|
||||
|
||||
|
||||
void Plugin::SetSessionManager(SessionManager * psession_manager)
|
||||
{
|
||||
session_manager = psession_manager;
|
||||
}
|
||||
|
||||
|
||||
bool Plugin::SetPointers(PluginInfo & info)
|
||||
{
|
||||
// for safety we call a plugin function only when all our pointers are not null
|
||||
bool res = (db && config && request && system && functions && templates && session_manager);
|
||||
|
||||
if( !res )
|
||||
log << log1 << "Plugin: cannot call a function - some of the winix pointers are null" << logend;
|
||||
|
||||
info.db = db;
|
||||
info.config = config;
|
||||
info.request = request;
|
||||
info.system = system;
|
||||
info.functions = functions;
|
||||
info.templates = templates;
|
||||
info.session_manager = session_manager;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void Plugin::LoadPlugins(const std::vector<std::string> & plugins)
|
||||
{
|
||||
size_t i;
|
||||
@@ -60,7 +130,8 @@ void * Plugin::LoadInitFun(const char * filename, Fun1 & fun_init)
|
||||
|
||||
if( !p )
|
||||
{
|
||||
log << log1 << "Plugin: cannot load a plugin: " << filename << logend;
|
||||
log << log1 << "Plugin: cannot load a plugin: \"" << filename << "\"" << logend;
|
||||
log << log1 << "Plugin: dlerror: " << dlerror() << logend;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -90,6 +161,9 @@ Fun1 fun_init;
|
||||
void * plugin_handle;
|
||||
int old_current_plugin;
|
||||
|
||||
if( !SetPointers(info) )
|
||||
return;
|
||||
|
||||
if( !(plugin_handle = LoadInitFun(filename, fun_init)) )
|
||||
return;
|
||||
|
||||
@@ -102,7 +176,7 @@ int old_current_plugin;
|
||||
|
||||
PluginsItem item;
|
||||
item.handle = plugin_handle;
|
||||
item.plugin_name = (const char *)info.p1;
|
||||
item.plugin_name = reinterpret_cast<const char *>(info.p1);
|
||||
|
||||
plugins.push_back(item);
|
||||
|
||||
@@ -113,11 +187,14 @@ int old_current_plugin;
|
||||
|
||||
void Plugin::Call(int message, Slots::iterator & slot)
|
||||
{
|
||||
if( !SetPointers(info) )
|
||||
return;
|
||||
|
||||
current_plugin = slot->second.index;
|
||||
info.plugin_id = current_plugin;
|
||||
|
||||
if( request.session && current_plugin != -1 )
|
||||
info.plugin_data_base = request.session->plugin_data.Get(current_plugin);
|
||||
if( request && request->session && current_plugin != -1 )
|
||||
info.plugin_data_base = request->session->plugin_data.Get(current_plugin);
|
||||
else
|
||||
info.plugin_data_base = 0;
|
||||
|
||||
@@ -168,36 +245,43 @@ void Plugin::Call(int message)
|
||||
Call(message, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
void Plugin::Call(int message, void * p1_)
|
||||
{
|
||||
Call(message, p1_, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
void Plugin::Call(int message, void * p1_, void * p2_)
|
||||
{
|
||||
Call(message, p1_, p2_, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
void Plugin::Call(int message, long l1_)
|
||||
{
|
||||
Call(message, 0, 0, l1_, 0);
|
||||
}
|
||||
|
||||
|
||||
void Plugin::Call(int message, long l1_, long l2_)
|
||||
{
|
||||
Call(message, 0, 0, l1_, l2_);
|
||||
}
|
||||
|
||||
|
||||
void Plugin::Call(int message, void * p1_, long l1_)
|
||||
{
|
||||
Call(message, p1_, 0, l1_, 0);
|
||||
}
|
||||
|
||||
|
||||
void Plugin::Call(int message, void * p1_, long l1_, long l2_)
|
||||
{
|
||||
Call(message, p1_, 0, l1_, l2_);
|
||||
}
|
||||
|
||||
|
||||
void Plugin::Call(int message, void * p1_, void * p2_, long l1_)
|
||||
{
|
||||
Call(message, p1_, p2_, l1_, 0);
|
||||
|
||||
@@ -14,11 +14,15 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "request.h"
|
||||
#include "data.h"
|
||||
#include "pluginmsg.h"
|
||||
#include "log.h"
|
||||
#include "plugindata.h"
|
||||
#include "config.h"
|
||||
#include "request.h"
|
||||
#include "system.h"
|
||||
#include "sessionmanager.h"
|
||||
#include "functions/functions.h"
|
||||
#include "templates/templates.h"
|
||||
|
||||
|
||||
/*
|
||||
@@ -33,6 +37,8 @@
|
||||
and you can set the name of the plugin by setting info.p1 pointer
|
||||
to a string buffer (const char *)
|
||||
(this buffer will not be copied so it should not be destroyed after Init finishes)
|
||||
also in Init you can only use logger (log) info.config and info.db objects
|
||||
(the rest winix objects are not initialized yet)
|
||||
*/
|
||||
|
||||
|
||||
@@ -50,10 +56,19 @@ struct PluginInfo
|
||||
// unique plugin identifier
|
||||
int plugin_id;
|
||||
|
||||
// objects from winix which are accessible from a plugin
|
||||
Db * db;
|
||||
Config * config;
|
||||
Request * request;
|
||||
System * system;
|
||||
Functions * functions;
|
||||
Templates * templates;
|
||||
SessionManager * session_manager;
|
||||
|
||||
// pointer to the plugin session (can be null if not set by the plugin)
|
||||
// you should use WINIX_SESSION_CREATED and WINIX_SESSION_REMOVE
|
||||
// to create your plugin's session data
|
||||
PluginDataBase * plugin_data_base;
|
||||
PluginDataBase * plugin_data_base; // !! zmienic nazwe na plugin_session_base ? a moze session_base; a moze plugin_session?
|
||||
|
||||
// function return status
|
||||
// default: false (if not set by the plugin)
|
||||
@@ -62,6 +77,8 @@ struct PluginInfo
|
||||
|
||||
void Clear()
|
||||
{
|
||||
// pointers to winix objects are not cleared here
|
||||
|
||||
p1 = 0;
|
||||
p2 = 0;
|
||||
l1 = 0;
|
||||
@@ -109,6 +126,14 @@ public:
|
||||
Plugin();
|
||||
~Plugin();
|
||||
|
||||
void SetDb(Db * pdb);
|
||||
void SetConfig(Config * pconfig);
|
||||
void SetRequest(Request * prequest);
|
||||
void SetSystem(System * psystem);
|
||||
void SetFunctions(Functions * pfunctions);
|
||||
void SetTemplates(Templates * ptemplates);
|
||||
void SetSessionManager(SessionManager * psession_manager);
|
||||
|
||||
void LoadPlugin(const char * filename);
|
||||
void LoadPlugin(const std::string & filename);
|
||||
void LoadPlugins(const std::vector<std::string> & plugins);
|
||||
@@ -134,6 +159,14 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
Db * db;
|
||||
Config * config;
|
||||
Request * request;
|
||||
System * system;
|
||||
Functions * functions;
|
||||
Templates * templates;
|
||||
SessionManager * session_manager;
|
||||
|
||||
|
||||
struct PluginsItem
|
||||
{
|
||||
@@ -151,6 +184,8 @@ private:
|
||||
|
||||
void * LoadInitFun(const char * filename, Fun1 & fun_init);
|
||||
void Call(int message, Slots::iterator & slot);
|
||||
|
||||
bool SetPointers(PluginInfo & info);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -30,9 +30,6 @@
|
||||
// when a session is changed (you can save a pointer to your data here)
|
||||
#define WINIX_SESSION_CHANGED 3002
|
||||
|
||||
// all plugins have been started, now you can init
|
||||
#define WINIX_PLUGIN_INIT 3003
|
||||
|
||||
// the winix is closing
|
||||
#define WINIX_CLOSE 3004
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "postmultiparser.h"
|
||||
#include "log.h"
|
||||
#include "data.h"
|
||||
|
||||
|
||||
|
||||
PostMultiParser::PostMultiParser()
|
||||
@@ -18,16 +18,17 @@ PostMultiParser::PostMultiParser()
|
||||
}
|
||||
|
||||
|
||||
PostMultiParser::PostMultiParser(const PostMultiParser &)
|
||||
PostMultiParser::PostMultiParser(const PostMultiParser & p)
|
||||
{
|
||||
in_buffer = new unsigned char[WINIX_POSTMULTI_INPUT_BUFFER];
|
||||
config = p.config;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PostMultiParser & PostMultiParser::operator=(const PostMultiParser &)
|
||||
PostMultiParser & PostMultiParser::operator=(const PostMultiParser & p)
|
||||
{
|
||||
in_buffer = new unsigned char[WINIX_POSTMULTI_INPUT_BUFFER];
|
||||
config = p.config;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -39,6 +40,11 @@ PostMultiParser::~PostMultiParser()
|
||||
}
|
||||
|
||||
|
||||
void PostMultiParser::SetConfig(Config * pconfig)
|
||||
{
|
||||
config = pconfig;
|
||||
}
|
||||
|
||||
|
||||
void PostMultiParser::ReadBoundary()
|
||||
{
|
||||
@@ -263,10 +269,10 @@ bool has_boundary = false;
|
||||
content.erase(0, WINIX_POSTMULTI_OUTPUT_BUFFER);
|
||||
}
|
||||
|
||||
if( data.post_file_max != 0 && content_len > (size_t)data.post_file_max )
|
||||
if( config->post_file_max != 0 && content_len > (size_t)config->post_file_max )
|
||||
{
|
||||
err = WINIX_ERR_INPUT_TOO_LARGE;
|
||||
log << log1 << "PMP: content greater than " << data.post_file_max << " (skipping)" << logend;
|
||||
log << log1 << "PMP: content greater than " << config->post_file_max << " (skipping)" << logend;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -317,10 +323,10 @@ bool has_boundary = false;
|
||||
content_len += 1;
|
||||
ReadChar();
|
||||
|
||||
if( data.post_file_max != 0 && content_len > (size_t)data.post_file_max )
|
||||
if( config->post_file_max != 0 && content_len > (size_t)config->post_file_max )
|
||||
{
|
||||
err = WINIX_ERR_INPUT_TOO_LARGE;
|
||||
log << log1 << "PMP: content greater than " << data.post_file_max << " (skipping)" << logend;
|
||||
log << log1 << "PMP: content greater than " << config->post_file_max << " (skipping)" << logend;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -433,14 +439,14 @@ void PostMultiParser::CreateTmpFile()
|
||||
{
|
||||
char buf[100];
|
||||
|
||||
if( data.auth_tmp_dir.empty() )
|
||||
if( config->auth_tmp_dir.empty() )
|
||||
{
|
||||
log << log1 << "PMP: auth_tmp_dir is not set in the config" << logend;
|
||||
err = WINIX_ERR_CANT_CREATE_FILE;
|
||||
return;
|
||||
}
|
||||
|
||||
sprintf(buf, "%s/winix_%u_%d_%u", data.auth_tmp_dir.c_str(), (unsigned)getpid(), tmp_filename_postfix, rand());
|
||||
sprintf(buf, "%s/winix_%u_%d_%u", config->auth_tmp_dir.c_str(), (unsigned)getpid(), tmp_filename_postfix, rand());
|
||||
tmp_filename_postfix += 1;
|
||||
|
||||
tmp_file.open(buf, std::ios_base::binary | std::ios_base::out);
|
||||
@@ -457,6 +463,8 @@ char buf[100];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void PostMultiParser::ReadPart()
|
||||
{
|
||||
name.clear();
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include <fstream>
|
||||
#include "error.h"
|
||||
#include "requesttypes.h"
|
||||
#include "config.h"
|
||||
|
||||
|
||||
// 2 MB
|
||||
#define WINIX_POSTMULTI_INPUT_BUFFER 2097152
|
||||
@@ -31,10 +33,13 @@ public:
|
||||
PostMultiParser & operator=(const PostMultiParser &);
|
||||
~PostMultiParser();
|
||||
|
||||
void SetConfig(Config * pconfig);
|
||||
Error Parse(FCGX_Stream * in_, PostTable & post_table_, PostFileTable & post_file_table_);
|
||||
|
||||
private:
|
||||
|
||||
Config * config;
|
||||
|
||||
FCGX_Stream * in;
|
||||
unsigned char * in_buffer;
|
||||
std::ofstream tmp_file;
|
||||
|
||||
@@ -12,9 +12,16 @@
|
||||
#include "log.h"
|
||||
#include "rebus.h"
|
||||
#include "misc.h"
|
||||
#include "request.h"
|
||||
|
||||
|
||||
|
||||
void Rebus::SetRequest(Request * prequest)
|
||||
{
|
||||
request = prequest;
|
||||
}
|
||||
|
||||
|
||||
bool Rebus::InitPair(int a, int b, Item & item)
|
||||
{
|
||||
char buffer[100];
|
||||
@@ -118,6 +125,37 @@ return result;
|
||||
|
||||
|
||||
|
||||
bool Rebus::CheckRebus()
|
||||
{
|
||||
if( !request->session )
|
||||
return false;
|
||||
|
||||
if( request->session->puser )
|
||||
// logged users don't have to use the rebus
|
||||
return true;
|
||||
|
||||
if( request->session->rebus_checked )
|
||||
return true;
|
||||
|
||||
request->session->rebus_checked = true;
|
||||
|
||||
if( !request->session->rebus_item )
|
||||
{
|
||||
log << log1 << "Rebus: rebus not set" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string * answer = request->PostVar("rebus");
|
||||
|
||||
if( answer && IsAnswerOk(request->session->rebus_item, *answer) )
|
||||
return true;
|
||||
|
||||
log << log1 << "Rebus: rebus has an incorrect answer" << logend;
|
||||
// don't add request->session->spam_score when the rebus has incorrect answer
|
||||
// a user could have made a mistake
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
#include <vector>
|
||||
|
||||
|
||||
class Request;
|
||||
|
||||
|
||||
class Rebus
|
||||
{
|
||||
public:
|
||||
@@ -27,12 +30,17 @@ public:
|
||||
};
|
||||
|
||||
|
||||
|
||||
void SetRequest(Request * prequest);
|
||||
void Init();
|
||||
Item * Rand();
|
||||
bool IsAnswerOk(Item * item, const std::string & answer);
|
||||
bool CheckRebus();
|
||||
|
||||
private:
|
||||
|
||||
Request * request;
|
||||
|
||||
bool InitPair(int a, int b, Item & item);
|
||||
|
||||
std::vector<Item> table;
|
||||
|
||||
544
core/request.cpp
544
core/request.cpp
@@ -15,10 +15,13 @@
|
||||
#include "postparser.h"
|
||||
#include "cookieparser.h"
|
||||
#include "log.h"
|
||||
#include "data.h"
|
||||
#include "plugin.h"
|
||||
#include "misc.h"
|
||||
#include "db.h"
|
||||
#include "functions/functionbase.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Request::Request() : char_empty(0)
|
||||
@@ -27,6 +30,13 @@ Request::Request() : char_empty(0)
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
void Request::SetConfig(Config * pconfig)
|
||||
{
|
||||
config = pconfig;
|
||||
}
|
||||
|
||||
|
||||
void Request::Init()
|
||||
{
|
||||
compress.Init();
|
||||
@@ -125,7 +135,7 @@ void Request::SetCookie(const char * name, const char * value, tm * expires)
|
||||
if( expires )
|
||||
headers << "; expires=" << DateToStrCookie(expires) << " GMT";
|
||||
|
||||
headers << "; path=/; domain=." << data.base_server << "\r\n";
|
||||
headers << "; path=/; domain=." << config->base_server << "\r\n";
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +147,7 @@ void Request::SetCookie(const char * name, long value, tm * expires)
|
||||
if( expires )
|
||||
headers << "; expires=" << DateToStrCookie(expires) << " GMT";
|
||||
|
||||
headers << "; path=/; domain=." << data.base_server << "\r\n";
|
||||
headers << "; path=/; domain=." << config->base_server << "\r\n";
|
||||
}
|
||||
|
||||
|
||||
@@ -327,6 +337,8 @@ return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// !! czy te parsery powinny byc skladowymi Request?
|
||||
void Request::ReadParameters()
|
||||
{
|
||||
// !! wrzucic jako skladowa klasy
|
||||
@@ -339,6 +351,7 @@ void Request::ReadParameters()
|
||||
{
|
||||
log << log3 << "Request: post content type: multipart/form-data" << logend;
|
||||
|
||||
post_multi_parser.SetConfig(config);
|
||||
post_multi_parser.Parse(in, post_table, post_file_table);
|
||||
}
|
||||
else
|
||||
@@ -390,21 +403,21 @@ void Request::SendSessionCookie()
|
||||
|
||||
if( !session->puser || !session->remember_me )
|
||||
{
|
||||
SetCookie(data.http_session_id_name.c_str(), session->id);
|
||||
SetCookie(config->http_session_id_name.c_str(), session->id);
|
||||
return;
|
||||
}
|
||||
|
||||
time_t t = time(0) + data.session_remember_max_idle;
|
||||
time_t t = time(0) + config->session_remember_max_idle;
|
||||
tm * expires = localtime(&t);
|
||||
|
||||
if( !expires )
|
||||
{
|
||||
// oops, something wrong
|
||||
SetCookie(data.http_session_id_name.c_str(), session->id);
|
||||
SetCookie(config->http_session_id_name.c_str(), session->id);
|
||||
return;
|
||||
}
|
||||
|
||||
SetCookie(data.http_session_id_name.c_str(), session->id, expires);
|
||||
SetCookie(config->http_session_id_name.c_str(), session->id, expires);
|
||||
}
|
||||
|
||||
|
||||
@@ -472,15 +485,15 @@ void Request::AddDebugInfo()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// !! to powinno isc do kontrolera app
|
||||
void Request::SendPage(bool compressing, const std::string & source_ref)
|
||||
{
|
||||
const std::string * source = &source_ref;
|
||||
|
||||
bool raw = request.is_item && request.item.content_type == Item::ct_raw && request.status == WINIX_ERR_OK &&
|
||||
request.pfunction && (request.pfunction->code == FUN_CAT || request.pfunction->code == FUN_RUN);
|
||||
bool raw = is_item && item.content_type == Item::ct_raw && status == WINIX_ERR_OK &&
|
||||
pfunction && (pfunction->fun.url == "cat" || pfunction->fun.url == "run");
|
||||
|
||||
if( data.html_filter && !raw )
|
||||
if( config->html_filter && !raw )
|
||||
{
|
||||
html_filter.TrimWhite(true);
|
||||
html_filter.BreakLines(60);
|
||||
@@ -502,7 +515,7 @@ void Request::SendAll()
|
||||
{
|
||||
const std::string & source = page.str();
|
||||
Header header = h_200;
|
||||
bool compressing = data.compression && role == responder && redirect_to.empty() && x_sendfile.empty() &&
|
||||
bool compressing = config->compression && role == responder && redirect_to.empty() && x_sendfile.empty() &&
|
||||
!browser_msie && !browser_konqueror &&
|
||||
accept_encoding_parser.AcceptDeflate() && source.size() >= 512;
|
||||
|
||||
@@ -567,514 +580,7 @@ return str_empty;
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanChangeUser(const Item & item, long new_user_id)
|
||||
{
|
||||
if( !session )
|
||||
// session must be set
|
||||
return false;
|
||||
|
||||
if( session->puser && session->puser->super_user )
|
||||
// super user is allowed everything
|
||||
return true;
|
||||
|
||||
if( item.user_id != new_user_id )
|
||||
// only super user can change the owner of an item
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanChangeGroup(const Item & item, long new_group_id)
|
||||
{
|
||||
if( !session )
|
||||
// session must be set
|
||||
return false;
|
||||
|
||||
if( session->puser && session->puser->super_user )
|
||||
// super user is allowed everything
|
||||
return true;
|
||||
|
||||
if( item.group_id != new_group_id )
|
||||
{
|
||||
// user is allowed to change the group only if he is an owner of the item
|
||||
// he can change only into a group in which he is a member of, or into a 'no_group'
|
||||
|
||||
if( !session->puser )
|
||||
return false;
|
||||
|
||||
if( session->puser->id != item.user_id )
|
||||
return false;
|
||||
|
||||
if( new_group_id == -1 )
|
||||
return true;
|
||||
|
||||
if( !session->puser->IsMemberOf(new_group_id) )
|
||||
return false;
|
||||
|
||||
// is logged, is the owner of the item, is the member of the new group
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanChangePrivileges(const Item & item, int new_priv)
|
||||
{
|
||||
if( !session )
|
||||
// session must be set
|
||||
return false;
|
||||
|
||||
if( session->puser && session->puser->super_user )
|
||||
// super user is allowed everything
|
||||
return true;
|
||||
|
||||
if( item.privileges != new_priv )
|
||||
{
|
||||
// the owner of an item is allowed to change the privileges
|
||||
|
||||
if( !session->puser )
|
||||
return false;
|
||||
|
||||
if( session->puser->id != item.user_id )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Request::HasAccess(const Item & item, int mask)
|
||||
{
|
||||
if( !session )
|
||||
// session must be set
|
||||
return false;
|
||||
|
||||
if( session->puser && session->puser->super_user )
|
||||
// super user is allowed everything
|
||||
return true;
|
||||
|
||||
if( session->puser && session->puser->id == item.user_id )
|
||||
{
|
||||
// the owner
|
||||
return ((item.privileges >> 6) & mask) == mask;
|
||||
}
|
||||
|
||||
if( session->puser && session->puser->IsMemberOf(item.group_id) )
|
||||
{
|
||||
// group
|
||||
return ((item.privileges >> 3) & mask) == mask;
|
||||
}
|
||||
|
||||
// others
|
||||
|
||||
return (item.privileges & mask) == mask;
|
||||
}
|
||||
|
||||
|
||||
bool Request::HasReadAccess(const Item & item)
|
||||
{
|
||||
return HasAccess(item, 4);
|
||||
}
|
||||
|
||||
|
||||
bool Request::HasWriteAccess(const Item & item)
|
||||
{
|
||||
return HasAccess(item, 2);
|
||||
}
|
||||
|
||||
|
||||
bool Request::HasReadWriteAccess(const Item & item)
|
||||
{
|
||||
return HasAccess(item, 6); // r+w
|
||||
}
|
||||
|
||||
|
||||
bool Request::HasReadExecAccess(const Item & item)
|
||||
{
|
||||
if( session && session->puser && session->puser->super_user )
|
||||
{
|
||||
// there must be at least one 'x' (for the root)
|
||||
|
||||
return (item.privileges & 0111) != 0;
|
||||
}
|
||||
|
||||
return HasAccess(item, 5); // r+x
|
||||
}
|
||||
|
||||
|
||||
bool Request::HasReadExecAccessForRoot(const Item & item)
|
||||
{
|
||||
// there must be at least one 'x' (for the root)
|
||||
|
||||
return (item.privileges & 0111) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Request::HasReadExecAccessToPath(long dir_id)
|
||||
{
|
||||
while( true )
|
||||
{
|
||||
Item * pdir = data.dirs.GetDir(dir_id);
|
||||
|
||||
if( !pdir )
|
||||
return false;
|
||||
|
||||
if( !HasReadExecAccess(*pdir) )
|
||||
return false;
|
||||
|
||||
dir_id = pdir->parent_id;
|
||||
|
||||
if( dir_id == -1 )
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// returning true if we can create a thread in the current directory
|
||||
bool Request::CanCreateThread(bool check_root)
|
||||
{
|
||||
if( request.dir_table.empty() )
|
||||
return false;
|
||||
|
||||
if( request.is_item )
|
||||
return false;
|
||||
|
||||
if( !HasWriteAccess(*request.dir_table.back()) )
|
||||
return false;
|
||||
|
||||
if( !data.mounts.pmount || data.mounts.pmount->type != Mount::thread )
|
||||
return false;
|
||||
|
||||
if( !check_root && session && session->puser && session->puser->super_user )
|
||||
// super can create thread regardless of the restrictcreatethread option
|
||||
return true;
|
||||
|
||||
if( !data.mounts.pmount->IsPar(Mount::par_createthread_on) )
|
||||
return true;
|
||||
|
||||
if( data.mounts.pmount->IsArg(Mount::par_createthread_on, request.dir_table.size()) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// returning true if we can create a ticket in the current directory
|
||||
bool Request::CanCreateTicket(bool check_root)
|
||||
{
|
||||
if( request.dir_table.empty() )
|
||||
return false;
|
||||
|
||||
if( request.is_item )
|
||||
return false;
|
||||
|
||||
if( !HasWriteAccess(*request.dir_table.back()) )
|
||||
return false;
|
||||
|
||||
if( !data.mounts.pmount || data.mounts.pmount->type != Mount::ticket )
|
||||
return false;
|
||||
|
||||
|
||||
// checking for par_createticket_on mount option
|
||||
|
||||
if( !check_root && session && session->puser && session->puser->super_user )
|
||||
// super can create tickets regardless of the createticket_on option
|
||||
return true;
|
||||
|
||||
if( !data.mounts.pmount->IsPar(Mount::par_createticket_on) )
|
||||
return true;
|
||||
|
||||
if( data.mounts.pmount->IsArg(Mount::par_createticket_on, request.dir_table.size()) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Request::CanEditTicket()
|
||||
{
|
||||
// not logged users cannot edit tickets
|
||||
if( !request.session->puser )
|
||||
return false;
|
||||
|
||||
if( request.dir_table.empty() )
|
||||
return false;
|
||||
|
||||
if( request.is_item || !request.is_ticket )
|
||||
return false;
|
||||
|
||||
if( !HasWriteAccess(*request.dir_table.back()) )
|
||||
return false;
|
||||
|
||||
if( !data.mounts.pmount || data.mounts.pmount->type != Mount::ticket )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Request::CanRemove(const Item & item)
|
||||
{
|
||||
// !! temporarily (we're waiting for the sticky bit to be implemented)
|
||||
// not logged users cannot remove anything
|
||||
if( !request.session->puser )
|
||||
return false;
|
||||
|
||||
if( item.parent_id == -1 )
|
||||
{
|
||||
// rm for the root dir
|
||||
// only the superuser can do it
|
||||
if( !request.session->puser || !request.session->puser->super_user )
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Item * last_but_one_dir = data.dirs.GetDir(item.parent_id);
|
||||
|
||||
if( !last_but_one_dir )
|
||||
// ops, there is no a parent dir
|
||||
return false;
|
||||
|
||||
if( !request.HasWriteAccess(*last_but_one_dir) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if( data.mounts.pmount->IsPar(Mount::par_only_root_remove) )
|
||||
if( !request.session->puser || !request.session->puser->super_user )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanUseEmacs(const Item & item, bool check_root)
|
||||
{
|
||||
if( !check_root && request.session->puser && request.session->puser->super_user )
|
||||
// super user can use emacs everywhere
|
||||
return true;
|
||||
|
||||
if( !request.HasWriteAccess(item) )
|
||||
return false;
|
||||
|
||||
if( !data.mounts.pmount->IsPar(Mount::par_emacs_on) )
|
||||
return true;
|
||||
|
||||
if( data.mounts.pmount->IsArg(Mount::par_emacs_on, request.dir_table.size()) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanUseMkdir(const Item & item, bool check_root)
|
||||
{
|
||||
// you can create a directory only in a directory
|
||||
if( item.type != Item::dir )
|
||||
return false;
|
||||
|
||||
if( !check_root && request.session->puser && request.session->puser->super_user )
|
||||
// super user can use mkdir everywhere
|
||||
return true;
|
||||
|
||||
if( !request.HasWriteAccess(item) )
|
||||
return false;
|
||||
|
||||
if( !data.mounts.pmount->IsPar(Mount::par_mkdir_on) )
|
||||
return true;
|
||||
|
||||
if( data.mounts.pmount->IsArg(Mount::par_mkdir_on, request.dir_table.size()) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanUseUpload(const Item & item, bool check_root)
|
||||
{
|
||||
// you can use 'upload' only in a directory
|
||||
if( item.type != Item::dir )
|
||||
return false;
|
||||
|
||||
// we must know where to store the file
|
||||
if( !data.mounts.pmount )
|
||||
return false;
|
||||
|
||||
if( data.mounts.pmount->fs == Mount::simplefs && data.auth_simplefs_dir.empty() )
|
||||
{
|
||||
log << log1 << "Request: can't use upload function, auth_simplefs_dir must be set in the config file" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( data.mounts.pmount->fs == Mount::hashfs && data.auth_hashfs_dir.empty() )
|
||||
{
|
||||
log << log1 << "Request: can't use upload function, auth_hashfs_dir must be set in the config file" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( data.auth_tmp_dir.empty() )
|
||||
{
|
||||
log << log1 << "Request: can't use upload function, auth_tmp_dir must be set in the config file" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !check_root && request.session->puser && request.session->puser->super_user )
|
||||
// super user can use upload everywhere
|
||||
return true;
|
||||
|
||||
if( !request.HasWriteAccess(item) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanUseHtml(long user_id)
|
||||
{
|
||||
return CanUse(user_id, "allow_html");
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanUseBBCode(long user_id)
|
||||
{
|
||||
// logged users can use bbcode
|
||||
return (user_id != -1);
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanUseRaw(long user_id)
|
||||
{
|
||||
return CanUse(user_id, "allow_raw");
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanUse(long user_id, const char * group_name)
|
||||
{
|
||||
User * puser = data.users.GetUser(user_id);
|
||||
|
||||
if( !puser )
|
||||
return false;
|
||||
|
||||
if( puser->super_user )
|
||||
return true;
|
||||
|
||||
long group = data.groups.GetGroupId(group_name);
|
||||
|
||||
if( group == -1 )
|
||||
// there is no such a group
|
||||
return false;
|
||||
|
||||
if( puser->IsMemberOf(group) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool Request::MakePathSimpleFs(std::string & path, long dir_id, bool create_dir)
|
||||
{
|
||||
if( data.auth_simplefs_dir.empty() )
|
||||
{
|
||||
log << log1 << "Request: auth_simplefs_dir is not set in the config file" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !data.dirs.MakePath(dir_id, path) )
|
||||
return false;
|
||||
|
||||
if( create_dir && !CreateDirs(data.auth_simplefs_dir, path, 0755) )
|
||||
return false;
|
||||
|
||||
path.insert(0, data.auth_simplefs_dir);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// the path depends on id
|
||||
bool Request::MakePathHashFs(std::string & path, long id, bool create_dir)
|
||||
{
|
||||
char buffer[50];
|
||||
char * hash = buffer;
|
||||
|
||||
// get 'id' as hexadecimal
|
||||
buffer[0] = '0';
|
||||
sprintf(buffer+1, "%lx", (unsigned long)id);
|
||||
|
||||
path = data.auth_hashfs_dir;
|
||||
if( path.empty() )
|
||||
{
|
||||
log << log1 << "Request: auth_hashfs_dir is not set in the config file" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
path += '/';
|
||||
|
||||
// make sure that the length is even
|
||||
if( (strlen(hash) & 1) != 0 )
|
||||
hash = buffer + 1; // the first character was zero
|
||||
|
||||
// creating dirs without the last part
|
||||
// the last part is a part of a file
|
||||
for(size_t i=0 ; hash[i] != 0 ; i+=2)
|
||||
{
|
||||
path += hash[i];
|
||||
path += hash[i+1];
|
||||
|
||||
if( hash[i+2] != 0 )
|
||||
{
|
||||
if( create_dir && !CreateDir(path, 0755) )
|
||||
return false;
|
||||
|
||||
path += '/';
|
||||
}
|
||||
}
|
||||
|
||||
// one character more to make sure the path is unique
|
||||
// (we can have a directory without the character)
|
||||
path += "_";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// making a complete path to a static file
|
||||
bool Request::MakePath(const Item & item, std::string & path, bool create_dir)
|
||||
{
|
||||
bool res;
|
||||
|
||||
Mount * pmount = data.mounts.CalcMount(item.parent_id);
|
||||
|
||||
if( !pmount || pmount->fs == Mount::simplefs )
|
||||
{
|
||||
res = MakePathSimpleFs(path, item.parent_id, create_dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
res = MakePathHashFs(path, item.id, create_dir);
|
||||
}
|
||||
|
||||
if( res )
|
||||
path += item.url;
|
||||
else
|
||||
path.clear();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Request::MakePath(Item & item, bool create_dir)
|
||||
{
|
||||
return MakePath(item, item.auth_path, create_dir);
|
||||
}
|
||||
|
||||
@@ -19,16 +19,19 @@
|
||||
#include "session.h"
|
||||
#include "item.h"
|
||||
#include "error.h"
|
||||
#include "function.h"
|
||||
#include "thread.h"
|
||||
#include "compress.h"
|
||||
#include "acceptencodingparser.h"
|
||||
#include "htmlfilter.h"
|
||||
#include "postmultiparser.h"
|
||||
#include "ticket.h"
|
||||
#include "config.h"
|
||||
|
||||
|
||||
|
||||
class FunctionBase;
|
||||
|
||||
|
||||
struct Request
|
||||
{
|
||||
// request id
|
||||
@@ -87,7 +90,7 @@ struct Request
|
||||
Item item;
|
||||
|
||||
// null if there is no a function
|
||||
Function * pfunction;
|
||||
FunctionBase * pfunction;
|
||||
|
||||
// parameters (name:value)
|
||||
ParamTable param_table;
|
||||
@@ -149,37 +152,12 @@ struct Request
|
||||
void SendAll();
|
||||
void SendNotify();
|
||||
|
||||
bool CanChangeUser(const Item & item, long new_user_id);
|
||||
bool CanChangeGroup(const Item & item, long new_group_id);
|
||||
bool CanChangePrivileges(const Item & item, int new_priv);
|
||||
|
||||
bool HasAccess(const Item & item, int mask);
|
||||
bool HasReadAccess(const Item & item);
|
||||
bool HasWriteAccess(const Item & item);
|
||||
bool HasReadWriteAccess(const Item & item);
|
||||
bool HasReadExecAccess(const Item & item);
|
||||
bool HasReadExecAccessForRoot(const Item & item);
|
||||
bool HasReadExecAccessToPath(long dir_id);
|
||||
|
||||
bool CanCreateThread(bool check_root = false);
|
||||
bool CanCreateTicket(bool check_root = false);
|
||||
bool CanEditTicket();
|
||||
bool CanRemove(const Item & item);
|
||||
bool CanUseEmacs(const Item & item, bool check_root = false);
|
||||
bool CanUseMkdir(const Item & item, bool check_root = false);
|
||||
bool CanUseUpload(const Item & item, bool check_root = false);
|
||||
|
||||
bool CanUseHtml(long user_id);
|
||||
bool CanUseBBCode(long user_id);
|
||||
bool CanUseRaw(long user_id);
|
||||
|
||||
bool MakePathSimpleFs(std::string & path, long dir_id, bool create_dir = false);
|
||||
bool MakePathHashFs(std::string & path, long id, bool create_dir = false);
|
||||
bool MakePath(const Item & item, std::string & path, bool create_dir = false);
|
||||
bool MakePath(Item & item, bool create_dir = false);
|
||||
void SetConfig(Config * pconfig);
|
||||
|
||||
private:
|
||||
|
||||
Config * config;
|
||||
|
||||
enum Header
|
||||
{
|
||||
h_200,
|
||||
@@ -204,6 +182,7 @@ private:
|
||||
// used in ParamValue(const char * param_name) when there is no such a param
|
||||
const std::string str_empty;
|
||||
|
||||
|
||||
PostMultiParser post_multi_parser;
|
||||
|
||||
const char * SetEnvVar(const char * var);
|
||||
@@ -221,7 +200,7 @@ private:
|
||||
|
||||
|
||||
|
||||
extern Request request;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,260 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "requestcontroller.h"
|
||||
#include "data.h"
|
||||
#include "log.h"
|
||||
#include "request.h"
|
||||
#include "postparser.h"
|
||||
#include "cookieparser.h"
|
||||
#include "notify.h"
|
||||
|
||||
|
||||
|
||||
RequestController::RequestController()
|
||||
{
|
||||
last_sessions_save = time(0);
|
||||
}
|
||||
|
||||
|
||||
RequestController::~RequestController()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
void RequestController::Close()
|
||||
{
|
||||
// don't call close(0)
|
||||
// it will be closed next time during dup(s,0)
|
||||
|
||||
// if you closed the descriptor here
|
||||
// then the database would have that descriptor (during connecting)
|
||||
// and there'll be a problem in the next loop (after SIGHUP)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool RequestController::Init()
|
||||
{
|
||||
const char * sock = data.fcgi_socket.c_str();
|
||||
|
||||
unlink(sock);
|
||||
|
||||
|
||||
|
||||
int s = FCGX_OpenSocket(sock, 10);
|
||||
|
||||
if( s < 0 )
|
||||
{
|
||||
log << log1 << "An error during creating a socket" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
chmod(sock, data.fcgi_socket_chmod);
|
||||
|
||||
passwd * pw = getpwnam(data.fcgi_socket_user.c_str());
|
||||
|
||||
if( !pw )
|
||||
{
|
||||
log << log1 << "There is no user: " << data.fcgi_socket_user << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
group * gr = getgrnam(data.fcgi_socket_group.c_str());
|
||||
|
||||
if( !gr )
|
||||
{
|
||||
log << log1 << "There is no group: " << data.fcgi_socket_group << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
chown(sock, pw->pw_uid, gr->gr_gid);
|
||||
|
||||
|
||||
|
||||
if( setuid(pw->pw_uid) < 0 )
|
||||
{
|
||||
log << log1 << "I can't change the user into: " << data.fcgi_socket_user << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
if( setgid(gr->gr_gid) < 0 )
|
||||
{
|
||||
int e = errno;
|
||||
|
||||
log << log1 << "I can't change the group into: " << data.fcgi_socket_group << " " << gr->gr_gid << logend;
|
||||
log << log1 << "errno: " << e << logend;
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
dup2(s, 0);
|
||||
|
||||
//
|
||||
data.dirs.ReadDirs();
|
||||
data.users.ReadUsers();
|
||||
data.groups.ReadGroups();
|
||||
data.functions.ReadFunctions();
|
||||
data.mounts.ReadMounts();
|
||||
data.rebus.Init();
|
||||
//
|
||||
|
||||
|
||||
|
||||
if( !content.Init() )
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void RequestController::LoadSessions()
|
||||
{
|
||||
session_manager.LoadSessions();
|
||||
}
|
||||
|
||||
void RequestController::SaveSessions()
|
||||
{
|
||||
session_manager.SaveSessions();
|
||||
}
|
||||
|
||||
|
||||
void RequestController::DeleteAllPluginsData()
|
||||
{
|
||||
session_manager.DeleteAllPluginsData();
|
||||
}
|
||||
|
||||
|
||||
void RequestController::SaveSessionsIfNeeded()
|
||||
{
|
||||
time_t t = time(0);
|
||||
|
||||
if( last_sessions_save + 86400 > t )
|
||||
return;
|
||||
|
||||
// saving once a day for safety
|
||||
last_sessions_save = t;
|
||||
SaveSessions();
|
||||
}
|
||||
|
||||
|
||||
bool RequestController::BaseUrlRedirect()
|
||||
{
|
||||
if( request.role == Request::responder )
|
||||
{
|
||||
if( data.base_url_http_host.empty() )
|
||||
return false;
|
||||
|
||||
if( data.base_url_http_host == request.env_http_host )
|
||||
return false;
|
||||
|
||||
request.redirect_to = data.base_url + request.env_request_uri;
|
||||
}
|
||||
else
|
||||
{
|
||||
// authorizer
|
||||
|
||||
if( data.base_url_auth_http_host.empty() )
|
||||
return false;
|
||||
|
||||
if( data.base_url_auth_http_host == request.env_http_host )
|
||||
return false;
|
||||
|
||||
request.redirect_to = data.base_url_auth + request.env_request_uri;
|
||||
}
|
||||
|
||||
log << log3 << "RC: BaseUrlRedirect from: " << request.env_http_host << logend;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RequestController::Loop()
|
||||
{
|
||||
while( FCGX_Accept(&request.in, &request.out, &request.err, &request.env) == 0 )
|
||||
{
|
||||
data.load_avg.StartRequest();
|
||||
log << log2 << "---------------------------------------------------------------------------------" << logend;
|
||||
|
||||
try
|
||||
{
|
||||
request.Clear();
|
||||
request.Read();
|
||||
|
||||
// when BaseUrlRedirect() return true we didn't have to set everything in request.Read()
|
||||
// in the future request.Read() can be split and at the beginning only environment variables will be read
|
||||
// and then BaseUrlRedirect() will be called (for performance)
|
||||
if( !BaseUrlRedirect() )
|
||||
{
|
||||
session_manager.DeleteOldSessions();
|
||||
session_manager.SetSession(); // set request.session as well
|
||||
|
||||
function_parser.Parse();
|
||||
data.mounts.CalcCurMount();
|
||||
|
||||
content.ReadAdditionalInfo();
|
||||
content.Make();
|
||||
}
|
||||
|
||||
request.SendAll();
|
||||
notify.ItemChanged(request.notify_code);
|
||||
}
|
||||
catch(const std::logic_error & e)
|
||||
{
|
||||
log << log1 << "std logic exception: " << e.what() << logend;
|
||||
}
|
||||
catch(const std::exception & e)
|
||||
{
|
||||
log << log1 << "std exception: " << e.what() << logend;
|
||||
}
|
||||
catch(const Error & e)
|
||||
{
|
||||
log << log1 << "exception: Error: " << e << logend;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
log << log1 << "uncaught unknown exception" << logend;
|
||||
}
|
||||
|
||||
SaveSessionsIfNeeded();
|
||||
|
||||
// !! this should be immediately after FCGX_Accept() but signals don't want to break FCGX_Accept
|
||||
if( data.signal_hup )
|
||||
{
|
||||
log << logsave;
|
||||
FCGX_Finish();
|
||||
return;
|
||||
}
|
||||
|
||||
request.ClearPostFileTmp();
|
||||
data.load_avg.StopRequest();
|
||||
log << logsave;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
SessionContainer::Iterator RequestController::SessionBegin()
|
||||
{
|
||||
return session_manager.SessionBegin();
|
||||
}
|
||||
|
||||
|
||||
SessionContainer::Iterator RequestController::SessionEnd()
|
||||
{
|
||||
return session_manager.SessionEnd();
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilecmslucorerequestcontroller
|
||||
#define headerfilecmslucorerequestcontroller
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <iostream>
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <errno.h>
|
||||
#include <ctime>
|
||||
|
||||
#include "../content/content.h"
|
||||
#include "sessionmanager.h"
|
||||
#include "functionparser.h"
|
||||
#include "sessioncontainer.h"
|
||||
|
||||
|
||||
class RequestController
|
||||
{
|
||||
Content content;
|
||||
|
||||
|
||||
SessionManager session_manager;
|
||||
|
||||
bool BaseUrlRedirect();
|
||||
|
||||
FunctionParser function_parser;
|
||||
|
||||
public:
|
||||
|
||||
RequestController();
|
||||
~RequestController();
|
||||
|
||||
bool Init();
|
||||
void Close();
|
||||
void Loop();
|
||||
|
||||
void LoadSessions();
|
||||
void SaveSessions();
|
||||
void SaveSessionsIfNeeded(); // saving only once a day
|
||||
void DeleteAllPluginsData();
|
||||
|
||||
SessionContainer::Iterator SessionBegin();
|
||||
SessionContainer::Iterator SessionEnd();
|
||||
|
||||
time_t last_sessions_save;
|
||||
};
|
||||
|
||||
|
||||
extern RequestController req_controller;
|
||||
|
||||
#endif
|
||||
@@ -14,11 +14,8 @@
|
||||
#include "item.h"
|
||||
#include "error.h"
|
||||
#include "user.h"
|
||||
#include "rebus.h"
|
||||
#include "plugindata.h"
|
||||
|
||||
|
||||
|
||||
#include "rebus.h"
|
||||
|
||||
|
||||
struct Session
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
|
||||
#include "sessioncontainer.h"
|
||||
#include "data.h"
|
||||
#include "log.h"
|
||||
|
||||
|
||||
@@ -22,6 +21,12 @@ void SessionContainer::Clear()
|
||||
}
|
||||
|
||||
|
||||
void SessionContainer::SetLastContainer(LastContainer * plast_container)
|
||||
{
|
||||
last_container = plast_container;
|
||||
}
|
||||
|
||||
|
||||
SessionContainer::TableSize SessionContainer::Size()
|
||||
{
|
||||
return table.size();
|
||||
@@ -96,7 +101,7 @@ time_t limit = std::time(0) - interval;
|
||||
continue;
|
||||
|
||||
if( iold->second->puser )
|
||||
data.last.UserLogout(iold->second->puser->id, iold->second->id);
|
||||
last_container->UserLogout(iold->second->puser->id, iold->second->id);
|
||||
|
||||
// we're logging session.id (call this before table.erase())
|
||||
DelFromIdIndex(iold->second);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <ctime>
|
||||
|
||||
#include "session.h"
|
||||
|
||||
#include "lastcontainer.h"
|
||||
|
||||
|
||||
|
||||
@@ -30,8 +30,12 @@ public:
|
||||
typedef std::map<long, Iterator> IndexId;
|
||||
typedef std::multimap<time_t, Iterator> IndexTime;
|
||||
|
||||
void SetLastContainer(LastContainer * plast_container);
|
||||
|
||||
private:
|
||||
|
||||
LastContainer * last_container;
|
||||
|
||||
Table table;
|
||||
IndexId index_id;
|
||||
IndexTime index_time;
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include "sessionmanager.h"
|
||||
#include "request.h"
|
||||
#include "log.h"
|
||||
#include "data.h"
|
||||
#include "session.h"
|
||||
#include "sessionparser.h"
|
||||
#include "plugin.h"
|
||||
@@ -27,6 +26,28 @@ SessionManager::SessionManager()
|
||||
}
|
||||
|
||||
|
||||
void SessionManager::SetRequest(Request * prequest)
|
||||
{
|
||||
request = prequest;
|
||||
}
|
||||
|
||||
|
||||
void SessionManager::SetConfig(Config * pconfig)
|
||||
{
|
||||
config = pconfig;
|
||||
}
|
||||
|
||||
|
||||
void SessionManager::SetSystem(System * psystem)
|
||||
{
|
||||
system = psystem;
|
||||
}
|
||||
|
||||
void SessionManager::SetLastContainer(LastContainer * plast_container)
|
||||
{
|
||||
session_table.SetLastContainer(plast_container);
|
||||
}
|
||||
|
||||
|
||||
bool SessionManager::IsSession(long id)
|
||||
{
|
||||
@@ -79,11 +100,11 @@ void SessionManager::CreateTemporarySession()
|
||||
s.id = 0;
|
||||
|
||||
session_table.PushBack(s);
|
||||
request.session = &session_table.Back();
|
||||
request->session = &session_table.Back();
|
||||
}
|
||||
else
|
||||
{
|
||||
request.session = &(*i);
|
||||
request->session = &(*i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,10 +123,10 @@ int attempts = 100;
|
||||
|
||||
if( added )
|
||||
{
|
||||
request.session = &session_table.Back();
|
||||
request.session->new_session = true;
|
||||
request->session = &session_table.Back();
|
||||
request->session->new_session = true;
|
||||
|
||||
log << log2 << "SM: created a new session: " << request.session->id << logend;
|
||||
log << log2 << "SM: created a new session: " << request->session->id << logend;
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -129,17 +150,17 @@ bool SessionManager::SetSessionFromCookie(const std::string & cookie)
|
||||
return false;
|
||||
|
||||
// that session is in the table
|
||||
request.session = &(*s);
|
||||
request.session->new_session = false;
|
||||
request->session = &(*s);
|
||||
request->session->new_session = false;
|
||||
session_table.UpdateLastTime(s, std::time(0));
|
||||
|
||||
if( request.method == Request::get )
|
||||
request.session->last_time_get = request.session->last_time;
|
||||
if( request->method == Request::get )
|
||||
request->session->last_time_get = request->session->last_time;
|
||||
|
||||
log << log2 << "SM: session: " << s->id;
|
||||
|
||||
if( request.session->puser )
|
||||
log << log2 << ", user: " << request.session->puser->name << ", id: " << request.session->puser->id;
|
||||
if( request->session->puser )
|
||||
log << log2 << ", user: " << request->session->puser->name << ", id: " << request->session->puser->id;
|
||||
|
||||
log << log2 << logend;
|
||||
|
||||
@@ -150,9 +171,9 @@ return true;
|
||||
|
||||
void SessionManager::SetSession()
|
||||
{
|
||||
CookieTable::iterator i = request.cookie_table.find(data.http_session_id_name);
|
||||
CookieTable::iterator i = request->cookie_table.find(config->http_session_id_name);
|
||||
|
||||
if( i == request.cookie_table.end() )
|
||||
if( i == request->cookie_table.end() )
|
||||
{
|
||||
CreateSession();
|
||||
}
|
||||
@@ -162,18 +183,18 @@ void SessionManager::SetSession()
|
||||
{
|
||||
// there is no such a session
|
||||
// deleting the old cookie
|
||||
request.cookie_table.erase(i);
|
||||
request->cookie_table.erase(i);
|
||||
|
||||
// and creating a new one
|
||||
CreateSession();
|
||||
}
|
||||
}
|
||||
|
||||
// request.session is set now
|
||||
// request->session is set now
|
||||
|
||||
if( request.session->new_session )
|
||||
if( request->session->new_session )
|
||||
{
|
||||
request.session->plugin_data.Resize(plugin.Size());
|
||||
request->session->plugin_data.Resize(plugin.Size());
|
||||
plugin.Call(WINIX_SESSION_CREATED);
|
||||
}
|
||||
|
||||
@@ -199,7 +220,7 @@ SessionContainer::Iterator SessionManager::SessionEnd()
|
||||
|
||||
void SessionManager::DeleteOldSessions()
|
||||
{
|
||||
session_table.DelFirstByTimeInterval(data.session_max_idle);
|
||||
session_table.DelFirstByTimeInterval(config->session_max_idle);
|
||||
|
||||
if( ++session_checker > 1000 )
|
||||
{
|
||||
@@ -207,7 +228,7 @@ void SessionManager::DeleteOldSessions()
|
||||
log << log3 << "SM: checking sessions which have 'remember me' flag set" << logend;
|
||||
|
||||
session_checker = 0;
|
||||
session_table.DelFirstByTimeInterval(data.session_remember_max_idle, false);
|
||||
session_table.DelFirstByTimeInterval(config->session_remember_max_idle, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,15 +238,15 @@ void SessionManager::DeleteAllPluginsData()
|
||||
{
|
||||
SessionContainer::Iterator i = session_table.Begin();
|
||||
|
||||
Session * old_session = request.session;
|
||||
Session * old_session = request->session;
|
||||
|
||||
for( ; i!=session_table.End() ; ++i )
|
||||
{
|
||||
request.session = &(*i);
|
||||
request->session = &(*i);
|
||||
i->plugin_data.DeleteAll();
|
||||
}
|
||||
|
||||
request.session = old_session;
|
||||
request->session = old_session;
|
||||
}
|
||||
|
||||
|
||||
@@ -237,19 +258,20 @@ void SessionManager::LoadSessions()
|
||||
SessionParser sp;
|
||||
SessionContainer::Iterator i;
|
||||
|
||||
Session * old_session = request.session;
|
||||
sp.SetUsers(&system->users);
|
||||
Session * old_session = request->session;
|
||||
|
||||
sp.Parse(data.session_file, session_table);
|
||||
sp.Parse(config->session_file, session_table);
|
||||
i = session_table.Begin();
|
||||
|
||||
for( ; i!=session_table.End() ; ++i )
|
||||
{
|
||||
i->plugin_data.Resize(plugin.Size());
|
||||
request.session = &(*i);
|
||||
request->session = &(*i);
|
||||
plugin.Call(WINIX_SESSION_CREATED);
|
||||
}
|
||||
|
||||
request.session = old_session;
|
||||
request->session = old_session;
|
||||
}
|
||||
|
||||
|
||||
@@ -258,10 +280,10 @@ SessionContainer::Iterator i;
|
||||
|
||||
void SessionManager::SaveSessions()
|
||||
{
|
||||
if( data.session_file.empty() )
|
||||
if( config->session_file.empty() )
|
||||
return;
|
||||
|
||||
std::ofstream file(data.session_file.c_str());
|
||||
std::ofstream file(config->session_file.c_str());
|
||||
|
||||
if( !file )
|
||||
{
|
||||
@@ -286,7 +308,7 @@ void SessionManager::SaveSessions()
|
||||
}
|
||||
|
||||
file.close();
|
||||
chmod(data.session_file.c_str(), 0600);
|
||||
chmod(config->session_file.c_str(), 0600);
|
||||
|
||||
log << log2 << "SM: saved " << len << " session(s)" << logend;
|
||||
}
|
||||
|
||||
@@ -14,15 +14,21 @@
|
||||
#include <ctime>
|
||||
|
||||
#include "sessioncontainer.h"
|
||||
#include "config.h"
|
||||
#include "request.h"
|
||||
#include "lastcontainer.h"
|
||||
#include "system.h"
|
||||
|
||||
|
||||
|
||||
class SessionManager
|
||||
{
|
||||
Config * config;
|
||||
Request * request;
|
||||
System * system;
|
||||
|
||||
SessionContainer session_table;
|
||||
|
||||
|
||||
|
||||
bool IsSession(long s);
|
||||
|
||||
long CreateSessionId();
|
||||
@@ -34,6 +40,12 @@ class SessionManager
|
||||
public:
|
||||
|
||||
SessionManager();
|
||||
|
||||
void SetRequest(Request * prequest);
|
||||
void SetConfig(Config * pconfig);
|
||||
void SetSystem(System * psystem);
|
||||
void SetLastContainer(LastContainer * plast_container);
|
||||
|
||||
void SetSession();
|
||||
void DeleteAllPluginsData();
|
||||
void DeleteOldSessions();
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "sessionparser.h"
|
||||
#include "log.h"
|
||||
#include "data.h"
|
||||
|
||||
|
||||
|
||||
bool SessionParser::Parse(const std::string & path, SessionContainer & container)
|
||||
@@ -18,6 +18,12 @@ bool SessionParser::Parse(const std::string & path, SessionContainer & container
|
||||
}
|
||||
|
||||
|
||||
void SessionParser::SetUsers(Users * pusers)
|
||||
{
|
||||
users = pusers;
|
||||
}
|
||||
|
||||
|
||||
bool SessionParser::Parse(const char * path, SessionContainer & container)
|
||||
{
|
||||
container.Clear();
|
||||
@@ -66,7 +72,7 @@ bool SessionParser::Parse(SessionContainer & container)
|
||||
|
||||
if( MakeSession(user_id) )
|
||||
{
|
||||
data.how_many_logged += 1;
|
||||
users->IncrementLoggedUsers();
|
||||
container.PushBack(session);
|
||||
log << log2 << "SP: read session id: " << session.id << " for user: " << session.puser->name << logend;
|
||||
}
|
||||
@@ -82,7 +88,7 @@ return true;
|
||||
|
||||
bool SessionParser::MakeSession(long user_id)
|
||||
{
|
||||
User * puser = data.users.GetUser(user_id);
|
||||
User * puser = users->GetUser(user_id);
|
||||
|
||||
if( !puser )
|
||||
{
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
#include <string>
|
||||
#include "session.h"
|
||||
#include "sessioncontainer.h"
|
||||
#include "users.h"
|
||||
|
||||
|
||||
|
||||
class SessionParser
|
||||
{
|
||||
@@ -21,9 +24,11 @@ public:
|
||||
|
||||
bool Parse(const char * path, SessionContainer & container);
|
||||
bool Parse(const std::string & path, SessionContainer & container);
|
||||
|
||||
void SetUsers(Users * pusers);
|
||||
|
||||
private:
|
||||
|
||||
Users * users;
|
||||
|
||||
bool Parse(SessionContainer & container);
|
||||
bool MakeSession(long user_id);
|
||||
|
||||
589
core/system.cpp
Executable file
589
core/system.cpp
Executable file
@@ -0,0 +1,589 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
#include "misc.h"
|
||||
#include "error.h"
|
||||
#include "notify.h"
|
||||
#include "functions/functions.h"
|
||||
#include "templates/templates.h"
|
||||
|
||||
|
||||
|
||||
void System::SetRequest(Request * prequest)
|
||||
{
|
||||
request = prequest;
|
||||
}
|
||||
|
||||
|
||||
void System::SetConfig(Config * pconfig)
|
||||
{
|
||||
config = pconfig;
|
||||
}
|
||||
|
||||
|
||||
void System::SetDb(Db * pdb)
|
||||
{
|
||||
db = pdb;
|
||||
}
|
||||
|
||||
|
||||
void System::SetFunctions(Functions * pfunctions)
|
||||
{
|
||||
functions = pfunctions;
|
||||
}
|
||||
|
||||
|
||||
void System::SetTemplates(Templates * ptemplates)
|
||||
{
|
||||
templates = ptemplates;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void System::Init()
|
||||
{
|
||||
dirs.SetDb(db);
|
||||
dirs.SetRequest(request);
|
||||
|
||||
dirs.ReadDirs();
|
||||
|
||||
mounts.SetDirs(&dirs);
|
||||
mounts.SetDb(db);
|
||||
mounts.SetRequest(request);
|
||||
mounts.ReadMounts();
|
||||
|
||||
users.SetRequest(request);
|
||||
users.ReadUsers(db);
|
||||
groups.ReadGroups(db); // !! chwilowe przekazanie argumentu, db bedzie zmienione
|
||||
|
||||
rebus.SetRequest(request);
|
||||
rebus.Init();
|
||||
}
|
||||
|
||||
|
||||
// !! mozna zrobic jakas obsluge kiedy nie mozemy sie redirectnac, np gdy wystapil blad
|
||||
// !! moze zwracac jakas wartosc?
|
||||
void System::RedirectTo(const Item & item, const char * postfix)
|
||||
{
|
||||
request->redirect_to = config->base_url;
|
||||
|
||||
if( item.type == Item::dir )
|
||||
{
|
||||
// item_id is pointing to a directory
|
||||
dirs.MakePath(item.id, path);
|
||||
request->redirect_to += path;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !dirs.MakePath(item.parent_id, path) )
|
||||
log << log1 << "Content: Can't redirect: no dirs for item id: " << item.id << logend;
|
||||
|
||||
request->redirect_to += path;
|
||||
request->redirect_to += item.url;
|
||||
}
|
||||
|
||||
if( postfix )
|
||||
request->redirect_to += postfix;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void System::RedirectTo(long item_id, const char * postfix)
|
||||
{
|
||||
std::string path;
|
||||
Item * pdir;
|
||||
|
||||
request->redirect_to = config->base_url;
|
||||
pdir = dirs.GetDir(item_id);
|
||||
|
||||
|
||||
if( pdir )
|
||||
{
|
||||
// item_id is pointing to a directory
|
||||
dirs.MakePath(pdir->id, path);
|
||||
request->redirect_to += path;
|
||||
}
|
||||
else
|
||||
{
|
||||
// !! zrobic nowy interfejs
|
||||
// !! GetItem pozamieniac na GetFile
|
||||
// !! i nie uzywac request->item_table (zrobic sobie lokalny tutaj)
|
||||
db->GetItem(request->item_table, item_id);
|
||||
|
||||
if( !request->item_table.empty() )
|
||||
{
|
||||
if( !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->redirect_to += path + request->item_table[0].url;
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Content: Can't redirect: no such item: id: " << item_id << logend;
|
||||
}
|
||||
}
|
||||
|
||||
if( postfix )
|
||||
request->redirect_to += postfix;
|
||||
}
|
||||
|
||||
|
||||
void System::RedirectToLastDir()
|
||||
{
|
||||
// !! dac sprawdzenie czy istnieje
|
||||
RedirectTo( *request->dir_table.back() );
|
||||
}
|
||||
|
||||
|
||||
void System::RedirectToLastItem()
|
||||
{
|
||||
if( request->is_item )
|
||||
RedirectTo(request->item);
|
||||
else
|
||||
RedirectTo( *request->dir_table.back() );// !! dac sprawdzenie czy istnieje
|
||||
}
|
||||
|
||||
|
||||
void System::PrepareUrl(Item & item)
|
||||
{
|
||||
TrimWhite(item.url);
|
||||
|
||||
if( item.url.empty() )
|
||||
item.url = item.subject; // if the subject is empty then the url will be corrected by CorrectUrlOnlyAllowedChar()
|
||||
|
||||
CorrectUrlOnlyAllowedChar(item.url);
|
||||
|
||||
if( functions->Find(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(), '_');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool System::CanChangeUser(const Item & item, long new_user_id)
|
||||
{
|
||||
if( !request->session )
|
||||
// session must be set
|
||||
return false;
|
||||
|
||||
if( request->session->puser && request->session->puser->super_user )
|
||||
// super user is allowed everything
|
||||
return true;
|
||||
|
||||
if( item.user_id != new_user_id )
|
||||
// only super user can change the owner of an item
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool System::CanChangeGroup(const Item & item, long new_group_id)
|
||||
{
|
||||
if( !request->session )
|
||||
// session must be set
|
||||
return false;
|
||||
|
||||
if( request->session->puser && request->session->puser->super_user )
|
||||
// super user is allowed everything
|
||||
return true;
|
||||
|
||||
if( item.group_id != new_group_id )
|
||||
{
|
||||
// user is allowed to change the group only if he is an owner of the item
|
||||
// he can change only into a group in which he is a member of, or into a 'no_group'
|
||||
|
||||
if( !request->session->puser )
|
||||
return false;
|
||||
|
||||
if( request->session->puser->id != item.user_id )
|
||||
return false;
|
||||
|
||||
if( new_group_id == -1 )
|
||||
return true;
|
||||
|
||||
if( !request->session->puser->IsMemberOf(new_group_id) )
|
||||
return false;
|
||||
|
||||
// is logged, is the owner of the item, is the member of the new group
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool System::CanChangePrivileges(const Item & item, int new_priv)
|
||||
{
|
||||
if( !request->session )
|
||||
// session must be set
|
||||
return false;
|
||||
|
||||
if( request->session->puser && request->session->puser->super_user )
|
||||
// super user is allowed everything
|
||||
return true;
|
||||
|
||||
if( item.privileges != new_priv )
|
||||
{
|
||||
// the owner of an item is allowed to change the privileges
|
||||
|
||||
if( !request->session->puser )
|
||||
return false;
|
||||
|
||||
if( request->session->puser->id != item.user_id )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool System::HasAccess(const Item & item, int mask)
|
||||
{
|
||||
if( !request->session )
|
||||
// session must be set
|
||||
return false;
|
||||
|
||||
if( request->session->puser && request->session->puser->super_user )
|
||||
// super user is allowed everything
|
||||
return true;
|
||||
|
||||
if( request->session->puser && request->session->puser->id == item.user_id )
|
||||
{
|
||||
// the owner
|
||||
return ((item.privileges >> 6) & mask) == mask;
|
||||
}
|
||||
|
||||
if( request->session->puser && request->session->puser->IsMemberOf(item.group_id) )
|
||||
{
|
||||
// group
|
||||
return ((item.privileges >> 3) & mask) == mask;
|
||||
}
|
||||
|
||||
// others
|
||||
|
||||
return (item.privileges & mask) == mask;
|
||||
}
|
||||
|
||||
|
||||
bool System::HasReadAccess(const Item & item)
|
||||
{
|
||||
return HasAccess(item, 4);
|
||||
}
|
||||
|
||||
|
||||
bool System::HasWriteAccess(const Item & item)
|
||||
{
|
||||
return HasAccess(item, 2);
|
||||
}
|
||||
|
||||
|
||||
bool System::HasReadWriteAccess(const Item & item)
|
||||
{
|
||||
return HasAccess(item, 6); // r+w
|
||||
}
|
||||
|
||||
|
||||
bool System::HasReadExecAccess(const Item & item)
|
||||
{
|
||||
if( request->session && request->session->puser && request->session->puser->super_user )
|
||||
{
|
||||
// there must be at least one 'x' (for the root)
|
||||
|
||||
return (item.privileges & 0111) != 0;
|
||||
}
|
||||
|
||||
return HasAccess(item, 5); // r+x
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool System::HasReadExecAccessToPath(long dir_id)
|
||||
{
|
||||
while( true )
|
||||
{
|
||||
Item * pdir = dirs.GetDir(dir_id);
|
||||
|
||||
if( !pdir )
|
||||
return false;
|
||||
|
||||
if( !HasReadExecAccess(*pdir) )
|
||||
return false;
|
||||
|
||||
dir_id = pdir->parent_id;
|
||||
|
||||
if( dir_id == -1 )
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool System::DirsHaveReadExecPerm()
|
||||
{
|
||||
std::vector<Item*>::iterator i;
|
||||
|
||||
for(i = request->dir_table.begin() ; i!=request->dir_table.end() ; ++i)
|
||||
{
|
||||
if( !HasReadExecAccess(**i) )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// if we don't have access we only remove the item from the table
|
||||
void System::CheckAccessToItems(std::vector<Item> & item_table)
|
||||
{
|
||||
size_t i = 0;
|
||||
|
||||
while( i < item_table.size() )
|
||||
{
|
||||
if( !HasReadAccess(item_table[i]) )
|
||||
{
|
||||
item_table.erase(item_table.begin() + i);
|
||||
}
|
||||
else
|
||||
{
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool System::CanUseHtml(long user_id)
|
||||
{
|
||||
return IsMemberOfGroup(user_id, "allow_html");
|
||||
}
|
||||
|
||||
|
||||
bool System::CanUseBBCode(long user_id)
|
||||
{
|
||||
// logged users can use bbcode
|
||||
return (user_id != -1);
|
||||
}
|
||||
|
||||
|
||||
bool System::CanUseRaw(long user_id)
|
||||
{
|
||||
return IsMemberOfGroup(user_id, "allow_raw");
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool System::IsMemberOfGroup(long user_id, const char * group_name)
|
||||
{
|
||||
User * puser = users.GetUser(user_id);
|
||||
|
||||
if( !puser )
|
||||
return false;
|
||||
|
||||
if( puser->super_user )
|
||||
return true;
|
||||
|
||||
long group = groups.GetGroupId(group_name);
|
||||
|
||||
if( group == -1 )
|
||||
// there is no such a group
|
||||
return false;
|
||||
|
||||
if( puser->IsMemberOf(group) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool System::MakePathSimpleFs(std::string & path, long dir_id, bool create_dir)
|
||||
{
|
||||
if( config->auth_simplefs_dir.empty() )
|
||||
{
|
||||
log << log1 << "System: auth_simplefs_dir is not set in the config file" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !dirs.MakePath(dir_id, path) )
|
||||
return false;
|
||||
|
||||
if( create_dir && !CreateDirs(config->auth_simplefs_dir, path, 0755) )
|
||||
return false;
|
||||
|
||||
path.insert(0, config->auth_simplefs_dir);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// the path depends on id
|
||||
bool System::MakePathHashFs(std::string & path, long id, bool create_dir)
|
||||
{
|
||||
char buffer[50];
|
||||
char * hash = buffer;
|
||||
|
||||
// get 'id' as hexadecimal
|
||||
buffer[0] = '0';
|
||||
sprintf(buffer+1, "%lx", (unsigned long)id);
|
||||
|
||||
path = config->auth_hashfs_dir;
|
||||
if( path.empty() )
|
||||
{
|
||||
log << log1 << "System: auth_hashfs_dir is not set in the config file" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
path += '/';
|
||||
|
||||
// make sure that the length is even
|
||||
if( (strlen(hash) & 1) != 0 )
|
||||
hash = buffer + 1; // the first character was zero
|
||||
|
||||
// creating dirs without the last part
|
||||
// the last part is a part of a file
|
||||
for(size_t i=0 ; hash[i] != 0 ; i+=2)
|
||||
{
|
||||
path += hash[i];
|
||||
path += hash[i+1];
|
||||
|
||||
if( hash[i+2] != 0 )
|
||||
{
|
||||
if( create_dir && !CreateDir(path, 0755) )
|
||||
return false;
|
||||
|
||||
path += '/';
|
||||
}
|
||||
}
|
||||
|
||||
// one character more to make sure the path is unique
|
||||
// (we can have a directory without the character)
|
||||
path += "_";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// making a complete path to a static file
|
||||
bool System::MakePath(const Item & item, std::string & path, bool create_dir)
|
||||
{
|
||||
bool res;
|
||||
|
||||
Mount * pmount = mounts.CalcMount(item.parent_id);
|
||||
|
||||
if( !pmount || pmount->fs == Mount::simplefs )
|
||||
{
|
||||
res = MakePathSimpleFs(path, item.parent_id, create_dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
res = MakePathHashFs(path, item.id, create_dir);
|
||||
}
|
||||
|
||||
if( res )
|
||||
path += item.url;
|
||||
else
|
||||
path.clear();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool System::MakePath(Item & item, bool create_dir)
|
||||
{
|
||||
return MakePath(item, item.auth_path, create_dir);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Error System::AddFile(Item & item)
|
||||
{
|
||||
if( item.type == Item::dir )
|
||||
return WINIX_ERR_FILE_EXPECTED;
|
||||
|
||||
Error status = db->AddItem(item);
|
||||
|
||||
if( status == WINIX_ERR_OK )
|
||||
{
|
||||
log << log2 << "System: added a new file, url: " << item.url << ", id: " << item.id
|
||||
<< ", parent_id: " << item.parent_id << logend;
|
||||
|
||||
request->notify_code |= WINIX_NOTIFY_ITEM_ADD;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Error System::EditFile(Item & item, bool with_url)
|
||||
{
|
||||
if( item.type == Item::dir )
|
||||
return WINIX_ERR_FILE_EXPECTED;
|
||||
|
||||
if( request->session && request->session->puser )
|
||||
request->item.modification_user_id = request->session->puser->id;
|
||||
else
|
||||
request->item.modification_user_id = -1;
|
||||
|
||||
item.SetDateModifyToNow();
|
||||
Error status = db->EditItemById(item, with_url);
|
||||
|
||||
if( status == WINIX_ERR_OK )
|
||||
{
|
||||
TemplatesFunctions::pattern_cacher.UpdatePattern(item);
|
||||
log << log2 << "System: modified an item" << logend;
|
||||
|
||||
request->notify_code |= WINIX_NOTIFY_ITEM_EDIT;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Error System::CheckSpecialFile(const Item & item)
|
||||
{
|
||||
static std::string fstab = "fstab";
|
||||
|
||||
Item * etc = dirs.GetEtcDir();
|
||||
|
||||
if( !etc )
|
||||
return WINIX_NOTHING_TO_DO;
|
||||
|
||||
if( item.parent_id != etc->id )
|
||||
return WINIX_NOTHING_TO_DO;
|
||||
|
||||
if( item.url == fstab )
|
||||
{
|
||||
log << log3 << "System: reloading mount points" << logend;
|
||||
|
||||
Error status = mounts.ReadMounts(item.content);
|
||||
templates->ReadNewIndexTemplates();
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
return WINIX_NOTHING_TO_DO;
|
||||
}
|
||||
111
core/system.h
Executable file
111
core/system.h
Executable file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilecmslucorefs
|
||||
#define headerfilecmslucorefs
|
||||
|
||||
|
||||
#include "dirs.h"
|
||||
#include "mounts.h"
|
||||
#include "db.h"
|
||||
#include "request.h"
|
||||
#include "config.h"
|
||||
#include "users.h"
|
||||
#include "groups.h"
|
||||
#include "rebus.h"
|
||||
#include "loadavg.h"
|
||||
|
||||
|
||||
class Functions;
|
||||
class Templates;
|
||||
|
||||
|
||||
// file system
|
||||
class System
|
||||
{
|
||||
public:
|
||||
|
||||
// contains current directories tree
|
||||
Dirs dirs;
|
||||
|
||||
// mount points
|
||||
Mounts mounts;
|
||||
|
||||
// users
|
||||
Users users;
|
||||
|
||||
// groups
|
||||
Groups groups;
|
||||
|
||||
// rebus (captcha)
|
||||
Rebus rebus;
|
||||
|
||||
// load averages
|
||||
LoadAvg load_avg;
|
||||
|
||||
// the time when the winix starts
|
||||
time_t system_start;
|
||||
|
||||
|
||||
void SetRequest(Request * prequest);
|
||||
void SetConfig(Config * pconfig);
|
||||
void SetDb(Db * pdb);
|
||||
void SetFunctions(Functions * pfunctions);
|
||||
void SetTemplates(Templates * ptemplates);
|
||||
void Init();
|
||||
|
||||
void RedirectTo(const Item & item, const char * postfix = 0);
|
||||
void RedirectTo(long item_id, const char * postfix = 0);
|
||||
void RedirectToLastDir();
|
||||
void RedirectToLastItem(); // redirect to an item if exists or to the last directory
|
||||
|
||||
void PrepareUrl(Item & item);
|
||||
|
||||
bool CanChangeUser(const Item & item, long new_user_id);
|
||||
bool CanChangeGroup(const Item & item, long new_group_id);
|
||||
bool CanChangePrivileges(const Item & item, int new_priv);
|
||||
bool HasAccess(const Item & item, int mask);
|
||||
bool HasReadAccess(const Item & item);
|
||||
bool HasWriteAccess(const Item & item);
|
||||
bool HasReadWriteAccess(const Item & item);
|
||||
bool HasReadExecAccess(const Item & item);
|
||||
bool HasReadExecAccessToPath(long dir_id);
|
||||
bool DirsHaveReadExecPerm();
|
||||
void CheckAccessToItems(std::vector<Item> & item_table);
|
||||
|
||||
bool CanUseHtml(long user_id);
|
||||
bool CanUseBBCode(long user_id);
|
||||
bool CanUseRaw(long user_id);
|
||||
|
||||
bool IsMemberOfGroup(long user_id, const char * group_name);
|
||||
|
||||
bool MakePath(const Item & item, std::string & path, bool create_dir);
|
||||
bool MakePath(Item & item, bool create_dir); // output path is: item.auth_path
|
||||
|
||||
Error AddFile(Item & item);
|
||||
Error EditFile(Item & item, bool with_url = true);
|
||||
|
||||
Error CheckSpecialFile(const Item & item);
|
||||
|
||||
private:
|
||||
Request * request;
|
||||
Config * config;
|
||||
Db * db;
|
||||
Functions * functions;
|
||||
Templates * templates;
|
||||
|
||||
std::string path;
|
||||
bool MakePathSimpleFs(std::string & path, long dir_id, bool create_dir);
|
||||
bool MakePathHashFs(std::string & path, long id, bool create_dir);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -31,12 +31,16 @@ public:
|
||||
// at the moment only used: id, date_modification, user_id
|
||||
Item last_item;
|
||||
|
||||
// used when sorting
|
||||
long sort;
|
||||
|
||||
void Clear()
|
||||
{
|
||||
id = parent_id = dir_id = -1;
|
||||
last_item.Clear();
|
||||
closed = false;
|
||||
items = 0;
|
||||
sort = 0;
|
||||
}
|
||||
|
||||
Thread()
|
||||
|
||||
@@ -7,17 +7,23 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include "users.h"
|
||||
#include "db.h"
|
||||
|
||||
|
||||
|
||||
Users::Users()
|
||||
{
|
||||
how_many_logged = 0;
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
void Users::SetRequest(Request * prequest)
|
||||
{
|
||||
request = prequest;
|
||||
}
|
||||
|
||||
|
||||
void Users::Clear()
|
||||
{
|
||||
@@ -26,11 +32,10 @@ void Users::Clear()
|
||||
|
||||
|
||||
|
||||
void Users::ReadUsers()
|
||||
void Users::ReadUsers(Db * db)
|
||||
{
|
||||
Clear();
|
||||
|
||||
db.GetUsers(table);
|
||||
db->GetUsers(table);
|
||||
}
|
||||
|
||||
|
||||
@@ -110,13 +115,59 @@ User & Users::operator[](Users::SizeType pos)
|
||||
}
|
||||
|
||||
|
||||
void Users::LoginUser(long user_id, bool remember_me)
|
||||
{
|
||||
if( !request->session )
|
||||
return;
|
||||
|
||||
request->session->puser = GetUser(user_id);
|
||||
request->session->spam_score = 0;
|
||||
|
||||
if( !request->session->puser )
|
||||
{
|
||||
log << log1 << "Users: user id: " << user_id << " is not in system.users table" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
request->session->remember_me = remember_me;
|
||||
|
||||
last.UserLogin(user_id, request->session->puser->name, inet_addr(request->env_remote_addr), request->session->id);
|
||||
how_many_logged += 1;
|
||||
|
||||
log << log2 << "User " << request->session->puser->name << " (id: " << user_id << ") logged" << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Users::LogoutCurrentUser()
|
||||
{
|
||||
if( !request->session || !request->session->puser )
|
||||
return;
|
||||
|
||||
log << log2 << "Users: user " << request->session->puser->name << ", id: "
|
||||
<< request->session->puser->id << " logged out" << logend;
|
||||
|
||||
last.UserLogout(request->session->puser->id, request->session->id);
|
||||
|
||||
if( how_many_logged > 0 ) // for safety
|
||||
how_many_logged -= 1;
|
||||
|
||||
request->session->puser = 0;
|
||||
request->session->remember_me = 0;
|
||||
}
|
||||
|
||||
|
||||
void Users::IncrementLoggedUsers()
|
||||
{
|
||||
how_many_logged += 1;
|
||||
}
|
||||
|
||||
|
||||
long Users::HowManyLogged()
|
||||
{
|
||||
return how_many_logged;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
20
core/users.h
20
core/users.h
@@ -13,26 +13,32 @@
|
||||
#include <map>
|
||||
#include "user.h"
|
||||
#include "ugcontainer.h"
|
||||
|
||||
|
||||
#include "lastcontainer.h"
|
||||
#include "request.h"
|
||||
#include "db.h"
|
||||
|
||||
|
||||
class Users
|
||||
{
|
||||
|
||||
typedef UGContainer<User> Table;
|
||||
Table table;
|
||||
|
||||
Request * request;
|
||||
long how_many_logged;
|
||||
|
||||
public:
|
||||
|
||||
typedef Table::Iterator Iterator;
|
||||
typedef Table::SizeType SizeType;
|
||||
|
||||
LastContainer last;
|
||||
|
||||
Users();
|
||||
|
||||
void SetRequest(Request * request);
|
||||
|
||||
void Clear();
|
||||
void ReadUsers();
|
||||
void ReadUsers(Db * db);
|
||||
bool AddUser(const User & user);
|
||||
bool IsUser(const std::string & name);
|
||||
User * GetUser(long user_id);
|
||||
@@ -42,6 +48,12 @@ public:
|
||||
Iterator End();
|
||||
SizeType Size();
|
||||
User & operator[](SizeType pos);
|
||||
|
||||
void LoginUser(long user_id, bool remember_me);
|
||||
void LogoutCurrentUser();
|
||||
|
||||
void IncrementLoggedUsers();
|
||||
long HowManyLogged();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
|
||||
|
||||
#define WINIX_VER_MAJOR 0
|
||||
#define WINIX_VER_MINOR 3
|
||||
#define WINIX_VER_REVISION 3
|
||||
#define WINIX_VER_MINOR 4
|
||||
#define WINIX_VER_REVISION 0
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user