diff --git a/gosa-si/server/events/server_server_com.pm b/gosa-si/server/events/server_server_com.pm
index b1abc8e12092e0761870f483f72ac74d14dae698..686d9f7687b09a54f9f69edfd2688545196948d9 100644 (file)
'new_server',
'confirm_new_server',
'new_foreign_client',
+ 'trigger_wake',
+ 'foreign_job_updates',
);
@EXPORT = @events;
use Data::Dumper;
use GOSA::GosaSupportDaemon;
use Time::HiRes qw( usleep);
+use Socket;
BEGIN {}
}
+sub foreign_job_updates {
+ my ($msg, $msg_hash, $session_id) = @_ ;
+ my $header = @{$msg_hash->{'header'}}[0];
+ my $source = @{$msg_hash->{'source'}}[0];
+ my $target = @{$msg_hash->{'target'}}[0];
+
+ my @act_keys = keys %$msg_hash;
+ my @jobs;
+ foreach my $key (@act_keys) {
+ if ($key =~ /answer\d+/ ) { push(@jobs, $key); }
+ }
+
+ foreach my $foreign_job (@jobs) {
+
+ # add job to job queue
+ my $func_dic = {table=>$main::job_queue_tn,
+ primkey=>['macaddress', 'headertag'],
+ timestamp=>@{@{$msg_hash->{$foreign_job}}[0]->{'timestamp'}}[0],
+ status=>@{@{$msg_hash->{$foreign_job}}[0]->{'status'}}[0],
+ result=>@{@{$msg_hash->{$foreign_job}}[0]->{'result'}}[0],
+ progress=>@{@{$msg_hash->{$foreign_job}}[0]->{'progress'}}[0],
+ headertag=>@{@{$msg_hash->{$foreign_job}}[0]->{'headertag'}}[0],
+ targettag=>@{@{$msg_hash->{$foreign_job}}[0]->{'targettag'}}[0],
+ xmlmessage=>@{@{$msg_hash->{$foreign_job}}[0]->{'xmlmessage'}}[0],
+ macaddress=>@{@{$msg_hash->{$foreign_job}}[0]->{'macaddress'}}[0],
+ plainname=>@{@{$msg_hash->{$foreign_job}}[0]->{'plainname'}}[0],
+ siserver=>$source,
+ modified=>"0",
+ };
+ my $res = $main::job_db->add_dbentry($func_dic);
+ if (not $res == 0) {
+ &main::daemon_log("$session_id ERROR: ServerPackages: process_job_msg: $res", 1);
+ } else {
+ &main::daemon_log("$session_id INFO: ServerPackages: $header, job '".@{@{$msg_hash->{$foreign_job}}[0]->{'headertag'}}[0].
+ "' successfully added to job queue", 5);
+ }
+ }
+
+ return;
+}
+
+
sub new_server {
my ($msg, $msg_hash, $session_id) = @_ ;
my $header = @{$msg_hash->{'header'}}[0];
}
+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');
+ if (not defined $port) {
+ &main::daemon_log("$session_id ERROR: cannot determine port for wol $_: 'getservbyname('discard', 'udp')' failed!",1);
+ next;
+ }
+
+ 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 . $main::wake_on_lan_passwd;
+
+ # Allocate socket and send packet
+
+ $raddr = gethostbyname($ipaddr);
+ if (not defined $raddr) {
+ &main::daemon_log("$session_id ERROR: cannot determine raddr for wol $_: 'gethostbyname($ipaddr)' failed!", 1);
+ next;
+ }
+
+ $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;