mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
New class: bizSubnet, implementing a dedicated view for IP management
SVN:trunk[147]
This commit is contained in:
@@ -980,6 +980,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
setup/data/21.subnets.xml
Normal file
11
setup/data/21.subnets.xml
Normal file
@@ -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>
|
||||
@@ -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"
|
||||
|
||||
@@ -155,7 +155,26 @@
|
||||
<p></p>
|
||||
<p style="text-align:center; font-family:Georgia, 'Times New Roman', Times, serif; font-size:24px;">All Servers</p>
|
||||
<p></p>
|
||||
<itopblock BlockClass="DisplayBlock" objectclass="bizContact" type="list" asynchronous="false" encoding="text/sibusql">bizServer</itopblock>
|
||||
<itopblock BlockClass="DisplayBlock" objectclass="bizServer" type="list" asynchronous="false" encoding="text/sibusql">bizServer</itopblock>
|
||||
</div>
|
||||
</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><itopblock BlockClass="DisplayBlock" objectclass="bizSubnet" type="search" asynchronous="false" encoding="text/sibusql">bizSubnet</itopblock>
|
||||
<div id="BottomPane">
|
||||
<p></p>
|
||||
<p></p>
|
||||
<p style="text-align:center; font-family:Georgia, 'Times New Roman', Times, serif; font-size:24px;">All Subnets</p>
|
||||
<p></p>
|
||||
<itopblock BlockClass="DisplayBlock" objectclass="bizSubnet" type="list" asynchronous="false" encoding="text/sibusql">bizSubnet</itopblock>
|
||||
</div>
|
||||
</template>
|
||||
<type>application</type>
|
||||
|
||||
Reference in New Issue
Block a user