commit | author | age
|
46598e
|
1 |
<?php |
T |
2 |
/* |
|
3 |
Copyright (c) 2010, Till Brehm, projektfarm Gmbh |
|
4 |
All rights reserved. |
|
5 |
*/ |
|
6 |
|
7fe908
|
7 |
require_once '../../lib/config.inc.php'; |
MC |
8 |
require_once '../../lib/app.inc.php'; |
46598e
|
9 |
|
T |
10 |
//* Check permissions for module |
|
11 |
$app->auth->check_module_permissions('vm'); |
|
12 |
|
|
13 |
$action = (isset($_POST['action']) && $_POST['action'] != '')?$_POST['action']:'show'; |
65ea2e
|
14 |
$vm_id = $app->functions->intval($_REQUEST['id']); |
46598e
|
15 |
$error_msg = ''; |
T |
16 |
$notify_msg = ''; |
|
17 |
|
|
18 |
if($vm_id == 0) die('Invalid VM ID'); |
|
19 |
|
5af0cf
|
20 |
if(isset($_POST) && count($_POST) > 1) { |
TB |
21 |
//* CSRF Check |
|
22 |
$app->auth->csrf_token_check(); |
|
23 |
} |
|
24 |
|
46598e
|
25 |
$vm = $app->db->queryOneRecord("SELECT server_id, veid FROM openvz_vm WHERE vm_id = $vm_id"); |
dce3bb
|
26 |
$veid = $app->functions->intval($vm['veid']); |
TB |
27 |
$server_id = $app->functions->intval($vm['server_id']); |
46598e
|
28 |
|
T |
29 |
//* Loading classes |
|
30 |
$app->uses('tpl'); |
|
31 |
|
|
32 |
$app->tpl->newTemplate('form.tpl.htm'); |
|
33 |
$app->tpl->setInclude('content_tpl', 'templates/openvz_action.htm'); |
|
34 |
|
7fe908
|
35 |
//* load language file |
MC |
36 |
$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_openvz_action.lng'; |
|
37 |
include_once $lng_file; |
|
38 |
$app->tpl->setVar($wb); |
|
39 |
|
|
40 |
$app->tpl->setVar('id', $vm_id); |
|
41 |
$app->tpl->setVar('veid', $veid); |
|
42 |
|
|
43 |
$options = array('start_option_enabled'=>'', 'stop_option_enabled'=>'', 'restart_option_enabled'=>'', 'ostemplate_option_enabled'=>''); |
46598e
|
44 |
|
T |
45 |
|
|
46 |
//* Show the action select page |
|
47 |
if($action == 'show') { |
|
48 |
|
7fe908
|
49 |
$options['start_option_enabled'] = 'checked="checked"'; |
MC |
50 |
|
46598e
|
51 |
} elseif ($action == 'start') { |
7fe908
|
52 |
|
46598e
|
53 |
//* Start the virtual machine |
T |
54 |
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " . |
7fe908
|
55 |
"VALUES (". |
MC |
56 |
(int)$server_id . ", ". |
|
57 |
time() . ", ". |
|
58 |
"'openvz_start_vm', ". |
|
59 |
$veid.", ". |
|
60 |
"'pending', ". |
|
61 |
"''". |
|
62 |
")"; |
46598e
|
63 |
$app->db->query($sql); |
7fe908
|
64 |
|
MC |
65 |
$app->tpl->setVar('msg', $wb['start_exec_txt']); |
46598e
|
66 |
$options['start_option_enabled'] = 'checked="checked"'; |
7fe908
|
67 |
|
46598e
|
68 |
} elseif ($action == 'stop') { |
7fe908
|
69 |
|
46598e
|
70 |
//* Stop the virtual machine |
T |
71 |
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " . |
7fe908
|
72 |
"VALUES (". |
MC |
73 |
(int)$server_id . ", ". |
|
74 |
time() . ", ". |
|
75 |
"'openvz_stop_vm', ". |
|
76 |
$veid.", ". |
|
77 |
"'pending', ". |
|
78 |
"''". |
|
79 |
")"; |
46598e
|
80 |
$app->db->query($sql); |
7fe908
|
81 |
|
MC |
82 |
$app->tpl->setVar('msg', $wb['stop_exec_txt']); |
46598e
|
83 |
$options['stop_option_enabled'] = 'checked="checked"'; |
T |
84 |
|
|
85 |
} elseif ($action == 'restart') { |
7fe908
|
86 |
|
46598e
|
87 |
//* Restart the virtual machine |
T |
88 |
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " . |
7fe908
|
89 |
"VALUES (". |
MC |
90 |
(int)$server_id . ", ". |
|
91 |
time() . ", ". |
|
92 |
"'openvz_restart_vm', ". |
|
93 |
$veid.", ". |
|
94 |
"'pending', ". |
|
95 |
"''". |
|
96 |
")"; |
46598e
|
97 |
$app->db->query($sql); |
7fe908
|
98 |
|
MC |
99 |
$app->tpl->setVar('msg', $wb['restart_exec_txt']); |
46598e
|
100 |
$options['restart_option_enabled'] = 'checked="checked"'; |
T |
101 |
|
|
102 |
} elseif ($action == 'ostemplate') { |
7fe908
|
103 |
|
46598e
|
104 |
$ostemplate_name = $_POST['ostemplate_name']; |
7fe908
|
105 |
|
46598e
|
106 |
if(!preg_match("/^[a-zA-Z0-9\.\-\_]{1,50}$/i", $ostemplate_name)) { |
T |
107 |
$error_msg .= $wb['ostemplate_name_error'].'<br />'; |
7fe908
|
108 |
$app->tpl->setVar('ostemplate_name', $ostemplate_name); |
46598e
|
109 |
} |
7fe908
|
110 |
|
46598e
|
111 |
//* Quote name |
T |
112 |
$ostemplate_name = $app->db->quote($ostemplate_name); |
7fe908
|
113 |
|
46598e
|
114 |
//* Check for duplicates |
T |
115 |
$tmp = $app->db->queryOneRecord("SELECT count(ostemplate_id) as number FROM openvz_ostemplate WHERE template_file = '$ostemplate_name'"); |
|
116 |
if($tmp['number'] > 0) $error_msg .= $wb['ostemplate_name_unique_error'].'<br />'; |
|
117 |
unset($tmp); |
7fe908
|
118 |
|
46598e
|
119 |
if($error_msg == '') { |
T |
120 |
//* Create ostemplate action |
|
121 |
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " . |
7fe908
|
122 |
"VALUES (". |
MC |
123 |
(int)$server_id . ", ". |
|
124 |
time() . ", ". |
|
125 |
"'openvz_create_ostpl', ". |
|
126 |
"'".$veid.":".$ostemplate_name."', ". |
|
127 |
"'pending', ". |
|
128 |
"''". |
|
129 |
")"; |
46598e
|
130 |
$app->db->query($sql); |
7fe908
|
131 |
|
46598e
|
132 |
//* Create a record in the openvz_ostemplate table |
7fe908
|
133 |
$sql = "INSERT INTO `openvz_ostemplate` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `template_name`, `template_file`, `server_id`, `allservers`, `active`, `description`) |
46598e
|
134 |
VALUES(1, 1, 'riud', 'riud', '', '$ostemplate_name', '$ostemplate_name', $server_id, 'n', 'y', '')"; |
T |
135 |
$app->db->query($sql); |
7fe908
|
136 |
|
MC |
137 |
$app->tpl->setVar('msg', $wb['ostemplate_exec_txt']); |
46598e
|
138 |
$options['ostemplate_option_enabled'] = 'checked="checked"'; |
T |
139 |
} |
|
140 |
|
|
141 |
} else { |
|
142 |
$error_msg = $app->lng('Unknown action'); |
|
143 |
$app->error($error_msg); |
|
144 |
} |
|
145 |
|
|
146 |
$app->tpl->setVar($options); |
7fe908
|
147 |
$app->tpl->setVar('error', $error_msg); |
46598e
|
148 |
|
5af0cf
|
149 |
//* SET csrf token |
TB |
150 |
$csrf_token = $app->auth->csrf_token_get('openvz_action'); |
|
151 |
$app->tpl->setVar('_csrf_id',$csrf_token['csrf_id']); |
|
152 |
$app->tpl->setVar('_csrf_key',$csrf_token['csrf_key']); |
|
153 |
|
46598e
|
154 |
$app->tpl_defaults(); |
T |
155 |
$app->tpl->pparse(); |
|
156 |
|
|
157 |
|
|
158 |
|
7fe908
|
159 |
?> |