[-]
[+]
|
Changed |
_service:set_version:inventory-system.spec
|
|
[-]
[+]
|
Changed |
inventory-system.spec
^
|
|
[-]
[+]
|
Deleted |
_service:recompress:tar_scm:inventory-system-0.0.rev1828.tar.bz2/server/get_dhcp.php
^
|
@@ -1,63 +0,0 @@
-#!/usr/bin/php
-<?php
-/*
-// isdf - dhcp generator
-// Author: Carsten Schoene
-//
-// $LastChangedDate: 2012-09-15 19:44:43 +0200 (Sat, 15 Sep 2012) $
-// $Rev: 1827 $
-*/
-
-// define our name
-define('MYNAME', "isdf");
-// open syslog connection
-openlog(MYNAME,LOG_PID | LOG_ODELAY,LOG_MAIL);
-
-// check for required extensions
-if ( ! extension_loaded("mysql") ) {
- if ( ! dl("mysql") ) {
- syslog(LOG_ERR,"mysql extension not loaded!");
- exit;
- }
-}
-
-// load additional files
-define('BASE',dirname(__FILE__));
-require_once("MDB2.php");
-require_once(BASE . "/config.inc.php");
-require_once(BASE . "/config-custom.inc.php");
-require_once(BASE . "/db.inc.php");
-require_once(BASE . "/inet4.class.php");
-require_once(BASE . "/inv-dhcp4.class.php");
-require_once(BASE . "/dhcpconf.class.php");
-
-// create database connection
-$dbh =& MDB2::singleton($config['isdf']['db'], $config['mdb2']['options'] );
-
-// create inv-dhcp4 object
-$idhcp4 = new inv_dhcp4();
-
-$qrybkvm="SELECT value FROM inv_system_properties WHERE inv_system_id=(SELECT inv_system_id FROM inv_system_properties WHERE datakey='get_system_type_ix' and value='baremetal-kvm') AND datakey='get_system_net_info';";
-
-$dhcpmacs = array();
-
-$res = $dbh->query($qrybkvm);
-if (PEAR::isError($res)) {
- syslog(LOG_ERR, "MDB2: " . $res->getMessage());
-} else {
- while (( $row = $res->fetchRow(MDB2_FETCHMODE_ASSOC) )) {
- // each result is interface list with values of mac,interface,linkstatus
- $intlist = preg_split('/\s/',$row['value']);
- foreach ( $intlist as $macintlink ) {
- list($mac,$int,$link) = explode(",", trim($macintlink));
- if ($idhcp4->int_is_valid($mac,$int,$link)) {
- // create dhcp entry - push to array
- array_push($dhcpmacs, $mac);
- }
- }
-
-
- }
-}
-
-print_r($dhcpmacs);
|
[-]
[+]
|
Changed |
_service:recompress:tar_scm:inventory-system-0.0.rev1844.tar.bz2/server/config-custom.inc.php
^
|
@@ -13,4 +13,16 @@
$config["isdf"]["dhcp"]["systemmgmt"]["net6"] = "";
$config["isdf"]["dhcp"]["systempxe"]["net6"] = "";
+$config["isdf"]["dhcp"]["system"]["hostnameprefix"] = "sys-";
+$config["isdf"]["dhcp"]["systemmgmt"]["hostnameprefix"] = "mgmt-";
+$config["isdf"]["dhcp"]["systempxe"]["hostnameprefix"] = "pxe-";
+
+$config["isdf"]["dhcp"]["system"]["net4file"] = "/etc/dhcp3/conf.d/system4.hosts";
+$config["isdf"]["dhcp"]["systemmgmt"]["net4file"] = "/etc/dhcp3/conf.d/systemmgmt4.hosts";
+$config["isdf"]["dhcp"]["systempxe"]["net4file"] = "/etc/dhcp3/conf.d/systempxe4.hosts";
+
+$config["isdf"]["dhcp"]["system"]["net6file"] = "/etc/dhcp3/conf.d/system6.hosts";
+$config["isdf"]["dhcp"]["systemmgmt"]["net6file"] = "/etc/dhcp3/conf.d/systemmgmt6.hosts";
+$config["isdf"]["dhcp"]["systempxe"]["net6file"] = "/etc/dhcp3/conf.d/systempxe6.hosts";
+
?>
|
[-]
[+]
|
Added |
_service:recompress:tar_scm:inventory-system-0.0.rev1844.tar.bz2/server/create_dhcp_configs.php
^
|
@@ -0,0 +1,170 @@
+#!/usr/bin/php
+<?php
+/*
+// isdf - dhcp generator
+// Author: Carsten Schoene
+//
+// $LastChangedDate: 2012-09-17 19:24:23 +0200 (Mon, 17 Sep 2012) $
+// $Rev: 1844 $
+*/
+
+// define our name
+define('MYNAME', "create_dhcp_configs");
+// open syslog connection
+openlog(MYNAME,LOG_PID | LOG_ODELAY,LOG_MAIL);
+
+// check for required extensions
+if ( ! extension_loaded("mysql") ) {
+ if ( ! dl("mysql") ) {
+ syslog(LOG_ERR,"mysql extension not loaded!");
+ exit;
+ }
+}
+
+// load additional files
+define('BASE',dirname(__FILE__));
+require_once("MDB2.php");
+require_once(BASE . "/config.inc.php");
+require_once(BASE . "/config-custom.inc.php");
+require_once(BASE . "/db.inc.php");
+require_once(BASE . "/inet4.class.php");
+require_once(BASE . "/inv-dhcp4.class.php");
+require_once(BASE . "/dhcpconf.class.php");
+
+// create database connection
+$dbh =& MDB2::singleton($config['isdf']['db'], $config['mdb2']['options'] );
+
+// create inv-dhcp4 object
+$idhcp4 = new inv_dhcp4();
+
+// create dhcpconf objects
+if ( is_file($config["isdf"]["dhcp"]["system"]["net4file"])) {
+ $dhcpsystem = new dhcpconf($config["isdf"]["dhcp"]["system"]["net4file"]);
+} else {
+ die("File " . $config["isdf"]["dhcp"]["system"]["net4file"] . " not found!");
+}
+if ( is_file($config["isdf"]["dhcp"]["systemmgmt"]["net4file"])) {
+ $dhcpsystemmgmt = new dhcpconf($config["isdf"]["dhcp"]["systemmgmt"]["net4file"]);
+} else {
+ die("File " . $config["isdf"]["dhcp"]["systemmgmt"]["net4file"] . " not found!");
+}
+if ( is_file($config["isdf"]["dhcp"]["systempxe"]["net4file"])) {
+ $dhcpsystempxe = new dhcpconf($config["isdf"]["dhcp"]["systempxe"]["net4file"]);
+} else {
+ die("File " . $config["isdf"]["dhcp"]["systempxe"]["net4file"] . " not found!");
+}
+
+// create inet4 objects
+$systemaddr = explode("/", $config["isdf"]["dhcp"]["system"]["net4"]);
+$systeminet4 = new IPv4($systemaddr[0], $systemaddr[1]);
+$pxeaddr = explode("/", $config["isdf"]["dhcp"]["systempxe"]["net4"]);
+$pxeinet4 = new IPv4($pxeaddr[0], $pxeaddr[1]);
+
+$systemend = $systeminet4->broadcast();
+$pxeend = $pxeinet4->broadcast();
+
+// create dhcp entry for host & pxe
+$qrybkvm="SELECT value FROM inv_system_properties WHERE inv_system_id=(SELECT inv_system_id FROM inv_system_properties WHERE datakey='get_system_type_ix' and value='baremetal-kvm') AND datakey='get_system_net_info';";
+
+$dhcpmacs = array();
+
+$res = $dbh->query($qrybkvm);
+if (PEAR::isError($res)) {
+ syslog(LOG_ERR, "MDB2: " . $res->getMessage());
+} else {
+ while (( $row = $res->fetchRow(MDB2_FETCHMODE_ASSOC) )) {
+ // each result is interface list with values of mac,interface,linkstatus
+ $intlist = preg_split('/\s/',$row['value']);
+ foreach ( $intlist as $macintlink ) {
+ list($mac,$int,$link) = explode(",", trim($macintlink));
+ if ($idhcp4->int_is_valid($mac,$int,$link)) {
+ // create dhcp entry - push to array
+ array_push($dhcpmacs, $mac);
+ }
+ }
+ }
+}
+//print_r($dhcpmacs);
+foreach ( $dhcpmacs as $mac ) {
+ $retval="";
+ //echo "Working on MAC: $mac \n";
+ $systemfirst = $config["isdf"]["dhcp"]["system"]["firstusable"];
+ if ( $systeminet4->isipin($systemfirst) ) {
+ $revhost = $config["isdf"]["dhcp"]["system"]["hostnameprefix"] . preg_replace('/\./','-', $systemfirst);
+ //echo " first try on with: $revhost\n";
+ while ( !($retval = $dhcpsystem->hostExists($revhost,$mac)) === false ) {
+ //echo "Retval: $retval\n";
+ if ( $retval == 2 ) {
+ // mac exists
+ //echo " mac address found in config\n";
+ break 2;
+ } elseif ( $retval == 1 ) {
+ // hostname/ip exists
+ //echo " another try with: $revhost\n";
+ $systemfirst = $systeminet4->increment($systemfirst,$systemend);
+ $revhost = $config["isdf"]["dhcp"]["system"]["hostnameprefix"] . preg_replace('/\./', '-', $systemfirst);
+ }
+ }
+ //echo " while loop ended with: $revhost\n";
+ $dhcpsystem->addHost($revhost,$mac,$systemfirst);
+ }
+}
+foreach ( $dhcpmacs as $mac ) {
+ $retval="";
+ $pxefirst = $config["isdf"]["dhcp"]["systempxe"]["firstusable"];
+ if ( $pxeinet4->isipin($pxefirst) ) {
+ $revhost = $config["isdf"]["dhcp"]["systempxe"]["hostnameprefix"] . preg_replace('/\./','-', $pxefirst);
+ while ( !($retval = $dhcpsystempxe->hostExists($revhost,$mac)) === false ) {
+ if ( $retval == 2 ) {
+ break 2;
+ } elseif ( $retval == 1 ) {
+ $pxefirst = $pxeinet4->increment($pxefirst,$pxeend);
+ $revhost = $config["isdf"]["dhcp"]["systempxe"]["hostnameprefix"] . preg_replace('/\./', '-', $pxefirst);
+ }
+ }
+ $dhcpsystempxe->addHost($revhost,$mac,$pxefirst);
+ }
+}
+
+
+
+// create dhcp entry for mgmt
+$qrymgmtbkvm = "SELECT value FROM inv_system_properties WHERE datakey LIKE 'get_system_mgmt_mac' AND inv_system_id=(SELECT inv_system_id FROM inv_system_properties WHERE datakey='get_system_type_ix' AND value='baremetal-kvm');";
+$mgmtaddr = explode("/", $config["isdf"]["dhcp"]["systemmgmt"]["net4"]);
+$mgmtinet4 = new IPv4($mgmtaddr[0], $mgmtaddr[1]);
+$mgmtend = $mgmtinet4->broadcast();
+
+$dhcpmgmtmacs = array();
+
+$res = $dbh->query($qrymgmtbkvm);
+if (PEAR::isError($res)) {
+ syslog(LOG_ERR, "MDB2: " . $res->getMessage());
+} else {
+ while (( $row = $res->fetchRow(MDB2_FETCHMODE_ASSOC) )) {
+ // each result is interface list with values of mac,interface,linkstatus
+ $mac = trim($row['value']);
+ if ($idhcp4->mac_is_valid($mac)) {
+ // create dhcp entry - push to array
+ array_push($dhcpmgmtmacs, $mac);
+ }
+ }
+}
+
+foreach ( $dhcpmgmtmacs as $mac ) {
+ $retval="";
+ $mgmtfirst = $config["isdf"]["dhcp"]["systemmgmt"]["firstusable"];
+ if ( $mgmtinet4->isipin($mgmtfirst) ) {
+ $revhost = $config["isdf"]["dhcp"]["systemmgmt"]["hostnameprefix"] . preg_replace('/\./','-', $mgmtfirst);
+ while ( !($retval = $dhcpsystemmgmt->hostExists($revhost,$mac)) === false ) {
+ if ( $retval == 2 ) {
+ break 2;
+ } elseif ( $retval == 1 ) {
+ $mgmtfirst = $mgmtinet4->increment($mgmtfirst,$mgmtend);
+ $revhost = $config["isdf"]["dhcp"]["systemmgmt"]["hostnameprefix"] . preg_replace('/\./', '-', $mgmtfirst);
+ }
+ }
+ $dhcpsystemmgmt->addHost($revhost,$mac,$mgmtfirst);
+ }
+}
+
+$dbh->disconnect();
|
[-]
[+]
|
Changed |
_service:recompress:tar_scm:inventory-system-0.0.rev1844.tar.bz2/server/dhcpconf.class.php
^
|
@@ -1,6 +1,6 @@
<?php
-// $LastChangedDate: 2012-08-11 16:27:06 +0200 (Sat, 11 Aug 2012) $
-// $Rev: 1692 $
+// $LastChangedDate: 2012-09-17 18:09:05 +0200 (Mon, 17 Sep 2012) $
+// $Rev: 1832 $
class dhcpconf {
var $dhcpdHosts;
@@ -202,10 +202,10 @@
if ( isset($this->hosts) ) {
foreach($this->hosts as $host){
if(strtoupper($hostname) == strtoupper($host["hostname"])){
- $match = true;
+ $match = 1;
}
elseif(strtoupper($mac) == strtoupper($host["mac"])){
- $match = true;
+ $match = 2;
}
if($match)
|
[-]
[+]
|
Changed |
_service:recompress:tar_scm:inventory-system-0.0.rev1844.tar.bz2/server/inet4.class.php
^
|
@@ -1,6 +1,6 @@
<?php
-// $LastChangedDate: 2012-08-12 17:00:15 +0200 (Sun, 12 Aug 2012) $
-// $Rev: 1696 $
+// $LastChangedDate: 2012-09-17 19:12:38 +0200 (Mon, 17 Sep 2012) $
+// $Rev: 1843 $
class IPv4
{
@@ -88,9 +88,9 @@
{
$lnet=ip2long($this->network());
$lip=ip2long($ip);
- $binnet=str_pad( decbin($lnet),32,"0","STR_PAD_LEFT" );
+ $binnet=str_pad( decbin($lnet),32,"0",STR_PAD_LEFT );
$firstpart=substr($binnet,0,$this->mask2cidr($this->netmask()));
- $binip=str_pad( decbin($lip),32,"0","STR_PAD_LEFT" );
+ $binip=str_pad( decbin($lip),32,"0",STR_PAD_LEFT );
$firstip=substr($binip,0,$this->mask2cidr($this->netmask()));
return(strcmp($firstpart,$firstip)==0);
}
|