Code

update: server event module opsi_com.pm
[gosa.git] / gosa-si / server / events / opsi_com.pm
1 ## @file
2 # @details A GOsa-SI-server event module containing all functions for message handling.
3 # @brief Implementation of an event module for GOsa-SI-server. 
6 package opsi_com;
7 use Exporter;
8 @ISA = qw(Exporter);
9 my @events = (
10     "get_events",
11     "opsi_install_client",
12 #    "opsi_get_netboot_products",
13 #    "opsi_get_local_products",
14 #    "opsi_get_product_properties",
15 #    "opsi_get_client_hardware",
16 #    "opsi_get_client_software",
17    );
18 @EXPORT = @events;
20 use strict;
21 use warnings;
22 use GOSA::GosaSupportDaemon;
23 use Data::Dumper;
26 BEGIN {}
28 END {}
30 ## @method get_events()
31 # A brief function returning a list of functions which are exported by importing the module.
32 # @return List of all provided functions
33 sub get_events {
34     return \@events;
35 }
37     
38 ## @method opsi_install_client
39
40 # @param msg - STRING - xml message with tags 
41 # @param msg_hash - HASHREF - message information parsed into a hash
42 # @param session_id - INTEGER - POE session id of the processing of this message
43 sub opsi_install_client {
44     my ($msg, $msg_hash, $session_id) = @_ ;
45     my $error = 0;
46     my $out_msg;
47     my $out_hash;
49     # Prepare incoming message
50     $msg =~ s/<header>gosa_/<header>/;
51     $msg_hash->{'header'}[0] =~ s/gosa_//;
54     # Assign variables
55     my $header = @{$msg_hash->{'header'}}[0];
56     my $source = @{$msg_hash->{'source'}}[0];
57     my $target = @{$msg_hash->{'target'}}[0];
60     # If no timestamp is specified in incoming message, use 19700101000000
61     my $timestamp = "19700101000000";
62     if( exists $msg_hash->{'timestamp'} ) {
63         $timestamp = @{$msg_hash->{'timestamp'}}[0];
64     }
65      
67     # If no macaddress is specified, raise error 
68     my $macaddress;
69     if ((exists $msg_hash->{'macaddress'}) &&
70             ($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)) { 
71         $macaddress = $1;
72     } else {
73         $error ++;
74         $out_msg = "<xml>".
75             "<header>answer</header>".
76             "<source>$main::server_address</source>".
77             "<target>GOSA</target>".
78             "<answer1>1</answer1>".
79             "<error_string>no mac address specified in macaddres-tag</error_string>".
80             "</xml>";
81     }
82     
84     # Set hostID to plain_name
85     my $plain_name;
86     if (not $error) {
87         if (exists $msg_hash->{'hostId'}) {
88             $plain_name = $msg_hash->{'hostId'}[0];
89         } else {
90             $error++;
91             $out_msg = "<xml>".
92             "<header>answer</header>".
93             "<source>$main::server_address</source>".
94             "<target>GOSA</target>".
95             "<answer1>1</answer1>".
96             "<error_string>no hostId specified in hostId-tag</error_string>".
97             "</xml>";
98         }
99     }
102     # Add installation job to job queue
103     if (not $error) {
104         my $insert_dic = {table=>$main::job_queue_tn, 
105             primkey=>['macaddress', 'headertag'],
106             timestamp=>&get_time(),
107             status=>'processing', 
108             result=>'none',
109             progress=>'none',
110             headertag=>$header, 
111             targettag=>$target,
112             xmlmessage=>$msg,
113             macaddress=>$macaddress,
114             plainname=>$plain_name,
115             siserver=>"windowsOpsi",
116             modified=>"1",
117         };
118         my $res = $main::job_db->add_dbentry($insert_dic);
119         if (not $res == 0) {
120             &main::daemon_log("$session_id ERROR: Cannot add opsi-job to job_queue: $msg", 1);
121         } else {
122             &main::daemon_log("$session_id INFO: '$header'-job successfully added to job queue", 5);
123         }
124         $out_msg = $msg;   # forward GOsa message to client 
125     }
126     
127     return ($out_msg);
133 #sub opsi_get_netboot_products {
134 #        my ($msg, $msg_hash, $session_id) = @_;
135 #        $msg =~ s/gosa_opsi/opsi/g;
136 #        return ( $msg );
137 #}
140 #sub opsi_set_product_properties {
141 #        my ($msg, $msg_hash, $session_id) = @_;
142 #        $msg =~ s/gosa_opsi/opsi/g;
143 #        return ( $msg );
144 #}
147 #sub opsi_get_product_properties {
148 #        my ($msg, $msg_hash, $session_id) = @_;
149 #        $msg =~ s/gosa_opsi/opsi/g;
150 #        return ( $msg );
151 #}
154 #sub opsi_get_local_products {
155 #        my ($msg, $msg_hash, $session_id) = @_;
156 #        $msg =~ s/gosa_opsi/opsi/g;
157 #        return ( $msg );
158 #}
160 #sub opsi_get_client_hardware {
161 #        my ($msg, $msg_hash, $session_id) = @_;
162 #        $msg =~ s/gosa_opsi/opsi/g;
163 #        return ( $msg );
164 #}
166 #sub opsi_get_client_software {
167 #        my ($msg, $msg_hash, $session_id) = @_;
168 #        $msg =~ s/gosa_opsi/opsi/g;
169 #        return ( $msg );
170 #}
172 1;