add new func
This commit is contained in:
parent
4b16e4dacc
commit
c1eee1f1d0
2 changed files with 21 additions and 23 deletions
|
@ -11,37 +11,34 @@ our $VERSION = '0.1';
|
|||
my $regex_for_email =
|
||||
qr((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]));
|
||||
|
||||
sub valid_param {
|
||||
my $address = shift;
|
||||
if ( $address =~ $regex_for_email ) {
|
||||
return {
|
||||
flag => 0,
|
||||
address => $1
|
||||
};
|
||||
}
|
||||
return {
|
||||
flag => 1,
|
||||
address => "Error Address"
|
||||
};
|
||||
}
|
||||
|
||||
get '/' => sub {
|
||||
template 'get_address' => { title => 'Поиск Логов' };
|
||||
};
|
||||
|
||||
post '/logs' => sub {
|
||||
my $address = body_parameters->get('address');
|
||||
my $err;
|
||||
my %params = %{ valid_param( body_parameters->get('address') ) };
|
||||
|
||||
if ($address) {
|
||||
if ( $address =~ $regex_for_email ) {
|
||||
$err = 0;
|
||||
}
|
||||
else {
|
||||
$err = 'Ошибка: не верно указанный адрес';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$err = 'Ошибка: пустой адрес';
|
||||
}
|
||||
|
||||
my %res_get_rows;
|
||||
|
||||
unless ($err) {
|
||||
my $dbh = DB->new();
|
||||
$dbh->connect();
|
||||
%res_get_rows = $dbh->get_rows($address);
|
||||
}
|
||||
my $dbh = DB->new();
|
||||
$dbh->connect();
|
||||
my %res_get_rows = %{ $dbh->get_rows( $params{address} ) };
|
||||
|
||||
template 'logs' => {
|
||||
title => $address,
|
||||
err => $err,
|
||||
title => $params{flag},
|
||||
err => $params{address},
|
||||
alert => $res_get_rows{alert},
|
||||
rows => $res_get_rows{table},
|
||||
get_address => uri_for('/'),
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/perl
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use DBI;
|
||||
|
||||
my $dbi_info = 'dbi:Pg:dbname=postgres;host=localhost;port=5432';
|
||||
my $db_username = 'postgres';
|
||||
|
|
Loading…
Reference in a new issue