Disable auto-reconnect, and handle db/dbh centrally-ish
This commit is contained in:
13
lib/ssh.pm
13
lib/ssh.pm
@@ -15,18 +15,17 @@ sub new {
|
||||
|
||||
sub fetch {
|
||||
my $self = shift;
|
||||
$self->{'config'}->db_connect();
|
||||
$self->{'dbh'} = $self->{'config'}->get_dbh unless($self->{'dbh'});
|
||||
my $dbh = $self->{'config'}->db_connect();
|
||||
my $seq = $self->{'seq'} || 0;
|
||||
my $retmsg;
|
||||
my @toreturn;
|
||||
unless($seq) {
|
||||
my $seqsth = $self->{'dbh'}->prepare("SELECT seq FROM logs WHERE program = 'sshd' ORDER BY seq DESC LIMIT 1") or return { retval => 0, retmsg => DBI::errstr, error => 1 };
|
||||
$seqsth->execute or return { retval => 0, retmsg => DBI::errstr, error => 1};
|
||||
$seq = $seqsth->fetchrow_arrayref->[0] or return { retval => 0, retmsg => DBI::errstr, error => 1};
|
||||
my $seqsth = $dbh->prepare("SELECT seq FROM logs WHERE program = 'sshd' ORDER BY seq DESC LIMIT 1") or return { retval => 0, retmsg => DBI::errstr, error => 1 };
|
||||
$seqsth->execute() or return { retval => 0, retmsg => DBI::errstr, error => 1};
|
||||
$seq = $seqsth->fetchrow_arrayref()->[0] or return { retval => 0, retmsg => DBI::errstr, error => 1};
|
||||
}
|
||||
my $sth = $self->{'dbh'}->prepare("SELECT msg,seq FROM logs WHERE program = 'sshd' AND seq > $seq") or return { retval => 1, retmsg => DBI::errstr, error => 1 };
|
||||
$sth->execute or return { retval => 0, retmsg => DBI::errstr, error => 1};
|
||||
my $sth = $dbh->prepare("SELECT msg,seq FROM logs WHERE program = 'sshd' AND seq > $seq") or return { retval => 1, retmsg => DBI::errstr, error => 1 };
|
||||
$sth->execute() or return { retval => 0, retmsg => DBI::errstr, error => 1};
|
||||
while(my $ref = $sth->fetchrow_hashref) {
|
||||
my $string = $$ref{'msg'};
|
||||
$seq = $$ref{'seq'};
|
||||
|
||||
Reference in New Issue
Block a user