/** * 检查是否登录 */ protected function check_login() { $session = $this->session(); $member = $session->member(); try { if (!$member->id > 0) { throw new Exception('请先登录'); } # 超时时间 if (($admin_login_expired_time = Core::config('admin.core.admin_login_expired_time')) > 0 && TIME - $admin_login_expired_time > $session->last_actived_time()) { throw new Exception('登录超时,请重新登录'); } if ($member->password != $_SESSION['member_password']) { throw new Exception('此号密码已更新,请重新登录'); } if (!$member->setting['only_self_login'] && $session->id() != $member->last_login_session_id) { # 如果设置为仅仅可单人登录,若发现最后登录session id和当前登录session不一致,则取消此用户登录,并输出相应信息 throw new Exception('此号已在其它地方登录,登录IP:' . $member->last_login_ip . ' (' . IpSource::get($member->last_login_ip) . '),登录时间:' . date('Y-m-d H:i:s', $member->last_login_time)); } } catch (Exception $e) { if (HttpIO::IS_AJAX) { # AJAX 请求 $this->message($e->getMessage(), -1); } else { # 正常页面请求 # 记录错误消息 $session->set_flash('admin_member_login_message', $e->getMessage()); # 页面跳转 $this->redirect(Core::url('login/?forward=' . urlencode($_SERVER['REQUEST_URI'] . ($_SERVER['QUERY_STRING'] ? '?' . $_SERVER['QUERY_STRING'] : '')))); } exit; } }
/** * 检查是否登录 */ protected function check_login() { return; $session = $this->session(); $member = $session->member(); try { if (!$member->id > 0) { throw new \Exception(\__('Please login')); } # 超时时间 if (($admin_login_expired_time = \Core::config('admin.core.admin_login_expired_time')) > 0 && \TIME - $admin_login_expired_time > $session->last_actived_time()) { throw new \Exception(\__('Login timeout, please log in again')); } if ($member->password != $_SESSION['member_password']) { throw new \Exception(\__('This account password has been updated, please re-login')); } if ($member->setting['only_self_login'] && $session->id() != $member->last_login_session_id) { # 如果设置为仅仅可单人登录,若发现最后登录session id和当前登录session不一致,则取消此用户登录,并输出相应信息 throw new \Exception(\__('This account has been elsewhere login, log the IP: :ip - :iplocal, login time: :time', array(':ip' => $member->last_login_ip, ':iplocal' => \IpSource::get($member->last_login_ip), ':time' => $member->last_login_time))); } } catch (\Exception $e) { if (\HttpIO::IS_AJAX) { # AJAX 请求 self::message($e->getMessage(), -1); } else { # 正常页面请求 # 记录错误消息 $session->set_flash('admin_member_login_message', $e->getMessage()); # 页面跳转 $this->redirect(\Core::url('login/?forward=' . \urlencode($_SERVER['REQUEST_URI'] . ($_SERVER['QUERY_STRING'] ? '?' . $_SERVER['QUERY_STRING'] : '')))); } exit; } }
public static function &instance() { if (null === self::$instance) { self::$instance = new self(); } return self::$instance; }
/** * 获取天气信息 */ public function action_weather_data() { $city = $_GET['city']; if (!$city) { $city = \PinYIn::get(\IpSource::get()); if (\in_array($city, array('LAN', 'Local IP', 'Invalid IP Address'))) { $city = 'shanghai'; } } $view = new \View('admin/desktop/weather_data'); $view->weather = Weather::get($city); $view->city = $city; $view->render(); }
/** * 获取IP地址 * * @param string $ip 不传则为访客IP * @return string */ public static function get($ip = null) { $ip or $ip = HttpIO::IP; if ($ip == '127.0.0.1' || $ip == '0.0.0.0') { return 'Local IP'; } $return = ''; if (preg_match('#^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$#', $ip)) { $iparray = explode('.', $ip); if ($iparray[0] == 10 || $iparray[0] == 127 || $iparray[0] == 192 && $iparray[1] == 168 || $iparray[0] == 172 && ($iparray[1] >= 16 && $iparray[1] <= 31)) { $return = 'LAN'; } elseif ($iparray[0] > 255 || $iparray[1] > 255 || $iparray[2] > 255 || $iparray[3] > 255) { $return = 'Invalid IP Address'; } else { if (true == ($tinyipfile = Core::find_file('data', 'tinyipdata', 'dat'))) { $return = IpSource::_convertip_tiny($ip, $tinyipfile); } elseif (true == ($fullipfile = Core::find_file('data', 'wry', 'dat'))) { $return = IpSource::_convertip_full($ip, $fullipfile); } } } return $return; }
/** * 获取IP地址归属地 * * @param string $ip * @return string */ function ip_source($ip) { return IpSource::instance()->get($ip); }