Skip to content

Commit

Permalink
check for latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
pentium10 committed Feb 16, 2014
1 parent 1ea2759 commit 39a3c15
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 48 deletions.
9 changes: 8 additions & 1 deletion config.php
@@ -1,9 +1,16 @@
<?php

$config = array(
/**
* List of servers available for all users
*/
'servers' => array(/* 'localhost:11300' */),
/**
* Saved samples jobs are kept in this file, must be writable
*/
'storage' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'storage.json'
'storage' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'storage.json',
/**
* Version number
*/
'version' => '1.4',
);
5 changes: 5 additions & 0 deletions lib/include.php
Expand Up @@ -207,6 +207,11 @@ protected function __init() {
$this->servers[] = $server;
}
}
try {
$storage = new Storage($config['storage']);
} catch (Exception $ex) {
$this->_errors[] = $ex->getMessage();
}
}

public function getErrors() {
Expand Down
121 changes: 77 additions & 44 deletions lib/tpl/serversList.php
Expand Up @@ -14,39 +14,40 @@
);
}
?>
<?php if(!empty($servers)):?>
<?php if (!empty($servers)): ?>
<table class="table table-striped table-hover" id="servers-index">
<thead>
<tr>
<th>name</th>
<?php foreach($console->getServerStats(reset($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?>
<?php foreach ($console->getServerStats(reset($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>&nbsp;</th>
</tr>
</thead>
<tbody>
<?php foreach($servers as $server):
$stats = $console->getServerStats($server);
?>
<?php
foreach ($servers as $server):
$stats = $console->getServerStats($server);
?>
<tr>
<?php if(empty($stats)):?>
<td><?php echo $server?></td>
<?php else:?>
<td><a href="?server=<?php echo $server?>"><?php echo $server?></a></td>
<?php endif?>
<?php foreach($stats as $key => $item):?>
<td class="<?php if(!in_array($key, $visible)) echo 'hide'?>" 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">&nbsp;</td>
<?php endif?>
<td><a class="btn btn-small" title="Remove from list" href="?action=serversRemove&removeServer=<?php echo $server?>"><span class="icon-minus"></span></a></td>
<?php if (empty($stats)): ?>
<td><?php echo $server ?></td>
<?php else: ?>
<td><a href="?server=<?php echo $server ?>"><?php echo $server ?></a></td>
<?php endif ?>
<?php foreach ($stats as $key => $item): ?>
<td class="<?php if (!in_array($key, $visible)) echo 'hide' ?>" 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">&nbsp;</td>
<?php endif ?>
<td><a class="btn btn-small" title="Remove from list" href="?action=serversRemove&removeServer=<?php echo $server ?>"><span class="icon-minus"></span></a></td>
</tr>
<?php endforeach?>
<?php endforeach ?>
</tbody>
</table>
<?php else:?>
<?php else: ?>
<div class="page-header">
<h1 class="text-info">Hello!</h1>
</div>
Expand All @@ -56,15 +57,41 @@
</p>
<p>
Your servers' list is empty. You could fix it in two ways:
<ol>
<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>
<ol>
<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>
<?php endif?>
<?php endif ?>

<br /><a href="#servers-add" role="button" class="btn btn-info" data-toggle="modal">Add server</a>
<?php
$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
}
}
?>
<div id="servers-add" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="servers-add-label" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
Expand All @@ -81,7 +108,7 @@
<div class="control-group">
<label class="control-label" for="port">Port</label>
<div class="controls">
<input type="text" id="port" value="<?php echo Pheanstalk::DEFAULT_PORT?>">
<input type="text" id="port" value="<?php echo Pheanstalk::DEFAULT_PORT ?>">
</div>
</div>
</form>
Expand All @@ -101,26 +128,32 @@
<form>
<div class="tabbable">
<ul class="nav nav-tabs">
<?php $i=0; foreach($console->getServerStatsGroups() as $groupName => $fields): $i++;?>
<li <?php if($i==1) echo 'class="active"'?>><a href="#<?php echo $groupName?>" data-toggle="tab"><?php echo $groupName?></a></li>
<?php endforeach?>
<?php
$i = 0;
foreach ($console->getServerStatsGroups() as $groupName => $fields): $i++;
?>
<li <?php if ($i == 1) echo 'class="active"' ?>><a href="#<?php echo $groupName ?>" data-toggle="tab"><?php echo $groupName ?></a></li>
<?php endforeach ?>
</ul>
<div class="tab-content">
<?php $i=0; foreach($console->getServerStatsGroups() as $groupName => $fields): $i++;?>
<div class="tab-pane <?php if($i==1) echo 'active'?>" id="<?php echo $groupName?>">
<?php foreach($fields as $key => $description):?>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" name="<?php echo $key?>" <?php if(in_array($key, $visible)) echo 'checked="checked"'?>>
<b><?php echo $key?></b>
<br /><?php echo $description?>
</label>
<?php
$i = 0;
foreach ($console->getServerStatsGroups() as $groupName => $fields): $i++;
?>
<div class="tab-pane <?php if ($i == 1) echo 'active' ?>" id="<?php echo $groupName ?>">
<?php foreach ($fields as $key => $description): ?>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" name="<?php echo $key ?>" <?php if (in_array($key, $visible)) echo 'checked="checked"' ?>>
<b><?php echo $key ?></b>
<br /><?php echo $description ?>
</label>
</div>
</div>
</div>
<?php endforeach?>
</div>
<?php endforeach?>
<?php endforeach ?>
</div>
<?php endforeach ?>
</div>
</div>
</form>
Expand Down
6 changes: 3 additions & 3 deletions src/Storage.php
Expand Up @@ -21,13 +21,13 @@ function __construct($config) {

public function isAvailable() {
if (!is_file($this->file)) {
$this->error = "The given storage file doesn't exists: $this->file";
$this->error = "Please create the storage file, it must be writable: $this->file";
return false;
}
if (!is_writable($this->file)) {
chmod($this->file, '0755');
@chmod($this->file, '0755');
if (!is_writable($this->file)) {
$this->error = "The given storage file is not writable: $this->file";
$this->error = "Please make the storage file writable: $this->file";
return false;
}
}
Expand Down

0 comments on commit 39a3c15

Please sign in to comment.