Created
August 10, 2021 10:50
-
-
Save brain90/4baf1a560b4ea4bd3f4c9c1e8a7c554a to your computer and use it in GitHub Desktop.
os ticket dump whole attachment to file system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// path to restore image | |
$path = '/data/helpdesk'; | |
// db config | |
$host = 'localhost'; | |
$dbname = 'helpdesk'; | |
$user = 'your_user'; | |
$pass = 'your_pass'; | |
$dsn = "mysql:host=$host;dbname=$dbname;"; | |
$options = [ | |
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, | |
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, | |
PDO::ATTR_EMULATE_PREPARES => false, | |
]; | |
global $db; | |
try { | |
$db = new PDO($dsn, $user, $pass, $options); | |
} catch (\PDOException $e) { | |
throw new \PDOException($e->getMessage(), (int)$e->getCode()); | |
} | |
$sql = "SELECT | |
ost_thread_entry.id as thread_entry_id, | |
ost_attachment.file_id, | |
ost_file.name, | |
GROUP_CONCAT(ost_file_chunk.filedata) as filedata | |
FROM | |
ost_thread_entry | |
JOIN ost_attachment ON ost_attachment.object_id = ost_thread_entry.id | |
JOIN ost_file ON ost_file.id = ost_attachment.file_id | |
JOIN ost_file_chunk ON ost_file_chunk.file_id = ost_attachment.file_id | |
group by ost_attachment.file_id;"; | |
$salt = 's3cr3t_s4lt!'; | |
$stmt = $db->query($sql); | |
while ($row = $stmt->fetch()) | |
{ | |
$hash = $path . '/' . hash('sha256', $salt . $row['thread_entry_id'] . $row['file_id']); | |
mkdir($hash); | |
file_put_contents($hash . "/" . $row['name'], $row['filedata']); | |
echo 'dumping: ' . $row['thread_entry_id'] . "\n"; | |
} | |
echo 'DONE'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment