Subversion-Projekte lars-tiefland.openvz_admin

Revision

Revision 118 | Revision 120 | Zur aktuellen Revision | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?php
        //$Id: load.php 119 2008-05-22 13:42:05Z lars $
        /**
         *      @package        openvz_admin
         *      @author         Lars Tiefland <ltiefland@gmail.com> 
         **/
        require ("include/common.php");
        $hns = HN::getHNs();
        unset($hns[-1]);
        #       $hns[3]="gate.dynalias.net";
        foreach ($hns as $hn_id => $hn_name)
        {
                $configs=load_configs($hn_id,$hn_name);
                foreach($configs as $conf_id => $config)
                {
                        $cfg=read_config($hn_name,$config);
                        var_dump($cfg);
                }
        }
        
        function load_configs($hn_id,$hn_name)
        {
                unset($out);
                $cmd = "ssh root@$hn_name ls /etc/vz/conf/*.conf";
                exec($cmd, $out, $ret);
                return $out;
        }
        
        function read_config($hn_name, $conf)
        {
                        $cmd = "scp root@$hn_name:/etc/vz/conf/$conf cfgs/$hn_id";
                        exec($cmd, $out, $ret);
                        $cont = file("cfgs/$hn_id/$conf");
                        $cont[] = "v_id=\"" . substr($conf, 0, strpos($conf, '.')) . "\"";
                        return $cont;
        }
/*              foreach ($files as $conf)
                {
                        unset($cont);
                        $conf = basename($conf);
                        unset($out);
                        foreach ($cont as $conf)
                        {
                                unset($cfgs);
                                foreach ($conf as $value)
                                {
                                        if ($value)
                                        {
                                                $value = rtrim($value);
                                                if ($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;
                                foreach ($cfgs as $config)
                                {
                                        $sql = "SELECT * FROM distributions WHERE dist_name='" . $config["DISTRIBUTION"] .
                                                "'";
                                        $res = $db->query($sql);
                                        if (!PEAR::isError($res))
                                        {
                                                if ($res->numRows())
                                                {
                                                        $row = $res->fetchRow();
                                                        $dist_id = $row["dist_id"];
                                                }
                                                else
                                                {
                                                        $sql = "INSERT INTO distributions (dist_name, dist_template) VALUES('" . $config["DISTRIBUTION"] .
                                                                "', '" . $config["OSTEMPLATE"] . "')";
                                                        $res = $db->query($sql);
                                                        $dist_id = $res->lastinsertID();
                                                }
                                                $sql = "SELECT * FROM vservers WHERE v_id=" . $config["v_id"] . " AND hn_id=$hn_id";
                                                $res = $db->query($sql);
                                                if (!PEAR::isError($res))
                                                {
                                                        if (!$res->numRows())
                                                        {
                                                                $sql = "INSERT INTO vservers (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))
                                                                {
                                                                        echo $res->getUserInfo();
                                                                }
                                                        }
                                                }
                                                foreach ($conf as $field => $value)
                                                {
                                                        $sql = "SELECT * FROM vserver_config WHERE vc_name='$field' AND v_id=" . $config["v_id"] .
                                                                " AND hn_id=$hn_id";
                                                        $res = $db->query($sql);
                                                        if (!PEAR::isError($res))
                                                        {
                                                                if ($res->numRows())
                                                                {
                                                                        $sql = "UPDATE vserver_config SET vc_value='$value' WHERE vc_name='$field' AND v_id=" .
                                                                                $config["v_id"] . " AND hn_id=$hn_id";
                                                                }
                                                                else
                                                                {
                                                                        $sql = "INSERT INTO vserver_config VALUES (" . $config["v_id"] . ", $hn_id, '$field', '$value')";
                                                                }
                                                                $res = $db->query($sql);
                                                                if (PEAR::isError($res))
                                                                {
                                                                        echo $res->getUserInfo();
                                                                }
                                                        }
                                                        else
                                                        {
                                                                echo $res->getUserInfo();
                                                        }
                                                }
                                        }
                                        else
                                        {
                                                echo $res->getUserInfo();
                                        }
                                }
                        }
                }
        }*/
?>