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>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2018-04-25 21:48:47 +02:00
|
|
|
* Copyright (c) 2010-2018, 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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2011-06-19 22:59:58 +02:00
|
|
|
system->mounts.ReadMounts(item.content);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Functions::Add(FunctionBase * fun)
|
|
|
|
{
|
2012-01-06 13:55:08 +01:00
|
|
|
if( fun->fun.url.empty() )
|
|
|
|
{
|
|
|
|
log << log1 << "Functions: skipping a function with an empty url" << logend;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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;
|
2010-08-10 18:12:50 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetObjects(fun);
|
2010-08-13 22:04:57 +02:00
|
|
|
table[fun->fun.url] = fun;
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Functions::Add(FunctionBase & fun)
|
|
|
|
{
|
|
|
|
Add(&fun);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
2010-08-10 18:12:50 +02:00
|
|
|
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);
|
2010-08-10 18:12:50 +02:00
|
|
|
Add(fun_who);
|
2010-11-04 17:46:19 +01:00
|
|
|
Add(fun_vim);
|
2010-09-29 23:24:34 +02:00
|
|
|
|
2018-11-21 12:03:53 +01:00
|
|
|
plugin->Call((Session*)0, 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Functions::Init()
|
|
|
|
{
|
|
|
|
CreateFunctions();
|
|
|
|
InitFunctions();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
void Functions::Parse()
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
function_parser.Parse(cur, db, this, system);
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Functions::SetDefaultFunctionForFile()
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->item.file_type != WINIX_ITEM_FILETYPE_NONE )
|
|
|
|
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 )
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->dir_tab.back()->link_redirect == 1 )
|
2011-01-05 22:24:11 +01:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
system->RedirectTo(cur->request->dir_tab.back()->link_to);
|
2011-01-05 22:24:11 +01:00
|
|
|
}
|
|
|
|
else
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( system->FollowAllLinks(cur->request->dir_tab.back()->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)
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->item.link_redirect == 1 )
|
2011-01-05 22:24:11 +01:00
|
|
|
{
|
|
|
|
if( was_default_function )
|
2011-01-23 15:15:30 +01:00
|
|
|
system->RedirectTo(cur->request->item.link_to);
|
2011-01-05 22:24:11 +01:00
|
|
|
else
|
2011-01-23 15:15:30 +01:00
|
|
|
system->RedirectWithFunctionAndParamsTo(cur->request->item.link_to);
|
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( system->FollowAllLinks(cur->request->item.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;
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( !cur->request->is_item && !cur->request->dir_tab.back()->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
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->status = WINIX_ERR_NO_FUNCTION;
|
2011-01-05 22:24:11 +01:00
|
|
|
log << log1 << "Functions: no function (neither cat nor ls)" << logend;
|
2010-08-10 18:12:50 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
if( !system->DirsHaveReadExecPerm() ||
|
2011-01-23 15:15:30 +01:00
|
|
|
!system->HasReadExecAccess(cur->request->function->fun) ||
|
|
|
|
!cur->request->function->HasAccess() )
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
|
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
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->redirect_to.empty() )
|
|
|
|
cur->request->function->MakeGet();
|
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
|
|
|
{
|
|
|
|
// we don't use post with redirecting (the post variables would be lost)
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->redirect_to.empty() )
|
|
|
|
cur->request->function->MakePost();
|
2011-01-05 22:24:11 +01:00
|
|
|
else
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
|
2011-01-05 22:24:11 +01:00
|
|
|
}
|
|
|
|
else
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->method == Request::head )
|
2011-01-05 22:24:11 +01:00
|
|
|
{
|
|
|
|
// do nothing
|
2016-07-13 15:13:56 +02:00
|
|
|
|
|
|
|
// !! IMPROVE ME
|
|
|
|
// we should make a page similar like in a GET request but the content should not be returned only
|
2011-01-05 22:24:11 +01:00
|
|
|
}
|
|
|
|
else
|
2018-04-25 21:48:47 +02:00
|
|
|
if( cur->request->method == Request::delete_ )
|
|
|
|
{
|
|
|
|
if( cur->request->redirect_to.empty() )
|
|
|
|
cur->request->function->MakeDelete();
|
|
|
|
}
|
|
|
|
else
|
2016-07-13 15:13:56 +02:00
|
|
|
{
|
2011-01-05 22:24:11 +01:00
|
|
|
log << log1 << "Functions: unknown request method (skipping)" << logend;
|
2016-07-13 15:13:56 +02:00
|
|
|
}
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
void Functions::CheckGetPostTimes(time_t difference)
|
|
|
|
{
|
|
|
|
time_t now = std::time(0);
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->session->puser )
|
2010-08-10 18:12:50 +02:00
|
|
|
return;
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->method != Request::post )
|
2010-08-10 18:12:50 +02:00
|
|
|
return;
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( now - cur->session->last_time_get >= (time_t)difference )
|
2010-08-10 18:12:50 +02:00
|
|
|
return;
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->AllPostVarEmpty() )
|
2010-08-10 18:12:50 +02:00
|
|
|
return;
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->session->spam_score += 1;
|
2010-08-10 18:12:50 +02:00
|
|
|
log << log1 << "Functions: spam +1: POST after GET sent too fast" << logend;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-07-02 13:16:36 +02:00
|
|
|
|
|
|
|
bool Functions::CheckAntispamCounter()
|
|
|
|
{
|
|
|
|
if( !cur->session->puser )
|
|
|
|
{
|
|
|
|
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
|
2010-10-19 02:31:20 +02:00
|
|
|
bool Functions::CheckAbuse()
|
|
|
|
{
|
|
|
|
if( !system->rebus.CheckRebus() )
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->status = WINIX_ERR_INCORRECT_REBUS;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-14 19:56:07 +02:00
|
|
|
void Functions::ReadItemFilterHtml(Item & item)
|
|
|
|
{
|
2011-04-16 10:42:22 +02:00
|
|
|
html_filter.BreakWord(0);
|
|
|
|
html_filter.WrapLine(0);
|
2010-08-14 19:56:07 +02:00
|
|
|
html_filter.TrimWhite(false);
|
|
|
|
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
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
html_filter.Filter(cur->request->PostVar(L"itemcontent"), item.content);
|
2010-08-14 19:56:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
void Functions::ReadItemContent(Item & item, const std::wstring & content_type)
|
2010-08-14 19:56:07 +02:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
bool is_root = cur->session->puser && cur->session->puser->super_user;
|
2010-11-21 01:19:17 +01:00
|
|
|
bool filter_html = (content_type == L"2") && config->editors_html_safe_mode;
|
2010-08-14 19:56:07 +02:00
|
|
|
|
|
|
|
if( filter_html && is_root && config->editors_html_safe_mode_skip_root )
|
|
|
|
filter_html = false;
|
|
|
|
|
|
|
|
if( filter_html )
|
|
|
|
ReadItemFilterHtml(item);
|
|
|
|
else
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->PostVar(L"itemcontent", item.content);
|
2010-08-14 19:56:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
void Functions::ReadItemContentWithType(Item & item)
|
|
|
|
{
|
|
|
|
item.content_type = Item::ct_formatted_text; // default is formatted text
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->PostVar(L"contenttype", temp);
|
2010-08-14 19:56:07 +02:00
|
|
|
|
|
|
|
ReadItemContent(item, temp);
|
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
// ct_text and ct_formatted_text can use everyone
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
if( temp == L"0" )
|
2010-08-10 18:12:50 +02:00
|
|
|
item.content_type = Item::ct_text;
|
|
|
|
else
|
2010-11-21 01:19:17 +01:00
|
|
|
if( temp == L"1" )
|
2010-08-10 18:12:50 +02:00
|
|
|
item.content_type = Item::ct_formatted_text;
|
|
|
|
|
|
|
|
|
|
|
|
// those below need special privileges
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( !cur->session->puser )
|
2010-08-10 18:12:50 +02:00
|
|
|
return;
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
long user_id = cur->session->puser->id;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
if( temp == L"2" )
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
|
|
|
if( system->CanUseHtml(user_id) )
|
|
|
|
item.content_type = Item::ct_html;
|
|
|
|
}
|
|
|
|
else
|
2010-11-21 01:19:17 +01:00
|
|
|
if( temp == L"3" )
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
|
|
|
if( system->CanUseBBCode(user_id) )
|
|
|
|
item.content_type = Item::ct_bbcode;
|
|
|
|
}
|
2016-07-13 15:13:56 +02:00
|
|
|
else
|
|
|
|
if( temp == L"4" )
|
|
|
|
{
|
|
|
|
if( system->CanUseOther(user_id) )
|
|
|
|
item.content_type = Item::ct_other;
|
|
|
|
}
|
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 )
|
|
|
|
ReadItemContentWithType(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
item.user_id = cur->session->puser->id;
|
2010-08-10 18:12:50 +02:00
|
|
|
item.guest_name.clear();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item.user_id = -1;
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->PostVar(L"guestname", item.guest_name);
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
item.group_id = cur->request->dir_tab.back()->group_id;
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
2014-02-12 17:30:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace Winix
|
|
|
|
|