fixed: there were mktime() used on some dirs Items
so sometimes the time of the dir was changed now for converting tm into time_t use: time_t Time(const tm & par); time_t Time(const tm * par); tm Time(time_t par); from core/misc.h now winix internally use GMT time only when printing it is converted to local user time temporarily all users use the same local time (config: time_zone_offset) (only logs are genereted with local system time) added to system: time_t LocalTime(time_t gmt_time); tm LocalTime(const tm * ptm); tm LocalTime(const tm & ptm); they convert GMT time to local user time git-svn-id: svn://ttmath.org/publicrep/winix/trunk@666 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -83,7 +83,8 @@ groups.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h
|
||||
groups.o: ../core/thread.h ../core/dircontainer.h ../core/ugcontainer.h
|
||||
htmlfilter.o: htmlfilter.h
|
||||
httpsimpleparser.o: httpsimpleparser.h
|
||||
lastcontainer.o: lastcontainer.h log.h
|
||||
item.o: item.h misc.h
|
||||
lastcontainer.o: lastcontainer.h log.h misc.h item.h
|
||||
loadavg.o: loadavg.h log.h
|
||||
locale.o: locale.h confparser.h log.h
|
||||
log.o: log.h
|
||||
@@ -231,9 +232,9 @@ request.o: ../core/item.h ../templates/ckeditorgetparser.h
|
||||
request.o: ../core/httpsimpleparser.h ../core/log.h
|
||||
request.o: ../templates/indexpatterns.h ../templates/localefilter.h
|
||||
request.o: ../core/locale.h ../core/locale.h ../core/sessionmanager.h
|
||||
session.o: session.h item.h error.h user.h plugindata.h rebus.h
|
||||
session.o: session.h item.h error.h user.h plugindata.h rebus.h misc.h
|
||||
sessioncontainer.o: sessioncontainer.h session.h item.h error.h user.h
|
||||
sessioncontainer.o: plugindata.h rebus.h lastcontainer.h log.h
|
||||
sessioncontainer.o: plugindata.h rebus.h lastcontainer.h log.h misc.h
|
||||
sessionmanager.o: sessionmanager.h sessioncontainer.h session.h item.h
|
||||
sessionmanager.o: error.h user.h plugindata.h rebus.h lastcontainer.h
|
||||
sessionmanager.o: config.h confparser.h htmlfilter.h request.h requesttypes.h
|
||||
@@ -277,7 +278,7 @@ sessionparser.o: ../db/dbtextstream.h ../core/textstream.h ../core/error.h
|
||||
sessionparser.o: log.h ../db/dbitemquery.h ../core/item.h
|
||||
sessionparser.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h
|
||||
sessionparser.o: ../core/thread.h ../core/dircontainer.h
|
||||
sessionparser.o: ../core/ugcontainer.h
|
||||
sessionparser.o: ../core/ugcontainer.h misc.h
|
||||
system.o: system.h dirs.h item.h dircontainer.h ../db/db.h ../db/dbbase.h
|
||||
system.o: ../db/dbconn.h ../db/dbtextstream.h ../core/textstream.h
|
||||
system.o: ../core/error.h log.h ../db/dbitemquery.h ../core/item.h
|
||||
|
@@ -1 +1 @@
|
||||
o = acceptbaseparser.o app.o bbcodeparser.o compress.o config.o confparser.o dircontainer.o dirs.o groups.o htmlfilter.o httpsimpleparser.o lastcontainer.o loadavg.o locale.o log.o misc.o mount.o mountparser.o mounts.o notify.o plugin.o plugindata.o postmultiparser.o rebus.o request.o session.o sessioncontainer.o sessionmanager.o sessionparser.o system.o textstream.o users.o
|
||||
o = acceptbaseparser.o app.o bbcodeparser.o compress.o config.o confparser.o dircontainer.o dirs.o groups.o htmlfilter.o httpsimpleparser.o item.o lastcontainer.o loadavg.o locale.o log.o misc.o mount.o mountparser.o mounts.o notify.o plugin.o plugindata.o postmultiparser.o rebus.o request.o session.o sessioncontainer.o sessionmanager.o sessionparser.o system.o textstream.o users.o
|
||||
|
18
core/app.cpp
18
core/app.cpp
@@ -19,7 +19,7 @@
|
||||
App::App()
|
||||
{
|
||||
stdout_is_closed = false;
|
||||
last_sessions_save = time(0);
|
||||
last_sessions_save = std::time(0);
|
||||
|
||||
db.SetConn(db_conn);
|
||||
|
||||
@@ -278,7 +278,7 @@ void App::Start()
|
||||
|
||||
void App::SaveSessionsIfNeeded()
|
||||
{
|
||||
time_t t = time(0);
|
||||
time_t t = std::time(0);
|
||||
|
||||
if( last_sessions_save + 86400 > t )
|
||||
return;
|
||||
@@ -531,17 +531,9 @@ void App::PrepareSessionCookie()
|
||||
}
|
||||
else
|
||||
{
|
||||
time_t t = time(0) + config.session_remember_max_idle;
|
||||
tm * expires = localtime(&t);
|
||||
|
||||
if( !expires )
|
||||
{
|
||||
// oops, something wrong
|
||||
request.SetCookie(config.http_session_id_name.c_str(), request.session->id);
|
||||
return;
|
||||
}
|
||||
|
||||
request.SetCookie(config.http_session_id_name.c_str(), request.session->id, expires);
|
||||
time_t t = std::time(0) + config.session_remember_max_idle;
|
||||
tm expires = Time(t);
|
||||
request.SetCookie(config.http_session_id_name.c_str(), request.session->id, &expires);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -165,6 +165,9 @@ void Config::AssignValues(bool stdout_is_closed)
|
||||
plugins_dir = Text("plugins_dir", "/usr/local/winix/plugins");
|
||||
NoLastSlash(plugins_dir);
|
||||
parser.ListText("plugins", plugin_file);
|
||||
|
||||
time_zone_offset = Int("time_zone_offset", 0);
|
||||
time_zone_offset_guest = Int("time_zone_offset_guest", 0);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -210,6 +210,15 @@ public:
|
||||
// (if true the html code for root is not filtered)
|
||||
bool editors_html_safe_mode_skip_root;
|
||||
|
||||
// temporarily we do not support time zones per user
|
||||
// there is one offset for all users
|
||||
// default: 0
|
||||
int time_zone_offset;
|
||||
|
||||
// time zone offset for guests (not logged users)
|
||||
// default: 0
|
||||
int time_zone_offset_guest;
|
||||
|
||||
|
||||
/*
|
||||
*/
|
||||
|
63
core/item.cpp
Executable file
63
core/item.cpp
Executable file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "item.h"
|
||||
#include "misc.h"
|
||||
|
||||
|
||||
|
||||
Item::Item()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
void Item::SetDateToNow()
|
||||
{
|
||||
date_creation = Time(std::time(0));
|
||||
date_modification = date_creation;
|
||||
}
|
||||
|
||||
|
||||
void Item::SetDateModifyToNow()
|
||||
{
|
||||
date_modification = Time(std::time(0));
|
||||
}
|
||||
|
||||
|
||||
void Item::Clear()
|
||||
{
|
||||
id = -1;
|
||||
|
||||
user_id = -1;
|
||||
group_id = -1;
|
||||
privileges = 0;
|
||||
modification_user_id = -1;
|
||||
|
||||
guest_name.clear();
|
||||
|
||||
subject.clear();
|
||||
content.clear();
|
||||
url.clear();
|
||||
|
||||
content_type = ct_formatted_text;
|
||||
|
||||
type = none;
|
||||
parent_id = -1;
|
||||
default_item = -1;
|
||||
|
||||
content_id = -1;
|
||||
|
||||
auth = auth_none;
|
||||
auth_path.clear();
|
||||
|
||||
html_template.clear();
|
||||
|
||||
SetDateToNow();
|
||||
}
|
63
core/item.h
63
core/item.h
@@ -14,7 +14,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
struct Item
|
||||
{
|
||||
long id;
|
||||
@@ -83,64 +82,12 @@ std::string auth_path; // path to a file (if auth!=auth_none)
|
||||
|
||||
std::string html_template;
|
||||
|
||||
// methods
|
||||
|
||||
Item()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
void SetDateToNow()
|
||||
{
|
||||
time_t t = std::time(0);
|
||||
date_creation = *std::localtime( &t );
|
||||
date_modification = date_creation;
|
||||
}
|
||||
|
||||
|
||||
void SetDateModifyToNow()
|
||||
{
|
||||
time_t t = std::time(0);
|
||||
date_modification = *std::localtime( &t );
|
||||
}
|
||||
|
||||
|
||||
void Clear()
|
||||
{
|
||||
id = -1;
|
||||
|
||||
user_id = -1;
|
||||
group_id = -1;
|
||||
privileges = 0;
|
||||
modification_user_id = -1;
|
||||
|
||||
guest_name.clear();
|
||||
|
||||
subject.clear();
|
||||
content.clear();
|
||||
url.clear();
|
||||
|
||||
content_type = ct_formatted_text;
|
||||
|
||||
type = none;
|
||||
parent_id = -1;
|
||||
default_item = -1;
|
||||
|
||||
content_id = -1;
|
||||
|
||||
auth = auth_none;
|
||||
auth_path.clear();
|
||||
|
||||
html_template.clear();
|
||||
|
||||
SetDateToNow();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// methods
|
||||
Item();
|
||||
void SetDateToNow();
|
||||
void SetDateModifyToNow();
|
||||
void Clear();
|
||||
|
||||
};
|
||||
|
||||
|
@@ -10,7 +10,7 @@
|
||||
|
||||
#include "lastcontainer.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
|
||||
LastItem::LastItem()
|
||||
@@ -87,9 +87,7 @@ LastTab::iterator i = FindNotLoggedOut(user_id, session_id);
|
||||
li.name = name;
|
||||
li.ip = ip;
|
||||
li.session_id = session_id;
|
||||
|
||||
time_t t = std::time(0);
|
||||
li.start = *localtime(&t);
|
||||
li.start = Time(std::time(0));
|
||||
|
||||
last_tab.insert(last_tab.end(), li);
|
||||
|
||||
@@ -105,8 +103,7 @@ LastTab::iterator i = FindNotLoggedOut(user_id, session_id);
|
||||
|
||||
if( i != last_tab.end() )
|
||||
{
|
||||
time_t t = std::time(0);
|
||||
i->end = *localtime(&t);
|
||||
i->end = Time(std::time(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -42,6 +42,8 @@ void Log::OpenFile()
|
||||
|
||||
void Log::PutDate(Manipulators m)
|
||||
{
|
||||
// logs are related to localtime
|
||||
|
||||
time_t t = std::time(0);
|
||||
std::tm * loct = std::localtime(&t);
|
||||
|
||||
|
@@ -311,31 +311,43 @@ static char buffer[100];
|
||||
}
|
||||
|
||||
|
||||
const char * DateToStr(tm * ptm)
|
||||
const char * DateToStr(const tm * ptm)
|
||||
{
|
||||
return DateToStr(ptm->tm_year + 1900, ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
|
||||
}
|
||||
|
||||
|
||||
const char * DateToStr(time_t t)
|
||||
const char * DateToStr(const tm & rtm)
|
||||
{
|
||||
tm * ptm = std::localtime(&t);
|
||||
|
||||
return DateToStr(ptm);
|
||||
return DateToStr(rtm.tm_year + 1900, rtm.tm_mon+1, rtm.tm_mday, rtm.tm_hour, rtm.tm_min, rtm.tm_sec);
|
||||
}
|
||||
|
||||
|
||||
const char * DateToStrWithoutHours(tm * ptm)
|
||||
const char * DateToStr(time_t t)
|
||||
{
|
||||
tm rtm = Time(t);
|
||||
|
||||
return DateToStr(rtm);
|
||||
}
|
||||
|
||||
|
||||
const char * DateToStrWithoutHours(const tm * ptm)
|
||||
{
|
||||
return DateToStr(ptm->tm_year + 1900, ptm->tm_mon+1, ptm->tm_mday);
|
||||
}
|
||||
|
||||
|
||||
const char * DateToStrWithoutHours(const tm & rtm)
|
||||
{
|
||||
return DateToStr(rtm.tm_year + 1900, rtm.tm_mon+1, rtm.tm_mday);
|
||||
}
|
||||
|
||||
|
||||
const char * DateToStrWithoutHours(time_t t)
|
||||
{
|
||||
tm * ptm = std::localtime(&t);
|
||||
tm rtm = Time(t);
|
||||
|
||||
return DateToStrWithoutHours(ptm);
|
||||
return DateToStrWithoutHours(rtm);
|
||||
}
|
||||
|
||||
|
||||
@@ -360,17 +372,23 @@ return buffer;
|
||||
}
|
||||
|
||||
|
||||
const char * DateToStrCookie(tm * ptm)
|
||||
const char * DateToStrCookie(const tm * ptm)
|
||||
{
|
||||
return DateToStrCookie(ptm->tm_year + 1900, ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
|
||||
}
|
||||
|
||||
|
||||
const char * DateToStrCookie(const tm & rtm)
|
||||
{
|
||||
return DateToStrCookie(rtm.tm_year + 1900, rtm.tm_mon+1, rtm.tm_mday, rtm.tm_hour, rtm.tm_min, rtm.tm_sec);
|
||||
}
|
||||
|
||||
|
||||
const char * DateToStrCookie(time_t t)
|
||||
{
|
||||
tm * ptm = std::localtime(&t);
|
||||
tm rtm = Time(t);
|
||||
|
||||
return DateToStrCookie(ptm);
|
||||
return DateToStrCookie(rtm);
|
||||
}
|
||||
|
||||
|
||||
@@ -801,3 +819,47 @@ Item::Auth SelectFileType(const char * file_name)
|
||||
return Item::auth_other;
|
||||
}
|
||||
|
||||
|
||||
|
||||
time_t Time(const tm & par)
|
||||
{
|
||||
tm t;
|
||||
|
||||
memset(&t, 0, sizeof(t));
|
||||
|
||||
t.tm_year = par.tm_year;
|
||||
t.tm_mon = par.tm_mon;
|
||||
t.tm_mday = par.tm_mday;
|
||||
t.tm_hour = par.tm_hour;
|
||||
t.tm_min = par.tm_min;
|
||||
t.tm_sec = par.tm_sec;
|
||||
|
||||
return timegm(&t);
|
||||
}
|
||||
|
||||
|
||||
time_t Time(const tm * par)
|
||||
{
|
||||
return Time(*par);
|
||||
}
|
||||
|
||||
|
||||
tm Time(time_t par)
|
||||
{
|
||||
tm * ptm = gmtime(&par);
|
||||
tm res;
|
||||
|
||||
memset(&res, 0, sizeof(res));
|
||||
|
||||
if( ptm )
|
||||
{
|
||||
res.tm_year = ptm->tm_year;
|
||||
res.tm_mon = ptm->tm_mon;
|
||||
res.tm_mday = ptm->tm_mday;
|
||||
res.tm_hour = ptm->tm_hour;
|
||||
res.tm_min = ptm->tm_min;
|
||||
res.tm_sec = ptm->tm_sec;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
15
core/misc.h
15
core/misc.h
@@ -14,8 +14,8 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <ctime>
|
||||
#include "item.h"
|
||||
#include <cstdio>
|
||||
#include "item.h"
|
||||
|
||||
|
||||
void ToString(std::string & s, int value);
|
||||
@@ -34,13 +34,16 @@ std::string HtmlEscapeFormTxt(const std::string & in);
|
||||
|
||||
const char * DateToStr(int year, int month, int day);
|
||||
const char * DateToStr(int year, int month, int day, int hour, int min, int sec);
|
||||
const char * DateToStr(tm * ptm);
|
||||
const char * DateToStr(const tm * ptm);
|
||||
const char * DateToStr(const tm & rtm);
|
||||
const char * DateToStr(time_t t);
|
||||
const char * DateToStrWithoutHours(tm * ptm);
|
||||
const char * DateToStrWithoutHours(const tm * ptm);
|
||||
const char * DateToStrWithoutHours(const tm & rtm);
|
||||
const char * DateToStrWithoutHours(time_t t);
|
||||
|
||||
const char * DateToStrCookie(int year, int month, int day, int hour, int min, int sec);
|
||||
const char * DateToStrCookie(tm * ptm);
|
||||
const char * DateToStrCookie(const tm * ptm);
|
||||
const char * DateToStrCookie(const tm & rtm);
|
||||
const char * DateToStrCookie(time_t t);
|
||||
|
||||
const char * IpToStr(unsigned int ip_);
|
||||
@@ -76,4 +79,8 @@ bool CopyFile(const std::string & src, const std::string & dst);
|
||||
const char * GetFileExt(const char * name);
|
||||
Item::Auth SelectFileType(const char * file_name);
|
||||
|
||||
time_t Time(const tm & par);
|
||||
time_t Time(const tm * par);
|
||||
tm Time(time_t par);
|
||||
|
||||
#endif
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
#include "session.h"
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ Session::Session()
|
||||
Clear();
|
||||
|
||||
time = std::time(0);
|
||||
tm_time = *std::localtime(&time);
|
||||
tm_time = Time(time);
|
||||
|
||||
last_time = time;
|
||||
tm_last_time = tm_time;
|
||||
|
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "sessioncontainer.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ void SessionContainer::UpdateLastTime(SessionContainer::Iterator iter, time_t ne
|
||||
index_time.insert( std::make_pair(new_time, iter) );
|
||||
|
||||
iter->last_time = new_time;
|
||||
iter->tm_last_time = *std::localtime(&new_time);
|
||||
iter->tm_last_time = Time(new_time);
|
||||
|
||||
log << log3 << "SC: last time and the time index for session id: " << iter->id << " updated" << logend;
|
||||
found = true;
|
||||
|
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "sessionparser.h"
|
||||
#include "log.h"
|
||||
#include "misc.h"
|
||||
|
||||
|
||||
|
||||
@@ -98,8 +99,8 @@ bool SessionParser::MakeSession(long user_id)
|
||||
|
||||
session.puser = puser;
|
||||
session.new_session = true;
|
||||
session.tm_time = *std::localtime(&session.time);
|
||||
session.tm_last_time = *std::localtime(&session.last_time);
|
||||
session.tm_time = Time(session.time);
|
||||
session.tm_last_time = Time(session.last_time);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -51,6 +51,7 @@ void System::Init()
|
||||
|
||||
users.SetRequest(request);
|
||||
users.ReadUsers(db);
|
||||
users.SetTimeZoneOffset(config->time_zone_offset);
|
||||
groups.ReadGroups(db); // !! chwilowe przekazanie argumentu, db bedzie zmienione
|
||||
|
||||
rebus.SetRequest(request);
|
||||
@@ -533,3 +534,35 @@ Error System::EditFile(Item & item, bool with_url, bool notify)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
time_t System::LocalTime(time_t gmt_time)
|
||||
{
|
||||
int time_offset;
|
||||
|
||||
if( request->session && request->session->puser )
|
||||
time_offset = request->session->puser->time_zone_offset;
|
||||
else
|
||||
time_offset = config->time_zone_offset_guest;
|
||||
|
||||
return gmt_time + (time_t)time_offset;
|
||||
}
|
||||
|
||||
|
||||
tm System::LocalTime(const tm * ptm)
|
||||
{
|
||||
time_t t;
|
||||
tm rtm;
|
||||
|
||||
t = Time(ptm);
|
||||
t = LocalTime(t);
|
||||
rtm = Time(t);
|
||||
|
||||
return rtm;
|
||||
}
|
||||
|
||||
|
||||
tm System::LocalTime(const tm & ptm)
|
||||
{
|
||||
return LocalTime(&ptm);
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@
|
||||
#include "groups.h"
|
||||
#include "rebus.h"
|
||||
#include "loadavg.h"
|
||||
|
||||
#include <ctime>
|
||||
|
||||
|
||||
|
||||
@@ -86,6 +86,13 @@ public:
|
||||
Error AddFile(Item & item, bool notify = true);
|
||||
Error EditFile(Item & item, bool with_url = true, bool notify = true);
|
||||
|
||||
// converting GMT time to local time (different for each user)
|
||||
time_t LocalTime(time_t gmt_time);
|
||||
tm LocalTime(const tm * ptm);
|
||||
tm LocalTime(const tm & ptm);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
Request * request;
|
||||
Config * config;
|
||||
|
@@ -32,7 +32,7 @@ public:
|
||||
Item last_item;
|
||||
|
||||
// used when sorting
|
||||
long sort;
|
||||
unsigned long sort;
|
||||
|
||||
void Clear()
|
||||
{
|
||||
|
@@ -24,9 +24,13 @@ struct User
|
||||
|
||||
int cms_notify;
|
||||
int thread_notify;
|
||||
|
||||
// !! currently all users have the same offset
|
||||
// option in config: time_zone_offset
|
||||
int time_zone_offset;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
User()
|
||||
{
|
||||
Clear();
|
||||
@@ -42,6 +46,7 @@ struct User
|
||||
email.clear();
|
||||
cms_notify = 0;
|
||||
thread_notify = 0;
|
||||
time_zone_offset = 0;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -39,6 +39,17 @@ void Users::ReadUsers(Db * db)
|
||||
}
|
||||
|
||||
|
||||
void Users::SetTimeZoneOffset(int offset)
|
||||
{
|
||||
Table::Iterator i;
|
||||
|
||||
for(i=table.Begin() ; i!=table.End() ; ++i)
|
||||
{
|
||||
i->time_zone_offset = offset;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Users::AddUser(const User & user)
|
||||
{
|
||||
Table::Iterator i = table.PushBack(user);
|
||||
|
@@ -39,6 +39,7 @@ public:
|
||||
|
||||
void Clear();
|
||||
void ReadUsers(Db * db);
|
||||
void SetTimeZoneOffset(int offset); // !! temporarily one time_zone for all users
|
||||
bool AddUser(const User & user);
|
||||
bool IsUser(const std::string & name);
|
||||
User * GetUser(long user_id);
|
||||
|
Reference in New Issue
Block a user