fixed spacing master
fixed spacing

file:a/PHPDc.php -> file:b/PHPDc.php
--- a/PHPDc.php
+++ b/PHPDc.php
@@ -1,69 +1,68 @@
-<?php

-

-//=============================//

-//                             //

-//   PHPDc v0.2                //

-//   PHPDc Manual Bot          //

-//   PHPDc.php                 //

-//   by [RO]VeNoM              //

-//   razvan_stanga@yahoo.com   //

-//                             //

-//       MADE IN ROMANIA       //

-//                             //

-//=============================//

-

-error_reporting  (E_ERROR | E_WARNING | E_PARSE);

-

-@set_time_limit(0);

-

-//---------------

-// Include Config

-//---------------

-

-require ("includes/PHPDc.Config.php");

-

-//----------------

-// Check User/Pass

-//----------------

-

-if ( (!isset($PHP_AUTH_USER)) || !(($PHP_AUTH_USER == $config['admin_user']) && ($PHP_AUTH_PW == $config['admin_password'])) ) {

-		header("WWW-Authenticate: Basic entrer=\"Form2txt admin\"");

-		header("HTTP/1.0 401 Unauthorized");

-		exit;

-}

-

-//--------------------

-// Include PHPDc Class

-//--------------------

-

-require ("includes/PHPDc.Class.php");

-

-foreach ($hub as $k => $v) {

-

-//------------

-// Start PHPDc

-//------------

-

-$PHPDc = new PHPDc;

-

-$config['hub'] = $v['hub'];

-$config['port'] = $v['port'];

-$config['name'] = $v['name'];

-$config['desc'] = $v['desc'];

-$config['template'] = $v['template'];

-$config['time'] = time ();

-

-$PHPDc->config = $config;

-

-$PHPDc->hub = $hub;

-

-$PHPDc->debuglog ('----- '.date("Y-m-d H:i:s").' -----');

-

-$PHPDc->connect($config['hub'], $config['port']);

-

-$PHPDc->listen ();

-

-}

-

-?>

+<?php
 
+//=============================//
+//                             //
+//   PHPDc v0.2                //
+//   PHPDc Manual Bot          //
+//   PHPDc.php                 //
+//   by [RO]VeNoM              //
+//   razvan_stanga@yahoo.com   //
+//                             //
+//       MADE IN ROMANIA       //
+//                             //
+//=============================//
+
+error_reporting  (E_ERROR | E_WARNING | E_PARSE);
+
+@set_time_limit(0);
+
+//---------------
+// Include Config
+//---------------
+
+require ("includes/PHPDc.Config.php");
+
+//----------------
+// Check User/Pass
+//----------------
+
+if ( (!isset($PHP_AUTH_USER)) || !(($PHP_AUTH_USER == $config['admin_user']) && ($PHP_AUTH_PW == $config['admin_password'])) ) {
+		header("WWW-Authenticate: Basic entrer=\"Form2txt admin\"");
+		header("HTTP/1.0 401 Unauthorized");
+		exit;
+}
+
+//--------------------
+// Include PHPDc Class
+//--------------------
+
+require ("includes/PHPDc.Class.php");
+
+foreach ($hub as $k => $v) {
+
+//------------
+// Start PHPDc
+//------------
+
+$PHPDc = new PHPDc;
+
+$config['hub'] = $v['hub'];
+$config['port'] = $v['port'];
+$config['name'] = $v['name'];
+$config['desc'] = $v['desc'];
+$config['template'] = $v['template'];
+$config['time'] = time ();
+
+$PHPDc->config = $config;
+
+$PHPDc->hub = $hub;
+
+$PHPDc->debuglog ('----- '.date("Y-m-d H:i:s").' -----');
+
+$PHPDc->connect($config['hub'], $config['port']);
+
+$PHPDc->listen ();
+
+}
+
+?>

--- a/PHPDc_Cron.php
+++ b/PHPDc_Cron.php
@@ -1,94 +1,93 @@
-<?

-

-//=============================//

-//                             //

-//   PHPDc v0.2                //

-//   PHPDc Cron Job Bot        //

-//   PHPDc_Cron.php            //

-//   by [RO]VeNoM              //

-//   razvan_stanga@yahoo.com   //

-//                             //

-//       MADE IN ROMANIA       //

-//                             //

-//=============================//

-

-error_reporting  (E_ERROR | E_WARNING | E_PARSE);

-

-@set_time_limit(0);

-

-//---------------

-// Include Config

-//---------------

-

-require ("includes/PHPDc.Config.php");

-

-//--------------------

-// Include PHPDC Class

-//--------------------

-

-require ("includes/PHPDc.Class.php");

-

-//-----------------------

-// Include Cron Job Class

-//-----------------------

-

-require ("includes/PHPDc.Cron.php");

-

-//----------------

-// Start PHPDcCron

-//----------------

-

-$PHPDcCron = new PHPDcCron;

-

-//-----------------

-// Start Time Cache

-//-----------------

-

-$time_cache = array ();

-

-require ("html/time_cache.php");

-

-$dowrite = 0;

-

-$time_temp = time ();

-

-if ( $time_cache[ $config['cronjob'] ] <= $time_temp ) {

-$time_cache[ $config['cronjob'] ] = $time_temp + $config['cronjob'];

-

-// Writing new time

-

-$PHPDcCron->do_write ($time_cache);

-

-foreach ($hub as $k => $v) {

-

-//------------

-// Start PHPDc

-//------------

-

-$PHPDc = new PHPDc;

-

-$config['hub'] = $v['hub'];

-$config['port'] = $v['port'];

-$config['name'] = $v['name'];

-$config['desc'] = $v['desc'];

-$config['template'] = $v['template'];

-$config['time'] = time ();

-

-$PHPDc->config = $config;

-

-$PHPDc->hub = $hub;

-

-$PHPDc->debuglog ('----- '.date("Y-m-d H:i:s").' -----');

-

-$PHPDc->connect($config['hub'], $config['port']);

-

-$PHPDc->listen ();

-

-}

-

-}

-

-// End Cache

-

-?>

+<?
 
+//=============================//
+//                             //
+//   PHPDc v0.2                //
+//   PHPDc Cron Job Bot        //
+//   PHPDc_Cron.php            //
+//   by [RO]VeNoM              //
+//   razvan_stanga@yahoo.com   //
+//                             //
+//       MADE IN ROMANIA       //
+//                             //
+//=============================//
+
+error_reporting  (E_ERROR | E_WARNING | E_PARSE);
+
+@set_time_limit(0);
+
+//---------------
+// Include Config
+//---------------
+
+require ("includes/PHPDc.Config.php");
+
+//--------------------
+// Include PHPDC Class
+//--------------------
+
+require ("includes/PHPDc.Class.php");
+
+//-----------------------
+// Include Cron Job Class
+//-----------------------
+
+require ("includes/PHPDc.Cron.php");
+
+//----------------
+// Start PHPDcCron
+//----------------
+
+$PHPDcCron = new PHPDcCron;
+
+//-----------------
+// Start Time Cache
+//-----------------
+
+$time_cache = array ();
+
+require ("html/time_cache.php");
+
+$dowrite = 0;
+
+$time_temp = time ();
+
+if ( $time_cache[ $config['cronjob'] ] <= $time_temp ) {
+    $time_cache[ $config['cronjob'] ] = $time_temp + $config['cronjob'];
+    
+    // Writing new time
+    
+    $PHPDcCron->do_write ($time_cache);
+    
+    foreach ($hub as $k => $v) {
+    
+        //------------
+        // Start PHPDc
+        //------------
+        
+        $PHPDc = new PHPDc;
+        
+        $config['hub'] = $v['hub'];
+        $config['port'] = $v['port'];
+        $config['name'] = $v['name'];
+        $config['desc'] = $v['desc'];
+        $config['template'] = $v['template'];
+        $config['time'] = time ();
+        
+        $PHPDc->config = $config;
+        
+        $PHPDc->hub = $hub;
+        
+        $PHPDc->debuglog ('----- '.date("Y-m-d H:i:s").' -----');
+        
+        $PHPDc->connect($config['hub'], $config['port']);
+        
+        $PHPDc->listen ();
+    
+    }
+
+}
+
+// End Cache
+
+?>

--- a/html/time_cache.php
+++ b/html/time_cache.php
@@ -1,3 +1,3 @@
-<?

-$time_cache['900']	=	'1066059889';

+<?
+$time_cache['900']	=	'1066059889';
 ?>

--- a/includes/PHPDc.Class.php
+++ b/includes/PHPDc.Class.php
@@ -1,872 +1,871 @@
-<?php

-

-//=============================//

-//                             //

-//   PHPDc v0.2                //

-//   PHPDc Class file          //

-//   PHPDc.Class.php           //

-//   by [RO]VeNoM              //

-//   razvan_stanga@yahoo.com   //

-//                             //

-//       MADE IN ROMANIA       //

-//                             //

-//=============================//

-

-class PHPDc {

-

-    var $socket;

-    var $usesockets;

-    var $config;

-    var $hub;

-    var $state = FALSE;

-    var $nrconnect = 1;

-    var $userdata = array ();

-    var $sendstats = array ();

-    var $statsfiles = array ();

-    var $ftp_conn;

-

-//-------------------------------

-// Connect to a given host / port

-//-------------------------------

-

-function connect ($host, $port) {

-

-  $address = gethostbyname($host);

-

-			if(array_search('sockets',get_loaded_extensions()) !== FALSE) {

-			

-			    $this->debuglog ("NR Connect : ".$this->nrconnect, "\r\n");

-			    $this->debuglog ("WARNING: your PHP build supports real sockets.");			

-				$this->usesockets = 1;

-				$this->nrconnect++;

-				

-                $this->socket = socket_create(AF_INET, SOCK_STREAM, 0);

-                

-                if (!$this->socket) {

-

-                  $this->debuglog ('Failed to create socket '.$adress);

-			      $this->debuglog ('Error : '. socket_strerror(socket_last_error()) );

-			      $this->debuglog ('Error NR : '. socket_last_error() );

-			      

-                }

-

-                if (!socket_connect($this->socket, $address, $port)) {

-

-                  $this->debuglog ('Failed to connect to '.$adress);

-			      $this->debuglog ('Error : '. socket_strerror(socket_last_error()) );

-			      $this->debuglog ('Error NR : '. socket_last_error() );

-			      

-                }

-                /*

-                if (!socket_set_nonblock ($this->socket)) {

-

-                  $this->debuglog ('Sockets are blocked');

-			      $this->debuglog ('Error : '. socket_strerror(socket_last_error()) );

-			      $this->debuglog ('Error NR : '. socket_last_error() );

-                }

-                */

-                  $this->debuglog ('Succesfully connected to '. $host .' ('.$address.'), port '.$port);

-                

-	            } else {

-			

-			      $this->debuglog ("NR Connect : ".$this->nrconnect, "\r\n");

-				  $this->debuglog ("WARNING: your PHP build doesn't support real sockets.");				

-				  $this->usesockets = 0;

-				  $this->nrconnect++;

-				

-                if (!$this->socket = @pfsockopen ($address , $port, $errno, $errstr, 30)) {

-

-                  $this->debuglog ('Failed to create socket'. $errno .', '. $errstr);

-                

-                }

-

-                if (!socket_set_blocking ($this->socket, FALSE)) {

-

-                  $this->debuglog ('Socket Stream is blocked');

-                

-                }

-                

-                  //socket_set_timeout ($this->socket, 5);

-                  $this->debuglog ('Succesfully connected to '. $host .' ('.$address.'), port '.$port);

-			    }

-}

-

-

-//-------------

-// Close socket

-//-------------

-

-function close () {

-

-  if ($this->usesockets == 1)       { socket_close($this->socket); }

-  else { fclose ($this->socket); }

-

-}

-

-

-//-------

-// Listen

-//-------

-

-function listen() {

-

-	if($this->state() == TRUE) {

-	  $this->receive();

-	  return TRUE;

-	} else {

-		return FALSE;

-	}

-}

-	

-

-//-------------

-// Recieve data

-//-------------

-

-function receive () {

-

-while($this->state() == TRUE) {

-

-  if ($this->config['time'] + $this->config['timetostay'] <= time() ) {

-

-   $this->do_stats ();

-   $this->send_data ();

-   

-   $this->debuglog ('### Done STATS for '. $this->config['hub']);

-   

-   $this->close ();

-   $this->debuglog ("Disconnected from ".$this->config['hub']);

-   

-   break;

-

-  }

-                

-  usleep ($this->config['receivesleep']);

-  

-  if ($this->usesockets == 1)  {

-

-  if (str_replace( ".", "", phpversion () ) >= 430 ) {

-    $r = array($this->socket);

-    socket_select($r, $w, $except = NULL, 1);

-  }

-

-    if ($_DATA = @socket_read ($this->socket, 1024)) {

-        

-			flush ();

-			$buffer .= $_DATA;	

-			

-			if (substr($buffer,-1) == "|") {

-				$this->do_stuff($buffer);

-				$buffer = "";

-			}

-			

-			if (strlen($buffer) > (50*1024)) {

-				$buffer = "";

-			}

-

-    } else {

-

-	  $this->debuglog ('Error : '. socket_strerror(socket_last_error()) );

-	  $this->debuglog ('Error NR : '. socket_last_error() );

-

-      $this->send('$Quit '.$this->config['nick'].'');

-

-      $this->close();

-

-      sleep($this->config['reconnect_after']);

-

-      $this->connect($this->config['hub'], $this->config['port']);

-

-    }

-

-  } else {

-

-    if ($_DATA = @fgets ($this->socket, 1024)) {

-        

-			flush();

-			$buffer .= $_DATA;	

-			

-			if (substr($buffer,-1) == "|") {

-				$this->do_stuff($buffer);

-				$buffer = "";

-			}

-			

-			if (strlen($buffer) > (50*1024)) {

-				$buffer = "";

-			}

-

-    } else {

-

-      $this->send('$Quit '.$this->config['nick'].'');

-

-      $this->close();

-

-      sleep($this->config['reconnect_after']);

-

-      $this->connect($this->config['hub'], $this->config['port']);

-

-    }

-

-  }

-  

-}

-  

-}

-

-

-//--------------------

-// Send data to socket

-//--------------------

-

-function send ($str) {

-

-  //$str = trim($str);

-  //if ($str{strlen ($str)-1} != "|") {$str .= "|";}

-

-  $str .= "|";

-  usleep($this->config['sendsleep']);

-  if ($this->usesockets == 1) {

-      $res = @socket_write($this->socket, $str, strlen($str));

-      if (!$res) {$this->debuglog ("CAN'T SEND : ". $str);}

-      } else {

-          $res = @fwrite($this->socket, $str, strlen($str));

-          if (!$res) {$this->debuglog ("CAN'T SEND : ". $str);}

-          }

-          

-  $this->debuglog ('SEND : '.$str);

-

-}

-

-

-//---------

-// Do Stuff

-//---------

-

-function do_stuff ($buffer) {

-

-		$_CMDLIST=explode("|",$buffer);

-		while (list($_tmpstr,$_COMMAND)=each($_CMDLIST)) {

-			$_CMD = $_COMMAND;

-			if (!$_CMD) {continue;}

-

-			$_PARAMSLIST=array();

-			$_PARAMS="";

-			

-			$this->debuglog("RECEIVE : " . $_CMD . "");

-			

-			$_tmpArr=explode(" ",$_CMD);

-			$_CMD=trim(strtoupper($_tmpArr[0]));

-			array_shift($_tmpArr);

-			$_PARAMS=trim(implode(" ",$_tmpArr));

-			

-			if ($_CMD{0} == "<") {

-				

-			} else {

-				$_tmpArr=explode("$",$_CMD);

-				array_shift($_tmpArr);

-				$_CMD=trim(implode(" ",$_tmpArr));

-

-				switch($_CMD) {

-					case "LOCK":

-						$this->send ("\$Key ".$this->lock2key ($_PARAMS)."");

-						$this->send ("\$ValidateNick {$this->config['nick']}");

-						break;

-					case "HUBNAME":

-						//$this->send ("\$ValidateNick {$this->config['nick']}");

-						break;

-					case "GETPASS":

-						$this->send ("\$MyPass {$this->config['password']}");

-						break;

-					case "BADPASS":

-						$this->debuglog ("LOGIN FAILED! (User {$this->config['nick']} - Pass {$this->config['password']})");

-						$this->send ("\$Quit {$this->config['nick']}");

-						break;

-					case "LOGEDIN":

-						$this->debuglog ("LOGIN SUCCESSFUL! (User {$this->config['nick']} - Pass {$this->config['password']})");

-						break;

-					case "HELLO":

-						if ($_PARAMS == $this->config['nick']) {			

-							$this->send ("\$Version {$this->config['version']}");

-							$this->send ("\$GetNickList");

-							$this->send ("\$MyINFO \$ALL {$this->config['nick']} {$this->config['description']}$ \${$this->config['speed']}\${$this->config['email']}\${$this->config['sharesize']}$");

-						}

-						break;

-					case "NICKLIST":

-						$_NICKLIST=explode("$$",$_PARAMS);

-						while (list ($_tmpstr,$nickname) = each($_NICKLIST)) {

-							if (!$nickname) {continue;}

-							if ($nickname == $this->config['nick']) {continue;}

-							$this->$userdata[$nickname] = array ();

-							$this->$userdata[$nickname]['nick'] = $nickname;

-							$this->send ("\$GetINFO {$nickname} {$this->config['nick']}");

-						}

-						break;

-					Case "OPLIST":

-						$_OPLIST=explode("$$",$_PARAMS);

-						while (list ($_tmpstr,$nickname) = each($_OPLIST)) {

-							$this->$userdata[$nickname]['IsOp'] = 1;

-						}

-						break;

-					Case "MYINFO":					

-						if (preg_match("/\\\$ALL ([^ \$\|]+) (.*)\\\$ \\\$(.+).\\\$(.+)\\\$(.+)\\\$/i",$_PARAMS,$tmpARR)){

-						$this->userdata[$tmpARR[1]]['description'] = $tmpARR[2];

-						$this->userdata[$tmpARR[1]]['speed'] = $tmpARR[3];

-						$this->userdata[$tmpARR[1]]['email'] = $tmpARR[4];

-						$this->userdata[$tmpARR[1]]['sharesize'] = $tmpARR[5];

-						$this->debuglog("User Data : ".$tmpARR[1]."|".$tmpARR[2]."|".$tmpARR[3]."|".$tmpARR[4]."|".$tmpARR[5]);

-						}

-						$tmpARR = array ();

-						if (preg_match("/\\\$ALL ([^ \$\|]+) (.*)\\\$ \\\$(.+).\\\$\\\$(.+)\\\$/i",$_PARAMS,$tmpARR)){

-						$this->userdata[$tmpARR[1]]['description'] = $tmpARR[2];

-						$this->userdata[$tmpARR[1]]['speed'] = $tmpARR[3];

-						$this->userdata[$tmpARR[1]]['sharesize'] = $tmpARR[4];

-						$this->debuglog("User Data : ".$tmpARR[1]."|".$tmpARR[2]."|".$tmpARR[3]."||".$tmpARR[4]);

-						}						

-						break;

-					Case "QUIT":

-						

-						break;

-					Case "SEARCH":

-						preg_match("/(.+):(.+) (.)\?(.)\?([0-9]+)\?(.)\?(.*)/i",$_PARAMS,$tmpARR);

-						$tmpARR[7]=str_replace("$"," ",$tmpARR[7]);

-						break;

-					case "SR":

-						break;

-					case "FORCEMOVE":

-						$this->debuglog("REDIRECTING NOT SUPPORTED! DISCONNECTING!");

-						$this->close ();

-					case "TO:":

-						

-						break;

-					default:

-						$this->debuglog("Unknown CMD " . $_CMD . "");

-						break;

-				}

-			}			

-		}

-}

-

-	

-//------

-// State

-//------

-

-function state (){

-

-  $result = $this->updatestate();

-		

-    if($result == TRUE) {

-        return TRUE;

-    }

-    else {

-        return FALSE;

-    }

-}

-

-

-//-------------

-// Update State

-//-------------

-

-function updatestate() {

-

-  $type = get_resource_type($this->socket);

-

-    if( is_resource ($this->socket) && $this->socket !== FALSE && ( $type == 'socket' || $type == 'Socket' || $type == 'stream' || $type == 'Stream') ) {

-      $this->state = TRUE;

-		return TRUE;

-    } else {

-      $this->state = FALSE;

-		return FALSE;

-    }

-

-}

-

-

-//----------

-// Debug Log

-//----------

-

-function debuglog ($stuff, $f='') {

-

-  if ($this->config['debug']) {

-    $this->writetolog ($f.$stuff."\r\n");

-    flush ();

-    echo $stuff."<br>";

-  }

-

-}

-

-

-//--------------

-// Write to file

-//--------------

-

-function writetolog ($data) {

-

-  if ($data!="") {

-

-    $filenum=fopen("logs/".$this->config['log']."","a");

-

-    fwrite($filenum,$data);

-

-    fclose($filenum);

-

-  }

-

-}

-

-

-//------------

-// Decode Lock

-//------------

-

-function lock2key($_LOCK) {

-

-   $this->debuglog ('Lock & Pk : '.$_LOCK);

-

-   $pk = stristr ($_LOCK, 'Pk=');

-   $this->debuglog ('Pk : '.$pk);

-

-   $_LOCK = str_replace ($pk, '', $_LOCK);

-

-   $_LOCK = substr ($_LOCK, 0, -1);

-   $this->debuglog ('Lock : '.$_LOCK);

-

-   $lockLength = strlen ($_LOCK);

-

-   $h = ord($_LOCK{0}) ^ ord( $_LOCK{ $lockLength - 1} ) ^ ord( $_LOCK{ $lockLength - 2} ) ^ 5;

-

-   //echo $h . "<br>";

-

-    while ($h > 255) {$h = $h - 256;}

-

-    $h = (($h<<4) & 240) | (($h>>4) & 15);

-

-	$a = $h;

-	

-	if ($a == '126' or // '~'

-	    $a == '124' or // '|'

-	    $a == '96' or  // '`'

-	    $a == '36' or  // '$'

-	    $a == '5' or   // '^E'

-	    $a == '0')     // NUL

-	{

-	  $LockToKey = "/%DCN";

-

-	  if ($a < 100)

-	    $LockToKey .="0";

-	  if ($a < 10)

-	    $LockToKey .="0";

-      $LockToKey .= $a; // As a string integer

-	  $LockToKey .= "%/";	

-	} else {

-	  $LockToKey = chr ($a);  // No transformation.

-	}

-

-   for ($j = 1; $j < strlen($_LOCK); $j++) {

-      $h = ord($_LOCK{$j}) ^ ord($_LOCK{$j-1});

-

-   while ($h > 255) {$h = $h - 256;}

-

-      $h = (($h<<4) & 240) | (($h>>4) & 15);

-

-      //echo $j . " - " . ($h*16) . "<br>";

-

-	  $a = $h;

-	

-	if ($a == '126' or // '~'

-	    $a == '124' or // '|'

-	    $a == '96' or  // '`'

-	    $a == '36' or  // '$'

-	    $a == '5' or   // '^E'

-	    $a == '0')     // NUL

-	{

-	  $LockToKey .= "/%DCN";

-

-	  if ($a < 100)

-	    $LockToKey .="0";

-	  if ($a < 10)

-	    $LockToKey .="0";

-      $LockToKey .= $a; // As a string integer

-	  $LockToKey .= "%/";	

-	} else {

-	  $LockToKey .= chr ($a);  // No transformation.

-	}

-   }

-

-   return $LockToKey;

-}

-

-//--------------------------------------

-// Start Lode, Pharse -> Template

-//--------------------------------------

-

-function lode_template ($t="") {

-

-    $file = "templates/".$t.".tpl";

-	

-	if ( file_exists($file) )

-	{

-		if ( $T = fopen($file, 'r') )

-		{

-			$template = fread( $T, filesize($file) );

-			fclose($T);

-		}

-		else

-		{

-			$this->debuglog ("Can't open template");

-		}

-	}

-	else

-	{

-		$this->debuglog ("Template doesn't exist");

-	}

-	

-	return $template;

-

-}

-

-function pharse_template( $template, $assigned=array() )

-{

-	

-	foreach( $assigned as $word => $replace)

-	{

-		$template = preg_replace( "/\{$word\}/i", "$replace", $template );

-	}

-	

-	return $template;

-}

-

-

-//-------------------

-// Start Write 2 File

-//-------------------

-

-function writetofile ($path,$data,$backup=0) {

-

-  if (file_exists($path)!=0) {

-    if ($backup==1) {

-      $filenamenew=$path."venom";

-

-      rename ($path,$filenamenew);

-    } else {

-      unlink($path);

-    }

-  }

-

-  if ($data!="") {

-

-    $filenum=fopen($path,"w");

-

-    fwrite($filenum,$data);

-

-    fclose($filenum);

-

-  }

-

-}

-

-

-//-----

-// Size

-//-----

-

-function Size($size) {

-    $mb = 1024*1024;

-    $gb = 1024*1024*1024;

-    $tb = 1024*1024*1024*1024;

-    if ( $size >= $tb ) {

-        $mysize = sprintf ("%01.2f",$size/$tb) . " TB";

-    } elseif ( $size >= $gb ) {

-        $mysize = sprintf ("%01.2f",$size/$gb) . " GB";

-    } elseif ( $size >= $mb ) {

-        $mysize = sprintf ("%01.2f",$size/$mb) . " MB";

-    } elseif ( $size >= 1024 ) {

-        $mysize = sprintf ("%01.2f",$size/1024) . " Kb";

-    } else {

-        $mysize = $size . " bytes";

-    }

-    return $mysize;

-}

-

-

-//------

-// Pages

-//------

-

-function page ($total_raw, $link, $offset, $pagina, $show = 1) {

-	

-	$pagenavpages = $this->config['navpages'];

-

-	if ($total_raw <= $offset) {

-		return "";

-	}

-	

-	if ($show == 1) {

-	$minim = ($pagina - 1) * $offset + 1;

-	$maxim = $minim + $offset - 1;

-	if ($total_raw <= $maxim) {$maxim = $total_raw;}

-	$showing = "Showing $minim - $maxim ($total_raw) |";} else {$showing = "";}

-

-	$totalpages = ceil($total_raw/$offset);

-

-	if ($pagina>1) {

-		$prevpage = $pagina-1;

-		$prevlink = "<a href=\"$link$prevpage.html\" title=\"Previous Page\">&laquo;</a>\r\n";

-	}

-	if ($pagina<$totalpages) {

-		$nextpage = $pagina+1;	

-		$nextlink = "<a href=\"$link$nextpage.html\" title=\"Next Page\">&raquo;</a>\r\n";		

-	}

-	while ($curpage++<$totalpages) {

-		if ( ( $curpage <= $pagina-$pagenavpages || $curpage >= $pagina+$pagenavpages ) && $pagenavpages!=0 ) {

-			if ($curpage==1) {

-				$firstlink = "<a href=\"$link$curpage.html\" title=\"First Page\">&laquo; First</a> ...\r\n";				

-			}

-		    if ($curpage==$totalpages) {

-		        $lastlink = "... <a href=\"$link$curpage.html\" title=\"Last Page\">Last &raquo;</a>\r\n";				

-			}

-		} else {

-			if ($curpage==$pagina) {

-				$pagenav .= "<font size=\"2\">[$curpage]</font>\r\n";			

-			} else {

-				$pagenav .= "<a href=\"$link$curpage.html\">$curpage</a>\r\n";

-			}

-		}

-	}

-	$pagenav = "<br><br>\r\nPages: $totalpages | $showing\r\n<b>\r\n$firstlink$prevlink$pagenav$nextlink$lastlink</b>\r\n";

-

-	return $pagenav;

-

-}

-

-

-//----------

-// Anti Spam

-//----------

-

-function AntiSpam ($email="", $name=""){

-

-    if ($email != "") {

-

-        for ( $i=0; $i < strlen ( $email ); $i++ ) {

-

-          $A .= "&#". ord( substr($email, $i) ) .";";

-

-         }

-    

-    }

-             

-    if ($name != "") {

-

-         for ( $i=0; $i < strlen ( $name ); $i++ ) {

-

-          $B .= "&#". ord( substr($name, $i) ) .";";

-

-         }

-    }

-    

-    if ($B != "" and $A == "") {return "none";}

-    

-    if ($B == "" and $A != "") {$B = $A;}

-    

-    if ($B == "" and $A == "") {return "none";}

-             

-    return "<SCRIPT LANGUAGE=\"JavaScript\">\r\ndocument.write('<a href=\"' + 'mailto:' + '".$A."' + '\">' + '".$B."' + '</a>');\r\n</script>";

-

-

-}

-

-

-//-----------

-// FTP Upload

-//-----------

-

-function ftp_start () {

-

-    $this->ftp_conn = ftp_connect ($this->config['ftp_server'], $this->config['ftp_port']);

-    $login_result = ftp_login($this->ftp_conn, $this->config['ftp_user'], $this->config['ftp_pass']);

-    

-}

-

-function ftp_upload ($filename, $filesource) {

-

-    $upload = ftp_put ($this->ftp_conn, $filename, $filesource, FTP_BINARY);

-    

-}

-

-function ftp_end () {

-

-    ftp_quit ($this->ftp_conn);

-        

-}

-

-

-//---------------

-// Make The Stats

-//---------------

-

-function do_stats () {

-

-                $tpl = $this->lode_template ($this->config['template']);

-                $tpl_user = $this->lode_template ($this->config['template']."-user");

-                $tpl_index = $this->lode_template ("index");

-                $tpl_counter = $this->lode_template ("counter");

-

-                $users = count ($this->userdata);

-

-                ksort ($this->userdata);

-

-                $j = 1;

-                $i = 1;

-                $x = 1;

-                $templates = array ();

-                $content = "";

-                $select = "";

-

-                $select .= "<option value=\"#\">Select Hub</option>\r\n";

-

-                foreach ($this->hub as $hub) {

-                  $select .= "<option value=\"{site_url}html/".$hub['hub']."/1.html\">".$hub['name']."</option>\r\n";

-                }

-

-                $rpli = array (

-                       "select" => $select,

-                       "counter" => $tpl_counter,

-                       "phpdc_author" => $this->AntiSpam($this->config['author_email'], $this->config['author_name']),

-                       "phpdc_version" => $this->config['version'],

-                       "site_url" => $this->config['site_url'],

-                );

-

-                $tpl_index = $this->pharse_template ($tpl_index, $rpli);

-

-                $this->writetofile ("html/index.html", $tpl_index);

-

-                foreach ($this->userdata as $k => $v) {

-

-                $rpl = array (

-                       "nick" => $k,

-                       "description" => $v[description],

-                       "speed" => $v[speed],

-                       "email" => $this->AntiSpam($v[email], $k),

-                       "sharesize" => $this->Size ($v[sharesize]),

-                );

-

-                  $content .= $this->pharse_template ($tpl_user, $rpl);

-                  $share += $v[sharesize];

-

-                if ($j >= $this->config['onpage'] or $x >= $users) {

-

-                $rplt = array (

-                       "content" => $content,

-                       "counter" => $tpl_counter,

-                       "users" => $users,

-                       "select" => $select,

-                       "hub" => $this->config['hub'],

-                       "port" => $this->config['port'],

-                       "name" => $this->config['name'],

-                       "desc" => $this->config['desc'],

-                       "phpdc_author" => $this->AntiSpam($this->config['author_email'], $this->config['author_name']),

-                       "phpdc_version" => "<a href=\"http://www.computergames.ro/venom/PHPDc/\">".$this->config['version']."</a>",

-                       "menu" => $this->page ($users ,"{site_url}html/".$this->config['hub']."/", $this->config['onpage'], $i, $this->config['pagedetalies']),

-                       "site_url" => $this->config['site_url'],

-                       "date" => date("d/m/Y H:i:s", $this->config['time']),

-                );

-

-                $templates[$i] = $this->pharse_template ($tpl, $rplt);

-

-                $i++; $j = 0; $content = "";

-

-                }

-                $j++;

-                $x++;

-                }

-                

-                $this->sendstats['share'] = $this->Size ($share);

-                $this->sendstats['hub'] = $this->config['hub'];

-                $this->sendstats['site_url'] = $this->config['site_url'];

-                $this->sendstats['users'] = $users;

-                

-                if ($this->config['ftp_active']) {

-                  

-                  $this->ftp_start ();

-                  $this->ftp_upload ("index.html", "html/index.html");

-                  ftp_chdir($this->ftp_conn, "html");

-                  $this->ftp_upload ("index.html", "html/index.html");

-                  ftp_chdir($this->ftp_conn, $this->config['hub']);

-                  

-                }

-

-                if (!is_dir ( "html/".$this->config['hub'] )) {mkdir ( "html/".$this->config['hub'] );}

-

-                foreach ($templates as $k => $v) {

-

-                  $r = array ("share" => $this->Size ($share),);

-                  $v = $this->pharse_template ($v, $r);

-

-                  $this->writetofile ("html/".$this->config['hub']."/".$k.".html", $v);

-                  

-                  $this->statsfiles[ $this->config['hub'] ] = $k;

-                 

-                    if ($this->config['ftp_active']) {

-                      $this->ftp_upload ($k.".html", "html/".$this->config['hub']."/".$k.".html");

-                    }

-

-                }

-

-                if ($this->config['ftp_active']) {

-                  $this->ftp_end ();

-                }

-

-}

-

-

-//--------------

-// Send To PHPDc

-//--------------

-

-function sendToPHPDc ($host,$method,$path,$data,$useragent=0) {

-	if (empty($method)) {

-	  $method = 'GET';

-	}

-	$method = strtoupper($method);

-	$fp = fsockopen($host,80);

-	if ($fp) {

-	if ($method == 'GET') {

-	  $path .= '?' . $data;

-	}

-	fputs($fp, "$method $path HTTP/1.0\r\n");

-	fputs($fp, "Host: $host\r\n");

-	fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");

-	fputs($fp, "Content-length: " . strlen($data) . "\r\n");

-	if ($useragent)

-		fputs($fp, "User-Agent: MSIE\r\n");

-	fputs($fp, "Connection: close\r\n\r\n");

-	if ($method == 'POST') {

-	  fputs($fp, $data);

-    }

-	while (!feof($fp))

-		$buf .= fgets($fp,1024);

-	fclose($fp);

-	}

-	return $buf;

-}

-

-function send_data () {

-

- $host      = "www.computergames.ro";

- $method    = "POST";

- $path      = "/venom/PHPDc/data.php";

- $data      = "share=".$this->sendstats['share']."&hub=".$this->sendstats['hub']."&site_url=".$this->sendstats['site_url']."&users=".$this->sendstats['users']."";

- $useragent = 1;

-

- $buffer = $this->sendToPHPDc ($host,$method,$path,$data,$useragent);

- //$this->debuglog ("Data Sent to PHPDc Homepage : ".$buffer);

-

-}

-

-} // End Class

-

-?>

-
+<?php
+
+//=============================//
+//                             //
+//   PHPDc v0.2                //
+//   PHPDc Class file          //
+//   PHPDc.Class.php           //
+//   by [RO]VeNoM              //
+//   razvan_stanga@yahoo.com   //
+//                             //
+//       MADE IN ROMANIA       //
+//                             //
+//=============================//
+
+class PHPDc {
+
+    var $socket;
+    var $usesockets;
+    var $config;
+    var $hub;
+    var $state = FALSE;
+    var $nrconnect = 1;
+    var $userdata = array ();
+    var $sendstats = array ();
+    var $statsfiles = array ();
+    var $ftp_conn;
+
+//-------------------------------
+// Connect to a given host / port
+//-------------------------------
+
+function connect ($host, $port) {
+
+  $address = gethostbyname($host);
+
+			if(array_search('sockets',get_loaded_extensions()) !== FALSE) {
+			
+			    $this->debuglog ("NR Connect : ".$this->nrconnect, "\r\n");
+			    $this->debuglog ("WARNING: your PHP build supports real sockets.");			
+				$this->usesockets = 1;
+				$this->nrconnect++;
+				
+                $this->socket = socket_create(AF_INET, SOCK_STREAM, 0);
+                
+                if (!$this->socket) {
+
+                  $this->debuglog ('Failed to create socket '.$adress);
+			      $this->debuglog ('Error : '. socket_strerror(socket_last_error()) );
+			      $this->debuglog ('Error NR : '. socket_last_error() );
+			      
+                }
+
+                if (!socket_connect($this->socket, $address, $port)) {
+
+                  $this->debuglog ('Failed to connect to '.$adress);
+			      $this->debuglog ('Error : '. socket_strerror(socket_last_error()) );
+			      $this->debuglog ('Error NR : '. socket_last_error() );
+			      
+                }
+                /*
+                if (!socket_set_nonblock ($this->socket)) {
+
+                  $this->debuglog ('Sockets are blocked');
+			      $this->debuglog ('Error : '. socket_strerror(socket_last_error()) );
+			      $this->debuglog ('Error NR : '. socket_last_error() );
+                }
+                */
+                  $this->debuglog ('Succesfully connected to '. $host .' ('.$address.'), port '.$port);
+                
+	            } else {
+			
+			      $this->debuglog ("NR Connect : ".$this->nrconnect, "\r\n");
+				  $this->debuglog ("WARNING: your PHP build doesn't support real sockets.");				
+				  $this->usesockets = 0;
+				  $this->nrconnect++;
+				
+                if (!$this->socket = @pfsockopen ($address , $port, $errno, $errstr, 30)) {
+
+                  $this->debuglog ('Failed to create socket'. $errno .', '. $errstr);
+                
+                }
+
+                if (!socket_set_blocking ($this->socket, FALSE)) {
+
+                  $this->debuglog ('Socket Stream is blocked');
+                
+                }
+                
+                  //socket_set_timeout ($this->socket, 5);
+                  $this->debuglog ('Succesfully connected to '. $host .' ('.$address.'), port '.$port);
+			    }
+}
+
+
+//-------------
+// Close socket
+//-------------
+
+function close () {
+
+  if ($this->usesockets == 1)       { socket_close($this->socket); }
+  else { fclose ($this->socket); }
+
+}
+
+
+//-------
+// Listen
+//-------
+
+function listen() {
+
+	if($this->state() == TRUE) {
+	  $this->receive();
+	  return TRUE;
+	} else {
+		return FALSE;
+	}
+}
+	
+
+//-------------
+// Recieve data
+//-------------
+
+function receive () {
+
+while($this->state() == TRUE) {
+
+  if ($this->config['time'] + $this->config['timetostay'] <= time() ) {
+
+   $this->do_stats ();
+   $this->send_data ();
+   
+   $this->debuglog ('### Done STATS for '. $this->config['hub']);
+   
+   $this->close ();
+   $this->debuglog ("Disconnected from ".$this->config['hub']);
+   
+   break;
+
+  }
+                
+  usleep ($this->config['receivesleep']);
+  
+  if ($this->usesockets == 1)  {
+
+  if (str_replace( ".", "", phpversion () ) >= 430 ) {
+    $r = array($this->socket);
+    socket_select($r, $w, $except = NULL, 1);
+  }
+
+    if ($_DATA = @socket_read ($this->socket, 1024)) {
+        
+			flush ();
+			$buffer .= $_DATA;	
+			
+			if (substr($buffer,-1) == "|") {
+				$this->do_stuff($buffer);
+				$buffer = "";
+			}
+			
+			if (strlen($buffer) > (50*1024)) {
+				$buffer = "";
+			}
+
+    } else {
+
+	  $this->debuglog ('Error : '. socket_strerror(socket_last_error()) );
+	  $this->debuglog ('Error NR : '. socket_last_error() );
+
+      $this->send('$Quit '.$this->config['nick'].'');
+
+      $this->close();
+
+      sleep($this->config['reconnect_after']);
+
+      $this->connect($this->config['hub'], $this->config['port']);
+
+    }
+
+  } else {
+
+    if ($_DATA = @fgets ($this->socket, 1024)) {
+        
+			flush();
+			$buffer .= $_DATA;	
+			
+			if (substr($buffer,-1) == "|") {
+				$this->do_stuff($buffer);
+				$buffer = "";
+			}
+			
+			if (strlen($buffer) > (50*1024)) {
+				$buffer = "";
+			}
+
+    } else {
+
+      $this->send('$Quit '.$this->config['nick'].'');
+
+      $this->close();
+
+      sleep($this->config['reconnect_after']);
+
+      $this->connect($this->config['hub'], $this->config['port']);
+
+    }
+
+  }
+  
+}
+  
+}
+
+
+//--------------------
+// Send data to socket
+//--------------------
+
+function send ($str) {
+
+  //$str = trim($str);
+  //if ($str{strlen ($str)-1} != "|") {$str .= "|";}
+
+  $str .= "|";
+  usleep($this->config['sendsleep']);
+  if ($this->usesockets == 1) {
+      $res = @socket_write($this->socket, $str, strlen($str));
+      if (!$res) {$this->debuglog ("CAN'T SEND : ". $str);}
+      } else {
+          $res = @fwrite($this->socket, $str, strlen($str));
+          if (!$res) {$this->debuglog ("CAN'T SEND : ". $str);}
+          }
+          
+  $this->debuglog ('SEND : '.$str);
+
+}
+
+
+//---------
+// Do Stuff
+//---------
+
+function do_stuff ($buffer) {
+
+		$_CMDLIST=explode("|",$buffer);
+		while (list($_tmpstr,$_COMMAND)=each($_CMDLIST)) {
+			$_CMD = $_COMMAND;
+			if (!$_CMD) {continue;}
+
+			$_PARAMSLIST=array();
+			$_PARAMS="";
+			
+			$this->debuglog("RECEIVE : " . $_CMD . "");
+			
+			$_tmpArr=explode(" ",$_CMD);
+			$_CMD=trim(strtoupper($_tmpArr[0]));
+			array_shift($_tmpArr);
+			$_PARAMS=trim(implode(" ",$_tmpArr));
+			
+			if ($_CMD{0} == "<") {
+				
+			} else {
+				$_tmpArr=explode("$",$_CMD);
+				array_shift($_tmpArr);
+				$_CMD=trim(implode(" ",$_tmpArr));
+
+				switch($_CMD) {
+					case "LOCK":
+						$this->send ("\$Key ".$this->lock2key ($_PARAMS)."");
+						$this->send ("\$ValidateNick {$this->config['nick']}");
+						break;
+					case "HUBNAME":
+						//$this->send ("\$ValidateNick {$this->config['nick']}");
+						break;
+					case "GETPASS":
+						$this->send ("\$MyPass {$this->config['password']}");
+						break;
+					case "BADPASS":
+						$this->debuglog ("LOGIN FAILED! (User {$this->config['nick']} - Pass {$this->config['password']})");
+						$this->send ("\$Quit {$this->config['nick']}");
+						break;
+					case "LOGEDIN":
+						$this->debuglog ("LOGIN SUCCESSFUL! (User {$this->config['nick']} - Pass {$this->config['password']})");
+						break;
+					case "HELLO":
+						if ($_PARAMS == $this->config['nick']) {			
+							$this->send ("\$Version {$this->config['version']}");
+							$this->send ("\$GetNickList");
+							$this->send ("\$MyINFO \$ALL {$this->config['nick']} {$this->config['description']}$ \${$this->config['speed']}\${$this->config['email']}\${$this->config['sharesize']}$");
+						}
+						break;
+					case "NICKLIST":
+						$_NICKLIST=explode("$$",$_PARAMS);
+						while (list ($_tmpstr,$nickname) = each($_NICKLIST)) {
+							if (!$nickname) {continue;}
+							if ($nickname == $this->config['nick']) {continue;}
+							$this->$userdata[$nickname] = array ();
+							$this->$userdata[$nickname]['nick'] = $nickname;
+							$this->send ("\$GetINFO {$nickname} {$this->config['nick']}");
+						}
+						break;
+					Case "OPLIST":
+						$_OPLIST=explode("$$",$_PARAMS);
+						while (list ($_tmpstr,$nickname) = each($_OPLIST)) {
+							$this->$userdata[$nickname]['IsOp'] = 1;
+						}
+						break;
+					Case "MYINFO":					
+						if (preg_match("/\\\$ALL ([^ \$\|]+) (.*)\\\$ \\\$(.+).\\\$(.+)\\\$(.+)\\\$/i",$_PARAMS,$tmpARR)){
+						$this->userdata[$tmpARR[1]]['description'] = $tmpARR[2];
+						$this->userdata[$tmpARR[1]]['speed'] = $tmpARR[3];
+						$this->userdata[$tmpARR[1]]['email'] = $tmpARR[4];
+						$this->userdata[$tmpARR[1]]['sharesize'] = $tmpARR[5];
+						$this->debuglog("User Data : ".$tmpARR[1]."|".$tmpARR[2]."|".$tmpARR[3]."|".$tmpARR[4]."|".$tmpARR[5]);
+						}
+						$tmpARR = array ();
+						if (preg_match("/\\\$ALL ([^ \$\|]+) (.*)\\\$ \\\$(.+).\\\$\\\$(.+)\\\$/i",$_PARAMS,$tmpARR)){
+						$this->userdata[$tmpARR[1]]['description'] = $tmpARR[2];
+						$this->userdata[$tmpARR[1]]['speed'] = $tmpARR[3];
+						$this->userdata[$tmpARR[1]]['sharesize'] = $tmpARR[4];
+						$this->debuglog("User Data : ".$tmpARR[1]."|".$tmpARR[2]."|".$tmpARR[3]."||".$tmpARR[4]);
+						}						
+						break;
+					Case "QUIT":
+						
+						break;
+					Case "SEARCH":
+						preg_match("/(.+):(.+) (.)\?(.)\?([0-9]+)\?(.)\?(.*)/i",$_PARAMS,$tmpARR);
+						$tmpARR[7]=str_replace("$"," ",$tmpARR[7]);
+						break;
+					case "SR":
+						break;
+					case "FORCEMOVE":
+						$this->debuglog("REDIRECTING NOT SUPPORTED! DISCONNECTING!");
+						$this->close ();
+					case "TO:":
+						
+						break;
+					default:
+						$this->debuglog("Unknown CMD " . $_CMD . "");
+						break;
+				}
+			}			
+		}
+}
+
+	
+//------
+// State
+//------
+
+function state (){
+
+  $result = $this->updatestate();
+		
+    if($result == TRUE) {
+        return TRUE;
+    }
+    else {
+        return FALSE;
+    }
+}
+
+
+//-------------
+// Update State
+//-------------
+
+function updatestate() {
+
+  $type = get_resource_type($this->socket);
+
+    if( is_resource ($this->socket) && $this->socket !== FALSE && ( $type == 'socket' || $type == 'Socket' || $type == 'stream' || $type == 'Stream') ) {
+      $this->state = TRUE;
+		return TRUE;
+    } else {
+      $this->state = FALSE;
+		return FALSE;
+    }
+
+}
+
+
+//----------
+// Debug Log
+//----------
+
+function debuglog ($stuff, $f='') {
+
+  if ($this->config['debug']) {
+    $this->writetolog ($f.$stuff."\r\n");
+    flush ();
+    echo $stuff."<br>";
+  }
+
+}
+
+
+//--------------
+// Write to file
+//--------------
+
+function writetolog ($data) {
+
+  if ($data!="") {
+
+    $filenum=fopen("logs/".$this->config['log']."","a");
+
+    fwrite($filenum,$data);
+
+    fclose($filenum);
+
+  }
+
+}
+
+
+//------------
+// Decode Lock
+//------------
+
+function lock2key($_LOCK) {
+
+   $this->debuglog ('Lock & Pk : '.$_LOCK);
+
+   $pk = stristr ($_LOCK, 'Pk=');
+   $this->debuglog ('Pk : '.$pk);
+
+   $_LOCK = str_replace ($pk, '', $_LOCK);
+
+   $_LOCK = substr ($_LOCK, 0, -1);
+   $this->debuglog ('Lock : '.$_LOCK);
+
+   $lockLength = strlen ($_LOCK);
+
+   $h = ord($_LOCK{0}) ^ ord( $_LOCK{ $lockLength - 1} ) ^ ord( $_LOCK{ $lockLength - 2} ) ^ 5;
+
+   //echo $h . "<br>";
+
+    while ($h > 255) {$h = $h - 256;}
+
+    $h = (($h<<4) & 240) | (($h>>4) & 15);
+
+	$a = $h;
+	
+	if ($a == '126' or // '~'
+	    $a == '124' or // '|'
+	    $a == '96' or  // '`'
+	    $a == '36' or  // '$'
+	    $a == '5' or   // '^E'
+	    $a == '0')     // NUL
+	{
+	  $LockToKey = "/%DCN";
+
+	  if ($a < 100)
+	    $LockToKey .="0";
+	  if ($a < 10)
+	    $LockToKey .="0";
+      $LockToKey .= $a; // As a string integer
+	  $LockToKey .= "%/";	
+	} else {
+	  $LockToKey = chr ($a);  // No transformation.
+	}
+
+   for ($j = 1; $j < strlen($_LOCK); $j++) {
+      $h = ord($_LOCK{$j}) ^ ord($_LOCK{$j-1});
+
+   while ($h > 255) {$h = $h - 256;}
+
+      $h = (($h<<4) & 240) | (($h>>4) & 15);
+
+      //echo $j . " - " . ($h*16) . "<br>";
+
+	  $a = $h;
+	
+	if ($a == '126' or // '~'
+	    $a == '124' or // '|'
+	    $a == '96' or  // '`'
+	    $a == '36' or  // '$'
+	    $a == '5' or   // '^E'
+	    $a == '0')     // NUL
+	{
+	  $LockToKey .= "/%DCN";
+
+	  if ($a < 100)
+	    $LockToKey .="0";
+	  if ($a < 10)
+	    $LockToKey .="0";
+      $LockToKey .= $a; // As a string integer
+	  $LockToKey .= "%/";	
+	} else {
+	  $LockToKey .= chr ($a);  // No transformation.
+	}
+   }
+
+   return $LockToKey;
+}
+
+//--------------------------------------
+// Start Lode, Pharse -> Template
+//--------------------------------------
+
+function lode_template ($t="") {
+
+    $file = "templates/".$t.".tpl";
+	
+	if ( file_exists($file) )
+	{
+		if ( $T = fopen($file, 'r') )
+		{
+			$template = fread( $T, filesize($file) );
+			fclose($T);
+		}
+		else
+		{
+			$this->debuglog ("Can't open template");
+		}
+	}
+	else
+	{
+		$this->debuglog ("Template doesn't exist");
+	}
+	
+	return $template;
+
+}
+
+function pharse_template( $template, $assigned=array() )
+{
+	
+	foreach( $assigned as $word => $replace)
+	{
+		$template = preg_replace( "/\{$word\}/i", "$replace", $template );
+	}
+	
+	return $template;
+}
+
+
+//-------------------
+// Start Write 2 File
+//-------------------
+
+function writetofile ($path,$data,$backup=0) {
+
+  if (file_exists($path)!=0) {
+    if ($backup==1) {
+      $filenamenew=$path."venom";
+
+      rename ($path,$filenamenew);
+    } else {
+      unlink($path);
+    }
+  }
+
+  if ($data!="") {
+
+    $filenum=fopen($path,"w");
+
+    fwrite($filenum,$data);
+
+    fclose($filenum);
+
+  }
+
+}
+
+
+//-----
+// Size
+//-----
+
+function Size($size) {
+    $mb = 1024*1024;
+    $gb = 1024*1024*1024;
+    $tb = 1024*1024*1024*1024;
+    if ( $size >= $tb ) {
+        $mysize = sprintf ("%01.2f",$size/$tb) . " TB";
+    } elseif ( $size >= $gb ) {
+        $mysize = sprintf ("%01.2f",$size/$gb) . " GB";
+    } elseif ( $size >= $mb ) {
+        $mysize = sprintf ("%01.2f",$size/$mb) . " MB";
+    } elseif ( $size >= 1024 ) {
+        $mysize = sprintf ("%01.2f",$size/1024) . " Kb";
+    } else {
+        $mysize = $size . " bytes";
+    }
+    return $mysize;
+}
+
+
+//------
+// Pages
+//------
+
+function page ($total_raw, $link, $offset, $pagina, $show = 1) {
+	
+	$pagenavpages = $this->config['navpages'];
+
+	if ($total_raw <= $offset) {
+		return "";
+	}
+	
+	if ($show == 1) {
+	$minim = ($pagina - 1) * $offset + 1;
+	$maxim = $minim + $offset - 1;
+	if ($total_raw <= $maxim) {$maxim = $total_raw;}
+	$showing = "Showing $minim - $maxim ($total_raw) |";} else {$showing = "";}
+
+	$totalpages = ceil($total_raw/$offset);
+
+	if ($pagina>1) {
+		$prevpage = $pagina-1;
+		$prevlink = "<a href=\"$link$prevpage.html\" title=\"Previous Page\">&laquo;</a>\r\n";
+	}
+	if ($pagina<$totalpages) {
+		$nextpage = $pagina+1;	
+		$nextlink = "<a href=\"$link$nextpage.html\" title=\"Next Page\">&raquo;</a>\r\n";		
+	}
+	while ($curpage++<$totalpages) {
+		if ( ( $curpage <= $pagina-$pagenavpages || $curpage >= $pagina+$pagenavpages ) && $pagenavpages!=0 ) {
+			if ($curpage==1) {
+				$firstlink = "<a href=\"$link$curpage.html\" title=\"First Page\">&laquo; First</a> ...\r\n";				
+			}
+		    if ($curpage==$totalpages) {
+		        $lastlink = "... <a href=\"$link$curpage.html\" title=\"Last Page\">Last &raquo;</a>\r\n";				
+			}
+		} else {
+			if ($curpage==$pagina) {
+				$pagenav .= "<font size=\"2\">[$curpage]</font>\r\n";			
+			} else {
+				$pagenav .= "<a href=\"$link$curpage.html\">$curpage</a>\r\n";
+			}
+		}
+	}
+	$pagenav = "<br><br>\r\nPages: $totalpages | $showing\r\n<b>\r\n$firstlink$prevlink$pagenav$nextlink$lastlink</b>\r\n";
+
+	return $pagenav;
+
+}
+
+
+//----------
+// Anti Spam
+//----------
+
+function AntiSpam ($email="", $name=""){
+
+    if ($email != "") {
+
+        for ( $i=0; $i < strlen ( $email ); $i++ ) {
+
+          $A .= "&#". ord( substr($email, $i) ) .";";
+
+         }
+    
+    }
+             
+    if ($name != "") {
+
+         for ( $i=0; $i < strlen ( $name ); $i++ ) {
+
+          $B .= "&#". ord( substr($name, $i) ) .";";
+
+         }
+    }
+    
+    if ($B != "" and $A == "") {return "none";}
+    
+    if ($B == "" and $A != "") {$B = $A;}
+    
+    if ($B == "" and $A == "") {return "none";}
+             
+    return "<SCRIPT LANGUAGE=\"JavaScript\">\r\ndocument.write('<a href=\"' + 'mailto:' + '".$A."' + '\">' + '".$B."' + '</a>');\r\n</script>";
+
+
+}
+
+
+//-----------
+// FTP Upload
+//-----------
+
+function ftp_start () {
+
+    $this->ftp_conn = ftp_connect ($this->config['ftp_server'], $this->config['ftp_port']);
+    $login_result = ftp_login($this->ftp_conn, $this->config['ftp_user'], $this->config['ftp_pass']);
+    
+}
+
+function ftp_upload ($filename, $filesource) {
+
+    $upload = ftp_put ($this->ftp_conn, $filename, $filesource, FTP_BINARY);
+    
+}
+
+function ftp_end () {
+
+    ftp_quit ($this->ftp_conn);
+        
+}
+
+
+//---------------
+// Make The Stats
+//---------------
+
+function do_stats () {
+
+                $tpl = $this->lode_template ($this->config['template']);
+                $tpl_user = $this->lode_template ($this->config['template']."-user");
+                $tpl_index = $this->lode_template ("index");
+                $tpl_counter = $this->lode_template ("counter");
+
+                $users = count ($this->userdata);
+
+                ksort ($this->userdata);
+
+                $j = 1;
+                $i = 1;
+                $x = 1;
+                $templates = array ();
+                $content = "";
+                $select = "";
+
+                $select .= "<option value=\"#\">Select Hub</option>\r\n";
+
+                foreach ($this->hub as $hub) {
+                  $select .= "<option value=\"{site_url}html/".$hub['hub']."/1.html\">".$hub['name']."</option>\r\n";
+                }
+
+                $rpli = array (
+                       "select" => $select,
+                       "counter" => $tpl_counter,
+                       "phpdc_author" => $this->AntiSpam($this->config['author_email'], $this->config['author_name']),
+                       "phpdc_version" => $this->config['version'],
+                       "site_url" => $this->config['site_url'],
+                );
+
+                $tpl_index = $this->pharse_template ($tpl_index, $rpli);
+
+                $this->writetofile ("html/index.html", $tpl_index);
+
+                foreach ($this->userdata as $k => $v) {
+
+                $rpl = array (
+                       "nick" => $k,
+                       "description" => $v[description],
+                       "speed" => $v[speed],
+                       "email" => $this->AntiSpam($v[email], $k),
+                       "sharesize" => $this->Size ($v[sharesize]),
+                );
+
+                  $content .= $this->pharse_template ($tpl_user, $rpl);
+                  $share += $v[sharesize];
+
+                if ($j >= $this->config['onpage'] or $x >= $users) {
+
+                $rplt = array (
+                       "content" => $content,
+                       "counter" => $tpl_counter,
+                       "users" => $users,
+                       "select" => $select,
+                       "hub" => $this->config['hub'],
+                       "port" => $this->config['port'],
+                       "name" => $this->config['name'],
+                       "desc" => $this->config['desc'],
+                       "phpdc_author" => $this->AntiSpam($this->config['author_email'], $this->config['author_name']),
+                       "phpdc_version" => "<a href=\"http://www.computergames.ro/venom/PHPDc/\">".$this->config['version']."</a>",
+                       "menu" => $this->page ($users ,"{site_url}html/".$this->config['hub']."/", $this->config['onpage'], $i, $this->config['pagedetalies']),
+                       "site_url" => $this->config['site_url'],
+                       "date" => date("d/m/Y H:i:s", $this->config['time']),
+                );
+
+                $templates[$i] = $this->pharse_template ($tpl, $rplt);
+
+                $i++; $j = 0; $content = "";
+
+                }
+                $j++;
+                $x++;
+                }
+                
+                $this->sendstats['share'] = $this->Size ($share);
+                $this->sendstats['hub'] = $this->config['hub'];
+                $this->sendstats['site_url'] = $this->config['site_url'];
+                $this->sendstats['users'] = $users;
+                
+                if ($this->config['ftp_active']) {
+                  
+                  $this->ftp_start ();
+                  $this->ftp_upload ("index.html", "html/index.html");
+                  ftp_chdir($this->ftp_conn, "html");
+                  $this->ftp_upload ("index.html", "html/index.html");
+                  ftp_chdir($this->ftp_conn, $this->config['hub']);
+                  
+                }
+
+                if (!is_dir ( "html/".$this->config['hub'] )) {mkdir ( "html/".$this->config['hub'] );}
+
+                foreach ($templates as $k => $v) {
+
+                  $r = array ("share" => $this->Size ($share),);
+                  $v = $this->pharse_template ($v, $r);
+
+                  $this->writetofile ("html/".$this->config['hub']."/".$k.".html", $v);
+                  
+                  $this->statsfiles[ $this->config['hub'] ] = $k;
+                 
+                    if ($this->config['ftp_active']) {
+                      $this->ftp_upload ($k.".html", "html/".$this->config['hub']."/".$k.".html");
+                    }
+
+                }
+
+                if ($this->config['ftp_active']) {
+                  $this->ftp_end ();
+                }
+
+}
+
+
+//--------------
+// Send To PHPDc
+//--------------
+
+function sendToPHPDc ($host,$method,$path,$data,$useragent=0) {
+	if (empty($method)) {
+	  $method = 'GET';
+	}
+	$method = strtoupper($method);
+	$fp = fsockopen($host,80);
+	if ($fp) {
+	if ($method == 'GET') {
+	  $path .= '?' . $data;
+	}
+	fputs($fp, "$method $path HTTP/1.0\r\n");
+	fputs($fp, "Host: $host\r\n");
+	fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
+	fputs($fp, "Content-length: " . strlen($data) . "\r\n");
+	if ($useragent)
+		fputs($fp, "User-Agent: MSIE\r\n");
+	fputs($fp, "Connection: close\r\n\r\n");
+	if ($method == 'POST') {
+	  fputs($fp, $data);
+    }
+	while (!feof($fp))
+		$buf .= fgets($fp,1024);
+	fclose($fp);
+	}
+	return $buf;
+}
+
+function send_data () {
+
+ $host      = "www.computergames.ro";
+ $method    = "POST";
+ $path      = "/venom/PHPDc/data.php";
+ $data      = "share=".$this->sendstats['share']."&hub=".$this->sendstats['hub']."&site_url=".$this->sendstats['site_url']."&users=".$this->sendstats['users']."";
+ $useragent = 1;
+
+ $buffer = $this->sendToPHPDc ($host,$method,$path,$data,$useragent);
+ //$this->debuglog ("Data Sent to PHPDc Homepage : ".$buffer);
+
+}
+
+} // End Class
+
+?>

--- a/includes/PHPDc.Config.php
+++ b/includes/PHPDc.Config.php
@@ -1,115 +1,114 @@
-<?php

-

-//=============================//

-//                             //

-//   PHPDc v0.2                //

-//   PHPDc Config file         //

-//   PHPDc.Config.php          //

-//   by [RO]VeNoM              //

-//   razvan_stanga@yahoo.com   //

-//                             //

-//       MADE IN ROMANIA       //

-//                             //

-//=============================//

-

-$config = array ();

-$hub = array ();

-

-//====================//

-// EDITABLE VARIABLES //

-//====================//

-

-// Admin User/Password/Email

-

-$config['admin_user'] = "venom";

-$config['admin_password'] = "venom";

-$config['admin_email'] = "razvan_stanga@yahoo.com";

-

-// Hub(s), Port, Name & Description

-

-$hub['1']['hub'] = 'hub.wareznet.ro';

-$hub['1']['port'] = 411;

-$hub['1']['name'] = "Romania's #1 DC Hub";

-$hub['1']['desc'] = "dual pentrum 3, 512 MB RAM";

-$hub['1']['template'] = 'zap';

-

-// Bot User Data

-

-$config['nick'] = '[RO][B][TotalNet]VeNoMPHPDc';

-$config['description'] = 'PHPDC Stats by [RO]VeNoM';

-$config['email'] = 'venom@venom-is.yourtrap.com';

-$config['speed'] = 'Cable'.chr(1); // do not remove .chr(1)

-$config['sharesize'] = '75805505065';

-

-// FTP Stuff

-

-$config['ftp_active'] = 0;

-

-$config['ftp_server'] = "";

-$config['ftp_port'] = "21";

-$config['ftp_user'] = "";

-$config['ftp_pass'] = "";

-

-// When disconnected, Reconnect after (seconds)

-

-$config['reconnect_after'] = 3;

-

-// If debugger is set to 1, it will write a log in logs dir

-

-$config['debug'] = 1;

-

-// Site URL

-

-$config['site_url'] = 'http://www.hubstats.go.ro/'; // must end with /

-

-// Time to stay and collect info (seconds)

-

-$config['timetostay'] = 60;

-

-// Cron job time (seconds)

-

-$config['cronjob'] = 900;

-

-// Nicks / Users per page

-

-$config['onpage'] = 30;

-

-// Navigation Pages

-

-$config['navpages'] = 5;

-

-// Page Details

-

-$config['pagedetalies'] = 1;

-

-//========================//

-// NOT EDITABLE VARIABLES //

-//========================//

-

-// Author Details

-

-$config['author_name'] = "[RO]VeNoM";

-$config['author_email'] = "razvan_stanga@yahoo.com";

-

-// Log file name

-

-$config['log'] = 'debug-'.date("Y-m-d").'.log';

-

-// Time to seeep between sends (microseconds)

-

-$config['sendsleep'] = 10000;

-

-// Time to seeep between receives (microseconds)

-

-$config['receivesleep'] = 10000;

-

-// Start Time

-

-$config['time'] = time ();

-

-// PHPDc Version

-

-$config['version'] = 'PHPDc v0.2';

-

-?>

+<?php
 
+//=============================//
+//                             //
+//   PHPDc v0.2                //
+//   PHPDc Config file         //
+//   PHPDc.Config.php          //
+//   by [RO]VeNoM              //
+//   razvan_stanga@yahoo.com   //
+//                             //
+//       MADE IN ROMANIA       //
+//                             //
+//=============================//
+
+$config = array ();
+$hub = array ();
+
+//====================//
+// EDITABLE VARIABLES //
+//====================//
+
+// Admin User/Password/Email
+
+$config['admin_user'] = "venom";
+$config['admin_password'] = "venom";
+$config['admin_email'] = "razvan_stanga@yahoo.com";
+
+// Hub(s), Port, Name & Description
+
+$hub['1']['hub'] = 'hub.wareznet.ro';
+$hub['1']['port'] = 411;
+$hub['1']['name'] = "Romania's #1 DC Hub";
+$hub['1']['desc'] = "dual pentrum 3, 512 MB RAM";
+$hub['1']['template'] = 'zap';
+
+// Bot User Data
+
+$config['nick'] = '[RO][B][TotalNet]VeNoMPHPDc';
+$config['description'] = 'PHPDC Stats by [RO]VeNoM';
+$config['email'] = 'venom@venom-is.yourtrap.com';
+$config['speed'] = 'Cable'.chr(1); // do not remove .chr(1)
+$config['sharesize'] = '75805505065';
+
+// FTP Stuff
+
+$config['ftp_active'] = 0;
+
+$config['ftp_server'] = "";
+$config['ftp_port'] = "21";
+$config['ftp_user'] = "";
+$config['ftp_pass'] = "";
+
+// When disconnected, Reconnect after (seconds)
+
+$config['reconnect_after'] = 3;
+
+// If debugger is set to 1, it will write a log in logs dir
+
+$config['debug'] = 1;
+
+// Site URL
+
+$config['site_url'] = 'http://www.hubstats.go.ro/'; // must end with /
+
+// Time to stay and collect info (seconds)
+
+$config['timetostay'] = 60;
+
+// Cron job time (seconds)
+
+$config['cronjob'] = 900;
+
+// Nicks / Users per page
+
+$config['onpage'] = 30;
+
+// Navigation Pages
+
+$config['navpages'] = 5;
+
+// Page Details
+
+$config['pagedetalies'] = 1;
+
+//========================//
+// NOT EDITABLE VARIABLES //
+//========================//
+
+// Author Details
+
+$config['author_name'] = "[RO]VeNoM";
+$config['author_email'] = "razvan_stanga@yahoo.com";
+
+// Log file name
+
+$config['log'] = 'debug-'.date("Y-m-d").'.log';
+
+// Time to seeep between sends (microseconds)
+
+$config['sendsleep'] = 10000;
+
+// Time to seeep between receives (microseconds)
+
+$config['receivesleep'] = 10000;
+
+// Start Time
+
+$config['time'] = time ();
+
+// PHPDc Version
+
+$config['version'] = 'PHPDc v0.2';
+
+?>

--- a/includes/PHPDc.Cron.php
+++ b/includes/PHPDc.Cron.php
@@ -1,70 +1,69 @@
-<?php

-

-//=============================//

-//                             //

-//   PHPDc v0.2                //

-//   PHPDc Cron Job file       //

-//   PHPDc.Cron.php            //

-//   by [RO]VeNoM              //

-//   razvan_stanga@yahoo.com   //

-//                             //

-//       MADE IN ROMANIA       //

-//                             //

-//=============================//

-

-class PHPDcCron {

-

-//---------

-// Cron Job

-//---------

-

-function do_write ($time_cache) {

-    global $config;

-

-        ksort ($time_cache);

-

-		$file_data = "<?\r\n";

-		

-		foreach( $time_cache as $t => $c )

-		{

-			$file_data .= '$time_cache['."'".$t."'".']'."\t=\t'".$c."';\r\n";	

-		}

-		

-		$file_data .= "".'?'.'>';

-

-        $this->writetofile ("html/time_cache.php", $file_data);

-

-}

-

-//-------------------

-// Start Write 2 File

-//-------------------

-

-function writetofile ($path,$data,$backup=0) {

-

-  if (file_exists($path)!=0) {

-    if ($backup==1) {

-      $filenamenew=$path."venom";

-

-      rename ($path,$filenamenew);

-    } else {

-      unlink($path);

-    }

-  }

-

-  if ($data!="") {

-

-    $filenum=fopen($path,"w");

-

-    fwrite($filenum,$data);

-

-    fclose($filenum);

-

-  }

-

-}

-

-}

-

-?>

+<?php
 
+//=============================//
+//                             //
+//   PHPDc v0.2                //
+//   PHPDc Cron Job file       //
+//   PHPDc.Cron.php            //
+//   by [RO]VeNoM              //
+//   razvan_stanga@yahoo.com   //
+//                             //
+//       MADE IN ROMANIA       //
+//                             //
+//=============================//
+
+class PHPDcCron {
+
+//---------
+// Cron Job
+//---------
+
+function do_write ($time_cache) {
+    global $config;
+
+        ksort ($time_cache);
+
+		$file_data = "<?\r\n";
+		
+		foreach( $time_cache as $t => $c )
+		{
+			$file_data .= '$time_cache['."'".$t."'".']'."\t=\t'".$c."';\r\n";	
+		}
+		
+		$file_data .= "".'?'.'>';
+
+        $this->writetofile ("html/time_cache.php", $file_data);
+
+}
+
+//-------------------
+// Start Write 2 File
+//-------------------
+
+function writetofile ($path,$data,$backup=0) {
+
+  if (file_exists($path)!=0) {
+    if ($backup==1) {
+      $filenamenew=$path."venom";
+
+      rename ($path,$filenamenew);
+    } else {
+      unlink($path);
+    }
+  }
+
+  if ($data!="") {
+
+    $filenum=fopen($path,"w");
+
+    fwrite($filenum,$data);
+
+    fclose($filenum);
+
+  }
+
+}
+
+}
+
+?>

comments