From: rettenbe Date: Mon, 25 Feb 2008 14:36:21 +0000 (+0000) Subject: new functions: get_client_for_login_usr and get_login_usr_for_client in gosaTriggered.pm X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ea9da8009fef988bf4acd1d4010af96c766001b3;p=gosa.git new functions: get_client_for_login_usr and get_login_usr_for_client in gosaTriggered.pm mv function db_res_2_xml from GosaPackages.pm to db_res2xml in GosaSupportDaemon.pm git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9110 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/modules/DBsqlite.pm b/gosa-si/modules/DBsqlite.pm index d4297aac1..cde297823 100644 --- a/gosa-si/modules/DBsqlite.pm +++ b/gosa-si/modules/DBsqlite.pm @@ -272,4 +272,7 @@ sub count_dbentries { return $count; } + + + 1; diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index 9161c2c80..b71485cfc 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -401,33 +401,6 @@ sub process_job_msg { } -sub db_res_2_xml { - my ($db_res) = @_ ; - my $xml = "
answer
$server_addressGOSA"; - - my $len_db_res= keys %{$db_res}; - for( my $i= 1; $i<= $len_db_res; $i++ ) { - $xml .= "\n"; - my $hash= $db_res->{$i}; - while ( my ($column_name, $column_value) = each %{$hash} ) { - $xml .= "<$column_name>"; - my $xml_content; - if( $column_name eq "xmlmessage" ) { - $xml_content = &encode_base64($column_value); - } else { - $xml_content = $column_value; - } - $xml .= $xml_content; - $xml .= ""; - } - $xml .= ""; - - } - - $xml .= "
"; - return $xml; -} - ## CORE FUNCTIONS ############################################################ @@ -445,7 +418,7 @@ sub query_jobdb { # execute db query my $res_hash = $main::job_db->select_dbentry($sql_statement); - my $out_xml = &db_res_2_xml($res_hash); + my $out_xml = &db_res2xml($res_hash); my @out_msg_l = ( $out_xml ); return @out_msg_l; } diff --git a/gosa-si/modules/GosaSupportDaemon.pm b/gosa-si/modules/GosaSupportDaemon.pm index bcf0176da..6fecf1bb3 100644 --- a/gosa-si/modules/GosaSupportDaemon.pm +++ b/gosa-si/modules/GosaSupportDaemon.pm @@ -10,6 +10,7 @@ my @functions = ( "transform_msg2hash", "get_time", "build_msg", + "db_res2xml", "get_where_statement", "get_select_statement", "get_update_statement", @@ -276,6 +277,33 @@ sub build_msg ($$$$) { } +sub db_res2xml { + my ($db_res) = @_ ; + my $xml = ""; + + my $len_db_res= keys %{$db_res}; + for( my $i= 1; $i<= $len_db_res; $i++ ) { + $xml .= ""; + my $hash= $db_res->{$i}; + while ( my ($column_name, $column_value) = each %{$hash} ) { + $xml .= "<$column_name>"; + my $xml_content; + if( $column_name eq "xmlmessage" ) { + $xml_content = &encode_base64($column_value); + } else { + $xml_content = $column_value; + } + $xml .= $xml_content; + $xml .= ""; + } + $xml .= ""; + + } + + return $xml; +} + + sub get_where_statement { my ($msg, $msg_hash) = @_; my $error= 0; diff --git a/gosa-si/server/events/gosaTriggered.pm b/gosa-si/server/events/gosaTriggered.pm index 100a75f8a..ae10c2547 100644 --- a/gosa-si/server/events/gosaTriggered.pm +++ b/gosa-si/server/events/gosaTriggered.pm @@ -3,6 +3,8 @@ use Exporter; @ISA = qw(Exporter); my @events = ( "get_events", + "get_login_usr_for_client", + "get_client_for_login_usr", "gen_smb_hash", "trigger_reload_ldap_config", "ping", @@ -10,6 +12,8 @@ my @events = ( "set_activated_for_installation", "new_key_for_client", "detect_hardware", + "get_login_usr", + "get_login_client", "trigger_action_localboot", "trigger_action_faireboot", "trigger_action_reboot", @@ -27,6 +31,7 @@ my @events = ( use strict; use warnings; use GOSA::GosaSupportDaemon; +use Data::Dumper; use Crypt::SmbHash; use Net::ARP; use Net::Ping; @@ -46,6 +51,46 @@ sub get_events { } +sub get_login_usr_for_client { + 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 $client = @{$msg_hash->{'client'}}[0]; + + $header =~ s/^gosa_//; + + my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$client' OR macaddress='$client'"; + my $res = $main::known_clients_db->select_dbentry($sql_statement); + + my $out_msg = "
$header
$target$source"; + $out_msg .= &db_res2xml($res); + $out_msg .= "
"; + + my @out_msg_l = ( $out_msg ); + return @out_msg_l; +} + + +sub get_client_for_login_usr { + 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 $usr = @{$msg_hash->{'usr'}}[0]; + + my $sql_statement = "SELECT * FROM known_clients WHERE login LIKE '%$usr%'"; + my $res = $main::known_clients_db->select_dbentry($sql_statement); + + my $out_msg = "
$header
$target$source"; + $out_msg .= &db_res2xml($res); + $out_msg .= "
"; + my @out_msg_l = ( $out_msg ); + return @out_msg_l; + +} + + sub ping { my ($msg, $msg_hash, $session_id) = @_ ; my $source = @{$msg_hash->{source}}[0]; diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index debee10d9..5fbe5f314 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -53,7 +53,7 @@ if($sock->connected()){ #$data = "
gosa_detect_hardware
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_trigger_action_wake
00:01:6c:9d:b9:fa 10.89.1.31:20081
"; -$data = "
gosa_trigger_action_faireboot
00:01:6c:9d:b9:fa GOSA
"; +#$data = "
gosa_trigger_action_faireboot
00:01:6c:9d:b9:fa GOSA
"; #$data = "
job_trigger_action_reinstall
GOSA 00:01:6c:9d:b9:fa 00:01:6c:9d:b9:fa 20130101000000
"; #$data = "
gosa_ping
00:01:6c:9d:b9:fa GOSA
"; @@ -73,7 +73,11 @@ $data = "
gosa_trigger_action_faireboot
00:01:6c:9 # "trigger_action_rescan", # "trigger_action_wake", +# get_login_usr_for_client +$data = "
gosa_get_login_usr_for_client
GOSA GOSA 00:01:6c:9d:b9:fa
"; +# get_client_for_login_usr +$data = "
gosa_get_client_for_login_usr
GOSA GOSA harald
";