98 lines
1.7 KiB
PHP
Executable File
98 lines
1.7 KiB
PHP
Executable File
<?php
|
|
|
|
set_time_limit(0);
|
|
|
|
function get_ip($domain){
|
|
|
|
// if its not an IP
|
|
if(!filter_var($domain, FILTER_VALIDATE_IP)){
|
|
|
|
// resolve domain's IP
|
|
return gethostbyname($domain . ".");
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
function curl($url){
|
|
|
|
$curlproc = curl_init();
|
|
|
|
curl_setopt($curlproc, CURLOPT_URL, $url);
|
|
|
|
curl_setopt($curlproc, CURLOPT_ENCODING, ""); // accept all encoding
|
|
curl_setopt($curlproc, CURLOPT_RETURNTRANSFER, 1);
|
|
curl_setopt($curlproc, CURLOPT_SSL_VERIFYHOST, 2);
|
|
curl_setopt($curlproc, CURLOPT_SSL_VERIFYPEER, 1);
|
|
curl_setopt($curlproc, CURLOPT_CONNECTTIMEOUT, 5);
|
|
|
|
$data = curl_exec($curlproc);
|
|
|
|
if(curl_errno($curlproc)){
|
|
|
|
throw new Exception(curl_error($curlproc));
|
|
}
|
|
|
|
curl_close($curlproc);
|
|
|
|
return $data;
|
|
}
|
|
|
|
while(true){
|
|
|
|
echo "Got " . getserbers() . " serbers";
|
|
|
|
sleep((60 * 60) * 24);
|
|
}
|
|
|
|
function getserbers(){
|
|
$xml = curl("https://publist.mumble.info/v1/list");
|
|
/*
|
|
$stream = fopen("list.xml", "r");
|
|
$xml = fread($stream, filesize("list.xml"));
|
|
fclose($stream);*/
|
|
|
|
preg_match_all(
|
|
'/<server name="(.*)" ca=".*ip="(.*)" port="(.*)" region=".*url="(.*)" ?\/>/',
|
|
$xml,
|
|
$matches
|
|
);
|
|
|
|
$servers = [];
|
|
for($i=0; $i<count($matches[0]); $i++){
|
|
|
|
$servers[$i]["name"] = $matches[1][$i];
|
|
$servers[$i]["ip"] = [
|
|
str_replace(
|
|
[
|
|
"http://",
|
|
"https://",
|
|
"mumble://",
|
|
"/"
|
|
],
|
|
"",
|
|
$matches[2][$i]
|
|
)
|
|
];
|
|
|
|
if($ip = get_ip($servers[$i]["ip"][0])){
|
|
|
|
usleep(500000);
|
|
$servers[$i]["ip"][1] = $ip;
|
|
}
|
|
|
|
$servers[$i]["port"] = intval($matches[3][$i]);
|
|
$servers[$i]["url"] = $matches[4][$i];
|
|
}
|
|
|
|
$len = count($servers);
|
|
$servers = json_encode($servers);
|
|
|
|
$stream = fopen("list.json", "w");
|
|
fwrite($stream, $servers);
|
|
fclose($stream);
|
|
|
|
return $len;
|
|
}
|
|
?>
|