示例#1
2
function my_inet_ntop($ip)
{
    if (strlen($ip) == 4) {
        // ipv4
        list(, $ip) = unpack('N', $ip);
        $ip = long2ip($ip);
    } elseif (strlen($ip) == 16) {
        // ipv6
        $ip = bin2hex($ip);
        $ip = substr(chunk_split($ip, 4, ':'), 0, -1);
        $ip = explode(':', $ip);
        $res = '';
        foreach ($ip as $seg) {
            while ($seg[0] == '0') {
                $seg = substr($seg, 1);
            }
            if ($seg != '') {
                $res .= ($res == '' ? '' : ':') . $seg;
            } else {
                if (strpos($res, '::') === false) {
                    if (substr($res, -1) == ':') {
                        continue;
                    }
                    $res .= ':';
                    continue;
                }
                $res .= ($res == '' ? '' : ':') . '0';
            }
        }
        $ip = $res;
    }
    return $ip;
}
示例#2
1
 function form_subnet()
 {
     global $db, $vars, $lang;
     $form_subnet = new form(array('FORM_NAME' => 'form_subnet'));
     $form_subnet->db_data('subnets.ip_start, subnets.ip_end, subnets.type, subnets.link_id, subnets.client_node_id');
     $links = $db->get('links.id AS value, links.type, links.ssid, nodes.name, links.peer_node_id, "" AS output', "links\n\t\t\t\t\t\t\tLEFT JOIN nodes ON links.peer_node_id = nodes.id", "(links.type = 'ap' OR links.type = 'p2p') AND node_id = " . intval(get('node')), "", "links.type ASC, links.date_in ASC");
     foreach ((array) $links as $key => $value) {
         $links[$key]['output'] .= $lang['db']['links__type-' . $value['type']] . ' - ';
         if ($value['type'] == 'ap') {
             $links[$key]['output'] .= $links[$key]['ssid'];
         }
         if ($value['type'] == 'p2p') {
             $links[$key]['output'] .= $links[$key]['name'] . ' (#' . $links[$key]['peer_node_id'] . ')';
         }
     }
     $form_subnet->db_data_enum('subnets.link_id', $links);
     $clients = $db->get('cl_n.id AS value, ap_l.ssid, cl_n.name, cl_n.id, "" AS output', "links AS cl_l " . "LEFT JOIN links AS ap_l ON cl_l.peer_ap_id = ap_l.id\n\t\t\t\t\t\t\tLEFT JOIN nodes AS ap_n ON ap_l.node_id = ap_n.id " . "LEFT JOIN nodes AS cl_n ON cl_l.node_id = cl_n.id", "cl_l.type = 'client' AND ap_l.type = 'ap' AND ap_l.node_id = " . intval(get('node')), "", "ap_l.date_in ASC, cl_l.date_in ASC");
     foreach ((array) $clients as $key => $value) {
         $clients[$key]['output'] = '[' . $lang['db']['links__type-ap'] . ' ' . $clients[$key]['ssid'] . '] - ' . $clients[$key]['name'] . ' (#' . $clients[$key]['id'] . ')';
     }
     $form_subnet->db_data_enum('subnets.client_node_id', $clients);
     $form_subnet->db_data_values("subnets", "id", get('subnet'));
     if (get('subnet') != 'add') {
         $form_subnet->data[0]['value'] = long2ip($form_subnet->data[0]['value']);
         $form_subnet->data[1]['value'] = long2ip($form_subnet->data[1]['value']);
     }
     return $form_subnet;
 }
/**
 * Reverse IP filter
 */
function fn_settings_actions_addons_access_restrictions_admin_reverse_ip_access(&$new_value, $old_value)
{
    $ip = fn_get_ip(true);
    if ($new_value == 'Y') {
        $ip_data = db_get_row("SELECT item_id, status FROM ?:access_restriction WHERE ip_from = ?i AND ip_to = ?i AND type IN ('aas', 'aab', 'aar')", $ip['host'], $ip['host']);
        if (empty($ip_data) || empty($ip_data['item_id'])) {
            // Add IP
            $restrict_ip = array('ip_from' => $ip['host'], 'ip_to' => $ip['host'], 'type' => 'aas', 'timestamp' => TIME, 'expires' => '0', 'status' => 'A');
            $__data = array();
            $__data['item_id'] = db_query("REPLACE INTO ?:access_restriction ?e", $restrict_ip);
            $__data['type'] = 'aas';
            foreach (fn_get_translation_languages() as $__data['lang_code'] => $_v) {
                $__data['reason'] = __('store_admin', '', $__data['lang_code']);
                db_query("REPLACE INTO ?:access_restriction_reason_descriptions ?e", $__data);
            }
            fn_set_notification('W', __('warning'), __('your_ip_added', array('[ip]' => long2ip($ip['host']))));
        } elseif (empty($ip_data['status']) || $ip_data['status'] != 'A') {
            // Change IP status to available
            db_query("UPDATE ?:access_restriction SET ?u WHERE item_id = ?i", array('status' => 'A'), $ip_data['item_id']);
            fn_set_notification('W', __('warning'), __('your_ip_enabled', array('[ip]' => long2ip($ip['host']))));
        }
    } else {
        // Delete IP
        $ips_data = db_get_array("SELECT item_id, type FROM ?:access_restriction WHERE ip_from <= ?i AND ip_to >= ?i AND type IN ('aas', 'aab', 'aar')", $ip['host'], $ip['host']);
        if (!empty($ips_data)) {
            foreach ($ips_data as $ip_data) {
                db_query("DELETE FROM ?:access_restriction WHERE item_id = ?i", $ip_data['item_id']);
                db_query("DELETE FROM ?:access_restriction_reason_descriptions WHERE item_id = ?i AND type = ?s", $ip_data['item_id'], $ip_data['type']);
            }
            fn_set_notification('W', __('warning'), __('your_ip_removed', array('[ip]' => long2ip($ip['host']))));
        }
    }
    return true;
}
 /**
  * Valid conversion should complete with no
  * exception thrown.
  *
  *
  * @group validconversion
  */
 public function testValidDataConversion()
 {
     $data = json_decode(json_encode($this->validSubmission));
     $data->data->cookie = md5(time());
     $data->data->domain = 'phptest' . time() . '.com';
     $data->data->domain_name = 'tsetphp' . time() . '.com';
     $data->data->registrant_ip = long2ip(time());
     $data->data->max_to_expiry = strtotime('-1 week');
     $data->data->min_to_expiry = strtotime('-2 years');
     $data->data->page = '10';
     $data->data->limit = '100';
     $data->data->type = md5(serialize($data));
     $shouldMatchNewDataObject = new \stdClass();
     $shouldMatchNewDataObject->cookie = $data->data->cookie;
     $shouldMatchNewDataObject->attributes = new \stdClass();
     $shouldMatchNewDataObject->attributes->domain = $data->data->domain;
     $shouldMatchNewDataObject->attributes->domain_name = $data->data->domain_name;
     $shouldMatchNewDataObject->attributes->registrant_ip = $data->data->registrant_ip;
     $shouldMatchNewDataObject->attributes->max_to_expiry = $data->data->max_to_expiry;
     $shouldMatchNewDataObject->attributes->min_to_expiry = $data->data->min_to_expiry;
     $shouldMatchNewDataObject->attributes->page = $data->data->page;
     $shouldMatchNewDataObject->attributes->limit = $data->data->limit;
     $shouldMatchNewDataObject->attributes->type = $data->data->type;
     $ns = new GetDomain();
     $newDataObject = $ns->convertDataObject($data);
     $this->assertTrue($newDataObject == $shouldMatchNewDataObject);
 }
示例#5
1
 /**
  * [index 管理员列表]
  * @return [type] [description]
  */
 public function index()
 {
     if (IS_AJAX) {
         $draw = I('draw', 1, 'intval');
         //排序设置
         $mycolumns = I('mycolumns', '');
         $myorder = I('order', '');
         if (empty($myorder) || empty($mycolumns)) {
             $order = 'id desc';
         } else {
             foreach ($myorder as $key => $v) {
                 $order .= $mycolumns[$v['column']] . ' ' . $v['dir'] . ' ,';
             }
             $order = rtrim($order, ',');
         }
         $db = D('UsersView');
         $lists = $db->where(true)->order($order)->select();
         foreach ($lists as $key => $v) {
             $lists[$key]['loginTime'] = $v['loginTime'] ? date('Y/m/d H:i:s', $v['loginTime']) : '';
             $lists[$key]['loginIp'] = $v['loginIp'] ? long2ip($v['loginIp']) : '';
             if ($v['status']) {
                 $lists[$key]['status'] = '正常';
             } else {
                 $lists[$key]['status'] = '禁用';
             }
         }
         $result['draw'] = $draw;
         $result['recordsTotal'] = $db->where(true)->count();
         $result['recordsFiltered'] = $result['recordsTotal'];
         $result['data'] = $lists;
         $this->ajaxReturn($result);
     } else {
         $this->display();
     }
 }
示例#6
0
 public function get_data()
 {
     $data = $this->input->stream();
     $page = isset($data['page']) ? $data['page'] : 1;
     $page--;
     $where = '1=1 AND ';
     if (isset($data['start_time']) && !empty($data['start_time'])) {
         $where .= "opera_time >= " . strtotime($data['start_time']) . " AND ";
     }
     if (isset($data['end_time']) && !empty($data['end_time'])) {
         $where .= "opera_time <= " . strtotime($data['end_time']) . " AND ";
     }
     if (isset($data['user']) && !empty($data['user'])) {
         $where .= "user like  '%{$data['user']}%' AND ";
     }
     $where = rtrim($where, 'AND ');
     $logs = $this->log_model->get_limit_length($page, self::PAGELENGTH, $where);
     $total_pages = $this->log_model->get_pages($where, self::PAGELENGTH);
     if ($logs) {
         array_walk($logs, function (&$item) {
             $item['ip'] = long2ip($item['ip']);
             $item['opera_time'] = date('Y-m-d H:i:s', $item['opera_time']);
         });
     }
     die(json_encode(array('code' => 200, 'message' => '获取成功', 'data' => array('data' => $logs, 'total_pages' => $total_pages, 'current_page' => $page + 1))));
 }
示例#7
0
文件: net.php 项目: WeihuaGu/phputil
function getRandomIp()
{
    $ip_long = array(array('607649792', '608174079'), array('1038614528', '1039007743'), array('1783627776', '1784676351'), array('2035023872', '2035154943'), array('2078801920', '2079064063'), array('-1950089216', '-1948778497'), array('-1425539072', '-1425014785'), array('-1236271104', '-1235419137'), array('-770113536', '-768606209'), array('-569376768', '-564133889'));
    $rand_key = mt_rand(0, 9);
    $ip = long2ip(mt_rand($ip_long[$rand_key][0], $ip_long[$rand_key][1]));
    return $ip;
}
 public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status)
 {
     if (!$ip || long2ip(ip2long($ip)) != $ip) {
         return;
     }
     $urls = $this->getLinks($content);
     array_unshift($urls, $site);
     foreach ($urls as $u) {
         $b = parse_url($u);
         if (!isset($b['host']) || !$b['host']) {
             continue;
         }
         $domain = preg_replace('/^[\\w]{2,6}:\\/\\/([\\w\\d\\.\\-]+).*$/', '$1', $b['host']);
         $domain_elem = explode(".", $domain);
         $i = count($domain_elem) - 1;
         if ($i == 0) {
             // "domain" is 1 word long, don't check it
             return null;
         }
         $host = $domain_elem[$i];
         do {
             $host = $domain_elem[$i - 1] . '.' . $host;
             $i--;
             if (substr(gethostbyname($host . '.' . $this->server), 0, 3) == "127") {
                 $status = substr($domain, 0, 128);
                 return true;
             }
         } while ($i > 0);
     }
 }
示例#9
0
function shop_match_network($nets, $ip, $first = false)
{
    $return = false;
    if (!is_array($nets)) {
        $nets = array($nets);
    }
    foreach ($nets as $net) {
        if ($rev = $net[0] == '!') {
            $net = substr($net, 1);
        }
        $ip_arr = explode('/', $net);
        $net_long = ip2long($ip_arr[0]);
        $x = ip2long($ip_arr[1]);
        $mask = long2ip($x) == $ip_arr[1] ? $x : 4294967295.0 << 32 - $ip_arr[1];
        $ip_long = ip2long($ip);
        if ($rev) {
            if (($ip_long & $mask) == ($net_long & $mask)) {
                return false;
            }
        } else {
            if (($ip_long & $mask) == ($net_long & $mask)) {
                $return = true;
            }
            if ($first && $return) {
                return true;
            }
        }
    }
    return $return;
}
 /**
  * 用户个人信息,收货信息
  * 收货人,收货手机,收货地址,邮编
  */
 public function userOneDetail()
 {
     $this->V(['user_id' => ['egNum', null, true]]);
     $id = intval($_POST['user_id']);
     $address = $this->table('user_address')->where(['is_on' => 1, 'user_id' => $id, 'is_default' => 1])->get(['id'], true);
     if (!$address) {
         $userinfo = $this->table('user')->where(['is_on' => 1, 'id' => $id])->get(null, true);
         $userinfo['add_time'] = date('Y-m-d H:i:s', $userinfo['add_time']);
         $userinfo['update_time'] = date('Y-m-d H:i:s', $userinfo['update_time']);
         $userinfo['last_ip'] = long2ip($userinfo['last_ip']);
         $userinfo['last_login'] = date('Y-m-d H:i:s', $userinfo['last_login']);
         $this->R(['userinfo' => $userinfo]);
     }
     $where = 'A.id=' . $id . ' and A.is_on = 1 and B.is_default = 1 and B.is_on = 1';
     $dataClass = $this->H('UserInfo');
     $userinfo = $dataClass->getUserInfo($where);
     if (!$userinfo) {
         $this->R('', 70009);
     }
     $userinfo['last_ip'] = long2ip($userinfo['last_ip']);
     $userinfo['last_login'] = date('Y-m-d H:i:s', $userinfo['last_login']);
     $userinfo['add_time'] = date('Y-m-d H:i:s', $userinfo['add_time']);
     $userinfo['update_time'] = date('Y-m-d H:i:s', $userinfo['update_time']);
     //返回数据,参见System/BaseClass.class.php方法
     $this->R(['userinfo' => $userinfo]);
 }
示例#11
0
 /**
  * @param Query $query
  * @param $filename
  * @return array
  */
 private function dump(Query $query, $filename)
 {
     $result = [];
     if (count($query) > 0) {
         $this->stdout("dump {$filename}:\n", Console::FG_GREEN);
         $total = count($query);
         Console::startProgress(0, $total);
         $n = 0;
         $time = Query::time();
         foreach ($query as $ip => $division) {
             if (is_integer($division)) {
                 $division = $query->divisionById($division);
             }
             $result[long2ip($ip)] = $division;
             $n++;
             if ($time < Query::time()) {
                 Console::updateProgress($n, $total);
                 $time = Query::time();
             }
         }
         Console::updateProgress($total, $total);
         Console::endProgress();
         $this->stdout(" completed!\n", Console::FG_GREEN);
     }
     return $result;
 }
示例#12
0
 protected function main()
 {
     inc_lib('news/news_exists');
     $count_news_existe = news_exists($_GET['id']);
     if ($count_news_existe == false && (is_logged_in() && !check_auth('view_histo_all_news'))) {
         redir(Nw::$lang['news']['news_not_exist'], false, './');
     }
     inc_lib('news/get_info_news');
     $donnees_news = get_info_news($_GET['id']);
     $this->set_title(Nw::$lang['news']['historique_news'] . ' | ' . $donnees_news['n_titre']);
     $this->set_tpl('news/log_news.html');
     $this->add_css('code.css');
     // Fil ariane
     if ($count_news_existe) {
         $this->set_filAriane(array(Nw::$lang['news']['news_section'] => array('news-70.html'), $donnees_news['c_nom'] => array($donnees_news['c_rewrite'] . '/'), $donnees_news['n_titre'] => array($donnees_news['c_rewrite'] . '/' . rewrite($donnees_news['n_titre']) . '-' . $_GET['id'] . '/'), Nw::$lang['news']['historique_news'] => array('')));
     } else {
         $this->set_filAriane(array(Nw::$lang['news']['news_section'] => array('news-70.html'), Nw::$lang['news']['historique_news'] => array('')));
     }
     /**
      *   Affichage du logo
      **/
     inc_lib('news/get_news_logs');
     $donnees_logs = get_news_logs('l_id_news = ' . intval($_GET['id']), 'l_date DESC');
     foreach ($donnees_logs as $donnees) {
         Nw::$tpl->setBlock('log', array('ACTION' => $donnees['l_action'], 'ACTION_LOG' => isset(Nw::$lang['news']['log_news_' . $donnees['l_action']]) ? Nw::$lang['news']['log_news_' . $donnees['l_action']] : '', 'TEXTE' => nl2br($donnees['l_texte']), 'TITRE' => $donnees['l_titre'], 'DATE' => date_sql($donnees['date'], $donnees['heures_date'], $donnees['jours_date']), 'AUTEUR' => $donnees['u_pseudo'], 'AUTEUR_ID' => $donnees['u_id'], 'AUTEUR_AVATAR' => $donnees['u_avatar'], 'AUTEUR_ALIAS' => $donnees['u_alias'], 'IP' => long2ip($donnees['l_ip'])));
     }
     Nw::$tpl->set(array('ID' => $_GET['id'], 'TITRE' => $donnees_news['n_titre']));
 }
示例#13
0
 /**
  * 应用程序初始化
  * @access public
  * @return void
  */
 public static function start()
 {
     // 设定错误和异常处理
     register_shutdown_function(array('Think', 'fatalError'));
     set_error_handler(array('Think', 'appError'));
     set_exception_handler(array('Think', 'appException'));
     // 注册AUTOLOAD方法
     spl_autoload_register(array('Think', 'autoload'));
     //[RUNTIME]
     Think::buildApp();
     // 预编译项目
     //[/RUNTIME]
     // 运行应用
     $_SERVER['ip'] = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
     $cdn_ips = array('182.140.245.*', '58.49.105.*', '61.147.103.*', '61.147.79.*', '61.158.240.*', '61.244.110.*', '210.209.122.*', '64.32.4.*', '69.28.51.*', '111.161.72.*', '112.253.3.*', '112.64.18.*', '113.31.80.*', '113.31.82.*', '117.34.91.*', '118.144.86.*', '119.97.153.*', '120.197.85.*', '121.11.83.*', '121.12.119.*', '121.14.212.*', '122.200.77.*', '122.225.36.*', '123.129.209.*', '123.150.187.*', '124.95.164.*', '182.118.12.*', '182.118.38.*', '183.232.29.*', '202.102.85.*', '202.105.176.*', '203.171.228.*', '220.181.135.*', '223.202.2.*', '211.155.80.*', '61.164.211.*');
     foreach ($cdn_ips as $cdnip) {
         if ($_SERVER['ip'] == $cdnip || strrchr($cdnip, '.') == '.*' && ($pre = substr($cdnip, 0, -2)) && $pre == substr($_SERVER['ip'], 0, strlen($pre))) {
             $realip = $_SERVER['HTTP_X_FORWARDED_FOR'];
             empty($realip) && ($realip = $_SERVER['HTTP_CLIENT_IP']);
             if (preg_match('#^\\d+(\\.\\d+){3}$#', $realip)) {
                 $_SERVER['REMOTE_ADDR'] = long2ip(ip2long($realip));
             }
         }
     }
     App::run();
     return;
 }
示例#14
0
 public function index()
 {
     echo $_POST['keyword'];
     //搜索
     if (!empty($_GET['keyword'])) {
         if ($_GET['searchtype'] == 'uid') {
             $condition_user['uid'] = $_GET['keyword'];
         } else {
             if ($_GET['searchtype'] == 'nickname') {
                 $condition_user['nickname'] = array('like', '%' . $_GET['keyword'] . '%');
             } else {
                 if ($_GET['searchtype'] == 'phone') {
                     $condition_user['phone'] = array('like', '%' . $_GET['keyword'] . '%');
                 }
             }
         }
     }
     $database_user = D('User');
     $count_user = $database_user->where($condition_user)->count();
     import('@.ORG.system_page');
     $p = new Page($count_user, 15);
     $user_list = $database_user->field(true)->where($condition_user)->order('`uid` DESC')->limit($p->firstRow . ',' . $p->listRows)->select();
     if (!empty($user_list)) {
         import('ORG.Net.IpLocation');
         $IpLocation = new IpLocation();
         foreach ($user_list as &$value) {
             $last_location = $IpLocation->getlocation(long2ip($value['last_ip']));
             $value['last_ip_txt'] = iconv('GBK', 'UTF-8', $last_location['country']);
         }
     }
     $this->assign('user_list', $user_list);
     $pagebar = $p->show();
     $this->assign('pagebar', $pagebar);
     $this->display();
 }
示例#15
0
 public static function get_IP()
 {
   /**
    * Si PHP est derrière un reverse proxy ou un load balancer, REMOTE_ADDR peut contenir l'ip du proxy.
    * Normalement, le proxy doit renseigner HTTP_X_REAL_IP, ou HTTP_X_FORWARDED_FOR.
    * Au CITIC, REMOTE_ADDR est correct, et chez OVH aussi (avec apache derrière nginx ou pas).
    */
   $ip = $_SERVER['REMOTE_ADDR'];
   if (isset($_SERVER['HTTP_X_REAL_IP']))
   {
     $ip = $_SERVER['HTTP_X_REAL_IP'];
   }
   elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
   {
     $forwarded = $_SERVER['HTTP_X_FORWARDED_FOR'];
     // on s'arrête à la 1re virgule si on en trouve une
     $tab_forwarded = preg_split("/,| /",$forwarded);
     $ip_candidate = $tab_forwarded[0];
     $ip_composantes = explode('.', $ip_candidate);
     // On vérifie que ça ressemble à une ip (au cas où on aurait une chaîne bizarre ou vide on garde notre REMOTE_ADDR)
     if ( (count($ip_composantes)==4) && (min($ip_composantes)>=0) && (max($ip_composantes)<256) && (max($ip_composantes)>0) )
     {
       $ip = $ip_candidate;
     }
   }
   // petit truc pour s'assurer d'avoir une IP valide
   return ($ip == long2ip(ip2long($ip))) ? $ip : '' ;
 }
示例#16
0
 function getIp()
 {
     if (isset($this->details['location_ip'])) {
         return long2ip($this->details['location_ip']);
     }
     return false;
 }
示例#17
0
 public function getBroadcastIP($ip, $subnet)
 {
     $ip = ip2long($ip);
     $subnet = ip2long($subnet);
     $broadcastIP = $ip | ~$subnet;
     return long2ip($broadcastIP);
 }
示例#18
0
function validIP($ip)
{
    if ($ip == long2ip(ip2long($ip))) {
        return true;
    }
    return false;
}
 public function init($row)
 {
     //подставляем массив в свойства объекта
     foreach ($this->properties as $key => $value) {
         //получаем все поля
         $val = $row[$key];
         //print_r($val);
         switch ($value["type"]) {
             //проверка типа
             case self::TYPE_TIMESTAMP:
                 //если дата
                 if (!is_null($val)) {
                     $val = strftime($this->format_date, $val);
                 }
                 //преобразуем дату в чиловой формат
                 break;
             case self::TYPE_IP:
                 //если IP
                 if (!is_null($val)) {
                     $val = long2ip($val);
                 }
                 //преобразуем ip в обычное число
                 break;
         }
         $this->properties[$key]["value"] = $val;
     }
     $this->id = $row["id"];
     return $this->postInit();
 }
示例#20
0
 function isip($ip)
 {
     if (!strcmp(long2ip(sprintf("%u", ip2long($ip))), $ip)) {
         return true;
     }
     return false;
 }
示例#21
0
 public function run()
 {
     $model = new Model_ReportApi_Accesslog();
     $hosts = $model->getBusiness();
     $day = strtotime($this->getRequest()->getQuery('from', date('Y-m-d')));
     $where = " and `time`={$day} ";
     $where .= empty($hosts) ? '' : " AND `host_id` in ({$hosts})";
     $res = $model->rtcTopTen($where);
     //        print_r($res);exit;
     //        $result['name'] = 'rtcTopTen';
     $result = array();
     foreach ($res as $value) {
         $result['series'][] = array('ip' => long2ip($value['ip']), 'name' => ucwords(strtolower($model->ip2location($value['ip']))), 'second' => $value['total_request_time'], 'path' => $value['path'], 'host' => $value['host']);
     }
     //        print_r($result);exit;
     if (empty($res)) {
         static::output(0, 'no data', array());
     } else {
         static::output(1, 'RtcTopTen', $result);
     }
     //      测试数据
     //        $result['series'] = array(
     //            array('ip'     => '172.30.10.222',
     //            'name'   => 'china',
     //            'second' => '1123',
     //            'path' => '/root'
     //            ),
     //            array('ip'     => '192.40.30.222',
     //                'name'   => 'USA',
     //                'second' => '1589',
     //                'path' => '/usr/local'
     //            ),
     //        );
     //        static::output(1,'RtcTopTen',$result);
 }
/**
 * returns IPv4 address
 *
 * @see http://php.net/long2ip
 */
function PMA_transformation_text_plain__longToIpv4($buffer, $options = array(), $meta = '')
{
    if ($buffer < 0 || $buffer > 4294967295) {
        return $buffer;
    }
    return long2ip($buffer);
}
示例#23
0
 public static function long2ipv4($cidr)
 {
     if ($cidr < 1 || $cidr > 32) {
         throw new InvalidArgumentException('Invalid CIDR specified');
     }
     return long2ip(-1 << 32 - (int) $cidr);
 }
示例#24
0
 public function __construct()
 {
     parent::__construct();
     $user = M('User')->getUserById($this->user_session['uid']);
     $user['last_ip'] = long2ip($user['last_ip']);
     $this->assign('user', $user);
 }
示例#25
0
    function column_default($item, $name)
    {
        global $wpdb;
        switch ($name) {
            case 'created_at':
                $timestamp = $item->{$name} / 1000 + $this->gmt_offset * 3600;
                return date_i18n('d/m/Y H:i', $timestamp);
                // return get_date_from_gmt( date( 'Y-m-d H:i:s', $item->$name / 1000 ), 'd/m/Y H:i' );
            // return get_date_from_gmt( date( 'Y-m-d H:i:s', $item->$name / 1000 ), 'd/m/Y H:i' );
            case 'total_msgs':
                // Total messages
                return $wpdb->get_var($wpdb->prepare('SELECT COUNT(*) FROM ' . CX_PX . 'chat_logs 
							WHERE cnv_id = %s', $item->cnv_id));
            case 'ip':
                return long2ip($item->{$name});
            case 'email':
                if (!empty($item->{$name})) {
                    return '<a href="mailto:' . $item->{$name} . '">' . $item->{$name} . '</a>';
                } else {
                    return '<span style="color:silver">' . __('N/A', 'cx') . '</span>';
                }
                // return $item->$column_name;
            // return $item->$column_name;
            default:
                return print_r($item, true);
                // Show the whole array for troubleshooting purposes
        }
    }
 /**
  * Valid conversion should complete with no
  * exception thrown.
  *
  *
  * @group validconversion
  */
 public function testValidDataConversion()
 {
     $data = json_decode(json_encode($this->validSubmission));
     $data->data->domain = 'phptest' . time() . '.com';
     $data->data->content = long2ip(time());
     $data->data->name = '@';
     $data->data->type = 'A';
     $data->data->forward_email = '*****@*****.**';
     $data->data->mailbox_type = 'MAILBOX';
     $data->data->password = '******';
     $shouldMatchNewDataObject = new \stdClass();
     $shouldMatchNewDataObject->attributes = new \stdClass();
     $shouldMatchNewDataObject->attributes->dnsRecords = new \stdClass();
     $shouldMatchNewDataObject->attributes->mailbox = new \stdClass();
     $shouldMatchNewDataObject->attributes->dnsRecords->content = $data->data->content;
     $shouldMatchNewDataObject->attributes->dnsRecords->name = $data->data->name;
     $shouldMatchNewDataObject->attributes->dnsRecords->type = $data->data->type;
     $shouldMatchNewDataObject->attributes->domain = $data->data->domain;
     $shouldMatchNewDataObject->attributes->mailbox->forward_email = $data->data->forward_email;
     $shouldMatchNewDataObject->attributes->mailbox->mailbox_type = $data->data->mailbox_type;
     $shouldMatchNewDataObject->attributes->mailbox->password = $data->data->password;
     $ns = new PersonalNamesUpdate();
     $newDataObject = $ns->convertDataObject($data);
     $this->assertTrue($newDataObject == $shouldMatchNewDataObject);
 }
示例#27
0
文件: utils.php 项目: syjzwjj/quyeba
 static function match_network($nets, $ip, $first = false)
 {
     $return = false;
     if (!is_array($nets)) {
         $nets = array($nets);
     }
     foreach ($nets as $net) {
         $rev = preg_match("/^\\!/", $net) ? true : false;
         $net = preg_replace("/^\\!/", "", $net);
         $ip_arr = explode('/', $net);
         $net_long = ip2long($ip_arr[0]);
         $x = ip2long($ip_arr[1]);
         $mask = long2ip($x) == $ip_arr[1] ? $x : 4294967295.0 << 32 - $ip_arr[1];
         $ip_long = ip2long($ip);
         if ($rev) {
             if (($ip_long & $mask) == ($net_long & $mask)) {
                 return false;
             }
         } else {
             if (($ip_long & $mask) == ($net_long & $mask)) {
                 $return = true;
             }
             if ($first && $return) {
                 return true;
             }
         }
     }
     return $return;
 }
示例#28
0
 function inet_ntop($ip)
 {
     if (strlen($ip) == 4) {
         // Unpack IPv4
         list(, $ip) = unpack('N', $ip);
         $ip = long2ip($ip);
         return $ip;
     } elseif (strlen($ip) == 16) {
         // Unpack IPv6
         $ip = bin2hex($ip);
         $sz = strlen($ip);
         $res = '';
         while ($sz >= 4) {
             $sz -= 4;
             $seg = ltrim(substr($ip, $sz, 4), '0');
             if ($seg != '') {
                 $res = $seg . ($res == '' ? '' : ':') . $res;
             } else {
                 // Make sure 0:2:3:4:5:6:7:8 is handled
                 if (strpos($res, '::') === false && substr_count($res, ':') < 6) {
                     // Make sure ::1 is handled
                     if ($res != '' && $res[0] == ':' && $i > 4) {
                         continue;
                     }
                     $res = ':' . $res;
                     continue;
                 }
                 $res = '0' . ($res == '' ? '' : ':') . $res;
             }
         }
         return $res;
     }
     return false;
 }
示例#29
0
 private function parseIPBlacklistIntoRanges()
 {
     $ips = preg_split('{[\\r\\n]+}', $this->post('ip_ban_manual'), null, PREG_SPLIT_NO_EMPTY);
     $ip_ranges = array();
     foreach ($ips as $ip) {
         if (strpos($ip, '*') === false) {
             $ip = long2ip(ip2long($ip));
             //ensures a valid ip
             $ip_ranges[] = array('ipFrom' => $ip, 'ipTo' => 0);
         } else {
             $aOctets = preg_split('{\\.}', $ip);
             $ipFrom = '';
             $ipTo = '';
             for ($i = 0; $i < 4; $i++) {
                 if (is_numeric($aOctets[$i])) {
                     $ipFrom .= $aOctets[$i] . '.';
                     $ipTo .= $aOctets[$i] . '.';
                 } else {
                     $ipFrom .= '0' . '.';
                     $ipTo .= '255' . '.';
                 }
             }
             $ipFrom = substr($ipFrom, 0, strlen($ipFrom) - 1);
             $ipTo = substr($ipTo, 0, strlen($ipTo) - 1);
             $ipFrom = long2ip(ip2long($ipFrom));
             //ensures a valid ip
             $ipTo = long2ip(ip2long($ipTo));
             //ensures a valid ip
             $ip_ranges[] = array('ipFrom' => $ipFrom, 'ipTo' => $ipTo);
         }
     }
     return $ip_ranges;
 }
示例#30
0
 public function AddHost($name)
 {
     if (array_key_exists($name, $this->nodes)) {
         die(sprintf("TopoGen::AddHost duplicate %s\n", $name));
     }
     $this->nodes[$name] = array('type' => 'host', 'ip' => long2ip(++$this->last_ip), 'devices' => array());
 }