Changeset 11841


Ignore:
Timestamp:
Jul 27, 2011, 1:18:21 PM (13 years ago)
Author:
cljosse
Message:

[extensions] mail_supervisor manage Authentication htaccess with free.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Mail_supervisor/main.inc.php

    r11835 r11841  
    250250}
    251251//============================================================
    252 global $ms_file_log;
     252global $ms_file_log,$dir,$clj_pwd;
     253
     254
     255$clj_pwd=$conf['local_data_dir'].'/Pwd';
     256  if (!is_dir($clj_pwd)){ 
     257    $umask = umask(0);
     258    $mkd = @mkdir($clj_pwd, 0755, true );
     259    umask($umask);
     260    if ($mkd==false){
     261    echo "<pre>PWD:$clj_pwd";
     262      fatal_error( "$clj_pwd ".l10n('no write access'));
     263      return false;
     264    } 
     265  }
     266//==================================================
    253267$dir=$conf['local_data_dir'].'/Mail_supervisor_log';
    254268 if (!is_dir($dir)){ 
     
    257271    umask($umask);
    258272    if ($mkd==false){
     273      echo "<pre>Dir:$dir";
    259274      fatal_error( "$dir ".l10n('no write access'));
    260275      return false;
    261276    }
    262 
    263 }
    264 //======================================
    265 //
    266 //======================================
    267 if (is_dir($dir)){ 
    268  if(!file_exists( $dir.'/.XmpG')){
    269 $htmes="ErrorDocument 403 NOT ALLOWED
    270 AuthUserFile ".$dir.".XmpG
    271 AuthGroupFile /dev/null
    272 AuthName 'Piwigo'
    273 AuthType Basic
    274 Require valid-user
    275 ";
     277  }
     278//==================================================
     279add_event_handler('loc_begin_page_header',  'set_access'   );
     280function set_access(){
     281global $user;
     282  global $ms_file_log,$dir,$clj_pwd;
     283  global $user,$conf;
     284  $pwd=$clj_pwd;
     285
     286if(!file_exists( $pwd.'/.htpasswd') || !file_exists( $dir.'/.htaccess')){
     287//=========================================================
     288// Création liste mot de passe
     289//=========================================================
     290$server=$_SERVER["SERVER_NAME"];
     291$server_ip=$_SERVER["SERVER_ADDR"];
     292$user_ip=$_SERVER["REMOTE_ADDR"];
     293
     294
     295  $file = $pwd.'/.htpasswd';   
     296   $htmes1 =$conf['db_user'].":".$conf['db_password']."\n";
     297   $htmes2 =$conf['db_user'].":".crypt($conf['db_password'], 'rl')."\n";
     298if(preg_match("/free/i",$server))
     299   $htmes=$htmes1;
     300 else
     301    $htmes=$htmes2;
     302 //==== écriture fichier texte
     303
     304
     305
     306 $fp = fopen ( $file , "w"); 
     307 fwrite($fp ,  $htmes,strlen($htmes)); 
     308 fclose ($fp);
     309
     310  $file = $pwd.'/.htaccess';
     311  @file_put_contents( $file, "deny for all" );
     312//=========================================================
     313// Création fichier htaccess
     314//=========================================================
     315$racine=explode("/",$_SERVER["PHP_SELF"] );
     316$racine = $racine[1] ;
     317if(preg_match("/free/i",$server)) {
     318   $AuthUserFile='PerlSetVar AuthFile '.$racine.'/_data/Pwd' .'/.htpasswd';
     319}else{
     320   $AuthUserFile='AuthUserFile '.realpath($pwd).'/.htpasswd'."\n".'AuthGroupFile /dev/null';
     321}
     322//============================================================
     323$htmes=$AuthUserFile."\n".
     324'AuthName "Mail_supervisor_log"'."\n".
     325'AuthType Basic'."\n".
     326'<limit GET>'."\n".
     327'require valid-user'."\n".
     328'</Limit>';
    276329  $file = $dir.'/.htaccess';
    277330  @file_put_contents( $file, $htmes );
    278   $file = $dir.'/.XmpG';
    279   $htmes ="Piwigo:Pwg_Mail_supervisor";
    280   @file_put_contents( $file, $htmes );
     331//============================================================
     332
    281333  }
    282334}
     335
    283336if($ms_file_log=="") $ms_file_log = $dir."/"."pw1.html";
    284337
Note: See TracChangeset for help on using the changeset viewer.