summaryrefslogtreecommitdiffstats
path: root/perl-install
diff options
context:
space:
mode:
authorOlivier Blin <oblin@mandriva.org>2005-02-15 17:09:54 +0000
committerOlivier Blin <oblin@mandriva.org>2005-02-15 17:09:54 +0000
commit5174f7149f524b3a1165adab3ed72364612849f4 (patch)
treeec118fa386f80176fbfde2137c74ca92972d7d46 /perl-install
parent2dda5943253074f31ffcf811300365048bf4e6ce (diff)
downloaddrakx-5174f7149f524b3a1165adab3ed72364612849f4.tar
drakx-5174f7149f524b3a1165adab3ed72364612849f4.tar.gz
drakx-5174f7149f524b3a1165adab3ed72364612849f4.tar.bz2
drakx-5174f7149f524b3a1165adab3ed72364612849f4.tar.xz
drakx-5174f7149f524b3a1165adab3ed72364612849f4.zip
initial import
Diffstat (limited to 'perl-install')
-rw-r--r--perl-install/network/activefw.pm131
1 files changed, 131 insertions, 0 deletions
diff --git a/perl-install/network/activefw.pm b/perl-install/network/activefw.pm
new file mode 100644
index 000000000..a62b00c07
--- /dev/null
+++ b/perl-install/network/activefw.pm
@@ -0,0 +1,131 @@
+package activefw;
+
+use Net::DBus;
+use Net::DBus::Binding::Watch;
+use Gtk2::Helper;
+use POSIX qw(strftime);
+use Socket;
+
+sub new {
+ my ($type, $filter) = @_;
+
+ my $bus = Net::DBus->system;
+ my $con = $bus->{connection};
+
+ $con->add_filter($filter);
+ $con->add_match("type='signal',interface='com.mandrakesoft.activefirewall'");
+
+ set_DBus_watch($con);
+ $con->dispatch;
+
+ my $service = $bus->get_service("com.mandrakesoft.activefirewall.daemon");
+ my $daemon = $service->get_object("/com/mandrakesoft/activefirewall", "com.mandrakesoft.activefirewall.daemon");
+
+ bless {
+ bus => $bus,
+ daemon => $daemon
+ }, $type;
+}
+
+sub set_DBus_watch {
+ my ($con) = @_;
+ $con->set_watch_callbacks(sub {
+ my ($con, $watch) = @_;
+ my $flags = $watch->get_flags;
+ if ($flags & &Net::DBus::Binding::Watch::READABLE) {
+ Gtk2::Helper->add_watch($watch->get_fileno, 'in', sub {
+ $watch->handle(&Net::DBus::Binding::Watch::READABLE);
+ $con->dispatch;
+ 1;
+ });
+ }
+ #- do nothing for WRITABLE watch, we dispatch when needed
+ }, undef, undef); #- do nothing when watch is disabled or toggled yet
+}
+
+sub dispatch {
+ my ($o) = @_;
+ $o->{bus}{connection}->dispatch;
+}
+
+sub get_mode {
+ my ($o) = @_;
+ my $mode;
+ eval {
+ $mode = $o->{daemon}->GetMode;
+ };
+ if ($@) {
+ print "(GetMode) exception: $@\n";
+ $o->dispatch;
+ return;
+ }
+ $mode;
+}
+
+sub blacklist {
+ my ($o, $seq, $blacklist) = @_;
+ eval {
+ $o->{daemon}->Blacklist(Net::DBus::Binding::Value->new(&Net::DBus::Binding::Message::TYPE_UINT32, $seq),
+ Net::DBus::Binding::Value->new(&Net::DBus::Binding::Message::TYPE_UINT32, $blacklist));
+ };
+ if ($@) {
+ print "(Blacklist) exception: $@\n";
+ $o->dispatch;
+ }
+}
+
+sub set_interactive {
+ my ($o, $mode) = @_;
+ print "setting new IDS mode: $mode\n";
+ eval {
+ $o->{daemon}->SetMode(Net::DBus::Binding::Value->new(&Net::DBus::Binding::Message::TYPE_UINT32, $mode));
+ };
+ if ($@) {
+ print "(SetMode) exception: $@\n";
+ $o->dispatch;
+ }
+}
+
+sub get_blacklist {
+ my ($o) = @_;
+ my @blacklist;
+ eval {
+ @blacklist = $o->{daemon}->GetBlacklist;
+ };
+ if ($@) {
+ print "(GetBlacklist) exception: $@\n";
+ $o->dispatch;
+ return;
+ }
+ @blacklist;
+}
+
+sub format_date {
+ my ($timestamp) = @_;
+ strftime("%c", localtime($timestamp));
+}
+
+sub get_service {
+ my ($port) = @_;
+ getservbyport($port, undef) || $port;
+}
+
+sub get_ip_address {
+ my ($addr) = @_;
+ inet_ntoa(pack('N', $addr));
+}
+
+sub resolve_address {
+ my ($ip_addr) = @_;
+ #- try to resolve address, timeout after 2 seconds
+ my $hostname;
+ eval {
+ local $SIG{ALRM} = sub { die "ALARM" };
+ alarm 2;
+ $hostname = gethostbyaddr(inet_aton($ip_addr), AF_INET);
+ alarm 0;
+ };
+ $hostname || $ip_addr;
+}
+
+1;