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-22 23:26:56 +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
|
|
|
*/
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
#ifndef headerfile_winix_core_system
|
|
|
|
#define headerfile_winix_core_system
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2010-12-02 03:36:49 +01:00
|
|
|
#include <ctime>
|
2012-04-26 00:24:37 +02:00
|
|
|
#include "job.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
#include "dirs.h"
|
|
|
|
#include "mounts.h"
|
2010-09-18 02:51:12 +02:00
|
|
|
#include "db/db.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
#include "request.h"
|
|
|
|
#include "config.h"
|
changed: when winix demonizes it creates a three new descriptors (0, 1 and 3)
pointing to /dev/null
added: DbBase::AssertValueBin(PGresult * r, int row, int col, std::string & result)
it reads binary (bytea) data
added: DbTextStream can handle 'bool' types now
(is puts 'true' of 'false' to the stream)
changed: now passwords can be stored either as plain text, a hash or can be encrypted
with RSA
currently we have following hashes:
md4, md5, sha1, sha224, sha256, sha384, sha512
we are using openssl to manage them
(look at config options for more info)
changed: winix version to 0.4.7
added: class Run - you can run any program from os and send a buffer to its standard input
and read what the program put on its standard output
added: class Crypt (in System) - calculating hashes, and crypting/decrypting
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@734 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-06-09 23:22:08 +02:00
|
|
|
#include "crypt.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
#include "users.h"
|
|
|
|
#include "groups.h"
|
|
|
|
#include "rebus.h"
|
|
|
|
#include "loadavg.h"
|
2010-12-02 02:02:02 +01:00
|
|
|
#include "synchro.h"
|
2011-09-13 08:08:34 +02:00
|
|
|
#include "image.h"
|
2011-07-29 00:18:10 +02:00
|
|
|
#include "threadmanager.h"
|
2010-12-02 03:36:49 +01:00
|
|
|
#include "notify/notify.h"
|
2012-06-23 01:34:33 +02:00
|
|
|
#include "timezones.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2010-08-12 21:10:12 +02:00
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
namespace Winix
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-09-14 11:56:00 +02:00
|
|
|
class Functions;
|
2012-03-09 03:36:25 +01:00
|
|
|
class SessionManager;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
// file system
|
2021-08-10 22:06:53 +02:00
|
|
|
class System : public WinixModelDeprecated
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
// contains current directories tree
|
|
|
|
Dirs dirs;
|
|
|
|
|
|
|
|
// mount points
|
|
|
|
Mounts mounts;
|
|
|
|
|
|
|
|
// users
|
|
|
|
Users users;
|
|
|
|
|
|
|
|
// groups
|
|
|
|
Groups groups;
|
|
|
|
|
|
|
|
// rebus (captcha)
|
|
|
|
Rebus rebus;
|
|
|
|
|
|
|
|
// load averages
|
|
|
|
LoadAvg load_avg;
|
|
|
|
|
2010-12-02 02:02:02 +01:00
|
|
|
// notifications (by emails)
|
|
|
|
Notify notify;
|
|
|
|
|
2011-09-13 08:08:34 +02:00
|
|
|
// images (resizing, generating thumbnails)
|
|
|
|
Image image;
|
2010-12-11 23:55:48 +01:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
// the time when the winix starts
|
|
|
|
time_t system_start;
|
|
|
|
|
changed: when winix demonizes it creates a three new descriptors (0, 1 and 3)
pointing to /dev/null
added: DbBase::AssertValueBin(PGresult * r, int row, int col, std::string & result)
it reads binary (bytea) data
added: DbTextStream can handle 'bool' types now
(is puts 'true' of 'false' to the stream)
changed: now passwords can be stored either as plain text, a hash or can be encrypted
with RSA
currently we have following hashes:
md4, md5, sha1, sha224, sha256, sha384, sha512
we are using openssl to manage them
(look at config options for more info)
changed: winix version to 0.4.7
added: class Run - you can run any program from os and send a buffer to its standard input
and read what the program put on its standard output
added: class Crypt (in System) - calculating hashes, and crypting/decrypting
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@734 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-06-09 23:22:08 +02:00
|
|
|
// cryptography and hashes
|
|
|
|
Crypt crypt;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2011-07-29 00:18:10 +02:00
|
|
|
// thread management
|
|
|
|
ThreadManager thread_manager;
|
|
|
|
|
2012-04-26 00:24:37 +02:00
|
|
|
// jobs
|
|
|
|
Job job;
|
|
|
|
|
2012-06-23 01:34:33 +02:00
|
|
|
// time zones read from etc/time_zones.conf
|
|
|
|
// when winix starts
|
|
|
|
TimeZones time_zones;
|
|
|
|
|
2012-04-26 00:24:37 +02:00
|
|
|
|
2021-06-16 18:07:44 +02:00
|
|
|
using WinixModelDeprecated::get_model_connector;
|
2021-04-09 17:50:58 +02:00
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
void SetCur(Cur * pcur);
|
2018-11-21 12:03:53 +01:00
|
|
|
//void SetConfig(Config * pconfig);
|
2010-08-10 18:12:50 +02:00
|
|
|
void SetDb(Db * pdb);
|
2018-11-21 12:03:53 +01:00
|
|
|
//void SetSynchro(Synchro * psynchro);
|
2011-09-14 11:56:00 +02:00
|
|
|
void SetFunctions(Functions * pfunctions);
|
2012-03-09 03:36:25 +01:00
|
|
|
void SetSessionManager(SessionManager * sm);
|
2018-11-21 12:03:53 +01:00
|
|
|
|
2021-06-16 18:07:44 +02:00
|
|
|
void set_dependency(WinixModelDeprecated * winix_model);
|
2018-11-21 12:03:53 +01:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
void Init();
|
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
void AddParams(const ParamTab & param_tab, std::wstring & str, bool clear_str = true);
|
|
|
|
|
2018-04-22 23:26:56 +02:00
|
|
|
bool IsSSLRequired(bool try_to_use_ssl);
|
|
|
|
bool IsSSLRequired();
|
2011-08-18 01:09:47 +02:00
|
|
|
void PutUrlProto(bool can_use_ssl, std::wstring & str, bool clear_str = true);
|
2021-05-20 20:59:12 +02:00
|
|
|
void PutUrlProto(bool can_use_ssl, pt::TextStream & str, bool clear_stream = true);
|
2018-04-22 23:26:56 +02:00
|
|
|
void PutUrlProto(std::wstring & str, bool clear_str = true);
|
2021-05-20 20:59:12 +02:00
|
|
|
void PutUrlProto(pt::TextStream & str, bool clear_stream = true);
|
2018-04-22 23:26:56 +02:00
|
|
|
|
2013-03-26 01:04:01 +01:00
|
|
|
void RedirectTo(const Item & item, const wchar_t * postfix = 0, bool use_reqtype = true);
|
|
|
|
void RedirectTo(long item_id, const wchar_t * postfix = 0, bool use_reqtype = true);
|
|
|
|
void RedirectTo(const wchar_t * url, bool use_reqtype = true);
|
|
|
|
void RedirectTo(const std::wstring & url, bool use_reqtype = true);
|
2012-02-19 01:59:08 +01:00
|
|
|
void RedirectWithFunctionAndParamsTo(const wchar_t * url);
|
2011-01-05 22:24:11 +01:00
|
|
|
void RedirectWithFunctionAndParamsTo(const std::wstring & url);
|
2013-03-26 01:04:01 +01:00
|
|
|
void RedirectToLastDir(const wchar_t * postfix = 0, bool use_reqtype = true);
|
|
|
|
void RedirectToLastItem(const wchar_t * postfix = 0, bool use_reqtype = true); // redirect to an item if exists or to the last directory
|
|
|
|
void RedirectToLastFunction(const wchar_t * postfix = 0, bool use_reqtype = true);
|
2012-10-27 11:03:49 +02:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
bool CanChangeUser(const Item & item, long new_user_id);
|
|
|
|
bool CanChangeGroup(const Item & item, long new_group_id);
|
|
|
|
bool CanChangePrivileges(const Item & item, int new_priv);
|
2012-01-25 00:03:36 +01:00
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
bool HasReadAccess(const Item & item);
|
|
|
|
bool HasWriteAccess(const Item & item);
|
|
|
|
bool HasReadWriteAccess(const Item & item);
|
|
|
|
bool HasReadExecAccess(const Item & item);
|
|
|
|
bool HasReadExecAccessToPath(long dir_id);
|
2011-01-05 22:24:11 +01:00
|
|
|
bool HasReadExecAccessToPath(const std::vector<Item*> & dir_tab);
|
2010-08-10 18:12:50 +02:00
|
|
|
bool DirsHaveReadExecPerm();
|
2010-08-10 22:43:38 +02:00
|
|
|
void CheckAccessToItems(std::vector<Item> & item_tab);
|
2011-08-02 02:10:45 +02:00
|
|
|
void CheckWriteAccessToItems(std::vector<Item> & item_tab);
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2012-01-25 00:03:36 +01:00
|
|
|
/*
|
|
|
|
this method checks the sticky bit and write permissions
|
|
|
|
it returns true if we can remove/rename an item for the given child_item_user_id user id
|
|
|
|
*/
|
|
|
|
bool CanRemoveRenameChild(const Item & dir, long child_item_user_id);
|
|
|
|
|
|
|
|
int NewFilePrivileges();
|
|
|
|
int NewDirPrivileges();
|
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
bool CanUseHtml(long user_id);
|
|
|
|
bool CanUseBBCode(long user_id);
|
2016-07-13 15:13:56 +02:00
|
|
|
bool CanUseOther(long user_id);
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2015-01-02 09:18:06 +01:00
|
|
|
bool IsSuperUser(long user_id);
|
2010-11-21 01:19:17 +01:00
|
|
|
bool IsMemberOfGroup(long user_id, const wchar_t * group_name);
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2010-12-10 22:07:01 +01:00
|
|
|
// creating item.file_path and item.file_fs (the mountpoint where the item is located)
|
|
|
|
bool CreateNewFile(Item & item);
|
2014-09-28 19:30:05 +02:00
|
|
|
bool MakeFilePath(const Item & item, std::wstring & path, bool thumb = false, bool create_dir = false, int chmod = 0755, int group = -1);
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2021-09-15 20:28:34 +02:00
|
|
|
bool MakeRelativeFilePath(const Item & item, const std::wstring & path_prefix, std::wstring & path, bool thumb = false);
|
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
bool MakePath(const Item & item, std::wstring & path, bool clear_path = true);
|
|
|
|
|
2021-02-24 01:19:47 +01:00
|
|
|
bool AddFile(Item & item, int notify_code = 0, bool call_plugins = true);
|
|
|
|
bool EditFile(Item & item, bool with_url = true, int notify_code = 0, bool call_plugins = true);
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2012-05-30 21:04:18 +02:00
|
|
|
|
2012-06-27 01:19:19 +02:00
|
|
|
time_t ToLocal(time_t utc_time);
|
2021-05-20 20:59:12 +02:00
|
|
|
pt::Date ToLocal(const pt::Date & utc_date);
|
2012-05-30 21:04:18 +02:00
|
|
|
|
|
|
|
time_t ToUTC(time_t local_time);
|
2021-05-20 20:59:12 +02:00
|
|
|
pt::Date ToUTC(const pt::Date & local_date);
|
2012-05-30 21:04:18 +02:00
|
|
|
|
2010-10-24 01:12:47 +02:00
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
int FollowLink(const std::vector<Item*> & current_dir_tab, const std::wstring & link_to,
|
|
|
|
std::vector<Item*> & out_dir_tab, Item & out_item);
|
|
|
|
|
|
|
|
int FollowAllLinks(const std::vector<Item*> & current_dir_tab, const std::wstring & link_to,
|
|
|
|
std::vector<Item*> & out_dir_tab, Item & out_item,
|
|
|
|
bool follow_dir_default = false, bool stop_on_link_redirect = false, bool check_access = true);
|
|
|
|
|
|
|
|
// starting from root dir
|
|
|
|
int FollowAllLinks(const std::wstring & link_to,
|
|
|
|
std::vector<Item*> & out_dir_tab, Item & out_item,
|
|
|
|
bool follow_dir_default = false, bool stop_on_link_redirect = false, bool check_access = true);
|
2010-10-24 01:12:47 +02:00
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
// using cur->request->dir_tab and cur->request->item
|
2011-01-05 22:24:11 +01:00
|
|
|
bool FollowAllLinks(const std::wstring & link_to,
|
|
|
|
bool follow_dir_default = false, bool stop_on_link_redirect = false, bool check_access = true);
|
2010-10-24 01:12:47 +02:00
|
|
|
|
2011-06-24 22:53:21 +02:00
|
|
|
|
2021-10-13 01:27:14 +02:00
|
|
|
bool AddCommonFileToVar(const wchar_t * file_path, const wchar_t * url, const wchar_t * mime_type = nullptr, bool overwrite_existing = true);
|
2011-06-24 22:53:21 +02:00
|
|
|
|
2012-06-23 01:34:33 +02:00
|
|
|
// reloading time zones
|
|
|
|
void ReadTimeZones();
|
|
|
|
|
2013-11-14 21:59:23 +01:00
|
|
|
|
|
|
|
void CreateItemLink(long parent_id, const std::wstring & url, const std::wstring & subdomain,
|
|
|
|
std::wstring & link, bool clear_str = true);
|
|
|
|
|
|
|
|
void CreateItemLink(const Item & item, std::wstring & link, bool clear_str = true);
|
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
private:
|
2011-01-23 15:15:30 +01:00
|
|
|
|
|
|
|
Cur * cur;
|
|
|
|
Db * db;
|
2018-11-21 12:03:53 +01:00
|
|
|
//Config * config;
|
|
|
|
//Synchro * synchro;
|
2011-09-14 11:56:00 +02:00
|
|
|
Functions * functions;
|
2012-03-09 03:36:25 +01:00
|
|
|
SessionManager * session_manager;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
Item item_temp;
|
|
|
|
std::wstring link_to_temp, name_temp;
|
2011-06-24 22:53:21 +02:00
|
|
|
std::wstring file_content, file_name;
|
|
|
|
Item file_content_item;
|
2011-01-05 22:24:11 +01:00
|
|
|
|
|
|
|
// for FollowAllLinks
|
|
|
|
std::vector<Item*> temp_follow_dir_tab;
|
|
|
|
std::vector<Item*> root_follow_dir_tab;
|
|
|
|
Item temp_follow_item;
|
|
|
|
|
2012-01-25 00:03:36 +01:00
|
|
|
int NewPrivileges(int creation_mask);
|
|
|
|
|
2010-12-10 22:07:01 +01:00
|
|
|
bool CreateNewFileSimpleFs(Item & item);
|
|
|
|
bool CreateNewFileHashFs(Item & item);
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
bool FollowAllLinksDirFound(std::vector<Item*> & out_dir_tab,
|
|
|
|
bool follow_dir_default, bool stop_on_link_redirect, bool check_access);
|
|
|
|
|
|
|
|
bool FollowAllLinksFileOrSymlinkFound(std::vector<Item*> & out_dir_tab, Item & out_item,
|
|
|
|
bool stop_on_link_redirect, bool check_access);
|
2010-08-10 18:12:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
|
|
|
|
} // namespace Winix
|
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
#endif
|
|
|
|
|