File indexing completed on 2024-12-22 05:33:23
0001 <?php 0002 0003 /* 0004 * GFX 4 0005 * 0006 * support: happy.snizzo@gmail.com 0007 * website: http://www.gfx3.org 0008 * credits: Claudio Desideri 0009 * 0010 * This software is released under the MIT License. 0011 * http://opensource.org/licenses/mit-license.php 0012 */ 0013 0014 /* Use this class to protect your webpage. 0015 * this works by adding those properties to local generic.conf.php: 0016 * 0017 * enabled|yes 0018 * enabled|no 0019 * enabled|protected 0020 * 0021 * which can be 'yes' or 'no'. If nonsense is written, gfx will keep no 0022 * as default. 0023 * 0024 * password|yourpassword 0025 */ 0026 0027 class EProtect { 0028 0029 private static $localkey; 0030 0031 public static function load(){ 0032 EProtect::$localkey = ELoader::$subsite_path.'pwd'; 0033 0034 //ELoader::$subsite_path; cointains the actual caller of protect call 0035 //keep enabled as standard choice 0036 if(isset(EConfig::$data['generic']['enabled'])){ 0037 //case in which it is 'no' or anything different from 'yes' or 'protected' 0038 if(EConfig::$data['generic']['enabled']!='yes' and EConfig::$data['generic']['enabled']!='protected'){ 0039 die('Access denied.'); 0040 } 0041 0042 //asks for password 0043 if(EConfig::$data['generic']['enabled']=='protected'){ 0044 if(!EProtect::checklogin()){ 0045 echo '<html>'; 0046 die(EProtect::loginform()); 0047 echo '</html>'; 0048 } 0049 } 0050 } 0051 } 0052 0053 public static function logout(){ 0054 EHeaderDataParser::del_cookie(EProtect::$localkey); 0055 $sp = ELoader::$subsite_path; 0056 header('Location: '.$sp.''); 0057 } 0058 0059 /* 0060 * checks login on a subsite using a dedicated cookie 0061 */ 0062 public static function checklogin(){ 0063 $password = EHeaderDataParser::get_cookie(EProtect::$localkey); 0064 if($password){ 0065 if($password == EConfig::$data['generic']['password']){ 0066 return true; 0067 } 0068 } 0069 0070 if(isset($_POST['password'])){ 0071 $password = $_POST['password']; 0072 if($password == EConfig::$data['generic']['password']){ 0073 EHeaderDataParser::set_cookie(EProtect::$localkey, $password, 60); //60seconds*30 = max 30 minutes session 0074 return true; 0075 } 0076 } 0077 0078 return false; 0079 } 0080 /* 0081 * prints a very basic login form, that lets you login with cookies 0082 * to your protected website 0083 */ 0084 public static function loginform(){ 0085 $thispage = ELoader::$request_uri; 0086 $html = ' 0087 <div align="center"> 0088 <form method="POST" action="'.$thispage.'"> 0089 Password: <input type="password" name="password" size="15" /><br /> 0090 0091 <p><input type="submit" value="Login" /></p> 0092 </form> 0093 </div> 0094 '; 0095 0096 return $html; 0097 } 0098 } 0099 0100 ?>