diff --git a/common_config.php b/common_config.php
index e5541b9..ea46085 100644
--- a/common_config.php
+++ b/common_config.php
@@ -35,6 +35,7 @@ const PER_PAGE = 50; // Sites listed per page
const VERSION = '1.1'; // Script version
const DBVERSION = 6; // Database layout version
const REQUIRE_APPROVAL = false; // require admin approval of new sites? true/false
+const CANONICAL_URL = 'https://onions.danwin1210.me'; // our preferred domain for search engines
//Categories - new links will always be put into the first one, leave it to Unsorted
//once configured, only add new categories at the end or you have to manually adjust the database.
$categories=['Unsorted', 'Adult/Porn', 'Communication/Social', 'Forums', 'Hacking/Programming/Software', 'Hosting', 'Libraries/Wikis', 'Link Lists', 'Market/Shop/Store', 'Other', 'Personal Sites/Blogs', 'Security/Privacy/Encryption', 'Whistleblowing', 'Empty/Error/Unknown', 'Cryptocurrencies', 'Scams', 'Fun/Games/Joke', 'Search', 'Autodetected scam (unchecked)'];
diff --git a/www/admin.php b/www/admin.php
index 71c4550..0866625 100644
--- a/www/admin.php
+++ b/www/admin.php
@@ -5,6 +5,7 @@ send_headers([$style]);
try{
$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_send_status(500);
die($I['nodb']);
}
asort($categories);
@@ -14,6 +15,7 @@ asort($categories);
+
diff --git a/www/onions.php b/www/onions.php
index 2931776..045172f 100644
--- a/www/onions.php
+++ b/www/onions.php
@@ -25,6 +25,7 @@ require_once(__DIR__.'/../common_config.php');
try{
$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_send_status(500);
}
date_default_timezone_set('UTC');
//select output format
@@ -70,6 +71,7 @@ function send_html(){
echo '';
echo '';
echo '';
+ echo '';
echo '';
echo '';
echo '';
diff --git a/www/robots.txt b/www/robots.txt
index 20c1862..185a634 100644
--- a/www/robots.txt
+++ b/www/robots.txt
@@ -1,3 +1,4 @@
User-agent: *
Disallow: /*?*addr=
Allow: *
+Sitemap: /sitemap.php
diff --git a/www/sitemap.php b/www/sitemap.php
new file mode 100644
index 0000000..7a4c56b
--- /dev/null
+++ b/www/sitemap.php
@@ -0,0 +1,74 @@
+PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]);
+}catch(PDOException $e){
+ http_send_status(500);
+ die($I['nodb']);
+}
+$links = [];
+$links []= ['loc' => CANONICAL_URL . '/test.php', 'changefreq' => 'weekly', 'priority' => '0.8'];
+$links []= ['loc' => CANONICAL_URL . '/onions.php', 'changefreq' => 'daily', 'priority' => '1'];
+$links []= ['loc' => CANONICAL_URL . '/onions.php?format=json', 'changefreq' => 'daily', 'priority' => '0.2'];
+$links []= ['loc' => CANONICAL_URL . '/onions.php?format=text', 'changefreq' => 'daily', 'priority' => '0.2'];
+$admin_approval = '';
+if(REQUIRE_APPROVAL){
+ $admin_approval = PREFIX . 'onions.approved = 1 AND';
+}
+foreach ($L as $lang_code => $lang){
+ $links []= ['loc' => CANONICAL_URL . "/onions.php?lang=$lang_code", 'changefreq' => 'daily', 'priority' => '0.5'];
+ $stmt=$db->prepare('SELECT COUNT(*) FROM ' . PREFIX . "onions WHERE $admin_approval category=? AND address!='' AND id NOT IN (SELECT onion_id FROM " . PREFIX . 'phishing) AND timediff<604800;');
+ foreach($categories as $cat => $name){
+ $links []= ['loc' => CANONICAL_URL . "/onions.php?cat=$cat&lang=$lang_code", 'changefreq' => 'daily', 'priority' => '0.3'];
+ $stmt->execute([$cat]);
+ $num=$stmt->fetch(PDO::FETCH_NUM);
+ $pages=ceil($num[0]/PER_PAGE);
+ if($pages > 1) {
+ while ( $pages > -1 ) {
+ $links [] = [ 'loc' => CANONICAL_URL . "/onions.php?cat=$cat&pg=$pages&lang=$lang_code", 'changefreq' => 'daily', 'priority' => '0.3' ];
+ --$pages;
+ }
+ }
+ }
+ $special=[
+ $I['all']=>"address!='' AND category!=15 AND id NOT IN (SELECT onion_id FROM " . PREFIX . 'phishing) AND timediff<604800',
+ $I['lastadded']=>"address!='' AND id NOT IN (SELECT onion_id FROM " . PREFIX . 'phishing)',
+ $I['offline']=>"address!='' AND id NOT IN (SELECT onion_id FROM " . PREFIX . 'phishing) AND timediff>604800'
+ ];
+ $cat=count($categories);
+ foreach($special as $name=>$query){
+ $links []= ['loc' => CANONICAL_URL . "/onions.php?cat=$cat&lang=$lang_code", 'changefreq' => 'daily', 'priority' => '0.3'];
+ if($cat===count($categories)+1){
+ $num[0]=PER_PAGE;
+ }else{
+ $num=$db->query('SELECT COUNT(*) FROM ' . PREFIX . "onions WHERE $admin_approval $query;")->fetch(PDO::FETCH_NUM);
+ }
+ $pages=ceil($num[0]/PER_PAGE);
+ if($pages > 1) {
+ while ( $pages > -1 ) {
+ $links [] = [ 'loc' => CANONICAL_URL . "/onions.php?cat=$cat&pg=$pages&lang=$lang_code", 'changefreq' => 'daily', 'priority' => '0.3' ];
+ --$pages;
+ }
+ }
+ ++$cat;
+ }
+ $links []= ['loc' => CANONICAL_URL . "/onions.php?cat=$cat&lang=$lang_code", 'changefreq' => 'daily', 'priority' => '0.3'];
+}
+$dom = new DOMDocument('1.0', 'UTF-8');
+$urlset= $dom->createElement('urlset');
+$urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
+$urlset->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
+$urlset->setAttribute('xsi:schemaLocation', 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd');
+$dom->appendChild($urlset);
+foreach ($links as $link) {
+ $url = $dom->createElement('url');
+ $urlset->appendChild($url);
+ $loc = $dom->createElement('loc', htmlspecialchars($link['loc']));
+ $url->appendChild($loc);
+ $changefreq = $dom->createElement('changefreq', $link['changefreq']);
+ $url->appendChild($changefreq);
+ $priority = $dom->createElement('priority', $link['priority']);
+ $url->appendChild($priority);
+}
+header('Content-Type: text/xml; charset=UTF-8');
+echo $dom->saveXML();
\ No newline at end of file
diff --git a/www/test.php b/www/test.php
index e427ec4..53160d3 100644
--- a/www/test.php
+++ b/www/test.php
@@ -8,6 +8,7 @@ echo '';
echo '';
echo '';
echo '';
+echo '';
echo '';
echo '';
echo 'Online-Test
';
@@ -30,7 +31,8 @@ if(!empty($_REQUEST['addr'])){
try{
$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){
- die('No DB connection');
+ http_send_status(500);
+ die($I['nodb']);
}
if(!preg_match('~(^(https?://)?([a-z0-9]*\.)?([a-z2-7]{16}|[a-z2-7]{56})(\.onion(/.*)?)?$)~i', trim($_REQUEST['addr']), $addr)){
echo "$I[invalonion]
";