lots of progress
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class PortScannerController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('port-scanner.index');
|
||||
}
|
||||
|
||||
public function scan(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'ip' => 'required|ip',
|
||||
'port' => 'required|integer|min:1|max:65535',
|
||||
]);
|
||||
|
||||
$ip = $request->input('ip');
|
||||
$port = $request->input('port');
|
||||
$timeout = 2; // Timeout in seconds
|
||||
|
||||
try {
|
||||
$startTime = microtime(true);
|
||||
$connection = @fsockopen($ip, $port, $errno, $errstr, $timeout);
|
||||
$endTime = microtime(true);
|
||||
$responseTime = round(($endTime - $startTime) * 1000, 2); // Convert to milliseconds
|
||||
|
||||
if ($connection) {
|
||||
fclose($connection);
|
||||
$status = 'open';
|
||||
$message = "Port $port is open on $ip";
|
||||
} else {
|
||||
$status = 'closed';
|
||||
$message = "Port $port is closed on $ip";
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'status' => $status,
|
||||
'message' => $message,
|
||||
'response_time' => $responseTime,
|
||||
'ip' => $ip,
|
||||
'port' => $port
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Port scan error', [
|
||||
'ip' => $ip,
|
||||
'port' => $port,
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'An error occurred while scanning the port',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\ProxyService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ProxyController extends Controller
|
||||
{
|
||||
protected $proxyService;
|
||||
|
||||
public function __construct(ProxyService $proxyService)
|
||||
{
|
||||
$this->proxyService = $proxyService;
|
||||
}
|
||||
|
||||
public function home()
|
||||
{
|
||||
return view('proxy.home');
|
||||
}
|
||||
|
||||
public function browse(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'url' => 'required'
|
||||
]);
|
||||
|
||||
try {
|
||||
// Decode the URL if it's base64 encoded
|
||||
$url = $request->url;
|
||||
if (base64_encode(base64_decode($url, true)) === $url) {
|
||||
// Decode base64 and then URL decode
|
||||
$url = urldecode(base64_decode($url));
|
||||
}
|
||||
|
||||
// Log the URL processing
|
||||
\Log::info('Processing URL', [
|
||||
'original' => $request->url,
|
||||
'decoded' => $url
|
||||
]);
|
||||
|
||||
// Validate the decoded URL
|
||||
if (!filter_var($url, FILTER_VALIDATE_URL)) {
|
||||
throw new \Exception('Invalid URL format: ' . $url);
|
||||
}
|
||||
|
||||
$content = $this->proxyService->fetchUrl($url);
|
||||
|
||||
// Get content type from response
|
||||
$contentType = $this->proxyService->getLastContentType();
|
||||
|
||||
// Log the content type for debugging
|
||||
\Log::info('Content type received', [
|
||||
'url' => $url,
|
||||
'content_type' => $contentType,
|
||||
'is_css' => strpos($contentType, 'text/css') !== false ||
|
||||
strpos($contentType, 'application/css') !== false ||
|
||||
strpos($url, '.css') !== false
|
||||
]);
|
||||
|
||||
// If it's a CSS file, serve it with the correct content type
|
||||
if (strpos($contentType, 'text/css') !== false ||
|
||||
strpos($contentType, 'application/css') !== false ||
|
||||
strpos($url, '.css') !== false) {
|
||||
|
||||
\Log::info('Serving CSS file', [
|
||||
'url' => $url,
|
||||
'content_type' => $contentType,
|
||||
'content_length' => strlen($content)
|
||||
]);
|
||||
|
||||
return response($content)
|
||||
->header('Content-Type', 'text/css')
|
||||
->header('Cache-Control', 'public, max-age=3600')
|
||||
->header('Access-Control-Allow-Origin', '*')
|
||||
->header('X-Content-Type-Options', 'nosniff');
|
||||
}
|
||||
|
||||
// For HTML content, return the view
|
||||
return view('proxy.browse', [
|
||||
'url' => $url,
|
||||
'content' => $content
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('Proxy error', [
|
||||
'url' => $request->url,
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
return back()->withErrors(['url' => 'Failed to fetch URL: ' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,17 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Proxy;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ProxyListController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('proxies.index');
|
||||
$proxies = Proxy::orderBy('score', 'desc')
|
||||
->orderBy('last_tested_at', 'desc')
|
||||
->paginate(20);
|
||||
|
||||
return view('proxies.index', compact('proxies'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user