Prefer single quotes to reduce amount of escaping necessary

This commit is contained in:
2022-12-28 00:26:40 +01:00
parent aa5264cd3b
commit aae719d025
13 changed files with 341 additions and 150 deletions

View File

@ -4,7 +4,7 @@ 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]);
echo '<!DOCTYPE html><html lang="'.$language.'" dir="'.$dir.'"><head>';
echo "<title>"._('Online-Test')."</title>";
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">';
@ -14,19 +14,19 @@ echo '<link rel="alternate" href="' . CANONICAL_URL . $_SERVER['SCRIPT_NAME'] .
alt_links();
echo '<style>'.$style.'</style>';
echo '</head><body><main>';
echo "<h1>"._('Online-Test')."</h1>";
echo '<h1>'._('Online-Test').'</h1>';
print_langs();
echo "<p>"._('Test whether a Tor hidden service onion is online or offline')."</p>";
echo "<form action=\"$_SERVER[SCRIPT_NAME]\" method=\"POST\">";
echo "<input type=\"hidden\" name=\"lang\" value=\"$language\">";
echo "<p><label for=\"addr\">"._('Onion link:')."</label><br><input id=\"addr\" name=\"addr\" size=\"30\" value=\"";
echo '<p>'._('Test whether a Tor hidden service onion is online or offline')."</p>";
echo '<form action="'.$_SERVER['SCRIPT_NAME'].'" method="POST">';
echo '<input type="hidden" name="lang" value="'.$language.'">';
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=\""._('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();
@ -38,7 +38,7 @@ if(!empty($_REQUEST['addr'])){
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\">"._('Invalid onion address!')."</p>";
echo '<p class="red" role="alert">'._('Invalid onion address!').'</p>';
}else{
$ch=curl_init();
set_curl_options($ch);
@ -53,17 +53,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\">"._('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>");
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\">"._('Yes, the service is online!')."</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);
@ -98,13 +98,13 @@ if(!empty($_REQUEST['addr'])){
}
blacklist_scams($addr, $content);
}
echo "<p class=\"green\" role=\"alert\">"._('Yes, the service is online!')."</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\">"._('No, the service is offline!')."</p>";
echo '<p class="red" role="alert">'._('No, the service is offline!').'</p>';
}
curl_close($ch);
}