diff --git a/lib/libconfigfile/configfile.h b/lib/libconfigfile/configfile.h index 69aa5353a..9d2c39853 100644 --- a/lib/libconfigfile/configfile.h +++ b/lib/libconfigfile/configfile.h @@ -30,13 +30,12 @@ #include #include +typedef std::map ConfigDataMap; class CConfigFile { private: - typedef std::map ConfigDataMap; - ConfigDataMap configData; char delimiter; bool saveDefaults; @@ -106,6 +105,7 @@ class CConfigFile bool getUnknownKeyQueryedFlag() const { return unknownKeyQueryedFlag; } void setUnknownKeyQueryedFlag(const bool val) { unknownKeyQueryedFlag = val; } + ConfigDataMap getConfigDataMap(){ return configData; } }; #endif /* __configfile_h__ */ diff --git a/src/nhttpd/tuxboxapi/coolstream/controlapi.cpp b/src/nhttpd/tuxboxapi/coolstream/controlapi.cpp index 2e2787bb3..620c1c4cc 100644 --- a/src/nhttpd/tuxboxapi/coolstream/controlapi.cpp +++ b/src/nhttpd/tuxboxapi/coolstream/controlapi.cpp @@ -192,6 +192,8 @@ const CControlAPI::TyCgiCall CControlAPI::yCgiCallList[]= // utils {"build_live_url", &CControlAPI::build_live_url, ""}, {"get_logo", &CControlAPI::logoCGI, "text/plain"}, + // settings + {"config", &CControlAPI::ConfigCGI, "text/plain"}, }; //----------------------------------------------------------------------------- @@ -2224,3 +2226,70 @@ void CControlAPI::logoCGI(CyhookHandler *hh) &channel_id); hh->Write(NeutrinoAPI->getLogoFile(hh->WebserverConfigList["Tuxbox.LogosURL"], channel_id)); } +//------------------------------------------------------------------------- +void CControlAPI::ConfigCGI(CyhookHandler *hh) +{ + bool load = true; + CConfigFile *Config = new CConfigFile(','); + ConfigDataMap conf; + std::string config_filename=""; + std::string error = ""; + std::string result = ""; + + if (hh->ParamList["action"] == "submit") + load = false; + + // Para "config" describes the config type + if(hh->ParamList["config"] == "neutrino") + config_filename = NEUTRINO_CONFIGFILE; + else if(hh->ParamList["config"] == "nhttpd") + config_filename = HTTPD_CONFIGFILE; + else if(hh->ParamList["config"] == "yweb") + config_filename = YWEB_CONFIGFILE; + + if(config_filename != ""){ + Config->loadConfig(config_filename); + + if(load){ + conf = Config->getConfigDataMap(); + ConfigDataMap::iterator it; + for(it = conf.begin(); it != conf.end(); it++){ + std::string key =it->first; + replace(key,".","_dot_"); + replace(key,"-","_bind_"); + if(!(hh->ParamList["config"] == "nhttpd" && it->first == "mod_auth.password")){ + // Output as json (default) + if (hh->ParamList["format"] == "json" || hh->ParamList["format"] == ""){ + result += string_printf("%s: '%s',\n", (key).c_str(), (it->second).c_str()); + } + } + } + } else { + for (CStringList::iterator it = hh->ParamList.begin(); it + != hh->ParamList.end(); it++) + if(it->first != "_dc" && it->first != "action" && it->first != "format" && it->first != "config"){ + Config->setString(it->first, it->second); + } + if(config_filename != "") + Config->saveConfig(config_filename); + } + } + else + error = string_printf("no config defined for: %s", (hh->ParamList["config"]).c_str() ); + + if(error == ""){ + if (hh->ParamList["format"] == "json" || hh->ParamList["format"] == ""){ + hh->WriteLn("{success: 'true', data:{"); + hh->WriteLn(result); + hh->WriteLn("}}"); + } + } else { + if (hh->ParamList["format"] == "json" || hh->ParamList["format"] == ""){ + hh->WriteLn("{success: 'false', error:{"); + hh->WriteLn(error); + hh->WriteLn("}}"); + } + } + + delete Config; +} diff --git a/src/nhttpd/tuxboxapi/coolstream/controlapi.h b/src/nhttpd/tuxboxapi/coolstream/controlapi.h index 8f09b0fe8..61226bc90 100644 --- a/src/nhttpd/tuxboxapi/coolstream/controlapi.h +++ b/src/nhttpd/tuxboxapi/coolstream/controlapi.h @@ -98,6 +98,7 @@ private: void updateBouquetCGI(CyhookHandler *hh); void build_live_url(CyhookHandler *hh); void logoCGI(CyhookHandler *hh); + void ConfigCGI(CyhookHandler *hh); protected: static const unsigned int PLUGIN_DIR_COUNT = 5; diff --git a/src/nhttpd/yconfig.h b/src/nhttpd/yconfig.h index ff913c2e2..1cec30b34 100644 --- a/src/nhttpd/yconfig.h +++ b/src/nhttpd/yconfig.h @@ -25,7 +25,7 @@ //----------------------------------------------------------------------------- // General central Definitions //----------------------------------------------------------------------------- -#define HTTPD_VERSION "3.3.0" // Webserver version (can be overloaded) +#define HTTPD_VERSION "3.3.1" // Webserver version (can be overloaded) #define YHTTPD_VERSION "1.3.1" // Webserver version (Version of yhttpd-core!) #define IADDR_LOCAL "127.0.0.1" // local IP #define HTTPD_NAME "yhttpd" // Webserver name (can be overloaded) @@ -103,6 +103,7 @@ #define HTTPD_CONFIGDIR "/var/tuxbox/config" #define HTTPD_CONFIGFILE HTTPD_CONFIGDIR "/nhttpd.conf" +#define YWEB_CONFIGFILE HTTPD_CONFIGDIR "/Y-Web.conf" #define PUBLICDOCUMENTROOT "/var/httpd" #define NEUTRINO_CONFIGFILE "/var/tuxbox/config/neutrino.conf" #define HOSTEDDOCUMENTROOT "/mnt/hosted"