mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 16:31:11 +02:00
yWeb 2.8.a.4
- updated nhttpd - Code clean up - changes to nhttpd.conf - some changes for logo display git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@416 e54a6e83-5905-42d5-8d5c-058d10e6a962
This commit is contained in:
@@ -70,21 +70,21 @@ static void sig_catch(int msignal)
|
||||
{
|
||||
aprintf("!!! SIGNAL !!! :%d!\n",msignal);
|
||||
switch (msignal) {
|
||||
// case SIGTERM:
|
||||
// case SIGINT:
|
||||
// case SIGTERM:
|
||||
// case SIGINT:
|
||||
|
||||
case SIGPIPE:
|
||||
case SIGPIPE:
|
||||
aprintf("got signal PIPE, nice!\n");
|
||||
break;
|
||||
case SIGHUP:
|
||||
case SIGUSR1:
|
||||
case SIGHUP:
|
||||
case SIGUSR1:
|
||||
aprintf("got signal HUP/USR1, reading config\n");
|
||||
if (yhttpd)
|
||||
yhttpd->ReadConfig();
|
||||
yhttpd->ReadConfig();
|
||||
break;
|
||||
default:
|
||||
default:
|
||||
aprintf("No special SIGNAL-Handler:%d!\n",msignal);
|
||||
// log_level_printf(1, "Got SIGTERM\n");
|
||||
// log_level_printf(1, "Got SIGTERM\n");
|
||||
Cyhttpd::sig_do_shutdown = 1;
|
||||
yhttpd->stop_webserver();
|
||||
delete yhttpd;
|
||||
@@ -96,8 +96,7 @@ static void sig_catch(int msignal)
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void yhttpd_reload_config()
|
||||
{
|
||||
void yhttpd_reload_config() {
|
||||
if (yhttpd)
|
||||
yhttpd->ReadConfig();
|
||||
}
|
||||
@@ -105,15 +104,13 @@ void yhttpd_reload_config()
|
||||
// Main Entry
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef Y_CONFIG_BUILD_AS_DAEMON
|
||||
void * nhttpd_main_thread(void *)
|
||||
{
|
||||
pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0);
|
||||
void * nhttpd_main_thread(void *) {
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
|
||||
aprintf("Webserver %s tid %ld\n", WEBSERVERNAME, syscall(__NR_gettid));
|
||||
yhttpd = new Cyhttpd();
|
||||
//CLogging::getInstance()->setDebug(true);
|
||||
//CLogging::getInstance()->LogLevel = 9;
|
||||
if(!yhttpd)
|
||||
{
|
||||
//CLogging::getInstance()->setDebug(true);
|
||||
//CLogging::getInstance()->LogLevel = 9;
|
||||
if (!yhttpd) {
|
||||
aprintf("Error initializing WebServer\n");
|
||||
return (void *) EXIT_FAILURE;
|
||||
}
|
||||
@@ -121,8 +118,7 @@ void * nhttpd_main_thread(void *)
|
||||
|
||||
yhttpd->hooks_attach();
|
||||
yhttpd->ReadConfig();
|
||||
if(yhttpd->Configure())
|
||||
{
|
||||
if (yhttpd->Configure()) {
|
||||
// Start Webserver: fork ist if not in debug mode
|
||||
aprintf("Webserver starting...\n");
|
||||
dprintf("Start in Debug-Mode\n"); // non forked debugging loop
|
||||
@@ -174,7 +170,7 @@ int main(int argc, char **argv)
|
||||
else if ((!strncmp(argv[i], "-l", 2)) )
|
||||
{
|
||||
if(argv[i][2] >= '0' && argv[i][2] <= '9')
|
||||
CLogging::getInstance()->LogLevel = (argv[i][2]-'0');
|
||||
CLogging::getInstance()->LogLevel = (argv[i][2]-'0');
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -189,7 +185,7 @@ int main(int argc, char **argv)
|
||||
signal(SIGUSR1, sig_catch);
|
||||
signal(SIGTERM, sig_catch);
|
||||
signal(SIGCLD, SIG_IGN);
|
||||
// signal(SIGALRM, sig_catch);
|
||||
// signal(SIGALRM, sig_catch);
|
||||
|
||||
yhttpd->hooks_attach();
|
||||
yhttpd->ReadConfig();
|
||||
@@ -201,12 +197,12 @@ int main(int argc, char **argv)
|
||||
{
|
||||
log_level_printf(9,"do fork\n");
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
case -1:
|
||||
dperror("fork");
|
||||
return -1;
|
||||
case 0:
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
default:
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -229,15 +225,13 @@ int main(int argc, char **argv)
|
||||
//=============================================================================
|
||||
// Class yhttpd
|
||||
//=============================================================================
|
||||
Cyhttpd::Cyhttpd()
|
||||
{
|
||||
Cyhttpd::Cyhttpd() {
|
||||
webserver = new CWebserver();
|
||||
flag_threading_off = false;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
Cyhttpd::~Cyhttpd()
|
||||
{
|
||||
if(webserver)
|
||||
Cyhttpd::~Cyhttpd() {
|
||||
if (webserver)
|
||||
delete webserver;
|
||||
webserver = NULL;
|
||||
}
|
||||
@@ -245,10 +239,9 @@ Cyhttpd::~Cyhttpd()
|
||||
//-----------------------------------------------------------------------------
|
||||
// Change to Root
|
||||
//-----------------------------------------------------------------------------
|
||||
bool Cyhttpd::Configure()
|
||||
{
|
||||
bool Cyhttpd::Configure() {
|
||||
|
||||
if(!getuid()) // you must be root to do that!
|
||||
if (!getuid()) // you must be root to do that!
|
||||
{
|
||||
// Get user and group data
|
||||
#ifdef Y_CONFIG_FEATURE_HTTPD_USER
|
||||
@@ -276,7 +269,7 @@ bool Cyhttpd::Configure()
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// change root directory
|
||||
// change root directory
|
||||
#ifdef Y_CONFIG_FEATURE_CHROOT
|
||||
if(!ConfigList["server.chroot"].empty())
|
||||
{
|
||||
@@ -305,7 +298,7 @@ bool Cyhttpd::Configure()
|
||||
setgroups(0, NULL);
|
||||
// set user group
|
||||
if(groupname != "")
|
||||
initgroups(username.c_str(), grp->gr_gid);
|
||||
initgroups(username.c_str(), grp->gr_gid);
|
||||
// set user
|
||||
if(setuid(pwd->pw_uid) == -1)
|
||||
{
|
||||
@@ -320,32 +313,27 @@ bool Cyhttpd::Configure()
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main Webserver call
|
||||
//-----------------------------------------------------------------------------
|
||||
void Cyhttpd::run()
|
||||
{
|
||||
if(webserver)
|
||||
{
|
||||
if(flag_threading_off)
|
||||
void Cyhttpd::run() {
|
||||
if (webserver) {
|
||||
if (flag_threading_off)
|
||||
webserver->is_threading = false;
|
||||
webserver->run();
|
||||
stop_webserver();
|
||||
}
|
||||
else
|
||||
} else
|
||||
aprintf("Error initializing WebServer\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Show Version Text and Number
|
||||
//-----------------------------------------------------------------------------
|
||||
void Cyhttpd::version(FILE *dest)
|
||||
{
|
||||
void Cyhttpd::version(FILE *dest) {
|
||||
fprintf(dest, "%s - Webserver v%s\n", HTTPD_NAME, HTTPD_VERSION);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Show Usage
|
||||
//-----------------------------------------------------------------------------
|
||||
void Cyhttpd::usage(FILE *dest)
|
||||
{
|
||||
void Cyhttpd::usage(FILE *dest) {
|
||||
version(dest);
|
||||
fprintf(dest, "command line parameters:\n");
|
||||
fprintf(dest, "-d, --debug enable debugging code (implies -f)\n");
|
||||
@@ -359,8 +347,7 @@ void Cyhttpd::usage(FILE *dest)
|
||||
//-----------------------------------------------------------------------------
|
||||
// Stop WebServer
|
||||
//-----------------------------------------------------------------------------
|
||||
void Cyhttpd::stop_webserver()
|
||||
{
|
||||
void Cyhttpd::stop_webserver() {
|
||||
aprintf("stop requested......\n");
|
||||
if (webserver) {
|
||||
webserver->stop();
|
||||
@@ -370,8 +357,7 @@ void Cyhttpd::stop_webserver()
|
||||
//-----------------------------------------------------------------------------
|
||||
// Attach hooks (use hook order carefully)
|
||||
//-----------------------------------------------------------------------------
|
||||
void Cyhttpd::hooks_attach()
|
||||
{
|
||||
void Cyhttpd::hooks_attach() {
|
||||
#ifdef Y_CONFIG_USE_AUTHHOOK
|
||||
// First Check Authentication
|
||||
auth = new CmAuth();
|
||||
@@ -410,8 +396,7 @@ void Cyhttpd::hooks_attach()
|
||||
//-----------------------------------------------------------------------------
|
||||
// Detach hooks & Destroy
|
||||
//-----------------------------------------------------------------------------
|
||||
void Cyhttpd::hooks_detach()
|
||||
{
|
||||
void Cyhttpd::hooks_detach() {
|
||||
#ifdef Y_CONFIG_USE_AUTHHOOK
|
||||
CyhookHandler::detach(auth);
|
||||
delete auth;
|
||||
@@ -448,95 +433,128 @@ void Cyhttpd::hooks_detach()
|
||||
// Read Webserver Configurationfile
|
||||
// Call "Hooks_ReadConfig" so Hooks can read/write own Configuration Values
|
||||
//-----------------------------------------------------------------------------
|
||||
void Cyhttpd::ReadConfig(void)
|
||||
{
|
||||
log_level_printf(3,"ReadConfig Start\n");
|
||||
void Cyhttpd::ReadConfig(void) {
|
||||
log_level_printf(3, "ReadConfig Start\n");
|
||||
CConfigFile *Config = new CConfigFile(',');
|
||||
bool have_config = false;
|
||||
if(access(HTTPD_CONFIGFILE,4) == 0)
|
||||
if (access(HTTPD_CONFIGFILE, 4) == 0)
|
||||
have_config = true;
|
||||
Config->loadConfig(HTTPD_CONFIGFILE);
|
||||
// convert old config files
|
||||
if(have_config)
|
||||
{
|
||||
if(Config->getInt32("configfile.version",0) == 0)
|
||||
{
|
||||
if (have_config) {
|
||||
if (Config->getInt32("configfile.version", 0) == 0) {
|
||||
CConfigFile OrgConfig = *Config;
|
||||
Config->clear();
|
||||
|
||||
Config->setInt32("server.log.loglevel", OrgConfig.getInt32("LogLevel", 0));
|
||||
Config->setInt32("server.log.loglevel", OrgConfig.getInt32(
|
||||
"LogLevel", 0));
|
||||
Config->setInt32("configfile.version", CONF_VERSION);
|
||||
Config->setString("webserver.websites", "WebsiteMain");
|
||||
Config->setBool("webserver.threading", OrgConfig.getBool("THREADS", true));
|
||||
Config->setInt32("WebsiteMain.port",OrgConfig.getInt32("Port", HTTPD_STANDARD_PORT));
|
||||
Config->setString("WebsiteMain.directory", OrgConfig.getString("PrivatDocRoot", PRIVATEDOCUMENTROOT));
|
||||
if(OrgConfig.getString("PublicDocRoot", "") != "")
|
||||
Config->setString("WebsiteMain.override_directory", OrgConfig.getString("PublicDocRoot", PRIVATEDOCUMENTROOT));
|
||||
if(OrgConfig.getString("HostedDocRoot", "") != "")
|
||||
Config->setString("WebsiteMain.special_locations", "/hosted/="+OrgConfig.getString("HostedDocRoot", PRIVATEDOCUMENTROOT));
|
||||
if(OrgConfig.getString("HostedDocRoot", "") != "")
|
||||
Config->setString("Tuxbox.HostedDocumentRoot", OrgConfig.getString("HostedDocRoot", PRIVATEDOCUMENTROOT));
|
||||
Config->setBool("webserver.threading", OrgConfig.getBool("THREADS",
|
||||
true));
|
||||
Config->setInt32("WebsiteMain.port", OrgConfig.getInt32("Port",
|
||||
HTTPD_STANDARD_PORT));
|
||||
Config->setString("WebsiteMain.directory", OrgConfig.getString(
|
||||
"PrivatDocRoot", PRIVATEDOCUMENTROOT));
|
||||
if (OrgConfig.getString("PublicDocRoot", "") != "")
|
||||
Config->setString("WebsiteMain.override_directory",
|
||||
OrgConfig.getString("PublicDocRoot",
|
||||
PRIVATEDOCUMENTROOT));
|
||||
// mod_auth
|
||||
Config->setString("mod_auth.username", OrgConfig.getString("AuthUser", AUTHUSER));
|
||||
Config->setString("mod_auth.password", OrgConfig.getString("AuthPassword", AUTHPASSWORD));
|
||||
Config->setString("mod_auth.no_auth_client", OrgConfig.getString("NoAuthClient", ""));
|
||||
Config->setString("mod_auth.authenticate", OrgConfig.getString("Authenticate", "false"));
|
||||
Config->setString("mod_auth.username", OrgConfig.getString(
|
||||
"AuthUser", AUTHUSER));
|
||||
Config->setString("mod_auth.password", OrgConfig.getString(
|
||||
"AuthPassword", AUTHPASSWORD));
|
||||
Config->setString("mod_auth.no_auth_client", OrgConfig.getString(
|
||||
"NoAuthClient", ""));
|
||||
Config->setString("mod_auth.authenticate", OrgConfig.getString(
|
||||
"Authenticate", "false"));
|
||||
|
||||
Config->setString("mod_sendfile.mime_types", HTTPD_SENDFILE_EXT);
|
||||
|
||||
Config->saveConfig(HTTPD_CONFIGFILE);
|
||||
|
||||
}
|
||||
if (Config->getInt32("configfile.version") < 2)
|
||||
{
|
||||
// Add Defaults for Version 2
|
||||
if (Config->getInt32("configfile.version") < 2) {
|
||||
Config->setString("mod_sendfile.mime_types", HTTPD_SENDFILE_EXT);
|
||||
Config->setInt32("configfile.version", CONF_VERSION);
|
||||
Config->setString("mod_sendfile.sendAll","false");
|
||||
Config->setString("mod_sendfile.sendAll", "false");
|
||||
Config->saveConfig(HTTPD_CONFIGFILE);
|
||||
}
|
||||
if (Config->getInt32("configfile.version") < 4)
|
||||
{
|
||||
// Add Defaults for Version 4
|
||||
if (Config->getInt32("configfile.version") < 4) {
|
||||
Config->setInt32("configfile.version", CONF_VERSION);
|
||||
Config->setString("Language.selected", HTTPD_DEFAULT_LANGUAGE);
|
||||
Config->setString("Language.directory", HTTPD_LANGUAGEDIR);
|
||||
if (Config->getString("WebsiteMain.hosted_directory", "") == "")
|
||||
Config->setString("WebsiteMain.hosted_directory", "/var/hosted");
|
||||
Config->saveConfig(HTTPD_CONFIGFILE);
|
||||
}
|
||||
}
|
||||
// configure debugging & logging
|
||||
if(CLogging::getInstance()->LogLevel == 0)
|
||||
CLogging::getInstance()->LogLevel = Config->getInt32("server.log.loglevel", 0);
|
||||
if (CLogging::getInstance()->LogLevel == 0)
|
||||
CLogging::getInstance()->LogLevel = Config->getInt32(
|
||||
"server.log.loglevel", 0);
|
||||
|
||||
// get variables
|
||||
webserver->init(Config->getInt32("WebsiteMain.port", HTTPD_STANDARD_PORT), Config->getBool("webserver.threading", true));
|
||||
webserver->init(Config->getInt32("WebsiteMain.port", HTTPD_STANDARD_PORT),
|
||||
Config->getBool("webserver.threading", true));
|
||||
// informational use
|
||||
ConfigList["WebsiteMain.port"]= itoa(Config->getInt32("WebsiteMain.port", HTTPD_STANDARD_PORT));
|
||||
ConfigList["webserver.threading"]= Config->getString("webserver.threading", "true");
|
||||
ConfigList["configfile.version"]= Config->getInt32("configfile.version", CONF_VERSION);
|
||||
ConfigList["server.log.loglevel"]= itoa(Config->getInt32("server.log.loglevel", 0));
|
||||
ConfigList["server.no_keep-alive_ips"]= Config->getString("server.no_keep-alive_ips", "");
|
||||
webserver->conf_no_keep_alive_ips = Config->getStringVector("server.no_keep-alive_ips");
|
||||
ConfigList["WebsiteMain.port"] = itoa(Config->getInt32("WebsiteMain.port",
|
||||
HTTPD_STANDARD_PORT));
|
||||
ConfigList["webserver.threading"] = Config->getString(
|
||||
"webserver.threading", "true");
|
||||
ConfigList["configfile.version"] = Config->getInt32("configfile.version",
|
||||
CONF_VERSION);
|
||||
ConfigList["server.log.loglevel"] = itoa(Config->getInt32(
|
||||
"server.log.loglevel", 0));
|
||||
ConfigList["server.no_keep-alive_ips"] = Config->getString(
|
||||
"server.no_keep-alive_ips", "");
|
||||
webserver->conf_no_keep_alive_ips = Config->getStringVector(
|
||||
"server.no_keep-alive_ips");
|
||||
|
||||
// MainSite
|
||||
ConfigList["PrivatDocumentRoot"]= Config->getString("WebsiteMain.directory", PRIVATEDOCUMENTROOT);
|
||||
ConfigList["PublicDocumentRoot"]= Config->getString("WebsiteMain.override_directory", PUBLICDOCUMENTROOT);
|
||||
ConfigList["HostedDocumentRoot"]= Config->getString("Tuxbox.HostedDocumentRoot", HOSTEDDOCUMENTROOT);
|
||||
#ifdef Y_CONFIG_USE_OPEN_SSL
|
||||
ConfigList["SSL"] = Config->getString("WebsiteMain.ssl", "false");
|
||||
ConfigList["SSL_pemfile"] = Config->getString("WebsiteMain.ssl_pemfile", SSL_PEMFILE);
|
||||
ConfigList["SSL_CA_file"] = Config->getString("WebsiteMain.ssl_ca_file", SSL_CA_FILE);
|
||||
ConfigList["WebsiteMain.directory"] = Config->getString(
|
||||
"WebsiteMain.directory", PRIVATEDOCUMENTROOT);
|
||||
ConfigList["WebsiteMain.override_directory"] = Config->getString(
|
||||
"WebsiteMain.override_directory", PUBLICDOCUMENTROOT);
|
||||
ConfigList["WebsiteMain.hosted_directory"] = Config->getString(
|
||||
"WebsiteMain.hosted_directory", HOSTEDDOCUMENTROOT);
|
||||
|
||||
CySocket::SSL_pemfile = ConfigList["SSL_pemfile"];
|
||||
CySocket::SSL_CA_file = ConfigList["SSL_CA_file"];
|
||||
// Check location of logos
|
||||
if (Config->getString("Tuxbox.LogosURL", "") == "") {
|
||||
if (access(std::string(ConfigList["WebsiteMain.directory"] + "/logos").c_str(), 4) == 0) {
|
||||
Config->setString("Tuxbox.LogosURL", ConfigList["WebsiteMain.directory"] + "/logos");
|
||||
have_config = false; //save config
|
||||
}
|
||||
else if (access(std::string(ConfigList["WebsiteMain.override_directory"] ).c_str(), 4) == 0){
|
||||
Config->setString("Tuxbox.LogosURL", ConfigList["WebsiteMain.override_directory"] + "/logos");
|
||||
have_config = false; //save config
|
||||
}
|
||||
}
|
||||
ConfigList["Tuxbox.LogosURL"] = Config->getString("Tuxbox.LogosURL", "");
|
||||
|
||||
#ifdef Y_CONFIG_USE_OPEN_SSL
|
||||
ConfigList["SSL"] = Config->getString("WebsiteMain.ssl", "false");
|
||||
ConfigList["SSL_pemfile"] = Config->getString("WebsiteMain.ssl_pemfile", SSL_PEMFILE);
|
||||
ConfigList["SSL_CA_file"] = Config->getString("WebsiteMain.ssl_ca_file", SSL_CA_FILE);
|
||||
|
||||
CySocket::SSL_pemfile = ConfigList["SSL_pemfile"];
|
||||
CySocket::SSL_CA_file = ConfigList["SSL_CA_file"];
|
||||
if(ConfigList["SSL"] == "true")
|
||||
CySocket::initSSL();
|
||||
CySocket::initSSL();
|
||||
#endif
|
||||
ConfigList["server.user_name"]= Config->getString("server.user_name", "");
|
||||
ConfigList["server.group_name"]= Config->getString("server.group_name", "");
|
||||
ConfigList["server.chroot"]= Config->getString("server.chroot", "");
|
||||
ConfigList["server.user_name"] = Config->getString("server.user_name", "");
|
||||
ConfigList["server.group_name"]
|
||||
= Config->getString("server.group_name", "");
|
||||
ConfigList["server.chroot"] = Config->getString("server.chroot", "");
|
||||
|
||||
// language
|
||||
ConfigList["Language.directory"]=Config->getString("Language.directory", HTTPD_LANGUAGEDIR);
|
||||
ConfigList["Language.selected"]=Config->getString("Language.selected", HTTPD_DEFAULT_LANGUAGE);
|
||||
ConfigList["Language.directory"] = Config->getString("Language.directory",
|
||||
HTTPD_LANGUAGEDIR);
|
||||
ConfigList["Language.selected"] = Config->getString("Language.selected",
|
||||
HTTPD_DEFAULT_LANGUAGE);
|
||||
yhttpd->ReadLanguage();
|
||||
|
||||
// Read App specifig settings by Hook
|
||||
@@ -545,16 +563,16 @@ void Cyhttpd::ReadConfig(void)
|
||||
// Save if new defaults are set
|
||||
if (!have_config)
|
||||
Config->saveConfig(HTTPD_CONFIGFILE);
|
||||
log_level_printf(3,"ReadConfig End\n");
|
||||
log_level_printf(3, "ReadConfig End\n");
|
||||
delete Config;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
// Read Webserver Configurationfile for languages
|
||||
//-----------------------------------------------------------------------------
|
||||
void Cyhttpd::ReadLanguage(void)
|
||||
{
|
||||
void Cyhttpd::ReadLanguage(void) {
|
||||
// Init Class vars
|
||||
CLanguage *lang = CLanguage::getInstance();
|
||||
log_level_printf(3,"ReadLanguage:%s\n",ConfigList["Language.selected"].c_str());
|
||||
log_level_printf(3, "ReadLanguage:%s\n",
|
||||
ConfigList["Language.selected"].c_str());
|
||||
lang->setLanguage(ConfigList["Language.selected"]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user