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

O Operator
Diff

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

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

Added
+20
lines
Removed
-3
lines
Context
37
unchanged
Blobs
from f0a44a1113a6
to 6db9f3b7ebe4
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
22use strict; use warnings; use CGI ();
33use MODS::Config; use MODS::DBConnect; use MODS::Template; use MODS::PageWrapper;
44my $cgi = CGI->new; my $db = MODS::DBConnect->new; my $tpl = MODS::Template->new;
55$|=1;
66my $dbh = $db->db_connect or die "DB connect failed\n";
77
88if (($ENV{REQUEST_METHOD} || '') eq 'POST' && $cgi->param('save')) {
99 my $q_name = $dbh->quote($cgi->param('scan_name') || '');
1010 my $q_path = $dbh->quote($cgi->param('scan_path') || '');
1111 my $q_ig = $dbh->quote($cgi->param('ignore_list') || '.git/,node_modules/,*.log,*.tmp,.DS_Store');
1212 my $q_ft = $dbh->quote($cgi->param('file_type_filter') || '');
1313 my $status = $cgi->param('status') ? 1 : 0;
14 my $ret = int($cgi->param('retention_days') || 0);
15 my $ret_expr = $ret > 0 ? $ret : 'NULL';
1416 $db->db_readwrite($dbh, qq~
1517 INSERT INTO FILE_MONITOR_SETTINGS
16 (scan_name, scan_path, ignore_list, file_type_filter, status, server_id)
17 VALUES ($q_name, $q_path, $q_ig, $q_ft, $status, 1)
18 (scan_name, scan_path, ignore_list, file_type_filter, status, server_id, retention_days)
19 VALUES ($q_name, $q_path, $q_ig, $q_ft, $status, 1, $ret_expr)
1820 ~, __FILE__, __LINE__);
1921 print "Status: 302 Found\nLocation: /file_monitors.cgi?saved=1\n\n"; exit;
22}
23
24# POST-update: change per-monitor retention_days
25if (($ENV{REQUEST_METHOD} || '') eq 'POST' && $cgi->param('update_retention')) {
26 my $mid = int($cgi->param('mid') || 0);
27 my $ret = int($cgi->param('retention_days') || 0);
28 my $ret_expr = $ret > 0 ? $ret : 'NULL';
29 $db->db_readwrite($dbh,
30 "UPDATE FILE_MONITOR_SETTINGS SET retention_days = $ret_expr WHERE file_monitor_list_id = $mid",
31 __FILE__, __LINE__);
32 print "Status: 302 Found\nLocation: /file_monitors.cgi?updated=1\n\n"; exit;
2033}
2134
2235print "Content-Type: text/html; charset=utf-8\nCache-Control: no-cache\n\n";
2336my @rows = $db->db_readwrite_multiple($dbh, q~
2437 SELECT file_monitor_list_id AS id, scan_name, scan_path, ignore_list, file_type_filter,
25 status, DATE_FORMAT(last_scanned, '%b %d %H:%i') AS last_h
38 status, retention_days,
39 DATE_FORMAT(last_scanned, '%b %d %H:%i') AS last_h
2640 FROM FILE_MONITOR_SETTINGS ORDER BY file_monitor_list_id ASC
2741~, __FILE__, __LINE__);
2842foreach my $r (@rows) {
2943 $r->{status_pill} = $r->{status} ? 'pill-ok' : 'pill-mute';
3044 $r->{status_lbl} = $r->{status} ? 'ACTIVE' : 'DISABLED';
3145 $r->{ignore_preview} = $r->{ignore_list} ? substr($r->{ignore_list}, 0, 50) . (length($r->{ignore_list}) > 50 ? '...' : '') : '';
46 $r->{retention_h} = defined($r->{retention_days}) && $r->{retention_days} > 0
47 ? "$r->{retention_days} d" : '(global)';
48 $r->{retention_days} //= 0;
3249}
3350$db->db_disconnect($dbh);
3451
3552my @body = $tpl->template('file_monitors.html',
3653 { rows => \@rows, has_rows => scalar(@rows) ? 1 : 0, total => scalar @rows });
3754MODS::PageWrapper->new->wrapper(
3855 page_title => 'File monitors', page_key => 'file_monitors',
3956 body_html => join('', @body), userinfo => { display_name => 'Operator' },
4057);