add new func

This commit is contained in:
Ougi 2023-11-10 12:00:53 +03:00
parent 4b16e4dacc
commit c1eee1f1d0
2 changed files with 21 additions and 23 deletions

View file

@ -11,37 +11,34 @@ our $VERSION = '0.1';
my $regex_for_email = 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])+)\])); 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 { get '/' => sub {
template 'get_address' => { title => 'Поиск Логов' }; template 'get_address' => { title => 'Поиск Логов' };
}; };
post '/logs' => sub { post '/logs' => sub {
my $address = body_parameters->get('address'); my %params = %{ valid_param( body_parameters->get('address') ) };
my $err;
if ($address) {
if ( $address =~ $regex_for_email ) {
$err = 0;
}
else {
$err = 'Ошибка: не верно указанный адрес';
}
}
else {
$err = 'Ошибка: пустой адрес';
}
my %res_get_rows;
unless ($err) {
my $dbh = DB->new(); my $dbh = DB->new();
$dbh->connect(); $dbh->connect();
%res_get_rows = $dbh->get_rows($address); my %res_get_rows = %{ $dbh->get_rows( $params{address} ) };
}
template 'logs' => { template 'logs' => {
title => $address, title => $params{flag},
err => $err, err => $params{address},
alert => $res_get_rows{alert}, alert => $res_get_rows{alert},
rows => $res_get_rows{table}, rows => $res_get_rows{table},
get_address => uri_for('/'), get_address => uri_for('/'),

View file

@ -1,6 +1,7 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings FATAL => 'all'; use warnings FATAL => 'all';
use DBI;
my $dbi_info = 'dbi:Pg:dbname=postgres;host=localhost;port=5432'; my $dbi_info = 'dbi:Pg:dbname=postgres;host=localhost;port=5432';
my $db_username = 'postgres'; my $db_username = 'postgres';