/** * Test that a false is returned on an "allow" with * no match */ public function testEvaluateAllowNoMatch() { $_SERVER['REMOTE_ADDR'] = '192.168.1.1'; $config = array('ALLOW' => array('10.0.*')); $ip = new Ip($config); $this->assertFalse($ip->evaluate()); }
/** * @param Ip $customerIp * @param TokenExpiration $tokenExpiration * @param TokenChecksum $tokenChecksum */ public function __construct(Ip $customerIp, TokenExpiration $tokenExpiration, TokenChecksum $tokenChecksum) { $timeAsHexadecimal = $tokenExpiration->asHexadecimalTimestamp(); $firstTimeChars = substr($timeAsHexadecimal, 0, -1); $lastTimeChar = substr($timeAsHexadecimal, -1); $this->token = $lastTimeChar . $customerIp->getVersion() . $customerIp->tokenify() . $tokenChecksum . $firstTimeChars; }
public function testFilter() { $filter = new Ip(); $this->assertEquals('80.80.80.80', $filter->apply('80.80.80.80')); $this->assertEquals(false, $filter->apply('foo')); // test error message $this->assertErrorMessage($filter->getErrorMessage()); }
/** * Create sha512 checksum for token * * @param SignOnMode $mode * @param Ip $customerIp * @param TokenExpiration $tokenExpiration * @param string $shopSalt * @param string $serverSalt */ public function __construct(SignOnMode $mode, Ip $customerIp, TokenExpiration $tokenExpiration, $shopSalt, $serverSalt) { $token = $shopSalt . $serverSalt . $tokenExpiration->asTimestamp() . $mode . $customerIp->tokenify(); if ($mode->isUser()) { $token .= ":" . self::ADMIN_ID_DEFAULT; } $this->tokenChecksum = hash('sha512', $token); }
public function insertCrawlData($data) { $router_data = Router_old::getRouterInfo($data['router_id']); $actual_crawl_cycle = Crawling::getActualCrawlCycle(); $last_endet_crawl_cycle = Crawling::getLastEndedCrawlCycle(); /**Insert Router Interfaces*/ foreach ($data['interface_data'] as $sendet_interface) { //Update RRD Graph DB $interface_last_endet_crawl = Interfaces::getInterfaceCrawlByCrawlCycleAndRouterIdAndInterfaceName($last_endet_crawl_cycle['id'], $data['router_id'], $sendet_interface['name']); $traffic_rx_bps = round(($sendet_interface['traffic_rx'] - $interface_last_endet_crawl['traffic_rx']) / $GLOBALS['crawl_cycle'] / 60); $traffic_rx_bps = $traffic_rx_bps < 0 ? 0 : $traffic_rx_bps; $traffic_tx_bps = round(($sendet_interface['traffic_tx'] - $interface_last_endet_crawl['traffic_tx']) / $GLOBALS['crawl_cycle'] / 60); $traffic_tx_bps = $traffic_tx_bps < 0 ? 0 : $traffic_tx_bps; //Set default indizies to prevent from warnings $sendet_interface['wlan_frequency'] = isset($sendet_interface['wlan_frequency']) ? preg_replace("/([A-Za-z])/", "", $sendet_interface['wlan_frequency']) : ""; $sendet_interface['wlan_mode'] = isset($sendet_interface['wlan_mode']) ? $sendet_interface['wlan_mode'] : ""; $sendet_interface['wlan_essid'] = isset($sendet_interface['wlan_essid']) ? $sendet_interface['wlan_essid'] : ""; $sendet_interface['wlan_bssid'] = isset($sendet_interface['wlan_bssid']) ? $sendet_interface['wlan_bssid'] : ""; $sendet_interface['wlan_tx_power'] = isset($sendet_interface['wlan_tx_power']) ? $sendet_interface['wlan_tx_power'] : 0; //check if interface already exists $networkinterface_test = new Networkinterface(false, (int) $data['router_id'], $sendet_interface['name']); //if interface not exist, create new if (!$networkinterface_test->fetch()) { $networkinterface_new = new Networkinterface(false, (int) $data['router_id'], $sendet_interface['name']); $networkinterface_id = $networkinterface_new->store(); } else { $networkinterface_id = $networkinterface_test->getNetworkinterfaceId(); } //save crawl data for interface $networkinterface_status = new NetworkinterfaceStatus(false, (int) $actual_crawl_cycle['id'], (int) $networkinterface_id, (int) $data['router_id'], $sendet_interface['name'], $sendet_interface['mac_addr'], (int) $sendet_interface['mtu'], (int) $sendet_interface['traffic_rx'], (int) $traffic_rx_bps, (int) $sendet_interface['traffic_tx'], (int) $traffic_tx_bps, $sendet_interface['wlan_mode'], $sendet_interface['wlan_frequency'], $sendet_interface['wlan_essid'], $sendet_interface['wlan_bssid'], (int) $sendet_interface['wlan_tx_power'], false); $networkinterface_status->store(); //Update RRDDatabase $rrd_path_traffic_rx = ROOT_DIR . "/rrdtool/databases/router_{$data['router_id']}_interface_{$sendet_interface['name']}_traffic_rx.rrd"; if (!file_exists($rrd_path_traffic_rx)) { exec("rrdtool create {$rrd_path_traffic_rx} --step 600 --start " . time() . " DS:traffic_rx:GAUGE:700:U:U DS:traffic_tx:GAUGE:900:U:U RRA:AVERAGE:0:1:144 RRA:AVERAGE:0:6:168 RRA:AVERAGE:0:18:240"); } exec("rrdtool update {$rrd_path_traffic_rx} " . time() . ":" . round($traffic_rx_bps / 1000, 2) . ":" . round($traffic_tx_bps / 1000, 2)); //add unknown ipv6 link local addresses to netmon //prepare data $ipv6_link_local_addr = explode("/", $sendet_interface['ipv6_link_local_addr']); $ipv6_link_local_netmask = isset($ipv6_link_local_addr[1]) ? (int) $ipv6_link_local_addr[1] : 64; $ipv6_link_local_addr = Ip::ipv6Expand($ipv6_link_local_addr[0]); //first try to determine network of given address $ipv6_link_local_network = Ip::ipv6NetworkFromAddr($ipv6_link_local_addr, (int) $ipv6_link_local_netmask); $network = new Network(false, false, $ipv6_link_local_network, (int) $ipv6_link_local_netmask, 6); if ($network->fetch()) { //if network found, then try to add ip address $ip = new Ip(false, (int) $networkinterface_id, $network->getNetworkId(), $ipv6_link_local_addr); $ip->store(); } } RrdTool::updateRouterClientCountHistory($data['router_id'], $data['client_count']); }
public function admin_consola() { if ($this->request->is('post')) { $sql = new Ip(); if (!empty($this->data['query'])) { $resultados = $sql->query($this->data['query']); $this->set(compact('resultados')); } else { $this->Session->setFlash(__('No dejes el campo vacío, por favor.'), 'default', array('class' => 'error-message'), 'error'); } } }
private function buildHtAccessString() { /* build htaccess header string*/ $htaccessStr = <<<EOL # index file can be index.php, home.php, default.php etc. # Rewrite engine RewriteEngine On # condition with escaping special chars RewriteCond \$1 !^(index\\.php|robots\\.txt|favicon\\.ico) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)\$ claimdatastorage/index.php/\$1 [L,QSA]\t Order allow,deny EOL; /*get all ip address*/ $allIpAddresses = Ip::model()->findAll(); foreach ($allIpAddresses as $currentIpAddress) { $tempIpaddress = $currentIpAddress->ip_address; /*append ip addreeeses*/ $htaccessStr = $htaccessStr . <<<EOL Allow from {$tempIpaddress} EOL; } /*build htaccess footer*/ $htaccessStr = $htaccessStr . <<<EOL Deny from all EOL; return $htaccessStr; }
function setUp() { $this->server = $_SERVER; $_SERVER['HTTP_HOST'] = 'test'; $this->stats_counter = new StatsCounter(); $this->stats_ip = new StatsIpTestVersion($this); $this->stats_ip->__construct(); $this->stats_ip->setReturnValue('getClientIp', Ip::encodeIp('127.0.0.1')); $this->stats_counter = new StatsCounterTestVersion2($this); $this->stats_counter->__construct(); $this->stats_referer = new StatsRefererTestVersion($this); $this->stats_referer->__construct(); $this->stats_referer->setReturnValue('getRefererPageId', 10); $this->stats_search_phrase = new StatsSearchPhraseTestVersion($this); $this->stats_search_phrase->__construct(); $this->stats_search_phrase->setReturnValue('register', true); $this->stats_register = new StatsRegisterTestVersion($this); $this->stats_register->__construct(); $this->stats_register->setReturnValue('_getIpRegister', $this->stats_ip); $this->stats_register->setReturnValue('_getCounterRegister', $this->stats_counter); $this->stats_register->setReturnValue('_getRefererRegister', $this->stats_referer); $this->stats_register->setReturnValue('_getSearchPhraseRegister', $this->stats_search_phrase); Limb::toolkit()->getUser()->set('id', 10); $this->_cleanUp(); }
function testFetch() { $time = mktime(6, 0, 0, 3, 6, 2005); $day = 24 * 60 * 60; $toolkit =& Limb::toolkit(); $db_table =& $toolkit->createDBTable('StatsHit'); $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => 1, 'action' => 'any', 'time' => $time1 = $time, 'ip' => $ip1 = Ip::encode('192.168.0.1'))); $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => 1, 'action' => 'any', 'time' => $time2 = $time + $day, 'ip' => $ip1)); $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => 1, 'action' => 'any', 'time' => $time3 = $time + $day, 'ip' => $ip2 = Ip::encode('192.168.0.2'))); $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => 1, 'action' => 'any', 'time' => $time4 = $time + 2 * $day, 'ip' => $ip1)); $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => 1, 'action' => 'any', 'time' => $time5 = $time + 3 * $day, 'ip' => $ip1)); $request =& $toolkit->getRequest(); $request->set('start_date', date('Y-m-d', $time2)); $request->set('finish_date', date('Y-m-d', $time4)); // Must find three records only $dao = new StatsHitsReportDAO(); $rs =& $dao->fetch(); $this->assertEqual($rs->getRowCount(), 3); $rs->rewind(); $record =& $rs->current(); $this->assertEqual($record->get('ip'), $ip1); $this->assertEqual($record->get('stats_referer_id'), 1); $this->assertEqual($record->get('session_id'), 'any'); $this->assertEqual($record->get('action'), 'any'); $this->assertEqual($record->get('time'), $time2); }
function testFetch() { $time = mktime(6, 0, 0, 3, 6, 2005); $day = 24 * 60 * 60; $toolkit =& Limb::toolkit(); $db_table =& $toolkit->createDBTable('StatsUri'); $db_table->insert(array('id' => $uri_id1 = 1, 'uri' => $uri1 = '/news')); $db_table->insert(array('id' => $uri_id2 = 2, 'uri' => $uri2 = '/articles')); $db_table =& $toolkit->createDBTable('StatsHit'); $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => $uri_id1, 'action' => 'any', 'time' => $time1 = $time, 'ip' => $ip = Ip::encode('192.168.0.1'))); $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => $uri_id1, 'action' => 'any', 'time' => $time2 = $time + $day, 'ip' => $ip)); $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => $uri_id1, 'action' => 'any', 'time' => $time3 = $time + $day, 'ip' => $ip)); $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => $uri_id2, 'action' => 'any', 'time' => $time4 = $time + 2 * $day, 'ip' => $ip)); $db_table->insert(array('stats_referer_id' => 1, 'session_id' => 'any', 'stats_uri_id' => $uri_id1, 'action' => 'any', 'time' => $time5 = $time + 3 * $day, 'ip' => $ip)); $request =& $toolkit->getRequest(); $request->set('start_date', date('Y-m-d', $time2)); $request->set('finish_date', date('Y-m-d', $time5)); // Must find three records only $dao = new StatsPagesReportDAO(); $rs =& $dao->fetch(); $this->assertTrue(is_a($rs, 'StatsPercentageRecordSet')); $this->assertEqual($rs->getRowCount(), 2); $rs->rewind(); $record =& $rs->current(); $this->assertEqual($record->get('uri'), $uri1); $rs->next(); $record =& $rs->current(); $this->assertEqual($record->get('uri'), $uri2); }
public static function city_ip2city(\ApiParam $params) { $city = \Ip::ip2city($params->ip, \Ip::INFO_ARRAY); if (is_array($city) && isset($city['englishName'])) { return self::cityFilter(\City::loadByName($city['englishName']), $params); } return null; }
public static function showCity() { $ip = Ip::getClientIp(); $url = "http://ip.taobao.com/service/getIpInfo2.php?ip={$ip}"; $data = Http::get($url); $data = json_decode($data, true); return $data; }
function _checkStatsIpRecord($total_records, $ip, $time) { $encoded_ip = Ip::encode($ip); $rs =& $this->db->select('stats_ip'); $arr = $rs->getArray('id'); $this->assertTrue(sizeof($arr), $total_records, 'ip count is wrong'); $this->assertTrue(isset($arr[$encoded_ip])); $this->assertEqual($arr[$encoded_ip]['time'], $time, 'ip time is incorrect'); }
public static function log($username, $psd, $ip = '') { if (empty($ip)) { Sys::S('core.Server.Ip'); $ip = Ip::get_client_ip(); } $data = array('username' => addslashes($username), 'psd' => addslashes($psd), 'ip' => bindec(decbin(ip2long($ip))), 'record_time' => NOW); return Sys::M(self::$trueTableName)->insert($data); }
function getValue() { include_once(LIMB_DIR . '/core/http/Ip.class.php'); if ($this->isConstant()) return Ip :: decode($this->base->getValue()); else RaiseError('compiler', 'UNRESOLVED_BINDING'); }
protected function connected($user) { socket_getpeername($user->socket, $user->ip); //save the client ip $ip = Ip::find($user->ip); $user->ip = $ip[1] . $ip[2] . '-' . date('H:i:s'); //file_put_contents(__DIR__.'/log.log', serialize($ip)); //exit; }
public function __construct($state, $action) { session_start(); parent::__construct($state, $action); $this->ip = Ip::getClientIp(); if ($action == 'set' || $action == 'set_tmp_log') { Switcher::close('postRefererCheck'); Switcher::close('masterDbPostOnly'); } }
public function __construct($state, $action) { session_start(); $_SESSION['group'] = 1; parent::__construct($state, $action); $this->ip = Ip::getClientIp(); $sysAdmin = true; $this->setView('sysAdmin', $sysAdmin); $this->username = '******'; }
private static function loginSuccess($userId, $ip = '') { if (empty($ip)) { Sys::S('core.Server.Ip'); $ip = Ip::get_client_ip(); } $intIp = Ip::getInt($ip); $data = array('last_login_ip' => array($intIp, 'int'), 'last_login_time' => array(NOW, 'int'), 'login_err_times' => array(0, 'int')); return Sys::M(self::$trueTableName)->update($data, '`id`=' . $userId); }
/** * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. */ public function actionIndex() { $criteria = new CDbCriteria(); $criteria->compare('ip_address', $_SERVER['REMOTE_ADDR']); $inRecord = Ip::model()->exists($criteria); if (!$inRecord) { throw new CHttpException(404, 'Page doesnt exist'); } else { $this->redirect(array('accounts/index')); } }
public function testGetIpReturnsIp() { $ip = '127.0.0.1'; $_SERVER['HTTP_CLIENT_IP'] = $ip; $this->assertEquals($ip, Ip::getClientIp()); unset($_SERVER['HTTP_CLIENT_IP']); $_SERVER['HTTP_X_FORWARDED_FOR'] = $ip; $this->assertEquals($ip, Ip::getClientIp()); unset($_SERVER['HTTP_X_FORWARDED_FOR']); $_SERVER['REMOTE_ADDR'] = $ip; $this->assertEquals($ip, Ip::getClientIp()); }
function testSameHostWrongDay() { $date1 = new Date(); $ip = Ip::encodeIp('192.168.0.5'); $this->stats_ip->setReturnValue('getClientIp', $ip); $this->stats_ip->isNewHost($date1); $date2 = new Date(); $date2->setByDays($date1->dateToDays() - 2); $this->stats_ip->setReturnValueAt(1, 'getClientIp', $ip); $this->assertFalse($this->stats_ip->isNewHost($date2)); $this->_checkStatsIpRecord($total_records = 1, $ip, $date1); }
public static function show() { $ip = Ip::getClientIp(); $url = "http://ip.taobao.com/service/getIpInfo2.php?ip={$ip}"; $data = Http::get($url); $data = json_decode($data, true); $city = false; if (isset($data['code']) && $data['code'] == 0) { $city = $data['data']['city']; } return $city; }
public function __construct($state, $action) { SESSION_START(); parent::__construct($state, $action); $this->ip = Ip::getClientIp(); /* //控制外网IP访问管理功能 if (substr($this->ip, 0, 3) != '10.') { header("HTTP/1.0 404 Not Found"); exit; } */ }
function beforeFilter() { parent::beforeFilter(); // Contador de visitas if (!$this->Session->check('Ip')) { $this->Session->write('Ip', 'echo'); $ip = new Ip(); $ip->create(array('ip' => env('REMOTE_ADDR'), 'navegador' => env('HTTP_USER_AGENT'), 'fecha' => getdate())); $ip->save(); } $this->Company_Nombre = 'Rubén Toca Lucio'; $this->Company_Email = '*****@*****.**'; $this->set('Company_Email', $this->Company_Email); $this->set('Company_Nombre', $this->Company_Nombre); // hay que comprobar que estás registrado como administrador if (isset($this->params['admin'])) { $this->checkAdminSession(); } // si no estás registrado Tipo = invitado if (!$this->Session->check('Tipo')) { $this->Session->write('Tipo', 'invitado'); } }
public function __construct($state, $action) { SESSION_START(); parent::__construct($state, $action); $this->ip = Ip::getClientIp(); if (in_array($action, array('debug'))) { Switcher::close('postRefererCheck'); } //控制外网IP访问管理功能 if (substr($this->ip, 0, 3) != '10.') { header("HTTP/1.0 404 Not Found"); exit; } }
public function setIpFilter($ip_string) { $ip_positive_hex_list = array(); $ip_negative_hex_list = array(); $ip_string_list = $this->_parseInputString($ip_string); foreach ($ip_string_list as $ip_piece) { if (substr($ip_piece, 0, 1) == '!') { $ip_piece = substr($ip_piece, 1); $ip_hex_list =& $ip_negative_hex_list; } else { $ip_hex_list =& $ip_positive_hex_list; } if (Ip::isValid($ip_piece)) { if (strpos($ip_piece, '*') !== false) { $ip_hex_list[] = Ip::encodeIp(str_replace('*', '255', $ip_piece)); } else { $ip_hex_list[] = Ip::encodeIp($ip_piece); } } elseif (preg_match('/^([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})[ ]*\\-[ ]*([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})$/', $ip_piece, $ip_match)) { foreach (Ip::encodeIpRange($ip_match[1], $ip_match[2]) as $ip_range_hex_item) { $ip_hex_list[] = $ip_range_hex_item; } } } $positive_conditions = array(); foreach ($ip_positive_hex_list as $hex_ip) { if (preg_match('/(ff\\.)|(\\.ff)/is', chunk_split($hex_ip, 2, '.'))) { $value = str_replace('.', '', preg_replace('/(ff\\.)|(\\.ff)/is', '%', chunk_split($hex_ip, 2, "."))) . "'"; } else { $value = $hex_ip; } $positive_conditions[] = $this->_buildPositiveCondition('sslog.ip', $value); } $negative_conditions = array(); foreach ($ip_negative_hex_list as $hex_ip) { if (preg_match('/(ff\\.)|(\\.ff)/is', chunk_split($hex_ip, 2, '.'))) { $value = str_replace('.', '', preg_replace('/(ff\\.)|(\\.ff)/is', '%', chunk_split($hex_ip, 2, "."))) . "'"; } else { $value = $hex_ip; } $negative_conditions[] = $this->_buildNegativeCondition('sslog.ip', $value); } $condition = $this->_combinePositiveNegativeConditions($positive_conditions, $negative_conditions); if ($condition) { $this->filter_conditions[] = ' AND ( ' . $condition . ' ) '; } }
protected function preFilter($filterChain) { $verdict = true; $criteriaSettings = new CDbCriteria(); $criteriaSettings->compare("setting_key", "enabled"); $criteriaSettings->compare("setting_value", "true"); $ipBlockFeatureisEnabled = Settings::model()->exists($criteriaSettings); $ipAddress = Yii::app()->request->getUserHostAddress(); $criteria = new CDbCriteria(); $criteria->compare("ip_address", $ipAddress); $ipExists = Ip::model()->exists($criteria); if (!$ipExists && $ipBlockFeatureisEnabled) { throw new CHttpException(403, "You are unauthorized to access this site"); $verdict = false; } return $verdict; }
/** * 显示登录页(默认Action) */ function doDefault() { /* {{{ 调试用例开始 */ $data = array('a' => 'a', 'b' => 3); $this->debug('数据库连接失败'); $this->debug($data); $this->debug('提示信息'); $this->debug('警告信息'); $this->debug('错误信息'); echo '调试方法使用,通过firephp和friebug查看相关调试信息<br />'; /* }}} */ $page = $this->app->page(); /* {{{ 输出验证码链接 */ echo '<img src="?do=code" ><br />'; /* }}} */ /* {{{ 验证验证码 */ if ($_GET['code']) { echo '验证码检测结果:' . var_export($this->_checkCode(trim($_GET['code'])), true) . '<br />'; } /* }}} */ /* {{{ 导出基础类 */ import('util.Ip'); //include('util/Ip.class.php'); echo Ip::get() . '<br />'; //调用IP类中获取IP的方法 /* }}} */ /* {{{ 导出应用定义模块文件 */ importModule('HelloWorld'); //include('modules/HelloWorld.class.php'); echo HelloWorld::Test('HelloWorld::Test') . '<br />'; //调用IP类中获取IP的方法 /* }}} */ /* {{{ 获取IP地址 */ echo 'Application 获得的IP地址' . $this->app->ip() . '<br />'; /* }}} */ /* {{{页面跳转 */ if ($_GET['go'] == 'redirect') { $this->app->redirect('http://www.baidu.com/'); } /* }}} */ /* {{{ 测试smarty页面输出 */ $page->value('title', '这是页面变量!!'); $page->output(); /* }}} */ }
function isNewToday($ip, $reg_time) { $ip = Ip::encode($ip); if (($record = $this->_getStatIpRecord($ip)) === false) { $this->_insertStatIpRecord($reg_time, $ip); return true; } $ip_date = new Date(); $ip_date->setByStamp($record['time']); $reg_date = new Date(); $reg_date->setByStamp($reg_time); if ($ip_date->dateToDays() < $reg_date->dateToDays()) { $this->_updateStatIpRecord($reg_time, $ip); return true; } elseif ($ip_date->dateToDays() > $reg_date->dateToDays()) { //this shouldn't happen normally... return false; } return false; }