summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7bebde3)
raw | patch | inline | side by side (parent: 7bebde3)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 4 Mar 2008 18:16:48 +0000 (18:16 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 4 Mar 2008 18:16:48 +0000 (18:16 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9328 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-si/client/events/corefunctions.pm | patch | blob | history | |
gosa-si/gosa-si-client | patch | blob | history | |
gosa-si/server/events/clMessages.pm | patch | blob | history |
index 6651fcf5d69570b303b4c8754d929b7c0bcd46f6..892a561f04b335d7daeadf39426958ea658de474 100644 (file)
if( $header eq "registered" ) {
my $source = @{$msg_hash->{'source'}}[0];
&main::daemon_log("registration at $source",1);
+ $main::server_address = $source;
}
# set globaly variable client_address
unlink($main::opts_file);
}
- &main::daemon_log(Dumper($msg_hash),1);
my $opts_file_FH;
my $hostname= $main::client_dnsname;
$hostname =~ s/\..*$//;
diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client
index abda025bdbc8b80370cec7278cb3dd8e4929500e..4e48451073feb9254a50962b422e89e4c502fa67 100755 (executable)
--- a/gosa-si/gosa-si-client
+++ b/gosa-si/gosa-si-client
my $delay_set_time = 5;
our $prg= basename($0);
+# all x seconds the client reports logged_in users to gosa-si-server
+my $trigger_logged_in_users_report_delay = 600;
+
%cfg_defaults = (
"general" =>
{"log-file" => [\$log_file, "/var/run/".$prg.".log"],
&send_msg_to_target($msg, $client_address, $server_key, 'new_key');
$kernel->delay_set('trigger_new_key', $server_key_lifetime);
+}
+
+
+sub trigger_logged_in_users_report {
+ my ($kernel) = $_[KERNEL] ;
+ # just do if client is registered already
+ if( $REGISTERED ) {
+ my $result = qx(/usr/bin/w -hs);
+ my @res_lines;
+
+ if( defined $result ) {
+ chomp($result);
+ @res_lines = split("\n", $result);
+ }
+
+ my @logged_in_user_list;
+ foreach my $line (@res_lines) {
+ chomp($line);
+ my @line_parts = split(/\s+/, $line);
+ push(@logged_in_user_list, $line_parts[0]);
+ }
+ system("echo 'CURRENTLY_LOGGED_IN ".join(" ", @logged_in_user_list)."' > /var/run/gosa-si-client.socket");
+ $kernel->delay_set('trigger_logged_in_users_report', $trigger_logged_in_users_report_delay);
+ } else {
+ # try it in 1 sec again
+ $kernel->delay_set('trigger_logged_in_users_report', 1);
+ }
}
my $clmsg_hash = &create_xml_hash("CLMSG_$header", $client_address, $server_address, $content);
&add_content2xml_hash($clmsg_hash, "macaddress", $client_mac_address);
my $clmsg = &create_xml_string($clmsg_hash);
- &send_msg_to_target($clmsg, $server_address, $server_key);
+ &send_msg_to_target($clmsg, $server_address, $server_key, "CLMSG_$header");
return;
}
$heap->{services}->{ $file_watcher->ID } = $file_name;
$heap->{watchers}->{ $file_watcher->ID } = $file_watcher;
}
+ $kernel->yield('trigger_logged_in_users_report');
+}
+
+
+sub _default {
+ daemon_log("ERROR: can not handle incoming msg with header '$_[ARG0]'", 1);
+ return;
}
POE::Session->create(
inline_states => {
_start => \&_start,
+ _default => \&_default,
register_at_gosa_si_server => \®ister_at_gosa_si_server,
+
+ # trigger periodical tasks
trigger_new_key => \&trigger_new_key,
+ trigger_logged_in_users_report => \&trigger_logged_in_users_report,
# handle records from each defined file differently
fifo_record => \&fifo_got_record,
index a7487a3e1fb3e6d7550015a68daf810456a90ae8..088ce5ab7964c339ac0baa69a62cdfe99c84a7bb 100644 (file)
"GOTOACTIVATION",
"LOGIN",
"LOGOUT",
+ "CURRENTLY_LOGGED_IN",
);
@EXPORT = @events;
client=>$source,
user=>$login,
timestamp=>&get_time,
- );
+ );
my ($res, $error_str) = $main::login_users_db->add_dbentry( \%add_hash );
if ($res != 0) {
&main::daemon_log("ERROR: cannot add entry to known_clients: $error_str");
return;
}
-
+# TODO umstellen wie bei LOGIN
sub LOGOUT {
my ($msg, $msg_hash, $session_id) = @_;
my $header = @{$msg_hash->{'header'}}[0];
if( $act_login eq "" ){ $act_login = "nobody"; }
- $sql_statement = "UPDATE known_clients ".
- "SET login='$act_login' ".
- "WHERE hostname='$source'";
+ $sql_statement = "UPDATE known_clients SET login='$act_login' WHERE hostname='$source'";
$res = $main::known_clients_db->update_dbentry($sql_statement);
return;
}
+sub CURRENTLY_LOGGED_IN {
+ my ($msg, $msg_hash, $session_id) = @_;
+ my ($sql_statement, $db_res);
+ my $header = @{$msg_hash->{'header'}}[0];
+ my $source = @{$msg_hash->{'source'}}[0];
+ my $login = @{$msg_hash->{$header}}[0];
+
+ $sql_statement = "SELECT * FROM $main::login_users_tn WHERE client='$source'";
+ $db_res = $main::login_users_db->select_dbentry($sql_statement);
+ my %currently_logged_in_user = ();
+ while( my($hit_id, $hit) = each(%{$db_res}) ) {
+ $currently_logged_in_user{$hit->{'user'}} = 1;
+ }
+ &main::daemon_log("DEBUG: logged in users from login_user_db: ".join(", ", keys(%currently_logged_in_user)), 7);
+
+ my @logged_in_user = split(/\s+/, $login);
+ &main::daemon_log("DEBUG: logged in users reported from client: ".join(", ", @logged_in_user), 7);
+ foreach my $user (@logged_in_user) {
+ my %add_hash = ( table=>$main::login_users_tn,
+ primkey=> ['client', 'user'],
+ client=>$source,
+ user=>$user,
+ timestamp=>&get_time,
+ );
+ my ($res, $error_str) = $main::login_users_db->add_dbentry( \%add_hash );
+ if ($res != 0) {
+ &main::daemon_log("ERROR: cannot add entry to known_clients: $error_str");
+ return;
+ }
+
+ delete $currently_logged_in_user{$user};
+ }
+
+ # if there is still a user in %currently_logged_in_user
+ # although he is not reported by client
+ # then delete it from $login_user_db
+ foreach my $obsolete_user (keys(%currently_logged_in_user)) {
+ &main::daemon_log("WARNING: user '$obsolete_user' is currently not logged ".
+ "in at client '$source' but still found at login_user_db", 3);
+ my $sql_statement = "DELETE FROM $main::login_users_tn WHERE client='$source' AND user='$obsolete_user'";
+ my $res = $main::login_users_db->del_dbentry($sql_statement);
+ &main::daemon_log("WARNING: delete user '$obsolete_user' at client '$source' from login_user_db", 3);
+ }
+
+ return;
+}
+
+
sub GOTOACTIVATION {
my ($msg, $msg_hash, $session_id) = @_;
my $out_msg = &build_result_update_msg($msg_hash);