Title: [219093] trunk/Websites/perf.webkit.org
Revision
219093
Author
[email protected]
Date
2017-07-03 14:16:01 -0700 (Mon, 03 Jul 2017)

Log Message

Add an admin page to manage uploaded files
https://bugs.webkit.org/show_bug.cgi?id=174089

Reviewed by Andreas Kling.

Add an admin page to see the disk usage per user as well as the total, and to prune any zombie files (ones marked
as deleted but aren't actually deleted in the filesystem).

* public/admin/files.php: Added.
(format_size): Added.
* public/include/admin-header.php:

Modified Paths

Added Paths

Diff

Modified: trunk/Websites/perf.webkit.org/ChangeLog (219092 => 219093)


--- trunk/Websites/perf.webkit.org/ChangeLog	2017-07-03 21:14:52 UTC (rev 219092)
+++ trunk/Websites/perf.webkit.org/ChangeLog	2017-07-03 21:16:01 UTC (rev 219093)
@@ -1,5 +1,19 @@
 2017-07-03  Ryosuke Niwa  <[email protected]>
 
+        Add an admin page to manage uploaded files
+        https://bugs.webkit.org/show_bug.cgi?id=174089
+
+        Reviewed by Andreas Kling.
+
+        Add an admin page to see the disk usage per user as well as the total, and to prune any zombie files (ones marked
+        as deleted but aren't actually deleted in the filesystem).
+
+        * public/admin/files.php: Added.
+        (format_size): Added.
+        * public/include/admin-header.php:
+
+2017-07-03  Ryosuke Niwa  <[email protected]>
+
         Roots uploaded by bots don't get author specified properly
         https://bugs.webkit.org/show_bug.cgi?id=174087
 

Added: trunk/Websites/perf.webkit.org/public/admin/files.php (0 => 219093)


--- trunk/Websites/perf.webkit.org/public/admin/files.php	                        (rev 0)
+++ trunk/Websites/perf.webkit.org/public/admin/files.php	2017-07-03 21:16:01 UTC (rev 219093)
@@ -0,0 +1,83 @@
+<?php
+
+include('../include/admin-header.php');
+include('../include/uploaded-file-helpers.php');
+
+if ($db) {
+
+    if ($action == 'prune-zombie-files') {
+        $uploaded_file_rows = $db->select_rows('uploaded_files', 'file', array('deleted_at' => NULL));
+        $file_by_id = array();
+        foreach ($uploaded_file_rows as &$row)
+            $file_by_id[$row['file_id']] = &$row;
+
+        $file_name_list = scandir(config_path('uploadDirectory', ''));
+        foreach ($file_name_list as $file_name) {
+            if ($file_name == '.' || $file_name == '..')
+                continue;
+            if (!preg_match('/^(\d+)((\.[A-Za-z0-9]{1,5}){1,2})$/', $file_name, $matches)) {
+                echo 'Unknown file: ' . htmlspecialchars($file_name) . '<br>';
+                continue;
+            }
+            $file_name = $matches[0];
+            $file_path = config_path('uploadDirectory', $file_name);
+            $file_id = $matches[1];
+            if (!array_key_exists($file_id, $file_by_id)) {
+                echo "Deleting a zombie file: $file_name...";
+                if (file_exists($file_path) && !unlink($file_path))
+                    echo "Failed";
+                else
+                    echo "Deleted";
+                echo "<br>";
+            }
+        }
+    }
+
+    $files_per_user = $db->query_and_fetch_all('SELECT file_author AS "author", SUM(file_size) AS "usage", COUNT(file_id) AS "count"
+        FROM uploaded_files GROUP BY file_author');
+
+    echo <<< END
+<table>
+    <thead>
+        <tr>
+            <td>User</td>
+            <td>Number of Files</td>
+            <td>Disk Usage</td>
+        </tr>
+    </thead>
+    <tbody>
+END;
+
+    function format_size($usage, $quota) {
+        $megabytes = round($usage / MEGABYTES);
+        $percent = round(10000 * $usage / $quota) / 100;
+        return "$megabytes MB ($percent%)";
+    }
+
+    $quota_per_user = config('uploadUserQuotaInMB');
+    $total_disk_usage = 0;
+    $total_file_count = 0;
+
+    foreach ($files_per_user as $row) {
+        $user_name = $row['author'] ? $row['author'] : 'anonymous';
+        $file_count = $row['count'];
+        $disk_usage = format_size($row['usage'], $quota_per_user * MEGABYTES);
+        echo "    <tr><td>$user_name</td><td>$file_count</td><td>$disk_usage</td></tr>";
+        $total_disk_usage += $row['usage'];
+        $total_file_count += $file_count;
+    }
+
+    $total_disk_usage = format_size($total_disk_usage, config('uploadTotalQuotaInMB') * MEGABYTES);
+    echo "    <tr><td>Total</td><td>$total_file_count</td><td>$total_disk_usage</td>";
+
+    echo <<< END
+    </tbody>
+</table>
+<form method="POST"><button name="action" value="prune-zombie-files" type="submit">Prune zombie files (slow)</button></form>
+END;
+
+}
+
+include('../include/admin-footer.php');
+
+?>

Modified: trunk/Websites/perf.webkit.org/public/include/admin-header.php (219092 => 219093)


--- trunk/Websites/perf.webkit.org/public/include/admin-header.php	2017-07-03 21:14:52 UTC (rev 219092)
+++ trunk/Websites/perf.webkit.org/public/include/admin-header.php	2017-07-03 21:16:01 UTC (rev 219093)
@@ -22,6 +22,7 @@
     <li><a href=""
     <li><a href=""
     <li><a href="" Trackers</a></li>
+    <li><a href=""
 </ul>
 </header>
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to