2010-08-10 18:12:50 +02: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>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
remove Request::post_tab and add Request::http_status
Instead of Reqest::post_tab we use now Request::post_in (pt::Space).
Request::http_status will be used instead Request::status,
but at the moment is not changed in all places.
Request::status has been marked as depracated.
While here:
- Check for root dir in App and not in FunctionParser,
let FunctionParser only log the root dir.
- Read post variables after parsing url parameters,
this allows winix functions to set limits
for post input.
- Set limits when parsing input json format, new
options added to config: post_max_object_items, post_max_table_items,
post_max_all_items, post_max_nested_objects.
There are similar options in each winix function (they are in
FunctionBase).
- Some refactoring in App.
- Add config option: log_whole_http_post if true
then the whole parsed post input is logged.
- Add config option: post_json_max - max length of input stream
for parsing json.
- Add config option: templates_request_status, default request_status.html
this is an ezc template used as [content] when the request status
is not 200_ok.
- Fix: Sort winix function didn't show items to sort (fix and do some
refactoring as well)
- Properly sort items in: ImgCrop, Ls, Sort, Upload
- Remove ezc templates: err_404.html, err_per_denied.html - now
request_status.html is used.
2022-05-30 01:29:18 +02:00
|
|
|
* Copyright (c) 2010-2022, Tomasz Sowa
|
2010-08-10 18:12:50 +02: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.
|
|
|
|
*
|
2010-08-10 18:12:50 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "functions.h"
|
|
|
|
#include "core/misc.h"
|
|
|
|
#include "templates/templates.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
namespace Winix
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-21 12:03:53 +01:00
|
|
|
//void Functions::SetConfig(Config * pconfig)
|
|
|
|
//{
|
|
|
|
// config = pconfig;
|
|
|
|
//}
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
void Functions::SetCur(Cur * pcur)
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
cur = pcur;
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
void Functions::SetDb(Db * pdb)
|
|
|
|
{
|
|
|
|
db = pdb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Functions::SetSystem(System * psystem)
|
|
|
|
{
|
|
|
|
system = psystem;
|
|
|
|
}
|
|
|
|
|
2010-08-13 22:04:57 +02:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
void Functions::SetTemplates(Templates * ptemplates)
|
|
|
|
{
|
|
|
|
templates = ptemplates;
|
|
|
|
}
|
|
|
|
|
2010-08-13 22:04:57 +02:00
|
|
|
|
2018-11-21 12:03:53 +01:00
|
|
|
//void Functions::SetSynchro(Synchro * psynchro)
|
|
|
|
//{
|
|
|
|
// synchro = psynchro;
|
|
|
|
//}
|
2010-12-06 01:25:46 +01:00
|
|
|
|
|
|
|
|
2012-10-27 09:44:26 +02:00
|
|
|
void Functions::SetSessionManager(SessionManager * pmanager)
|
|
|
|
{
|
|
|
|
session_manager = pmanager;
|
|
|
|
}
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2018-11-21 12:03:53 +01:00
|
|
|
void Functions::set_dependency(WinixRequest * winix_request)
|
|
|
|
{
|
|
|
|
WinixRequest::set_dependency(winix_request);
|
|
|
|
function_parser.set_dependency(winix_request);
|
|
|
|
}
|
|
|
|
|
2010-08-13 22:04:57 +02:00
|
|
|
|
|
|
|
size_t Functions::FunctionsSize()
|
|
|
|
{
|
|
|
|
return table.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Functions::Iterator Functions::Begin()
|
|
|
|
{
|
|
|
|
return table.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Functions::Iterator Functions::End()
|
|
|
|
{
|
|
|
|
return table.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
FunctionBase * Functions::Find(const std::wstring & function_name)
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
|
|
|
Table::iterator i = table.find(function_name);
|
|
|
|
|
|
|
|
if( i == table.end() )
|
|
|
|
return 0;
|
|
|
|
|
2021-01-25 17:55:07 +01:00
|
|
|
FunctionBase * fun = i->second;
|
|
|
|
|
|
|
|
// this is to set 'cur' and 'locale' for slog, but in the future slog will be moved to Session
|
|
|
|
fun->set_cur(cur);
|
|
|
|
fun->set_locale(locale);
|
|
|
|
//
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-12 21:10:12 +02:00
|
|
|
void Functions::PrepareUrl(Item & item)
|
|
|
|
{
|
|
|
|
TrimWhite(item.url);
|
|
|
|
|
|
|
|
if( item.url.empty() )
|
|
|
|
item.url = item.subject; // if the subject is empty then the url will be corrected by CorrectUrlOnlyAllowedChar()
|
|
|
|
|
|
|
|
CorrectUrlOnlyAllowedChar(item.url);
|
|
|
|
|
|
|
|
if( Find(item.url) )
|
|
|
|
{
|
|
|
|
// the name provided by an user is the same as a name of a function
|
|
|
|
// we add one underscore character at the beginning
|
|
|
|
|
|
|
|
// names of functions should not begin with an underscore '_'
|
|
|
|
// and we can simply add one '_' at the beginning
|
|
|
|
// and the name will be unique
|
|
|
|
item.url.insert(item.url.begin(), '_');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Error Functions::CheckSpecialFile(const Item & item)
|
|
|
|
{
|
2010-11-21 01:19:17 +01:00
|
|
|
static std::wstring fstab = L"fstab";
|
2010-08-12 21:10:12 +02:00
|
|
|
|
|
|
|
Item * etc = system->dirs.GetEtcDir();
|
|
|
|
|
|
|
|
if( !etc )
|
|
|
|
return WINIX_NOTHING_TO_DO;
|
|
|
|
|
|
|
|
if( item.parent_id != etc->id )
|
|
|
|
return WINIX_NOTHING_TO_DO;
|
|
|
|
|
|
|
|
if( item.url == fstab )
|
|
|
|
{
|
|
|
|
log << log3 << "Functions: reloading mount points" << logend;
|
|
|
|
|
2021-02-16 17:23:36 +01:00
|
|
|
cur->mount = system->mounts.GetEmptyMount();
|
2021-02-24 01:19:47 +01:00
|
|
|
system->mounts.ReadMounts(item.item_content.content_raw);
|
2022-07-25 14:21:21 +02:00
|
|
|
system->mounts.CalcCurMount(cur->request);
|
2021-02-16 17:23:36 +01:00
|
|
|
cur->mount = system->mounts.pmount;
|
2022-07-30 18:37:50 +02:00
|
|
|
cur->request->mount = cur->mount;
|
2010-08-12 21:10:12 +02:00
|
|
|
templates->ReadNewIndexTemplates();
|
2011-08-26 01:53:49 +02:00
|
|
|
templates->ReadNewChangeTemplates();
|
2011-01-05 22:24:11 +01:00
|
|
|
|
2011-06-19 22:59:58 +02:00
|
|
|
return WINIX_ERR_OK;
|
2010-08-12 21:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return WINIX_NOTHING_TO_DO;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
void Functions::SetObjects(FunctionBase * fun)
|
|
|
|
{
|
2018-11-21 12:03:53 +01:00
|
|
|
fun->set_dependency(this);
|
|
|
|
|
|
|
|
//fun->SetConfig(config);
|
|
|
|
//fun->SetCur(cur);
|
2010-08-10 18:12:50 +02:00
|
|
|
fun->SetDb(db);
|
2018-11-21 12:03:53 +01:00
|
|
|
//fun->SetSystem(system);
|
2010-08-10 18:12:50 +02:00
|
|
|
fun->SetFunctions(this);
|
|
|
|
fun->SetTemplates(templates);
|
2018-11-21 12:03:53 +01:00
|
|
|
//fun->SetSynchro(synchro);
|
|
|
|
//fun->SetSessionManager(session_manager);
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-25 16:35:14 +02:00
|
|
|
bool Functions::Add(FunctionBase * fun)
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2012-01-06 13:55:08 +01:00
|
|
|
if( fun->fun.url.empty() )
|
|
|
|
{
|
|
|
|
log << log1 << "Functions: skipping a function with an empty url" << logend;
|
2022-04-25 16:35:14 +02:00
|
|
|
return false;
|
2012-01-06 13:55:08 +01:00
|
|
|
}
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
if( Find(fun->fun.url) )
|
|
|
|
{
|
2012-01-06 13:55:08 +01:00
|
|
|
log << log1 << "Functions: function " << fun->fun.url << " already exists (skipped)" << logend;
|
2022-04-25 16:35:14 +02:00
|
|
|
return false;
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SetObjects(fun);
|
2010-08-13 22:04:57 +02:00
|
|
|
table[fun->fun.url] = fun;
|
2022-04-25 16:35:14 +02:00
|
|
|
|
|
|
|
return true;
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-25 16:35:14 +02:00
|
|
|
bool Functions::Add(FunctionBase & fun)
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2022-04-25 16:35:14 +02:00
|
|
|
return Add(&fun);
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-11-04 17:46:19 +01:00
|
|
|
void Functions::CreateFunctions()
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2013-05-16 21:26:44 +02:00
|
|
|
Add(fun_account);
|
2010-08-10 18:12:50 +02:00
|
|
|
Add(fun_adduser);
|
|
|
|
Add(fun_cat);
|
|
|
|
Add(fun_chmod);
|
|
|
|
Add(fun_chown);
|
2010-08-10 19:05:19 +02:00
|
|
|
Add(fun_ckeditor);
|
2010-08-10 18:12:50 +02:00
|
|
|
Add(fun_cp);
|
|
|
|
Add(fun_default);
|
|
|
|
Add(fun_download);
|
|
|
|
Add(fun_emacs);
|
2012-01-08 04:59:51 +01:00
|
|
|
Add(fun_env);
|
2013-03-29 23:03:28 +01:00
|
|
|
Add(fun_imgcrop);
|
2010-08-10 18:12:50 +02:00
|
|
|
Add(fun_last);
|
2012-06-27 01:19:19 +02:00
|
|
|
Add(fun_locale);
|
2022-07-26 21:54:33 +02:00
|
|
|
|
|
|
|
if( config->use_internal_loggin_mechanism )
|
|
|
|
{
|
|
|
|
Add(fun_login);
|
|
|
|
Add(fun_logout);
|
|
|
|
}
|
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
Add(fun_ln);
|
2010-08-10 18:12:50 +02:00
|
|
|
Add(fun_ls);
|
2012-10-27 09:44:26 +02:00
|
|
|
Add(fun_ipban);
|
2012-01-06 13:07:23 +01:00
|
|
|
Add(fun_man);
|
2011-11-25 05:51:55 +01:00
|
|
|
Add(fun_meta);
|
2010-08-10 18:12:50 +02:00
|
|
|
Add(fun_mkdir);
|
2011-06-21 23:24:49 +02:00
|
|
|
Add(fun_mount);
|
2010-08-10 18:12:50 +02:00
|
|
|
Add(fun_mv);
|
2011-06-13 03:06:10 +02:00
|
|
|
Add(fun_nicedit);
|
2010-08-10 18:12:50 +02:00
|
|
|
Add(fun_node);
|
2011-06-27 23:38:19 +02:00
|
|
|
Add(fun_passwd);
|
2010-08-10 18:12:50 +02:00
|
|
|
Add(fun_priv);
|
2012-02-28 22:09:44 +01:00
|
|
|
Add(fun_pw);
|
2010-08-10 18:12:50 +02:00
|
|
|
Add(fun_reload);
|
|
|
|
Add(fun_rm);
|
2012-03-09 03:36:25 +01:00
|
|
|
Add(fun_rmuser);
|
2010-08-10 18:12:50 +02:00
|
|
|
Add(fun_run);
|
2011-08-02 02:10:45 +02:00
|
|
|
Add(fun_sort);
|
2010-12-07 19:18:45 +01:00
|
|
|
Add(fun_special_default);
|
2010-10-23 16:54:44 +02:00
|
|
|
Add(fun_stat);
|
2010-08-10 18:12:50 +02:00
|
|
|
Add(fun_subject);
|
2010-09-30 22:58:20 +02:00
|
|
|
Add(fun_template);
|
2012-06-27 01:19:19 +02:00
|
|
|
Add(fun_time_zone);
|
2010-08-10 19:05:19 +02:00
|
|
|
Add(fun_tinymce);
|
2010-08-10 18:12:50 +02:00
|
|
|
Add(fun_uname);
|
|
|
|
Add(fun_upload);
|
2010-08-10 22:43:38 +02:00
|
|
|
Add(fun_uptime);
|
2022-07-26 21:54:33 +02:00
|
|
|
|
|
|
|
if( config->use_internal_session_mechanism )
|
|
|
|
{
|
|
|
|
Add(fun_who);
|
|
|
|
}
|
|
|
|
|
2010-11-04 17:46:19 +01:00
|
|
|
Add(fun_vim);
|
2010-09-29 23:24:34 +02:00
|
|
|
|
2022-07-25 14:21:21 +02:00
|
|
|
plugin->Call(WINIX_CREATE_FUNCTIONS);
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-04 17:46:19 +01:00
|
|
|
void Functions::InitFunctions()
|
|
|
|
{
|
|
|
|
Table::iterator i = table.begin();
|
|
|
|
|
|
|
|
for( ; i!=table.end() ; ++i)
|
|
|
|
i->second->Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-22 00:23:25 +02:00
|
|
|
void Functions::FinishFunctions()
|
|
|
|
{
|
|
|
|
Table::iterator i = table.begin();
|
|
|
|
|
|
|
|
for( ; i!=table.end() ; ++i)
|
|
|
|
i->second->Finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-04 17:46:19 +01:00
|
|
|
void Functions::Init()
|
|
|
|
{
|
|
|
|
CreateFunctions();
|
|
|
|
InitFunctions();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-22 00:23:25 +02:00
|
|
|
void Functions::Finish()
|
|
|
|
{
|
|
|
|
FinishFunctions();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
remove Request::post_tab and add Request::http_status
Instead of Reqest::post_tab we use now Request::post_in (pt::Space).
Request::http_status will be used instead Request::status,
but at the moment is not changed in all places.
Request::status has been marked as depracated.
While here:
- Check for root dir in App and not in FunctionParser,
let FunctionParser only log the root dir.
- Read post variables after parsing url parameters,
this allows winix functions to set limits
for post input.
- Set limits when parsing input json format, new
options added to config: post_max_object_items, post_max_table_items,
post_max_all_items, post_max_nested_objects.
There are similar options in each winix function (they are in
FunctionBase).
- Some refactoring in App.
- Add config option: log_whole_http_post if true
then the whole parsed post input is logged.
- Add config option: post_json_max - max length of input stream
for parsing json.
- Add config option: templates_request_status, default request_status.html
this is an ezc template used as [content] when the request status
is not 200_ok.
- Fix: Sort winix function didn't show items to sort (fix and do some
refactoring as well)
- Properly sort items in: ImgCrop, Ls, Sort, Upload
- Remove ezc templates: err_404.html, err_per_denied.html - now
request_status.html is used.
2022-05-30 01:29:18 +02:00
|
|
|
bool Functions::Parse()
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2022-07-25 14:21:21 +02:00
|
|
|
return function_parser.Parse(cur->request, &system->dirs, this);
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-25 14:21:21 +02:00
|
|
|
bool Functions::ParseOnlyDirs()
|
|
|
|
{
|
|
|
|
return function_parser.ParseDirs(cur->request, &system->dirs);
|
|
|
|
}
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
void Functions::SetDefaultFunctionForFile()
|
|
|
|
{
|
2021-02-24 01:19:47 +01:00
|
|
|
if( cur->request->item.item_content.file_type != WINIX_ITEM_FILETYPE_NONE )
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->function = &fun_download;
|
2010-08-10 18:12:50 +02:00
|
|
|
else
|
2011-01-23 15:15:30 +01:00
|
|
|
if( system->HasReadExecAccess(cur->request->item) )
|
|
|
|
cur->request->function = &fun_run;
|
2010-08-10 18:12:50 +02:00
|
|
|
else
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->function = &fun_cat;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
log << log3 << "Functions: default function: " << cur->request->function->fun.url << logend;
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Functions::SetDefaultFunctionForDir()
|
|
|
|
{
|
2011-01-20 19:37:51 +01:00
|
|
|
// !! nie potrzebne
|
|
|
|
// if( system->mounts.pmount->type == system->mounts.MountTypeThread() )
|
2011-01-23 15:15:30 +01:00
|
|
|
// cur->request->function = &fun_thread;
|
2011-01-20 19:37:51 +01:00
|
|
|
// else
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->function = &fun_ls;
|
2010-09-29 23:24:34 +02:00
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
log << log3 << "Functions: default function: " << cur->request->function->fun.url << logend;
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Functions::SetDefaultFunction()
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->function = 0;
|
2011-01-05 22:24:11 +01:00
|
|
|
|
2018-11-21 12:03:53 +01:00
|
|
|
plugin->Call(WINIX_SELECT_DEFAULT_FUNCTION);
|
2010-09-29 23:24:34 +02:00
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->function )
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
log << log3 << "Functions: default function: " << cur->request->function->fun.url
|
2011-01-05 22:24:11 +01:00
|
|
|
<< " (set by a plugin)" << logend;
|
|
|
|
|
2010-09-29 23:24:34 +02:00
|
|
|
return;
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
2010-09-29 23:24:34 +02:00
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->is_item )
|
2010-09-29 23:24:34 +02:00
|
|
|
SetDefaultFunctionForFile();
|
2010-08-10 18:12:50 +02:00
|
|
|
else
|
|
|
|
SetDefaultFunctionForDir();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
|
|
|
|
void Functions::CheckFunctionFollowDir(bool was_default_function)
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2011-01-05 22:24:11 +01:00
|
|
|
// directory with 'default' flag
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
if( was_default_function )
|
|
|
|
{
|
2021-02-24 01:19:47 +01:00
|
|
|
if( cur->request->dir_tab.back()->item_content.link_redirect == 1 )
|
2011-01-05 22:24:11 +01:00
|
|
|
{
|
2021-02-24 01:19:47 +01:00
|
|
|
system->RedirectTo(cur->request->dir_tab.back()->item_content.link_to);
|
2011-01-05 22:24:11 +01:00
|
|
|
}
|
|
|
|
else
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2021-02-24 01:19:47 +01:00
|
|
|
if( system->FollowAllLinks(cur->request->dir_tab.back()->item_content.link_to, true, true) )
|
2011-01-05 22:24:11 +01:00
|
|
|
SetDefaultFunction();
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
2011-01-05 22:24:11 +01:00
|
|
|
}
|
|
|
|
}
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
void Functions::CheckFunctionFollowSymlink(bool was_default_function)
|
|
|
|
{
|
2021-02-24 01:19:47 +01:00
|
|
|
if( cur->request->item.item_content.link_redirect == 1 )
|
2011-01-05 22:24:11 +01:00
|
|
|
{
|
|
|
|
if( was_default_function )
|
2021-02-24 01:19:47 +01:00
|
|
|
system->RedirectTo(cur->request->item.item_content.link_to);
|
2011-01-05 22:24:11 +01:00
|
|
|
else
|
2021-02-24 01:19:47 +01:00
|
|
|
system->RedirectWithFunctionAndParamsTo(cur->request->item.item_content.link_to);
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
2011-01-05 22:24:11 +01:00
|
|
|
else
|
2021-02-24 01:19:47 +01:00
|
|
|
if( system->FollowAllLinks(cur->request->item.item_content.link_to, true, true) )
|
2011-01-05 22:24:11 +01:00
|
|
|
{
|
|
|
|
if( was_default_function )
|
|
|
|
SetDefaultFunction();
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->status == WINIX_ERR_OK && !cur->request->redirect_to.empty() && !was_default_function && cur->request->function )
|
2011-01-05 22:24:11 +01:00
|
|
|
{
|
|
|
|
// !! nie jestem pewny dodania tej nowej funkcji do redirecta... (sprawdzic to)
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->redirect_to += '/';
|
|
|
|
cur->request->redirect_to += cur->request->function->fun.url;
|
|
|
|
system->AddParams(cur->request->param_tab, cur->request->redirect_to, false);
|
2011-01-05 22:24:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
// making a proper redirection from a directory with 'default' flag
|
|
|
|
// or from a symlink (or just loading it if there is no redirection flag set)
|
|
|
|
void Functions::CheckFunctionAndSymlink()
|
|
|
|
{
|
|
|
|
bool was_default_function = false;
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( !cur->request->function || cur->request->function == &fun_special_default )
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2011-01-05 22:24:11 +01:00
|
|
|
was_default_function = true;
|
|
|
|
SetDefaultFunction();
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
2018-06-20 17:00:02 +02:00
|
|
|
// callback for plugins can set a different status
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->status != WINIX_ERR_OK || !cur->request->redirect_to.empty() )
|
2010-08-10 18:12:50 +02:00
|
|
|
return;
|
|
|
|
|
2021-02-24 01:19:47 +01:00
|
|
|
if( !cur->request->is_item && !cur->request->dir_tab.back()->item_content.link_to.empty() )
|
2011-01-05 22:24:11 +01:00
|
|
|
CheckFunctionFollowDir(was_default_function);
|
|
|
|
else
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->is_item && cur->request->item.type == Item::symlink && cur->request->function && cur->request->function->follow_symlinks )
|
2011-01-05 22:24:11 +01:00
|
|
|
CheckFunctionFollowSymlink(was_default_function);
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
void Functions::MakeFunction()
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( !cur->request->function )
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2022-08-29 19:20:41 +02:00
|
|
|
cur->request->http_status = Header::status_500_internal_server_error; // or 404? (404 was originally)
|
|
|
|
log << log1 << "Functions: no function to call" << logend;
|
2010-08-10 18:12:50 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-29 19:20:41 +02:00
|
|
|
if( !system->DirsHaveReadExecPerm() ||
|
|
|
|
!system->HasReadExecAccess(cur->request->function->fun) ||
|
2011-01-23 15:15:30 +01:00
|
|
|
!cur->request->function->HasAccess() )
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2022-08-29 19:20:41 +02:00
|
|
|
cur->request->http_status = Header::status_403_forbidden;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !cur->request->redirect_to.empty() )
|
|
|
|
{
|
|
|
|
log << log3 << "Functions: there is a redirect_to set so I do not call the function" << logend;
|
2010-08-10 18:12:50 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->method == Request::get )
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2022-08-29 19:20:41 +02:00
|
|
|
cur->request->function->MakeGet();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( cur->request->method == Request::head )
|
|
|
|
{
|
|
|
|
cur->request->function->MakeHead();
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
2011-01-05 22:24:11 +01:00
|
|
|
else
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->method == Request::post )
|
2011-01-05 22:24:11 +01:00
|
|
|
{
|
2022-08-29 19:20:41 +02:00
|
|
|
cur->request->function->MakePost();
|
2011-01-05 22:24:11 +01:00
|
|
|
}
|
|
|
|
else
|
2022-08-29 19:20:41 +02:00
|
|
|
if( cur->request->method == Request::put )
|
2011-01-05 22:24:11 +01:00
|
|
|
{
|
2022-08-29 19:20:41 +02:00
|
|
|
cur->request->function->MakePut();
|
2011-01-05 22:24:11 +01:00
|
|
|
}
|
|
|
|
else
|
2018-04-25 21:48:47 +02:00
|
|
|
if( cur->request->method == Request::delete_ )
|
|
|
|
{
|
2022-08-29 19:20:41 +02:00
|
|
|
cur->request->function->MakeDelete();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( cur->request->method == Request::connect )
|
|
|
|
{
|
|
|
|
cur->request->function->MakeConnect();
|
2018-04-25 21:48:47 +02:00
|
|
|
}
|
|
|
|
else
|
2022-08-11 08:04:40 +02:00
|
|
|
if( cur->request->method == Request::options )
|
|
|
|
{
|
2022-08-29 19:20:41 +02:00
|
|
|
cur->request->function->MakeOptions();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( cur->request->method == Request::trace )
|
|
|
|
{
|
|
|
|
cur->request->function->MakeTrace();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( cur->request->method == Request::patch )
|
|
|
|
{
|
|
|
|
cur->request->function->MakePatch();
|
2022-08-11 08:04:40 +02:00
|
|
|
}
|
|
|
|
else
|
2016-07-13 15:13:56 +02:00
|
|
|
{
|
2022-08-29 19:20:41 +02:00
|
|
|
log << log1 << "Functions: I cannot call a function, an unknown request method (skipping)" << logend;
|
2016-07-13 15:13:56 +02:00
|
|
|
}
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-25 14:21:21 +02:00
|
|
|
void Functions::ContinueMakeFunction()
|
|
|
|
{
|
|
|
|
if( !cur->request->function )
|
|
|
|
{
|
2022-08-29 19:20:41 +02:00
|
|
|
cur->request->http_status = Header::status_500_internal_server_error; // or 404? (404 was originally)
|
|
|
|
log << log1 << "Functions: no function to call in the request continuation" << logend;
|
2022-07-25 14:21:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-29 19:20:41 +02:00
|
|
|
if( !system->DirsHaveReadExecPerm() ||
|
|
|
|
!system->HasReadExecAccess(cur->request->function->fun) ||
|
|
|
|
!cur->request->function->HasAccess() )
|
|
|
|
{
|
|
|
|
cur->request->http_status = Header::status_403_forbidden;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
log << log4 << "Functions: continuing method ";
|
|
|
|
cur->request->PutMethodName(log);
|
|
|
|
log << " for request " << cur->request << " for function " << cur->request->function->fun.url << logend;
|
2022-07-25 14:21:21 +02:00
|
|
|
|
|
|
|
if( cur->request->method == Request::get )
|
|
|
|
{
|
|
|
|
cur->request->function->ContinueMakeGet();
|
|
|
|
}
|
|
|
|
else
|
2022-08-29 19:20:41 +02:00
|
|
|
if( cur->request->method == Request::head )
|
|
|
|
{
|
|
|
|
cur->request->function->ContinueMakeHead();
|
|
|
|
}
|
|
|
|
else
|
2022-07-25 14:21:21 +02:00
|
|
|
if( cur->request->method == Request::post )
|
|
|
|
{
|
|
|
|
cur->request->function->ContinueMakePost();
|
|
|
|
}
|
|
|
|
else
|
2022-08-29 19:20:41 +02:00
|
|
|
if( cur->request->method == Request::put )
|
2022-07-25 14:21:21 +02:00
|
|
|
{
|
2022-08-29 19:20:41 +02:00
|
|
|
cur->request->function->ContinueMakePut();
|
2022-07-25 14:21:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if( cur->request->method == Request::delete_ )
|
|
|
|
{
|
|
|
|
cur->request->function->ContinueMakeDelete();
|
|
|
|
}
|
|
|
|
else
|
2022-08-29 19:20:41 +02:00
|
|
|
if( cur->request->method == Request::connect )
|
|
|
|
{
|
|
|
|
cur->request->function->ContinueMakeConnect();
|
|
|
|
}
|
|
|
|
else
|
2022-08-11 08:04:40 +02:00
|
|
|
if( cur->request->method == Request::options )
|
|
|
|
{
|
|
|
|
cur->request->function->ContinueMakeOptions();
|
|
|
|
}
|
|
|
|
else
|
2022-08-29 19:20:41 +02:00
|
|
|
if( cur->request->method == Request::trace )
|
|
|
|
{
|
|
|
|
cur->request->function->ContinueMakeTrace();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( cur->request->method == Request::patch )
|
|
|
|
{
|
|
|
|
cur->request->function->ContinueMakePatch();
|
|
|
|
}
|
|
|
|
else
|
2022-07-25 14:21:21 +02:00
|
|
|
{
|
2022-08-29 19:20:41 +02:00
|
|
|
log << log1 << "Functions: I cannot continue a request, an unknown request method (skipping)" << logend;
|
2022-07-25 14:21:21 +02:00
|
|
|
}
|
|
|
|
}
|
2011-01-05 22:24:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
void Functions::CheckGetPostTimes(time_t difference)
|
|
|
|
{
|
2022-05-30 05:35:05 +02:00
|
|
|
if( !cur->session->puser && config->use_antispam_mechanism_for_not_logged_users )
|
|
|
|
{
|
|
|
|
time_t now = std::time(0);
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2022-05-30 05:35:05 +02:00
|
|
|
if( cur->request->method != Request::post )
|
|
|
|
return;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2022-05-30 05:35:05 +02:00
|
|
|
if( now - cur->session->last_time_get >= (time_t)difference )
|
|
|
|
return;
|
|
|
|
|
|
|
|
cur->session->spam_score += 1;
|
|
|
|
log << log1 << "Functions: spam +1: POST after GET sent too fast" << logend;
|
|
|
|
}
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-07-02 13:16:36 +02:00
|
|
|
|
|
|
|
bool Functions::CheckAntispamCounter()
|
|
|
|
{
|
2022-05-30 05:35:05 +02:00
|
|
|
if( !cur->session->puser && config->use_antispam_mechanism_for_not_logged_users )
|
2018-07-02 13:16:36 +02:00
|
|
|
{
|
|
|
|
long form_id = Tol(cur->request->PostVar(L"winix_form_id"));
|
|
|
|
long counter_id = Tol(cur->request->PostVar(L"winix_form_counter"));
|
|
|
|
auto i = cur->session->antispan.find(form_id);
|
|
|
|
|
|
|
|
if( i != cur->session->antispan.end() )
|
|
|
|
{
|
|
|
|
if( i->second != counter_id )
|
|
|
|
{
|
|
|
|
log << log2 << "AP: you have provided a different counter, expecting: " << i->second << ", given: " << counter_id << logend;
|
|
|
|
cur->session->antispan.erase(i);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cur->session->antispan.erase(i);
|
|
|
|
log << log2 << "AP: provided a correct counter for this form" << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log << log2 << "AP: nonexisting form_id" << logend;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// !!uwaga zwracana wartosc zmieniona (true/false)
|
|
|
|
// !! IMPROVE ME in emacs.cpp there is a similar function
|
2021-05-31 10:58:34 +02:00
|
|
|
bool Functions::CheckAbuse(SLog * slog)
|
2010-10-19 02:31:20 +02:00
|
|
|
{
|
|
|
|
if( !system->rebus.CheckRebus() )
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->status = WINIX_ERR_INCORRECT_REBUS;
|
2021-05-31 10:58:34 +02:00
|
|
|
|
|
|
|
if( slog )
|
|
|
|
{
|
|
|
|
// put to locale
|
|
|
|
(*slog) << logerror << T(L"rebus_need_to_solve") << logend;
|
|
|
|
}
|
|
|
|
|
2010-10-19 02:31:20 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-02 13:16:36 +02:00
|
|
|
if( CheckAntispamCounter() )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-19 02:31:20 +02:00
|
|
|
CheckGetPostTimes();
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->session->spam_score > 0 )
|
2010-10-19 02:31:20 +02:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->status = WINIX_ERR_SPAM;
|
2010-10-19 02:31:20 +02:00
|
|
|
log << log1 << "Functions: ignoring due to suspected spamming" << logend;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
// returning true if the 'url' has to be changed
|
2010-09-30 22:58:20 +02:00
|
|
|
void Functions::ReadItemUrlSubject(Item & item, Item::Type item_type)
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
std::wstring * new_subject = cur->request->PostVarp(L"subject");
|
|
|
|
std::wstring * new_url = cur->request->PostVarp(L"url");
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2010-09-30 22:58:20 +02:00
|
|
|
if( new_subject )
|
|
|
|
item.subject = *new_subject;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2015-03-02 22:23:29 +01:00
|
|
|
/*
|
2010-08-10 18:12:50 +02:00
|
|
|
if( item.subject.empty() )
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
item.subject = cur->request->dir_tab.back()->subject;
|
2010-11-21 01:19:17 +01:00
|
|
|
item.subject += L"_msg_";
|
2011-01-23 15:15:30 +01:00
|
|
|
Toa(db->Size(cur->request->dir_tab.back()->id, Item::file), item.subject, 10, false);
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
2015-03-02 22:23:29 +01:00
|
|
|
*/
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2010-09-30 22:58:20 +02:00
|
|
|
if( new_url )
|
|
|
|
item.url = *new_url;
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
// if item.url is empty then it will be set from item.subject
|
2010-08-12 21:10:12 +02:00
|
|
|
PrepareUrl(item);
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-26 21:49:21 +01:00
|
|
|
void Functions::ReadItemFilterHtml(const std::wstring & html, std::wstring & html_filtered)
|
2010-08-14 19:56:07 +02:00
|
|
|
{
|
2021-07-26 03:54:02 +02:00
|
|
|
//html_filter.BreakWord(0);
|
2011-04-16 10:42:22 +02:00
|
|
|
html_filter.WrapLine(0);
|
2021-07-26 03:54:02 +02:00
|
|
|
//html_filter.TrimWhite(false);
|
2010-08-14 19:56:07 +02:00
|
|
|
html_filter.InsertTabs(0);
|
|
|
|
html_filter.SafeMode(true);
|
2011-04-16 10:42:22 +02:00
|
|
|
html_filter.ClearOrphans();
|
2014-06-19 01:18:28 +02:00
|
|
|
// SetNoFilterTag doesn't have to be called (default empty tag)
|
2010-08-14 19:56:07 +02:00
|
|
|
|
2021-11-26 21:49:21 +01:00
|
|
|
//html_filter.filter(cur->request->PostVar(L"itemcontent"), item.item_content.content_raw);
|
|
|
|
html_filter.filter(html, html_filtered);
|
2010-08-14 19:56:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-26 21:49:21 +01:00
|
|
|
void Functions::ReadItemContent(Item & item)
|
2010-08-14 19:56:07 +02:00
|
|
|
{
|
2021-11-26 21:49:21 +01:00
|
|
|
bool filter_html = config->editors_html_safe_mode;
|
2021-06-27 23:31:50 +02:00
|
|
|
bool is_root = cur->session->puser && cur->session->puser->is_super_user;
|
2010-08-14 19:56:07 +02:00
|
|
|
|
2021-11-26 21:49:21 +01:00
|
|
|
if( is_root && config->editors_html_safe_mode_skip_root )
|
2010-08-14 19:56:07 +02:00
|
|
|
filter_html = false;
|
|
|
|
|
2021-11-26 21:49:21 +01:00
|
|
|
std::wstring * content = cur->request->PostVarp(L"itemcontent");
|
|
|
|
std::wstring * content_parsed = cur->request->PostVarp(L"itemcontent_parsed");
|
|
|
|
|
|
|
|
if( item.item_content.content_raw_type != ItemContent::ct_markdown )
|
|
|
|
{
|
|
|
|
item.item_content.content_parsed.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( content )
|
|
|
|
{
|
|
|
|
if( item.item_content.content_raw_type == ItemContent::ct_html )
|
|
|
|
{
|
|
|
|
if( filter_html )
|
|
|
|
{
|
|
|
|
ReadItemFilterHtml(*content, item.item_content.content_raw);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item.item_content.content_raw = *content;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item.item_content.content_raw = *content;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( content_parsed )
|
|
|
|
{
|
|
|
|
if( item.item_content.content_raw_type == ItemContent::ct_markdown )
|
|
|
|
{
|
|
|
|
if( filter_html )
|
|
|
|
{
|
|
|
|
ReadItemFilterHtml(*content_parsed, item.item_content.content_parsed);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item.item_content.content_parsed = *content_parsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
item.item_content.content_parsed_type = ItemContent::ct_html;
|
|
|
|
}
|
|
|
|
}
|
2010-08-14 19:56:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-26 21:49:21 +01:00
|
|
|
void Functions::ReadItemContentType(Item & item)
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2021-02-24 01:19:47 +01:00
|
|
|
item.item_content.content_raw_type = ItemContent::ct_formatted_text; // default is formatted text
|
2021-11-26 21:49:21 +01:00
|
|
|
item.item_content.content_parsed_type = ItemContent::ct_formatted_text;
|
|
|
|
std::wstring * content_type_str = cur->request->PostVarp(L"contenttype");
|
2010-08-14 19:56:07 +02:00
|
|
|
|
2021-11-26 21:49:21 +01:00
|
|
|
if( content_type_str )
|
|
|
|
item.item_content.content_raw_type = ItemContent::get_content_type_from_str(*content_type_str);
|
2010-08-14 19:56:07 +02:00
|
|
|
|
2021-11-26 21:49:21 +01:00
|
|
|
if( item.item_content.content_raw_type != ItemContent::ct_text &&
|
|
|
|
item.item_content.content_raw_type != ItemContent::ct_formatted_text )
|
|
|
|
{
|
|
|
|
// ct_text and ct_formatted_text can use everyone
|
|
|
|
bool has_privileges = false;
|
2010-08-14 19:56:07 +02:00
|
|
|
|
2021-11-26 21:49:21 +01:00
|
|
|
if( cur->session->puser )
|
|
|
|
{
|
|
|
|
long user_id = cur->session->puser->id;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2021-11-26 21:49:21 +01:00
|
|
|
switch(item.item_content.content_raw_type)
|
|
|
|
{
|
|
|
|
case ItemContent::ct_html:
|
|
|
|
has_privileges = system->CanUseHtml(user_id);
|
|
|
|
break;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2021-11-26 21:49:21 +01:00
|
|
|
case ItemContent::ct_bbcode:
|
|
|
|
has_privileges = system->CanUseBBCode(user_id); // may test 'allow html' in such a case?
|
|
|
|
break;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2021-11-26 21:49:21 +01:00
|
|
|
case ItemContent::ct_other:
|
|
|
|
has_privileges = system->CanUseOther(user_id);
|
|
|
|
break;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2021-11-26 21:49:21 +01:00
|
|
|
case ItemContent::ct_markdown:
|
|
|
|
has_privileges = system->CanUseHtml(user_id);
|
|
|
|
break;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2021-11-26 21:49:21 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2021-11-26 21:49:21 +01:00
|
|
|
if( !has_privileges )
|
|
|
|
{
|
|
|
|
item.item_content.content_raw_type = ItemContent::ct_formatted_text;
|
|
|
|
}
|
2016-07-13 15:13:56 +02:00
|
|
|
}
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// item_type - the type of an item you are expecting to read
|
|
|
|
// returns true if the url has to be changed
|
|
|
|
// at the moment this is only checked for Item::file - for Item::dir it returns always true
|
2011-01-05 22:24:11 +01:00
|
|
|
// !! zmienic nazwe na ReadUrlSubjectContent
|
2010-09-30 22:58:20 +02:00
|
|
|
void Functions::ReadItem(Item & item, Item::Type item_type)
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
|
|
|
if( item_type == Item::none )
|
2010-09-30 22:58:20 +02:00
|
|
|
return;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
item.type = item_type;
|
2011-01-23 15:15:30 +01:00
|
|
|
item.parent_id = cur->request->dir_tab.back()->id; // !! moze to dac jako parametr?
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2010-09-30 22:58:20 +02:00
|
|
|
ReadItemUrlSubject(item, item_type);
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
if( item_type == Item::file )
|
2021-11-26 21:49:21 +01:00
|
|
|
{
|
|
|
|
ReadItemContentType(item);
|
|
|
|
ReadItemContent(item);
|
|
|
|
}
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Functions::SetUser(Item & item)
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->session && cur->session->puser )
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2021-02-24 01:19:47 +01:00
|
|
|
item.item_content.user_id = cur->session->puser->id;
|
|
|
|
item.item_content.guest_name.clear();
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-24 01:19:47 +01:00
|
|
|
item.item_content.user_id = -1;
|
|
|
|
cur->request->PostVar(L"guestname", item.item_content.guest_name);
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
2021-02-24 01:19:47 +01:00
|
|
|
item.item_content.group_id = cur->request->dir_tab.back()->item_content.group_id;
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
2014-02-12 17:30:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace Winix
|
|
|
|
|