summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b3e004f)
raw | patch | inline | side by side (parent: b3e004f)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 26 Feb 2008 14:12:36 +0000 (14:12 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 26 Feb 2008 14:12:36 +0000 (14:12 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9128 594d385d-05f5-0310-b6e9-bd551577e9d8
diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client
index 9838f476eafb7132a4b57112fe5273309be86d85..ffdae1f57f93d93a8507227aa840b34f9afec015 100755 (executable)
--- a/gosa-si/gosa-si-client
+++ b/gosa-si/gosa-si-client
# create new passwd and ciphering object for client-server communication
$server_key = &create_passwd();
- my $events = join( ", ", keys %{$event_hash} );
+ my $events = join( ",", keys %{$event_hash} );
while(1) {
if( $try_to_register >= @servers ) {
# reset try_to_register
$try_to_register = 0;
- # Set fixed client address
+ # Set fixed client address and mac address
$client_ip= &get_local_ip_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/));
$client_address= "$client_ip:$client_port";
+ $client_mac_address = $local_mac;
# Write the MAC address to file
if(stat($opts_file)) {
$kernel->delay_set('register_at_gosa_si_server', $delay_set_time);
}
else {
- daemon_log("waiting for msg 'register_at_gosa_si_server'",1);
+ daemon_log("INFO: waiting for msg 'register_at_gosa_si_server'",5);
$kernel->delay_set('register_at_gosa_si_server', $delay_set_time);
# clear old settings and set it again
$kernel->delay_set('trigger_new_key', $server_key_lifetime);
diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index 4086f6b247210ebbe57763c92e5752d2dcf2a431..f9203baaa1dd9d48ecf0bf3e1fb5e40a6ab2030c 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
my (%cfg_defaults, $foreground, $verbose, $ping_timeout);
my ($bus_activ, $bus, $msg_to_bus, $bus_cipher);
my ($server, $server_mac_address);
-my ($gosa_server, $job_queue_timeout, $job_queue_table_name, $job_queue_file_name,$job_queue_loop_delay);
-my ($known_modules, $known_clients_file_name, $known_server_file_name);
+my ($gosa_server, $job_queue_timeout, $job_queue_loop_delay);
+my ($known_modules);
my ($pid_file, $procid, $pid, $log_file);
my ($arp_activ, $arp_fifo);
my ($xml);
$no_arp = 0;
+our $prg= basename($0);
+
# holds all gosa jobs
+my $job_queue_file_name;
our $job_db;
-our $job_queue_table_name = 'jobs';
+our $job_queue_tn = 'jobs';
# holds all other gosa-sd as well as the gosa-sd-bus
+my $known_server_file_name;
our $known_server_db;
+our $known_server_tn = "known_server";
# holds all registrated clients
+my $known_clients_file_name;
our $known_clients_db;
-our $prg= basename($0);
+our $known_clients_tn = "known_clients";
+
+# holds all logged in user at each client
+my $login_users_file_name;
+our $login_users_db;
+our $login_users_tn = "login_users";
%cfg_defaults = (
"general" => {
"port" => [\$server_port, "20081"],
"known-clients" => [\$known_clients_file_name, '/var/lib/gosa-si/clients.db' ],
"known-servers" => [\$known_server_file_name, '/var/lib/gosa-si/servers.db'],
+ "login-users" => [\$login_users_file_name, '/var/lib/gosa-si/users.db'],
"gosa-unit-tag" => [\$gosa_unit_tag, ""],
},
"GOsaPackages" => {
# check gosa job queue for jobs with executable timestamp
my $timestamp = &get_time();
- my $sql_statement = "SELECT * FROM ".$job_queue_table_name.
+ my $sql_statement = "SELECT * FROM ".$job_queue_tn.
" WHERE status='waiting' AND timestamp<'$timestamp'";
my $res = $job_db->select_dbentry( $sql_statement );
if (not defined $target) {
&daemon_log("ERROR: no host found for mac address: $macaddress", 1);
&daemon_log("$hit->{xmlmessage}", 8);
- my $sql_statement = "UPDATE $job_queue_table_name ".
+ my $sql_statement = "UPDATE $job_queue_tn ".
"SET status='error', result='no host found for mac address' ".
"WHERE id='$jobdb_id'";
my $res = $job_db->update_dbentry($sql_statement);
$job_db->create_table('jobs', \@job_col_names);
# connect to known_clients_db
-my @clients_col_names = ('hostname', 'status', 'hostkey', 'timestamp', 'macaddress', 'events', 'login');
+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);
$known_server_db = GOSA::DBsqlite->new($known_server_file_name);
$known_server_db->create_table('known_server', \@server_col_names);
+# connect to login_usr_db
+my @login_users_col_names = ('client', 'user', 'timestamp');
+$login_users_db = GOSA::DBsqlite->new($login_users_file_name);
+$login_users_db->create_table("login_users", \@login_users_col_names);
+
# create xml object used for en/decrypting
$xml = new XML::Simple();
index cde2978231a52f3a18b92169d70dc86305d4e11d..78592fff7629763f99298c51f0ff778a450c5039 100644 (file)
# specify primary key in table
if (not exists $arg->{primkey}) {
- return 2;
+ return (2, "a hash key 'primkey' with at least an empty list as value is necessary for add_dbentry");
}
- my $primkey = $arg->{primkey};
-
- # if primkey is id, fetch max id from table and give new job id= max(id)+1
- if ($primkey eq 'id') {
- my $id;
- my $sql_statement = "SELECT MAX(CAST(id AS INTEGER)) FROM $table";
- &create_lock($self,'add_dbentry');
- my $max_id = @{ @{ $self->{dbh}->selectall_arrayref($sql_statement) }[0] }[0];
- &remove_lock($self,'add_dbentry');
- if( defined $max_id) {
- $id = $max_id + 1;
- } else {
- $id = 1;
+ my $primkeys = $arg->{'primkey'};
+ my $prim_statement;
+ if( 0 != length(@$primkeys) ) {
+ my @prim_list;
+ foreach my $primkey (@$primkeys) {
+ if($primkey eq 'id') {
+ # if primkey is id, fetch max id from table and give new job id= max(id)+1
+ my $sql_statement = "SELECT MAX(CAST(id AS INTEGER)) FROM $table";
+ &create_lock($self,'add_dbentry');
+ my $max_id = @{ @{ $self->{dbh}->selectall_arrayref($sql_statement) }[0] }[0];
+ &remove_lock($self,'add_dbentry');
+ my $id;
+ if( defined $max_id) {
+ $id = $max_id + 1;
+ } else {
+ $id = 1;
+ }
+ $arg->{id} = $id;
+ }
+ if( not exists $arg->{$primkey} ) {
+ return (3, "primkey '$primkey' has no value for add_dbentry");
+ }
+ push(@prim_list, "$primkey='".$arg->{$primkey}."'");
}
- $arg->{id} = $id;
+ $prim_statement = "WHERE ".join(" AND ", @prim_list);
}
-
+
# if timestamp is not provided, add timestamp
if( not exists $arg->{timestamp} ) {
$arg->{timestamp} = &get_time;
}
# check wether primkey is unique in table, otherwise return errorflag
- my $sql_statement = "SELECT * FROM $table WHERE $primkey='$arg->{$primkey}'";
+ my $sql_statement = "SELECT * FROM $table $prim_statement";
&create_lock($self,'add_dbentry');
my $res = @{ $self->{dbh}->selectall_arrayref($sql_statement) };
&remove_lock($self,'add_dbentry');
+
if ($res == 0) {
# primekey is unique
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});
}
my $db_res = $self->{dbh}->do($sql_statement);
&remove_lock($self,'add_dbentry');
if( $db_res != 1 ) {
- return 4;
+ return (4, $sql_statement);
}
} else {
# entry already exists, so update it
- my $where_str= " WHERE $primkey='".$arg->{$primkey}."'";
-
my @update_l;
while( my ($pram, $val) = each %{$arg} ) {
if( $pram eq 'table' ) { next; }
my $update_str= join(", ", @update_l);
$update_str= " SET $update_str";
- my $sql_statement= "UPDATE $table $update_str $where_str";
+ my $sql_statement= "UPDATE $table $update_str $prim_statement";
my $db_res = &update_dbentry($self, $sql_statement );
}
index 18879d691480d3e77f58dab54e3a148c4750b14b..747f93a955da077c1e4ec95ad8a529a3fb3b0115 100644 (file)
# 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."'".
+ my $sql = "UPDATE '".$main::job_queue_tn."'".
" SET status='processing'".
" WHERE id='$job_id'";
my $res = $main::job_db->exec_statement($sql);
if( $error == 0 ) {
# add job to job queue
- my $func_dic = {table=>$main::job_queue_table_name,
- primkey=>'id',
+ my $func_dic = {table=>$main::job_queue_tn,
+ primkey=>['id'],
timestamp=>$timestamp,
status=>'waiting',
result=>'none',
my $out_xml= "<xml><count>error</count></xml>";
# prepare query sql statement
- my $table= $main::job_queue_table_name;
+ my $table= $main::job_queue_tn;
my $sql_statement= "SELECT * FROM $table ";
# execute db query
my $msg_hash = &transform_msg2hash($msg);
# prepare query sql statement
- my $table= $main::job_queue_table_name;
+ my $table= $main::job_queue_tn;
my $where= &get_where_statement($msg, $msg_hash);
my $sql_statement = "DELETE FROM $table $where";
my $error= 0;
my $out_xml= "<xml><answer1>1</answer1></xml>";
- my $table= $main::job_queue_table_name;
+ my $table= $main::job_queue_tn;
my $sql_statement = "DELETE FROM $table";
my $db_res = $main::job_db->del_dbentry($sql_statement);
# prepare query sql statement
if( $error == 0) {
- my $table= $main::job_queue_table_name;
+ my $table= $main::job_queue_tn;
my $where= &get_where_statement($msg, $msg_hash);
my $update= &get_update_statement($msg, $msg_hash);
index 492b109a006bb5294b4c51e0050bf481fe1fc573..d85d0b05d849645fd454b0ba3cad6cda93c9e12a 100644 (file)
# add myself to known_server_db
my $res = $main::known_server_db->add_dbentry( {table=>'known_server',
- primkey=>'hostname',
+ primkey=>['hostname'],
hostname=>$server_address,
status=>'myself',
hostkey=>$SIPackages_key,
# add bus to known_server_db
my $res = $main::known_server_db->add_dbentry( {table=>'known_server',
- primkey=>'hostname',
+ primkey=>['hostname'],
hostname=>$bus_address,
status=>'bus',
hostkey=>$bus_key,
# add entry to known_clients_db
my $act_timestamp = &get_time;
my $res = $main::known_clients_db->add_dbentry( {table=>'known_clients',
- primkey=>'hostname',
+ primkey=>['hostname'],
hostname=>$source,
events=>$events,
macaddress=>$mac_address,
status=>'registered',
hostkey=>$new_passwd,
timestamp=>$act_timestamp,
- login=>"nobody",
} );
if ($res != 0) {
index 686c9a0419ac72470d8e5ee1a0810c76abc40b99..62a3a50aeecb6525f826480af4f0db0e4e8645f0 100644 (file)
my $source = @{$msg_hash->{'source'}}[0];
my $login = @{$msg_hash->{$header}}[0];
- my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$source'";
- my $res = $main::known_clients_db->select_dbentry($sql_statement);
- if( 1 != keys(%$res) ) {
- &main::daemon_log("DEBUG: clMessages.pm: LOGIN: no or more hits found in known_clients_db for host '$source'");
+ my %add_hash = ( table=>$main::login_users_tn,
+ primkey=> ['client', 'user'],
+ client=>$source,
+ user=>$login,
+ timestamp=>&get_time,
+ );
+ my ($res, $error_str) = $main::login_users_db->add_dbentry( \%add_hash );
+ if ($res != 0) {
+ &main::daemon_log("ERROR: cannot add entry to known_clients: $error_str");
return;
}
- my $act_login = $res->{'1'}->{'login'};
- if( $act_login eq "nobody" ) {
- $act_login = "";
- }
-
- $act_login =~ s/$login,?//gi;
- my @act_login = split(",", $act_login);
- unshift(@act_login, $login);
- $act_login = join(",", @act_login);
-
-#print STDERR "source: $source\n";
-#print STDERR "login: $login\n";
-#print STDERR "act_login: $act_login\n";
-#print STDERR "dbres: ".Dumper($res)."\n";
- $sql_statement = "UPDATE known_clients ".
- "SET login='$act_login' ".
- "WHERE hostname='$source'";
- $res = $main::known_clients_db->update_dbentry($sql_statement);
return;
}
index 717928154a53f3e61e11bdb2aaf552f332721f3e..f8185db75b21e7a4af1eb4130714086b55681b0f 100644 (file)
my $source = @{$msg_hash->{'source'}}[0];
my $target = @{$msg_hash->{'target'}}[0];
my $usr = @{$msg_hash->{'usr'}}[0];
+ $header =~ s/^gosa_//;
my $sql_statement = "SELECT * FROM known_clients WHERE login LIKE '%$usr%'";
my $res = $main::known_clients_db->select_dbentry($sql_statement);
index 5fbe5f3148e4ecb84fb38bae4c842f2aaa09eb1f..d3ada5c74da18d5a7b34c571b9db03d380f0d7cc 100755 (executable)
--- a/gosa-si/tests/client.php
+++ b/gosa-si/tests/client.php
# jobdb update
#$data = "<xml> <header>gosa_update_status_jobdb_entry</header> <source>GOSA</source><target>GOSA</target><where><clause><phrase> <macaddress>00:01:6c:9d:b9:fa</macaddress></phrase></clause> </where> <update><timestamp>23450101000000</timestamp><result>XXXXXXXXXXXXXXx</result></update></xml>";
-#$data = "<xml> <header>gosa_update_status_jobdb_entry</header> <source>GOSA</source><target>GOSA</target><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> <source>GOSA</source><target>GOSA</target><where><clause><phrase> <status>waiting</status></phrase></clause> </where> <update><status>processing</status> <result>update</result></update></xml>";
# jobdb 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_query_jobdb</header><where><clause><phrase><headertag>ping</headertag></phrase></clause></where><limit><from>0</from><to>3</to></limit></xml>";
-#$data= "<xml><header>gosa_query_jobdb</header><where><clause><phrase><headertag>ping</headertag></phrase></clause></where><limit><from>0</from><to>5</to></limit><orderby>timestamp</orderby></xml>";
-#$data= "<xml><header>gosa_query_jobdb</header></xml>";
+#$data= "<xml><header>gosa_query_jobdb</header><source>GOSA</source> <target>GOSA</target><where><clause><phrase><HEADERTAG>trigger_action_reinstall</HEADERTAG></phrase></clause></where><limit><from>0</from><to>25</to></limit><orderby>timestamp DESC</orderby></xml>";
+#$data= "<xml><header>gosa_query_jobdb</header><source>GOSA</source> <target>GOSA</target></xml>";
# jobdb count
#$data = "<xml> <header>gosa_count_jobdb</header></xml>";
# "trigger_action_wake",
# get_login_usr_for_client
-$data = "<xml> <header>gosa_get_login_usr_for_client</header> <target>GOSA</target> <source>GOSA</source> <client>00:01:6c:9d:b9:fa</client></xml>";
+#$data = "<xml> <header>gosa_get_login_usr_for_client</header> <target>GOSA</target> <source>GOSA</source> <client>00:01:6c:9d:b9:fa</client></xml>";
# get_client_for_login_usr
-$data = "<xml> <header>gosa_get_client_for_login_usr</header> <target>GOSA</target> <source>GOSA</source> <usr>harald</usr></xml>";
+#$data = "<xml> <header>gosa_get_client_for_login_usr</header> <target>GOSA</target> <source>GOSA</source> <usr>harald</usr></xml>";