-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathprocesses.php
More file actions
82 lines (72 loc) · 3.68 KB
/
Copy pathprocesses.php
File metadata and controls
82 lines (72 loc) · 3.68 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
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
<?php
declare(strict_types=1);
$active_page = 'processes';
require_once('./include/init.php');
if (!isset($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
// Sort by CPU descending; 'ps aux' columns: USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
$raw = @shell_exec('ps aux | sort -rk 3,3');
$rows = [];
foreach (preg_split('/\r\n|\r|\n/', (string)$raw) as $line) {
$line = trim($line);
if ($line === '') continue;
$rows[] = explode(' ', preg_replace('/\s+/', ' ', $line), 11);
}
$page_title = 'Processes';
require_once('./include/header.php');
?>
<div class="panel panel-default" style="margin-bottom:5px">
<div class="panel-heading">
<h3 class="panel-title">
<?php echo htmlspecialchars(t('proc.title', 'System Processes'), ENT_QUOTES, 'UTF-8'); ?>
<a href="?" class="btn btn-success pull-right" style="margin:-6px -11px; color:#fff;">
<i class="fa fa-refresh"></i>
</a>
</h3>
</div>
<div class="panel-body">
<?php if (empty($rows)): ?>
<div class="alert alert-warning" role="alert">
<i class="fa fa-exclamation-triangle"></i> Unable to retrieve process list.
</div>
<?php else: ?>
<table class="table table-bordered table-condensed">
<tbody>
<?php foreach ($rows as $row):
// ps aux header row has "PID" as its second token
$is_header = (($row[1] ?? '') === 'PID');
$pid = $is_header ? 0 : (int)($row[1] ?? 0);
?>
<tr>
<?php foreach ($row as $i => $cell): ?>
<td<?php echo ($i > 3 && $i < 9) ? ' class="hidden-xs hidden-sm"' : ''; ?>>
<?php if ($is_header): ?>
<b><?php echo htmlspecialchars($cell, ENT_QUOTES, 'UTF-8'); ?></b>
<?php else: ?>
<?php echo htmlspecialchars($cell, ENT_QUOTES, 'UTF-8'); ?>
<?php endif; ?>
</td>
<?php endforeach; ?>
<td>
<?php if (!$is_header && $pid > 0): ?>
<form method="post" action="./actions.php" style="display:inline-block">
<input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($_SESSION['csrf_token'], ENT_QUOTES, 'UTF-8'); ?>">
<input type="hidden" name="pid" value="<?php echo $pid; ?>">
<input type="hidden" name="action" value="kill_pid">
<button type="submit" class="btn btn-xs btn-danger"
onclick="return confirm('Kill process <?php echo $pid; ?>?')">
Kill
</button>
</form>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
</div>
</div>
<?php require_once('./include/footer.php'); ?>