Code

update: server event module opsi_com.pm
authorrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 4 Aug 2008 15:00:49 +0000 (15:00 +0000)
committerrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 4 Aug 2008 15:00:49 +0000 (15:00 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12144 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-si/server/events/gosaTriggered.pm
gosa-si/server/events/opsi.pm [deleted file]
gosa-si/server/events/opsi_com.pm [new file with mode: 0644]

index 8bb7acc337c10ecc53b95dd5fa72666ee18e3e99..b65319c0bb2ede5074750c26ae5ff0e0e91f21ed 100644 (file)
@@ -1,9 +1,6 @@
 ## @file
 # @details A GOsa-SI event module containing all functions common used by GOsa
 # @brief Implementation of a GOsa-SI event module. 
-# @author Andreas Rettenberger <rettenberger@gonicus.de> 
-# @date 2008
-# @version 1.0
 
 package gosaTriggered;
 use Exporter;
diff --git a/gosa-si/server/events/opsi.pm b/gosa-si/server/events/opsi.pm
deleted file mode 100644 (file)
index 9fb0e4e..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-package opsi;
-use Exporter;
-@ISA = qw(Exporter);
-my @events = (
-    "get_events",
-    "opsi_get_netboot_products",
-    "opsi_get_local_products",
-    "opsi_get_product_properties",
-    "opsi_get_client_hardware",
-    "opsi_get_client_software",
-    "answer_opsi_get_netboot_products",
-    "answer_opsi_get_local_products",
-    "answer_opsi_get_product_properties",
-    "answer_opsi_set_product_properties",
-    "answer_opsi_get_client_hardware",
-    "answer_opsi_get_client_software",
-   );
-@EXPORT = @events;
-
-use strict;
-use warnings;
-use GOSA::GosaSupportDaemon;
-
-
-BEGIN {}
-
-END {}
-
-### Start ######################################################################
-
-sub get_events {
-    return \@events;
-}
-
-    
-sub opsi_get_netboot_products {
-        my ($msg, $msg_hash, $session_id) = @_;
-        $msg =~ s/gosa_opsi/opsi/g;
-        return ( $msg );
-}
-
-
-sub opsi_set_product_properties {
-        my ($msg, $msg_hash, $session_id) = @_;
-        $msg =~ s/gosa_opsi/opsi/g;
-        return ( $msg );
-}
-
-
-sub opsi_get_product_properties {
-        my ($msg, $msg_hash, $session_id) = @_;
-        $msg =~ s/gosa_opsi/opsi/g;
-        return ( $msg );
-}
-
-
-sub opsi_get_local_products {
-        my ($msg, $msg_hash, $session_id) = @_;
-        $msg =~ s/gosa_opsi/opsi/g;
-        return ( $msg );
-}
-
-sub opsi_get_client_hardware {
-        my ($msg, $msg_hash, $session_id) = @_;
-        $msg =~ s/gosa_opsi/opsi/g;
-        return ( $msg );
-}
-
-sub opsi_get_client_software {
-        my ($msg, $msg_hash, $session_id) = @_;
-        $msg =~ s/gosa_opsi/opsi/g;
-        return ( $msg );
-}
-
-sub answer_opsi_get_netboot_products {
-    my ($msg, $msg_hash, $session_id) = @_ ;
-    $msg =~ s/<target>\S+<\/target>/<target>GOSA<\/target>/g;
-    return ($msg);
-}
-
-sub answer_opsi_get_product_properties {
-    my ($msg, $msg_hash, $session_id) = @_ ;
-    $msg =~ s/<target>\S+<\/target>/<target>GOSA<\/target>/g;
-    return ($msg);
-}
-
-sub answer_opsi_set_product_properties {
-    my ($msg, $msg_hash, $session_id) = @_ ;
-    $msg =~ s/<target>\S+<\/target>/<target>GOSA<\/target>/g;
-    return ($msg);
-}
-
-sub answer_opsi_get_local_products {
-    my ($msg, $msg_hash, $session_id) = @_ ;
-    $msg =~ s/<target>\S+<\/target>/<target>GOSA<\/target>/g;
-    return ($msg);
-}
-
-sub answer_opsi_get_client_hardware {
-    my ($msg, $msg_hash, $session_id) = @_ ;
-    $msg =~ s/<target>\S+<\/target>/<target>GOSA<\/target>/g;
-    return ($msg);
-}
-
-sub answer_opsi_get_client_software {
-    my ($msg, $msg_hash, $session_id) = @_ ;
-    $msg =~ s/<target>\S+<\/target>/<target>GOSA<\/target>/g;
-    return ($msg);
-}
-
-1;
diff --git a/gosa-si/server/events/opsi_com.pm b/gosa-si/server/events/opsi_com.pm
new file mode 100644 (file)
index 0000000..ce1c1ed
--- /dev/null
@@ -0,0 +1,172 @@
+## @file
+# @details A GOsa-SI-server event module containing all functions for message handling.
+# @brief Implementation of an event module for GOsa-SI-server. 
+
+
+package opsi_com;
+use Exporter;
+@ISA = qw(Exporter);
+my @events = (
+    "get_events",
+    "opsi_install_client",
+#    "opsi_get_netboot_products",
+#    "opsi_get_local_products",
+#    "opsi_get_product_properties",
+#    "opsi_get_client_hardware",
+#    "opsi_get_client_software",
+   );
+@EXPORT = @events;
+
+use strict;
+use warnings;
+use GOSA::GosaSupportDaemon;
+use Data::Dumper;
+
+
+BEGIN {}
+
+END {}
+
+## @method get_events()
+# A brief function returning a list of functions which are exported by importing the module.
+# @return List of all provided functions
+sub get_events {
+    return \@events;
+}
+
+    
+## @method opsi_install_client
+# 
+# @param msg - STRING - xml message with tags 
+# @param msg_hash - HASHREF - message information parsed into a hash
+# @param session_id - INTEGER - POE session id of the processing of this message
+sub opsi_install_client {
+    my ($msg, $msg_hash, $session_id) = @_ ;
+    my $error = 0;
+    my $out_msg;
+    my $out_hash;
+
+    # Prepare incoming message
+    $msg =~ s/<header>gosa_/<header>/;
+    $msg_hash->{'header'}[0] =~ s/gosa_//;
+
+
+    # Assign variables
+    my $header = @{$msg_hash->{'header'}}[0];
+    my $source = @{$msg_hash->{'source'}}[0];
+    my $target = @{$msg_hash->{'target'}}[0];
+
+
+    # If no timestamp is specified in incoming message, use 19700101000000
+    my $timestamp = "19700101000000";
+    if( exists $msg_hash->{'timestamp'} ) {
+        $timestamp = @{$msg_hash->{'timestamp'}}[0];
+    }
+     
+
+    # If no macaddress is specified, raise error 
+    my $macaddress;
+    if ((exists $msg_hash->{'macaddress'}) &&
+            ($msg_hash->{'macaddress'}[0] =~ /^([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2})$/i)) { 
+        $macaddress = $1;
+    } else {
+        $error ++;
+        $out_msg = "<xml>".
+            "<header>answer</header>".
+            "<source>$main::server_address</source>".
+            "<target>GOSA</target>".
+            "<answer1>1</answer1>".
+            "<error_string>no mac address specified in macaddres-tag</error_string>".
+            "</xml>";
+    }
+    
+
+    # Set hostID to plain_name
+    my $plain_name;
+    if (not $error) {
+        if (exists $msg_hash->{'hostId'}) {
+            $plain_name = $msg_hash->{'hostId'}[0];
+        } else {
+            $error++;
+            $out_msg = "<xml>".
+            "<header>answer</header>".
+            "<source>$main::server_address</source>".
+            "<target>GOSA</target>".
+            "<answer1>1</answer1>".
+            "<error_string>no hostId specified in hostId-tag</error_string>".
+            "</xml>";
+        }
+    }
+
+
+    # Add installation job to job queue
+    if (not $error) {
+        my $insert_dic = {table=>$main::job_queue_tn, 
+            primkey=>['macaddress', 'headertag'],
+            timestamp=>&get_time(),
+            status=>'processing', 
+            result=>'none',
+            progress=>'none',
+            headertag=>$header, 
+            targettag=>$target,
+            xmlmessage=>$msg,
+            macaddress=>$macaddress,
+            plainname=>$plain_name,
+            siserver=>"windowsOpsi",
+            modified=>"1",
+        };
+        my $res = $main::job_db->add_dbentry($insert_dic);
+        if (not $res == 0) {
+            &main::daemon_log("$session_id ERROR: Cannot add opsi-job to job_queue: $msg", 1);
+        } else {
+            &main::daemon_log("$session_id INFO: '$header'-job successfully added to job queue", 5);
+        }
+        $out_msg = $msg;   # forward GOsa message to client 
+    }
+    
+    return ($out_msg);
+}
+
+
+
+
+#sub opsi_get_netboot_products {
+#        my ($msg, $msg_hash, $session_id) = @_;
+#        $msg =~ s/gosa_opsi/opsi/g;
+#        return ( $msg );
+#}
+#
+#
+#sub opsi_set_product_properties {
+#        my ($msg, $msg_hash, $session_id) = @_;
+#        $msg =~ s/gosa_opsi/opsi/g;
+#        return ( $msg );
+#}
+#
+#
+#sub opsi_get_product_properties {
+#        my ($msg, $msg_hash, $session_id) = @_;
+#        $msg =~ s/gosa_opsi/opsi/g;
+#        return ( $msg );
+#}
+#
+#
+#sub opsi_get_local_products {
+#        my ($msg, $msg_hash, $session_id) = @_;
+#        $msg =~ s/gosa_opsi/opsi/g;
+#        return ( $msg );
+#}
+#
+#sub opsi_get_client_hardware {
+#        my ($msg, $msg_hash, $session_id) = @_;
+#        $msg =~ s/gosa_opsi/opsi/g;
+#        return ( $msg );
+#}
+#
+#sub opsi_get_client_software {
+#        my ($msg, $msg_hash, $session_id) = @_;
+#        $msg =~ s/gosa_opsi/opsi/g;
+#        return ( $msg );
+#}
+#
+1;