2023-03-01 22:55:33 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Closure;
|
2023-03-03 05:07:11 +00:00
|
|
|
use GuzzleHttp\Client;
|
2023-03-01 22:55:33 +00:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
class CheckUpdate
|
|
|
|
{
|
2023-03-03 05:07:11 +00:00
|
|
|
private const UPDATE_SERVER = 'https://version.phpldapadmin.org';
|
|
|
|
private const UPDATE_TIME = 60*60*6;
|
|
|
|
|
2023-03-01 22:55:33 +00:00
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Closure $next
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle($request, Closure $next)
|
|
|
|
{
|
2023-03-03 05:07:11 +00:00
|
|
|
\Config::set('update_available',Cache::get('upstream_version'));
|
|
|
|
|
2023-03-01 22:55:33 +00:00
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle tasks after the response has been sent to the browser.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2023-03-03 05:07:11 +00:00
|
|
|
public function terminate()
|
2023-03-01 22:55:33 +00:00
|
|
|
{
|
2023-03-03 05:07:11 +00:00
|
|
|
Cache::remember('upstream_version',self::UPDATE_TIME,function() {
|
2023-03-01 22:55:33 +00:00
|
|
|
// CURL call to URL to see if there is a new version
|
2023-03-03 05:07:11 +00:00
|
|
|
Log::debug(sprintf('CU_:Checking for updates for [%s]',config('app.version')));
|
|
|
|
|
|
|
|
$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;
|
|
|
|
}
|
2023-03-01 22:55:33 +00:00
|
|
|
|
2023-03-03 05:07:11 +00:00
|
|
|
return NULL;
|
2023-03-01 22:55:33 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|