diff --git a/content/Makefile.dep b/content/Makefile.dep index 0d4b13a..2431f51 100755 --- a/content/Makefile.dep +++ b/content/Makefile.dep @@ -107,6 +107,13 @@ priv.o: ../core/error.h ../core/db.h ../core/group.h ../core/dircontainer.h priv.o: ../core/ugcontainer.h ../core/data.h ../core/dirs.h ../core/users.h priv.o: ../core/groups.h ../core/functions.h ../core/lastcontainer.h priv.o: ../core/mounts.h ../core/mount.h +reload.o: content.h ../core/item.h ../templates/templates.h +reload.o: ../templates/patterncacher.h ../core/thread.h ../core/request.h +reload.o: ../core/requesttypes.h ../core/session.h ../core/done.h +reload.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h +reload.o: ../core/function.h ../core/thread.h ../core/compress.h +reload.o: ../core/acceptencodingparser.h ../core/acceptbaseparser.h +reload.o: ../core/error.h rm.o: content.h ../core/item.h ../templates/templates.h rm.o: ../templates/patterncacher.h ../core/thread.h ../core/request.h rm.o: ../core/requesttypes.h ../core/session.h ../core/done.h ../core/item.h diff --git a/content/Makefile.o.dep b/content/Makefile.o.dep index 536c090..14e119f 100755 --- a/content/Makefile.o.dep +++ b/content/Makefile.o.dep @@ -1 +1 @@ -o = cat.o content.o createthread.o default.o emacs.o last.o login.o logout.o ls.o mkdir.o node.o priv.o rm.o run.o thread.o who.o +o = cat.o content.o createthread.o default.o emacs.o last.o login.o logout.o ls.o mkdir.o node.o priv.o reload.o rm.o run.o thread.o who.o diff --git a/content/content.cpp b/content/content.cpp index 25924d5..d714d75 100755 --- a/content/content.cpp +++ b/content/content.cpp @@ -19,8 +19,8 @@ bool Content::Init() { - templates.Read(); - + templates.ReadTemplates(); + templates.CreateFunctions(); return true; } @@ -160,6 +160,9 @@ void Content::MakeStandardFunction() if( request.pfunction->code == FUN_THREAD ) FunThread(); else + if( request.pfunction->code == FUN_RELOAD ) + FunReload(); + else if( request.pfunction->code == FUN_CREATETHREAD ) FunCreateThread(); else diff --git a/content/content.h b/content/content.h index 9abed65..525b04b 100755 --- a/content/content.h +++ b/content/content.h @@ -56,7 +56,10 @@ class Content void FunRun(); void FunWho(); void FunLast(); - + + void FunReloadTemplates(); + void FunReload(); + static bool FunThreadSort(const Thread & t1, const Thread & t2); void FunThread(); void FunCreateThread(); diff --git a/content/reload.cpp b/content/reload.cpp new file mode 100755 index 0000000..8af3333 --- /dev/null +++ b/content/reload.cpp @@ -0,0 +1,45 @@ +/* + * This file is a part of CMSLU -- Content Management System like Unix + * and is not publicly distributed + * + * Copyright (c) 2008-2009, Tomasz Sowa + * All rights reserved. + * + */ + +#include "content.h" +#include "../core/request.h" +#include "../core/error.h" + + +void Content::FunReloadTemplates() +{ + log << log1 << "Content: reloading html templates" << logend; + templates.ReadTemplates(); + + request.session->done = Done::reloaded_templates; + request.session->done_status = Error::ok; + request.session->done_timer = 1; +} + + + + +void Content::FunReload() +{ + // !! temporarily only an admin has access + + if( !request.session->puser || !request.session->puser->super_user ) + { + log << log1 << "Content: Only an admin has access to reload function" << logend; + request.status = Error::permision_denied; + return; + } + + if( request.IsParam("templates") ) + FunReloadTemplates(); +} + + + + diff --git a/core/dircontainer.cpp b/core/dircontainer.cpp index 43c80e0..283d4c7 100755 --- a/core/dircontainer.cpp +++ b/core/dircontainer.cpp @@ -11,6 +11,9 @@ #include "log.h" +std::string DirContainer::dir_etc = "etc"; + + DirContainer::DirContainer() { is_root = false; @@ -62,10 +65,9 @@ bool DirContainer::Empty() // looking for '/etc' // 'root' is found beforehand +// CheckSpecialFolder() may not find everything (when the first is a special folder and then the root) void DirContainer::FindSpecialFolders() { -static std::string etc = "etc"; - is_etc = false; if( !is_root ) @@ -75,7 +77,7 @@ static std::string etc = "etc"; for( ; i!=ParentEnd() ; i = NextParent(i) ) { - if( i->second->url == etc ) + if( i->second->url == dir_etc ) { is_etc = true; etc_iter = i->second; @@ -85,6 +87,27 @@ static std::string etc = "etc"; } +// this is used with PushBack() method +void DirContainer::CheckSpecialFolder(const Item & item, Iterator iter) +{ + if( item.parent_id == -1 ) + { + is_root = true; + root_iter = iter; + } + + if( !is_root ) + return; + + if( item.parent_id==root_iter->id && item.url==dir_etc ) + { + is_etc = true; + etc_iter = iter; + log << log1 << "DirCont: added special folder: /etc" << logend; + } +} + + DirContainer::Iterator DirContainer::PushBack(const Item & item) { if( item.parent_id == -1 && is_root ) @@ -94,12 +117,7 @@ DirContainer::Iterator DirContainer::PushBack(const Item & item) } Iterator last_iter = table.insert(table.end(), item); - - if( item.parent_id == -1 ) - { - is_root = true; - root_iter = last_iter; - } + CheckSpecialFolder(item, last_iter); log << log2 << "DirCont: added dir, url: " << item.url << ", id: " << item.id << ", parent_id: " << item.parent_id << logend; diff --git a/core/dircontainer.h b/core/dircontainer.h index ee676ee..94cffe7 100755 --- a/core/dircontainer.h +++ b/core/dircontainer.h @@ -57,6 +57,8 @@ public: private: + void CheckSpecialFolder(const Item & item, Iterator iter); + // main table with dirs Table table; @@ -75,6 +77,9 @@ private: // indexes TableId table_id; TableParent table_parent; + + // names of folders + static std::string dir_etc; }; diff --git a/core/done.h b/core/done.h index 3185b46..12e24c9 100755 --- a/core/done.h +++ b/core/done.h @@ -28,6 +28,7 @@ public: added_dir, added_thread, defaulted_dir, + reloaded_templates, loggedout }; diff --git a/core/function.h b/core/function.h index 1d2e835..8b808b3 100755 --- a/core/function.h +++ b/core/function.h @@ -30,6 +30,7 @@ #define FUN_LAST 13 #define FUN_CREATETHREAD 14 #define FUN_THREAD 15 +#define FUN_RELOAD 16 diff --git a/core/functions.cpp b/core/functions.cpp index eb406ab..016177d 100755 --- a/core/functions.cpp +++ b/core/functions.cpp @@ -30,7 +30,7 @@ void Functions::ReadFunctions() f.item.user_id = -1; f.item.group_id = -1; - f.item.privileges = 0644; + f.item.privileges = 0755; f.item.parent_id = -1; // !! temporarily doesn't matter f.item.id = -1; f.item.type = Item::file; @@ -96,9 +96,14 @@ void Functions::ReadFunctions() f.item.url = "thread"; table.insert( std::make_pair(f.item.url, f) ); -// ----------- -// FunctionCodeParser fc; -// fc.Parse(Item()); // temporary for linking + + // functions which need more privileges + + f.code = FUN_RELOAD; + f.item.url = "reload"; + f.item.privileges = 0700; + table.insert( std::make_pair(f.item.url, f) ); + } diff --git a/templates/done.cpp b/templates/done.cpp index a9d97b7..24c5c5a 100755 --- a/templates/done.cpp +++ b/templates/done.cpp @@ -95,6 +95,12 @@ void done_defaulted_dir(Info & i) } +void done_reloaded_templates(Info & i) +{ + i.result = request.session->done == Done::reloaded_templates; +} + + } // namespace TemplatesFunctions diff --git a/templates/templates.cpp b/templates/templates.cpp index 481c34f..08850fb 100755 --- a/templates/templates.cpp +++ b/templates/templates.cpp @@ -28,6 +28,7 @@ Ezc::Pattern pat_fun_who; Ezc::Pattern pat_fun_run; Ezc::Pattern pat_fun_last; Ezc::Pattern pat_fun_thread; +Ezc::Pattern pat_fun_reload; Ezc::Pattern pat_fun_createthread; Ezc::Pattern pat_err_item_required; Ezc::Pattern pat_err_404; @@ -110,6 +111,10 @@ Ezc::Pattern * p = 0; p = &pat_fun_thread; break; + case FUN_RELOAD: + p = &pat_fun_reload; + break; + case FUN_CREATETHREAD: p = &pat_fun_createthread; break; @@ -322,6 +327,7 @@ void Templates::CreateFunctions() functions.Insert("done_added_dir", done_added_dir); functions.Insert("done_deleted_dir", done_deleted_dir); functions.Insert("done_defaulted_dir", done_defaulted_dir); + functions.Insert("done_reloaded_templates", done_reloaded_templates); /* @@ -384,7 +390,7 @@ void Templates::CreateFunctions() -void Templates::Read() +void Templates::ReadTemplates() { using namespace TemplatesFunctions; @@ -448,8 +454,9 @@ void Templates::Read() pat_dir_last_info.Directory(data.templates); pat_dir_last_info.ParseFile("dir_last_info.html"); + pat_fun_reload.Directory(data.templates); + pat_fun_reload.ParseFile("fun_reload.html"); - CreateFunctions(); } diff --git a/templates/templates.h b/templates/templates.h index 70fbf07..3afbeac 100755 --- a/templates/templates.h +++ b/templates/templates.h @@ -174,7 +174,7 @@ namespace TemplatesFunctions void done_defaulted_dir(Info & i); void done_loggedout(Info & i); - + void done_reloaded_templates(Info & i); /* who @@ -229,18 +229,11 @@ namespace TemplatesFunctions class Templates { - - public: - - void Read(); - void Generate(); - - -private: - + void ReadTemplates(); void CreateFunctions(); + void Generate(); };