aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Cleberg <hello@cleberg.net>2023-05-23 18:35:45 -0500
committerChristian Cleberg <hello@cleberg.net>2023-05-23 18:35:45 -0500
commit6435c9100bffea6a2df7603ef62ae00d64c92831 (patch)
treefc5e919ad281cc383bb90c4c0ea1423339b431ff
parente9d1ab5b5229a8888f0cf8aacd65d1810d3c54cb (diff)
downloadifconfig.php-6435c9100bffea6a2df7603ef62ae00d64c92831.tar.gz
ifconfig.php-6435c9100bffea6a2df7603ef62ae00d64c92831.tar.bz2
ifconfig.php-6435c9100bffea6a2df7603ef62ae00d64c92831.zip
initial fork: updating for php8
-rw-r--r--README.md18
-rw-r--r--ifconfig.php153
2 files changed, 76 insertions, 95 deletions
diff --git a/README.md b/README.md
index 35a84a4..39f6c48 100644
--- a/README.md
+++ b/README.md
@@ -9,14 +9,12 @@ Available all basic features such as output in HTML, plain text, XML and JSON.
By default it will be in HTML. Also it is possible to request single values.
Visit some of the links below to view it in action:
-* [all in plain text](http://briskin.org/ifconfig/text)
-* [all in xml](http://briskin.org/ifconfig/xml)
-* [ip address only](http://briskin.org/ifconfig/ip)
-* [useragent only](http://briskin.org/ifconfig/ua)
+* [all in plain text](http://ip.cleberg.net?q=text)
+* [all in xml](http://ip.cleberg.net?q=xml)
+* [ip address only](http://ip.cleberg.net?q=ip)
+* [useragent only](http://ip.cleberg.net?q=ua)
-
-
-This is example of .htaccess rules, to make this script more user friendly:
+If you're using the Apache web server, you can use the .htaccess rules below to make this site more user friendly:
RewriteEngine On
@@ -25,7 +23,7 @@ This is example of .htaccess rules, to make this script more user friendly:
RewriteRule ^ifconfig$ ifconfig.php [L]
RewriteRule ^ifconfig/(.*)$ /ifconfig.php?q=$1 [L]
-With this code in .htaccess file there is no need to type long line 'ifconfig.php?q='.
-Now just enough to open 'ifconfig/xml' to get XML output or 'ifconfig/ua' to determine useragent.
+With this code in the .htaccess file there is no need to type out the full URL, i.e. 'ifconfig.php?q='.
+Instead, you can just open 'ifconfig/xml' to get XML output or 'ifconfig/ua' to determine useragent.
-Run `curl briskin.org/ifconfig/text` in Linux terminal to get some info.
+Run `curl -L -X GET https://ip.cleberg.net/\?q\=text` in Linux terminal to get some info.
diff --git a/ifconfig.php b/ifconfig.php
index fd0f876..c6fc39b 100644
--- a/ifconfig.php
+++ b/ifconfig.php
@@ -1,45 +1,25 @@
<?php
-/*
- * User connection info
- *
- * License: GPL v2 (https://www.gnu.org/licenses/gpl-2.0.html)
- *
- * Copyright (C) 2014 Sergey Briskin (http://briskin.org)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
+
+$site_title = 'ip.cleberg.net';
// Create array of values
$user = array(
- 'ip' => $_SERVER['REMOTE_ADDR'],
- 'host' => (isset($_SERVER['REMOTE_ADDR']) ? gethostbyaddr($_SERVER['REMOTE_ADDR']) : ""),
- 'port' => $_SERVER['REMOTE_PORT'],
- 'ua' => $_SERVER['HTTP_USER_AGENT'],
- 'lang' => $_SERVER['HTTP_ACCEPT_LANGUAGE'],
- 'mime' => $_SERVER['HTTP_ACCEPT'],
- 'encoding' => $_SERVER['HTTP_ACCEPT_ENCODING'],
- 'charset' => $_SERVER['HTTP_ACCEPT_CHARSET'],
+ 'ip' => $_SERVER['REMOTE_ADDR'],
+ 'host' => (isset($_SERVER['REMOTE_ADDR']) ? gethostbyaddr($_SERVER['REMOTE_ADDR']) : ""),
+ 'port' => $_SERVER['REMOTE_PORT'],
+ 'ua' => $_SERVER['HTTP_USER_AGENT'],
+ 'lang' => $_SERVER['HTTP_ACCEPT_LANGUAGE'],
+ 'mime' => $_SERVER['HTTP_ACCEPT'],
+ 'encoding' => $_SERVER['HTTP_ACCEPT_ENCODING'],
+ 'charset' => $_SERVER['HTTP_ACCEPT_CHARSET'],
'connection' => $_SERVER['HTTP_CONNECTION'],
- 'cache' => $_SERVER['HTTP_CACHE_CONTROL'],
- 'cookie' => $_SERVER['HTTP_COOKIE'],
- 'referer' => $_SERVER['HTTP_REFERER'],
- 'real_ip' => $_SERVER['HTTP_X_REAL_IP'],
- 'fwd_ip' => $_SERVER['HTTP_X_FORWARDED_FOR'],
- 'fwd_host' => (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? gethostbyaddr($_SERVER['HTTP_X_FORWARDED_FOR']) : ""),
- 'dnt' => $_SERVER['HTTP_DNT']
+ 'cache' => $_SERVER['HTTP_CACHE_CONTROL'],
+ 'cookie' => $_SERVER['HTTP_COOKIE'],
+ 'referer' => $_SERVER['HTTP_REFERER'],
+ 'real_ip' => $_SERVER['HTTP_X_REAL_IP'],
+ 'fwd_ip' => $_SERVER['HTTP_X_FORWARDED_FOR'],
+ 'fwd_host' => (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? gethostbyaddr($_SERVER['HTTP_X_FORWARDED_FOR']) : ""),
+ 'dnt' => $_SERVER['HTTP_DNT']
);
// Check request (ex. ifconfig.php?q=ip)
@@ -56,64 +36,67 @@ elseif (isset($query) && (($query=="text") || ($query=="all"))) {
echo $key.": ".$value."\n";
}
die();
-
} elseif (isset($query) && ($query=="xml")) {
header('Content-Type: text/xml');
-
-// Function for SimpleXML creation
-function array_to_xml(array $arr, SimpleXMLElement $xml)
-{
- foreach ($arr as $k => $v) {
- is_array($v)
- ? array_to_xml($v, $xml->addChild($k))
- : $xml->addChild($k, $v);
- }
- return $xml;
-}
-echo array_to_xml($user, new SimpleXMLElement('<info/>'))->asXML();
-
+ // Function for SimpleXML creation
+ function array_to_xml(array $arr, SimpleXMLElement $xml)
+ {
+ foreach ($arr as $k => $v) {
+ is_array($v)
+ ? array_to_xml($v, $xml->addChild($k))
+ : $xml->addChild($k, $v);
+ }
+ return $xml;
+ }
+ echo array_to_xml($user, new SimpleXMLElement('<info/>'))->asXML();
} elseif (isset($query) && ($query=="json")) {
header('Content-Type: application/json');
die(json_encode($user));
-
} else {
header('Content-Type: text/html');
-?><!DOCTYPE html>
-<html lang="en">
-<head>
- <meta charset="UTF-8">
- <title>info</title>
- <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
- <style>
- body {
- background: #FDFDFD;
- color: #111;
- font-size: .9em;
- }
- p {
- font-family: "Source Code Pro", "Droid Mono", "Courier New", "Consolas", "Terminal", fixed;
- line-height: 1em;
- }
- .small, .small > a {
- font-size: 9pt;
- color: #777;
- text-align: center;
- text-decoration: none;
- }
- </style>
-</head>
-<body>
-<?
+ echo <<<EOD
+ <!DOCTYPE html>
+ <html lang="en">
+ <head>
+ <meta charset="UTF-8">
+ <title>{$site_title}</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
+ <style>
+ p,a {
+ font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, 'DejaVu Sans Mono', monospace;
+ line-height: 1em;
+ }
+ .small, .small > a {
+ font-size: 9pt;
+ color: #777;
+ text-align: center;
+ text-decoration: none;
+ }
+ </style>
+ </head>
+ <body>
+ <nav>
+ <a href="/">home</a> &middot;
+ <a href="/?q=text">text</a> &middot;
+ <a href="/?q=xml">xml</a> &middot;
+ <a href="/?q=ip">ip</a> &middot;
+ <a href="/?q=ua">ua</a>
+ </nav>
+ <hr>
+ EOD;
+
foreach($user as $key => $value) {
echo ' <p id="'.$key.'">'.$key.': '.$value.'</p>'."\n";
}
-?>
-<br/>
-<p class="small">Copyright &copy; 2014 <a href="http://briskin.org">Sergey Briskin</a>.<br/>
-<a href="https://github.com/sbriskin/ifconfig.php">Get Source code on GitHub</a></p>
-</body>
-</html>
-<?
+
+ $date = date("Y");
+ echo <<<EOD
+ <br>
+ <p class="small">Copyright &copy; {$date} <a href="https://cleberg.net">Christian Cleberg</a>.<br/>
+ <a target="_blank" rel="noreferrer" href="https://git.sr.ht/~cmc/ifconfig.php">Source Code</a></p>
+ </body>
+ </html>
+ EOD;
}
die();
?>