mumble-ping/banner.php

126 lines
2.3 KiB
PHP
Raw Permalink Normal View History

2023-07-22 18:51:57 +00:00
<?php
include "mumble-ping.php";
// load
try{
$mumble = new mumble("GeoLite2-Country.mmdb");
$res = $mumble->ping(
$_GET["ip"],
isset($_GET["port"]) ? $_GET["port"] : 64738,
);
if($res["server"]["name"] !== null){
$str = $res["server"]["name"];
}else{
$str = "Unknown serber name!!";
if(isset($_GET["name"])){
$str = $_GET["name"];
}
}
}catch(Exception $error){
$ip = isset($_GET["ip"]) ? $_GET["ip"] : "Unknown address";
$port = isset($_GET["port"]) ? $_GET["port"] : "???";
http_response_code(404);
$res = [
"server" => [
"online" => "0",
"max" => "0",
"domains" => [ $ip ],
"port" => $port,
"country" => [
"code" => "blank"
]
]
];
$str = "Host unreachable!!";
}
$im = new Imagick();
$im->newImage(468, 60, "#282828");
$im->setImageFormat("png");
// bg
$bg = new Imagick("bg.png");
$im->compositeImage($bg, imagick::COMPOSITE_OVER, 367, 1);
// text
$stroke = new ImagickDraw();
$stroke->setStrokeColor("#504945");
$stroke->setFillColor("transparent");
$stroke->rectangle(0, 0, 467, 59);
$im->drawImage($stroke);
$draw = new ImagickDraw();
$draw->setFillColor("#ebdbb2");
$draw->setFontSize(13);
$draw->setFont("COMIC.TTF");
$newstr = "";
if(strlen($str) > 84){
for($i=0; $i<84; $i++){
$newstr .= $str[$i];
}
$str = trim($newstr) . "...";
unset($newstr);
}
$str = trim($str);
$str = explode("\n", wordwrap($str, 45, "\n", true));
if(count($str) === 1){
$im->annotateImage($draw, 5, 25, 0, $str[0]);
}else{
for($i=0; $i<2; $i++){
$im->annotateImage($draw, 5, (16 * $i) + 15, 0, $str[$i]);
}
}
// flag
if(idate("m") === 11){
$path = "flag/xmas/";
}else{
$path = "flag/";
}
$merge = new Imagick($path . strtolower($res["server"]["country"]["code"]) . ".png");
$height = $merge->getImageHeight();
$im->compositeImage($merge, imagick::COMPOSITE_OVER, 5, 46 - ($height / 2));
// ip
$draw->setFillColor("#bdae93");
$im->annotateImage($draw, 30, 51, 0, $res["server"]["domains"][0]);
// users
if($res["server"]["online"] > 0){
$name = "buddy.png";
}else{
$name = "buddy_alone.png";
}
$buddy = new Imagick($name);
$im->compositeImage($buddy, imagick::COMPOSITE_OVER, 340, 40);
$im->annotateImage($draw, 360, 53, 0, $res["server"]["online"] . "/" . $res["server"]["max"]);
// done.
header("Content-Type: image/png");
echo $im->getImageBlob();
?>