Diff -- /var/www/vhosts/3dshawn.com/site1/databases.cgi
Diff
/var/www/vhosts/3dshawn.com/site1/databases.cgi
added on local at 2026-07-10 18:57:29
Added
+60
lines
Removed
-0
lines
Context
0
unchanged
Blobs
from
to ff38817268ac
to ff38817268ac
Unified diff
Naive LCS-based line diff. Additions in emerald, deletions in rose. Both sides decompressed live from BLOB_STORE.| 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 $cgi = CGI->new; my $db = MODS::DBConnect->new; my $tpl = MODS::Template->new; | |
| 5 | $|=1; | |
| 6 | my $dbh = $db->db_connect or die "DB connect failed\n"; | |
| 7 | ||
| 8 | if (($ENV{REQUEST_METHOD} || '') eq 'POST' && $cgi->param('save')) { | |
| 9 | my $id = int($cgi->param('id') || 0); | |
| 10 | my $q_db = $dbh->quote($cgi->param('db_name') || ''); | |
| 11 | my $q_host = $dbh->quote($cgi->param('hostname') || 'localhost'); | |
| 12 | my $q_port = $dbh->quote($cgi->param('port') || '3306'); | |
| 13 | my $q_user = $dbh->quote($cgi->param('username') || ''); | |
| 14 | my $q_pass = $dbh->quote($cgi->param('password') || ''); | |
| 15 | my $status = $cgi->param('status') ? 1 : 0; | |
| 16 | my $track = $cgi->param('track_row_count') ? 1 : 0; | |
| 17 | my $q_ig = $dbh->quote($cgi->param('ignore_tables') || ''); | |
| 18 | my $q_em = $dbh->quote($cgi->param('notify_emails') || ''); | |
| 19 | if ($id > 0) { | |
| 20 | $db->db_readwrite($dbh, qq~ | |
| 21 | UPDATE DATABASE_MONITOR_SETTINGS SET | |
| 22 | db_name=$q_db, hostname=$q_host, port=$q_port, username=$q_user, | |
| 23 | password=$q_pass, status=$status, track_row_count=$track, | |
| 24 | ignore_tables=$q_ig, notify_emails=$q_em | |
| 25 | WHERE database_list_id=$id LIMIT 1 | |
| 26 | ~, __FILE__, __LINE__); | |
| 27 | } else { | |
| 28 | $db->db_readwrite($dbh, qq~ | |
| 29 | INSERT INTO DATABASE_MONITOR_SETTINGS | |
| 30 | (db_name, hostname, port, username, password, status, | |
| 31 | track_row_count, ignore_tables, notify_emails, server_id) | |
| 32 | VALUES ($q_db, $q_host, $q_port, $q_user, $q_pass, $status, | |
| 33 | $track, $q_ig, $q_em, 1) | |
| 34 | ~, __FILE__, __LINE__); | |
| 35 | } | |
| 36 | print "Status: 302 Found\nLocation: /databases.cgi?saved=1\n\n"; exit; | |
| 37 | } | |
| 38 | ||
| 39 | print "Content-Type: text/html; charset=utf-8\nCache-Control: no-cache\n\n"; | |
| 40 | my @rows = $db->db_readwrite_multiple($dbh, q~ | |
| 41 | SELECT database_list_id AS id, db_name, hostname, port, username, status, | |
| 42 | track_row_count, connection_status, | |
| 43 | DATE_FORMAT(last_connection, '%b %d %H:%i') AS last_h | |
| 44 | FROM DATABASE_MONITOR_SETTINGS | |
| 45 | ORDER BY database_list_id ASC | |
| 46 | ~, __FILE__, __LINE__); | |
| 47 | foreach my $r (@rows) { | |
| 48 | $r->{status_pill} = $r->{status} ? 'pill-ok' : 'pill-mute'; | |
| 49 | $r->{status_lbl} = $r->{status} ? 'ACTIVE' : 'DISABLED'; | |
| 50 | $r->{conn_pill} = $r->{connection_status} ? 'pill-ok' : 'pill-bad'; | |
| 51 | $r->{conn_lbl} = $r->{connection_status} ? 'ONLINE' : 'DOWN'; | |
| 52 | } | |
| 53 | $db->db_disconnect($dbh); | |
| 54 | ||
| 55 | my @body = $tpl->template('databases.html', | |
| 56 | { rows => \@rows, has_rows => scalar(@rows) ? 1 : 0, total => scalar @rows }); | |
| 57 | MODS::PageWrapper->new->wrapper( | |
| 58 | page_title => 'Databases', page_key => 'databases', | |
| 59 | body_html => join('', @body), userinfo => { display_name => 'Operator' }, | |
| 60 | ); |