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