235 lines
4.1 KiB
C++
Executable File
235 lines
4.1 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2011, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include "core/log.h"
|
|
#include "exportinfo.h"
|
|
|
|
|
|
|
|
namespace Export
|
|
{
|
|
|
|
|
|
ExportInfo::ExportInfo()
|
|
{
|
|
use_rsa = false;
|
|
}
|
|
|
|
|
|
|
|
void ExportInfo::SetSystem(System * psystem)
|
|
{
|
|
system = psystem;
|
|
}
|
|
|
|
|
|
void ExportInfo::SetConfig(Config * pconfig)
|
|
{
|
|
config = pconfig;
|
|
}
|
|
|
|
|
|
void ExportInfo::SetDb(Db * pdb)
|
|
{
|
|
db = pdb;
|
|
}
|
|
|
|
|
|
void ExportInfo::SetExportThread(ExportThread * pexport_thread)
|
|
{
|
|
export_thread = pexport_thread;
|
|
}
|
|
|
|
|
|
|
|
void ExportInfo::ReadExportDirs()
|
|
{
|
|
db->GetExportDirs(export_dirs);
|
|
}
|
|
|
|
|
|
void ExportInfo::ReadConfigVars()
|
|
{
|
|
use_rsa = config->Bool(L"export_rsa", false);
|
|
rsa_key = config->Text(L"export_rsa_key");
|
|
}
|
|
|
|
|
|
ExportDir * ExportInfo::FindDir(long dir_id)
|
|
{
|
|
for(size_t i=0 ; i<export_dirs.size() ; ++i)
|
|
{
|
|
if( dir_id == export_dirs[i].dir_id || system->dirs.HasParent(dir_id, export_dirs[i].dir_id) )
|
|
return &export_dirs[i];
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ExportInfo::DecodePass(Export & exp)
|
|
{
|
|
if( exp.ftp_pass_type == 0 )
|
|
{
|
|
Ezc::UTF8ToWide(exp.ftp_pass_bin, exp.ftp_pass);
|
|
}
|
|
else
|
|
{
|
|
if( system->crypt.RSA(false, rsa_key, exp.ftp_pass_bin, pass_decrypted) )
|
|
{
|
|
Ezc::UTF8ToWide(pass_decrypted, exp.ftp_pass);
|
|
system->crypt.ClearString(pass_decrypted);
|
|
}
|
|
else
|
|
{
|
|
log << log1 << "Export: I cannot decrypt a password (RSA failed)" << logend;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
bool ExportInfo::SkipDir(long dir_id, std::wstring & dir)
|
|
{
|
|
if( system->dirs.MakePath(dir_id, tmp_dir) )
|
|
{
|
|
if( !tmp_dir.empty() && IsSubString(tmp_dir, dir) )
|
|
{
|
|
// tmp_dir has a slash at the end
|
|
// we want the slash at the beginning
|
|
dir.erase(0, tmp_dir.size()-1);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
|
|
void ExportInfo::SendFile(const Item & item, bool thumb)
|
|
{
|
|
ExportDir * exp_dir = FindDir(item.parent_id);
|
|
|
|
if( !exp_dir )
|
|
return;
|
|
|
|
msg.Clear();
|
|
system->dirs.MakePath(item.parent_id, msg.path);
|
|
msg.path += item.url;
|
|
|
|
if( item.file_type != WINIX_ITEM_FILETYPE_NONE )
|
|
{
|
|
msg.type = WINIX_PL_EXPORT_TYPE_CREATE_FILE_STATIC;
|
|
|
|
if( !system->MakeFilePath(item, msg.url, thumb) )
|
|
{
|
|
log << log1 << "Export: I cannot create a path to a static file, item id: " << item.id << logend;
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
msg.type = WINIX_PL_EXPORT_TYPE_CREATE_FILE;
|
|
msg.url = config->url_proto;
|
|
msg.url += config->base_url;
|
|
system->dirs.MakePath(item.parent_id, msg.url, false);
|
|
msg.url += item.url;
|
|
msg.path += L".php"; // !! do konfiga
|
|
}
|
|
|
|
msg.errors = 0;
|
|
|
|
if( SkipDir(exp_dir->dir_id, msg.path) && db->GetExport(exp_dir->id, exp) )
|
|
{
|
|
if( DecodePass(exp) )
|
|
{
|
|
msg.ftp_login = exp.ftp_login;
|
|
msg.ftp_pass = exp.ftp_pass;
|
|
msg.ftp_server = exp.ftp_server;
|
|
msg.http_server = exp.http_server;
|
|
system->dirs.MakePath(exp_dir->dir_id, msg.src_dir);
|
|
|
|
if( !item.file_path.empty() && thumb ) // !! uzyc file_type
|
|
msg.path.insert(0, L"/download"); // !! do konfiga
|
|
|
|
if( !exp.ftp_dir.empty() )
|
|
msg.path.insert(0, exp.ftp_dir);
|
|
|
|
if( !msg.path.empty() && msg.path[0] != '/' )
|
|
msg.path.insert(0, L"/");
|
|
|
|
export_thread->AddMessage(msg);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void ExportInfo::SendDir(const Item & item)
|
|
{
|
|
ExportDir * exp_dir = FindDir(item.id);
|
|
|
|
if( !exp_dir )
|
|
return;
|
|
|
|
msg.Clear();
|
|
system->dirs.MakePath(item.id, msg.path);
|
|
|
|
msg.type = WINIX_PL_EXPORT_TYPE_CREATE_FILE;
|
|
msg.url = config->url_proto;
|
|
msg.url += config->base_url;
|
|
system->dirs.MakePath(item.id, msg.url, false);
|
|
msg.path += L"index.html"; // !! do konfiga
|
|
|
|
msg.errors = 0;
|
|
|
|
if( SkipDir(exp_dir->dir_id, msg.path) && db->GetExport(exp_dir->id, exp) )
|
|
{
|
|
if( DecodePass(exp) )
|
|
{
|
|
msg.ftp_login = exp.ftp_login;
|
|
msg.ftp_pass = exp.ftp_pass;
|
|
msg.ftp_server = exp.ftp_server;
|
|
msg.http_server = exp.http_server;
|
|
system->dirs.MakePath(exp_dir->dir_id, msg.src_dir);
|
|
|
|
if( !exp.ftp_dir.empty() )
|
|
msg.path.insert(0, exp.ftp_dir);
|
|
|
|
if( !msg.path.empty() && msg.path[0] != '/' )
|
|
msg.path.insert(0, L"/");
|
|
|
|
export_thread->AddMessage(msg);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void ExportInfo::SendDir(long dir_id)
|
|
{
|
|
Item * dir = system->dirs.GetDir(dir_id);
|
|
|
|
if( !dir )
|
|
return;
|
|
|
|
SendDir(*dir);
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|