aMule Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're back! (IN POG FORM)

Author Topic: [off-topic] aMule Signature  (Read 4216 times)

AnimAlf

  • Full Member
  • ***
  • Karma: 3
  • Offline Offline
  • Posts: 225
    • Home
[off-topic] aMule Signature
« on: April 29, 2006, 10:35:48 AM »

Hola,
vereis, estoy aprendiendo a utilizar las funciones para php de la librería GD, y ¡cómo no! aprovecho para ello el archivo ~/.aMule/amulesig.dat

El objetivo es crear una imagen dinámica, que muestre unas características o otras, dependiendo de quien la visualice y de la información que se quiera mostrar.

Por ahora, sólo he tratado el texto, de una forma fundamental y pocas condiciones. Pero aspiro crear varias ramificaciones en las que no sólo se afecte al texto, si no a las imágenes que se dibujarán. Y, pues he pensado que si a alguien más le gustaría aprender a crear su propias imágenes dinámicas, pues quizás pueda interesarle echarle un ojo al código, ya sean para aMule o para cualquier otra cosa que pase por la mente del desarrollador.

El código fuente del archivo estará aquí. Y aquí la muestra del resultado del script. (Acabo de empezar, ahora está todo un poco cutre)

Poco a poco espero conseguir una imagen bien curiosa y moldeable para que pueda ser utilizada por qualquier otra persona con su propio texto colocando ademas las 17 opciones como etiquetas y opcionales (bueno o eso me gustaría conseguir ...  (variar imagenes dependiendo de la estación del año, de la zona horaria ...  )  (quizás debería volver a poner los pies en suelo ... no se))

Disculpad el off-topic (or kill me please)

bye  ;)

wuischke

  • Developer
  • Hero Member
  • *****
  • Karma: 183
  • Offline Offline
  • Posts: 4292
Re: [off-topic] aMule Signature
« Reply #1 on: April 29, 2006, 10:55:34 AM »

Hay amps (PHP) que puede hacer unas cosas que quieres. :)
No sé si hay que desplazar al foro off-topic, porque es en Español...voy a esperar otra mod ;)
Logged

AnimAlf

  • Full Member
  • ***
  • Karma: 3
  • Offline Offline
  • Posts: 225
    • Home
Re: [off-topic] aMule Signature
« Reply #2 on: December 16, 2007, 03:48:05 PM »

Finalmente la cosa quedó así, por si a alguien le interesa.
Code: [Select]
<?php
#
# file: aMSig.php
# author: AnimAlf
#
# This lines are under the GNU General Public License.
# http://www.gnu.org/copyleft/gpl.html
#

header("Content-type: image/PNG");

function 
chomp(&$string){
  if (
is_array($string)){
    foreach(
$string as $i => $val){
      
$endchar chomp($string[$i]);
    }
  } else {
    
$endchar substr("$string"strlen("$string") - 11);
    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 ($lineafgets($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\" -P PASSWORD""r")){
    while (!
feof($gestor)) {
      
$buffer fgets($gestor4096);
      if(
stristr($buffer" > ") && stristr($buffer"%] ")) {
        
$cuantas++;
      }
    }
    
pclose ($gestor);
  }

  return 
$cuantas;
}

function 
ConvertBytes($bytes){
  if (
$bytes >= 1262485504){#Gigas
    
return number_format $bytes/12624855042","".") . " Gigas";
  } elseif (
$bytes >= 1048576){#Megas
    
return number_format $bytes/10485762","".") . " Megas";
  } elseif (
$bytes >= 1024){#Kbytes
    
return number_format $bytes/10242","".") . " KBytes";
  } else {
#bytes
    
return number_format $bytes0","".") . " 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 descargado 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++) {
  
$tmpBoximagettfbbox (9,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]. "<br>\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);

$insert imagecreatefrompng("insert1.png");
imagecolortransparent($insert,imagecolorexact($insert,255,0,255));
$insert_x imagesx($insert);
$insert_y imagesy($insert);

//imagealphablending($insert, 1);

$un_x imagesx($im);
//$un_y = imagesy($im);

$un_x -= $insert_x;
//$un_y = $un_y - $insert_y;

imagecopymerge($im,$insert,$un_x,0,0,0,$insert_x,$insert_y,100);

$insert2 imagecreatefrompng("gnu-head.png");
imagecolortransparent($insert2,imagecolorexact($insert,255,0,255));
$insert_x imagesx($insert2);
$insert_y imagesy($insert2);
$un_y imagesy($im);
$un_y $un_y $insert_y;

imagecopymerge($im,$insert2,$insert_x*3,$un_y,0,0,$insert_x,$insert_y,100);

for (
$a=1;$a<=$tmpInt;$a++) {
  
imagettftext($im,9,0,2,$alto*$a,$oscuro,"./trebucit.ttf",$linea[$a]);
}


//Mostramos el grafico en pantalla
imagepng($im);

//Liberamos memoria
imagedestroy($im);
?>

« Last Edit: December 16, 2007, 06:58:24 PM by AnimAlf »
Logged