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 | By default it will be in HTML. Also it is possible to request single values. | 9 | By default it will be in HTML. Also it is possible to request single values. |
| 10 | 10 | ||
| 11 | Visit some of the links below to view it in action: | 11 | Visit some of the links below to view it in action: |
| 12 | * [all in plain text](http://briskin.org/ifconfig/text) | 12 | * [all in plain text](http://ip.cleberg.net?q=text) |
| 13 | * [all in xml](http://briskin.org/ifconfig/xml) | 13 | * [all in xml](http://ip.cleberg.net?q=xml) |
| 14 | * [ip address only](http://briskin.org/ifconfig/ip) | 14 | * [ip address only](http://ip.cleberg.net?q=ip) |
| 15 | * [useragent only](http://briskin.org/ifconfig/ua) | 15 | * [useragent only](http://ip.cleberg.net?q=ua) |
| 16 | 16 | ||
| 17 | 17 | If you're using the Apache web server, you can use the .htaccess rules below to make this site more user friendly: | |
| 18 | |||
| 19 | This is example of .htaccess rules, to make this script more user friendly: | ||
| 20 | 18 | ||
| 21 | RewriteEngine On | 19 | RewriteEngine On |
| 22 | 20 | ||
| @@ -25,7 +23,7 @@ This is example of .htaccess rules, to make this script more user friendly: | |||
| 25 | RewriteRule ^ifconfig$ ifconfig.php [L] | 23 | RewriteRule ^ifconfig$ ifconfig.php [L] |
| 26 | RewriteRule ^ifconfig/(.*)$ /ifconfig.php?q=$1 [L] | 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='. | 26 | With this code in the .htaccess file there is no need to type out the full URL, i.e. 'ifconfig.php?q='. |
| 29 | Now just enough to open 'ifconfig/xml' to get XML output or 'ifconfig/ua' to determine useragent. | 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 | <?php | 1 | <?php |
| 2 | /* | 2 | |
| 3 | * User connection info | 3 | $site_title = 'ip.cleberg.net'; |
| 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 | */ | ||
| 24 | 4 | ||
| 25 | // Create array of values | 5 | // Create array of values |
| 26 | $user = array( | 6 | $user = array( |
| 27 | 'ip' => $_SERVER['REMOTE_ADDR'], | 7 | 'ip' => $_SERVER['REMOTE_ADDR'], |
| 28 | 'host' => (isset($_SERVER['REMOTE_ADDR']) ? gethostbyaddr($_SERVER['REMOTE_ADDR']) : ""), | 8 | 'host' => (isset($_SERVER['REMOTE_ADDR']) ? gethostbyaddr($_SERVER['REMOTE_ADDR']) : ""), |
| 29 | 'port' => $_SERVER['REMOTE_PORT'], | 9 | 'port' => $_SERVER['REMOTE_PORT'], |
| 30 | 'ua' => $_SERVER['HTTP_USER_AGENT'], | 10 | 'ua' => $_SERVER['HTTP_USER_AGENT'], |
| 31 | 'lang' => $_SERVER['HTTP_ACCEPT_LANGUAGE'], | 11 | 'lang' => $_SERVER['HTTP_ACCEPT_LANGUAGE'], |
| 32 | 'mime' => $_SERVER['HTTP_ACCEPT'], | 12 | 'mime' => $_SERVER['HTTP_ACCEPT'], |
| 33 | 'encoding' => $_SERVER['HTTP_ACCEPT_ENCODING'], | 13 | 'encoding' => $_SERVER['HTTP_ACCEPT_ENCODING'], |
| 34 | 'charset' => $_SERVER['HTTP_ACCEPT_CHARSET'], | 14 | 'charset' => $_SERVER['HTTP_ACCEPT_CHARSET'], |
| 35 | 'connection' => $_SERVER['HTTP_CONNECTION'], | 15 | 'connection' => $_SERVER['HTTP_CONNECTION'], |
| 36 | 'cache' => $_SERVER['HTTP_CACHE_CONTROL'], | 16 | 'cache' => $_SERVER['HTTP_CACHE_CONTROL'], |
| 37 | 'cookie' => $_SERVER['HTTP_COOKIE'], | 17 | 'cookie' => $_SERVER['HTTP_COOKIE'], |
| 38 | 'referer' => $_SERVER['HTTP_REFERER'], | 18 | 'referer' => $_SERVER['HTTP_REFERER'], |
| 39 | 'real_ip' => $_SERVER['HTTP_X_REAL_IP'], | 19 | 'real_ip' => $_SERVER['HTTP_X_REAL_IP'], |
| 40 | 'fwd_ip' => $_SERVER['HTTP_X_FORWARDED_FOR'], | 20 | 'fwd_ip' => $_SERVER['HTTP_X_FORWARDED_FOR'], |
| 41 | 'fwd_host' => (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? gethostbyaddr($_SERVER['HTTP_X_FORWARDED_FOR']) : ""), | 21 | 'fwd_host' => (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? gethostbyaddr($_SERVER['HTTP_X_FORWARDED_FOR']) : ""), |
| 42 | 'dnt' => $_SERVER['HTTP_DNT'] | 22 | 'dnt' => $_SERVER['HTTP_DNT'] |
| 43 | ); | 23 | ); |
| 44 | 24 | ||
| 45 | // Check request (ex. ifconfig.php?q=ip) | 25 | // Check request (ex. ifconfig.php?q=ip) |
| @@ -56,64 +36,67 @@ elseif (isset($query) && (($query=="text") || ($query=="all"))) { | |||
| 56 | echo $key.": ".$value."\n"; | 36 | echo $key.": ".$value."\n"; |
| 57 | } | 37 | } |
| 58 | die(); | 38 | die(); |
| 59 | |||
| 60 | } elseif (isset($query) && ($query=="xml")) { | 39 | } elseif (isset($query) && ($query=="xml")) { |
| 61 | header('Content-Type: text/xml'); | 40 | header('Content-Type: text/xml'); |
| 62 | 41 | // Function for SimpleXML creation | |
| 63 | // Function for SimpleXML creation | 42 | function array_to_xml(array $arr, SimpleXMLElement $xml) |
| 64 | function array_to_xml(array $arr, SimpleXMLElement $xml) | 43 | { |
| 65 | { | 44 | foreach ($arr as $k => $v) { |
| 66 | foreach ($arr as $k => $v) { | 45 | is_array($v) |
| 67 | is_array($v) | 46 | ? array_to_xml($v, $xml->addChild($k)) |
| 68 | ? array_to_xml($v, $xml->addChild($k)) | 47 | : $xml->addChild($k, $v); |
| 69 | : $xml->addChild($k, $v); | 48 | } |
| 70 | } | 49 | return $xml; |
| 71 | return $xml; | 50 | } |
| 72 | } | 51 | echo array_to_xml($user, new SimpleXMLElement('<info/>'))->asXML(); |
| 73 | echo array_to_xml($user, new SimpleXMLElement('<info/>'))->asXML(); | ||
| 74 | |||
| 75 | } elseif (isset($query) && ($query=="json")) { | 52 | } elseif (isset($query) && ($query=="json")) { |
| 76 | header('Content-Type: application/json'); | 53 | header('Content-Type: application/json'); |
| 77 | die(json_encode($user)); | 54 | die(json_encode($user)); |
| 78 | |||
| 79 | } else { | 55 | } else { |
| 80 | header('Content-Type: text/html'); | 56 | header('Content-Type: text/html'); |
| 81 | ?><!DOCTYPE html> | 57 | echo <<<EOD |
| 82 | <html lang="en"> | 58 | <!DOCTYPE html> |
| 83 | <head> | 59 | <html lang="en"> |
| 84 | <meta charset="UTF-8"> | 60 | <head> |
| 85 | <title>info</title> | 61 | <meta charset="UTF-8"> |
| 86 | <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/> | 62 | <title>{$site_title}</title> |
| 87 | <style> | 63 | <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/> |
| 88 | body { | 64 | <style> |
| 89 | background: #FDFDFD; | 65 | p,a { |
| 90 | color: #111; | 66 | font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, 'DejaVu Sans Mono', monospace; |
| 91 | font-size: .9em; | 67 | line-height: 1em; |
| 92 | } | 68 | } |
| 93 | p { | 69 | .small, .small > a { |
| 94 | font-family: "Source Code Pro", "Droid Mono", "Courier New", "Consolas", "Terminal", fixed; | 70 | font-size: 9pt; |
| 95 | line-height: 1em; | 71 | color: #777; |
| 96 | } | 72 | text-align: center; |
| 97 | .small, .small > a { | 73 | text-decoration: none; |
| 98 | font-size: 9pt; | 74 | } |
| 99 | color: #777; | 75 | </style> |
| 100 | text-align: center; | 76 | </head> |
| 101 | text-decoration: none; | 77 | <body> |
| 102 | } | 78 | <nav> |
| 103 | </style> | 79 | <a href="/">home</a> · |
| 104 | </head> | 80 | <a href="/?q=text">text</a> · |
| 105 | <body> | 81 | <a href="/?q=xml">xml</a> · |
| 106 | <? | 82 | <a href="/?q=ip">ip</a> · |
| 83 | <a href="/?q=ua">ua</a> | ||
| 84 | </nav> | ||
| 85 | <hr> | ||
| 86 | EOD; | ||
| 87 | |||
| 107 | foreach($user as $key => $value) { | 88 | foreach($user as $key => $value) { |
| 108 | echo ' <p id="'.$key.'">'.$key.': '.$value.'</p>'."\n"; | 89 | echo ' <p id="'.$key.'">'.$key.': '.$value.'</p>'."\n"; |
| 109 | } | 90 | } |
| 110 | ?> | 91 | |
| 111 | <br/> | 92 | $date = date("Y"); |
| 112 | <p class="small">Copyright © 2014 <a href="http://briskin.org">Sergey Briskin</a>.<br/> | 93 | echo <<<EOD |
| 113 | <a href="https://github.com/sbriskin/ifconfig.php">Get Source code on GitHub</a></p> | 94 | <br> |
| 114 | </body> | 95 | <p class="small">Copyright © {$date} <a href="https://cleberg.net">Christian Cleberg</a>.<br/> |
| 115 | </html> | 96 | <a target="_blank" rel="noreferrer" href="https://git.sr.ht/~cmc/ifconfig.php">Source Code</a></p> |
| 116 | <? | 97 | </body> |
| 98 | </html> | ||
| 99 | EOD; | ||
| 117 | } | 100 | } |
| 118 | die(); | 101 | die(); |
| 119 | ?> | 102 | ?> |