Changeset 5810
- Timestamp:
- Apr 12, 2010, 12:00:47 AM (14 years ago)
- Location:
- extensions/whois_online
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/whois_online/Changelog.txt.php
r3695 r5810 3 3 Plugin Name: Whois online 4 4 ** History ** 5 2010-04-11 2.0.k 6 MySQL 4.1 support 7 Alternate reading solutions: file_get_contents / fsockopen / curl 8 Replace of deprecated functions as of PHP 5.3.0 5 9 2009-07-28 2.0.j 6 10 Minor changes in Config management -
extensions/whois_online/main.inc.php
r3695 r5810 23 23 /* 24 24 Plugin Name: Whois online 25 Version: 2.0. j25 Version: 2.0.k 26 26 Description: Who is online? 27 27 Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=279 … … 29 29 Author URI: http://www.vdigital.org 30 30 */ 31 define('WHOIS_ONLINE_VER', '2.0. j');31 define('WHOIS_ONLINE_VER', '2.0.k'); 32 32 global $prefixeTable, $conf; 33 33 // $conf['debug_l10n'] = true; -
extensions/whois_online/maintain.inc.php
r3695 r5810 16 16 `username` varchar(100) character set utf8 collate utf8_bin NOT NULL DEFAULT '', 17 17 `lang` char(2) character set utf8 collate utf8_bin NOT NULL DEFAULT 'en', 18 `country` VARCHAR( 25 6) NOT NULL DEFAULT '',18 `country` VARCHAR( 255 ) NOT NULL DEFAULT '', 19 19 `user_agent` VARCHAR( 160 ) NOT NULL DEFAULT '', 20 `any_previous` VARCHAR( 25 6) NOT NULL DEFAULT '',21 `same_previous` VARCHAR( 25 6) NOT NULL DEFAULT '',20 `any_previous` VARCHAR( 255 ) NOT NULL DEFAULT '', 21 `same_previous` VARCHAR( 255 ) NOT NULL DEFAULT '', 22 22 `permanent` enum('true','false') NOT NULL DEFAULT 'false', 23 23 `last_access` varchar(12) NOT NULL DEFAULT '', -
extensions/whois_online/online.php
r3695 r5810 49 49 } 50 50 51 52 53 51 if ( !function_exists('pwg_get_contents') ) { 52 function pwg_get_contents($url, $mode='') { 53 54 global $pwg_mode, $pwg_prev_host; 55 $timeout = 5; // will be a parameter (only for the socket) 56 57 $host = (strtolower(substr($url,0,7)) == 'http://') ? substr($url,7) : $url; 58 $host = (strtolower(substr($host,0,8)) == 'https://') ? substr($host,8) : $host; 59 $doc = substr($host, strpos($host, '/')); 60 $host = substr($host, 0, strpos($host, '/')); 61 62 if ($pwg_prev_host != $host) $pwg_mode = ''; // What was possible with one website could be different with another 63 $pwg_prev_host = $host; 64 if (isset($pwg_mode)) $mode = $pwg_mode; 65 if ($mode == 'r') $mode = ''; 66 // $mode = 'ch'; // Forcing a test '' all, 'fs' fsockopen, 'ch' cURL 67 68 // 1 - The simplest solution: file_get_contents 69 // Contraint: php.ini 70 // ; Whether to allow the treatment of URLs (like http:// or ftp://) as files. 71 // allow_url_fopen = On 72 if ( $mode == '' ) { 73 if ( true === (bool) ini_get('allow_url_fopen') ) { 74 $value = file_get_contents($url); 75 if ( $value !== false and substr($value,0,21) != '<!DOCTYPE HTML PUBLIC') { 76 return $value; 77 } 78 } 79 } 80 if ( $mode == '' ) $mode = 'fs'; 81 if ( $pwg_mode == '' ) $pwg_mode = 'fs'; // Remind it 82 // 2 - Often accepted access: fsockopen 83 if ($mode == 'fs') { 84 $fs = fsockopen($host, 80, $errno, $errstr, $timeout); 85 if ( $fs !== false ) { 86 fwrite($fs, 'GET ' . $doc . " HTTP/1.1\r\n"); 87 fwrite($fs, 'Host: ' . $host . "\r\n"); 88 fwrite($fs, "Connection: Close\r\n\r\n"); 89 stream_set_blocking($fs, TRUE); 90 stream_set_timeout($fs,$timeout); // Again the $timeout on the get 91 $info = stream_get_meta_data($fs); 92 $value = ''; 93 while ((!feof($fs)) && (!$info['timed_out'])) { 94 $value .= fgets($fs, 4096); 95 $info = stream_get_meta_data($fs); 96 flush(); 97 } 98 if ( $info['timed_out'] === false and substr($value,0,21) != '<!DOCTYPE HTML PUBLIC') return $value; 99 } 100 } 101 102 if ( $pwg_mode == 'fs' ) $pwg_mode = 'ch'; // Remind it 103 // 3 - Sometime another solution: curl_exec 104 // See http://fr2.php.net/manual/en/curl.installation.php 105 if (function_exists('curl_init') and $pwg_mode == 'ch') { 106 $ch = @curl_init(); 107 @curl_setopt($ch, CURLOPT_URL, $url); 108 @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 109 @curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 110 @curl_setopt($ch, CURLOPT_HEADER, 1); 111 @curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0'); 112 @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 113 @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 114 $value = @curl_exec($ch); 115 $header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE); 116 $status = @curl_getinfo($ch, CURLINFO_HTTP_CODE); 117 @curl_close($value); 118 if ($value !== false and $status >= 200 and $status < 400) { 119 $value = substr($value, $header_length); 120 // echo '<br/>-ch- ('. $value . ') <br/>'; 121 return $value; 122 } 123 else $pwg_mode = 'failed'; // Sorry but remind it as well 124 } 125 126 // No other solutions 127 return false; 128 } 129 } 54 130 // Assume the Default display on pages 55 131 function whois_default_display() { … … 89 165 function whois_country($trace, $bypass = false) { 90 166 if (!isset($trace['country'])) { 91 pwg_query('ALTER TABLE ' . WHOIS_ONLINE_TABLE . ' ADD `country` VARCHAR( 25 6) NOT NULL AFTER `lang` ;');167 pwg_query('ALTER TABLE ' . WHOIS_ONLINE_TABLE . ' ADD `country` VARCHAR( 255 ) NOT NULL AFTER `lang` ;'); 92 168 $trace['country']=''; 93 169 } … … 96 172 if (isset($c['Code']) and $c['Code']!='' and $c['Code']!='__') return $c; 97 173 if ($bypass and isset($c['Code']) and $c['Code']=='__') return $c; 98 $f = @fopen ('http://api.hostip.info/get_html.php?ip=' . $trace['IP'], 'r'); 99 if ($f === FALSE) return Array('Code' => '__', 'Name' => l10n('Unknown country'), 'City' => 'N/A',); 100 $result=''; 101 while ($l = fgets ($f, 1024)) $result .= $l; 102 fclose ($f); 103 $tokens = split ("[:\n]", $result); 104 $c = array ('Name' => $tokens[1], 'City' => $tokens[3]); 105 if (strpos ($c['Name'], '?') === FALSE) { 106 $tokens = split ("[\(\)]", $c['Name']); 107 $c['Code'] = isset($tokens[1]) ? $tokens[1]:'__'; 108 $c['Name'] = ucwords ( strtolower( ereg_replace 109 (' \([^\)]+)', '', $c['Name']))); 174 $result = pwg_get_contents ('http://api.hostip.info/get_html.php?ip=' . $trace['IP'], 'r'); 175 if ( $result !== false ) { 176 $tokens = preg_split("/[:]+/", $result); 177 $c = array ('Name' => $tokens[1], 'City' => substr($tokens[3],0,-3)); 178 if (strpos ($c['Name'], '?') === FALSE) { 179 $tokens = preg_split ("/[\(\)]/", $c['Name']); 180 $c['Code'] = isset($tokens[1]) ? $tokens[1]:'__'; 181 $c['Name'] = ucwords ( strtolower( substr($c['Name'],0,-5))); 182 } 110 183 } 111 184 else $c = Array('Code' => '__', 'Name' => l10n('Unknown country'), 'City' => 'N/A',); … … 127 200 if (file_exists($flag)) return $flag; 128 201 if ( $step > $limit ) return WHOIS_ONLINE_PATH . 'flags/__.jpg'; 129 $f = fopen('http://api.hostip.info/flag.php?ip=' . $trace['IP'], 'r');130 131 132 133 $f = fopen($flag,"w+");202 $f = fopen ('http://api.hostip.info/flag.php?ip=' . $trace['IP'], 'r'); 203 $result=''; 204 while ($l = fgets ($f, 1024)) $result .= $l; 205 fclose ($f); 206 $f = fopen($flag,"w+"); 134 207 fputs($f,$result); 135 208 fclose($f); … … 385 458 if (!isset($global['any_previous'])) { 386 459 pwg_query('ALTER TABLE ' . WHOIS_ONLINE_TABLE . 387 ' ADD `same_previous` VARCHAR( 25 6) NOT NULL DEFAULT \'\' AFTER `country`;');460 ' ADD `same_previous` VARCHAR( 255 ) NOT NULL DEFAULT \'\' AFTER `country`;'); 388 461 pwg_query('ALTER TABLE ' . WHOIS_ONLINE_TABLE . 389 ' ADD `any_previous` VARCHAR( 25 6) NOT NULL DEFAULT \'\' AFTER `country`;');462 ' ADD `any_previous` VARCHAR( 255 ) NOT NULL DEFAULT \'\' AFTER `country`;'); 390 463 pwg_query('ALTER TABLE ' . WHOIS_ONLINE_TABLE . 391 464 ' ADD `user_agent` VARCHAR( 160 ) NOT NULL DEFAULT \'\' AFTER `country`;');
Note: See TracChangeset
for help on using the changeset viewer.