index 79143ff9c74290b2158bd084f6192f2650de7d8d..f069da1d4eb46362f612591af2f2c8e161374f8a 100644 (file)
use Net::ARP;
use Net::Ping;
use Socket;
-use utf8;
BEGIN {}
if( exists $msg_hash->{'user'} ) { @user_list = @{$msg_hash->{'user'}}; }
if( exists $msg_hash->{'group'} ) { @group_list = @{$msg_hash->{'group'}}; }
+ my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
+ }
+
# error handling
if( not @user_list && not @group_list ) {
&main::daemon_log("WARNING: no user-tag or a group-tag specified in 'send_user_msg'", 3);
my ($msg, $msg_hash, $session_id) = @_ ;
my $out_msg;
+ my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
+ }
+
$main::fai_server_db->create_table("new_fai_server", \@main::fai_server_col_names);
&main::create_fai_server_db("new_fai_server");
$main::fai_server_db->move_table("new_fai_server", $main::fai_server_tn);
my $target = @{$msg_hash->{'target'}}[0];
my $client = @{$msg_hash->{'client'}}[0];
+ my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
+ }
+
$header =~ s/^gosa_//;
- my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$client' OR macaddress='$client'";
+ my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$client' OR macaddress LIKE '$client'";
my $res = $main::known_clients_db->select_dbentry($sql_statement);
my $out_msg = "<xml><header>$header</header><source>$target</source><target>$source</target>";
my $header = @{$msg_hash->{'header'}}[0];
my $source = @{$msg_hash->{'source'}}[0];
my $target = @{$msg_hash->{'target'}}[0];
+
+ my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
+ }
+
my $usr = @{$msg_hash->{'usr'}}[0];
$header =~ s/^gosa_//;
sub ping {
my ($msg, $msg_hash, $session_id) = @_ ;
my $out_msg = $msg;
+ my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
+ }
+
$out_msg =~ s/<header>gosa_/<header>/;
- $out_msg =~ s/<\/xml>/<session_id>$session_id<\/session_id><\/xml>/;
my @out_msg_l = ( $out_msg );
return @out_msg_l;
sub detect_hardware {
- my ($msg, $msg_hash) = @_ ;
+ my ($msg, $msg_hash, $session_id) = @_ ;
# just forward msg to client, but dont forget to split off 'gosa_' in header
my $source = @{$msg_hash->{source}}[0];
my $target = @{$msg_hash->{target}}[0];
+ my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
+ }
my $out_hash = &create_xml_hash("detect_hardware", $source, $target);
- if( exists $msg_hash->{'jobdb_id'} ) {
- &add_content2xml_hash($out_hash, 'jobdb_id', @{$msg_hash->{'jobdb_id'}}[0]);
+ if( defined $jobdb_id ) {
+ &add_content2xml_hash($out_hash, 'jobdb_id', $jobdb_id);
}
my $out_msg = &create_xml_string($out_hash);
sub trigger_reload_ldap_config {
- my ($msg, $msg_hash) = @_ ;
+ my ($msg, $msg_hash, $session_id) = @_ ;
my $target = @{$msg_hash->{target}}[0];
+ my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
+ }
+
my $out_hash = &create_xml_hash("reload_ldap_config", $main::server_address, $main::server_address, $target);
- if( exists $msg_hash->{'jobdb_id'} ) {
- &add_content2xml_hash($out_hash, 'jobdb_id', @{$msg_hash->{'jobdb_id'}}[0]);
+ if( defined ) {
+ &add_content2xml_hash($out_hash, 'jobdb_id', $jobdb_id);
}
my $out_msg = &create_xml_string($out_hash);
my @out_msg_l;
sub set_activated_for_installation {
- my ($msg, $msg_hash) = @_;
-
+ 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 $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
+ }
+
my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $target);
- if( exists $msg_hash->{'jobdb_id'} ) {
- &add_content2xml_hash($out_hash, 'jobdb_id', @{$msg_hash->{'jobdb_id'}}[0]);
+ if( defined $jobdb_id ) {
+ &add_content2xml_hash($out_hash, 'jobdb_id', $jobdb_id);
}
my $out_msg = &create_xml_string($out_hash);
my @out_msg_l = ( $out_msg );
sub trigger_action_faireboot {
- my ($msg, $msg_hash) = @_;
+ my ($msg, $msg_hash, $session_id) = @_;
my $macaddress = @{$msg_hash->{target}}[0];
my $source = @{$msg_hash->{source}}[0];
$msg =~ s/<header>gosa_trigger_action_faireboot<\/header>/<header>trigger_action_faireboot<\/header>/;
push(@out_msg_l, $msg);
- change_goto_state('locked', \@{$msg_hash->{target}});
+ &main::change_goto_state('locked', \@{$msg_hash->{target}}, $session_id);
+ &main::change_fai_state('localboot', \@{$msg_hash->{target}}, $session_id);
# delete all jobs from jobqueue which correspond to fai
my $sql_statement = "DELETE FROM $main::job_queue_tn WHERE (macaddress='$macaddress' AND ".
sub trigger_action_lock {
- my ($msg, $msg_hash) = @_;
+ my ($msg, $msg_hash, $session_id) = @_;
my $macaddress = @{$msg_hash->{target}}[0];
my $source = @{$msg_hash->{source}}[0];
- change_goto_state('locked', \@{$msg_hash->{target}});
+ &main::change_goto_state('locked', \@{$msg_hash->{target}}, $session_id);
+ my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
+ }
my @out_msg_l;
return @out_msg_l;
sub trigger_action_activate {
- my ($msg, $msg_hash) = @_;
+ my ($msg, $msg_hash, $session_id) = @_;
my $macaddress = @{$msg_hash->{target}}[0];
my $source = @{$msg_hash->{source}}[0];
- change_goto_state('active', \@{$msg_hash->{target}});
+ &main::change_goto_state('active', \@{$msg_hash->{target}}, $session_id);
+ my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
+ }
my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $macaddress);
if( exists $msg_hash->{'jobdb_id'} ) {
sub trigger_action_localboot {
- my ($msg, $msg_hash) = @_;
+ my ($msg, $msg_hash, $session_id) = @_;
$msg =~ s/<header>gosa_trigger_action_localboot<\/header>/<header>trigger_action_localboot<\/header>/;
-
- change_fai_state('localboot', \@{$msg_hash->{target}});
+ &main::change_fai_state('localboot', \@{$msg_hash->{target}}, $session_id);
+ my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
+ }
my @out_msg_l = ($msg);
return @out_msg_l;
sub trigger_action_halt {
- my ($msg, $msg_hash) = @_;
+ my ($msg, $msg_hash, $session_id) = @_;
$msg =~ s/<header>gosa_trigger_action_halt<\/header>/<header>trigger_action_halt<\/header>/;
- change_fai_state('halt', \@{$msg_hash->{target}});
+ &main::change_fai_state('halt', \@{$msg_hash->{target}}, $session_id);
+ my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
+ }
my @out_msg_l = ($msg);
return @out_msg_l;
sub trigger_action_reboot {
- my ($msg, $msg_hash) = @_;
+ my ($msg, $msg_hash, $session_id) = @_;
$msg =~ s/<header>gosa_trigger_action_reboot<\/header>/<header>trigger_action_reboot<\/header>/;
- change_fai_state('reboot', \@{$msg_hash->{target}});
+ &main::change_fai_state('reboot', \@{$msg_hash->{target}}, $session_id);
+ my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
+ }
my @out_msg_l = ($msg);
return @out_msg_l;
sub trigger_action_memcheck {
- my ($msg, $msg_hash) = @_ ;
+ my ($msg, $msg_hash, $session_id) = @_ ;
$msg =~ s/<header>gosa_trigger_action_memcheck<\/header>/<header>trigger_action_memcheck<\/header>/;
- change_fai_state('memcheck', \@{$msg_hash->{target}});
+ &main::change_fai_state('memcheck', \@{$msg_hash->{target}}, $session_id);
+ my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
+ }
my @out_msg_l = ($msg);
return @out_msg_l;
sub trigger_action_reinstall {
- my ($msg, $msg_hash) = @_;
+ my ($msg, $msg_hash, $session_id) = @_;
$msg =~ s/<header>gosa_trigger_action_reinstall<\/header>/<header>trigger_action_reinstall<\/header>/;
- change_fai_state('reinstall', \@{$msg_hash->{target}});
+ &main::change_fai_state('reinstall', \@{$msg_hash->{target}}, $session_id);
my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
sub trigger_action_update {
- my ($msg, $msg_hash) = @_;
+ my ($msg, $msg_hash, $session_id) = @_;
$msg =~ s/<header>gosa_trigger_action_update<\/header>/<header>trigger_action_update<\/header>/;
- change_fai_state('update', \@{$msg_hash->{target}});
+ &main::change_fai_state('update', \@{$msg_hash->{target}}, $session_id);
my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
sub trigger_action_instant_update {
- my ($msg, $msg_hash) = @_;
+ my ($msg, $msg_hash, $session_id) = @_;
$msg =~ s/<header>gosa_trigger_action_instant_update<\/header>/<header>trigger_action_instant_update<\/header>/;
- change_fai_state('update', \@{$msg_hash->{target}});
+ &main::change_fai_state('update', \@{$msg_hash->{target}}, $session_id);
+
+ my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
+ }
my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
sub trigger_action_sysinfo {
- my ($msg, $msg_hash) = @_;
+ my ($msg, $msg_hash, $session_id) = @_;
$msg =~ s/<header>gosa_trigger_action_sysinfo<\/header>/<header>trigger_action_sysinfo<\/header>/;
- change_fai_state('sysinfo', \@{$msg_hash->{target}});
+ &main::change_fai_state('sysinfo', \@{$msg_hash->{target}}, $session_id);
+ my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
+ }
my @out_msg_l = ($msg);
return @out_msg_l;
sub new_key_for_client {
- my ($msg, $msg_hash) = @_;
+ my ($msg, $msg_hash, $session_id) = @_;
+
+ my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
+ }
+
$msg =~ s/<header>gosa_new_key_for_client<\/header>/<header>new_key<\/header>/;
my @out_msg_l = ($msg);
return @out_msg_l;
sub trigger_action_rescan {
- my ($msg, $msg_hash) = @_;
+ my ($msg, $msg_hash, $session_id) = @_;
+
+ my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
+ }
+
+
$msg =~ s/<header>gosa_trigger_action_rescan<\/header>/<header>trigger_action_rescan<\/header>/;
my @out_msg_l = ($msg);
return @out_msg_l;
sub trigger_action_wake {
- my ($msg, $msg_hash) = @_;
- my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
- my $out_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
- my @out_msg_l = ($out_msg);
- return @out_msg_l;
-}
+ my ($msg, $msg_hash, $session_id) = @_;
-
-sub change_fai_state {
- my ($st, $targets) = @_;
-
- # Set FAI state to localboot
- my %mapActions= (
- reboot => '',
- update => 'softupdate',
- localboot => 'localboot',
- reinstall => 'install',
- rescan => '',
- wake => '',
- memcheck => 'memcheck',
- sysinfo => 'sysinfo',
- );
-
- # Return if this is unknown
- if (!exists $mapActions{ $st }){
- return;
+ my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
}
- my $state= $mapActions{ $st };
-
- &main::refresh_ldap_handle();
- if( defined($main::ldap_handle) ) {
-
- # Build search filter for hosts
- my $search= "(&(objectClass=GOhard)";
- foreach (@{$targets}){
- $search.= "(macAddress=$_)";
- }
- $search.= ")";
-
- # If there's any host inside of the search string, procress them
- if (!($search =~ /macAddress/)){
- return;
- }
-
- # Perform search for Unit Tag
- my $mesg = $main::ldap_handle->search(
- base => $main::ldap_base,
- scope => 'sub',
- attrs => ['dn', 'FAIstate', 'objectClass'],
- filter => "$search"
- );
-
- if ($mesg->count) {
- my @entries = $mesg->entries;
- foreach my $entry (@entries) {
-
- # Only modify entry if it is not set to '$state'
- if ($entry->get_value("FAIstate") ne "$state"){
-
- &main::daemon_log("INFO: Setting FAIstate to '$state' for ".$entry->dn, 5);
- my $result;
- my %tmp = map { $_ => 1 } $entry->get_value("objectClass");
- if (exists $tmp{'FAIobject'}){
- if ($state eq ''){
- $result= $main::ldap_handle->modify($entry->dn, changes => [
- delete => [ FAIstate => [] ] ]);
- } else {
- $result= $main::ldap_handle->modify($entry->dn, changes => [
- replace => [ FAIstate => $state ] ]);
- }
- } elsif ($state ne ''){
- $result= $main::ldap_handle->modify($entry->dn, changes => [
- add => [ objectClass => 'FAIobject' ],
- add => [ FAIstate => $state ] ]);
- }
- # Errors?
- if ($result->code){
- &main::daemon_log("Error: Setting FAIstate to '$state' for ".$entry->dn. "failed: ".$result->error, 1);
- }
-
- }
- }
- }
- }
+ my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
+ my $out_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
+ my @out_msg_l = ($out_msg);
+ return @out_msg_l;
}
-sub change_goto_state {
- my ($st, $targets) = @_;
-
- # Switch on or off?
- my $state= $st eq 'active' ? 'active': 'locked';
-
- &main::refresh_ldap_handle();
- if( defined($main::ldap_handle) ) {
-
- # Build search filter for hosts
- my $search= "(&(objectClass=GOhard)";
- foreach (@{$targets}){
- $search.= "(macAddress=$_)";
- }
- $search.= ")";
-
- # If there's any host inside of the search string, procress them
- if (!($search =~ /macAddress/)){
- return;
- }
-
- # Perform search for Unit Tag
- my $mesg = $main::ldap_handle->search(
- base => $main::ldap_base,
- scope => 'sub',
- attrs => ['dn', 'gotoMode'],
- filter => "$search"
- );
-
- if ($mesg->count) {
- my @entries = $mesg->entries;
- foreach my $entry (@entries) {
-
- # Only modify entry if it is not set to '$state'
- if ($entry->get_value("gotoMode") ne $state){
-
- &main::daemon_log("INFO: Setting gotoMode to '$state' for ".$entry->dn, 5);
- my $result;
- $result= $main::ldap_handle->modify($entry->dn, changes => [
- replace => [ gotoMode => $state ] ]);
-
- # Errors?
- if ($result->code){
- &main::daemon_log("Error: Setting gotoMode to '$state' for ".$entry->dn. "failed: ".$result->error, 1);
- }
-
- }
- }
- }
-
- }
-}
1;