@@ -4,8 +4,8 @@
// isdf - dhcp generator
// Author: Carsten Schoene
//
-// $LastChangedDate: 2012-09-18 15:27:50 +0200 (Tue, 18 Sep 2012) $
-// $Rev: 1857 $
+// $LastChangedDate: 2012-09-30 19:51:40 +0200 (Sun, 30 Sep 2012) $
+// $Rev: 1884 $
*/
// 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,33 +105,69 @@
}
}
}
-//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";
$reread = true;
while ( !($retval = $dhcpsystem->hostExists($revhost,$mac, $reread)) === false ) {
- //echo "Retval: $retval\n";
if ( $retval == 2 ) {
+ if ( $config["isdf"]["dhcp"]["guacamole"]["createconfig"] ) {
+ $guacamole[$revhost] = $systemfirst;
+ }
// 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;
+ if ( $config["isdf"]["dhcp"]["guacamole"]["createconfig"] ) {
+ $guacamole[$revhost] = $systemfirst;
+ }
} else {
break;
}
}
- //echo " while loop ended with: $revhost\n";
$dhcpsystem->addHost($revhost,$mac,$systemfirst);
+ if ( $config["isdf"]["dhcp"]["guacamole"]["createconfig"] ) {
+ $guacamole[$revhost] = $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 ) {
|