added: new plugin: menu

fixed: System::FollowAllLinks didn't check permissions to a file (only to a simlink or a directory)
added: new ezc function: insert_page
       now we are able to nest pages in pages



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@750 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2011-07-13 23:14:10 +00:00
parent ccc02f41bf
commit 1812a2e9ad
16 changed files with 551 additions and 16 deletions

View File

@ -40,6 +40,7 @@ plugins: FORCE
@cd plugins/ticket ; $(MAKE) -e
@cd plugins/gallery ; $(MAKE) -e
@cd plugins/groupitem ; $(MAKE) -e
@cd plugins/menu ; $(MAKE) -e
FORCE:
@ -56,6 +57,7 @@ clean:
@cd plugins/ticket ; $(MAKE) -e clean
@cd plugins/gallery ; $(MAKE) -e clean
@cd plugins/groupitem ; $(MAKE) -e clean
@cd plugins/menu ; $(MAKE) -e clean
@cd ../ezc/src ; $(MAKE) -e clean
@cd main ; $(MAKE) -e clean
rm -f winix.so
@ -76,6 +78,7 @@ depend:
@cd plugins/ticket ; $(MAKE) -e depend
@cd plugins/gallery ; $(MAKE) -e depend
@cd plugins/groupitem ; $(MAKE) -e depend
@cd plugins/menu ; $(MAKE) -e depend
@cd ../ezc/src ; $(MAKE) -e depend
@cd main ; $(MAKE) -e depend

View File

@ -356,14 +356,12 @@ Item * Dirs::GetDir(const std::wstring & path)
// ops, we do not have a root dir
return 0;
Item * pitem = &(*root);
std::wstring name; // !! dodac jako skladowa klasy
Item * pitem = &(*root);
const wchar_t * s = path.c_str();
while( ExtractName(s, name) )
while( ExtractName(s, get_dir_temp) )
{
pitem = GetDir(name, pitem->id);
pitem = GetDir(get_dir_temp, pitem->id);
if( !pitem )
return 0;

View File

@ -99,6 +99,7 @@ private:
size_t AnalyzeDir(Item * pdir, const std::wstring & path, long & dir_id, std::wstring & dir);
size_t AnalyzeDir(std::vector<Item*> & dir_tab, const std::wstring & link_to);
std::wstring analyze_temp;
std::wstring get_dir_temp;
void CopyDirTab(const std::vector<Item*> & in, std::vector<Item*> & out);
int FollowLink(std::vector<Item*> & dir_tab, const std::wstring & link_to, std::wstring & out_item);

View File

@ -547,6 +547,14 @@ return false;
bool IsLastSlash(const std::wstring & path)
{
if( path.empty() )
return false;
return path[path.size()-1] == '/';
}

View File

@ -185,6 +185,7 @@ const char * DateToStrCookie(time_t t);
const wchar_t * IpToStr(unsigned int ip_);
bool IsWhite(wchar_t s);
bool IsLastSlash(const std::wstring & path);
template<class StringType>
void TrimWhite(StringType & s)

View File

@ -785,6 +785,12 @@ bool System::FollowAllLinksFileOrSymlinkFound(std::vector<Item*> & out_dir_tab,
return false;
}
if( check_access && !HasReadAccess(out_item) )
{
log << log1 << "System: no read access to the file or symlink" << logend;
return false;
}
if( out_item.type == Item::symlink )
{
if( out_item.link_to.empty() )
@ -794,16 +800,8 @@ bool System::FollowAllLinksFileOrSymlinkFound(std::vector<Item*> & out_dir_tab,
}
else
{
if( !check_access || HasReadAccess(out_item) )
{
if( !(stop_on_link_redirect && out_item.link_redirect==1) )
link_to_temp = out_item.link_to;
}
else
{
log << log1 << "System: no read access to the symlink" << logend;
return false;
}
if( !(stop_on_link_redirect && out_item.link_redirect==1) )
link_to_temp = out_item.link_to;
}
}

27
plugins/menu/Makefile Executable file
View File

@ -0,0 +1,27 @@
include Makefile.o.dep
name = menu.so
all: $(name)
$(name): $(o)
$(CXX) -shared -Wl,-soname,$(name).so -o $(name) $(CXXFLAGS) *.o
%.o: %.cpp
$(CXX) -c $(CXXFLAGS) $<
depend:
makedepend -Y. -I../.. -I../../../ezc/src -f- *.cpp > Makefile.dep
echo -n "o = " > Makefile.o.dep
ls -1 *.cpp | xargs -I foo echo -n foo " " | sed -E "s/([^\.]*)\.cpp[ ]/\1\.o/g" >> Makefile.o.dep
clean:
rm -f *.o
rm -f $(name)
include Makefile.dep

109
plugins/menu/Makefile.dep Executable file
View File

@ -0,0 +1,109 @@
# DO NOT DELETE
init.o: ../../core/log.h ../../core/textstream.h ../../core/misc.h
init.o: ../../core/item.h ../../core/requesttypes.h
init.o: ../../core/logmanipulators.h ../../core/slog.h ../../core/cur.h
init.o: ../../core/request.h ../../core/error.h ../../core/config.h
init.o: ../../core/confparser.h ../../core/htmlfilter.h
init.o: ../../templates/htmltextstream.h ../../core/textstream.h
init.o: ../../core/session.h ../../core/user.h ../../core/plugindata.h
init.o: ../../core/rebus.h ../../core/mount.h ../../templates/locale.h
init.o: ../../core/confparser.h ../../core/plugin.h ../../core/pluginmsg.h
init.o: ../../core/log.h ../../core/system.h ../../core/dirs.h
init.o: ../../core/dircontainer.h ../../db/db.h ../../db/dbbase.h
init.o: ../../db/dbconn.h ../../db/dbtextstream.h ../../core/error.h
init.o: ../../db/dbitemquery.h ../../core/item.h ../../db/dbitemcolumns.h
init.o: ../../core/user.h ../../core/group.h ../../core/dircontainer.h
init.o: ../../core/ugcontainer.h ../../notify/notify.h
init.o: ../../notify/notifypool.h ../../templates/misc.h
init.o: ../../templates/localefilter.h ../../templates/locale.h
init.o: ../../../ezc/src/ezc.h ../../../ezc/src/utf8.h
init.o: ../../../ezc/src/generator.h ../../../ezc/src/pattern.h
init.o: ../../../ezc/src/functions.h ../../../ezc/src/funinfo.h
init.o: ../../../ezc/src/stringconv.h ../../templates/htmltextstream.h
init.o: ../../notify/notifythread.h ../../core/basethread.h
init.o: ../../core/synchro.h ../../notify/templatesnotify.h
init.o: ../../core/config.h ../../core/users.h ../../core/ugcontainer.h
init.o: ../../core/lastcontainer.h ../../core/mounts.h
init.o: ../../core/mountparser.h ../../core/crypt.h ../../core/run.h
init.o: ../../core/users.h ../../core/groups.h ../../core/group.h
init.o: ../../core/loadavg.h ../../core/thumb.h ../../core/basethread.h
init.o: ../../core/sessionmanager.h ../../core/sessioncontainer.h
init.o: ../../functions/functions.h ../../functions/functionbase.h
init.o: ../../core/request.h ../../core/system.h ../../core/synchro.h
init.o: ../../functions/functionparser.h ../../core/cur.h
init.o: ../../functions/adduser.h ../../functions/cat.h
init.o: ../../functions/chmod.h ../../functions/privchanger.h
init.o: ../../functions/chown.h ../../functions/ckeditor.h
init.o: ../../functions/cp.h ../../functions/default.h
init.o: ../../functions/download.h ../../functions/emacs.h
init.o: ../../functions/last.h ../../functions/login.h
init.o: ../../functions/logout.h ../../functions/ln.h ../../functions/ls.h
init.o: ../../functions/mkdir.h ../../functions/mv.h
init.o: ../../functions/nicedit.h ../../functions/node.h
init.o: ../../functions/passwd.h ../../functions/priv.h
init.o: ../../functions/reload.h ../../functions/rm.h
init.o: ../../functions/specialdefault.h ../../functions/stat.h
init.o: ../../functions/subject.h ../../functions/template.h
init.o: ../../functions/tinymce.h ../../functions/uname.h
init.o: ../../functions/upload.h ../../functions/uptime.h
init.o: ../../functions/who.h ../../functions/vim.h ../../core/htmlfilter.h
init.o: ../../templates/templates.h ../../templates/patterncacher.h
init.o: ../../templates/ckeditorgetparser.h ../../core/httpsimpleparser.h
init.o: ../../core/log.h ../../templates/indexpatterns.h
init.o: ../../core/sessionmanager.h
templates.o: ../../templates/templates.h ../../../ezc/src/ezc.h
templates.o: ../../../ezc/src/utf8.h ../../../ezc/src/generator.h
templates.o: ../../../ezc/src/pattern.h ../../core/item.h
templates.o: ../../../ezc/src/functions.h ../../../ezc/src/funinfo.h
templates.o: ../../../ezc/src/stringconv.h ../../core/misc.h
templates.o: ../../core/requesttypes.h ../../templates/patterncacher.h
templates.o: ../../core/item.h ../../templates/ckeditorgetparser.h
templates.o: ../../core/httpsimpleparser.h ../../core/log.h
templates.o: ../../templates/indexpatterns.h ../../templates/localefilter.h
templates.o: ../../templates/locale.h ../../core/config.h
templates.o: ../../templates/htmltextstream.h ../../core/cur.h
templates.o: ../../core/system.h ../../core/sessionmanager.h
templates.o: ../../core/htmlfilter.h ../../db/db.h ../../db/dbbase.h
templates.o: ../../db/dbconn.h ../../db/dbtextstream.h
templates.o: ../../core/textstream.h ../../core/error.h
templates.o: ../../db/dbitemquery.h ../../db/dbitemcolumns.h
templates.o: ../../core/user.h ../../core/group.h ../../core/dircontainer.h
templates.o: ../../core/ugcontainer.h ../../core/log.h ../../core/plugin.h
templates.o: ../../core/pluginmsg.h ../../core/plugindata.h
templates.o: ../../core/config.h ../../core/confparser.h
templates.o: ../../core/htmlfilter.h ../../core/request.h ../../core/error.h
templates.o: ../../core/textstream.h ../../templates/htmltextstream.h
templates.o: ../../core/system.h ../../core/dirs.h ../../core/dircontainer.h
templates.o: ../../notify/notify.h ../../notify/notifypool.h
templates.o: ../../templates/locale.h ../../core/confparser.h
templates.o: ../../templates/misc.h ../../notify/notifythread.h
templates.o: ../../core/basethread.h ../../core/synchro.h
templates.o: ../../notify/templatesnotify.h ../../core/users.h
templates.o: ../../core/user.h ../../core/ugcontainer.h
templates.o: ../../core/lastcontainer.h ../../core/cur.h ../../core/session.h
templates.o: ../../core/rebus.h ../../core/mount.h ../../core/mounts.h
templates.o: ../../core/mountparser.h ../../core/crypt.h ../../core/run.h
templates.o: ../../core/users.h ../../core/groups.h ../../core/group.h
templates.o: ../../core/loadavg.h ../../core/thumb.h ../../core/basethread.h
templates.o: ../../core/sessionmanager.h ../../core/sessioncontainer.h
templates.o: ../../functions/functions.h ../../functions/functionbase.h
templates.o: ../../core/request.h ../../core/synchro.h
templates.o: ../../functions/functionparser.h ../../functions/adduser.h
templates.o: ../../functions/cat.h ../../functions/chmod.h
templates.o: ../../functions/privchanger.h ../../functions/chown.h
templates.o: ../../functions/ckeditor.h ../../functions/cp.h
templates.o: ../../functions/default.h ../../functions/download.h
templates.o: ../../functions/emacs.h ../../functions/last.h
templates.o: ../../functions/login.h ../../functions/logout.h
templates.o: ../../functions/ln.h ../../functions/ls.h
templates.o: ../../functions/mkdir.h ../../functions/mv.h
templates.o: ../../functions/nicedit.h ../../functions/node.h
templates.o: ../../functions/passwd.h ../../functions/priv.h
templates.o: ../../functions/reload.h ../../functions/rm.h
templates.o: ../../functions/specialdefault.h ../../functions/stat.h
templates.o: ../../functions/subject.h ../../functions/template.h
templates.o: ../../functions/tinymce.h ../../functions/uname.h
templates.o: ../../functions/upload.h ../../functions/uptime.h
templates.o: ../../functions/who.h ../../functions/vim.h ../../core/log.h
templates.o: ../../core/logmanipulators.h ../../core/slog.h ../../core/misc.h

1
plugins/menu/Makefile.o.dep Executable file
View File

@ -0,0 +1 @@
o = init.o templates.o

78
plugins/menu/init.cpp Executable file
View File

@ -0,0 +1,78 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011, Tomasz Sowa
* All rights reserved.
*
*/
#include "core/log.h"
#include "core/plugin.h"
extern "C" void Init(PluginInfo &);
namespace Menu
{
const wchar_t plugin_name[] = L"menu";
int mount_par_menu_skip = -1;
void AddMountParams(PluginInfo & info)
{
using TemplatesFunctions::system;
mount_par_menu_skip = system->mounts.AddMountPar(L"menu_skip");
}
void FstabChanged(PluginInfo & info)
{
if( mount_par_menu_skip == -1 )
return;
/*
// GetMountTab() returns a const pointer so we cannot sort menu_skip parameters
// may change it to non-const in the future?
const Mounts::MountTab * mt = system->mounts.GetMountTab();
Mounts::MountTab::const_iterator i;
for(i = mt->begin() ; i != mt->end() ; ++i)
SortMenuSkip(i->second);
*/
}
void AddEzcFunctions(PluginInfo & info);
} // namespace
void Init(PluginInfo & info)
{
using namespace Menu;
plugin.Assign(WINIX_TEMPLATES_CREATEFUNCTIONS, AddEzcFunctions);
plugin.Assign(WINIX_ADD_MOUNTS, AddMountParams);
plugin.Assign(WINIX_FSTAB_CHANGED, FstabChanged);
info.p1 = (void*)(plugin_name);
}

165
plugins/menu/templates.cpp Executable file
View File

@ -0,0 +1,165 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011, Tomasz Sowa
* All rights reserved.
*
*/
#include "templates/templates.h"
#include "core/plugin.h"
#include "core/item.h"
#include "core/log.h"
#include "core/misc.h"
namespace Menu
{
using namespace TemplatesFunctions;
using TemplatesFunctions::system;
extern int mount_par_menu_skip;
static std::vector<Item> menu_dir_items;
static size_t menu_dir_index;
static size_t menu_dir_reqid = 0;
static std::wstring menu_dir_last_dir;
static DbItemQuery menu_dir_iq;
// O(n^2) complexity
void menu_dir_skip_items(long parent_id)
{
Mount * m = system->mounts.CalcMount(parent_id);
if( !m || mount_par_menu_skip==-1 || !m->param[mount_par_menu_skip].defined )
return;
const Mount::ParamRow::ParamArg & arg = m->param[mount_par_menu_skip].arg;
for(size_t i=0 ; i<arg.size() ; ++i)
{
for(size_t x=0 ; x<menu_dir_items.size() ; )
{
if( menu_dir_items[x].url == arg[i] )
menu_dir_items.erase(menu_dir_items.begin() + x);
else
x += 1;
}
}
}
void menu_dir_load_menu(long parent_id)
{
menu_dir_iq.SetAll(false, false);
menu_dir_iq.sel_subject = true;
menu_dir_iq.sel_url = true;
menu_dir_iq.WhereParentId(parent_id);
// !! directories will not be read with WINIX_ITEM_FILETYPE_NONE
//menu_dir_iq.WhereFileType(WINIX_ITEM_FILETYPE_NONE);
db->GetItems(menu_dir_items, menu_dir_iq);
menu_dir_skip_items(parent_id);
log << log1 << "Menu: db used" << logend;
}
void menu_dir_init(const std::wstring & path)
{
if( cur->request->id != menu_dir_reqid || menu_dir_last_dir != path )
{
menu_dir_reqid = cur->request->id;
menu_dir_last_dir = path;
menu_dir_items.clear();
if( path.empty() )
{
log << log1 << "Menu: you should provide a path for menu" << logend;
}
else
if( path[0] != '/' )
{
log << log1 << "Menu: path for menu should not be relative" << logend;
}
else
{
Item * pdir = system->dirs.GetDir(path);
if( pdir )
menu_dir_load_menu(pdir->id);
else
log << log1 << "Menu: I cannot find a directory: " << path << logend;
}
}
}
void menu_dir_tab(Info & i)
{
if( i.iter == 0 )
menu_dir_init(i.par);
menu_dir_index = i.iter;
i.res = menu_dir_index < menu_dir_items.size();
}
void menu_dir_tab_subject(Info & i)
{
if( menu_dir_index < menu_dir_items.size() )
i.out << menu_dir_items[menu_dir_index].subject;
}
void menu_dir_tab_url(Info & i)
{
if( menu_dir_index < menu_dir_items.size() )
i.out << menu_dir_items[menu_dir_index].url;
}
void menu_dir_tab_link(Info & i)
{
if( menu_dir_index < menu_dir_items.size() )
{
i.out << menu_dir_last_dir;
if( !IsLastSlash(menu_dir_last_dir) )
i.out << '/';
i.out << menu_dir_items[menu_dir_index].url;
}
}
void AddEzcFunctions(PluginInfo & info)
{
using TemplatesFunctions::EzcFun;
EzcFun * fun = reinterpret_cast<EzcFun*>(info.p1);
fun->Insert("menu_dir_tab", menu_dir_tab);
fun->Insert("menu_dir_tab_subject", menu_dir_tab_subject);
fun->Insert("menu_dir_tab_url", menu_dir_tab_url);
fun->Insert("menu_dir_tab_link", menu_dir_tab_link);
}
} // namespace

View File

@ -136,6 +136,33 @@ indexpatterns.o: ../core/config.h ../core/confparser.h ../core/htmlfilter.h
indexpatterns.o: ../templates/htmltextstream.h ../core/session.h
indexpatterns.o: ../core/user.h ../core/plugindata.h ../core/rebus.h
indexpatterns.o: ../core/mount.h ../templates/locale.h
insert.o: templates.h ../../ezc/src/ezc.h ../../ezc/src/utf8.h
insert.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
insert.o: ../../ezc/src/item.h ../../ezc/src/funinfo.h
insert.o: ../../ezc/src/functions.h ../../ezc/src/stringconv.h misc.h
insert.o: localefilter.h locale.h ../core/confparser.h htmltextstream.h
insert.o: ../core/textstream.h ../core/user.h patterncacher.h ../core/item.h
insert.o: ckeditorgetparser.h ../core/httpsimpleparser.h ../core/log.h
insert.o: ../core/textstream.h ../core/logmanipulators.h ../core/slog.h
insert.o: ../core/cur.h ../core/request.h ../core/requesttypes.h
insert.o: ../core/error.h ../core/config.h ../core/confparser.h
insert.o: ../core/htmlfilter.h ../templates/htmltextstream.h
insert.o: ../core/session.h ../core/user.h ../core/plugindata.h
insert.o: ../core/rebus.h ../core/mount.h ../templates/locale.h
insert.o: indexpatterns.h ../core/config.h ../core/cur.h ../core/system.h
insert.o: ../core/dirs.h ../core/dircontainer.h ../db/db.h ../db/dbbase.h
insert.o: ../db/dbconn.h ../db/dbtextstream.h ../core/error.h
insert.o: ../db/dbitemquery.h ../db/dbitemcolumns.h ../core/group.h
insert.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/log.h
insert.o: ../notify/notify.h ../notify/notifypool.h ../templates/misc.h
insert.o: ../notify/notifythread.h ../core/basethread.h ../core/synchro.h
insert.o: ../notify/templatesnotify.h ../core/users.h ../core/ugcontainer.h
insert.o: ../core/lastcontainer.h ../core/mounts.h ../core/mountparser.h
insert.o: ../core/crypt.h ../core/run.h ../core/users.h ../core/groups.h
insert.o: ../core/group.h ../core/loadavg.h ../core/thumb.h
insert.o: ../core/basethread.h ../core/sessionmanager.h
insert.o: ../core/sessioncontainer.h ../core/system.h ../core/htmlfilter.h
insert.o: ../core/request.h ../core/misc.h
item.o: templates.h ../../ezc/src/ezc.h ../../ezc/src/utf8.h
item.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
item.o: ../../ezc/src/item.h ../../ezc/src/funinfo.h

View File

@ -1 +1 @@
o = adduser.o dir.o doc.o filters.o htmltextstream.o indexpatterns.o item.o last.o locale.o localefilter.o ls.o misc.o mount.o patterncacher.o priv.o rebus.o slog.o stat.o sys.o template.o templates.o upload.o uptime.o user.o who.o winix.o
o = adduser.o dir.o doc.o filters.o htmltextstream.o indexpatterns.o insert.o item.o last.o locale.o localefilter.o ls.o misc.o mount.o patterncacher.o priv.o rebus.o slog.o stat.o sys.o template.o templates.o upload.o uptime.o user.o who.o winix.o

107
templates/insert.cpp Executable file
View File

@ -0,0 +1,107 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011, Tomasz Sowa
* All rights reserved.
*
*/
#include "templates.h"
#include "misc.h"
#include "core/request.h"
#include "core/misc.h"
// max 20 nested insert_page ezc functions allowed
#define WINIX_TEMPLATES_INSERT_PAGE_MAX 20
namespace TemplatesFunctions
{
struct InsertPageInfo
{
std::vector<Item*> dirs;
Item item;
EzcGen ezc_gen;
HtmlTextStream run_content;
};
static InsertPageInfo insert_page_info[WINIX_TEMPLATES_INSERT_PAGE_MAX];
size_t insert_page_cur = 0;
size_t insert_page_reqid = 0;
void insert_page_run(Info & i)
{
InsertPageInfo & info = insert_page_info[insert_page_cur];
Ezc::Pattern * pat = pattern_cacher.GetPattern(info.item);
log << "insert page: using " << insert_page_cur << " generator" << logend;
insert_page_cur += 1;
info.run_content.Clear();
info.ezc_gen.Generate(info.run_content, *pat);
item_print_content(i.out, info.run_content.Str(), info.item.content_type);
insert_page_cur -= 1;
}
bool insert_page_init(const std::wstring & path)
{
if( path.empty() )
return false;
log << "insert page: " << path << logend;
if( insert_page_reqid != cur->request->id )
{
insert_page_reqid = cur->request->id;
insert_page_cur = 0;
}
if( insert_page_cur >= WINIX_TEMPLATES_INSERT_PAGE_MAX )
{
log << log1 << "Templates: insert_page: maximum nested insert_page exceeded" << logend;
return false;
}
return true;
}
void insert_page(Info & i)
{
if( !insert_page_init(i.par) )
return;
InsertPageInfo & info = insert_page_info[insert_page_cur];
if( system->FollowAllLinks(cur->request->dir_tab, i.par, info.dirs, info.item) == 1 )
{
if( system->HasReadExecAccess(info.item) )
insert_page_run(i);
else
if( system->HasReadAccess(info.item) )
item_print_content(i.out, info.item.content, info.item.content_type);
}
}
} // namespace TemplatesFunctions

View File

@ -210,6 +210,11 @@ void Templates::CreateFunctions()
ezc_functions.Insert("doc_css_more_than_one", doc_css_more_than_one);
/*
insert
*/
ezc_functions.Insert("insert_page", insert_page);
/*
item

View File

@ -140,6 +140,13 @@ namespace TemplatesFunctions
void fil_tosmall(Info & i);
void fil_firstup(Info & i);
/*
insert
*/
void insert_page(Info & i);
/*
item
*/