Changeset 5954 for extensions
- Timestamp:
- Apr 24, 2010, 10:18:27 PM (15 years ago)
- Location:
- extensions/whois_online
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/whois_online/Changelog.txt.php
r5916 r5954 3 3 Plugin Name: Whois online 4 4 ** History ** 5 2010-04-24 2.0.m 6 Fix: IE8 User agent could be too long 7 Fix: Failure on localisation (a French internet provider blocks external get_files) 8 Fix: Loss of previous collected data 9 5 10 2010-04-18 2.0.l 6 11 "Undefined index: Code" is removed -
extensions/whois_online/include/wo_functions.inc.php
r3695 r5954 2 2 /* Functions */ 3 3 4 5 6 7 8 9 4 /* Secure Config */ 5 if (!isset($conf['Whois Online']) or !isset($conf_whois['Active'])) $conf_whois = whois_online_conf(); 6 7 function whois_online_conf() 8 { 9 global $conf; 10 $default = array( 11 'Active' => true, 12 'Delete level' => 20, 13 'Radar limit' => 25, 14 'Webmasters' => 2, // Normal 15 'Administrators' => 2, 16 'Obsolete limit' => 20, 17 'Default display' => true, 18 'Add to Plugins menu' => false, 19 'Add icon to History' => true, 20 'Keep data' => true, 21 'Search id' => 0, 22 'Users' => Array('max' => 0, 'When' => date('Y-m-d'), 'count' => 0), 23 ); 24 if (!isset($conf['Whois Online'])) $conf['Whois Online'] = serialize(Array()); 25 $conf_whois = array_merge($default, unserialize($conf['Whois Online'])); 26 if ((!isset($conf_whois['Version'])) or $conf_whois['Version'] != WHOIS_ONLINE_VER 27 or $conf['Whois Online'] != serialize($conf_whois)) { 28 $conf_whois['Version'] = WHOIS_ONLINE_VER; 29 $conf['Whois Online'] = serialize($conf_whois); 30 pwg_query('REPLACE INTO ' . CONFIG_TABLE . " (param,value,comment) 31 VALUES ('Whois Online','". $conf['Whois Online'] ."','Whois Online configuration');"); 32 } 33 return $conf_whois; 34 } 35 36 37 if ( !function_exists('pwg_get_contents') ) { 38 function pwg_get_contents($url, $mode='') { 39 40 global $pwg_mode, $pwg_prev_host; 41 $timeout = 5; // will be a parameter (only for the socket) 42 43 $host = (strtolower(substr($url,0,7)) == 'http://') ? substr($url,7) : $url; 44 $host = (strtolower(substr($host,0,8)) == 'https://') ? substr($host,8) : $host; 45 $doc = substr($host, strpos($host, '/')); 46 $host = substr($host, 0, strpos($host, '/')); 47 48 if ($pwg_prev_host != $host) $pwg_mode = ''; // What was possible with one website could be different with another 49 $pwg_prev_host = $host; 50 if (isset($pwg_mode)) $mode = $pwg_mode; 51 if ($mode == 'r') $mode = ''; 52 // $mode = 'ch'; // Forcing a test '' all, 'fs' fsockopen, 'ch' cURL 53 54 // 1 - The simplest solution: file_get_contents 55 // Contraint: php.ini 56 // ; Whether to allow the treatment of URLs (like http:// or ftp://) as files. 57 // allow_url_fopen = On 58 if ( $mode == '' ) { 59 if ( true === (bool) ini_get('allow_url_fopen') ) { 60 $value = file_get_contents($url); 61 if ( $value !== false and substr($value,0,21) != '<!DOCTYPE HTML PUBLIC') { 62 return $value; 63 } 64 } 65 } 66 if ( $mode == '' ) $mode = 'fs'; 67 if ( $pwg_mode == '' ) $pwg_mode = 'fs'; // Remind it 68 // 2 - Often accepted access: fsockopen 69 if ($mode == 'fs') { 70 $fs = fsockopen($host, 80, $errno, $errstr, $timeout); 71 if ( $fs !== false ) { 72 fwrite($fs, 'GET ' . $doc . " HTTP/1.1\r\n"); 73 fwrite($fs, 'Host: ' . $host . "\r\n"); 74 fwrite($fs, "Connection: Close\r\n\r\n"); 75 stream_set_blocking($fs, TRUE); 76 stream_set_timeout($fs,$timeout); // Again the $timeout on the get 77 $info = stream_get_meta_data($fs); 78 $value = ''; 79 while ((!feof($fs)) && (!$info['timed_out'])) { 80 $value .= fgets($fs, 4096); 81 $info = stream_get_meta_data($fs); 82 flush(); 83 } 84 if ( $info['timed_out'] === false and substr($value,0,21) != '<!DOCTYPE HTML PUBLIC') return $value; 85 } 86 } 87 88 if ( $pwg_mode == 'fs' ) $pwg_mode = 'ch'; // Remind it 89 // 3 - Sometime another solution: curl_exec 90 // See http://fr2.php.net/manual/en/curl.installation.php 91 if (function_exists('curl_init') and $pwg_mode == 'ch') { 92 $ch = @curl_init(); 93 @curl_setopt($ch, CURLOPT_URL, $url); 94 @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 95 @curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 96 @curl_setopt($ch, CURLOPT_HEADER, 1); 97 @curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0'); 98 @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 99 @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 100 $value = @curl_exec($ch); 101 $header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE); 102 $status = @curl_getinfo($ch, CURLINFO_HTTP_CODE); 103 @curl_close($value); 104 if ($value !== false and $status >= 200 and $status < 400) { 105 $value = substr($value, $header_length); 106 // echo '<br/>-ch- ('. $value . ') <br/>'; 107 return $value; 108 } 109 else $pwg_mode = 'failed'; // Sorry but remind it as well 110 } 111 112 // No other solutions 113 return false; 114 } 115 } 116 // Assume the Default display on pages 117 function whois_default_display() { 118 global $template; 119 $template->set_filenames(array( 'Whois_display' => dirname(__FILE__).'/../default.tpl')); 120 $template->pparse('Whois_display'); 121 } 122 123 // Add admin links 124 function whois_add_icon($menu) { 125 global $conf_whois, $lang; 126 if ($conf_whois['Add icon to History']) 127 $lang['History'] .= '</a> <a class="external" href="' . get_admin_plugin_menu_link(WHOIS_ONLINE_PATH.'config.php') . '"> 128 <img class="button" src="' . WHOIS_ONLINE_PATH . 'icons/Whois_tuner.gif" alt="Whois Online configuration" title="Whois Online configuration" /></a>'; 129 if ($conf_whois['Add to Plugins menu']) array_push($menu, array( 130 'NAME' => 'Whois Online', 131 'URL' => get_admin_plugin_menu_link(WHOIS_ONLINE_PATH.'config.php'), 132 )); 133 return $menu; 134 } 135 136 // Template function 137 function Whois_most($text, $count, $when, $format) { 138 return sprintf(l10n($text),$count,date(l10n($format),$when)); 139 } 140 141 // New member 142 function whois_online_register($who) { 143 global $conf, $conf_whois; 144 $conf_whois['Users']['count'] = $who['id']; 145 $conf['Whois Online'] = serialize($conf_whois); 146 pwg_query('REPLACE INTO ' . CONFIG_TABLE . " (param,value,comment) 147 VALUES ('Whois Online','". $conf['Whois Online'] ."','Whois Online configuration');"); 148 return; 149 } 150 151 function whois_country($trace, $bypass = false) { 152 if (!isset($trace['country'])) { 153 pwg_query('ALTER TABLE ' . WHOIS_ONLINE_TABLE . ' ADD `country` VARCHAR( 255 ) NOT NULL AFTER `lang` ;'); 154 $trace['country']=''; 155 } 156 $c = array(); 157 if ($trace['country']!='') $c = @unserialize(htmlspecialchars_decode($trace['country'])); 158 if (isset($c['Code']) and $c['Code']!='' and $c['Code']!='__') return $c; 159 if ($bypass and isset($c['Code']) and $c['Code']=='__') return $c; 160 $result = pwg_get_contents ('http://api.hostip.info/get_html.php?ip=' . $trace['IP'], 'r'); 161 if ( $result !== false ) { 162 $tokens = preg_split("/[:]+/", $result); 163 $c = array ('Name' => $tokens[1], 'City' => substr($tokens[3],0,-3)); 164 if (strpos ($c['Name'], '?') === FALSE) { 165 $tokens = preg_split ("/[\(\)]/", $c['Name']); 166 $c['Code'] = isset($tokens[1]) ? $tokens[1]:'__'; 167 $c['Name'] = ucwords ( strtolower( substr($c['Name'],0,-5))); 168 } 169 else $c = Array('Code' => '__', 'Name' => l10n('Unknown country'), 'City' => 'N/A',); 170 } 171 if (stripos($c['Name'], 'Squid')!==false) $c = Array('Code' => '__', 'Name' => l10n('Unknown country'), 'City' => 'N/A',); 172 else $c = Array('Code' => '__', 'Name' => l10n('Unknown country'), 'City' => 'N/A',); 173 if ($c['Code'] == 'Private Address') { 174 $c['Name'] = l10n('Private Address'); 175 $c['City'] = l10n('N/A'); 176 $c['Code'] = '__'; 177 } 178 $new = htmlspecialchars(serialize($c),ENT_QUOTES,'UTF-8'); 179 if ($new == $trace['country']) return $c; 180 pwg_query('UPDATE ' . WHOIS_ONLINE_TABLE . ' 181 SET `country` = \'' . $new . '\' 182 WHERE `session_id` = \'' . $trace['session_id'] . '\';'); 183 return $c; 184 } 185 186 function whois_flag($trace, &$step, $limit = 10) { 187 $flag = WHOIS_ONLINE_PATH . 'flags/' . $trace['Country']['Code'] . '.jpg'; 188 if (file_exists($flag)) return $flag; 189 if ( $step > $limit ) return WHOIS_ONLINE_PATH . 'flags/__.jpg'; 190 $f = fopen ('http://api.hostip.info/flag.php?ip=' . $trace['IP'], 'r'); 191 $result=''; 192 while ($l = fgets ($f, 1024)) $result .= $l; 193 fclose ($f); 194 $f = fopen($flag,"w+"); 195 fputs($f,$result); 196 fclose($f); 197 return $flag; 198 } 199 200 // Read all data 201 function whois_online_get_data($order='') { 202 $remove = "''"; // Nothing to remove ( = an empty session_id) 203 $ctr = 0; $Online[0] = ''; 204 $result = pwg_query('SELECT * FROM ' . WHOIS_ONLINE_TABLE . $order . ';'); 205 while($row=mysql_fetch_array($result)) { 206 $row['delay'] = (int) time() - $row['last_access']; 207 $row['elm_ids'] = explode(' ', $row['last_elm_ids']); 208 $row['cat_ids'] = explode(' ', $row['last_cat_ids']); 209 $row['tag_ids'] = explode(' ', $row['last_tag_ids']); 210 $row['sch_ids'] = explode(' ', $row['last_sch_ids']); 211 $row['dates'] = explode(' ', $row['last_dates']); 212 $ctr++; 213 if ( $row['IP'] != 'global' and $row['permanent'] == 'false' 214 and $row['delay'] > (float)( 60 * 60 * 24 * 3 )) $remove .= ", '" . $row['session_id'] . "'"; 215 elseif ($row['IP'] == 'global') $Online[0] = $row; 216 else $Online[] = $row; 217 } 218 // Out of 7 visits: Reduce registered visits for 3 days without access 219 if ($remove != "''" and $ctr > (count($Online) * ONLINE_LEVEL) 220 and ($ctr-count($Online)) > ONLINE_LIMIT and ($Online[0]['pag_hits']%7)==0) { 221 pwg_query('DELETE FROM ' . WHOIS_ONLINE_TABLE . ' WHERE `session_id` IN ('. $remove .') 222 AND `permanent` = \'false\' AND `IP` <> \'global\';'); 223 if (($Online[0]['pag_hits']%13)==0) @pwg_query('OPTIMIZE TABLE ' . WHOIS_ONLINE_TABLE . ';'); 224 } 225 return $Online; 226 } 227 228 // Update global and update/create current session_id 229 function whois_online_update(&$global, &$dedicated, &$gtrace) 230 { 231 global $lang_info; 232 // Rewrite the global record 233 if ( $gtrace == 2 ) { 234 $query = 'REPLACE INTO ' . WHOIS_ONLINE_TABLE . ' (`IP`, `hidden_IP`, `session_id`,`user_id`,`username`,`lang`, 235 `permanent`,`last_access`,`last_elm_ids`, `last_cat_ids`, `last_tag_ids`, `last_sch_ids`, 236 `first_access_date`, `last_dates`, `elm_hits`, `pag_hits`) 237 VALUES (\'global\', \'true\',\'global\', 0, \''. $global['username'] .'\', \'--\', \'true\', \'' 238 . time() .'\', \'' 239 . implode(' ',$global['elm_ids']) . '\', \'' 240 . implode(' ',$global['cat_ids']) . '\', \'' 241 . implode(' ',$global['tag_ids']) . '\', \'' 242 . implode(' ',$global['sch_ids']) . '\', \'' 243 . $global['first_access_date'] . '\', \'\', \'' 244 . $global['elm_hits'] . '\', \'' . $global['pag_hits'] . '\');'; 245 pwg_query($query); 246 } 247 // Write or Rewrite the dedicated record 248 $query = 'REPLACE INTO ' . WHOIS_ONLINE_TABLE . ' (`IP`, `hidden_IP`, `session_id`,`user_id`,`username`,`lang`, `user_agent`, 249 `any_previous`, `same_previous`, `permanent`,`last_access`,`last_elm_ids`, `last_cat_ids`, `last_tag_ids`, `last_sch_ids`, 250 `first_access_date`, `last_dates`, `elm_hits`, `pag_hits`) 251 VALUES (\''. $dedicated['IP'] .'\', \'' 252 . $dedicated['hidden_IP'] .'\', \''. $dedicated['session_id'] .'\', \'' 253 . $dedicated['user_id'] .'\', \''. $dedicated['username'] .'\', \'' 254 . substr($lang_info['code'],0,2) .'\', \'' 255 . $dedicated['user_agent'] .'\', \'' 256 . $dedicated['any_previous'] .'\', \'' 257 . $dedicated['same_previous'] .'\', \'' 258 . $dedicated['permanent'] . '\', \''. time() .'\', \'' 259 . implode(' ',$dedicated['elm_ids']) . '\', \'' 260 . implode(' ',$dedicated['cat_ids']) . '\', \'' 261 . implode(' ',$dedicated['tag_ids']) . '\', \'' 262 . implode(' ',$dedicated['sch_ids']) . '\', \'' 263 . $dedicated['first_access_date'] . '\', \'' 264 . implode(' ',$dedicated['dates']) . '\', \'' 265 . $dedicated['elm_hits'] . '\', \'' 266 . $dedicated['pag_hits'] . '\');'; 267 pwg_query($query); 268 } 269 270 // Data tracking 271 // Parameters: 272 // - Array of Ids 273 // - New ID 274 // - Array of dates 275 // => Add the ID if needed, Add Today if needed 276 function whois_online_track(&$key, $id, &$date) { 277 if ($id != '') array_unshift($key, $id); 278 $key = array_unique($key); 279 if (count($key)>10) array_pop($key); 280 array_unshift($date, date('Y-m-d')); 281 $date = array_unique($date); 282 if (count($date)>5) array_pop($date); 283 return; 284 } 285 286 // Antiaspi delay conversion in seconds 287 // delay in "HH:ii:ss" or "d :HH:ii:ss" 288 // return delay in seconds 289 function whois_online_duration($date_string) 290 { 291 list($s, $i, $H, $d, $more) = 292 array_merge(array_reverse( 293 explode(" ",str_ireplace(':',' ', $date_string))), 294 array(0,0,0,0,0)); 295 $t = time(); 296 return strtotime(sprintf("+%s days %s hours %s minutes %s seconds", 297 $d, $H, $i, $s), $t) - $t; 298 } 10 299 11 300 /* -
extensions/whois_online/main.inc.php
r5916 r5954 23 23 /* 24 24 Plugin Name: Whois online 25 Version: 2.0. l25 Version: 2.0.m 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. l');31 define('WHOIS_ONLINE_VER', '2.0.m'); 32 32 global $prefixeTable, $conf; 33 33 // $conf['debug_l10n'] = true; -
extensions/whois_online/maintain.inc.php
r5810 r5954 45 45 list($hits) = mysql_fetch_row(pwg_query('SELECT SUM(hit) FROM '.IMAGES_TABLE.';')); 46 46 $pags = floor($hits * 1.69); /* estimate : 1.69 is a frequent ratio between images hits and pages hits */ 47 pwg_query(' REPLACE INTO ' . WHOIS_ONLINE_TABLE . ' (`IP`, `hidden_IP`, `session_id`, `user_id`,`username`,`lang`,`permanent`,`last_access`,47 pwg_query('INSERT IGNORE INTO ' . WHOIS_ONLINE_TABLE . ' (`IP`, `hidden_IP`, `session_id`, `user_id`,`username`,`lang`,`permanent`,`last_access`, 48 48 `last_elm_ids`, `last_cat_ids`, `last_tag_ids`, `last_sch_ids`, 49 49 `first_access_date`, `last_dates`, `elm_hits`, `pag_hits`) -
extensions/whois_online/online.php
r5916 r5954 4 4 global $conf, $conf_whois, $prefixeTable; 5 5 include_once(WHOIS_ONLINE_PATH.'include/wo_functions.inc.php'); 6 /* Secure Config */7 if (!isset($conf_whois['Active'])) $conf_whois = whois_online_conf();8 9 function whois_online_conf()10 {11 global $conf;12 $default = array(13 'Active' => true,14 'Delete level' => 20,15 'Radar limit' => 25,16 'Webmasters' => 2, // Normal17 'Administrators' => 2,18 'Obsolete limit' => 20,19 'Default display' => true,20 'Add to Plugins menu' => false,21 'Add icon to History' => true,22 'Keep data' => true,23 'Search id' => 0,24 'Users' => Array('max' => 0, 'When' => date('Y-m-d'), 'count' => 0),25 );26 $conf_whois = array_merge($default, unserialize($conf['Whois Online']));27 if ((!isset($conf_whois['Version'])) or $conf_whois['Version'] != WHOIS_ONLINE_VER28 or $conf['Whois Online'] != serialize($conf_whois)) {29 $conf_whois['Version'] = WHOIS_ONLINE_VER;30 $conf['Whois Online'] = serialize($conf_whois);31 pwg_query('REPLACE INTO ' . CONFIG_TABLE . " (param,value,comment)32 VALUES ('Whois Online','". $conf['Whois Online'] ."','Whois Online configuration');");33 }34 return $conf_whois;35 }36 6 37 7 define('ONLINE_LEVEL', (100+$conf_whois['Delete level'])/100); … … 49 19 } 50 20 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 another63 $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' cURL67 68 // 1 - The simplest solution: file_get_contents69 // Contraint: php.ini70 // ; Whether to allow the treatment of URLs (like http:// or ftp://) as files.71 // allow_url_fopen = On72 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 it82 // 2 - Often accepted access: fsockopen83 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 get91 $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 it103 // 3 - Sometime another solution: curl_exec104 // See http://fr2.php.net/manual/en/curl.installation.php105 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 well124 }125 126 // No other solutions127 return false;128 }129 }130 // Assume the Default display on pages131 function whois_default_display() {132 global $template;133 $template->set_filenames(array( 'Whois_display' => dirname(__FILE__).'/default.tpl'));134 $template->pparse('Whois_display');135 }136 137 // Add admin links138 function whois_add_icon($menu) {139 global $conf_whois, $lang;140 if ($conf_whois['Add icon to History'])141 $lang['History'] .= '</a> <a class="external" href="' . get_admin_plugin_menu_link(WHOIS_ONLINE_PATH.'config.php') . '">142 <img class="button" src="' . WHOIS_ONLINE_PATH . 'icons/Whois_tuner.gif" alt="Whois Online configuration" title="Whois Online configuration" /></a>';143 if ($conf_whois['Add to Plugins menu']) array_push($menu, array(144 'NAME' => 'Whois Online',145 'URL' => get_admin_plugin_menu_link(WHOIS_ONLINE_PATH.'config.php'),146 ));147 return $menu;148 }149 150 // Template function151 function Whois_most($text, $count, $when, $format) {152 return sprintf(l10n($text),$count,date(l10n($format),$when));153 }154 155 // New member156 function whois_online_register($who) {157 global $conf, $conf_whois;158 $conf_whois['Users']['count'] = $who['id'];159 $conf['Whois Online'] = serialize($conf_whois);160 pwg_query('REPLACE INTO ' . CONFIG_TABLE . " (param,value,comment)161 VALUES ('Whois Online','". $conf['Whois Online'] ."','Whois Online configuration');");162 return;163 }164 165 function whois_country($trace, $bypass = false) {166 if (!isset($trace['country'])) {167 pwg_query('ALTER TABLE ' . WHOIS_ONLINE_TABLE . ' ADD `country` VARCHAR( 255 ) NOT NULL AFTER `lang` ;');168 $trace['country']='';169 }170 $c = array();171 if ($trace['country']!='') $c = @unserialize(htmlspecialchars_decode($trace['country']));172 if (isset($c['Code']) and $c['Code']!='' and $c['Code']!='__') return $c;173 if ($bypass and isset($c['Code']) and $c['Code']=='__') return $c;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 }183 else $c = Array('Code' => '__', 'Name' => l10n('Unknown country'), 'City' => 'N/A',);184 }185 else $c = Array('Code' => '__', 'Name' => l10n('Unknown country'), 'City' => 'N/A',);186 if ($c['Code'] == 'Private Address') {187 $c['Name'] = l10n('Private Address');188 $c['City'] = l10n('N/A');189 $c['Code'] = '__';190 }191 $new = htmlspecialchars(serialize($c),ENT_QUOTES,'UTF-8');192 if ($new == $trace['country']) return $c;193 pwg_query('UPDATE ' . WHOIS_ONLINE_TABLE . '194 SET `country` = \'' . $new . '\'195 WHERE `session_id` = \'' . $trace['session_id'] . '\';');196 return $c;197 }198 199 function whois_flag($trace, &$step, $limit = 10) {200 $flag = WHOIS_ONLINE_PATH . 'flags/' . $trace['Country']['Code'] . '.jpg';201 if (file_exists($flag)) return $flag;202 if ( $step > $limit ) return WHOIS_ONLINE_PATH . 'flags/__.jpg';203 $f = fopen ('http://api.hostip.info/flag.php?ip=' . $trace['IP'], 'r');204 $result='';205 while ($l = fgets ($f, 1024)) $result .= $l;206 fclose ($f);207 $f = fopen($flag,"w+");208 fputs($f,$result);209 fclose($f);210 return $flag;211 }212 213 // Read all data214 function whois_online_get_data($order='') {215 $remove = "''"; // Nothing to remove ( = an empty session_id)216 $ctr = 0; $Online[0] = '';217 $result = pwg_query('SELECT * FROM ' . WHOIS_ONLINE_TABLE . $order . ';');218 while($row=mysql_fetch_array($result)) {219 $row['delay'] = (int) time() - $row['last_access'];220 $row['elm_ids'] = explode(' ', $row['last_elm_ids']);221 $row['cat_ids'] = explode(' ', $row['last_cat_ids']);222 $row['tag_ids'] = explode(' ', $row['last_tag_ids']);223 $row['sch_ids'] = explode(' ', $row['last_sch_ids']);224 $row['dates'] = explode(' ', $row['last_dates']);225 $ctr++;226 if ( $row['IP'] != 'global' and $row['permanent'] == 'false'227 and $row['delay'] > (float)( 60 * 60 * 24 * 3 )) $remove .= ", '" . $row['session_id'] . "'";228 elseif ($row['IP'] == 'global') $Online[0] = $row;229 else $Online[] = $row;230 }231 // Out of 7 visits: Reduce registered visits for 3 days without access232 if ($remove != "''" and $ctr > (count($Online) * ONLINE_LEVEL)233 and ($ctr-count($Online)) > ONLINE_LIMIT and ($Online[0]['pag_hits']%7)==0) {234 pwg_query('DELETE FROM ' . WHOIS_ONLINE_TABLE . ' WHERE `session_id` IN ('. $remove .')235 AND `permanent` = \'false\' AND `IP` <> \'global\';');236 if (($Online[0]['pag_hits']%13)==0) @pwg_query('OPTIMIZE TABLE ' . WHOIS_ONLINE_TABLE . ';');237 }238 return $Online;239 }240 241 // Update global and update/create current session_id242 function whois_online_update(&$global, &$dedicated, &$gtrace)243 {244 global $lang_info;245 // Rewrite the global record246 if ( $gtrace == 2 ) {247 $query = 'REPLACE INTO ' . WHOIS_ONLINE_TABLE . ' (`IP`, `hidden_IP`, `session_id`,`user_id`,`username`,`lang`,248 `permanent`,`last_access`,`last_elm_ids`, `last_cat_ids`, `last_tag_ids`, `last_sch_ids`,249 `first_access_date`, `last_dates`, `elm_hits`, `pag_hits`)250 VALUES (\'global\', \'true\',\'global\', 0, \''. $global['username'] .'\', \'--\', \'true\', \''251 . time() .'\', \''252 . implode(' ',$global['elm_ids']) . '\', \''253 . implode(' ',$global['cat_ids']) . '\', \''254 . implode(' ',$global['tag_ids']) . '\', \''255 . implode(' ',$global['sch_ids']) . '\', \''256 . $global['first_access_date'] . '\', \'\', \''257 . $global['elm_hits'] . '\', \'' . $global['pag_hits'] . '\');';258 pwg_query($query);259 }260 // Write or Rewrite the dedicated record261 $query = 'REPLACE INTO ' . WHOIS_ONLINE_TABLE . ' (`IP`, `hidden_IP`, `session_id`,`user_id`,`username`,`lang`, `user_agent`,262 `any_previous`, `same_previous`, `permanent`,`last_access`,`last_elm_ids`, `last_cat_ids`, `last_tag_ids`, `last_sch_ids`,263 `first_access_date`, `last_dates`, `elm_hits`, `pag_hits`)264 VALUES (\''. $dedicated['IP'] .'\', \''265 . $dedicated['hidden_IP'] .'\', \''. $dedicated['session_id'] .'\', \''266 . $dedicated['user_id'] .'\', \''. $dedicated['username'] .'\', \''267 . substr($lang_info['code'],0,2) .'\', \''268 . $dedicated['user_agent'] .'\', \''269 . $dedicated['any_previous'] .'\', \''270 . $dedicated['same_previous'] .'\', \''271 . $dedicated['permanent'] . '\', \''. time() .'\', \''272 . implode(' ',$dedicated['elm_ids']) . '\', \''273 . implode(' ',$dedicated['cat_ids']) . '\', \''274 . implode(' ',$dedicated['tag_ids']) . '\', \''275 . implode(' ',$dedicated['sch_ids']) . '\', \''276 . $dedicated['first_access_date'] . '\', \''277 . implode(' ',$dedicated['dates']) . '\', \''278 . $dedicated['elm_hits'] . '\', \''279 . $dedicated['pag_hits'] . '\');';280 pwg_query($query);281 }282 283 // Data tracking284 // Parameters:285 // - Array of Ids286 // - New ID287 // - Array of dates288 // => Add the ID if needed, Add Today if needed289 function whois_online_track(&$key, $id, &$date) {290 if ($id != '') array_unshift($key, $id);291 $key = array_unique($key);292 if (count($key)>10) array_pop($key);293 array_unshift($date, date('Y-m-d'));294 $date = array_unique($date);295 if (count($date)>5) array_pop($date);296 return;297 }298 299 // Antiaspi delay conversion in seconds300 // delay in "HH:ii:ss" or "d :HH:ii:ss"301 // return delay in seconds302 function whois_online_duration($date_string)303 {304 list($s, $i, $H, $d, $more) =305 array_merge(array_reverse(306 explode(" ",str_ireplace(':',' ', $date_string))),307 array(0,0,0,0,0));308 $t = time();309 return strtotime(sprintf("+%s days %s hours %s minutes %s seconds",310 $d, $H, $i, $s), $t) - $t;311 }312 21 313 22 /* … … 523 232 $ctr_same = count(explode(' ',$visit['same_previous'])); 524 233 525 $visit['user_agent'] = $_SERVER['HTTP_USER_AGENT'];234 $visit['user_agent'] = substr($_SERVER['HTTP_USER_AGENT'],0,160); 526 235 $Vip =& $visit['IP']; 527 236 $visit['Allowed_SE'] = false;
Note: See TracChangeset
for help on using the changeset viewer.