HTTP get directory list

If not exist in directory file index.htm its generated file list.I just want to know if this list is generated by server or by browser.Or how i can obtain file list on http server.

Comments

  • : If not exist in directory file index.htm its generated file list.I just want to know if this list is generated by server or by browser.Or how i can obtain file list on http server.
    :
    That list is created by the server and largely depends on the security settings of that server. Apache initially allows (and thus shows) directory listings. By applying the relevant settings this can be turned off, allowed for certain users, or fully allowed throughout the server, per file-system directory, or per virtual location. I'm not familiar with the IIS.
  • : If not exist in directory file index.htm its generated file list.I just want to know if this list is generated by server or by browser.Or how i can obtain file list on http server.
    :
    You can also create a simple php script that lets a user login, and depending on the user level it shows certain files or it hides them...

    I'll see if I can make you an example and ppost it here...


    ;-)
    -mac-
    mailto:mac_doggie@hotmail.com
    the Netherlands...


  • [b][red]This message was edited by mac_doggie at 2006-6-20 22:20:28[/red][/b][hr]
    : : If not exist in directory file index.htm its generated file list.I just want to know if this list is generated by server or by browser.Or how i can obtain file list on http server.
    : :
    : You can also create a simple php script that lets a user login, and depending on the user level it shows certain files or it hides them...
    :
    : I'll see if I can make you an example and ppost it here...
    :
    :
    : ;-)
    : -mac-
    : mailto:mac_doggie@hotmail.com
    : the Netherlands...
    :
    :
    :
    I've made an example script, you can expand it with more options like creating and removing directories etc.. For now I only put in removing files for users with admin rights. Create a directory php and put in this script, call it userlogin.php
    [code]
    <?php
    /*##############################################################
    ##
    ## Project : Programmersheaven example
    ## file : userlogin.php
    ## Type : PHP script
    ##
    ## Programmer : MAC-DOGGIE (c) 2006
    ## license : You may use this code for free, as long as you
    ## do not remove or alter this block of comment...
    ##
    ## Description : This file lets a user login, and depending on the
    ## username and password, files and folders are hidden
    ## or displayed.
    ##
    ##
    ## Example : place a PHP file in each folder that contains:
    ## <? require_once("/php/userlogin.php"); ?>
    ##
    ##############################################################

    ##############################################################
    ## id = $ID:$
    ############################################################*/

    // Userlist
    //
    $user[1]["username"] = "admin";
    $user[1]["password"] = "admin";
    $user[1]["userlevel"] = "admin";

    $user[2]["username"] = "guest";
    $user[2]["password"] = "guest";
    $user[2]["userlevel"] = "guest";

    $hidedir["guest"][] = "admin";
    $hidedir["guest"][] = "private";
    $hidedir["admin"][] = "public";

    $hidefile["guest"][] = ".exe";
    $hidefile["guest"][] = ".php";
    $hidefile["admin"][] = ".php";


    // Classes and functions
    //
    set_include_path("..;../php");
    class User {
    private $loggedin;
    private $userlevel;

    public function __construct() {
    // Initialise properties
    //
    $this->loggedin = false;
    $this->userlevel = "";
    }

    public function Login($username, $password) {
    global $user;
    foreach($user as $id=>$usr) {
    if(($usr["username"] == $username) && ($usr["password"] == $password)) {
    $this->loggedin = true;
    $this->userlevel = $usr["userlevel"];
    }
    }
    }

    public function Logout() {
    $this->loggedin = false;
    }

    public function IsLoggedin() {
    return $this->loggedin;
    }

    public function getUserlevel() {
    return $this->userlevel;
    }
    }


    // Start of main program
    //
    session_start();
    if(!is_a($_SESSION["user"], "User")) {
    $_SESSION["user"] = new User();
    }
    if(!empty($_GET["logout"])) {
    $_SESSION["user"]->Logout();
    }

    if(!$_SESSION["user"]->IsLoggedin()) {
    if(!empty($_POST["username"]) && !empty($_POST["password"])) {
    $_SESSION["user"]->Login($_POST["username"], $_POST["password"]);
    }else {
    $output = file_get_contents("../forms/loginform.html");
    }
    }
    if($_SESSION["user"]->IsLoggedin()) {
    $output .= "logout";
    if(!empty($_GET["delete"])) {
    if($_GET["confirmed"] == "true") {
    if($_SESSION["user"]->getUserlevel() == "admin") {
    unlink($_GET["delete"]);
    $output .= "File {$_GET["delete"]} deleted...

    ";
    }
    }else {
    $output .= "Please confirm that you widh to delete file: {$_GET["delete"]}

    ";
    }
    }
    if($handle=opendir(".")) {
    $output .= "

    Contents of Directory:

    ";
    $output .= "body {font:85% arial helvetica sans-serif;} td {background-color:lightgrey;padding:6px;}";
    $output .= "";
    while (false !== ($file = readdir($handle))) {
    if(is_dir($file)) {
    $hide = false;
    foreach($hidedir[$_SESSION["user"]->getUserlevel()] as $hdir) {
    if(strpos($hdir, $file) !== false) {
    $hide = true;
    }
    }
    if(!$hide) {
    $output .= "";
    }
    }elseif(is_file($file)) {
    $hide = false;
    foreach($hidefile[$_SESSION["user"]->getUserlevel()] as $hfile) {
    if(strpos($hfile, $file) !== false) {
    $hide = true;
    }
    }
    if(!$hide) {
    if($_SESSION["user"]->getUserlevel() == "admin") {
    $delete = "Delete";
    }else {
    $delete = "";
    }
    $output .= "";
    }
    }
    }
    $output .= "
    {$file}<dir>".date("d-M-Y h:i:s", filemtime($file))."
    {$file}".filesize($file)." bytes ".date("d-M-Y h:i:s", filemtime($file))."{$delete}
    ";
    }
    } echo $output;

    /*##############################################################
    ##
    ## Bestand Omschrijving
    ## CVS-versie
    ## ----------------------------------------------------------
    ## $log$
    ##
    ##
    ############################################################*/
    ?>
    [/code]

    After that create a direcory on the same level as the php dir, and call it forms. Put in the next file and call it loginform.html
    [code]
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />


    website - Login











    username:

    password:






    [/code]

    finaly create a direcory users and put in the next script. Call it index.php
    [code]
    <?php
    require_once("../php/userlogin.php");
    ?>
    [/code]
    also put this script in any subdirectory of wich you want to see the directory listing, make sure the path to userlogin.php stays valid, so for subdirs insert another ../ to the path...

    I didn't have enough time yesterday to really finish it, so there still is a bug in it. It was my intention to look for the text that is in hidedir and hide file and even not show the file when the name is part of the filename (strpos !== false) but that didn't work yet... but for the rest it works... Hope someone will find this script usefull. Please let me know...


    ;-)
    -mac-
    mailto:mac_doggie@hotmail.com
    the Netherlands...




Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories