⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 index.php

📁 电驴的MAC源代码
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/** * AMPS - AMule PHP Statistics * Written by 黚erpenguin, AMPS is an adaptation of BigBob's aStats * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */// If you want to mess with these settings, do so at your OWN RISK// They are not all fully documented and it may not be obvious to anyone// except myself what they do!define(VERSION, "0.7.6");define(AMULESIGDAT, "/tmp/amulesig.dat");define(IMAGEPATH, "./images");define(IMAGETYPE, "png");define(CLEANSIGIMG, "baseimage.png");define(RUNNINGIMG, "running.png");define(RX0TX0IMG, "rx0tx0.png");define(RX0TX1IMG, "rx0tx1.png");define(RX1TX0IMG, "rx1tx0.png");define(RX1TX1IMG, "rx1tx1.png");define(HIGHIDIMGKADON, "conn_highid_kad_on.png");define(HIGHIDIMGKADOFF, "conn_highid_kad_off.png");define(HIGHIDIMGKADFW, "conn_highid_kad_fw.png");define(LOWIDIMGKADFW, "conn_lowid_kad_fw.png");define(LOWIDIMGKADOFF, "conn_lowid_kad_off.png");define(LOWIDIMGKADON, "conn_lowid_kad_on.png");define(NOCONNIMGKADON, "noconn_kad_on.png");define(NOCONNIMGKADFW, "noconn_kad_fw.png");define(NOCONNIMGKADOFF, "noconn_kad_off.png");define(TIMEGENIMG, "clock.png");define(SERVERIMG, "serverbox.png");define(SHAREDFILESIMG, "files.png");define(QUEUEIMG, "queue.png");define(ERRFONTPADDING, 5);define(FONTSIZE, 9);define(FONTFILE, "./LucidaSansRegular.ttf");define(IMAGETEXTCOLOR, "ffffff");$completelangs = array("ca", "de", "en", "es", "eu", "fr", "fi", "hu", "it",	"nl", "pl", "pt", "pt_BR");// end constants// initialize values array$values = array("running"=>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 imageif (!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 imageif (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"]);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -