-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathunserialize.php
70 lines (68 loc) · 3.19 KB
/
unserialize.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/* This plugin allows viewing Kanbani profiles stored as regular files somewhere
on this server's file system. Suitable for FTP, SFTP, WebDAV transports.
Only !disable it if you have another plugin providing board data, like welcome.php. */
$context->hooks->register("unserialize", function () {
$profile = $this->request["profile"] ?? "";
if (preg_match('/^[\w-]+$/', $profile) &&
($root = $this->config["unserialize.path"]) &&
is_dir($path = "$root/$profile/boards")) {
$syncFile = new Kanbani\SyncFile;
$boards = $filePaths = [];
foreach (scandir($path) as $file) {
if (strrchr($file, ".") === ".kanbani") {
$fileData = null;
$filePath = "$path/$file";
$filePaths[$filePath] = filemtime($filePath);
if ($cacheFile = $this->config["cache"]) {
$syncFile->unserializeHeader(file_get_contents($filePath));
$cacheFile = "$cacheFile/unser.".bin2hex($syncFile->hash);
try {
$fileData = unserialize(Kanbani\getFileContentsWithLock($cacheFile));
touch($cacheFile);
$cacheFile = null; // don't write cache file below, it's ok.
} catch (\Throwable $e) {
// No cache file, corrupted, wrong serialize format, etc.
// Try unserializing the file directly, bypassing the cache.
}
}
if (!$fileData) {
try {
$fileData = (new Kanbani\SyncData)->unserializeFileUsing($syncFile, $filePath);
} catch (Kanbani\MissingSyncFileSecret $e) {
$fileData = $this->hooks->decrypt([
"filePath" => $filePath,
"syncFile" => $syncFile,
"profileID" => $profile,
]);
if (!$fileData) {
$this->hooks->echo_decryptPage(["profileID" => $profile]);
exit;
}
}
if ($cacheFile && $this->config["unserialize.cache"] && !$syncFile->isEncrypted()) {
file_put_contents($cacheFile, serialize($fileData), LOCK_EX);
}
}
$boards = array_merge($boards, $fileData->boards);
}
}
if ($boards) {
$this->custom->unserialize_files = $filePaths;
$this->syncData(new Kanbani\SyncData($boards), $syncFile)
->persistent($profile, $this->config["unserialize.qrCode"]);
foreach ($boards as $board) {
if ($board->id === ($this->request["board"] ?? "")) {
$this->currentBoard($board);
}
}
return true;
}
}
});
$context->hooks->register("updated", function () {
if ($files = ($this->custom->unserialize_files ?? [])) {
clearstatcache();
return array_map("filemtime", array_keys($files)) !== array_values($files);
}
});