Firewall-Controller
view release on metacpan or search on metacpan
lib/Firewall/Controller/Ff.pm view on Meta::CPAN
};
# è¿å计ç®ç»æ
$self->render( json => $result );
}
#------------------------------------------------------------------------------
# initFirewall åå§åé²ç«å¢ï¼å¿
é¡»æºå¸¦ jsonStr
#------------------------------------------------------------------------------
sub initFirewall {
my $self = shift;
# åå§ååé
my $result;
# å®ä¾å Pg
my $dbi = Firewall::DBI::Pg->new( $self->app->config->{db}{main} );
# å°è¯èæºåå§åé²ç«å¢
try {
# æ£æ¥ http è¯·æ±æ¯å¦æºå¸¦ jsonStr
my $json = $self->param('jsonStr');
my $param = decode_json $json;
if ( not defined $json ) {
$result = {
status => 'error',
type => 'text',
content => "缺å°è¾å
¥åæ° "
};
}
# è¿è¡é²ç«å¢åå§å
else {
my $initFW = Firewall::Config::InitFirewall->new( dbi => $dbi );
my $initResult = $initFW->initFirewall($param);
# åå
¥æ°æ®ç»æ
$result = {
status => 'ok',
type => 'json',
content => $initResult
};
}
}
# ææå¼å¸¸ä¿¡æ¯
catch {
print $_->to_string;
$result = {
status => 'error',
type => 'text',
content => $_->to_string
};
};
# è¿å计ç®ç»æ
$self->render( json => $result );
}
#------------------------------------------------------------------------------
# updateNetwork æ´æ°ç½ç»ä¿¡æ¯ï¼å¿
é¡»æºå¸¦ fwId
#------------------------------------------------------------------------------
sub updateNetwork {
my $self = shift;
# åå§ååé
my $result;
# å®ä¾å Pg æ°æ®åºå¯¹è±¡
my $dbi = Firewall::DBI::Pg->new( $self->app->config->{db}{main} );
# å°è¯èæºæ´æ°é²ç«å¢
try {
# æ£æ¥ http è¯·æ±æ¯å¦æºå¸¦ fwId
my $fwId = $self->param('fwId');
if ( not defined $fwId ) {
$result = {
status => 'error',
type => 'text',
content => "缺å°è¾å
¥åæ° "
};
}
# æ´æ°é²ç«å¢
else {
my $initFW = Firewall::Config::InitFirewall->new( dbi => $dbi );
my $initResult = $initFW->updateNetwork($fwId);
# å¡«å
æ°æ®ç»æ
$result = {
status => 'ok',
type => 'json',
content => $initResult
};
}
}
# ææå¼å¸¸ä¿¡æ¯
catch {
print $_->to_string;
$result = {
status => 'error',
type => 'text',
content => $_->to_string
};
};
# è¿å计ç®ç»æ
$self->render( json => $result );
}
1;
( run in 0.775 second using v1.01-cache-2.11-cpan-e1769b4cff6 )