@@ -4,8 +4,8 @@
// isdf - dhcp generator
// Author: Carsten Schoene
//
-// $LastChangedDate: 2012-09-17 21:47:13 +0200 (Mon, 17 Sep 2012) $
-// $Rev: 1850 $
+// $LastChangedDate: 2012-10-01 15:49:50 +0200 (Mon, 01 Oct 2012) $
+// $Rev: 1890 $
*/
// define our name
@@ -38,16 +38,37 @@
$idhcp4 = new inv_dhcp4();
// create dhcpconf objects
+$touchret=false;
+while ( ! file_exists($config["isdf"]["dhcp"]["system"]["net4file"]) && $touchret == false ) {
+ $touchret = touch($config["isdf"]["dhcp"]["system"]["net4file"]);
+ if ( $touchret == false ) {
+ break;
+ }
+}
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!");
}
+$touchret=false;
+while ( ! file_exists($config["isdf"]["dhcp"]["systemmgmt"]["net4file"]) && $touchret == false ) {
+ $touchret = touch($config["isdf"]["dhcp"]["systemmgmt"]["net4file"]);
+ if ( $touchret == false ) {
+ break;
+ }
+}
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!");
}
+$touchret=false;
+while ( ! file_exists($config["isdf"]["dhcp"]["systempxe"]["net4file"]) && $touchret == false ) {
+ $touchret = touch($config["isdf"]["dhcp"]["systempxe"]["net4file"]);
+ if ( $touchret == false ) {
+ break;
+ }
+}
if ( is_file($config["isdf"]["dhcp"]["systempxe"]["net4file"])) {
$dhcpsystempxe = new dhcpconf($config["isdf"]["dhcp"]["systempxe"]["net4file"]);
} else {
@@ -84,44 +105,78 @@
}
}
}
-//print_r($dhcpmacs);
+
+$guacamole = array();
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";
+ $reread = true;
+ if ( $config["isdf"]["dhcp"]["guacamole"]["createconfig"] ) {
+ $guacamole[$revhost] = $systemfirst;
+ }
+ while ( !($retval = $dhcpsystem->hostExists($revhost,$mac, $reread)) === false ) {
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);
+ $reread = false;
} else {
break;
}
}
- //echo " while loop ended with: $revhost\n";
$dhcpsystem->addHost($revhost,$mac,$systemfirst);
}
}
+if ( $config["isdf"]["dhcp"]["guacamole"]["createconfig"] ) {
+ if ( file_exists(dirname($config["isdf"]["dhcp"]["guacamole"]["user-mapping"]))) {
+ $xmlhead = '<user-mapping>
+ <authorize username="internetx" password="bd1d426fa0b9354e3da87fb804fbce31" encoding="md5">' . "\n";
+ $xmlfoot = ' </authorize>
+</user-mapping>' . "\n";
+ if ( isset($config["isdf"]["dhcp"]["guacamole"]["defvncpw"] ) ) {
+ $defpw = $config["isdf"]["dhcp"]["guacamole"]["defvncpw"];
+ } else {
+ $defpw = "guacamole";
+ }
+ if ( isset($config["isdf"]["dhcp"]["guacamole"]["maxvncport"]) ) {
+ $maxvnc = $config["isdf"]["dhcp"]["guacamole"]["maxvncport"];
+ } else {
+ $maxvnc = 5901;
+ }
+ $xmlbody="";
+ foreach ( $guacamole as $hostname => $ipaddress ) {
+ for ( $vncport = 5900 ; $vncport <= $maxvnc ; $vncport++ ) {
+ $xmlbody .= ' <connection name="'. $hostname . '_' . $vncport . '">' . "\n";
+ $xmlbody .= ' <protocol>vnc</protocol>' . "\n";
+ $xmlbody .= ' <param name="hostname">' . $ipaddress . '</param>' . "\n";
+ $xmlbody .= ' <param name="port">' . $vncport . '</param>' . "\n";
+ $xmlbody .= ' <param name="password">' . $defpw . '</param>' . "\n";
+ $xmlbody .= ' </connection>' . "\n";
+ }
+ }
+ if ( file_put_contents($config["isdf"]["dhcp"]["guacamole"]["user-mapping"], $xmlhead . $xmlbody . $xmlfoot) === false ) {
+ echo "writing guacamole config failed!";
+ }
+ }
+}
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 ) {
+ $reread = true;
+ while ( !($retval = $dhcpsystempxe->hostExists($revhost,$mac, $reread)) === false ) {
if ( $retval == 2 ) {
break 2;
} elseif ( $retval == 1 ) {
$pxefirst = $pxeinet4->increment($pxefirst,$pxeend);
$revhost = $config["isdf"]["dhcp"]["systempxe"]["hostnameprefix"] . preg_replace('/\./', '-', $pxefirst);
+ $reread = false;
} else {
break;
}
@@ -160,12 +215,14 @@
$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 ) {
+ $reread = true;
+ while ( !($retval = $dhcpsystemmgmt->hostExists($revhost,$mac,$reread)) === false ) {
if ( $retval == 2 ) {
break 2;
} elseif ( $retval == 1 ) {
$mgmtfirst = $mgmtinet4->increment($mgmtfirst,$mgmtend);
$revhost = $config["isdf"]["dhcp"]["systemmgmt"]["hostnameprefix"] . preg_replace('/\./', '-', $mgmtfirst);
+ $reread = false;
} else {
break;
}
|
@@ -1,6 +1,6 @@
<?php
-// $LastChangedDate: 2012-09-17 18:09:05 +0200 (Mon, 17 Sep 2012) $
-// $Rev: 1832 $
+// $LastChangedDate: 2012-09-18 14:47:51 +0200 (Tue, 18 Sep 2012) $
+// $Rev: 1855 $
class dhcpconf {
var $dhcpdHosts;
@@ -196,18 +196,27 @@
return $found;
}
- public function hostExists($hostname, $mac){
- $this->readHosts();
+ public function hostExists($hostname, $mac, $reread = true ){
+ if ( $reread == true ) {
+ $this->readHosts();
+ }
$match = false;
if ( isset($this->hosts) ) {
foreach($this->hosts as $host){
+ /*
if(strtoupper($hostname) == strtoupper($host["hostname"])){
$match = 1;
}
elseif(strtoupper($mac) == strtoupper($host["mac"])){
$match = 2;
}
-
+ */
+ if ( $hostname == $host["hostname"] ) {
+ $match = 1;
+ }
+ elseif ( $mac == $host["mac"] ) {
+ $match = 2;
+ }
if($match)
break;
}
|