2010-02-11 21:56:52 +01:00
|
|
|
/*
|
2010-02-28 01:08:10 +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>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2021-05-31 10:58:34 +02:00
|
|
|
* Copyright (c) 2008-2021, Tomasz Sowa
|
2010-02-11 21:56:52 +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.
|
|
|
|
*
|
2010-02-11 21:56:52 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ctime>
|
|
|
|
#include "templates.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
#include "core/request.h"
|
2010-10-24 01:12:47 +02:00
|
|
|
#include "core/misc.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
#include "functions/functions.h"
|
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
namespace Winix
|
|
|
|
{
|
2010-02-11 21:56:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
namespace TemplatesFunctions
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2012-02-28 22:09:44 +01:00
|
|
|
void winix_account_need_email_verification(Info & i)
|
|
|
|
{
|
|
|
|
i.res = config->account_need_email_verification;
|
|
|
|
}
|
|
|
|
|
2010-02-11 21:56:52 +01:00
|
|
|
|
|
|
|
void winix_cur_time(Info & i)
|
|
|
|
{
|
|
|
|
static char buffer[100];
|
|
|
|
|
2021-05-20 20:59:12 +02:00
|
|
|
pt::Date & date = cur->request->start_date;
|
2010-02-11 21:56:52 +01:00
|
|
|
|
2012-05-27 01:04:49 +02:00
|
|
|
sprintf(buffer, "%02d:%02d:%02d", date.hour, date.min, date.sec);
|
2010-02-11 21:56:52 +01:00
|
|
|
i.out << buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
void winix_how_many_sessions(Info & i)
|
|
|
|
{
|
|
|
|
i.out << session_manager->Size();
|
|
|
|
}
|
|
|
|
|
2010-02-11 21:56:52 +01:00
|
|
|
|
|
|
|
void winix_users_logged(Info & i)
|
|
|
|
{
|
2010-08-10 18:12:50 +02:00
|
|
|
i.out << system->users.HowManyLogged();
|
2010-02-11 21:56:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-16 19:34:41 +01:00
|
|
|
void winix_function(Info & i)
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
i.out << cur->request->function->fun.url;
|
2010-02-16 19:34:41 +01:00
|
|
|
}
|
|
|
|
|
2010-02-11 21:56:52 +01:00
|
|
|
|
|
|
|
void winix_function_is(Info & i)
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( !cur->request->function )
|
2010-02-11 21:56:52 +01:00
|
|
|
return;
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
i.res = (cur->request->function->fun.url == i.par);
|
2010-02-11 21:56:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_function_param_is(Info & i)
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
i.res = cur->request->IsParam(i.par);
|
2010-02-11 21:56:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-22 05:14:26 +01:00
|
|
|
void winix_function_param_is_not(Info & i)
|
|
|
|
{
|
|
|
|
i.res = !cur->request->IsParam(i.par);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-11 22:37:28 +01:00
|
|
|
void winix_function_param_value(Info & i)
|
|
|
|
{
|
|
|
|
i.out << cur->request->ParamValue(i.par);
|
|
|
|
}
|
|
|
|
|
2011-02-22 05:14:26 +01:00
|
|
|
|
2011-12-04 20:34:39 +01:00
|
|
|
// first parameter is param_name
|
|
|
|
// second parameter is param_value
|
|
|
|
void winix_function_param_value_is(Info & i)
|
|
|
|
{
|
|
|
|
if( i.params.size() == 2 )
|
2014-10-28 20:14:46 +01:00
|
|
|
i.res = (cur->request->ParamValue(i.params[0].str) == i.params[1].str);
|
2011-12-04 20:34:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_function_param_value_is_not(Info & i)
|
|
|
|
{
|
|
|
|
if( i.params.size() == 2 )
|
2014-10-28 20:14:46 +01:00
|
|
|
i.res = (cur->request->ParamValue(i.params[0].str) != i.params[1].str);
|
2011-12-04 20:34:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-11 22:42:49 +02:00
|
|
|
void winix_has_plugin(Info & i)
|
|
|
|
{
|
|
|
|
size_t exist = 0;
|
|
|
|
|
|
|
|
if( i.params.empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
for(size_t a=0 ; a<i.params.size() ; ++a)
|
|
|
|
{
|
2018-11-21 18:51:15 +01:00
|
|
|
if( plugin->HasPlugin(i.params[a].str) )
|
2010-10-11 22:42:49 +02:00
|
|
|
++exist;
|
|
|
|
}
|
|
|
|
|
|
|
|
i.res = (exist == i.params.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-11 21:56:52 +01:00
|
|
|
|
2010-02-13 21:12:15 +01:00
|
|
|
void winix_loadavg_now(Info & i)
|
|
|
|
{
|
|
|
|
char buf[20];
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
sprintf(buf, "%.2f", (double)system->load_avg.LoadAvgNow());
|
2010-02-13 21:12:15 +01:00
|
|
|
i.out << buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_loadavg_1(Info & i)
|
|
|
|
{
|
|
|
|
char buf[20];
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
sprintf(buf, "%.2f", (double)system->load_avg.LoadAvg1());
|
2010-02-13 21:12:15 +01:00
|
|
|
i.out << buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_loadavg_5(Info & i)
|
|
|
|
{
|
|
|
|
char buf[20];
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
sprintf(buf, "%.2f", (double)system->load_avg.LoadAvg5());
|
2010-02-13 21:12:15 +01:00
|
|
|
i.out << buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_loadavg_15(Info & i)
|
|
|
|
{
|
|
|
|
char buf[20];
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
sprintf(buf, "%.2f", (double)system->load_avg.LoadAvg15());
|
2010-02-13 21:12:15 +01:00
|
|
|
i.out << buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_req_per_sec_now(Info & i)
|
|
|
|
{
|
|
|
|
char buf[20];
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
sprintf(buf, "%.2f", (double)system->load_avg.ReqPerSecNow());
|
2010-02-13 21:12:15 +01:00
|
|
|
i.out << buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_req_per_sec_1(Info & i)
|
|
|
|
{
|
|
|
|
char buf[20];
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
sprintf(buf, "%.2f", (double)system->load_avg.ReqPerSec1());
|
2010-02-13 21:12:15 +01:00
|
|
|
i.out << buf;
|
|
|
|
}
|
|
|
|
|
2010-02-15 01:31:14 +01:00
|
|
|
|
2010-02-13 21:12:15 +01:00
|
|
|
void winix_req_per_sec_5(Info & i)
|
|
|
|
{
|
|
|
|
char buf[20];
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
sprintf(buf, "%.2f", (double)system->load_avg.ReqPerSec5());
|
2010-02-13 21:12:15 +01:00
|
|
|
i.out << buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_req_per_sec_15(Info & i)
|
|
|
|
{
|
|
|
|
char buf[20];
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
sprintf(buf, "%.2f", (double)system->load_avg.ReqPerSec15());
|
2010-02-13 21:12:15 +01:00
|
|
|
i.out << buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-28 01:08:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-06-22 01:53:19 +02:00
|
|
|
void winix_show_content_in_full_window(Info & i)
|
2010-06-21 00:47:24 +02:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->function )
|
2011-06-15 01:45:42 +02:00
|
|
|
i.res = (cur->request->function == &functions->fun_ckeditor ||
|
|
|
|
cur->request->function == &functions->fun_tinymce ||
|
|
|
|
cur->request->function == &functions->fun_nicedit ||
|
|
|
|
cur->request->function == &functions->fun_vim ||
|
2011-08-02 02:10:45 +02:00
|
|
|
cur->request->function == &functions->fun_emacs ||
|
|
|
|
cur->request->function == &functions->fun_upload );
|
2010-06-21 00:47:24 +02:00
|
|
|
}
|
|
|
|
|
2010-02-28 01:08:10 +01:00
|
|
|
|
2011-04-26 19:19:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-02-13 21:12:15 +01:00
|
|
|
|
2011-11-25 05:51:55 +01:00
|
|
|
void winix_has_postvar(Info & i)
|
|
|
|
{
|
|
|
|
i.res = cur->request->IsPostVar(i.par);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_postvar(Info & i)
|
|
|
|
{
|
|
|
|
i.out << cur->request->PostVar(i.par);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-28 02:09:27 +02:00
|
|
|
// first parameter is param_name
|
|
|
|
// second parameter is param_value
|
|
|
|
void winix_postvar_value_is(Info & i)
|
|
|
|
{
|
|
|
|
if( i.params.size() == 2 )
|
2014-10-28 20:14:46 +01:00
|
|
|
i.res = (cur->request->PostVar(i.params[0].str) == i.params[1].str);
|
2012-03-28 02:09:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_postvar_value_is_not(Info & i)
|
|
|
|
{
|
|
|
|
if( i.params.size() == 2 )
|
2014-10-28 20:14:46 +01:00
|
|
|
i.res = (cur->request->PostVar(i.params[0].str) != i.params[1].str);
|
2012-03-28 02:09:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-30 23:14:03 +02:00
|
|
|
void winix_subdomain(Info & i)
|
|
|
|
{
|
2012-06-03 04:14:33 +02:00
|
|
|
i.out << cur->request->subdomain;
|
2012-05-30 23:14:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_subdomain_is_empty(Info & i)
|
|
|
|
{
|
|
|
|
i.res = cur->request->subdomain.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_subdomain_is_not_empty(Info & i)
|
|
|
|
{
|
|
|
|
i.res = !cur->request->subdomain.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
void winix_subdomain_is(Info & i)
|
|
|
|
{
|
|
|
|
i.res = cur->request->subdomain == i.par;
|
|
|
|
}
|
|
|
|
|
2012-03-28 02:09:27 +02:00
|
|
|
|
2011-04-26 19:19:08 +02:00
|
|
|
|
|
|
|
|
2014-10-18 20:12:04 +02:00
|
|
|
|
2011-04-26 19:19:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-23 01:34:33 +02:00
|
|
|
static size_t tz_index;
|
2011-04-26 19:19:08 +02:00
|
|
|
|
2012-06-23 01:34:33 +02:00
|
|
|
void winix_tz_tab(Info & i)
|
|
|
|
{
|
|
|
|
tz_index = i.iter;
|
|
|
|
|
|
|
|
i.res = tz_index < system->time_zones.Size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_tz_tab_id(Info & i)
|
|
|
|
{
|
2012-06-27 01:19:19 +02:00
|
|
|
TimeZone * tz = system->time_zones.GetZoneByIndex(tz_index);
|
|
|
|
|
|
|
|
if( tz )
|
|
|
|
i.out << tz->id;
|
2012-06-23 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_tz_tab_name(Info & i)
|
|
|
|
{
|
2012-06-27 01:19:19 +02:00
|
|
|
TimeZone * tz = system->time_zones.GetZoneByIndex(tz_index);
|
|
|
|
|
|
|
|
if( tz )
|
|
|
|
i.out << locale.Get(tz->name);
|
2012-06-23 01:34:33 +02:00
|
|
|
}
|
2011-04-26 19:19:08 +02:00
|
|
|
|
|
|
|
|
2012-06-23 01:34:33 +02:00
|
|
|
void winix_tz_tab_offset_sec(Info & i)
|
|
|
|
{
|
2012-06-27 01:19:19 +02:00
|
|
|
TimeZone * tz = system->time_zones.GetZoneByIndex(tz_index);
|
|
|
|
|
|
|
|
if( tz )
|
|
|
|
i.out << tz->offset;
|
2012-06-23 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void winix_tz_tab_offset_hour_min(Info & i)
|
|
|
|
{
|
2012-06-27 01:19:19 +02:00
|
|
|
TimeZone * tz = system->time_zones.GetZoneByIndex(tz_index);
|
|
|
|
|
|
|
|
if( tz )
|
2012-06-23 01:34:33 +02:00
|
|
|
{
|
2012-06-27 01:19:19 +02:00
|
|
|
time_t offset = tz->offset;
|
2012-06-23 01:34:33 +02:00
|
|
|
|
|
|
|
if( offset < 0 )
|
|
|
|
{
|
|
|
|
i.out << '-';
|
|
|
|
offset = -offset;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i.out << '+';
|
|
|
|
}
|
|
|
|
|
|
|
|
print_hour_min(i, offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-27 01:19:19 +02:00
|
|
|
static size_t locale_id;
|
2012-06-23 01:34:33 +02:00
|
|
|
|
2012-06-27 01:19:19 +02:00
|
|
|
void winix_locale_tab(Info & i)
|
2012-06-23 01:34:33 +02:00
|
|
|
{
|
2012-06-27 01:19:19 +02:00
|
|
|
locale_id = i.iter;
|
|
|
|
i.res = locale_id < locale.Size();
|
2012-06-23 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-27 01:19:19 +02:00
|
|
|
void winix_locale_tab_id(Info & i)
|
2012-06-23 01:34:33 +02:00
|
|
|
{
|
2012-06-27 01:19:19 +02:00
|
|
|
if( locale_id < locale.Size() )
|
2012-06-28 01:21:43 +02:00
|
|
|
i.out << Toi(locale.GetByIndex(L"winix_locale_id", locale_id, false));
|
2012-06-23 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-27 01:19:19 +02:00
|
|
|
void winix_locale_tab_name(Info & i)
|
2012-06-23 01:34:33 +02:00
|
|
|
{
|
2012-06-27 01:19:19 +02:00
|
|
|
if( locale_id < locale.Size() )
|
2012-06-28 01:21:43 +02:00
|
|
|
i.out << locale.GetByIndex(L"locale_name", locale_id, false);
|
2012-06-23 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-27 19:36:04 +02:00
|
|
|
void winix_is_htmx_request(Info & i)
|
|
|
|
{
|
2021-05-31 10:58:34 +02:00
|
|
|
i.res = cur->request->is_htmx_request;
|
2021-05-27 19:36:04 +02:00
|
|
|
}
|
|
|
|
|
2012-06-23 01:34:33 +02:00
|
|
|
|
2021-10-07 04:41:06 +02:00
|
|
|
void lang(Info & i)
|
|
|
|
{
|
|
|
|
i.res = !i.par.empty();
|
|
|
|
|
|
|
|
if( i.res )
|
|
|
|
i.out << locale.Get(i.par);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-26 19:19:08 +02:00
|
|
|
|
|
|
|
|
2010-02-11 21:56:52 +01:00
|
|
|
} // namespace
|
2014-02-12 17:30:49 +01:00
|
|
|
|
|
|
|
} // namespace Winix
|
|
|
|
|