From 4782b1362fd1b4f3269d9b15bceccf06f9279be3 Mon Sep 17 00:00:00 2001 From: Davide Aprea <davide@suma-ev.de> Date: Thu, 25 Feb 2021 16:05:15 +0100 Subject: [PATCH] add controller to send searx request --- app/Http/Controllers/SearxProxy.php | 27 +++++++++++++++++++++++++++ routes/web.php | 5 ++--- 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 app/Http/Controllers/SearxProxy.php diff --git a/app/Http/Controllers/SearxProxy.php b/app/Http/Controllers/SearxProxy.php new file mode 100644 index 0000000..c5ed555 --- /dev/null +++ b/app/Http/Controllers/SearxProxy.php @@ -0,0 +1,27 @@ +<?php + +namespace App\Http\Controllers; + +use Illuminate\Http\Request; + +class SearxProxy extends Controller +{ + public function search(Request $request) { + $search = $request->input('search'); + + $instances = file('/html/storage/instances.txt'); + $host = $instances[rand(1,sizeof($instances))]; + $url = trim($host) . '?q=' . $search . '&format=json'; + + //dd($url); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_HEADER, FALSE); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); + $response = curl_exec($ch); + curl_close($ch); + dd($host, json_decode($response), $response); + } +} diff --git a/routes/web.php b/routes/web.php index b130397..b1ad391 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,6 +1,7 @@ <?php use Illuminate\Support\Facades\Route; +use App\Http\Controllers\SearxProxy; /* |-------------------------------------------------------------------------- @@ -13,6 +14,4 @@ use Illuminate\Support\Facades\Route; | */ -Route::get('/', function () { - return view('welcome'); -}); +Route::get('/', [SearxProxy::class, 'search']); \ No newline at end of file -- GitLab