From 29b8af84e3dff8886518478250213ee1b2af3998 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Fri, 15 Feb 2008 17:51:37 +0000 Subject: [PATCH] general update git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8940 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/client/events/corefunctions.pm | 42 +---- gosa-si/client/events/gosaTriggered.pm | 222 +++++++++++++++++++++++++ gosa-si/gosa-si-client | 5 + gosa-si/gosa-si-server | 2 + gosa-si/modules/GosaPackages.pm | 17 +- gosa-si/server/events/installation.pm | 93 ----------- gosa-si/tests/client.php | 7 +- 7 files changed, 249 insertions(+), 139 deletions(-) create mode 100644 gosa-si/client/events/gosaTriggered.pm delete mode 100644 gosa-si/server/events/installation.pm diff --git a/gosa-si/client/events/corefunctions.pm b/gosa-si/client/events/corefunctions.pm index d0126a28e..80589e863 100644 --- a/gosa-si/client/events/corefunctions.pm +++ b/gosa-si/client/events/corefunctions.pm @@ -1,7 +1,7 @@ package corefunctions; use Exporter; @ISA = qw(Exporter); -my @events = qw(get_events registered new_ldap_config new_key generate_hw_digest detect_hardware reboot halt reinstall softupdate confirm_new_key); +my @events = qw(get_events registered new_ldap_config new_key generate_hw_digest detect_hardware confirm_new_key ping import_events); @EXPORT = @events; use strict; @@ -54,8 +54,12 @@ sub write_to_file { if( $error == 0 ) { chomp($string); - - open(FILE, ">> $file"); + + if( not -f $file ) { + open (FILE, "$file"); + close(FILE); + } + open(FILE, ">> $file") or &main::daemon_log("ERROR in corefunctions.pm: can not open '$file' to write '$string'", 1);; print FILE $string."\n"; close(FILE); } @@ -75,37 +79,6 @@ sub daemon_log { } -sub reboot { - my ($msg, $msg_hash) = @_ ; - &main::daemon_log("got reboot-msg: $msg", 5); - return; -} - - -sub halt { - my ($msg, $msg_hash) = @_ ; - - &main::daemon_log("got halt-msg: $msg", 5); - return; -} - - -sub reinstall { - my ($msg, $msg_hash) = @_ ; - &main::daemon_log("got reinstall-msg: $msg", 5); - - return; -} - - -sub softupdate { - my ($msg, $msg_hash) = @_ ; - &main::daemon_log("got softupdate-msg: $msg", 5); - - return; -} - - sub registered { my ($msg, $msg_hash) = @_ ; @@ -453,5 +426,4 @@ sub ping { } - 1; diff --git a/gosa-si/client/events/gosaTriggered.pm b/gosa-si/client/events/gosaTriggered.pm new file mode 100644 index 000000000..e12911547 --- /dev/null +++ b/gosa-si/client/events/gosaTriggered.pm @@ -0,0 +1,222 @@ +package gosaTriggered; +use Exporter; +@ISA = qw(Exporter); +my @events = ( + "get_events", + "trigger_action_localboot", + "trigger_action_halt", + "trigger_action_reboot", + "trigger_action_memcheck", + "trigger_action_reinstall", + "trigger_action_update", + "trigger_action_instant_update", + "trigger_action_sysinfo", + "trigger_action_rescan", + ); +@EXPORT = @events; + +use strict; +use warnings; + + +BEGIN {} + +END {} + + +sub get_events { return \@events; } + + +sub trigger_action_localboot { + my ($msg, $msg_hash) = @_; + my $timeout; + + if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) { + $timeout = -1; + } + else { + $timeout = @{$msg_hash->{timeout}}[0]; + } + + # check logged in user + my $logged_in_user = 1; + if( $logged_in_user ) { + # TODO do something + } + else { + $timeout = 0; + } + + # execute function + if( $timeout == 0 ) { + print STDERR ("shutdown -r +$timeout\n"); + } + elsif( $timeout > 0 ) { + print STDERR ("shutdown -r +$timeout\n"); + } + elsif( $timeout < 0 ) { + print STDERR "The administrator has sent a signal to reboot this workstation. It will reboot after you've logged out.\n"; + open(FILE, "> /etc/gosa-si/event"); + print FILE "trigger_action_localboot\n"; + close(FILE); + } + else { + # TODO do something, error handling, logging + } + + return; +} + + +sub trigger_action_reboot { + my ($msg, $msg_hash) = @_; + print STDERR "jetzt würde ich trigger_action_reboot ausführen\n"; + return; +} + + +sub trigger_action_halt { + my ($msg, $msg_hash) = @_; + my $timeout; + + if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) { + $timeout = -1; + } + else { + $timeout = @{$msg_hash->{timeout}}[0]; + } + + # check logged in user + my $logged_in_user = 1; + if( $logged_in_user ) { + # TODO do something + } + else { + $timeout = 0; + } + + # execute function + if( $timeout == 0 ) { + print STDERR ("shutdown -h +$timeout\n"); + } + elsif( $timeout > 0 ) { + print STDERR ("shutdown -h +$timeout\n"); + } + elsif( $timeout < 0 ) { + print STDERR "The administrator has sent a signal to shutdown this workstation. It will shutdown after you've logged out.\n"; + open(FILE, "> /etc/gosa-si/event"); + print FILE "trigger_action_halt\n"; + close(FILE); + } + else { + # TODO do something, error handling, logging + } + + return; +} + + +# TODO +sub trigger_action_memcheck { + my ($msg, $msg_hash) = @_ ; + print STDERR "\n\njetzt würde ich trigger_action_memcheck ausführen\n\n"; + return; +} + + +sub trigger_action_reinstall { + my ($msg, $msg_hash) = @_; + my $timeout; + + # check timeout + if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) { + $timeout = -1; + } + else { + $timeout = @{$msg_hash->{timeout}}[0]; + } + + # check logged in user + my $logged_in_user = 1; + if( $logged_in_user ) { + # TODO do something + } + else { + $timeout = 0; + } + + # execute function + if( $timeout == 0 ) { + print STDERR ("shutdown -r +$timeout\n"); + } + elsif( $timeout > 0 ) { + print STDERR ("shutdown -r +$timeout\n"); + + } + elsif( $timeout < 0 ) { + print STDERR "The administrator has sent a signal to reinstall this workstation. It will reinstall after you've logged out.\n"; + open(FILE, "> /etc/gosa-si/event"); + print FILE "trigger_action_reinstall\n"; + close(FILE); + } + else { + # TODO do something, error handling, logging + } + + return; +} + + +sub trigger_action_update { + my ($msg, $msg_hash) = @_; + + # execute function + open(FILE, "> /etc/gosa-si/event"); + print FILE "trigger_action_reinstall\n"; + close(FILE); + + # check logged in user + my $logged_in_user = 1; + if( $logged_in_user ) { + print STDERR "This system has been sent a signal for an update. The update will take place after you log out.\n"; + } + else { + # not jet + #system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai -N softupdate &" ) + } + + return; +} + + +sub trigger_action_instant_update { + my ($msg, $msg_hash) = @_; + + # check logged in user + my $logged_in_user = 1; + if( $logged_in_user ) { + print STDERR "This system has been sent a signal for an update. The update will take place now.\n"; + } + + # not jet + #system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai -N softupdate &" ) + + return; +} + + +# TODO +sub trigger_action_sysinfo { + my ($msg, $msg_hash) = @_; + print STDERR "jetzt würde ich trigger_action_sysinfo ausführen\n"; + return; +} + +# TODO +sub trigger_action_rescan{ + my ($msg, $msg_hash) = @_; + print STDERR "jetzt würde ich trigger_action_rescan ausführen\n"; + return; +} + +1; diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client index 27de3ab34..cf4488c25 100755 --- a/gosa-si/gosa-si-client +++ b/gosa-si/gosa-si-client @@ -1096,6 +1096,11 @@ sub import_events { } } + + my @all_events = keys %$event_hash; + my $all_events_string = join(", ", @all_events); + + daemon_log("INFO: imported events: $all_events_string", 5); } sub trigger_new_key { diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index e3849b442..570906585 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -889,6 +889,8 @@ sub client_input { daemon_log("Incoming msg from '".$heap->{'remote_ip'}."'", 7); daemon_log("\n$input", 8); + #################### + # check incoming msg # msg is from a new client or gosa ($msg, $msg_hash, $module) = &input_from_unknown_host($input); # msg is from a gosa-si-server or gosa-si-bus diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index 7ea3e54f0..bc067c337 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -297,23 +297,20 @@ sub process_gosa_msg { # decide wether msg is a core function or a event handler if ( $header eq 'query_jobdb') { - $out_msg = &query_jobdb + $out_msg = &query_jobdb } elsif ($header eq 'delete_jobdb_entry') { $out_msg = &delete_jobdb_entry } elsif ($header eq 'clear_jobdb') { - $out_msg = &clear_jobdb + $out_msg = &clear_jobdb } elsif ($header eq 'update_status_jobdb_entry' ) { - $out_msg = &update_status_jobdb_entry + $out_msg = &update_status_jobdb_entry } elsif ($header eq 'count_jobdb' ) { $out_msg = &count_jobdb - } elsif ($header eq 'trigger_action_reboot' ) { - print STDERR "trigger_action_reboot\n"; - print STDERR Dumper($msg); } 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 = &send_msg("trigger_wake", $server_address, "KNOWN_SERVER", \%data); + # Forward messages to all known servers as "trigger_wake" + my $in_hash= &transform_msg2hash($msg); + my %data = ( 'macAddress' => \@{$in_hash->{macAddress}} ); + $out_msg = &send_msg("trigger_wake", $server_address, "KNOWN_SERVER", \%data); } else { # msg could not be assigned to core function # maybe it is an eventa diff --git a/gosa-si/server/events/installation.pm b/gosa-si/server/events/installation.pm deleted file mode 100644 index b12e20ca2..000000000 --- a/gosa-si/server/events/installation.pm +++ /dev/null @@ -1,93 +0,0 @@ -package installation; -use Exporter; -@ISA = qw(Exporter); -my @events = qw(get_events set_activated_for_installation reboot halt softupdate reinstall new_key_for_client detect_hardware); -@EXPORT = @events; - -use strict; -use warnings; -use GOSA::GosaSupportDaemon; - - -BEGIN {} - -END {} - -### Start ###################################################################### - -#&main::read_configfile($main::cfg_file, %cfg_defaults); - -sub get_events { - return \@events; -} - - -sub detect_hardware { - my ($msg, $msg_hash) = @_ ; - # just forward msg to client, but dont forget to split off 'gosa_' in header - my $header = @{$msg_hash->{header}}[0]; - my $source = @{$msg_hash->{source}}[0]; - my $target = @{$msg_hash->{target}}[0]; - - my $out_hash = &create_xml_hash("detect_hardware", $source, $target); - my $out_msg = &create_xml_string($out_hash); - - return $out_msg; -} - - -sub set_activated_for_installation { - my ($msg, $msg_hash) = @_; - - my $header = @{$msg_hash->{header}}[0]; - my $source = @{$msg_hash->{source}}[0]; - my $target = @{$msg_hash->{target}}[0]; - - my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $target); - my $out_msg = &create_xml_string($out_hash); - - return $out_msg; -} - -sub reboot { - my ($msg, $msg_hash) = @_; - $msg =~ s/
gosa_reboot<\/header>/
reboot<\/header>/; - - return $msg; -} - - -sub halt { - my ($msg, $msg_hash) = @_; - $msg =~ s/
gosa_halt<\/header>/
halt<\/header>/; - - return $msg; -} - - -sub reinstall { - my ($msg, $msg_hash) = @_; - $msg =~ s/
gosa_reinstall<\/header>/
reinstall<\/header>/; - - return $msg; -} - - -sub softupdate { - my ($msg, $msg_hash) = @_; - $msg =~ s/
gosa_softupdate<\/header>/
softupdate<\/header>/; - - return $msg; -} - - -sub new_key_for_client { - my ($msg, $msg_hash) = @_; - $msg =~ s/
gosa_new_key_for_client<\/header>/
new_key<\/header>/; - - return $msg; -} - - - -1; diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index c0d3332d0..98391deab 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -48,10 +48,15 @@ if($sock->connected()){ #$data = "
gosa_halt
10.89.1.31:20083 10.89.1.31:20081
"; #$data = "
gosa_new_key_for_client
00:01:6c:9d:b9:fa 10.89.1.31:20081
"; #$data = "
gosa_new_key_for_client
00:0c:29:bd:7b:e7 10.89.1.31:20081
"; -$data = "
gosa_new_key_for_client
10.89.1.12:1234 10.89.1.31:20081
"; +#$data = "
gosa_new_key_for_client
10.89.1.12:1234 10.89.1.31:20081
"; #$data = "
gosa_new_key_for_client
10.89.1.31:20083 10.89.1.31:20081
"; +#$data = "
gosa_import_events
00:01:6c:9d:b9:fa 10.89.1.31:20081
"; +$data = "
gosa_trigger_action_localboot
00:01:6c:9d:b9:fa 10.89.1.31:20081 -1
"; + + + $sock->write($data); $answer = "nothing"; $answer = $sock->read(); -- 2.30.2