105 lines
2.9 KiB
PHP
105 lines
2.9 KiB
PHP
<?php
|
|
// --- Configurazione ---
|
|
$inputFile = __DIR__ . '../web_list.json';
|
|
$outputFile = __DIR__ . '../web_check.json';
|
|
$timeout = 10; // timeout connessioni in secondi
|
|
|
|
// --- Funzioni ---
|
|
function checkSSL($host, $timeout) {
|
|
$streamContext = stream_context_create([
|
|
"ssl" => ["capture_peer_cert" => true, "verify_peer" => true, "verify_peer_name" => true]
|
|
]);
|
|
|
|
$client = @stream_socket_client("ssl://$host:443", $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $streamContext);
|
|
|
|
if (!$client) {
|
|
return ["status" => false, "expiry" => null, "error" => $errstr];
|
|
}
|
|
|
|
$params = stream_context_get_params($client);
|
|
$cert = $params["options"]["ssl"]["peer_certificate"];
|
|
$cert_info = openssl_x509_parse($cert);
|
|
$expiry = date('Y-m-d H:i:s', $cert_info['validTo_time_t']);
|
|
|
|
// Controllo se scaduto
|
|
$isValid = time() < $cert_info['validTo_time_t'];
|
|
|
|
return ["status" => $isValid, "expiry" => $expiry, "error" => null];
|
|
}
|
|
|
|
function checkContent($host, $match, $user = null, $pass = null, $timeout = 10) {
|
|
$opts = ['http' => ['timeout' => $timeout]];
|
|
if ($user && $pass) {
|
|
$opts['http']['header'] = "Authorization: Basic " . base64_encode("$user:$pass");
|
|
}
|
|
$context = stream_context_create($opts);
|
|
$content = @file_get_contents("https://$host", false, $context);
|
|
|
|
if ($content === false) return false;
|
|
return strpos($content, $match) !== false;
|
|
}
|
|
|
|
// --- Leggi lista domini ---
|
|
if (!file_exists($inputFile)) {
|
|
die("File $inputFile non trovato.\n");
|
|
}
|
|
$domains = json_decode(file_get_contents($inputFile), true);
|
|
|
|
$results = [];
|
|
$totalSSLok = 0;
|
|
$totalContentOk = 0;
|
|
|
|
foreach ($domains as $entry) {
|
|
$host = $entry[0];
|
|
$domain = $entry[1];
|
|
$match = $entry[2];
|
|
$checkContentFlag = $entry[3];
|
|
|
|
// Leggi user/pass solo se flag true
|
|
$user = null;
|
|
$pass = null;
|
|
if ($checkContentFlag) {
|
|
$user = $entry[4] ?? null;
|
|
$pass = $entry[5] ?? null;
|
|
}
|
|
|
|
// --- SSL ---
|
|
$ssl = checkSSL($host, $timeout);
|
|
if ($ssl['status']) $totalSSLok++;
|
|
|
|
// --- Content ---
|
|
$contentOk = true;
|
|
if ($checkContentFlag) {
|
|
$contentOk = checkContent($host, $match, $user, $pass, $timeout);
|
|
if ($contentOk) $totalContentOk++;
|
|
}
|
|
|
|
// --- Tutto OK? ---
|
|
$allOk = $ssl['status'] && $contentOk;
|
|
|
|
// --- Salva risultato ---
|
|
$results[] = [
|
|
"host" => $host,
|
|
"domain" => $domain,
|
|
"ssl_status" => $ssl['status'],
|
|
"ssl_expiry" => $ssl['expiry'],
|
|
"content_match" => $contentOk,
|
|
"all_ok" => $allOk
|
|
];
|
|
}
|
|
|
|
// --- Salva JSON output ---
|
|
$output = [
|
|
"results" => $results,
|
|
"summary" => [
|
|
"total_ssl_ok" => $totalSSLok,
|
|
"total_content_ok" => $totalContentOk,
|
|
"total_checked" => count($domains)
|
|
]
|
|
];
|
|
|
|
file_put_contents($outputFile, json_encode($output, JSON_PRETTY_PRINT));
|
|
|
|
echo "Check completato. Risultati salvati in $outputFile\n";
|
|
?>
|