2014-04-25 14:33:45 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
|
|
|
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
|
|
|
* *
|
|
|
|
* 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-03 20:02:22 +02:00
|
|
|
#include "remote/zone.h"
|
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-05-03 20:02:22 +02:00
|
|
|
BOOST_FOREACH(const String& endpoint, GetEndpointsRaw())
|
|
|
|
result.insert(Endpoint::GetByName(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
|
2014-05-08 13:29:53 +02:00
|
|
|
object_zone = Zone::GetByName(object->GetZone());
|
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-05-13 15:57:02 +02:00
|
|
|
return object_zone->IsChildOf(GetSelf());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Zone::IsChildOf(const Zone::Ptr& zone)
|
|
|
|
{
|
|
|
|
Zone::Ptr azone = GetSelf();
|
|
|
|
|
|
|
|
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-05-03 20:02:22 +02:00
|
|
|
Zone::Ptr Zone::GetLocalZone(void)
|
2014-04-25 14:33:45 +02:00
|
|
|
{
|
2014-05-03 20:02:22 +02:00
|
|
|
return Endpoint::GetLocalEndpoint()->GetZone();
|
2014-04-25 14:33:45 +02:00
|
|
|
}
|