Scripts

Apache directory listing++

Op zich had ik het volgende script overgenomen http://www.phphulp.nl/php/scripts/7/256/ en langzaam aan heb ik dit script steeds wat uitgebreid. En op iedere Apache server staat een dir genaamd icons en anders kan je ze wel uit bijvoorbeeld de volgende copieeren http://www.webhostingtalk.com/icons/ Alhoewel ik wel een voorbeeld heb is dit beveiligd, dus daaraan hebben jullie niks. Ik zal nog even opschrijven wat de verschillen zijn met de normale versie: - Mappen bovenaan - Mappen browsen - Meer iconen als apache zelf gebruikt

apache-directory-listing
<?php 
$dir='';//Leeg laten voor de deze directory te scannen 
$n_ext=array('');// extensies voorbeeld: array('html','php') voor directories schrijf je als extensie dir 
$n_file=array('.htaccess', '.htpasswd',"apache.html");// bestanden of mappen die niet mogen getoont worden 
$m_up_name = "Parent Directory"; //Naam van de Link om een Map omhoog te gaan
//------------------------------------ 
//iconnen die gebruikt worden 
//------------------------------------ 
 

//Compressed 
$icons['zip']='compressed'; 
$icons['rar']='compressed'; 
$icons['z']='compressed'; 
$icons['tgz']='compressed'; 
$icons['gz']='compressed'; 
$icons['tar']='compressed'; 

//Binary 

$icons['bin']='binary'; 
$icons['exe']='binary'; 
$icons['hqx']='binhex'; 

//andere bestanden (volgens apache bestaad dat ook :D) 

$icons['wrl']='world2'; 
$icons['vrml']='world2'; 
$icons['vrm']='world2'; 
$icons['iv']='world2'; 
$icons['ps']='a'; 
$icons['ai']='a'; 
$icons['eps']='a'; 
$icons['c']='c'; 
$icons['pl']='p'; 
$icons['py']='p'; 
$icons['f']='for'; 
$icons['dvi']='dvi'; 
$icons['uu']='uuencoded'; 
$icons['core']='bomb'; 


//Sites 

$icons['html']='layout'; 
$icons['shtml']='layout'; 
$icons['htm']='layout'; 
$icons['pdf']='layout'; 

//Text 

$icons['txt']='text'; 

//Scripts 

$icons['php']='script'; 
$icons['conf']='script'; 
$icons['sh']='script'; 
$icons['shar']='script'; 
$icons['csh']='script'; 
$icons['ksh']='script'; 
$icons['tcl']='script'; 

//Directories en vorige directory 

$icons['..']='back'; 
$icons['']='folder'; 
$icons['dir']='folder';
$icons['opendir']='folder.open';

//Zelf toegevoegde icononen die ook in apache zitten maar niet gebruikt worden 

//foto's 

$icons['gif']='image2'; 
$icons['jpg']='image2'; 
$icons['png']='image2'; 
$icons['bmp']='image2'; 
$icons['pntg']='image2'; 
$icons['pnt']='image2'; 
$icons['mac']='image2'; 
$icons['pict']='image2'; 
$icons['pic']='image2'; 
$icons['pct']='image2'; 
$icons['qtif']='image2'; 
$icons['qti']='image2'; 
$icons['sgi']='image2'; 
$icons['rgb']='image2'; 
$icons['targa']='image2'; 
$icons['tga']='image2'; 
$icons['tif']='image2'; 
$icons['tiff']='image2'; 
$icons['psd']='image2'; 

//Films 

$icons['mpg']='movie'; 
$icons['mpeg']='movie'; 
$icons['mov']='movie'; 
$icons['qt']='movie'; 
$icons['wmv']='movie'; 
$icons['avi']='movie'; 
$icons['flc']='movie'; 
$icons['fli']='movie'; 
$icons['m1s']='movie'; 
$icons['m1v']='movie'; 
$icons['m1a']='movie'; 
$icons['m75']='movie'; 
$icons['m15']='movie'; 
$icons['mp2']='movie'; 
$icons['mpm']='movie'; 
$icons['mpv']='movie'; 
$icons['mpa']='movie'; 
$icons['3gp']='movie'; 
$icons['3gpp']='movie'; 
$icons['3g2']='movie'; 
$icons['3gp2']='movie'; 
$icons['mp4']='movie'; 
$icons['mpg4']='movie'; 
$icons['sdv']='movie'; 
$icons['amc']='movie'; 
$icons['m4v']='movie'; 
$icons['swf']='movie'; 
$icons['dv']='movie'; 
$icons['dif']='movie'; 


//Geluids bestanden 

$icons['wav']='sound1'; 
$icons['bwf']='sound1'; 
$icons['midi']='sound1'; 

//Muziek 

$icons['mp3']='sound2'; 
$icons['wma']='sound2'; 
$icons['au']='sound2'; 
$icons['aiff']='sound2'; 
$icons['au']='sound2'; 
$icons['snd']='sound2'; 
$icons['ulw']='sound2'; 
$icons['qcp']='sound2'; 
$icons['sd2']='sound2'; 
$icons['amr']='sound2'; 
$icons['gsm']='sound2'; 
$icons['aiff']='sound2'; 
$icons['m4a']='sound2'; 
$icons['m4p']='sound2'; 
$icons['m4b']='sound2'; 
$icons['swa']='sound2'; 
$icons['m4b']='sound2'; 

//------------------------------------ 
//Functie voor te kijken of het bestand toegelaten is 
//------------------------------------ 
function check_allow($file){ 
    global $n_ext, $n_file, $icons; 
     
    for($a=0;$a<count($n_ext);$a++){ 
        $ext=explode('.',$file); 
        $ext_check=count($ext); 
        $ext=$ext[count($ext)-1]; 
        if(is_file($file)){ 
            $img=$icons[strtolower($ext)]; 
        } 
        else{ 
            $img=''; 
        } 
        if($img==''){ 
            $ext='dir'; 
        } 
        if($ext==$n_ext[$a]){ 
            $allow=1; 
        } 
    } 

    for($a=0;$a<count($n_file);$a++){ 
        if($file==$n_file[$a]){ 
            $allow=1; 
        }
    } 
    if(isset($allow)){ 
        return FALSE; 
    } 
    else{ 
        return TRUE; 
    } 
} 
//------------------------------------ 
//Begin van de pagina 
//------------------------------------ 
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> 
<html> 
<head> 
  <title>Index of '.$dir.'/</title> 
</head> 
<body>'; 
echo '<h1>Index of '.$dir.'/</h1>'."\n".'<pre>'; 
//------------------------------------ 
//Sorteer volgorder en dan opslaan in $sort 
//------------------------------------ 
if(isset($_GET['C'])){ 
    $type=explode(';O=',$_GET['C']); 
    $sort_by=$type[0]; 
    $sort_way=$type[1]; 
    if(($sort_by=='N' || $sort_by=='M' || $sort_by=='S' || $sort_by=='D') && ($sort_way=='A' || $sort_way=='D')){ 
        if($sort_by=='N'){ 
            if($sort_way=='A'){ 
                $n='D'; 
                $m='A'; 
                $s='A'; 
                $d='A'; 
            } 
            else{ 
                $n='A'; 
                $m='A'; 
                $s='A'; 
                $d='A';     
            } 
            $sort=1; 
        } 
        elseif($sort_by=='M'){ 
            if($sort_way=='A'){ 
                $n='A'; 
                $m='D'; 
                $s='A'; 
                $d='A'; 
            } 
            else{ 
                $n='A'; 
                $m='A'; 
                $s='A'; 
                $d='A';     
            } 
            $sort=2; 
        } 
        elseif($sort_by=='S'){ 
            if($sort_way=='A'){ 
                $n='A'; 
                $m='A'; 
                $s='D'; 
                $d='A'; 
            } 
            else{ 
                $n='A'; 
                $m='A'; 
                $s='A'; 
                $d='A';     
            } 
            $sort=3; 
        } 
        elseif($sort_by=='D'){ 
            if($sort_way=='A'){ 
                $n='A'; 
                $m='A'; 
                $s='A'; 
                $d='D'; 
            } 
            else{ 
                $n='A'; 
                $m='A'; 
                $s='A'; 
                $d='A';     
            } 
        } 
    } 
    else{ 
        $n='D'; 
        $m='A'; 
        $s='A'; 
        $d='A'; 
    } 
} 
else{ 
    $n='D'; 
    $m='A'; 
    $s='A'; 
    $d='A'; 
} 
if($_GET['dir']){
echo '<img src="/icons/blank.gif" alt="Icon "> <a href="?dir='.$_GET['dir'].'&C=N;O='.$n.'">Name</a>                    '; 
echo '<a href="?dir='.$_GET['dir'].'&C=M;O='.$m.'">Last modified</a>      '; 
echo '<a href="?dir='.$_GET['dir'].'&C=S;O='.$s.'">Size</a>  '; 
echo '<a href="?dir='.$_GET['dir'].'&C=D;O='.$d.'">Description</a><hr>'; 
}else{
echo '<img src="/icons/blank.gif" alt="Icon "> <a href="?C=N;O='.$n.'">Name</a>                    '; 
echo '<a href="?C=M;O='.$m.'">Last modified</a>      '; 
echo '<a href="?C=S;O='.$s.'">Size</a>  '; 
echo '<a href="?C=D;O='.$d.'">Description</a><hr>'; 

}
//------------------------------------ 
//Directory openen en alles in een array zetten zodat we het nog kunnen sorteren later 
//En controle of het bestand is toegelaten 
//------------------------------------ 

if($_GET['dir']==''){ 
    $open_dir='.'; 
} 
else{ 
    $open_dir=$_GET['dir']; 
} 
$handle=opendir($open_dir); 
$a=0; 
$test_iri=str_replace(basename($_SERVER['PHP_SELF']),'',$_SERVER['REQUEST_URI']); 
$test_iri=explode('?',$test_iri); 
$test_iri=$test_iri[0]; 
while (false!==($file = readdir($handle))) { 
    if($file!='.'){ 
        if($file!='..'){ 
            $ext=explode('.',$file); 
            $ext_check=count($ext); 
            $ext=$ext[count($ext)-1]; 
            if(is_file($file)){ 
                $img=$icons[strtolower($ext)]; 
            } 
            else{ 
                $img=''; 
            } 
            if($img=='' && $ext!='' && $ext_check>=2){ 
                $img='unknown'; 
            } 
            elseif($img==''){ 
                $img=$icons['']; 
                $file=$file.'/'; 
                $ext=''; 
            } 
        } 
        else{ 
            $img=$icons['..']; 
            $ext='dir'; 
            $file=$m_up_name;
        } 
        if($test_iri=='/'){ 
            $test=($file!='..'); 
        } 
        else{ 
            $test=TRUE; 
        } 
        if($test && check_allow($file)){ 
            $files_file[$a]=$file; 
            $files_ext[$a]=$ext; 
            $files_time[$a]=filemtime($file); 
            if($files_ext[$a]==''){ 
                $size='  -'; 
            } 
            else{ 
                $size=round(filesize($files_file[$a])/1024,1).'K'; 
            } 
            $files_size[$a]=$size; 
            $a++; 
        } 
    } 
} 

closedir($handle); 
//------------------------------------ 
//Als de lijst moet gesorteert worden 
//------------------------------------ 
if($sort==1){ 
    if($sort_way=='A'){ 
        array_multisort($files_file, SORT_ASC, $files_ext, SORT_ASC, $files_time, SORT_ASC, $files_size, SORT_ASC); 
    } 
    else{ 
        array_multisort($files_file, SORT_DESC, $files_ext, SORT_DESC, $files_time, SORT_DESC, $files_size, SORT_DESC); 
    } 
} 
elseif($sort==2){ 
    if($sort_way=='A'){ 
        array_multisort($files_time, SORT_ASC, $files_ext, SORT_ASC, $files_file, SORT_ASC, $files_size, SORT_ASC); 
    } 
    else{ 
        array_multisort($files_time, SORT_DESC, $files_ext, SORT_DESC, $files_file, SORT_DESC, $files_size, SORT_DESC); 
    } 
} 
elseif($sort==3){ 
    if($sort_way=='A'){ 
        array_multisort($files_size, SORT_ASC, $files_ext, SORT_ASC, $files_file, SORT_ASC, $files_time, SORT_ASC); 
    } 
    else{ 
        array_multisort($files_size, SORT_DESC, $files_ext, SORT_DESC, $files_file, SORT_DESC, $files_time, SORT_DESC); 
    } 
} 
//------------------------------------ 
//Alles echo'en 
//------------------------------------ 
for($b=0;$b<$a;$b++){ 
        $alt='[DIR]'; 

if($files_file[$b] == $m_up_name){
           echo '<img src="/icons/'.$icons[$files_ext[$b]].'.gif" width="20" height="22" alt="'.$alt.'"> '; 
           $lastone = explode ("/", $_GET['dir']);
           $tmp = count($lastone);
if($lastone[$tmp - 1] == ""){
                       echo '<a href="?dir='.$_GET['dir'].'..">'; 
}else{
                       echo '<a href="?dir='.$_GET['dir'].'/..">'; 
                       }
                       echo '<img border="0" src="/icons/'.$icons['opendir'].'.gif" height="22" alt="'.$alt.'"></a> '; 
 
            echo '<a href="..">'.$files_file[$b].'</a>'; 
            $spaces=24-strlen($files_file[$b]); 
            for($c=0;$c<$spaces;$c++){ 
                echo ' '; 
            } 
            echo date('d\-M\-Y H\:i',$files_time[$b]); 
    echo '  '.$files_size[$b]."\n"; 
}
}
for($b=0;$b<$a;$b++){ 
if($files_file[$b] == $m_up_name){
}else{
if($files_ext[$b]==''){ 
        $alt='[DIR]'; 
//folder.open
            echo '<img border="0" src="/icons/'.$icons[$files_ext[$b]].'.gif" width="20" height="22" alt="'.$alt.'"> '; 
            echo '<a href="?dir='.$_GET['dir'].'/'.$files_file[$b].'">'; 
            echo '<img border="0" src="/icons/'.$icons['opendir'].'.gif" height="22" alt="'.$alt.'"></a> '; 
            echo '<a href="'.$_GET['dir'].'/'.$files_file[$b].'">'.$files_file[$b].'</a>'; 
            $spaces=24-strlen($files_file[$b]); 
            for($c=0;$c<$spaces;$c++){ 
                echo ' '; 
            } 
            echo date('d\-M\-Y H\:i',$files_time[$b]); 
    echo '  '.$files_size[$b]."\n"; 
}
}
}
for($b=0;$b<$a;$b++){ 
if($files_file[$b] == $m_up_name){
}else{
    if($files_ext[$b]==''){ 
        $alt='[DIR]'; 
    } 
    else{ 
        $alt='['.strtoupper($files_ext[$b]).']';
        
        if($icons[$files_ext[$b]]==''){
        $iconuri = "unknown";
        }else{
        $iconuri = $icons[$files_ext[$b]];
        }
        if($files_file[$b] == "index.html"){
        $iconuri = "index";
        }
            echo '    <img border="0" src="/icons/'.$iconuri.'.gif" width="20" height="22" alt="'.$alt.'"> '; 
            echo '<a href="'.$_GET['dir'].'/'.$files_file[$b].'">'.$files_file[$b].'</a>'; 
            $spaces=24-strlen($files_file[$b]); 
            for($c=0;$c<$spaces;$c++){ 
                echo ' '; 
            } 
            echo date('d\-M\-Y H\:i',$files_time[$b]); 
    echo '  '.$files_size[$b]."\n"; 
    } 
}
} 
//------------------------------------ 
//Einde van de pagina 
//------------------------------------ 
echo '</pre><hr><address>'.$_SERVER['SERVER_SIGNATURE'].'</address>'; 
?></body></html> 

Reacties

0
Nog geen reacties.