mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-24 06:05:01 +02:00
parent
6fff339212
commit
da83bae660
@ -79,7 +79,7 @@ abstract class ConfigObject : ConfigObjectBase
|
|||||||
};
|
};
|
||||||
[config, internal, get_protected] String type (TypeNameV);
|
[config, internal, get_protected] String type (TypeNameV);
|
||||||
[config] name(Zone) zone (ZoneName);
|
[config] name(Zone) zone (ZoneName);
|
||||||
[config] String module;
|
[config] String package;
|
||||||
[config, internal, get_protected] Array::Ptr templates;
|
[config, internal, get_protected] Array::Ptr templates;
|
||||||
[get_protected] bool active;
|
[get_protected] bool active;
|
||||||
[get_protected] bool paused {
|
[get_protected] bool paused {
|
||||||
|
@ -44,7 +44,7 @@ static bool ExecuteExpression(Expression *expression)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void IncludeZoneDirRecursive(const String& path, const String& module, bool& success)
|
static void IncludeZoneDirRecursive(const String& path, const String& package, bool& success)
|
||||||
{
|
{
|
||||||
String zoneName = Utility::BaseName(path);
|
String zoneName = Utility::BaseName(path);
|
||||||
|
|
||||||
@ -52,29 +52,29 @@ static void IncludeZoneDirRecursive(const String& path, const String& module, bo
|
|||||||
ConfigCompiler::RegisterZoneDir("_etc", path, zoneName);
|
ConfigCompiler::RegisterZoneDir("_etc", path, zoneName);
|
||||||
|
|
||||||
std::vector<Expression *> expressions;
|
std::vector<Expression *> expressions;
|
||||||
Utility::GlobRecursive(path, "*.conf", boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, zoneName, module), GlobFile);
|
Utility::GlobRecursive(path, "*.conf", boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, zoneName, package), GlobFile);
|
||||||
DictExpression expr(expressions);
|
DictExpression expr(expressions);
|
||||||
if (!ExecuteExpression(&expr))
|
if (!ExecuteExpression(&expr))
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void IncludeNonLocalZone(const String& zonePath, const String& module, bool& success)
|
static void IncludeNonLocalZone(const String& zonePath, const String& package, bool& success)
|
||||||
{
|
{
|
||||||
String etcPath = Application::GetZonesDir() + "/" + Utility::BaseName(zonePath);
|
String etcPath = Application::GetZonesDir() + "/" + Utility::BaseName(zonePath);
|
||||||
|
|
||||||
if (Utility::PathExists(etcPath) || Utility::PathExists(zonePath + "/.authoritative"))
|
if (Utility::PathExists(etcPath) || Utility::PathExists(zonePath + "/.authoritative"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
IncludeZoneDirRecursive(zonePath, module, success);
|
IncludeZoneDirRecursive(zonePath, package, success);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void IncludeModule(const String& modulePath, bool& success)
|
static void IncludePackage(const String& packagePath, bool& success)
|
||||||
{
|
{
|
||||||
String moduleName = Utility::BaseName(modulePath);
|
String packageName = Utility::BaseName(packagePath);
|
||||||
|
|
||||||
if (Utility::PathExists(modulePath + "/include.conf")) {
|
if (Utility::PathExists(packagePath + "/include.conf")) {
|
||||||
Expression *expr = ConfigCompiler::CompileFile(modulePath + "/include.conf",
|
Expression *expr = ConfigCompiler::CompileFile(packagePath + "/include.conf",
|
||||||
String(), moduleName);
|
String(), packageName);
|
||||||
|
|
||||||
if (!ExecuteExpression(expr))
|
if (!ExecuteExpression(expr))
|
||||||
success = false;
|
success = false;
|
||||||
@ -117,9 +117,9 @@ bool DaemonUtility::ValidateConfigFiles(const std::vector<std::string>& configs,
|
|||||||
if (!success)
|
if (!success)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
String modulesVarDir = Application::GetLocalStateDir() + "/lib/icinga2/api/modules";
|
String packagesVarDir = Application::GetLocalStateDir() + "/lib/icinga2/api/packages";
|
||||||
if (Utility::PathExists(modulesVarDir))
|
if (Utility::PathExists(packagesVarDir))
|
||||||
Utility::Glob(modulesVarDir + "/*", boost::bind(&IncludeModule, _1, boost::ref(success)), GlobDirectory);
|
Utility::Glob(packagesVarDir + "/*", boost::bind(&IncludePackage, _1, boost::ref(success)), GlobDirectory);
|
||||||
|
|
||||||
if (!success)
|
if (!success)
|
||||||
return false;
|
return false;
|
||||||
|
@ -28,9 +28,9 @@ ApplyRule::RuleMap ApplyRule::m_Rules;
|
|||||||
ApplyRule::TypeMap ApplyRule::m_Types;
|
ApplyRule::TypeMap ApplyRule::m_Types;
|
||||||
|
|
||||||
ApplyRule::ApplyRule(const String& targetType, const String& name, const boost::shared_ptr<Expression>& expression,
|
ApplyRule::ApplyRule(const String& targetType, const String& name, const boost::shared_ptr<Expression>& expression,
|
||||||
const boost::shared_ptr<Expression>& filter, const String& module, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm,
|
const boost::shared_ptr<Expression>& filter, const String& package, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm,
|
||||||
const DebugInfo& di, const Dictionary::Ptr& scope)
|
const DebugInfo& di, const Dictionary::Ptr& scope)
|
||||||
: m_TargetType(targetType), m_Name(name), m_Expression(expression), m_Filter(filter), m_Module(module), m_FKVar(fkvar),
|
: m_TargetType(targetType), m_Name(name), m_Expression(expression), m_Filter(filter), m_Package(package), m_FKVar(fkvar),
|
||||||
m_FVVar(fvvar), m_FTerm(fterm), m_DebugInfo(di), m_Scope(scope), m_HasMatches(false)
|
m_FVVar(fvvar), m_FTerm(fterm), m_DebugInfo(di), m_Scope(scope), m_HasMatches(false)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@ -54,9 +54,9 @@ boost::shared_ptr<Expression> ApplyRule::GetFilter(void) const
|
|||||||
return m_Filter;
|
return m_Filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
String ApplyRule::GetModule(void) const
|
String ApplyRule::GetPackage(void) const
|
||||||
{
|
{
|
||||||
return m_Module;
|
return m_Package;
|
||||||
}
|
}
|
||||||
|
|
||||||
String ApplyRule::GetFKVar(void) const
|
String ApplyRule::GetFKVar(void) const
|
||||||
@ -85,10 +85,10 @@ Dictionary::Ptr ApplyRule::GetScope(void) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ApplyRule::AddRule(const String& sourceType, const String& targetType, const String& name,
|
void ApplyRule::AddRule(const String& sourceType, const String& targetType, const String& name,
|
||||||
const boost::shared_ptr<Expression>& expression, const boost::shared_ptr<Expression>& filter, const String& module, const String& fkvar,
|
const boost::shared_ptr<Expression>& expression, const boost::shared_ptr<Expression>& filter, const String& package, const String& fkvar,
|
||||||
const String& fvvar, const boost::shared_ptr<Expression>& fterm, const DebugInfo& di, const Dictionary::Ptr& scope)
|
const String& fvvar, const boost::shared_ptr<Expression>& fterm, const DebugInfo& di, const Dictionary::Ptr& scope)
|
||||||
{
|
{
|
||||||
m_Rules[sourceType].push_back(ApplyRule(targetType, name, expression, filter, module, fkvar, fvvar, fterm, di, scope));
|
m_Rules[sourceType].push_back(ApplyRule(targetType, name, expression, filter, package, fkvar, fvvar, fterm, di, scope));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ApplyRule::EvaluateFilter(ScriptFrame& frame) const
|
bool ApplyRule::EvaluateFilter(ScriptFrame& frame) const
|
||||||
|
@ -41,7 +41,7 @@ public:
|
|||||||
String GetName(void) const;
|
String GetName(void) const;
|
||||||
boost::shared_ptr<Expression> GetExpression(void) const;
|
boost::shared_ptr<Expression> GetExpression(void) const;
|
||||||
boost::shared_ptr<Expression> GetFilter(void) const;
|
boost::shared_ptr<Expression> GetFilter(void) const;
|
||||||
String GetModule(void) const;
|
String GetPackage(void) const;
|
||||||
String GetFKVar(void) const;
|
String GetFKVar(void) const;
|
||||||
String GetFVVar(void) const;
|
String GetFVVar(void) const;
|
||||||
boost::shared_ptr<Expression> GetFTerm(void) const;
|
boost::shared_ptr<Expression> GetFTerm(void) const;
|
||||||
@ -53,7 +53,7 @@ public:
|
|||||||
bool EvaluateFilter(ScriptFrame& frame) const;
|
bool EvaluateFilter(ScriptFrame& frame) const;
|
||||||
|
|
||||||
static void AddRule(const String& sourceType, const String& targetType, const String& name, const boost::shared_ptr<Expression>& expression,
|
static void AddRule(const String& sourceType, const String& targetType, const String& name, const boost::shared_ptr<Expression>& expression,
|
||||||
const boost::shared_ptr<Expression>& filter, const String& module, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm, const DebugInfo& di, const Dictionary::Ptr& scope);
|
const boost::shared_ptr<Expression>& filter, const String& package, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm, const DebugInfo& di, const Dictionary::Ptr& scope);
|
||||||
static std::vector<ApplyRule>& GetRules(const String& type);
|
static std::vector<ApplyRule>& GetRules(const String& type);
|
||||||
|
|
||||||
static void RegisterType(const String& sourceType, const std::vector<String>& targetTypes);
|
static void RegisterType(const String& sourceType, const std::vector<String>& targetTypes);
|
||||||
@ -69,7 +69,7 @@ private:
|
|||||||
String m_Name;
|
String m_Name;
|
||||||
boost::shared_ptr<Expression> m_Expression;
|
boost::shared_ptr<Expression> m_Expression;
|
||||||
boost::shared_ptr<Expression> m_Filter;
|
boost::shared_ptr<Expression> m_Filter;
|
||||||
String m_Module;
|
String m_Package;
|
||||||
String m_FKVar;
|
String m_FKVar;
|
||||||
String m_FVVar;
|
String m_FVVar;
|
||||||
boost::shared_ptr<Expression> m_FTerm;
|
boost::shared_ptr<Expression> m_FTerm;
|
||||||
@ -81,7 +81,7 @@ private:
|
|||||||
static RuleMap m_Rules;
|
static RuleMap m_Rules;
|
||||||
|
|
||||||
ApplyRule(const String& targetType, const String& name, const boost::shared_ptr<Expression>& expression,
|
ApplyRule(const String& targetType, const String& name, const boost::shared_ptr<Expression>& expression,
|
||||||
const boost::shared_ptr<Expression>& filter, const String& module, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm,
|
const boost::shared_ptr<Expression>& filter, const String& package, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm,
|
||||||
const DebugInfo& di, const Dictionary::Ptr& scope);
|
const DebugInfo& di, const Dictionary::Ptr& scope);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -378,7 +378,7 @@ object:
|
|||||||
BOOST_THROW_EXCEPTION(ScriptError("object rule 'ignore' is missing 'assign' for type '" + type + "'", DebugInfoRange(@2, @4)));
|
BOOST_THROW_EXCEPTION(ScriptError("object rule 'ignore' is missing 'assign' for type '" + type + "'", DebugInfoRange(@2, @4)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$$ = new ObjectExpression(abstract, type, $4, filter, context->GetZone(), context->GetModule(), $5, $6, DebugInfoRange(@2, @5));
|
$$ = new ObjectExpression(abstract, type, $4, filter, context->GetZone(), context->GetPackage(), $5, $6, DebugInfoRange(@2, @5));
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -1015,7 +1015,7 @@ apply:
|
|||||||
Expression *fterm = context->m_FTerm.top();
|
Expression *fterm = context->m_FTerm.top();
|
||||||
context->m_FTerm.pop();
|
context->m_FTerm.pop();
|
||||||
|
|
||||||
$$ = new ApplyExpression(type, target, $4, filter, context->GetModule(), fkvar, fvvar, fterm, $7, $8, DebugInfoRange(@2, @7));
|
$$ = new ApplyExpression(type, target, $4, filter, context->GetPackage(), fkvar, fvvar, fterm, $7, $8, DebugInfoRange(@2, @7));
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -42,8 +42,8 @@ std::map<String, std::vector<ZoneFragment> > ConfigCompiler::m_ZoneDirs;
|
|||||||
* @param zone The zone.
|
* @param zone The zone.
|
||||||
*/
|
*/
|
||||||
ConfigCompiler::ConfigCompiler(const String& path, std::istream *input,
|
ConfigCompiler::ConfigCompiler(const String& path, std::istream *input,
|
||||||
const String& zone, const String& module)
|
const String& zone, const String& package)
|
||||||
: m_Path(path), m_Input(input), m_Zone(zone), m_Module(module),
|
: m_Path(path), m_Input(input), m_Zone(zone), m_Package(package),
|
||||||
m_Eof(false), m_OpenBraces(0), m_IgnoreNewlines(0)
|
m_Eof(false), m_OpenBraces(0), m_IgnoreNewlines(0)
|
||||||
{
|
{
|
||||||
InitializeScanner();
|
InitializeScanner();
|
||||||
@ -100,20 +100,20 @@ String ConfigCompiler::GetZone(void) const
|
|||||||
return m_Zone;
|
return m_Zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigCompiler::SetModule(const String& module)
|
void ConfigCompiler::SetPackage(const String& package)
|
||||||
{
|
{
|
||||||
m_Module = module;
|
m_Package = package;
|
||||||
}
|
}
|
||||||
|
|
||||||
String ConfigCompiler::GetModule(void) const
|
String ConfigCompiler::GetPackage(void) const
|
||||||
{
|
{
|
||||||
return m_Module;
|
return m_Package;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigCompiler::CollectIncludes(std::vector<Expression *>& expressions,
|
void ConfigCompiler::CollectIncludes(std::vector<Expression *>& expressions,
|
||||||
const String& file, const String& zone, const String& module)
|
const String& file, const String& zone, const String& package)
|
||||||
{
|
{
|
||||||
expressions.push_back(CompileFile(file, zone, module));
|
expressions.push_back(CompileFile(file, zone, package));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -147,7 +147,7 @@ Expression *ConfigCompiler::HandleInclude(const String& include, bool search, co
|
|||||||
|
|
||||||
std::vector<Expression *> expressions;
|
std::vector<Expression *> expressions;
|
||||||
|
|
||||||
if (!Utility::Glob(includePath, boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, m_Zone, m_Module), GlobFile) && includePath.FindFirstOf("*?") == String::NPos) {
|
if (!Utility::Glob(includePath, boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, m_Zone, m_Package), GlobFile) && includePath.FindFirstOf("*?") == String::NPos) {
|
||||||
std::ostringstream msgbuf;
|
std::ostringstream msgbuf;
|
||||||
msgbuf << "Include file '" + include + "' does not exist";
|
msgbuf << "Include file '" + include + "' does not exist";
|
||||||
BOOST_THROW_EXCEPTION(ScriptError(msgbuf.str(), debuginfo));
|
BOOST_THROW_EXCEPTION(ScriptError(msgbuf.str(), debuginfo));
|
||||||
@ -175,7 +175,7 @@ Expression *ConfigCompiler::HandleIncludeRecursive(const String& path, const Str
|
|||||||
ppath = Utility::DirName(GetPath()) + "/" + path;
|
ppath = Utility::DirName(GetPath()) + "/" + path;
|
||||||
|
|
||||||
std::vector<Expression *> expressions;
|
std::vector<Expression *> expressions;
|
||||||
Utility::GlobRecursive(ppath, pattern, boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, m_Zone, m_Module), GlobFile);
|
Utility::GlobRecursive(ppath, pattern, boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, m_Zone, m_Package), GlobFile);
|
||||||
return new DictExpression(expressions);
|
return new DictExpression(expressions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ void ConfigCompiler::HandleIncludeZone(const String& tag, const String& path, co
|
|||||||
|
|
||||||
RegisterZoneDir(tag, ppath, zoneName);
|
RegisterZoneDir(tag, ppath, zoneName);
|
||||||
|
|
||||||
Utility::GlobRecursive(ppath, pattern, boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, zoneName, m_Module), GlobFile);
|
Utility::GlobRecursive(ppath, pattern, boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, zoneName, m_Package), GlobFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -225,13 +225,13 @@ Expression *ConfigCompiler::HandleIncludeZones(const String& tag, const String&
|
|||||||
* @returns Configuration items.
|
* @returns Configuration items.
|
||||||
*/
|
*/
|
||||||
Expression *ConfigCompiler::CompileStream(const String& path,
|
Expression *ConfigCompiler::CompileStream(const String& path,
|
||||||
std::istream *stream, const String& zone, const String& module)
|
std::istream *stream, const String& zone, const String& package)
|
||||||
{
|
{
|
||||||
CONTEXT("Compiling configuration stream with name '" + path + "'");
|
CONTEXT("Compiling configuration stream with name '" + path + "'");
|
||||||
|
|
||||||
stream->exceptions(std::istream::badbit);
|
stream->exceptions(std::istream::badbit);
|
||||||
|
|
||||||
ConfigCompiler ctx(path, stream, zone, module);
|
ConfigCompiler ctx(path, stream, zone, package);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return ctx.Compile();
|
return ctx.Compile();
|
||||||
@ -249,7 +249,7 @@ Expression *ConfigCompiler::CompileStream(const String& path,
|
|||||||
* @returns Configuration items.
|
* @returns Configuration items.
|
||||||
*/
|
*/
|
||||||
Expression *ConfigCompiler::CompileFile(const String& path, const String& zone,
|
Expression *ConfigCompiler::CompileFile(const String& path, const String& zone,
|
||||||
const String& module)
|
const String& package)
|
||||||
{
|
{
|
||||||
CONTEXT("Compiling configuration file '" + path + "'");
|
CONTEXT("Compiling configuration file '" + path + "'");
|
||||||
|
|
||||||
@ -264,7 +264,7 @@ Expression *ConfigCompiler::CompileFile(const String& path, const String& zone,
|
|||||||
Log(LogInformation, "ConfigCompiler")
|
Log(LogInformation, "ConfigCompiler")
|
||||||
<< "Compiling config file: " << path;
|
<< "Compiling config file: " << path;
|
||||||
|
|
||||||
return CompileStream(path, &stream, zone, module);
|
return CompileStream(path, &stream, zone, package);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -275,10 +275,10 @@ Expression *ConfigCompiler::CompileFile(const String& path, const String& zone,
|
|||||||
* @returns Configuration items.
|
* @returns Configuration items.
|
||||||
*/
|
*/
|
||||||
Expression *ConfigCompiler::CompileText(const String& path, const String& text,
|
Expression *ConfigCompiler::CompileText(const String& path, const String& text,
|
||||||
const String& zone, const String& module)
|
const String& zone, const String& package)
|
||||||
{
|
{
|
||||||
std::stringstream stream(text);
|
std::stringstream stream(text);
|
||||||
return CompileStream(path, &stream, zone, module);
|
return CompileStream(path, &stream, zone, package);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,17 +80,17 @@ class I2_CONFIG_API ConfigCompiler
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit ConfigCompiler(const String& path, std::istream *input,
|
explicit ConfigCompiler(const String& path, std::istream *input,
|
||||||
const String& zone = String(), const String& module = String());
|
const String& zone = String(), const String& package = String());
|
||||||
virtual ~ConfigCompiler(void);
|
virtual ~ConfigCompiler(void);
|
||||||
|
|
||||||
Expression *Compile(void);
|
Expression *Compile(void);
|
||||||
|
|
||||||
static Expression *CompileStream(const String& path, std::istream *stream,
|
static Expression *CompileStream(const String& path, std::istream *stream,
|
||||||
const String& zone = String(), const String& module = String());
|
const String& zone = String(), const String& package = String());
|
||||||
static Expression *CompileFile(const String& path, const String& zone = String(),
|
static Expression *CompileFile(const String& path, const String& zone = String(),
|
||||||
const String& module = String());
|
const String& package = String());
|
||||||
static Expression *CompileText(const String& path, const String& text,
|
static Expression *CompileText(const String& path, const String& text,
|
||||||
const String& zone = String(), const String& module = String());
|
const String& zone = String(), const String& package = String());
|
||||||
|
|
||||||
static void AddIncludeSearchDir(const String& dir);
|
static void AddIncludeSearchDir(const String& dir);
|
||||||
|
|
||||||
@ -99,11 +99,11 @@ public:
|
|||||||
void SetZone(const String& zone);
|
void SetZone(const String& zone);
|
||||||
String GetZone(void) const;
|
String GetZone(void) const;
|
||||||
|
|
||||||
void SetModule(const String& module);
|
void SetPackage(const String& package);
|
||||||
String GetModule(void) const;
|
String GetPackage(void) const;
|
||||||
|
|
||||||
static void CollectIncludes(std::vector<Expression *>& expressions,
|
static void CollectIncludes(std::vector<Expression *>& expressions,
|
||||||
const String& file, const String& zone, const String& module);
|
const String& file, const String& zone, const String& package);
|
||||||
|
|
||||||
/* internally used methods */
|
/* internally used methods */
|
||||||
Expression *HandleInclude(const String& include, bool search, const DebugInfo& debuginfo = DebugInfo());
|
Expression *HandleInclude(const String& include, bool search, const DebugInfo& debuginfo = DebugInfo());
|
||||||
@ -124,7 +124,7 @@ private:
|
|||||||
String m_Path;
|
String m_Path;
|
||||||
std::istream *m_Input;
|
std::istream *m_Input;
|
||||||
String m_Zone;
|
String m_Zone;
|
||||||
String m_Module;
|
String m_Package;
|
||||||
|
|
||||||
void *m_Scanner;
|
void *m_Scanner;
|
||||||
|
|
||||||
|
@ -62,11 +62,11 @@ ConfigItem::ConfigItem(const String& type, const String& name,
|
|||||||
bool abstract, const boost::shared_ptr<Expression>& exprl,
|
bool abstract, const boost::shared_ptr<Expression>& exprl,
|
||||||
const boost::shared_ptr<Expression>& filter,
|
const boost::shared_ptr<Expression>& filter,
|
||||||
const DebugInfo& debuginfo, const Dictionary::Ptr& scope,
|
const DebugInfo& debuginfo, const Dictionary::Ptr& scope,
|
||||||
const String& zone, const String& module)
|
const String& zone, const String& package)
|
||||||
: m_Type(type), m_Name(name), m_Abstract(abstract),
|
: m_Type(type), m_Name(name), m_Abstract(abstract),
|
||||||
m_Expression(exprl), m_Filter(filter),
|
m_Expression(exprl), m_Filter(filter),
|
||||||
m_DebugInfo(debuginfo), m_Scope(scope), m_Zone(zone),
|
m_DebugInfo(debuginfo), m_Scope(scope), m_Zone(zone),
|
||||||
m_Module(module)
|
m_Package(package)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard)
|
|||||||
dobj->SetDebugInfo(m_DebugInfo);
|
dobj->SetDebugInfo(m_DebugInfo);
|
||||||
dobj->SetTypeNameV(m_Type);
|
dobj->SetTypeNameV(m_Type);
|
||||||
dobj->SetZoneName(m_Zone);
|
dobj->SetZoneName(m_Zone);
|
||||||
dobj->SetModule(m_Module);
|
dobj->SetPackage(m_Package);
|
||||||
dobj->SetName(m_Name);
|
dobj->SetName(m_Name);
|
||||||
|
|
||||||
DebugHint debugHints;
|
DebugHint debugHints;
|
||||||
|
@ -43,7 +43,7 @@ public:
|
|||||||
const boost::shared_ptr<Expression>& filter,
|
const boost::shared_ptr<Expression>& filter,
|
||||||
const DebugInfo& debuginfo,
|
const DebugInfo& debuginfo,
|
||||||
const Dictionary::Ptr& scope, const String& zone,
|
const Dictionary::Ptr& scope, const String& zone,
|
||||||
const String& module);
|
const String& package);
|
||||||
|
|
||||||
String GetType(void) const;
|
String GetType(void) const;
|
||||||
String GetName(void) const;
|
String GetName(void) const;
|
||||||
@ -81,7 +81,7 @@ private:
|
|||||||
DebugInfo m_DebugInfo; /**< Debug information. */
|
DebugInfo m_DebugInfo; /**< Debug information. */
|
||||||
Dictionary::Ptr m_Scope; /**< variable scope. */
|
Dictionary::Ptr m_Scope; /**< variable scope. */
|
||||||
String m_Zone; /**< The zone. */
|
String m_Zone; /**< The zone. */
|
||||||
String m_Module;
|
String m_Package;
|
||||||
|
|
||||||
ConfigObject::Ptr m_Object;
|
ConfigObject::Ptr m_Object;
|
||||||
|
|
||||||
|
@ -65,9 +65,9 @@ void ConfigItemBuilder::SetZone(const String& zone)
|
|||||||
m_Zone = zone;
|
m_Zone = zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigItemBuilder::SetModule(const String& module)
|
void ConfigItemBuilder::SetPackage(const String& package)
|
||||||
{
|
{
|
||||||
m_Module = module;
|
m_Package = package;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigItemBuilder::AddExpression(Expression *expr)
|
void ConfigItemBuilder::AddExpression(Expression *expr)
|
||||||
@ -116,6 +116,6 @@ ConfigItem::Ptr ConfigItemBuilder::Compile(void)
|
|||||||
exprl->MakeInline();
|
exprl->MakeInline();
|
||||||
|
|
||||||
return new ConfigItem(m_Type, m_Name, m_Abstract, exprl, m_Filter,
|
return new ConfigItem(m_Type, m_Name, m_Abstract, exprl, m_Filter,
|
||||||
m_DebugInfo, m_Scope, m_Zone, m_Module);
|
m_DebugInfo, m_Scope, m_Zone, m_Package);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ public:
|
|||||||
void SetAbstract(bool abstract);
|
void SetAbstract(bool abstract);
|
||||||
void SetScope(const Dictionary::Ptr& scope);
|
void SetScope(const Dictionary::Ptr& scope);
|
||||||
void SetZone(const String& zone);
|
void SetZone(const String& zone);
|
||||||
void SetModule(const String& module);
|
void SetPackage(const String& package);
|
||||||
|
|
||||||
void AddExpression(Expression *expr);
|
void AddExpression(Expression *expr);
|
||||||
void SetFilter(const boost::shared_ptr<Expression>& filter);
|
void SetFilter(const boost::shared_ptr<Expression>& filter);
|
||||||
@ -63,7 +63,7 @@ private:
|
|||||||
DebugInfo m_DebugInfo; /**< Debug information. */
|
DebugInfo m_DebugInfo; /**< Debug information. */
|
||||||
Dictionary::Ptr m_Scope; /**< variable scope. */
|
Dictionary::Ptr m_Scope; /**< variable scope. */
|
||||||
String m_Zone; /**< The zone. */
|
String m_Zone; /**< The zone. */
|
||||||
String m_Module; /**< The module name. */
|
String m_Package; /**< The package name. */
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -749,7 +749,7 @@ ExpressionResult ApplyExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhin
|
|||||||
CHECK_RESULT(nameres);
|
CHECK_RESULT(nameres);
|
||||||
|
|
||||||
return VMOps::NewApply(frame, m_Type, m_Target, nameres.GetValue(), m_Filter,
|
return VMOps::NewApply(frame, m_Type, m_Target, nameres.GetValue(), m_Filter,
|
||||||
m_Module, m_FKVar, m_FVVar, m_FTerm, m_ClosedVars, m_Expression, m_DebugInfo);
|
m_Package, m_FKVar, m_FVVar, m_FTerm, m_ClosedVars, m_Expression, m_DebugInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpressionResult ObjectExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
ExpressionResult ObjectExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
||||||
@ -767,7 +767,7 @@ ExpressionResult ObjectExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhi
|
|||||||
}
|
}
|
||||||
|
|
||||||
return VMOps::NewObject(frame, m_Abstract, m_Type, name, m_Filter, m_Zone,
|
return VMOps::NewObject(frame, m_Abstract, m_Type, name, m_Filter, m_Zone,
|
||||||
m_Module, m_ClosedVars, m_Expression, m_DebugInfo);
|
m_Package, m_ClosedVars, m_Expression, m_DebugInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpressionResult ForExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
ExpressionResult ForExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
||||||
|
@ -803,11 +803,11 @@ class I2_CONFIG_API ApplyExpression : public DebuggableExpression
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ApplyExpression(const String& type, const String& target, Expression *name,
|
ApplyExpression(const String& type, const String& target, Expression *name,
|
||||||
Expression *filter, const String& module, const String& fkvar, const String& fvvar,
|
Expression *filter, const String& package, const String& fkvar, const String& fvvar,
|
||||||
Expression *fterm, std::map<String, Expression *> *closedVars,
|
Expression *fterm, std::map<String, Expression *> *closedVars,
|
||||||
Expression *expression, const DebugInfo& debugInfo = DebugInfo())
|
Expression *expression, const DebugInfo& debugInfo = DebugInfo())
|
||||||
: DebuggableExpression(debugInfo), m_Type(type), m_Target(target),
|
: DebuggableExpression(debugInfo), m_Type(type), m_Target(target),
|
||||||
m_Name(name), m_Filter(filter), m_Module(module), m_FKVar(fkvar), m_FVVar(fvvar),
|
m_Name(name), m_Filter(filter), m_Package(package), m_FKVar(fkvar), m_FVVar(fvvar),
|
||||||
m_FTerm(fterm), m_ClosedVars(closedVars), m_Expression(expression)
|
m_FTerm(fterm), m_ClosedVars(closedVars), m_Expression(expression)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@ -824,7 +824,7 @@ private:
|
|||||||
String m_Target;
|
String m_Target;
|
||||||
Expression *m_Name;
|
Expression *m_Name;
|
||||||
boost::shared_ptr<Expression> m_Filter;
|
boost::shared_ptr<Expression> m_Filter;
|
||||||
String m_Module;
|
String m_Package;
|
||||||
String m_FKVar;
|
String m_FKVar;
|
||||||
String m_FVVar;
|
String m_FVVar;
|
||||||
boost::shared_ptr<Expression> m_FTerm;
|
boost::shared_ptr<Expression> m_FTerm;
|
||||||
@ -836,10 +836,10 @@ class I2_CONFIG_API ObjectExpression : public DebuggableExpression
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ObjectExpression(bool abstract, const String& type, Expression *name, Expression *filter,
|
ObjectExpression(bool abstract, const String& type, Expression *name, Expression *filter,
|
||||||
const String& zone, const String& module, std::map<String, Expression *> *closedVars,
|
const String& zone, const String& package, std::map<String, Expression *> *closedVars,
|
||||||
Expression *expression, const DebugInfo& debugInfo = DebugInfo())
|
Expression *expression, const DebugInfo& debugInfo = DebugInfo())
|
||||||
: DebuggableExpression(debugInfo), m_Abstract(abstract), m_Type(type),
|
: DebuggableExpression(debugInfo), m_Abstract(abstract), m_Type(type),
|
||||||
m_Name(name), m_Filter(filter), m_Zone(zone), m_Module(module), m_ClosedVars(closedVars), m_Expression(expression)
|
m_Name(name), m_Filter(filter), m_Zone(zone), m_Package(package), m_ClosedVars(closedVars), m_Expression(expression)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
~ObjectExpression(void)
|
~ObjectExpression(void)
|
||||||
@ -856,7 +856,7 @@ private:
|
|||||||
Expression *m_Name;
|
Expression *m_Name;
|
||||||
boost::shared_ptr<Expression> m_Filter;
|
boost::shared_ptr<Expression> m_Filter;
|
||||||
String m_Zone;
|
String m_Zone;
|
||||||
String m_Module;
|
String m_Package;
|
||||||
std::map<String, Expression *> *m_ClosedVars;
|
std::map<String, Expression *> *m_ClosedVars;
|
||||||
boost::shared_ptr<Expression> m_Expression;
|
boost::shared_ptr<Expression> m_Expression;
|
||||||
};
|
};
|
||||||
|
@ -105,17 +105,17 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline Value NewApply(ScriptFrame& frame, const String& type, const String& target, const String& name, const boost::shared_ptr<Expression>& filter,
|
static inline Value NewApply(ScriptFrame& frame, const String& type, const String& target, const String& name, const boost::shared_ptr<Expression>& filter,
|
||||||
const String& module, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm, std::map<String, Expression *> *closedVars,
|
const String& package, const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm, std::map<String, Expression *> *closedVars,
|
||||||
const boost::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
|
const boost::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
|
||||||
{
|
{
|
||||||
ApplyRule::AddRule(type, target, name, expression, filter, module, fkvar,
|
ApplyRule::AddRule(type, target, name, expression, filter, package, fkvar,
|
||||||
fvvar, fterm, debugInfo, EvaluateClosedVars(frame, closedVars));
|
fvvar, fterm, debugInfo, EvaluateClosedVars(frame, closedVars));
|
||||||
|
|
||||||
return Empty;
|
return Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Value NewObject(ScriptFrame& frame, bool abstract, const String& type, const String& name, const boost::shared_ptr<Expression>& filter,
|
static inline Value NewObject(ScriptFrame& frame, bool abstract, const String& type, const String& name, const boost::shared_ptr<Expression>& filter,
|
||||||
const String& zone, const String& module, std::map<String, Expression *> *closedVars, const boost::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
|
const String& zone, const String& package, std::map<String, Expression *> *closedVars, const boost::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
|
||||||
{
|
{
|
||||||
ConfigItemBuilder::Ptr item = new ConfigItemBuilder(debugInfo);
|
ConfigItemBuilder::Ptr item = new ConfigItemBuilder(debugInfo);
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ public:
|
|||||||
item->SetAbstract(abstract);
|
item->SetAbstract(abstract);
|
||||||
item->SetScope(EvaluateClosedVars(frame, closedVars));
|
item->SetScope(EvaluateClosedVars(frame, closedVars));
|
||||||
item->SetZone(zone);
|
item->SetZone(zone);
|
||||||
item->SetModule(module);
|
item->SetPackage(package);
|
||||||
item->SetFilter(filter);
|
item->SetFilter(filter);
|
||||||
item->Compile()->Register();
|
item->Compile()->Register();
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ bool Dependency::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, cons
|
|||||||
if (!zone.IsEmpty())
|
if (!zone.IsEmpty())
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
||||||
|
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "module"), OpSetLiteral, MakeLiteral(rule.GetModule()), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di));
|
||||||
|
|
||||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ bool Notification::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, co
|
|||||||
if (!zone.IsEmpty())
|
if (!zone.IsEmpty())
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
||||||
|
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "module"), OpSetLiteral, MakeLiteral(rule.GetModule()), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di));
|
||||||
|
|
||||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ bool ScheduledDowntime::EvaluateApplyRuleInstance(const Checkable::Ptr& checkabl
|
|||||||
if (!zone.IsEmpty())
|
if (!zone.IsEmpty())
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
||||||
|
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "module"), OpSetLiteral, MakeLiteral(rule.GetModule()), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di));
|
||||||
|
|
||||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ bool Service::EvaluateApplyRuleInstance(const Host::Ptr& host, const String& nam
|
|||||||
if (!zone.IsEmpty())
|
if (!zone.IsEmpty())
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
||||||
|
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "module"), OpSetLiteral, MakeLiteral(rule.GetModule()), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di));
|
||||||
|
|
||||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ set(remote_SOURCES
|
|||||||
actionshandler.cpp apiaction.cpp
|
actionshandler.cpp apiaction.cpp
|
||||||
apifunction.cpp apilistener.cpp apilistener.thpp apilistener-sync.cpp
|
apifunction.cpp apilistener.cpp apilistener.thpp apilistener-sync.cpp
|
||||||
apiuser.cpp apiuser.thpp authority.cpp base64.cpp
|
apiuser.cpp apiuser.thpp authority.cpp base64.cpp
|
||||||
configfileshandler.cpp configmoduleshandler.cpp configmoduleutility.cpp configobjectutility.cpp
|
configfileshandler.cpp configpackageshandler.cpp configpackageutility.cpp configobjectutility.cpp
|
||||||
configstageshandler.cpp createobjecthandler.cpp deleteobjecthandler.cpp
|
configstageshandler.cpp createobjecthandler.cpp deleteobjecthandler.cpp
|
||||||
endpoint.cpp endpoint.thpp filterutility.cpp
|
endpoint.cpp endpoint.thpp filterutility.cpp
|
||||||
httpchunkedencoding.cpp httpclientconnection.cpp httpserverconnection.cpp httphandler.cpp httprequest.cpp httpresponse.cpp
|
httpchunkedencoding.cpp httpclientconnection.cpp httpserverconnection.cpp httphandler.cpp httprequest.cpp httpresponse.cpp
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "remote/configfileshandler.hpp"
|
#include "remote/configfileshandler.hpp"
|
||||||
#include "remote/configmoduleutility.hpp"
|
#include "remote/configpackageutility.hpp"
|
||||||
#include "remote/httputility.hpp"
|
#include "remote/httputility.hpp"
|
||||||
#include "base/exception.hpp"
|
#include "base/exception.hpp"
|
||||||
#include <boost/algorithm/string/join.hpp>
|
#include <boost/algorithm/string/join.hpp>
|
||||||
@ -45,7 +45,7 @@ void ConfigFilesHandler::HandleGet(const ApiUser::Ptr& user, HttpRequest& reques
|
|||||||
const std::vector<String>& urlPath = request.RequestUrl->GetPath();
|
const std::vector<String>& urlPath = request.RequestUrl->GetPath();
|
||||||
|
|
||||||
if (urlPath.size() >= 4)
|
if (urlPath.size() >= 4)
|
||||||
params->Set("module", urlPath[3]);
|
params->Set("package", urlPath[3]);
|
||||||
|
|
||||||
if (urlPath.size() >= 5)
|
if (urlPath.size() >= 5)
|
||||||
params->Set("stage", urlPath[4]);
|
params->Set("stage", urlPath[4]);
|
||||||
@ -55,22 +55,22 @@ void ConfigFilesHandler::HandleGet(const ApiUser::Ptr& user, HttpRequest& reques
|
|||||||
params->Set("path", boost::algorithm::join(tmpPath, "/"));
|
params->Set("path", boost::algorithm::join(tmpPath, "/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
String moduleName = HttpUtility::GetLastParameter(params, "module");
|
String packageName = HttpUtility::GetLastParameter(params, "package");
|
||||||
String stageName = HttpUtility::GetLastParameter(params, "stage");
|
String stageName = HttpUtility::GetLastParameter(params, "stage");
|
||||||
|
|
||||||
if (!ConfigModuleUtility::ValidateName(moduleName) || !ConfigModuleUtility::ValidateName(stageName)) {
|
if (!ConfigPackageUtility::ValidateName(packageName) || !ConfigPackageUtility::ValidateName(stageName)) {
|
||||||
response.SetStatus(403, "Forbidden");
|
response.SetStatus(403, "Forbidden");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String relativePath = HttpUtility::GetLastParameter(params, "path");
|
String relativePath = HttpUtility::GetLastParameter(params, "path");
|
||||||
|
|
||||||
if (ConfigModuleUtility::ContainsDotDot(relativePath)) {
|
if (ConfigPackageUtility::ContainsDotDot(relativePath)) {
|
||||||
response.SetStatus(403, "Forbidden");
|
response.SetStatus(403, "Forbidden");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String path = ConfigModuleUtility::GetModuleDir() + "/" + moduleName + "/" + stageName + "/" + relativePath;
|
String path = ConfigPackageUtility::GetPackageDir() + "/" + packageName + "/" + stageName + "/" + relativePath;
|
||||||
|
|
||||||
if (!Utility::PathExists(path)) {
|
if (!Utility::PathExists(path)) {
|
||||||
response.SetStatus(404, "File not found");
|
response.SetStatus(404, "File not found");
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "remote/configobjectutility.hpp"
|
#include "remote/configobjectutility.hpp"
|
||||||
#include "remote/configmoduleutility.hpp"
|
#include "remote/configpackageutility.hpp"
|
||||||
#include "config/configitembuilder.hpp"
|
#include "config/configitembuilder.hpp"
|
||||||
#include "config/configitem.hpp"
|
#include "config/configitem.hpp"
|
||||||
#include "config/configwriter.hpp"
|
#include "config/configwriter.hpp"
|
||||||
@ -33,8 +33,8 @@ using namespace icinga;
|
|||||||
|
|
||||||
String ConfigObjectUtility::GetConfigDir(void)
|
String ConfigObjectUtility::GetConfigDir(void)
|
||||||
{
|
{
|
||||||
return ConfigModuleUtility::GetModuleDir() + "/_api/" +
|
return ConfigPackageUtility::GetPackageDir() + "/_api/" +
|
||||||
ConfigModuleUtility::GetActiveStage("_api");
|
ConfigPackageUtility::GetActiveStage("_api");
|
||||||
}
|
}
|
||||||
|
|
||||||
String ConfigObjectUtility::EscapeName(const String& name)
|
String ConfigObjectUtility::EscapeName(const String& name)
|
||||||
@ -59,7 +59,7 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full
|
|||||||
builder->SetType(type->GetName());
|
builder->SetType(type->GetName());
|
||||||
builder->SetName(name);
|
builder->SetName(name);
|
||||||
builder->SetScope(ScriptGlobal::GetGlobals());
|
builder->SetScope(ScriptGlobal::GetGlobals());
|
||||||
builder->SetModule("_api");
|
builder->SetPackage("_api");
|
||||||
|
|
||||||
if (templates) {
|
if (templates) {
|
||||||
ObjectLock olock(templates);
|
ObjectLock olock(templates);
|
||||||
@ -116,11 +116,11 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ConfigModuleUtility::ModuleExists("_api")) {
|
if (!ConfigPackageUtility::PackageExists("_api")) {
|
||||||
ConfigModuleUtility::CreateModule("_api");
|
ConfigPackageUtility::CreatePackage("_api");
|
||||||
|
|
||||||
String stage = ConfigModuleUtility::CreateStage("_api");
|
String stage = ConfigPackageUtility::CreateStage("_api");
|
||||||
ConfigModuleUtility::ActivateStage("_api", stage);
|
ConfigPackageUtility::ActivateStage("_api", stage);
|
||||||
}
|
}
|
||||||
|
|
||||||
String typeDir = type->GetPluralName();
|
String typeDir = type->GetPluralName();
|
||||||
@ -205,7 +205,7 @@ bool ConfigObjectUtility::DeleteObjectHelper(const ConfigObject::Ptr& object, bo
|
|||||||
|
|
||||||
bool ConfigObjectUtility::DeleteObject(const ConfigObject::Ptr& object, bool cascade, const Array::Ptr& errors)
|
bool ConfigObjectUtility::DeleteObject(const ConfigObject::Ptr& object, bool cascade, const Array::Ptr& errors)
|
||||||
{
|
{
|
||||||
if (object->GetModule() != "_api") {
|
if (object->GetPackage() != "_api") {
|
||||||
if (errors)
|
if (errors)
|
||||||
errors->Add("Object cannot be deleted because it was not created using the API.");
|
errors->Add("Object cannot be deleted because it was not created using the API.");
|
||||||
|
|
||||||
|
@ -17,16 +17,16 @@
|
|||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "remote/configmoduleshandler.hpp"
|
#include "remote/configpackageshandler.hpp"
|
||||||
#include "remote/configmoduleutility.hpp"
|
#include "remote/configpackageutility.hpp"
|
||||||
#include "remote/httputility.hpp"
|
#include "remote/httputility.hpp"
|
||||||
#include "base/exception.hpp"
|
#include "base/exception.hpp"
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
REGISTER_URLHANDLER("/v1/config/modules", ConfigModulesHandler);
|
REGISTER_URLHANDLER("/v1/config/packages", ConfigPackagesHandler);
|
||||||
|
|
||||||
bool ConfigModulesHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
bool ConfigPackagesHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
||||||
{
|
{
|
||||||
if (request.RequestUrl->GetPath().size() > 4)
|
if (request.RequestUrl->GetPath().size() > 4)
|
||||||
return false;
|
return false;
|
||||||
@ -43,18 +43,18 @@ bool ConfigModulesHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest&
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigModulesHandler::HandleGet(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
void ConfigPackagesHandler::HandleGet(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
||||||
{
|
{
|
||||||
std::vector<String> modules = ConfigModuleUtility::GetModules();
|
std::vector<String> packages = ConfigPackageUtility::GetPackages();
|
||||||
|
|
||||||
Array::Ptr results = new Array();
|
Array::Ptr results = new Array();
|
||||||
|
|
||||||
BOOST_FOREACH(const String& module, modules) {
|
BOOST_FOREACH(const String& package, packages) {
|
||||||
Dictionary::Ptr moduleInfo = new Dictionary();
|
Dictionary::Ptr packageInfo = new Dictionary();
|
||||||
moduleInfo->Set("name", module);
|
packageInfo->Set("name", package);
|
||||||
moduleInfo->Set("stages", Array::FromVector(ConfigModuleUtility::GetStages(module)));
|
packageInfo->Set("stages", Array::FromVector(ConfigPackageUtility::GetStages(package)));
|
||||||
moduleInfo->Set("active-stage", ConfigModuleUtility::GetActiveStage(module));
|
packageInfo->Set("active-stage", ConfigPackageUtility::GetActiveStage(package));
|
||||||
results->Add(moduleInfo);
|
results->Add(packageInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::Ptr result = new Dictionary();
|
Dictionary::Ptr result = new Dictionary();
|
||||||
@ -64,25 +64,25 @@ void ConfigModulesHandler::HandleGet(const ApiUser::Ptr& user, HttpRequest& requ
|
|||||||
HttpUtility::SendJsonBody(response, result);
|
HttpUtility::SendJsonBody(response, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigModulesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
void ConfigPackagesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
||||||
{
|
{
|
||||||
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
||||||
|
|
||||||
if (request.RequestUrl->GetPath().size() >= 4)
|
if (request.RequestUrl->GetPath().size() >= 4)
|
||||||
params->Set("module", request.RequestUrl->GetPath()[3]);
|
params->Set("package", request.RequestUrl->GetPath()[3]);
|
||||||
|
|
||||||
String moduleName = HttpUtility::GetLastParameter(params, "module");
|
String packageName = HttpUtility::GetLastParameter(params, "package");
|
||||||
|
|
||||||
if (!ConfigModuleUtility::ValidateName(moduleName)) {
|
if (!ConfigPackageUtility::ValidateName(packageName)) {
|
||||||
response.SetStatus(403, "Forbidden");
|
response.SetStatus(403, "Forbidden");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int code = 200;
|
int code = 200;
|
||||||
String status = "Created module.";
|
String status = "Created package.";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ConfigModuleUtility::CreateModule(moduleName);
|
ConfigPackageUtility::CreatePackage(packageName);
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
code = 501;
|
code = 501;
|
||||||
status = "Error: " + DiagnosticInformation(ex);
|
status = "Error: " + DiagnosticInformation(ex);
|
||||||
@ -90,7 +90,7 @@ void ConfigModulesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& req
|
|||||||
|
|
||||||
Dictionary::Ptr result1 = new Dictionary();
|
Dictionary::Ptr result1 = new Dictionary();
|
||||||
|
|
||||||
result1->Set("module", moduleName);
|
result1->Set("package", packageName);
|
||||||
result1->Set("code", code);
|
result1->Set("code", code);
|
||||||
result1->Set("status", status);
|
result1->Set("status", status);
|
||||||
|
|
||||||
@ -104,25 +104,25 @@ void ConfigModulesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& req
|
|||||||
HttpUtility::SendJsonBody(response, result);
|
HttpUtility::SendJsonBody(response, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigModulesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
void ConfigPackagesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
||||||
{
|
{
|
||||||
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
||||||
|
|
||||||
if (request.RequestUrl->GetPath().size() >= 4)
|
if (request.RequestUrl->GetPath().size() >= 4)
|
||||||
params->Set("module", request.RequestUrl->GetPath()[3]);
|
params->Set("package", request.RequestUrl->GetPath()[3]);
|
||||||
|
|
||||||
String moduleName = HttpUtility::GetLastParameter(params, "module");
|
String packageName = HttpUtility::GetLastParameter(params, "package");
|
||||||
|
|
||||||
if (!ConfigModuleUtility::ValidateName(moduleName)) {
|
if (!ConfigPackageUtility::ValidateName(packageName)) {
|
||||||
response.SetStatus(403, "Forbidden");
|
response.SetStatus(403, "Forbidden");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int code = 200;
|
int code = 200;
|
||||||
String status = "Deleted module.";
|
String status = "Deleted package.";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ConfigModuleUtility::DeleteModule(moduleName);
|
ConfigPackageUtility::DeletePackage(packageName);
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
code = 501;
|
code = 501;
|
||||||
status = "Error: " + DiagnosticInformation(ex);
|
status = "Error: " + DiagnosticInformation(ex);
|
||||||
@ -130,7 +130,7 @@ void ConfigModulesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest& r
|
|||||||
|
|
||||||
Dictionary::Ptr result1 = new Dictionary();
|
Dictionary::Ptr result1 = new Dictionary();
|
||||||
|
|
||||||
result1->Set("module", moduleName);
|
result1->Set("package", packageName);
|
||||||
result1->Set("code", code);
|
result1->Set("code", code);
|
||||||
result1->Set("status", status);
|
result1->Set("status", status);
|
||||||
|
|
@ -25,10 +25,10 @@
|
|||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
class I2_REMOTE_API ConfigModulesHandler : public HttpHandler
|
class I2_REMOTE_API ConfigPackagesHandler : public HttpHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(ConfigModulesHandler);
|
DECLARE_PTR_TYPEDEFS(ConfigPackagesHandler);
|
||||||
|
|
||||||
virtual bool HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response) override;
|
virtual bool HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response) override;
|
||||||
|
|
@ -17,7 +17,7 @@
|
|||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "remote/configmoduleutility.hpp"
|
#include "remote/configpackageutility.hpp"
|
||||||
#include "base/application.hpp"
|
#include "base/application.hpp"
|
||||||
#include "base/exception.hpp"
|
#include "base/exception.hpp"
|
||||||
#include "base/scriptglobal.hpp"
|
#include "base/scriptglobal.hpp"
|
||||||
@ -30,66 +30,66 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
String ConfigModuleUtility::GetModuleDir(void)
|
String ConfigPackageUtility::GetPackageDir(void)
|
||||||
{
|
{
|
||||||
return Application::GetLocalStateDir() + "/lib/icinga2/api/modules";
|
return Application::GetLocalStateDir() + "/lib/icinga2/api/packages";
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigModuleUtility::CreateModule(const String& name)
|
void ConfigPackageUtility::CreatePackage(const String& name)
|
||||||
{
|
{
|
||||||
String path = GetModuleDir() + "/" + name;
|
String path = GetPackageDir() + "/" + name;
|
||||||
|
|
||||||
if (Utility::PathExists(path))
|
if (Utility::PathExists(path))
|
||||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Module already exists."));
|
BOOST_THROW_EXCEPTION(std::invalid_argument("Package already exists."));
|
||||||
|
|
||||||
Utility::MkDirP(path, 0700);
|
Utility::MkDirP(path, 0700);
|
||||||
WriteModuleConfig(name);
|
WritePackageConfig(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigModuleUtility::DeleteModule(const String& name)
|
void ConfigPackageUtility::DeletePackage(const String& name)
|
||||||
{
|
{
|
||||||
String path = GetModuleDir() + "/" + name;
|
String path = GetPackageDir() + "/" + name;
|
||||||
|
|
||||||
if (!Utility::PathExists(path))
|
if (!Utility::PathExists(path))
|
||||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Module does not exist."));
|
BOOST_THROW_EXCEPTION(std::invalid_argument("Package does not exist."));
|
||||||
|
|
||||||
Utility::RemoveDirRecursive(path);
|
Utility::RemoveDirRecursive(path);
|
||||||
Application::RequestRestart();
|
Application::RequestRestart();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<String> ConfigModuleUtility::GetModules(void)
|
std::vector<String> ConfigPackageUtility::GetPackages(void)
|
||||||
{
|
{
|
||||||
std::vector<String> modules;
|
std::vector<String> packages;
|
||||||
Utility::Glob(GetModuleDir() + "/*", boost::bind(&ConfigModuleUtility::CollectDirNames, _1, boost::ref(modules)), GlobDirectory);
|
Utility::Glob(GetPackageDir() + "/*", boost::bind(&ConfigPackageUtility::CollectDirNames, _1, boost::ref(packages)), GlobDirectory);
|
||||||
return modules;
|
return packages;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigModuleUtility::CollectDirNames(const String& path, std::vector<String>& dirs)
|
void ConfigPackageUtility::CollectDirNames(const String& path, std::vector<String>& dirs)
|
||||||
{
|
{
|
||||||
String name = Utility::BaseName(path);
|
String name = Utility::BaseName(path);
|
||||||
dirs.push_back(name);
|
dirs.push_back(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigModuleUtility::ModuleExists(const String& name)
|
bool ConfigPackageUtility::PackageExists(const String& name)
|
||||||
{
|
{
|
||||||
return Utility::PathExists(GetModuleDir() + "/" + name);
|
return Utility::PathExists(GetPackageDir() + "/" + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
String ConfigModuleUtility::CreateStage(const String& moduleName, const Dictionary::Ptr& files)
|
String ConfigPackageUtility::CreateStage(const String& packageName, const Dictionary::Ptr& files)
|
||||||
{
|
{
|
||||||
String stageName = Utility::NewUniqueID();
|
String stageName = Utility::NewUniqueID();
|
||||||
|
|
||||||
String path = GetModuleDir() + "/" + moduleName;
|
String path = GetPackageDir() + "/" + packageName;
|
||||||
|
|
||||||
if (!Utility::PathExists(path))
|
if (!Utility::PathExists(path))
|
||||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Module does not exist."));
|
BOOST_THROW_EXCEPTION(std::invalid_argument("Package does not exist."));
|
||||||
|
|
||||||
path += "/" + stageName;
|
path += "/" + stageName;
|
||||||
|
|
||||||
Utility::MkDirP(path, 0700);
|
Utility::MkDirP(path, 0700);
|
||||||
Utility::MkDirP(path + "/conf.d", 0700);
|
Utility::MkDirP(path + "/conf.d", 0700);
|
||||||
Utility::MkDirP(path + "/zones.d", 0700);
|
Utility::MkDirP(path + "/zones.d", 0700);
|
||||||
WriteStageConfig(moduleName, stageName);
|
WriteStageConfig(packageName, stageName);
|
||||||
|
|
||||||
bool foundDotDot = false;
|
bool foundDotDot = false;
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ String ConfigModuleUtility::CreateStage(const String& moduleName, const Dictiona
|
|||||||
|
|
||||||
String filePath = path + "/" + kv.first;
|
String filePath = path + "/" + kv.first;
|
||||||
|
|
||||||
Log(LogInformation, "ConfigModuleUtility")
|
Log(LogInformation, "ConfigPackageUtility")
|
||||||
<< "Updating configuration file: " << filePath;
|
<< "Updating configuration file: " << filePath;
|
||||||
|
|
||||||
//pass the directory and generate a dir tree, if not existing already
|
//pass the directory and generate a dir tree, if not existing already
|
||||||
@ -122,16 +122,16 @@ String ConfigModuleUtility::CreateStage(const String& moduleName, const Dictiona
|
|||||||
return stageName;
|
return stageName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigModuleUtility::WriteModuleConfig(const String& moduleName)
|
void ConfigPackageUtility::WritePackageConfig(const String& packageName)
|
||||||
{
|
{
|
||||||
String stageName = GetActiveStage(moduleName);
|
String stageName = GetActiveStage(packageName);
|
||||||
|
|
||||||
String includePath = GetModuleDir() + "/" + moduleName + "/include.conf";
|
String includePath = GetPackageDir() + "/" + packageName + "/include.conf";
|
||||||
std::ofstream fpInclude(includePath.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
|
std::ofstream fpInclude(includePath.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
|
||||||
fpInclude << "include \"*/include.conf\"\n";
|
fpInclude << "include \"*/include.conf\"\n";
|
||||||
fpInclude.close();
|
fpInclude.close();
|
||||||
|
|
||||||
String activePath = GetModuleDir() + "/" + moduleName + "/active.conf";
|
String activePath = GetPackageDir() + "/" + packageName + "/active.conf";
|
||||||
std::ofstream fpActive(activePath.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
|
std::ofstream fpActive(activePath.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
|
||||||
fpActive << "if (!globals.contains(\"ActiveStages\")) {\n"
|
fpActive << "if (!globals.contains(\"ActiveStages\")) {\n"
|
||||||
<< " globals.ActiveStages = {}\n"
|
<< " globals.ActiveStages = {}\n"
|
||||||
@ -139,67 +139,67 @@ void ConfigModuleUtility::WriteModuleConfig(const String& moduleName)
|
|||||||
<< "\n"
|
<< "\n"
|
||||||
<< "if (globals.contains(\"ActiveStageOverride\")) {\n"
|
<< "if (globals.contains(\"ActiveStageOverride\")) {\n"
|
||||||
<< " var arr = ActiveStageOverride.split(\":\")\n"
|
<< " var arr = ActiveStageOverride.split(\":\")\n"
|
||||||
<< " if (arr[0] == \"" << moduleName << "\") {\n"
|
<< " if (arr[0] == \"" << packageName << "\") {\n"
|
||||||
<< " if (arr.len() < 2) {\n"
|
<< " if (arr.len() < 2) {\n"
|
||||||
<< " log(LogCritical, \"Config\", \"Invalid value for ActiveStageOverride\")\n"
|
<< " log(LogCritical, \"Config\", \"Invalid value for ActiveStageOverride\")\n"
|
||||||
<< " } else {\n"
|
<< " } else {\n"
|
||||||
<< " ActiveStages[\"" << moduleName << "\"] = arr[1]\n"
|
<< " ActiveStages[\"" << packageName << "\"] = arr[1]\n"
|
||||||
<< " }\n"
|
<< " }\n"
|
||||||
<< " }\n"
|
<< " }\n"
|
||||||
<< "}\n"
|
<< "}\n"
|
||||||
<< "\n"
|
<< "\n"
|
||||||
<< "if (!ActiveStages.contains(\"" << moduleName << "\")) {\n"
|
<< "if (!ActiveStages.contains(\"" << packageName << "\")) {\n"
|
||||||
<< " ActiveStages[\"" << moduleName << "\"] = \"" << stageName << "\"\n"
|
<< " ActiveStages[\"" << packageName << "\"] = \"" << stageName << "\"\n"
|
||||||
<< "}\n";
|
<< "}\n";
|
||||||
fpActive.close();
|
fpActive.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigModuleUtility::WriteStageConfig(const String& moduleName, const String& stageName)
|
void ConfigPackageUtility::WriteStageConfig(const String& packageName, const String& stageName)
|
||||||
{
|
{
|
||||||
String path = GetModuleDir() + "/" + moduleName + "/" + stageName + "/include.conf";
|
String path = GetPackageDir() + "/" + packageName + "/" + stageName + "/include.conf";
|
||||||
std::ofstream fp(path.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
|
std::ofstream fp(path.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
|
||||||
fp << "include \"../active.conf\"\n"
|
fp << "include \"../active.conf\"\n"
|
||||||
<< "if (ActiveStages[\"" << moduleName << "\"] == \"" << stageName << "\") {\n"
|
<< "if (ActiveStages[\"" << packageName << "\"] == \"" << stageName << "\") {\n"
|
||||||
<< " include_recursive \"conf.d\"\n"
|
<< " include_recursive \"conf.d\"\n"
|
||||||
<< " include_zones \"" << moduleName << "\", \"zones.d\"\n"
|
<< " include_zones \"" << packageName << "\", \"zones.d\"\n"
|
||||||
<< "}\n";
|
<< "}\n";
|
||||||
fp.close();
|
fp.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigModuleUtility::ActivateStage(const String& moduleName, const String& stageName)
|
void ConfigPackageUtility::ActivateStage(const String& packageName, const String& stageName)
|
||||||
{
|
{
|
||||||
String activeStagePath = GetModuleDir() + "/" + moduleName + "/active-stage";
|
String activeStagePath = GetPackageDir() + "/" + packageName + "/active-stage";
|
||||||
std::ofstream fpActiveStage(activeStagePath.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
|
std::ofstream fpActiveStage(activeStagePath.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
|
||||||
fpActiveStage << stageName;
|
fpActiveStage << stageName;
|
||||||
fpActiveStage.close();
|
fpActiveStage.close();
|
||||||
|
|
||||||
WriteModuleConfig(moduleName);
|
WritePackageConfig(packageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigModuleUtility::TryActivateStageCallback(const ProcessResult& pr, const String& moduleName, const String& stageName)
|
void ConfigPackageUtility::TryActivateStageCallback(const ProcessResult& pr, const String& packageName, const String& stageName)
|
||||||
{
|
{
|
||||||
String logFile = GetModuleDir() + "/" + moduleName + "/" + stageName + "/startup.log";
|
String logFile = GetPackageDir() + "/" + packageName + "/" + stageName + "/startup.log";
|
||||||
std::ofstream fpLog(logFile.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
|
std::ofstream fpLog(logFile.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
|
||||||
fpLog << pr.Output;
|
fpLog << pr.Output;
|
||||||
fpLog.close();
|
fpLog.close();
|
||||||
|
|
||||||
String statusFile = GetModuleDir() + "/" + moduleName + "/" + stageName + "/status";
|
String statusFile = GetPackageDir() + "/" + packageName + "/" + stageName + "/status";
|
||||||
std::ofstream fpStatus(statusFile.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
|
std::ofstream fpStatus(statusFile.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
|
||||||
fpStatus << pr.ExitStatus;
|
fpStatus << pr.ExitStatus;
|
||||||
fpStatus.close();
|
fpStatus.close();
|
||||||
|
|
||||||
/* validation went fine, activate stage and reload */
|
/* validation went fine, activate stage and reload */
|
||||||
if (pr.ExitStatus == 0) {
|
if (pr.ExitStatus == 0) {
|
||||||
ActivateStage(moduleName, stageName);
|
ActivateStage(packageName, stageName);
|
||||||
Application::RequestRestart();
|
Application::RequestRestart();
|
||||||
} else {
|
} else {
|
||||||
Log(LogCritical, "ConfigModuleUtility")
|
Log(LogCritical, "ConfigPackageUtility")
|
||||||
<< "Config validation failed for module '"
|
<< "Config validation failed for package '"
|
||||||
<< moduleName << "' and stage '" << stageName << "'.";
|
<< packageName << "' and stage '" << stageName << "'.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigModuleUtility::AsyncTryActivateStage(const String& moduleName, const String& stageName)
|
void ConfigPackageUtility::AsyncTryActivateStage(const String& packageName, const String& stageName)
|
||||||
{
|
{
|
||||||
// prepare arguments
|
// prepare arguments
|
||||||
Array::Ptr args = new Array();
|
Array::Ptr args = new Array();
|
||||||
@ -207,36 +207,36 @@ void ConfigModuleUtility::AsyncTryActivateStage(const String& moduleName, const
|
|||||||
args->Add("daemon");
|
args->Add("daemon");
|
||||||
args->Add("--validate");
|
args->Add("--validate");
|
||||||
args->Add("--define");
|
args->Add("--define");
|
||||||
args->Add("ActiveStageOverride=" + moduleName + ":" + stageName);
|
args->Add("ActiveStageOverride=" + packageName + ":" + stageName);
|
||||||
|
|
||||||
Process::Ptr process = new Process(Process::PrepareCommand(args));
|
Process::Ptr process = new Process(Process::PrepareCommand(args));
|
||||||
process->SetTimeout(300);
|
process->SetTimeout(300);
|
||||||
process->Run(boost::bind(&TryActivateStageCallback, _1, moduleName, stageName));
|
process->Run(boost::bind(&TryActivateStageCallback, _1, packageName, stageName));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigModuleUtility::DeleteStage(const String& moduleName, const String& stageName)
|
void ConfigPackageUtility::DeleteStage(const String& packageName, const String& stageName)
|
||||||
{
|
{
|
||||||
String path = GetModuleDir() + "/" + moduleName + "/" + stageName;
|
String path = GetPackageDir() + "/" + packageName + "/" + stageName;
|
||||||
|
|
||||||
if (!Utility::PathExists(path))
|
if (!Utility::PathExists(path))
|
||||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Stage does not exist."));
|
BOOST_THROW_EXCEPTION(std::invalid_argument("Stage does not exist."));
|
||||||
|
|
||||||
if (GetActiveStage(moduleName) == stageName)
|
if (GetActiveStage(packageName) == stageName)
|
||||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Active stage cannot be deleted."));
|
BOOST_THROW_EXCEPTION(std::invalid_argument("Active stage cannot be deleted."));
|
||||||
|
|
||||||
Utility::RemoveDirRecursive(path);
|
Utility::RemoveDirRecursive(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<String> ConfigModuleUtility::GetStages(const String& moduleName)
|
std::vector<String> ConfigPackageUtility::GetStages(const String& packageName)
|
||||||
{
|
{
|
||||||
std::vector<String> stages;
|
std::vector<String> stages;
|
||||||
Utility::Glob(GetModuleDir() + "/" + moduleName + "/*", boost::bind(&ConfigModuleUtility::CollectDirNames, _1, boost::ref(stages)), GlobDirectory);
|
Utility::Glob(GetPackageDir() + "/" + packageName + "/*", boost::bind(&ConfigPackageUtility::CollectDirNames, _1, boost::ref(stages)), GlobDirectory);
|
||||||
return stages;
|
return stages;
|
||||||
}
|
}
|
||||||
|
|
||||||
String ConfigModuleUtility::GetActiveStage(const String& moduleName)
|
String ConfigPackageUtility::GetActiveStage(const String& packageName)
|
||||||
{
|
{
|
||||||
String path = GetModuleDir() + "/" + moduleName + "/active-stage";
|
String path = GetPackageDir() + "/" + packageName + "/active-stage";
|
||||||
|
|
||||||
std::ifstream fp;
|
std::ifstream fp;
|
||||||
fp.open(path.CStr());
|
fp.open(path.CStr());
|
||||||
@ -253,15 +253,15 @@ String ConfigModuleUtility::GetActiveStage(const String& moduleName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<std::pair<String, bool> > ConfigModuleUtility::GetFiles(const String& moduleName, const String& stageName)
|
std::vector<std::pair<String, bool> > ConfigPackageUtility::GetFiles(const String& packageName, const String& stageName)
|
||||||
{
|
{
|
||||||
std::vector<std::pair<String, bool> > paths;
|
std::vector<std::pair<String, bool> > paths;
|
||||||
Utility::GlobRecursive(GetModuleDir() + "/" + moduleName + "/" + stageName, "*", boost::bind(&ConfigModuleUtility::CollectPaths, _1, boost::ref(paths)), GlobDirectory | GlobFile);
|
Utility::GlobRecursive(GetPackageDir() + "/" + packageName + "/" + stageName, "*", boost::bind(&ConfigPackageUtility::CollectPaths, _1, boost::ref(paths)), GlobDirectory | GlobFile);
|
||||||
|
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigModuleUtility::CollectPaths(const String& path, std::vector<std::pair<String, bool> >& paths)
|
void ConfigPackageUtility::CollectPaths(const String& path, std::vector<std::pair<String, bool> >& paths)
|
||||||
{
|
{
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
@ -286,7 +286,7 @@ void ConfigModuleUtility::CollectPaths(const String& path, std::vector<std::pair
|
|||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigModuleUtility::ContainsDotDot(const String& path)
|
bool ConfigPackageUtility::ContainsDotDot(const String& path)
|
||||||
{
|
{
|
||||||
std::vector<String> tokens;
|
std::vector<String> tokens;
|
||||||
boost::algorithm::split(tokens, path, boost::is_any_of("/\\"));
|
boost::algorithm::split(tokens, path, boost::is_any_of("/\\"));
|
||||||
@ -299,7 +299,7 @@ bool ConfigModuleUtility::ContainsDotDot(const String& path)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigModuleUtility::ValidateName(const String& name)
|
bool ConfigPackageUtility::ValidateName(const String& name)
|
||||||
{
|
{
|
||||||
if (name.IsEmpty())
|
if (name.IsEmpty())
|
||||||
return false;
|
return false;
|
@ -35,25 +35,25 @@ namespace icinga
|
|||||||
*
|
*
|
||||||
* @ingroup remote
|
* @ingroup remote
|
||||||
*/
|
*/
|
||||||
class I2_REMOTE_API ConfigModuleUtility
|
class I2_REMOTE_API ConfigPackageUtility
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static String GetModuleDir(void);
|
static String GetPackageDir(void);
|
||||||
|
|
||||||
static void CreateModule(const String& name);
|
static void CreatePackage(const String& name);
|
||||||
static void DeleteModule(const String& name);
|
static void DeletePackage(const String& name);
|
||||||
static std::vector<String> GetModules(void);
|
static std::vector<String> GetPackages(void);
|
||||||
static bool ModuleExists(const String& name);
|
static bool PackageExists(const String& name);
|
||||||
|
|
||||||
static String CreateStage(const String& moduleName, const Dictionary::Ptr& files = Dictionary::Ptr());
|
static String CreateStage(const String& packageName, const Dictionary::Ptr& files = Dictionary::Ptr());
|
||||||
static void DeleteStage(const String& moduleName, const String& stageName);
|
static void DeleteStage(const String& packageName, const String& stageName);
|
||||||
static std::vector<String> GetStages(const String& moduleName);
|
static std::vector<String> GetStages(const String& packageName);
|
||||||
static String GetActiveStage(const String& moduleName);
|
static String GetActiveStage(const String& packageName);
|
||||||
static void ActivateStage(const String& moduleName, const String& stageName);
|
static void ActivateStage(const String& packageName, const String& stageName);
|
||||||
static void AsyncTryActivateStage(const String& moduleName, const String& stageName);
|
static void AsyncTryActivateStage(const String& packageName, const String& stageName);
|
||||||
|
|
||||||
static std::vector<std::pair<String, bool> > GetFiles(const String& moduleName, const String& stageName);
|
static std::vector<std::pair<String, bool> > GetFiles(const String& packageName, const String& stageName);
|
||||||
|
|
||||||
static bool ContainsDotDot(const String& path);
|
static bool ContainsDotDot(const String& path);
|
||||||
static bool ValidateName(const String& name);
|
static bool ValidateName(const String& name);
|
||||||
@ -62,10 +62,10 @@ private:
|
|||||||
static void CollectDirNames(const String& path, std::vector<String>& dirs);
|
static void CollectDirNames(const String& path, std::vector<String>& dirs);
|
||||||
static void CollectPaths(const String& path, std::vector<std::pair<String, bool> >& paths);
|
static void CollectPaths(const String& path, std::vector<std::pair<String, bool> >& paths);
|
||||||
|
|
||||||
static void WriteModuleConfig(const String& moduleName);
|
static void WritePackageConfig(const String& packageName);
|
||||||
static void WriteStageConfig(const String& moduleName, const String& stageName);
|
static void WriteStageConfig(const String& packageName, const String& stageName);
|
||||||
|
|
||||||
static void TryActivateStageCallback(const ProcessResult& pr, const String& moduleName, const String& stageName);
|
static void TryActivateStageCallback(const ProcessResult& pr, const String& packageName, const String& stageName);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
@ -18,7 +18,7 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "remote/configstageshandler.hpp"
|
#include "remote/configstageshandler.hpp"
|
||||||
#include "remote/configmoduleutility.hpp"
|
#include "remote/configpackageutility.hpp"
|
||||||
#include "remote/httputility.hpp"
|
#include "remote/httputility.hpp"
|
||||||
#include "base/application.hpp"
|
#include "base/application.hpp"
|
||||||
#include "base/exception.hpp"
|
#include "base/exception.hpp"
|
||||||
@ -50,24 +50,24 @@ void ConfigStagesHandler::HandleGet(const ApiUser::Ptr& user, HttpRequest& reque
|
|||||||
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
||||||
|
|
||||||
if (request.RequestUrl->GetPath().size() >= 4)
|
if (request.RequestUrl->GetPath().size() >= 4)
|
||||||
params->Set("module", request.RequestUrl->GetPath()[3]);
|
params->Set("package", request.RequestUrl->GetPath()[3]);
|
||||||
|
|
||||||
if (request.RequestUrl->GetPath().size() >= 5)
|
if (request.RequestUrl->GetPath().size() >= 5)
|
||||||
params->Set("stage", request.RequestUrl->GetPath()[4]);
|
params->Set("stage", request.RequestUrl->GetPath()[4]);
|
||||||
|
|
||||||
String moduleName = HttpUtility::GetLastParameter(params, "module");
|
String packageName = HttpUtility::GetLastParameter(params, "package");
|
||||||
String stageName = HttpUtility::GetLastParameter(params, "stage");
|
String stageName = HttpUtility::GetLastParameter(params, "stage");
|
||||||
|
|
||||||
if (!ConfigModuleUtility::ValidateName(moduleName) || !ConfigModuleUtility::ValidateName(stageName)) {
|
if (!ConfigPackageUtility::ValidateName(packageName) || !ConfigPackageUtility::ValidateName(stageName)) {
|
||||||
response.SetStatus(403, "Forbidden");
|
response.SetStatus(403, "Forbidden");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Array::Ptr results = new Array();
|
Array::Ptr results = new Array();
|
||||||
|
|
||||||
std::vector<std::pair<String, bool> > paths = ConfigModuleUtility::GetFiles(moduleName, stageName);
|
std::vector<std::pair<String, bool> > paths = ConfigPackageUtility::GetFiles(packageName, stageName);
|
||||||
|
|
||||||
String prefixPath = ConfigModuleUtility::GetModuleDir() + "/" + moduleName + "/" + stageName + "/";
|
String prefixPath = ConfigPackageUtility::GetPackageDir() + "/" + packageName + "/" + stageName + "/";
|
||||||
|
|
||||||
typedef std::pair<String, bool> kv_pair;
|
typedef std::pair<String, bool> kv_pair;
|
||||||
BOOST_FOREACH(const kv_pair& kv, paths) {
|
BOOST_FOREACH(const kv_pair& kv, paths) {
|
||||||
@ -89,11 +89,11 @@ void ConfigStagesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& requ
|
|||||||
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
||||||
|
|
||||||
if (request.RequestUrl->GetPath().size() >= 4)
|
if (request.RequestUrl->GetPath().size() >= 4)
|
||||||
params->Set("module", request.RequestUrl->GetPath()[3]);
|
params->Set("package", request.RequestUrl->GetPath()[3]);
|
||||||
|
|
||||||
String moduleName = HttpUtility::GetLastParameter(params, "module");
|
String packageName = HttpUtility::GetLastParameter(params, "package");
|
||||||
|
|
||||||
if (!ConfigModuleUtility::ValidateName(moduleName)) {
|
if (!ConfigPackageUtility::ValidateName(packageName)) {
|
||||||
response.SetStatus(403, "Forbidden");
|
response.SetStatus(403, "Forbidden");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -108,10 +108,10 @@ void ConfigStagesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& requ
|
|||||||
if (!files)
|
if (!files)
|
||||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Parameter 'files' must be specified."));
|
BOOST_THROW_EXCEPTION(std::invalid_argument("Parameter 'files' must be specified."));
|
||||||
|
|
||||||
stageName = ConfigModuleUtility::CreateStage(moduleName, files);
|
stageName = ConfigPackageUtility::CreateStage(packageName, files);
|
||||||
|
|
||||||
/* validate the config. on success, activate stage and reload */
|
/* validate the config. on success, activate stage and reload */
|
||||||
ConfigModuleUtility::AsyncTryActivateStage(moduleName, stageName);
|
ConfigPackageUtility::AsyncTryActivateStage(packageName, stageName);
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
code = 501;
|
code = 501;
|
||||||
status = "Error: " + DiagnosticInformation(ex);
|
status = "Error: " + DiagnosticInformation(ex);
|
||||||
@ -119,7 +119,7 @@ void ConfigStagesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& requ
|
|||||||
|
|
||||||
Dictionary::Ptr result1 = new Dictionary();
|
Dictionary::Ptr result1 = new Dictionary();
|
||||||
|
|
||||||
result1->Set("module", moduleName);
|
result1->Set("package", packageName);
|
||||||
result1->Set("stage", stageName);
|
result1->Set("stage", stageName);
|
||||||
result1->Set("code", code);
|
result1->Set("code", code);
|
||||||
result1->Set("status", status);
|
result1->Set("status", status);
|
||||||
@ -139,15 +139,15 @@ void ConfigStagesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest& re
|
|||||||
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
||||||
|
|
||||||
if (request.RequestUrl->GetPath().size() >= 4)
|
if (request.RequestUrl->GetPath().size() >= 4)
|
||||||
params->Set("module", request.RequestUrl->GetPath()[3]);
|
params->Set("package", request.RequestUrl->GetPath()[3]);
|
||||||
|
|
||||||
if (request.RequestUrl->GetPath().size() >= 5)
|
if (request.RequestUrl->GetPath().size() >= 5)
|
||||||
params->Set("stage", request.RequestUrl->GetPath()[4]);
|
params->Set("stage", request.RequestUrl->GetPath()[4]);
|
||||||
|
|
||||||
String moduleName = HttpUtility::GetLastParameter(params, "module");
|
String packageName = HttpUtility::GetLastParameter(params, "package");
|
||||||
String stageName = HttpUtility::GetLastParameter(params, "stage");
|
String stageName = HttpUtility::GetLastParameter(params, "stage");
|
||||||
|
|
||||||
if (!ConfigModuleUtility::ValidateName(moduleName) || !ConfigModuleUtility::ValidateName(stageName)) {
|
if (!ConfigPackageUtility::ValidateName(packageName) || !ConfigPackageUtility::ValidateName(stageName)) {
|
||||||
response.SetStatus(403, "Forbidden");
|
response.SetStatus(403, "Forbidden");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ void ConfigStagesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest& re
|
|||||||
String status = "Deleted stage.";
|
String status = "Deleted stage.";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ConfigModuleUtility::DeleteStage(moduleName, stageName);
|
ConfigPackageUtility::DeleteStage(packageName, stageName);
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
code = 501;
|
code = 501;
|
||||||
status = "Error: " + DiagnosticInformation(ex);
|
status = "Error: " + DiagnosticInformation(ex);
|
||||||
@ -164,7 +164,7 @@ void ConfigStagesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest& re
|
|||||||
|
|
||||||
Dictionary::Ptr result1 = new Dictionary();
|
Dictionary::Ptr result1 = new Dictionary();
|
||||||
|
|
||||||
result1->Set("module", moduleName);
|
result1->Set("package", packageName);
|
||||||
result1->Set("stage", stageName);
|
result1->Set("stage", stageName);
|
||||||
result1->Set("code", code);
|
result1->Set("code", code);
|
||||||
result1->Set("status", status);
|
result1->Set("status", status);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user