summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2c48134)
raw | patch | inline | side by side (parent: 2c48134)
author | janw <janw@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 18 Sep 2008 11:50:18 +0000 (11:50 +0000) | ||
committer | janw <janw@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 18 Sep 2008 11:50:18 +0000 (11:50 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-lhm@12503 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-si/debian/gosa-si-server.postinst | patch | blob | history | |
gosa-si/debian/rules | patch | blob | history | |
gosa-si/debian/templates | [deleted file] | patch | blob | history |
gosa-si/gosa-si-server | patch | blob | history | |
gosa-si/modules/DBmysql.pm | [deleted file] | patch | blob | history |
gosa-si/modules/DBsqlite.pm | [new file with mode: 0644] | patch | blob |
gosa-si/modules/GosaPackages.pm | patch | blob | history | |
gosa-si/server/events/gosaTriggered.pm | patch | blob | history |
index e20a28fc9b65671c57c5b6aa758d71cee2dfc660..ccbf8c3c942fbdc3ea6d21b613cc3dfea3f7f66e 100644 (file)
#!/bin/sh
-set -e
-
-. /usr/share/debconf/confmodule
-
-db_version 2.0
-
-for i in hostname database username password rootpw; do
- db_get gosa-si/$i || true
- eval $i'="$RET"'
-done
-
-host="127.0.0.1"
-
#DEBHELPER#
# We exit unless the package is being configured
*) exit 0;
esac
-# Setup database
-/usr/bin/mysqladmin -u root --password=$rootpw create "$database" &> /dev/null || true
-/usr/bin/mysql -u root --password=$rootpw -e "GRANT ALL PRIVILEGES ON $database.* to '$username'@'127.0.0.1' identified by '$password'"
-
# Fix permission
[ -f /etc/gosa-si/server.conf ] && chmod go-rwx /etc/gosa-si/server.conf
-# Apply DB settings to config file
-if [ -w /etc/gosa-si/server.conf ]; then
- for i in database username password host; do
- eval 'val=$'$i
- grep -E "mysql-$i" /etc/gosa-si/server.conf | grep -vE '^ *#' && sed -i "/\[server\]/,/\[/s/mysql-$i\s*=\s*\(.*\)$/mysql-$i = $val/g" /etc/gosa-si/server.conf || sed -i "
-/\[server\]/ a\
-mysql-$i = $val" /etc/gosa-si/server.conf
- done
-fi
-
# Restart daemon
invoke-rc.d gosa-si restart
-db_stop
-
exit 0
diff --git a/gosa-si/debian/rules b/gosa-si/debian/rules
index 0b12205ef94d6a4518c212521710792da4ced21f..892de833cbcea10e684d584719876dd7e1926dcd 100755 (executable)
--- a/gosa-si/debian/rules
+++ b/gosa-si/debian/rules
# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.
# Uncomment this to turn on verbose mode.
-# export DH_VERBOSE=1
+#export DH_VERBOSE=1
build: patch
#********************************************************
done
-find debian/tmp -name '*.svn' -type d -exec rm -rf {} \; 2> /dev/null
- -for i in gosa-si-client gosa-si-server modules/GosaPackages.pm modules/ClientPackages.pm modules/ServerPackages.pm server/events/*; do sed -i 's/use GosaSupportDaemon;/use GOSA::GosaSupportDaemon;/g;s/use DBmysql;/use GOSA::DBmysql;/g' debian/tmp/$$i; done
+ -for i in gosa-si-client gosa-si-server modules/GosaPackages.pm modules/ClientPackages.pm modules/ServerPackages.pm server/events/*; do sed -i 's/use GosaSupportDaemon;/use GOSA::GosaSupportDaemon;/g;s/use DBsqlite;/use GOSA::DBsqlite;/g' debian/tmp/$$i; done
-sed -i 's!"/etc/gosa-si/modules";!use lib "/usr/lib/gosa-si/modules";!g' debian/tmp/gosa-si-server
dh_installchangelogs
dh_installman
dh_installlogrotate
- dh_installdebconf
+ #dh_installdebconf
dh_installinit --init-script=gosa-si -- start 00 2 3 4 5 . stop 29 1 .
chmod 640 debian/gosa-si-server/etc/gosa-si/server.conf debian/gosa-si-client/etc/gosa-si/client.conf
diff --git a/gosa-si/debian/templates b/gosa-si/debian/templates
--- a/gosa-si/debian/templates
+++ /dev/null
@@ -1,28 +0,0 @@
-Template: gosa-si/hostname
-Type: string
-Default: 127.0.0.1
-Description: Hostname or IP of the MySQL-Server
- Please enter the full-qualified hostname or IP Address of the desired MySQL Host.
-
-Template: gosa-si/database
-Type: string
-Default: gosa_si
-Description: Name of the GOsa-SI Database
- Please choose a name for the gosa-si database.
-
-Template: gosa-si/username
-Type: string
-Default: gosa_si
-Description: Name of the GOsa-SI Database User
- Please choose a name for the gosa-si database user.
-
-Template: gosa-si/password
-Type: password
-Description: Password for the GOsa-SI Database User
- Please enter a password for the gosa-si database user.
-
-Template: gosa-si/rootpw
-Type: password
-Description: Password for the Database Administrator 'root'
- In order to create the privileged account, setup needs the password of the
- database administrator. Please enter the password of the database user 'root'.
diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index ca826949bf5d726bd8b37cb1b349ec577244efee..0ed129cb468b41a57d02dc90a55a3d80b0b56aae 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
use File::Find;
use File::Copy;
use File::Path;
-use GOSA::DBmysql;
+use GOSA::DBsqlite;
use GOSA::GosaSupportDaemon;
use POE qw(Component::Server::TCP Wheel::Run Filter::Reference);
use Net::LDAP;
our $forground;
our $cfg_file;
our ($ldap_uri, $ldap_base, $ldap_admin_dn, $ldap_admin_password, $ldap_server_dn);
-our ($mysql_username, $mysql_password, $mysql_database, $mysql_host);
our $known_modules;
our $root_uid;
our $adm_gid;
our $incoming_db;
our $incoming_tn = 'incoming';
my $incoming_file_name;
-my @incoming_col_names = ("id INTEGER PRIMARY KEY auto_increment",
- "timestamp VARCHAR(14) DEFAULT 'none'",
- "headertag VARCHAR(255) DEFAULT 'none'",
- "targettag VARCHAR(255) DEFAULT 'none'",
- "xmlmessage TEXT",
- "module VARCHAR(255) DEFAULT 'none'",
- "sessionid VARCHAR(255) DEFAULT '0'",
-);
+my @incoming_col_names = ("id INTEGER PRIMARY KEY",
+ "timestamp DEFAULT 'none'",
+ "headertag DEFAULT 'none'",
+ "targettag DEFAULT 'none'",
+ "xmlmessage DEFAULT 'none'",
+ "module DEFAULT 'none'",
+ "sessionid DEFAULT '0'",
+ );
# holds all gosa jobs
our $job_db;
our $job_queue_tn = 'jobs';
my $job_queue_file_name;
-my @job_queue_col_names = ("id INTEGER PRIMARY KEY auto_increment",
- "timestamp VARCHAR(14) DEFAULT 'none'",
- "status VARCHAR(255) DEFAULT 'none'",
- "result TEXT",
- "progress VARCHAR(255) DEFAULT 'none'",
- "headertag VARCHAR(255) DEFAULT 'none'",
- "targettag VARCHAR(255) DEFAULT 'none'",
- "xmlmessage TEXT",
- "macaddress VARCHAR(17) DEFAULT 'none'",
- "plainname VARCHAR(255) DEFAULT 'none'",
- "siserver VARCHAR(255) DEFAULT 'none'",
- "modified INTEGER DEFAULT '0'",
-);
+my @job_queue_col_names = ("id INTEGER PRIMARY KEY",
+ "timestamp DEFAULT 'none'",
+ "status DEFAULT 'none'",
+ "result DEFAULT 'none'",
+ "progress DEFAULT 'none'",
+ "headertag DEFAULT 'none'",
+ "targettag DEFAULT 'none'",
+ "xmlmessage DEFAULT 'none'",
+ "macaddress DEFAULT 'none'",
+ "plainname DEFAULT 'none'",
+ "siserver DEFAULT 'none'",
+ "modified DEFAULT '0'",
+ );
# holds all other gosa-si-server
our $known_server_db;
our $known_server_tn = "known_server";
my $known_server_file_name;
-my @known_server_col_names = ("hostname VARCHAR(255)", "macaddress VARCHAR(17)", "status VARCHAR(255)", "hostkey VARCHAR(255)", "loaded_modules TEXT", "timestamp VARCHAR(14)");
+my @known_server_col_names = ("hostname", "macaddress", "status", "hostkey", "loaded_modules", "timestamp");
# holds all registrated clients
our $known_clients_db;
our $known_clients_tn = "known_clients";
my $known_clients_file_name;
-my @known_clients_col_names = ("hostname VARCHAR(255)", "status VARCHAR(255)", "hostkey VARCHAR(255)", "timestamp VARCHAR(14)", "macaddress VARCHAR(17)", "events TEXT", "keylifetime VARCHAR(255)");
+my @known_clients_col_names = ("hostname", "status", "hostkey", "timestamp", "macaddress", "events", "keylifetime");
# holds all registered clients at a foreign server
our $foreign_clients_db;
our $foreign_clients_tn = "foreign_clients";
my $foreign_clients_file_name;
-my @foreign_clients_col_names = ("hostname VARCHAR(255)", "macaddress VARCHAR(17)", "regserver VARCHAR(255)", "timestamp VARCHAR(14)");
+my @foreign_clients_col_names = ("hostname", "macaddress", "regserver", "timestamp");
# holds all logged in user at each client
our $login_users_db;
our $login_users_tn = "login_users";
my $login_users_file_name;
-my @login_users_col_names = ("client VARCHAR(255)", "user VARCHAR(255)", "timestamp VARCHAR(14)");
+my @login_users_col_names = ("client", "user", "timestamp");
# holds all fai server, the debian release and tag
our $fai_server_db;
our $fai_server_tn = "fai_server";
my $fai_server_file_name;
-our @fai_server_col_names = ("timestamp VARCHAR(14)", "server VARCHAR(255)", "fai_release VARCHAR(255)", "sections VARCHAR(255)", "tag VARCHAR(255)");
+our @fai_server_col_names = ("timestamp", "server", "release", "sections", "tag");
our $fai_release_db;
our $fai_release_tn = "fai_release";
my $fai_release_file_name;
-our @fai_release_col_names = ("timestamp VARCHAR(14)", "fai_release VARCHAR(255)", "class VARCHAR(255)", "type VARCHAR(255)", "state VARCHAR(255)");
+our @fai_release_col_names = ("timestamp", "release", "class", "type", "state");
# holds all packages available from different repositories
our $packages_list_db;
our $packages_list_tn = "packages_list";
my $packages_list_file_name;
-our @packages_list_col_names = ("distribution VARCHAR(255)", "package VARCHAR(255)", "version VARCHAR(255)", "section VARCHAR(255)", "description TEXT", "template LONGBLOB", "timestamp VARCHAR(14)");
+our @packages_list_col_names = ("distribution", "package", "version", "section", "description", "template", "timestamp");
my $outdir = "/tmp/packages_list_db";
my $arch = "i386";
# holds all messages which should be delivered to a user
our $messaging_db;
our $messaging_tn = "messaging";
-our @messaging_col_names = ("id INTEGER", "subject TEXT", "message_from VARCHAR(255)", "message_to VARCHAR(255)",
- "flag VARCHAR(255)", "direction VARCHAR(255)", "delivery_time VARCHAR(255)", "message TEXT", "timestamp VARCHAR(14)" );
+our @messaging_col_names = ("id INTEGER", "subject", "message_from", "message_to",
+ "flag", "direction", "delivery_time", "message", "timestamp" );
my $messaging_file_name;
# path to directory to store client install log files
"gosa-unit-tag" => [\$gosa_unit_tag, ""],
"max-clients" => [\$max_clients, 10],
"wol-password" => [\$wake_on_lan_passwd, ""],
- "mysql-username" => [\$mysql_username, "gosa_si"],
- "mysql-password" => [\$mysql_password, ""],
- "mysql-database" => [\$mysql_database, "gosa_si"],
- "mysql-host" => [\$mysql_host, "127.0.0.1"],
},
"GOsaPackages" => {
"job-queue" => [\$job_queue_file_name, '/var/lib/gosa-si/jobs.db'],
sub msg_to_decrypt {
- my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
- my $session_id = $session->ID;
- my ($msg, $msg_hash, $module);
- my $error = 0;
-
- # hole neue msg aus @msgs_to_decrypt
- my $next_msg = shift @msgs_to_decrypt;
-
- # entschlüssle sie
+ my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
+ my $session_id = $session->ID;
+ my ($msg, $msg_hash, $module);
+ my $error = 0;
- # msg is from a new client or gosa
- ($msg, $msg_hash, $module) = &input_from_unknown_host($next_msg, $session_id);
- # msg is from a gosa-si-server
- if(( !$msg ) || ( !$msg_hash ) || ( !$module )){
- ($msg, $msg_hash, $module) = &input_from_known_server($next_msg, $heap->{'remote_ip'}, $session_id);
- }
- # msg is from a gosa-si-client
- if(( !$msg ) || ( !$msg_hash ) || ( !$module )){
- ($msg, $msg_hash, $module) = &input_from_known_client($next_msg, $heap->{'remote_ip'}, $session_id);
- }
- # an error occurred
- if(( !$msg ) || ( !$msg_hash ) || ( !$module )){
- # if an incoming msg could not be decrypted (maybe a wrong key), send client a ping. If the client
- # could not understand a msg from its server the client cause a re-registering process
- daemon_log("$session_id WARNING cannot understand incoming msg, send 'ping'-msg to all host with ip '".$heap->{remote_ip}.
- "' to cause a re-registering of the client if necessary", 3);
- my $sql_statement = "SELECT * FROM $main::known_clients_tn WHERE (hostname LIKE '".$heap->{'remote_ip'}."%')";
- my $query_res = $known_clients_db->select_dbentry( $sql_statement );
- while( my ($hit_num, $hit) = each %{ $query_res } ) {
- my $host_name = $hit->{'hostname'};
- my $host_key = $hit->{'hostkey'};
- my $ping_msg = "<xml> <header>gosa_ping</header> <source>$server_address</source> <target>$host_name</target></xml>";
- my $error = &send_msg_to_target($ping_msg, $host_name, $host_key, "gosa_ping", $session_id);
- &update_jobdb_status_for_send_msgs($ping_msg, $error);
- }
- $error++;
- }
+ # hole neue msg aus @msgs_to_decrypt
+ my $next_msg = shift @msgs_to_decrypt;
+
+ # entschlüssle sie
+ # msg is from a new client or gosa
+ ($msg, $msg_hash, $module) = &input_from_unknown_host($next_msg, $session_id);
+ # msg is from a gosa-si-server
+ if(( !$msg ) || ( !$msg_hash ) || ( !$module )){
+ ($msg, $msg_hash, $module) = &input_from_known_server($next_msg, $heap->{'remote_ip'}, $session_id);
+ }
+ # msg is from a gosa-si-client
+ if(( !$msg ) || ( !$msg_hash ) || ( !$module )){
+ ($msg, $msg_hash, $module) = &input_from_known_client($next_msg, $heap->{'remote_ip'}, $session_id);
+ }
+ # an error occurred
+ if(( !$msg ) || ( !$msg_hash ) || ( !$module )){
+ # if an incoming msg could not be decrypted (maybe a wrong key), send client a ping. If the client
+ # could not understand a msg from its server the client cause a re-registering process
+ daemon_log("$session_id WARNING cannot understand incoming msg, send 'ping'-msg to all host with ip '".$heap->{remote_ip}.
+ "' to cause a re-registering of the client if necessary", 3);
+ my $sql_statement = "SELECT * FROM $main::known_clients_tn WHERE (hostname LIKE '".$heap->{'remote_ip'}."%')";
+ my $query_res = $known_clients_db->select_dbentry( $sql_statement );
+ while( my ($hit_num, $hit) = each %{ $query_res } ) {
+ my $host_name = $hit->{'hostname'};
+ my $host_key = $hit->{'hostkey'};
+ my $ping_msg = "<xml> <header>gosa_ping</header> <source>$server_address</source> <target>$host_name</target></xml>";
+ my $error = &send_msg_to_target($ping_msg, $host_name, $host_key, "gosa_ping", $session_id);
+ &update_jobdb_status_for_send_msgs($ping_msg, $error);
+ }
+ $error++;
+ }
- my $header;
- my $target;
- my $source;
- my $done = 0;
- my $sql;
- my $res;
- # check whether this message should be processed here
- if ($error == 0) {
- $header = @{$msg_hash->{'header'}}[0];
- $target = @{$msg_hash->{'target'}}[0];
- $source = @{$msg_hash->{'source'}}[0];
+ my $header;
+ my $target;
+ my $source;
+ my $done = 0;
+ my $sql;
+ my $res;
+
+ # check whether this message should be processed here
+ if ($error == 0) {
+ $header = @{$msg_hash->{'header'}}[0];
+ $target = @{$msg_hash->{'target'}}[0];
+ $source = @{$msg_hash->{'source'}}[0];
my $not_found_in_known_clients_db = 0;
my $not_found_in_known_server_db = 0;
my $not_found_in_foreign_clients_db = 0;
- my $local_address;
- my $local_mac;
- my ($target_ip, $target_port) = split(':', $target);
-
- # Determine the local ip address if target is an ip address
+ my $local_address;
+ my $local_mac;
+ my ($target_ip, $target_port) = split(':', $target);
+
+ # Determine the local ip address if target is an ip address
if ($target =~ /^\d+\.\d+\.\d+\.\d+:\d+$/) {
$local_address = &get_local_ip_for_remote_ip($target_ip).":$server_port";
} else {
- $local_address = $server_address;
- }
+ $local_address = $server_address;
+ }
- # Determine the local mac address if target is a mac address
- if ($target =~ /^([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) {
- my $loc_ip = &get_local_ip_for_remote_ip($heap->{'remote_ip'});
- my $network_interface= &get_interface_for_ip($loc_ip);
- $local_mac = &get_mac_for_interface($network_interface);
- } else {
- $local_mac = $server_mac_address;
- }
+ # Determine the local mac address if target is a mac address
+ if ($target =~ /^([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) {
+ my $loc_ip = &get_local_ip_for_remote_ip($heap->{'remote_ip'});
+ my $network_interface= &get_interface_for_ip($loc_ip);
+ $local_mac = &get_mac_for_interface($network_interface);
+ } else {
+ $local_mac = $server_mac_address;
+ }
- # target and source is equal to GOSA -> process here
- if (not $done) {
- if ($target eq "GOSA" && $source eq "GOSA") {
- $done = 1;
- &daemon_log("$session_id DEBUG: target and source is 'GOSA' -> process here", 7);
- }
- }
+ # target and source is equal to GOSA -> process here
+ if (not $done) {
+ if ($target eq "GOSA" && $source eq "GOSA") {
+ $done = 1;
+ &daemon_log("$session_id DEBUG: target and source is 'GOSA' -> process here", 7);
+ }
+ }
- # target is own address without forward_to_gosa-tag -> process here
- if (not $done) {
- #if ((($target eq $local_address) || ($target eq $local_mac) ) && (not exists $msg_hash->{'forward_to_gosa'})) {
- if (($target eq $local_address) && (not exists $msg_hash->{'forward_to_gosa'})) {
- $done = 1;
- if ($source eq "GOSA") {
- $msg =~ s/<\/xml>/<forward_to_gosa>$local_address,$session_id<\/forward_to_gosa><\/xml>/;
- }
- &daemon_log("$session_id DEBUG: target is own address without forward_to_gosa-tag -> process here", 7);
- }
- }
+ # target is own address without forward_to_gosa-tag -> process here
+ if (not $done) {
+ #if ((($target eq $local_address) || ($target eq $local_mac) ) && (not exists $msg_hash->{'forward_to_gosa'})) {
+ if (($target eq $local_address) && (not exists $msg_hash->{'forward_to_gosa'})) {
+ $done = 1;
+ if ($source eq "GOSA") {
+ $msg =~ s/<\/xml>/<forward_to_gosa>$local_address,$session_id<\/forward_to_gosa><\/xml>/;
+ }
+ &daemon_log("$session_id DEBUG: target is own address without forward_to_gosa-tag -> process here", 7);
+ }
+ }
- # target is a client address in known_clients -> process here
+ # target is a client address in known_clients -> process here
if (not $done) {
- $sql = "SELECT * FROM $known_clients_tn WHERE (hostname='$target' OR macaddress LIKE '$target')";
- $res = $known_clients_db->select_dbentry($sql);
- if (keys(%$res) > 0) {
- $done = 1;
- my $hostname = $res->{1}->{'hostname'};
- $msg =~ s/<target>$target<\/target>/<target>$hostname<\/target>/;
- my $local_address = &get_local_ip_for_remote_ip($target_ip).":$server_port";
- if ($source eq "GOSA") {
- $msg =~ s/<\/xml>/<forward_to_gosa>$local_address,$session_id<\/forward_to_gosa><\/xml>/;
- }
- &daemon_log("$session_id DEBUG: target is a client address in known_clients -> process here", 7);
-
- } else {
- $not_found_in_known_clients_db = 1;
- }
- }
+ $sql = "SELECT * FROM $known_clients_tn WHERE (hostname='$target' OR macaddress LIKE '$target')";
+ $res = $known_clients_db->select_dbentry($sql);
+ if (keys(%$res) > 0) {
+ $done = 1;
+ my $hostname = $res->{1}->{'hostname'};
+ $msg =~ s/<target>$target<\/target>/<target>$hostname<\/target>/;
+ my $local_address = &get_local_ip_for_remote_ip($target_ip).":$server_port";
+ if ($source eq "GOSA") {
+ $msg =~ s/<\/xml>/<forward_to_gosa>$local_address,$session_id<\/forward_to_gosa><\/xml>/;
+ }
+ &daemon_log("$session_id DEBUG: target is a client address in known_clients -> process here", 7);
- # target ist own address with forward_to_gosa-tag not pointing to myself -> process here
- if (not $done) {
- my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
- my $gosa_at;
- my $gosa_session_id;
- if (($target eq $local_address) && (defined $forward_to_gosa)){
- my ($gosa_at, $gosa_session_id) = split(/,/, $forward_to_gosa);
- if ($gosa_at ne $local_address) {
- $done = 1;
- &daemon_log("$session_id DEBUG: target is own address with forward_to_gosa-tag not pointing to myself -> process here", 7);
+ } else {
+ $not_found_in_known_clients_db = 1;
}
- }
}
+
+ # target ist own address with forward_to_gosa-tag not pointing to myself -> process here
+ if (not $done) {
+ my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
+ my $gosa_at;
+ my $gosa_session_id;
+ if (($target eq $local_address) && (defined $forward_to_gosa)){
+ my ($gosa_at, $gosa_session_id) = split(/,/, $forward_to_gosa);
+ if ($gosa_at ne $local_address) {
+ $done = 1;
+ &daemon_log("$session_id DEBUG: target is own address with forward_to_gosa-tag not pointing to myself -> process here", 7);
+ }
+ }
+ }
- # if message should be processed here -> add message to incoming_db
+ # if message should be processed here -> add message to incoming_db
if ($done) {
- # if a job or a gosa message comes from a foreign server, fake module to GosaPackages
- # so gosa-si-server knows how to process this kind of messages
- if ($header =~ /^gosa_/ || $header =~ /^job_/) {
- $module = "GosaPackages";
- }
-
- my $res = $incoming_db->add_dbentry( {table=>$incoming_tn,
- primkey=>[],
- headertag=>$header,
- targettag=>$target,
- xmlmessage=>&encode_base64($msg),
- timestamp=>&get_time,
- module=>$module,
- sessionid=>$session_id,
- } );
+ # if a job or a gosa message comes from a foreign server, fake module to GosaPackages
+ # so gosa-si-server knows how to process this kind of messages
+ if ($header =~ /^gosa_/ || $header =~ /^job_/) {
+ $module = "GosaPackages";
+ }
+ my $res = $incoming_db->add_dbentry( {table=>$incoming_tn,
+ primkey=>[],
+ headertag=>$header,
+ targettag=>$target,
+ xmlmessage=>&encode_base64($msg),
+ timestamp=>&get_time,
+ module=>$module,
+ sessionid=>$session_id,
+ } );
}
- # target is own address with forward_to_gosa-tag pointing at myself -> forward to gosa
- if (not $done) {
- my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
- my $gosa_at;
- my $gosa_session_id;
- if (($target eq $local_address) && (defined $forward_to_gosa)){
- my ($gosa_at, $gosa_session_id) = split(/,/, $forward_to_gosa);
- if ($gosa_at eq $local_address) {
- my $session_reference = $kernel->ID_id_to_session($gosa_session_id);
- if( defined $session_reference ) {
- $heap = $session_reference->get_heap();
- }
- if(exists $heap->{'client'}) {
- $msg = &encrypt_msg($msg, $GosaPackages_key);
- $heap->{'client'}->put($msg);
- &daemon_log("$session_id INFO: incoming '$header' message forwarded to GOsa", 5);
- }
- $done = 1;
- &daemon_log("$session_id DEBUG: target is own address with forward_to_gosa-tag pointing at myself -> forward to gosa", 7);
- }
- }
+ # target is own address with forward_to_gosa-tag pointing at myself -> forward to gosa
+ if (not $done) {
+ my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
+ my $gosa_at;
+ my $gosa_session_id;
+ if (($target eq $local_address) && (defined $forward_to_gosa)){
+ my ($gosa_at, $gosa_session_id) = split(/,/, $forward_to_gosa);
+ if ($gosa_at eq $local_address) {
+ my $session_reference = $kernel->ID_id_to_session($gosa_session_id);
+ if( defined $session_reference ) {
+ $heap = $session_reference->get_heap();
+ }
+ if(exists $heap->{'client'}) {
+ $msg = &encrypt_msg($msg, $GosaPackages_key);
+ $heap->{'client'}->put($msg);
+ &daemon_log("$session_id INFO: incoming '$header' message forwarded to GOsa", 5);
+ }
+ $done = 1;
+ &daemon_log("$session_id DEBUG: target is own address with forward_to_gosa-tag pointing at myself -> forward to gosa", 7);
+ }
+ }
- }
+ }
- # target is a client address in foreign_clients -> forward to registration server
- if (not $done) {
- $sql = "SELECT * FROM $foreign_clients_tn WHERE (hostname='$target' OR macaddress LIKE '$target')";
- $res = $foreign_clients_db->select_dbentry($sql);
- if (keys(%$res) > 0) {
- my $hostname = $res->{1}->{'hostname'};
- my ($host_ip, $host_port) = split(/:/, $hostname);
- my $local_address = &get_local_ip_for_remote_ip($host_ip).":$server_port";
- my $regserver = $res->{1}->{'regserver'};
- my $sql = "SELECT * FROM $known_server_tn WHERE hostname='$regserver'";
- my $res = $known_server_db->select_dbentry($sql);
- if (keys(%$res) > 0) {
- my $regserver_key = $res->{1}->{'hostkey'};
- $msg =~ s/<source>GOSA<\/source>/<source>$local_address<\/source>/;
- $msg =~ s/<target>$target<\/target>/<target>$hostname<\/target>/;
- if ($source eq "GOSA") {
- $msg =~ s/<\/xml>/<forward_to_gosa>$local_address,$session_id<\/forward_to_gosa><\/xml>/;
- }
- &send_msg_to_target($msg, $regserver, $regserver_key, $header, $session_id);
- }
- $done = 1;
- &daemon_log("$session_id DEBUG: target is a client address in foreign_clients -> forward to registration server", 7);
- } else {
+ # target is a client address in foreign_clients -> forward to registration server
+ if (not $done) {
+ $sql = "SELECT * FROM $foreign_clients_tn WHERE (hostname='$target' OR macaddress LIKE '$target')";
+ $res = $foreign_clients_db->select_dbentry($sql);
+ if (keys(%$res) > 0) {
+ my $hostname = $res->{1}->{'hostname'};
+ my ($host_ip, $host_port) = split(/:/, $hostname);
+ my $local_address = &get_local_ip_for_remote_ip($host_ip).":$server_port";
+ my $regserver = $res->{1}->{'regserver'};
+ my $sql = "SELECT * FROM $known_server_tn WHERE hostname='$regserver'";
+ my $res = $known_server_db->select_dbentry($sql);
+ if (keys(%$res) > 0) {
+ my $regserver_key = $res->{1}->{'hostkey'};
+ $msg =~ s/<source>GOSA<\/source>/<source>$local_address<\/source>/;
+ $msg =~ s/<target>$target<\/target>/<target>$hostname<\/target>/;
+ if ($source eq "GOSA") {
+ $msg =~ s/<\/xml>/<forward_to_gosa>$local_address,$session_id<\/forward_to_gosa><\/xml>/;
+ }
+ &send_msg_to_target($msg, $regserver, $regserver_key, $header, $session_id);
+ }
+ $done = 1;
+ &daemon_log("$session_id DEBUG: target is a client address in foreign_clients -> forward to registration server", 7);
+ } else {
$not_found_in_foreign_clients_db = 1;
}
- }
+ }
- # target is a server address -> forward to server
- if (not $done) {
- $sql = "SELECT * FROM $known_server_tn WHERE (hostname='$target' OR macaddress LIKE '$target')";
- $res = $known_server_db->select_dbentry($sql);
- if (keys(%$res) > 0) {
- my $hostkey = $res->{1}->{'hostkey'};
+ # target is a server address -> forward to server
+ if (not $done) {
+ $sql = "SELECT * FROM $known_server_tn WHERE (hostname='$target' OR macaddress LIKE '$target')";
+ $res = $known_server_db->select_dbentry($sql);
+ if (keys(%$res) > 0) {
+ my $hostkey = $res->{1}->{'hostkey'};
- if ($source eq "GOSA") {
- $msg =~ s/<source>GOSA<\/source>/<source>$local_address<\/source>/;
- $msg =~ s/<\/xml>/<forward_to_gosa>$local_address,$session_id<\/forward_to_gosa><\/xml>/;
+ if ($source eq "GOSA") {
+ $msg =~ s/<source>GOSA<\/source>/<source>$local_address<\/source>/;
+ $msg =~ s/<\/xml>/<forward_to_gosa>$local_address,$session_id<\/forward_to_gosa><\/xml>/;
- }
+ }
- &send_msg_to_target($msg, $target, $hostkey, $header, $session_id);
- $done = 1;
- &daemon_log("$session_id DEBUG: target is a server address -> forward to server", 7);
- } else {
+ &send_msg_to_target($msg, $target, $hostkey, $header, $session_id);
+ $done = 1;
+ &daemon_log("$session_id DEBUG: target is a server address -> forward to server", 7);
+ } else {
$not_found_in_known_server_db = 1;
}
- }
-
+ }
+
# target is not in foreign_clients_db, known_server_db or known_clients_db, maybe it is a complete new one -> process here
if ( $not_found_in_foreign_clients_db
- && $not_found_in_known_server_db
- && $not_found_in_known_clients_db) {
- my $res = $incoming_db->add_dbentry( {table=>$incoming_tn,
- primkey=>[],
- headertag=>$header,
- targettag=>$target,
- xmlmessage=>&encode_base64($msg),
- timestamp=>&get_time,
- module=>$module,
- sessionid=>$session_id,
- } );
- $done = 1;
- &daemon_log("$session_id DEBUG: target is not in foreign_clients_db, known_server_db or known_clients_db, maybe it is a complete new one -> process here", 7);
+ && $not_found_in_known_server_db
+ && $not_found_in_known_clients_db) {
+ my $res = $incoming_db->add_dbentry( {table=>$incoming_tn,
+ primkey=>[],
+ headertag=>$header,
+ targettag=>$target,
+ xmlmessage=>&encode_base64($msg),
+ timestamp=>&get_time,
+ module=>$module,
+ sessionid=>$session_id,
+ } );
+ $done = 1;
+ &daemon_log("$session_id DEBUG: target is not in foreign_clients_db, known_server_db or known_clients_db, maybe it is a complete new one -> process here", 7);
}
- if (not $done) {
- daemon_log("$session_id ERROR: do not know what to do with this message: $msg", 1);
- if ($source eq "GOSA") {
- my %data = ('error_msg' => &encode_base64($msg), 'error_string' => "Do not know what to do with this message!");
- my $error_msg = &build_msg("error", $local_address, "GOSA", \%data );
-
- my $session_reference = $kernel->ID_id_to_session($session_id);
- if( defined $session_reference ) {
- $heap = $session_reference->get_heap();
- }
- if(exists $heap->{'client'}) {
- $error_msg = &encrypt_msg($error_msg, $GosaPackages_key);
- $heap->{'client'}->put($error_msg);
- }
- }
- }
+ if (not $done) {
+ daemon_log("$session_id ERROR: do not know what to do with this message: $msg", 1);
+ if ($source eq "GOSA") {
+ my %data = ('error_msg' => &encode_base64($msg), 'error_string' => "Do not know what to do with this message!");
+ my $error_msg = &build_msg("error", $local_address, "GOSA", \%data );
- }
+ my $session_reference = $kernel->ID_id_to_session($session_id);
+ if( defined $session_reference ) {
+ $heap = $session_reference->get_heap();
+ }
+ if(exists $heap->{'client'}) {
+ $error_msg = &encrypt_msg($error_msg, $GosaPackages_key);
+ $heap->{'client'}->put($error_msg);
+ }
+ }
+ }
- return;
+ }
+
+ return;
}
my $module = $task->{'module'};
my $header = $task->{'headertag'};
my $session_id = $task->{'sessionid'};
- my $msg_hash;
- eval {
- $msg_hash = $xml->XMLin($msg, ForceArray=>1);
- };
- daemon_log("ERROR: XML failure '$@'") if ($@);
+ my $msg_hash = $xml->XMLin($msg, ForceArray=>1);
my $source = @{$msg_hash->{'source'}}[0];
# set timestamp of incoming client uptodate, so client will not
# check gosa job quaeue for jobs with executable timestamp
my $timestamp = &get_time();
- my $sql_statement = "SELECT * FROM $job_queue_tn WHERE status='waiting' AND (CAST(timestamp AS UNSIGNED)) < $timestamp ORDER BY timestamp";
+ my $sql_statement = "SELECT * FROM $job_queue_tn WHERE status='waiting' AND (CAST (timestamp AS INTEGER)) < $timestamp ORDER BY timestamp";
my $res = $job_db->exec_statement( $sql_statement );
# Merge all new jobs that would do the same actions
# check messaging_db for new incoming messages with executable timestamp
my $timestamp = &get_time();
- my $sql_statement = "SELECT * FROM $messaging_tn WHERE ( (CAST(timestamp AS UNSIGNED))<$timestamp AND flag='n' AND direction='in' )";
+ my $sql_statement = "SELECT * FROM $messaging_tn WHERE ( (CAST(timestamp AS INTEGER))<$timestamp AND flag='n' AND direction='in' )";
my $res = $messaging_db->exec_statement( $sql_statement );
foreach my $hit (@{$res}) {
my $res = $incoming_db->exec_statement($sql);
}
- $kernel->delay_set('watch_for_next_tasks', 1);
+ $kernel->delay_set('watch_for_next_tasks', 0.1);
}
sub create_fai_server_db {
- my ($table_name, $kernel, $dont_create_packages_list, $session_id) = @_;
+ my ($table_name, $kernel, $dont_create_packages_list, $session_id) = @_;
my $result;
if (not defined $session_id) { $session_id = 0; }
- my $ldap_handle = &get_ldap_handle();
+ my $ldap_handle = &get_ldap_handle();
if(defined($ldap_handle)) {
daemon_log("$session_id INFO: create_fai_server_db: start", 5);
my $mesg= $ldap_handle->search(
filter => "(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",
);
if($mesg->{'resultCode'} == 0 &&
- $mesg->count != 0) {
- foreach my $entry (@{$mesg->{entries}}) {
- if($entry->exists('FAIrepository')) {
- # Add an entry for each Repository configured for server
- foreach my $repo(@{$entry->get_value('FAIrepository', asref => 1)}) {
- my($tmp_url,$tmp_server,$tmp_release,$tmp_sections) = split(/\|/, $repo);
- my $tmp_tag= $entry->get_value('gosaUnitTag') || "";
- $result= $fai_server_db->add_dbentry( {
- table => $table_name,
- primkey => ['server', 'fai_release', 'tag'],
- server => $tmp_url,
- fai_release => $tmp_release,
- sections => $tmp_sections,
- tag => (length($tmp_tag)>0)?$tmp_tag:"",
- } );
- }
- }
- }
- }
+ $mesg->count != 0) {
+ foreach my $entry (@{$mesg->{entries}}) {
+ if($entry->exists('FAIrepository')) {
+ # Add an entry for each Repository configured for server
+ foreach my $repo(@{$entry->get_value('FAIrepository', asref => 1)}) {
+ my($tmp_url,$tmp_server,$tmp_release,$tmp_sections) = split(/\|/, $repo);
+ my $tmp_tag= $entry->get_value('gosaUnitTag') || "";
+ $result= $fai_server_db->add_dbentry( {
+ table => $table_name,
+ primkey => ['server', 'release', 'tag'],
+ server => $tmp_url,
+ release => $tmp_release,
+ sections => $tmp_sections,
+ tag => (length($tmp_tag)>0)?$tmp_tag:"",
+ } );
+ }
+ }
+ }
+ }
daemon_log("$session_id INFO: create_fai_server_db: finished", 5);
# TODO: Find a way to post the 'create_packages_list_db' event
&create_packages_list_db(undef, undef, $session_id);
}
}
-
- $ldap_handle->disconnect;
- return $result;
+
+ $ldap_handle->disconnect;
+ return $result;
}
sub run_create_fai_release_db {
- my ($session, $heap, $table_name) = @_[SESSION, HEAP, ARG0];
+ my ($session, $heap, $table_name) = @_[SESSION, HEAP, ARG0];
my $session_id = $session->ID;
- my $task = POE::Wheel::Run->new(
- Program => sub { &create_fai_release_db($table_name, $session_id) },
- StdoutEvent => "session_run_result",
- StderrEvent => "session_run_debug",
- CloseEvent => "session_run_done",
- );
+ my $task = POE::Wheel::Run->new(
+ Program => sub { &create_fai_release_db($table_name, $session_id) },
+ StdoutEvent => "session_run_result",
+ StderrEvent => "session_run_debug",
+ CloseEvent => "session_run_done",
+ );
- $heap->{task}->{ $task->ID } = $task;
- return;
+ $heap->{task}->{ $task->ID } = $task;
+ return;
}
my ($table_name, $session_id) = @_;
my $result;
- # used for logging
- if (not defined $session_id) { $session_id = 0; }
+ # used for logging
+ if (not defined $session_id) { $session_id = 0; }
- my $ldap_handle = &get_ldap_handle();
+ my $ldap_handle = &get_ldap_handle();
if(defined($ldap_handle)) {
daemon_log("$session_id INFO: create_fai_release_db: start",5);
my $mesg= $ldap_handle->search(
if(defined($entry) && ref($entry) eq 'HASH') {
my $sql=
"INSERT INTO $table_name "
- ."(timestamp, fai_release, class, type, state) VALUES ("
+ ."(timestamp, release, class, type, state) VALUES ("
.$timestamp.","
."'".$entry->{'release'}."',"
."'".$entry->{'class'}."',"
daemon_log("$session_id DEBUG: Inserting ".scalar @sql_list." entries to DB",8);
if(@sql_list) {
+ unshift @sql_list, "VACUUM";
unshift @sql_list, "DELETE FROM $table_name";
$fai_release_db->exec_statementlist(\@sql_list);
}
}
daemon_log("$session_id INFO: create_fai_release_db: finished",5);
}
- $ldap_handle->disconnect;
+ $ldap_handle->disconnect;
return $result;
}
if(keys(%repo_dirs)) {
find(\&cleanup_and_extract, keys( %repo_dirs ));
&main::strip_packages_list_statements();
+ unshift @packages_list_statements, "VACUUM";
$packages_list_db->exec_statementlist(\@packages_list_statements);
}
unlink($packages_list_under_construction);
sub cleanup_and_extract {
- my $fileinfo = $repo_files{ $File::Find::name };
+ my $fileinfo = $repo_files{ $File::Find::name };
+
+ if( defined $fileinfo ) {
- if( defined $fileinfo ) {
- my $dir = "$outdir/$fileinfo->{ 'dist' }/debconf.d";
- my $sql;
- my $package = $fileinfo->{ 'package' };
- my $newver = $fileinfo->{ 'version' };
+ my $dir = "$outdir/$fileinfo->{ 'dist' }/debconf.d";
+ my $sql;
+ my $package = $fileinfo->{ 'package' };
+ my $newver = $fileinfo->{ 'version' };
- mkpath($dir);
- system( "dpkg -e '$File::Find::name' '$dir/DEBIAN'" );
+ mkpath($dir);
+ system( "dpkg -e '$File::Find::name' '$dir/DEBIAN'" );
if( -f "$dir/DEBIAN/templates" ) {
daemon_log("DEBUG: Found debconf templates in '$package' - $newver", 7);
- my $tmpl= ""; {
+ my $tmpl= "";
+ {
local $/=undef;
open FILE, "$dir/DEBIAN/templates";
$tmpl = &encode_base64(<FILE>);
rmtree("$dir/DEBIAN/templates");
$sql= "update $main::packages_list_tn set template = '$tmpl' where package = '$package' and version = '$newver';";
- push @packages_list_statements, $sql;
+ push @packages_list_statements, $sql;
}
- }
+ }
- return;
+ return;
}
# connect to incoming_db
unlink($incoming_file_name);
-$incoming_db = GOSA::DBmysql->new($incoming_file_name);
+$incoming_db = GOSA::DBsqlite->new($incoming_file_name);
$incoming_db->create_table($incoming_tn, \@incoming_col_names);
# connect to gosa-si job queue
unlink($job_queue_file_name); ## just for debugging
-$job_db = GOSA::DBmysql->new($job_queue_file_name);
+$job_db = GOSA::DBsqlite->new($job_queue_file_name);
$job_db->create_table($job_queue_tn, \@job_queue_col_names);
chmod(0660, $job_queue_file_name);
chown($root_uid, $adm_gid, $job_queue_file_name);
# connect to known_clients_db
unlink($known_clients_file_name); ## just for debugging
-$known_clients_db = GOSA::DBmysql->new($known_clients_file_name);
+$known_clients_db = GOSA::DBsqlite->new($known_clients_file_name);
$known_clients_db->create_table($known_clients_tn, \@known_clients_col_names);
chmod(0660, $known_clients_file_name);
chown($root_uid, $adm_gid, $known_clients_file_name);
# connect to foreign_clients_db
unlink($foreign_clients_file_name);
-$foreign_clients_db = GOSA::DBmysql->new($foreign_clients_file_name);
+$foreign_clients_db = GOSA::DBsqlite->new($foreign_clients_file_name);
$foreign_clients_db->create_table($foreign_clients_tn, \@foreign_clients_col_names);
chmod(0660, $foreign_clients_file_name);
chown($root_uid, $adm_gid, $foreign_clients_file_name);
# connect to known_server_db
unlink($known_server_file_name);
-$known_server_db = GOSA::DBmysql->new($known_server_file_name);
+$known_server_db = GOSA::DBsqlite->new($known_server_file_name);
$known_server_db->create_table($known_server_tn, \@known_server_col_names);
chmod(0660, $known_server_file_name);
chown($root_uid, $adm_gid, $known_server_file_name);
# connect to login_usr_db
unlink($login_users_file_name);
-$login_users_db = GOSA::DBmysql->new($login_users_file_name);
+$login_users_db = GOSA::DBsqlite->new($login_users_file_name);
$login_users_db->create_table($login_users_tn, \@login_users_col_names);
chmod(0660, $login_users_file_name);
chown($root_uid, $adm_gid, $login_users_file_name);
# connect to fai_server_db
unlink($fai_server_file_name);
-$fai_server_db = GOSA::DBmysql->new($fai_server_file_name);
+$fai_server_db = GOSA::DBsqlite->new($fai_server_file_name);
$fai_server_db->create_table($fai_server_tn, \@fai_server_col_names);
chmod(0660, $fai_server_file_name);
chown($root_uid, $adm_gid, $fai_server_file_name);
# connect to fai_release_db
unlink($fai_release_file_name);
-$fai_release_db = GOSA::DBmysql->new($fai_release_file_name);
+$fai_release_db = GOSA::DBsqlite->new($fai_release_file_name);
$fai_release_db->create_table($fai_release_tn, \@fai_release_col_names);
chmod(0660, $fai_release_file_name);
chown($root_uid, $adm_gid, $fai_release_file_name);
# connect to packages_list_db
#unlink($packages_list_file_name);
unlink($packages_list_under_construction);
-$packages_list_db = GOSA::DBmysql->new($packages_list_file_name);
+$packages_list_db = GOSA::DBsqlite->new($packages_list_file_name);
$packages_list_db->create_table($packages_list_tn, \@packages_list_col_names);
chmod(0660, $packages_list_file_name);
chown($root_uid, $adm_gid, $packages_list_file_name);
# connect to messaging_db
unlink($messaging_file_name);
-$messaging_db = GOSA::DBmysql->new($messaging_file_name);
+$messaging_db = GOSA::DBsqlite->new($messaging_file_name);
$messaging_db->create_table($messaging_tn, \@messaging_col_names);
chmod(0660, $messaging_file_name);
chown($root_uid, $adm_gid, $messaging_file_name);
POE::Component::Server::TCP->new(
- Alias => "TCP_SERVER",
+ Alias => "TCP_SERVER",
Port => $server_port,
ClientInput => sub {
- my ($kernel, $input) = @_[KERNEL, ARG0];
- push(@tasks, $input);
- push(@msgs_to_decrypt, $input);
- $kernel->yield("msg_to_decrypt");
- },
- InlineStates => {
- msg_to_decrypt => \&msg_to_decrypt,
- next_task => \&next_task,
- task_result => \&handle_task_result,
- task_done => \&handle_task_done,
- task_debug => \&handle_task_debug,
- child_reap => sub { "Do nothing special. I'm just a comment, but i'm necessary!" },
- }
+ my ($kernel, $input) = @_[KERNEL, ARG0];
+ push(@tasks, $input);
+ push(@msgs_to_decrypt, $input);
+ $kernel->yield("msg_to_decrypt");
+ },
+ InlineStates => {
+ msg_to_decrypt => \&msg_to_decrypt,
+ next_task => \&next_task,
+ task_result => \&handle_task_result,
+ task_done => \&handle_task_done,
+ task_debug => \&handle_task_debug,
+ child_reap => sub { "Do nothing special. I'm just a comment, but i'm necessary!" },
+ }
);
daemon_log("start socket for incoming xml messages at port '$server_port' ", 1);
diff --git a/gosa-si/modules/DBmysql.pm b/gosa-si/modules/DBmysql.pm
+++ /dev/null
@@ -1,343 +0,0 @@
-package GOSA::DBmysql;
-
-use strict;
-use warnings;
-use DBI;
-use Data::Dumper;
-use GOSA::GosaSupportDaemon;
-use Time::HiRes qw(usleep);
-
-my $col_names = {};
-
-sub new {
- my $class = shift;
-
- my $self = {dbh=>undef};
- my $dbh = DBI->connect("dbi:mysql:database=$main::mysql_database;host=$main::mysql_host", $main::mysql_username, $main::mysql_password,{ RaiseError => 1, AutoCommit => 1 });
- $dbh->{mysql_auto_reconnect} = 1;
- $self->{dbh} = $dbh;
- bless($self,$class);
-
- return($self);
-}
-
-
-sub create_table {
- my $self = shift;
- my $table_name = shift;
- my $col_names_ref = shift;
- my $recreate_table = shift || 0;
- my @col_names;
- my $col_names_string = join(", ", @$col_names_ref);
-
- if($recreate_table) {
- $self->{dbh}->do("DROP TABLE $table_name");
- }
- my $sql_statement = "CREATE TABLE IF NOT EXISTS $table_name ( $col_names_string )";
- # &main::daemon_log("DEBUG: $sql_statement");
- eval {
- $self->{dbh}->do($sql_statement);
- };
- if($@) {
- &main::daemon_log("ERROR: $sql_statement failed with $@", 1);
- }
-
- return 0;
-}
-
-
-sub add_dbentry {
- my $self = shift;
- my $arg = shift;
- my $res = 0; # default value
-
- # if dbh not specified, return errorflag 1
- my $table = $arg->{table};
- if( not defined $table ) {
- return 1 ;
- }
-
- # if timestamp is not provided, add timestamp
- if( not exists $arg->{timestamp} ) {
- $arg->{timestamp} = &get_time;
- }
-
- # check primkey and run insert or update
- my $primkeys = $arg->{'primkey'};
- my $prim_statement="";
- if( 0 != @$primkeys ) { # more than one primkey exist in list
- my @prim_list;
- foreach my $primkey (@$primkeys) {
- if( not exists $arg->{$primkey} ) {
- return (3, "primkey '$primkey' has no value for add_dbentry");
- }
- push(@prim_list, "$primkey='".$arg->{$primkey}."'");
- }
- $prim_statement = "WHERE ".join(" AND ", @prim_list);
-
- # check wether primkey is unique in table, otherwise return errorflag
- my $sql_statement = "SELECT * FROM $table $prim_statement";
- eval {
- # &main::daemon_log("DEBUG: $sql_statement");
- my $sth = $self->{dbh}->prepare($sql_statement);
- $sth->execute;
- $res = @{ $sth->fetchall_arrayref() };
- $sth->finish;
- };
- if($@) {
- &main::daemon_log("ERROR: $sql_statement failed with $@", 1);
- }
-
- }
-
- # primkey is unique or no primkey specified -> run insert
- if ($res == 0) {
- # fetch column names of table
- my $col_names = &get_table_columns($self, $table);
-
- #my $create_id=0;
- #foreach my $col_name (@{$col_names}) {
- # #if($col_name eq "id" && (! exists $arg->{$col_name})) {
- # #&main::daemon_log("0 DEBUG: id field found without value! Creating autoincrement statement!", 7);
- # $create_id=1;
- # }
- #}
-
- # assign values to column name variables
- my @col_list;
- my @val_list;
- foreach my $col_name (@{$col_names}) {
- # use function parameter for column values
- if (exists $arg->{$col_name}) {
- push(@col_list, $col_name);
- push(@val_list, "'".$arg->{$col_name}."'");
- }
- }
-
- my $sql_statement;
- #if($create_id==1) {
- # $sql_statement = "INSERT INTO $table (id, ".join(", ", @col_list).") VALUES ((select coalesce(max(id),0)+1), ".join(", ", @val_list).")";
- #} else {
- $sql_statement = "INSERT INTO $table (".join(", ", @col_list).") VALUES (".join(", ", @val_list).")";
- #}
- my $db_res;
- # &main::daemon_log("DEBUG: $sql_statement",1);
- eval {
- $db_res = $self->{dbh}->do($sql_statement);
- };
- if($@) {
- &main::daemon_log("ERROR: $sql_statement failed with $@", 1);
- }
-
- if( $db_res != 1 ) {
- return (4, $sql_statement);
- }
-
- # entry already exists -> run update
- } else {
- my @update_l;
- while( my ($pram, $val) = each %{$arg} ) {
- if( $pram eq 'table' ) { next; }
- if( $pram eq 'primkey' ) { next; }
- push(@update_l, "$pram='$val'");
- }
- my $update_str= join(", ", @update_l);
- $update_str= " SET $update_str";
-
- my $sql_statement= "UPDATE $table $update_str $prim_statement";
- my $db_res = &update_dbentry($self, $sql_statement );
- }
-
- return 0;
-}
-
-
-sub update_dbentry {
- my ($self, $sql)= @_;
- my $db_answer= &exec_statement($self, $sql);
- return $db_answer;
-}
-
-
-sub del_dbentry {
- my ($self, $sql)= @_;
- my $db_res= &exec_statement($self, $sql);
- return $db_res;
-}
-
-
-sub get_table_columns {
- my $self = shift;
- my $table = shift;
- my @column_names;
-
- my @res;
- eval {
- my $sth = $self->{dbh}->prepare("describe $table") or &main::daemon_log("ERROR: Preparation of statement 'describe $table' failed!", 1);
- $sth->execute or &main::daemon_log("ERROR: Execution of statement 'describe $table' failed!", 1);
- @res = @{ $sth->fetchall_arrayref() };
- $sth->finish or &main::daemon_log("ERROR: Finishing the statement handle failed!", 1);
- };
- if($@) {
- &main::daemon_log("ERROR: describe ('$table') failed with $@", 1);
- }
-
- foreach my $column (@res) {
- push(@column_names, @$column[0]);
- }
-
- return \@column_names;
-}
-
-
-sub select_dbentry {
- my ($self, $sql)= @_;
- my $error= 0;
- my $answer= {};
- my $db_answer= &exec_statement($self, $sql);
- my @column_list;
-
- # fetch column list of db and create a hash with column_name->column_value of the select query
- $sql =~ /SELECT ([\S\s]*?) FROM ([\S]*?)( |$)/g;
- my $selected_cols = $1;
- my $table = $2;
-
- # all columns are used for creating answer
- if ($selected_cols eq '*') {
- @column_list = @{ &get_table_columns($self, $table) };
-
- # specific columns are used for creating answer
- } else {
- # remove all blanks and split string to list of column names
- $selected_cols =~ s/ //g;
- @column_list = split(/,/, $selected_cols);
- }
-
- # create answer
- my $hit_counter = 0;
- my $list_len = @column_list;
- foreach my $hit ( @{$db_answer} ){
- $hit_counter++;
- for ( my $i = 0; $i < $list_len; $i++) {
- $answer->{ $hit_counter }->{ $column_list[$i] } = @{ $hit }[$i];
- }
- }
-
- return $answer;
-}
-
-
-sub show_table {
- my $self = shift;
- my $table_name = shift;
-
- my $sql_statement= "SELECT * FROM $table_name ORDER BY timestamp";
- my $res= &exec_statement($self, $sql_statement);
- my @answer;
- foreach my $hit (@{$res}) {
- push(@answer, "hit: ".join(', ', @{$hit}));
- }
-
- return join("\n", @answer);
-}
-
-
-sub exec_statement {
- my $self = shift;
- my $sql_statement = shift;
- my $sth;
- my @db_answer;
-
- # print STDERR Dumper($sql_statement);
- eval {
- if($sql_statement =~ /^SELECT/i) {
- $sth = $self->{dbh}->prepare($sql_statement) or &main::daemon_log("ERROR: Preparation of statement '$sql_statement' failed!", 1);
- $sth->execute or &main::daemon_log("ERROR: Execution of statement '$sql_statement' failed!", 1);
- if($sth->rows > 0) {
- @db_answer = @{ $sth->fetchall_arrayref() } or &main::daemon_log("ERROR: Fetch() failed!", 1);
- # print STDERR Dumper(@db_answer);
- }
- $sth->finish or &main::daemon_log("ERROR: Finishing the statement handle failed!", 1);
- } else {
- $self->{dbh}->do($sql_statement);
- }
- };
- if($@) {
- &main::daemon_log("ERROR: $sql_statement failed with '$@'", 1);
- }
- # TODO : maybe an error handling and an erro feedback to invoking function
- my $error = $self->{dbh}->err;
- if ($error) {
- &main::daemon_log("ERROR: ".@$self->{dbh}->errstr, 1);
- }
-
- return \@db_answer;
-}
-
-
-sub exec_statementlist {
- my $self = shift;
- my $sql_list = shift;
- my @db_answer;
-
- foreach my $sql (@$sql_list) {
- if(defined($sql) && length($sql) > 0) {
- # &main::daemon_log("DEBUG: $sql");
- eval {
- if($sql =~ /^SELECT/i) {
- my $sth = $self->{dbh}->prepare($sql);
- # &main::daemon_log("DEBUG: ".$sth->execute);
- if($sth->rows > 0) {
- my @answer = @{$sth->fetchall_arrayref()};
- push @db_answer, @answer;
- }
- $sth->finish;
- } else {
- $self->{dbh}->do($sql);
- }
- };
- if($@) {
- &main::daemon_log("ERROR: $sql failed with $@", 1);
- }
- } else {
- next;
- }
- }
-
- return \@db_answer;
-}
-
-
-sub count_dbentries {
- my ($self, $table)= @_;
- my $error= 0;
- my $answer= -1;
-
- my $sql_statement= "SELECT * FROM $table";
- my $db_answer= &select_dbentry($self, $sql_statement);
-
- my $count = keys(%{$db_answer});
- return $count;
-}
-
-
-sub move_table {
- my ($self, $from, $to) = @_;
-
- my $sql_statement_drop = "DROP TABLE IF EXISTS $to";
- my $sql_statement_alter = "ALTER TABLE $from RENAME TO $to";
-
- eval {
- $self->{dbh}->do($sql_statement_drop);
- $self->{dbh}->do($sql_statement_alter);
- };
-
- if($@) {
- &main::daemon_log("ERROR: $sql_statement_drop failed with $@", 1);
- }
-
- return;
-}
-
-
-1;
diff --git a/gosa-si/modules/DBsqlite.pm b/gosa-si/modules/DBsqlite.pm
--- /dev/null
@@ -0,0 +1,382 @@
+package GOSA::DBsqlite;
+
+
+use strict;
+use warnings;
+use DBI;
+use Data::Dumper;
+use GOSA::GosaSupportDaemon;
+use Time::HiRes qw(usleep);
+
+
+my $col_names = {};
+
+sub new {
+ my $class = shift;
+ my $db_name = shift;
+
+ my $lock = $db_name.".si.lock";
+ # delete existing lock - instance should be running only once
+ if(stat($lock)) {
+ &main::daemon_log("DEBUG: Removed existing lock $lock.", 7);
+ unlink($lock);
+ }
+ my $self = {dbh=>undef,db_name=>undef,db_lock=>undef,db_lock_handle=>undef};
+ my $dbh = DBI->connect("dbi:SQLite:dbname=$db_name", "", "", {RaiseError => 1, AutoCommit => 1});
+ $self->{dbh} = $dbh;
+ $self->{db_name} = $db_name;
+ $self->{db_lock} = $lock;
+
+ bless($self,$class);
+ return($self);
+}
+
+
+sub create_table {
+ my $self = shift;
+ my $table_name = shift;
+ my $col_names_ref = shift;
+ my @col_names;
+ foreach my $col_name (@$col_names_ref) {
+ my @t = split(" ", $col_name);
+ $col_name = $t[0];
+ push(@col_names, $col_name);
+ }
+
+ $col_names->{ $table_name } = $col_names_ref;
+ my $col_names_string = join("', '", @col_names);
+ my $sql_statement = "CREATE TABLE IF NOT EXISTS $table_name ( '$col_names_string' )";
+ eval {
+ my $res = $self->{dbh}->do($sql_statement);
+ };
+ if($@) {
+ $self->{dbh}->do("ANALYZE");
+ }
+ eval {
+ my $res = $self->{dbh}->do($sql_statement);
+ };
+ if($@) {
+ &main::daemon_log("ERROR: $sql_statement failed with $@", 1);
+ }
+
+ return 0;
+}
+
+
+sub add_dbentry {
+ my $self = shift;
+ my $arg = shift;
+ my $res = 0; # default value
+
+ # if dbh not specified, return errorflag 1
+ my $table = $arg->{table};
+ if( not defined $table ) {
+ return 1 ;
+ }
+
+ # if timestamp is not provided, add timestamp
+ if( not exists $arg->{timestamp} ) {
+ $arg->{timestamp} = &get_time;
+ }
+
+ # check primkey and run insert or update
+ my $primkeys = $arg->{'primkey'};
+ my $prim_statement="";
+ if( 0 != @$primkeys ) { # more than one primkey exist in list
+ my @prim_list;
+ foreach my $primkey (@$primkeys) {
+ if( not exists $arg->{$primkey} ) {
+ return (3, "primkey '$primkey' has no value for add_dbentry");
+ }
+ push(@prim_list, "$primkey='".$arg->{$primkey}."'");
+ }
+ $prim_statement = "WHERE ".join(" AND ", @prim_list);
+
+ # check wether primkey is unique in table, otherwise return errorflag
+ my $sql_statement = "SELECT * FROM $table $prim_statement";
+ eval {
+ $res = @{ $self->{dbh}->selectall_arrayref($sql_statement) };
+ };
+ if($@) {
+ $self->{dbh}->do("ANALYZE");
+ eval {
+ $res = @{ $self->{dbh}->selectall_arrayref($sql_statement) };
+ };
+ if($@) {
+ &main::daemon_log("ERROR: $sql_statement failed with $@", 1);
+ }
+ }
+
+ }
+
+ # primkey is unique or no primkey specified -> run insert
+ if ($res == 0) {
+ # fetch column names of table
+ my $col_names = &get_table_columns($self, $table);
+
+ my $create_id=0;
+ foreach my $col_name (@{$col_names}) {
+ if($col_name eq "id" && (! exists $arg->{$col_name})) {
+ #&main::daemon_log("0 DEBUG: id field found without value! Creating autoincrement statement!", 7);
+ $create_id=1;
+ }
+ }
+
+ # assign values to column name variables
+ my @col_list;
+ my @val_list;
+ foreach my $col_name (@{$col_names}) {
+ # use function parameter for column values
+ if (exists $arg->{$col_name}) {
+ push(@col_list, "'".$col_name."'");
+ push(@val_list, "'".$arg->{$col_name}."'");
+ }
+ }
+
+ my $sql_statement;
+ if($create_id==1) {
+ $sql_statement = "INSERT INTO $table ('id', ".join(", ", @col_list).") VALUES ((select coalesce(max(id), 0)+1 from $table), ".join(", ", @val_list).")";
+ } else {
+ $sql_statement = "INSERT INTO $table (".join(", ", @col_list).") VALUES (".join(", ", @val_list).")";
+ }
+ my $db_res;
+ eval {
+ $db_res = $self->{dbh}->do($sql_statement);
+ };
+ if($@) {
+ $self->{dbh}->do("ANALYZE");
+ eval {
+ $db_res = $self->{dbh}->do($sql_statement);
+ };
+ if($@) {
+ &main::daemon_log("ERROR: $sql_statement failed with $@", 1);
+ }
+ }
+
+ if( $db_res != 1 ) {
+ return (4, $sql_statement);
+ }
+
+ # entry already exists -> run update
+ } else {
+ my @update_l;
+ while( my ($pram, $val) = each %{$arg} ) {
+ if( $pram eq 'table' ) { next; }
+ if( $pram eq 'primkey' ) { next; }
+ push(@update_l, "$pram='$val'");
+ }
+ my $update_str= join(", ", @update_l);
+ $update_str= " SET $update_str";
+
+ my $sql_statement= "UPDATE $table $update_str $prim_statement";
+ my $db_res = &update_dbentry($self, $sql_statement );
+ }
+
+ return 0;
+}
+
+
+sub update_dbentry {
+ my ($self, $sql)= @_;
+ my $db_answer= &exec_statement($self, $sql);
+ return $db_answer;
+}
+
+
+sub del_dbentry {
+ my ($self, $sql)= @_;;
+ my $db_res= &exec_statement($self, $sql);
+ return $db_res;
+}
+
+
+sub get_table_columns {
+ my $self = shift;
+ my $table = shift;
+ my @column_names;
+
+ if(exists $col_names->{$table}) {
+ @column_names = @{$col_names->{$table}};
+ } else {
+ my @res;
+ eval {
+ @res = @{$self->{dbh}->selectall_arrayref("pragma table_info('$table')")};
+ };
+ if($@) {
+ $self->{dbh}->do("ANALYZE");
+ eval {
+ @res = @{$self->{dbh}->selectall_arrayref("pragma table_info('$table')")};
+ };
+ if($@) {
+ &main::daemon_log("ERROR: pragma table_info('$table') failed with $@", 1);
+ }
+ }
+
+ foreach my $column (@res) {
+ push(@column_names, @$column[1]);
+ }
+ }
+ return \@column_names;
+
+}
+
+
+sub select_dbentry {
+ my ($self, $sql)= @_;
+ my $error= 0;
+ my $answer= {};
+ my $db_answer= &exec_statement($self, $sql);
+ my @column_list;
+
+ # fetch column list of db and create a hash with column_name->column_value of the select query
+ $sql =~ /SELECT ([\S\s]*?) FROM ([\S]*?)( |$)/g;
+ my $selected_cols = $1;
+ my $table = $2;
+
+ # all columns are used for creating answer
+ if ($selected_cols eq '*') {
+ @column_list = @{ &get_table_columns($self, $table) };
+
+ # specific columns are used for creating answer
+ } else {
+ # remove all blanks and split string to list of column names
+ $selected_cols =~ s/ //g;
+ @column_list = split(/,/, $selected_cols);
+ }
+
+ # create answer
+ my $hit_counter = 0;
+ my $list_len = @column_list;
+ foreach my $hit ( @{$db_answer} ){
+ $hit_counter++;
+ for ( my $i = 0; $i < $list_len; $i++) {
+ $answer->{ $hit_counter }->{ $column_list[$i] } = @{ $hit }[$i];
+ }
+ }
+
+ return $answer;
+}
+
+
+sub show_table {
+ my $self = shift;
+ my $table_name = shift;
+
+ my $sql_statement= "SELECT * FROM $table_name ORDER BY timestamp";
+ my $res= &exec_statement($self, $sql_statement);
+ my @answer;
+ foreach my $hit (@{$res}) {
+ push(@answer, "hit: ".join(', ', @{$hit}));
+ }
+
+ return join("\n", @answer);
+}
+
+
+sub exec_statement {
+ my $self = shift;
+ my $sql_statement = shift;
+ my @db_answer;
+
+ eval {
+ @db_answer = @{$self->{dbh}->selectall_arrayref($sql_statement)};
+ };
+ if($@) {
+ $self->{dbh}->do("ANALYZE");
+ eval {
+ @db_answer = @{$self->{dbh}->selectall_arrayref($sql_statement)};
+ };
+ if($@) {
+ &main::daemon_log("ERROR: $sql_statement failed with $@", 1);
+ }
+ }
+ # TODO : maybe an error handling and an erro feedback to invoking function
+ #my $error = @$self->{dbh}->err;
+ #if ($error) {
+ # my $error_string = @$self->{dbh}->errstr;
+ #}
+
+ return \@db_answer;
+}
+
+
+sub exec_statementlist {
+ my $self = shift;
+ my $sql_list = shift;
+ my @db_answer;
+
+ foreach my $sql (@$sql_list) {
+ if(defined($sql) && length($sql) > 0) {
+ eval {
+ my @answer = @{$self->{dbh}->selectall_arrayref($sql)};
+ push @db_answer, @answer;
+ };
+ if($@) {
+ $self->{dbh}->do("ANALYZE");
+ eval {
+ my @answer = @{$self->{dbh}->selectall_arrayref($sql)};
+ push @db_answer, @answer;
+ };
+ if($@) {
+ &main::daemon_log("ERROR: $sql failed with $@", 1);
+ }
+ }
+ } else {
+ next;
+ }
+ }
+
+ return \@db_answer;
+}
+
+
+sub count_dbentries {
+ my ($self, $table)= @_;
+ my $error= 0;
+ my $answer= -1;
+
+ my $sql_statement= "SELECT * FROM $table";
+ my $db_answer= &select_dbentry($self, $sql_statement);
+
+ my $count = keys(%{$db_answer});
+ return $count;
+}
+
+
+sub move_table {
+ my ($self, $from, $to) = @_;
+
+ my $sql_statement_drop = "DROP TABLE IF EXISTS $to";
+ my $sql_statement_alter = "ALTER TABLE $from RENAME TO $to";
+
+ eval {
+ $self->{dbh}->do($sql_statement_drop);
+ };
+ if($@) {
+ $self->{dbh}->do("ANALYZE");
+ eval {
+ $self->{dbh}->do($sql_statement_drop);
+ };
+ if($@) {
+ &main::daemon_log("ERROR: $sql_statement_drop failed with $@", 1);
+ }
+ }
+
+ eval {
+ $self->{dbh}->do($sql_statement_alter);
+ };
+ if($@) {
+ $self->{dbh}->do("ANALYZE");
+ eval {
+ $self->{dbh}->do($sql_statement_alter);
+ };
+ if($@) {
+ &main::daemon_log("ERROR: $sql_statement_alter failed with $@", 1);
+ }
+ }
+
+ return;
+}
+
+
+1;
index 17a731bab481a6e701b1116f1c57a743b8e81728..a2cf9f040096fde021aa4a1acb4512aaed2a4f7c 100644 (file)
use XML::Simple;
use File::Spec;
use Data::Dumper;
-use GOSA::DBmysql;
+use GOSA::DBsqlite;
use MIME::Base64;
my $event_dir = "/usr/lib/gosa-si/server/GosaPackages";
index e91aa4639d7eb7ab9ea45362e71116ccc038b3c0..d49a4a381ebcb5404d9b4529026e0bbeb73d3aac 100644 (file)
# determine new message id
my $new_msg_id = 1;
- my $new_msg_id_sql = "SELECT MAX(id) FROM $main::messaging_tn";
+ my $new_msg_id_sql = "SELECT MAX(CAST(id AS INTEGER)) FROM $main::messaging_tn";
my $new_msg_id_res = $main::messaging_db->exec_statement($new_msg_id_sql);
if (defined @{@{$new_msg_id_res}[0]}[0] ) {
$new_msg_id = int(@{@{$new_msg_id_res}[0]}[0]);
sub get_available_kernel {
- my ($msg, $msg_hash, $session_id) = @_;
-
- my $source = @{$msg_hash->{'source'}}[0];
- my $target = @{$msg_hash->{'target'}}[0];
- my $fai_release= @{$msg_hash->{'fai_release'}}[0];
-
- my @kernel;
- # Get Kernel packages for release
- my $sql_statement = "SELECT * FROM $main::packages_list_tn WHERE distribution='$fai_release' AND package LIKE 'linux\-image\-%'";
- my $res_hash = $main::packages_list_db->select_dbentry($sql_statement);
- my %data;
- my $i=1;
-
- foreach my $package (keys %{$res_hash}) {
- $data{"answer".$i++}= $data{"answer".$i++}= ${$res_hash}{$package}->{'package'};
- }
- $data{"answer".$i++}= "default";
-
- my $out_msg = &build_msg("get_available_kernel", $target, $source, \%data);
- my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
- if (defined $forward_to_gosa) {
- $out_msg =~s/<\/xml>/<forward_to_gosa>$forward_to_gosa<\/forward_to_gosa><\/xml>/;
- }
-
- return ( $out_msg );
+ my ($msg, $msg_hash, $session_id) = @_;
+
+ my $source = @{$msg_hash->{'source'}}[0];
+ my $target = @{$msg_hash->{'target'}}[0];
+ my $release= @{$msg_hash->{'release'}}[0];
+
+ my @kernel;
+ # Get Kernel packages for release
+ my $sql_statement = "SELECT * FROM $main::packages_list_tn WHERE distribution='$release' AND package LIKE 'linux\-image\-%'";
+ my $res_hash = $main::packages_list_db->select_dbentry($sql_statement);
+ my %data;
+ my $i=1;
+
+ foreach my $package (keys %{$res_hash}) {
+ $data{"answer".$i++}= $data{"answer".$i++}= ${$res_hash}{$package}->{'package'};
+ }
+ $data{"answer".$i++}= "default";
+
+ my $out_msg = &build_msg("get_available_kernel", $target, $source, \%data);
+ my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
+ if (defined $forward_to_gosa) {
+ $out_msg =~s/<\/xml>/<forward_to_gosa>$forward_to_gosa<\/forward_to_gosa><\/xml>/;
+ }
+
+ return ( $out_msg );
}