diff --git a/pheditor.min.php b/pheditor.min.php new file mode 100644 index 0000000..d16215f --- /dev/null +++ b/pheditor.min.php @@ -0,0 +1,12 @@ +3&&time()-$log[$_SERVER['REMOTE_ADDR']]['time']<86400){die('This IP address is blocked due to unsuccessful login attempts.');}foreach($log as $key=>$value){if(time()-$value['time']>86400){unset($log[$key]);$log_updated=true;}}if(isset($log_updated)){file_put_contents(LOG_FILE,serialize($log));}}session_name('pheditor');session_start();if(isset($_SESSION['pheditor_admin'])===false||$_SESSION['pheditor_admin']!==true){if(isset($_POST['pheditor_password'])&&empty($_POST['pheditor_password'])===false){if(hash('sha512',$_POST['pheditor_password'])===PASSWORD){$_SESSION['pheditor_admin']=true;redirect();}else{$error='The entry password is not correct.';$log=file_exists(LOG_FILE)?unserialize(file_get_contents(LOG_FILE)):array();if(isset($log[$_SERVER['REMOTE_ADDR']])===false){$log[$_SERVER['REMOTE_ADDR']]=array('num'=>0,'time'=>0);}$log[$_SERVER['REMOTE_ADDR']]['num']+= 1;$log[$_SERVER['REMOTE_ADDR']]['time']=time();file_put_contents(LOG_FILE,serialize($log));}}die('Pheditor

Pheditor

'.(isset($error)?'

'.$error.'

':null).'

');}if(isset($_GET['logout'])){unset($_SESSION['pheditor_admin']);redirect();}if(isset($_POST['action'])){if(isset($_POST['file'])&&empty($_POST['file'])===false){$formats=explode(',',EDITABLE_FORMATS);if(($position=strrpos($_POST['file'],'.'))!==false){$extension=substr($_POST['file'],$position+1);}else{$extension=null;}if(empty(EDITABLE_FORMATS)===false&&empty($extension)===false&&in_array(strtolower($extension),$formats)!==true){die('INVALID_EDITABLE_FORMAT');}if(strpos($_POST['file'],'../')!==false||strpos($_POST['file'],'..\'')!==false){die('INVALID_FILE_PATH');}}switch($_POST['action']){case 'open':$_POST['file']=urldecode($_POST['file']);if(isset($_POST['file'])&&file_exists(__DIR__.$_POST['file'])){echo file_get_contents(__DIR__.$_POST['file']);}break;case 'save':$file=__DIR__.$_POST['file'];if(isset($_POST['file'])&&isset($_POST['data'])&&(file_exists($file)===false||is_writable($file))){if(file_exists($file)===false){file_put_contents($file,$_POST['data']);echo 'success|File saved successfully';}elseif(is_writable($file)===false){echo 'danger|File is not writable';}else{if(file_exists($_POST['file'])){file_to_history($file);}file_put_contents($file,$_POST['data']);echo 'success|File saved successfully';}}break;case 'make-dir':$dir=__DIR__.$_POST['dir'];if(file_exists($dir)===false){mkdir($dir);echo 'success|Directory created successfully';}else{echo 'warning|Directory already exists';}break;case 'reload':echo files(__DIR__);break;case 'password':if(isset($_POST['password'])&&empty($_POST['password'])===false){$contents=file(__FILE__);foreach($contents as $key=>$line){if(strpos($line,'define(\'PASSWORD\'')!==false){$contents[$key]="define('PASSWORD', '".hash('sha512',$_POST['password'])."');\n";break;}}file_put_contents(__FILE__,implode($contents));echo 'Password changed successfully.';}break;case 'delete':if(isset($_POST['path'])&&file_exists(__DIR__.$_POST['path'])){$path=__DIR__.$_POST['path'];if($_POST['path']=='/'){echo 'danger|Unable to delete main directory';}elseif(is_dir($path)){if(count(scandir($path))!==2){echo 'danger|Directory is not empty';}elseif(is_writable($path)===false){echo 'danger|Unable to delete directory';}else{rmdir($path);echo 'success|Directory deleted successfully';}}else{file_to_history($path);if(is_writable($path)){unlink($path);echo 'success|File deleted successfully';}else{echo 'danger|Unable to delete file';}}}break;case 'rename':if(isset($_POST['path'])&&file_exists(__DIR__.$_POST['path'])&&isset($_POST['name'])&&empty($_POST['name'])===false){$path=__DIR__.$_POST['path'];$new_path=str_replace(basename($path),'',dirname($path)).DS.$_POST['name'];if($_POST['path']=='/'){echo 'danger|Unable to rename main directory';}elseif(is_dir($path)){if(is_writable($path)===false){echo 'danger|Unable to rename directory';}else{rename($path,$new_path);echo 'success|Directory renamed successfully';}}else{file_to_history($path);if(is_writable($path)){rename($path,$new_path);echo 'success|File renamed successfully';}else{echo 'danger|Unable to rename file';}}}break;}exit;}function files($dir,$first=true){$data='';if($first===true){$data.='';}return $data;}function redirect($address=null){if(empty($address)){$address=$_SERVER['PHP_SELF'];}header('Location: '.$address);exit;}function file_to_history($file){if(is_numeric(MAX_HISTORY_FILES)&&MAX_HISTORY_FILES>0){$file_dir=dirname($file);$file_name=basename($file);$file_history_dir=HISTORY_PATH.DS.str_replace(__DIR__,'',$file_dir);foreach([HISTORY_PATH,$file_history_dir]as $dir){if(file_exists($dir)===false||is_dir($dir)===false){mkdir($dir);}}$history_files=scandir($file_history_dir);foreach($history_files as $key=>$history_file){if(in_array($history_file,['.','..','.DS_Store'])){unset($history_files[$key]);}}$history_files=array_values($history_files);if(count($history_files)>= MAX_HISTORY_FILES){foreach($history_files as $key=>$history_file){if($key<1){unlink($file_history_dir.DS.$history_file);unset($history_files[$key]);}else{rename($file_history_dir.DS.$history_file,$file_history_dir.DS.$file_name.'.'.($key-1));}}}copy($file,$file_history_dir.DS.$file_name.'.'.count($history_files));}} ?>Pheditor
\ No newline at end of file