113 lines
2.1 KiB
C++
Executable File
113 lines
2.1 KiB
C++
Executable File
/*
|
|
* This file is a part of CMSLU -- Content Management System like Unix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2008-2009, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <cstdio>
|
|
#include "content.h"
|
|
#include "../core/request.h"
|
|
#include "../core/data.h"
|
|
|
|
|
|
|
|
|
|
bool Content::FunUploadCheckAccess()
|
|
{
|
|
if( request.is_item || !request.CanUseUpload(*request.dir_table.back()) )
|
|
{
|
|
request.status = Error::permission_denied;
|
|
return false;
|
|
}
|
|
|
|
// !! in the future the 'upload' can be used everywhere
|
|
if( data.mounts.pmount->type != Mount::cms )
|
|
{
|
|
request.status = Error::permission_denied;
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
void Content::UploadSaveFile()
|
|
{
|
|
static std::string path;
|
|
struct stat sb;
|
|
|
|
request.MakePath(path);
|
|
|
|
if( stat(path.c_str(), &sb) < 0 )
|
|
{
|
|
if( !request.MakeDirsOnFS() )
|
|
{
|
|
request.status = Error::permission_denied;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
path += '/';
|
|
path += request.item.url;
|
|
const std::string & tmp_filename = request.post_file_table.begin()->second.tmp_filename;
|
|
|
|
if( rename(tmp_filename.c_str(), path.c_str()) == 0 )
|
|
{
|
|
log << log1 << "Content: uploaded a new file: " << path << logend;
|
|
}
|
|
else
|
|
{
|
|
// !! skasowac takze plik z bazy danych
|
|
log << log1 << "Content: can't move the tmp file from: " << tmp_filename;
|
|
log << log1 << ", to: " << path << logend;
|
|
request.status = Error::permission_denied;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
void Content::PostFunUpload()
|
|
{
|
|
if( !FunUploadCheckAccess() )
|
|
return;
|
|
|
|
if( request.post_file_table.empty() )
|
|
{
|
|
request.status = Error::permission_denied;
|
|
return;
|
|
}
|
|
|
|
// !! moze request.session->done_status trzeba ustawic na Error::ok na poczatku? (i podobnie w innych metodach, mkdir, emacs ...)
|
|
ReadItem(request.item, Item::file);
|
|
|
|
// !! sprawdzanie rebusa?
|
|
|
|
// !! tutaj w zaleznosci od rozszerzenia dobrac odpowiedni static_auth
|
|
request.item.static_auth = Item::static_other;
|
|
|
|
PostFunEmacsAdd(); // always adding a new item
|
|
|
|
|
|
if( request.session->done_status == Error::ok )
|
|
UploadSaveFile();
|
|
|
|
if( request.session->done_status == Error::ok )
|
|
RedirectTo(request.item);
|
|
}
|
|
|
|
|
|
|
|
void Content::FunUpload()
|
|
{
|
|
FunUploadCheckAccess();
|
|
}
|
|
|