summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 714a84d)
raw | patch | inline | side by side (parent: 714a84d)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 20 Feb 2008 18:49:27 +0000 (18:49 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 20 Feb 2008 18:49:27 +0000 (18:49 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8997 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-si/gosa-si-server | patch | blob | history | |
gosa-si/modules/GosaPackages.pm | patch | blob | history | |
gosa-si/tests/client.php | patch | blob | history |
diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index 5e61e9a553ce107458d65cd9feb4bed940c9abe2..10a6d118545fd228de44eec18beb9d5e20fd220b 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
sub check_key_and_xml_validity {
my ($crypted_msg, $module_key) = @_;
-
my $msg;
my $msg_hash;
+ my $error_string;
eval{
$msg = &decrypt_msg($crypted_msg, $module_key);
&main::daemon_log("decrypted_msg: \n$msg", 8);
$msg_hash = $xml->XMLin($msg, ForceArray=>1);
+ ##############
# check header
+ if( not exists $msg_hash->{'header'} ) { die "no header specified"; }
my $header_l = $msg_hash->{'header'};
- if( 1 != @{$header_l} ) {
- die 'header error';
- }
+ if( 1 > @{$header_l} ) { die 'empty header tag'; }
+ if( 1 < @{$header_l} ) { die 'more than one header specified'; }
my $header = @{$header_l}[0];
- if( 0 == length $header) {
- die 'header error';
- }
+ if( 0 == length $header) { die 'empty string in header tag'; }
+ ##############
# check source
+ if( not exists $msg_hash->{'source'} ) { die "no source specified"; }
my $source_l = $msg_hash->{'source'};
- if( not defined @{$source_l} or 1 != @{$source_l} ) {
- die 'source error';
- }
+ if( 1 > @{$source_l} ) { die 'empty source tag'; }
+ if( 1 < @{$source_l} ) { die 'more than one source specified'; }
my $source = @{$source_l}[0];
- if( 0 == length $source) {
- die 'source error';
- }
+ if( 0 == length $source) { die 'source error'; }
+ ##############
# check target
+ if( not exists $msg_hash->{'target'} ) { die "no target specified"; }
my $target_l = $msg_hash->{'target'};
- if( 1 != @{$target_l} ) {
- die'target error';
- }
- my $target = @{$target_l}[0];
- if( 0 == length $target) {
- die 'target error';
- }
+ if( 1 > @{$target_l} ) { die 'empty target tag'; }
}
};
if($@) {
&main::daemon_log("WARNING: do not understand the message", 5);
&main::daemon_log("$@", 8);
+ $msg = undef;
+ $msg_hash = undef;
}
return ($msg, $msg_hash);
no strict "refs";
my ($input) = @_ ;
my ($msg, $msg_hash, $module);
+ my $error_string;
my %act_modules = %$known_modules;
# check a key exists for this module
my $module_key = ${$mod."_key"};
- if( ! $module_key ) {
+ if( not defined $module_key ) {
if( $mod eq 'ArpHandler' ) {
next;
}
# check if module can open msg envelope with module key
($msg, $msg_hash) = &check_key_and_xml_validity($input, $module_key);
- if( (!$msg) || (!$msg_hash) ) {
- #daemon_log("$mod: deciphering failed", 5);
+ if( (not defined $msg) || (not defined $msg_hash) ) {
next;
}
else {
# check gosa job queue for jobs with executable timestamp
my $timestamp = &get_time();
-
my $sql_statement = "SELECT * FROM ".$job_queue_table_name.
" WHERE status='waiting' AND timestamp<'$timestamp'";
-
my $res = $job_db->select_dbentry( $sql_statement );
while( my ($id, $hit) = each %{$res} ) {
-
my $jobdb_id = $hit->{id};
- my $macaddress = $hit->{macaddress};
- my $job_msg_hash = &transform_msg2hash($hit->{xmlmessage});
- my $out_msg_hash = $job_msg_hash;
+ my $macaddress = $hit->{'macaddress'};
+ my $job_msg = $hit->{'xmlmessage'};
+ my $header = $hit->{'headertag'};
my $sql_statement = "SELECT * FROM known_clients WHERE macaddress='$macaddress'";
my $res_hash = $known_clients_db->select_dbentry( $sql_statement );
# expect macaddress is unique!!!!!!
my $target = $res_hash->{1}->{hostname};
if (not defined $target) {
- &daemon_log("ERROR: no host found for mac address: $job_msg_hash->{mac}[0]", 1);
- &daemon_log("xml message: $hit->{xmlmessage}", 5);
+ &daemon_log("ERROR: no host found for mac address: $macaddress", 1);
+ &daemon_log("$hit->{xmlmessage}", 8);
my $sql_statement = "UPDATE $job_queue_table_name ".
"SET status='error', result='no host found for mac address' ".
"WHERE id='$jobdb_id'";
next;
}
- # add target
- &add_content2xml_hash($out_msg_hash, "target", $target);
-
- # add new header
- my $out_header = $job_msg_hash->{header}[0];
- $out_header =~ s/job_/gosa_/;
- delete $out_msg_hash->{header};
- &add_content2xml_hash($out_msg_hash, "header", $out_header);
+ # change header
+ $job_msg =~ s/<header>job_/<header>gosa_/;
# add sqlite_id
- &add_content2xml_hash($out_msg_hash, "jobdb_id", $jobdb_id);
+ $job_msg =~ s/<\/xml>$/<jobdb_id>$jobdb_id<\/jobdb_id><\/xml>/;
- my $out_msg = &create_xml_string($out_msg_hash);
- # encrypt msg as a GosaPackage module
- my $cipher = &create_ciphering($GosaPackages_key);
- my $crypted_out_msg = &encrypt_msg($out_msg, $cipher);
+print STDERR "=======================================================\n$job_msg\n";
- my $error = &send_msg_hash2address($out_msg_hash, "$gosa_ip:$gosa_port", $GosaPackages_key);
+ &send_msg_to_target($job_msg, $server_address, $GosaPackages_key, $header);
- if ($error == 0) {
- my $sql_statement = "UPDATE $job_queue_table_name ".
- "SET status='processing', targettag='$target' ".
- "WHERE id='$jobdb_id'";
- my $res = $job_db->update_dbentry($sql_statement);
- } else {
- my $sql_statement = "UPDATE $job_queue_table_name ".
- "SET status='error' ".
- "WHERE id='$jobdb_id'";
- my $res = $job_db->update_dbentry($sql_statement);
- }
+# my $error = 1;
+# if ($error == 0) {
+# my $sql_statement = "UPDATE $job_queue_table_name ".
+# "SET status='done', targettag='$target' ".
+# "WHERE id='$jobdb_id'";
+# my $res = $job_db->update_dbentry($sql_statement);
+# } else {
+# my $sql_statement = "UPDATE $job_queue_table_name ".
+# "SET status='error' ".
+# "WHERE id='$jobdb_id'";
+# my $res = $job_db->update_dbentry($sql_statement);
+# }
}
$kernel->delay_set('watch_for_new_jobs',3);
index e2e7b3fc357a43e8cd36eb2b177f564c71ebb480..8314850c7528de65485f44b2afd7b1c68e8e5f56 100644 (file)
foreach my $out_msg ( @msg_l ) {
- # keep job queue uptodate and save result and status
- if (defined ($out_msg) && $out_msg =~ /<jobdb_id>(\d*?)<\/jobdb_id>/) {
+ # 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.
- "' SET status='done', result='".$out_msg.
- "' WHERE id='$job_id'";
+ my $sql = "UPDATE '".$main::job_queue_table_name."'".
+ " SET status='done'".
+ " WHERE id='$job_id'";
my $res = $main::job_db->exec_statement($sql);
}
sub process_job_msg {
- my ($msg, $msg_hash)= @_ ;
+ my ($msg, $msg_hash, $session_id)= @_ ;
my $out_msg;
+ my $error = 0;
- my $header = @{$msg_hash->{header}}[0];
+ my $header = @{$msg_hash->{'header'}}[0];
$header =~ s/job_//;
+ # if no timestamp is specified, 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'} ) {
+ $macaddress = @{$msg_hash->{'macaddress'}}[0];
+ } else {
+ $error ++;
+ $out_msg = "<xml>".
+ "<header>answer</header>".
+ "<source>$server_address</source>".
+ "<target>GOSA</target>".
+ "<answer1>1</answer1>".
+ "<error_string>no mac address specified</error_string>".
+ "</xml>";
+ }
+
# check wether mac address is already known in known_daemons or known_clients
my $target = 'none';
- # add job to job queue
- my $func_dic = {table=>$main::job_queue_table_name,
- primkey=>'id',
- timestamp=>@{$msg_hash->{timestamp}}[0],
- status=>'waiting',
- result=>'none',
- headertag=>$header,
- targettag=>$target,
- xmlmessage=>$msg,
- macaddress=>@{$msg_hash->{mac}}[0],
- };
- my $res = $main::job_db->add_dbentry($func_dic);
- if (not $res == 0) {
- &main::daemon_log("ERROR: GosaPackages: process_job_msg: $res", 1);
- } else {
- &main::daemon_log("INFO: GosaPackages: $header job successfully added to job queue", 5);
+ if( $error == 0 ) {
+ # add job to job queue
+ my $func_dic = {table=>$main::job_queue_table_name,
+ primkey=>'id',
+ timestamp=>$timestamp,
+ status=>'waiting',
+ result=>'none',
+ headertag=>$header,
+ targettag=>$target,
+ xmlmessage=>$msg,
+ macaddress=>$macaddress,
+ };
+
+ my $res = $main::job_db->add_dbentry($func_dic);
+ if (not $res == 0) {
+ &main::daemon_log("ERROR: GosaPackages: process_job_msg: $res", 1);
+ } else {
+ &main::daemon_log("INFO: GosaPackages: $header job successfully added to job queue", 5);
+ }
+ $out_msg = "<xml><header>answer</header><source>$server_address</source><target>GOSA</target><answer1>$res</answer1></xml>";
}
- $out_msg = "<xml><header>answer</header><source>$server_address</source><target>GOSA</target><answer1>$res</answer1></xml>";
my @out_msg_l = ( $out_msg );
return @out_msg_l;
}
index dbaeb8f3a05ce54a0f67fcb5d7230fd76908e94a..0ff74479c92def5229b38dfef316087fd1d07666 100755 (executable)
--- a/gosa-si/tests/client.php
+++ b/gosa-si/tests/client.php
#$data = "<xml> <header>gosa_delete_jobdb_entry</header><where><clause><phrase><id>3</id></phrase></clause></where></xml>";
# update
-$data = "<xml> <header>gosa_update_status_jobdb_entry</header> <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> <where><clause><phrase> <status>waiting</status></phrase></clause> </where> <update><status>processing</status> <result>update</result></update></xml>";
# 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_trigger_action_wake</header> <target>00:01:6c:9d:b9:fa</target> <source>10.89.1.31:20081</source> </xml>";
-#$data = "<xml> <header>gosa_trigger_action_localboot</header> <target>00:01:6c:9d:b9:fa</target> <source>10.89.1.31:20081</source> <timeout>-1</timeout></xml>";
-
+#$data = "<xml><header>job_trigger_action_reinstall</header><source>GOSA</source><target>00:01:6c:9d:b9:fa</target><macaddress>00:01:6c:9d:b9:fa</macaddress><timestamp>20130101000000</timestamp></xml>";
+$data = "<xml><header>job_trigger_action_reinstall</header><source>GOSA</source><target>00:01:6c:9d:b9:fa</target><macaddress>00:01:6c:9d:b9:fa</macaddress></xml>";
$sock->write($data);