Diverse Änderungen an Live-Version
authorMalte Bublitz <malte@rolltreppe3.de>
Wed, 24 Jan 2024 17:35:23 +0000 (18:35 +0100)
committerMalte Bublitz <malte@rolltreppe3.de>
Wed, 24 Jan 2024 17:35:23 +0000 (18:35 +0100)
98.php
api-doc.php [new file with mode: 0644]
api.php
clientinfo.class.php
config.inc.php
index.php
info.php
robots.txt [new file with mode: 0644]
widget.php

diff --git a/98.php b/98.php
index fa497c42977dc100c2a5863c4847f7865b209a4b..aaaa5721cc1b82b352e0ff8a42c565d15c8c1b93 100644 (file)
--- a/98.php
+++ b/98.php
@@ -23,9 +23,13 @@ $Languages = Array(
 /**
  * Retrieve GeoIP data
  */
-$geo = $info->getGeoIPCity();
-if (empty($geo[1])) {
-    $geo = False;
+if (function_exists("geoip_record_by_name")) {
+       $geo = $info->getGeoIPCity();
+       if (empty($geo[1])) {
+               $geo = False;
+       }
+} else {
+       $geo = False;
 }
 
 
@@ -56,9 +60,10 @@ $Data = Array(
                <meta charset="UTF-8">
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
                
-               <title>Deine IP &mdash; ip.malte70.de</title>
+               <title>Deine IP (powered by Windows&nbsp;98) <?=$AppInfo["TitleSeparator"]?> <?=$AppInfo["Name"]?></title>
                
                <meta name="author" content="Malte Bublitz">
+               <meta name="robots" content="noindex">
 <?php foreach ($Data["Stylesheet"] as $css): ?>
                <link rel="stylesheet" type="text/css" href="<?=$css?>">
 <?php endforeach; ?>
diff --git a/api-doc.php b/api-doc.php
new file mode 100644 (file)
index 0000000..d3818dd
--- /dev/null
@@ -0,0 +1,104 @@
+<?php
+/**
+ * API Documentation
+ *
+ * Parse Markdown from `API.md` to HTML and
+ * embed it in a small page layout.
+ */
+
+//ini_set("error_reporting", True);
+//error_reporting(E_ALL & ~E_DEPRECATED);
+
+require_once("config.inc.php");
+require_once("../lib/Markdown2HTML.php");
+
+$md2html = new Markdown2HTML();
+$md2html->setFilename("API.md");
+if (!$md2html->getFileExists()) {
+       header("HTTP/1.0 404 Not Found");
+} elseif (!$md2html->getFileReadable()) {
+       header("HTTP/1.0 403 Forbidden");
+}
+$md2html->getMarkdown();
+$md2html->parseMarkdown();
+
+/**
+ * DEBUG: Only show parsed Markdown
+ * served as text/plain
+ */
+if ((is_bool(@$_GET["debug"]) && @$_GET["debug"]) || in_array(strtolower(@$_GET["debug"]), array("true","yes","1"))) {
+       header("Content-Type:text/plain; charset=UTF-8");
+       die($md2html->getHTML());
+}
+
+$css = "markdown.css";
+
+$title = "API " . $AppInfo["TitleSeparator"] . " " . $AppInfo["Name"];
+
+// store locale
+$originalLocales = explode(";", setlocale(LC_ALL, 0));
+//setlocale(LC_ALL, "de_DE.utf8");
+
+$mtime  = filemtime($md2html->getFilename());
+// date is always English, but strftime is localized.
+// Note: Using RFC 2822 format
+//$mtime  = date("r", $mtime);
+$mtime  = strftime("%a, %d %b %Y %T %z", $mtime);
+
+// restore locale
+/*
+foreach ($originalLocales as $localeSetting) {
+  if (strpos($localeSetting, "=") !== false) {
+    list ($category, $locale) = explode("=", $localeSetting);
+  }
+  else {
+    $category = LC_ALL;
+    $locale   = $localeSetting;
+  }
+  setlocale($category, $locale);
+}*/
+
+
+$Data   = Array(
+       "Filename"       => $filename,
+       "Title"          => $title,
+       "Headline"       => '<a href="' . $filename . '" download>' . $md2html->getHeadline() . '</a>',
+       "ParsedMarkdown" => $md2html->getHTML(),
+       "Stylesheet"     => "//xyz.malte70.de/css/".$css,
+       "Favicon"        => "https://xyz.malte70.de/img/icons_tango/floppy-512.png",
+       "FaviconSize"    => "512x512",
+       "Footer"         => "<a href=\"$filename\" download>$filename</a> &middot; Last modified: $mtime",
+);
+
+?><!DOCTYPE html>
+<html lang="en">
+       <head>
+               <meta charset="utf-8">
+               <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
+               <title><?=$Data["Title"]?></title>
+               
+               <link rel="icon" type="image/png" sizes="128x128" href="/assets/img/favicon.png">
+               <link rel="stylesheet" href="<?=$Data["Stylesheet"]?>">
+       </head>
+       <body>
+               <header>
+                       <h1>
+                               <?=$Data["Headline"]?>
+                       </h1>
+               </header>
+               
+               <main>
+                       <section id="markdown">
+<?=$Data["ParsedMarkdown"]?>
+                       </section>
+               </main>
+<?php if (!empty($Data["Footer"])): ?>
+               
+               <footer>
+                       <p>
+                               <?=$Data["Footer"]?>
+                       </p>
+               </footer>
+<?php endif; ?>
+       </body>
+</html>
diff --git a/api.php b/api.php
index 533270517f96f3f672f69bf665194c1f2dfdcbf4..0ca2760ac7d0da38bd62e5c484b0e276d20f9b02 100644 (file)
--- a/api.php
+++ b/api.php
@@ -53,22 +53,37 @@ switch ($id) {
                break;
                
        case "country":
-               print $info->getGeoIPCountry();
+               print function_exists("geoip_record_by_name") ? $info->getGeoIPCountry() : "Error: API method not available!";
                break;
                
        case "region_code":
+               if (!function_exists("geoip_record_by_name")) {
+                       print "Error: API method not available!";
+                       http_response_code(405);
+                       break;
+               }
                $region = $info->getGeoIPRegion();
                if (is_array($region))
                        print $region[0];
                break;
                
        case "region":
+               if (!function_exists("geoip_record_by_name")) {
+                       print "Error: API method not available!";
+                       http_response_code(405);
+                       break;
+               }
                $region = $info->getGeoIPRegion();
                if (is_array($region))
                        print $region[1];
                break;
                
        case "city":
+               if (!function_exists("geoip_record_by_name")) {
+                       print "Error: API method not available!";
+                       http_response_code(405);
+                       break;
+               }
                $city = $info->getGeoIPCity();
                if ($city)
                        print $city[0];
@@ -76,6 +91,11 @@ switch ($id) {
                
        case "zip":
        case "postal_code":
+               if (!function_exists("geoip_record_by_name")) {
+                       print "Error: API method not available!";
+                       http_response_code(405);
+                       break;
+               }
                $city = $info->getGeoIPCity();
                if ($city)
                        print $city[1];
@@ -83,18 +103,33 @@ switch ($id) {
                
        case "coordinates":
        case "gps":
+               if (!function_exists("geoip_record_by_name")) {
+                       print "Error: API method not available!";
+                       http_response_code(405);
+                       break;
+               }
                $city = $info->getGeoIPCity();
                if ($city)
                        print $city[2][0] . " " . $city[2][1];
                break;
                
        case "latitude":
+               if (!function_exists("geoip_record_by_name")) {
+                       print "Error: API method not available!";
+                       http_response_code(405);
+                       break;
+               }
                $city = $info->getGeoIPCity();
                if ($city)
                        print $city[2][0];
                break;
                
        case "longitude":
+               if (!function_exists("geoip_record_by_name")) {
+                       print "Error: API method not available!";
+                       http_response_code(405);
+                       break;
+               }
                $city = $info->getGeoIPCity();
                if ($city)
                        print $city[2][1];
@@ -105,4 +140,4 @@ switch ($id) {
                
 }
 
-?>
\ No newline at end of file
+?>
index e751843a762931fc3cc92043dceafcdea1da9d5a..21edf2bdebff21124599572198e8338f40ddc4ed 100644 (file)
@@ -466,7 +466,7 @@ class ClientInfo {
                                        )
                                );
                                
-                               $this->OS .= " " . implode($version, ".");
+                               $this->OS .= " " . implode(".", $version);
                                
                        } elseif (stripos($ua, "iPhone") !== false) {
                                $this->OS = "iOS";
@@ -489,7 +489,7 @@ class ClientInfo {
                                        )
                                );
                                
-                               $this->OS .= " " . implode($version, ".");
+                               $this->OS .= " " . implode(".", $version);
                                
                        } elseif (stripos($ua, "Macintosh") !== false) {
                                $this->OS = "Apple OS X";
@@ -527,7 +527,8 @@ class ClientInfo {
                                        )
                                );
                                
-                               $this->OS .= " " . implode($version, ".");
+                               $this->OS .= " " . implode(".", $version);
+                               
                        } else {
                                $this->OS = $fallback;
                                
index eb52c10968cdf1d007a3f2eeedd8c4abab020d22..62e5a3bfa0e0ea023248decf5ea9e72d412c5d70 100644 (file)
@@ -10,6 +10,9 @@
  */
 $AppInfo = Array(
        "Name"      => "ip.malte70.de",
+       //"TitleSeparator" => "::",
+       "TitleSeparator" => "|",
+       //"TitleSeparator" => "-",
        "URL"       => "https://github.com/projekt-ancistrus/ipinfo",
        "Copyright" => Array(
                "Year"       => "2016-".date("Y"),
@@ -49,6 +52,11 @@ $WidgetConfig = Array(
        ),
 );
 
+
+/**
+ * Enable debugging mode if "debug" GET parameter is
+ * set.
+ */
 @$debug = in_array(
        strtolower($_GET["debug"]),
        Array(
@@ -62,4 +70,10 @@ if ($debug) {
        ini_set("display_errors", "On");
 }
 
-?>
\ No newline at end of file
+
+/**
+ * Autoloading for composer packages
+ */
+require __DIR__ . '/vendor/autoload.php';
+
+?>
index b4377c426349ab991963c06e47c06aa30993a157..849bd388d98b5310546f70d95c45996c62db99af 100644 (file)
--- a/index.php
+++ b/index.php
@@ -33,7 +33,7 @@ $contentData = Array(
 $footerData = Array(
        "© " . $AppInfo["Copyright"]["Year"] . ' <a href="' . $AppInfo["Copyright"]["AuthorLink"] . '" rel="me nofollow">' . $AppInfo["Copyright"]["AuthorName"] . '</a>',
        'Powered by <a href="' . $AppInfo["URL"] . '">' . $AppInfo["Name"] . '</a>',
-       '<a href="API.md">API</a>'
+       '<a href="api-doc.php">API</a>'
 );
 
 $lang = substr(
@@ -42,15 +42,15 @@ $lang = substr(
        2
 );
 if ($lang == "de") {
-       $msg_your_ip = "Deine IPAdresse";
+       $msg_your_ip = "Deine IP-Adresse";
 } else {
-       $msg_your_ip = "Your IP";
+       $msg_your_ip = "Your IP Address";
 }
 $Data = Array(
        "Meta" => Array(
                "Lang" => $lang,
                "Charset" => "UTF-8",
-               "Title" => $msg_your_ip . " :: " . $AppInfo["Name"],
+               "Title" => $msg_your_ip." ".$AppInfo["TitleSeparator"]." ".$AppInfo["Name"],
                "Author" => "Malte Bublitz",
                "HumansTXT" => false,
                "Stylesheet" => "assets/css/style.css"
@@ -73,4 +73,4 @@ if ($debug) {
        require_once("template.inc.php");
 }
 
-?>
\ No newline at end of file
+?>
index 31b7d76c69b3f7862de906582e9e6b501beef672..cbd1f0100d5e1c613382eb538ea531ad37e50a38 100644 (file)
--- a/info.php
+++ b/info.php
@@ -19,7 +19,7 @@ function getMsg($lang, $id) {
        $is_ipv6 = $info->isIPv6();
        $Translations = Array(
                "de" => Array(
-                       "Title"   => "Deine IP",
+                       "Title"   => "Deine IP/Browserkennung",
                        "IP"      => "IP-Adresse" . ($is_ipv6 ? " (IPv6)" : " (IPv4)"),
                        "IPv4"    => "IP-Adresse (IPv4)",
                        "IPv6"    => "IP-Adresse (IPv6)",
@@ -30,7 +30,7 @@ function getMsg($lang, $id) {
                        "Loc"     => "Ort"
                ),
                "en" => Array(
-                       "Title"   => "Your IP",
+                       "Title"   => "Your IP and User-agent",
                        "IP"      => "IP Address" . ($is_ipv6 ? " (IPv6)" : " (IPv4)"),
                        "IPv4"    => "IP Address (IPv4)",
                        "IPv6"    => "IP Address (IPv6)",
@@ -69,25 +69,36 @@ ob_start();
        <?=$info->getOS()?> (<?=getMsg($lang, "Lang")?>: <?=$info->getLanguage()?>)
 </p>
 <?php
-if ($debug) {
-       print '<pre>';
-       print "\$info->getGeoIPCountry() = " . $info->getGeoIPCountry() . "\n";
 
-       print "\n\$info->getGeoIPCity() = ";
-       print_r($info->getGeoIPCity());
-       print '</pre>';
-}
-if (!empty($info->getGeoIPCity()[0])) {
-       $coord = Array(
-               number_format($info->getGeoIPCity()[2][0], 4, ".", ""),
-               number_format($info->getGeoIPCity()[2][1], 4, ".", "")
-       );
+/**
+ * Verify that GeoIP is available, which is not the case
+ * after I updated the server from Ubuntu 20.04 to 22.04 !!!
+ */
+if (function_exists("geoip_record_by_name")) {
+       
+       if ($debug) {
+               print '<pre>';
+               print "\$info->getGeoIPCountry() = " . $info->getGeoIPCountry() . "\n";
+
+               print "\n\$info->getGeoIPCity() = ";
+               print_r($info->getGeoIPCity());
+               print '</pre>';
+       }
+       if (!empty($info->getGeoIPCity()[0])) {
+               $coord = Array(
+                       number_format($info->getGeoIPCity()[2][0], 4, ".", ""),
+                       number_format($info->getGeoIPCity()[2][1], 4, ".", "")
+               );
 ?>
 <h3><?=getMsg($lang, "Loc")?></h3>
 <p class="info" id="location">
        <?=$info->getGeoIPCity()[0]?>, <?=$info->getGeoIPCountry()?>
 </p>
-<?php } ?>
+<?php
+       }
+
+} // GeoIP functions available
+?>
 <h3><?=getMsg($lang, "UA")?></h3>
 <p class="info" id="user-agent">
        <?=$info->getUserAgent()?>
@@ -100,14 +111,14 @@ $contentData = Array(
 $footerData = Array(
        "© " . $AppInfo["Copyright"]["Year"] . ' <a href="' . $AppInfo["Copyright"]["AuthorLink"] . '" rel="me nofollow">' . $AppInfo["Copyright"]["AuthorName"] . '</a>',
        'Powered by <a href="' . $AppInfo["URL"] . '">' . $AppInfo["Name"] . '</a>',
-       '<a href="API.md">API</a>'
+       '<a href="api-doc.php">API</a>'
 );
 
 $Data = Array(
        "Meta" => Array(
                "Lang"       => $lang,
                "Charset"    => "UTF-8",
-               "Title"      => getMsg($lang, "Title") . " :: " . $AppInfo["Name"],
+               "Title"      => getMsg($lang, "Title")." ".$AppInfo["TitleSeparator"]." ".$AppInfo["Name"],
                "Author"     => "Malte Bublitz",
                "HumansTXT"  => false,
                "Stylesheet" => "assets/css/style.css"
diff --git a/robots.txt b/robots.txt
new file mode 100644 (file)
index 0000000..71128d1
--- /dev/null
@@ -0,0 +1,16 @@
+# robotstxt.org/
+
+User-agent: *
+Disallow: /98.php
+
+User-agent: *
+Disallow: /api-doc.php
+
+User-agent: *
+Disallow: /api.php
+
+User-agent: *
+Disallow: /assets
+
+User-agent: *
+Disallow: /widget.php
index 871613f07688bf3bb119cbaab6a63abcddb75787..6a308d0019f7e7f9dad84bc199eb18160250246f 100644 (file)
@@ -114,6 +114,7 @@ imagettftext(
        $text_color,
        $WidgetConfig["FontFamily"],
        $info->getIP()
+       //$info->getIP()=="188.136.91.26" ? "203.0.113.42" :  $info->getIP()
 );