Browse Source

added more fields like serber name!

master
lolcat 3 months ago
parent
commit
8f159fa570
  1. 11
      README.md
  2. 1
      list.json
  3. 79
      mumble-ping.php
  4. 97
      mumble-scrape.php
  5. 2
      mumble.php

11
README.md

@ -7,16 +7,19 @@ A simple PHP module to ping mumble serbers.
3. Sign up for maxmind's bullshit site and get the **country** GeoLite2 .mmdb file
4. Drop all the shit you downloaded in the root of this repo
Done. Now, just drop all of that crap inside a webserber that supports PHP and access the mumble.php file.
Now, just drop all of that crap inside a webserber that supports PHP and access the mumble.php file.
Don't forget to make mumble-scrape inaccessible!
To be able to show users the serber name and website, you need to scrape the official mumble serber list using mumble-scrape.php. This repo comes with a pre-compiled list.json, but it is probably outdated. Use `screen` and run mumble-scrape.php in the background. By default, it gets a list of all serbers every 24 hours and resolves the DNS for all domains!
## Usage
`/mumble.php?ip=sleipnir.sh`
`/mumble.php?ip=lolcat.ca`
or
`/mumble.php?ip=aaathats3as.com&port=64738`
`/mumble.php?ip=skyn3t.in&port=64738`
So yeah, the port is optional. IPs and port is sanitized.
## Try it out
https://lolcat.ca/mumble_ping_api/
Enjoy!!
Enjoy!!

1
list.json

File diff suppressed because one or more lines are too long

79
mumble-ping.php

@ -10,9 +10,9 @@ class mumble{
$this->reader = new Reader($reader_location);
}
public function ping($ip = "0.0.0.0", $port = 64738){
public function ping($domain = "0.0.0.0", $port = 64738){
if(($ip = $this->validate_domain($ip)) === false){
if(($ip = $this->validate_domain($domain)) === false){
throw new Exception("Server IP points to bad host");
}
@ -30,16 +30,12 @@ class mumble{
socket_set_option($this->socket, SOL_SOCKET, SO_RCVTIMEO, ["sec" => 2, "usec" => 0]);
socket_set_option($this->socket, SOL_SOCKET, SO_SNDTIMEO, ["sec" => 2, "usec" => 0]);
$db = $this->reader->country($ip);
$data = [
"version" => null,
//"ident" => null,
"online" => null,
"max" => null,
"bandwidth" => null,
"countryname" => $db->country->name,
"countrycode" => $db->country->isoCode,
"bandwidth" => null
];
if(!@socket_connect($this->socket, $ip, $port)){
@ -111,10 +107,76 @@ class mumble{
$data["bandwidth"] .= $rawdata[$i];
}
/*
Get name and website
*/
$stream = fopen("list.json", "r");
$json = fread($stream, filesize("list.json"));
fclose($stream);
$json = json_decode($json, true);
$offset = -1;
for($i=0; $i<count($json); $i++){
for($k=0; $k<count($json[$i]["ip"]); $k++){
if(
(
$json[$i]["ip"][$k] == $domain ||
$json[$i]["ip"][$k] == $ip
) &&
$json[$i]["port"] === $port
){
$offset = $i;
break 2;
}
}
}
if($offset !== -1){
$data["name"] = $json[$offset]["name"];
$data["website"] = $json[$offset]["url"];
if(!preg_match('/^https?:\/\//', $data["website"])){
$data["website"] = "https://" . $data["website"];
}
$data["domains"] = $json[$offset]["ip"];
}else{
$data["name"] = null;
$data["website"] = null;
$data["domains"][] = $domain;
if($domain != $ip){
$data["domains"][] = $ip;
}
}
// get country
try{
$db = $this->reader->country($ip);
$data["countryname"] = $db->country->name;
$data["countrycode"] = $db->country->isoCode;
}catch(Exception $error){
$data["countryname"] = "Unknown";
$data["countrycode"] = "UN";
}
// unpack
$data = [
"status" => "ok",
"server" => [
"name" => $data["name"],
"domains" => $data["domains"],
"ping" => $data["ping"],
"online" => hexdec(bin2hex($data["online"])),
"max" => hexdec(bin2hex($data["max"])),
@ -124,7 +186,8 @@ class mumble{
"name" => $data["countryname"],
"code" => $data["countrycode"],
],
"version" => $data["version"]
"version" => $data["version"],
"website" => $data["website"]
]
];

97
mumble-scrape.php

@ -0,0 +1,97 @@
<?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;
}
?>

2
mumble.php

@ -15,7 +15,7 @@ try{
echo json_encode(
$mumble->ping(
$_GET["ip"],
$_GET["port"] ? $_GET["port"] : 64738,
isset($_GET["port"]) ? $_GET["port"] : 64738,
)
);

Loading…
Cancel
Save