$val){ $endchar = chomp($string[$i]); } } else { $endchar = substr("$string", strlen("$string") - 1, 1); if ($endchar == "\n"){ $string = substr("$string", 0, -1); } } return $endchar; } #$sigVal=array (); $texto = ""; $i=0; //Abrimos el archivo en modo lectura $fp = fopen("/home/p2p/.aMule/amulesig.dat","r"); //Leemos linea por linea el contenido del archivo while ($linea= fgets($fp,1024)) { $i++; chomp($linea); switch ($i) { case 1: $sigdat["On"]=$linea; break; case 2: $sigdat["ServName"]=$linea; break; case 3: $sigdat["ServIp"]=$linea; break; case 4: $sigdat["ServPort"]=$linea; break; case 5: $sigdat["Id"]=$linea; break; case 6: $sigdat["Kad"]=$linea; break; case 7: $sigdat["Down"]=$linea; break; case 8: $sigdat["Up"]=$linea; break; case 9: $sigdat["CliNum"]=$linea; break; case 10: $sigdat["shareF"]=$linea; break; case 11: $sigdat["Name"]=$linea; break; case 12: $sigdat["TotalDown"]=$linea; break; case 13: $sigdat["TotalUp"]=$linea; break; case 14: $sigdat["aMuleVer"]=$linea; break; case 15: $sigdat["SesiDown"]=$linea; break; case 16: $sigdat["SesiUp"]=$linea; break; case 17: $sigdat["TimeOn"]=$linea; break; } } function getRealIP(){ if( $_SERVER['HTTP_X_FORWARDED_FOR'] != '' ){ $client_ip = ( !empty($_SERVER['REMOTE_ADDR']) ) ? $_SERVER['REMOTE_ADDR'] : ( ( !empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : "unknown" ); // los proxys van añadiendo al final de esta cabecera // las direcciones ip que van "ocultando". Para localizar la ip real // del usuario se comienza a mirar por el principio hasta encontrar // una dirección ip que no sea del rango privado. En caso de no // encontrarse ninguna se toma como valor el REMOTE_ADDR $entries = split('[, ]', $_SERVER['HTTP_X_FORWARDED_FOR']); reset($entries); while (list(, $entry) = each($entries)) { $entry = trim($entry); if ( preg_match("/^([0-9]+.[0-9]+.[0-9]+.[0-9]+)/", $entry, $ip_list) ) { // http://www.faqs.org/rfcs/rfc1918.html $private_ip = array( '/^0./', '/^127.0.0.1/', '/^192.168..*/', '/^172.((1[6-9])|(2[0-9])|(3[0-1]))..*/', '/^10..*/'); $found_ip = preg_replace($private_ip, $client_ip, $ip_list[1]); if ($client_ip != $found_ip) { $client_ip = $found_ip; break; } } } } else { $client_ip = ( !empty($_SERVER['REMOTE_ADDR']) ) ? $_SERVER['REMOTE_ADDR'] : ( ( !empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : "unknown" ); } return $client_ip; } function OssDetect(){ if(eregi("linux",$_SERVER['HTTP_USER_AGENT'])){ $system = "Linux"; } elseif (eregi("win32",$_SERVER['HTTP_USER_AGENT'])){ $system = "Windows"; } elseif(eregi("Win 9x 4.90",$_SERVER['HTTP_USER_AGENT'])){ $system = "Windows Me"; } elseif(eregi("windows 2000",$_SERVER['HTTP_USER_AGENT']) || eregi("(windows nt)( ){0,1}(5.0)",$_SERVER['HTTP_USER_AGENT']) ){ $system = "Windows 2000"; } elseif (eregi("(windows nt)( ){0,1}(5.1)",$_SERVER['HTTP_USER_AGENT']) ){ $system = "Windows XP"; } elseif( (eregi("(win)([0-9]{2})",$_SERVER['HTTP_USER_AGENT'],$regs)) || (eregi("(windows) ([0-9]{2})",$_SERVER['HTTP_USER_AGENT'],$regs)) ){ $system = "Windows $regs[2]"; } elseif (eregi("(winnt)([0-9]{1,2}.[0-9]{1,2}){0,1}",$_SERVER['HTTP_USER_AGENT'],$regs) ) { $system = "Windows NT $regs[2]"; } elseif(eregi("(windows nt)( ){0,1}([0-9]{1,2}.[0-9]{1,2}){0,1}",$_SERVER['HTTP_USER_AGENT'],$regs) ){ $system = "Windows NT $regs[3]"; } elseif(eregi("mac",$_SERVER['HTTP_USER_AGENT'])){ $system = "Macintosh"; } elseif(eregi("(sunos) ([0-9]{1,2}.[0-9]{1,2}){0,1}",$_SERVER['HTTP_USER_AGENT'],$regs)){ $system = "SunOS $regs[2]"; } elseif(eregi("(beos) r([0-9]{1,2}.[0-9]{1,2}){0,1}",$_SERVER['HTTP_USER_AGENT'],$regs)){ $system = "BeOS $regs[2]"; } elseif(eregi("freebsd",$_SERVER['HTTP_USER_AGENT'])){ $system = "FreeBSD"; } elseif(eregi("openbsd",$_SERVER['HTTP_USER_AGENT'])){ $system = "OpenBSD"; } elseif(eregi("irix",$_SERVER['HTTP_USER_AGENT'])){ $system = "IRIX"; } elseif(eregi("os/2",$_SERVER['HTTP_USER_AGENT'])){ $system = "OS/2"; } elseif(eregi("plan9",$_SERVER['HTTP_USER_AGENT'])){ $system = "Plan9"; } elseif(eregi("unix",$_SERVER['HTTP_USER_AGENT']) || eregi("hp-ux",$_SERVER['HTTP_USER_AGENT']) || eregi("X11",$_SERVER['HTTP_USER_AGENT']) ){ $system = "Unix"; } elseif(eregi("osf",$_SERVER['HTTP_USER_AGENT'])){ $system = "OSF"; } else{$system = "TuMáquinA";} return $system; } function CalculaTiempo($tiempo){ $resto = ''; $resultado = ""; $segundos = $tiempo % 60; $tiempo = $tiempo - $segundos; if ($tiempo) $tiempo = $tiempo/60; if ($segundos){ if ($segundos == 1) $resultado = "$segundos segundo $resultado"; else $resultado = "$segundos segundos $resultado"; if ($tiempo) $resultado = "y $resultado"; } if ($tiempo) { $minutos = $tiempo % 60; $tiempo = $tiempo - $minutos; if ($tiempo) $tiempo = $tiempo / 60; if ($minutos) { if ($minutos == 1) $resultado = "$minutos minuto $resultado"; else $resultado = "$minutos minutos $resultado"; if ($tiempo && !$segundos) $resultado = "y $resultado"; } } if ($tiempo) { $horas = $tiempo % 24; $tiempo = $tiempo - $horas; if ($tiempo) $tiempo = $tiempo / 24; if ($horas) { if ($horas == 1) $resultado = "$horas hora $resultado"; else $resultado = "$horas horas $resultado"; if ($tiempo && !$minutos && !$segundos) $resultado = "y $resultado"; } } if ($tiempo) { if ($tiempo == 1) $resultado = "$tiempo dia $resultado"; else $resultado = "$tiempo dias $resultado"; } return $resultado; } function CuantasDescargas(){ $cuantas = 0; /* if ($gestor = opendir('/home/p2p/.aMule/Temp')) { while (false !== ($archivo = readdir($gestor))) { if ($archivo != "." && $archivo != "..") { if(stristr($file, ".part")) //echo "$archivo\n"; $cuantas++; } } closedir($gestor); }*/ if ($gestor = popen("/usr/bin/amulecmd -c \"show DL\"", "r")){ while (!feof($gestor)) { $buffer = fgets($gestor, 4096); if(stristr($buffer, " > ") && stristr($buffer, "%] ")) { $cuantas++; } } pclose ($gestor); } return $cuantas; } function ConvertBytes($bytes){ if ($bytes >= 1262485504){#Gigas return number_format ( $bytes/1262485504, 2, ",", ".") . " Gigas"; } elseif ($bytes >= 1048576){#Megas return number_format ( $bytes/1048576, 2, ",", ".") . " Megas"; } elseif ($bytes >= 1024){#Kbytes return number_format ( $bytes/1024, 2, ",", ".") . " KBytes"; } else {#bytes return number_format ( $bytes, 0, ",", ".") . " bytes"; }; } $descargas = CuantasDescargas(); $tmpInt = 1; $linea[$tmpInt]="Hola ciberSurfista de " . OssDetect() . " residente en [" . gethostbyaddr(getRealIP()) . "]"; $tmpInt++; $linea[$tmpInt]=""; $tmpInt++; $linea[$tmpInt]="Me llamo " . $sigdat["Name"] . " y estoy con el aMule " . $sigdat["aMuleVer"]; $tmpInt++; if ($sigdat["On"]){ $linea[$tmpInt] = "que lleva " . CalculaTiempo($sigdat["TimeOn"]) . " en marcha"; } else { $linea[$tmpInt] = "que ahora mismo no está funcionando"; } $linea[$tmpInt] .= " en mi Gentoo/Linux"; if ($sigdat["On"]){ $tmpInt++; if ($sigdat["On"]=="1"){ $linea[$tmpInt] = "Lo tengo conectado a " . $sigdat["ServName"] . " [" . $sigdat["ServIp"] .":" . $sigdat["ServPort"] . "] con Id"; switch ($sigdat["Id"]) { case "H": $linea[$tmpInt] .= "Alta"; break; case "L": $linea[$tmpInt] .= "Baja"; break; } $linea[$tmpInt] .= " y la red Kad "; switch ($sigdat["Kad"]) { case "0": $linea[$tmpInt] .= "Desconectada"; break; case "1": $linea[$tmpInt] .= "en firewalled"; break; case "2": $linea[$tmpInt] .= "bien conectada"; break; } } else {$linea[$tmpInt] = "y en estos momento está estableciendo una conexión ... ";} $tmpInt++; if ($descargas == 0) { $linea[$tmpInt] = "Es estos momentos no estoy descargándome nada."; } else { $tmpStr="archivo"; if ($descargas > 1) $tmpStr = "archivos"; $linea[$tmpInt] = "En estos momentos me estoy descangando $descargas $tmpStr."; } $tmpInt++; $linea[$tmpInt] = "compartiendo " . $sigdat["shareF"] . " archivos y con " . $sigdat["CliNum"] . " clientes en cola "; if ($descargas > 0) $linea[$tmpInt] .= " [Bajada: " . $sigdat["Down"] . " kb/s "; else $linea[$tmpInt] .= " ["; $linea[$tmpInt] .= "Subida: " . $sigdat["Up"] . " kb/s]"; $tmpInt++; $linea[$tmpInt] = "Se ha descargado en esta sesión " . ConvertBytes($sigdat["SesiDown"]) . " sumando un total descagado de " . ConvertBytes($sigdat["TotalDown"]) . "."; $tmpInt++; $linea[$tmpInt] = "Subiendo a la red en esta sesión " . ConvertBytes($sigdat["SesiUp"]) . " con lo que se suma un total subido de " . ConvertBytes($sigdat["TotalUp"]) . "."; }; $ancho = 0; $alto = 0; for ($a=1;$a<=$tmpInt;$a++) { $tmpBox= imagettfbbox (12,0,"./trebucit.ttf",$linea[$a]); if ( $tmpBox[2]-$tmpBox[0] > $ancho ) $ancho = $tmpBox[2]-$tmpBox[0]; if ( $tmpBox[3]-$tmpBox[5] > $alto ) $alto = $tmpBox[3]-$tmpBox[5]; # echo $linea[$a]. "
\n"; } $altoTotal = $alto * $tmpInt; $im = imagecreate($ancho+4,$altoTotal+4); $oscuro = imagecolorallocate($im,33,57,41); $blanco = imagecolorallocate($im,255,255,255); $transparente = imagecolortransparent ($im, $blanco); imagefill($im,0,0,$transparente); for ($a=1;$a<=$tmpInt;$a++) { imagettftext($im,12,0,2,$alto*$a,$oscuro,"./trebucit.ttf",$linea[$a]); } //Mostramos el grafico en pantalla imagepng($im); //Liberamos memoria imagedestroy($im); ?>