Diff -- /var/www/vhosts/3dshawn.com/site1/named_releases.cgi
Diff
/var/www/vhosts/3dshawn.com/site1/named_releases.cgi
modified on local at 2026-07-12 00:19:40
Added
+9
lines
Removed
-2
lines
Context
105
unchanged
Blobs
from f9cb5afdbf95
to c958968f6b22
to c958968f6b22
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 | 2 | #====================================================================== |
| 3 | 3 | # DriftSense -- /named_releases.cgi |
| 4 | 4 | # |
| 5 | 5 | # List + create named releases. Each release is a bookmark that pins |
| 6 | 6 | # every blob referenced by FILE_CHANGES rows in a chosen scope. A |
| 7 | 7 | # release can be portfolio-wide (scope_monitor_id NULL) or scoped to |
| 8 | 8 | # a single site (scope_monitor_id set). Pinned blobs are exempt from |
| 9 | 9 | # auto-purge. |
| 10 | 10 | #====================================================================== |
| 11 | 11 | use strict; |
| 12 | 12 | use warnings; |
| 13 | 13 | use CGI (); |
| 14 | 14 | use MODS::Config; use MODS::DBConnect; use MODS::Template; use MODS::PageWrapper; |
| 15 | 15 | my $cgi = CGI->new; my $db = MODS::DBConnect->new; my $tpl = MODS::Template->new; |
| 16 | 16 | $|=1; |
| 17 | 17 | |
| 18 | 18 | my $dbh = $db->db_connect or die "DB connect failed\n"; |
| 19 | 19 | |
| 20 | 20 | # ---- POST: create --------------------------------------------------- |
| 21 | 21 | if (($ENV{REQUEST_METHOD} || '') eq 'POST' && $cgi->param('save')) { |
| 22 | 22 | my $name = $cgi->param('name') || ''; |
| 23 | 23 | my $desc = $cgi->param('description') || ''; |
| 24 | 24 | my $by = $cgi->param('released_by') || 'Operator'; |
| 25 | 25 | my $scope_mid = int($cgi->param('scope_monitor_id') || 0); |
| 26 | 26 | my $scope_sid = int($cgi->param('scope_server_id') || 0); |
| 27 | my $dkind = $cgi->param('alert_delivery_kind') || 'none'; | |
| 28 | $dkind = 'none' unless $dkind =~ /^(none|generic_webhook|slack|discord)$/; | |
| 29 | my $durl = $cgi->param('alert_delivery_url') || ''; | |
| 27 | 30 | |
| 28 | 31 | if (length $name) { |
| 29 | 32 | my $q_name = $dbh->quote($name); |
| 30 | 33 | my $q_desc = $dbh->quote($desc); |
| 31 | 34 | my $q_by = $dbh->quote($by); |
| 35 | my $q_dk = $dbh->quote($dkind); | |
| 36 | my $q_du = $dbh->quote($durl); | |
| 32 | 37 | my $mid_expr = $scope_mid ? $scope_mid : 'NULL'; |
| 33 | 38 | my $sid_expr = $scope_sid ? $scope_sid : 'NULL'; |
| 34 | 39 | $db->db_readwrite($dbh, qq~ |
| 35 | 40 | INSERT INTO NAMED_RELEASES |
| 36 | 41 | (name, description, released_at, released_by, is_locked, created_at, |
| 37 | scope_monitor_id, scope_server_id) | |
| 42 | scope_monitor_id, scope_server_id, | |
| 43 | alert_delivery_kind, alert_delivery_url) | |
| 38 | 44 | VALUES |
| 39 | 45 | ($q_name, $q_desc, NOW(), $q_by, 1, NOW(), |
| 40 | $mid_expr, $sid_expr) | |
| 46 | $mid_expr, $sid_expr, | |
| 47 | $q_dk, $q_du) | |
| 41 | 48 | ~, __FILE__, __LINE__); |
| 42 | 49 | } |
| 43 | 50 | print "Status: 302 Found\nLocation: /named_releases.cgi\n\n"; exit; |
| 44 | 51 | } |
| 45 | 52 | |
| 46 | 53 | print "Content-Type: text/html; charset=utf-8\nCache-Control: no-cache\n\n"; |
| 47 | 54 | |
| 48 | 55 | # ---- Existing releases + count how many blobs each pins ------------- |
| 49 | 56 | my @rows = $db->db_readwrite_multiple($dbh, q~ |
| 50 | 57 | SELECT nr.named_release_id AS id, nr.name, nr.description, |
| 51 | 58 | DATE_FORMAT(nr.released_at, '%b %d, %Y %H:%i') AS released_h, |
| 52 | 59 | UNIX_TIMESTAMP(nr.released_at) AS released_epoch, |
| 53 | 60 | nr.released_by, nr.is_locked, |
| 54 | 61 | nr.scope_monitor_id, nr.scope_server_id, |
| 55 | 62 | m.scan_name, s.server_name |
| 56 | 63 | FROM NAMED_RELEASES nr |
| 57 | 64 | LEFT JOIN FILE_MONITOR_SETTINGS m ON m.file_monitor_list_id = nr.scope_monitor_id |
| 58 | 65 | LEFT JOIN SERVERS s ON s.server_id = nr.scope_server_id |
| 59 | 66 | ORDER BY nr.released_at DESC |
| 60 | 67 | LIMIT 100 |
| 61 | 68 | ~, __FILE__, __LINE__); |
| 62 | 69 | foreach my $r (@rows) { |
| 63 | 70 | $r->{lock_pill} = $r->{is_locked} ? 'pill-ok' : 'pill-mute'; |
| 64 | 71 | $r->{lock_lbl} = $r->{is_locked} ? 'PROTECTED' : 'UNLOCKED'; |
| 65 | 72 | $r->{released_epoch} //= 0; |
| 66 | 73 | if ($r->{scope_monitor_id}) { |
| 67 | 74 | $r->{scope_pill} = 'pill-info'; |
| 68 | 75 | $r->{scope_lbl} = 'per-site'; |
| 69 | 76 | $r->{scope_h} = $r->{scan_name} || "monitor #$r->{scope_monitor_id}"; |
| 70 | 77 | } elsif ($r->{scope_server_id}) { |
| 71 | 78 | $r->{scope_pill} = 'pill-info'; |
| 72 | 79 | $r->{scope_lbl} = 'per-server'; |
| 73 | 80 | $r->{scope_h} = $r->{server_name} || "server #$r->{scope_server_id}"; |
| 74 | 81 | } else { |
| 75 | 82 | $r->{scope_pill} = 'pill-mute'; |
| 76 | 83 | $r->{scope_lbl} = 'portfolio'; |
| 77 | 84 | $r->{scope_h} = 'All monitored sites'; |
| 78 | 85 | } |
| 79 | 86 | } |
| 80 | 87 | |
| 81 | 88 | # ---- All monitors + servers for scope picker ------------------------ |
| 82 | 89 | my @monitors = $db->db_readwrite_multiple($dbh, q~ |
| 83 | 90 | SELECT m.file_monitor_list_id AS mid, m.scan_name, s.server_name |
| 84 | 91 | FROM FILE_MONITOR_SETTINGS m |
| 85 | 92 | LEFT JOIN SERVERS s ON s.server_id = m.server_id |
| 86 | 93 | WHERE m.status = 1 |
| 87 | 94 | ORDER BY s.server_id ASC, m.file_monitor_list_id ASC |
| 88 | 95 | ~, __FILE__, __LINE__); |
| 89 | 96 | foreach my $m (@monitors) { |
| 90 | 97 | $m->{label} = ($m->{scan_name} // '?') . ' (on ' . ($m->{server_name} // '?') . ')'; |
| 91 | 98 | } |
| 92 | 99 | |
| 93 | 100 | my $total = scalar @rows; |
| 94 | 101 | $db->db_disconnect($dbh); |
| 95 | 102 | |
| 96 | 103 | my $tvars = { |
| 97 | 104 | rows => \@rows, |
| 98 | 105 | has_rows => $total ? 1 : 0, |
| 99 | 106 | total => $total, |
| 100 | 107 | monitors => \@monitors, |
| 101 | 108 | has_monitors=> scalar(@monitors) ? 1 : 0, |
| 102 | 109 | }; |
| 103 | 110 | my @body = $tpl->template('named_releases.html', $tvars); |
| 104 | 111 | MODS::PageWrapper->new->wrapper( |
| 105 | 112 | page_title => 'Named releases', page_key => 'named_releases', |
| 106 | 113 | body_html => join('', @body), userinfo => { display_name => 'Operator' }, |
| 107 | 114 | ); |