Code

seperate 'login' column at known_clients into a own sqlite-db
authorrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 26 Feb 2008 14:12:36 +0000 (14:12 +0000)
committerrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 26 Feb 2008 14:12:36 +0000 (14:12 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9128 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-si/gosa-si-client
gosa-si/gosa-si-server
gosa-si/modules/DBsqlite.pm
gosa-si/modules/GosaPackages.pm
gosa-si/modules/SIPackages.pm
gosa-si/server/events/clMessages.pm
gosa-si/server/events/gosaTriggered.pm
gosa-si/tests/client.php

index 9838f476eafb7132a4b57112fe5273309be86d85..ffdae1f57f93d93a8507227aa840b34f9afec015 100755 (executable)
@@ -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);
index 4086f6b247210ebbe57763c92e5752d2dcf2a431..f9203baaa1dd9d48ecf0bf3e1fb5e40a6ab2030c 100755 (executable)
@@ -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();
 
index cde2978231a52f3a18b92169d70dc86305d4e11d..78592fff7629763f99298c51f0ff778a450c5039 100644 (file)
@@ -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 );
 
     }
index 18879d691480d3e77f58dab54e3a148c4750b14b..747f93a955da077c1e4ec95ad8a529a3fb3b0115 100644 (file)
@@ -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 =~ /<jobdb_id>(\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= "<xml><count>error</count></xml>";
 
     # 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= "<xml><answer1>1</answer1></xml>";
  
-    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);
 
index 492b109a006bb5294b4c51e0050bf481fe1fc573..d85d0b05d849645fd454b0ba3cad6cda93c9e12a 100644 (file)
@@ -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)  {
index 686c9a0419ac72470d8e5ee1a0810c76abc40b99..62a3a50aeecb6525f826480af4f0db0e4e8645f0 100644 (file)
@@ -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;   
 }
 
index 717928154a53f3e61e11bdb2aaf552f332721f3e..f8185db75b21e7a4af1eb4130714086b55681b0f 100644 (file)
@@ -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);
index 5fbe5f3148e4ecb84fb38bae4c842f2aaa09eb1f..d3ada5c74da18d5a7b34c571b9db03d380f0d7cc 100755 (executable)
@@ -31,13 +31,13 @@ if($sock->connected()){
 
 # jobdb update  
 #$data = "<xml> <header>gosa_update_status_jobdb_entry</header> <source>GOSA</source><target>GOSA</target><where><clause><phrase> <macaddress>00:01:6c:9d:b9:fa</macaddress></phrase></clause> </where> <update><timestamp>23450101000000</timestamp><result>XXXXXXXXXXXXXXx</result></update></xml>";
-#$data = "<xml> <header>gosa_update_status_jobdb_entry</header> <source>GOSA</source><target>GOSA</target><where><clause><phrase> <status>waiting</status></phrase></clause> </where> <update><status>processing</status> <result>update</result></update></xml>";
+$data = "<xml> <header>gosa_update_status_jobdb_entry</header> <source>GOSA</source><target>GOSA</target><where><clause><phrase> <status>waiting</status></phrase></clause> </where> <update><status>processing</status> <result>update</result></update></xml>";
 
 # jobdb query
 #$data = "<xml><header>gosa_query_jobdb</header><where><clause><connector>and</connector><phrase><operator>gt</operator><ROWID>0</ROWID></phrase><phrase><operator>le</operator><ROWID>5</ROWID></phrase></clause></where></xml>";
 #$data= "<xml><header>gosa_query_jobdb</header><where><clause><phrase><headertag>ping</headertag></phrase></clause></where><limit><from>0</from><to>3</to></limit></xml>";
-#$data= "<xml><header>gosa_query_jobdb</header><where><clause><phrase><headertag>ping</headertag></phrase></clause></where><limit><from>0</from><to>5</to></limit><orderby>timestamp</orderby></xml>";
-#$data= "<xml><header>gosa_query_jobdb</header></xml>";
+#$data= "<xml><header>gosa_query_jobdb</header><source>GOSA</source> <target>GOSA</target><where><clause><phrase><HEADERTAG>trigger_action_reinstall</HEADERTAG></phrase></clause></where><limit><from>0</from><to>25</to></limit><orderby>timestamp DESC</orderby></xml>";
+#$data= "<xml><header>gosa_query_jobdb</header><source>GOSA</source> <target>GOSA</target></xml>";
 
 # jobdb count
 #$data = "<xml> <header>gosa_count_jobdb</header></xml>";
@@ -74,10 +74,10 @@ if($sock->connected()){
 #    "trigger_action_wake",
 
 # get_login_usr_for_client
-$data = "<xml> <header>gosa_get_login_usr_for_client</header> <target>GOSA</target> <source>GOSA</source> <client>00:01:6c:9d:b9:fa</client></xml>";
+#$data = "<xml> <header>gosa_get_login_usr_for_client</header> <target>GOSA</target> <source>GOSA</source> <client>00:01:6c:9d:b9:fa</client></xml>";
 
 # get_client_for_login_usr
-$data = "<xml> <header>gosa_get_client_for_login_usr</header> <target>GOSA</target> <source>GOSA</source> <usr>harald</usr></xml>";
+#$data = "<xml> <header>gosa_get_client_for_login_usr</header> <target>GOSA</target> <source>GOSA</source> <usr>harald</usr></xml>";