false, "psuptime"=>"", "connected"=>"0", "servername"=>"", "serverip"=>"0.0.0.0", "highlowid"=>"", "rxspeed"=> "0.0", "txspeed"=>"0.0", "queuedclients"=>"0", "sharedfiles"=>"0", "nick"=>"", "rxtotal"=>"0.0", "txtotal"=>"0.0", "muleversion"=>"0.0.0" ); // make sure gd and freetype are loaded; we need them for the signature image if (!extension_loaded("gd")) { echo "gd extension missing"; exit(); } if (!in_array("imagettftext", get_extension_funcs("gd"))) { echo "FreeType extensions missing from gd"; exit(); } // lang can come from two places; as an argument to the script (i.e. // index.php?lang=xx or as an HTTP POST variable. The latter takes prescedence // over the former. if (isset($_GET["lang"])) $lang = $_GET["lang"]; if (isset($_POST["lang"])) $lang = $_POST["lang"]; if (isset($lang)) { $temp = @fopen("./langs/".$lang.".inc", "r"); if (!$temp) { $lang = strtolower($lang); $temp = @fopen("./langs/".$lang.".inc", "r"); } if (!$temp) { require("./langs/en.inc"); } else { require("./langs/".$lang.".inc"); fclose($temp); } } else { $lang = "en"; require("./langs/en.inc"); } // if the variable $sig_image is set, only output the signature image if (isset($_GET["sig_image"])) { $ret = get_stats(); if (!$ret) output_error_img($text["sigfileerr"]." (".AMULESIGDAT. ")"); else output_sig_image(); exit(); } /** * Retrieves the statistics, of course! First checks to see if the process is * actually running. If not, the function returns true without attempting to * read the aMule signature file. If the process IS running, the function reads * the appropriate data from the aMule signiture file, stores them in the * associative array $values and returns true on success, and false if there * is a failure reading the signature file. */ function get_stats() { global $values, $text; // the ps command should output something like 1-05:23:45, in // days-hours:minutes:seconds format. // alternative ps command; doesn't work on *BSD! // $values["psuptime"] = trim(exec("ps --no-header -C amule -o etime")); $values["psuptime"] = trim(exec("ps ax -o etime,comm --no-header | ". "awk '/amule$/ {print $1}' | head -n 1")); if (!$values["psuptime"]) { $values["running"] = false; return true; } else { $values["running"] = true; // Uncomment to test etime parser... // $values["psuptime"] = "3442-12:34:55"; if (strlen($values["psuptime"]) >= 5) $uptimestr = substr($values["psuptime"], -5, 2). $text["minabbr"]." ".substr($values["psuptime"], -2).$text["secabbr"]; if (strlen($values["psuptime"]) >= 8) $uptimestr = substr($values["psuptime"], -8, 2). $text["hourabbr"]." ".$uptimestr; if (strlen($values["psuptime"]) >= 10) $uptimestr = substr($values["psuptime"], 0, strlen( $values["psuptime"]) - 9).$text["dayabbr"]." ". $uptimestr; $values["psuptime"] = $uptimestr; $sigfile = @fopen(AMULESIGDAT, "r"); if (!$sigfile) return false; else { $values["connected"] = trim(fgets($sigfile)); $values["servername"] = trim(fgets($sigfile)); $values["serverip"] = trim(fgets($sigfile)); $values["serverport"] = trim(fgets($sigfile)); $values["highlowid"] = trim(fgets($sigfile)); $values["kad"] = trim(fgets($sigfile)); $values["rxspeed"] = trim(fgets($sigfile)); $values["txspeed"] = trim(fgets($sigfile)); $values["queuedclients"] = trim(fgets($sigfile)); $values["sharedfiles"] = trim(fgets($sigfile)); $values["nick"] = trim(fgets($sigfile)); $values["rxtotal"] = trim(fgets($sigfile)); $values["txtotal"] = trim(fgets($sigfile)); $values["muleversion"] = trim(fgets($sigfile)); fclose($sigfile); return true; } } } /** * This function creates the signiture image and writes out in JPEG format (may * change this to PNG or add an option for image time in the future). The * function assumes get_stats() has already been called and will use whatever * values are in the $values array. */ function output_sig_image() { global $values, $text; // open the base image for writing on. If unsuccessful, exit with an // error image. $finalimg = @imagecreatefrompng(IMAGEPATH."/".CLEANSIGIMG); if (!$finalimg) { output_error_img($text["baseimgerr"]); exit(); } // open up all the icons $runningimg = @imagecreatefrompng(IMAGEPATH."/".RUNNINGIMG); $sharedfilesimg = @imagecreatefrompng(IMAGEPATH."/".SHAREDFILESIMG); $serverimg = @imagecreatefrompng(IMAGEPATH."/".SERVERIMG); $queueimg = @imagecreatefrompng(IMAGEPATH."/".QUEUEIMG); $timegenimg = @imagecreatefrompng(IMAGEPATH."/".TIMEGENIMG); if($values["kad"] == "2") { if ($values["highlowid"] == "H" && $values["connected"] == "1") $idimg = @imagecreatefrompng(IMAGEPATH."/".HIGHIDIMGKADON); else if ($values["highlowid"] == "L" && $values["connected"] == "1") $idimg = @imagecreatefrompng(IMAGEPATH."/".LOWIDIMGKADON); else $idimg = @imagecreatefrompng(IMAGEPATH."/".NOCONNIMGKADON); } else if ($values["kad"] == "1") { if ($values["highlowid"] == "H" && $values["connected"] == "1") $idimg = @imagecreatefrompng(IMAGEPATH."/".HIGHIDIMGKADFW); else if ($values["highlowid"] == "L" && $values["connected"] == "1") $idimg = @imagecreatefrompng(IMAGEPATH."/".LOWIDIMGKADFW); else $idimg = @imagecreatefrompng(IMAGEPATH."/".NOCONNIMGKADFW); } else { if ($values["highlowid"] == "H" && $values["connected"] == "1") $idimg = @imagecreatefrompng(IMAGEPATH."/".HIGHIDIMGKADOFF); else if ($values["highlowid"] == "L" && $values["connected"] == "1") $idimg = @imagecreatefrompng(IMAGEPATH."/".LOWIDIMGKADOFF); else $idimg = @imagecreatefrompng(IMAGEPATH."/".NOCONNIMGKADOFF); } if (($values["rxspeed"] == "0.0" && $values["txspeed"] == "0.0") || !$values["running"]) $speedimg = @imagecreatefrompng(IMAGEPATH."/".RX0TX0IMG); else if ($values["rxspeed"] == "0.0" && $values["txspeed"] != "0.0") $speedimg = @imagecreatefrompng(IMAGEPATH."/".RX0TX1IMG); else if ($values["rxspeed"] != "0.0" && $values["txspeed"] == "0.0") $speedimg = @imagecreatefrompng(IMAGEPATH."/".RX1TX0IMG); else if ($values["rxspeed"] != "0.0" && $values["txspeed"] != "0.0") $speedimg = @imagecreatefrompng(IMAGEPATH."/".RX1TX1IMG); // check to make sure all the icons were successfully opened. If not, // output an image containing the appropriate error message and exit // the script here. if (! ($runningimg && $sharedfilesimg && $serverimg && $queueimg && $timegenimg && $idimg && $speedimg)) { output_error_img($text["iconerr"]); exit(); } // place the icons onto the base image imagecopy($finalimg, $runningimg, 5, 5, 0, 0, imagesx($runningimg) - 1, imagesy($runningimg) - 1); imagecopy($finalimg, $sharedfilesimg, 249, 71, 0, 0, imagesy($sharedfilesimg) - 1, imagesy($sharedfilesimg) - 1); imagecopy($finalimg, $idimg, 5, 27, 0, 0, imagesx($idimg) - 1, imagesy($idimg) - 1); imagecopy($finalimg, $serverimg, 5, 49, 0, 0, imagesx($serverimg) - 1, imagesy($serverimg) - 1); imagecopy($finalimg, $speedimg, 5, 71, 0, 0, imagesx($speedimg) - 1, imagesy($speedimg) - 1); imagecopy($finalimg, $queueimg, 249, 93, 0, 0, imagesx($queueimg) - 1, imagesy($queueimg) - 1); imagecopy($finalimg, $timegenimg, 5, 93, 0, 0, imagesx($timegenimg) - 1, imagesy($timegenimg) - 1); // allocate white for the text color sscanf(IMAGETEXTCOLOR, "%2x%2x%2x", $red, $green, $blue); $fgcolor = imagecolorallocate($finalimg, $red, $green, $blue); // aMule version and process status if ($values["running"]) imagettftext($finalimg, FONTSIZE, 0, 26, 19, $fgcolor, FONTFILE, "aMule ".$values["muleversion"]. " ".$text["runtimemsg"]." ".$values["psuptime"]); else imagettftext($finalimg, FONTSIZE, 0, 26, 19, $fgcolor, FONTFILE, "aMule ".$text["norunmsg"]); // connection status and nickname if($values["kad"] == "2") { if ($values["running"] && $values["connected"] == "2") imagettftext($finalimg, FONTSIZE, 0, 25, 41, $fgcolor, FONTFILE, "aMule ".$text["connmsg"]." ".$text["kadonmsg"]); else if ($values["running"] && $values["connected"] != "0" && $values["highlowid"] == "H") imagettftext($finalimg, FONTSIZE, 0, 25, 41, $fgcolor, FONTFILE, $values["nick"]." ".$text["highidmsg"]." ".$text["kadonmsg"]); else if ($values["running"] && $values["connected"] != "0" && $values["highlowid"] != "H") imagettftext($finalimg, FONTSIZE, 0, 25, 41, $fgcolor, FONTFILE, $values["nick"]." ".$text["lowidmsg"]." ".$text["kadonmsg"]); else if ($values["running"] && $values["connected"] == "0") imagettftext($finalimg, FONTSIZE, 0, 25, 41, $fgcolor, FONTFILE, $values["nick"]." ".$text["offrunmsg"]." ". $text["amulenorun"]." ".$text["kadonmsg"]); else imagettftext($finalimg, FONTSIZE, 0, 25, 41, $fgcolor, FONTFILE, $text["offline"]." ".$text["amulenorun"]); } else if($values["kad"] == "1") { if ($values["running"] && $values["connected"] == "2") imagettftext($finalimg, FONTSIZE, 0, 25, 41, $fgcolor, FONTFILE, "aMule ".$text["connmsg"]." ".$text["kadfwmsg"]); else if ($values["running"] && $values["connected"] != "0" && $values["highlowid"] == "H") imagettftext($finalimg, FONTSIZE, 0, 25, 41, $fgcolor, FONTFILE, $values["nick"]." ".$text["highidmsg"]." ".$text["kadfwmsg"]); else if ($values["running"] && $values["connected"] != "0" && $values["highlowid"] != "H") imagettftext($finalimg, FONTSIZE, 0, 25, 41, $fgcolor, FONTFILE, $values["nick"]." ".$text["lowidmsg"]." ".$text["kadfwmsg"]); else if ($values["running"] && $values["connected"] == "0") imagettftext($finalimg, FONTSIZE, 0, 25, 41, $fgcolor, FONTFILE, $values["nick"]." ".$text["offrunmsg"]." ". $text["amulenorun"]." ".$text["kadfwmsg"]); else imagettftext($finalimg, FONTSIZE, 0, 25, 41, $fgcolor, FONTFILE, $text["offline"]." ".$text["amulenorun"]); } else { if ($values["running"] && $values["connected"] == "2") imagettftext($finalimg, FONTSIZE, 0, 25, 41, $fgcolor, FONTFILE, "aMule ".$text["connmsg"]." ".$text["kadoffmsg"]); else if ($values["running"] && $values["connected"] != "0" && $values["highlowid"] == "H") imagettftext($finalimg, FONTSIZE, 0, 25, 41, $fgcolor, FONTFILE, $values["nick"]." ".$text["highidmsg"]." ".$text["kadoffmsg"]); else if ($values["running"] && $values["connected"] != "0" && $values["highlowid"] != "H") imagettftext($finalimg, FONTSIZE, 0, 25, 41, $fgcolor, FONTFILE, $values["nick"]." ".$text["lowidmsg"]." ".$text["kadoffmsg"]); else if ($values["running"] && $values["connected"] == "0") imagettftext($finalimg, FONTSIZE, 0, 25, 41, $fgcolor, FONTFILE, $values["nick"]." ".$text["offrunmsg"]." ". $text["amulenorun"]." ".$text["kadoffmsg"]); else imagettftext($finalimg, FONTSIZE, 0, 25, 41, $fgcolor, FONTFILE, $text["offline"]." ".$text["amulenorun"]); } // shared files if ($values["running"] && $values["connected"] == "1") imagettftext($finalimg, FONTSIZE, 0, 270, 85, $fgcolor, FONTFILE, $text["sharedfiles"].": ". $values["sharedfiles"]); else imagettftext($finalimg, FONTSIZE, 0, 270, 85, $fgcolor, FONTFILE, $text["sharedfiles"].": ".$text["na"]); // server name, ip, port if ($values["running"] && $values["connected"] == "1") imagettftext($finalimg, FONTSIZE, 0, 25, 63, $fgcolor, FONTFILE, $values["servername"]." (".$values["serverip"].":". $values["serverport"].")"); else imagettftext($finalimg, FONTSIZE, 0, 25, 63, $fgcolor, FONTFILE, $text["na"]); // RX & TX if ($values["running"]) imagettftext($finalimg, FONTSIZE, 0, 25, 85, $fgcolor, FONTFILE, $text["rx"].": ".$values["rxspeed"].$text["transrate"]. " | ".$text["tx"].": ".$values["txspeed"]. $text["transrate"]); else imagettftext($finalimg, FONTSIZE, 0, 25, 85, $fgcolor, FONTFILE, $text["rx"].": ".$text["na"]." | ".$text["tx"].": ". $text["na"]); // queued clients if ($values["running"]) imagettftext($finalimg, FONTSIZE, 0, 270, 107, $fgcolor, FONTFILE, $text["queuedclients"].": ". $values["queuedclients"]); else imagettftext($finalimg, FONTSIZE, 0, 270, 107, $fgcolor, FONTFILE, $text["queuedclients"].": ".$text["na"]); // RFC 2822 Datestamp imagettftext($finalimg, FONTSIZE, 0, 25, 107, $fgcolor, FONTFILE, date("r")); // outputs the signature image based on the value of IMAGETYPE. The case // for png and default are the same; in other words, PNG is the default // image output type. Note that your installation of GD has to support // the type of image you are outputting here. switch (IMAGETYPE) { case "jpg": case "jpeg": { header("Content-type: image/jpeg"); imagejpeg($finalimg, "", 100); } case "gif": { header("Content-type: image/gif"); imagegif($finalimg); } case "png": default: { header("Content-type: image/png"); imagepng($finalimg); } } } /** * This function outputs a simple image containing an error message specified * by the only parameter, $err_message. The image is black text and border on * a white background. */ function output_error_img($err_message) { // determine the size of the text string and add to it the amount of // padding specified earlier. $fontdims = imagettfbbox(FONTSIZE, 0, FONTFILE, $err_message); $min_x = min($fontdims[0], $fontdims[2], $fontdims[4], $fontdims[6]); $max_x = max($fontdims[0], $fontdims[2], $fontdims[4], $fontdims[6]); $min_y = min($fontdims[1], $fontdims[3], $fontdims[5], $fontdims[7]); $max_y = max($fontdims[1], $fontdims[3], $fontdims[5], $fontdims[7]); $width = ($max_x - $min_x) + (2 * ERRFONTPADDING); $height = ($max_y - $min_y) + (2 * ERRFONTPADDING); $img = @imagecreate($width, $height); $bgcolor = imagecolorallocate($img, 255, 255, 255); $fgcolor = imagecolorallocate($img, 0, 0, 0); imagesetthickness($img, 2); // draw the border imagerectangle($img, 1, 1, $width - 2, $height - 2, $fgcolor); // print the text imagettftext($img, FONTSIZE, 0, ERRFONTPADDING, ERRFONTPADDING + 0.5 * $height, $fgcolor, FONTFILE, $err_message); header("Content-type: image/jpeg"); imagejpeg($img, "", 100); } /** * Writes the non-dynamic leading part of the HTML that makes up the statistics * page. Right now this is just a stub for future theme support. */ function write_header() { ?> AMPS - AMule PHP Statistics

Generated by AMPS version
http://www.amule-project.net/
<uberpenguin at hotpop dot com> ".$text["na"]. "\n\t\t\t\t\n"; $titlecolstart = "\t\t\t\t\n\t\t\t\t\t"; $titlecolend = "\n"; $datacolstart = "\t\t\t\t\t"; $datacolend = "\n\t\t\t\t\n"; $sectiontablestart = "\t\n\t\t". "\n\t\t\t\n\t\t\n"; $sectionend = "\t\t\t
"; $sectiontablenext = "
\n\t\t\t\n\t\t\n\t". "\n\t

\n"; $innertable = "\t\t\n\t\t\t". "\n"; $organizetable = "\t\t\t\n"; // title echo "\t
\n\t\t\n\t\t\t". "\n\t\t\n\t". "

AMPS - ". "AMule PHP Statistics

\n\t

\n"; // first section echo $sectiontablestart.$text["general"].$sectiontablenext; echo $innertable; echo $organizetable; // client info echo $titlecolstart.$text["client"].$titlecolend; if ($values["running"]) echo $datacolstart."aMule ".$values["muleversion"]." ". $text["runtimemsg"]." ".$values["psuptime"].$datacolend; else echo $datacolstart."aMule ".$text["norunmsg"].$datacolend; // ed2kstatus echo $titlecolstart.$text["ed2kstatus"].$titlecolend; if ($values["connected"] == "2") echo $datacolstart.$text["connecting"]; else if ($values["connected"] == "1") echo $datacolstart.$text["online"]; else echo $datacolstart.$text["offline"]; if (!$values["running"]) echo " ".$text["amulenorun"].$datacolend; else echo $datacolend; // kadstatus echo $titlecolstart.$text["kadstatus"].$titlecolend; if ($values["kad"] == "2") echo $datacolstart.$text["kadon"]; else if ($values["kad"] == "1") echo $datacolstart.$text["kadfw"]; else echo $datacolstart.$text["kadoff"]; if (!$values["running"]) echo " ".$text["amulenorun"].$datacolend; else echo $datacolend; // nick echo $titlecolstart.$text["nick"].$titlecolend; if ($values["running"]) echo $datacolstart.$values["nick"].$datacolend; else echo $nastring; // RFC 2282 datestamp echo $titlecolstart.$text["localtime"].$titlecolend; echo $datacolstart.date("r").$datacolend; // RX speed echo $titlecolstart.$text["rxspeed"].$titlecolend; if ($values["running"]) echo $datacolstart.$values["rxspeed"].$text["transrate"]. $datacolend; else echo $nastring; // TX speed echo $titlecolstart.$text["txspeed"].$titlecolend; if ($values["running"]) echo $datacolstart.$values["txspeed"].$text["transrate"]. $datacolend; else echo $nastring; // queued clients echo $titlecolstart.$text["queuedclients"].$titlecolend; if ($values["running"]) echo $datacolstart.$values["queuedclients"].$datacolend; else echo $nastring; // TX total echo $titlecolstart.$text["txtotal"].$titlecolend; if ($values["running"]) echo $datacolstart.round($values["txtotal"] / 1073741824, 2). $text["gigabytes"].$datacolend; else echo $nastring; // RX total echo $titlecolstart.$text["rxtotal"].$titlecolend; if ($values["running"]) echo $datacolstart.round($values["rxtotal"] / 1073741824, 2). $text["gigabytes"].$datacolend; else echo $nastring; // shared files echo $titlecolstart.$text["sharedfiles"].$titlecolend; if ($values["running"] && $values["connected"] == "1") echo $datacolstart.$values["sharedfiles"].$datacolend; else echo $nastring; // OS identification echo $titlecolstart.$text["osversion"].$titlecolend; echo $datacolstart.exec("uname -sr").$datacolend; // uptime echo $titlecolstart.$text["hostuptime"].$titlecolend; echo $datacolstart.exec("uptime").$datacolend; // break into next section echo $sectionend; echo $sectiontablestart.$text["server"].$sectiontablenext; echo $innertable; echo $organizetable; // server name echo $titlecolstart.$text["servername"].$titlecolend; if ($values["running"] && $values["connected"] == "1") echo $datacolstart.$values["servername"].$datacolend; else echo $nastring; // server IP:port echo $titlecolstart.$text["serveraddr"].$titlecolend; if ($values["running"] && $values["connected"] == "1") echo $datacolstart.$values["serverip"].":". $values["serverport"].$datacolend; else echo $nastring; // ED2K link echo $titlecolstart.$text["ed2klink"].$titlecolend; if ($values["running"] && $values["connected"] == "1") echo $datacolstart."ed2k://".$values["servername"]."|". $values["serverip"]."|".$values["serverport"]. "|/".$datacolend; else echo $nastring; // break into next section echo $sectionend; echo $sectiontablestart.$text["signature"].$sectiontablenext; echo $innertable; echo $organizetable; // signature image global $lang; echo "\t\t\t\t\"\"\n"; // language selection echo $sectionend; echo $sectiontablestart; echo "\n\t\t\t\t

\n\t\t\t\t\t". $text["language"].":  \n\t\t\t\t\t  \n\t\t\t\t
\n"; echo "\t\t\t\n\t\t\n\t"; } write_footer(); ?>