2010-08-10 18:12:50 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of Winix
|
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
2012-09-04 22:24:42 +02:00
|
|
|
* Copyright (c) 2010-2012, Tomasz Sowa
|
2010-08-10 18:12:50 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
#ifndef headerfile_winix_core_app
|
|
|
|
#define headerfile_winix_core_app
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <ctime>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <grp.h>
|
|
|
|
#include <errno.h>
|
2010-11-23 22:52:25 +01:00
|
|
|
#include <fcgiapp.h>
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "mounts.h"
|
|
|
|
#include "request.h"
|
2010-12-02 02:02:02 +01:00
|
|
|
#include "synchro.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
#include "sessionmanager.h"
|
2010-09-18 02:51:12 +02:00
|
|
|
#include "db/db.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
#include "functions/functions.h"
|
|
|
|
#include "templates/templates.h"
|
2010-08-12 21:10:12 +02:00
|
|
|
#include "compress.h"
|
|
|
|
#include "postparser.h"
|
|
|
|
#include "cookieparser.h"
|
|
|
|
#include "postmultiparser.h"
|
|
|
|
#include "acceptencodingparser.h"
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
class App
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
App();
|
|
|
|
|
2010-11-23 22:52:25 +01:00
|
|
|
bool InitFCGI();
|
|
|
|
bool DropPrivileges();
|
2010-08-10 18:12:50 +02:00
|
|
|
bool Init();
|
|
|
|
void Start();
|
|
|
|
void Close();
|
2010-10-24 19:49:38 +02:00
|
|
|
void LogUserGroups();
|
2010-10-24 21:26:54 +02:00
|
|
|
bool Demonize();
|
2010-12-02 02:02:02 +01:00
|
|
|
void SetStopSignal();
|
|
|
|
bool WasStopSignal();
|
|
|
|
bool Lock();
|
|
|
|
void Unlock();
|
|
|
|
void StartThreads();
|
|
|
|
void WaitForThreads();
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
// configuration read from a config file
|
|
|
|
Config config;
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
// pointers to the current request and a session
|
|
|
|
Cur cur;
|
|
|
|
|
|
|
|
// temporary one request object
|
2010-08-10 18:12:50 +02:00
|
|
|
// current request
|
2011-01-23 15:15:30 +01:00
|
|
|
Request req;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
// users sessions
|
|
|
|
SessionManager session_manager;
|
|
|
|
|
|
|
|
// database
|
|
|
|
Db db;
|
2010-09-18 02:51:12 +02:00
|
|
|
DbConn db_conn;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
model
|
|
|
|
*/
|
|
|
|
|
2011-07-15 04:09:02 +02:00
|
|
|
// ...
|
2010-08-10 18:12:50 +02:00
|
|
|
System system;
|
|
|
|
|
2011-07-15 04:09:02 +02:00
|
|
|
// functions (ls, cat, emacs, ...)
|
|
|
|
Functions functions;
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
// false at the beginning
|
2010-08-12 21:10:12 +02:00
|
|
|
// !! moze to do loggera dac?
|
2010-08-10 18:12:50 +02:00
|
|
|
bool stdout_is_closed;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
view
|
|
|
|
*/
|
|
|
|
|
|
|
|
Templates templates;
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2010-08-12 21:10:12 +02:00
|
|
|
|
|
|
|
enum Header
|
|
|
|
{
|
|
|
|
h_200,
|
|
|
|
h_404,
|
|
|
|
h_403
|
|
|
|
};
|
|
|
|
|
|
|
|
PostParser post_parser;
|
|
|
|
PostMultiParser post_multi_parser;
|
|
|
|
CookieParser cookie_parser;
|
2011-07-29 00:18:10 +02:00
|
|
|
AcceptEncodingParser accept_encoding_parser;
|
2010-08-12 21:10:12 +02:00
|
|
|
Compress compress;
|
2010-11-21 01:19:17 +01:00
|
|
|
std::wstring clean_html, html_with_debug;
|
2010-11-23 22:52:25 +01:00
|
|
|
FCGX_Request fcgi_request;
|
|
|
|
int fcgi_socket;
|
2010-12-02 02:02:02 +01:00
|
|
|
Synchro synchro;
|
|
|
|
pthread_t signal_thread;
|
|
|
|
std::string url_to_fetch_on_exit;
|
2011-04-02 02:10:16 +02:00
|
|
|
std::string source_a;
|
2011-09-07 00:46:15 +02:00
|
|
|
std::string sendh_t, sendh_t2, sendh_t3;
|
2011-07-07 19:02:14 +02:00
|
|
|
std::string sendfilea, sendfile2a;
|
2012-09-11 07:19:45 +02:00
|
|
|
std::string send_data_buf;
|
2010-08-12 21:10:12 +02:00
|
|
|
|
|
|
|
void ProcessRequestThrow();
|
2010-08-10 18:12:50 +02:00
|
|
|
void ProcessRequest();
|
2012-06-07 02:26:37 +02:00
|
|
|
void BaseUrlRedirect(int code, bool add_subdomain);
|
2010-08-10 18:12:50 +02:00
|
|
|
bool BaseUrlRedirect();
|
2012-06-07 02:26:37 +02:00
|
|
|
bool ShouldUseSSL();
|
|
|
|
bool ShouldNotUseSSL();
|
|
|
|
bool CheckSSLcorrectness();
|
2012-06-27 01:19:19 +02:00
|
|
|
void SetLocale();
|
2012-09-04 22:24:42 +02:00
|
|
|
void CheckPostRedirect();
|
2010-08-10 18:12:50 +02:00
|
|
|
void MakePage();
|
|
|
|
void Make();
|
2010-12-02 02:02:02 +01:00
|
|
|
void SaveSessionsIfNeeded(); // !! wywalic do menagera sesji??
|
2010-08-12 21:10:12 +02:00
|
|
|
void LogAccess();
|
2012-09-11 07:19:45 +02:00
|
|
|
void SendData(const BinaryPage & page, FCGX_Stream * out);
|
2010-08-12 21:10:12 +02:00
|
|
|
|
|
|
|
void ReadRequest();
|
2012-09-11 07:19:45 +02:00
|
|
|
void SendTextAnswer();
|
|
|
|
void SendBinaryAnswer();
|
2010-08-12 21:10:12 +02:00
|
|
|
void SendAnswer();
|
|
|
|
|
2011-09-07 00:46:15 +02:00
|
|
|
void PrintEnv();
|
|
|
|
|
2010-08-12 21:10:12 +02:00
|
|
|
void SetEnv(const char * & env, const char * name);
|
|
|
|
void ReadEnvVariables();
|
|
|
|
void ReadGetPostVars();
|
|
|
|
|
|
|
|
void CheckIE();
|
|
|
|
void CheckKonqueror();
|
|
|
|
void CheckRequestMethod();
|
|
|
|
void CheckFCGIRole();
|
2011-09-07 00:46:15 +02:00
|
|
|
void CheckSSL();
|
2012-04-22 20:23:44 +02:00
|
|
|
void SetSubdomain();
|
2010-08-12 21:10:12 +02:00
|
|
|
|
|
|
|
void PrepareSessionCookie();
|
2010-11-21 01:19:17 +01:00
|
|
|
void AddDebugInfo(std::wstring & out);
|
2011-04-02 02:10:16 +02:00
|
|
|
void FilterCompressSend(bool compressing, int compress_encoding, const std::wstring & source_ref);
|
2011-09-07 00:46:15 +02:00
|
|
|
bool SendHeadersStaticCreateResource();
|
2011-06-15 01:45:42 +02:00
|
|
|
void SendHeadersStatic();
|
2011-12-17 22:59:22 +01:00
|
|
|
void SendHeaderContentType();
|
2011-06-15 01:45:42 +02:00
|
|
|
void SendHeadersForbidden();
|
2011-07-07 19:02:14 +02:00
|
|
|
void SendHeadersRedirect();
|
|
|
|
void SendHeadersSendFile();
|
|
|
|
void SendHeadersCompression(int compress_encoding);
|
|
|
|
void SendHeadersNormal(Header header);
|
2011-04-02 02:10:16 +02:00
|
|
|
void SendHeaders(bool compressing, int compress_encoding, Header header);
|
|
|
|
int SelectDeflateVersion();
|
|
|
|
void SelectCompression(size_t source_len, bool & compression_allowed, int & compression_encoding);
|
2010-08-12 21:10:12 +02:00
|
|
|
bool CanSendContent(Header header);
|
|
|
|
|
2010-10-24 19:49:38 +02:00
|
|
|
void LogUser(const char * msg, uid_t id);
|
|
|
|
void LogGroup(const char * msg, gid_t id, bool put_logend = true);
|
|
|
|
void LogUsers();
|
|
|
|
void LogEffectiveGroups(std::vector<gid_t> & tab);
|
|
|
|
void LogGroups();
|
|
|
|
bool DropPrivileges(const std::string & user, uid_t uid, gid_t gid, bool additional_groups);
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2010-12-02 02:02:02 +01:00
|
|
|
static void * SpecialThreadForSignals(void*);
|
|
|
|
void FetchPageOnExit();
|
|
|
|
|
2010-12-10 22:07:01 +01:00
|
|
|
void CreateStaticTree();
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
// !! dodac do session managera?
|
|
|
|
time_t last_sessions_save;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|