From 3702efc5bec861bee7208718eaede905f14f41c9 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Mon, 22 Feb 2010 22:52:09 +0000 Subject: [PATCH] added: parameter 'l' to 'ls' function added: Db::ItemQuery struct for querying items changed: some refactoring (renamed some config variables) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@589 e52654a7-88a9-db11-a3e9-0013d4bc506e --- content/content.cpp | 4 +- content/content.h | 2 +- content/download.cpp | 4 +- content/ls.cpp | 29 ++++++++------ content/priv.cpp | 11 +++++- content/thread.cpp | 11 ++++-- content/ticket.cpp | 8 +++- content/upload.cpp | 4 +- core/config.cpp | 38 ++++++++++-------- core/data.cpp | 2 +- core/data.h | 35 +++++++---------- core/db.cpp | 71 ++++++++++++++++++--------------- core/db.h | 80 ++++++++++++++++++++++++++++++++++++-- core/db_itemcolumns.cpp | 4 +- core/functionparser.cpp | 2 +- core/item.h | 33 ++++++++-------- core/misc.cpp | 8 ++-- core/misc.h | 2 +- core/postmultiparser.cpp | 6 +-- core/request.cpp | 22 +++++------ core/requestcontroller.cpp | 6 +-- html/fun_cat.html | 4 +- html/fun_ckeditor.html | 4 +- html/fun_ls.html | 62 ++++++++++++++++++++++------- templates/dir.cpp | 44 ++++++++++++++++++++- templates/doc.cpp | 14 +++---- templates/item.cpp | 29 ++++++++++---- templates/templates.cpp | 38 ++++++++++-------- templates/templates.h | 14 ++++--- 29 files changed, 396 insertions(+), 195 deletions(-) diff --git a/content/content.cpp b/content/content.cpp index d88fe2c..9c33c2c 100755 --- a/content/content.cpp +++ b/content/content.cpp @@ -46,7 +46,7 @@ return true; void Content::SetDefaultFunctionForFile() { - if( request.item.static_auth != Item::static_none ) + if( request.item.auth != Item::auth_none ) request.pfunction = data.functions.GetFunction(FUN_DOWNLOAD); else if( request.HasReadExecAccess(request.item) ) @@ -320,7 +320,7 @@ bool sent = false; return; - if( request.is_item && request.item.static_auth == Item::static_none && + if( request.is_item && request.item.auth == Item::auth_none && request.item.content_type == Item::ct_raw && request.status == Error::ok && request.pfunction ) { if( request.pfunction->code == FUN_CAT ) diff --git a/content/content.h b/content/content.h index 158e0d1..de256c7 100755 --- a/content/content.h +++ b/content/content.h @@ -55,7 +55,7 @@ class Content void FunEmacs(); - void AddPathToStaticAuth(std::string & path); + void AddPathToAuth(std::string & path); void FunCKEditor(); diff --git a/content/download.cpp b/content/download.cpp index 7c3fa77..a6dd178 100755 --- a/content/download.cpp +++ b/content/download.cpp @@ -27,8 +27,8 @@ void Content::FunDownload() if( !request.HasReadAccess(request.item) || - request.item.static_auth == Item::static_none || - data.static_simplefs_dir.empty() ) + request.item.auth == Item::auth_none || + data.auth_simplefs_dir.empty() ) { request.status = Error::permission_denied; return; diff --git a/content/ls.cpp b/content/ls.cpp index 2141d3d..66aa292 100755 --- a/content/ls.cpp +++ b/content/ls.cpp @@ -15,20 +15,25 @@ void Content::FunLs() { - if( request.is_item ) + if( !request.is_item ) { - // we're showing only the item - request.item_table.push_back( request.item ); - return; - } - - // we're reading only files here - db.GetItems(request.item_table, request.dir_table.back()->id, Item::file, false, false, true); + Db::ItemQuery iq; - /* - request.IsParam("ckeditor_browse"); - */ - + iq.sel_content = false; + + iq.WhereParentId(request.dir_table.back()->id); + iq.WhereType(Item::file); + + if( request.IsParam("ckeditor_browse") ) + { + iq.WhereAuth(Item::auth_image); + db.GetItems(request.item_table, iq); + } + else + { + db.GetItems(request.item_table, iq); + } + } } diff --git a/content/priv.cpp b/content/priv.cpp index e865ef1..491c6b5 100755 --- a/content/priv.cpp +++ b/content/priv.cpp @@ -157,7 +157,16 @@ Item * root = 0; void Content::PrivFilesInDir(long parent_id) { - db.GetItems(request.item_table, parent_id, Item::file, false, false, true); + Db::ItemQuery iq; + + iq.SetAll(false, false); + iq.sel_user_id = iq.sel_group_id = iq.sel_guest_name = iq.sel_privileges = true; + + iq.WhereParentId(parent_id); + iq.WhereType(Item::file); + + db.GetItems(request.item_table, iq); + std::vector::iterator i = request.item_table.begin(); diff --git a/content/thread.cpp b/content/thread.cpp index be05679..7237de8 100755 --- a/content/thread.cpp +++ b/content/thread.cpp @@ -39,13 +39,16 @@ void Content::FunThread() return; } - bool asc = true; - + Db::ItemQuery iq; + if( data.mounts.pmount->IsArg(Mount::par_thread, "sort_desc") ) - asc = false; + iq.sort_asc = false; + iq.WhereParentId(request.dir_table.back()->id); + iq.WhereType(Item::file); + iq.WhereAuth(Item::auth_none); - db.GetItems(request.item_table, request.dir_table.back()->id, Item::file, true, true, asc); + db.GetItems(request.item_table, iq); db.GetThreads(request.dir_table.back()->id, request.thread_tab); CheckAccessToItems(); diff --git a/content/ticket.cpp b/content/ticket.cpp index 15ed770..171ab96 100755 --- a/content/ticket.cpp +++ b/content/ticket.cpp @@ -50,7 +50,13 @@ void Content::FunTicket() return; } - db.GetItems(request.item_table, request.dir_table.back()->id, Item::file, true, true, true); + Db::ItemQuery iq; + + iq.WhereParentId(request.dir_table.back()->id); + iq.WhereType(Item::file); + iq.WhereAuth(Item::auth_none); + + db.GetItems(request.item_table, iq); db.GetTickets(request.dir_table.back()->id, request.ticket_tab); TicketDeleteFirst(); diff --git a/content/upload.cpp b/content/upload.cpp index 8a45916..a152d20 100755 --- a/content/upload.cpp +++ b/content/upload.cpp @@ -115,7 +115,7 @@ void Content::UploadMulti() request.item.subject = file_name; request.item.url = file_name; - request.item.static_auth = SelectFileType(file_name); + request.item.auth = SelectFileType(file_name); PrepareUrl(request.item); PostFunEmacsAdd(); // always adding a new item @@ -142,7 +142,7 @@ void Content::UploadSingle() request.item.privileges = 0644; // !! tymczasowo const char * file_name = request.post_file_table.begin()->second.filename.c_str(); - request.item.static_auth = SelectFileType(file_name); + request.item.auth = SelectFileType(file_name); if( !has_subject ) request.item.subject = file_name; diff --git a/core/config.cpp b/core/config.cpp index 3c84280..424f08c 100755 --- a/core/config.cpp +++ b/core/config.cpp @@ -109,9 +109,9 @@ void Config::AssignValues() data.log_stdout = false; data.post_file_max = Int("post_file_max", 8388608); // 8 MB - data.static_simplefs_dir = Text("static_simplefs_dir"); - data.static_hashfs_dir = Text("static_hashfs_dir"); - data.static_tmp_dir = Text("static_tmp_dir"); + data.auth_simplefs_dir = Text("auth_simplefs_dir"); + data.auth_hashfs_dir = Text("auth_hashfs_dir"); + data.auth_tmp_dir = Text("auth_tmp_dir"); data.templates_dir = Text("templates_dir"); data.templates_dir_default = Text("templates_dir_default"); @@ -121,19 +121,17 @@ void Config::AssignValues() data.db_pass = Text("db_pass"); data.item_url_empty = Text("item_url_empty"); - data.base_server = Text("base_server"); - data.base_url_prefix = Text("base_url_prefix"); - data.base_url_static_prefix = Text("base_url_static_prefix"); - data.base_url_static_ext_prefix = Text("base_url_static_ext_prefix"); - data.base_url_static_auth_prefix = Text("base_url_static_auth_prefix"); + 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"); NoLastSlash(data.base_server); - NoFirstHttp(data.base_server); - - data.base_url = data.base_url_prefix + data.base_server; - data.base_url_static = data.base_url_static_prefix + data.base_server; - data.base_url_static_ext = data.base_url_static_ext_prefix + data.base_server; - data.base_url_static_auth = data.base_url_static_auth_prefix + data.base_server; + NoLastSlash(data.base_url); + NoLastSlash(data.base_url_auth); + NoLastSlash(data.base_url_static); + NoLastSlash(data.base_url_common); data.priv_no_user = Text("priv_no_user", "-- no user --"); data.priv_no_group = Text("priv_no_group", "-- no group --"); @@ -247,12 +245,18 @@ void Config::NoLastSlash(std::string & s) { if( s.empty() ) return; - - if( *(--s.end()) == '/' ) - s.erase(--s.end()); + + + size_t i = s.size(); + + for( ; i>0 && s[i-1]=='/' ; --i); + + if( i < s.size() ) + s.erase(i); } + void Config::NoFirstHttp(std::string & s) { if( s.empty() ) diff --git a/core/data.cpp b/core/data.cpp index 7e3337e..f2581f4 100755 --- a/core/data.cpp +++ b/core/data.cpp @@ -27,7 +27,7 @@ Data::Data() void Data::SetAdditionalVariables() { SetHttpHost(base_url, base_url_http_host); - SetHttpHost(base_url_static_auth, base_url_static_auth_http_host); + SetHttpHost(base_url_auth, base_url_auth_http_host); } diff --git a/core/data.h b/core/data.h index ec049bb..74cebe9 100755 --- a/core/data.h +++ b/core/data.h @@ -2,7 +2,7 @@ * This file is a part of CMSLU -- Content Management System like Unix * and is not publicly distributed * - * Copyright (c) 2008-2009, Tomasz Sowa + * Copyright (c) 2008-2010, Tomasz Sowa * All rights reserved. * */ @@ -69,12 +69,6 @@ public: std::string db_user; std::string db_pass; - std::string base_server; - std::string base_url_prefix; - std::string base_url_static_prefix; - std::string base_url_static_ext_prefix; - std::string base_url_static_auth_prefix; - 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) @@ -113,12 +107,12 @@ public: int post_file_max; // directories for static files - std::string static_simplefs_dir; - std::string static_hashfs_dir; + 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 static_simplefs_dir and static_hashfs_dir - std::string static_tmp_dir; + // 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; @@ -129,19 +123,20 @@ public: // directory with default locale files (those from winix) std::string locale_dir_default; - // below variables are based on the other config variables + // the main address of the server (e.g. someserver.com) (without the 'www' part etc) + std::string base_server; - // base_url_prefix + base_server + // the main address of the site (e.g. http://www.someserver.com) std::string base_url; - // base_url_static_prefix + base_server + // 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 such as ckeditor - std::string base_url_static_ext; - - // base_url_static_auth_prefix + base_server - std::string base_url_static_auth; + // additional static server for common content (not authorized) + std::string base_url_common; // separator used in html tag std::string title_separator; @@ -166,7 +161,7 @@ public: // 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_static_auth_http_host; + std::string base_url_auth_http_host; diff --git a/core/db.cpp b/core/db.cpp index 2840b63..5e91c31 100755 --- a/core/db.cpp +++ b/core/db.cpp @@ -421,7 +421,7 @@ Error Db::AddItemIntoItem(Item & item) AssertConnection(); std::ostringstream query; query << "insert into core.item (user_id, group_id, privileges, date_creation, date_modification, type, " - "parent_id, content_id, static_auth, default_item, subject, guest_name, url) values ("; + "parent_id, content_id, auth, default_item, subject, guest_name, url) values ("; query << '\'' << item.user_id << "', "; query << '\'' << item.group_id << "', "; query << '\'' << item.privileges << "', "; @@ -430,7 +430,7 @@ Error Db::AddItemIntoItem(Item & item) query << '\'' << static_cast<int>(item.type) << "', "; query << '\'' << item.parent_id << "', "; query << '\'' << item.content_id << "', "; - query << '\'' << static_cast<int>(item.static_auth) << "', "; + query << '\'' << static_cast<int>(item.auth) << "', "; query << '\'' << item.default_item << "', "; query << '\'' << Escape(item.subject) << "', "; query << '\'' << Escape(item.guest_name) << "', "; @@ -527,7 +527,7 @@ Error Db::EditItemInItem(Item & item, bool with_url) AssertConnection(); std::ostringstream query; query << "update core.item set (user_id, group_id, privileges, date_creation, date_modification, type, " - "default_item, parent_id, subject, guest_name, static_auth"; + "default_item, parent_id, subject, guest_name, auth"; if( with_url ) query << ", url"; @@ -543,7 +543,7 @@ Error Db::EditItemInItem(Item & item, bool with_url) query << '\'' << item.parent_id << "', "; query << '\'' << Escape(item.subject) << "', "; query << '\'' << Escape(item.guest_name) << "', "; - query << '\'' << static_cast<int>(item.static_auth) << "' "; + query << '\'' << static_cast<int>(item.auth) << "' "; if( with_url ) { @@ -752,49 +752,56 @@ return result; -PGresult * Db::GetItemsQuery(long parent_id, Item::Type type, bool with_subject, bool with_content, bool sort_asc) +PGresult * Db::GetItemsQuery(const ItemQuery & iq) { std::ostringstream query; - query << "select item.id, user_id, group_id, privileges, date_creation, date_modification, url, type, parent_id, " - "content_id, default_item, guest_name, static_auth"; + query << "select item.id"; - if( type != Item::dir ) - { - if( with_subject ) - query << ", subject"; - - if( with_content ) - query << ", content, content_type"; - } + if( iq.sel_parent_id ) query << " ,parent_id"; + if( iq.sel_user_id ) query << " ,user_id"; + if( iq.sel_group_id ) query << " ,group_id"; + if( iq.sel_guest_name) query << " ,guest_name"; + if( iq.sel_privileges ) query << " ,privileges"; + if( iq.sel_date ) query << " ,date_creation, date_modification"; + if( iq.sel_subject ) query << " ,subject"; + if( iq.sel_content ) query << " ,content, content_type, content_id"; + if( iq.sel_url ) query << " ,url"; + if( iq.sel_type ) query << " ,type"; + if( iq.sel_default_item ) query << " ,default_item"; + if( iq.sel_auth ) query << " ,auth"; query << " from core.item"; - if( type != Item::dir && with_content ) - query << " left join core.content on item.content_id = content.id"; - - query << " where parent_id='" << parent_id << "'"; + if( iq.sel_content ) query << " left join core.content on item.content_id = content.id"; + + + if( iq.where_id || iq.where_parent_id || iq.where_type || iq.where_auth ) + { + query << " where "; + const char * add_and = " and "; + const char * if_and = ""; + + if( iq.where_id ) { query << if_and << "id='" << iq.id << "'" ; if_and = add_and; } + if( iq.where_parent_id ) { query << if_and << "parent_id='" << iq.parent_id << "'" ; if_and = add_and; } + if( iq.where_type ) { query << if_and << "type='" << static_cast<int>(iq.type) << "'" ; if_and = add_and; } + if( iq.where_auth ) { query << if_and << "auth='" << static_cast<int>(iq.auth) << "'" ; if_and = add_and; } + } + - if( type == Item::dir ) - query << " and type='0'"; - - if( type == Item::file ) - query << " and type='1'"; - query << " order by item.date_creation"; - if( sort_asc ) - query << " asc"; + if( iq.sort_asc ) + query << " asc;"; else - query << " desc"; + query << " desc;"; - query << ';'; - return AssertQuery(query.str()); } -void Db::GetItems(std::vector<Item> & item_table, long parent_id, Item::Type type, bool with_subject, bool with_content, bool sort_asc) + +void Db::GetItems(std::vector<Item> & item_table, const ItemQuery & item_query) { item_table.clear(); PGresult * r = 0; @@ -805,7 +812,7 @@ void Db::GetItems(std::vector<Item> & item_table, long parent_id, Item::Type typ { AssertConnection(); - r = GetItemsQuery(parent_id, type, with_subject, with_content, sort_asc); + r = GetItemsQuery(item_query); AssertResultStatus(r, PGRES_TUPLES_OK); Item item; diff --git a/core/db.h b/core/db.h index 54103cf..67898dd 100755 --- a/core/db.h +++ b/core/db.h @@ -49,7 +49,79 @@ public: Error EditItemByUrl(Item & item, bool with_url = true); void CheckAllUrlSubject(); - void GetItems(std::vector<Item> & item_table, long parent_id, Item::Type type, bool with_subject, bool with_content, bool sort_asc); + + struct ItemQuery + { + // id is selected always + bool sel_parent_id; // parent_id + bool sel_user_id; // user_id + bool sel_group_id; // group_id + bool sel_guest_name; // guest_name + bool sel_privileges; // privileges + bool sel_date; // date_creation, date_modification + bool sel_subject; // subject + bool sel_content; // content, content_type, (content_id) + bool sel_url; // url + bool sel_type; // type (dir, file, none) + bool sel_default_item; // default_item + bool sel_auth; // auth + + bool where_id; // + bool where_parent_id; // + bool where_type; + bool where_auth; + + long id; // if where_id is true + long parent_id; // if where_parent_id is true + Item::Type type; + Item::Auth auth; + + bool sort_asc; + + + void SetAll(bool sel, bool where_) + { + sel_parent_id = sel; + sel_user_id = sel; + sel_group_id = sel; + sel_guest_name = sel; + sel_privileges = sel; + sel_date = sel; + sel_subject = sel; + sel_content = sel; + sel_url = sel; + sel_type = sel; + sel_default_item= sel; + sel_auth = sel; + + where_id = where_; + where_parent_id = where_; + where_type = where_; + where_auth = where_; + } + + void WhereId(long id_) { where_id = true; id = id_; } + void WhereParentId(long parent_id_) { where_parent_id = true; parent_id = parent_id_; } + void WhereType(Item::Type type_) { where_type = true; type = type_; } + void WhereAuth(Item::Auth st) { where_auth = true; auth = st; } + + ItemQuery() + { + sort_asc = true; + SetAll(true, false); + + id = -1; + parent_id = -1; + type = Item::none; + auth = Item::auth_none; + } + }; + + + void GetItems(std::vector<Item> & item_table, const ItemQuery & item_query); + + + // !! pobiera tylko jeden item (cos wymyslec innego z nazwa albo argumentem) void GetItem(std::vector<Item> & item_table, long id); @@ -131,8 +203,8 @@ protected: void CheckAllUrlSubjectModifyItem(Item & item); - PGresult * GetItemsQuery(long parent_id, Item::Type type, bool with_subject, bool with_content, bool sort_asc); - + PGresult * GetItemsQuery(const ItemQuery & iq); + bool DelItemDelItem(const Item & item); void DelItemDelContent(const Item & item); Error DelItemCountContents(const Item & item, long & contents); @@ -141,7 +213,7 @@ protected: struct ItemColumns { int id, user_id, group_id, privileges, date_creation, date_modification, url, type, parent_id, - content_id, default_item, subject, content, content_type, guest_name, static_auth; + content_id, default_item, subject, content, content_type, guest_name, auth; void SetColumns(PGresult * r); void SetItem(PGresult * r, long row, Item & item); diff --git a/core/db_itemcolumns.cpp b/core/db_itemcolumns.cpp index 6275864..f3f2b58 100755 --- a/core/db_itemcolumns.cpp +++ b/core/db_itemcolumns.cpp @@ -29,7 +29,7 @@ void Db::ItemColumns::SetColumns(PGresult * r) content = PQfnumber(r, "content"); content_type = PQfnumber(r, "content_type"); guest_name = PQfnumber(r, "guest_name"); - static_auth = PQfnumber(r, "static_auth"); + auth = PQfnumber(r, "auth"); } @@ -51,7 +51,7 @@ void Db::ItemColumns::SetItem(PGresult * r, long row, Item & item) if( content != -1 ) item.content = Db::AssertValue(r, row, content); if( content_type != -1 ) item.content_type = static_cast<Item::ContentType>( atoi(Db::AssertValue(r, row, content_type)) ); if( guest_name != -1 ) item.guest_name = Db::AssertValue(r, row, guest_name); - if( static_auth != -1 ) item.static_auth = static_cast<Item::StaticAuth>( atoi(Db::AssertValue(r, row, static_auth)) ); + if( auth != -1 ) item.auth = static_cast<Item::Auth>( atoi(Db::AssertValue(r, row, auth)) ); } diff --git a/core/functionparser.cpp b/core/functionparser.cpp index 0abe358..0569873 100755 --- a/core/functionparser.cpp +++ b/core/functionparser.cpp @@ -80,7 +80,7 @@ void FunctionParser::ParseItem() if( request.status == Error::ok ) { - if( request.role == Request::authorizer && request.item.static_auth == Item::static_none ) + 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 = Error::no_item; diff --git a/core/item.h b/core/item.h index 7334dbe..2eff367 100755 --- a/core/item.h +++ b/core/item.h @@ -18,20 +18,21 @@ struct Item { long id; +long parent_id; long user_id; long group_id; -int privileges; +std::string guest_name; // used as a user name when user_id is equal -1 -// used as a user name when user_id is equal -1 -std::string guest_name; +int privileges; tm date_creation; tm date_modification; std::string subject; std::string content; +long content_id; // used by the database std::string url; enum ContentType @@ -52,36 +53,34 @@ enum Type dir = 0, file = 1, - none = 1000 + none = 1000 // !! pozbyc sie tego }; Type type; -//item_type; -long parent_id; long default_item; -// used by the database -long content_id; -// external static file (saved in file system) -// the direct url is the same but the prefix is: base_url_static_auth -enum StaticAuth +// external static file authorized by winix +enum Auth { - static_none = 0, - static_image = 1, /* png, gif, jpg - only types available to render by a web browser*/ - static_document = 2, /* pdf doc xls txt */ - static_other = 3 + auth_none = 0, /* there is not an external file */ + auth_image = 1, /* png, gif, jpg - only types available to render by a web browser*/ + auth_document = 2, /* pdf doc xls txt */ + auth_other = 3 /* other file */ }; -StaticAuth static_auth; +Auth auth; + +// methods + Item() { Clear(); @@ -125,7 +124,7 @@ void Clear() content_id = -1; - static_auth = static_none; + auth = auth_none; SetDateToNow(); } diff --git a/core/misc.cpp b/core/misc.cpp index cf0a6ed..a1d2e1d 100755 --- a/core/misc.cpp +++ b/core/misc.cpp @@ -635,7 +635,7 @@ return name + i + 1; } -Item::StaticAuth SelectFileType(const char * file_name) +Item::Auth SelectFileType(const char * file_name) { const char * ext = GetFileExt(file_name); @@ -644,7 +644,7 @@ Item::StaticAuth SelectFileType(const char * file_name) if( EqualNoCase(ext, "jpg") || EqualNoCase(ext, "gif") || EqualNoCase(ext, "png") ) - return Item::static_image; + return Item::auth_image; if( EqualNoCase(ext, "pdf") || EqualNoCase(ext, "doc") || @@ -652,8 +652,8 @@ Item::StaticAuth SelectFileType(const char * file_name) EqualNoCase(ext, "txt") || EqualNoCase(ext, "ods") || EqualNoCase(ext, "odt") ) - return Item::static_document; + return Item::auth_document; -return Item::static_other; +return Item::auth_other; } diff --git a/core/misc.h b/core/misc.h index 0c13d0b..a9b05dc 100755 --- a/core/misc.h +++ b/core/misc.h @@ -68,6 +68,6 @@ bool CreateDir(const char * dir, int priv); bool CreateDir(const std::string & dir, int priv); const char * GetFileExt(const char * name); -Item::StaticAuth SelectFileType(const char * file_name); +Item::Auth SelectFileType(const char * file_name); #endif diff --git a/core/postmultiparser.cpp b/core/postmultiparser.cpp index f9d1505..6f7217d 100755 --- a/core/postmultiparser.cpp +++ b/core/postmultiparser.cpp @@ -433,14 +433,14 @@ void PostMultiParser::CreateTmpFile() { char buf[100]; - if( data.static_tmp_dir.empty() ) + if( data.auth_tmp_dir.empty() ) { - log << log1 << "PMP: static_tmp_dir is not set in the config" << logend; + log << log1 << "PMP: auth_tmp_dir is not set in the config" << logend; err = Error::cant_create_file; return; } - sprintf(buf, "%s/winix_%u_%d_%u", data.static_tmp_dir.c_str(), (unsigned)getpid(), tmp_filename_postfix, rand()); + sprintf(buf, "%s/winix_%u_%d_%u", data.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); diff --git a/core/request.cpp b/core/request.cpp index e59fced..35dd60e 100755 --- a/core/request.cpp +++ b/core/request.cpp @@ -519,7 +519,7 @@ bool compressing = data.compression && role == responder && redirect_to.empty() // if there is a redirect or a file to send then we do not send a content return; - if( header == h_200 && role == authorizer && is_item && item.static_auth != Item::static_none ) + if( header == h_200 && role == authorizer && is_item && item.auth != Item::auth_none ) // if there is an item and the item has 'file' storage we do not send a content return; @@ -867,21 +867,21 @@ bool Request::CanUseUpload(const Item & item, bool check_root) if( !data.mounts.pmount ) return false; - if( data.mounts.pmount->fs == Mount::simplefs && data.static_simplefs_dir.empty() ) + if( data.mounts.pmount->fs == Mount::simplefs && data.auth_simplefs_dir.empty() ) { - log << log1 << "Request: can't use upload function, static_simplefs_dir must be set in the config file" << logend; + 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.static_hashfs_dir.empty() ) + if( data.mounts.pmount->fs == Mount::hashfs && data.auth_hashfs_dir.empty() ) { - log << log1 << "Request: can't use upload function, static_hashfs_dir must be set in the config file" << logend; + log << log1 << "Request: can't use upload function, auth_hashfs_dir must be set in the config file" << logend; return false; } - if( data.static_tmp_dir.empty() ) + if( data.auth_tmp_dir.empty() ) { - log << log1 << "Request: can't use upload function, static_tmp_dir must be set in the config file" << logend; + log << log1 << "Request: can't use upload function, auth_tmp_dir must be set in the config file" << logend; return false; } @@ -943,11 +943,11 @@ bool Request::MakePathSimpleFs(std::string & path, bool create_dir) { size_t i; - path = data.static_simplefs_dir; + path = data.auth_simplefs_dir; if( path.empty() ) { - log << log1 << "Request: static_simplefs_dir is not set in the config file" << logend; + log << log1 << "Request: auth_simplefs_dir is not set in the config file" << logend; return false; } @@ -979,10 +979,10 @@ char * hash = buffer; buffer[0] = '0'; sprintf(buffer+1, "%lx", (unsigned long)id); - path = data.static_hashfs_dir; + path = data.auth_hashfs_dir; if( path.empty() ) { - log << log1 << "Request: static_hashfs_dir is not set in the config file" << logend; + log << log1 << "Request: auth_hashfs_dir is not set in the config file" << logend; return false; } diff --git a/core/requestcontroller.cpp b/core/requestcontroller.cpp index 365a2e9..3ebcdfd 100755 --- a/core/requestcontroller.cpp +++ b/core/requestcontroller.cpp @@ -161,13 +161,13 @@ bool RequestController::BaseUrlRedirect() { // authorizer - if( data.base_url_static_auth_http_host.empty() ) + if( data.base_url_auth_http_host.empty() ) return false; - if( data.base_url_static_auth_http_host == request.env_http_host ) + if( data.base_url_auth_http_host == request.env_http_host ) return false; - request.redirect_to = data.base_url_static_auth + request.env_request_uri; + request.redirect_to = data.base_url_auth + request.env_request_uri; } log << log3 << "RC: BaseUrlRedirect from: " << request.env_http_host << logend; diff --git a/html/fun_cat.html b/html/fun_cat.html index 79d2b31..a0ad277 100755 --- a/html/fun_cat.html +++ b/html/fun_cat.html @@ -1,11 +1,11 @@ [is mount_page_is "subject"][is mount_page_is "info"]<h1 class="withinfo">[else]<h1>[end][item_subject]</h1>[end] [is mount_page_is "info"][item_info][end] -[if-one item_static_auth_is_image] +[if-one item_auth_is_image] <img class="catimage" src="[item_link]/download/thumb" alt="[item_subject]"> [item_print_content] [else] - [if-no item_static_auth_is_none] + [if-no item_auth_is_none] {download}: <a href="[item_link]/download" title="[item_subject]">[item_subject]</a> [item_print_content] [else] diff --git a/html/fun_ckeditor.html b/html/fun_ckeditor.html index 2133f6c..d50cf24 100755 --- a/html/fun_ckeditor.html +++ b/html/fun_ckeditor.html @@ -34,9 +34,9 @@ <input type="hidden" name="contenttype" value="2"> [is winix_function_param_is "full"] - <script type="text/javascript">CKEDITOR.replace('itemcontent', \{filebrowserUploadUrl: '[doc_base_url][dir]upload/ckeditor_upload/', filebrowserBrowseUrl: '[doc_base_url][dir]ls/ckeditor_browse/fullscreen/', customConfig : '[doc_base_url_static_ext]/ckeditor_full.js' \});</script> + <script type="text/javascript">CKEDITOR.replace('itemcontent', \{filebrowserUploadUrl: '[doc_base_url][dir]upload/ckeditor_upload/', filebrowserBrowseUrl: '[doc_base_url][dir]ls/ckeditor_browse/fullscreen/', customConfig : '[doc_base_url_common]/ckeditor_full.js' \});</script> [else] - <script type="text/javascript">CKEDITOR.replace('itemcontent', \{filebrowserUploadUrl: '[doc_base_url][dir]upload/ckeditor_upload/', filebrowserBrowseUrl: '[doc_base_url][dir]ls/ckeditor_browse/fullscreen/', customConfig : '[doc_base_url_static_ext]/ckeditor_winix.js' \});</script> + <script type="text/javascript">CKEDITOR.replace('itemcontent', \{filebrowserUploadUrl: '[doc_base_url][dir]upload/ckeditor_upload/', filebrowserBrowseUrl: '[doc_base_url][dir]ls/ckeditor_browse/fullscreen/', customConfig : '[doc_base_url_common]/ckeditor_winix.js' \});</script> [end] [if-no user_logged] diff --git a/html/fun_ls.html b/html/fun_ls.html index c269f94..14169aa 100755 --- a/html/fun_ls.html +++ b/html/fun_ls.html @@ -8,7 +8,7 @@ <ul class="ls_browse"> [for item_tab] - <li><a href="javascript:select('[item_tab_link_static_auth]')"><img src="[item_tab_link_static_auth]" alt="[item_tab_subject]" height="120"></a></li> + <li><a href="javascript:select('[item_tab_link_auth]')"><img src="[item_tab_link_auth]" alt="[item_tab_subject]" height="120"></a></li> [end] </ul> @@ -20,23 +20,59 @@ <h1>{ls_header}</h1> [if-no item_is] - [if-one dir_childs_tab] - <ul> - [for dir_childs_tab] - <li><a href="[doc_base_url][dir][dir_childs_tab_url]">[dir_childs_tab_url]/</a></li> + + [is winix_function_param_is "l"] + + [if-one dir_childs_tab item_tab] + + <table class="withoutborder"> + [for dir_childs_tab] + <tr> + <td>[dir_childs_tab_privileges]</td> + <td>[dir_childs_tab_user]</td> + <td>[dir_childs_tab_group]</td> + <td><a href="[doc_base_url][dir][dir_childs_tab_url]">[dir_childs_tab_url]/</a></td> + </tr> + [end] + + [for item_tab] + <tr> + <td>[item_tab_privileges]</td> + <td>[item_tab_user]</td> + <td>[item_tab_group]</td> + <td><a href="[doc_base_url][dir][item_tab_url]">[item_tab_url]</a></td> + </tr> + [end] + </table> + [end] - </ul> + + [else] + + [if-one dir_childs_tab] + <ul> + [for dir_childs_tab] + <li><a href="[doc_base_url][dir][dir_childs_tab_url]">[dir_childs_tab_url]/</a></li> + [end] + </ul> + [end] + + [if-one item_tab] + <ul> + [for item_tab] + <li><a href="[doc_base_url][dir][item_tab_url]">[item_tab_url]</a></li> + [end] + </ul> + [end] + [end] - [end] + + [else] - - - [if-one item_tab] <ul> - [for item_tab] - <li><a href="[doc_base_url][dir][item_tab_url]">[item_tab_url]</a></li> - [end] + <li><a href="[doc_base_url][dir][item_url]">[item_url]</a></li> </ul> + [end] diff --git a/templates/dir.cpp b/templates/dir.cpp index 9f0c9fc..4bf5d19 100755 --- a/templates/dir.cpp +++ b/templates/dir.cpp @@ -143,6 +143,49 @@ void dir_childs_tab_url(Info & i) +void dir_childs_tab_privileges(Info & i) +{ + if( dir_childs_index < dir_childs_table.size() ) + i.out << "0" << std::setbase(8) << dir_childs_table[dir_childs_index]->privileges << std::setbase(10); +} + + +void dir_childs_tab_user(Info & i) +{ + if( dir_childs_index < dir_childs_table.size() ) + { + long user_id = dir_childs_table[dir_childs_index]->user_id; + User * puser = data.users.GetUser(user_id); + + if( puser ) + HtmlEscape(i.out, puser->name); + else + { + i.out << "~"; + + if( !dir_childs_table[dir_childs_index]->guest_name.empty() ) + HtmlEscape(i.out, dir_childs_table[dir_childs_index]->guest_name); + else + i.out << "guest"; // !! dodac do konfiga + } + } +} + + + +void dir_childs_tab_group(Info & i) +{ + if( dir_childs_index < dir_childs_table.size() ) + { + long group_id = dir_childs_table[dir_childs_index]->group_id; + Group * pgroup = data.groups.GetGroup(group_id); + + if( pgroup ) + HtmlEscape(i.out, pgroup->name); + else + i.out << group_id; + } +} @@ -178,7 +221,6 @@ void dir_tab_link(Info & i) } - static Item dir_last_default_item; static size_t dir_last_default_item_reqid = 0; diff --git a/templates/doc.cpp b/templates/doc.cpp index 36a1148..f9eeb36 100755 --- a/templates/doc.cpp +++ b/templates/doc.cpp @@ -57,6 +57,11 @@ void doc_base_url(Info & i) } +void doc_base_url_auth(Info & i) +{ + i.out << data.base_url_auth; +} + void doc_base_url_static(Info & i) { @@ -64,17 +69,12 @@ void doc_base_url_static(Info & i) } -void doc_base_url_static_ext(Info & i) +void doc_base_url_common(Info & i) { - i.out << data.base_url_static_ext; + i.out << data.base_url_common; } -void doc_base_url_static_auth(Info & i) -{ - i.out << data.base_url_static_auth; -} - void doc_current_url(Info & i) { diff --git a/templates/item.cpp b/templates/item.cpp index 2f01aad..557267a 100755 --- a/templates/item.cpp +++ b/templates/item.cpp @@ -168,15 +168,15 @@ void item_link(Info & i) -void item_static_auth_is_none(Info & i) +void item_auth_is_none(Info & i) { - i.result = request.item.static_auth == Item::static_none; + i.result = request.item.auth == Item::auth_none; } -void item_static_auth_is_image(Info & i) +void item_auth_is_image(Info & i) { - i.result = request.item.static_auth == Item::static_image; + i.result = request.item.auth == Item::auth_image; } @@ -427,7 +427,7 @@ void item_tab_print_content(Info & i) void item_tab_privileges(Info & i) { if( item_index < request.item_table.size() ) - i.out << std::setbase(8) << request.item_table[item_index].privileges << std::setbase(10); + i.out << "0" << std::setbase(8) << request.item_table[item_index].privileges << std::setbase(10); } @@ -464,11 +464,11 @@ void item_tab_link(Info & i) } -void item_tab_link_static_auth(Info & i) +void item_tab_link_auth(Info & i) { if( item_index < request.item_table.size() ) { - HtmlEscape(i.out, data.base_url_static_auth); + HtmlEscape(i.out, data.base_url_auth); item_tab_dir(i); item_tab_url(i); } @@ -515,6 +515,21 @@ void item_tab_user(Info & i) } +void item_tab_group(Info & i) +{ + if( item_index < request.item_table.size() ) + { + long group_id = request.item_table[item_index].group_id; + Group * pgroup = data.groups.GetGroup(group_id); + + if( pgroup ) + HtmlEscape(i.out, pgroup->name); + else + i.out << group_id; + } +} + + void item_tab_date_creation(Info & i) { if( item_index < request.item_table.size() ) diff --git a/templates/templates.cpp b/templates/templates.cpp index d9c0029..befe14d 100755 --- a/templates/templates.cpp +++ b/templates/templates.cpp @@ -173,9 +173,9 @@ void Templates::CreateFunctions() */ functions.Insert("doc_title", doc_title); functions.Insert("doc_base_url", doc_base_url); + functions.Insert("doc_base_url_auth", doc_base_url_auth); functions.Insert("doc_base_url_static", doc_base_url_static); - functions.Insert("doc_base_url_static_ext", doc_base_url_static_ext); - functions.Insert("doc_base_url_static_auth", doc_base_url_static_auth); + functions.Insert("doc_base_url_common", doc_base_url_common); functions.Insert("doc_current_url", doc_current_url); functions.Insert("doc_is_error", doc_is_error); functions.Insert("doc_status", doc_status); @@ -198,8 +198,8 @@ void Templates::CreateFunctions() functions.Insert("item_url", item_url); functions.Insert("item_url_is", item_url_is); functions.Insert("item_link", item_link); - functions.Insert("item_static_auth_is_none", item_static_auth_is_none); - functions.Insert("item_static_auth_is_image", item_static_auth_is_image); + functions.Insert("item_auth_is_none", item_auth_is_none); + functions.Insert("item_auth_is_image", item_auth_is_image); functions.Insert("item_can_read", item_can_read); functions.Insert("item_can_write", item_can_write); @@ -235,10 +235,11 @@ void Templates::CreateFunctions() functions.Insert("item_tab_dir", item_tab_dir); functions.Insert("item_tab_url", item_tab_url); functions.Insert("item_tab_link", item_tab_link); - functions.Insert("item_tab_link_static_auth", item_tab_link_static_auth); + functions.Insert("item_tab_link_auth", item_tab_link_auth); functions.Insert("item_tab_can_read", item_tab_can_read); functions.Insert("item_tab_info", item_tab_info); functions.Insert("item_tab_user", item_tab_user); + functions.Insert("item_tab_group", item_tab_group); functions.Insert("item_tab_date_creation", item_tab_date_creation); functions.Insert("item_tab_date_modification", item_tab_date_modification); functions.Insert("item_tab_date_creation_nice", item_tab_date_creation_nice); @@ -250,20 +251,23 @@ void Templates::CreateFunctions() /* dir */ - functions.Insert("dir", dir); - functions.Insert("dir_without_slash", dir_without_slash); - functions.Insert("dir_can_read_exec", dir_can_read_exec); - functions.Insert("dir_can_write", dir_can_write); - functions.Insert("dir_can_remove", dir_can_remove); - functions.Insert("dir_can_use_emacs", dir_can_use_emacs); - functions.Insert("dir_can_use_mkdir", dir_can_use_mkdir); + functions.Insert("dir", dir); + functions.Insert("dir_without_slash", dir_without_slash); + functions.Insert("dir_can_read_exec", dir_can_read_exec); + functions.Insert("dir_can_write", dir_can_write); + functions.Insert("dir_can_remove", dir_can_remove); + functions.Insert("dir_can_use_emacs", dir_can_use_emacs); + functions.Insert("dir_can_use_mkdir", dir_can_use_mkdir); - functions.Insert("dir_childs_tab", dir_childs_tab); - functions.Insert("dir_childs_tab_url", dir_childs_tab_url); + functions.Insert("dir_childs_tab", dir_childs_tab); + functions.Insert("dir_childs_tab_url", dir_childs_tab_url); + functions.Insert("dir_childs_tab_privileges", dir_childs_tab_privileges); + functions.Insert("dir_childs_tab_user", dir_childs_tab_user); + functions.Insert("dir_childs_tab_group", dir_childs_tab_group); - functions.Insert("dir_tab", dir_tab); - functions.Insert("dir_tab_url", dir_tab_url); - functions.Insert("dir_tab_link", dir_tab_link); + functions.Insert("dir_tab", dir_tab); + functions.Insert("dir_tab_url", dir_tab_url); + functions.Insert("dir_tab_link", dir_tab_link); functions.Insert("dir_last_default_item_dir", dir_last_default_item_dir); functions.Insert("dir_last_default_item_url", dir_last_default_item_url); diff --git a/templates/templates.h b/templates/templates.h index 5ddca56..f876ab5 100755 --- a/templates/templates.h +++ b/templates/templates.h @@ -86,9 +86,9 @@ namespace TemplatesFunctions */ void doc_title(Info & i); void doc_base_url(Info & i); + void doc_base_url_auth(Info & i); void doc_base_url_static(Info & i); - void doc_base_url_static_ext(Info & i); - void doc_base_url_static_auth(Info & i); + void doc_base_url_common(Info & i); void doc_current_url(Info & i); void doc_is_error(Info & i); void doc_status(Info & i); @@ -112,8 +112,8 @@ namespace TemplatesFunctions void item_url(Info & i); void item_url_is(Info & i); void item_link(Info & i); - void item_static_auth_is_none(Info & i); - void item_static_auth_is_image(Info & i); + void item_auth_is_none(Info & i); + void item_auth_is_image(Info & i); void item_can_read(Info & i); void item_can_write(Info & i); void item_can_remove(Info & i); @@ -148,10 +148,11 @@ namespace TemplatesFunctions void item_tab_dir(Info & i); void item_tab_url(Info & i); void item_tab_link(Info & i); - void item_tab_link_static_auth(Info & i); + void item_tab_link_auth(Info & i); void item_tab_can_read(Info & i); void item_tab_info(Info & i); void item_tab_user(Info & i); + void item_tab_group(Info & i); void item_tab_date_creation(Info & i); void item_tab_date_modification(Info & i); void item_tab_date_creation_nice(Info & i); @@ -173,6 +174,9 @@ namespace TemplatesFunctions void dir_childs_tab(Info & i); void dir_childs_tab_url(Info & i); + void dir_childs_tab_privileges(Info & i); + void dir_childs_tab_user(Info & i); + void dir_childs_tab_group(Info & i); void dir_tab(Info & i); void dir_tab_url(Info & i);