<?php
//#################################################################################################
// Webuser class
//#################################################################################################
// chillyCMS - Content Management System
// Copyright (C) 2008
// Stefanie Wiegand <hide@address.com> & Johannes Cox <hide@address.com>
//
// This program is licensed under the GPL 3.0 license. For more information see LICENSE.txt.
//#################################################################################################
defined('DOIT') or die('Restricted access');
class Webuser {
//Class variables//////////////////////////////////////////////////////////////////////////
private $agent; //User agent
private $browser;
private $browserversion;
private $ip;
private $os;
private $referer; //the site the visitor came from
private $country;
private $isbot;
//Functions////////////////////////////////////////////////////////////////////////////////
//Constructor
public function __construct() {
global $l_ctr;
//check for bots
$this->isbot=false;
$bots = '/[Ss]lurp|[Ss]earch|[Gg]rub|[Bb]ot|[Aa]rchiver|[Jj]ava|[Ss]pider|[Cc]rawler|mail.ru|[Ss]qworm|'.
'[Vv]alidator|[Ww]orm|[Vv]irus|talktalk|[Ll]arbin|[Ff]acebook|[Aa]pp[Ee]ngine|[Ss]urvey|c[Uu]rl|[Ll]ink[Ww]alker|'.
'[Pp]age2[Rr]ss|google web preview|red hat modified|google web preview|[Ww]ho[Ii]s|libwww-perl|whoisde|'.
'findlinks|compatible;|pirst|whatweb|[Ss]coutjet|netcraftsurveyagent|htdig|mail.ru|[Ww]ordpress|xenu|'.
'yahoocachesystem|htmlparser|twisted pagegetter|thegetpr.net|microsoft url control|linkchecker|nutch|'.
'synapse/';
$morebots = array('wget/1.9+cvs-stable (red hat modified)','mediapartners-google','msie 7.0',
'python-urllib/2.6','mozilla/5.0 firefox/3.6.8','mozilla','mozilla/5.0','mozilla','internet explorer 6.0',
'lynx/2.8.8dev.9 libwww-fm/2.14 ssl-mm/1.4.1 gnutls/2.10.5');
if (preg_match($bots, $_SERVER['HTTP_USER_AGENT']) or in_array($_SERVER['HTTP_USER_AGENT'], $morebots)
or trim($_SERVER['HTTP_USER_AGENT'])=='') {
$this->browser=$this->browserversion=$this->os=$this->country="Bot";
$this->isbot=true;
} else {
$mail = false;
$serverenc = (isset($_SERVER['HTTP_ACCEPT_CHARSET']))?$_SERVER['HTTP_ACCEPT_CHARSET']:'undefined';
$mailtext = 'Hello, this is a dummy text to ensure the mail is not filtered as spam.<br />'.
'chillyCMSs Botreportingtool has found an unknown HTTP_USER_AGENT string.<br /><br />'.
'<b>Server Name:</b> '.$_SERVER['SERVER_NAME'].'<br /><b>Server Address:</b> '.
$_SERVER['SERVER_ADDR'].'<br /><b>Server Encoding: </b>'.$serverenc.
'<br /><b>Server Software:</b> '.$_SERVER['SERVER_SOFTWARE'].'<br /><br />';
//browser
$browsers = array('firefox','opera','chrome','chromium','safari','seamonkey','konqueror','k-meleon',
'msie 6.0','msie 7.0','msie 8.0','msie 9.0','msie','epiphany','wget','applewebkit','curl','dillo','mosaic',
'netscape','gecko','navigator','mosaic','lynx','amaya','omniweb','avant','camino','flock','aol','mozilla',
'ms internet explorer','blackberry','iphone','android','nokia','blackberry');
$this->agent = strtolower($_SERVER["HTTP_USER_AGENT"]);
$found=0;
foreach($browsers as $browser) {
if (preg_match("#($browser)[/ ]?([0-9.]*)#", $this->agent, $match)) {
$this->browser = $match[1] ;
$this->browserversion = $match[2] ;
$found++;
break;
}
}
if ($found==0) {
$this->browser = "unknown";
$this->browserversion = "0.0.0";
$mail=true;
$mailtext .= '<p>Unknown browser: '.$this->agent.'</p><br />';
}
//ip
$this->ip = $_SERVER['REMOTE_ADDR'];
//os
if (strstr($_SERVER["HTTP_USER_AGENT"], "windows 95")) { $this->os = "Windows 95"; }
elseif (strstr($this->agent, "windows 98")) { $this->os = "Windows 98"; }
elseif (strstr($this->agent, "nt 4.0")) { $this->os = "Windows NT"; }
elseif (strstr($this->agent, "nt 5.0")) { $this->os = "Windows 2000"; }
elseif (strstr($this->agent, "nt 5.1")) { $this->os = "Windows XP"; }
elseif (strstr($this->agent, "nt 6.0")) { $this->os = "Windows Vista"; }
elseif (strstr($this->agent, "nt 6.1")) { $this->os = "Windows 7"; }
elseif (strstr($this->agent, "win")) { $this->os = "Windows"; }
elseif (strstr($this->agent, "iphone")) { $this->os = "iPhone"; }
elseif (strstr($this->agent, "android")) { $this->os = "Android"; }
elseif (strstr($this->agent, "blackberry")) { $this->os = "Blackberry"; }
elseif (strstr($this->agent, "symbian")) { $this->os = "Symbian"; }
elseif (strstr($this->agent, "nokia")) { $this->os = "Nokia"; }
elseif (strstr($this->agent, "presto")) { $this->os = "Nokia"; }
elseif (strstr($this->agent, "opera mini")) { $this->os = "Nokia"; }
elseif (strstr($this->agent, "google wireless transcoder")) { $this->os = "Mobile"; }
elseif (strstr($this->agent, "mac")) { $this->os = "MacOS"; }
elseif (strstr($this->agent, "linux")) {
if (strstr($this->agent, "ubuntu")) { $this->os = "Ubuntu"; }
elseif (strstr($this->agent, "debian")) { $this->os = "Debian"; }
elseif (strstr($this->agent, "fedora")) { $this->os = "Fedora"; }
elseif (strstr($this->agent, "red hat")) { $this->os = "Red Hat"; }
elseif (strstr($this->agent, "mint")) { $this->os = "Linux Mint"; }
elseif (strstr($this->agent, "kubuntu")) { $this->os = "Kubuntu"; }
elseif (strstr($this->agent, "opensuse")) { $this->os = "openSUSE"; }
elseif (strstr($this->agent, "mandriva")) { $this->os = "Mandriva"; }
elseif (strstr($this->agent, "gentoo")) { $this->os = "Gentoo"; }
elseif (strstr($this->agent, "arch")) { $this->os = "Arch"; }
elseif (strstr($this->agent, "slackware")) { $this->os = "Slackware"; }
elseif (strstr($this->agent, "android")) { $this->os = "Android"; }
else { $this->os = "Linux"; }
}
elseif (strstr($this->agent, "freebsd")) { $this->os = "FreeBSD"; }
elseif (strstr($this->agent, "openbsd")) { $this->os = "OpenBSD"; }
elseif (strstr($this->agent, "sunos")) { $this->os = "SunOS"; }
elseif (strstr($this->agent, "irix")) { $this->os = "IRIX"; }
elseif (strstr($this->agent, "beos")) { $this->os = "BeOS"; }
elseif (strstr($this->agent, "os/2")) { $this->os = "OS/2"; }
elseif (strstr($this->agent, "aix")) { $this->os = "AIX"; }
elseif (strstr($this->agent, "unix")) { $this->os = "Unix"; }
elseif (strstr($this->agent, "dos")) { $this->os = "DOS"; }
else {
$this->os = "unknown";
$mail=true;
$mailtext .= '<p>Unknown OS: '.$this->agent.'</p><br />';
}
//referer
if (isset($_SERVER['HTTP_REFERER'])) { $this->referer = $_SERVER['HTTP_REFERER']; }
else { $this->referer = "unknown"; }
//country
$countries = array(
"af" => "ZA", "ar-ae" => "UAE", "ar-bh" => "BAH", "ar-dz" => "ALG",
"ar-eg" => "EGY", "ar-iq" => "IRQ", "ar-jo" => "JOR", "ar-kw" => "KUW",
"ar-lb" => "LEB", "ar-ly" => "LIB", "ar-ma" => "MAR", "ar-om" => "OM",
"ar-qa" => "QAT", "ar-sa" => "SA", "ar-sy" => "SYR", "ar-tn" => "TUN",
"ar-ye" => "YEM", "ar" => "AR", "as" => "ASS", "az" => "IRN",
"be" => "BE", "bg" => "BG", "bn" => "BEN", "ca" => "CAT",
"cs" => "CZ", "da" => "DK", "de-at" => "AU", "de-ch" => "CH",
"de-li" => "LIE", "de-lu" => "LUX", "de" => "DE", "div" => "MALE",
"el" => "GR", "en-au" => "AUS", "en-bz" => "BLZ", "en-ca" => "CAN",
"en-gb" => "UK", "en-ie" => "IRL", "en-jm" => "JAM", "en-nz" => "NZ",
"en-ph" => "PHI", "en-tt" => "TRI", "en-us" => "USA", "en-za" => "ZA",
"en-zw" => "ZIM", "en" => "CAR", "es-ar" => "ARG", "es-bo" => "BOL",
"es-cl" => "CHI", "es-co" => "COL", "es-cr" => "COR", "es-do" => "DOM",
"es-ec" => "ECU", "es-es" => "E", "es-gt" => "GUA", "es-hn" => "HON",
"es-mx" => "MX", "es-ni" => "NIC", "es-pa" => "PAN", "es-pe" => "PRU",
"es-pr" => "PUE", "es-py" => "PAR", "es-sv" => "SAL", "es-us" => "USA",
"es-uy" => "URU", "es-ve" => "VEN", "es" => "E", "et" => "EST",
"eu" => "BAS", "fa" => "PER", "fi" => "FIN", "fo" => "FAE",
"fr-be" => "BE", "fr-ca" => "CAN", "fr-ch" => "CH", "fr-lu" => "LUX",
"fr-mc" => "MON", "fr" => "FR", "ga" => "IRL", "gd" => "SCO",
"gu" => "IN", "he" => "ISR", "hi" => "IN", "hr" => "HR",
"hu" => "HU", "hy" => "ARM", "id" => "IND", "is" => "ICE",
"it" => "IT", "it-ch" => "CH", "ja" => "JAP", "ji" => "ISR",
"ka" => "GEO", "kk" => "KZS", "kn" => "IN", "ko" => "KOR",
"kok" => "IN", "kz" => "KIR", "lv" => "LAT", "ls" => "SLE",
"lt" => "LIT", "mk" => "MAK", "ml" => "IN", "mn" => "MONG",
"mr" => "IN", "ms" => "MAL", "mt" => "MALT", "nb-no" => "NOR",
"ne" => "NEP", "nl-be" => "BE", "nl" => "NL", "nn-no" => "NOR",
"no" => "NOR", "or" => "IN", "pa" => "IN", "pl" => "PL",
"pt-br" => "BR", "pt" => "PTG", "rm" => "CH", "ro-mo" => "MOL",
"ro" => "RO", "ru-mo" => "MOL", "ru" => "RU", "sa" => "IN",
"sb" => "SER", "sk" => "SLA", "sl" => "SLE", "sq" => "ALB",
"sr" => "SER", "sv-fi" => "FIN", "sv" => "SWE", "sw" => "EA",
"sx" => "ZA", "syr" => "SYR", "sz" => "LAP", "ta" => "IN",
"te" => "IN", "th" => "THA", "tn" => "BOT", "tr" => "TR",
"ts" => "ZA", "tt" => "RU", "uk" => "UKR", "ur" => "PAK",
"uz" => "UZB", "ve" => "ZA", "vi" => "VI", "xh" => "ZA",
"yi" => "ISR", "zh-cn" => "CN", "zh-hk" => "HK", "zh-mo" => "MAC",
"zh-sg" => "SIN", "zh-tw" => "TAI", "zh" => "CN", "zu" => "ZA",
);
$this->country = strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"]);
$found=0;
$maybecountries=array();
foreach($countries as $key=>$country) {
if (strstr($this->country,$key)) {
$this->country = $country;
$found++;
break;
}
}
//Was there something unidentifiable?
if ($found==0) {
$this->country = "unknown";
if (trim($_SERVER["HTTP_ACCEPT_LANGUAGE"]) != "") {
$mail=true;
$mailtext .= '<p>Unknown language: '.$_SERVER["HTTP_ACCEPT_LANGUAGE"].'</p><br />';
}
}
if ($mail) {
$to='hide@address.com';
$subject="New HTTP_USER_AGENT found!";
$mailmsg="<h3>New HTTP_USER_AGENT found!</h3><br />".$mailtext;
$header = "MIME-Version: 1.0'\r\n";
$header.= "Content-type: text/html; charset=iso-8859-1\r\n";
$header.= "From: chillyCMS <hide@address.com>\r\n";
//mail($to, $subject, $mailmsg, $header);
}
}
}
//Getter
public function __get($name) {
if (isset($name, $this->$name)) { return $this->$name; }
else { return false; }
}
}
?>