summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4861504)
raw | patch | inline | side by side (parent: 4861504)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 20 Feb 2008 09:41:33 +0000 (09:41 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 20 Feb 2008 09:41:33 +0000 (09:41 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8979 594d385d-05f5-0310-b6e9-bd551577e9d8
diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index ea39ccfdd73889eeff8e50718848cab6d2591277..5c1a96a38ff563e0aecf4d68e6e13d494e20eec8 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
my $client_answer;
daemon_log("Incoming msg from '".$heap->{'remote_ip'}."'", 7);
- daemon_log("\n$input", 8);
+ daemon_log("message:\n$input", 8);
####################
# check incoming msg
index baebb4cbe2d1062cffaac632c77b9d9520d22f52..1668c10fef1d316d3c9336f21933431b6eee7d23 100644 (file)
opendir (DIR, $event_dir) or die "ERROR while loading gosa-si-events from directory $event_dir : $!\n";
while (defined (my $event = readdir (DIR))) {
- if( $event eq "." || $event eq ".." ) { next; }
+ if( $event eq "." || $event eq ".." ) { next; }
+ if( $event eq "siTriggered.pm" ) { next; } # only SI specific events
eval{ require $event; };
if( $@ ) {
foreach my $event_name (@{$events_l}) {
$event_hash->{$event_name} = $event_module;
}
-
+ my $events_string = join( ", ", @{$events_l});
+ &main::daemon_log("INFO: GosaPackages imported events $events_string", 5);
}
}
@out_msg_l = &update_status_jobdb_entry
} elsif ($header eq 'count_jobdb' ) {
@out_msg_l = &count_jobdb
-# } elsif ($header eq 'trigger_action_wake' ) {
-# # Forward messages to all known servers as "trigger_wake"
-# my $in_hash= &transform_msg2hash($msg);
-# my %data = ( 'macAddress' => \@{$in_hash->{macAddress}} );
-# @out_msg_l = &build_msg("trigger_wake", $server_address, "KNOWN_SERVER", \%data);
} else {
# msg could not be assigned to core function
# maybe it is an eventa
index ffe43332fca652adab860c7bc484e8c52180e23b..3a15aa94186b8ee6ea56ebfad0955d08883bf535 100644 (file)
}
+
+
#=== FUNCTION ================================================================
# NAME: create_xml_hash
# PARAMETERS: header - string - message header (required)
index 8f052d07c7db414b6aa2761ecb114d1537f7ae65..47092086595211b4ea0d87909391e70acf779b3f 100644 (file)
use Net::hostent;
use Net::DNS;
+my $event_dir = "/usr/lib/gosa-si/server/events";
+use lib "/usr/lib/gosa-si/server/events";
+
BEGIN{}
END {}
my ($server_ip, $server_mac_address, $server_port, $SIPackages_key, $max_clients, $ldap_uri, $ldap_base, $ldap_admin_dn, $ldap_admin_password, $server_interface);
my ($bus_activ, $bus_key, $bus_ip, $bus_port);
my $server;
+my $event_hash;
my $network_interface;
my $no_bus;
my (@ldap_cfg, @pam_cfg, @nss_cfg, $goto_admin, $goto_secret, $gosa_unit_tag);
$network_interface= &get_interface_for_ip($server_ip);
$server_mac_address= &get_mac($network_interface);
+&import_events();
+
# Unit tag can be defined in config
if((not defined($gosa_unit_tag)) || length($gosa_unit_tag) == 0) {
# Read gosaUnitTag from LDAP
}
-sub do_wake {
- my $host = shift;
- my $ipaddr = shift || '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 {
- # $host is not a hardware address, try to resolve it
- my $ip_re = join('\.', ('([0-9]|[1-9][0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))') x 4);
- my $ip_addr;
- if ($host =~ m/^$ip_re$/) {
- $ip_addr = $host;
- } else {
- my $h;
- unless ($h = gethost($host)) {
- return undef;
- }
- $ip_addr = inet_ntoa($h->addr);
- }
- }
-
- # 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)->addr;
- $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;
-}
+#sub daemon_log {
+# my ($msg, $level) = @_ ;
+# &main::daemon_log($msg, $level);
+# return;
+#}
+#
+
+#sub do_wake {
+# my $host = shift;
+# my $ipaddr = shift || '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 {
+# # $host is not a hardware address, try to resolve it
+# my $ip_re = join('\.', ('([0-9]|[1-9][0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))') x 4);
+# my $ip_addr;
+# if ($host =~ m/^$ip_re$/) {
+# $ip_addr = $host;
+# } else {
+# my $h;
+# unless ($h = gethost($host)) {
+# return undef;
+# }
+# $ip_addr = inet_ntoa($h->addr);
+# }
+# }
+#
+# # 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)->addr;
+# $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;
+#}
#=== FUNCTION ================================================================
}
+sub import_events {
+ if (not -e $event_dir) {
+ &main::daemon_log("ERROR: cannot find directory or directory is not readable: $event_dir", 1);
+ }
+ opendir (DIR, $event_dir) or die "ERROR while loading gosa-si-events from directory $event_dir : $!\n";
+
+ while (defined (my $event = readdir (DIR))) {
+ if( $event eq "." || $event eq ".." ) { next; }
+ if( $event eq "gosaTriggered.pm" ) { next; } # only GOsa specific events
+
+ eval{ require $event; };
+ if( $@ ) {
+ &main::daemon_log("import of event module '$event' failed", 1);
+ &main::daemon_log("$@", 8);
+ next;
+ }
+
+ $event =~ /(\S*?).pm$/;
+ my $event_module = $1;
+ my $events_l = eval( $1."::get_events()") ;
+ foreach my $event_name (@{$events_l}) {
+ $event_hash->{$event_name} = $event_module;
+ }
+ my $events_string = join( ", ", @{$events_l});
+ &main::daemon_log("INFO: SIPackages imported events $events_string", 5);
+ }
+}
+
+
#=== FUNCTION ================================================================
# NAME: process_incoming_msg
# PARAMETERS: crypted_msg - string - incoming crypted message
# DESCRIPTION: handels the proceeded distribution to the appropriated functions
#===============================================================================
sub process_incoming_msg {
- my ($msg, $msg_hash, $remote_ip) = @_ ;
+ my ($msg, $msg_hash, $session_id) = @_ ;
my $error = 0;
my $host_name;
my $host_key;
- my @out_msg_l;
+ my @out_msg_l = ();
# process incoming msg
my $header = @{$msg_hash->{header}}[0];
if( 1 == length @target_l) {
my $target = $target_l[0];
if(&server_matches($target)) {
+
+
if ($header eq 'new_key') {
@out_msg_l = &new_key($msg_hash)
} elsif ($header eq 'here_i_am') {
@out_msg_l = &here_i_am($msg_hash)
- } elsif ($header eq 'who_has') {
- @out_msg_l = &who_has($msg_hash)
- } elsif ($header eq 'who_has_i_do') {
- @out_msg_l = &who_has_i_do($msg_hash)
- } elsif ($header eq 'got_ping') {
- @out_msg_l = &got_ping($msg_hash)
- } elsif ($header eq 'get_load') {
- @out_msg_l = &execute_actions($msg_hash)
- } elsif ($header eq 'detected_hardware') {
- @out_msg_l = &process_detected_hardware($msg_hash)
- } elsif ($header eq 'trigger_wake') {
- foreach (@{$msg_hash->{macAddress}}){
- &main::daemon_log("SIPackages: trigger wake for $_", 1);
- do_wake($_);
- }
} else {
- &main::daemon_log("ERROR: $header is an unknown core function", 1);
- $error++;
+ if( exists $event_hash->{$header} ) {
+ # a event exists with the header as name
+ &main::daemon_log("found event '$header' at event-module '".$event_hash->{$header}."'", 5);
+ no strict 'refs';
+ @out_msg_l = &{$event_hash->{$header}."::$header"}($msg, $msg_hash, $session_id);
+ }
}
- } else {
- &main::daemon_log("msg is not for gosa-si-server '$server_address', deliver it to target '$target'", 5);
- push(@out_msg_l, $msg);
- }
+
+ # if delivery not possible raise error and return
+ if( not @out_msg_l ) {
+ &main::daemon_log("WARNING: SIPackages got not answer from event handler '$header'", 3);
+ } elsif( 0 == @out_msg_l) {
+ &main::daemon_log("ERROR: SIPackages: no event handler or core function defined for '$header'", 1);
+ }
+ }
+ else {
+ &main::daemon_log("msg is not for gosa-si-server '$server_address', deliver it to target '$target'", 5);
+ push(@out_msg_l, $msg);
+ }
}
return \@out_msg_l;
# RETURNS: nothing
# DESCRIPTION: process this incoming message
#===============================================================================
-sub got_ping {
- my ($msg_hash) = @_;
-
- my $source = @{$msg_hash->{source}}[0];
- my $target = @{$msg_hash->{target}}[0];
- my $header = @{$msg_hash->{header}}[0];
- my $session_id = @{$msg_hash->{'session_id'}}[0];
- my $act_time = &get_time;
- my @out_msg_l;
- my $out_msg;
-
- # check known_clients_db
- my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$source'";
- my $query_res = $main::known_clients_db->select_dbentry( $sql_statement );
- if( 1 == keys %{$query_res} ) {
- my $sql_statement= "UPDATE known_clients ".
- "SET status='$header', timestamp='$act_time' ".
- "WHERE hostname='$source'";
- my $res = $main::known_clients_db->update_dbentry( $sql_statement );
- }
-
- # check known_server_db
- $sql_statement = "SELECT * FROM known_server WHERE hostname='$source'";
- $query_res = $main::known_server_db->select_dbentry( $sql_statement );
- if( 1 == keys %{$query_res} ) {
- my $sql_statement= "UPDATE known_server ".
- "SET status='$header', timestamp='$act_time' ".
- "WHERE hostname='$source'";
- my $res = $main::known_server_db->update_dbentry( $sql_statement );
- }
-
- # create out_msg
- my $out_hash = &create_xml_hash($header, $source, "GOSA");
- &add_content2xml_hash($out_hash, "session_id", $session_id);
- $out_msg = &create_xml_string($out_hash);
- push(@out_msg_l, $out_msg);
-
- return @out_msg_l;
-}
+#sub got_ping {
+# my ($msg_hash) = @_;
+#
+# my $source = @{$msg_hash->{source}}[0];
+# my $target = @{$msg_hash->{target}}[0];
+# my $header = @{$msg_hash->{header}}[0];
+# my $session_id = @{$msg_hash->{'session_id'}}[0];
+# my $act_time = &get_time;
+# my @out_msg_l;
+# my $out_msg;
+#
+# # check known_clients_db
+# my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$source'";
+# my $query_res = $main::known_clients_db->select_dbentry( $sql_statement );
+# if( 1 == keys %{$query_res} ) {
+# my $sql_statement= "UPDATE known_clients ".
+# "SET status='$header', timestamp='$act_time' ".
+# "WHERE hostname='$source'";
+# my $res = $main::known_clients_db->update_dbentry( $sql_statement );
+# }
+#
+# # check known_server_db
+# $sql_statement = "SELECT * FROM known_server WHERE hostname='$source'";
+# $query_res = $main::known_server_db->select_dbentry( $sql_statement );
+# if( 1 == keys %{$query_res} ) {
+# my $sql_statement= "UPDATE known_server ".
+# "SET status='$header', timestamp='$act_time' ".
+# "WHERE hostname='$source'";
+# my $res = $main::known_server_db->update_dbentry( $sql_statement );
+# }
+#
+# # create out_msg
+# my $out_hash = &create_xml_hash($header, $source, "GOSA");
+# &add_content2xml_hash($out_hash, "session_id", $session_id);
+# $out_msg = &create_xml_string($out_hash);
+# push(@out_msg_l, $out_msg);
+#
+# return @out_msg_l;
+#}
#=== FUNCTION ================================================================
# NAME: new_passwd
return &build_msg("new_ldap_config", $server_address, $address, \%data);
}
-sub process_detected_hardware {
- my $msg_hash = shift;
- my $address = $msg_hash->{source}[0];
- my $gotoHardwareChecksum= $msg_hash->{detected_hardware}[0]->{gotoHardwareChecksum};
-
- my $sql_statement= "SELECT * FROM known_clients WHERE hostname='$address'";
- my $res = $main::known_clients_db->select_dbentry( $sql_statement );
-
- # check hit
- my $hit_counter = keys %{$res};
- if( not $hit_counter == 1 ) {
- &main::daemon_log("ERROR: more or no hit found in known_clients_db by query by '$address'", 1);
- return;
- }
-
- my $macaddress = $res->{1}->{macaddress};
- my $hostkey = $res->{1}->{hostkey};
-
- if (not defined $macaddress) {
- &main::daemon_log("ERROR: no mac address found for client $address", 1);
- return;
- }
- # Build LDAP connection
- my $ldap = Net::LDAP->new($ldap_uri);
- if( not defined $ldap ) {
- &main::daemon_log("ERROR: cannot connect to ldap: $ldap_uri", 1);
- return;
- }
-
- # Bind to a directory with dn and password
- my $mesg= $ldap->bind($ldap_admin_dn, password => $ldap_admin_password);
-
- # Perform search
- $mesg = $ldap->search(
- base => $ldap_base,
- scope => 'sub',
- filter => "(&(objectClass=GOhard)(|(macAddress=$macaddress)(dhcpHWaddress=ethernet $macaddress)))"
- );
-
- # We need to create a base entry first (if not done from ArpHandler)
- if($mesg->count == 0) {
- &main::daemon_log("Need to create a new LDAP Entry for client $address", 1);
- my $resolver=Net::DNS::Resolver->new;
- my $ipaddress= $1 if $address =~ /^([0-9\.]*?):.*$/;
- my $dnsresult= $resolver->search($ipaddress);
- my $dnsname= (defined($dnsresult))?$dnsresult->{answer}[0]->{ptrdname}:$ipaddress;
- my $cn = (($dnsname =~ /^(\d){1,3}\.(\d){1,3}\.(\d){1,3}\.(\d){1,3}/) ? $dnsname : sprintf "%s", $dnsname =~ /([^\.]+)\.?/);
- my $dn = "cn=$cn,ou=incoming,$ldap_base";
- &main::daemon_log("Creating entry for $dn",6);
- my $entry= Net::LDAP::Entry->new( $dn );
- $entry->dn($dn);
- $entry->add("objectClass" => "goHard");
- $entry->add("cn" => $cn);
- $entry->add("macAddress" => $macaddress);
- $entry->add("gotomode" => "locked");
- $entry->add("gotoSysStatus" => "new-system");
- $entry->add("ipHostNumber" => $ipaddress);
- if(defined($gosa_unit_tag) && length($gosa_unit_tag) > 0) {
- $entry->add("objectClass" => "gosaAdministrativeUnit");
- $entry->add("gosaUnitTag" => $gosa_unit_tag);
- }
- my $res=$entry->update($ldap);
- if(defined($res->{'errorMessage'}) &&
- length($res->{'errorMessage'}) >0) {
- &main::daemon_log("There was a problem adding the entries to LDAP:", 1);
- &main::daemon_log($res->{'errorMessage'}, 1);
- return;
- } else {
- # Fill $mesg again
- $mesg = $ldap->search(
- base => $ldap_base,
- scope => 'sub',
- filter => "(&(objectClass=GOhard)(|(macAddress=$macaddress)(dhcpHWaddress=ethernet $macaddress)))"
- );
- }
- }
-
- if($mesg->count == 1) {
- my $entry= $mesg->entry(0);
- $entry->changetype("modify");
- foreach my $attribute (
- "gotoSndModule", "ghNetNic", "gotoXResolution", "ghSoundAdapter", "ghCpuType", "gotoXkbModel",
- "ghGfxAdapter", "gotoXMousePort", "ghMemSize", "gotoXMouseType", "ghUsbSupport", "gotoXHsync",
- "gotoXDriver", "gotoXVsync", "gotoXMonitor", "gotoHardwareChecksum") {
- if(defined($msg_hash->{detected_hardware}[0]->{$attribute}) &&
- length($msg_hash->{detected_hardware}[0]->{$attribute}) >0 ) {
- if(defined($entry->get_value($attribute))) {
- $entry->delete($attribute);
- }
- &main::daemon_log("Adding attribute $attribute with value ".$msg_hash->{detected_hardware}[0]->{$attribute},1);
- $entry->add($attribute => $msg_hash->{detected_hardware}[0]->{$attribute});
- }
- }
- foreach my $attribute (
- "gotoModules", "ghScsiDev", "ghIdeDev") {
- if(defined($msg_hash->{detected_hardware}[0]->{$attribute}) &&
- length($msg_hash->{detected_hardware}[0]->{$attribute}) >0 ) {
- if(defined($entry->get_value($attribute))) {
- $entry->delete($attribute);
- }
- foreach my $array_entry (@{$msg_hash->{detected_hardware}[0]->{$attribute}}) {
- $entry->add($attribute => $array_entry);
- }
- }
- }
-
- my $res=$entry->update($ldap);
- if(defined($res->{'errorMessage'}) &&
- length($res->{'errorMessage'}) >0) {
- &main::daemon_log("There was a problem adding the entries to LDAP:", 1);
- &main::daemon_log($res->{'errorMessage'}, 1);
- } else {
- &main::daemon_log("Added Hardware configuration to LDAP", 4);
- }
-
- }
- return;
-}
+#sub process_detected_hardware {
+# my $msg_hash = shift;
+# my $address = $msg_hash->{source}[0];
+# my $gotoHardwareChecksum= $msg_hash->{detected_hardware}[0]->{gotoHardwareChecksum};
+#
+# my $sql_statement= "SELECT * FROM known_clients WHERE hostname='$address'";
+# my $res = $main::known_clients_db->select_dbentry( $sql_statement );
+#
+# # check hit
+# my $hit_counter = keys %{$res};
+# if( not $hit_counter == 1 ) {
+# &main::daemon_log("ERROR: more or no hit found in known_clients_db by query by '$address'", 1);
+# return;
+# }
+#
+# my $macaddress = $res->{1}->{macaddress};
+# my $hostkey = $res->{1}->{hostkey};
+#
+# if (not defined $macaddress) {
+# &main::daemon_log("ERROR: no mac address found for client $address", 1);
+# return;
+# }
+# # Build LDAP connection
+# my $ldap = Net::LDAP->new($ldap_uri);
+# if( not defined $ldap ) {
+# &main::daemon_log("ERROR: cannot connect to ldap: $ldap_uri", 1);
+# return;
+# }
+#
+# # Bind to a directory with dn and password
+# my $mesg= $ldap->bind($ldap_admin_dn, password => $ldap_admin_password);
+#
+# # Perform search
+# $mesg = $ldap->search(
+# base => $ldap_base,
+# scope => 'sub',
+# filter => "(&(objectClass=GOhard)(|(macAddress=$macaddress)(dhcpHWaddress=ethernet $macaddress)))"
+# );
+#
+# # We need to create a base entry first (if not done from ArpHandler)
+# if($mesg->count == 0) {
+# &main::daemon_log("Need to create a new LDAP Entry for client $address", 1);
+# my $resolver=Net::DNS::Resolver->new;
+# my $ipaddress= $1 if $address =~ /^([0-9\.]*?):.*$/;
+# my $dnsresult= $resolver->search($ipaddress);
+# my $dnsname= (defined($dnsresult))?$dnsresult->{answer}[0]->{ptrdname}:$ipaddress;
+# my $cn = (($dnsname =~ /^(\d){1,3}\.(\d){1,3}\.(\d){1,3}\.(\d){1,3}/) ? $dnsname : sprintf "%s", $dnsname =~ /([^\.]+)\.?/);
+# my $dn = "cn=$cn,ou=incoming,$ldap_base";
+# &main::daemon_log("Creating entry for $dn",6);
+# my $entry= Net::LDAP::Entry->new( $dn );
+# $entry->dn($dn);
+# $entry->add("objectClass" => "goHard");
+# $entry->add("cn" => $cn);
+# $entry->add("macAddress" => $macaddress);
+# $entry->add("gotomode" => "locked");
+# $entry->add("gotoSysStatus" => "new-system");
+# $entry->add("ipHostNumber" => $ipaddress);
+# if(defined($gosa_unit_tag) && length($gosa_unit_tag) > 0) {
+# $entry->add("objectClass" => "gosaAdministrativeUnit");
+# $entry->add("gosaUnitTag" => $gosa_unit_tag);
+# }
+# my $res=$entry->update($ldap);
+# if(defined($res->{'errorMessage'}) &&
+# length($res->{'errorMessage'}) >0) {
+# &main::daemon_log("There was a problem adding the entries to LDAP:", 1);
+# &main::daemon_log($res->{'errorMessage'}, 1);
+# return;
+# } else {
+# # Fill $mesg again
+# $mesg = $ldap->search(
+# base => $ldap_base,
+# scope => 'sub',
+# filter => "(&(objectClass=GOhard)(|(macAddress=$macaddress)(dhcpHWaddress=ethernet $macaddress)))"
+# );
+# }
+# }
+#
+# if($mesg->count == 1) {
+# my $entry= $mesg->entry(0);
+# $entry->changetype("modify");
+# foreach my $attribute (
+# "gotoSndModule", "ghNetNic", "gotoXResolution", "ghSoundAdapter", "ghCpuType", "gotoXkbModel",
+# "ghGfxAdapter", "gotoXMousePort", "ghMemSize", "gotoXMouseType", "ghUsbSupport", "gotoXHsync",
+# "gotoXDriver", "gotoXVsync", "gotoXMonitor", "gotoHardwareChecksum") {
+# if(defined($msg_hash->{detected_hardware}[0]->{$attribute}) &&
+# length($msg_hash->{detected_hardware}[0]->{$attribute}) >0 ) {
+# if(defined($entry->get_value($attribute))) {
+# $entry->delete($attribute);
+# }
+# &main::daemon_log("Adding attribute $attribute with value ".$msg_hash->{detected_hardware}[0]->{$attribute},1);
+# $entry->add($attribute => $msg_hash->{detected_hardware}[0]->{$attribute});
+# }
+# }
+# foreach my $attribute (
+# "gotoModules", "ghScsiDev", "ghIdeDev") {
+# if(defined($msg_hash->{detected_hardware}[0]->{$attribute}) &&
+# length($msg_hash->{detected_hardware}[0]->{$attribute}) >0 ) {
+# if(defined($entry->get_value($attribute))) {
+# $entry->delete($attribute);
+# }
+# foreach my $array_entry (@{$msg_hash->{detected_hardware}[0]->{$attribute}}) {
+# $entry->add($attribute => $array_entry);
+# }
+# }
+# }
+#
+# my $res=$entry->update($ldap);
+# if(defined($res->{'errorMessage'}) &&
+# length($res->{'errorMessage'}) >0) {
+# &main::daemon_log("There was a problem adding the entries to LDAP:", 1);
+# &main::daemon_log($res->{'errorMessage'}, 1);
+# } else {
+# &main::daemon_log("Added Hardware configuration to LDAP", 4);
+# }
+#
+# }
+# return;
+#}
#=== FUNCTION ================================================================
# NAME: hardware_config
# PARAMETERS: address - string - ip address and port of a host
}
-#=== FUNCTION ================================================================
-# NAME: execute_actions
-# PARAMETERS: msg_hash - hash - hash from function create_xml_hash
-# RETURNS: nothing
-# DESCRIPTION: invokes the script specified in msg_hash which is located under
-# /etc/gosad/actions
-#===============================================================================
-sub execute_actions {
- my ($msg_hash) = @_ ;
- my $configdir= '/etc/gosad/actions/';
- my $result;
-
- my $header = @{$msg_hash->{header}}[0];
- my $source = @{$msg_hash->{source}}[0];
- my $target = @{$msg_hash->{target}}[0];
-
- if((not defined $source)
- && (not defined $target)
- && (not defined $header)) {
- &main::daemon_log("ERROR: Entries missing in XML msg for gosad actions under /etc/gosad/actions");
- } else {
- my $parameters="";
- my @params = @{$msg_hash->{$header}};
- my $params = join(", ", @params);
- &main::daemon_log("execute_actions: got parameters: $params", 5);
-
- if (@params) {
- foreach my $param (@params) {
- my $param_value = (&get_content_from_xml_hash($msg_hash, $param))[0];
- &main::daemon_log("execute_actions: parameter -> value: $param -> $param_value", 7);
- $parameters.= " ".$param_value;
- }
- }
-
- my $cmd= $configdir.$header."$parameters";
- &main::daemon_log("execute_actions: executing cmd: $cmd", 7);
- $result= "";
- open(PIPE, "$cmd 2>&1 |");
- while(<PIPE>) {
- $result.=$_;
- }
- close(PIPE);
- }
-
- # process the event result
-
-
- return;
-}
-
+##=== FUNCTION ================================================================
+## NAME: execute_actions
+## PARAMETERS: msg_hash - hash - hash from function create_xml_hash
+## RETURNS: nothing
+## DESCRIPTION: invokes the script specified in msg_hash which is located under
+## /etc/gosad/actions
+##===============================================================================
+#sub execute_actions {
+# my ($msg_hash) = @_ ;
+# my $configdir= '/etc/gosad/actions/';
+# my $result;
+#
+# my $header = @{$msg_hash->{header}}[0];
+# my $source = @{$msg_hash->{source}}[0];
+# my $target = @{$msg_hash->{target}}[0];
+#
+# if((not defined $source)
+# && (not defined $target)
+# && (not defined $header)) {
+# &main::daemon_log("ERROR: Entries missing in XML msg for gosad actions under /etc/gosad/actions");
+# } else {
+# my $parameters="";
+# my @params = @{$msg_hash->{$header}};
+# my $params = join(", ", @params);
+# &main::daemon_log("execute_actions: got parameters: $params", 5);
+#
+# if (@params) {
+# foreach my $param (@params) {
+# my $param_value = (&get_content_from_xml_hash($msg_hash, $param))[0];
+# &main::daemon_log("execute_actions: parameter -> value: $param -> $param_value", 7);
+# $parameters.= " ".$param_value;
+# }
+# }
+#
+# my $cmd= $configdir.$header."$parameters";
+# &main::daemon_log("execute_actions: executing cmd: $cmd", 7);
+# $result= "";
+# open(PIPE, "$cmd 2>&1 |");
+# while(<PIPE>) {
+# $result.=$_;
+# }
+# close(PIPE);
+# }
+#
+# # process the event result
+#
+#
+# return;
+#}
+#
-#vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1;
index dbb7ed7f1713be365897eb55736d84650b7a0b8e..23dae9f5159ac83b2fdebca6c4bfb496bcfba051 100644 (file)
"trigger_action_sysinfo",
"trigger_action_instant_update",
"trigger_action_rescan",
+ "trigger_action_wake",
);
@EXPORT = @events;
&add_content2xml_hash($out_hash, "session_id", $session_id);
my $out_msg = &create_xml_string($out_hash);
- return ( $out_msg );
+ my @out_msg_l = ( $out_msg );
+ return @out_msg_l;
}
sub network_completition {
my $out_hash = &create_xml_hash("detect_hardware", $source, $target);
my $out_msg = &create_xml_string($out_hash);
- return ( $out_msg );
+ my @out_msg_l = ( $out_msg );
+ return @out_msg_l;
+
}
my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $target);
my $out_msg = &create_xml_string($out_hash);
- return ( $out_msg );
+ my @out_msg_l = ( $out_msg );
+ return @out_msg_l;
}
sub trigger_action_localboot {
my ($msg, $msg_hash) = @_;
$msg =~ s/<header>gosa_trigger_action_localboot<\/header>/<header>trigger_action_localboot<\/header>/;
-
- return ( $msg );
+ my @out_msg_l = ($msg);
+ return @out_msg_l;
}
sub trigger_action_halt {
my ($msg, $msg_hash) = @_;
$msg =~ s/<header>gosa_trigger_action_halt<\/header>/<header>trigger_action_halt<\/header>/;
- return ( $msg );
+ my @out_msg_l = ($msg);
+ return @out_msg_l;
}
sub trigger_action_reboot {
my ($msg, $msg_hash) = @_;
$msg =~ s/<header>gosa_trigger_action_reboot<\/header>/<header>trigger_action_reboot<\/header>/;
- return ( $msg );
+ my @out_msg_l = ($msg);
+ return @out_msg_l;
}
sub trigger_action_memcheck {
my ($msg, $msg_hash) = @_ ;
$msg =~ s/<header>gosa_trigger_action_memcheck<\/header>/<header>trigger_action_memcheck<\/header>/;
- return ( $msg );
+ my @out_msg_l = ($msg);
+ return @out_msg_l;
}
sub trigger_action_reinstall {
my ($msg, $msg_hash) = @_;
$msg =~ s/<header>gosa_trigger_action_reinstall<\/header>/<header>trigger_action_reinstall<\/header>/;
- return ( $msg );
+ my @out_msg_l = ($msg);
+ return @out_msg_l;
}
sub trigger_action_update {
my ($msg, $msg_hash) = @_;
$msg =~ s/<header>gosa_trigger_action_update<\/header>/<header>trigger_action_update<\/header>/;
- return ( $msg );
+ my @out_msg_l = ($msg);
+ return @out_msg_l;
}
sub trigger_action_instant_update {
my ($msg, $msg_hash) = @_;
$msg =~ s/<header>gosa_trigger_action_instant_update<\/header>/<header>trigger_action_instant_update<\/header>/;
- return ( $msg );
+ my @out_msg_l = ($msg);
+ return @out_msg_l;
}
sub trigger_action_sysinfo {
my ($msg, $msg_hash) = @_;
$msg =~ s/<header>gosa_trigger_action_sysinfo<\/header>/<header>trigger_action_sysinfo<\/header>/;
- return ( $msg );
+ my @out_msg_l = ($msg);
+ return @out_msg_l;
}
sub new_key_for_client {
my ($msg, $msg_hash) = @_;
$msg =~ s/<header>gosa_new_key_for_client<\/header>/<header>new_key<\/header>/;
- return ( $msg );
+ my @out_msg_l = ($msg);
+ return @out_msg_l;
}
sub trigger_action_rescan {
my ($msg, $msg_hash) = @_;
$msg =~ s/<header>gosa_trigger_action_rescan<\/header>/<header>trigger_action_rescan<\/header>/;
- return ( $msg );
+ my @out_msg_l = ($msg);
+ return @out_msg_l;
+}
+
+
+sub trigger_action_wake {
+ my ($msg, $msg_hash) = @_;
+ my %data = ( 'macAddress' => \@{$msg_hash->{macAddress}} );
+ my $out_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
+ my @out_msg_l = ($out_msg);
+ return @out_msg_l;
}
1;
index 4cd6abff2aaf2812b918168fd030282b52bab201..88cc39f1b1ce1605278dc00fa9a64140aa6a9ce8 100644 (file)
@ISA = qw(Exporter);
my @events = (
"got_ping",
+ "detected_hardware",
+ "trigger_wake",
);
@EXPORT = @events;
use strict;
use warnings;
use GOSA::GosaSupportDaemon;
+use Socket;
BEGIN {}
### Start ######################################################################
-#&main::read_configfile($main::cfg_file, %cfg_defaults);
+my $ldap_uri;
+my $ldap_base;
+my $ldap_admin_dn;
+my $ldap_admin_password;
+my $gosa_unit_tag;
+
+my %cfg_defaults = (
+"server" => {
+ "ldap-uri" => [\$ldap_uri, ""],
+ "ldap-base" => [\$ldap_base, ""],
+ "ldap-admin-dn" => [\$ldap_admin_dn, ""],
+ "ldap-admin-password" => [\$ldap_admin_password, ""],
+ "gosa-unit-tag" => [\$gosa_unit_tag, ""],
+ },
+);
+&read_configfile($main::cfg_file, %cfg_defaults);
+
sub get_events {
return \@events;
}
+sub read_configfile {
+ my ($cfg_file, %cfg_defaults) = @_;
+ my $cfg;
+
+ if( defined( $cfg_file) && ( length($cfg_file) > 0 )) {
+ if( -r $cfg_file ) {
+ $cfg = Config::IniFiles->new( -file => $cfg_file );
+ } else {
+ &main::daemon_log("ERROR: siTriggered.pm couldn't read config file!", 1);
+ }
+ } else {
+ $cfg = Config::IniFiles->new() ;
+ }
+ foreach my $section (keys %cfg_defaults) {
+ foreach my $param (keys %{$cfg_defaults{ $section }}) {
+ my $pinfo = $cfg_defaults{ $section }{ $param };
+ ${@$pinfo[0]} = $cfg->val( $section, $param, @$pinfo[1] );
+ }
+ }
+}
+
sub got_ping {
my ($msg, $msg_hash, $session_id) = @_;
}
+sub detected_hardware {
+ my ($msg, $msg_hash, $session_id) = @_ ;
+ my $address = $msg_hash->{source}[0];
+ my $gotoHardwareChecksum= $msg_hash->{detected_hardware}[0]->{gotoHardwareChecksum};
+
+ my $sql_statement= "SELECT * FROM known_clients WHERE hostname='$address'";
+ my $res = $main::known_clients_db->select_dbentry( $sql_statement );
+
+ # check hit
+ my $hit_counter = keys %{$res};
+ if( not $hit_counter == 1 ) {
+ &main::daemon_log("ERROR: more or no hit found in known_clients_db by query by '$address'", 1);
+ return;
+ }
+
+ my $macaddress = $res->{1}->{macaddress};
+ my $hostkey = $res->{1}->{hostkey};
+
+ if (not defined $macaddress) {
+ &main::daemon_log("ERROR: no mac address found for client $address", 1);
+ return;
+ }
+ # Build LDAP connection
+ my $ldap = Net::LDAP->new($ldap_uri);
+ if( not defined $ldap ) {
+ &main::daemon_log("ERROR: cannot connect to ldap: $ldap_uri", 1);
+ return;
+ }
+
+ # Bind to a directory with dn and password
+ my $mesg= $ldap->bind($ldap_admin_dn, password => $ldap_admin_password);
+
+ # Perform search
+ $mesg = $ldap->search(
+ base => $ldap_base,
+ scope => 'sub',
+ filter => "(&(objectClass=GOhard)(|(macAddress=$macaddress)(dhcpHWaddress=ethernet $macaddress)))"
+ );
+
+ # We need to create a base entry first (if not done from ArpHandler)
+ if($mesg->count == 0) {
+ &main::daemon_log("INFO: Need to create a new LDAP Entry for client $address", 6);
+ my $resolver=Net::DNS::Resolver->new;
+ my $ipaddress= $1 if $address =~ /^([0-9\.]*?):.*$/;
+ my $dnsresult= $resolver->search($ipaddress);
+ my $dnsname= (defined($dnsresult))?$dnsresult->{answer}[0]->{ptrdname}:$ipaddress;
+ my $cn = (($dnsname =~ /^(\d){1,3}\.(\d){1,3}\.(\d){1,3}\.(\d){1,3}/) ? $dnsname : sprintf "%s", $dnsname =~ /([^\.]+)\.?/);
+ my $dn = "cn=$cn,ou=incoming,$ldap_base";
+ &main::daemon_log("INFO: Creating entry for $dn",5);
+ my $entry= Net::LDAP::Entry->new( $dn );
+ $entry->dn($dn);
+ $entry->add("objectClass" => "goHard");
+ $entry->add("cn" => $cn);
+ $entry->add("macAddress" => $macaddress);
+ $entry->add("gotomode" => "locked");
+ $entry->add("gotoSysStatus" => "new-system");
+ $entry->add("ipHostNumber" => $ipaddress);
+ if(defined($gosa_unit_tag) && length($gosa_unit_tag) > 0) {
+ $entry->add("objectClass" => "gosaAdministrativeUnit");
+ $entry->add("gosaUnitTag" => $gosa_unit_tag);
+ }
+ my $res=$entry->update($ldap);
+ if(defined($res->{'errorMessage'}) &&
+ length($res->{'errorMessage'}) >0) {
+ &main::daemon_log("ERROR: can not add entries to LDAP: ".$res->{'errorMessage'}, 1);
+ return;
+ } else {
+ # Fill $mesg again
+ $mesg = $ldap->search(
+ base => $ldap_base,
+ scope => 'sub',
+ filter => "(&(objectClass=GOhard)(|(macAddress=$macaddress)(dhcpHWaddress=ethernet $macaddress)))"
+ );
+ }
+ }
+
+ if($mesg->count == 1) {
+ my $entry= $mesg->entry(0);
+ $entry->changetype("modify");
+ foreach my $attribute (
+ "gotoSndModule", "ghNetNic", "gotoXResolution", "ghSoundAdapter", "ghCpuType", "gotoXkbModel",
+ "ghGfxAdapter", "gotoXMousePort", "ghMemSize", "gotoXMouseType", "ghUsbSupport", "gotoXHsync",
+ "gotoXDriver", "gotoXVsync", "gotoXMonitor", "gotoHardwareChecksum") {
+ if(defined($msg_hash->{detected_hardware}[0]->{$attribute}) &&
+ length($msg_hash->{detected_hardware}[0]->{$attribute}) >0 ) {
+ if(defined($entry->get_value($attribute))) {
+ $entry->delete($attribute);
+ }
+ &main::daemon_log("INFO: Adding attribute $attribute with value ".$msg_hash->{detected_hardware}[0]->{$attribute},5);
+ $entry->add($attribute => $msg_hash->{detected_hardware}[0]->{$attribute});
+ }
+ }
+ foreach my $attribute (
+ "gotoModules", "ghScsiDev", "ghIdeDev") {
+ if(defined($msg_hash->{detected_hardware}[0]->{$attribute}) &&
+ length($msg_hash->{detected_hardware}[0]->{$attribute}) >0 ) {
+ if(defined($entry->get_value($attribute))) {
+ $entry->delete($attribute);
+ }
+ foreach my $array_entry (@{$msg_hash->{detected_hardware}[0]->{$attribute}}) {
+ $entry->add($attribute => $array_entry);
+ }
+ }
+ }
+
+ my $res=$entry->update($ldap);
+ if(defined($res->{'errorMessage'}) &&
+ length($res->{'errorMessage'}) >0) {
+ &main::daemon_log("ERROR: can not add entries to LDAP: ".$res->{'errorMessage'}, 1);
+ } else {
+ &main::daemon_log("INFO: Added Hardware configuration to LDAP", 5);
+ }
+
+ }
+ return ;
+}
+
+
+sub trigger_wake {
+ my ($msg, $msg_hash, $session_id) = @_ ;
+
+ foreach (@{$msg_hash->{macAddress}}){
+ &main::daemon_log("INFO: trigger wake for $_", 5);
+ my $host = shift;
+ my $ipaddr = shift || '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 {
+ # $host is not a hardware address, try to resolve it
+ my $ip_re = join('\.', ('([0-9]|[1-9][0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))') x 4);
+ my $ip_addr;
+ if ($host =~ m/^$ip_re$/) {
+ $ip_addr = $host;
+ } else {
+ my $h;
+ unless ($h = gethost($host)) {
+ return undef;
+ }
+ $ip_addr = inet_ntoa($h->addr);
+ }
+ }
+
+ # 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)->addr;
+ $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;
index 288676b93a25659f6ddc0b505328aae723495e2a..e38d7173668b2b76f4eb3083d244b2267e8656b9 100755 (executable)
--- a/gosa-si/tests/client.php
+++ b/gosa-si/tests/client.php
#$data = "<xml> <header>gosa_new_key_for_client</header> <target>00:0c:29:bd:7b:e7</target> <source>10.89.1.31:20081</source> </xml>";
#$data = "<xml> <header>gosa_new_key_for_client</header> <target>10.89.1.12:1234</target> <source>10.89.1.31:20081</source> </xml>";
#$data = "<xml> <header>gosa_new_key_for_client</header> <target>10.89.1.31:20083</target> <source>10.89.1.31:20081</source> </xml>";
+#$data = "<xml> <header>gosa_trigger_action_wake</header> <target>00:01:6c:9d:b9:fa</target> <source>10.89.1.31:20081</source> </xml>";
-#$data = "<xml> <header>gosa_import_events</header> <target>00:01:6c:9d:b9:fa</target> <source>10.89.1.31:20081</source> </xml>";
#$data = "<xml> <header>gosa_trigger_action_localboot</header> <target>00:01:6c:9d:b9:fa</target> <source>10.89.1.31:20081</source> <timeout>-1</timeout></xml>";