Skip to content

Commit

Permalink
Update TLD list via cron (#1643)
Browse files Browse the repository at this point in the history
Co-authored-by: Nabeel S <nabeelio@users.noreply.github.com>
  • Loading branch information
arthurpar06 and nabeelio authored Oct 30, 2023
1 parent e0d4fa0 commit 64db89a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/Listeners/TLDUpdater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Listeners;

use App\Events\CronWeekly;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;

class TLDUpdater
{
public function handle(CronWeekly $event): void
{
$response = Http::get(config('phpvms.tld_list_url'));

if ($response->successful()) {
Log::info('Updating TLD list');

$filePath = resource_path('tld/public_suffix_list.dat');

file_put_contents($filePath, $response->body());
} else {
Log::error('Unable to update TLD list, Error: '.$response->body());
}
}
}
6 changes: 6 additions & 0 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Providers;

use App\Events\CronWeekly;
use App\Events\Expenses;
use App\Events\Fares;
use App\Events\PirepFiled;
Expand All @@ -15,6 +16,7 @@
use App\Listeners\FinanceEventHandler;
use App\Listeners\MessageLoggedListener;
use App\Listeners\PirepEventsHandler;
use App\Listeners\TLDUpdater;
use App\Listeners\UserStateListener;
use App\Notifications\NotificationEventsHandler;
use Illuminate\Auth\Events\Registered;
Expand All @@ -25,6 +27,10 @@
class EventServiceProvider extends ServiceProvider
{
protected $listen = [
CronWeekly::class => [
TLDUpdater::class,
],

Expenses::class => [
ExpenseListener::class,
],
Expand Down
5 changes: 5 additions & 0 deletions config/phpvms.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
*/
'distrib_url' => 'http://downloads.phpvms.net/phpvms-{VERSION}.zip',

/**
* The URL to download the latest TLD list
*/
'tld_list_url' => 'https://publicsuffix.org/list/public_suffix_list.dat',

/*
* Where the KVP file is stored
*/
Expand Down

0 comments on commit 64db89a

Please sign in to comment.