From: rettenbe Date: Tue, 26 Feb 2008 14:12:36 +0000 (+0000) Subject: seperate 'login' column at known_clients into a own sqlite-db X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=49eb1ed27268cfe00ebf84de42762f16d8b64393;p=gosa.git seperate 'login' column at known_clients into a own sqlite-db git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9128 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client index 9838f476e..ffdae1f57 100755 --- a/gosa-si/gosa-si-client +++ b/gosa-si/gosa-si-client @@ -686,7 +686,7 @@ sub register_at_gosa_si_server { # create new passwd and ciphering object for client-server communication $server_key = &create_passwd(); - my $events = join( ", ", keys %{$event_hash} ); + my $events = join( ",", keys %{$event_hash} ); while(1) { if( $try_to_register >= @servers ) { @@ -727,9 +727,10 @@ sub register_at_gosa_si_server { # reset try_to_register $try_to_register = 0; - # Set fixed client address + # Set fixed client address and mac address $client_ip= &get_local_ip_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/)); $client_address= "$client_ip:$client_port"; + $client_mac_address = $local_mac; # Write the MAC address to file if(stat($opts_file)) { @@ -758,7 +759,7 @@ sub register_at_gosa_si_server { $kernel->delay_set('register_at_gosa_si_server', $delay_set_time); } else { - daemon_log("waiting for msg 'register_at_gosa_si_server'",1); + daemon_log("INFO: waiting for msg 'register_at_gosa_si_server'",5); $kernel->delay_set('register_at_gosa_si_server', $delay_set_time); # clear old settings and set it again $kernel->delay_set('trigger_new_key', $server_key_lifetime); diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 4086f6b24..f9203baaa 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -51,8 +51,8 @@ use lib "/usr/lib/gosa-si/modules"; my (%cfg_defaults, $foreground, $verbose, $ping_timeout); my ($bus_activ, $bus, $msg_to_bus, $bus_cipher); my ($server, $server_mac_address); -my ($gosa_server, $job_queue_timeout, $job_queue_table_name, $job_queue_file_name,$job_queue_loop_delay); -my ($known_modules, $known_clients_file_name, $known_server_file_name); +my ($gosa_server, $job_queue_timeout, $job_queue_loop_delay); +my ($known_modules); my ($pid_file, $procid, $pid, $log_file); my ($arp_activ, $arp_fifo); my ($xml); @@ -88,16 +88,27 @@ $bus_activ = "true"; $no_arp = 0; +our $prg= basename($0); + # holds all gosa jobs +my $job_queue_file_name; our $job_db; -our $job_queue_table_name = 'jobs'; +our $job_queue_tn = 'jobs'; # holds all other gosa-sd as well as the gosa-sd-bus +my $known_server_file_name; our $known_server_db; +our $known_server_tn = "known_server"; # holds all registrated clients +my $known_clients_file_name; our $known_clients_db; -our $prg= basename($0); +our $known_clients_tn = "known_clients"; + +# holds all logged in user at each client +my $login_users_file_name; +our $login_users_db; +our $login_users_tn = "login_users"; %cfg_defaults = ( "general" => { @@ -112,6 +123,7 @@ our $prg= basename($0); "port" => [\$server_port, "20081"], "known-clients" => [\$known_clients_file_name, '/var/lib/gosa-si/clients.db' ], "known-servers" => [\$known_server_file_name, '/var/lib/gosa-si/servers.db'], + "login-users" => [\$login_users_file_name, '/var/lib/gosa-si/users.db'], "gosa-unit-tag" => [\$gosa_unit_tag, ""], }, "GOsaPackages" => { @@ -1052,7 +1064,7 @@ sub watch_for_new_jobs { # check gosa job queue for jobs with executable timestamp my $timestamp = &get_time(); - my $sql_statement = "SELECT * FROM ".$job_queue_table_name. + my $sql_statement = "SELECT * FROM ".$job_queue_tn. " WHERE status='waiting' AND timestamp<'$timestamp'"; my $res = $job_db->select_dbentry( $sql_statement ); @@ -1069,7 +1081,7 @@ sub watch_for_new_jobs { if (not defined $target) { &daemon_log("ERROR: no host found for mac address: $macaddress", 1); &daemon_log("$hit->{xmlmessage}", 8); - my $sql_statement = "UPDATE $job_queue_table_name ". + my $sql_statement = "UPDATE $job_queue_tn ". "SET status='error', result='no host found for mac address' ". "WHERE id='$jobdb_id'"; my $res = $job_db->update_dbentry($sql_statement); @@ -1151,7 +1163,7 @@ $job_db = GOSA::DBsqlite->new($job_queue_file_name); $job_db->create_table('jobs', \@job_col_names); # connect to known_clients_db -my @clients_col_names = ('hostname', 'status', 'hostkey', 'timestamp', 'macaddress', 'events', 'login'); +my @clients_col_names = ('hostname', 'status', 'hostkey', 'timestamp', 'macaddress', 'events'); $known_clients_db = GOSA::DBsqlite->new($known_clients_file_name); $known_clients_db->create_table('known_clients', \@clients_col_names); @@ -1160,6 +1172,11 @@ my @server_col_names = ('hostname', 'status', 'hostkey', 'timestamp'); $known_server_db = GOSA::DBsqlite->new($known_server_file_name); $known_server_db->create_table('known_server', \@server_col_names); +# connect to login_usr_db +my @login_users_col_names = ('client', 'user', 'timestamp'); +$login_users_db = GOSA::DBsqlite->new($login_users_file_name); +$login_users_db->create_table("login_users", \@login_users_col_names); + # create xml object used for en/decrypting $xml = new XML::Simple(); diff --git a/gosa-si/modules/DBsqlite.pm b/gosa-si/modules/DBsqlite.pm index cde297823..78592fff7 100644 --- a/gosa-si/modules/DBsqlite.pm +++ b/gosa-si/modules/DBsqlite.pm @@ -100,35 +100,46 @@ sub add_dbentry { # specify primary key in table if (not exists $arg->{primkey}) { - return 2; + return (2, "a hash key 'primkey' with at least an empty list as value is necessary for add_dbentry"); } - my $primkey = $arg->{primkey}; - - # if primkey is id, fetch max id from table and give new job id= max(id)+1 - if ($primkey eq 'id') { - my $id; - my $sql_statement = "SELECT MAX(CAST(id AS INTEGER)) FROM $table"; - &create_lock($self,'add_dbentry'); - my $max_id = @{ @{ $self->{dbh}->selectall_arrayref($sql_statement) }[0] }[0]; - &remove_lock($self,'add_dbentry'); - if( defined $max_id) { - $id = $max_id + 1; - } else { - $id = 1; + my $primkeys = $arg->{'primkey'}; + my $prim_statement; + if( 0 != length(@$primkeys) ) { + my @prim_list; + foreach my $primkey (@$primkeys) { + if($primkey eq 'id') { + # if primkey is id, fetch max id from table and give new job id= max(id)+1 + my $sql_statement = "SELECT MAX(CAST(id AS INTEGER)) FROM $table"; + &create_lock($self,'add_dbentry'); + my $max_id = @{ @{ $self->{dbh}->selectall_arrayref($sql_statement) }[0] }[0]; + &remove_lock($self,'add_dbentry'); + my $id; + if( defined $max_id) { + $id = $max_id + 1; + } else { + $id = 1; + } + $arg->{id} = $id; + } + if( not exists $arg->{$primkey} ) { + return (3, "primkey '$primkey' has no value for add_dbentry"); + } + push(@prim_list, "$primkey='".$arg->{$primkey}."'"); } - $arg->{id} = $id; + $prim_statement = "WHERE ".join(" AND ", @prim_list); } - + # if timestamp is not provided, add timestamp if( not exists $arg->{timestamp} ) { $arg->{timestamp} = &get_time; } # check wether primkey is unique in table, otherwise return errorflag - my $sql_statement = "SELECT * FROM $table WHERE $primkey='$arg->{$primkey}'"; + my $sql_statement = "SELECT * FROM $table $prim_statement"; &create_lock($self,'add_dbentry'); my $res = @{ $self->{dbh}->selectall_arrayref($sql_statement) }; &remove_lock($self,'add_dbentry'); + if ($res == 0) { # primekey is unique @@ -139,7 +150,6 @@ sub add_dbentry { my @add_list; foreach my $col_name (@{$col_names}) { # use function parameter for column values - if (exists $arg->{$col_name}) { push(@add_list, $arg->{$col_name}); } @@ -150,13 +160,11 @@ sub add_dbentry { my $db_res = $self->{dbh}->do($sql_statement); &remove_lock($self,'add_dbentry'); if( $db_res != 1 ) { - return 4; + return (4, $sql_statement); } } else { # entry already exists, so update it - my $where_str= " WHERE $primkey='".$arg->{$primkey}."'"; - my @update_l; while( my ($pram, $val) = each %{$arg} ) { if( $pram eq 'table' ) { next; } @@ -166,7 +174,7 @@ sub add_dbentry { my $update_str= join(", ", @update_l); $update_str= " SET $update_str"; - my $sql_statement= "UPDATE $table $update_str $where_str"; + my $sql_statement= "UPDATE $table $update_str $prim_statement"; my $db_res = &update_dbentry($self, $sql_statement ); } diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index 18879d691..747f93a95 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -281,7 +281,7 @@ sub process_incoming_msg { # keep job queue up-to-date and save result and status if (defined ($out_msg) && $out_msg =~ /(\d+)<\/jobdb_id>/) { my $job_id = $1; - my $sql = "UPDATE '".$main::job_queue_table_name."'". + my $sql = "UPDATE '".$main::job_queue_tn."'". " SET status='processing'". " WHERE id='$job_id'"; my $res = $main::job_db->exec_statement($sql); @@ -375,8 +375,8 @@ sub process_job_msg { if( $error == 0 ) { # add job to job queue - my $func_dic = {table=>$main::job_queue_table_name, - primkey=>'id', + my $func_dic = {table=>$main::job_queue_tn, + primkey=>['id'], timestamp=>$timestamp, status=>'waiting', result=>'none', @@ -432,7 +432,7 @@ sub count_jobdb { my $out_xml= "error"; # prepare query sql statement - my $table= $main::job_queue_table_name; + my $table= $main::job_queue_tn; my $sql_statement= "SELECT * FROM $table "; # execute db query @@ -450,7 +450,7 @@ sub delete_jobdb_entry { my $msg_hash = &transform_msg2hash($msg); # prepare query sql statement - my $table= $main::job_queue_table_name; + my $table= $main::job_queue_tn; my $where= &get_where_statement($msg, $msg_hash); my $sql_statement = "DELETE FROM $table $where"; @@ -478,7 +478,7 @@ sub clear_jobdb { my $error= 0; my $out_xml= "1"; - my $table= $main::job_queue_table_name; + my $table= $main::job_queue_tn; my $sql_statement = "DELETE FROM $table"; my $db_res = $main::job_db->del_dbentry($sql_statement); @@ -503,7 +503,7 @@ sub update_status_jobdb_entry { # prepare query sql statement if( $error == 0) { - my $table= $main::job_queue_table_name; + my $table= $main::job_queue_tn; my $where= &get_where_statement($msg, $msg_hash); my $update= &get_update_statement($msg, $msg_hash); diff --git a/gosa-si/modules/SIPackages.pm b/gosa-si/modules/SIPackages.pm index 492b109a0..d85d0b05d 100644 --- a/gosa-si/modules/SIPackages.pm +++ b/gosa-si/modules/SIPackages.pm @@ -163,7 +163,7 @@ if($bus_activ eq "on") { # add myself to known_server_db my $res = $main::known_server_db->add_dbentry( {table=>'known_server', - primkey=>'hostname', + primkey=>['hostname'], hostname=>$server_address, status=>'myself', hostkey=>$SIPackages_key, @@ -338,7 +338,7 @@ sub register_at_bus { # add bus to known_server_db my $res = $main::known_server_db->add_dbentry( {table=>'known_server', - primkey=>'hostname', + primkey=>['hostname'], hostname=>$bus_address, status=>'bus', hostkey=>$bus_key, @@ -547,14 +547,13 @@ sub here_i_am { # add entry to known_clients_db my $act_timestamp = &get_time; my $res = $main::known_clients_db->add_dbentry( {table=>'known_clients', - primkey=>'hostname', + primkey=>['hostname'], hostname=>$source, events=>$events, macaddress=>$mac_address, status=>'registered', hostkey=>$new_passwd, timestamp=>$act_timestamp, - login=>"nobody", } ); if ($res != 0) { diff --git a/gosa-si/server/events/clMessages.pm b/gosa-si/server/events/clMessages.pm index 686c9a041..62a3a50ae 100644 --- a/gosa-si/server/events/clMessages.pm +++ b/gosa-si/server/events/clMessages.pm @@ -62,31 +62,18 @@ sub LOGIN { my $source = @{$msg_hash->{'source'}}[0]; my $login = @{$msg_hash->{$header}}[0]; - my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$source'"; - my $res = $main::known_clients_db->select_dbentry($sql_statement); - if( 1 != keys(%$res) ) { - &main::daemon_log("DEBUG: clMessages.pm: LOGIN: no or more hits found in known_clients_db for host '$source'"); + my %add_hash = ( table=>$main::login_users_tn, + primkey=> ['client', 'user'], + 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; } - my $act_login = $res->{'1'}->{'login'}; - if( $act_login eq "nobody" ) { - $act_login = ""; - } - - $act_login =~ s/$login,?//gi; - my @act_login = split(",", $act_login); - unshift(@act_login, $login); - $act_login = join(",", @act_login); - -#print STDERR "source: $source\n"; -#print STDERR "login: $login\n"; -#print STDERR "act_login: $act_login\n"; -#print STDERR "dbres: ".Dumper($res)."\n"; - $sql_statement = "UPDATE known_clients ". - "SET login='$act_login' ". - "WHERE hostname='$source'"; - $res = $main::known_clients_db->update_dbentry($sql_statement); return; } diff --git a/gosa-si/server/events/gosaTriggered.pm b/gosa-si/server/events/gosaTriggered.pm index 717928154..f8185db75 100644 --- a/gosa-si/server/events/gosaTriggered.pm +++ b/gosa-si/server/events/gosaTriggered.pm @@ -78,6 +78,7 @@ sub get_client_for_login_usr { my $source = @{$msg_hash->{'source'}}[0]; my $target = @{$msg_hash->{'target'}}[0]; my $usr = @{$msg_hash->{'usr'}}[0]; + $header =~ s/^gosa_//; my $sql_statement = "SELECT * FROM known_clients WHERE login LIKE '%$usr%'"; my $res = $main::known_clients_db->select_dbentry($sql_statement); diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index 5fbe5f314..d3ada5c74 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -31,13 +31,13 @@ if($sock->connected()){ # jobdb update #$data = "
gosa_update_status_jobdb_entry
GOSAGOSA 00:01:6c:9d:b9:fa 23450101000000XXXXXXXXXXXXXXx
"; -#$data = "
gosa_update_status_jobdb_entry
GOSAGOSA waiting processing update
"; +$data = "
gosa_update_status_jobdb_entry
GOSAGOSA waiting processing update
"; # jobdb query #$data = "
gosa_query_jobdb
andgt0le5
"; #$data= "
gosa_query_jobdb
ping03
"; -#$data= "
gosa_query_jobdb
ping05timestamp
"; -#$data= "
gosa_query_jobdb
"; +#$data= "
gosa_query_jobdb
GOSA GOSAtrigger_action_reinstall025timestamp DESC
"; +#$data= "
gosa_query_jobdb
GOSA GOSA
"; # jobdb count #$data = "
gosa_count_jobdb
"; @@ -74,10 +74,10 @@ if($sock->connected()){ # "trigger_action_wake", # get_login_usr_for_client -$data = "
gosa_get_login_usr_for_client
GOSA GOSA 00:01:6c:9d:b9:fa
"; +#$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
"; +#$data = "
gosa_get_client_for_login_usr
GOSA GOSA harald
";