forked from lattera/drupal-jailadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jailstatus.inc
119 lines (94 loc) · 3.72 KB
/
jailstatus.inc
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
require_once('jailadmin.helpers.inc');
require_once('classes/Mount.php');
require_once('classes/Service.php');
require_once('classes/Network.php');
require_once('classes/NetworkDevice.php');
require_once('classes/Jail.php');
function jailadmin_status($form, &$form_state) {
$jails = Jail::LoadAll();
$header = array('Jail Name', 'Hostname', 'Status', 'Network Status', 'Actions');
$rows = array();
foreach ($jails as $jail) {
$action = "";
if (user_access('config ' . $jail->name) || user_access('view ' . $jail->name . ' config'))
$name = l(t($jail->name), 'jailadmin/' . $jail->name . '/config');
else
$name = t('@name', array('@name' => $jail->name));
if ($jail->MultipleActiveBEs) {
$action = "Unavailable: Multiple active BEs";
} else {
if (user_access("start jails")) {
if ($jail->IsOnline())
$action = l("Stop", "jailadmin/{$jail->name}/stop");
else
$action = l("Start", "jailadmin/{$jail->name}/start");
}
if (user_access("config {$jail->name}")) {
$network = l(t("Network Settings"), "jailadmin/{$jail->name}/network");
$action .= (strlen($action) ? " | " : "")
. l("Snapshot", "jailadmin/{$jail->name}/snapshot")
. " | {$network}";
}
}
$hostname = (strlen($jail->hostname)) ? $jail->hostname : $jail->name;
$rows[] = array($name, $hostname, $jail->IsOnlineString(), $jail->NetworkStatus(), $action);
}
$form['jails'] = array(
'#type' => 'markup',
'#prefix' => '<div>',
'#markup' => theme('table', array(
'header' => $header,
'rows' => $rows,
)),
'#suffix' => '</div>',
);
return $form;
}
function jail_start($form, &$form_state) {
$jail = Jail::Load($form_state['build_info']['args'][0]);
if (user_access("start jails") == FALSE) {
drupal_set_message(t("Access Denied"), "error");
$form_state['rebuild'] = TRUE;
drupal_goto("jailadmin/status");
return;
}
if ($jail->Start()) {
drupal_set_message(t('Jail @jail started successfully', array('@jail' => $jail->name)));
} else {
drupal_set_message(t('Jail @jail failed to start', array('@jail' => $jail->name)), 'error');
}
$form_state['rebuild'] = true;
drupal_goto("jailadmin/status");
}
function jail_stop($form, &$form_state) {
$jail = Jail::Load($form_state['build_info']['args'][0]);
if (user_access("start jails") == FALSE) {
drupal_set_message(t("Access Denied"), "error");
$form_state['rebuild'] = TRUE;
drupal_goto("jailadmin/status");
return;
}
if ($jail->Stop()) {
drupal_set_message(t('Jail @jail stopped successfully', array('@jail' => $jail->name)));
} else {
drupal_set_message(t('Jail @jail failed to stop', array('@jail' => $jail->name)), 'error');
}
$form_state['rebuild'] = true;
drupal_goto("jailadmin/status");
}
function jail_snapshot($form, &$form_state) {
$jail = Jail::Load($form_state['build_info']['args'][0]);
if (user_access("config {$jail->name}") == FALSE) {
drupal_set_message(t("Access Denied"), "error");
$form_state['rebuild'] = TRUE;
drupal_goto("jailadmin/status");
return;
}
if ($jail->Snapshot() !== FALSE)
drupal_set_message(t('Jail @jail snapshot successful', array('@jail' => $jail->name)));
else
drupal_set_message(t('Jail @jail snapshot unsuccessful', array('@jail' => $jail->name)));
$form_state['rebuild'] = true;
drupal_goto("jailadmin/status");
}