Diff -- /var/www/vhosts/3dshawn.com/site1/settings.cgi

O Operator
Diff

/var/www/vhosts/3dshawn.com/site1/settings.cgi

modified on local at 2026-07-12 00:19:33

Added
+27
lines
Removed
-0
lines
Context
105
unchanged
Blobs
from c41f0faf4e6b
to 7dd39d832ea1
Restore this content →
Unified diff
Naive LCS-based line diff. Additions in emerald, deletions in rose. Both sides decompressed live from BLOB_STORE.
11#!/usr/bin/perl
22#======================================================================
33# DriftSense -- /settings.cgi
44#
55# Read-only view of the resolved config file + editable form for the
66# SCAN_GLOBALS row (global ignore patterns, allowed file types, max
77# file size).
88#======================================================================
99use strict;
1010use warnings;
1111use CGI ();
1212use MODS::Config;
1313use MODS::DBConnect;
1414use MODS::Template;
1515use MODS::PageWrapper;
1616
1717my $cgi = CGI->new;
1818my $cfg = MODS::Config->new;
1919my $db = MODS::DBConnect->new;
2020my $tpl = MODS::Template->new;
2121
2222$|=1;
2323my $dbh = $db->db_connect or die "DB connect failed\n";
2424
2525# ---- POST: update globals ------------------------------------------
2626if (($ENV{REQUEST_METHOD} || '') eq 'POST' && $cgi->param('save_globals')) {
2727 my $ign = $cgi->param('global_ignore_list') // '';
2828 my $ftyp = $cgi->param('global_file_type_filter') // '';
2929 my $mx = int($cgi->param('global_max_file_size_bytes') || 0);
3030
3131 # Normalize whitespace on ignore list -> comma-joined single-line
3232 my @clean_ign;
3333 for my $tok (split /[,\r\n]+/, $ign) {
3434 $tok =~ s/^\s+|\s+$//g;
3535 push @clean_ign, $tok if length $tok;
3636 }
3737 my $normalized = join(',', @clean_ign);
3838
3939 my $q_ign = $dbh->quote($normalized);
4040 my $q_ftyp = $dbh->quote($ftyp);
4141 $mx = 'NULL' unless $mx;
4242
4343 $db->db_readwrite($dbh, qq~
4444 UPDATE SCAN_GLOBALS
4545 SET global_ignore_list = $q_ign,
4646 global_file_type_filter = $q_ftyp,
4747 global_max_file_size_bytes = $mx
4848 WHERE id = 1
4949 ~, __FILE__, __LINE__);
5050 $db->db_disconnect($dbh);
5151 print "Status: 302 Found\nLocation: /settings.cgi?saved=1\n\n";
5252 exit;
5353}
5454
5555print "Content-Type: text/html; charset=utf-8\nCache-Control: no-cache\n\n";
5656
5757my $all = $cfg->all;
5858
5959# Blob store stats
6060my $blob_stats = $db->db_readwrite($dbh, q~
6161 SELECT COUNT(*) AS blob_ct,
6262 COALESCE(SUM(size_uncompressed), 0) AS bytes_uncomp,
6363 COALESCE(SUM(size_compressed), 0) AS bytes_comp,
6464 COALESCE(SUM(ref_count), 0) AS total_refs
6565 FROM BLOB_STORE
66~, __FILE__, __LINE__);
67
68# Recent purge stats (last 30 days) for the tile
69my $recent_purge = $db->db_readwrite($dbh, q~
70 SELECT
71 SUM(CASE WHEN dry_run = 1 THEN 1 ELSE 0 END) AS dry_ct,
72 SUM(CASE WHEN dry_run = 1 THEN freed_bytes ELSE 0 END) AS dry_bytes,
73 SUM(CASE WHEN dry_run = 0 THEN 1 ELSE 0 END) AS live_ct,
74 SUM(CASE WHEN dry_run = 0 THEN freed_bytes ELSE 0 END) AS live_bytes,
75 DATE_FORMAT(MAX(purged_at), '%b %d %H:%i') AS last_purge_h,
76 UNIX_TIMESTAMP(MAX(purged_at)) AS last_purge_epoch
77 FROM PURGE_LOG
78 WHERE purged_at >= DATE_SUB(NOW(), INTERVAL 30 DAY)
6679~, __FILE__, __LINE__);
6780
6881# Global scan settings
6982my $g = $db->db_readwrite($dbh, q~
7083 SELECT global_ignore_list, global_file_type_filter, global_max_file_size_bytes
7184 FROM SCAN_GLOBALS WHERE id = 1 LIMIT 1
7285~, __FILE__, __LINE__);
7386my $global_ignore = ($g && $g->{global_ignore_list}) // '';
7487my $global_ftypes = ($g && $g->{global_file_type_filter}) // '';
7588my $global_max_sz = ($g && $g->{global_max_file_size_bytes}) || 0;
7689# Split the ignore list onto lines for the textarea (nicer edit UX)
7790my $ignore_pretty = join("\n", split /,/, $global_ignore);
7891
7992$db->db_disconnect($dbh);
8093
8194my @cfg_rows;
8295foreach my $k (sort keys %$all) {
8396 my $v = $all->{$k} // '';
8497 $v = length($v) > 4 ? '***' . substr($v, -4) : '****'
8598 if $k =~ /pass(word)?|secret|hmac|smtp_password/i && length $v;
8699 push @cfg_rows, { key => $k, value => $v };
87100}
88101
89102my $tvars = {
90103 cfg_rows => \@cfg_rows,
91104 blob_ct => ($blob_stats && $blob_stats->{blob_ct}) || 0,
92105 bytes_uncomp => ($blob_stats && $blob_stats->{bytes_uncomp}) || 0,
93106 bytes_comp => ($blob_stats && $blob_stats->{bytes_comp}) || 0,
94107 total_refs => ($blob_stats && $blob_stats->{total_refs}) || 0,
95108 ratio => (($blob_stats && $blob_stats->{bytes_uncomp}) ? sprintf('%.1fx', $blob_stats->{bytes_uncomp} / ($blob_stats->{bytes_comp} || 1)) : '-'),
96109 global_ignore_pretty => $ignore_pretty,
97110 global_file_type_filter => $global_ftypes,
98111 global_max_file_size_bytes => $global_max_sz,
99112 saved => $cgi->param('saved') ? 1 : 0,
113 purge_dry_ct => ($recent_purge && $recent_purge->{dry_ct}) || 0,
114 purge_dry_bytes => _fmt_bytes(($recent_purge && $recent_purge->{dry_bytes}) || 0),
115 purge_live_ct => ($recent_purge && $recent_purge->{live_ct}) || 0,
116 purge_live_bytes => _fmt_bytes(($recent_purge && $recent_purge->{live_bytes}) || 0),
117 last_purge_h => ($recent_purge && $recent_purge->{last_purge_h}) // 'never',
118 last_purge_epoch => ($recent_purge && $recent_purge->{last_purge_epoch}) || 0,
100119};
120
121sub _fmt_bytes {
122 my $n = shift; $n //= 0;
123 return "$n B" if $n < 1024;
124 return sprintf('%.1f KB', $n/1024) if $n < 1024*1024;
125 return sprintf('%.1f MB', $n/1024/1024) if $n < 1024*1024*1024;
126 return sprintf('%.1f GB', $n/1024/1024/1024);
127}
101128my @body = $tpl->template('settings.html', $tvars);
102129MODS::PageWrapper->new->wrapper(
103130 page_title => 'Settings', page_key => 'settings',
104131 body_html => join('', @body), userinfo => { display_name => 'Operator' },
105132);