PHP Console Monitor : Différence entre versions
De Wiki levelKro
(Page créée avec « Permet d'afficher le états des serveurs défini et de leur services (réponse). Simple affichage en console des résultats aux Ping avec personnalisation de l'affichage.... ») |
(Aucune différence)
|
Version du 25 janvier 2019 à 06:25
Permet d'afficher le états des serveurs défini et de leur services (réponse). Simple affichage en console des résultats aux Ping avec personnalisation de l'affichage.
Sommaire
Pré-requis
- PHP-CLI 5.4+
- Shell (Telnet/SSH ou Prompt de commande)
- PHP Minecraft Query API si vous désirez faire un ping d'un serveur Minecraft
Fichiers
colors.php
Pour rendre le résultat en couleur.
<?php class Colors { private $foreground_colors = array(); private $background_colors = array(); public function __construct() { // Set up shell colors $this->foreground_colors['black'] = '0;30'; $this->foreground_colors['dark_gray'] = '1;30'; $this->foreground_colors['blue'] = '0;34'; $this->foreground_colors['light_blue'] = '1;34'; $this->foreground_colors['green'] = '0;32'; $this->foreground_colors['light_green'] = '1;32'; $this->foreground_colors['cyan'] = '0;36'; $this->foreground_colors['light_cyan'] = '1;36'; $this->foreground_colors['red'] = '0;31'; $this->foreground_colors['light_red'] = '1;31'; $this->foreground_colors['purple'] = '0;35'; $this->foreground_colors['light_purple'] = '1;35'; $this->foreground_colors['brown'] = '0;33'; $this->foreground_colors['yellow'] = '1;33'; $this->foreground_colors['light_gray'] = '0;37'; $this->foreground_colors['white'] = '1;37'; $this->background_colors['black'] = '40'; $this->background_colors['red'] = '41'; $this->background_colors['green'] = '42'; $this->background_colors['yellow'] = '43'; $this->background_colors['blue'] = '44'; $this->background_colors['magenta'] = '45'; $this->background_colors['cyan'] = '46'; $this->background_colors['light_gray'] = '47'; } // Returns colored string public function getColoredString($string, $foreground_color = null, $background_color = null) { $colored_string = ""; // Check if given foreground color found if (isset($this->foreground_colors[$foreground_color])) { $colored_string .= "\033[" . $this->foreground_colors[$foreground_color] . "m"; } // Check if given background color found if (isset($this->background_colors[$background_color])) { $colored_string .= "\033[" . $this->background_colors[$background_color] . "m"; } // Add string and end coloring $colored_string .= $string . "\033[0m"; return $colored_string; } // Returns all foreground color names public function getForegroundColors() { return array_keys($this->foreground_colors); } // Returns all background color names public function getBackgroundColors() { return array_keys($this->background_colors); } }
libs.php
Inclus les fonctions PHP du script.
<?php $services=array( "ftp"=>"21", "ssh"=>"22", "dns"=>"53", "http"=>"80", "https"=>"443", "sc"=>"8000", "tnet"=>"31457", "webmin"=>"10000", "sql"=>"3306", "source"=>"27015", "smtp"=>"25", "pop"=>"995", "rtmp"=>"1935", "mc"=>"25565", "mcpe"=>"19132", "smb"=>"445", "netb"=>"139", "proxy"=>"3128" ); $names=array( "ftp"=>"FTP - Serveur de fichier", "ssh"=>"SSH - Shell de commande", "dns"=>"DNS - Serveur de nom de domaine (DNS)", "http"=>"HTTP - Serveur Web", "https"=>"HTTPS - Serveur Web sécurisé avec SSL ", "sc"=>"SHOUTCast - Serveur de streaming Audio", "tnet"=>"TetriNet - Serveur de jeu Tetrinet", "webmin"=>"Webmin/Virtualmin - Serveur de gestion", "sql"=>"MySQL - Base de données", "source"=>"Source - Serveur de jeu Source", "smtp"=>"SMTP - Serveur d'envoie des courriels", "pop"=>"POP - Service de boîte des courriels", "rtmp"=>"RTMP - Serveur de diffusion Flash", "mc"=>"Minecraft - Serveur Minecraft (Java)", "mcpe"=>"Minecraft PE - Serveur Minecraft Pocket Edition/Windows 10", "smb"=>"Samba - Réseau de partage de type Samba/Windows", "netbios"=>"Samba NetBIOS - Réseau de partage de type Samba/Windows avec NetBIOS", "proxy"=>"Proxy - Service de camouglage de l'adresse réel du client", ); function remoteState($host,$port){ if($fp=@fsockopen($host, $port, $errno, $errstr, 20)){ $rep=true; } else{ $rep=false; } return($rep); @fclose($fp); $fp=null; $name=null; $rep=null; $port=null; $host=null; } function remoteStateMC($host,$port){ $json=exec("php ./mcstatus/json.php ".$host." ".$port,$ret); $array = json_decode($json,true); return (($array['status']=="Online")?true:false); } function remotePing($ip){ $ping = exec("ping -c 1 $ip"); $ping=explode("=",$ping); if(!$ping[1]) return false; else return true; }