Просмотр файла admin/ips.php

Размер файла: 11.08Kb
<?php
#############################################
# 0JXRgdC70Lgg0YLRiyDRh9C40YLQsNC10YjRjCDRj #
# dGC0L4g0YHQvtC+0LHRidC10L3QuNC1LCDQt9C90L #
# DRh9C40YIg0YLRiyDQvdC10LzQvdC+0LPQviDQt9C #
#          90LDQtdGI0YwgUEhQIQ==            #
#__---------------------------------------__#
#__        0JrQu9C40Log0JrQu9GD0LE=       __#
#  ---------------------------------------  #
# 0JDQstGC0L7RgCA6IE1vcmdhbg==              #
# SUNRIDog0L3QtSDRgdC60LDQttGDIHhE          #
#                                           #
#############################################

require '../inc/start.php';
require '../inc/regvars.php';
require '../inc/db.php';
require '../inc/config.php';
require '../inc/funct.php';
require '../inc/antidos.php';
require '../inc/gzip.php';
require '../inc/header.php';



only_reg('/aut.php?',true);

if($user_prof['admin']<3){location('menu/index.php');}

 switch($mode = (!empty($_GET['mode'])) ? $_GET['mode'] : null)
{
default:
$title = 'IP операторов';
require '../inc/head.php';
echo '<div class="sec">
IP операторов
</div><div class="vstavka">';

echo '<div class="ad"><img src="/pic/element.png"/> <a href="ips.php?mode=updt">Обновить базу</a></div>
<div class="ad"><img src="/pic/element.png"/> <a href="ips.php?mode=view">Просмотр</a></div>
<div class="ad"><img src="/pic/element.png"/> <a href="ips.php?mode=stat">Статистика</a></div>
<div class="ad"><img src="/pic/element.png"/> <a href="ips.php?mode=ip">Получение оператора</a></div>';

break;
#################################3
 case 'updt':
$title = 'Обновление базы';
require '../inc/head.php';
echo '<div class="sec">
Обновление базы
</div><div class="vstavka">';

echo 'Операторов до : <b>'.($count_op_before = mysql_num_rows(query("SELECT COUNT(*) FROM `$db[prefix]ips` GROUP BY `id_op` "))).'</b><br />';
echo 'Диапазонов до : <b>'.($count_di_before = mysql_result(query("SELECT COUNT(*) FROM `$db[prefix]ips` "),0)).'</b><br />';


//-- Очищаем таблицу
query("TRUNCATE TABLE `$db[prefix]ips`")or my_error();

if($_SERVER['REMOTE_ADDR'] == '127.0.0.1')$link = 'http://bookphp.wapmaste.wm/text/ips.xml';
else $link = 'http://www.logofon.ru/xml/ips.xml';

$file = win_to_utf(file_get_contents($link));

$file = trim(substr((substr($file,0,strripos($file,'</operators>'))),(stripos($file,'<operators>') + 11)));

#echo substr_count($file,'<operator').'<br />';

#preg_match_all('|\<operator(.*)\>(.*)\<\/operator\>|sUu',$file,$res);
#array_dump($res);

preg_match_all('|\<operator id="([0-9]*)" name="([[:space:]a-zA-Zа-яА-ЯёЁ0-9-(){}_.:]*)" label="([[:space:]a-zA-Z0-9]*)" tld="([a-zA-Z0-9]*)" country="([[:space:]a-zA-Zа-яА-Я0-9-(){}_.]*)" publish="([0-9]*)"\>(.*)\<\/operator\>|Usu',$file,$result);



//-- Количество операторов
$count_oper = count($result[0]);

//-- Массив операторов
$operators = array();

//-- Запускаем цикл
 for($i = 0;$i < $count_oper; $i ++)
{
//-- Массив текущего оператора
$operators[$i] = array();

$operators[$i]['id'] = $result[1][$i];
$operators[$i]['name'] = $result[2][$i];
#$operators[$i]['label'] = $result[3][$i];
$operators[$i]['tld'] = $result[4][$i];
$operators[$i]['country'] = $result[5][$i];



//-- Создаем базы IP
$operators[$i]['ip'] = array();

preg_match_all('|\<range ip1="([0-9]{10})" ip2="([0-9]{10})" mode="([0-9]*)" \/\>|Usu',$result[7][$i],$result2);
#echo '<b>#'.($i + 1).'.</b>'.htmlspecialchars($result[7][$i]).'<br />';
#array_dump($result2);

//-- Количество диапазанов для текущего опера
$count_ip = count($result2[0]);

//-- Еще один цикл
  for($j = 0;$j < $count_ip; $j ++)
 {
 	query("INSERT INTO `$db[prefix]ips` SET `name`='{$operators[$i]['name']}',`id_op`='{$operators[$i]['id']}',`country`='{$operators[$i]['country']}',`tld`='{$operators[$i]['tld']}',`ip1`='{$result2[1][$j]}',`ip2`='{$result2[2][$j]}' ")or my_error();
# $operators[$i]['ip'][$j] = array($result2[1][$j],$result2[2][$j]);
#echo long2ip($result2[1][$j]).' --- '.long2ip($result2[2][$j]).'<br />';
 }

}


echo 'Операторов после : <b>'.($count_op_after = mysql_num_rows(query("SELECT COUNT(*) FROM `$db[prefix]ips` GROUP BY `id_op` "))).'</b><br />';
echo 'Диапазонов после : <b>'.($count_di_after = mysql_result(query("SELECT COUNT(*) FROM `$db[prefix]ips` "),0)).'</b><br />';

if($count_op_after > $count_op_before)echo '+ Новых операторов : <b>'.($count_op_after - $count_op_before).'</b><br />';
if($count_di_after > $count_di_before)echo '+ Новых диапазонов : <b>'.($count_di_after - $count_di_before).'</b><br />';

if($count_op_before > $count_op_after)echo '- Удалено операторов : <b>'.($count_op_before - $count_op_after).'</b><br />';
if($count_di_before > $count_di_after)echo '- Удалено диапазонов : <b>'.($count_di_before - $count_di_after).'</b><br />';

echo '<a href="ips.php">Далее&gt;&gt;&gt;</a>';

break;
##################################
 case 'view':
$title = 'Просмотр';
require '../inc/head.php';



 switch($act = (!empty($_GET['act'])) ? $_GET['act'] : null)
{
default:
echo '<div class="sec">
Просмотр
</div><div class="vstavka">';

$count = mysql_num_rows(query("SELECT COUNT(*) FROM `$db[prefix]ips` GROUP BY `id_op`"));
if($count > 0)
{
$str = ceil($count/$set_on_page);
if($page > $str)location('admin/ips.php?mode=view');

sorting(array('name'=>'Оператору','strana'=>'Стране','count'=>'Количеству диапазонов'),'name','ips.php?mode=view&page='.$page.'&sort={$sort}');

$res = query("SELECT id_op,name,country,COUNT(id_op) AS count FROM `$db[prefix]ips` GROUP BY `id_op` ORDER BY ".str_replace(array('count','strana'),array('COUNT(id_op)','country'),$sort)." ".($sort == 'count' ? 'DESC' : 'ASC')." LIMIT $p_str,$set_on_page ");

$num = $p_str;
 while($record = mysql_fetch_array($res))
{
$num ++;

echo '<div class="ie"><b>'.$num.'.</b> <a href="ips.php?mode=view&act=op&oid='.$record['id_op'].'"><b>'.$record['name'].'</b></a> ('.$record['country'].','.$record['count'].')</div>';
}


 navigator($str,$page,'ips.php','mode=view');


}else{echo 'Операторов нет!';}
break;
###############
 case 'op':
if(!empty($_GET['oid']))
{
$oid = obr($_GET['oid'],'integer');
$res = query("SELECT name,id_op,country,tld FROM `$db[prefix]ips` WHERE `id_op` = '$oid' LIMIT 0,1 ");
if(mysql_num_rows($res) > 0)
{
$range = mysql_fetch_array($res);

echo '<div class="sec">
Диапазоны оператора <b>'.$range['name'].'</b>
</div><div class="vstavka">';

echo 'Оператор : <b>'.$range['name'].'</b>('.$range['id_op'].')<br />
Страна : <b>'.$range['country'].'</b>(<b>'.$range['tld'].'</b>)<br />';

$count = mysql_result(query("SELECT COUNT(*) FROM `$db[prefix]ips` WHERE `id_op` = '$oid' "),0);
if($count > 0)
{
$str = ceil($count/$set_on_page);
if($page > $str)location('admin/ips.php?mode=view&act=op&oid='.$oid);

$res = query("SELECT * FROM `$db[prefix]ips` WHERE `id_op` = '$oid' ORDER BY `ip1` ASC,`ip2` ASC LIMIT $p_str,$set_on_page ");
$num = $p_str;
 while($record = mysql_fetch_array($res))
{
$num ++;
echo '<div class="ie"><b>'.$num.'.</b> <b>'.long2ip($record['ip1']).'</b> - <b>'.long2ip($record['ip2']).'</b></div>';
}

 navigator($str,$page,'ips.php','mode=view&act=op&oid='.$oid);

}else{echo 'Диапазонов нет!';}

}else{echo 'Оператор не существует!';}
}else{echo 'Укажите ID!';}

break;
}

break;
##################################
 case 'stat':
$title = 'Статистика';
require '../inc/head.php';
echo '<div class="sec">
Статистика
</div><div class="vstavka">';

echo 'Операторов России : <b>'.mysql_num_rows(query("SELECT COUNT(*) FROM `$db[prefix]ips` WHERE `tld` = 'RU' GROUP BY `id_op` ")).'</b><br />
Операторов Украины : <b>'.mysql_num_rows(query("SELECT COUNT(*) FROM `$db[prefix]ips` WHERE `tld` = 'UA' GROUP BY `id_op` ")).'</b><br />
Операторов США : <b>'.mysql_num_rows(query("SELECT COUNT(*) FROM `$db[prefix]ips` WHERE `tld` = 'US' GROUP BY `id_op` ")).'</b><br />
Операторов Литвы : <b>'.mysql_num_rows(query("SELECT COUNT(*) FROM `$db[prefix]ips` WHERE `tld` = 'LT' GROUP BY `id_op` ")).'</b><br />
Операторов Латвии : <b>'.mysql_num_rows(query("SELECT COUNT(*) FROM `$db[prefix]ips` WHERE `tld` = 'LV' GROUP BY `id_op` ")).'</b><br />
Операторов Молдавии : <b>'.mysql_num_rows(query("SELECT COUNT(*) FROM `$db[prefix]ips` WHERE `tld` = 'MD' GROUP BY `id_op` ")).'</b><br />
Операторов Казахстана : <b>'.mysql_num_rows(query("SELECT COUNT(*) FROM `$db[prefix]ips` WHERE `tld` = 'KZ' GROUP BY `id_op` ")).'</b><br />
Операторов Армении : <b>'.mysql_num_rows(query("SELECT COUNT(*) FROM `$db[prefix]ips` WHERE `tld` = 'AM' GROUP BY `id_op` ")).'</b><br />
Операторов Болгарии : <b>'.mysql_num_rows(query("SELECT COUNT(*) FROM `$db[prefix]ips` WHERE `tld` = 'BG' GROUP BY `id_op` ")).'</b><br />
Операторов Грузии : <b>'.mysql_num_rows(query("SELECT COUNT(*) FROM `$db[prefix]ips` WHERE `tld` = 'GE' GROUP BY `id_op` ")).'</b><br />
Операторов Норвегии : <b>'.mysql_num_rows(query("SELECT COUNT(*) FROM `$db[prefix]ips` WHERE `tld` = 'NO' GROUP BY `id_op` ")).'</b><br />';

break;
##################################
 case 'ip':
$title = 'IP';
require '../inc/head.php';
echo '<div class="sec">
IP
</div><div class="vstavka">';

require '../inc/oper.php';

if(!empty($_GET['ip']))
 {

 $trans = !empty($_GET['trans']) && $_GET['trans'] == 1 ? 1 : 0;
 $ip = obr($_GET['ip'],'string');
 if($trans == 1)$ip = ip2long($ip);



 $operator = get_operator($ip);

 echo 'IP : <b>'.$ip.'</b><br />';
 echo 'Оператор : <b>'.$operator['name'].'</b><br />';
 if($operator['type'] > 0)
  {
  echo 'Страна : <b>'.$operator['country'].'</b><br />';
  }


 }
else
 {
echo '<form action="ips.php?mode=ip" method="GET"><input name="mode" type="hidden" value="ip">
IP : <br />
<input name="ip" type="text" value="'.$_ip.'"><br />
<input name="trans" type="checkbox" value="1">'.ip2long($_ip).' -> '.$_ip.'<br />
<input type="submit" value="Получить">
</form>';
 }

break;
/*
##################################
 case '-':
$title = '';
require '../inc/head.php';
echo '<div class="sec">

</div><div class="vstavka">';

break;
*/

}

echo '<hr/>';
if($mode != '')echo '...<a href="ips.php">IP операторов</a><br />';
echo '..<a href="/admin/index.php?">Админ панель</a><br />';
echo '.<a href="/menu/index.php?">Кабинет</a><br />';

require '../inc/foot.php';

################################################
# 0KHQutGA0LjQv9GCINC90LUg0L/QsNCx0LvQuNC6IQ== #
#   0KHRgtCw0LLRgNC+0L/QvtC70YwsIDIwMDkg0LMu   #
################################################

?>