2011-11-25 05:51:55 +01:00
|
|
|
/*
|
|
|
|
* This file is a part of Winix
|
2014-10-04 20:04:03 +02:00
|
|
|
* and is distributed under the 2-Clause BSD licence.
|
|
|
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2018-01-06 19:12:53 +01:00
|
|
|
* Copyright (c) 2011-2018, Tomasz Sowa
|
2011-11-25 05:51:55 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2014-10-04 20:04:03 +02:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2011-11-25 05:51:55 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "meta.h"
|
|
|
|
#include "core/log.h"
|
|
|
|
|
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
namespace Winix
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2011-11-25 05:51:55 +01:00
|
|
|
namespace Fun
|
|
|
|
{
|
|
|
|
|
|
|
|
Meta::Meta()
|
|
|
|
{
|
|
|
|
fun.url = L"meta";
|
2012-11-04 22:01:02 +01:00
|
|
|
// !! CHECKME what about follow symlinks?
|
2011-11-25 05:51:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Meta::HasAccess()
|
|
|
|
{
|
2012-11-04 22:01:02 +01:00
|
|
|
if( cur->request->IsParam(L"a") )
|
|
|
|
return cur->session->puser && cur->session->puser->super_user;
|
|
|
|
else
|
|
|
|
return system->HasWriteAccess(*cur->request->last_item);
|
2011-11-25 05:51:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-11-04 22:01:02 +01:00
|
|
|
bool Meta::Parse(const std::wstring & meta_str)
|
2011-11-25 05:51:55 +01:00
|
|
|
{
|
|
|
|
space.Clear();
|
|
|
|
conf_parser.SetSpace(space);
|
|
|
|
|
2012-11-04 22:01:02 +01:00
|
|
|
return (conf_parser.ParseString(meta_str) == PT::SpaceParser::ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Meta::EditAdminMeta(long item_id, const std::wstring & meta_str, bool use_ses_log)
|
|
|
|
{
|
|
|
|
if( Parse(meta_str) )
|
2011-11-25 05:51:55 +01:00
|
|
|
{
|
2012-11-04 22:01:02 +01:00
|
|
|
if( db->EditAdminMetaById(space, item_id) == WINIX_ERR_OK )
|
2011-11-25 05:51:55 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-04 22:01:02 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
log << log1 << "Meta: a database problem with changing admin meta information for item id: "
|
|
|
|
<< item_id << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log << log2 << "Meta: Syntax error in line: " << conf_parser.line << logend;
|
|
|
|
|
|
|
|
if( use_ses_log )
|
|
|
|
slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.line << logend;
|
2011-11-25 05:51:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-11-04 22:01:02 +01:00
|
|
|
bool Meta::EditMeta(long item_id, const std::wstring & meta_str, bool use_ses_log)
|
2011-11-25 05:51:55 +01:00
|
|
|
{
|
2012-11-04 22:01:02 +01:00
|
|
|
if( Parse(meta_str) )
|
|
|
|
{
|
|
|
|
if( db->EditMetaById(space, item_id) == WINIX_ERR_OK )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log << log1 << "Meta: a database problem with changing meta information for item id: "
|
|
|
|
<< item_id << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log << log2 << "Meta: Syntax error in line: " << conf_parser.line << logend;
|
|
|
|
|
|
|
|
if( use_ses_log )
|
|
|
|
slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.line << logend;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Meta::ChangeAdminMeta()
|
|
|
|
{
|
|
|
|
if( cur->session->puser && cur->session->puser->super_user )
|
2011-11-25 05:51:55 +01:00
|
|
|
{
|
|
|
|
const std::wstring & meta_str = cur->request->PostVar(L"itemmeta");
|
|
|
|
|
2012-11-04 22:01:02 +01:00
|
|
|
if( EditAdminMeta(cur->request->last_item->id, meta_str, true) )
|
2015-06-16 04:37:07 +02:00
|
|
|
{
|
|
|
|
if( cur->request->last_item->type == Item::dir )
|
|
|
|
cur->request->last_item->ameta = space;
|
|
|
|
|
2011-11-25 05:51:55 +01:00
|
|
|
system->RedirectToLastItem();
|
2015-06-16 04:37:07 +02:00
|
|
|
}
|
2011-11-25 05:51:55 +01:00
|
|
|
}
|
2012-11-04 22:01:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Meta::ChangeMeta()
|
|
|
|
{
|
|
|
|
if( system->HasWriteAccess(*cur->request->last_item) )
|
2011-11-25 05:51:55 +01:00
|
|
|
{
|
2012-11-04 22:01:02 +01:00
|
|
|
const std::wstring & meta_str = cur->request->PostVar(L"itemmeta");
|
|
|
|
|
|
|
|
if( EditMeta(cur->request->last_item->id, meta_str, true) )
|
2015-06-16 04:37:07 +02:00
|
|
|
{
|
|
|
|
if( cur->request->last_item->type == Item::dir )
|
|
|
|
cur->request->last_item->meta = space;
|
|
|
|
|
2012-11-04 22:01:02 +01:00
|
|
|
system->RedirectToLastItem();
|
2015-06-16 04:37:07 +02:00
|
|
|
}
|
2011-11-25 05:51:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-11-04 22:01:02 +01:00
|
|
|
void Meta::MakePost()
|
|
|
|
{
|
|
|
|
if( cur->request->IsParam(L"a") )
|
|
|
|
ChangeAdminMeta();
|
|
|
|
else
|
|
|
|
ChangeMeta();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-11-25 05:51:55 +01:00
|
|
|
} // namespace
|
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
|
|
|
|
} // namespace Winix
|
|
|
|
|