Code

a little bit more of messaging handling
authorrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 17 Apr 2008 15:21:36 +0000 (15:21 +0000)
committerrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 17 Apr 2008 15:21:36 +0000 (15:21 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10545 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-si/gosa-si-server
gosa-si/server/events/gosaTriggered.pm
gosa-si/tests/client.php

index b70ec8430ed2214638cb9570b85dbd4116db05c6..fce69ae0b419ea4a2c78cf35e37e6d21cdb3b89e 100755 (executable)
@@ -131,43 +131,44 @@ my @job_queue_col_names = ("id INTEGER PRIMARY KEY",
 our $known_server_db;
 our $known_server_tn = "known_server";
 my $known_server_file_name;
-my @known_server_col_names = ('hostname', 'status', 'hostkey', 'timestamp');
+my @known_server_col_names = ("hostname", "status", "hostkey", "timestamp");
 
 # holds all registrated clients
 our $known_clients_db;
 our $known_clients_tn = "known_clients";
 my $known_clients_file_name;
-my @known_clients_col_names = ('hostname', 'status', 'hostkey', 'timestamp', 'macaddress', 'events');
+my @known_clients_col_names = ("hostname", "status", "hostkey", "timestamp", "macaddress", "events");
 
 # holds all logged in user at each client 
 our $login_users_db;
 our $login_users_tn = "login_users";
 my $login_users_file_name;
-my @login_users_col_names = ('client', 'user', 'timestamp');
+my @login_users_col_names = ("client", "user", "timestamp");
 
 # holds all fai server, the debian release and tag
 our $fai_server_db;
 our $fai_server_tn = "fai_server"; 
 my $fai_server_file_name;
-our @fai_server_col_names = ('timestamp', 'server', 'release', 'sections', 'tag'); 
+our @fai_server_col_names = ("timestamp", "server", "release", "sections", "tag"); 
 
 our $fai_release_db;
 our $fai_release_tn = "fai_release"; 
 my $fai_release_file_name;
-our @fai_release_col_names = ('timestamp', 'release', 'class', 'type', 'state'); 
+our @fai_release_col_names = ("timestamp", "release", "class", "type", "state"); 
 
 # holds all packages available from different repositories
 our $packages_list_db;
 our $packages_list_tn = "packages_list";
 my $packages_list_file_name;
-our @packages_list_col_names = ('distribution', 'package', 'version', 'section', 'description', 'template', 'timestamp');
+our @packages_list_col_names = ("distribution", "package", "version", "section", "description", "template", "timestamp");
 my $outdir = "/tmp/packages_list_db";
 my $arch = "i386"; 
 
 # holds all messages which should be delivered to a user
 our $messaging_db;
 our $messaging_tn = "messaging"; 
-our @messaging_col_names = ('subject', 'message_from', 'message_to', 'flag', 'direction', 'delivery_time', 'message', 'timestamp', 'id INTEGER' );
+our @messaging_col_names = ("id INTEGER", "subject", "message_from", "message_to", 
+        "flag", "direction", "delivery_time", "message", "timestamp" );
 my $messaging_file_name;
 
 # path to directory to store client install log files
@@ -1352,34 +1353,33 @@ sub watch_for_new_messages {
     my $timestamp = &get_time();
     my $sql_statement = "SELECT * FROM $messaging_tn WHERE ( (CAST(timestamp AS INTEGER))<$timestamp AND flag='n' AND direction='in' )";
     my $res = $messaging_db->exec_statement( $sql_statement );
-
        foreach my $hit (@{$res}) {
 
         # create outgoing messages
-        my $message_to = @{$hit}[2];
+        my $message_to = @{$hit}[3];
 
         # translate message_to to plain login name
         my @reciever_l = ($message_to);  
-        my $message_id = @{$hit}[8];
+        my $message_id = @{$hit}[0];
 
         #add each outgoing msg to messaging_db
         my $reciever;
         foreach $reciever (@reciever_l) {
-            my $sql_statement = "INSERT INTO $messaging_tn (subject, message_from, message_to, flag, direction, delivery_time, message, timestamp, id) ".
+            my $sql_statement = "INSERT INTO $messaging_tn (id, subject, message_from, message_to, flag, direction, delivery_time, message, timestamp) ".
                 "VALUES ('".
-                @{$hit}[0]."', '".   # subject
-                @{$hit}[1]."', '".   # message_from
-                $reciever."', '".    # message_to
-                "none"."', '".       # flag
-                "out"."', '".        # direction
-                @{$hit}[5]."', '".   # delivery_time
-                @{$hit}[6]."', '".   # message
-                $timestamp."', '".   # timestamp
-                @{$hit}[8].          # id
-                "')";
+                $message_id."', '".    # id
+                @{$hit}[1]."', '".     # subject
+                @{$hit}[2]."', '".     # message_from
+                $reciever."', '".      # message_to
+                "none"."', '".         # flag
+                "out"."', '".          # direction
+                @{$hit}[6]."', '".     # delivery_time
+                @{$hit}[7]."', '".     # message
+                $timestamp."'".     # timestamp
+                ")";
             &daemon_log("M DEBUG: $sql_statement", 1);
             my $res = $messaging_db->exec_statement($sql_statement);
-            &daemon_log("M INFO: message '".@{$hit}[8]."' is prepared for delivery to reciever '$reciever'", 5);
+            &daemon_log("M INFO: message '".@{$hit}[0]."' is prepared for delivery to reciever '$reciever'", 5);
         }
 
         # send outgoing messages
@@ -1387,7 +1387,7 @@ sub watch_for_new_messages {
         my $res = $messaging_db->exec_statement( $sql_statement );
         foreach my $hit (@{$res}) {
             # add subject, from, to and message to list coll_user_msg
-            my @user_msg = [@{$hit}[0], @{$hit}[1], $reciever, @{$hit}[6]];
+            my @user_msg = [@{$hit}[1], @{$hit}[2], $reciever, @{$hit}[7]];
             push( @coll_user_msg, \@user_msg);
         }
 
@@ -1405,7 +1405,7 @@ sub watch_for_new_messages {
         $sql_statement = "UPDATE $messaging_tn SET flag='p' WHERE id='$message_id'"; 
         &daemon_log("M DEBUG: $sql_statement", 7);
         $res = $messaging_db->update_dbentry($sql_statement);
-        &daemon_log("M INFO: message '".@{$hit}[8]."' is set to flag 'p' (processed)", 5);
+        &daemon_log("M INFO: message '$message_id' is set to flag 'p' (processed)", 5);
 
     }
     
index aa9fada4f2890729333d1ba9d5a51da4dc1ee392..062315328b72dd122c7283a25c216cf792645fbe 100644 (file)
@@ -85,8 +85,17 @@ sub send_user_msg {
     }
 
     # add incoming message to messaging_db
+    my $new_msg_id = 1;
+    my $new_msg_id_sql = "SELECT MAX(id) FROM $main::messaging_tn"; 
+    my $new_msg_id_res = $main::messaging_db->exec_statement($new_msg_id_sql);
+    if (defined @{@{$new_msg_id_res}[0]}[0] ) {
+        $new_msg_id = int(@{@{$new_msg_id_res}[0]}[0]);
+        $new_msg_id += 1;
+    }
+
     my $func_dic = {table=>$main::messaging_tn,
-        primkey=>['id'],
+        primkey=>[],
+        id=>$new_msg_id,
         subject=>$subject,
         message_from=>$from,
         message_to=>$to,
index f21fa09d1c1e88e5203f7a1db98ef41b4d5fef12..cc9e1b31e41bbb59e967f3161ea3622dfc101d7b 100755 (executable)
@@ -17,7 +17,7 @@ if($sock->connected()){
 
 # jobdb add
 #$data = "<xml> <header>gosa_network_completition</header> <source>GOSA</source><target>GOSA</target><hostname>ws-muc-2</hostname></xml>";
-$data = "<xml> <header>job_sayHello</header> <source>10.89.1.155:20083</source><target>00:01:6c:9d:b9:fa</target><mac>00:1B:77:04:8A:6C</mac> <timestamp>20130102133908</timestamp> </xml>";
+#$data = "<xml> <header>job_sayHello</header> <source>10.89.1.155:20083</source><target>00:01:6c:9d:b9:fa</target><mac>00:1B:77:04:8A:6C</mac> <timestamp>20130102133908</timestamp> </xml>";
 #$data = "<xml> <header>job_ping</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:01:6c:9d:b9:fa</macaddress><timestamp>19700101000000</timestamp> </xml>";
 
 
@@ -40,6 +40,10 @@ $data = "<xml> <header>job_sayHello</header> <source>10.89.1.155:20083</source><
 #$data= "<xml><header>gosa_query_jobdb</header><source>GOSA</source> <target>GOSA</target><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><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>";
+#$data= "<xml><header>gosa_query_fai_server</header><source>GOSA</source> <target>GOSA</target></xml>";
+#$data= "<xml><header>gosa_query_fai_release</header><source>GOSA</source> <target>GOSA</target></xml>";
+#$data= "<xml><header>gosa_query_packages_list</header><source>GOSA</source> <target>GOSA</target></xml>";
+
 
 # jobdb count
 #$data = "<xml> <header>gosa_count_jobdb</header><source>GOSA</source> <target>GOSA</target></xml>";
@@ -78,10 +82,7 @@ $data = "<xml> <header>job_sayHello</header> <source>10.89.1.155:20083</source><
 
 ###########
 # messaging 
-#$data = "<xml> <header>gosa_send_user_msg</header> <target>GOSA</target> <source>GOSA</source> <user>susi</user> <user>harald</user> <user>susi</user> <group>gosa-admins-all</group> </xml>"; 
-#$data = "<xml> <header>gosa_send_user_msg</header> <target>GOSA</target> <source>GOSA</source> <group>gosa-admins-all</group> <usrmesg>kaffeepause</usrmesg> </xml>"; 
-#$data = "<xml> <header>gosa_send_user_msg</header> <target>GOSA</target> <source>GOSA</source> <user>rettenbe</user> <message>kaffeepause</message> </xml>"; 
-#$data = "<xml> <header>gosa_send_user_msg</header> <target>GOSA</target> <source>GOSA</source> <subject>eine wichtige nachricht</subject> <from>me</from> <to>you</to> <delivery_time>20130101235959</delivery_time> <message>kaffeepause</message> </xml>"; 
+$data = "<xml> <header>gosa_send_user_msg</header> <target>GOSA</target> <source>GOSA</source> <subject>eine wichtige nachricht</subject> <from>me</from> <to>you</to> <delivery_time>20130101235959</delivery_time> <message>kaffeepause</message> </xml>"; 
 
 
 ################
@@ -98,6 +99,9 @@ $data = "<xml> <header>job_sayHello</header> <source>10.89.1.155:20083</source><
 #$data = "<xml> <header>gosa_show_log_files_by_date_and_mac</header> <target>GOSA</target> <source>GOSA</source> <date>install_20080311_090900</date> <mac>00:01:6c:9d:b9:fa</mac> </xml>"; 
 #$data = "<xml> <header>gosa_get_log_file_by_date_and_mac</header> <target>GOSA</target> <source>GOSA</source> <date>install_20080311_090900</date> <mac>00:01:6c:9d:b9:fa</mac> <log_file>boot.log</log_file></xml>"; 
 
+#########
+# testing
+#$data = "<xml> <header>gosa_query_packages_list</header><source>GOSA</source> <target>GOSA</target></xml>";
 
     $sock->write($data);
     $answer = "nothing";