<?php
/*
 * @Descripttion:
 * @version:
 * @Author: kangkang
 * @Date: 2020-11-03 11:04:15
 * @LastEditors: “wanyongkang” “937888580@qq.com”
 * @LastEditTime: 2024-03-29 16:22:00
 */

$is_script = 1;
include_once __DIR__ . '/../../index.php';
include_once __DIR__ . '/auto_format.php';
include_once __DIR__ . '/../../extends/jinyouapi/Jinyou.php';

use extend\jinyouapi\jinyou;

ini_set("display_errors", 0);


// // //测试用----------------------------------------------------------------------------------------------------------

//极光
// $url = "http://106.119.166.87:18702/api/agent/getList2?apikey=80cf4f64e990b78a9fc5eb";
// $jiguang = json_decode(file_get_contents($url), true)['data'];
// if ($jiguang) {
//     $jiguang_f = fopen(__DIR__ . '/data/jiguang.csv', 'w');
//     jiguang_getList($jiguang, $jiguang_f, $all);
//     fclose($jiguang_f);
// }

// die;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$dnx_has_exit = [];
// //强子迅联特征码
// $sp_xl_code = file_get_contents(__DIR__ . '/data/xl.txt', 'r');

// // echo $sp_xl_code;

// $sp_xl_json = json_decode(substr($sp_xl_code,3),true);
// $sp_xl_list = [];
// foreach($sp_xl_json as $k=>$v){
//     $temp = explode('-',$k);
//     $sp_xl_list[$temp[1]] = $v;
// }



// $sp_qz_code = file_get_contents(__DIR__ . '/data/qz.txt', 'r');

// // echo $sp_qz_code;

// $sp_qz_json = json_decode(substr($sp_qz_code,3),true);
// $sp_qz_list = [];
// foreach($sp_qz_json as $k=>$v){
//     $temp = explode('-',$k);
//     $sp_qz_list[$temp[1]] = $v;
// }
//--------------------------------------------

$all = fopen(__DIR__ . '/data/all.csv', 'w');
$dnx_exit = fopen(__DIR__ . '/data/dns_diff.csv', 'a');
$dnx_has_exit = get_product(__DIR__ . '/data/dns_diff.csv', 1);
//-----------------------------------------------------------------------------------------------------

//极狐
$url = "http://124.236.113.166:18702/api/agent/getList2?apikey=80cf4f64e990b78a9fc5eb";
$jihu = json_decode(file_get_contents($url), true)['data'];
if ($jihu) {
    $jihu_f = fopen(__DIR__ . '/data/jihu.csv', 'w');
    jihu_getList($jihu, $jihu_f, $all);
    fclose($jihu_f);
}

//极光
$url = "http://106.119.166.87:18702/api/agent/getList2?apikey=80cf4f64e990b78a9fc5eb";
$jiguang = json_decode(file_get_contents($url), true)['data'];
if ($jiguang) {
    $jiguang_f = fopen(__DIR__ . '/data/jiguang.csv', 'w');
    jiguang_getList($jiguang, $jiguang_f, $all);
    fclose($jiguang_f);
}


$apikey = '80cf4f64e990b78a9fc5eb';
$url = "http://rds-api.juip.com/api/index/getList2?apikey=".$apikey;
$mogu = json_decode(file_get_contents($url), true)['data'];
if ($mogu) {
    $mogu_f = fopen(__DIR__ . '/data/mogu.csv', 'w');
    mogu_getList($mogu, $mogu_f, $all);
    fclose($mogu_f);
}



//麒麟动态
$dnx_has_exit = [];
$qilin = new jinyou();

$qilin_api_data = (array)((array)((array)($qilin::getDynamicLine()))['res'])['data'];

if ($qilin_api_data) {
    $qilin_data = get_product(__DIR__ . '/data/qilin.csv');
    $qilin_f = fopen(__DIR__ . '/data/qilin.csv', 'w');
    qilin_getList($qilin_api_data, $qilin_f, $all,$qilin_data);
    fclose($qilin_f);
}


//猎豹
$url = "http://106.119.166.87:18702/api/agent/getList2?apikey=80cf4f64e990b78a9fc5eb";
$liebao = json_decode(file_get_contents($url), true)['data'];
if ($liebao) {
    $liebao_f = fopen(__DIR__ . '/data/liebao.csv', 'w');
    liebao_getList($liebao, $liebao_f, $all);
    fclose($liebao_f);
}

// $liebao = json_decode(file_get_contents("https://xmapi.xingmojs.com/ppp/v1/areas?apiid=130&sendtime=" . time() . "&sign=" . md5('apiid=130&sendtime=' . time() . '3AT7XCHjWG8sSMpRBjtAJ8JRkSAbhJit')), true)['data'];

// if($liebao){
// $liebao_data = get_product(__DIR__ . '/data/liebao.csv');
// $liebao_f = fopen(__DIR__ . '/data/liebao.csv', 'w');
// //写入天天文件
// liebao_getList($liebao, $liebao_f, $all, $liebao_data, '猎豹');
// fclose($liebao_f);
// }

// //先锋
// $xianfeng = json_decode(file_get_contents("http://service.shenlongip.com/api/server/getlist"), true)['P'];


// if($xianfeng){
// $xianfeng_data = get_product(__DIR__ . '/data/xianfeng.csv');
// $xianfeng_f = fopen(__DIR__ . '/data/xianfeng.csv', 'w');
// //写入先锋文件
// xianfeng_getList($xianfeng, $xianfeng_f, $all, $xianfeng_data);
// fclose($xianfeng_f);
// }



// $time =  time();
// $noce = md5(time());
// $apikey = 'a478ad5aa3079bbbef3cd45e2d55d61e';
// $sign = md5($time.$noce.$apikey);
// $url = "http://47.92.116.14:2222/api/getNodeList?agentid=admin1&ti=".$time."&nonce=".$noce."&sign=".$sign;
// $qiangzi = json_decode(file_get_contents($url), true)['data'];
// if(!empty($qiangzi)){
// $qiangzi_data = get_product(__DIR__ . '/data/qiangzi.csv');
// $qiangzi_f = fopen(__DIR__ . '/data/qiangzi.csv', 'w');

// //写入强子文件
// qiangzi_getList($qiangzi, $qiangzi_f, $all, $qiangzi_data);
// fclose($qiangzi_f);
// }


// $time =  time();
// $noce = md5(time());
// $apikey = 'osoa917321hdjw';
// $sign = md5($time.$noce.$apikey);
// $url = "http://47.92.65.184:2223/api/getNodeList?agentid=admin2&ti=".$time."&nonce=".$noce."&sign=".$sign;
// $xunlian = json_decode(file_get_contents($url), true)['data'];
// // $xunlian = false;
// if ($xunlian){
//     $xunlian_data = get_product(__DIR__ . '/data/xunlian.csv');
//     $xunlian_f = fopen(__DIR__ . '/data/xunlian.csv', 'w');
//     //写入讯连文件
//     xunlian_getList($xunlian, $xunlian_f, $all, $xunlian_data);
//     fclose($xunlian_f);
// }

///动态
$url = 'http://int.lhok.net:8000/lineapi_admin1.php?secretId=201000018&secretKey=13239c30a2cb41fe1bc1fa129de2cc5c';
$yunniu = json_decode(file_get_contents($url), true);


if(!empty($yunniu)){
    $yunniu_f = fopen(__DIR__ . '/data/yunniu.csv', 'w');
    //写入火狐文件
    $yunniu_data = get_product(__DIR__ . '/data/yunniu.csv');
    yunniu_getList($yunniu, $yunniu_f, $all,$yunniu_data);
    fclose($yunniu_f);
}

// $xigua = json_decode(file_get_contents("http://api.beikeip.com/serverlistyzip/"), true)['data'];
// if($xigua){
// $xigua_data = get_product(__DIR__ . '/data/xigua.csv');
// $xigua_f = fopen(__DIR__ . '/data/xigua.csv', 'w');
// //写入西瓜文件
// jike_getList($xigua, $xigua_f, $all, $xigua_data, false);
// fclose($xigua_f);
// }

// $tiantian = json_decode(file_get_contents("https://yoyoapi.yoyoip.com/v1/areas?apiid=89&sendtime=" . time() . "&sign=" . md5('apiid=89&sendtime=' . time() . 'NFeK72yYXmPiGR86YeMCBRTWDxXkrQsd')), true)['data'];
// if($tiantian){
// $tiantian_data = get_product(__DIR__ . '/data/tiantian.csv');
// $tiantian_f = fopen(__DIR__ . '/data/tiantian.csv', 'w');
// //写入天天文件
// tiantian_getList($tiantian, $tiantian_f, $all, $tiantian_data, '天天');
// fclose($tiantian_f);
// }

// $jike = json_decode(file_get_contents("http://api.beikeip.com/beikeiplist/"), true)['data'];
// if($jike){
// $jike_data = get_product(__DIR__ . '/data/jike.csv');
// $jike_f = fopen(__DIR__ . '/data/jike.csv', 'w');
// //写入极客文件
// jike_getList($jike, $jike_f, $all, $jike_data);
// fclose($jike_f);
// }


//水滴
$url = "https://www.jyip.net/static-list";
$shuidi_api_data = json_decode(file_get_contents($url),true)['data'];

if ($shuidi_api_data) {
    $shuidi_data = get_product(__DIR__ . '/data/shuidi.csv');
    $shuidi_f = fopen(__DIR__ . '/data/shuidi.csv', 'w');
    shuidi_getList($shuidi_api_data, $shuidi_f, $all,$shuidi_data);
    fclose($shuidi_f);
}

$url = 'http://int.linghangadmin.com:8000/sysadmin/useradmin/lineapi_admin1.php?secretId=108006113&secretKey=87085a351a64c116df09ebc07d5781sf';
$huohu = json_decode(file_get_contents($url), true);


if(!empty($huohu)){
    $huohu_f = fopen(__DIR__ . '/data/huohu.csv', 'w');
    //写入火狐文件
    $huohu_data = get_product(__DIR__ . '/data/huohu.csv');
    huohu_getList($huohu, $huohu_f, $all,$huohu_data);
    fclose($huohu_f);
}



// 静态
$time =  time();
$noce = md5(time());
$apikey = 'a478ad5aa3079bbbef3cd45e2d55d61e';
$sign = md5($time.$noce.$apikey);
$url = "http://47.92.116.14:2222/api/getNodeList?agentid=admin1&ti=".$time."&nonce=".$noce."&sign=".$sign;
$qiangzi = json_decode(file_get_contents($url), true)['data'];

if(!empty($qiangzi)){
    $qiangzi_data = get_product(__DIR__ . '/data/qiangzijt.csv');
    $qiangzi_f = fopen(__DIR__ . '/data/qiangzijt.csv', 'w');
    
    //写入强子文件
    qiangzijt_getList($qiangzi, $qiangzi_f, $all, $qiangzi_data);
    fclose($qiangzi_f);
}
    


// $time =  time();
// $noce = md5(time());
// $apikey = 'd50f2b2ffd421efa67df8efb96d5ff6c';
// $sign = md5($time.$noce.$apikey);
// $url = "http://106.54.198.154/api/getNodeList?agentid=admin1&ti=".$time."&nonce=".$noce."&sign=".$sign;
// $xingxing = json_decode(file_get_contents($url), true)['data'];
// //写入星星文件
// if($xingxing){
// $xingxing_data = get_product(__DIR__ . '/data/xingxing.csv');
// $xingxing_f = fopen(__DIR__ . '/data/xingxing.csv', 'w');
// xingxing_getList($xingxing, $xingxing_f, $all, $xingxing_data);
// fclose($xingxing_f);
// }




// $jinrui_data = get_product(__DIR__ . '/data/jinrui.csv');
// $jinrui_f = fopen(__DIR__ . '/data/jinrui.csv', 'w');
// $jinrui = file_get_contents("http://pptp.zhekou5.com/api/getnas.php");
// //写入金瑞文件
// jinrui_getList($jinrui, $jinrui_f, $all, $jinrui_data);
// fclose($jinrui_f);

// $laoying = json_decode(file_get_contents("http://diqu.pptp.pro:8070/sapi/getroslist"), true)['list'];
// if($laoying){
// $laoying_data = get_product(__DIR__ . '/data/laoying.csv');
// $laoying_f = fopen(__DIR__ . '/data/laoying.csv', 'w');
// //写入老鹰文件
// laoying_getList($laoying, $laoying_f, $all, $laoying_data);
// fclose($laoying_f);
// }

sleep(5);
auto_format_list();

//强子服务器解析规则
function qiangzi_getList($data, &$file, &$all, $exit)
{
    global $dnx_exit, $dnx_has_exit,$sp_qz_list;
    $online = ['故障', '正常', '紧张','繁忙'];
    $status = ['正常', '拥挤', '超载'];

    $key = '';
    $list1 = [];
    $province_record = [];

    foreach ($data as $info) {
        $record = [];
        $record['name'] = '强子';
        if ($info['areaname'] == '静态线路') {
            continue;
        }
        //如果存在 不为空 则
        $city_name = explode('-',$info['name']);
        if (strpos($city_name[1], '混播') !== false) {

            //如果存在 不为空 则
            if (!in_array( $city_name[1], $province_record)) {
                $record['city'] =  $city_name[1];
                $province_record[] =  $city_name[1];
                $key = $record['city'];
                $list1[$key][] = $record;
            }
        } else {
             //如果存在 不为空 则
            if (!in_array( $city_name[0], $province_record)) {
                $record['city'] =  $city_name[0];
                $province_record[] =  $city_name[0];
                $key = $record['city'];
                $list1[$key][] = $record;
            }
            $key = $city_name[0];
        }
        
       

        $record['city'] = $city_name[1];

        $record['supply'] = isset($city_name[2]) ? $city_name[2] : '';

        $daikuan = $info['bandwidth'];
        $record['ip'] = $info['name2'];
        $record['daikuan'] = $daikuan;
        $record['onlineuser'] = '';
        $record['maxuser'] = '';
        $record['online'] = $online[$info['status']];

        $record['status'] = $sp_qz_list[$record['city']];
        if(!empty($info['host2'])){
            $nas_list = explode(',',$info['host2']);

            foreach ($nas_list as $nas) {
                $record['nasname'] = trim($nas);
                if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) {
                    fputcsv($dnx_exit, ['强子', explode('.',$record['nasname'])[0], $record['nasname'], date('Y-m-d H:i:s')]);
                }

                $list1[$key][] = $record;
            }
        } 
        $record['nasname'] = trim($info['host']);
        if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) {
            fputcsv($dnx_exit, ['强子', explode('.',$record['nasname'])[0], $record['nasname'], date('Y-m-d H:i:s')]);
        }

        $list1[$key][] = $record;




        
    }
    foreach ($list1 as $val) {
        foreach ($val as $net_data) {

            fputcsv($file, $net_data);
            fputcsv($all, $net_data);
        }
    }

}


//强子静态服务器解析规则
function qiangzijt_getList($data, &$file, &$all, $exit)
{
    global $dnx_exit, $dnx_has_exit,$sp_qz_list;
    $online = ['故障', '正常', '紧张','繁忙'];
    $status = ['正常', '拥挤', '超载'];

    $key = '';
    $list1 = [];
    $province_record = [];

    foreach ($data as $info) {
        $record = [];
        $record['name'] = '强子静态';
        if ($info['areaname'] != '静态线路') {
            continue;
        }
        //如果存在 不为空 则
        $city_name = explode('-',$info['name']);
        if (strpos($city_name[1], '混播') !== false) {

            //如果存在 不为空 则
            if (!in_array( $city_name[1], $province_record)) {
                $record['city'] =  $city_name[1];
                $province_record[] =  $city_name[1];
                $key = $record['city'];
                $list1[$key][] = $record;
            }
        } else {
             //如果存在 不为空 则
            if (!in_array( $city_name[1], $province_record)) {
                $record['city'] =  $city_name[1];
                $province_record[] =  $city_name[1];
                $key = $record['city'];
                $list1[$key][] = $record;
            }
            $key = $city_name[1];
        }
        
       

        $record['city'] = $city_name[2];

        $record['supply'] = isset($city_name[2]) ? $city_name[2] : '';

        $daikuan = $info['bandwidth'];
        $record['ip'] = $info['name2'];
        $record['daikuan'] = $daikuan;
        $record['onlineuser'] = '';
        $record['maxuser'] = '';
        $record['online'] = $online[$info['status']];

        $record['status'] = $sp_qz_list[$record['city']];
        if(!empty($info['host2'])){
            $nas_list = explode(',',$info['host2']);

            foreach ($nas_list as $nas) {
                $record['nasname'] = trim($nas);
                if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) {
                    fputcsv($dnx_exit, ['强子', explode('.',$record['nasname'])[0], $record['nasname'], date('Y-m-d H:i:s')]);
                }

                $list1[$key][] = $record;
            }
        } 
        $record['nasname'] = trim($info['host']);
        if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) {
            fputcsv($dnx_exit, ['强子', explode('.',$record['nasname'])[0], $record['nasname'], date('Y-m-d H:i:s')]);
        }

        $list1[$key][] = $record;




        
    }
    foreach ($list1 as $val) {
        foreach ($val as $net_data) {

            fputcsv($file, $net_data);
            fputcsv($all, $net_data);
        }
    }

}


//火狐服务器解析规则
function huohu_getList($data, &$file, &$all, $exit)
{
    
    global $dnx_exit, $dnx_has_exit;
    $online = ['故障', '正常','故障'];
    $list = [];
    
    $province_record = [];
    foreach ($data as $info){
        $record = [];
        $record['name'] = '火狐静态';
        //如果存在 不为空 则
        if (!in_array( $info['province'], $province_record)) {
            $record['city'] =  $info['province'];
            $province_record[] =  $info['province'];
            $key = $record['city'];
            $list[$key][] = $record;
        }
        //匹配所有的城市
        //每一个城市再解析获取城市和剩余数量

        $record['city'] = $info['city'];
        $record['supply'] = $info['displayname'];
        $record['ip'] = '';
        $record['daikuan'] = '';
        $record['onlineuser'] = '';
        $record['maxuser'] = '';
        $record['online'] = $online[$info['status']];
        $record['status'] = '';
        $record['nasname'] = $info['ip'];

        $list[$key][] = $record;
        
        // if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) {
        //     fputcsv($dnx_exit, ['火狐', explode('.',$record['nasname'])[0], $record['nasname'], date('Y-m-d H:i:s')]);
        // }
    }
    $temp = [];
    foreach ($list as $key=>$val) {
        if ($key == '全国') {
            $temp = $val;
            unset($list['全国']);
        }
    }
    array_unshift($list,$temp);


    
    foreach ($list as $val) {
        foreach ($val as $net_data) {

            fputcsv($file, $net_data);
            fputcsv($all, $net_data);
        }
    }
}


//火狐服务器解析规则
function yunniu_getList($data, &$file, &$all, $exit)
{
    
    global $dnx_exit, $dnx_has_exit;
    $online = ['故障', '正常','故障'];
    $list = [];
    
    $province_record = [];
    foreach ($data as $info){
        $record = [];
        $record['name'] = '云牛';
        //如果存在 不为空 则
        if (!in_array( $info['province'], $province_record)) {
            $record['city'] =  $info['province'];
            $province_record[] =  $info['province'];
            $key = $record['city'];
            $list[$key][] = $record;
        }
        //匹配所有的城市
        //每一个城市再解析获取城市和剩余数量

        $record['city'] = $info['city'];
        $record['supply'] = $info['displayname'];
        $record['ip'] = '';
        $record['daikuan'] = '';
        $record['onlineuser'] = '';
        $record['maxuser'] = '';
        $record['online'] = $online[$info['status']];
        $record['status'] = '';
        $record['nasname'] = $info['ip'];

        $list[$key][] = $record;
        
        // if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) {
        //     fputcsv($dnx_exit, ['火狐', explode('.',$record['nasname'])[0], $record['nasname'], date('Y-m-d H:i:s')]);
        // }
    }
    $temp = [];
    foreach ($list as $key=>$val) {
        if ($key == '全国') {
            $temp = $val;
            unset($list['全国']);
        }
    }
    array_unshift($list,$temp);


    
    foreach ($list as $val) {
        foreach ($val as $net_data) {

            fputcsv($file, $net_data);
            fputcsv($all, $net_data);
        }
    }
}

//星星服务器解析
function xingxing_getList($data, &$file, &$all, $exit)
{
    global $dnx_exit, $dnx_has_exit;
    $online = ['故障', '正常', '正常'];
    $province_record = [];
    $key = '';
    $list1 = [];
    //省会
    $province = ['黑龙', '内蒙'];
    $citys = ['北京', '上海', '天津', '重庆'];
    foreach ($data as $info) {

        $record = [];
        $record['name'] = '星星';
        $province_detail = mb_substr($info['name'], 0, 2);
        if (in_array($province_detail, $province)) {
            $province_detail = mb_substr($info['name'], 0, 3);
            $info['name'] = mb_substr($info['name'], 3);
        } elseif (!in_array($province_detail, $citys)) {
            $info['name'] = mb_substr($info['name'], 2);
        }
        if (!in_array($province_detail, $province_record)) {
            $record['city'] = $province_detail;
            $province_record[] = $province_detail;
            $key = $province_detail;
            $list1[$key][] = $record;
        }
        $city_ex = explode('电信', $info['name']);
        if (strpos($info['name'], '电信') !== false) {
            $record['city'] = $city_ex[0] . ($city_ex[1] ?? '');
            $record['supply'] = '电信';
        } elseif (strpos($info['name'], '联通') !== false) {
            $record['city'] = $city_ex[0] . ($city_ex[1] ?? '');
            $record['supply'] = '联通';
        } elseif (strpos($info['name'], '移动') !== false) {
            $record['city'] = $city_ex[0] . ($city_ex[1] ?? '');
            $record['supply'] = '移动';
        } else {
            $record['city'] = $info['name'];
            $record['supply'] = '电信/联通';
        }

        $record['ip'] = strpos($info['name2'], '-') ? explode('-', $info['name2'])[1] : $info['name2'];
        $record['daikuan'] = $info['bandwidth'];
        $record['onlineuser'] = '';
        $record['maxuser'] = '';
        $record['online'] = ($info['status'] == 0) ? '故障' : '正常';
        $record['status'] = ($info['status'] == 1) ? '正常' : '紧张';;
        $record['nasname'] = $info['host'];
        if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) {
            fputcsv($dnx_exit, ['星星', explode('.',$record['nasname'])[0], $record['nasname'], date('Y-m-d H:i:s')]);
        }
        $key = $province_detail;
        $list1[$key][] = $record;
    }
    foreach ($list1 as $val) {
        foreach ($val as $net_data) {

            fputcsv($file, $net_data);
            fputcsv($all, $net_data);
        }
    }

}

//极客服务器解析
function jike_getList($data, &$file, &$all, $exit, $is_jike = true)
{
    global $dnx_exit, $dnx_has_exit;
    $status = ['yes' => '正常', 'no' => '故障'];
    $key = '';
    $list1 = [];

    $province_record = [];
    foreach ($data as $info) {
        $record = [];
        if($is_jike){
            $record['name'] = '极客';
        } else {
            $record['name'] = '西瓜';
        }
        //如果存在 不为空 则
        if (!in_array($info['province'], $province_record)) {
            $record['city'] = $info['province'];
            $province_record[] = $info['province'];
            $key = $record['city'];
            $list1[$key][] = $record;
        }
        if (empty($info['city'])) {
            $record['city'] = '全国混播';
        } else {
            $record['city'] = $info['city'];
        }
        $record['supply'] = $info['isp'];
        $record['ip'] = '';
        $record['daikuan'] = '';
        $record['onlineuser'] = '';
        $record['maxuser'] = '';
        $record['online'] = $status[$info['status']];
        $record['status'] = '';
        $record['nasname'] = $info['domain'];
        if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) {
            fputcsv($dnx_exit, [$record['name'], explode('.',$record['nasname'])[0], $record['nasname'], date('Y-m-d H:i:s')]);
        }
        $list1[$key][] = $record;
    }
    foreach ($list1 as $val) {
        $temp = $val[0];
        unset($val[0]);
        $sort = array_column($val,'city');
        array_multisort($sort,SORT_ASC,$val);
        array_unshift($val,$temp);
        foreach ($val as $net_data) {

            fputcsv($file, $net_data);
            fputcsv($all, $net_data);
        }
    }

}

//天天服务器解析规则
function tiantian_getList($data, &$file, &$all, $exit, $product_name)
{
    global $dnx_exit, $dnx_has_exit;
    $status = ['故障', '正常'];
    $key = '';
    $list1 = [];

    foreach ($data as $info) {

        $record = [];
        $record['name'] = $product_name;
        $record['city'] = $info['name'];
        $key = $record['city'];
        $list1[$key][] = $record;
        foreach ($info['areas'] as $v) {

            if (strpos($v['name'], '电信') !== false) {
                $record['city'] = $v['name'];
                $record['supply'] = '电信';
            } elseif (strpos($v['name'], '联通') !== false) {
                $record['city'] = $v['name'];
                $record['supply'] = '联通';
            } elseif (strpos($v['name'], '移动') !== false) {
                $record['city'] = $v['name'];
                $record['supply'] = '移动';
            } else {
                $record['city'] = $v['name'];
                $record['supply'] = '电信/联通';
            }
            $record['ip'] = '';
            $record['daikuan'] = '';
            $record['onlineuser'] = '';
            $record['maxuser'] = '';
            $record['online'] = empty($v['status']) ? '故障' : $status[$v['status']];
            $record['status'] = '';
            $record['nasname'] = $v['address'];
            if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) {
                fputcsv($dnx_exit, [$product_name, explode('.',$record['nasname'])[0], $record['nasname'], date('Y-m-d H:i:s')]);
            }
            $list1[$key][] = $record;
        }
    }
    foreach ($list1 as $val) {
        foreach ($val as $net_data) {

            fputcsv($file, $net_data);
            fputcsv($all, $net_data);
        }
    }

}

// //天天服务器解析规则
// function liebao_getList($data, &$file, &$all, $exit, $product_name)
// {
//     global $dnx_exit, $dnx_has_exit;
//     $status = ['故障', '正常'];
//     $key = '';
//     $list1 = [];
//     foreach ($data as $info) {
//         $record = [];
//         $record['name'] = $product_name;
//         $record['city'] = $info['name'];
//         $key = $record['city'];
//         $list1[$key][] = $record;
//         foreach ($info['areas'] as $v) {

//             if (strpos($v['name'], '电信') !== false) {
//                 $record['city'] = $v['name'];
//                 $record['supply'] = '电信';
//             } elseif (strpos($v['name'], '联通') !== false) {
//                 $record['city'] = $v['name'];
//                 $record['supply'] = '联通';
//             } elseif (strpos($v['name'], '移动') !== false) {
//                 $record['city'] = $v['name'];
//                 $record['supply'] = '移动';
//             } else {
//                 $record['city'] = $v['name'];
//                 $record['supply'] = '电信/联通';
//             }
//             $record['ip'] = '';
//             $record['daikuan'] = '';
//             $record['onlineuser'] = '';
//             $record['maxuser'] = '';
//             $record['online'] = empty($v['status']) ? '故障' : $status[$v['status']];
//             $record['status'] = '';
//             $record['nasname'] = $v['address'];
//             if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) {
//                 fputcsv($dnx_exit, [$product_name, explode('.',$record['nasname'])[0], $record['nasname'], date('Y-m-d H:i:s')]);
//             }
//             $list1[$key][] = $record;
//         }
//     }
//     foreach ($list1 as $val) {
//         foreach ($val as $net_data) {

//             fputcsv($file, $net_data);
//             fputcsv($all, $net_data);
//         }
//     }

// }


//蘑菇服务器解析规则
function mogu_getList($data, &$file, &$all )
{
    $key = '';
    $list1 = [];
    // print_r($data);
    
    $province_record = [];

    foreach ($data as $info) {

        $record = [];

        $record['name'] = '蘑菇';
        //如果存在 不为空 则
        $city_name = explode('-',$info['city']);
        if(empty($info['city'])) {
            continue;
        }
             //如果存在 不为空 则
            if (!in_array( $city_name[0], $province_record)) {
                $record['city'] =  $city_name[0];
                $province_record[] =  $city_name[0];
                $key = $record['city'];
                $list1[$key][] = $record;
            }
            $key = $city_name[0];


        $record['city'] = $city_name[1];
        $record['supply'] = $info['yunying'];
        
        $record['ip'] = $info['ipCount'];
        $record['daikuan'] = $info['daikuan'];
        $record['onlineuser'] = '';
        $record['maxuser'] = '';
        $record['online'] = $info['status'];
        $record['status'] = $info['onlinestatus'];
        $record['nasname'] = $info['address'];
        $list1[$key][] = $record;
    }
    foreach ($list1 as $val) {
        foreach ($val as $net_data) {

            fputcsv($file, $net_data);
            fputcsv($all, $net_data);
        }
    }

}

//极狐服务器解析规则
function jihu_getList($data, &$file, &$all )
{
    $key = '';
    $list1 = [];
    // print_r($data);
    
    $province_record = [];

    foreach ($data as $info) {

        $record = [];

        $record['name'] = '极狐';
        //如果存在 不为空 则
        $city_name = explode('-',$info['city']);
        if(empty($info['city'])) {
            continue;
        }
             //如果存在 不为空 则
            if (!in_array( $city_name[0], $province_record)) {
                $record['city'] =  $city_name[0];
                $province_record[] =  $city_name[0];
                $key = $record['city'];
                $list1[$key][] = $record;
            }
            $key = $city_name[0];


        $record['city'] = $city_name[1];
        $record['supply'] = $info['yunying'];
        
        $record['ip'] = $info['ipCount'];
        $record['daikuan'] = $info['daikuan'];
        $record['onlineuser'] = '';
        $record['maxuser'] = '';
        $record['online'] = $info['status'];
        $record['status'] = $info['onlinestatus'];
        $record['nasname'] = $info['address'];
        $list1[$key][] = $record;
    }
    foreach ($list1 as $val) {
        foreach ($val as $net_data) {

            fputcsv($file, $net_data);
            fputcsv($all, $net_data);
        }
    }

}

//极光服务器解析规则
function jiguang_getList($data, &$file, &$all )
{
    $key = '';
    $list1 = [];
    // print_r($data);
    
    $province_record = [];

    foreach ($data as $info) {

        $record = [];

        $record['name'] = '极光';
        //如果存在 不为空 则
        $city_name = explode('-',$info['city']);
        if(empty($info['city'])) {
            continue;
        }
             //如果存在 不为空 则
            if (!in_array( $city_name[0], $province_record)) {
                $record['city'] =  $city_name[0];
                $province_record[] =  $city_name[0];
                $key = $record['city'];
                $list1[$key][] = $record;
            }
            $key = $city_name[0];


        $record['city'] = $city_name[1];
        $record['supply'] = $info['yunying'];
        
        $record['ip'] = $info['ipCount'];
        $record['daikuan'] = $info['daikuan'];
        $record['onlineuser'] = '';
        $record['maxuser'] = '';
        $record['online'] = $info['status'];
        $record['status'] = $info['onlinestatus'];
        $record['nasname'] = $info['address'];
        $list1[$key][] = $record;
    }
    foreach ($list1 as $val) {
        foreach ($val as $net_data) {

            fputcsv($file, $net_data);
            fputcsv($all, $net_data);
        }
    }

}


//极光服务器解析规则
function liebao_getList($data, &$file, &$all )
{
    $key = '';
    $list1 = [];
    // print_r($data);
    
    $province_record = [];

    foreach ($data as $info) {

        $record = [];

        $record['name'] = '猎豹';
        //如果存在 不为空 则
        $city_name = explode('-',$info['city']);
        if(empty($info['city'])) {
            continue;
        }
             //如果存在 不为空 则
            if (!in_array( $city_name[0], $province_record)) {
                $record['city'] =  $city_name[0];
                $province_record[] =  $city_name[0];
                $key = $record['city'];
                $list1[$key][] = $record;
            }
            $key = $city_name[0];


        $record['city'] = $city_name[1];
        $record['supply'] = $info['yunying'];
        
        $record['ip'] = $info['ipCount'];
        $record['daikuan'] = $info['daikuan'];
        $record['onlineuser'] = '';
        $record['maxuser'] = '';
        $record['online'] = $info['status'];
        $record['status'] = $info['onlinestatus'];
        $record['nasname'] = $info['address'];
        $list1[$key][] = $record;
    }
    foreach ($list1 as $val) {
        foreach ($val as $net_data) {

            fputcsv($file, $net_data);
            fputcsv($all, $net_data);
        }
    }

}


//麒麟服务器解析规则
function qilin_getList($data, &$file, &$all, $exit )
{
    global $dnx_exit, $dnx_has_exit;
    $key = '';
    $list1 = [];

    $records['name'] = '麒麟';

    $records['city'] =  "全国";
    
    $key2 = $records['city'];
    $list1[$key][] = $records;

    $records['city'] = '超级通用混拨';
    $records['supply'] = '';
    $records['ip'] = '';
    $records['daikuan'] = '';
    $records['onlineuser'] = '';
    $records['maxuser'] = '';
    $records['online'] = '正常';
    $records['status'] = '';
    $records['nasname'] = "super.qlip.cc";
    $list1[$key2][] = $records;
    
    $records['city'] = '通用混拨';
    $records['supply'] = '';
    $records['ip'] = '';
    $records['daikuan'] = '';
    $records['onlineuser'] = '';
    $records['maxuser'] = '';
    $records['online'] = '正常';
    $records['status'] = '';
    $records['nasname'] = "hb.qlip.cc";
    $list1[$key2][] = $records;
    
    $records['city'] = '通用混拨';
    $records['supply'] = '';
    $records['ip'] = '';
    $records['daikuan'] = '';
    $records['onlineuser'] = '';
    $records['maxuser'] = '';
    $records['online'] = '正常';
    $records['status'] = '';
    $records['nasname'] = "hb1.qlip.cc";
    $list1[$key2][] = $records;
    
    $records['city'] = '通用混拨';
    $records['supply'] = '';
    $records['ip'] = '';
    $records['daikuan'] = '';
    $records['onlineuser'] = '';
    $records['maxuser'] = '';
    $records['online'] = '正常';
    $records['status'] = '';
    $records['nasname'] = "hb2.qlip.cc";
    $list1[$key2][] = $records;
    $records['city'] = '通用混拨';
    $records['supply'] = '';
    $records['ip'] = '';
    $records['daikuan'] = '';
    $records['onlineuser'] = '';
    $records['maxuser'] = '';
    $records['online'] = '正常';
    $records['status'] = '';
    $records['nasname'] = "hb3.qlip.cc";
    $list1[$key2][] = $records;
    $records['city'] = '通用混拨';
    $records['supply'] = '';
    $records['ip'] = '';
    $records['daikuan'] = '';
    $records['onlineuser'] = '';
    $records['maxuser'] = '';
    $records['online'] = '正常';
    $records['status'] = '';
    $records['nasname'] = "hb4.qlip.cc";
    $list1[$key2][] = $records;
    
    $province_record = [];

        foreach ($data as $val) {
            $val = (array)$val;
            $record = [];
            $record['name'] = '麒麟';

            $record['city'] =  $val['info']->province_name;
            $province_record[] =  $val['info']->province_name;
            
            $key = $record['city'];
            $list1[$key][] = $record;

            $record['city'] = $val['info']->province_name.'混拨';
            $record['supply'] = '';
            $record['ip'] = '';
            $record['daikuan'] = '';
            $record['onlineuser'] = '';
            $record['maxuser'] = '';
            $record['online'] = '正常';
            $record['status'] = '';
            $record['nasname'] = $val['info']->province_domain;
            $list1[$key][] = $record;

            foreach($val['line'] as $city_info) {
                $city_info = (array)$city_info;

                $record['city'] = $city_info['city_name'];
                $record['supply'] = $city_info['isp'];
                
                $record['ip'] = '';
                $record['daikuan'] = '';
                $record['onlineuser'] = '';
                $record['maxuser'] = '';
                $record['online'] = $city_info['status'] ? '正常' : '故障';
                $record['status'] = '';
                $record['nasname'] = $city_info['domain'];
                $list1[$key][] = $record;
                
                if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) {
                    fputcsv($dnx_exit, [$record['name'], explode('.',$record['nasname'])[0], $record['nasname'], date('Y-m-d H:i:s')]);
                }

            }


        }
        
        
    foreach ($list1 as $val) {
        foreach ($val as $net_data) {

            fputcsv($file, $net_data);
            fputcsv($all, $net_data);
        }
    }

}


//麒麟服务器解析规则
function shuidi_getList($data, &$file, &$all, $exit )
{
    global $dnx_exit, $dnx_has_exit;
    $key = '';
    $list1 = [];
    $province_record = [];
    $isps = ['移动','电信','联通'];

        foreach ($data as $val) {
            $val = (array)$val;
            $record = [];
            $record['name'] = '水滴静态';

            $record['city'] =  $val['info']->province_name;
            $province_record[] =  $val['info']->province_name;
            
            $key = $record['city'];
            $list1[$key][] = $record;

            foreach($val['lines'] as $city_info) {
                $city_info = (array)$city_info;
                $jingtai_gutai = '';
                if ($city_info['class'] == 2) {
                    $jingtai_gutai = '静态-';
                }
                if ($city_info['class'] == 7) {
                    $jingtai_gutai = '固态-';
                }
                $jingtai_gutai .= $isps[$city_info['isp_class']];

                $record['city'] = $city_info['name'];
                $record['supply'] = $jingtai_gutai;
                
                $record['ip'] = '';
                $record['daikuan'] = '';
                $record['onlineuser'] = '';
                $record['maxuser'] = '';
                $record['online'] = $city_info['online'] ? '正常' : '故障';
                $record['status'] = $city_info['cpu_load']."%";
                $record['nasname'] = "开通后账号中心查看";
                $list1[$key][] = $record;
                
                if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) {
                    fputcsv($dnx_exit, [$record['name'], explode('.',$record['nasname'])[0], $record['nasname'], date('Y-m-d H:i:s')]);
                }

            }


        }
        
        
    foreach ($list1 as $val) {
        foreach ($val as $net_data) {

            fputcsv($file, $net_data);
            fputcsv($all, $net_data);
        }
    }

}

function laoying_getList($list, &$file, &$all, $exit)
{
    global $dnx_exit, $dnx_has_exit;
    $key = '';
    
    $online = ['故障', '正常'];
    $province_record = [];
    foreach ($list as $k => $info) {
        
        //生成数据
        $record = [];
        $record['name'] = '老鹰';

        
        //运营商
        if (strpos($info['server_address'], '电信') !== false) {
            $supply = '电信';
        } elseif (strpos($info['server_address'], '联通') !== false) {
            $supply = '联通';
        } elseif (strpos($info['server_address'], '移动') !== false) {
            $supply = '移动';
        } else {
            $supply = '电信/联通';
        }

        //如果存在 不为空 则
        if (!in_array( $info['category_name'], $province_record)) {
            $record['city'] =  $info['category_name'];
            $province_record[] =  $info['category_name'];
            $key = $record['city'];
            $list1[$key][] = $record;
        }
        $key = $info['category_name'];


        $record['city'] =$info['server_address'];
        $record['supply'] = $supply;
        $record['ip'] = '';
        $record['daikuan'] = '';
        $record['onlineuser'] = '';
        $record['maxuser'] = '';
        $record['online'] = $online[$info['isonline']];
        $record['status'] = '';
        if (strpos($info['remote_domain'], ' ') !== false) {
            $nas_list = explode(' ',$info['remote_domain']);
            $record['nasname'] = $nas_list[0];
            if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) {
                fputcsv($dnx_exit, ['老鹰', explode('.',$record['nasname'])[0], $record['nasname'], date('Y-m-d H:i:s')]);
            }
            $list1[$key][] = $record;
            $record['nasname'] = empty($nas_list[1])?$nas_list[2]:$nas_list[1];
            if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) {
                fputcsv($dnx_exit, ['老鹰', explode('.',$record['nasname'])[0], $record['nasname'], date('Y-m-d H:i:s')]);
            }
            $list1[$key][] = $record;
        } else {
            $record['nasname'] = $info['remote_domain'];
            if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) {
                fputcsv($dnx_exit, ['老鹰', explode('.',$record['nasname'])[0], $record['nasname'], date('Y-m-d H:i:s')]);
            }
            $list1[$key][] = $record;
        }

    }
    foreach ($list1 as $val) {
        $temp = $val[0];
        unset($val[0]);
        $sort = array_column($val,'city');
        array_multisort($sort,SORT_ASC,$val);
        array_unshift($val,$temp);
        foreach ($val as $net_data) {

            fputcsv($file, $net_data);
            fputcsv($all, $net_data);
        }
    }
}

//共享
function gongxiang_getList($html, &$file, &$all, $exit, $pro = '共享')
{
    global $dnx_exit, $dnx_has_exit;
    //省会
    $province = ['黑龙', '内蒙'];
    $province_record = [];
    $key = '';
    $list1 = [];
    preg_match_all("/<tr(.*?)<\/tr>/is", $html, $result);
    foreach ($result[0] as $k => $info) {
        $record = [];
        $record['name'] = $pro;
        $records['name'] = $pro;
        if ($k == 0) {
            continue;
        } else {
            preg_match_all("/<td>(.*?)<\/td>/is", $info, $result);
            $info = $result[0];
            foreach ($info as $i => $v) {
                $info[$i] = ltrim($info[$i], '<td>');
                $info[$i] = rtrim($info[$i], '</td>');
            }
            $nasname = $info[1];

            $data[1] = $info[2];
            if (strpos($data[1], '电信') !== false) {
                $supply = '电信';
                $data[1] = mb_substr($data[1], 0, mb_strlen($data[1]) - 2);
            } elseif (strpos($data[1], '联通') !== false) {
                $supply = '联通';
                $data[1] = mb_substr($data[1], 0, mb_strlen($data[1]) - 2);
            } elseif (strpos($data[1], '移动') !== false) {
                $supply = '移动';
                $data[1] = mb_substr($data[1], 0, mb_strlen($data[1]) - 2);
            } else {
                $supply = '电信/联通';
            }
            if (mb_strlen($data[1]) <= 3) {
                if (!in_array($data[1], $province_record)) {
                    $record['city'] = $data[1];
                    $record['supply'] = $supply;
                    $record['ip'] = '';
                    $record['daikuan'] = '';
                    $record['onlineuser'] = '';
                    $record['maxuser'] = '';
                    $record['online'] = strpos($info[4], '在线') ? '正常' : '故障';
                    $record['status'] = '';
                    $record['nasname'] = $nasname;
                    $records['city'] = $data[1];
                    $province_record[] = $data[1];
                    if (in_array($record['city'], ['曾', '龙'])) {
                        continue;
                    }
                    $key = $record['city'];
                    $list1[$key][] = $records;
                    $list1[$key][] = $record;
                } else {
                    $record['city'] = $data[1];
                    $record['supply'] = $supply;
                    $record['ip'] = '';
                    $record['daikuan'] = '';
                    $record['onlineuser'] = '';
                    $record['maxuser'] = '';
                    $record['online'] = strpos($info[4], '在线') ? '正常' : '故障';
                    $record['status'] = '';
                    $record['nasname'] = $nasname;
                    if (in_array($record['city'], ['曾', '龙'])) {
                        continue;
                    }
                    $list1[$key][] = $record;
                }
            } else {
                $province_detail = mb_substr($data['1'], 0, 2);
                if (in_array($province_detail, $province)) {
                    $province_detail = mb_substr($data['1'], 0, 3);
                    $key = $province_detail;
                    if (in_array($province_detail, $province_record)) {
                        $record['city'] = mb_substr($data['1'], 3);
                        $record['supply'] = $supply;
                        $record['ip'] = '';
                        $record['daikuan'] = '';
                        $record['onlineuser'] = '';
                        $record['maxuser'] = '';
                        $record['online'] = strpos($info[4], '在线') ? '正常' : '故障';
                        $record['status'] = '';
                        $record['nasname'] = $nasname;
                        if (in_array($record['city'], ['曾', '龙'])) {
                            continue;
                        }
                        $list1[$key][] = $record;
                    } else {
                        $record['city'] = mb_substr($data['1'], 3);
                        $record['supply'] = $supply;
                        $record['ip'] = '';
                        $record['daikuan'] = '';
                        $record['onlineuser'] = '';
                        $record['maxuser'] = '';
                        $record['online'] = strpos($info[4], '在线') ? '正常' : '故障';
                        $record['status'] = '';
                        $record['nasname'] = $nasname;
                        $records['city'] = $province_detail;
                        $province_record[] = $province_detail;
                        if (in_array($record['city'], ['曾', '龙'])) {
                            continue;
                        }
                        $list1[$key][] = $records;
                        $list1[$key][] = $record;
                    }
                } else {
                    $province_detail = mb_substr($data['1'], 0, 2);
                    $key = $province_detail;
                    if (in_array($province_detail, $province_record)) {
                        $record['city'] = mb_substr($data['1'], 2);
                        $record['supply'] = $supply;
                        $record['ip'] = '';
                        $record['daikuan'] = '';
                        $record['onlineuser'] = '';
                        $record['maxuser'] = '';
                        $record['online'] = strpos($info[4], '在线') ? '正常' : '故障';
                        $record['status'] = '';
                        $record['nasname'] = $nasname;
                        if (in_array($record['city'], ['曾', '龙'])) {
                            continue;
                        }
                        $list1[$key][] = $record;
                    } else {
                        $record['city'] = mb_substr($data['1'], 2);
                        $record['supply'] = $supply;
                        $record['ip'] = '';
                        $record['daikuan'] = '';
                        $record['onlineuser'] = '';
                        $record['maxuser'] = '';
                        $record['online'] = strpos($info[4], '在线') ? '正常' : '故障';
                        $record['status'] = '';
                        $record['nasname'] = $nasname;
                        $records['city'] = $province_detail;
                        $province_record[] = $province_detail;
                        if (in_array($record['city'], ['曾', '龙'])) {
                            continue;
                        }
                        $list1[$key][] = $records;
                        $list1[$key][] = $record;
                    }
                }
            }
        }
    }
    foreach ($list1 as $val) {
        foreach ($val as $net_data) {

            $net_data['city'] = str_replace('电信', '', $net_data['city']);
            $net_data['city'] = str_replace('联通', '', $net_data['city']);

            fputcsv($file, $net_data);
            fputcsv($all, $net_data);
        }
    }
}

function xunlian_getList($data, &$file, &$all, $exit)
{
    global $dnx_exit, $dnx_has_exit,$sp_xl_list;
    $online = ['故障', '正常', '紧张','繁忙'];
    $status = ['正常', '拥挤', '超载'];

    $key = '';
    $list1 = [];
    $province_record = [];

    foreach ($data as $info) {
        $record = [];
        $record['name'] = '迅连';
        //如果存在 不为空 则
        $city_name = explode('-',$info['name']);
        if (strpos($city_name[1], '混播') !== false) {

            //如果存在 不为空 则
            if (!in_array( $city_name[1], $province_record)) {
                $record['city'] =  $city_name[1];
                $province_record[] =  $city_name[1];
                $key = $record['city'];
                $list1[$key][] = $record;
            }
        } else {
             //如果存在 不为空 则
            if (!in_array( $city_name[0], $province_record)) {
                $record['city'] =  $city_name[0];
                $province_record[] =  $city_name[0];
                $key = $record['city'];
                $list1[$key][] = $record;
            }
            $key = $city_name[0];
        }
        
       

        $record['city'] = $city_name[1];

        $record['supply'] = isset($city_name[2]) ? trim($city_name[2]) : '';

        $daikuan = $info['bandwidth'];
        $record['ip'] = $info['name2'];
        $record['daikuan'] = $daikuan;
        $record['onlineuser'] = '';
        $record['maxuser'] = '';
        $record['online'] = $online[$info['status']];;

        $record['status'] = $sp_xl_list[$record['city']];
        if(!empty($info['host2'])){
            $nas_list = explode(',',$info['host2']);

            foreach ($nas_list as $nas) {
                $record['nasname'] = trim($nas);
                if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) {
                    fputcsv($dnx_exit, ['迅连', explode('.',$record['nasname'])[0], $record['nasname'], date('Y-m-d H:i:s')]);
                }

                $list1[$key][] = $record;
            }
        } 
        $record['nasname'] = trim($info['host']);
        if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) {
            fputcsv($dnx_exit, ['迅联', explode('.',$record['nasname'])[0], $record['nasname'], date('Y-m-d H:i:s')]);
        }

        $list1[$key][] = $record;




        
    }
    foreach ($list1 as $val) {
        foreach ($val as $net_data) {

            fputcsv($file, $net_data);
            fputcsv($all, $net_data);
        }
    }
}


function xianfeng_getList($data, &$file, &$all, $exit)
{
    global $dnx_exit, $dnx_has_exit,$sp_xl_list;

    $key = '';
    $list1 = [];
    $province_record = [];

    foreach ($data as $info) {
        $record = [];
        $record['name'] = '先锋';
        //如果存在 不为空 则
        $city_name = explode('-',$info['name']);
        if (strpos($city_name[1], '混播') !== false) {

            //如果存在 不为空 则
            if (!in_array( $city_name[1], $province_record)) {
                $record['city'] =  $city_name[1];
                $province_record[] =  $city_name[1];
                $key = $record['city'];
                $list1[$key][] = $record;
            }
        } else {
             //如果存在 不为空 则
            if (!in_array( $city_name[0], $province_record)) {
                $record['city'] =  $city_name[0];
                $province_record[] =  $city_name[0];
                $key = $record['city'];
                $list1[$key][] = $record;
            }
            $key = $city_name[0];
        }
        
       

        $record['city'] = $city_name[1];

        $record['supply'] = isset($city_name[2]) ? trim($city_name[2]) : '';

        $daikuan = '';
        $record['ip'] = '';
        $record['daikuan'] = $daikuan;
        $record['onlineuser'] = '';
        $record['maxuser'] = '';
        $record['online'] = '正常';

        $record['status'] = '';
        $record['nasname'] = trim($info['server']);
        
        if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) {
            fputcsv($dnx_exit, ['先锋', explode('.',$record['nasname'])[0], $record['nasname'], date('Y-m-d H:i:s')]);
        }
        $list1[$key][] = $record;




        
    }
    foreach ($list1 as $val) {
        foreach ($val as $net_data) {

            fputcsv($file, $net_data);
            fputcsv($all, $net_data);
        }
    }
}
function wuxian_getList($html, &$file, &$all, $exit)
{
    // global $dnx_exit, $dnx_has_exit;
    // //省会
    // $province = ['黑龙', '内蒙'];
    // $province_record = [];
    // $key = '';
    // $list1 = [];
    // $citys = ['北京', '上海', '天津', '重庆'];
    // preg_match("/<div>&nbsp;<\/div>(.*?)<\/div><\/div>/is", $html, $result);
    // $result = str_replace('<div>&nbsp;</div>', '', $result[0]);
    // preg_match_all("/<div>(.*?)<\/div>/is", $result, $result);
    // foreach ($result[0] as $k => $info) {
    //     $record = [];
    //     $record['name'] = '无限';
    //     $info = ltrim($info, '<div>');
    //     $info = rtrim($info, '</div>');
    //     if (strpos($info, 'span') !== false) {
    //         $data = explode('<span class="Apple-tab-span" style="white-space:pre">		</span>', $info);
    //     } else {
    //         $data = explode(' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;', $info);
    //     }
    //     $data[1] = trim($data[1]);
    //     $province_detail = mb_substr(trim($data[1]), 0, 2);
    //     if (in_array($province_detail, $province)) {
    //         $province_detail = mb_substr($data[1], 0, 3);
    //         $data[1] = mb_substr($data[1], 3);
    //     } elseif (!in_array($province_detail, $citys)) {
    //         $data[1] = mb_substr($data[1], 2);
    //     }
    //     if (!in_array($province_detail, $province_record)) {
    //         $record['city'] = $province_detail;
    //         $province_record[] = $province_detail;
    //         $key = $record['city'];
    //         $list1[$key][] = $record;
    //     }
    //     if (strpos($data[1], '电信') !== false) {
    //         $record['city'] = explode('电信', $data[1])[0];
    //         $record['city'] = str_replace('&lt;', '', $record['city']);
    //         $record['city'] = str_replace('&gt;', '', $record['city']);
    //         $record['supply'] = '电信';
    //     } elseif (strpos($data[1], '联通') !== false) {
    //         $record['city'] = explode('联通', $data[1])[0];
    //         $record['city'] = str_replace('&lt;', '', $record['city']);
    //         $record['city'] = str_replace('&gt;', '', $record['city']);
    //         $record['supply'] = '联通';
    //     } elseif (strpos($data[1], '移动') !== false) {
    //         $record['city'] = explode('移动', $data[1])[0];
    //         $record['city'] = str_replace('&lt;', '', $record['city']);
    //         $record['city'] = str_replace('&gt;', '', $record['city']);
    //         $record['supply'] = '移动';
    //     } else {
    //         $record['city'] = $data[1];
    //         $record['city'] = str_replace('&lt;', '', $record['city']);
    //         $record['city'] = str_replace('&gt;', '', $record['city']);
    //         $record['supply'] = '电信/联通';
    //     }

    //     $record['ip'] = '';
    //     $record['daikuan'] = '';
    //     $record['onlineuser'] = '';
    //     $record['maxuser'] = '';
    //     $record['online'] = '';
    //     $record['status'] = '';
    //     $record['nasname'] = $data[0];

    //     if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) {
    //         fputcsv($dnx_exit, ['无限', explode('.',$record['nasname'])[0], $record['nasname'], date('Y-m-d H:i:s')]);
    //     }
    //     $list1[$key][] = $record;

    // }
    // foreach ($list1 as $val) {
    //     foreach ($val as $net_data) {
    //         $net_data['city'] = str_replace('电信', '', $net_data['city']);
    //         $net_data['city'] = str_replace('联通', '', $net_data['city']);

    //         fputcsv($file, $net_data);
    //         fputcsv($all, $net_data);
    //     }
    // }
}

function jinrui_getList($html, &$file, &$all, $exit)
{
    global $dnx_exit, $dnx_has_exit;
    //省会
    $province_record = [];
    $key = '';
    $list1 = [];
    preg_match_all("/\{(.*?)\}/is", $html, $result);
    foreach ($result[0] as $info) {
        $info = json_decode($info, true);
        if (empty($info)) {
            continue;
        }
        $record = [];
        $record['name'] = '金瑞';
        if (!in_array($info['province'], $province_record)) {
            $record['city'] = $info['province'];
            $province_record[] = $info['province'];
            $key = $record['city'];
            $list1[$key][] = $record;
        }
        if (empty($info['city'])) {
            $record['city'] = $info['province'];
        } else {
            $record['city'] = $info['city'];
        }
        $record['supply'] = $info['isp'];
        $record['ip'] = '';
        $record['daikuan'] = '';
        $record['onlineuser'] = '';
        $record['maxuser'] = '';
        $record['online'] = $info['status'] == 1 ? '正常' : '故障';
        $record['status'] = '';
        $nasname = explode('|', $info['nasname']);
        foreach ($nasname as $v) {
            $record['nasname'] = $v;
            if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) {
                fputcsv($dnx_exit, ['金瑞', explode('.',$record['nasname'])[0], $record['nasname'], date('Y-m-d H:i:s')]);
            }
            $list1[$info['province']][] = $record;
        }
    }
    foreach ($list1 as $val) {
        foreach ($val as $net_data) {

            fputcsv($file, $net_data);
            fputcsv($all, $net_data);
        }
    }
}


function get_product($file_path, $num = 9)
{
    $list = [];
    $file = fopen($file_path, 'r');
    while ($info = fgetcsv($file)) {
        if (isset($info[$num])) {
            $list[] = $info[$num];
        }

    }
    fclose($file);
    return $list;
}

function xianfeng_post($url, $cookie, $post)
{
    $curl = curl_init(); //初始化curl模块
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_COOKIE, $cookie); //读取cookie
    curl_setopt($curl, CURLOPT_POST, 1); //post方式提交
    curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post)); //要提交的信息
    $rs = curl_exec($curl); //执行cURL抓取页面内容
    curl_close($curl);
    return $rs;
}
