summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e8306ac)
raw | patch | inline | side by side (parent: e8306ac)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 7 Jan 2008 10:54:00 +0000 (10:54 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 7 Jan 2008 10:54:00 +0000 (10:54 +0000) |
change known_clients storage from shared memory to sqlitedb
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8233 594d385d-05f5-0310-b6e9-bd551577e9d8
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8233 594d385d-05f5-0310-b6e9-bd551577e9d8
diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index 9ae65c92c88212c9b74cdaf20b246a490fdbcb9e..c60c5e2887cc82197ff00627dc2971fa924381b7 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
# DESCRIPTION:
#
# OPTIONS: ---
-# REQUIREMENTS: libconfig-inifiles-perl libcrypt-rijndael-perl libxml-simple-perl libipc-shareable-perl libdata-dumper-simple-perl
+# REQUIREMENTS: libconfig-inifiles-perl libcrypt-rijndael-perl libxml-simple-perl
+# libipc-shareable-perl libdata-dumper-simple-perl
+# libdbd-sqlite3-perl libnet-ldap-perl
# BUGS: ---
# NOTES:
# AUTHOR: (Andreas Rettenberger), <rettenberger@gonicus.de>
my ($bus, $msg_to_bus, $bus_cipher);
my ($server, $server_mac_address, $server_events);
my ($gosa_server, $job_queue_timeout, $job_queue_table_name, $job_queue_file_name);
-my ($known_daemons, $shmda, $known_clients, $shmcl, $known_modules);
+my ($known_daemons, $shmda, $known_clients, $shmcl, $known_modules, $known_clients_file_name, $known_server_file_name, $known_clients_db, $known_server_db);
my ($max_clients);
my ($pid_file, $procid, $pid, $log_file);
my (%free_child, %busy_child, $child_max, $child_min, %child_alive_time, $child_timeout);
$no_arp = 0;
# name of table for storing gosa jobs
-$job_queue_table_name = 'jobs';
+our $job_queue_table_name = 'jobs';
+our $job_db;
# holds all other gosa-sd as well as the gosa-sd-bus
+our $known_server;
our $known_daemons = {};
our $shmda = tie($known_daemons, 'IPC::Shareable', undef, {create => 1,
exclusive => 1,
destroy => 1,
});
# holds all registrated clients
-our $known_clients = {};
-our $shmcl = tie($known_clients, 'IPC::Shareable', undef, {create => 1,
- exclusive => 1,
- mode => 0666,
- destroy => 1,
- });
+our $known_clients;
+#our $known_clients = {};
+#our $shmcl = tie($known_clients, 'IPC::Shareable', undef, {create => 1,
+# exclusive => 1,
+# mode => 0666,
+# destroy => 1,
+# });
%cfg_defaults =
"child_timeout" => [\$child_timeout, 180],
"job_queue_timeout" => [\$job_queue_timeout, undef],
"job_queue_file_name" => [\$job_queue_file_name, '/var/lib/gosa-si/jobs.db'],
+ "known_clients_file_name" => [\$known_clients_file_name, '/var/lib/gosa-si/known_clients.db' ],
+ "known_server_file_name" => [\$known_server_file_name, '/var/lib/gosa-si/kown_server.db'],
},
"bus" =>
{"bus_activ" => [\$bus_activ, "on"],
my $answer;
my %act_modules = %$known_modules;
while( my ($module, $info) = each(%act_modules)) {
+ &daemon_log("##########", 5);
my $tmp = &{ $module."::process_incoming_msg" }($msg);
if (defined $tmp) {
$answer = $tmp;
}
+ &daemon_log("##########", 5);
}
#&print_known_daemons();
# RETURNS: nothing
# DESCRIPTION: nomen est omen
#===============================================================================
-sub print_known_clients {
-
- print "####################################\n";
- print "# status of known_clients\n";
- $shmcl->shlock(LOCK_EX);
- my @hosts = keys %$known_clients;
- if (@hosts) {
- foreach my $host (@hosts) {
- my $status = $known_clients->{$host}->{status} ;
- my $passwd = $known_clients->{$host}->{passwd};
- my $timestamp = $known_clients->{$host}->{timestamp};
- my $mac_address = $known_clients->{$host}->{mac_address};
- my $events = $known_clients->{$host}->{events};
- print "$host\n";
- print "\tstatus: $status\n";
- print "\tpasswd: $passwd\n";
- print "\ttimestamp: $timestamp\n";
- print "\tmac_address: $mac_address\n";
- print "\tevents: $events\n";
- }
- }
- $shmcl->shunlock(LOCK_EX);
- print "####################################\n";
- return;
-}
+#sub print_known_clients {
+#
+# print "####################################\n";
+# print "# status of known_clients\n";
+# $shmcl->shlock(LOCK_EX);
+# my @hosts = keys %$known_clients;
+# if (@hosts) {
+# foreach my $host (@hosts) {
+# my $status = $known_clients->{$host}->{status} ;
+# my $passwd = $known_clients->{$host}->{passwd};
+# my $timestamp = $known_clients->{$host}->{timestamp};
+# my $mac_address = $known_clients->{$host}->{mac_address};
+# my $events = $known_clients->{$host}->{events};
+# print "$host\n";
+# print "\tstatus: $status\n";
+# print "\tpasswd: $passwd\n";
+# print "\ttimestamp: $timestamp\n";
+# print "\tmac_address: $mac_address\n";
+# print "\tevents: $events\n";
+# }
+# }
+# $shmcl->shunlock(LOCK_EX);
+# print "####################################\n";
+# return;
+#}
#=== FUNCTION ================================================================
#===============================================================================
sub create_known_client {
my ($hostname) = @_;
- $shmcl->shlock(LOCK_EX);
- $known_clients->{$hostname} = {};
- $known_clients->{$hostname}->{status} = "none";
- $known_clients->{$hostname}->{passwd} = "none";
- $known_clients->{$hostname}->{timestamp} = "none";
- $known_clients->{$hostname}->{mac_address} = "none";
- $known_clients->{$hostname}->{events} = "none";
- $shmcl->shunlock(LOCK_EX);
+
+ my $entry = { table=>'known_clients',
+ hostname=>$hostname,
+ status=>'none',
+ hostkey=>'none',
+ timestamp=>'none',
+ macaddress=>'none',
+ events=>'none',
+ };
+ my $res = $known_clients_db->add_dbentry($entry);
+ if ($res > 0) {
+ daemon_log("ERROR: cannot add entry to known_clients.db: $res", 1);
+ }
+
+# $shmcl->shlock(LOCK_EX);
+# $known_clients->{$hostname} = {};
+# $known_clients->{$hostname}->{status} = "none";
+# $known_clients->{$hostname}->{passwd} = "none";
+# $known_clients->{$hostname}->{timestamp} = "none";
+# $known_clients->{$hostname}->{mac_address} = "none";
+# $known_clients->{$hostname}->{events} = "none";
+# $shmcl->shunlock(LOCK_EX);
return;
}
# RETURNS: nothing
# DESCRIPTION: nome est omen and updates each time the timestamp of hostname
#===============================================================================
-sub add_content2known_clients {
+sub update_known_clients {
my $arg = {
- hostname => undef, status => undef, passwd => undef,
- mac_address => undef, events => undef,
+ hostname => undef, status => undef, hostkey => undef,
+ macaddress => undef, events => undef, timestamp=>undef,
@_ };
my $hostname = $arg->{hostname};
my $status = $arg->{status};
- my $passwd = $arg->{passwd};
- my $mac_address = $arg->{mac_address};
+ my $hostkey = $arg->{hostkey};
+ my $macaddress = $arg->{macaddress};
my $events = $arg->{events};
+ my $timestamp = $arg->{timestamp};
if (not defined $hostname) {
daemon_log("ERROR: function add_content2known_clients is not invoked with requiered parameter 'hostname'", 1);
$monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
$year+=1900;
my $t = "$year$month$monthday$hours$minutes$seconds";
-
- $shmcl->shlock(LOCK_EX);
+
+ my $change_entry = { table=>'known_clients',
+ where=>'hostname',
+ timestamp=>$t,
+ };
+
+
if (defined $status) {
- $known_clients->{$hostname}->{status} = $status;
+ $change_entry->{status} = $status;
}
- if (defined $passwd) {
- $known_clients->{$hostname}->{passwd} = $passwd;
+ if (defined $hostkey) {
+ $change_entry->{hostkey} = $hostkey;
}
- if (defined $mac_address) {
- $known_clients->{$hostname}->{mac_address} = $mac_address;
+ if (defined $macaddress) {
+ $change_entry->{macaddress} = $macaddress;
}
if (defined $events) {
- $known_clients->{$hostname}->{events} = $events;
+ $change_entry->{events} = $events;
}
- $known_clients->{$hostname}->{timestamp} = $t;
- $shmcl->shlock(LOCK_EX);
+
+ $known_clients->change_dbentry($change_entry);
return;
}
# RETURNS: nothing
# DESCRIPTION: nome est omen and updates each time the timestamp of hostname
#===============================================================================
-sub update_known_clients {
- my $arg = {
- hostname => undef, status => undef, passwd => undef,
- mac_address => undef, events => undef,
- @_ };
- my $hostname = $arg->{hostname};
- my $status = $arg->{status};
- my $passwd = $arg->{passwd};
- my $mac_address = $arg->{mac_address};
- my $events = $arg->{events};
-
- if (not defined $hostname) {
- daemon_log("ERROR: function add_content2known_daemons is not invoked with requiered parameter 'hostname'", 1);
- return;
- }
-
- my ($seconds, $minutes, $hours, $monthday, $month,
- $year, $weekday, $yearday, $sommertime) = localtime(time);
- $hours = $hours < 10 ? $hours = "0".$hours : $hours;
- $minutes = $minutes < 10 ? $minutes = "0".$minutes : $minutes;
- $seconds = $seconds < 10 ? $seconds = "0".$seconds : $seconds;
- $month+=1;
- $month = $month < 10 ? $month = "0".$month : $month;
- $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
- $year+=1900;
- my $t = "$year$month$monthday$hours$minutes$seconds";
-
- $shmcl->shlock(LOCK_EX);
- if (defined $status) {
- $known_clients->{$hostname}->{status} = $status;
- }
- if (defined $passwd) {
- $known_clients->{$hostname}->{passwd} = $passwd;
- }
- if (defined $mac_address) {
- $known_clients->{$hostname}->{mac_address} = $mac_address;
- }
- if (defined $events) {
- $known_clients->{$hostname}->{events} = $events;
- }
- $known_clients->{$hostname}->{timestamp} = $t;
- $shmcl->shunlock(LOCK_EX);
- return;
-}
+#sub update_known_clients {
+# my $arg = {
+# hostname => undef, status => undef, passwd => undef,
+# mac_address => undef, events => undef,
+# @_ };
+# my $hostname = $arg->{hostname};
+# my $status = $arg->{status};
+# my $passwd = $arg->{passwd};
+# my $mac_address = $arg->{mac_address};
+# my $events = $arg->{events};
+#
+# if (not defined $hostname) {
+# daemon_log("ERROR: function add_content2known_daemons is not invoked with requiered parameter 'hostname'", 1);
+# return;
+# }
+#
+# my ($seconds, $minutes, $hours, $monthday, $month,
+# $year, $weekday, $yearday, $sommertime) = localtime(time);
+# $hours = $hours < 10 ? $hours = "0".$hours : $hours;
+# $minutes = $minutes < 10 ? $minutes = "0".$minutes : $minutes;
+# $seconds = $seconds < 10 ? $seconds = "0".$seconds : $seconds;
+# $month+=1;
+# $month = $month < 10 ? $month = "0".$month : $month;
+# $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
+# $year+=1900;
+# my $t = "$year$month$monthday$hours$minutes$seconds";
+#
+# if (defined $status) {
+# $known_clients->{$hostname}->{status} = $status;
+# }
+# if (defined $passwd) {
+# $known_clients->{$hostname}->{passwd} = $passwd;
+# }
+# if (defined $mac_address) {
+# $known_clients->{$hostname}->{mac_address} = $mac_address;
+# }
+# if (defined $events) {
+# $known_clients->{$hostname}->{events} = $events;
+# }
+# $known_clients_db->{$hostname}->{timestamp} = $t;
+# return;
+#}
if( !$foreground ) { exit( 0 ) };
}
+# connect to gosa-si job queue
+my @job_col_names = ("timestamp", "status", "result", "header", "target", "xmlmessage", "macaddress");
+$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');
+$known_clients_db = GOSA::DBsqlite->new($known_clients_file_name);
+$known_clients_db->create_table('known_clients', \@clients_col_names);
+
# import all modules
&import_modules;
# check wether all modules are gosa-si valid passwd check
-# connect to gosa-si job queue
-my $job_db = GOSA::DBsqlite->new($job_queue_file_name);
-
# create reading and writing vectors
my $rbits = my $wbits = my $ebits = "";
my $timestamp = "$year$month$monthday$hours$minutes$seconds";
- my $sql = "SELECT * FROM '$job_queue_table_name' WHERE status='waiting' AND timestamp<'$timestamp'";
- my $res = $job_db->exec_statement($sql);
- foreach my $msg (@{$res}) {
-
- my $jobdb_id = @{$msg}[0];
- my $job_msg_hash = &transform_msg2hash(@{$msg}[6]);
+ #my $res = $job_db->select_dbentry( { table=>$job_queue_table_name, status=>'waiting', timestamp=>'$timestamp'} );
+ my $res = $job_db->select_dbentry( { table=>$job_queue_table_name, status=>'waiting', timestamp=>'2007010709014800'} );
+ while( my ($id, $hit) = each %{$res} ) {
+
+ my $jobdb_id = $hit->{ROWID};
+ my $macaddress = $hit->{macaddress};
+ my $job_msg_hash = &transform_msg2hash($hit->{xmlmessage});
my $out_msg_hash = $job_msg_hash;
-
- # hole mac address und suche die entsprechende ip addresse
- my $target;
- my @hostnames = keys %{$known_clients};
- foreach my $hostname (@hostnames) {
- if ($known_clients->{$hostname}->{mac_address} eq $job_msg_hash->{mac}[0]) {
- $target = $hostname;
- last;
- }
- }
+ my $res_hash = $known_clients_db->select_dbentry( {table=>'known_clients', macaddress=>$macaddress} );
+ # 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);
# add sqlite_id
&add_content2xml_hash($out_msg_hash, "jobdb_id", $jobdb_id);
-# my $out_msg = &create_xml_string($out_msg_hash);
-#
-# # encrypt msg as a GosaPackage module
-# my $cipher = &create_ciphering($gosa_passwd);
-# my $crypted_out_msg = &encrypt_msg($out_msg, $cipher);
+ my $out_msg = &create_xml_string($out_msg_hash);
+
+ # encrypt msg as a GosaPackage module
+ my $cipher = &create_ciphering($gosa_passwd);
+ my $crypted_out_msg = &encrypt_msg($out_msg, $cipher);
my $error = &send_msg_hash2address($out_msg_hash, "$gosa_ip:$gosa_port", $gosa_passwd);
if ($error == 0) {
- my $sql = "UPDATE '$job_queue_table_name' SET status='processing', target='$target' WHERE id='$jobdb_id'";
+ my $sql = "UPDATE '$job_queue_table_name' SET status='processing', target='$target' WHERE ROWID='$jobdb_id'";
my $res = $job_db->exec_statement($sql);
}
index 46d13beaa74130331f1f93e7be070110652fe4bd..76014acdea135a8718846c73ddac3ddf2b7e1cfc 100644 (file)
my $object = shift;
my $table_name = shift;
my $col_names_ref = shift;
- my $sql_statement = "CREATE TABLE IF NOT EXISTS $table_name (".join(', ', @{$col_names_ref}).")";
+# unshift(@{$col_names_ref}, "id INTEGER PRIMARY KEY AUTOINCREMENT");
+ my $col_names_string = join(', ', @{$col_names_ref});
+ my $sql_statement = "CREATE TABLE IF NOT EXISTS $table_name ( $col_names_string )";
$object->{dbh}->do($sql_statement);
return 0;
}
if (not defined $table) {
return 1;
}
-
- # incrementing running id
- if (not exists $arg->{id}) {
- my $max_id = @{@{$obj->{dbh}->selectall_arrayref("SELECT MAX(id) FROM $table")}[0]}[0];
- if (not defined $max_id) {
- $max_id = 0;
+
+ # specify primary key in table
+ my $primkey = $arg->{primkey};
+
+ # check wether value to primary key is specified
+ if ( ( defined $primkey ) && ( not $arg->{ $primkey } ) ) {
+ return 2;
+ }
+
+ # check wether primkey is unique in table, otherwise return errorflag 3
+ if ( defined $primkey ) {
+ my $res = @{ $obj->{dbh}->selectall_arrayref( "SELECT * FROM $table WHERE $primkey='$arg->{$primkey}'") };
+ if ($res != 0) {
+ return 3;
}
- $arg->{id} = $max_id + 1;
}
-
-
+
# fetch column names of table
my $col_names = $obj->get_table_columns($table);
# assign values to column name variables
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});
- } else {
- my $default_val = "none";
- if ($col_name eq "timestamp") {
- $default_val = "19700101000000";
- }
- push(@add_list, $default_val);
}
-
+ # use default values for column values
+# } else {
+# my $default_val = "none";
+# if ($col_name eq "timestamp") {
+# $default_val = "19700101000000";
+# }
+# push(@add_list, $default_val);
+# }
}
- # check wether id does not exists in table, otherwise return errorflag 2
- my $res = @{$obj->{dbh}->selectall_arrayref( "SELECT * FROM $table WHERE id='$arg->{id}'")};
- if ($res != 0) {
- return 2;
- }
-
- my $sql_statement = " INSERT INTO $table VALUES ('".join("', '", @add_list)."') ";
+ my $sql_statement = " INSERT INTO $table VALUES ('".join("', '", @add_list)."')";
print " INSERT INTO $table VALUES ('".join("', '", @add_list)."')\n";
$obj->{dbh}->do($sql_statement);
-
return 0;
}
-sub change_dbentry {
+
+# error-flags
+# 1 no table ($table) defined
+# 2 no restriction parameter ($restric_pram) defined
+# 3 no restriction value ($restric_val) defined
+# 4 column name not known in table
+# 5 no column names to change specified
+sub update_dbentry {
my $obj = shift;
my $arg = shift;
push(@change_list, "$pram='$val'");
}
- if (not@change_list) {
+ if (not @change_list) {
return 5;
}
# collect select statements
my @select_list;
- my $sql_part;
+ my $sql_statement;
while (my ($pram, $val) = each %{$arg}) {
- push(@select_list, "$pram = '$val'");
+ if ( $pram eq 'timestamp' ) {
+ push(@select_list, "$pram < '$val'");
+ } else {
+ push(@select_list, "$pram = '$val'");
+ }
+
+ }
+ if (@select_list == 0) {
+ $sql_statement = "SELECT ROWID, * FROM '$table'";
+ } else {
+ $sql_statement = "SELECT ROWID, * FROM '$table' WHERE ".join(' AND ', @select_list);
}
+
+ # query db
+ my $query_answer = $obj->{dbh}->selectall_arrayref($sql_statement);
+
+ # fetch column list of db and create a hash with column_name->column_value of the select query
+ my $column_list = &get_table_columns($obj, $table);
+ my $list_len = @{ $column_list } ;
+ my $answer = {};
+ my $hit_counter = 0;
+
- my $sql_statement = "SELECT * FROM 'jobs' WHERE ".join(' AND ', @select_list);
- my $answer = $obj->{dbh}->selectall_arrayref($sql_statement);
+ foreach my $hit ( @{ $query_answer }) {
+ $hit_counter++;
+ $answer->{ $hit_counter }->{ 'ROWID' } = shift @{ $hit };
+ for ( my $i = 0; $i < $list_len; $i++) {
+ $answer->{ $hit_counter }->{ @{ $column_list }[$i] } = @{ $hit }[$i];
+ }
+ }
return $answer;
}
sub show_table {
my $obj = shift;
my $table_name = shift;
- my @res = @{$obj->{dbh}->selectall_arrayref( "SELECT * FROM $table_name")};
+ my @res = @{$obj->{dbh}->selectall_arrayref( "SELECT ROWID, * FROM $table_name")};
my @answer;
foreach my $hit (@res) {
push(@answer, "hit: ".join(', ', @{$hit}));
index d6eb36525415ed42c42f62993dce3f9ec50a10cb..a441a2fe1bea7a153c49e98fa16aac85d79c5952 100644 (file)
use IO::Socket::INET;
use XML::Simple;
use File::Spec;
+use Data::Dumper;
use GOSA::DBsqlite;
+use MIME::Base64;
BEGIN{}
END{}
-my ($server_activ, $server_port, $server_passwd, $max_clients);
+my ($server_activ, $server_port, $server_passwd, $max_clients, $server_event_dir);
my ($bus_activ, $bus_passwd, $bus_ip, $bus_port);
my ($gosa_activ, $gosa_ip, $gosa_port, $gosa_passwd);
my ($job_queue_timeout, $job_queue_file_name);
my $gosa_server;
-my $event_dir = "/etc/gosa-si/server/events";
-
-# name of table for storing gosa jobs
-my $job_queue_table_name = 'jobs';
my %cfg_defaults =
("general" =>
"server_port" => [\$server_port, "20081"],
"server_passwd" => [\$server_passwd, ""],
"max_clients" => [\$max_clients, 100],
+ "server_event_dir" => [\$server_event_dir, '/usr/lib/gosa-si/server/events'],
},
"bus" =>
{"bus_activ" => [\$bus_activ, "on"],
);
-### START ##########################
+## START ##########################
# read configfile and import variables
&read_configfile();
"target", "xml", "mac");
my $table_name = "jobs";
my $sqlite = GOSA::DBsqlite->new($job_queue_file_name);
-$sqlite->create_table($table_name, \@col_names);
+#$sqlite->create_table($table_name, \@col_names);
-### FUNCTIONS #################################################################
+## FUNCTIONS #################################################################
sub get_module_info {
my @info = ($gosa_address,
if(not defined $crypted_msg) {
&main::daemon_log("function 'process_incoming_msg': got no msg", 7);
}
-# &main::daemon_log("GosaPackages: crypted_msg:$crypted_msg", 7);
-# &main::daemon_log("GosaPackages: crypted_msg len:".length($crypted_msg), 7);
+ &main::daemon_log("GosaPackages: incoming msg: \n$crypted_msg", 7);
$crypted_msg =~ /^([\s\S]*?)\.(\d{1,3}?)\.(\d{1,3}?)\.(\d{1,3}?)\.(\d{1,3}?)$/;
$crypted_msg = $1;
my $host = sprintf("%s.%s.%s.%s", $2, $3, $4, $5);
- &main::daemon_log("GosaPackages: crypted_msg:$crypted_msg", 7);
-# &main::daemon_log("GosaPackages: crypted_msg len:".length($crypted_msg), 7);
-
-
# collect addresses from possible incoming clients
# only gosa is allowd as incoming client
&main::daemon_log("GosaPackages: host_key: $host", 7);
&main::daemon_log("GosaPackages: key_passwd: $gosa_passwd", 7);
$gosa_cipher = &create_ciphering($gosa_passwd);
+
# determine the correct passwd for deciphering of the incoming msgs
my $msg = "";
my $msg_hash;
eval{
$msg = &decrypt_msg($crypted_msg, $gosa_cipher);
- &main::daemon_log("GosaPackages: decrypted_msg: $msg", 7);
+ &main::daemon_log("GosaPackages: decrypted_msg: \n$msg", 7);
$msg_hash = $xml->XMLin($msg, ForceArray=>1);
};
&main::daemon_log("ERROR: $header is not a valid GosaPackage-header, need a 'job_' or a 'gosa_' prefix");
}
-
if (not defined $out_msg) {
return;
}
if ($out_msg =~ /<jobdb_id>(\d*?)<\/jobdb_id>/) {
my $job_id = $1;
- my $sql = "UPDATE '$job_queue_table_name' SET status='done', result='$out_msg' WHERE id='$job_id'";
- my $res = $sqlite->exec_statement($sql);
+ my $sql = "UPDATE '$main::job_queue_table_name' SET status='done', result='$out_msg' WHERE id='$job_id'";
+ my $res = $main::job_db->exec_statement($sql);
return;
} else {
$header =~ s/gosa_//;
&main::daemon_log("GosaPackages: got a gosa msg $header", 5);
- # fetch all available eventhandler under $event_dir
- opendir (DIR, $event_dir) or &main::daemon_log("ERROR cannot open $event_dir: $!\n", 1) and return;
- while (defined (my $file = readdir (DIR))) {
- if (not $file eq $header) {
- next;
- }
- # try to deliver incoming msg to eventhandler
-
- my $cmd = File::Spec->join($event_dir, $header)." '$msg'";
- &main::daemon_log("GosaPackages: execute event_handler $header", 3);
- &main::daemon_log("GosaPackages: cmd: $cmd", 7);
-
- $out_msg = "";
- open(PIPE, "$cmd 2>&1 |");
- while(<PIPE>) {
- $out_msg.=$_;
+ # decide wether msg is a core function or a event handler
+ if ( $header eq 'query_jobdb') { $out_msg = &query_jobdb }
+ else {
+ # msg could not be assigned to core function
+ # fetch all available eventhandler under $server_event_dir
+ opendir (DIR, $server_event_dir) or &main::daemon_log("ERROR cannot open $server_event_dir: $!\n", 1) and return;
+ while (defined (my $file = readdir (DIR))) {
+ if (not $file eq $header) {
+ next;
+ }
+ # try to deliver incoming msg to eventhandler
+ my $cmd = File::Spec->join($server_event_dir, $header)." '$msg'";
+ &main::daemon_log("GosaPackages: execute event_handler $header", 3);
+ &main::daemon_log("GosaPackages: cmd: $cmd", 7);
+
+ $out_msg = "";
+ open(PIPE, "$cmd 2>&1 |");
+ while(<PIPE>) {
+ $out_msg.=$_;
+ }
+ close(PIPE);
+ &main::daemon_log("GosaPackages: answer of cmd: $out_msg", 5);
+ last;
}
- close(PIPE);
- &main::daemon_log("GosaPackages: answer of cmd: $out_msg", 5);
- last;
}
# if delivery not possible raise error and return
if (not defined $out_msg) {
- &main::daemon_log("ERROR: GosaPackages: no event_handler defined for $header", 1);
+ &main::daemon_log("ERROR: GosaPackages: no event handler or core function defined for $header", 1);
} elsif ($out_msg eq "") {
&main::daemon_log("ERROR: GosaPackages got not answer from event_handler $header", 1);
}
my $target = 'not known until now';
# add job to job queue
- my $func_dic = {table=>$table_name,
+ my $func_dic = {table=>$main::job_queue_table_name,
timestamp=>@{$msg_hash->{timestamp}}[0],
status=>'waiting',
result=>'none',
header=>$header,
target=>$target,
- xml=>$msg,
- mac=>@{$msg_hash->{mac}}[0],
+ xmlmessage=>$msg,
+ macaddress=>@{$msg_hash->{mac}}[0],
};
- my $res = $sqlite->add_dbentry($func_dic);
+ my $res = $main::job_db->add_dbentry($func_dic);
if (not $res == 0) {
&main::daemon_log("ERROR: GosaPackages: process_job_msg: $res", 1);
}
}
+
+sub db_res_2_xml {
+ my ($db_res) = @_ ;
+ my $xml = "<xml>";
+
+ while ( my ($hit, $hash) = each %{ $db_res } ) {
+ $xml .= "<$hit>";
+
+ while ( my ($column_name, $column_value) = each %{$hash} ) {
+ $xml .= "<$column_name>";
+ my $xml_content = $column_value;
+ if( $column_name eq "xml" ) {
+ $xml_content = &encode_base64($column_value);
+ }
+ $xml .= $xml_content;
+ $xml .= "</$column_name>";
+ }
+
+ $xml .= "</$hit>";
+ }
+
+ $xml .= "</xml>";
+ return $xml;
+}
+
+
+## CORE FUNCTIONS ############################################################
+
+sub query_jobdb {
+ my ($msg) = @_;
+ my $msg_hash = &transform_msg2hash($msg);
+
+ # prepare query sql statement
+ my @where = @{$msg_hash->{where}};
+ my $where_hash = {table=>$main::job_queue_table_name };
+ foreach my $where_pram (@where) {
+ my $where_val = @{$msg_hash->{$where_pram}}[0];
+ if (defined $where_val) {
+ $where_hash->{$where_pram} = $where_val;
+ }
+ }
+
+ # execute db query
+ my $res_hash = $main::job_db->select_dbentry($where_hash);
+
+ my $out_xml = &db_res_2_xml($res_hash);
+ return $out_xml;
+}
+
+
+
1;
+
+
+
+
+
+
+
+
+
index bc5458af4a1d4d88e49e4bfb01d8395f579bbea2..670bb8e27a391268d29804b9dfe97f78f6dacf90 100644 (file)
use Exporter;
@ISA = qw(Exporter);
-@EXPORT = qw(create_xml_hash send_msg_hash2address get_content_from_xml_hash add_content2xml_hash create_xml_string encrypt_msg decrypt_msg create_ciphering transform_msg2hash send_msg);
+@EXPORT = qw(create_xml_hash send_msg_hash2address get_content_from_xml_hash add_content2xml_hash create_xml_string encrypt_msg decrypt_msg create_ciphering transform_msg2hash get_time send_msg);
use strict;
use warnings;
my $xml = new XML::Simple();
-
sub process_incoming_msg {
return;
}
sub transform_msg2hash {
my ($msg) = @_ ;
-
my $hash = $xml->XMLin($msg, ForceArray=>1);
return $hash;
}
daemon_log("cannot send '$header'-msg to $address , server not reachable",
5);
- if (exists $main::known_clients->{$address}) {
- if ($main::known_clients->{$address}->{status} eq "down") {
- # if status of not reachable client is already 'down',
- # then delete client from known_clients
- &clean_up_known_clients($address);
-
- } else {
- # update status to 'down'
- &update_known_clients(hostname=>$address, status=>"down");
-
- }
- }
+# if (exists $main::known_clients->{$address}) {
+# if ($main::known_clients->{$address}->{status} eq "down") {
+# # if status of not reachable client is already 'down',
+# # then delete client from known_clients
+# &clean_up_known_clients($address);
+#
+# } else {
+# # update status to 'down'
+# &update_known_clients(hostname=>$address, status=>"down");
+#
+# }
+# }
return 1;
}
#daemon_log("\t$crypted_msg", 7);
# update status of client in known_clients with last send msg
- if(exists $main::known_daemons->{$address}) {
- #&update_known_daemons();
- } elsif(exists $main::known_clients->{$address}) {
- &main::update_known_clients(hostname=>$address, status=>$header);
- }
+# if(exists $main::known_daemons->{$address}) {
+# #&update_known_daemons();
+# } elsif(exists $main::known_clients->{$address}) {
+# &main::update_known_clients(hostname=>$address, status=>$header);
+# }
return 0;
}
}
+sub get_time {
+ my ($seconds, $minutes, $hours, $monthday, $month,
+ $year, $weekday, $yearday, $sommertime) = localtime(time);
+ $hours = $hours < 10 ? $hours = "0".$hours : $hours;
+ $minutes = $minutes < 10 ? $minutes = "0".$minutes : $minutes;
+ $seconds = $seconds < 10 ? $seconds = "0".$seconds : $seconds;
+ $month+=1;
+ $month = $month < 10 ? $month = "0".$month : $month;
+ $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
+ $year+=1900;
+ return "$year$month$monthday$hours$minutes$seconds";
+
+}
+
+
#=== FUNCTION ================================================================
# NAME: send_msg
# DESCRIPTION: Send a message to a destination
index 846eed111f3acbc65ec3c8868647b89d553be24e..e810ffb0e47aeda5026bcb918cf0b08a39adb095 100644 (file)
use GOSA::GosaSupportDaemon;
use IO::Socket::INET;
use XML::Simple;
+use Data::Dumper;
use Net::LDAP;
BEGIN{}
END {}
-
+my ($known_clients_file_name);
my ($server_activ, $server_port, $server_passwd, $max_clients, $ldap_uri, $ldap_base, $ldap_admin_dn, $ldap_admin_password);
my ($bus_activ, $bus_passwd, $bus_ip, $bus_port);
my $server;
my $no_bus;
my (@ldap_cfg, @pam_cfg, @nss_cfg, $goto_admin, $goto_secret);
+
my %cfg_defaults =
-("server" =>
+("general" =>
+ {"known_clients_file_name" => [\$known_clients_file_name, '/var/lib/gosa-si/known_clients.db' ],
+ },
+"server" =>
{"server_activ" => [\$server_activ, "on"],
"server_port" => [\$server_port, "20081"],
"server_passwd" => [\$server_passwd, ""],
}
}
+# connect to known_clients_db
+my $known_clients_db = GOSA::DBsqlite->new($known_clients_file_name);
+
+
# register at bus
if ($main::no_bus > 0) {
$bus_activ = "off"
&main::daemon_log("function 'process_incoming_msg': got no msg", 7);
}
+ &main::daemon_log("ServerPackages: incoming msg: \n$crypted_msg", 7);
+
$crypted_msg =~ /^([\s\S]*?)\.(\d{1,3}?)\.(\d{1,3}?)\.(\d{1,3}?)\.(\d{1,3}?)$/;
$crypted_msg = $1;
my $host = sprintf("%s.%s.%s.%s", $2, $3, $4, $5);
&main::daemon_log("ServerPackage: key_passwd: $key_passwd", 7);
my $key_cipher = &create_ciphering($key_passwd);
$msg = &decrypt_msg($crypted_msg, $key_cipher);
- &main::daemon_log("ServerPackages: decrypted msg: $msg", 7);
+ &main::daemon_log("ServerPackages: decrypted msg: \n$msg", 7);
$msg_hash = $xml->XMLin($msg, ForceArray=>1);
#my $tmp = printf Dumper $msg_hash;
#&main::daemon_log("DEBUG: ServerPackages: xml hash: $tmp", 7);
my $source = @{$msg_hash->{source}}[0];
&main::daemon_log("recieve '$header' at ServerPackages from $host", 1);
-# &main::daemon_log("ServerPackages: msg from host:", 5);
-# &main::daemon_log("\t$host", 5);
-# &main::daemon_log("ServerPackages: header from msg:", 5);
-# &main::daemon_log("\t$header", 5);
- &main::daemon_log("ServerPackages: msg to process:", 5);
- &main::daemon_log("\t$msg", 5);
+ &main::daemon_log("ServerPackages: msg to process: \n$msg", 5);
my @targets = @{$msg_hash->{target}};
my $len_targets = @targets;
# we have only one target symbol
my $target = $targets[0];
- &main::daemon_log("SeverPackages: msg is for:", 7);
- &main::daemon_log("\t$target", 7);
+ &main::daemon_log("SeverPackages: msg is for: $target", 7);
+ # msg is for server
if ($target eq $server_address) {
- # msg is for server
+
+ # msg is a event
+
+ # msg is a hard implemented function
if ($header eq 'new_passwd'){ &new_passwd($msg_hash)}
elsif ($header eq 'here_i_am') { &here_i_am($msg_hash)}
elsif ($header eq 'who_has') { &who_has($msg_hash) }
else { &main::daemon_log("ERROR: ServerPackages: no function assigned to this msg", 5) }
+ # msg is for all clients
} elsif ($target eq "*") {
- # msg is for all clients
-
my @target_addresses = keys(%$main::known_clients);
foreach my $target_address (@target_addresses) {
if ($target_address eq $source) { next; }
$msg_hash->{target} = [$target_address];
&send_msg_hash2address($msg_hash, $target_address);
- }
+ }
+
+ # msg is for one host
} else {
- # msg is for one host
-
if (exists $main::known_clients->{$target}) {
&send_msg_hash2address($msg_hash, $target);
} elsif (exists $main::known_daemons->{$target}) {
my $out_hash;
# number of known clients
- my $nu_clients = keys %$main::known_clients;
+ my $nu_clients = keys %{$known_clients_db->select_dbentry( {table=>'known_clients'} )};
# check wether client address or mac address is already known
if (exists $main::known_clients->{$source}) {
# create known_daemons entry
my $events = @{$msg_hash->{events}}[0];
- &main::create_known_client($source);
- &main::add_content2known_clients(hostname=>$source, events=>$events, mac_address=>$mac_address,
- status=>"registered", passwd=>$new_passwd);
-
+
+ # add entry to known_clients_db
+ my $res = $known_clients_db->add_dbentry( {table=>'known_clients',
+ primkey=>'hostname',
+ hostname=>$source,
+ events=>$events,
+ macaddress=>$mac_address,
+ status=>'registered',
+ hostkey=>$new_passwd,
+ timestamp=>&get_time,
+ } );
+ if ($res == 3) {
+ $res = $known_clients_db->update_dbentry( {table=>'known_clients',
+ where=>'hostname',
+ hostname=>$source,
+ events=>$events,
+ macaddress=>$mac_address,
+ status=>'registered',
+ hostkey=>$new_passwd,
+ timestamp=>&get_time,
+ } );
+ }
+ if ($res > 0) {
+ &main::daemon_log("ERROR: cannot add entry to known_clients: $res");
+ return;
+ }
+
# return acknowledgement to client
$out_hash = &create_xml_hash("registered", $server_address, $source);
- &send_msg_hash2address($out_hash, $source);
+ &send_msg_hash2address($out_hash, $source, $new_passwd);
# notify registered client to bus
$out_hash = &create_xml_hash("new_client", $server_address, $bus_address, $source);
- #&main::send_msg_hash2bus($out_hash);
&send_msg_hash2address($out_hash, $bus_address);
# give the new client his ldap config
diff --git a/gosa-si/server.conf b/gosa-si/server.conf
index 97047ce4110ab48c60f4f84dfed28fa952a09d82..3386c00a6cfcd7fd4d53af84b01490680c1de109 100644 (file)
--- a/gosa-si/server.conf
+++ b/gosa-si/server.conf
server_port = 20081
server_passwd = secret-server-password
max_clients = 5
+server_event_dir = /usr/lib/gosa-si/server/events
[arp]
arp_activ = off
index 12f33c6426778284af25d52b7dc69976f74c4703..30c39b9d6c2105a9bedde1e1ded1a4f3b65ad433 100755 (executable)
--- a/gosa-si/tests/client.php
+++ b/gosa-si/tests/client.php
/* Prepare a hunge bunch of data to be send */
#$data = "<xml><header>gosa_ping</header><source>10.89.1.155:20082</source><target></target><mac>11:22:33:44:55</mac></xml>";
#$data = "<xml> <header>job_ping</header> <source>10.89.1.155:20083</source><mac>00:1B:77:04:8A:6C</mac> <timestamp>19700101000000</timestamp> </xml>";
- $data = "<xml> <header>job_ping</header> <source>10.89.1.155:20083</source><mac>00:1B:77:04:8A:6C</mac> <timestamp>20080102133900</timestamp> </xml>";
+ #$data = "<xml> <header>job_sayHello</header> <source>10.89.1.155:20083</source><mac>00:1B:77:04:8A:6C</mac> <timestamp>20130102133900</timestamp> </xml>";
+ #$data = "<xml> <header>job_ping</header> <source>10.89.1.155:20083</source><mac>00:1B:77:04:8A:6C</mac> <timestamp>20130102133900</timestamp> </xml>";
+ $data = "<xml><header>gosa_query_jobdb</header><where>status</where><status>waiting</status></xml>";
$sock->write($data);
-
+
+
#$sock->setEncryptionKey("ferdinand_frost");
$answer = $sock->read();