Configuration
Version: 4.1
Author: AskApache
Author URI: http://www.askapache.com
== Installation ==
1. Extract zip in plugins directory
2. Activate the Plugin
3. Setup plugin options
*/
/*
/--------------------------------------------------------------------\
| |
| License: GPL |
| |
| AskApache Password Protect Plugin - Adds HTTP Basic Authentication |
| Copyright (C) 2008, AskApache, www.askapache.com |
| All rights reserved. |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of the GNU General Public License |
| along with this program; if not, write to the |
| Free Software Foundation, Inc. |
| 51 Franklin Street, Fifth Floor |
| Boston, MA 02110-1301, USA |
| |
\--------------------------------------------------------------------/
*/
?>
',
'Order Deny,Allow',
'Deny from All',
'Satisfy Any',
'AuthName "'.$aa_PP['realm'].'"',
'AuthUserFile '.$aa_PP['htpasswd'],
'AuthType Basic',
'Require valid-user',
'',
'# END sid800');
break;
case 'sid900':
$sidrules=array(
'# BEGIN sid900',
'Order Deny,Allow',
'Deny from All',
'AuthName "'.$aa_PP['realm'].'"',
'AuthUserFile '.$aa_PP['htpasswd'],
'AuthType Basic',
'Require valid-user',
'
';print_r($_POST);echo '';} update_option('askapache_password_protect',$aa_PP); } // aa_pp_admin_header function aa_pp_admin_header(){ global $aa_PP; if (!current_user_can(8)||!current_user_can('upload_files')) die(__("You are not allowed to be here")); $aa_PP=get_option('askapache_password_protect'); if($_SERVER['REQUEST_METHOD']==='POST') { check_admin_referer('askapache-password-protect-update_modify'); aa_pp_get_post_values(); } update_option('askapache_password_protect',$aa_PP); } // aa_pp_main_page function aa_pp_main_page() { global $aa_PP; if (! user_can_access_admin_page()) die( __('You do not have sufficient permissions to access this page.') ); if (!current_user_can(8)||!current_user_can('upload_files'))die(__("You are not allowed to be here")); ?>
by | Google 404 Plugin - .htaccess tutorial - .htaccess help forum
NOTE: This is an incredibly powerful plugin as it modifies your server as opposed to modifying wordpress. This can easily take your site down. If you experience a bad error, delete the .htaccess files on the server using ftp, ssh, webftp, contact support, etc.. If everything works, you will love this plugin and what it will do for you.
";
if(!is_writable(ABSPATH))echo ABSPATH.' needs to be writable by php
';
if(!is_writable(ABSPATH.'wp-admin/'))echo ABSPATH.'wp-admin/ needs to be writable by php
';
if(!is_writable(ABSPATH.'wp-content/'))echo ABSPATH.'wp-content/ needs to be writable by php
';
echo "
NOTE: Never chmod 777 anything, if you must, for directories use 766 but only if 755 will not work and 750 is even better. Likewise the highest you should ever set a file is 666.
"; echo "Please make the required directories writable by php and reload this page.
"; } else { echo ' [ SUCCESS ]'; $error401='eNqFUU1PwkAQvTfpfxgbDnCgQ40nKIsIGEhQG60HT2RpV7bhY9fdIRV/vdtSEi/E05vMvDdvJi8'. 'eaanB99R6ZYkbancGvncvBc+FaQfzNE0wCiO460UwPpJUpvjhVKgDvIqvY2FEHnQG8EfxRpyOtv+vYMR'. '8L76ZvkzSj2QG8/RpCcn7w3IxgaCLuJilj4jTdHqe3IY9xNlzUGkk7Xc1OsMKqaCdYNftYjwzHBUvmrX'. 'KT/WOiF0TuZEjaJYYRSIjkcP6BDEHacTnMJBEuo9YlmXI7ZZrnkkRZmqPpTK5NsJalMSzzBVdza2t2l1'. '9XhVWHwRsbLfjWgdJQ4DGyx0SI2cx6vroy7F4+bxKzPdam6HLbCNole0EP9S5iUwqaG2q6rugBurJiP0CaXaZXQ=='; $testimage='eNrj5bKxL8go4OVyyEhNTEkt0lByzs8rSc0r0Q2pLEi1UsjMTUxP1U/PTFPStMaiyCc1L70kw0rBxBIsn5qcka9'. 'QkJicraHkoaWko2RibmJpYmZsYWxpZmhgaGAAwpYgGgrSkABExMgwzdLAxMDU0ATEAaJkuGKofrC4kakJiG2cBLG2IrMESmmA+PZ2AEyvN7w='; $testerror401file=gzuncompress(base64_decode($error401)); if(AA_PP_DEBUG){ aa_pp_mess('Test File 401.php'); aa_pp_mess(''.htmlentities($testerror401file).''); } $testimagefile=ltrim(gzuncompress(base64_decode($testimage))); if(AA_PP_DEBUG){ aa_pp_mess('Test File test.php'); aa_pp_mess('
'.htmlentities($testimagefile).''); } $absolute_to_root_modrewrite=aa_pp_mktempdir(ABSPATH.'wp-content/', 'askapache'); $rel_to_docroot_mod_rewrite=$aa_PP['root_path'].basename($absolute_to_root_modrewrite).'/'; $testing_mods=$aa_PP['root_path'].'wp-content/'.basename($absolute_to_root_modrewrite).'/test.php'; $testing_mods_401=$aa_PP['root_path'].'wp-content/'.basename($absolute_to_root_modrewrite).'/401.php'; $testing_mods_root=$aa_PP['root_path'].'wp-content/'.basename($absolute_to_root_modrewrite).'/'; if(!aa_pp_file_put_c("$absolute_to_root_modrewrite/401.php",$testerror401file)) die("Error Creating test pages for HTTP Authentication Enabled Test files!"); if(!aa_pp_file_put_c("$absolute_to_root_modrewrite/test.php",$testimagefile)) die("Error Creating test pages for HTTP Authentication Enabled Test files!"); $modrewritetesthtaccess=array( "DirectoryIndex $rel_to_docroot_mod_rewrite401.php 401.php", "ErrorDocument 401 $rel_to_docroot_mod_rewrite401.php", "ErrorDocument 403 $rel_to_docroot_mod_rewrite401.php", "
401 Response: '.$rv; if(function_exists('get_status_header_desc'))echo ' '.get_status_header_desc($rv); echo '
'; echo "305 Response: '.$rv; if(function_exists('get_status_header_desc'))echo ' '.get_status_header_desc($rv); echo '
'; echo "307 Response: '.$rv; if(function_exists('get_status_header_desc'))echo ' '.get_status_header_desc($rv); echo '
'; echo "503 Response: '.$rv; if(function_exists('get_status_header_desc'))echo ' '.get_status_header_desc($rv); echo '
'; $htpasswds=array(aa_pp_hashit('CRYPT','testCRYPT','testCRYPT'),aa_pp_hashit('MD5','testMD5','testMD5'),aa_pp_hashit('SHA1','testSHA1','testSHA1'),aa_pp_hashit('PLAIN','testPLAIN','testPLAIN')); $absolute_to_root_encryptions=aa_pp_mktempdir(ABSPATH.'wp-content/', 'askapache'); $rel_to_docroot_encryptions=$aa_PP['root_path'].basename($absolute_to_root_encryptions).'/'; $testing_encryptions=$aa_PP['root_path'].'wp-content/'.basename($absolute_to_root_encryptions).'/test.php'; if(!aa_pp_insert_mark("$absolute_to_root_encryptions/.htpasswda1", 'Test', $htpasswds)) die("Error Creating $absolute_to_root_encryptions .htpasswda1 Test files!"); if(!aa_pp_file_put_c("$absolute_to_root_encryptions/401.php",$testerror401file)) die("Error Creating test pages for HTTP Authentication Enabled Test files!"); if(!aa_pp_file_put_c("$absolute_to_root_encryptions/test.php",$testimagefile)) die("Error Creating $absolute_to_root_encryptions test.php for HTTP Authentication Enabled Test files!"); $encryptiontest=array( "DirectoryIndex $rel_to_docroot_encryptions401.php 401.php", "ErrorDocument 401 $rel_to_docroot_encryptions401.php", "ErrorDocument 403 $rel_to_docroot_encryptions401.php", 'Order Deny,Allow','Deny from All','Satisfy Any', 'AuthName "askapache test"', "AuthUserFile $absolute_to_root_encryptions/.htpasswda1", "AuthType Basic", "Require valid-user"); if(!aa_pp_insert_mark("$absolute_to_root_encryptions/.htaccess", 'Test', $encryptiontest)) die("Couldnt create $absolute_to_root_encryptions/.htaccess file!"); foreach($aa_PP['algorithms'] as $key=>$value){ $rg=aa_pp_test_userpass("test$key","test".$key,$testing_encryptions); $rb=aa_pp_test_userpass("fail$key","fail".$key,$testing_encryptions); sleep(1); if($rb=='401'){ $aa_PP['algorithms'][$key]['enabled']='1'; $aa_PP['htaccess_support']='1'; } else $aa_PP['algorithms'][$key]['enabled']='0'; if($rg=='200'){ $aa_PP['algorithms'][$key]['enabled']='1'; $aa_PP['htaccess_support']='1'; } else $aa_PP['algorithms'][$key]['enabled']='0'; echo "200 Response: '.$rg;
if(function_exists('get_status_header_desc'))echo ' '.get_status_header_desc($rg); echo '';
echo '
401 Response:: '.$rb;
if(function_exists('get_status_header_desc'))echo ' '.get_status_header_desc($rb); echo '
Sending this request for the test');aa_pp_mess('
'.htmlentities($http_req).'');} if( false!= ($fp = @fsockopen($target, $_SERVER['SERVER_PORT'], $errno, $errstr, 15)) && is_resource($fp)){ @socket_set_timeout($fp,15); if(!fwrite($fp,$http_req,strlen($http_req)))die('bad');; do{ $respons .= fgets($fp, 1160); $fp_status = @socket_get_status($fp); if( $fp_status['timed_out'] ) break; }while (true && !feof($fp)); if(@fclose($fp)){ if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$respons, $status))$response_code=$status[1]; else return false;//return false; $respons;//die('garbled response!'); $response = explode("\r\n\r\n", $respons, 2); } }else die('bad fsockopen'); if(AA_PP_DEBUG){aa_pp_mess('
'.htmlentities($respons).'');} return $response_code; } function aa_pp_clean_test($path, $d=0){ if (substr($path,strlen($path)-1)!= '/') $path .= '/'; if ($handle = opendir ($path)){ while (false !== ($file=readdir($handle))){ if ($file == '.' || $file == '..' || strpos($file,'askapache')===false && $d <= 0) continue; $file = $path.$file; if (!is_dir ($file) && !is_link($file)) @unlink($file); elseif(!is_link($file)) { aa_pp_clean_test($file.'/', $d+1); @rmdir($file.'/'); } } closedir ($handle); } if(AA_PP_DEBUG){aa_pp_mess('Removed temporary test directory'.$path);} } function aa_pp_notify_mail($username,$pass){ $result=false; if ( !is_object( $aappmailer ) || !is_a( $aappmailer, 'PHPMailer' ) && file_exists(ABSPATH . WPINC . '/class-phpmailer.php')) { require_once ABSPATH . WPINC . '/class-phpmailer.php'; $aappmailer = new PHPMailer(); $attach1=aa_pp_gzip($aa_PP['blog_root_htaccess'],ABSPATH.'wp-admin/htaccess-backup.zip'); $attach2=aa_pp_gzip(ABSPATH.'wp-admin/.htaccess',ABSPATH.'wp-admin/wpadmin-htaccess-backup.zip'); $message = sprintf("Your AskApache Protected WordPress blog has been modified, keep this email for your records. You can log in to the administrator account with the following information: Username: %1\$s Password: %2\$s We hope you enjoy your new security. Thanks! --AskApache http://www.askapache.com/ ",$username,$pass); $sitename = str_replace('www.','','wordpress@'.strtolower( $_SERVER['SERVER_NAME'])); $user = wp_get_current_user(); $aappmailer->ClearAddresses(); $aappmailer->ClearAllRecipients(); $aappmailer->ClearAttachments(); $aappmailer->ClearBCCs(); $aappmailer->ClearCCs(); $aappmailer->ClearCustomHeaders(); $aappmailer->ClearReplyTos(); $aappmailer->FromName='WordPress'; $aappmailer->From=$from_email; $aappmailer->AddAddress( $user->user_email ); $aappmailer->Subject = '['.get_option('blogname').'] AskApache Password Protection'; $aappmailer->Body = $message; $aappmailer->AddAttachment($attach1); $aappmailer->AddAttachment($attach2); $aappmailer->IsMail(); $aappmailer->IsHTML( false ); $aappmailer->CharSet=get_bloginfo( 'charset' ); $result = @$aappmailer->Send(); } aa_pp_unlink($attach1); aa_pp_unlink($attach2); return $result; } function aa_pp_generate_password($length = 5) { $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$!"; $p = ''; for ( $i = 0; $i < $length; $i++ )$p .= substr($chars, mt_rand(0, strlen($chars) - 1), 1); return $p; } function aa_pp_mess($message=''){ ?>
'.$hash.'');} return $hash; } // aa_pp_activate function aa_pp_activate(){ global $aa_PP; $oldoptions=array('aa_home_folder','aa_wpadmin_folder','aa_htpasswd_file','aa_htaccess_file','aa_original_htpasswd','aa_original_htaccess','aa_plugin_message','aa_plugin_version','aa_home','aa_wpadmin', 'aa_htpasswd_f','aa_htaccess_f','aa_user','aa_plugin_message','aa_home_folder','aa_wpadmin_folder','aa_htpasswd_file','aa_htaccess_file','aa_original_htpasswd','aa_original_htaccess','aa_plugin_message', 'aa_plugin_version','aa_pp_docroot_htaccess','aa_pp_wp_includes_htaccess','aa_pp_wp_content_htaccess','aa_pp_wp_includes_htaccess','aa_pp_main_base64','aa_pp_ok'); foreach($oldoptions as $key){ delete_option($key); } $aa_PP['htpasswd'] = ABSPATH.'.htpasswda1'; $aa_PP['htaccessusers']=aa_pp_current_users($aa_PP['htpasswd'],'AskApache PassPro'); $aa_PP['realm']='Protected By AskApache'; $aa_PP['user']='admin'; $aa_PP['format']='SHA1'; $home_path = parse_url(get_option('home')); $aa_PP['plugin_data'] =get_plugin_data(__FILE__); $aa_PP['pass'] =aa_pp_generate_password(); $aa_PP['blog_root_htaccess'] = ABSPATH.'.htaccess'; $aa_PP['root_path'] =$home_path['path'].'/'; $aa_PP['change_htpasswd'] ='0'; $aa_PP['change_htaccess'] ='0'; $aa_PP['config_step'] ='1'; $aa_PP['htaccess_support'] ='0'; $aa_PP['mod_alias_support'] ='0'; $aa_PP['mod_security_support'] ='0'; $aa_PP['mod_rewrite_support'] ='0'; $aa_PP['mod_rewrite_on'] ='0'; $aa_PP['algorithms']=array( 'CRYPT' => array('enabled'=>0,'desc'=>' - Unix only. Uses the traditional Unix crypt function with a randomly-generated 32-bit salt.'), 'MD5' => array('enabled'=>0,'desc'=>' - Base64-encoded SHA-1 digest of the password.'), 'SHA1' => array('enabled'=>0,'desc'=>' - Apache-specific algorithm using an iterated MD5 digest of randoml 32-bit salt and the password.'), 'PLAIN' => array('enabled'=>0,'desc'=>' - (i.e. unencrypted) Windows, BEOS, & Netware only') ); $aa_PP['S']['sid900']=array( 'ON'=>'0', 'TITLE'=>'wp-admin/*.*', 'FILE'=>ABSPATH.'wp-admin/.htaccess', 'RESP'=>'401', 'DESC'=>'Requires a valid user/pass to access any non-static (css, js, images) file in this directory'); $aa_PP['S']['sid1000']=array( 'ON'=>'0', 'TITLE'=>'wp-content/*.php', 'FILE'=>ABSPATH.'wp-content/.htaccess', 'RESP'=>'401', 'DESC'=>'Denies any Direct request for files ending in .php with a 403 Forbidden'); $aa_PP['S']['sid800']=array( 'ON'=>'0', 'TITLE'=>'wp-login.php', 'FILE'=>$aa_PP['blog_root_htaccess'], 'RESP'=>'401', 'DESC'=>'Requires a valid user/pass to access the login page'); $aa_PP['S']['sid1010']=array( 'ON'=>'0', 'TITLE'=>'wp-includes/*.php', 'FILE'=>ABSPATH.'wp-includes/.htaccess', 'RESP'=>'403', 'DESC'=>'Denies any Direct request for files ending in .php with a 403 Forbidden'); $aa_PP['S']['sid1015']=array( 'ON'=>'0', 'TITLE'=>'REQUEST_METHODS', 'FILE'=>$aa_PP['blog_root_htaccess'], 'RESP'=>'403', 'DESC'=>'Denies any request not using !GET|POST|OPTIONS|PUT|HEAD'); $aa_PP['S']['sid700']=array( 'ON'=>'0', 'TITLE'=>'Directory Protection', 'FILE'=>$aa_PP['blog_root_htaccess'], 'RESP'=>'Disable', 'DESC'=>'Enable the DirectoryIndex Protection, preventing directory index listing'); $aa_PP['S']['sid1030']=array( 'ON'=>'0', 'TITLE'=>'SSL Site', 'FILE'=>$aa_PP['blog_root_htaccess'], 'RESP'=>'301', 'DESC'=>'Redirects all non-SSL (https) requests to your https url'); // delete these old files if(is_file($aa_PP['S']['sid1010']['FILE'])) aa_pp_unlink($aa_PP['S']['sid1010']['FILE']); if(is_file($aa_PP['S']['sid1000']['FILE'])) aa_pp_unlink($aa_PP['S']['sid1000']['FILE']); aa_pp_insert_mark($aa_PP['blog_root_htaccess'], 'AskApache PassPro', array('')); //if(is_file($aa_PP['htpasswd'])) aa_pp_unlink($aa_PP['htpasswd']); update_option('askapache_password_protect',$aa_PP); } // aa_pp_deactivate function aa_pp_deactivate(){ global $aa_PP; $aa_PP=get_option('askapache_password_protect'); aa_pp_unlink($aa_PP['S']['sid900']['FILE']); //aa_pp_unlink($aa_PP['htpasswd']); aa_pp_insert_mark($aa_PP['blog_root_htaccess'], 'AskApache PassPro', array('')); delete_option('askapache_password_protect'); } register_activation_hook(__FILE__, 'aa_pp_activate'); register_deactivation_hook(__FILE__, 'aa_pp_deactivate'); if( strpos($_SERVER['REQUEST_URI'], basename(__FILE__))!==false ) add_action('admin_head', 'aa_pp_admin_header'); add_action('admin_menu', 'aa_pp_options_setup1'); ?>