service manager

This commit is contained in:
Serghey Rodin 2013-01-16 01:51:02 +02:00
commit fc80b0949a
19 changed files with 471 additions and 83 deletions

View file

@ -0,0 +1,28 @@
<?php
// Init
error_reporting(NULL);
ob_start();
session_start();
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
$service = $_POST['service'];
$action = $_POST['action'];
if ($_SESSION['user'] == 'admin') {
switch ($action) {
case 'stop': $cmd='v-stop-service';
break;
case 'start': $cmd='v-start-service';
break;
case 'restart': $cmd='v-restart-service';
break;
default: header("Location: /list/services/"); exit;
}
foreach ($service as $value) {
$value = escapeshellarg($value);
exec (VESTA_CMD.$cmd." ".$value, $output, $return_var);
}
}
header("Location: /list/services/");

BIN
web/images/start.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 B

BIN
web/images/stop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

View file

@ -44,10 +44,28 @@ function top_panel($user, $TAB) {
function humanize_time($usage) {
if ( $usage > 60 ) {
$usage = $usage / 60;
$usage = number_format($usage, 2);
$usage = $usage." Hour.";
if ( $usage > 24 ) {
$usage = $usage / 24;
$usage = number_format($usage, 0);
if ( $usage == 1 ) {
$usage = $usage." day";
} else {
$usage = $usage." days";
}
} else {
$usage = number_format($usage, 0);
if ( $usage == 1 ) {
$usage = $usage." hour";
} else {
$usage = $usage." hours";
}
}
} else {
$usage = $usage." Min.";
if ( $usage == 1 ) {
$usage = $usage." minute";
} else {
$usage = $usage." minutes";
}
}
return $usage;
}

View file

@ -60,7 +60,7 @@ VE.callbacks.click.do_suspend = function(evt, elm) {
var ref = elm.hasClass('data-controls') ? elm : elm.parents('.data-controls');
var url = $('input[name="suspend_url"]', ref).val();
var dialog_elm = ref.find('.confirmation-text-suspention');
VE.helpers.createConfirmationDialog(dialog_elm, 'Confirm SUSPEND', url);
VE.helpers.createConfirmationDialog(dialog_elm, 'Confirm action', url);
}
/*
@ -70,7 +70,7 @@ VE.callbacks.click.do_unsuspend = function(evt, elm) {
var ref = elm.hasClass('data-controls') ? elm : elm.parents('.data-controls');
var url = $('input[name="unsuspend_url"]', ref).val();
var dialog_elm = ref.find('.confirmation-text-suspention');
VE.helpers.createConfirmationDialog(dialog_elm, 'Confirm UNSUSPEND', url);
VE.helpers.createConfirmationDialog(dialog_elm, 'Confirm action', url);
}
/*
@ -80,7 +80,7 @@ VE.callbacks.click.do_delete = function(evt, elm) {
var ref = elm.hasClass('data-controls') ? elm : elm.parents('.data-controls');
var url = $('input[name="delete_url"]', ref).val();
var dialog_elm = ref.find('.confirmation-text-delete');
VE.helpers.createConfirmationDialog(dialog_elm, 'Confirm DELETE', url);
VE.helpers.createConfirmationDialog(dialog_elm, 'Confirm action', url);
}

View file

@ -0,0 +1,23 @@
<?php
// Init
error_reporting(NULL);
session_start();
$TAB = 'SERVICES';
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
// Header
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
// Panel
top_panel($user,$TAB);
// Data
if ($_SESSION['user'] == 'admin') {
exec (VESTA_CMD."v-list-sys-services json", $output, $return_var);
$data = json_decode(implode('', $output), true);
unset($output);
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/list_services.html');
}
// Footer
include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');

View file

@ -0,0 +1,22 @@
<?php
// Init
error_reporting(NULL);
ob_start();
session_start();
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
if ($_SESSION['user'] == 'admin') {
if (!empty($_GET['srv'])) {
$v_service = escapeshellarg($_GET['srv']);
exec (VESTA_CMD."v-restart-service ".$v_service, $output, $return_var);
}
if ($return_var != 0) {
$error = implode('<br>', $output);
if (empty($error)) $error = 'Error: service '.$v_service.' restart failed';
$_SESSION['error_srv'] = $error;
}
unset($output);
}
header("Location: /list/services/");
exit;

View file

@ -0,0 +1,22 @@
<?php
// Init
error_reporting(NULL);
ob_start();
session_start();
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
if ($_SESSION['user'] == 'admin') {
if (!empty($_GET['srv'])) {
$v_service = escapeshellarg($_GET['srv']);
exec (VESTA_CMD."v-start-service ".$v_service, $output, $return_var);
}
if ($return_var != 0) {
$error = implode('<br>', $output);
if (empty($error)) $error = 'Error: service '.$v_service.' start failed';
$_SESSION['error_srv'] = $error;
}
unset($output);
}
header("Location: /list/services/");
exit;

View file

@ -0,0 +1,22 @@
<?php
// Init
error_reporting(NULL);
ob_start();
session_start();
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
if ($_SESSION['user'] == 'admin') {
if (!empty($_GET['srv'])) {
$v_service = escapeshellarg($_GET['srv']);
exec (VESTA_CMD."v-stop-service ".$v_service, $output, $return_var);
}
if ($return_var != 0) {
$error = implode('<br>', $output);
if (empty($error)) $error = 'Error: service '.$v_service.' stop failed';
$_SESSION['error_srv'] = $error;
}
unset($output);
}
header("Location: /list/services/");
exit;

View file

@ -0,0 +1,152 @@
<table class="sub-menu" style="background: white;">
<tr>
<td style="padding: 12px 0 8px 6px">
<div style="text-align: right; float: right;">
<form action="/search/" method="get" >
<input type="text" name="q" style="margin: 2px 2px 0px 0px; width: 250px; padding: 3px;" size="30">
<input type="submit" value="Search" class="button" style="font-size: 12px; height: 24px;">
</form>
</div>
<div style="float:left; padding-left: 0px;">
<form action="/bulk/service/" method="post" id="objects">
<a style="padding: 0 4px 0 12px" class="select-controls" href='javascript:checkedAll("objects");'> toggle all </a>
<select style="margin:0 2px 0 0px;" name="action">
<option>apply to selected</option>
<option>stop</option>
<option>start</option>
<option>restart</option>
</select>
<input type="submit" name="ok" value="" class="button" style="width: 37px; font-size: 12px; height: 24px;">
</div>
<?php
if (!empty($_SESSION['error_srv'])) {
?>
<div>
<script type="text/javascript">
$(function() {
$( "#dialog:ui-dialog" ).dialog( "destroy" );
$( "#dialog-message" ).dialog({
modal: true,
buttons: {
Ok: function() {
$( this ).dialog( "close" );
}
}
});
});
</script>
<div id="dialog-message" title="Error">
<p><?php echo $_SESSION['error_srv'] ?></p>
</div>
</div>
<?php
unset($_SESSION['error_srv']);
}
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
<div id="vstobjects">
<table class='data'>
<?php
foreach ($data as $key => $value) {
++$i;
if ($data[$key]['STATE'] == 'running') {
$status = 'active';
$action = 'stop';
} else {
$status = 'suspended';
$action = 'start';
}
$cpu = $data[$key]['CPU'] / 10;
$cpu = number_format($cpu, 1);
if ($cpu == '0.0') $cpu = 0;
?>
<tr class="data-row">
<td class="data-dotted" style="padding: 0px 10px 0px 0px" width="150">
<table class="data-col1">
<tr><td style="padding: 18 0 4 18;"><input type="checkbox" name="service[]" value="<?php echo $key ?>" ></td></tr>
<tr><td class="data-<?php echo $status ?>"><b><?php echo $data[$key]['STATE'] ?></b></td></tr>
</table>
</td>
<td class="data-dotted" width="830px" style="vertical-align:top;">
<table width="830px">
<tr>
<td></td>
<td class="data-controls" width="68px"><a href="/restart/service/?srv=<?php echo $key ?>"><img src="/images/reload.png" width="6px" height="7px"> restart</a></td>
<td class="data-controls" width="48px"><a href="/<?php echo $action ?>/service/?srv=<?php echo $key ?>"><img src="/images/<?php echo $action ?>.png" width="7px" height="7px"> <?php echo $action ?></a></td>
</tr>
</table>
<table class="data-col2" width="830px">
<tr>
<td colspan=4 class="domain" style="padding: 0 0 0 4px;">
<b><?php echo $key ?></b>
</td>
</tr>
<tr>
<td style="vertical-align:top;" width="200px">
<table>
<tr>
<td class="counter-name" style="padding: 2px 0 0 0">
<?php echo $data[$key]['SYSTEM'] ?>
</td>
</tr>
</table>
</td>
<td style="vertical-align:top;" width="150px">
<table>
<tr>
<td class="counter-name">
CPU:
</td>
<td>
<a class="counter-value"> <?php echo $cpu ?>%</a>
</td>
</tr>
</table>
</td>
<td style="vertical-align:top;" width="180px">
<table>
<tr>
<td class="counter-name">
Memory:
</td>
<td>
<a class="counter-value"><?php echo $data[$key]['MEM'] ?> mb</a>
</td>
</tr>
</table>
</td>
<td style="vertical-align:top;" >
<table>
<tr>
<td class="counter-name">
Run Time:
</td>
<td>
<a class="counter-value"><?php echo humanize_time($data[$key]['RTIME']) ?> </a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<?php
}
?>
</table>
</form>
</div>

View file

@ -311,7 +311,7 @@
.data-suspended {
font-size: 8pt;
letter-spacing: 0.1em;
color: #de6c5d;
color: #de5543;
padding: 0 0 13 18;
}