Comments (2)
`
class Updater
{
const GEOLITE2_URL_BASE = 'GeoLite2-City';
protected $databaseFileGzipped;
protected $databaseFile;
protected $md5File;
protected $messages = [];
/**
* Add a message.
*
* @param $string
*/
private function addMessage($string)
{
$this->messages[] = $string;
}
protected function databaseIsUpdated($geoDbFileUrl, $geoDbMd5Url, $destinationPath)
{
$destinationGeoDbFile = $this->removeGzipExtension($destinationPath . DIRECTORY_SEPARATOR . basename($geoDbFileUrl));
$this->md5File = base_path("config\geoip\GeoLite2-City.md5");
if (!file_exists($destinationGeoDbFile)) {
return false;
}
if ($updated = file_get_contents($this->md5File) == md5_file($destinationGeoDbFile)) {
$this->addMessage('Database is already updated.');
}
return $updated;
}
/**
* Download gzipped database, unzip and check md5.
*
* @param $destinationPath
* @param $geoDbUrl
* @return bool
*/
protected function downloadGzipped($destinationPath, $geoDbUrl)
{
if (!$this->databaseFileGzipped = $this->getHTTPFile($geoDbUrl, ($destination = $destinationPath . DIRECTORY_SEPARATOR))) {
$this->addMessage("Unable to download file {$geoDbUrl} to {$destination}.");
}
$this->databaseFile = $this->dezipGzFile($destinationPath . DIRECTORY_SEPARATOR . basename($geoDbUrl));
return $this->md5Match();
}
private function getDbFileName($geoDbUrl)
{
return $geoDbUrl ?: static::GEOLITE2_URL_BASE . '.mmdb.gz';
}
private function getMd5FileName($geoDbMd5Url)
{
return $geoDbMd5Url ?: static::GEOLITE2_URL_BASE . '.md5';
}
/**
* Get messages.
*
* @return mixed
*/
public function getMessages()
{
return $this->messages;
}
/**
* Make directory.
*
* @param $destinationPath
* @return bool
*/
protected function makeDir($destinationPath)
{
return file_exists($destinationPath) || mkdir($destinationPath, 0770, true);
}
/**
* Compare MD5s.
*
* @return bool
*/
private function md5Match()
{
try {
if (!$match = md5_file($this->databaseFile) == file_get_contents($this->md5File)) {
$this->addMessage("MD5 is not matching for {$this->databaseFile} and {$this->md5File}.");
return false;
}
} catch (Exception $e) {
echo $e;
}
$this->addMessage("Database successfully downloaded to {$this->databaseFile}.");
return true;
}
/**
* Remove .gzip extension from file.
*
* @param $filePath
* @return mixed
*/
protected function removeGzipExtension($filePath)
{
return str_replace('.gz', '', $filePath);
}
/**
* Download and update GeoIp database.
*
* @param $destinationPath
* @param null $geoDbUrl
* @param null $geoDbMd5Url
* @return bool
*/
public function updateGeoIpFiles($destinationPath, $geoDbUrl = null, $geoDbMd5Url = null)
{
if ($this->databaseIsUpdated($geoDbUrl = $this->getDbFileName($geoDbUrl), $this->getMd5FileName($geoDbMd5Url), $destinationPath)) {
return true;
}
if ($this->downloadGzipped($destinationPath, $geoDbUrl)) {
return true;
}
$this->addMessage("Unknown error downloading {$geoDbUrl}.");
return false;
}
/**
* Read url to file.
*
* @param $uri
* @param $destinationPath
* @return bool|string
*/
protected function getHTTPFile($uri, $destinationPath)
{
set_time_limit(360);
if (!$this->makeDir($destinationPath)) {
return false;
}
$fileWriteName = $destinationPath . basename($uri);
if (($fileRead = @fopen($uri, "rb")) === false || ($fileWrite = @fopen($fileWriteName, 'wb')) === false) {
$this->addMessage("Unable to open {$uri} (read) or {$fileWriteName} (write).");
return false;
}
while (!feof($fileRead)) {
$content = @fread($fileRead, 1024 * 16);
$success = fwrite($fileWrite, $content);
if ($success === false) {
$this->addMessage("Error downloading file {$uri} to {$fileWriteName}.");
return false;
}
}
fclose($fileWrite);
fclose($fileRead);
return $fileWriteName;
}
/**
* Extract gzip file.
*
* @param $filePath
* @return bool|mixed
*/
protected function dezipGzFile($filePath)
{
$buffer_size = 8192; // read 8kb at a time
$out_file_name = $this->removeGzipExtension($filePath);
$fileRead = gzopen($filePath, 'rb');
$fileWrite = fopen($out_file_name, 'wb');
if ($fileRead === false || $fileWrite === false) {
$this->addMessage("Unable to extract gzip file {$filePath} to {$out_file_name}.");
return false;
}
while (!gzeof($fileRead)) {
$success = fwrite($fileWrite, gzread($fileRead, $buffer_size));
if ($success === false) {
$this->addMessage("Error degzipping file {$filePath} to {$out_file_name}.");
return false;
}
}
// Files are done, close files
fclose($fileWrite);
gzclose($fileRead);
return $out_file_name;
}
`
Change Updater.php file with this code,
the problem because they try to download a file called "GeoLite2-City" and extract that and check md5,
but the file can't download it now so it get error
from tracker.
Same issue here, been tried @gor3a 's Solution, but still, there's an issue. Check out my image below:
Any solution?
FYI: That GeoLite2-City.tar.gz file I add is just in case the original file is broken, I get a mirror version from the original link inside updater.php file
from tracker.
Related Issues (20)
- Non-static method should not be called statically HOT 1
- Session.user_id is set to null when the user logout
- Error in Laravel 8 migration problem, There is no active transaction HOT 13
- Tracker::logByRouteName returns 0 for multiple parameters
- Issue “Module 'PDO' already loaded”
- This project is still maintained? HOT 3
- Requirements are not Satisfied HOT 7
- Publish view templates for editing
- Using $this when not in object context HOT 2
- Update Laravel version
- Update tracker for Laravel 9
- PHP 8.1 is not working HOT 1
- Add support for PHP 8.x and new Laravel version HOT 8
- Tracker hacker
- Find
- Request for Laravel v10.x support HOT 2
- It does not install on Laravel 10.10 & PHP 8.1
- 大佬, 目前不支持 PHP 8以上的版本 HOT 1
- Versions of PHP 8 and above are not currently supported
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tracker.