From 3a7995bd2c87a50cfda14eaeb3662a97eabe04d5 Mon Sep 17 00:00:00 2001 From: Malte Bublitz Date: Wed, 24 Jan 2024 18:35:23 +0100 Subject: [PATCH] =?utf8?q?Diverse=20=C3=84nderungen=20an=20Live-Version?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- 98.php | 13 ++++-- api-doc.php | 104 +++++++++++++++++++++++++++++++++++++++++++ api.php | 39 +++++++++++++++- clientinfo.class.php | 7 +-- config.inc.php | 16 ++++++- index.php | 10 ++--- info.php | 45 ++++++++++++------- robots.txt | 16 +++++++ widget.php | 1 + 9 files changed, 219 insertions(+), 32 deletions(-) create mode 100644 api-doc.php create mode 100644 robots.txt diff --git a/98.php b/98.php index fa497c4..aaaa572 100644 --- 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( - Deine IP — ip.malte70.de + Deine IP (powered by Windows 98) <?=$AppInfo["TitleSeparator"]?> <?=$AppInfo["Name"]?> + diff --git a/api-doc.php b/api-doc.php new file mode 100644 index 0000000..d3818dd --- /dev/null +++ b/api-doc.php @@ -0,0 +1,104 @@ +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" => '' . $md2html->getHeadline() . '', + "ParsedMarkdown" => $md2html->getHTML(), + "Stylesheet" => "//xyz.malte70.de/css/".$css, + "Favicon" => "https://xyz.malte70.de/img/icons_tango/floppy-512.png", + "FaviconSize" => "512x512", + "Footer" => "$filename · Last modified: $mtime", +); + +?> + + + + + <?=$Data["Title"]?> + + + "> + + +
+

+ +

+
+ +
+
+ +
+
+ + + + + + diff --git a/api.php b/api.php index 5332705..0ca2760 100644 --- 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 +?> diff --git a/clientinfo.class.php b/clientinfo.class.php index e751843..21edf2b 100644 --- a/clientinfo.class.php +++ b/clientinfo.class.php @@ -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; diff --git a/config.inc.php b/config.inc.php index eb52c10..62e5a3b 100644 --- a/config.inc.php +++ b/config.inc.php @@ -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'; + +?> diff --git a/index.php b/index.php index b4377c4..849bd38 100644 --- a/index.php +++ b/index.php @@ -33,7 +33,7 @@ $contentData = Array( $footerData = Array( "© " . $AppInfo["Copyright"]["Year"] . ' ' . $AppInfo["Copyright"]["AuthorName"] . '', 'Powered by ' . $AppInfo["Name"] . '', - 'API' + 'API' ); $lang = substr( @@ -42,15 +42,15 @@ $lang = substr( 2 ); if ($lang == "de") { - $msg_your_ip = "Deine IP–Adresse"; + $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 +?> diff --git a/info.php b/info.php index 31b7d76..cbd1f01 100644 --- 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(); getOS()?> (: getLanguage()?>)

'; - print "\$info->getGeoIPCountry() = " . $info->getGeoIPCountry() . "\n"; - print "\n\$info->getGeoIPCity() = "; - print_r($info->getGeoIPCity()); - print ''; -} -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 '
';
+		print "\$info->getGeoIPCountry() = " . $info->getGeoIPCountry() . "\n";
+
+		print "\n\$info->getGeoIPCity() = ";
+		print_r($info->getGeoIPCity());
+		print '
'; + } + if (!empty($info->getGeoIPCity()[0])) { + $coord = Array( + number_format($info->getGeoIPCity()[2][0], 4, ".", ""), + number_format($info->getGeoIPCity()[2][1], 4, ".", "") + ); ?>

getGeoIPCity()[0]?>, getGeoIPCountry()?>

- +

getUserAgent()?> @@ -100,14 +111,14 @@ $contentData = Array( $footerData = Array( "© " . $AppInfo["Copyright"]["Year"] . ' ' . $AppInfo["Copyright"]["AuthorName"] . '', 'Powered by ' . $AppInfo["Name"] . '', - 'API' + 'API' ); $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 index 0000000..71128d1 --- /dev/null +++ b/robots.txt @@ -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 diff --git a/widget.php b/widget.php index 871613f..6a308d0 100644 --- a/widget.php +++ b/widget.php @@ -114,6 +114,7 @@ imagettftext( $text_color, $WidgetConfig["FontFamily"], $info->getIP() + //$info->getIP()=="188.136.91.26" ? "203.0.113.42" : $info->getIP() ); -- 2.30.2