2014-04-25 14:33:45 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2015-01-22 12:00:23 +01:00
|
|
|
* Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org) *
|
2014-04-25 14:33:45 +02:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "remote/zone.hpp"
|
2015-03-28 11:04:42 +01:00
|
|
|
#include "remote/zone.tcpp"
|
2014-11-08 21:17:16 +01:00
|
|
|
#include "remote/apiclient.hpp"
|
2014-06-06 13:30:06 +02:00
|
|
|
#include "base/objectlock.hpp"
|
2014-05-11 17:14:35 +02:00
|
|
|
#include <boost/foreach.hpp>
|
2014-04-25 14:33:45 +02:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
REGISTER_TYPE(Zone);
|
|
|
|
|
|
|
|
Zone::Ptr Zone::GetParent(void) const
|
2014-04-25 14:33:45 +02:00
|
|
|
{
|
2014-05-03 20:02:22 +02:00
|
|
|
return Zone::GetByName(GetParentRaw());
|
2014-04-25 14:33:45 +02:00
|
|
|
}
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
std::set<Endpoint::Ptr> Zone::GetEndpoints(void) const
|
2014-04-25 14:33:45 +02:00
|
|
|
{
|
2014-05-03 20:02:22 +02:00
|
|
|
std::set<Endpoint::Ptr> result;
|
2014-04-25 14:33:45 +02:00
|
|
|
|
2014-06-06 13:30:06 +02:00
|
|
|
Array::Ptr endpoints = GetEndpointsRaw();
|
|
|
|
|
|
|
|
if (endpoints) {
|
|
|
|
ObjectLock olock(endpoints);
|
|
|
|
|
|
|
|
BOOST_FOREACH(const String& name, endpoints) {
|
|
|
|
Endpoint::Ptr endpoint = Endpoint::GetByName(name);
|
|
|
|
|
|
|
|
if (!endpoint)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
result.insert(endpoint);
|
|
|
|
}
|
|
|
|
}
|
2014-04-25 14:33:45 +02:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
return result;
|
2014-04-25 14:33:45 +02:00
|
|
|
}
|
|
|
|
|
2014-05-13 15:57:02 +02:00
|
|
|
bool Zone::CanAccessObject(const DynamicObject::Ptr& object)
|
2014-04-25 14:33:45 +02:00
|
|
|
{
|
2014-05-03 20:02:22 +02:00
|
|
|
Zone::Ptr object_zone;
|
|
|
|
|
|
|
|
if (dynamic_pointer_cast<Zone>(object))
|
|
|
|
object_zone = static_pointer_cast<Zone>(object);
|
2014-04-25 14:33:45 +02:00
|
|
|
else
|
2015-02-09 08:50:17 +01:00
|
|
|
object_zone = Zone::GetByName(object->GetZoneName());
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
if (!object_zone)
|
2014-05-08 12:36:48 +02:00
|
|
|
object_zone = Zone::GetLocalZone();
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
return object_zone->IsChildOf(this);
|
2014-05-13 15:57:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Zone::IsChildOf(const Zone::Ptr& zone)
|
|
|
|
{
|
2014-11-08 21:17:16 +01:00
|
|
|
Zone::Ptr azone = this;
|
2014-05-13 15:57:02 +02:00
|
|
|
|
|
|
|
while (azone) {
|
|
|
|
if (azone == zone)
|
2014-05-03 20:02:22 +02:00
|
|
|
return true;
|
|
|
|
|
2014-05-13 15:57:02 +02:00
|
|
|
azone = azone->GetParent();
|
2014-05-03 20:02:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2014-04-25 14:33:45 +02:00
|
|
|
}
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
bool Zone::IsGlobal(void) const
|
2014-06-12 14:31:07 +02:00
|
|
|
{
|
2014-11-08 22:57:09 +01:00
|
|
|
return GetGlobal();
|
2014-06-12 14:31:07 +02:00
|
|
|
}
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
Zone::Ptr Zone::GetLocalZone(void)
|
2014-04-25 14:33:45 +02:00
|
|
|
{
|
2014-05-22 23:01:15 +02:00
|
|
|
Endpoint::Ptr local = Endpoint::GetLocalEndpoint();
|
|
|
|
|
|
|
|
if (!local)
|
|
|
|
return Zone::Ptr();
|
|
|
|
|
|
|
|
return local->GetZone();
|
2014-04-25 14:33:45 +02:00
|
|
|
}
|