class defcon_library{
//Deffense state 1
function defcon(){
$backupdir = "backup";
echo "<meta http-equiv='REFRESH' content='5;URL=./'>";
if(!is_dir($backupdir)){
print "<b>".ucfirst($backupdir)."</b> not exist in main directory!";
print "<br/>I want to create a <b><a href='?func=create'>new</a></b> one";
}
else{
$dirscan = scandir("./");
$num = 1;
foreach($dirscan as $value){
if(!preg_match("/.php/s", $value)){continue;}
else{
$addfile = $num++;
if(!is_file("./$backupdir/filelist.beam")){
$backupfile = fopen("./$backupdir/filelist.beam", "w");
}
else{
$value = basename($value, ".php");
$vzemi = @file_get_contents($value.".php");
$vzemi2 = @file_get_contents($backupdir."/".(hash_file('sha512', $value.".php")));
if(!file_exists($backupdir."/".(hash_file('sha512', $value.".php")))){
$error = 1;
$status = "<font color='#ffae00'>Not exist</font>";
}
elseif(!file_exists($value.".php")){
$error = 1;
$status = "<font color='red'>Deleted</font>";
}
elseif(base64_decode($vzemi2) != $vzemi){
$error = 1;
$status = "<font color='red'>Missing/Change</font> | <a href='?func=restore'>Restore it</a>";
}
elseif($error == 0){
$status = "<font color='green'>OK</font>";
$backupfile = fopen("./$backupdir/filelist.beam", "w+");
fwrite($backupfile, $addfile);
@fclose($backupfile);
}
else{}
print ucfirst($value)."- <a href='?func=backup&fileid=$value.php'>Copy it</a> | <a href='?func=remove&fileid=$value.php'>Remove it</a> | Status: $status<br/>";
}
}
}
}
//Create directory function
if(htmlspecialchars(addslashes($_GET[func])) == "create"){
mkdir("./$backupdir") or die("<br/>Can't create <b>".ucfirst($backupdir)."</b>, Windows do not allowed it");
print "<br/><b>".ucfirst($backupdir)."</b> is created";
echo "<meta http-equiv='REFRESH' content='2;URL=./'>";
}
//Remove function
elseif(htmlspecialchars(addslashes($_GET[func])) == "remove"){
unlink(htmlspecialchars(addslashes($_GET[fileid])));
print "<br/><b>".ucfirst(htmlspecialchars(addslashes($_GET[fileid])))."</b> is removed from main directory!";
echo "<meta http-equiv='REFRESH' content='2;URL=./'>";
}
//Backup function
elseif(htmlspecialchars(addslashes($_GET[func])) == "backup"){
if(file_exists(hash_file('sha512', $file))){
print "<br/><b>".ucfirst(htmlspecialchars(addslashes($_GET[fileid])))."</b> exists in <b>".ucfirst($backupdir)."</b> directory!";
echo "<meta http-equiv='REFRESH' content='2;URL=./'>";
}
else{
$file = htmlspecialchars(addslashes($_GET[fileid]));
$file = hash_file('sha512', $file);
$getcontent = file_get_contents(htmlspecialchars(addslashes($_GET[fileid])));
$getcontent = base64_encode($getcontent);
$newfile = fopen("./$backupdir/$file", "w");
fwrite($newfile, $getcontent);
@fclose($newfile);
print "<br/><b>".ucfirst(htmlspecialchars(addslashes($_GET[fileid])))."</b> is store in <b>".ucfirst($backupdir)."</b> directory!";
echo "<meta http-equiv='REFRESH' content='2;URL=./'>";
}
}
}
}