changed organization of static files

removed: item.auth item.auth_path
added:   item.file_path, item.file_fs, item.file_type
now the path to a static file is a relative path
added: thumbnails (not finished yet)
fixed: db didn't correctly return the number of deleted items /DelItem() method/




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@696 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2010-12-10 21:07:01 +00:00
parent 9b29cce1a4
commit 36c8822e6c
41 changed files with 435 additions and 364 deletions

View File

@ -5,9 +5,11 @@ CXX = g++
endif
ifndef CXXFLAGS
CXXFLAGS = -fPIC -Wall -pedantic -O2 -I/usr/local/include -I/home/tomek/roboczy/winix -I/home/tomek/roboczy/ezc/src -L/usr/local/lib -DEZC_USE_WINIX_LOGGER
CXXFLAGS = -fPIC -Wall -pedantic -O2 -I/usr/local/include -I/home/tomek/roboczy/winix -I/home/tomek/roboczy/ezc/src -L/usr/local/lib -I/usr/local/include/ImageMagick -DEZC_USE_WINIX_LOGGER
endif
export CXX
export CXXFLAGS
@ -26,7 +28,7 @@ winix: FORCE
@cd plugins/stats ; $(MAKE) -e
@cd plugins/ticket ; $(MAKE) -e
@cd ../ezc/src ; $(MAKE) -e
$(CXX) -shared -o winix.so $(CXXFLAGS) core/*.o db/*.o functions/*.o templates/*.o notify/*.o ../ezc/src/ezc.a -lfcgi -lpq -lz -lpthread -lfetch
$(CXX) -shared -o winix.so $(CXXFLAGS) core/*.o db/*.o functions/*.o templates/*.o notify/*.o ../ezc/src/ezc.a -lfcgi -lpq -lz -lpthread -lfetch `MagickWand-config --ldflags --libs`
@cd main ; $(MAKE) -e
# use the full path with winix.so
$(CXX) -o winix $(CXXFLAGS) main/*.o /home/tomek/roboczy/winix/winix.so

View File

@ -7,6 +7,7 @@
*
*/
#include "wand/MagickWand.h"
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
@ -142,17 +143,24 @@ bool App::Init()
templates.ReadTemplates();
// init notify after templates (it uses locales from templates)
system.notify.ReadTemplates();
session_manager.LoadSessions();
CreateStaticTree();
MagickWandGenesis();
plugin.Call(WINIX_PLUGIN_INIT);
return true;
}
void App::Uninit()
{
MagickWandTerminus();
}
void App::Close()
{
@ -165,30 +173,14 @@ void App::Close()
bool App::BaseUrlRedirect()
{
if( request.role == Request::responder )
{
if( config.base_url_http_host.empty() )
return false;
if( Equal(config.base_url_http_host.c_str(), request.env_http_host) )
return false;
if( config.base_url_http_host.empty() )
return false;
if( Equal(config.base_url_http_host.c_str(), request.env_http_host) )
return false;
request.redirect_to = config.base_url;
AssignString(request.env_request_uri, request.redirect_to, false);
}
else
{
// authorizer
if( config.base_url_auth_http_host.empty() )
return false;
if( Equal(config.base_url_auth_http_host.c_str(), request.env_http_host) )
return false;
request.redirect_to = config.base_url_auth;
AssignString(request.env_request_uri, request.redirect_to, false);
}
request.redirect_to = config.base_url;
AssignString(request.env_request_uri, request.redirect_to, false);
log << log3 << "RC: BaseUrlRedirect from: " << request.env_http_host << logend;
@ -294,7 +286,7 @@ bool sent = false;
return;
if( request.is_item && request.item.auth == Item::auth_none &&
if( request.is_item && request.item.file_type == WINIX_ITEM_FILETYPE_NONE &&
request.item.content_type == Item::ct_raw && request.status == WINIX_ERR_OK && request.function )
{
if( request.function == &functions.fun_cat )
@ -669,7 +661,7 @@ bool App::CanSendContent(Header header)
// if there is a redirect or a file to send then we do not send a content
return false;
if( header == h_200 && request.role == Request::authorizer && request.is_item && request.item.auth != Item::auth_none )
if( header == h_200 && request.role == Request::authorizer && request.is_item && request.item.file_type != WINIX_ITEM_FILETYPE_NONE )
// if there is an item and the item has 'file' storage we do not send a content
return false;
@ -1063,3 +1055,21 @@ sigset_t set;
void App::CreateStaticTree()
{
if( config.upload_dir.empty() )
{
log << log1 << "App: config: upload_dir not set, you are not allowed to upload static content" << logend;
return;
}
CreateDirs(L"/", config.upload_dir.c_str(), config.upload_dirs_chmod);
CreateDirs(config.upload_dir.c_str(), L"simplefs/normal", config.upload_dirs_chmod);
CreateDirs(config.upload_dir.c_str(), L"simplefs/thumb", config.upload_dirs_chmod);
CreateDirs(config.upload_dir.c_str(), L"hashfs/normal", config.upload_dirs_chmod);
CreateDirs(config.upload_dir.c_str(), L"hashfs/thumb", config.upload_dirs_chmod);
CreateDirs(config.upload_dir.c_str(), L"tmp", config.upload_dirs_chmod);
}

View File

@ -49,6 +49,7 @@ public:
bool InitFCGI();
bool DropPrivileges();
bool Init();
void Uninit();
void Start();
void Close();
void LogUserGroups();
@ -166,6 +167,8 @@ private:
static void * SpecialThreadForSignals(void*);
void FetchPageOnExit();
void CreateStaticTree();
// !! dodac do session managera?
time_t last_sessions_save;
};

View File

@ -109,10 +109,13 @@ void Config::AssignValues(bool stdout_is_closed)
log_db_query = Bool(L"log_db_query", false);
log_plugin_call = Bool(L"log_plugin_call", false);
post_file_max = Size(L"post_file_max", 8388608); // 8 MB
auth_simplefs_dir = Text(L"auth_simplefs_dir");
auth_hashfs_dir = Text(L"auth_hashfs_dir");
auth_tmp_dir = Text(L"auth_tmp_dir");
post_file_max = Size(L"post_file_max", 8388608); // 8 MB
upload_dir = Text(L"upload_dir");
upload_dirs_chmod = Int(L"upload_dirs_chmod", 0750);
upload_files_chmod = Int(L"upload_files_chmod", 0640);
create_thumb = Bool(L"create_thumb", false); // !! will be true
thumb_cx = Size(L"thumb_cx", 150);
thumb_cy = Size(L"thumb_cy", 150);
templates_dir = Text(L"templates_dir");
templates_dir_default = Text(L"templates_dir_default");
@ -131,13 +134,11 @@ void Config::AssignValues(bool stdout_is_closed)
base_server = Text(L"base_server");
base_url = Text(L"base_url");
base_url_auth = Text(L"base_url_auth");
base_url_static = Text(L"base_url_static");
base_url_common = Text(L"base_url_common");
NoLastSlash(base_server);
NoLastSlash(base_url);
NoLastSlash(base_url_auth);
NoLastSlash(base_url_static);
NoLastSlash(base_url_common);
@ -187,7 +188,6 @@ void Config::AssignValues(bool stdout_is_closed)
void Config::SetAdditionalVariables()
{
SetHttpHost(base_url, base_url_http_host);
SetHttpHost(base_url_auth, base_url_auth_http_host);
if( html_filter_orphans_lang_str == "pl" )
html_filter_orphans_lang = HTMLFilter::lang_pl;

View File

@ -186,13 +186,28 @@ public:
// 0 - not used
size_t post_file_max;
// directories for static files
std::wstring auth_simplefs_dir;
std::wstring auth_hashfs_dir;
// directory for static files
std::wstring upload_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::wstring auth_tmp_dir;
// chmod of newly created directories (under upload_dir)
// default: 0750
int upload_dirs_chmod;
// chmod of newly created files (under upload_dir)
// default: 0640
int upload_files_chmod;
// create a thumbnail from an image
// default: false (!!will be true)
bool create_thumb;
// width of thumbnails
// default: 150
size_t thumb_cx;
// height of thumbnails
// default: 150
size_t thumb_cy;
// locale: en, pl
// default: en
@ -210,9 +225,6 @@ public:
// the main address of the site (e.g. http://www.someserver.com)
std::wstring base_url;
// static content authorized by winix
std::wstring base_url_auth;
// static content not authorized by winix
std::wstring base_url_static;
@ -265,7 +277,6 @@ public:
// set by SetAdditionalVariables()
// without the first part http:// (or https://) or the whole string is empty
std::wstring base_url_http_host;
std::wstring base_url_auth_http_host;
Config();

View File

@ -54,10 +54,13 @@ void Item::Clear()
content_id = -1;
auth = auth_none;
auth_path.clear();
file_path.clear();
file_fs = -1;
file_type = WINIX_ITEM_FILETYPE_NONE;
html_template.clear();
SetDateToNow();
}

View File

@ -13,6 +13,11 @@
#include <string>
#define WINIX_ITEM_FILETYPE_NONE 0
#define WINIX_ITEM_FILETYPE_IMAGE 1
#define WINIX_ITEM_FILETYPE_DOCUMENT 2
#define WINIX_ITEM_FILETYPE_UNKNOWN 3
struct Item
{
@ -67,17 +72,25 @@ long default_item;
// external static file authorized by winix
/*
enum Auth
{
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 */
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
};
Auth auth;
std::wstring auth_path; // path to a file (if auth!=auth_none)
*/
// static file (if exists)
std::wstring file_path; // relative file path
int file_fs; // file system type where the file was saved
int file_type; // file type (none, image, doc, etc)
std::wstring html_template;

View File

@ -12,6 +12,7 @@
#include "misc.h"
#include "log.h"
#include "templates/templates.h"
#include "utf8.h"
int Toi(const std::string & str, int base)
@ -621,11 +622,12 @@ bool IsFile(const wchar_t * file)
struct stat sb;
static std::string afile;
AssignString(file, afile); // or it can be UTF-8 used
Ezc::WideToUTF8(file, afile);
return (stat(afile.c_str(), &sb) == 0);
}
bool IsFile(const std::wstring & file)
{
return IsFile(file.c_str());
@ -638,17 +640,11 @@ static std::string adir;
if( !IsFile(dir) )
{
AssignString(dir, adir);
Ezc::WideToUTF8(dir, adir);
if( mkdir(adir.c_str(), priv) < 0 )
{
log << log1 << "Can't create a directory on fs: " << adir;
if( !Equal(dir, adir.c_str()) )
log << " original name was: " << dir;
log << logend;
log << log1 << "Can't create a directory on fs: " << adir << logend;
return false;
}
}
@ -666,7 +662,7 @@ bool CreateDir(const std::wstring & dir, int priv)
// creating directories (can be more than one)
// 'dirs' can begin with a slash (will be skipped)
bool CreateDirs(const wchar_t * base_dir, const wchar_t * dirs, int priv)
bool CreateDirs(const wchar_t * base_dir, const wchar_t * dirs, int priv, bool skip_last)
{
static std::wstring temp;
const wchar_t * p = dirs;
@ -688,11 +684,12 @@ const wchar_t * p = dirs;
break;
// taking the name
for( ; *p && *p!='/' ; ++p )
for( ; *p!=0 && *p!='/' ; ++p )
temp += *p;
if( !CreateDir(temp.c_str(), priv) )
return false;
if( !skip_last || *p!=0 )
if( !CreateDir(temp.c_str(), priv) )
return false;
temp += '/';
}
@ -702,9 +699,9 @@ return true;
bool CreateDirs(const std::wstring & base_dir, const std::wstring & dirs, int priv)
bool CreateDirs(const std::wstring & base_dir, const std::wstring & dirs, int priv, bool skip_last)
{
return CreateDirs(base_dir.c_str(), dirs.c_str(), priv);
return CreateDirs(base_dir.c_str(), dirs.c_str(), priv, skip_last);
}
@ -736,8 +733,8 @@ bool CopyFile(const wchar_t * src, const wchar_t * dst)
static std::string asrc, adst;
FILE * in, * out;
AssignString(src, asrc);
AssignString(dst, adst);
Ezc::WideToUTF8(src, asrc);
Ezc::WideToUTF8(dst, adst);
in = fopen(asrc.c_str(), "rb");
@ -778,7 +775,7 @@ bool RemoveFile(const wchar_t * file)
{
static std::string afile;
AssignString(file, afile);
Ezc::WideToUTF8(file, afile);
return unlink(afile.c_str()) == 0;
}
@ -795,8 +792,8 @@ bool RenameFile(const wchar_t * from, const wchar_t * to)
{
static std::string afrom, ato;
AssignString(from, afrom);
AssignString(to, ato);
Ezc::WideToUTF8(from, afrom);
Ezc::WideToUTF8(to, ato);
return rename(afrom.c_str(), ato.c_str()) == 0;
}
@ -835,7 +832,7 @@ return name + i + 1;
}
Item::Auth SelectFileType(const wchar_t * file_name)
int SelectFileType(const wchar_t * file_name)
{
const wchar_t * ext = GetFileExt(file_name);
@ -849,7 +846,7 @@ Item::Auth SelectFileType(const wchar_t * file_name)
EqualNoCase(ext, L"gif") ||
EqualNoCase(ext, L"bmp") ||
EqualNoCase(ext, L"png") )
return Item::auth_image;
return WINIX_ITEM_FILETYPE_IMAGE;
if( EqualNoCase(ext, L"pdf") ||
EqualNoCase(ext, L"doc") ||
@ -857,9 +854,9 @@ Item::Auth SelectFileType(const wchar_t * file_name)
EqualNoCase(ext, L"txt") ||
EqualNoCase(ext, L"ods") ||
EqualNoCase(ext, L"odt") )
return Item::auth_document;
return WINIX_ITEM_FILETYPE_DOCUMENT;
return Item::auth_other;
return WINIX_ITEM_FILETYPE_UNKNOWN;
}

View File

@ -397,8 +397,11 @@ bool IsFile(const wchar_t * file);
bool IsFile(const std::wstring & file);
bool CreateDir(const wchar_t * dir, int priv);
bool CreateDir(const std::wstring & dir, int priv);
bool CreateDirs(const wchar_t * base_dir, const wchar_t * dirs, int priv);
bool CreateDirs(const std::wstring & base_dir, const std::wstring & dirs, int priv);
// creating directories (dirs) under base_dir (base_dir must exist)
// if skip_last == true then last part from dir is treated as a file (the last directory is not created)
bool CreateDirs(const wchar_t * base_dir, const wchar_t * dirs, int priv = 0755, bool skip_last = false);
bool CreateDirs(const std::wstring & base_dir, const std::wstring & dirs, int priv = 0755, bool skip_last = false);
bool CopyFile(FILE * in, FILE * out);
bool CopyFile(const wchar_t * src, const wchar_t * dst);
@ -411,7 +414,7 @@ bool RenameFile(const wchar_t * from, const wchar_t * to);
bool RenameFile(const std::wstring & from, const std::wstring & to);
const wchar_t * GetFileExt(const wchar_t * name);
Item::Auth SelectFileType(const wchar_t * file_name);
int SelectFileType(const wchar_t * file_name);
time_t Time(const tm & par);
time_t Time(const tm * par);

View File

@ -476,29 +476,30 @@ void PostMultiParser::CreateTmpFile()
wchar_t buf[1024];
size_t buf_len = sizeof(buf)/sizeof(wchar_t);
if( config->auth_tmp_dir.empty() )
if( config->upload_dir.empty() )
{
log << log1 << "PMP: auth_tmp_dir is not set in the config" << logend;
log << log1 << "PMP: upload_dir is not set in the config" << logend;
err = WINIX_ERR_CANT_CREATE_FILE;
return;
}
swprintf(buf, buf_len, L"%ls/winix_%u_%d_%u", config->auth_tmp_dir.c_str(), (unsigned)getpid(), tmp_filename_postfix, rand());
swprintf(buf, buf_len, L"%ls/tmp/winix_%u_%d_%u", config->upload_dir.c_str(), (unsigned)getpid(), tmp_filename_postfix, rand());
tmp_filename_postfix += 1;
AssignString(buf, atmp_filename);
AssignString(atmp_filename, tmp_filename); // this make sure that the names are exactly the same
tmp_filename = buf;
Ezc::WideToUTF8(tmp_filename, atmp_filename);
tmp_file.open(atmp_filename.c_str(), std::ios_base::binary | std::ios_base::out);
// !! dodac ustawienie chmod config.upload_files_chmod dla tymczasowego pliku
if( !tmp_file )
{
log << log1 << "PMP: can't create a temporary file: " << tmp_filename << logend;
log << log1 << "PMP: can't create a temporary file: " << atmp_filename << logend;
err = WINIX_ERR_CANT_CREATE_FILE;
return;
}
log << log3 << "PMP: using temporary file for the content: " << tmp_filename << logend;
log << log3 << "PMP: using temporary file for the content: " << atmp_filename << logend;
}

View File

@ -392,31 +392,30 @@ return puser->IsMemberOf(group);
bool System::MakePathSimpleFs(std::wstring & path, long dir_id, bool create_dir)
// the path depends on parent_id
bool System::CreateNewFileSimpleFs(Item & item)
{
if( config->auth_simplefs_dir.empty() )
bool res = dirs.MakePath(item.parent_id, item.file_path);
if( res )
{
log << log1 << "System: auth_simplefs_dir is not set in the config file" << logend;
return false;
if( !item.file_path.empty() && item.file_path[0] == '/' )
item.file_path.erase(0, 1);
}
else
{
log << log1 << "System: CreateNewFileSimpleFs: can't create a path to item.id: " << item.id
<< ", item.parent_id: " << item.parent_id << logend;
}
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;
return res;
}
// the path depends on id
bool System::MakePathHashFs(std::wstring & path, long id, bool create_dir)
bool System::CreateNewFileHashFs(Item & item)
{
wchar_t buffer[50];
wchar_t * hash = buffer;
@ -424,79 +423,112 @@ size_t buffer_len = sizeof(buffer)/sizeof(wchar_t);
// get 'id' as hexadecimal
buffer[0] = '0';
swprintf(buffer+1, buffer_len, L"%lx", (unsigned long)id);
swprintf(buffer+1, buffer_len, L"%lx", (unsigned long)item.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 += '/';
item.file_path.clear();
// make sure that the length is even
if( (wcslen(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];
item.file_path += hash[i];
item.file_path += hash[i+1];
if( hash[i+2] != 0 )
{
if( create_dir && !CreateDir(path, 0755) )
return false;
path += '/';
}
item.file_path += '/';
}
// one character more to make sure the path is unique
// (we can have a directory without the character)
path += '_';
item.file_path += '_';
return true;
}
// making a complete path to a static file
bool System::MakePath(const Item & item, std::wstring & path, bool create_dir)
// creating item.file_path and item.file_fs
// you should set file_type yourself
// this method uses: item.id, item.url, item.parent_id (for selecting a mountpoint)
bool System::CreateNewFile(Item & item)
{
bool res;
if( item.type != Item::file )
{
log << log1 << "System: CreateNewFile: the item should be a file" << logend;
return false;
}
Mount * pmount = mounts.CalcMount(item.parent_id);
if( !pmount || pmount->fs == mounts.MountFsSimplefs() )
if( !pmount || pmount->fs != mounts.MountFsHashfs() )
{
res = MakePathSimpleFs(path, item.parent_id, create_dir);
res = CreateNewFileSimpleFs(item);
item.file_fs = mounts.MountFsSimplefs();
}
else
{
res = MakePathHashFs(path, item.id, create_dir);
res = CreateNewFileHashFs(item);
item.file_fs = mounts.MountFsHashfs();
}
if( res )
path += item.url;
item.file_path += item.url;
else
path.clear();
item.file_path.clear();
return res;
}
bool System::MakePath(Item & item, bool create_dir)
// making a global file path
// you should call CreateNewFile before
bool System::MakeFilePath(const Item & item, std::wstring & path, bool thumb, bool create_dir, int chmod)
{
return MakePath(item, item.auth_path, create_dir);
path.clear();
if( config->upload_dir.empty() )
{
log << log1 << "System: MakePath: upload_dir is not set in the config file" << logend;
return false;
}
if( item.file_path.empty() || item.file_type == WINIX_ITEM_FILETYPE_NONE )
{
log << log1 << "System: MakePath: this item has not a static file" << logend;
return false;
}
path = config->upload_dir;
if( item.file_fs == mounts.MountFsHashfs() )
path += L"/hashfs";
else
path += L"/simplefs";
if( thumb )
path += L"/thumb";
else
path += L"/normal";
if( create_dir && !CreateDirs(path, item.file_path, chmod, true) )
return false;
path += '/';
path += item.file_path;
return true;
}
Error System::AddFile(Item & item, int notify_code)
{
if( item.type == Item::dir )

View File

@ -85,8 +85,9 @@ public:
bool IsMemberOfGroup(long user_id, const wchar_t * group_name);
bool MakePath(const Item & item, std::wstring & path, bool create_dir);
bool MakePath(Item & item, bool create_dir); // output path is: item.auth_path
// creating item.file_path and item.file_fs (the mountpoint where the item is located)
bool CreateNewFile(Item & item);
bool MakeFilePath(const Item & item, std::wstring & path, bool thumb = false, bool create_dir = false, int chmod = 0755);
Error AddFile(Item & item, int notify_code = 0);
Error EditFile(Item & item, bool with_url = true, int notify_code = 0);
@ -105,8 +106,8 @@ private:
Synchro * synchro;
std::wstring path;
bool MakePathSimpleFs(std::wstring & path, long dir_id, bool create_dir);
bool MakePathHashFs(std::wstring & path, long id, bool create_dir);
bool CreateNewFileSimpleFs(Item & item);
bool CreateNewFileHashFs(Item & item);
};

View File

@ -239,7 +239,7 @@ Error Db::AddItemIntoItem(Item & item)
{
query.Clear();
query << R("insert into core.item (user_id, modification_user_id, group_id, privileges, "
"date_creation, date_modification, type, parent_id, content_id, auth, auth_path, "
"date_creation, date_modification, type, parent_id, content_id, file_path, file_fs, file_type, "
"default_item, subject, guest_name, template, url) values (")
<< item.user_id
<< item.modification_user_id
@ -250,8 +250,9 @@ Error Db::AddItemIntoItem(Item & item)
<< static_cast<int>(item.type)
<< item.parent_id
<< item.content_id
<< static_cast<int>(item.auth)
<< item.auth_path
<< item.file_path
<< item.file_fs
<< item.file_type
<< item.default_item
<< item.subject
<< item.guest_name
@ -346,7 +347,7 @@ Error Db::EditItemInItem(Item & item, bool with_url)
query.Clear();
query << R("update core.item set (user_id, modification_user_id, group_id, privileges, "
"date_creation, date_modification, type, default_item, parent_id, subject, "
"guest_name, auth, auth_path, template");
"guest_name, file_path, file_fs, file_type, template");
if( with_url )
query << R(", url");
@ -363,8 +364,9 @@ Error Db::EditItemInItem(Item & item, bool with_url)
<< item.parent_id
<< item.subject
<< item.guest_name
<< static_cast<int>(item.auth)
<< item.auth_path
<< item.file_path
<< item.file_fs
<< item.file_type
<< item.html_template;
if( with_url )
@ -626,7 +628,7 @@ PGresult * Db::GetItemsQuery(const DbItemQuery & iq, bool skip_other_sel)
if( iq.sel_url ) query << R(" ,url");
if( iq.sel_type ) query << R(" ,type");
if( iq.sel_default_item ) query << R(" ,default_item");
if( iq.sel_auth ) query << R(" ,auth, auth_path");
if( iq.sel_file ) query << R(" ,file_path, file_fs, file_type");
if( iq.sel_html_template ) query << R(" ,template");
}
@ -635,7 +637,7 @@ PGresult * Db::GetItemsQuery(const DbItemQuery & iq, bool skip_other_sel)
if( iq.sel_content )
query << R(" left join core.content on item.content_id = content.id");
if( iq.where_id || iq.where_parent_id || iq.where_type || iq.where_auth )
if( iq.where_id || iq.where_parent_id || iq.where_type || iq.where_file_type )
{
query << R(" where ");
const char * add_and = " and ";
@ -645,16 +647,16 @@ PGresult * Db::GetItemsQuery(const DbItemQuery & iq, bool skip_other_sel)
if( iq.where_parent_id ){ query << R(if_and) << R("parent_id=") << iq.parent_id ; if_and = add_and; }
if( iq.where_type ) { query << R(if_and) << R("type=") << int(iq.type) ; if_and = add_and; }
if( iq.where_auth )
if( iq.where_file_type )
{
query << R(if_and) << R("auth");
query << R(if_and) << R("file_type");
if( iq.auth_equal )
if( iq.file_type_equal )
query << R("=");
else
query << R("!=");
query << static_cast<int>(iq.auth);
query << iq.file_type;
if_and = add_and;
}
}
@ -1038,7 +1040,7 @@ return result;
Error Db::EditAuthById(Item & item, long id)
Error Db::EditFileById(Item & item, long id)
{
PGresult * r = 0;
Error result = WINIX_ERR_OK;
@ -1046,12 +1048,11 @@ Error Db::EditAuthById(Item & item, long id)
try
{
query.Clear();
query << R("update core.item set (auth, auth_path) = (")
<< static_cast<int>(item.auth)
<< item.auth_path
<< R(") where id=")
<< id
<< R(";");
query << R("update core.item set (file_path, file_fs, file_type) = (")
<< item.file_path
<< item.file_fs
<< item.file_type
<< R(") where id=") << id << R(";");
r = AssertQuery(query);
AssertResult(r, PGRES_COMMAND_OK);
@ -1142,8 +1143,8 @@ return result;
bool Db::DelItemDelItem(const Item & item)
{
long rows = 0;
PGresult * r = 0;
long affected = 0;
PGresult * r = 0;
try
{
@ -1155,7 +1156,7 @@ bool Db::DelItemDelItem(const Item & item)
r = AssertQuery(query);
AssertResult(r, PGRES_COMMAND_OK);
long affected = AffectedRows(r);
affected = AffectedRows(r);
if( affected > 1 )
log << log1 << "Db: more than one item were deleted" << logend;
@ -1169,7 +1170,7 @@ bool Db::DelItemDelItem(const Item & item)
ClearResult(r);
return rows != 0;
return affected != 0;
}
@ -1240,9 +1241,9 @@ return result;
bool Db::DelItem(const Item & item)
{
long contents;
Error result = DelItemCountContents(item, contents);
if( result == WINIX_ERR_OK && contents == 1 )
DelItemDelContent(item);

View File

@ -63,7 +63,7 @@ public:
bool GetPriv(Item & item, long id);
Error EditPrivById(Item & item, long id);
Error EditParentUrlById(Item & item, long id);
Error EditAuthById(Item & item, long id);
Error EditFileById(Item & item, long id); // file_path, file_fs, file_type
Error DelDirById(long id);
Error EditSubjectById(Item & item, long id);

View File

@ -30,10 +30,11 @@ void DbItemColumns::SetColumns(PGresult * r)
content = PQfnumber(r, "content");
content_type = PQfnumber(r, "content_type");
guest_name = PQfnumber(r, "guest_name");
auth = PQfnumber(r, "auth");
auth_path = PQfnumber(r, "auth_path");
html_template = PQfnumber(r, "template");
modification_user_id = PQfnumber(r, "modification_user_id");
file_path = PQfnumber(r, "file_path");
file_fs = PQfnumber(r, "file_fs");
file_type = PQfnumber(r, "file_type");
}
@ -55,10 +56,11 @@ void DbItemColumns::SetItem(PGresult * r, long row, Item & item)
if( content != -1 ) item.content = DbBase::AssertValueWide(r, row, content);
if( content_type != -1 ) item.content_type = static_cast<Item::ContentType>( DbBase::AssertValueInt(r, row, content_type) );
if( guest_name != -1 ) item.guest_name = DbBase::AssertValueWide(r, row, guest_name);
if( auth != -1 ) item.auth = static_cast<Item::Auth>( DbBase::AssertValueInt(r, row, auth) );
if( auth_path != -1 ) item.auth_path = DbBase::AssertValueWide(r, row, auth_path);
if( html_template != -1 ) item.html_template = DbBase::AssertValueWide(r, row, html_template);
if( modification_user_id != -1 ) item.modification_user_id = DbBase::AssertValueLong(r, row, modification_user_id);
if( file_path != -1 ) item.file_path = DbBase::AssertValueWide(r, row, file_path);
if( file_fs != -1 ) item.file_fs = DbBase::AssertValueInt(r, row, file_fs);
if( file_type != -1 ) item.file_type = DbBase::AssertValueInt(r, row, file_type);
}

View File

@ -34,11 +34,12 @@ struct DbItemColumns
int content;
int content_type;
int guest_name;
int auth;
int auth_path;
int modification_user_id;
int html_template;
int file_path;
int file_fs;
int file_type;
void SetColumns(PGresult * r);
void SetItem(PGresult * r, long row, Item & item);
};

View File

@ -14,15 +14,15 @@
DbItemQuery::DbItemQuery()
{
sort_asc = true;
auth_equal = true;
sort_asc = true;
file_type_equal = true;
SetAll(true, false);
id = -1;
parent_id = -1;
type = Item::none;
auth = Item::auth_none;
file_type = WINIX_ITEM_FILETYPE_NONE;
limit = 0; // limit and offset not used by default
offset = 0;
@ -43,7 +43,7 @@ void DbItemQuery::SetAllSel(bool sel)
sel_url = sel;
sel_type = sel;
sel_default_item = sel;
sel_auth = sel;
sel_file = sel;
sel_html_template = sel;
}
@ -54,7 +54,7 @@ void DbItemQuery::SetAllWhere(bool where_)
where_id = where_;
where_parent_id = where_;
where_type = where_;
where_auth = where_;
where_file_type = where_;
}
@ -91,11 +91,11 @@ void DbItemQuery::WhereType(Item::Type type_)
void DbItemQuery::WhereAuth(Item::Auth st, bool equal)
void DbItemQuery::WhereFileType(int file_t, bool equal)
{
where_auth = true;
auth = st;
auth_equal = equal;
where_file_type = true;
file_type = file_t;
file_type_equal = equal;
}

View File

@ -30,19 +30,19 @@ struct DbItemQuery
bool sel_url; // url
bool sel_type; // type (dir, file, none)
bool sel_default_item; // default_item
bool sel_auth; // auth, auth_path
bool sel_file; // file_path, file_fs, file_type
bool sel_html_template; // template
bool where_id; //
bool where_parent_id; //
bool where_type;
bool where_auth;
bool where_file_type;
long id; // if where_id is true
long parent_id; // if where_parent_id is true
Item::Type type;
Item::Auth auth;
bool auth_equal; // if true means auth should be equal
int file_type;
bool file_type_equal; // if true means file_type should be equal
bool sort_asc;
long limit;
@ -57,7 +57,7 @@ struct DbItemQuery
void WhereId(long id_);
void WhereParentId(long parent_id_);
void WhereType(Item::Type type_);
void WhereAuth(Item::Auth st, bool equal = true);
void WhereFileType(int file_t, bool equal = true);
void Limit(long l); // setting 0 turns off
void Offset(long o); // setting 0 turns off

View File

@ -79,24 +79,26 @@ return res == 0;
}
void Cp::CpAuth(Item & item)
void Cp::CpStaticFile(Item & item)
{
if( !system->MakePath(item, mv_new_path, true) )
bool res1 = system->MakeFilePath(item, old_path);
bool res2 = system->CreateNewFile(item);
bool res3 = system->MakeFilePath(item, mv_new_path, false, true, config->upload_dirs_chmod);
if( !res1 || !res2 || !res3 )
{
request->status = WINIX_ERR_PERMISSION_DENIED;
return;
}
if( CopyFile(item.auth_path, mv_new_path) )
if( CopyFile(old_path, mv_new_path) )
{
log << log1 << "Content: copied static file from: " << item.auth_path << ", to: " << mv_new_path << logend;
item.auth_path = mv_new_path;
request->status = db->EditAuthById(item, item.id);
log << log1 << "Cp: copied static file from: " << old_path << ", to: " << mv_new_path << logend;
request->status = db->EditFileById(item, item.id);
}
else
{
log << log1 << "Content: can't copy a file from: " << item.auth_path << ", to: " << mv_new_path << logend;
log << log1 << "Cp: can't copy a file from: " << old_path << ", to: " << mv_new_path << logend;
request->status = WINIX_ERR_PERMISSION_DENIED;
}
}
@ -124,8 +126,8 @@ void Cp::CpItem(Item & item, long dst_dir_id)
if( request->status == WINIX_ERR_OK )
{
if( item.auth != Item::auth_none )
CpAuth(item);
if( item.file_type != WINIX_ITEM_FILETYPE_NONE )
CpStaticFile(item);
}
}

View File

@ -38,12 +38,13 @@ private:
std::wstring mv_dir;
std::wstring mv_file;
std::wstring mv_new_path;
std::wstring old_path;
long mv_dir_id;
bool CpCheckAccessFrom();
bool CheckAccessTo(long dir_id);
bool ParseDir(long & dir_id, std::wstring & dir, std::wstring & file);
void CpAuth(Item & item);
void CpStaticFile(Item & item);
void CpSetNewAttributes(Item & item);
void CpItem(Item & item, long dst_dir_id);
void CpPrepare();

View File

@ -80,10 +80,18 @@ void Default::MakePost()
try
{
long defaultid = PostFunDefaultParsePath();
request->status = db->EditDefaultItem(request->dir_tab.back()->id, defaultid);
if( defaultid != request->dir_tab.back()->id )
{
request->status = db->EditDefaultItem(request->dir_tab.back()->id, defaultid);
if( request->status == WINIX_ERR_OK )
request->dir_tab.back()->default_item = defaultid;
if( request->status == WINIX_ERR_OK )
request->dir_tab.back()->default_item = defaultid;
}
else
{
log << "Default: skipping the same directory" << logend;
}
}
catch(const Error & e)
{

View File

@ -32,16 +32,20 @@ void Download::MakeGet()
}
if( !system->HasReadAccess(request->item) ||
request->item.auth == Item::auth_none ||
request->item.auth_path.empty() )
if( !system->HasReadAccess(request->item) ||
request->item.file_type == WINIX_ITEM_FILETYPE_NONE ||
request->item.file_path.empty() )
{
request->status = WINIX_ERR_PERMISSION_DENIED;
return;
}
request->send_as_attachment = request->IsParam(L"attachment");
request->x_sendfile = request->item.auth_path;
if( request->item.file_type == WINIX_ITEM_FILETYPE_IMAGE && config->create_thumb && request->IsParam(L"thumb") )
system->MakeFilePath(request->item, request->x_sendfile, true);
else
system->MakeFilePath(request->item, request->x_sendfile);
}

View File

@ -81,7 +81,7 @@ void FunctionParser::ParseItem()
{
request->last_item = &request->item;
if( request->role == Request::authorizer && request->item.auth == Item::auth_none )
if( request->role == Request::authorizer && request->item.file_type == WINIX_ITEM_FILETYPE_NONE )
{
log << log1 << "FP: item.url: " << url << " exists but has not a static content (authorizer role)" << logend;
request->status = WINIX_ERR_NO_ITEM;

View File

@ -232,7 +232,7 @@ void Functions::Parse()
void Functions::SetDefaultFunctionForFile()
{
if( request->item.auth != Item::auth_none )
if( request->item.file_type != WINIX_ITEM_FILETYPE_NONE )
request->function = &fun_download;
else
if( system->HasReadExecAccess(request->item) )

View File

@ -71,7 +71,7 @@ void FunThread::MakeGet()
iq.WhereParentId(request->dir_tab.back()->id);
iq.WhereType(Item::file);
iq.WhereAuth(Item::auth_none);
iq.WhereFileType(WINIX_ITEM_FILETYPE_NONE);
db->GetItems(request->item_tab, iq);
db->GetThreads(request->dir_tab.back()->id, thread_tab);

View File

@ -34,7 +34,7 @@ void Ls::MakeGet()
if( request->IsParam(L"ckeditor_browse") )
{
iq.WhereAuth(Item::auth_image);
iq.WhereFileType(WINIX_ITEM_FILETYPE_IMAGE);
db->GetItems(request->item_tab, iq);
}
else

View File

@ -146,28 +146,26 @@ return res == 0;
void Mv::MoveAuth(Item & item)
void Mv::MoveStaticFile(Item & item)
{
if( !system->MakePath(item, mv_new_path, true) )
bool res1 = system->MakeFilePath(item, old_path);
bool res2 = system->CreateNewFile(item);
bool res3 = system->MakeFilePath(item, mv_new_path, false, true, config->upload_dirs_chmod);
if( !res1 || !res2 || !res3 )
{
request->status = WINIX_ERR_PERMISSION_DENIED;
return;
}
if( RenameFile(item.auth_path, mv_new_path) )
if( RenameFile(old_path, mv_new_path) )
{
log << log1 << "Mv: moved static file from: " << item.auth_path << ", to: " << mv_new_path << logend;
item.auth_path = mv_new_path;
request->status = db->EditAuthById(item, item.id);
log << log1 << "Mv: moved static file from: " << old_path << ", to: " << mv_new_path << logend;
request->status = db->EditFileById(item, item.id);
}
else
{
int err = errno;
log << log1 << "Mv: can't move a file from: " << item.auth_path << ", to: " << mv_new_path << ", ";
log.SystemErr(err);
log << logend;
log << log1 << "Mv: can't move a file from: " << old_path << ", to: " << mv_new_path << logend;
request->status = WINIX_ERR_PERMISSION_DENIED;
}
}
@ -210,8 +208,8 @@ void Mv::MoveFile(Item & item, bool redirect)
{
log << log2 << "Mv: the file was moved to: " << mv_dir << item.url << logend;
if( item.auth != Item::auth_none )
MoveAuth(item);
if( item.file_type != WINIX_ITEM_FILETYPE_NONE )
MoveStaticFile(item);
if( redirect )
system->RedirectTo(item);
@ -227,7 +225,7 @@ DbItemQuery iq;
iq.sel_parent_id = true;
iq.sel_type = true;
iq.sel_url = true;
iq.sel_auth = true;
iq.sel_file = true;
iq.WhereParentId(request->dir_tab.back()->id);
db->GetItems(request->item_tab, iq);
@ -252,10 +250,10 @@ void Mv::MoveAuthPrepareQuery()
mv_auth_iq.sel_parent_id = true;
mv_auth_iq.sel_type = true;
mv_auth_iq.sel_url = true;
mv_auth_iq.sel_auth = true;
mv_auth_iq.sel_file = true;
mv_auth_iq.WhereType(Item::file);
mv_auth_iq.WhereAuth(Item::auth_none, false);
mv_auth_iq.WhereFileType(WINIX_ITEM_FILETYPE_NONE, false);
}
@ -274,7 +272,7 @@ void Mv::MoveAuthContentOfDir(const Item & item)
db->GetItems(mv_auth, mv_auth_iq);
for(size_t i=0 ; i<mv_auth.size() ; ++i)
MoveAuth(mv_auth[i]);
MoveStaticFile(mv_auth[i]);
mv_auth.clear();
}

View File

@ -31,6 +31,7 @@ private:
std::wstring mv_dir;
std::wstring mv_file;
std::wstring mv_new_path;
std::wstring old_path;
long mv_dir_id;
std::vector<Item> mv_auth;
DbItemQuery mv_auth_iq;
@ -40,7 +41,7 @@ private:
bool MoveCheckAccessTo(long dir_id);
bool MoveCheckMountPoints(long dir_id);
bool MoveParseDir(long & dir_id, std::wstring & dir, std::wstring & file);
void MoveAuth(Item & item);
void MoveStaticFile(Item & item);
bool MoveIsTheSameFile(const Item & item);
void MoveFile(Item & item, bool redirect = true);
void MoveContentOfDir();

View File

@ -78,10 +78,10 @@ void Rm::RemoveAuthPrepareQuery()
rm_auth_iq.sel_parent_id = true;
rm_auth_iq.sel_type = true;
rm_auth_iq.sel_auth = true;
rm_auth_iq.sel_file = true;
rm_auth_iq.WhereType(Item::file);
rm_auth_iq.WhereAuth(Item::auth_none, false);
rm_auth_iq.WhereFileType(WINIX_ITEM_FILETYPE_NONE, false);
}
@ -104,15 +104,12 @@ void Rm::RemoveAllDirs(long dir_id)
db->GetItems(request->item_tab, rm_auth_iq);
for(size_t i=0 ; i<request->item_tab.size() ; ++i)
RemoveAuth(request->item_tab[i]);
RemoveStaticFile(request->item_tab[i]);
if( db->DelDirById(dir_id) == WINIX_ERR_OK )
{
system->dirs.DelDir(dir_id);
db->RemoveThread(dir_id);
// !! tticket
// db->RemoveTicket(dir_id);
plugin.Call(WINIX_DIR_REMOVED, dir_id);
}
@ -160,29 +157,27 @@ void Rm::RemoveDir()
void Rm::RemoveAuth(Item & item)
void Rm::RemoveStaticFile(Item & item)
{
if( item.auth_path.empty() )
if( item.file_path.empty() )
{
log << log1 << "Content: can't remove a static file: auth_path is empty" << logend;
log << log1 << "Rm: can't remove a static file: file_path is empty" << logend;
return;
}
if( ::RemoveFile(item.auth_path) )
if( !system->MakeFilePath(item, path) )
return;
if( ::RemoveFile(path) )
{
log << log1 << "Content: removed static file: " << item.auth_path << logend;
item.auth_path.clear();
item.auth = Item::auth_none;
log << log1 << "Rm: removed static file: " << path << logend;
item.file_path.clear();
item.file_type = WINIX_ITEM_FILETYPE_NONE;
// we don't store it to db (will be removed or is removed already)
}
else
{
int err = errno;
log << log1 << "Content: can't remove a file: " << item.auth_path;
log.SystemErr(err);
log << logend;
log << log1 << "Rm: can't remove a file: " << path << logend;
request->status = WINIX_ERR_PERMISSION_DENIED;
}
}
@ -198,26 +193,19 @@ void Rm::RemoveFile()
request->status = WINIX_ERR_UNKNOWN_PARAM;
return;
}
if( db->DelItem( request->item ) )
{
log << log2 << "Content: deleted item: subject: " << request->item.subject << ", id: " << request->item.id << logend;
log << log2 << "Rm: deleted item: subject: " << request->item.subject << ", id: " << request->item.id << logend;
TemplatesFunctions::pattern_cacher.DeletePattern(request->item);
plugin.Call(WINIX_FILE_REMOVED, request->item.id);
if( system->mounts.pmount->type == system->mounts.MountTypeThread() )
db->EditThreadRemoveItem(request->item.parent_id);
/*
!! tticket
else
if( system->mounts.pmount->type == system->mounts.MountTypeTicket() )
db->EditTicketRemoveItem(request->item.id);
*/
if( request->item.auth != Item::auth_none )
RemoveAuth(request->item);
if( request->item.file_type != WINIX_ITEM_FILETYPE_NONE )
RemoveStaticFile(request->item);
}
else
{

View File

@ -29,13 +29,14 @@ public:
private:
DbItemQuery rm_auth_iq;
std::wstring path;
bool HasAccess(const Item & item);
void RemoveAuthPrepareQuery();
void RemoveAllDirs(long dir_id);
void RemoveAllDirs();
void RemoveDir();
void RemoveAuth(Item & item);
void RemoveStaticFile(Item & item);
void RemoveFile();
};

View File

@ -7,6 +7,7 @@
*
*/
#include "wand/MagickWand.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <cstdio>
@ -14,6 +15,7 @@
#include "upload.h"
#include "core/misc.h"
#include "functions/functions.h"
#include "utf8.h"
@ -38,21 +40,9 @@ bool Upload::HasAccess(const Item & item)
if( !system->mounts.pmount )
return false;
if( system->mounts.pmount->fs == system->mounts.MountFsSimplefs() && config->auth_simplefs_dir.empty() )
if( config->upload_dir.empty() )
{
log << log1 << "Request: can't use upload function, auth_simplefs_dir must be set in the config file" << logend;
return false;
}
if( system->mounts.pmount->fs == system->mounts.MountFsHashfs() && config->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( config->auth_tmp_dir.empty() )
{
log << log1 << "Request: can't use upload function, auth_tmp_dir must be set in the config file" << logend;
log << log1 << "Request: can't use upload function, upload_dir must be set in the config file" << logend;
return false;
}
@ -77,40 +67,78 @@ return true;
bool Upload::UploadCreatePath()
void Upload::CreateThumbnail(const Item & item)
{
if( !system->MakePath(request->item, true) )
if( !system->MakeFilePath(item, path) ||
!system->MakeFilePath(item, path_thumb, true, true, config->upload_dirs_chmod) )
return;
Ezc::WideToUTF8(path, patha);
Ezc::WideToUTF8(path_thumb, path_thumba);
MagickWand * wand = NewMagickWand();
if( MagickReadImage(wand, patha.c_str()) )
{
//log <<log1 << "images: " << MagickGetNumberImages(wand) << logend << logsavenow;
//MagickResizeImage(wand, config->images_thumb_cx, config->images_thumb_cy, CubicFilter, 0.25);
//MagickScaleImage(wand, 100, 100);
MagickThumbnailImage(wand, config->thumb_cx, config->thumb_cy);
if( MagickWriteImage(wand, path_thumba.c_str()) )
log << log3 << "Upload: created a thumbnail: " << path_thumba << logend;
}
DestroyMagickWand(wand);
}
bool Upload::UploadSaveStaticFile(const Item & item, const std::wstring & tmp_filename)
{
if( !system->MakeFilePath(item, path, false, true, config->upload_dirs_chmod) )
{
request->status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
return true;
}
void Upload::UploadSaveFile(const std::wstring & tmp_filename, const std::wstring & destination)
{
if( RenameFile(tmp_filename, destination) )
if( RenameFile(tmp_filename, path) )
{
log << log1 << "Content: uploaded a new file: " << destination << logend;
log << log1 << "Upload: uploaded a new file: " << path << logend;
return true;
}
else
{
int err = errno;
// !! skasowac takze plik z bazy danych?
log << log1 << "Content: can't move the tmp file from: " << tmp_filename << ", to: " << destination << ", ";
log.SystemErr(err);
log << logend;
log << log1 << "Upload: can't move the tmp file from: " << tmp_filename << ", to: " << path << logend;
request->status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
}
void Upload::UploadFile(Item & item, const std::wstring & tmp_filename)
{
// we should add the file beforehand to get the proper item.id
request->status = system->AddFile(item);
if( request->status == WINIX_ERR_OK )
{
if( system->CreateNewFile(item) )
{
if( UploadSaveStaticFile(item, tmp_filename) )
{
request->status = db->EditFileById(item, item.id);
if( item.file_type == WINIX_ITEM_FILETYPE_IMAGE && config->create_thumb )
CreateThumbnail(item);
}
else
{
db->DelItem(item);
}
}
}
}
bool Upload::FunUploadCheckAbuse()
{
@ -136,7 +164,6 @@ return true;
void Upload::UploadMulti()
{
request->item.Clear(); // clearing and setting date
@ -151,21 +178,12 @@ void Upload::UploadMulti()
{
const wchar_t * file_name = i->second.filename.c_str();
request->item.subject = file_name;
request->item.url = file_name;
request->item.auth = SelectFileType(file_name);
request->item.subject = file_name;
request->item.url = file_name;
request->item.file_type = SelectFileType(file_name);
functions->PrepareUrl(request->item);
request->status = system->AddFile(request->item);
if( !UploadCreatePath() )
return;
if( request->status == WINIX_ERR_OK )
{
UploadSaveFile(i->second.tmp_filename, request->item.auth_path);
request->status = db->EditAuthById(request->item, request->item.id);
}
UploadFile(request->item, i->second.tmp_filename);
}
system->RedirectToLastDir();
@ -177,14 +195,14 @@ void Upload::UploadSingle()
const std::wstring & new_subject = request->PostVar(L"subject");
const std::wstring & new_url = request->PostVar(L"url");
bool has_subject = !new_subject.empty();
bool has_url = !new_url.empty(); //(new_url && (*new_url)[0] != 0 );
bool has_url = !new_url.empty();
functions->ReadItem(request->item, Item::file); // ReadItem() changes the url if it is empty
functions->SetUser(request->item);
request->item.privileges = 0644; // !! tymczasowo
const wchar_t * file_name = request->post_file_tab.begin()->second.filename.c_str();
request->item.auth = SelectFileType(file_name);
request->item.file_type = SelectFileType(file_name);
if( !has_subject )
request->item.subject = file_name;
@ -194,19 +212,8 @@ void Upload::UploadSingle()
request->item.url = file_name;
functions->PrepareUrl(request->item);
}
request->status = system->AddFile(request->item);
// url can be changed by PostFunEmacsAdd()
if( !UploadCreatePath() )
return;
if( request->status == WINIX_ERR_OK )
{
const std::wstring & tmp_filename = request->post_file_tab.begin()->second.tmp_filename;
UploadSaveFile(tmp_filename, request->item.auth_path);
request->status = db->EditAuthById(request->item, request->item.id);
}
UploadFile(request->item, request->post_file_tab.begin()->second.tmp_filename);
if( request->status == WINIX_ERR_OK )
system->RedirectTo(request->item, L"/cat");

View File

@ -28,10 +28,14 @@ public:
private:
std::wstring path, path_thumb;
std::string patha, path_thumba;
bool HasAccess(const Item & item);
bool UploadCreatePath();
void UploadSaveFile(const std::wstring & tmp_filename, const std::wstring & destination);
void CreateThumbnail(const Item & item);
bool UploadSaveStaticFile(const Item & item, const std::wstring & tmp_filename);
bool FunUploadCheckAbuse();
void UploadFile(Item & item, const std::wstring & tmp_filename);
void UploadMulti();
void UploadSingle();
};

View File

@ -1,11 +1,11 @@
[if mount_page_arg_is "subject"][if mount_page_arg_is "info"]<h1 class="withinfo">[else]<h1>[end][item_subject]</h1>[end]
[if mount_page_arg_is "info"][include "item_info.html"][end]
[if-one item_auth_is_image]
[if-one item_filetype_is_image]
<img class="catimage" src="[item_link]/download/thumb" alt="[item_subject]">
[item_print_content]
[else]
[if-no item_auth_is_none]
[if-no item_filetype_is_none]
{download}: <a href="[item_link]/download" title="[item_subject]">[item_subject]</a>
[item_print_content]
[else]

View File

@ -120,6 +120,8 @@ int main(int argv, char ** argc)
app.WaitForThreads();
// now all others threads are terminated
app.Uninit();
log.PutDate(log1);
log << "winix stopped" << logend << logsavenow;

View File

@ -60,7 +60,7 @@ void FunTicket::MakeGet()
DbItemQuery iq;
iq.WhereParentId(request->dir_tab.back()->id);
iq.WhereType(Item::file);
iq.WhereAuth(Item::auth_none);
iq.WhereFileType(WINIX_ITEM_FILETYPE_NONE);
db->GetItems(request->item_tab, iq);
if( !request->item_tab.empty() )

View File

@ -253,8 +253,9 @@ void dir_tab_link(Info & i)
}
static Item dir_last_default_item;
static size_t dir_last_default_item_reqid = 0;
static Item dir_last_default_item;
static size_t dir_last_default_item_reqid = 0;
static std::wstring dir_last_path;
@ -264,7 +265,6 @@ void dir_last_default_item_init()
return;
dir_last_default_item_reqid = request->id;
dir_last_default_item.Clear();
if( request->dir_tab.empty() )
@ -275,13 +275,9 @@ void dir_last_default_item_init()
if( default_item == -1 )
return;
std::vector<Item> item_tab; // !! tymczasowo, nie bedzie tego po zmianie interfejsu dla Db
db->GetItem(item_tab, default_item);
if( item_tab.empty() )
return;
dir_last_default_item = item_tab[0];
// !! tutaj nie musimy odczytywac wszystkiego (contentu itp)
if( db->GetItemById(default_item, dir_last_default_item) != WINIX_ERR_OK )
dir_last_default_item.Clear();
}
@ -289,12 +285,10 @@ void dir_last_default_item_init()
void dir_last_default_item_dir(Info & i)
{
dir_last_default_item_init();
std::wstring path;
if( dir_last_default_item.parent_id != -1 )
if( system->dirs.MakePath(dir_last_default_item.parent_id, path) )
i.out << path;
if( system->dirs.MakePath(dir_last_default_item.parent_id, dir_last_path) )
i.out << dir_last_path;
}

View File

@ -56,12 +56,6 @@ void doc_base_url(Info & i)
}
void doc_base_url_auth(Info & i)
{
i.out << config->base_url_auth;
}
void doc_base_url_static(Info & i)
{
i.out << config->base_url_static;

View File

@ -169,15 +169,15 @@ void item_link(Info & i)
void item_auth_is_none(Info & i)
void item_filetype_is_none(Info & i)
{
i.res = request->item.auth == Item::auth_none;
i.res = request->item.file_type == WINIX_ITEM_FILETYPE_NONE;
}
void item_auth_is_image(Info & i)
void item_filetype_is_image(Info & i)
{
i.res = request->item.auth == Item::auth_image;
i.res = request->item.file_type == WINIX_ITEM_FILETYPE_IMAGE;
}
@ -407,15 +407,6 @@ void item_tab_link(Info & i)
}
void item_tab_link_auth(Info & i)
{
if( item_index < request->item_tab.size() )
{
i.out << config->base_url_auth;
item_tab_dir(i);
item_tab_url(i);
}
}
void item_tab_can_read(Info & i)

View File

@ -19,14 +19,14 @@ namespace TemplatesFunctions
void stat_item_type_is_file(Info & i)
{
i.res = request->is_item && request->item.auth == Item::auth_none;
i.res = request->is_item && request->item.file_type == WINIX_ITEM_FILETYPE_NONE;
}
void stat_item_type_is_static_file(Info & i)
{
i.res = request->is_item && request->item.auth != Item::auth_none;
i.res = request->is_item && request->item.file_type != WINIX_ITEM_FILETYPE_NONE;
}

View File

@ -186,7 +186,6 @@ void Templates::CreateFunctions()
*/
ezc_functions.Insert("doc_title", doc_title);
ezc_functions.Insert("doc_base_url", doc_base_url);
ezc_functions.Insert("doc_base_url_auth", doc_base_url_auth);
ezc_functions.Insert("doc_base_url_static", doc_base_url_static);
ezc_functions.Insert("doc_base_url_common", doc_base_url_common);
ezc_functions.Insert("doc_current_url", doc_current_url);
@ -209,8 +208,8 @@ void Templates::CreateFunctions()
ezc_functions.Insert("item_url", item_url);
ezc_functions.Insert("item_url_is", item_url_is);
ezc_functions.Insert("item_link", item_link);
ezc_functions.Insert("item_auth_is_none", item_auth_is_none);
ezc_functions.Insert("item_auth_is_image", item_auth_is_image);
ezc_functions.Insert("item_filetype_is_none", item_filetype_is_none);
ezc_functions.Insert("item_filetype_is_image", item_filetype_is_image);
ezc_functions.Insert("item_can_read", item_can_read);
ezc_functions.Insert("item_can_write", item_can_write);
@ -240,7 +239,6 @@ void Templates::CreateFunctions()
ezc_functions.Insert("item_tab_dir", item_tab_dir);
ezc_functions.Insert("item_tab_url", item_tab_url);
ezc_functions.Insert("item_tab_link", item_tab_link);
ezc_functions.Insert("item_tab_link_auth", item_tab_link_auth);
ezc_functions.Insert("item_tab_can_read", item_tab_can_read);
ezc_functions.Insert("item_tab_can_write", item_tab_can_write);
ezc_functions.Insert("item_tab_user", item_tab_user);

View File

@ -116,7 +116,6 @@ 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_common(Info & i);
void doc_current_url(Info & i);
@ -141,8 +140,8 @@ namespace TemplatesFunctions
void item_url(Info & i);
void item_url_is(Info & i);
void item_link(Info & i);
void item_auth_is_none(Info & i);
void item_auth_is_image(Info & i);
void item_filetype_is_none(Info & i);
void item_filetype_is_image(Info & i);
void item_can_read(Info & i);
void item_can_write(Info & i);
void item_can_remove(Info & i);
@ -171,7 +170,6 @@ namespace TemplatesFunctions
void item_tab_dir(Info & i);
void item_tab_url(Info & i);
void item_tab_link(Info & i);
void item_tab_link_auth(Info & i);
void item_tab_can_read(Info & i);
void item_tab_can_write(Info & i);
void item_tab_user(Info & i);