diff --git a/content/Makefile.dep b/content/Makefile.dep index 133db91..b04dd2a 100755 --- a/content/Makefile.dep +++ b/content/Makefile.dep @@ -63,7 +63,7 @@ cp.o: ../core/acceptencodingparser.h ../core/acceptbaseparser.h cp.o: ../core/htmlfilter.h ../core/postmultiparser.h ../core/data.h cp.o: ../core/dirs.h ../core/users.h ../core/groups.h ../core/functions.h cp.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h -cp.o: ../core/loadavg.h +cp.o: ../core/loadavg.h ../core/misc.h createthread.o: content.h ../core/item.h ../templates/templates.h createthread.o: ../templates/patterncacher.h ../templates/misc.h createthread.o: ../templates/localefilter.h ../core/locale.h diff --git a/content/content.cpp b/content/content.cpp index 0c7e12f..8de6f65 100755 --- a/content/content.cpp +++ b/content/content.cpp @@ -524,6 +524,8 @@ void Content::SetUser(Item & item) item.user_id = -1; request.PostVar("guestname", item.guest_name); } + + item.group_id = request.dir_table.back()->group_id; } diff --git a/content/content.h b/content/content.h index 86ace22..1a92e22 100755 --- a/content/content.h +++ b/content/content.h @@ -71,9 +71,25 @@ class Content */ bool CpCheckAccessFrom(); void CpAuth(Item & item); - void CpItem(Item & item, bool redirect = true); + void CpSetNewAttributes(Item & item); + void CpItem(Item & item, long dst_dir_id); + void CpFilesInDir(const Item & dir, long dst_dir_id); + void CpContentOfDir(const Item & item, long dst_dir_id); + long CpDir(const Item & item, long dst_dir_id); + void CpItemCheck(Item & item, bool redirect = true); + void CpContentOfDirCheck(const Item & item, bool redirect = true); + void CpDirCheck(const Item & item, bool redirect = true); void PostFunCp(); void FunCp(); + void CpPrepare(); + Item cp_temp; + Db::ItemQuery cp_iq; + bool cp_remove_defaults; + bool cp_preserve_attr; + long cp_new_user; + long cp_new_group; + + diff --git a/content/cp.cpp b/content/cp.cpp index 21f33d8..6c5575b 100755 --- a/content/cp.cpp +++ b/content/cp.cpp @@ -24,8 +24,13 @@ bool Content::CpCheckAccessFrom() return false; } } + else + if( !request.IsParam("r") ) + { + // directories need 'r' parameter + request.status = WINIX_ERR_PERMISSION_DENIED; + } - // dirs are checked in function parser return true; } @@ -53,46 +58,197 @@ void Content::CpAuth(Item & item) } -void Content::CpItem(Item & item, bool redirect) +void Content::CpSetNewAttributes(Item & item) { - if( MoveIsTheSameFile(item) ) - return; - - if( !mv_file.empty() ) - { - item.url = mv_file; - PrepareUrl(item); - } - - item.parent_id = mv_dir_id; + item.user_id = cp_new_user; + item.group_id = cp_new_group; + item.SetDateModifyToNow(); +} + + +void Content::CpItem(Item & item, long dst_dir_id) +{ + if( !request.HasReadAccess(item) ) + return; // !! w przyszlosci bedziemy dodawac komunikaty do specjalnej tablicy (narazie nie zaimplementowane) + + item.parent_id = dst_dir_id; + + if( !cp_preserve_attr ) + CpSetNewAttributes(item); + PostFunEmacsAdd(item); if( request.status == WINIX_ERR_OK ) { if( item.auth != Item::auth_none ) CpAuth(item); - - if( redirect ) - RedirectTo(item); } } + +void Content::CpPrepare() +{ + cp_iq.SetAll(true, false); + cp_iq.WhereType(Item::file); + + cp_new_user = -1; + cp_new_group = -1; + + if( request.session->puser ) + cp_new_user = request.session->puser->id; + + Item * pdir = data.dirs.GetDir(mv_dir_id); + + if( pdir ) + cp_new_group = pdir->group_id; +} + + + +void Content::CpFilesInDir(const Item & dir, long dst_dir_id) +{ + cp_iq.WhereParentId(dir.id); + db.GetItems(request.item_table, cp_iq); + + for(size_t i=0 ; isecond), dst_dir_id); + + CpFilesInDir(item, dst_dir_id); +} + + + +// we shouldn't change 'item' because we have references to our data.dirs objects +long Content::CpDir(const Item & item, long dst_dir_id) +{ + cp_temp = item; + cp_temp.parent_id = dst_dir_id; + + if( !mv_file.empty() ) + { + cp_temp.url = mv_file; + mv_file.clear(); + PrepareUrl(cp_temp); + } + + if( !cp_preserve_attr ) + CpSetNewAttributes(cp_temp); + + if( cp_remove_defaults ) + cp_temp.default_item = -1; + + Mkdir(cp_temp, false); + long new_dir_id = cp_temp.id; // remember the new dir_id + + if( request.HasReadExecAccess(item) ) + CpContentOfDir(item, cp_temp.id); + +return new_dir_id; // and return it +} + + + + +// here 'item' can be changed in place +void Content::CpItemCheck(Item & item, bool redirect) +{ + if( MoveIsTheSameFile(item) ) + return; + + if( !mv_file.empty() ) + { + item.url = mv_file; + PrepareUrl(item); + } + + CpItem(item, mv_dir_id); + + if( request.status==WINIX_ERR_OK && redirect ) + RedirectTo(item); +} + + + +void Content::CpContentOfDirCheck(const Item & item, bool redirect) +{ + if( !mv_file.empty() ) + { + request.status = WINIX_ERR_INCORRECT_DIR; + return; + } + + if( mv_dir_id == item.id ) + return; // nothing to do + + if( data.dirs.HasParent(mv_dir_id, item.id) ) + { + log << log1 << "Content: cannot copy directory to inside it" << logend; + request.status = WINIX_ERR_INCORRECT_DIR; + return; + } + + CpContentOfDir(item, mv_dir_id); + + if( request.status==WINIX_ERR_OK && redirect ) + RedirectTo(mv_dir_id); +} + + + +void Content::CpDirCheck(const Item & item, bool redirect) +{ + if( mv_file.empty() && mv_dir_id == item.id ) + return; // nothing to do + + if( mv_dir_id == item.id || data.dirs.HasParent(mv_dir_id, item.id) ) + { + log << log1 << "Content: cannot copy directory to inside it" << logend; + request.status = WINIX_ERR_INCORRECT_DIR; + return; + } + + long new_dir_id = CpDir(item, mv_dir_id); + + if( request.status==WINIX_ERR_OK && redirect ) + RedirectTo(new_dir_id); +} + + + void Content::PostFunCp() { if( CpCheckAccessFrom() && MoveParseDir(mv_dir_id, mv_dir, mv_file) && MoveCheckAccessTo(mv_dir_id) ) { + CpPrepare(); + cp_preserve_attr = request.IsPostVar("preserveattr"); + if( request.is_item ) { - CpItem(request.item); + CpItemCheck(request.item); } else { - /* not implemented yet */ - request.status = WINIX_ERR_PERMISSION_DENIED; + cp_remove_defaults = request.IsPostVar("removedefaults"); + + if( request.IsPostVar("onlycontent") ) + CpContentOfDirCheck(*request.dir_table.back()); + else + CpDirCheck(*request.dir_table.back()); } } } diff --git a/content/emacs.cpp b/content/emacs.cpp index 930c7c5..f38ec08 100755 --- a/content/emacs.cpp +++ b/content/emacs.cpp @@ -45,7 +45,9 @@ void Content::PostFunEmacsAdd(Item & item) if( request.status == WINIX_ERR_OK ) { - log << log2 << "Content: added a new item" << logend; + log << log2 << "Content: added a new item, url: " << item.url << ", id: " << item.id + << ", parent_id: " << item.parent_id << logend; + request.notify_code |= WINIX_NOTIFY_ITEM_ADD; } } diff --git a/content/mv.cpp b/content/mv.cpp index 0b558a5..04719c1 100755 --- a/content/mv.cpp +++ b/content/mv.cpp @@ -248,7 +248,7 @@ Db::ItemQuery iq; void Content::MoveAuthPrepareQuery() { - mv_auth_iq.SetAll(true, false); + mv_auth_iq.SetAll(false, false); mv_auth_iq.sel_parent_id = true; mv_auth_iq.sel_type = true; diff --git a/html/fun_cp.html b/html/fun_cp.html index 55fc05c..8921994 100755 --- a/html/fun_cp.html +++ b/html/fun_cp.html @@ -2,7 +2,7 @@ [include "error.html"] -
+
{cp_form_legend} @@ -12,12 +12,16 @@

{suggested_url}

- + +

+ [if-no item_is] + [end] +

diff --git a/html/fun_ls.html b/html/fun_ls.html index 14169aa..42cb9da 100755 --- a/html/fun_ls.html +++ b/html/fun_ls.html @@ -23,20 +23,31 @@ [is winix_function_param_is "l"] + [# loading dir childs table with a parent directory] + [dir_childs_tab "with_parent"] + [if-one dir_childs_tab item_tab] [for dir_childs_tab] + - + [end] [for item_tab] + @@ -49,14 +60,23 @@ [else] + [# loading dir childs table with a parent directory] + [dir_childs_tab "with_parent"] + [if-one dir_childs_tab] [end] - + [if-one item_tab]
d [dir_childs_tab_privileges] [dir_childs_tab_user] [dir_childs_tab_group][dir_childs_tab_url]/ + [if-one dir_childs_is_parent] + ../ + [else] + [dir_childs_tab_url]/ + [end] +
- [item_tab_privileges] [item_tab_user] [item_tab_group]