Scripts to show secret and delete a host
authorTodd Lyons <tlyons@exim.org>
Mon, 5 May 2014 16:10:17 +0000 (09:10 -0700)
committerTodd Lyons <tlyons@exim.org>
Mon, 5 May 2014 16:10:17 +0000 (09:10 -0700)
scripts/delete_host.pl [new file with mode: 0755]
scripts/show_passwords.pl [new file with mode: 0755]

diff --git a/scripts/delete_host.pl b/scripts/delete_host.pl
new file mode 100755 (executable)
index 0000000..1c1baad
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use DBI;
+use Data::Dumper;
+
+die "Must pass one and only one sysname to delete\n"
+  unless scalar @ARGV == 1;
+
+use vars qw($dbhost $dbname $dbuser $dbpass $dbport
+);
+require "$ENV{BFConfDir}/BuildFarmWeb.pl";
+
+die "no dbname" unless $dbname;
+die "no dbuser" unless $dbuser;
+
+my $dsn="dbi:Pg:dbname=$dbname";
+$dsn .= ";host=$dbhost" if $dbhost;
+$dsn .= ";port=$dbport" if $dbport;
+
+my $db = DBI->connect($dsn,$dbuser,$dbpass);
+
+die $DBI::errstr unless $db;
+
+my @tables = qw/alerts buildsystems build_status build_status_log
+                build_status_recent_500 dashboard_mat latest_snapshot
+                nrecent_failures personality/;
+my $sth;
+for my $loop (0 .. (scalar @tables - 1) ) {
+  my $field = ($tables[$loop] eq 'personality') ? 'name' :
+              ($tables[$loop] eq 'buildsystems') ? 'name':
+              'sysname';
+  printf "Deleting from %s with field %s\n", $tables[$loop], $field;
+  $sth = $db->prepare("
+       DELETE FROM $tables[$loop]
+       WHERE $field = ?
+      ");
+  $sth->execute($ARGV[0]);
+}
+$db->disconnect();
diff --git a/scripts/show_passwords.pl b/scripts/show_passwords.pl
new file mode 100755 (executable)
index 0000000..687896f
--- /dev/null
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use DBI;
+use Data::Dumper;
+
+use vars qw($dbhost $dbname $dbuser $dbpass $dbport
+            $user_list_format
+);
+require "$ENV{BFConfDir}/BuildFarmWeb.pl";
+
+die "no dbname" unless $dbname;
+die "no dbuser" unless $dbuser;
+
+my $dsn="dbi:Pg:dbname=$dbname";
+$dsn .= ";host=$dbhost" if $dbhost;
+$dsn .= ";port=$dbport" if $dbport;
+
+my $db = DBI->connect($dsn,$dbuser,$dbpass);
+
+die $DBI::errstr unless $db;
+
+my $sth = $db->prepare(q[ 
+       SELECT name, secret
+       FROM buildsystems AS b
+       ORDER BY name ASC
+      ]);
+$sth->execute();
+
+$user_list_format = "%-20s %s\n";
+printf $user_list_format, "SysName", "Secret";
+while (my $row = $sth->fetchrow_hashref)
+{
+  printf $user_list_format, $row->{name}, $row->{secret};
+}
+$db->disconnect();