178 lines
3.4 KiB
C++
Executable File
178 lines
3.4 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2008-2010, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include "createticket.h"
|
|
#include "readticket.h"
|
|
#include "functions/functions.h"
|
|
|
|
|
|
namespace Ticket
|
|
{
|
|
|
|
|
|
CreateTicket::CreateTicket()
|
|
{
|
|
fun.url = "createticket";
|
|
}
|
|
|
|
|
|
void CreateTicket::SetTDb(TDb * ptdb)
|
|
{
|
|
tdb = ptdb;
|
|
}
|
|
|
|
|
|
void CreateTicket::SetTicketInfo(TicketInfo * pinfo)
|
|
{
|
|
ticket_info = pinfo;
|
|
}
|
|
|
|
|
|
|
|
|
|
void CreateTicket::Clear()
|
|
{
|
|
ticket_info->Clear();
|
|
}
|
|
|
|
|
|
// returning true if we can create a ticket in the current directory
|
|
bool CreateTicket::HasAccess(bool check_root)
|
|
{
|
|
if( request->dir_tab.empty() )
|
|
return false;
|
|
|
|
if( request->is_item )
|
|
return false;
|
|
|
|
if( !system->HasWriteAccess(*request->dir_tab.back()) )
|
|
return false;
|
|
|
|
if( !system->mounts.pmount || system->mounts.pmount->type != ticket_info->mount_type_ticket )
|
|
return false;
|
|
|
|
|
|
// checking for par_createticket_on mount option
|
|
|
|
if( !check_root && request->session && request->session->puser && request->session->puser->super_user )
|
|
// super can create tickets regardless of the createticket_on option
|
|
return true;
|
|
|
|
if( !system->mounts.pmount->IsPar(ticket_info->mount_par_createticket_on) )
|
|
return true;
|
|
|
|
if( system->mounts.pmount->IsArg(ticket_info->mount_par_createticket_on, request->dir_tab.size()) )
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
bool CreateTicket::HasAccess()
|
|
{
|
|
return HasAccess(false);
|
|
}
|
|
|
|
|
|
bool CreateTicket::FunCreateTicketCheckAbuse()
|
|
{
|
|
if( !system->rebus.CheckRebus() )
|
|
{
|
|
request->status = WINIX_ERR_INCORRECT_REBUS;
|
|
return false;
|
|
}
|
|
|
|
functions->CheckGetPostTimes();
|
|
|
|
if( request->session->spam_score > 0 )
|
|
{
|
|
request->status = WINIX_ERR_SPAM;
|
|
log << log1 << "Content: ignoring due to suspected spamming" << logend;
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
void CreateTicket::AddTicket()
|
|
{
|
|
static std::string temp;
|
|
|
|
ticket_info->ticket.dir_id = request->dir_tab.back()->id; // a new directory created by Mkdir()
|
|
ticket_info->ticket.item_id = request->item.id; // this id is set by PostFunEmacsAdd()
|
|
|
|
request->status = tdb->AddTicket(ticket_info->ticket);
|
|
|
|
if( request->status == WINIX_ERR_OK )
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void CreateTicket::PostFunCreateTicketLogAndRedirect()
|
|
{
|
|
if( request->status == WINIX_ERR_OK )
|
|
{
|
|
log << log2 << "CreateTicket: added a new ticket" << logend;
|
|
system->RedirectToLastDir();
|
|
}
|
|
else
|
|
{
|
|
log << log1 << "CreateTicket: problem with adding a new ticket, error code: "
|
|
<< request->status << logend;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void CreateTicket::MakePost()
|
|
{
|
|
functions->ReadItem(request->item, Item::dir);
|
|
functions->SetUser(request->item);
|
|
|
|
ReadTicket read_ticket;
|
|
read_ticket.Read(system, request, ticket_info, &ticket_info->ticket);
|
|
|
|
request->item.privileges = 0777; // !! tymczasowo 777 aby wszyscy mogli wysylac posty
|
|
|
|
if( !FunCreateTicketCheckAbuse() )
|
|
{
|
|
functions->ReadItemContentWithType(request->item); // for correctly displaying the form
|
|
return;
|
|
}
|
|
|
|
request->status = system->dirs.AddDirectory(request->item, true);
|
|
|
|
if( request->status == WINIX_ERR_OK )
|
|
{
|
|
functions->ReadItemContentWithType(request->item);
|
|
request->item.type = Item::file;
|
|
request->item.privileges = 0644; // !! tymczasowo
|
|
request->item.parent_id = request->dir_tab.back()->id;
|
|
|
|
request->status = system->AddFile(request->item);
|
|
|
|
if( request->status == WINIX_ERR_OK )
|
|
AddTicket();
|
|
}
|
|
|
|
PostFunCreateTicketLogAndRedirect();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|