Revision 165 | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed
<?php//$Id: load.php 166 2011-07-10 19:08:10Z lars $/*** @package openvz_admin* @author Lars Tiefland <ltiefland@gmail.com>**/require ( "include/common.php" );$hns = HN::getHNs();unset( $hns[-1] );foreach ( $hns as $hn_id => $hn_name ){$configs = load_configs( $hn_id, $hn_name );foreach ( $configs as $conf_id => $config ){$cfg = read_config( $hn_id, $hn_name, $config );update_db( $hn_id, $cfg );}}function load_configs( $hn_id, $hn_name ){unset( $out );$cmd = "ping $hn_name -w1";exec( $cmd, $out, $ret );if ( ! $ret ){echo "Hole Konfigurationen von $hn_name\n";unset( $out );$cmd = "ssh root@$hn_name ls /etc/vz/conf/*.conf";exec( $cmd, $out, $ret );if ( $ret ){trigger_error( "Konnte Konfigurationen nicht holen! Ist dies wirklich ein Virtuozzo / openvz-Server?",E_USER_ERROR );}return $out;}}function read_config( $hn_id, $hn_name, $config ){$config = basename( $config );$cmd = "scp root@$hn_name:/etc/vz/conf/$config cfgs/$hn_id";exec( $cmd, $out, $ret );$conf = file( "cfgs/$hn_id/$config" );$conf[] = "v_id=\"" . substr( $config, 0, strpos( $config, '.' ) ) . "\"";foreach ( $conf as $value ){if ( $value ){$value = rtrim( $value );if ( $value[0] == " " || $value[0] == "#" ){continue;}$cfg_v = explode( "=", $value );$cfg_val[$cfg_v[0]] = trim( $cfg_v[1], '"' );}else{continue;}}$cfgs[] = $cfg_val;return $cfgs;}function update_db( $hn_id, $cfgs ){global $db;foreach ( $cfgs as $config ){if ( isset( $config["DISTRIBUTION"] ) ){$dist_name = $config["DISTRIBUTION"];}else{if ( in_array( $hn_id, array( 1, 3 ) ) ){$dist_name = "gentoo";}else{$dist_name = "centos";}}$sql = "SELECT*FROMdistributionsWHEREdist_name='$dist_name'";$res = $db->query( $sql );if ( ! PEAR::isError( $res ) ){if ( $res->numRows() ){$row = $res->fetchRow();$dist_id = $row["dist_id"];$sql_v = "SELECTv_dist,dist_nameFROMdistributions,vserversWHEREv_id=" . $config["v_id"] . "ANDdist_id=v_dist";$res_v = $db->query( $sql_v );if ( PEAR::isError( $res_v ) ){die( $res_v->getUserInfo() );}$row_v = $res_v->fetchRow();$dist_name = $row_v["dist_name"];if ( $dist_name != $config["DISTRIBUTION"] ){$sql = "UPDATEvserversSETv_dist=$dist_idWHEREv_id=" . $config["v_id"] . "";$res = $db->query( $sql );if ( PEAR::isError( $res ) ){die( $res->getUserInfo() );}}}else{$sql = "INSERT INTOdistributions(dist_name,dist_template)VALUES('" . $config["DISTRIBUTION"] . "','" . $config["OSTEMPLATE"] . "')";$res = $db->query( $sql );$dist_id = $db->lastinsertID();}}else{die( $res->getUserInfo() );}$sql = "SELECT*FROMvserversWHEREv_id=" . $config["v_id"] . "ANDhn_id=$hn_id";$res = $db->query( $sql );if ( ! PEAR::isError( $res ) ){if ( ! $res->numRows() ){$sql = "INSERT INTOvservers(v_id,v_name,v_dist,hn_id)VALUES(" . $config["v_id"] . ",'" . $config["HOSTNAME"] . "',$dist_id,$hn_id)";$res = $db->query( $sql );if ( PEAR::isError( $res ) ){die( $res->getUserInfo() );}} elseif ( $config["HOSTNAME"] ){$sql = "UPDATEvserversSETv_name='" . $config["HOSTNAME"] . "'WHEREv_id=" . $config["v_id"] . "ANDhn_id=$hn_id";$res = $db->query( $sql );if ( PEAR::isError( $res ) ){die( $res->getUserInfo() );}}}else{die( $res->getUserInfo() );}foreach ( $config as $field => $value ){$sql = "SELECT*FROMvserver_configWHEREvc_name='$field'ANDv_id=" . $config["v_id"] . "ANDhn_id=$hn_id";$res = $db->query( $sql );if ( ! PEAR::isError( $res ) ){if ( $res->numRows() ){$sql = "UPDATEvserver_configSETvc_value='$value'WHEREvc_name='$field'ANDv_id=" . $config["v_id"] . "ANDhn_id=$hn_id";}else{$sql = "INSERT INTOvserver_configVALUES(" . $config["v_id"] . ",$hn_id,'$field','$value')";}$res = $db->query( $sql );if ( PEAR::isError( $res ) ){die( $res->getUserInfo() );}}else{die( $res->getUserInfo() );}}}}?>