Explorar o código

New class: bizSubnet, implementing a dedicated view for IP management

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@147 a333f486-631f-4898-b8df-5754b55c2be0
romainq %!s(int64=15) %!d(string=hai) anos
pai
achega
6f853b853d

+ 83 - 0
business/itop.business.class.inc.php

@@ -982,6 +982,89 @@ class lnkInterfaces extends cmdbAbstractObject
 
 ////////////////////////////////////////////////////////////////////////////////////
 /**
+* A subnet
+*/
+////////////////////////////////////////////////////////////////////////////////////
+class bizSubnet extends logInfra
+{
+	public static function Init()
+	{
+		$aParams = array
+		(
+			"category" => "bizmodel,searchable",
+			"name" => "Subnet",
+			"description" => "Logical or physical subnet",
+			"key_type" => "",
+			"key_label" => "id",
+			"name_attcode" => "name",
+			"state_attcode" => "",
+			"reconc_keys" => array("org_name", "name"), // inherited attributes
+			"db_table" => "subnets",
+			"db_key_field" => "id",
+			"db_finalclass_field" => "",
+			"display_template" => "",
+		);
+		MetaModel::Init_Params($aParams);
+		MetaModel::Init_InheritAttributes();
+		MetaModel::Init_AddAttribute(new AttributeString("ip", array("label"=>"IP", "description"=>"IP", "allowed_values"=>null, "sql"=>"ip", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
+		MetaModel::Init_AddAttribute(new AttributeString("mask", array("label"=>"IP mask", "description"=>"IP mask", "allowed_values"=>null, "sql"=>"mask", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
+
+		MetaModel::Init_InheritFilters();
+		MetaModel::Init_AddFilterFromAttribute("ip");
+		MetaModel::Init_AddFilterFromAttribute("mask");
+
+		// Display lists
+		MetaModel::Init_SetZListItems('details', array('name', 'ip','mask')); // Attributes to be displayed for the complete details
+		MetaModel::Init_SetZListItems('list', array('name', 'ip', 'mask')); // Attributes to be displayed for a list
+		// Search criteria
+		MetaModel::Init_SetZListItems('standard_search', array('name', 'ip','mask')); // Criteria of the std search form
+		MetaModel::Init_SetZListItems('advanced_search', array('name', 'ip','mask')); // Criteria of the advanced search form
+	}
+
+	function DisplayBareRelations(web_page $oPage)
+	{
+		parent::DisplayBareRelations($oPage);
+
+		$oPage->SetCurrentTabContainer('Related Objects');
+
+		$oPage->SetCurrentTab('IP Usage');
+
+		$bit_ip = ip2long($this->Get('ip'));
+		$bit_mask = ip2long($this->Get('mask'));
+		$sIPMin = long2ip($bit_ip & $bit_mask);
+		$sIPMax = long2ip(($bit_ip | (~$bit_mask)) - 1);
+
+		$oPage->p("Interfaces having an IP in the range: <em>$sIPMin</em> to <em>$sIPMax</em>");
+		
+		$oIfSet = new CMDBObjectSet(DBObjectSearch::FromOQL("SELECT bizInterface AS if WHERE INET_ATON(if.ip_address) >= INET_ATON('$sIPMin') AND INET_ATON(if.ip_address) <= INET_ATON('$sIPMax')"));
+		self::DisplaySet($oPage, $oIfSet);
+
+		$iCountUsed = $oIfSet->Count();
+		$iCountRange = ip2long($sIPMax) - ip2long($sIPMin);
+		$iFreeCount =  $iCountRange - $iCountUsed;
+
+		$oPage->SetCurrentTab('Free IPs');
+		$oPage->p("Free IPs: $iFreeCount");
+		$oPage->p("Here is an extract of 10 free IP addresses");
+
+		$aUsedIPs = $oIfSet->GetColumnAsArray('ip_address', false);
+		$i = 0;
+		while ($i < min($iFreeCount, 10))
+		{
+			$i++;
+
+			$iAnIP = ip2long($sIPMin) + $i;
+			if (in_array($iAnIP, $aUsedIPs)) continue;
+
+			$sAnIP = long2ip($iAnIP);
+			$oPage->p($sAnIP);
+		}
+		
+	}
+}
+
+////////////////////////////////////////////////////////////////////////////////////
+/**
 * Any electronic device
 */
 ////////////////////////////////////////////////////////////////////////////////////

+ 11 - 0
setup/data/21.subnets.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Set>
+<bizSubnet id="500">
+<org_id>3</org_id>
+<name>my subnet</name>
+<status>implementation</status>
+<criticity>low</criticity>
+<ip>10.22.0.0</ip>
+<mask>255.255.0.0</mask>
+</bizSubnet>
+</Set>

+ 1 - 0
setup/data/export.cmd

@@ -26,3 +26,4 @@ wget --output-document=17.contactchangetickets.xml --post-data="auth_user=%USER%
 wget --output-document=18.contracts.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT bizContract&format=xml"
 wget --output-document=19.infracontracts.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT lnkInfraContract&format=xml"
 wget --output-document=20.contactcontracts.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT lnkContactContract&format=xml"
+wget --output-document=21.subnets.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT bizSubnet&format=xml"

+ 20 - 1
setup/data/structure/1.menus.xml

@@ -155,7 +155,26 @@
 &lt;p&gt;&lt;/p&gt;
 &lt;p style=&quot;text-align:center; font-family:Georgia, &apos;Times New Roman&apos;, Times, serif; font-size:24px;&quot;&gt;All Servers&lt;/p&gt;
 &lt;p&gt;&lt;/p&gt;
-&lt;itopblock BlockClass=&quot;DisplayBlock&quot; objectclass=&quot;bizContact&quot; type=&quot;list&quot; asynchronous=&quot;false&quot; encoding=&quot;text/sibusql&quot;&gt;bizServer&lt;/itopblock&gt;
+&lt;itopblock BlockClass=&quot;DisplayBlock&quot; objectclass=&quot;bizServer&quot; type=&quot;list&quot; asynchronous=&quot;false&quot; encoding=&quot;text/sibusql&quot;&gt;bizServer&lt;/itopblock&gt;
+&lt;/div&gt;
+</template>
+<type>application</type>
+<rank>999</rank>
+<parent_id>14</parent_id>
+<user_id>0</user_id>
+</menuNode>
+<menuNode id="90">
+<name>All Subnets</name>
+<label>All subnets</label>
+<hyperlink>UI.php</hyperlink>
+<icon_path></icon_path>
+<template>&lt;itopblock BlockClass=&quot;DisplayBlock&quot; objectclass=&quot;bizSubnet&quot; type=&quot;search&quot; asynchronous=&quot;false&quot; encoding=&quot;text/sibusql&quot;&gt;bizSubnet&lt;/itopblock&gt;
+&lt;div id=&quot;BottomPane&quot;&gt;
+&lt;p&gt;&lt;/p&gt;
+&lt;p&gt;&lt;/p&gt;
+&lt;p style=&quot;text-align:center; font-family:Georgia, &apos;Times New Roman&apos;, Times, serif; font-size:24px;&quot;&gt;All Subnets&lt;/p&gt;
+&lt;p&gt;&lt;/p&gt;
+&lt;itopblock BlockClass=&quot;DisplayBlock&quot; objectclass=&quot;bizSubnet&quot; type=&quot;list&quot; asynchronous=&quot;false&quot; encoding=&quot;text/sibusql&quot;&gt;bizSubnet&lt;/itopblock&gt;
 &lt;/div&gt;
 </template>
 <type>application</type>