<?php

// config

$server = 'localhost';
$port = 6110;
$timeout = 10;
$name = 'DP';
$executable = './ghost3';

// config end


// don't modify below here unless you know what you do!

$img = imagecreate(220, 25);
$bg = imagecolorallocate($img, 0, 0, 0);
$col = imagecolorallocate($img, 255, 255, 255);
imagestring($img, 5, 5, 5, "$name:", $col);

$check = @fsockopen($server, $port, $errno, $errstr, $timeout);
if ($check) {
	$col = imagecolorallocate($img, 0, 128, 0);
	$txt = 'hosting';
} else {
	$cmd = "ps ax|grep $executable|grep -v grep";
	exec($cmd, $output, $result);
	if(!$result) {
		$col = imagecolorallocate($img, 255, 204, 0);
		$txt = 'idle';
	} else {
		$col = imagecolorallocate($img, 255, 0, 0);
		$txt = 'offline';
	}
}
imagestring($img, 5, 150, 5, $txt, $col);

header('Content-type: image/png');
imagepng($img);
imagecolordeallocate($bg);
imagecolordeallocate($col);
imagedestroy($img);

?>