Enabled version update check

This commit is contained in:
Deon George 2023-03-03 16:07:11 +11:00
parent 08678ce929
commit 7458001f5a
2 changed files with 41 additions and 7 deletions

View File

@ -3,11 +3,15 @@
namespace App\Http\Middleware; namespace App\Http\Middleware;
use Closure; use Closure;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
class CheckUpdate class CheckUpdate
{ {
private const UPDATE_SERVER = 'https://version.phpldapadmin.org';
private const UPDATE_TIME = 60*60*6;
/** /**
* Handle an incoming request. * Handle an incoming request.
* *
@ -17,23 +21,35 @@ class CheckUpdate
*/ */
public function handle($request, Closure $next) public function handle($request, Closure $next)
{ {
\Config::set('update_available',Cache::get('upstream_version'));
return $next($request); return $next($request);
} }
/** /**
* Handle tasks after the response has been sent to the browser. * Handle tasks after the response has been sent to the browser.
* *
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Http\Response $response
* @return void * @return void
*/ */
public function terminate($request, $response) public function terminate()
{ {
Cache::remember('version',60*5,function() { Cache::remember('upstream_version',self::UPDATE_TIME,function() {
// CURL call to URL to see if there is a new version // CURL call to URL to see if there is a new version
Log::debug(sprintf('Checking for updates for [%s]',config('app.version'))); Log::debug(sprintf('CU_:Checking for updates for [%s]',config('app.version')));
return TRUE; $client = new Client;
$response = $client->request('POST',sprintf('%s/%s',self::UPDATE_SERVER,strtolower(config('app.version'))));
if ($response->getStatusCode() === 200) {
$result = json_decode($response->getBody());
Log::debug(sprintf('CU_:- Update server returned...'),['update'=>$result]);
return $result;
}
return NULL;
}); });
} }
} }

View File

@ -3,9 +3,27 @@
<div class="app-footer__inner"> <div class="app-footer__inner">
<div class="app-footer-left"> <div class="app-footer-left">
<ul class="nav"> <ul class="nav">
<li> <li class="nav-item">
<strong>{{ config('app.version') }}</strong> <strong>{{ config('app.version') }}</strong>
</li> </li>
@if(($x=Config::get('update_available')) && $x->action !== 'current')
<li class="nav-item ml-2">
@switch($x->action)
@case('unable')
<abbr title="Upstream Version Unavailable"><i class="fas fa-exclamation text-alternate"></i></abbr>
@break
@case('upgrade')
<abbr title="Update Available: {{ $x->version }}"><i class="fas fa-wrench text-danger"></i></abbr>
@break
@case('mismatch')
<abbr title="Version Issue - Upstream {{ $x->version }}"><i class="fas fa-exclamation text-danger"></i></abbr>
@break
@case('unknown')
<abbr title="Version Issue - Upstream {{ $x->version }}"><i class="fas fa-bolt text-alternate"></i></abbr>
@break
@endswitch
</li>
@endif
{{-- {{--
<li class="nav-item"> <li class="nav-item">
<a href="javascript:void(0);" class="nav-link">Footer Link</a> <a href="javascript:void(0);" class="nav-link">Footer Link</a>