Commit 6435c9100b
Unsigned
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. | ||
| 9 | 9 | By default it will be in HTML. Also it is possible to request single values. |
| 10 | 10 | |
| 11 | 11 | Visit 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) | |
| 16 | 16 | |
| 17 | ||
| 18 | ||
| 19 | This is example of .htaccess rules, to make this script more user friendly: | |
| 17 | If you're using the Apache web server, you can use the .htaccess rules below to make this site more user friendly: | |
| 20 | 18 | |
| 21 | 19 | RewriteEngine On |
| 22 | 20 | |
| @@ -25,7 +23,7 @@ This is example of .htaccess rules, to make this script more user friendly: | ||
| 25 | 23 | RewriteRule ^ifconfig$ ifconfig.php [L] |
| 26 | 24 | RewriteRule ^ifconfig/(.*)$ /ifconfig.php?q=$1 [L] |
| 27 | 25 | |
| 28 | With this code in .htaccess file there is no need to type long line 'ifconfig.php?q='. | |
| 29 | Now just enough to open 'ifconfig/xml' to get XML output or 'ifconfig/ua' to determine useragent. | |
| 26 | With this code in the .htaccess file there is no need to type out the full URL, i.e. 'ifconfig.php?q='. | |
| 27 | Instead, you can just open 'ifconfig/xml' to get XML output or 'ifconfig/ua' to determine useragent. | |
| 30 | 28 | |
| 31 | Run `curl briskin.org/ifconfig/text` in Linux terminal to get some info. | |
| 29 | Run `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 @@ | ||
| 1 | 1 | <?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'; | |
| 24 | 4 | |
| 25 | 5 | // Create array of values |
| 26 | 6 | $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'], | |
| 35 | 15 | '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'] | |
| 43 | 23 | ); |
| 44 | 24 | |
| 45 | 25 | // Check request (ex. ifconfig.php?q=ip) |
| @@ -56,64 +36,67 @@ elseif (isset($query) && (($query=="text") || ($query=="all"))) { | ||
| 56 | 36 | echo $key.": ".$value."\n"; |
| 57 | 37 | } |
| 58 | 38 | die(); |
| 59 | ||
| 60 | 39 | } elseif (isset($query) && ($query=="xml")) { |
| 61 | 40 | header('Content-Type: text/xml'); |
| 62 | ||
| 63 | // Function for SimpleXML creation | |
| 64 | function 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 | } | |
| 73 | echo 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(); | |
| 75 | 52 | } elseif (isset($query) && ($query=="json")) { |
| 76 | 53 | header('Content-Type: application/json'); |
| 77 | 54 | die(json_encode($user)); |
| 78 | ||
| 79 | 55 | } else { |
| 80 | 56 | 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> · | |
| 80 | <a href="/?q=text">text</a> · | |
| 81 | <a href="/?q=xml">xml</a> · | |
| 82 | <a href="/?q=ip">ip</a> · | |
| 83 | <a href="/?q=ua">ua</a> | |
| 84 | </nav> | |
| 85 | <hr> | |
| 86 | EOD; | |
| 87 | ||
| 107 | 88 | foreach($user as $key => $value) { |
| 108 | 89 | echo ' <p id="'.$key.'">'.$key.': '.$value.'</p>'."\n"; |
| 109 | 90 | } |
| 110 | ?> | |
| 111 | <br/> | |
| 112 | <p class="small">Copyright © 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 © {$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; | |
| 117 | 100 | } |
| 118 | 101 | die(); |
| 119 | 102 | ?> |