Migrate translations to gettext

This commit is contained in:
2022-12-26 15:14:16 +01:00
parent e4c89f4baa
commit 14ef9100d5
37 changed files with 2511 additions and 757 deletions

View File

@ -1,33 +1,30 @@
<?php
require_once(__DIR__.'/../common_config.php');
global $language, $dir;
$style = '.red{color:red}.green{color:green}.software-link{text-align:center;font-size:small}.list{padding:0;}.list li{display:inline-block;padding:0.35em}';
send_headers([$style]);
$canonical_query = [];
if(!empty($_REQUEST['lang'])) {
$canonical_query['lang'] = $_REQUEST['lang'];
}
echo '<!DOCTYPE html><html lang="'.$language.'"><head>';
echo "<title>$I[testtitle]</title>";
echo '<!DOCTYPE html><html lang="'.$language.'" dir="'.$dir.'"><head>';
echo "<title>"._('Online-Test')."</title>";
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
echo '<meta name="author" content="Daniel Winzen">';
echo '<meta name="viewport" content="width=device-width, initial-scale=1">';
echo '<meta name="description" content="Test whether a Tor hidden service onion is online or offline">';
echo '<link rel="canonical" href="' . CANONICAL_URL . $_SERVER['SCRIPT_NAME'] . (empty($canonical_query) ? '' : '?' . http_build_query($canonical_query)) . '">';
echo '<style type="text/css">'.$style.'</style>';
echo '<link rel="canonical" href="' . CANONICAL_URL . $_SERVER['SCRIPT_NAME'] . '">';
echo '<style>'.$style.'</style>';
echo '</head><body><main>';
echo "<h1>$I[testtitle]</h1>";
echo "<h1>"._('Online-Test')."</h1>";
print_langs();
echo "<p>$I[testdesc]</p>";
echo "<p>"._('Here an onion address can be tested, for whether it is online or not.')."</p>";
echo "<form action=\"$_SERVER[SCRIPT_NAME]\" method=\"POST\">";
echo "<input type=\"hidden\" name=\"lang\" value=\"$language\">";
echo "<p><label for=\"addr\">$I[link]:</label><br><input id=\"addr\" name=\"addr\" size=\"30\" value=\"";
echo "<p><label for=\"addr\">"._('Onion link:')."</label><br><input id=\"addr\" name=\"addr\" size=\"30\" value=\"";
if(isset($_REQUEST['addr'])){
echo htmlspecialchars($_REQUEST['addr']);
}else{
echo "http://$_SERVER[HTTP_HOST]";
}
echo '" required></p>';
echo "<input type=\"submit\" name=\"action\" value=\"$I[test]\"></form><br>";
echo "<input type=\"submit\" name=\"action\" value=\""._('Test')."\"></form><br>";
if(!empty($_REQUEST['addr'])){
if(ob_get_level()>0){
ob_end_flush();
@ -36,15 +33,15 @@ if(!empty($_REQUEST['addr'])){
$db=new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME . ';charset=utf8mb4', DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]);
}catch(PDOException $e){
http_response_code(500);
die($I['nodb']);
die(_('No database connection!'));
}
if(!preg_match('~(^(https?://)?([a-z0-9]*\.)?([a-z2-7]{55}d)(\.onion(/.*)?)?$)~i', trim($_REQUEST['addr']), $addr)){
echo "<p class=\"red\" role=\"alert\">$I[invalonion]</p>";
echo "<p class=\"red\" role=\"alert\">"._('Invalid onion address!')."</p>";
}else{
$ch=curl_init();
set_curl_options($ch);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, "http://$addr[4].onion/");
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Host: $addr[4].onion", 'User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Firefox/68.0', 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language: en-US,en;q=0.5', 'Accept-Encoding: gzip, deflate', 'Connection: keep-alive', 'Upgrade-Insecure-Requests: 1']);
@ -54,17 +51,17 @@ if(!empty($_REQUEST['addr'])){
$phishing=$db->prepare('SELECT original FROM ' . PREFIX . 'phishing, ' . PREFIX . 'onions WHERE address=? AND onion_id=' . PREFIX . 'onions.id;');
$phishing->execute([$addr]);
if($orig=$phishing->fetch(PDO::FETCH_NUM)){
printf("<p class=\"red\" role=\"alert\">$I[testphishing]</p>", "<a href=\"http://$orig[0].onion\">$orig[0].onion</a>");
printf("<p class=\"red\" role=\"alert\">"._('Warning, this is a known phishing clone. The original site is located at %s.')."</p>", "<a href=\"http://$orig[0].onion\">$orig[0].onion</a>");
}
$scam=$db->prepare('SELECT null FROM ' . PREFIX . 'onions WHERE md5sum=? AND category=15 AND locked=1;');
$scam->execute([$md5]);
if($scam->fetch(PDO::FETCH_NUM)){
echo "<p class=\"red\" role=\"alert\">Warning: This is a known scam!</p>";
echo "<p class=\"red\" role=\"alert\">"._('Warning: This is a known scam!')."</p>";
}
$stmt=$db->prepare('SELECT null FROM ' . PREFIX . 'onions WHERE md5sum=? AND timediff=0 AND lasttest>?;');
$stmt->execute([$md5, time()-60]);
if($stmt->fetch(PDO::FETCH_NUM)){
echo "<p class=\"green\" role=\"alert\">$I[testonline]</p>";
echo "<p class=\"green\" role=\"alert\">"._('Yes, the service is online!')."</p>";
}elseif(($content=curl_exec($ch))!==false){
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($content, 0, $header_size);
@ -99,13 +96,13 @@ if(!empty($_REQUEST['addr'])){
}
blacklist_scams($addr, $content);
}
echo "<p class=\"green\" role=\"alert\">$I[testonline]</p>";
echo "<p class=\"green\" role=\"alert\">"._('Yes, the service is online!')."</p>";
}else{
if(isset($db)){
$time=time();
$db->prepare('UPDATE ' . PREFIX . 'onions SET lasttest=?, timediff=lasttest-lastup WHERE md5sum=? AND lasttest<?;')->execute([$time, $md5, $time]);
}
echo "<p class=\"red\" role=\"alert\">$I[testoffline]</p>";
echo "<p class=\"red\" role=\"alert\">"._('No, the service is offline!')."</p>";
}
curl_close($ch);
}