Commit 6435c9100b

6435c9100bffea6a2df7603ef62ae00d64c92831

parent: e9d1ab5b52

Unsigned

cmc <hello@cleberg.net> · 2023-05-23 23:35 UTC

initial fork: updating for php8

Layout: unified · split

README.md +8 −10
@@ -9,14 +9,12 @@ Available all basic features such as output in HTML, plain text, XML and JSON.
99By default it will be in HTML. Also it is possible to request single values.
1010
1111Visit some of the links below to view it in action:
12* [all in plain text](http://briskin.org/ifconfig/text)
13* [all in xml](http://briskin.org/ifconfig/xml)
14* [ip address only](http://briskin.org/ifconfig/ip)
15* [useragent only](http://briskin.org/ifconfig/ua)
12* [all in plain text](http://ip.cleberg.net?q=text)
13* [all in xml](http://ip.cleberg.net?q=xml)
14* [ip address only](http://ip.cleberg.net?q=ip)
15* [useragent only](http://ip.cleberg.net?q=ua)
1616
17
18
19This is example of .htaccess rules, to make this script more user friendly:
17If you're using the Apache web server, you can use the .htaccess rules below to make this site more user friendly:
2018
2119 RewriteEngine On
2220
@@ -25,7 +23,7 @@ This is example of .htaccess rules, to make this script more user friendly:
2523 RewriteRule ^ifconfig$ ifconfig.php [L]
2624 RewriteRule ^ifconfig/(.*)$ /ifconfig.php?q=$1 [L]
2725
28With this code in .htaccess file there is no need to type long line 'ifconfig.php?q='.
29Now just enough to open 'ifconfig/xml' to get XML output or 'ifconfig/ua' to determine useragent.
26With this code in the .htaccess file there is no need to type out the full URL, i.e. 'ifconfig.php?q='.
27Instead, you can just open 'ifconfig/xml' to get XML output or 'ifconfig/ua' to determine useragent.
3028
31Run `curl briskin.org/ifconfig/text` in Linux terminal to get some info.
29Run `curl -L -X GET https://ip.cleberg.net/\?q\=text` in Linux terminal to get some info.
ifconfig.php +68 −85
@@ -1,45 +1,25 @@
11<?php
2/*
3 * User connection info
4 *
5 * License: GPL v2 (https://www.gnu.org/licenses/gpl-2.0.html)
6 *
7 * Copyright (C) 2014 Sergey Briskin (http://briskin.org)
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 *
23 */
2
3$site_title = 'ip.cleberg.net';
244
255// Create array of values
266$user = array(
27 'ip' => $_SERVER['REMOTE_ADDR'],
28 'host' => (isset($_SERVER['REMOTE_ADDR']) ? gethostbyaddr($_SERVER['REMOTE_ADDR']) : ""),
29 'port' => $_SERVER['REMOTE_PORT'],
30 'ua' => $_SERVER['HTTP_USER_AGENT'],
31 'lang' => $_SERVER['HTTP_ACCEPT_LANGUAGE'],
32 'mime' => $_SERVER['HTTP_ACCEPT'],
33 'encoding' => $_SERVER['HTTP_ACCEPT_ENCODING'],
34 'charset' => $_SERVER['HTTP_ACCEPT_CHARSET'],
7 'ip' => $_SERVER['REMOTE_ADDR'],
8 'host' => (isset($_SERVER['REMOTE_ADDR']) ? gethostbyaddr($_SERVER['REMOTE_ADDR']) : ""),
9 'port' => $_SERVER['REMOTE_PORT'],
10 'ua' => $_SERVER['HTTP_USER_AGENT'],
11 'lang' => $_SERVER['HTTP_ACCEPT_LANGUAGE'],
12 'mime' => $_SERVER['HTTP_ACCEPT'],
13 'encoding' => $_SERVER['HTTP_ACCEPT_ENCODING'],
14 'charset' => $_SERVER['HTTP_ACCEPT_CHARSET'],
3515 'connection' => $_SERVER['HTTP_CONNECTION'],
36 'cache' => $_SERVER['HTTP_CACHE_CONTROL'],
37 'cookie' => $_SERVER['HTTP_COOKIE'],
38 'referer' => $_SERVER['HTTP_REFERER'],
39 'real_ip' => $_SERVER['HTTP_X_REAL_IP'],
40 'fwd_ip' => $_SERVER['HTTP_X_FORWARDED_FOR'],
41 'fwd_host' => (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? gethostbyaddr($_SERVER['HTTP_X_FORWARDED_FOR']) : ""),
42 'dnt' => $_SERVER['HTTP_DNT']
16 'cache' => $_SERVER['HTTP_CACHE_CONTROL'],
17 'cookie' => $_SERVER['HTTP_COOKIE'],
18 'referer' => $_SERVER['HTTP_REFERER'],
19 'real_ip' => $_SERVER['HTTP_X_REAL_IP'],
20 'fwd_ip' => $_SERVER['HTTP_X_FORWARDED_FOR'],
21 'fwd_host' => (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? gethostbyaddr($_SERVER['HTTP_X_FORWARDED_FOR']) : ""),
22 'dnt' => $_SERVER['HTTP_DNT']
4323 );
4424
4525// Check request (ex. ifconfig.php?q=ip)
@@ -56,64 +36,67 @@ elseif (isset($query) && (($query=="text") || ($query=="all"))) {
5636 echo $key.": ".$value."\n";
5737 }
5838 die();
59
6039} elseif (isset($query) && ($query=="xml")) {
6140 header('Content-Type: text/xml');
62
63// Function for SimpleXML creation
64function array_to_xml(array $arr, SimpleXMLElement $xml)
65{
66 foreach ($arr as $k => $v) {
67 is_array($v)
68 ? array_to_xml($v, $xml->addChild($k))
69 : $xml->addChild($k, $v);
70 }
71 return $xml;
72}
73echo array_to_xml($user, new SimpleXMLElement('<info/>'))->asXML();
74
41 // Function for SimpleXML creation
42 function array_to_xml(array $arr, SimpleXMLElement $xml)
43 {
44 foreach ($arr as $k => $v) {
45 is_array($v)
46 ? array_to_xml($v, $xml->addChild($k))
47 : $xml->addChild($k, $v);
48 }
49 return $xml;
50 }
51 echo array_to_xml($user, new SimpleXMLElement('<info/>'))->asXML();
7552} elseif (isset($query) && ($query=="json")) {
7653 header('Content-Type: application/json');
7754 die(json_encode($user));
78
7955} else {
8056 header('Content-Type: text/html');
81?><!DOCTYPE html>
82<html lang="en">
83<head>
84 <meta charset="UTF-8">
85 <title>info</title>
86 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
87 <style>
88 body {
89 background: #FDFDFD;
90 color: #111;
91 font-size: .9em;
92 }
93 p {
94 font-family: "Source Code Pro", "Droid Mono", "Courier New", "Consolas", "Terminal", fixed;
95 line-height: 1em;
96 }
97 .small, .small > a {
98 font-size: 9pt;
99 color: #777;
100 text-align: center;
101 text-decoration: none;
102 }
103 </style>
104</head>
105<body>
106<?
57 echo <<<EOD
58 <!DOCTYPE html>
59 <html lang="en">
60 <head>
61 <meta charset="UTF-8">
62 <title>{$site_title}</title>
63 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
64 <style>
65 p,a {
66 font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, 'DejaVu Sans Mono', monospace;
67 line-height: 1em;
68 }
69 .small, .small > a {
70 font-size: 9pt;
71 color: #777;
72 text-align: center;
73 text-decoration: none;
74 }
75 </style>
76 </head>
77 <body>
78 <nav>
79 <a href="/">home</a> &middot;
80 <a href="/?q=text">text</a> &middot;
81 <a href="/?q=xml">xml</a> &middot;
82 <a href="/?q=ip">ip</a> &middot;
83 <a href="/?q=ua">ua</a>
84 </nav>
85 <hr>
86 EOD;
87
10788 foreach($user as $key => $value) {
10889 echo ' <p id="'.$key.'">'.$key.': '.$value.'</p>'."\n";
10990 }
110?>
111<br/>
112<p class="small">Copyright &copy; 2014 <a href="http://briskin.org">Sergey Briskin</a>.<br/>
113<a href="https://github.com/sbriskin/ifconfig.php">Get Source code on GitHub</a></p>
114</body>
115</html>
116<?
91
92 $date = date("Y");
93 echo <<<EOD
94 <br>
95 <p class="small">Copyright &copy; {$date} <a href="https://cleberg.net">Christian Cleberg</a>.<br/>
96 <a target="_blank" rel="noreferrer" href="https://git.sr.ht/~cmc/ifconfig.php">Source Code</a></p>
97 </body>
98 </html>
99 EOD;
117100}
118101die();
119102?>