From: rettenbe Date: Mon, 30 Jun 2008 15:05:02 +0000 (+0000) Subject: bugfix: 'trigger_wake' at multiple si-server networks X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=37a03f163a66b6fca80d979448cac309938ed100;p=gosa.git bugfix: 'trigger_wake' at multiple si-server networks git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@11484 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/server/events/gosaTriggered.pm b/gosa-si/server/events/gosaTriggered.pm index 6703714c9..5c377e227 100644 --- a/gosa-si/server/events/gosaTriggered.pm +++ b/gosa-si/server/events/gosaTriggered.pm @@ -656,9 +656,18 @@ sub trigger_action_wake { my $res = $main::job_db->exec_statement($sql_statement); } + # build out message + my $out_hash = &create_xml_hash("trigger_wake", "GOSA", "KNOWN_SERVER"); + &add_content2xml_hash($out_hash, 'macAddress', $msg_hash->{macaddress}); + my $out_msg = &create_xml_string($out_hash); + + # invoke trigger wake for this gosa-si-server + &main::server_server_com::trigger_wake($out_msg, $out_hash, $session_id); - my %data = ( 'macAddress' => \@{$msg_hash->{macaddress}} ); - my $out_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data); + #my %data = ( 'macAddress' => \@{$msg_hash->{macaddress}} ); + #my $out_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data); + + # send trigger wake to all other gosa-si-server my @out_msg_l = ($out_msg); return @out_msg_l; } diff --git a/gosa-si/server/events/server_server_com.pm b/gosa-si/server/events/server_server_com.pm index b1abc8e12..8972f97a0 100644 --- a/gosa-si/server/events/server_server_com.pm +++ b/gosa-si/server/events/server_server_com.pm @@ -5,6 +5,7 @@ my @events = ( 'new_server', 'confirm_new_server', 'new_foreign_client', + 'trigger_wake', ); @EXPORT = @events; @@ -211,4 +212,47 @@ sub new_foreign_client { } +sub trigger_wake { + my ($msg, $msg_hash, $session_id) = @_ ; + + foreach (@{$msg_hash->{macAddress}}){ + &main::daemon_log("$session_id INFO: trigger wake for $_", 5); + my $host = $_; + my $ipaddr = '255.255.255.255'; + my $port = getservbyname('discard', 'udp'); + + my ($raddr, $them, $proto); + my ($hwaddr, $hwaddr_re, $pkt); + + # get the hardware address (ethernet address) + $hwaddr_re = join(':', ('[0-9A-Fa-f]{1,2}') x 6); + if ($host =~ m/^$hwaddr_re$/) { + $hwaddr = $host; + } else { + &main::daemon_log("$session_id ERROR: trigger_wake called with non mac address", 1); + } + + # Generate magic sequence + foreach (split /:/, $hwaddr) { + $pkt .= chr(hex($_)); + } + $pkt = chr(0xFF) x 6 . $pkt x 16; + + # Allocate socket and send packet + + $raddr = gethostbyname($ipaddr); + $them = pack_sockaddr_in($port, $raddr); + $proto = getprotobyname('udp'); + + socket(S, AF_INET, SOCK_DGRAM, $proto) or die "socket : $!"; + setsockopt(S, SOL_SOCKET, SO_BROADCAST, 1) or die "setsockopt : $!"; + + send(S, $pkt, 0, $them) or die "send : $!"; + close S; + } + + return; +} + + 1; diff --git a/gosa-si/server/events/siTriggered.pm b/gosa-si/server/events/siTriggered.pm index 25582abf8..7694b1910 100644 --- a/gosa-si/server/events/siTriggered.pm +++ b/gosa-si/server/events/siTriggered.pm @@ -249,46 +249,47 @@ sub detected_hardware { } -sub trigger_wake { - my ($msg, $msg_hash, $session_id) = @_ ; - - foreach (@{$msg_hash->{macAddress}}){ - &main::daemon_log("$session_id INFO: trigger wake for $_", 5); - my $host = $_; - my $ipaddr = '255.255.255.255'; - my $port = getservbyname('discard', 'udp'); - - my ($raddr, $them, $proto); - my ($hwaddr, $hwaddr_re, $pkt); - - # get the hardware address (ethernet address) - $hwaddr_re = join(':', ('[0-9A-Fa-f]{1,2}') x 6); - if ($host =~ m/^$hwaddr_re$/) { - $hwaddr = $host; - } else { - &main::daemon_log("$session_id ERROR: trigger_wake called with non mac address", 1); - } - - # Generate magic sequence - foreach (split /:/, $hwaddr) { - $pkt .= chr(hex($_)); - } - $pkt = chr(0xFF) x 6 . $pkt x 16; - - # Allocate socket and send packet - - $raddr = gethostbyname($ipaddr); - $them = pack_sockaddr_in($port, $raddr); - $proto = getprotobyname('udp'); - - socket(S, AF_INET, SOCK_DGRAM, $proto) or die "socket : $!"; - setsockopt(S, SOL_SOCKET, SO_BROADCAST, 1) or die "setsockopt : $!"; - - send(S, $pkt, 0, $them) or die "send : $!"; - close S; - } - - return; -} +# moved to server_server_com.pm: rettenbe 30.06.2008 +#sub trigger_wake { +# my ($msg, $msg_hash, $session_id) = @_ ; +# +# foreach (@{$msg_hash->{macAddress}}){ +# &main::daemon_log("$session_id INFO: trigger wake for $_", 5); +# my $host = $_; +# my $ipaddr = '255.255.255.255'; +# my $port = getservbyname('discard', 'udp'); +# +# my ($raddr, $them, $proto); +# my ($hwaddr, $hwaddr_re, $pkt); +# +# # get the hardware address (ethernet address) +# $hwaddr_re = join(':', ('[0-9A-Fa-f]{1,2}') x 6); +# if ($host =~ m/^$hwaddr_re$/) { +# $hwaddr = $host; +# } else { +# &main::daemon_log("$session_id ERROR: trigger_wake called with non mac address", 1); +# } +# +# # Generate magic sequence +# foreach (split /:/, $hwaddr) { +# $pkt .= chr(hex($_)); +# } +# $pkt = chr(0xFF) x 6 . $pkt x 16; +# +# # Allocate socket and send packet +# +# $raddr = gethostbyname($ipaddr); +# $them = pack_sockaddr_in($port, $raddr); +# $proto = getprotobyname('udp'); +# +# socket(S, AF_INET, SOCK_DGRAM, $proto) or die "socket : $!"; +# setsockopt(S, SOL_SOCKET, SO_BROADCAST, 1) or die "setsockopt : $!"; +# +# send(S, $pkt, 0, $them) or die "send : $!"; +# close S; +# } +# +# return; +#} 1; diff --git a/gosa-si/tests/deploy-gosa-si.pl b/gosa-si/tests/deploy-gosa-si.pl index 32fb6212b..1707c5ae5 100755 --- a/gosa-si/tests/deploy-gosa-si.pl +++ b/gosa-si/tests/deploy-gosa-si.pl @@ -27,10 +27,10 @@ my %copies = ( "modules/SIPackages.pm" => "/usr/lib/gosa-si/modules/SIPackages.pm", "modules/DBsqlite.pm" => "/usr/share/perl5/GOSA/DBsqlite.pm", "modules/GosaSupportDaemon.pm" => "/usr/share/perl5/GOSA/GosaSupportDaemon.pm", - "sever/events/clMessages.pm" => "/usr/lib/gosa-si/server/events/clMessages.pm", - "sever/events/databases.pm" => "/usr/lib/gosa-si/server/events/databases.pm", - "sever/events/gosaTriggered.pm" => "/usr/lib/gosa-si/server/events/gosaTriggered.pm", - "sever/events/siTriggered.pm" => "/usr/lib/gosa-si/server/events/siTriggered.pm", + "server/events/clMessages.pm" => "/usr/lib/gosa-si/server/events/clMessages.pm", + "server/events/databases.pm" => "/usr/lib/gosa-si/server/events/databases.pm", + "server/events/gosaTriggered.pm" => "/usr/lib/gosa-si/server/events/gosaTriggered.pm", + "server/events/siTriggered.pm" => "/usr/lib/gosa-si/server/events/siTriggered.pm", ); while( my($file_name, $new_file) = each %copies ) {