Skip to content
Snippets Groups Projects
Commit 83ed36c1 authored by Davide Aprea's avatar Davide Aprea
Browse files

add command to generate a list of instances

parent 247d967e
No related branches found
No related tags found
1 merge request!1Development
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
/public/hot /public/hot
/public/storage /public/storage
/storage/*.key /storage/*.key
/storage/instances.txt
/vendor /vendor
.env .env
.env.backup .env.backup
......
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class SearxInstances extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'instances:load';
/**
* The console command description.
*
* @var string
*/
protected $description = 'loads a list of running searx instances ( https://searx.space )';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://searx.space/data/instances.json');
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close($ch);
$response = json_decode($response);
if($response !== null){
$f = fopen('storage/instances.txt', 'w');
foreach($response->instances as $instance => $data) {
if(!isset($data->{'error'}) && $data->{'network_type'} !== 'tor') {
fwrite($f, $instance . "\n");
}
}
fclose($f);
} else {
echo "Unable to locate file. Check https://searx.space/data/instances.json for more info\n";
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment