/** * Save region data. * * @access public * @return void */ public function saveRegion() { $year = date('Y'); $month = date('Ym'); $day = date('Ymd'); $hour = date('YmdH'); $time = new stdclass(); $time->year = $year; $time->month = $month; $time->day = $day; $time->hour = $hour; foreach ($time as $type => $value) { $oldRegion = $this->dao->select('*')->from(TABLE_STATREGION)->where('timeType')->eq($type)->andWhere('timeValue')->eq($value)->fetch(); if (!empty($oldRegion)) { $ipAndUv = $this->dao->select('count(distinct(ip)) as ip, count(distinct(visitor)) as uv')->from(TABLE_STATLOG)->where($type)->eq($value)->fetch(); $this->dao->update(TABLE_STATREGION)->set('pv = pv + 1')->set('uv')->eq($ipAndUv->uv)->set('ip')->eq($ipAndUv->ip)->where('id')->eq($oldRegion->id)->exec(); } else { $location = $this->app->loadClass('IP')->find(helper::getRemoteIp()); $region = new stdclass(); $region->timeType = $type; $region->timeValue = $value; $region->country = $location[0]; $region->province = $location[1]; $region->city = $location[2]; $region->pv = 1; $region->uv = 1; $region->ip = 1; $this->dao->insert(TABLE_STATREGION)->data($region)->exec(); } } return !dao::isError(); }
/** * set site security info. * * @access public * @return void */ public function setSecurity() { $this->lang->site->menu = $this->lang->security->menu; $this->lang->menuGroups->site = 'security'; $captcha = (isset($this->config->site->captcha) and ($this->config->site->captcha == 'open' and ($this->post->captcha == 'close' or $this->post->captcha == 'auto')) or (!isset($this->config->site->captcha) or $this->config->site->captcha == 'auto') and $this->post->captcha == 'close'); $checkEmail = (isset($this->config->site->checkEmail) and $this->config->site->checkEmail == 'open' and $this->post->checkEmail == 'close'); $front = (isset($this->config->site->front) and $this->config->site->front == 'login' and $this->post->front == 'guest'); $checkLocation = (isset($this->config->site->checkLocation) and $this->config->site->checkLocation == 'open' and $this->post->checkLocation == 'close'); $checkSessionIP = (isset($this->config->site->checkSessionIP) and $this->config->site->checkSessionIP == 1 and $this->post->checkSessionIP == 0); $allowedIP = (isset($this->config->site->allowedIP) and $this->config->site->allowedIP != $this->post->allowedIP); $newImportantValidate = $this->post->importantValidate ? $this->post->importantValidate : array(); $oldImportantValidate = explode(',', $this->config->site->importantValidate); $importantChange = false; foreach ($oldImportantValidate as $validate) { if (!in_array($validate, $newImportantValidate)) { $importantChange = true; break; } } if ($captcha or $checkEmail or $front or $checkLocation or $checkSessionIP or $allowedIP or $importantChange) { $okFile = $this->loadModel('common')->verifyAdmin(); $pass = $this->loadModel('guarder')->verify('okFile'); $this->view->pass = $pass; $this->view->okFile = $okFile; if (!empty($_POST) && !$pass) { $this->send(array('result' => 'fail', 'reason' => 'captcha')); } } if (!empty($_POST)) { $setting = fixer::input('post')->setDefault('captcha', 'auto')->setDefault('filterSensitive', 'close')->setDefault('checkIP', 'close')->setDefault('checkSessionIP', '0')->setDefault('checkLocation', 'close')->setDefault('checkEmail', 'close')->setDefault('allowedIP', '')->setDefault('importantValidate', '')->join('importantValidate', ',')->setForce('sensitive', seo::unify($this->post->sensitive, ','))->get(); /* check IP. */ $ips = !$this->post->allowedIP ? array() : explode(',', $this->post->allowedIP); foreach ($ips as $ip) { if (!empty($ip) and !helper::checkIP($ip)) { dao::$errors['allowedIP'][] = $this->lang->site->wrongAllowedIP; break; } } $result = $this->loadModel('setting')->setItems('system.common.site', $setting, 'all'); if ($result) { $this->send(array('result' => 'success', 'message' => $this->lang->setSuccess, 'locate' => inlink('setsecurity'))); } $this->send(array('result' => 'fail', 'message' => dao::getError())); } $location = $this->app->loadClass('IP')->find(helper::getRemoteIp()); if (is_array($location)) { $locations = $location; $location = join(' ', $locations); if (count($location) > 3) { $location = $locations[0] . ' ' . $locations[1] . ' ' . $locations[2]; } } $this->view->title = $this->lang->site->setBasic; $this->view->location = $location; $this->display(); }
/** * sign in. * * @param string $account * @param string $date * @access public * @return bool */ public function signIn($account = '', $date = '') { if ($account == '') { $account = $this->app->user->account; } if ($date == '') { $date = date('Y-m-d'); } $attend = $this->dao->select('*')->from(TABLE_ATTEND)->where('account')->eq($account)->andWhere('`date`')->eq($date)->fetch(); if (empty($attend)) { $attend = new stdclass(); $attend->account = $account; $attend->date = $date; $attend->signIn = helper::time(); $attend->ip = helper::getRemoteIp(); $this->dao->insert(TABLE_ATTEND)->data($attend)->autoCheck()->exec(); return !dao::isError(); } if ($attend->signIn == '' or $attend->signIn == '00:00:00') { $this->dao->update(TABLE_ATTEND)->set('signIn')->eq(helper::time())->where('id')->eq($attend->id)->exec(); return !dao::isError(); } return true; }
/** * Check last login location. * * @param string $account * @access public * @return void */ public function checkLoginLocation($account) { if (!isset($this->config->site->checkLocation) or $this->config->site->checkLocation == 'close') { return true; } $location = $this->app->loadClass('IP')->find(helper::getRemoteIp()); if (is_array($location)) { $locations = $location; $location = join(' ', $locations); if (count($location) > 3) { $location = $locations[0] . ' ' . $locations[1] . ' ' . $locations[2]; } } $lastLocation = $this->dao->select('location')->from(TABLE_LOG)->where('account')->eq($account)->andWhere('`desc`')->eq('success')->andWhere('type')->eq('adminlogin')->orderBy('date_desc')->limit(1)->fetch('location'); if ($lastLocation and trim($location) != $lastLocation) { return false; } return true; }
/** * checkLocation * * @access public * @return bool */ public function checkLocation() { if (isset($this->config->site->safeMode) and $this->config->site->safeMode == '1') { return true; } if (!isset($this->config->site->checkLocation) or $this->config->site->checkLocation == 'close') { return true; } if (!isset($this->config->site->allowedLocation) or $this->config->site->allowedLocation == '') { return true; } $allowedLocation = $this->config->site->allowedLocation; $location = $this->app->loadClass('IP')->find(helper::getRemoteIp()); if (is_array($location)) { $locations = $location; $location = join(' ', $locations); if (count($location) > 3) { $location = $locations[0] . ' ' . $locations[1] . ' ' . $locations[2]; } } return $allowedLocation == $location; }