Repository navigation
Expand file tree
/
Copy pathxml.php
More file actions
43 lines (39 loc) · 1.69 KB
/
Copy pathxml.php
File metadata and controls
43 lines (39 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
// XML definition editor (administrators): the persistent definition of a machine,
// checked against the libvirt schema and redefined; name and UUID must stay
require_once 'function.php';
$node = (string)($_GET['node'] ?? $_POST['node'] ?? '');
$xml_url = 'xml.php?node='.urlencode($node);
require_permission('admin', 'node.php?node='.urlencode($node));
if (!machine_visible($con, $node)) {
flash_set('danger', t('Unknown machine: %s', $node));
redirect('index.php');
}
$res = libvirt_domain_lookup_by_name($con, $node);
$uuid = (string)libvirt_domain_get_uuid_string($res);
$current = domain_definition_xml($res);
$text = $current;
$errors = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
csrf_require();
readonly_guard($xml_url, 'admin');
$text = str_replace("\r\n", "\n", (string)($_POST['xml'] ?? ''));
$errors = vm_xml_identity_errors($text, $node, $uuid);
if (!$errors && ($schema = vm_xml_schema_error($text)) !== '') {
$errors[] = t('The XML does not match the libvirt schema:').' '.$schema;
}
if (!$errors && !libvirt_domain_define_xml($con, $text)) {
$errors[] = t('Error: %s', libvirt_get_last_error());
}
if (!$errors) {
action_log('edit_xml', $node, true, strlen($current).' -> '.strlen($text).' bytes');
$active = (bool)libvirt_domain_is_active($res);
flash_set('success', t('Definition saved.').($active ? ' '.t('Takes effect after the machine is shut down and started again.') : ''));
redirect($xml_url);
}
action_log('edit_xml', $node, false, implode(' ', $errors));
}
$smarty->assign('node', $node);
$smarty->assign('xml_text', $text);
$smarty->assign('errors', $errors);
$smarty->display('xml.tpl');