Subversion-Projekte lars-tiefland.openvz_admin

Revision

Revision 159 | Revision 165 | Zur aktuellen Revision | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 159 Revision 162
Zeile 1... Zeile 1...
1
<?php
1
<?php
2
    //$Id: load.php 159 2009-11-07 21:49:50Z lars $
2
    //$Id: load.php 162 2010-03-12 23:25:46Z lars $
3
    /**
3
    /**
4
     * 	@package	openvz_admin
4
     * 	@package	openvz_admin
5
     * 	@author		Lars Tiefland <ltiefland@gmail.com> 
5
     * 	@author		Lars Tiefland <ltiefland@gmail.com> 
6
     **/
6
     **/
7
    require ( "include/common.php" );
7
    require ( "include/common.php" );
Zeile 20... Zeile 20...
20
    function load_configs( $hn_id, $hn_name )
20
    function load_configs( $hn_id, $hn_name )
21
    {
21
    {
22
        unset( $out );
22
        unset( $out );
23
        $cmd = "ping $hn_name -w1";
23
        $cmd = "ping $hn_name -w1";
24
        exec( $cmd, $out, $ret );
24
        exec( $cmd, $out, $ret );
25
        if ( !$ret )
25
        if ( ! $ret )
26
        {
26
        {
27
            echo "Hole Konfigurationen von $hn_name\n";
27
            echo "Hole Konfigurationen von $hn_name\n";
28
            unset( $out );
28
            unset( $out );
29
            $cmd = "ssh root@$hn_name ls /etc/vz/conf/*.conf";
29
            $cmd = "ssh root@$hn_name ls /etc/vz/conf/*.conf";
30
            exec( $cmd, $out, $ret );
30
            exec( $cmd, $out, $ret );
-
 
31
            if ( $ret )
-
 
32
            {
-
 
33
                trigger_error( "Konnte Konfigurationen nicht holen! Ist dies wirklich ein Virtuozzo / openvz-Server?",
-
 
34
                    E_USER_ERROR );
-
 
35
            }
31
            return $out;
36
            return $out;
32
        }
37
        }
33
    }
38
    }
Zeile 34... Zeile 39...
34
 
39
 
35
    function read_config( $hn_id, $hn_name, $config )
40
    function read_config( $hn_id, $hn_name, $config )
36
    {
41
    {
37
        $config = basename( $config );
42
        $config = basename( $config );
38
        $cmd = "scp root@$hn_name:/etc/vz/conf/$config cfgs/$hn_id";
43
        $cmd = "scp root@$hn_name:/etc/vz/conf/$config cfgs/$hn_id";
39
        exec( $cmd, $out, $ret );
44
        exec( $cmd, $out, $ret );
40
        $conf = file( "cfgs/$hn_id/$config" );
45
        $conf = file( "cfgs/$hn_id/$config" );
41
        $conf[] = "v_id=\"" . substr( $config, 0, strpos($config, '.') ) . "\"";
46
        $conf[] = "v_id=\"" . substr( $config, 0, strpos( $config, '.' ) ) . "\"";
42
        foreach ( $conf as $value )
47
        foreach ( $conf as $value )
43
        {
48
        {
44
            if ( $value )
49
            if ( $value )
45
            {
50
            {
Zeile 64... Zeile 69...
64
    {
69
    {
65
        global $db;
70
        global $db;
Zeile 66... Zeile 71...
66
 
71
 
67
        foreach ( $cfgs as $config )
72
        foreach ( $cfgs as $config )
68
        {
73
        {
69
            if ( isset($config["DISTRIBUTION"]) )
74
            if ( isset( $config["DISTRIBUTION"] ) )
70
            {
75
            {
71
                $dist_name = $config["DISTRIBUTION"];
76
                $dist_name = $config["DISTRIBUTION"];
72
            } elseif ( in_array($hn_id, array(1, 3)) )
77
            } elseif ( in_array( $hn_id, array( 1, 3 ) ) )
73
            {
78
            {
74
                $dist_name = "gentoo";
79
                $dist_name = "gentoo";
75
            }
80
            }
76
            else
81
            else
Zeile 84... Zeile 89...
84
					distributions 
89
					distributions 
85
				WHERE 
90
				WHERE 
86
					dist_name='$dist_name'
91
					dist_name='$dist_name'
87
			";
92
			";
88
            $res = $db->query( $sql );
93
            $res = $db->query( $sql );
89
            if ( !PEAR::isError($res) )
94
            if ( ! PEAR::isError( $res ) )
90
            {
95
            {
91
                if ( $res->numRows() )
96
                if ( $res->numRows() )
92
                {
97
                {
93
                    $row = $res->fetchRow();
98
                    $row = $res->fetchRow();
94
                    $dist_id = $row["dist_id"];
99
                    $dist_id = $row["dist_id"];
Zeile 103... Zeile 108...
103
							v_id=" . $config["v_id"] . "
108
							v_id=" . $config["v_id"] . "
104
						AND 
109
						AND 
105
							dist_id=v_dist 
110
							dist_id=v_dist 
106
					";
111
					";
107
                    $res_v = $db->query( $sql_v );
112
                    $res_v = $db->query( $sql_v );
108
                    if ( PEAR::isError($res_v) )
113
                    if ( PEAR::isError( $res_v ) )
109
                    {
114
                    {
110
                        die( $res_v->getUserInfo() );
115
                        die( $res_v->getUserInfo() );
111
                    }
116
                    }
112
                    $row_v = $res_v->fetchRow();
117
                    $row_v = $res_v->fetchRow();
113
                    $dist_name = $row_v["dist_name"];
118
                    $dist_name = $row_v["dist_name"];
Zeile 120... Zeile 125...
120
								v_dist=$dist_id 
125
								v_dist=$dist_id 
121
							WHERE 
126
							WHERE 
122
								v_id=" . $config["v_id"] . "
127
								v_id=" . $config["v_id"] . "
123
						";
128
						";
124
                        $res = $db->query( $sql );
129
                        $res = $db->query( $sql );
125
                        if ( PEAR::isError($res) )
130
                        if ( PEAR::isError( $res ) )
126
                        {
131
                        {
127
                            die( $res->getUserInfo() );
132
                            die( $res->getUserInfo() );
128
                        }
133
                        }
129
                    }
134
                    }
130
                }
135
                }
Zeile 160... Zeile 165...
160
					v_id=" . $config["v_id"] . " 
165
					v_id=" . $config["v_id"] . " 
161
				AND 
166
				AND 
162
					hn_id=$hn_id
167
					hn_id=$hn_id
163
			";
168
			";
164
            $res = $db->query( $sql );
169
            $res = $db->query( $sql );
165
            if ( !PEAR::isError($res) )
170
            if ( ! PEAR::isError( $res ) )
166
            {
171
            {
167
                if ( !$res->numRows() )
172
                if ( ! $res->numRows() )
168
                {
173
                {
169
                    $sql = "
174
                    $sql = "
170
						INSERT INTO 
175
						INSERT INTO 
171
							vservers 
176
							vservers 
172
						(
177
						(
Zeile 182... Zeile 187...
182
							$dist_id, 
187
							$dist_id, 
183
							$hn_id
188
							$hn_id
184
						)
189
						)
185
					";
190
					";
186
                    $res = $db->query( $sql );
191
                    $res = $db->query( $sql );
187
                    if ( PEAR::isError($res) )
192
                    if ( PEAR::isError( $res ) )
188
                    {
193
                    {
189
                        die( $res->getUserInfo() );
194
                        die( $res->getUserInfo() );
190
                    }
195
                    }
191
                } elseif ( $config["HOSTNAME"] )
196
                } elseif ( $config["HOSTNAME"] )
192
                {
197
                {
Zeile 199... Zeile 204...
199
							v_id=" . $config["v_id"] . " 
204
							v_id=" . $config["v_id"] . " 
200
						AND 
205
						AND 
201
							hn_id=$hn_id
206
							hn_id=$hn_id
202
					";
207
					";
203
                    $res = $db->query( $sql );
208
                    $res = $db->query( $sql );
204
                    if ( PEAR::isError($res) )
209
                    if ( PEAR::isError( $res ) )
205
                    {
210
                    {
206
                        die( $res->getUserInfo() );
211
                        die( $res->getUserInfo() );
207
                    }
212
                    }
208
                }
213
                }
209
            }
214
            }
Zeile 224... Zeile 229...
224
						v_id=" . $config["v_id"] . " 
229
						v_id=" . $config["v_id"] . " 
225
					AND 
230
					AND 
226
						hn_id=$hn_id
231
						hn_id=$hn_id
227
				";
232
				";
228
                $res = $db->query( $sql );
233
                $res = $db->query( $sql );
229
                if ( !PEAR::isError($res) )
234
                if ( ! PEAR::isError( $res ) )
230
                {
235
                {
231
                    if ( $res->numRows() )
236
                    if ( $res->numRows() )
232
                    {
237
                    {
233
                        $sql = "
238
                        $sql = "
234
							UPDATE 
239
							UPDATE 
Zeile 256... Zeile 261...
256
								'$value'
261
								'$value'
257
							)
262
							)
258
						";
263
						";
259
                    }
264
                    }
260
                    $res = $db->query( $sql );
265
                    $res = $db->query( $sql );
261
                    if ( PEAR::isError($res) )
266
                    if ( PEAR::isError( $res ) )
262
                    {
267
                    {
263
                        die( $res->getUserInfo() );
268
                        die( $res->getUserInfo() );
264
                    }
269
                    }
265
                }
270
                }
266
                else
271
                else