diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index c60c5e2887cc82197ff00627dc2971fa924381b7..dfec2b882ef7a11752e3aeef476375b2d6858cac 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
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, $known_clients_file_name, $known_server_file_name, $known_clients_db, $known_server_db);
+my ($known_modules, $known_clients_file_name, $known_server_file_name);
my ($max_clients);
my ($pid_file, $procid, $pid, $log_file);
my (%free_child, %busy_child, $child_max, $child_min, %child_alive_time, $child_timeout);
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,
- mode => 0666,
- destroy => 1,
- });
-# holds all registrated clients
-our $known_clients;
-#our $known_clients = {};
-#our $shmcl = tie($known_clients, 'IPC::Shareable', undef, {create => 1,
-# exclusive => 1,
-# mode => 0666,
-# destroy => 1,
-# });
+our $known_server_db;
+# holds all registrated clients
+our $known_clients_db;
%cfg_defaults =
("general" =>
"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'],
+ "known_server_file_name" => [\$known_server_file_name, '/var/lib/gosa-si/known_server.db'],
},
"bus" =>
{"bus_activ" => [\$bus_activ, "on"],
},
"server" =>
{"server_activ" => [\$server_activ, "on"],
- "server_ip" => [\$server_ip, ""],
+ "server_ip" => [\$server_ip, "0.0.0.0"],
"server_port" => [\$server_port, "20081"],
"server_passwd" => [\$server_passwd, ""],
"max_clients" => [\$max_clients, 100],
chomp($msg);
if($level <= $verbose){
print LOG_HANDLE "$level $msg\n";
- if(defined $foreground) { print $msg."\n" }
+ if($foreground) { print $msg."\n" }
}
}
# close( LOG_HANDLE );
}
}
-
-#=== FUNCTION ================================================================
-# NAME: get_ip_and_mac
-# PARAMETERS: nothing
-# RETURNS: (ip, mac)
-# DESCRIPTION: executes /sbin/ifconfig and parses the output, the first occurence
-# of a inet address is returned as well as the mac address in the line
-# above the inet address
-#===============================================================================
-sub get_ip_and_mac {
- my $ip = "0.0.0.0.0"; # Defualt-IP
- my $mac = "00:00:00:00:00:00"; # Default-MAC
- my @ifconfig = qx(/sbin/ifconfig);
- foreach(@ifconfig) {
- if (/Hardware Adresse (\S{2}):(\S{2}):(\S{2}):(\S{2}):(\S{2}):(\S{2})/) {
- $mac = "$1:$2:$3:$4:$5:$6";
- next;
- }
- if (/inet Adresse:(\d+).(\d+).(\d+).(\d+)/) {
- $ip = "$1.$2.$3.$4";
- last;
- }
- }
- return ($ip, $mac);
-}
-
-
-
#=== FUNCTION ================================================================
# NAME: import_modules
# PARAMETERS: module_path - string - abs. path to the directory the modules
# RETURNS: nothing
# DESCRIPTION: nomen est omen
#===============================================================================
-sub print_known_daemons {
- my ($tmp) = @_ ;
- print "####################################\n";
- print "# status of known_daemons\n";
- $shmda->shlock(LOCK_EX);
- my @hosts = keys %$known_daemons;
- foreach my $host (@hosts) {
- my $status = $known_daemons->{$host}->{status} ;
- my $passwd = $known_daemons->{$host}->{passwd};
- my $timestamp = $known_daemons->{$host}->{timestamp};
- print "$host\n";
- print "\tstatus: $status\n";
- print "\tpasswd: $passwd\n";
- print "\ttimestamp: $timestamp\n";
- }
- $shmda->shunlock(LOCK_EX);
- print "####################################\n";
- return;
-}
+#sub print_known_daemons {
+# my ($tmp) = @_ ;
+# print "####################################\n";
+# print "# status of known_daemons\n";
+# $shmda->shlock(LOCK_EX);
+# my @hosts = keys %$known_daemons;
+# foreach my $host (@hosts) {
+# my $status = $known_daemons->{$host}->{status} ;
+# my $passwd = $known_daemons->{$host}->{passwd};
+# my $timestamp = $known_daemons->{$host}->{timestamp};
+# print "$host\n";
+# print "\tstatus: $status\n";
+# print "\tpasswd: $passwd\n";
+# print "\ttimestamp: $timestamp\n";
+# }
+# $shmda->shunlock(LOCK_EX);
+# print "####################################\n";
+# return;
+#}
#=== FUNCTION ================================================================
# RETURNS: nothing
# DESCRIPTION: creates a dummy entry for hostname in known_daemons
#===============================================================================
-sub create_known_daemon {
- my ($hostname) = @_;
- $shmda->shlock(LOCK_EX);
- $known_daemons->{$hostname} = {};
- $known_daemons->{$hostname}->{status} = "none";
- $known_daemons->{$hostname}->{passwd} = "none";
- $known_daemons->{$hostname}->{timestamp} = "none";
- $shmda->shunlock(LOCK_EX);
- return;
-}
+#sub create_known_daemon {
+# my ($hostname) = @_;
+# $shmda->shlock(LOCK_EX);
+# $known_daemons->{$hostname} = {};
+# $known_daemons->{$hostname}->{status} = "none";
+# $known_daemons->{$hostname}->{passwd} = "none";
+# $known_daemons->{$hostname}->{timestamp} = "none";
+# $shmda->shunlock(LOCK_EX);
+# return;
+#}
#=== FUNCTION ================================================================
# RETURNS: nothing
# DESCRIPTION: nome est omen and updates each time the timestamp of hostname
#===============================================================================
-sub add_content2known_daemons {
- 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";
-
- $shmda->shlock(LOCK_EX);
- if (defined $status) {
- $known_daemons->{$hostname}->{status} = $status;
- }
- if (defined $passwd) {
- $known_daemons->{$hostname}->{passwd} = $passwd;
- }
- if (defined $mac_address) {
- $known_daemons->{$hostname}->{mac_address} = $mac_address;
- }
- if (defined $events) {
- $known_daemons->{$hostname}->{events} = $events;
- }
- $known_daemons->{$hostname}->{timestamp} = $t;
- $shmda->shlock(LOCK_EX);
- return;
-}
+#sub add_content2known_daemons {
+# 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";
+#
+# $shmda->shlock(LOCK_EX);
+# if (defined $status) {
+# $known_daemons->{$hostname}->{status} = $status;
+# }
+# if (defined $passwd) {
+# $known_daemons->{$hostname}->{passwd} = $passwd;
+# }
+# if (defined $mac_address) {
+# $known_daemons->{$hostname}->{mac_address} = $mac_address;
+# }
+# if (defined $events) {
+# $known_daemons->{$hostname}->{events} = $events;
+# }
+# $known_daemons->{$hostname}->{timestamp} = $t;
+# $shmda->shlock(LOCK_EX);
+# return;
+#}
#=== FUNCTION ================================================================
# RETURNS: nothing
# DESCRIPTION: nome est omen and updates each time the timestamp of hostname
#===============================================================================
-sub update_known_daemons {
- my $arg = {
- hostname => undef, status => undef, passwd => undef,
- @_ };
- my $hostname = $arg->{hostname};
- my $status = $arg->{status};
- my $passwd = $arg->{passwd};
-
- 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";
-
- $shmda->shlock(LOCK_EX);
- if (defined $status) {
- $known_daemons->{$hostname}->{status} = $status;
- }
- if (defined $passwd) {
- $known_daemons->{$hostname}->{passwd} = $passwd;
- }
- $known_daemons->{$hostname}->{timestamp} = $t;
- $shmda->shunlock(LOCK_EX);
- return;
-}
+#sub update_known_daemons {
+# my $arg = {
+# hostname => undef, status => undef, passwd => undef,
+# @_ };
+# my $hostname = $arg->{hostname};
+# my $status = $arg->{status};
+# my $passwd = $arg->{passwd};
+#
+# 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";
+#
+# $shmda->shlock(LOCK_EX);
+# if (defined $status) {
+# $known_daemons->{$hostname}->{status} = $status;
+# }
+# if (defined $passwd) {
+# $known_daemons->{$hostname}->{passwd} = $passwd;
+# }
+# $known_daemons->{$hostname}->{timestamp} = $t;
+# $shmda->shunlock(LOCK_EX);
+# return;
+#}
#=== FUNCTION ================================================================
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 update_known_clients {
- my $arg = {
- hostname => undef, status => undef, hostkey => undef,
- macaddress => undef, events => undef, timestamp=>undef,
- @_ };
- my $hostname = $arg->{hostname};
- my $status = $arg->{status};
- 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);
- 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";
-
- my $change_entry = { table=>'known_clients',
- where=>'hostname',
- timestamp=>$t,
- };
-
-
- if (defined $status) {
- $change_entry->{status} = $status;
- }
- if (defined $hostkey) {
- $change_entry->{hostkey} = $hostkey;
- }
- if (defined $macaddress) {
- $change_entry->{macaddress} = $macaddress;
- }
- if (defined $events) {
- $change_entry->{events} = $events;
- }
-
- $known_clients->change_dbentry($change_entry);
- return;
-}
+#sub update_known_clients {
+# my $arg = {
+# hostname => undef, status => undef, hostkey => undef,
+# macaddress => undef, events => undef, timestamp=>undef,
+# @_ };
+# my $hostname = $arg->{hostname};
+# my $status = $arg->{status};
+# 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);
+# return;
+# }
+#
+# my $change_entry = { table=>'known_clients',
+# where=>'hostname',
+# timestamp=>&get_time,
+# };
+#
+#
+# if (defined $status) {
+# $change_entry->{status} = $status;
+# }
+# if (defined $hostkey) {
+# $change_entry->{hostkey} = $hostkey;
+# }
+# if (defined $macaddress) {
+# $change_entry->{macaddress} = $macaddress;
+# }
+# if (defined $events) {
+# $change_entry->{events} = $events;
+# }
+#
+# $known_clients->change_dbentry($change_entry);
+# return;
+#}
#=== FUNCTION ================================================================
# RETURNS:
# DESCRIPTION:
#===============================================================================
-sub clean_up_known_clients {
- my ($address) = @_ ;
-
- if (not exists $known_clients->{$address}) {
- daemon_log("cannot prune known_clients from $address, client not known", 5);
- return;
- }
-
- delete $known_clients->{$address};
-
- # send bus a msg that address was deleted from known_clients
- my $out_hash = &create_xml_hash('delete_client', $server_address, $bus_address, $address);
- &send_msg_hash2bus($out_hash);
-
- daemon_log("client $address deleted from known_clients because of multiple down time", 3);
- return;
-}
+#sub clean_up_known_clients {
+# my ($address) = @_ ;
+#
+# if (not exists $known_clients->{$address}) {
+# daemon_log("cannot prune known_clients from $address, client not known", 5);
+# return;
+# }
+#
+# delete $known_clients->{$address};
+#
+# # send bus a msg that address was deleted from known_clients
+# my $out_hash = &create_xml_hash('delete_client', $server_address, $bus_address, $address);
+# &send_msg_hash2bus($out_hash);
+#
+# daemon_log("client $address deleted from known_clients because of multiple down time", 3);
+# return;
+#}
#=== FUNCTION ================================================================
$SIG{CHLD} = 'IGNORE';
# restart daemon log file
-if(-e $log_file ) { unlink $log_file }
daemon_log(" ", 1);
daemon_log("$0 started!", 1);
# Just fork, if we"re not in foreground mode
-if( ! $foreground ) { $pid = fork(); }
-else { $pid = $$; }
+if( ! $foreground ) {
+ chdir '/' or die "Can't chdir to /: $!";
+ $pid = fork;
+ setsid or die "Can't start a new session: $!";
+ umask 0;
+} else {
+ $pid = $$;
+}
# Do something useful - put our PID into the pid_file
if( 0 != $pid ) {
open( LOCK_FILE, ">$pid_file" );
print LOCK_FILE "$pid\n";
-close( LOCK_FILE );
- if( !$foreground ) { exit( 0 ) };
+ close( LOCK_FILE );
+ if( !$foreground ) {
+ exit( 0 )
+ };
}
# connect to gosa-si job queue
-my @job_col_names = ("timestamp", "status", "result", "header", "target", "xmlmessage", "macaddress");
+my @job_col_names = ("timestamp", "status", "result", "headertag", "targettag", "xmlmessage", "macaddress");
$job_db = GOSA::DBsqlite->new($job_queue_file_name);
$job_db->create_table('jobs', \@job_col_names);
@@ -999,6 +947,11 @@ my @clients_col_names = ('hostname', 'status', 'hostkey', 'timestamp', 'macaddre
$known_clients_db = GOSA::DBsqlite->new($known_clients_file_name);
$known_clients_db->create_table('known_clients', \@clients_col_names);
+# connect to known_server_db
+my @server_col_names = ('hostname', 'status', 'hostkey', 'timestamp');
+$known_server_db = GOSA::DBsqlite->new($known_server_file_name);
+$known_server_db->create_table('known_server', \@server_col_names);
+
# import all modules
&import_modules;
#}
#
-
##################################
#everything ready, okay, lets start
##################################
}
- if($arp_activ eq "on" && vec($rout, fileno $arp_fifo, 1)) {
- my $in_msg = <$arp_fifo>;
- chomp($in_msg);
- print "arp_activ: msg: $in_msg\n";
- my $act_passwd = $known_daemons->{$bus_address}->{passwd};
- print "arp_activ: arp_passwd: $act_passwd\n";
-
- my $in_msg_hash = $xml->XMLin($in_msg, ForceArray=>1);
-
- my $target = &get_content_from_xml_hash($in_msg_hash, 'target');
-
- if ($target eq $server_address) {
- print "arp_activ: forward to server\n";
- my $arp_cipher = &create_ciphering($act_passwd);
- my $crypted_msg = &encrypt_msg($in_msg, $arp_cipher);
- &activating_child($crypted_msg, $server_ip);
- } else {
- print "arp_activ: send to bus\n";
- &send_msg_hash2address($in_msg_hash, $bus_address);
- }
- print "\n";
- }
+# if($arp_activ eq "on" && vec($rout, fileno $arp_fifo, 1)) {
+# my $in_msg = <$arp_fifo>;
+# chomp($in_msg);
+# print "arp_activ: msg: $in_msg\n";
+# my $act_passwd = $known_daemons->{$bus_address}->{passwd};
+# print "arp_activ: arp_passwd: $act_passwd\n";
+#
+# my $in_msg_hash = $xml->XMLin($in_msg, ForceArray=>1);
+#
+# my $target = &get_content_from_xml_hash($in_msg_hash, 'target');
+#
+# if ($target eq $server_address) {
+# print "arp_activ: forward to server\n";
+# my $arp_cipher = &create_ciphering($act_passwd);
+# my $crypted_msg = &encrypt_msg($in_msg, $arp_cipher);
+# &activating_child($crypted_msg, $server_ip);
+# } else {
+# print "arp_activ: send to bus\n";
+# &send_msg_hash2address($in_msg_hash, $bus_address);
+# }
+# print "\n";
+# }
# check input fhd of all modules
daemon_log("cannot read from $actual_ip", 5);
}
}
- #close($client);
-
}
}
print $act_client $in_msg."\n";
#my $act_pipe = $busy_child{$pid}{pipe_rd};
- sleep(10);
- close ($act_client);
delete $busy_child{$pid};
$free_child{$pid} = $child_hash;
+ # give the client a chance to read
+ sleep(2);
+ close ($act_client);
}
}
}
my $timestamp = "$year$month$monthday$hours$minutes$seconds";
- #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'} );
+ my $res = $job_db->select_dbentry( { table=>$job_queue_table_name, status=>'waiting', timestamp=>$timestamp } );
+
while( my ($id, $hit) = each %{$res} ) {
my $jobdb_id = $hit->{ROWID};
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);
+ my $update_hash = { table=>$job_queue_table_name,
+ update=> [ { status=>['error'], result=>["no host found for mac address"] } ],
+ where=> [ { ROWID=>[$jobdb_id] } ],
+ };
+ my $res = $job_db->update_dbentry($update_hash);
+
next;
}
# add target
- print "select: target: $target\n";
&add_content2xml_hash($out_msg_hash, "target", $target);
# add new header
my $out_header = $job_msg_hash->{header}[0];
$out_header =~ s/job_/gosa_/;
- print "select: header: $out_header\n";
delete $out_msg_hash->{header};
&add_content2xml_hash($out_msg_hash, "header", $out_header);
my $error = &send_msg_hash2address($out_msg_hash, "$gosa_ip:$gosa_port", $gosa_passwd);
+#######################
+# TODO exchange ROWID with jobid, insert column jobid in table jobs befor
+
if ($error == 0) {
- my $sql = "UPDATE '$job_queue_table_name' SET status='processing', target='$target' WHERE ROWID='$jobdb_id'";
+ my $sql = "UPDATE '$job_queue_table_name' SET status='processing', targettag='$target' WHERE ROWID='$jobdb_id'";
my $res = $job_db->exec_statement($sql);
+ } else {
+ my $update_hash = { table=>$job_queue_table_name,
+ update=> [ { status=>'error' } ],
+ where=> [ { ROWID=>$jobdb_id } ],
+ };
+ my $res = $job_db->update_dbentry($update_hash);
}
-
}