194 lines
3.9 KiB
C++
Executable File
194 lines
3.9 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2010-2012, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#ifndef headerfile_winix_core_app
|
|
#define headerfile_winix_core_app
|
|
|
|
#include <iostream>
|
|
#include <ctime>
|
|
#include <unistd.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/types.h>
|
|
#include <pwd.h>
|
|
#include <grp.h>
|
|
#include <errno.h>
|
|
#include <fcgiapp.h>
|
|
|
|
#include "config.h"
|
|
#include "system.h"
|
|
#include "mounts.h"
|
|
#include "request.h"
|
|
#include "synchro.h"
|
|
#include "sessionmanager.h"
|
|
#include "db/db.h"
|
|
#include "functions/functions.h"
|
|
#include "templates/templates.h"
|
|
#include "compress.h"
|
|
#include "postparser.h"
|
|
#include "cookieparser.h"
|
|
#include "postmultiparser.h"
|
|
#include "acceptencodingparser.h"
|
|
|
|
|
|
|
|
class App
|
|
{
|
|
public:
|
|
|
|
App();
|
|
|
|
bool InitFCGI();
|
|
bool DropPrivileges();
|
|
bool Init();
|
|
void Start();
|
|
void Close();
|
|
void LogUserGroups();
|
|
bool Demonize();
|
|
void SetStopSignal();
|
|
bool WasStopSignal();
|
|
bool Lock();
|
|
void Unlock();
|
|
void StartThreads();
|
|
void WaitForThreads();
|
|
|
|
// configuration read from a config file
|
|
Config config;
|
|
|
|
// pointers to the current request and a session
|
|
Cur cur;
|
|
|
|
// temporary one request object
|
|
// current request
|
|
Request req;
|
|
|
|
// users sessions
|
|
SessionManager session_manager;
|
|
|
|
// database
|
|
Db db;
|
|
DbConn db_conn;
|
|
|
|
|
|
|
|
/*
|
|
model
|
|
*/
|
|
|
|
// ...
|
|
System system;
|
|
|
|
// functions (ls, cat, emacs, ...)
|
|
Functions functions;
|
|
|
|
// false at the beginning
|
|
// !! moze to do loggera dac?
|
|
bool stdout_is_closed;
|
|
|
|
|
|
/*
|
|
view
|
|
*/
|
|
|
|
Templates templates;
|
|
|
|
|
|
private:
|
|
|
|
enum Header
|
|
{
|
|
h_200,
|
|
h_404,
|
|
h_403
|
|
};
|
|
|
|
PostParser post_parser;
|
|
PostMultiParser post_multi_parser;
|
|
CookieParser cookie_parser;
|
|
AcceptEncodingParser accept_encoding_parser;
|
|
Compress compress;
|
|
std::wstring clean_html, html_with_debug;
|
|
FCGX_Request fcgi_request;
|
|
int fcgi_socket;
|
|
Synchro synchro;
|
|
pthread_t signal_thread;
|
|
std::string url_to_fetch_on_exit;
|
|
std::string source_a;
|
|
std::string sendh_t, sendh_t2, sendh_t3;
|
|
std::string sendfilea, sendfile2a;
|
|
std::string send_data_buf;
|
|
|
|
void ProcessRequestThrow();
|
|
void ProcessRequest();
|
|
void BaseUrlRedirect(int code, bool add_subdomain);
|
|
bool BaseUrlRedirect();
|
|
bool ShouldUseSSL();
|
|
bool ShouldNotUseSSL();
|
|
bool CheckSSLcorrectness();
|
|
void SetLocale();
|
|
void CheckPostRedirect();
|
|
void MakePage();
|
|
void Make();
|
|
void SaveSessionsIfNeeded(); // !! wywalic do menagera sesji??
|
|
void LogAccess();
|
|
void SendData(const BinaryPage & page, FCGX_Stream * out);
|
|
|
|
void ReadRequest();
|
|
void SendTextAnswer();
|
|
void SendBinaryAnswer();
|
|
void SendAnswer();
|
|
|
|
void PrintEnv();
|
|
|
|
void SetEnv(const char * & env, const char * name);
|
|
void ReadEnvVariables();
|
|
void ReadGetPostVars();
|
|
|
|
void CheckIE();
|
|
void CheckKonqueror();
|
|
void CheckRequestMethod();
|
|
void CheckFCGIRole();
|
|
void CheckSSL();
|
|
void SetSubdomain();
|
|
|
|
void PrepareSessionCookie();
|
|
void AddDebugInfo(std::wstring & out);
|
|
void FilterCompressSend(bool compressing, int compress_encoding, const std::wstring & source_ref);
|
|
bool SendHeadersStaticCreateResource();
|
|
void SendHeadersStatic();
|
|
void SendHeaderContentType();
|
|
void SendHeadersForbidden();
|
|
void SendHeadersRedirect();
|
|
void SendHeadersSendFile();
|
|
void SendHeadersCompression(int compress_encoding);
|
|
void SendHeadersNormal(Header header);
|
|
void SendHeaders(bool compressing, int compress_encoding, Header header);
|
|
int SelectDeflateVersion();
|
|
void SelectCompression(size_t source_len, bool & compression_allowed, int & compression_encoding);
|
|
bool CanSendContent(Header header);
|
|
|
|
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);
|
|
|
|
static void * SpecialThreadForSignals(void*);
|
|
void FetchPageOnExit();
|
|
|
|
void CreateStaticTree();
|
|
|
|
// !! dodac do session managera?
|
|
time_t last_sessions_save;
|
|
};
|
|
|
|
#endif
|
|
|
|
|