private function showUser() { // FIXME: Does $_GET['userID'] exist? if (isset($_GET['privledged']) && $_GET['privledged'] == 'false' && $this->_userID == $_GET['userID']) { $privledged = false; } else { /* Bail out if the user doesn't have SA permissions. */ if ($this->_realAccessLevel < ACCESS_LEVEL_DEMO) { CommonErrors::fatal(COMMONERROR_PERMISSION, $this); return; //$this->fatal(ERROR_NO_PERMISSION); } $privledged = true; } $userID = $_GET['userID']; $users = new Users($this->_siteID); $data = $users->get($userID); if (empty($data)) { CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'No user found with selected ID.'); } $data['successfulDate'] = DateUtility::fixZeroDate($data['successfulDate'], 'Never'); $data['unsuccessfulDate'] = DateUtility::fixZeroDate($data['unsuccessfulDate'], 'Never'); $accessLevels = $users->getAccessLevels(); $loginAttempts = $users->getLastLoginAttempts($userID, self::MAX_RECENT_LOGINS); if (!empty($loginAttempts)) { foreach ($loginAttempts as $rowIndex => $row) { $loginAttempts[$rowIndex]['shortUserAgent'] = implode(' ', BrowserDetection::detect($loginAttempts[$rowIndex]['userAgent'])); if ($loginAttempts[$rowIndex]['successful'] == 0) { $loginAttempts[$rowIndex]['successful'] = 'No'; } else { $loginAttempts[$rowIndex]['successful'] = 'Yes'; } } } $siteIDPosition = strpos($data['username'], '@' . $_SESSION['CATS']->getSiteID()); // FIXME: The last test here might be redundant. if ($siteIDPosition !== false && substr($data['username'], $siteIDPosition) == '@' . $_SESSION['CATS']->getSiteID()) { $data['username'] = str_replace('@' . $_SESSION['CATS']->getSiteID(), '', $data['username']); } /* Get user categories, if any. */ $modules = ModuleUtility::getModules(); $categories = array(); foreach ($modules as $moduleName => $parameters) { $moduleCategories = $parameters[MODULE_SETTINGS_USER_CATEGORIES]; if ($moduleCategories != false) { foreach ($moduleCategories as $category) { $categories[] = $category; } } } $EEOSettings = new EEOSettings($this->_siteID); $EEOSettingsRS = $EEOSettings->getAll(); $this->_template->assign('privledged', $privledged); $this->_template->assign('active', $this); $this->_template->assign('subActive', ''); $this->_template->assign('data', $data); $this->_template->assign('categories', $categories); $this->_template->assign('accessLevels', $accessLevels); $this->_template->assign('EEOSettingsRS', $EEOSettingsRS); $this->_template->assign('currentUser', $this->_userID); $this->_template->assign('loginDisplay', self::MAX_RECENT_LOGINS); $this->_template->assign('loginAttempts', $loginAttempts); $this->_template->display('./modules/settings/ShowUser.tpl'); }
function testDetect() { // FIXME: Add more browsers! $intendedMatches = array(array('', array('name' => 'Masked', 'version' => ''), 'Detected masked user agent properly.'), array(' ', array('name' => 'Masked', 'version' => ''), 'Detected masked user agent properly.'), array('I don\'t exist!', array('name' => 'Unknown', 'version' => ''), 'Detected an unknown user agent properly.'), array('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1', array('name' => 'Firefox', 'version' => '2.0.0.1'), 'Detected Firefox 2.0.0.1.'), array('Mozilla/5.0 (Windows; U; Windows NT 6.0; fi) AppleWebKit/522.12.1 (KHTML, like Gecko) Version/3.0.1 Safari/522.12.2', array('name' => 'Safari', 'version' => '3.0.1'), 'Detected Safari 3.0.1.'), array('Mozilla/5.0 (Macintosh; U; PPC Mac OS X; tr-tr) AppleWebKit/418 (KHTML, like Gecko) Safari/417.9.3', array('name' => 'Safari', 'version' => '2.0.3'), 'Detected Safari 2.0.3.'), array('Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)', array('name' => 'Internet Explorer', 'version' => '7.0'), 'Detected Internet Explorer 7.0.5730.11.'), array('Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8b2) Gecko/20050702)', array('name' => 'Mozilla', 'version' => '1.8b'), 'Detected Mozilla rv:1.8b.'), array('Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.3 (like Gecko) Kubuntu 6.06 Dapper', array('name' => 'Konqueror', 'version' => '3.5'), 'Detected Konqueror 3.5.'), array('Opera/9.02 (Windows NT 5.1; U; en)', array('name' => 'Opera', 'version' => '9.02'), 'Detected Opera 9.02.'), array('Mozilla/5.0 (compatible; iCab 3.0.2; Macintosh; U; PPC Mac OS)', array('name' => 'iCab', 'version' => '3.0.2'), 'Detected iCab 3.0.2.'), array('iCab/2.9.1 (Macintosh; U; PPC)', array('name' => 'iCab', 'version' => '2.9.1'), 'Detected iCab 2.9.1.'), array('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.9) Gecko/20061211 SeaMonkey/1.0.7', array('name' => 'SeaMonkey', 'version' => '1.0.7'), 'Detected SeaMonkey 1.0.7.'), array('Mozilla/4.0 (compatible; MSIE 7.0; America Online Browser 1.1; rev1.5; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)', array('name' => 'America Online Browser', 'version' => '1.1'), 'Detected America Online Browser 1.1.'), array('Mozilla/4.0 (compatible; MSIE 6.0; AOL 9.0; Windows NT 5.1; SV1; FreeprodTB; FunWebProducts; .NET CLR 1.1.4322; .NET CLR 2.0.50727)', array('name' => 'AOL', 'version' => '9.0'), 'Detected AOL 9.0.'), array('Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.0.7) Gecko/20060911 Camino/1.0.3', array('name' => 'Camino', 'version' => '1.0.3'), 'Detected Camino 1.0.3.'), array('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', array('name' => 'Googlebot', 'version' => '2.1'), 'Detected Googlebot 2.1.'), array('Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)', array('name' => 'Yahoo Crawler', 'version' => ''), 'Detected Yahoo Crawler.'), array('Lynx/2.8.5rel.5 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.8d', array('name' => 'Lynx', 'version' => '2.8.5'), 'Detected Lynx 2.8.5.'), array('Links (0.99pre14; CYGWIN_NT-5.1 1.5.22(0.156/4/2) i686; 80x25)', array('name' => 'Links', 'version' => '0.99pre14'), 'Detected Links 0.99pre14.'), array('curl/7.15.4 (i686-pc-cygwin) libcurl/7.15.4 OpenSSL/0.9.8d zlib/1.2.3', array('name' => 'cURL', 'version' => '7.15.4'), 'Detected cURL 7.15.4.'), array('Wget/1.10.2', array('name' => 'Wget', 'version' => '1.10.2'), 'Detected Wget 1.10.2.'), array('W3C_Validator/1.432.2.5', array('name' => 'W3C Validator', 'version' => '1.432.2.5'), 'Detected W3C Validator 1.432.2.5.'), array('W3C-checklink/4.2.1 [4.21] libwww-perl/5.803', array('name' => 'W3C Link Checker', 'version' => '4.2.1'), 'Detected W3C Link Checker 4.2.1.'), array('Jigsaw/2.2.5 W3C_CSS_Validator_JFouffa/2.0', array('name' => 'W3C CSS Validator', 'version' => '2.0'), 'Detected W3C CSS Validator 2.0.')); foreach ($intendedMatches as $intendedMatch) { $this->assertIdentical(BrowserDetection::detect($intendedMatch[0]), $intendedMatch[1], ltrim($intendedMatch[2] . ' %s')); } }
/** * Returns the current page of login activity. * * @return array contacts data */ public function getPage() { $sql = sprintf("SELECT\n user_login.user_login_id AS userLoginID,\n user_login.user_id AS userID,\n user_login.ip AS ip,\n user_login.user_agent AS shortUserAgent,\n DATE_FORMAT(\n user_login.date, '%%m-%%d-%%y (%%h:%%i %%p)'\n ) AS date,\n user_login.date AS dateSort,\n user_login.host AS hostname,\n user.first_name AS firstName,\n user.last_name AS lastName\n FROM\n user_login\n LEFT JOIN user\n ON user_login.user_id = user.user_id\n WHERE\n user_login.successful = %s\n AND\n user.is_test_user = 0\n AND\n user_login.site_id = %s\n AND\n user.site_id = %s\n ORDER BY\n %s %s\n LIMIT %s, %s", $this->_successful ? '1' : '0', $this->_siteID, $this->_siteID, $this->_sortBy, $this->_sortDirection, $this->_thisPageStartRow, $this->_rowsPerPage); $rs = $this->_db->getAllAssoc($sql); foreach ($rs as $rowIndex => $row) { if (empty($row['hostname'])) { if (ENABLE_HOSTNAME_LOOKUP) { $rs[$rowIndex]['hostname'] = @gethostbyaddr($row['ip']); if (empty($rs[$rowIndex]['hostname'])) { $rs[$rowIndex]['hostname'] = '(unresolvable)'; } $this->updateHostName($row['userLoginID'], $row['hostname']); } else { $rs[$rowIndex]['hostname'] = $row['ip']; } } if ($row['hostname'] == '(unresolvable)') { $rs[$rowIndex]['hostname'] = ''; } $rs[$rowIndex]['shortUserAgent'] = implode(' ', BrowserDetection::detect($row['shortUserAgent'])); } return $rs; }