From 493ac12761d7f91567b57e16ad35ff6b6ec5501b Mon Sep 17 00:00:00 2001 From: Will Budic Date: Fri, 31 Oct 2025 12:06:27 +1100 Subject: [PATCH] Added option die_in_html. --- apps/sql.cnf | 1 + apps/sql.pl | 23 ++++++++++++++++++----- system/modules/CNFSQL.pm | 8 ++++++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/apps/sql.cnf b/apps/sql.cnf index e02d47a..d134eaf 100644 --- a/apps/sql.cnf +++ b/apps/sql.cnf @@ -1,6 +1,7 @@ !CNF3.3 <<>> <<new('apps/sql.cnf'); -my $arguments = $CNF->property(CNFParser::APP_ARGS()); -my $db = CNFSQL::_connectDB(CNFSQL::_credentialsToArray($arguments->{DB_CREDENTIALS}), - $arguments->{DB_SQL_SOURCE},$arguments->{DB}); our $SQL = $CNF->SQL(); -$SQL->initDatabase($db,1); -my %schema = $SQL->schema(); +our $db; +my $arguments = $CNF->property(CNFParser::APP_ARGS()); +try{ +$db = CNFSQL::_connectDB( + CNFSQL::_credentialsToArray($arguments->{DB_CREDENTIALS}), + $arguments->{DB_SQL_SOURCE}, + $arguments->{DB} + ); +}catch($e){ + if($e =~ /connection to server at \"(.*)\"/){ + say `nmap $1` if (-x "/usr/bin/nmap") + } + die $e +} + +$CNF->log("Connected to DB_SQL_SOURCE -> ".$arguments->{DB_SQL_SOURCE}) if $db; +$SQL->initDatabase($db,1); +my %schema = $SQL->schema(); my $action = $arguments->{action}; my $table = $arguments->{table}; die "Config error: Table $table not found in database -> ".$arguments->{DB} if not exists $schema{$table}; diff --git a/system/modules/CNFSQL.pm b/system/modules/CNFSQL.pm index c5b2a2a..3a0c4ff 100644 --- a/system/modules/CNFSQL.pm +++ b/system/modules/CNFSQL.pm @@ -18,7 +18,7 @@ our %views = (); our %mig = (); our @sql = (); our @statements; - +our $die_in_html = 1; my %schema_tables; my $isPostgreSQL = 0; my $TZ; @@ -31,6 +31,9 @@ sub new { # By convention any tables and views as appearing in the CNF script should in that order also be created. tie %tables_create_stmts, "Tie::IxHash"; tie %views, "Tie::IxHash"; + if(exists $attrs->{parser}->{die_in_html}){ + $die_in_html = CNFParser::_isTrue($attrs->{parser}->{die_in_html}) + } bless $self, $class; } @@ -451,7 +454,8 @@ sub _connectDB { try{ return DBI->connect($dsn, $user, $pass, {AutoCommit => 0, RaiseError => 1, PrintError => 0, show_trace=>1}); }catch{ - die "

Error->$@


DSN: $dsn
"; + die "

Error->$@


DSN: $dsn
" if $die_in_html; + die $@ } } sub _credentialsToArray{ -- 2.34.1