mirror of
https://github.com/pi-hole/web.git
synced 2026-04-28 04:33:58 +01:00
Major overhaul of update checker - checks only every 30 minutes to reduce number of GitHub API requests
This commit is contained in:
@@ -41,30 +41,6 @@
|
||||
</div>
|
||||
<!-- /.content-wrapper -->
|
||||
<footer class="main-footer">
|
||||
<?php
|
||||
// Check if on a dev branch
|
||||
$piholeBranch = exec("cd /etc/.pihole/ && git rev-parse --abbrev-ref HEAD");
|
||||
$webBranch = exec("git rev-parse --abbrev-ref HEAD");
|
||||
|
||||
// Use vDev if not on master
|
||||
if($piholeBranch !== "master") {
|
||||
$piholeVersion = "vDev";
|
||||
$piholeCommit = exec("cd /etc/.pihole/ && git describe --long --dirty --tags");
|
||||
}
|
||||
else {
|
||||
$piholeVersion = exec("cd /etc/.pihole/ && git describe --tags --abbrev=0");
|
||||
}
|
||||
|
||||
if($webBranch !== "master") {
|
||||
$webVersion = "vDev";
|
||||
$webCommit = exec("git describe --long --dirty --tags");
|
||||
}
|
||||
else {
|
||||
$webVersion = exec("git describe --tags --abbrev=0");
|
||||
}
|
||||
|
||||
$FTLVersion = exec("pihole-FTL version");
|
||||
?>
|
||||
<style type="text/css">
|
||||
@-webkit-keyframes Pulse{
|
||||
from {color:#630030;-webkit-text-shadow:0 0 9px #333;}
|
||||
@@ -77,10 +53,18 @@
|
||||
-webkit-animation-iteration-count: infinite;
|
||||
}
|
||||
</style>
|
||||
<div class="pull-right hidden-xs <?php if(isset($piholeCommit) || isset($webCommit)) { ?>hidden-md<?php } ?>">
|
||||
<b>Pi-hole Version </b> <span id="piholeVersion"><?php echo $piholeVersion; ?></span><?php if(isset($piholeCommit)) { echo " (".$piholeBranch.", ".$piholeCommit.")"; } ?>
|
||||
<b>Web Interface Version </b> <span id="webVersion"><?php echo $webVersion; ?></span><?php if(isset($webCommit)) { echo " (".$webBranch.", ".$webCommit.")"; } ?>
|
||||
<b>FTL Version </b> <span id="FTLVersion"><?php echo $FTLVersion; ?></span>
|
||||
<div class="pull-right hidden-xs <?php if(isset($core_commit) || isset($web_commit)) { ?>hidden-md<?php } ?>">
|
||||
<b>Pi-hole Version </b> <?php
|
||||
echo $core_current;
|
||||
if(isset($core_commit)) { echo " (".$core_branch.", ".$core_commit.")"; }
|
||||
if($core_update){ ?> <a class="alert-link lookatme" href="https://github.com/pi-hole/pi-hole/releases">(Update available!)</a><?php } ?>
|
||||
<b>Web Interface Version </b><?php
|
||||
echo $web_current;
|
||||
if(isset($web_commit)) { echo " (".$web_branch.", ".$web_commit.")"; }
|
||||
if($web_update){ ?> <a class="alert-link lookatme\" href="https://github.com/pi-hole/AdminLTE/releases">(Update available!)</a><?php } ?>
|
||||
<b>FTL Version </b> <?php
|
||||
echo $FTL_current;
|
||||
if($FTL_update){ ?> <a class="alert-link lookatme" href="https://github.com/pi-hole/FTL/releases">(Update available!)</a><?php } ?>
|
||||
</div>
|
||||
<div><a href="https://github.com/pi-hole" target="_blank"><i class="fa fa-github"></i></a> <strong><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3J2L3Z4DHW9UY" target="_blank">Donate</a></strong> if you found this useful.</div>
|
||||
</footer>
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<?php
|
||||
require "scripts/pi-hole/php/auth.php";
|
||||
require "scripts/pi-hole/php/password.php";
|
||||
require "scripts/pi-hole/php/update_checker.php";
|
||||
|
||||
check_cors();
|
||||
|
||||
@@ -264,12 +265,21 @@ if($auth) {
|
||||
<!-- Menu Footer -->
|
||||
<li class="user-footer">
|
||||
<!-- Update alerts -->
|
||||
<div id="alPiholeUpdate" class="alert alert-info alert-dismissible fade in" role="alert" hidden>
|
||||
<?php if($core_update){ ?>
|
||||
<div id="alPiholeUpdate" class="alert alert-info alert-dismissible fade in" role="alert">
|
||||
<a class="alert-link" href="https://github.com/pi-hole/pi-hole/releases">There's an update available for this Pi-hole!</a>
|
||||
</div>
|
||||
<div id="alWebUpdate" class="alert alert-info alert-dismissible fade in" role="alert" hidden>
|
||||
<?php } ?>
|
||||
<?php if($web_update){ ?>
|
||||
<div id="alWebUpdate" class="alert alert-info alert-dismissible fade in" role="alert">
|
||||
<a class="alert-link" href="https://github.com/pi-hole/AdminLTE/releases">There's an update available for this Web Interface!</a>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if($FTL_update){ ?>
|
||||
<div id="alFTLUpdate" class="alert alert-info alert-dismissible fade in" role="alert">
|
||||
<a class="alert-link" href="https://github.com/pi-hole/AdminLTE/releases">There's an update available for this FTL!</a>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<!-- PayPal -->
|
||||
<div>
|
||||
|
||||
118
scripts/pi-hole/php/update_checker.php
Normal file
118
scripts/pi-hole/php/update_checker.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
// Allow file_get_contents to read remote sources via URL
|
||||
ini_set("allow_url_fopen", 1);
|
||||
|
||||
// Function that grabs latest tag from GitHub
|
||||
function get_github_version($url)
|
||||
{
|
||||
// Have to fake the user agent to be able to query from Github's API
|
||||
$context = stream_context_create(array("http" => array("user_agent" => "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36")));
|
||||
|
||||
$json = file_get_contents($url, false, $context);
|
||||
$result = json_decode($json);
|
||||
|
||||
return $result->tag_name;
|
||||
}
|
||||
|
||||
/********** Get Pi-hole core branch / version / commit **********/
|
||||
// Check if on a dev branch
|
||||
$core_branch = exec("cd /etc/.pihole/ && git rev-parse --abbrev-ref HEAD");
|
||||
if($core_branch !== "master") {
|
||||
$core_current = "vDev";
|
||||
$core_commit = exec("cd /etc/.pihole/ && git describe --long --dirty --tags");
|
||||
}
|
||||
else {
|
||||
$core_current = exec("cd /etc/.pihole/ && git describe --tags --abbrev=0");
|
||||
}
|
||||
|
||||
/********** Get Pi-hole web branch / version / commit **********/
|
||||
$web_branch = exec("git rev-parse --abbrev-ref HEAD");
|
||||
if($web_branch !== "master") {
|
||||
$web_current = "vDev";
|
||||
$web_commit = exec("git describe --long --dirty --tags");
|
||||
}
|
||||
else {
|
||||
$web_current = exec("git describe --tags --abbrev=0");
|
||||
}
|
||||
|
||||
/********** Get Pi-hole FTL version (not a git repository) **********/
|
||||
$FTL_current = exec("pihole-FTL version");
|
||||
|
||||
// can write only in the root web dir, i.e. /var/www/html
|
||||
$versionfile = "../versions";
|
||||
|
||||
$check_version = false;
|
||||
|
||||
// Check version if version buffer file does not exist
|
||||
if(is_readable($versionfile))
|
||||
{
|
||||
// Obtain latest time stamp from buffer file
|
||||
$versions = explode(",",file_get_contents($versionfile));
|
||||
$date = date_create();
|
||||
$timestamp = date_timestamp_get($date);
|
||||
|
||||
// Is last check for updates older than 30 minutes?
|
||||
if($timestamp >= intval($versions[0]) + 1800)
|
||||
{
|
||||
// Yes: Retrieve new/updated version data
|
||||
$check_version = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No: We can use the buffered data
|
||||
$check_version = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// No buffer file or not readable: Request version data
|
||||
$check_version = true;
|
||||
}
|
||||
|
||||
// Get data from GitHub if requested
|
||||
if($check_version){
|
||||
$core_latest = get_github_version("https://api.github.com/repos/pi-hole/pi-hole/releases/latest");
|
||||
$web_latest = get_github_version("https://api.github.com/repos/pi-hole/AdminLTE/releases/latest");
|
||||
$FTL_latest = get_github_version("https://api.github.com/repos/pi-hole/FTL/releases/latest");
|
||||
|
||||
// Save to buffer file
|
||||
file_put_contents($versionfile, array($timestamp,",",$core_latest,",",$web_latest,",",$FTL_latest));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use data from buffer file
|
||||
$core_latest = $versions[1];
|
||||
$web_latest = $versions[2];
|
||||
$FTL_latest = $versions[3];
|
||||
}
|
||||
|
||||
// Core version comparison
|
||||
if($core_current !== "vDev")
|
||||
{
|
||||
// This logic allows the local core version to be newer than the upstream version
|
||||
// The update indicator is only shown if the upstream version is NEWER
|
||||
$core_update = (version_compare($core_current, $core_latest) < 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
$core_update = false;
|
||||
}
|
||||
|
||||
// Web version comparison
|
||||
if($web_current !== "vDev")
|
||||
{
|
||||
// This logic allows the local core version to be newer than the upstream version
|
||||
// The update indicator is only shown if the upstream version is NEWER
|
||||
$web_update = (version_compare($web_current, $web_latest) < 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
$web_update = false;
|
||||
}
|
||||
|
||||
// FTL version comparison
|
||||
// This logic allows the local core version to be newer than the upstream version
|
||||
// The update indicator is only shown if the upstream version is NEWER
|
||||
$FTL_update = (version_compare($FTL_current, $FTL_latest) < 0);
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user