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 |
} |
2af58c
|
24 |
$vm = $app->db->queryOneRecord("SELECT server_id, veid FROM openvz_vm WHERE vm_id = ?", $vm_id); |
dce3bb
|
25 |
$veid = $app->functions->intval($vm['veid']); |
TB |
26 |
$server_id = $app->functions->intval($vm['server_id']); |
46598e
|
27 |
|
T |
28 |
//* Loading classes |
|
29 |
$app->uses('tpl'); |
|
30 |
|
|
31 |
$app->tpl->newTemplate('form.tpl.htm'); |
|
32 |
$app->tpl->setInclude('content_tpl', 'templates/openvz_action.htm'); |
|
33 |
|
7fe908
|
34 |
//* load language file |
MC |
35 |
$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_openvz_action.lng'; |
|
36 |
include_once $lng_file; |
|
37 |
$app->tpl->setVar($wb); |
|
38 |
|
|
39 |
$app->tpl->setVar('id', $vm_id); |
|
40 |
$app->tpl->setVar('veid', $veid); |
|
41 |
|
|
42 |
$options = array('start_option_enabled'=>'', 'stop_option_enabled'=>'', 'restart_option_enabled'=>'', 'ostemplate_option_enabled'=>''); |
46598e
|
43 |
|
T |
44 |
|
|
45 |
//* Show the action select page |
|
46 |
if($action == 'show') { |
|
47 |
|
7fe908
|
48 |
$options['start_option_enabled'] = 'checked="checked"'; |
MC |
49 |
|
46598e
|
50 |
} elseif ($action == 'start') { |
7fe908
|
51 |
|
46598e
|
52 |
//* Start the virtual machine |
T |
53 |
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " . |
2af58c
|
54 |
"VALUES (?, UNIX_TIMESTAMP(), 'openvz_start_vm', ?, 'pending', '')"; |
MC |
55 |
$app->db->query($sql, $server_id, $veid); |
7fe908
|
56 |
|
MC |
57 |
$app->tpl->setVar('msg', $wb['start_exec_txt']); |
46598e
|
58 |
$options['start_option_enabled'] = 'checked="checked"'; |
7fe908
|
59 |
|
46598e
|
60 |
} elseif ($action == 'stop') { |
7fe908
|
61 |
|
46598e
|
62 |
//* Stop the virtual machine |
T |
63 |
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " . |
2af58c
|
64 |
"VALUES (?, UNIX_TIMESTAMP(), 'openvz_stop_vm', ?, 'pending', '')"; |
MC |
65 |
$app->db->query($sql, $server_id, $veid); |
7fe908
|
66 |
|
MC |
67 |
$app->tpl->setVar('msg', $wb['stop_exec_txt']); |
46598e
|
68 |
$options['stop_option_enabled'] = 'checked="checked"'; |
T |
69 |
|
|
70 |
} elseif ($action == 'restart') { |
7fe908
|
71 |
|
46598e
|
72 |
//* Restart the virtual machine |
T |
73 |
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " . |
2af58c
|
74 |
"VALUES (?, UNIX_TIMESTAMP(), 'openvz_restart_vm', ?, 'pending', '')"; |
MC |
75 |
$app->db->query($sql, $server_id, $veid); |
7fe908
|
76 |
|
MC |
77 |
$app->tpl->setVar('msg', $wb['restart_exec_txt']); |
46598e
|
78 |
$options['restart_option_enabled'] = 'checked="checked"'; |
T |
79 |
|
|
80 |
} elseif ($action == 'ostemplate') { |
7fe908
|
81 |
|
46598e
|
82 |
$ostemplate_name = $_POST['ostemplate_name']; |
7fe908
|
83 |
|
46598e
|
84 |
if(!preg_match("/^[a-zA-Z0-9\.\-\_]{1,50}$/i", $ostemplate_name)) { |
T |
85 |
$error_msg .= $wb['ostemplate_name_error'].'<br />'; |
7fe908
|
86 |
$app->tpl->setVar('ostemplate_name', $ostemplate_name); |
46598e
|
87 |
} |
7fe908
|
88 |
|
46598e
|
89 |
//* Quote name |
7fe908
|
90 |
|
46598e
|
91 |
//* Check for duplicates |
2af58c
|
92 |
$tmp = $app->db->queryOneRecord("SELECT count(ostemplate_id) as number FROM openvz_ostemplate WHERE template_file = ?", $ostemplate_name); |
46598e
|
93 |
if($tmp['number'] > 0) $error_msg .= $wb['ostemplate_name_unique_error'].'<br />'; |
T |
94 |
unset($tmp); |
7fe908
|
95 |
|
46598e
|
96 |
if($error_msg == '') { |
T |
97 |
//* Create ostemplate action |
|
98 |
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " . |
2af58c
|
99 |
"VALUES (?, UNIX_TIMESTAMP(), 'openvz_create_ostpl', ?, 'pending', '')"; |
MC |
100 |
$app->db->query($sql, $server_id, $veid.":".$ostemplate_name); |
7fe908
|
101 |
|
46598e
|
102 |
//* Create a record in the openvz_ostemplate table |
7fe908
|
103 |
$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`) |
2af58c
|
104 |
VALUES(1, 1, 'riud', 'riud', '', ?, ?, ?, 'n', 'y', '')"; |
MC |
105 |
$app->db->query($sql, $ostemplate_name, $ostemplate_name, $server_id); |
7fe908
|
106 |
|
MC |
107 |
$app->tpl->setVar('msg', $wb['ostemplate_exec_txt']); |
46598e
|
108 |
$options['ostemplate_option_enabled'] = 'checked="checked"'; |
T |
109 |
} |
|
110 |
|
|
111 |
} else { |
|
112 |
$error_msg = $app->lng('Unknown action'); |
|
113 |
$app->error($error_msg); |
|
114 |
} |
|
115 |
|
|
116 |
$app->tpl->setVar($options); |
7fe908
|
117 |
$app->tpl->setVar('error', $error_msg); |
46598e
|
118 |
|
5af0cf
|
119 |
//* SET csrf token |
TB |
120 |
$csrf_token = $app->auth->csrf_token_get('openvz_action'); |
|
121 |
$app->tpl->setVar('_csrf_id',$csrf_token['csrf_id']); |
|
122 |
$app->tpl->setVar('_csrf_key',$csrf_token['csrf_key']); |
|
123 |
|
46598e
|
124 |
$app->tpl_defaults(); |
T |
125 |
$app->tpl->pparse(); |
|
126 |
|
|
127 |
|
|
128 |
|
7fe908
|
129 |
?> |