/** * Get the country by IP * Return an array with : short name, like 'us', long name, like 'United States and response like 'OK' or <error_message> ' * @access public * @param string $ip * @return array */ public function getCountryByIp($ip) { $country = array(0 => 'unknown', 1 => 'NA', 'response' => 'OK'); if (Dot_Kernel::validIp($ip) != "public") { return $country; } if (extension_loaded('geoip') == false) { // GeoIp extension is not active $api = new Dot_Geoip_Country(); $geoipPath = $this->config->resources->geoip->path; if (file_exists($geoipPath)) { $country = $api->getCountryByAddr($geoipPath, $ip); } else { $country['response'] = 'Warning: ' . $this->option->warningMessage->modGeoIp; } } if (function_exists('geoip_db_avail') && geoip_db_avail(GEOIP_COUNTRY_EDITION) && 'unknown' == $country[0]) { //if GeoIP.dat file exists $countryCode = geoip_country_code_by_name($ip); $countryName = geoip_country_name_by_name($ip); $country[0] = $countryCode != false ? $countryCode : 'unknown'; $country[1] = $countryName != false ? $countryName : 'NA'; } if ('unknown' == $country[0]) { // GeoIp extension is active, but .dat files are missing $api = new Dot_Geoip_Country(); $geoipPath = $this->config->resources->geoip->path; if (file_exists($geoipPath)) { $country = $api->getCountryByAddr($geoipPath, $ip); } else { $country['response'] = 'Warning: ' . $this->option->warningMessage->modGeoIp; } } return $country; }
/** * Register usefull information about the visit * @access public * @return integer */ public static function recordVisit() { $db = Zend_Registry::get('database'); $ip = Dot_Kernel::GetUserIp(); $proxyIp = $_SERVER['REMOTE_ADDR']; $dotGeoip = new Dot_Geoip(); $country = $dotGeoip->getCountryByIp($ip); $logVisit = array('ip' => $ip, 'proxyIp' => $proxyIp, 'carrier' => 'unknown', 'country' => $country[1], 'accept' => array_key_exists("HTTP_ACCEPT", $_SERVER) ? $_SERVER["HTTP_ACCEPT"] : '', 'acceptLanguage' => array_key_exists("HTTP_ACCEPT_LANGUAGE", $_SERVER) ? $_SERVER["HTTP_ACCEPT_LANGUAGE"] : '', 'acceptEncoding' => array_key_exists("HTTP_ACCEPT_ENCODING", $_SERVER) ? $_SERVER["HTTP_ACCEPT_ENCODING"] : '', 'acceptCharset' => array_key_exists("HTTP_ACCEPT_CHARSET", $_SERVER) ? $_SERVER["HTTP_ACCEPT_CHARSET"] : '', 'userAgent' => array_key_exists("HTTP_USER_AGENT", $_SERVER) ? $_SERVER["HTTP_USER_AGENT"] : '', 'cacheControl' => array_key_exists("HTTP_CACHE_CONTROL", $_SERVER) ? $_SERVER["HTTP_CACHE_CONTROL"] : '', 'cookie' => array_key_exists("HTTP_COOKIE", $_SERVER) ? $_SERVER["HTTP_COOKIE"] : '', 'xWapProfile' => array_key_exists("HTTP_X_WAP_PROFILE", $_SERVER) ? $_SERVER["HTTP_X_WAP_PROFILE"] : '', 'xForwardedFor' => array_key_exists("HTTP_X_FORWARDED_FOR", $_SERVER) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : '', 'xForwardedHost' => array_key_exists("HTTP_X-FORWARDED-HOST", $_SERVER) ? $_SERVER["HTTP_X-FORWARDED-HOST "] : '', 'xForwardedServer' => array_key_exists("HTTP_X-FORWARDED-SERVER", $_SERVER) ? $_SERVER["HTTP_X-FORWARDED-SERVER"] : '', 'referer' => array_key_exists("HTTP_REFERER", $_SERVER) ? $_SERVER['HTTP_REFERER'] : ''); $db->insert('statisticVisit', $logVisit); return $db->lastInsertId(); }
/** * Get GeoIp Version release * Return an array with keys "country" & "city" * @access public * @return array */ public function getGeoIpVersion() { $return = array('country' => '-', 'city' => '-', 'local' => '-'); // let's see the version of local .dat file $geoipPath = $this->config->resources->geoip->path; $geoipVersion = explode(" ", Dot_Geoip_Country::geoipDatabaseInfo($geoipPath)); $return['local'] = $geoipVersion[0] . ' ' . Dot_Kernel::TimeFormat($geoipVersion[1]); // do we have geoIP server-wide ? if (function_exists('geoip_database_info')) { if (geoip_db_avail(GEOIP_COUNTRY_EDITION)) { $info = explode(" ", geoip_database_info(GEOIP_COUNTRY_EDITION)); $return['country'] = $info[0] . ' ' . Dot_Kernel::TimeFormat($info[1]); } } return $return; }
/** * Display user logins list * @access public * @param string $templateFile * @param array $list * @param int $page * @param int $browser * @param int $loginDate * @param int $sortField * @param int $orderBy * @return void */ public function loginsUser($templateFile, $list, $page, $browser, $loginDate, $sortField, $orderBy) { $dotGeoip = new Dot_Geoip(); $geoIpWorking = true; $this->tpl->setFile('tpl_main', 'user/' . $templateFile . '.tpl'); $this->tpl->setBlock('tpl_main', 'browser', 'browser_row'); $browserArray = Dot_UserAgent_Utilities::getBrowserArray(); foreach ($browserArray as $key => $val) { $this->tpl->setVar('BROWSERNAME', ucfirst($val['uaBrowser'])); if (strtolower($val['uaBrowser']) == strtolower($browser)) { $this->tpl->setVar('BROWSERSEL', 'selected'); } else { $this->tpl->setVar('BROWSERSEL', ''); } $this->tpl->parse('browser_row', 'browser', true); } $this->tpl->setVar('FILTERDATE', $loginDate); $this->tpl->setBlock('tpl_main', 'list', 'list_block'); $this->tpl->paginator($list['pages']); $this->tpl->setVar('PAGE', $page); $this->tpl->setVar('FILTER_URL', '/admin/user/logins'); $sortableFields = array('username', 'dateLogin'); foreach ($sortableFields as $field) { $linkSort = '/admin/user/logins/sort/' . $field . '/order/'; $linkSort .= $orderBy == 'asc' ? 'desc' : 'asc'; $this->tpl->setVar('LINK_SORT_' . strtoupper($field), $linkSort); if ($field != $sortField) { $sortClass = 'sortable'; } elseif ($orderBy == 'asc') { $sortClass = 'sort_up'; } else { $sortClass = 'sort_down'; } $this->tpl->setVar('CLASS_SORT_' . strtoupper($field), $sortClass); } foreach ($list['data'] as $k => $v) { $country = $dotGeoip->getCountryByIp($v['ip']); if ($country['response'] != 'OK' && $geoIpWorking === true) { $geoIpWorking = false; $this->session->message['txt'] = $country['response']; $this->session->message['type'] = 'warning'; } $this->tpl->setVar('ID', $v['id']); $this->tpl->setVar('USERID', $v['userId']); $this->tpl->setVar('USERNAME', $v['username']); $this->tpl->setVar('IP', $v['ip']); $this->tpl->setVar('COUNTRYIMAGE', strtolower($country[0])); $this->tpl->setVar('COUNTRYNAME', $country[1]); $this->tpl->setVar('REFERER', $v['referer']); $this->tpl->setVar('WHOISURL', $this->settings->whoisUrl); $this->tpl->setVar('USERAGENT', $v['userAgent']); $this->tpl->setVar('BROWSERIMAGE', Dot_UserAgent_Utilities::getBrowserIcon($v['userAgent'])); $os = Dot_UserAgent_Utilities::getOsIcon($v['userAgent']); $this->tpl->setVar('OSIMAGE', $os['icon']); $this->tpl->setVar('OSMAJOR', $os['major']); $this->tpl->setVar('OSMINOR', $os['minor']); $this->tpl->setVar('DATELOGIN', Dot_Kernel::timeFormat($v['dateLogin'], 'long')); $this->tpl->parse('list_block', 'list', true); } }
// call showPage method to view the home page $pageView->showPage('home'); if ($_SERVER['REQUEST_METHOD'] === "POST" && array_key_exists('phone', $_POST) && array_key_exists('phone', $_POST) && array_key_exists('email', $_POST) && array_key_exists('message', $_POST)) { // validate the response $values = array('email' => array('email' => $_POST['email']), 'details' => array('message' => $_POST['message'])); //if phone is completed, validate phone to be from US if ($_POST['phone'] != '') { $values['phone'] = array('phone' => $_POST['phone']); } $dotValidateUser = new Dot_Validate_User(array('who' => 'mobile', 'action' => 'form', 'values' => $values)); if ($dotValidateUser->isValid()) { //if valid, send a mail $data = $dotValidateUser->getData(); $dotEmail = new Dot_Email(); $dotEmail->addTo($settings->siteEmail); $dotEmail->setSubject($registry->seo->siteName . ' - ' . $option->contactForm->subject); $msg = str_replace(array('%EMAIL%', '%PHONE%', '%MESSAGE%', '%DATE%', '%IP%', '%USERAGENT%'), array($data['email'], isset($data['phone']) ? $data['phone'] : '', $data['message'], Dot_Kernel::timeFormat('now'), Dot_Kernel::getUserIp(), $_SERVER['HTTP_USER_AGENT']), $option->contactForm->message); $dotEmail->setBodyText($msg); $dotEmail->send(); /** If you want to redirect to a link, * uncomment the 2 lines below to display a message */ $tpl->setVar('ERROR_MESSAGE', $option->contactForm->mailSent); } else { $session->message['txt'] = $dotValidateUser->getError(); $session->message['type'] = 'error'; $pageView->showPage('home', $dotValidateUser->getData()); } } break; }
//Set include path to library directory set_include_path(implode(PATH_SEPARATOR, array(APPLICATION_PATH . '/library', get_include_path()))); // Define PATH's (absolute paths) to configuration, controllers, DotKernel, templates directories define('CONFIGURATION_PATH', APPLICATION_PATH . '/configs'); define('CONTROLLERS_PATH', APPLICATION_PATH . '/controllers'); define('DOTKERNEL_PATH', APPLICATION_PATH . '/DotKernel'); define('TEMPLATES_PATH', APPLICATION_PATH . '/templates'); // Define DIRECTORIES ( relative paths) define('TEMPLATES_DIR', '/templates'); define('IMAGES_DIR', '/images'); // Load Zend Framework require_once 'Zend/Loader/Autoloader.php'; $zendLoader = Zend_Loader_Autoloader::getInstance(); //includes all classes in library folder. That class names must start with Dot_ $zendLoader->registerNamespace('Dot_'); // also load plugin classes $zendLoader->registerNamespace('Plugin_'); // getting the request related params Dot_Request::setRequestData($_SERVER, $_GET, $_POST); // initialize the DotKernel Enviromnment Dot_Kernel::initialize($startTime); /** Pass control to the controller .'' ._.-.___.' (`\ //( ( `' '/ )\ ).__. ) ' <' `\ ._/'\ ` \ \ */ Dot_Kernel::gallop();
/** * Display user logins list * @access public * @param string $templateFile * @param array $list * @param int $page * @return void */ public function loginsUser($templateFile, $list, $page) { $dotGeoip = new Dot_Geoip(); $geoIpWorking = true; $this->tpl->setFile('tpl_main', 'admin/' . $templateFile . '.tpl'); $this->tpl->setBlock('tpl_main', 'list', 'list_block'); $this->tpl->paginator($list['pages']); $this->tpl->setVar('PAGE', $page); foreach ($list['data'] as $k => $v) { $country = $dotGeoip->getCountryByIp($v['ip']); if ($country['response'] != 'OK' && $geoIpWorking === true) { $geoIpWorking = false; $this->session->message['txt'] = $country['response']; $this->session->message['type'] = 'warning'; } $this->tpl->setVar('ID', $v['id']); $this->tpl->setVar('ADMINID', $v['adminId']); $this->tpl->setVar('USERNAME', $v['username']); $this->tpl->setVar('IP', $v['ip']); $this->tpl->setVar('COUNTRYIMAGE', strtolower($country[0])); $this->tpl->setVar('COUNTRYNAME', $country[1]); $this->tpl->setVar('REFERER', $v['referer']); $this->tpl->setVar('WHOISURL', $this->settings->whoisUrl); $this->tpl->setVar('USERAGENT', $v['userAgent']); $this->tpl->setVar('BROWSERIMAGE', Dot_UserAgent_Utilities::getBrowserIcon($v['userAgent'])); $os = Dot_UserAgent_Utilities::getOsIcon($v['userAgent']); $this->tpl->setVar('OSIMAGE', $os['icon']); $this->tpl->setVar('OSMAJOR', $os['major']); $this->tpl->setVar('OSMINOR', $os['minor']); $this->tpl->setVar('DATELOGIN', Dot_Kernel::timeFormat($v['dateLogin'], 'long')); $this->tpl->parse('list_block', 'list', true); } }
/** * Failed admin login - send email notice to valid admin account * @access private * @param arry $values * @return void */ private function sendEmailFailedLogin($values) { // get all admin list $emailAdminList = explode(',', $this->settings->devEmails); $dotEmail = new Dot_Email(); // Add each admin foreach ($emailAdminList as $emailAdmin) { $dotEmail->addTo($emailAdmin); } $dotEmail->setSubject($this->seo->siteName . ' - ' . $this->option->failedLogin->subject); $dotGeoip = new Dot_Geoip(); $country = $dotGeoip->getCountryByIp(Dot_Kernel::getUserIp()); $msg = str_replace(array('%LINK%', '%USERNAME%', '%PASSWORD%', '%DATE%', '%COUNTRY%', '%IP%', '%USERAGENT%'), array($this->config->website->params->url . '/' . Zend_Registry::get('requestModule'), $values['username'], $values['password'], Dot_Kernel::timeFormat('now', 'long'), $country[1], Dot_Kernel::getUserIp(), $this->_userAgent), $this->option->failedLogin->message); $dotEmail->setBodyText($msg); $success = $dotEmail->send(); return $success; }
/** * Authorize user login * @access public * @param array $validData * @return void */ public function authorizeLogin($validData) { $session = Zend_Registry::get('session'); unset($session->user); // login info are VALID, we can see if is a valid user now $dotAuth = Dot_Auth::getInstance(); $validAuth = $dotAuth->process('user', $validData); if ($validAuth) { //prepare data for register the login $dotGeoip = new Dot_Geoip(); $userIp = Dot_Kernel::getUserIp(); $userCountry = $dotGeoip->getCountryByIp($userIp); $dataLogin = array('ip' => $userIp, 'userId' => $session->user->id, 'referer' => $this->_httpReferer, 'userAgent' => $this->_userAgent, 'country' => $userCountry[1]); $this->registerLogin($dataLogin); $link = isset($session->wantUrl) ? $session->wantUrl : $this->config->website->params->url . '/user/account'; header('location: ' . $link); exit; } else { $session->message['txt'] = $this->option->errorMessage->login; $session->message['type'] = 'error'; } }