php.de

Zurück   php.de > Webentwicklung > PHP Einsteiger > PHP Tipps 2006

 
 
LinkBack Themen-Optionen Thema bewerten
Alt 30.11.2006, 15:23  
Erfahrener Benutzer
 
Registriert seit: 01.02.2004
Beiträge: 550
cytrobic
Standard Bewertung: .htaccess und .htpasswd AdminTool

Beschreibung: Admintool zur Passwort und Userverwaltung von .htaccess und .htpasswd (like commandline and Strings as return parameters).

Funktionalität: Selbsterklärend durch String rückgabe
erstellt .htaccess und .htpasswd dateien (wenn der Zugriff erlaubt ist)
managen von benutzern und passwörtern (erstellen / löschen)

Wird im Ordner ausgeführt und erstellt die dateien, danach kann man sich anmelden und weitere user über dieses tool hinzufügen.

File: htadmintool.php

Source:
PHP-Code:
<pre>
<?php

session_start
();

  
$SESSION_INDEX "status";
  
$SESSION_VALUE "administrator";

//  $_SESSION['$SESSION_INDEX'] = $SESSION_VALUE;

  
$default_user "default"// MODIFY IT between the "" ! e.g. administrator
  
$default_pass "default"// MODIFY IT between the "" ! e.g. myadminpass

if($_SESSION['$SESSION_INDEX'] == $SESSION_VALUE){
 if(
$_SERVER['QUERY_STRING'] != ""){
  if(!
is_file(".htaccess")){
    echo 
"Notice: .htaccess file not found ! But i try to create it ...\r\n";
    
$acc_file fopen(".htaccess""w");
    echo 
"Notice: .htaccess file created, now i try to write needed data ...\r\n";
    
fwrite($acc_file"AuthUserFile ".str_replace("\\""/"dirname(__FILE__))."/.htpasswd\r\n");
    
fwrite($acc_file"AuthName \"<<< Passwortgeschuetzter Bereich >>>\"\r\n");
    
fwrite($acc_file"AuthType Basic\r\n");
    
fwrite($acc_file"require valid-user");
    
fclose($acc_file);
    echo 
"Done: all data written to .htaccess file !\r\n";
  } else {
    echo 
"Notice: .htaccess file found here !\r\n";
  }

  if(!
is_file(".htpasswd")){
    echo 
"Notice: .htpasswd file not found ! But i try to create it ...\r\n";
    
fclose(fopen(".htpasswd""w"));
    echo 
"Notice: .htpasswd file created, i try to create the user ...\r\n";
    
$file fopen(".htpasswd""r");
    if(
filesize(".htpasswd") > 0){
      
$cont fread($filefilesize(".htpasswd"));
    } else {
      
$cont " ";
    }
    
fclose($file);

    if(!
preg_match("/".$default_user."/i"$cont)){
      echo 
"Notice: Creating the default user !\r\n";
      
$file fopen(".htpasswd""a");
      if(
preg_match("/windows/i"$_ENV['OS'])){
        
fwrite($file$default_user.":".$default_pass."\r\n");
      } else {
        
fwrite($file$default_user.":".crypt($default_pass)."\r\n");
      }
      echo 
"Notice: the defaultuser was created with the defaultpassword !\r\n";
      
fclose($file);
    }

    if(
$username != ""){
     if(
preg_match("/:/i"$username) || preg_match("/:/i"$password)){
       echo 
"Warning: Username or Password have a : in it - user not created !\r\n";
     } else {
      echo 
"Message: Username should be ok, check if it in the .htpasswd file ...\r\n";
      if(
preg_match("/".$username.":/i"$cont)){
        echo 
"Warning: Username already exist in the .htpasswd file !\r\n";
      } else {
    if(
$password != ""){
      
$file fopen(".htpasswd""a");
      if(
preg_match("/windows/i"$_ENV['OS'])){
        
fwrite($file$username.":".$password."\r\n");
      } else {
            
fwrite($file$username.":".crypt($password)."\r\n");
          }
      echo 
"Done: User ".$username." was successfully created !\r\n";
      
fclose($file);
    } else {
      echo 
"Warning: No password was set for user: ".$username."\r\n";
    }
      }
     }
    } else {
      echo 
"Warning: No username was set - so no user has been added !\r\n";
    }
  } else {
    echo 
"Notice: .htpasswd file found here ! I try to create the user ...\r\n";
    
$file fopen(".htpasswd""r");
    if(
filesize(".htpasswd") > 0){
      
$cont fread($filefilesize(".htpasswd"));
    } else {
      
$cont " ";
    }
    
fclose($file);

    if(!
preg_match("/".$default_user."/i"$cont)){
      echo 
"Notice: Creating the default user !\r\n";
      
$file fopen(".htpasswd""a");
      if(
preg_match("/windows/i"$_ENV['OS'])){
        
fwrite($file$default_user.":".$default_pass."\r\n");
      } else {
        
fwrite($file$default_user.":".crypt($default_pass)."\r\n");
      }
      echo 
"Notice: the defaultuser was created with the defaultpassword !\r\n";
      
fclose($file);
    }

    if(
$username != ""){
     if(
preg_match("/:/i"$username) || preg_match("/:/i"$password)){
       echo 
"Warning: Username or Password have a : in it - user not created !\r\n";
     } else {
      echo 
"Message: Username should be ok, check if it in the .htpasswd file ...\r\n";
      if(
preg_match("/".$username.":/i"$cont)){
        echo 
"Warning: Username already exist in the .htpasswd file !\r\n";
      } else {
    if(
$password != ""){
      
$file fopen(".htpasswd""a");
      if(
preg_match("/windows/i"$_ENV['OS'])){
        
fwrite($file$username.":".$password."\r\n");
      } else {
            
fwrite($file$username.":".crypt($password)."\r\n");
          }
      echo 
"Done: User ".$username." was successfully created !\r\n";
      
fclose($file);
    } else {
      echo 
"Warning: No password was set for user: ".$username."\r\n";
    }
      }
     }
    } else {
      echo 
"Warning: No username was set - so no user has added !\r\n";
    }
  }
  echo 
"Script finished !";
 } else {
  
$file split("/"$_SERVER['PHP_SELF']);
  
$file $file[sizeof($file) - 1];
  echo 
"USAGE: ".$file."?action=ACTION&username=USERNAME&password=PASSWORD\r\n";
  echo 
"       ACTION   = create | delete - returns ErrorString if USERNAME already exists or ErrorString if USERNAME doesnt exists !\r\n";
  echo 
"       USERNAME = username\r\n";
  echo 
"       PASSWORD = password (only needed at the create function)\r\n";
  echo 
"\r\n";
  echo 
"Examples:\r\nCreate a new user named 'james' with the password 'pretty':\r\n";
  echo 
$file."?action=create&username=james&password=pretty\r\n\r\n";
  echo 
"Delete a existing user named 'james':\r\n";
  echo 
$file."?action=delete&username=james\r\n\r\n";
  echo 
"NOTICE: USERNAME and PASSWORD cannot have : in it !";

  if(
$default_user == "default" || $default_pass == "default"){
    echo 
"\r\nWARNING: You should change the DEFAULT_USER from line 11 and/or DEFAULT_PASS from line 12 in this file !";
  }
 }
} else {
  
$file split("/"$_SERVER['PHP_SELF']);
  
$file $file[sizeof($file) - 1];

  echo 
"You must have a Valid \$_SESSION['\$SESSION_INDEX'] entry with the Value \"\$SESSION_VALUE\" to have access to this file !\r\n";
  echo 
"Please change: \$SESSION_INDEX in line 6 and \$SESSION_VALUE in line 7 to your specialized values in this file !\r\n\r\n";
  echo 
"To disable the needed SESSION remove the // from line 9 = //  \$_SESSION['\$SESSION_INDEX'] = $SESSION_VALUE;";
}

session_destroy();

?>
__________________
keine
cytrobic ist offline  
Sponsor Mitteilung
PHP Code Flüsterer

Registriert seit: 21.08.2005
Beiträge: 4682
PHP-Kenntnisse:
Fortgeschritten

Alt 30.11.2006, 16:00  
Erfahrener Benutzer
 
Registriert seit: 23.08.2007
Beiträge: 1.510
M3g4Star befindet sich auf einem aufstrebenden Ast
Standard

*öhm*

Und deine Frage dazu ??
M3g4Star ist offline  
Alt 30.11.2006, 16:04  
Erfahrener Benutzer
 
Registriert seit: 21.05.2008
Beiträge: 9.937
Zergling-new wird schon bald berühmt werden
Standard

Du kennst $_SERVER['PHP_AUTH_USER'] und $_SERVER['PHP_AUTH_PW']?
Zergling-new ist offline  
Alt 30.11.2006, 16:16  
Erfahrener Benutzer
 
Registriert seit: 01.02.2004
Beiträge: 550
cytrobic
Standard

Zitat:
Und deine Frage dazu ??
Sinnvoll ? Überfüssig ? Gut ? Gründe ? Was geht besser oder garnicht ?
usw.
PS: MegaStar schreibt sich so: M364574R

@Zergling
ja kenn ich aber dazu mal dies:
http://www.php-homepage.de/manual/fe....http-auth.php
__________________
keine
cytrobic ist offline  
Alt 30.11.2006, 17:07  
Erfahrener Benutzer
 
Registriert seit: 21.05.2008
Beiträge: 9.937
Zergling-new wird schon bald berühmt werden
Standard

Ich kenn die Seite, was willst du mir damit sagen?
Zergling-new ist offline  
Alt 01.12.2006, 06:14  
Erfahrener Benutzer
 
Registriert seit: 13.08.2007
Beiträge: 1.976
KingCrunch befindet sich auf einem aufstrebenden Ast
KingCrunch eine Nachricht über ICQ schicken KingCrunch eine Nachricht über AIM schicken KingCrunch eine Nachricht über MSN schicken KingCrunch eine Nachricht über Yahoo! schicken
Standard

Zitat:
PS: MegaStar schreibt sich so: M364574R
Hat lange gedauert
__________________
Nicht jeder Fehler ist ein Bug.
KingCrunch ist offline  
 


Themen-Optionen
Thema bewerten
Thema bewerten:

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are an
Gehe zu

Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
.htaccess !== ModRewrite Manko10 Off-Topic Diskussionen 2 05.05.2008 11:49
.htaccess login schlägt fehl sternschnuppe99 Server, Hosting und Workstations 6 07.02.2008 13:37
.htaccess Verzeichnisschutz oder Umleitung Igäl Server, Hosting und Workstations 2 24.08.2007 17:23
.htaccess LA-Finest HTML, Usability und Barrierefreiheit 4 28.02.2007 22:39
.htaccess Ausnahme für einzelne Verzeichnisse ssm Server, Hosting und Workstations 0 25.02.2007 19:24
.htpasswd Datei erstellen obi Server, Hosting und Workstations 9 26.09.2006 13:27
.htpasswd (im geschützten Ordner!) per skript ändern! Funky_ PHP Tipps 2006 8 22.07.2006 18:03
register_globals per .htaccess auf off stellen A Hoppe PHP Tipps 2006 4 26.03.2006 12:58
Sichere Vebindung mit MySQL & .htaccess erstellen + Vars PHP Tipps 2005 8 17.03.2005 16:56
.htaccess - require valid-user und trotzdem referer zulassen pixelcut Server, Hosting und Workstations 2 05.01.2005 10:56
[Erledigt] .htaccess verweigert meinen zugriff HTML, Usability und Barrierefreiheit 4 22.09.2004 17:28
uploadberechtigung mit .htaccess PHP Tipps 2004 2 13.08.2004 07:52
Sicherer Bereich mit .htaccess + phpskript auf einem Server PHP Tipps 2004 2 23.07.2004 18:25
Problem mit .htaccess und php PHP Tipps 2004 2 05.07.2004 14:06

Besucher kamen über folgende Suchanfragen bei Google auf diese Seite
htpasswd, htpasswd erstellen, .htpasswd, http://www.php.de/php-tipps-2006/42949-bewertung-htaccess-und-htpasswd-admintool.html, .htpasswd erstellen, htpasswd ausnahmen, php htpasswd tools, htpasswd cannot create file, php htpasswd erstellen, htaccess userverwaltung, \htpasswd: cannot create file\, php notice htaccess, wie die .htpasswd erstellen, php script for administration htpasswd htaccess admin, userverwaltung mit .htpasswd, .htpasswd php, php userverwaltung htpasswd, php bereiche preg_match_all und in text fwrite, .htpasswd ausnahmen, programm verwaltung .htpasswd

Alle Zeitangaben in WEZ +2. Es ist jetzt 13:00 Uhr.




Powered by vBulletin® Version 3.7.2 (Deutsch)
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Aprilia-Forum, Aquaristik-Forum, Liebeskummer-Forum, Zierfisch-Forum, Geizkragen-Forum

Creative Commons License
Dieser Inhalt ist unter einer Creative Commons-Lizenz lizenziert.