Diff -- /var/www/vhosts/3dshawn.com/site1/settings.cgi
Diff
/var/www/vhosts/3dshawn.com/site1/settings.cgi
modified on local at 2026-07-12 00:02:14
Added
+76
lines
Removed
-14
lines
Context
29
unchanged
Blobs
from c8439e2627a2
to c41f0faf4e6b
to c41f0faf4e6b
Unified diff
Naive LCS-based line diff. Additions in emerald, deletions in rose. Both sides decompressed live from BLOB_STORE.| 1 | 1 | #!/usr/bin/perl |
| 2 | use strict; use warnings; use CGI (); | |
| 3 | use MODS::Config; use MODS::DBConnect; use MODS::Template; use MODS::PageWrapper; | |
| 4 | my $cfg = MODS::Config->new; my $db = MODS::DBConnect->new; my $tpl = MODS::Template->new; | |
| 5 | $|=1; print "Content-Type: text/html; charset=utf-8\nCache-Control: no-cache\n\n"; | |
| 2 | #====================================================================== | |
| 3 | # DriftSense -- /settings.cgi | |
| 4 | # | |
| 5 | # Read-only view of the resolved config file + editable form for the | |
| 6 | # SCAN_GLOBALS row (global ignore patterns, allowed file types, max | |
| 7 | # file size). | |
| 8 | #====================================================================== | |
| 9 | use strict; | |
| 10 | use warnings; | |
| 11 | use CGI (); | |
| 12 | use MODS::Config; | |
| 13 | use MODS::DBConnect; | |
| 14 | use MODS::Template; | |
| 15 | use MODS::PageWrapper; | |
| 6 | 16 | |
| 7 | # The config file is read-only from the UI (managed by installer + admin). | |
| 8 | # We show its resolved values for confirmation + host statistics. | |
| 17 | my $cgi = CGI->new; | |
| 18 | my $cfg = MODS::Config->new; | |
| 19 | my $db = MODS::DBConnect->new; | |
| 20 | my $tpl = MODS::Template->new; | |
| 21 | ||
| 22 | $|=1; | |
| 23 | my $dbh = $db->db_connect or die "DB connect failed\n"; | |
| 24 | ||
| 25 | # ---- POST: update globals ------------------------------------------ | |
| 26 | if (($ENV{REQUEST_METHOD} || '') eq 'POST' && $cgi->param('save_globals')) { | |
| 27 | my $ign = $cgi->param('global_ignore_list') // ''; | |
| 28 | my $ftyp = $cgi->param('global_file_type_filter') // ''; | |
| 29 | my $mx = int($cgi->param('global_max_file_size_bytes') || 0); | |
| 30 | ||
| 31 | # Normalize whitespace on ignore list -> comma-joined single-line | |
| 32 | my @clean_ign; | |
| 33 | for my $tok (split /[,\r\n]+/, $ign) { | |
| 34 | $tok =~ s/^\s+|\s+$//g; | |
| 35 | push @clean_ign, $tok if length $tok; | |
| 36 | } | |
| 37 | my $normalized = join(',', @clean_ign); | |
| 38 | ||
| 39 | my $q_ign = $dbh->quote($normalized); | |
| 40 | my $q_ftyp = $dbh->quote($ftyp); | |
| 41 | $mx = 'NULL' unless $mx; | |
| 42 | ||
| 43 | $db->db_readwrite($dbh, qq~ | |
| 44 | UPDATE SCAN_GLOBALS | |
| 45 | SET global_ignore_list = $q_ign, | |
| 46 | global_file_type_filter = $q_ftyp, | |
| 47 | global_max_file_size_bytes = $mx | |
| 48 | WHERE id = 1 | |
| 49 | ~, __FILE__, __LINE__); | |
| 50 | $db->db_disconnect($dbh); | |
| 51 | print "Status: 302 Found\nLocation: /settings.cgi?saved=1\n\n"; | |
| 52 | exit; | |
| 53 | } | |
| 54 | ||
| 55 | print "Content-Type: text/html; charset=utf-8\nCache-Control: no-cache\n\n"; | |
| 56 | ||
| 9 | 57 | my $all = $cfg->all; |
| 10 | 58 | |
| 11 | 59 | # Blob store stats |
| 12 | my $dbh = $db->db_connect or die "DB connect failed\n"; | |
| 13 | 60 | my $blob_stats = $db->db_readwrite($dbh, q~ |
| 14 | 61 | SELECT COUNT(*) AS blob_ct, |
| 15 | 62 | COALESCE(SUM(size_uncompressed), 0) AS bytes_uncomp, |
| 16 | 63 | COALESCE(SUM(size_compressed), 0) AS bytes_comp, |
| 17 | 64 | COALESCE(SUM(ref_count), 0) AS total_refs |
| 18 | 65 | FROM BLOB_STORE |
| 66 | ~, __FILE__, __LINE__); | |
| 67 | ||
| 68 | # Global scan settings | |
| 69 | my $g = $db->db_readwrite($dbh, q~ | |
| 70 | SELECT global_ignore_list, global_file_type_filter, global_max_file_size_bytes | |
| 71 | FROM SCAN_GLOBALS WHERE id = 1 LIMIT 1 | |
| 19 | 72 | ~, __FILE__, __LINE__); |
| 73 | my $global_ignore = ($g && $g->{global_ignore_list}) // ''; | |
| 74 | my $global_ftypes = ($g && $g->{global_file_type_filter}) // ''; | |
| 75 | my $global_max_sz = ($g && $g->{global_max_file_size_bytes}) || 0; | |
| 76 | # Split the ignore list onto lines for the textarea (nicer edit UX) | |
| 77 | my $ignore_pretty = join("\n", split /,/, $global_ignore); | |
| 78 | ||
| 20 | 79 | $db->db_disconnect($dbh); |
| 21 | 80 | |
| 22 | 81 | my @cfg_rows; |
| 23 | 82 | foreach my $k (sort keys %$all) { |
| 24 | 83 | my $v = $all->{$k} // ''; |
| 25 | # Redact secrets | |
| 26 | 84 | $v = length($v) > 4 ? '***' . substr($v, -4) : '****' |
| 27 | 85 | if $k =~ /pass(word)?|secret|hmac|smtp_password/i && length $v; |
| 28 | 86 | push @cfg_rows, { key => $k, value => $v }; |
| 29 | 87 | } |
| 30 | 88 | |
| 31 | 89 | my $tvars = { |
| 32 | cfg_rows => \@cfg_rows, | |
| 33 | blob_ct => ($blob_stats && $blob_stats->{blob_ct}) || 0, | |
| 34 | bytes_uncomp => ($blob_stats && $blob_stats->{bytes_uncomp}) || 0, | |
| 35 | bytes_comp => ($blob_stats && $blob_stats->{bytes_comp}) || 0, | |
| 36 | total_refs => ($blob_stats && $blob_stats->{total_refs}) || 0, | |
| 37 | ratio => (($blob_stats && $blob_stats->{bytes_uncomp}) ? sprintf('%.1fx', $blob_stats->{bytes_uncomp} / ($blob_stats->{bytes_comp} || 1)) : '-'), | |
| 90 | cfg_rows => \@cfg_rows, | |
| 91 | blob_ct => ($blob_stats && $blob_stats->{blob_ct}) || 0, | |
| 92 | bytes_uncomp => ($blob_stats && $blob_stats->{bytes_uncomp}) || 0, | |
| 93 | bytes_comp => ($blob_stats && $blob_stats->{bytes_comp}) || 0, | |
| 94 | total_refs => ($blob_stats && $blob_stats->{total_refs}) || 0, | |
| 95 | ratio => (($blob_stats && $blob_stats->{bytes_uncomp}) ? sprintf('%.1fx', $blob_stats->{bytes_uncomp} / ($blob_stats->{bytes_comp} || 1)) : '-'), | |
| 96 | global_ignore_pretty => $ignore_pretty, | |
| 97 | global_file_type_filter => $global_ftypes, | |
| 98 | global_max_file_size_bytes => $global_max_sz, | |
| 99 | saved => $cgi->param('saved') ? 1 : 0, | |
| 38 | 100 | }; |
| 39 | 101 | my @body = $tpl->template('settings.html', $tvars); |
| 40 | 102 | MODS::PageWrapper->new->wrapper( |
| 41 | 103 | page_title => 'Settings', page_key => 'settings', |
| 42 | 104 | body_html => join('', @body), userinfo => { display_name => 'Operator' }, |
| 43 | 105 | ); |