Скрипт utm_import_tclasses.pl:
Код: Выделить всё
#!/usr/bin/perl
use Ourfa;
use Socket;
use Mysql;
use Data::Dumper;
$prefix="/netup/utm";
open (CONFIG, "$prefix/utm.cfg");
@config = <CONFIG>;
close (CONFIG);
foreach $line (@config) {
if ($line =~ m/^([^#].+?)=(.*)$/) {
$$1 = $2;
}
}
my $ourfa = Ourfa->new(
api_xml_dir=>"/netup/utm5/xml",
server=>'localhost',
login=>$ENV{OURFA_LOGIN} || 'init',
password=>$ENV{OURFA_PASSWORD} || 'init',
ssl_cert => '/netup/utm5/admin.crt',
ssl_key => '/netup/utm5/admin.crt',
ssl => 'rsa_cert',
debug=>1
);
$result = $ourfa->rpcf_get_tclasses(); foreach my $tcls (@{$result->{'array-1'}}){ $ourfa->rpcf_remove_tclass(tclass_id=>$tcls->{tclass_id}); } # remove previously existing traffic classes
$dbh = Mysql->connect($database_host,$database,$database_login,$database_password); $dbh->Query("SET NAMES utf8");
$sth1 = $dbh->query("SELECT cid, value FROM traffic_classes WHERE tag LIKE 'name' AND cid=10");
while(my %tclass1 = $sth1->fetchhash){
my @list;
my $graph = 0;
my $graph_color = 0;
my $cid = $tclass1{cid};
my $tclass_name = $tclass1{value};
$sth2 = $dbh->query("SELECT value FROM traffic_classes WHERE cid = $cid AND tag LIKE 'graph'"); if(my %tclass2 = $sth2->fetchhash){ $graph = $tclass2{value}; }
$sth2 = $dbh->query("SELECT value FROM traffic_classes WHERE cid = $cid AND tag LIKE 'graph_color'"); if(my %tclass2 = $sth2->fetchhash){ $graph_color = $tclass2{value}; }
$sth2 = $dbh->query("SELECT * FROM traffic_classes_nets WHERE cid = $cid");
while(my %tclass2 = $sth2->fetchhash){
push(@list, { saddr => inet_aton(%tclass2->{ip_from}),
saddr_mask => inet_aton(%tclass2->{netmask_from}),
daddr => inet_aton(%tclass2->{ip_to}),
daddr_mask => inet_aton(%tclass2->{netmask_to}),
src_as => inet_aton(%tclass2->{src_as}),
dst_as => inet_aton(%tclass2->{dst_as}),
sport => %tclass2->{srcport},
dport => %tclass2->{dstport},
input => %tclass2->{input},
output => %tclass2->{output},
tcp_flags => %tclass2->{tcp_flags},
proto => %tclass2->{prot},
tos => %tclass2->{tos},
nexthop => %tclass2->{nexthop},
ip_from => inet_aton('0.0.0.0'),
use_src_as => 0,
use_dst_as => 0,
use_sport => 0,
use_dport => 0,
use_input => 0,
use_output => 0,
use_tcp_flags => 0,
use_proto => 0,
use_tos => 0,
use_nexthop => 0,
skip => 0
}
);
}
my %tclass=(tclass_id => $cid,
tclass_name => $tclass_name,
graph_color => 0,
is_display => $graph,
is_fill => 0,
time_range_id => 0,
dont_save => 0,
local_traf_policy => 0,
tclass_count => $#list+1,
'array-1' => [@list]
);
$ourfa->rpcf_add_tclass2(%tclass);
# print Dumper \%tclass, "\n";
}
Буду признателен, если мне укажут на мою ошибку, или подтвердят и исправят баг в Ourfa.xs
Содержимое debug.log:
Код: Выделить всё
?Debug : Jan 17 23:50:33 b43bab90 RPCConn[SSL]<init@127.0.0.1>: Stream cleared
?Debug : Jan 17 23:50:33 b43bab90 RPCConn[SSL]<init@127.0.0.1>: Call: 0x2301 (rpcf_add_tclass2)
?Debug : Jan 17 23:50:33 b43bab90 RPCConn[SSL]<init@127.0.0.1>: Real Call: 0x2301 (rpcf_add_tclass2)
?Debug : Jan 17 23:50:33 b43bab90 DBCtx: <144160944> SQL SELECT query: SELECT t_class_name FROM t_class WHERE id='10' AND is_deleted=0
?Debug : Jan 17 23:50:33 b43bab90 DBCtx: <144160944> SQL query: DELETE FROM t_class WHERE id='10'
?Debug : Jan 17 23:50:33 b43bab90 DBCtx: <144160944> SQL SELECT query: SELECT t_class_name FROM t_class WHERE id='10' AND is_deleted=1
?Debug : Jan 17 23:50:33 b43bab90 DBCtx: <144160944> SQL query: INSERT INTO t_class(id,t_class_name,graph_color,is_display,is_fill,time_range_id,dont_save,local_traf_policy) VALUES('10','Входящий интернет','0','0','0','0','0','0')
?Debug : Jan 17 23:50:33 b43bab90 DBCtx: <144160944> SQL query: INSERT INTO t_class_detail(t_class_id,saddr,saddr_mask,daddr,daddr_mask,sport,dport,input,output,src_as,dst_as,nexthop,tcp_flags,proto,tos,use_sport,use_dport,use_input,use_output,use_src_as,use_dst_as,use_nexthop,use_tcp_flags,use_proto,use_tos,skip, ip_from) VALUES('10','0','0','167772160','-16777216','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0')
?Debug : Jan 17 23:50:33 b43bab90 DBCtx: <144160944> SQL query: INSERT INTO t_class_detail(t_class_id,saddr,saddr_mask,daddr,daddr_mask,sport,dport,input,output,src_as,dst_as,nexthop,tcp_flags,proto,tos,use_sport,use_dport,use_input,use_output,use_src_as,use_dst_as,use_nexthop,use_tcp_flags,use_proto,use_tos,skip, ip_from) VALUES('10','0','0','167772160','-16777216','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0')
?Debug : Jan 17 23:50:33 b43bab90 DBCtx: <144160944> SQL query: INSERT INTO t_class_detail(t_class_id,saddr,saddr_mask,daddr,daddr_mask,sport,dport,input,output,src_as,dst_as,nexthop,tcp_flags,proto,tos,use_sport,use_dport,use_input,use_output,use_src_as,use_dst_as,use_nexthop,use_tcp_flags,use_proto,use_tos,skip, ip_from) VALUES('10','0','0','167772160','-16777216','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0')
?Debug : Jan 17 23:50:33 b43bab90 DBCtx: <144160944> SQL query: INSERT INTO t_class_detail(t_class_id,saddr,saddr_mask,daddr,daddr_mask,sport,dport,input,output,src_as,dst_as,nexthop,tcp_flags,proto,tos,use_sport,use_dport,use_input,use_output,use_src_as,use_dst_as,use_nexthop,use_tcp_flags,use_proto,use_tos,skip, ip_from) VALUES('10','0','0','167772160','-16777216','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0')
?Debug : Jan 17 23:50:33 b43bab90 DBCtx: <144160944> SQL query: INSERT INTO t_class_detail(t_class_id,saddr,saddr_mask,daddr,daddr_mask,sport,dport,input,output,src_as,dst_as,nexthop,tcp_flags,proto,tos,use_sport,use_dport,use_input,use_output,use_src_as,use_dst_as,use_nexthop,use_tcp_flags,use_proto,use_tos,skip, ip_from) VALUES('10','0','0','167772160','-16777216','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0')
?Debug : Jan 17 23:50:33 b43bab90 DBCtx: <144160944> SQL query: INSERT INTO t_class_detail(t_class_id,saddr,saddr_mask,daddr,daddr_mask,sport,dport,input,output,src_as,dst_as,nexthop,tcp_flags,proto,tos,use_sport,use_dport,use_input,use_output,use_src_as,use_dst_as,use_nexthop,use_tcp_flags,use_proto,use_tos,skip, ip_from) VALUES('10','0','0','167772160','-16777216','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0')
?Debug : Jan 17 23:50:33 b43bab90 RPCConn[SSL]<init@127.0.0.1>: Call 0x2301 (rpcf_add_tclass2) finished...
?Debug : Jan 17 23:50:33 b43bab90 RPCConn[SSL]<init@127.0.0.1>: Stream cleared
Info : Jan 17 23:50:33 b43bab90 RPCConn[SSL]<init@127.0.0.1>: Connection terminated by peer