2010-08-10 18:12:50 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of Winix
|
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008-2010, Tomasz Sowa
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "emacs.h"
|
|
|
|
#include "templates/templates.h"
|
|
|
|
#include "functions.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Fun
|
|
|
|
{
|
|
|
|
|
|
|
|
Emacs::Emacs()
|
|
|
|
{
|
|
|
|
fun.url = "emacs";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Emacs::HasAccess(const Item & item)
|
|
|
|
{
|
|
|
|
if( request->session->puser && request->session->puser->super_user )
|
|
|
|
// super user can use emacs everywhere
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( !system->HasWriteAccess(item) )
|
|
|
|
return false;
|
|
|
|
|
2010-09-13 01:33:27 +02:00
|
|
|
if( !system->mounts.pmount->IsPar(system->mounts.MountParEmacsOn()) )
|
2010-08-10 18:12:50 +02:00
|
|
|
return true;
|
|
|
|
|
2010-09-13 01:33:27 +02:00
|
|
|
if( system->mounts.pmount->IsArg(system->mounts.MountParEmacsOn(), request->dir_tab.size()) )
|
2010-08-10 18:12:50 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Emacs::HasAccess()
|
|
|
|
{
|
2010-09-08 01:54:01 +02:00
|
|
|
return HasAccess(*request->last_item);
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Emacs::PostEmacsCheckAbuse(bool adding)
|
|
|
|
{
|
|
|
|
if( !system->rebus.CheckRebus() )
|
|
|
|
{
|
|
|
|
request->status = WINIX_ERR_INCORRECT_REBUS;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// !! is tested in createthread once
|
|
|
|
functions->CheckGetPostTimes();
|
|
|
|
|
|
|
|
if( request->session->spam_score > 0 )
|
|
|
|
{
|
|
|
|
request->status = WINIX_ERR_SPAM;
|
2010-08-14 18:55:16 +02:00
|
|
|
log << log1 << "Emacs: ignoring due to suspected spamming" << logend;
|
2010-08-10 18:12:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Emacs::PostFunEmacsModifyMountPoint(bool adding)
|
|
|
|
{
|
2010-09-30 22:58:20 +02:00
|
|
|
if( system->mounts.pmount->type == system->mounts.MountTypeThread() && adding )
|
|
|
|
db->EditThreadAddItem(request->dir_tab.back()->id, request->item.id);
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2010-09-30 22:58:20 +02:00
|
|
|
|
|
|
|
if( system->mounts.pmount->type == system->mounts.MountTypeCms() )
|
|
|
|
system->RedirectTo(request->item);
|
2010-08-10 18:12:50 +02:00
|
|
|
else
|
|
|
|
system->RedirectToLastDir();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Emacs::MakePost()
|
|
|
|
{
|
2010-09-30 22:58:20 +02:00
|
|
|
bool adding = !request->is_item;
|
|
|
|
|
|
|
|
if( !adding )
|
|
|
|
old_url = request->item.url;
|
|
|
|
|
|
|
|
functions->ReadItem(request->item, Item::file);
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
if( adding )
|
|
|
|
functions->SetUser(request->item); // set user before checking the rebus
|
|
|
|
|
|
|
|
if( !PostEmacsCheckAbuse(adding) )
|
|
|
|
return;
|
|
|
|
|
2010-08-14 18:55:16 +02:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
if( adding )
|
|
|
|
{
|
|
|
|
request->is_item = true;
|
|
|
|
request->item.privileges = 0644; // !! tymczasowo, bedzie uzyte umask
|
2010-08-14 18:55:16 +02:00
|
|
|
request->status = system->AddFile(request->item);
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-30 22:58:20 +02:00
|
|
|
request->status = system->EditFile(request->item, request->item.url != old_url);
|
2010-08-14 18:55:16 +02:00
|
|
|
|
|
|
|
if( request->status == WINIX_ERR_OK )
|
2010-08-12 21:10:12 +02:00
|
|
|
TemplatesFunctions::pattern_cacher.UpdatePattern(request->item);
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( request->status == WINIX_ERR_OK )
|
|
|
|
{
|
|
|
|
PostFunEmacsModifyMountPoint(adding);
|
2010-08-12 21:10:12 +02:00
|
|
|
functions->CheckSpecialFile(request->item);
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-14 18:55:16 +02:00
|
|
|
log << log1 << "Emacs: error: "
|
2010-08-10 18:12:50 +02:00
|
|
|
<< request->status << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|