/
serversList.php
140 lines (133 loc) · 6.2 KB
/
serversList.php
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
$servers = $console->getServers();
$cookieServers = $console->getServersCookie();
if (!empty($_COOKIE['filter'])) {
$visible = explode(',', $_COOKIE['filter']);
} else {
$visible = array(
'current-jobs-urgent',
'current-jobs-ready',
'current-jobs-reserved',
'current-jobs-delayed',
'current-jobs-buried',
'current-tubes',
'current-connections',
);
}
?>
<?php
if (!empty($servers)):
$servers = array_filter(array_unique($servers));
?>
<div class="row">
<div class="col-sm-12">
<table class="table table-striped table-hover" id="servers-index">
<thead>
<tr>
<th>name</th>
<?php foreach ($console->getServerStats(current($servers)) as $key => $item): ?>
<th class="<?php if (!in_array($key, $visible)) echo 'hide' ?>" name="<?php echo $key ?>"
title="<?php echo $item['description'] ?>"><?php echo $key ?></th>
<?php endforeach ?>
<th> </th>
</tr>
</thead>
<tbody>
<?php
foreach ($servers as $key => $server):
$stats = $console->getServerStats($server);
$label = $key;
if (empty($label) || is_numeric($label)) {
$label = $server;
}
?>
<tr>
<?php if (empty($stats)): ?>
<td style="white-space: nowrap;"><?php echo htmlspecialchars($label) ?></td>
<?php else: ?>
<td style="white-space: nowrap;"><a href="./?server=<?php echo htmlspecialchars($server) ?>"><?php echo htmlspecialchars($label); ?></a></td>
<?php endif ?>
<?php foreach ($stats as $key => $item): ?>
<?php
$classes = array("td-$key");
if (!in_array($key, $visible)) {
$classes[] = 'hide' ;
}
if (isset($stats[$key]) && $stats[$key] != '0') {
$classes[] = 'hasValue';
}
$cssClass = '' ;
if (count($classes) > 0) {
$cssClass = ' class = "' . join(' ', $classes) . '"' ;
}
?>
<td <?php echo $cssClass; ?>
name="<?php echo $key ?>"><?php echo htmlspecialchars($item['value']) ?></td>
<?php endforeach ?>
<?php if (empty($stats)): ?>
<td colspan="<?php echo count($visible) ?>" class="row-full"> </td>
<?php endif ?>
<td><?php if (array_intersect(array($server), $cookieServers)): ?>
<a class="btn btn-xs btn-danger" title="Remove from list" href="./?action=serversRemove&removeServer=<?php echo htmlspecialchars($server) ?>"><span
class="glyphicon glyphicon-minus"></span></a>
<?php endif; ?>
</td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<a href="#servers-add" role="button" class="btn btn-info" id="addServer">Add server</a>
</div>
</div>
<?php else: ?>
<div class="site-wrapper">
<div class="site-wrapper-inner">
<div class="col-sm-8 col-sm-push-2 text-center">
<h1>Hello!</h1>
<p class="lead">
This is Beanstalk console,<br/>web-interface for
<a href="http://kr.github.io/beanstalkd/" target="_blank">simple and fast work queue</a>
</p>
<p>
Your servers' list is empty. You could fix it in two ways:
<ol class="inside">
<li>Click the button below to add server just for you and save it in cookies</li>
<li>Edit <b>config.php</b> file and add server for everybody</li>
</ol>
</p>
<p>
<br/><a href="#servers-add" role="button" class="btn btn-lg btn-success" data-toggle="modal">Add server</a>
</p>
</div>
</div>
</div>
<?php
endif;
if ($tplVars['_tplMain'] != 'ajax') {
$url = 'https://api.github.com/repos/ptrofimov/beanstalk_console/tags';
$ctx = stream_context_create(
array('http' => array(
'timeout' => 2,
'header' => "Accept-language: en\r\n" .
"Cookie: foo=bar\r\n" . // check function.stream-context-create on php.net
"User-Agent: " . $_SERVER['HTTP_USER_AGENT'] . "\r\n" .
"Accept: application/vnd.github.v3+json\r\n",
)
));
$json = @file_get_contents($url, false, $ctx);
if ($json) {
$document = json_decode($json, true);
$latest = current($document);
$version = @$latest['name'];
if (version_compare($version, $config['version']) > 0) {
?>
<br/>
<div class="alert alert-info" style="position: relative;top:50px;">
<span>A new version is available: <b><?php echo $version; ?></b> Get it from <b><a href="https://github.com/ptrofimov/beanstalk_console"
target="_blank">Github</a></b></span>
</div>
<?php
}
}
}
?>