2008-12-10 05:42:49 +01:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2008-12-10 05:42:49 +01:00
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
2012-01-21 13:29:44 +01:00
|
|
|
* Copyright (c) 2008-2012, Tomasz Sowa
|
2008-12-10 05:42:49 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <ctime>
|
|
|
|
#include <iostream>
|
2010-11-23 22:52:25 +01:00
|
|
|
#include <sys/param.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 <fcntl.h>
|
2009-04-21 22:50:55 +02:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
#include "core/log.h"
|
2011-06-19 22:59:58 +02:00
|
|
|
#include "core/slog.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
#include "core/app.h"
|
|
|
|
#include "core/plugin.h"
|
|
|
|
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
Log log;
|
2010-09-18 02:51:12 +02:00
|
|
|
Log nlog; // notify log (used by a notification thread)
|
2011-06-19 22:59:58 +02:00
|
|
|
SLog slog; // session logger
|
2009-11-13 21:40:11 +01:00
|
|
|
Plugin plugin;
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
|
2010-01-28 16:39:01 +01:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
/*
|
|
|
|
application object
|
|
|
|
*/
|
|
|
|
App app;
|
|
|
|
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
|
2008-12-11 03:46:16 +01:00
|
|
|
void print_syntax()
|
|
|
|
{
|
|
|
|
std::cout << "Syntax:" << std::endl;
|
2010-08-18 00:32:47 +02:00
|
|
|
std::cout << " winix config_file" << std::endl;
|
2008-12-11 03:46:16 +01:00
|
|
|
}
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
void CreateNewDescriptor(int des_dst, int flags)
|
|
|
|
{
|
|
|
|
int descriptor;
|
|
|
|
|
|
|
|
descriptor = open("/dev/null", flags | O_NOCTTY);
|
|
|
|
|
|
|
|
if( descriptor != -1 )
|
|
|
|
{
|
|
|
|
dup2(descriptor, des_dst);
|
|
|
|
|
|
|
|
if( descriptor != des_dst )
|
|
|
|
close(descriptor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CloseDescriptors()
|
|
|
|
{
|
|
|
|
close(0);
|
|
|
|
close(1);
|
|
|
|
close(2);
|
|
|
|
app.stdout_is_closed = true;
|
|
|
|
|
|
|
|
CreateNewDescriptor(0, O_RDONLY);
|
|
|
|
CreateNewDescriptor(1, O_WRONLY);
|
|
|
|
CreateNewDescriptor(2, O_WRONLY);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-24 00:23:24 +01:00
|
|
|
|
2008-12-11 03:46:16 +01:00
|
|
|
int main(int argv, char ** argc)
|
|
|
|
{
|
|
|
|
std::srand(std::time(0));
|
|
|
|
|
|
|
|
if( argv != 2 )
|
|
|
|
{
|
|
|
|
print_syntax();
|
2008-12-10 05:42:49 +01:00
|
|
|
return 1;
|
2008-12-11 03:46:16 +01:00
|
|
|
}
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
app.system.system_start = time(0);
|
2010-11-21 01:19:17 +01:00
|
|
|
app.config.config_file = argc[1];
|
2008-12-11 03:46:16 +01:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
if( !app.config.ReadConfig(true, false) ) /* errors to stdout, stdout in not closed */
|
2008-12-11 03:46:16 +01:00
|
|
|
return 2;
|
|
|
|
|
2010-10-24 21:26:54 +02:00
|
|
|
if( app.stdout_is_closed || app.config.demonize )
|
2010-08-10 18:12:50 +02:00
|
|
|
app.config.log_stdout = false;
|
|
|
|
|
|
|
|
if( !app.config.log_stdout )
|
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
|
|
|
CloseDescriptors();
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2012-05-19 17:14:35 +02:00
|
|
|
if( app.config.demonize && !app.Demonize() )
|
|
|
|
return 4;
|
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
log.Init(app.config.log_level, app.config.log_save_each_line, app.config.log_file,
|
|
|
|
app.config.log_stdout, app.config.log_request);
|
2009-11-13 21:40:11 +01:00
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
nlog.Init(app.config.log_level, true, app.config.log_notify_file, false, 1);
|
|
|
|
|
|
|
|
log << log3 << "-- preparing to start winix --" << logend;
|
2010-11-23 22:52:25 +01:00
|
|
|
|
|
|
|
if( !app.InitFCGI() )
|
2012-05-19 17:14:35 +02:00
|
|
|
return 5;
|
2010-11-23 22:52:25 +01:00
|
|
|
|
2010-10-24 19:49:38 +02:00
|
|
|
if( !app.DropPrivileges() )
|
|
|
|
return 3;
|
|
|
|
|
|
|
|
app.LogUserGroups();
|
|
|
|
|
2011-08-18 01:09:47 +02:00
|
|
|
log << log3 << "base_url: " << app.config.base_url << logend;
|
2009-12-30 21:46:12 +01:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
// load plugins before loading sessions - session_manager.LoadSessions()
|
2010-08-14 18:23:18 +02:00
|
|
|
// because some of the plugins can init its own sessions dates
|
2010-08-18 00:32:47 +02:00
|
|
|
plugin.LoadPlugins(app.config.plugins_dir, app.config.plugin_file);
|
2009-11-13 21:40:11 +01:00
|
|
|
|
2010-12-02 02:02:02 +01:00
|
|
|
// app.Init() starts other threads as well (they will be waiting on the lock)
|
2010-08-10 18:12:50 +02:00
|
|
|
if( !app.Init() )
|
2009-10-01 00:31:20 +02:00
|
|
|
return 1;
|
|
|
|
|
2012-05-19 17:14:35 +02:00
|
|
|
log << log1 << PT::Date(std::time(0)) << " winix started" << logend;
|
2010-12-02 02:02:02 +01:00
|
|
|
|
|
|
|
app.StartThreads();
|
|
|
|
// now we have more threads, we should use Lock() and Unlock()
|
|
|
|
|
2011-07-29 00:18:10 +02:00
|
|
|
// saving all starting logs
|
|
|
|
app.Lock();
|
|
|
|
log << logsave;
|
|
|
|
app.Unlock();
|
|
|
|
|
2010-12-02 02:02:02 +01:00
|
|
|
// main loop
|
2010-08-10 18:12:50 +02:00
|
|
|
app.Start();
|
2010-11-23 22:52:25 +01:00
|
|
|
|
2010-12-02 02:02:02 +01:00
|
|
|
app.Lock();
|
2012-03-17 06:11:23 +01:00
|
|
|
plugin.Call((Session*)0, WINIX_CLOSE);
|
2010-08-10 18:12:50 +02:00
|
|
|
app.Close();
|
2012-01-21 13:29:44 +01:00
|
|
|
// now all sessions are cleared
|
2010-12-02 02:02:02 +01:00
|
|
|
app.Unlock();
|
|
|
|
|
|
|
|
app.WaitForThreads();
|
|
|
|
// now all others threads are terminated
|
2010-10-11 22:42:49 +02:00
|
|
|
|
2012-05-19 17:14:35 +02:00
|
|
|
log << log1 << PT::Date(std::time(0)) << " winix stopped" << logend << logsave;
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2010-11-23 22:52:25 +01:00
|
|
|
|