[6193] | 1 | <?php |
---|
| 2 | /* Functions */ |
---|
| 3 | |
---|
| 4 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 5 | if (!defined('IN_ADMIN') or !IN_ADMIN) die('Hacking attempt!'); |
---|
| 6 | |
---|
[6201] | 7 | // Select the correct menu on loc_end_admin |
---|
[9145] | 8 | function whois_select_menu() { |
---|
[6201] | 9 | global $conf_whois, $template; |
---|
| 10 | if ($conf_whois['Add icon to History'] or !$conf_whois['Add to Plugins menu']) |
---|
| 11 | $template->assign('ACTIVE_MENU', 4); |
---|
| 12 | else $template->assign('ACTIVE_MENU', 3); |
---|
| 13 | } |
---|
| 14 | |
---|
[6193] | 15 | // Template function |
---|
| 16 | function Whois_most($text, $count, $when, $format) { |
---|
| 17 | return sprintf(l10n($text),$count,date(l10n($format),$when)); |
---|
| 18 | } |
---|
| 19 | |
---|
[31341] | 20 | function whois_country($trace, $bypass = false) |
---|
| 21 | { |
---|
| 22 | global $conf; |
---|
| 23 | |
---|
[6193] | 24 | if (!isset($trace['country'])) { |
---|
| 25 | pwg_query('ALTER TABLE ' . WHOIS_ONLINE_TABLE . ' ADD `country` VARCHAR( 254 ) NOT NULL AFTER `lang` ;'); |
---|
| 26 | $trace['country']=''; |
---|
| 27 | } |
---|
| 28 | $c = array(); |
---|
| 29 | if ($trace['country']!='') $c = @unserialize(htmlspecialchars_decode($trace['country'])); |
---|
| 30 | if (isset($c['Code']) and $c['Code']!='' and $c['Code']!='__') return $c; |
---|
| 31 | if ($bypass and isset($c['Code'])) return $c; |
---|
[31341] | 32 | |
---|
| 33 | $c = array( |
---|
| 34 | 'Code' => '__', |
---|
| 35 | 'Name' => l10n('Unknown country'), |
---|
| 36 | 'City' => 'N/A', |
---|
| 37 | ); |
---|
| 38 | |
---|
| 39 | if (!filter_var($trace['IP'], FILTER_VALIDATE_IP)) |
---|
| 40 | { |
---|
| 41 | return $c; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | if (isset($conf['whois_online_use_geoiplookup']) and $conf['whois_online_use_geoiplookup']) |
---|
| 45 | { |
---|
| 46 | $geoiplookup_output = exec('geoiplookup '.$trace['IP']); |
---|
| 47 | |
---|
| 48 | if (!preg_match('/IP Address not found/', $geoiplookup_output)) |
---|
| 49 | { |
---|
| 50 | list(,$geoiplookup_output) = explode(':', $geoiplookup_output); |
---|
| 51 | list($country_code, $country_name) = explode(',', $geoiplookup_output); |
---|
| 52 | |
---|
| 53 | $c['Name'] = trim($country_name); |
---|
| 54 | $c['Code'] = trim($country_code); |
---|
| 55 | } |
---|
| 56 | } |
---|
| 57 | else |
---|
| 58 | { |
---|
| 59 | $url = 'http://freegeoip.net/json/' . $trace['IP']; |
---|
| 60 | |
---|
| 61 | if (fetchRemote($url, $result) and $geo_data = @json_decode($result, true)) |
---|
| 62 | { |
---|
| 63 | // echo '<pre>'; print_r($geo_data); echo '</pre>'; |
---|
| 64 | $c['Name'] = $geo_data['country_name']; |
---|
| 65 | $c['Code'] = $geo_data['country_code']; |
---|
| 66 | } |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | $new = htmlspecialchars(serialize($c),ENT_QUOTES,'UTF-8'); |
---|
| 70 | |
---|
[6193] | 71 | if ($new == $trace['country']) return $c; |
---|
[31341] | 72 | |
---|
| 73 | pwg_query(' |
---|
| 74 | UPDATE ' . WHOIS_ONLINE_TABLE . ' |
---|
| 75 | SET `country` = \'' . $new . '\' |
---|
| 76 | WHERE `session_id` = \'' . $trace['session_id'] . '\' |
---|
| 77 | ;'); |
---|
| 78 | |
---|
[6193] | 79 | return $c; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | function whois_flag($trace, &$step, $limit = 10) { |
---|
| 83 | $flag = WHOIS_ONLINE_PATH . 'flags/' . $trace['Country']['Code'] . '.jpg'; |
---|
| 84 | if (file_exists($flag) and $trace['Country']['Code'] != '__' ) return $flag; |
---|
| 85 | if ($trace['Country']['Code'] == '__' ) { |
---|
| 86 | $flag = WHOIS_ONLINE_PATH . 'flags/' . substr($trace['lang'],-2, 2) . '.jpg'; |
---|
| 87 | if (file_exists($flag)) return $flag; |
---|
| 88 | return WHOIS_ONLINE_PATH . 'flags/__.jpg'; |
---|
| 89 | } |
---|
| 90 | if ( $step > $limit ) return WHOIS_ONLINE_PATH . 'flags/.jpg'; |
---|
| 91 | $f = fopen ('http://api.hostip.info/flag.php?ip=' . $trace['IP'], 'r'); |
---|
| 92 | $result=''; |
---|
| 93 | while ($l = fgets ($f, 1024)) $result .= $l; |
---|
| 94 | fclose ($f); |
---|
| 95 | $f = fopen($flag,"w+"); |
---|
| 96 | fputs($f,$result); |
---|
| 97 | fclose($f); |
---|
| 98 | return $flag; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | /* |
---|
| 102 | returns (mixed): (string) 'bot agent name' || (bool) false |
---|
| 103 | @param (string) HTTP_USER_AGENT |
---|
| 104 | */ |
---|
| 105 | function is_a_bot($agent = '') |
---|
| 106 | { |
---|
| 107 | global $conf; |
---|
| 108 | if ($agent == '') $agent = $_SERVER['HTTP_USER_AGENT']; |
---|
| 109 | $botlist = array('Teoma', 'alexa', 'froogle', 'Gigabot', 'inktomi', |
---|
| 110 | 'looksmart', 'URL_Spider_SQL', 'Firefly', 'NationalDirectory', |
---|
| 111 | 'Ask Jeeves', 'TECNOSEEK', 'InfoSeek', 'WebFindBot', 'girafabot', |
---|
| 112 | 'crawler', 'www.galaxy.com', 'Googlebot', 'Scooter', 'Slurp', |
---|
| 113 | 'msnbot', 'appie', 'FAST', 'WebBug', 'Spade', 'ZyBorg', 'rabaz', |
---|
| 114 | 'Baiduspider', 'Feedfetcher-Google', 'TechnoratiSnoop', 'Rankivabot', |
---|
| 115 | 'Mediapartners-Google', 'Sogou web spider', 'WebAlta Crawler'); |
---|
| 116 | if (isset($conf['search_agents'])) |
---|
| 117 | $botlist = array_merge( $botlist, array_diff( $conf['search_agents'], $botlist ) ); |
---|
| 118 | foreach($botlist as $bot) { |
---|
| 119 | if (stripos($agent, $bot)!==false) return $bot; |
---|
| 120 | } |
---|
| 121 | return false; |
---|
| 122 | } |
---|
| 123 | ?> |
---|