summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 22a19f3)
raw | patch | inline | side by side (parent: 22a19f3)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 20 Aug 2008 14:04:46 +0000 (14:04 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 20 Aug 2008 14:04:46 +0000 (14:04 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12255 594d385d-05f5-0310-b6e9-bd551577e9d8
index f74f595d7e8782899737e108b5ff5d5b8ef043bf..acf03be3c4cf640ae7be602f17ab275a7ef5752c 100644 (file)
my @events = (
"get_events",
"registered",
+ 'new_syslog_config',
"new_ntp_config",
"new_ldap_config",
"new_key",
my ($ldap_enabled, $offline_enabled, $ldap_config, $pam_config, $nss_config, $fai_logpath);
my $chrony_file = "/etc/chrony/chrony.conf";
+my $syslog_file = "/etc/syslog.conf";
my %cfg_defaults = (
"client" => {
return;
}
+
+## @method new_syslog_config
+# Update or add syslog messages forwarding to specified syslog server.
+# @param msg - STRING - xml message with tag server
+# @param msg_hash - HASHREF - message information parsed into a hash
+sub new_syslog_config {
+ my ($msg, $msg_hash) = @_ ;
+
+ # Sanity check of incoming message
+ if ((not exists $msg_hash->{'server'}) || (not @{$msg_hash->{'server'}} == 1) ) {
+ &main::daemon_log("ERROR: 'new_syslog_config'-message does not contain a syslog server: $msg", 1);
+ return;
+ }
+
+ # Fetch the new syslog server from incoming message
+ my $syslog_server = @{$msg_hash->{'server'}}[0];
+ &main::daemon_log("INFO: found syslog server: ".join(", ", $syslog_server), 5);
+ my $found_server_flag = 0;
+
+ # Sanity check of /etc/syslog.conf
+ if (not -f $syslog_file) {
+ &main::daemon_log("ERROR: file '$syslog_file' does not exist, cannot do syslog reconfiguration!", 1);
+ return;
+ }
+
+ # Substitute existing server with new syslog server
+ open (FILE, "<$syslog_file");
+ my @file = <FILE>;
+ close FILE;
+ my $syslog_server_line = "*.*\t@".$syslog_server."\n";
+ foreach my $line (@file) {
+ if ($line =~ /^\*\.\*\s+@/) {
+ $line = $syslog_server_line;
+ $found_server_flag++;
+ }
+ }
+
+ # Append new server if no old server configuration found
+ if (not $found_server_flag) {
+ push(@file, "\n#\n# syslog server configuration written by GOsa-si\n#\n");
+ push(@file, $syslog_server_line);
+ }
+
+ # Write changes to file and close it
+ open (FILE, "+>$syslog_file");
+ print FILE join("", @file);
+ close FILE;
+ &main::daemon_log("INFO: wrote new configuration file: $syslog_file", 5);
+
+ # Restart syslog deamon
+ my $res = qx(/etc/init.d/sysklogd restart);
+ &main::daemon_log("INFO: restart syslog daemon: \n$res", 5);
+
+ return;
+}
+
+
## @method new_ntp_config
# Updates the server options in /etc/chrony/chrony.conf and restarts the chrony service
# @param msg - STRING - xml message with tag server
diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index 2e362facd328da98c6a5a7003786c429a1507141..bb6c6e8816132dcb7c8883da00f54a0ca4f8483b 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
}
}
- # Estimate "rough" progress
- $result->{'progress'}= int($installed * 100 / $products);
+ # Estimate "rough" progress, avoid division by zero
+ if ($products == 0) {
+ $result->{'progress'}= 0;
+ } else {
+ $result->{'progress'}= int($installed * 100 / $products);
+ }
# Set updates in job queue
if ((not $error) && (not $installing) && ($installed)) {
index 270cda8ab5f41333eaf85f8ff3a017fa960802c6..b2a5288d635386cd1648cb083887a3dbebd87ebc 100644 (file)
}
+sub new_syslog_config {
+ my ($mac_address, $session_id) = @_;
+ my $syslog_msg;
+
+ # Build LDAP connection
+ my $ldap_handle = &main::get_ldap_handle($session_id);
+ if( not defined $ldap_handle ) {
+ &main::daemon_log("$session_id ERROR: cannot connect to ldap: $ldap_uri", 1);
+ return;
+ }
+
+ # Perform search
+ my $ldap_res = $ldap_handle->search( base => $ldap_base,
+ scope => 'sub',
+ attrs => ['gotoSyslogServer'],
+ filter => "(&(objectClass=GOhard)(macaddress=$mac_address))");
+ if($ldap_res->code) {
+ &main::daemon_log("$session_id ".$ldap_res->error, 1);
+ return;
+ }
+
+ # Sanity check
+ if ($ldap_res->count != 1) {
+ &main::daemon_log("$session_id ERROR: client with mac address $mac_address not found/unique/active - not sending syslog config".
+ "\n\tbase: $ldap_base".
+ "\n\tscope: sub".
+ "\n\tattrs: gotoSyslogServer".
+ "\n\tfilter: (&(objectClass=GOhard)(macaddress=$mac_address))", 1);
+ return;
+ }
+
+ my $entry= $ldap_res->entry(0);
+ my $dn = &Net::LDAP::Util::escape_dn_value($entry->dn);
+ my $syslog_server = $entry->get_value("gotoSyslogServer");
+
+ # If no syslog server is specified at host, just have a look at the object group of the host
+ # Perform object group search
+ if (not defined $syslog_server) {
+ my $ldap_res = $ldap_handle->search( base => $ldap_base,
+ scope => 'sub',
+ attrs => ['gotoSyslogServer'],
+ filter => "(&(objectClass=gosaGroupOfNames)(member=$dn))");
+ if($ldap_res->code) {
+ &main::daemon_log("$session_id ".$ldap_res->error, 1);
+ return;
+ }
+
+ # Sanity check
+ if ($ldap_res->count != 1) {
+ &main::daemon_log("$session_id ERROR: client with mac address $mac_address not found/unique/active - not sending syslog config".
+ "\n\tbase: $ldap_base".
+ "\n\tscope: sub".
+ "\n\tattrs: gotoSyslogServer".
+ "\n\tfilter: (&(objectClass=gosaGroupOfNames)(member=$dn))", 1);
+ return;
+ }
+
+ my $entry= $ldap_res->entry(0);
+ $syslog_server= $entry->get_value("gotoSyslogServer");
+ }
+
+ # Return if no syslog server specified
+ if (not defined $syslog_server) {
+ &main::daemon_log("$session_id WARNING: no syslog server specified for this host '$mac_address'", 3);
+ return;
+ }
+
+ # Add syslog server to 'syslog_config' message
+ my $syslog_msg_hash = &create_xml_hash("new_syslog_config", $server_address, $mac_address);
+ &add_content2xml_hash($syslog_msg_hash, "server", $syslog_server);
+
+ return &create_xml_string($syslog_msg_hash);
+}
+
+
sub new_ntp_config {
my ($address, $session_id) = @_;
my $ntp_msg;
index 2f74dfd7678e3bf3a55a78bf68f878437453f840..d4d7ddd9f0308edc2f232eaf4c5912132cc0156e 100644 (file)
"get_login_usr_for_client",
"get_client_for_login_usr",
"gen_smb_hash",
+ "trigger_reload_syslog_config",
"trigger_reload_ntp_config",
"trigger_reload_ldap_config",
"ping",
}
+sub trigger_reload_syslog_config {
+ my ($msg, $msg_hash, $session_id) = @_ ;
+
+ # Sanity check of macaddress
+ # TODO
+
+ my $macaddress = @{$msg_hash->{macaddress}}[0];
+
+ my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
+ }
+
+ my $out_msg = &ClientPackages::new_syslog_config($macaddress, $session_id);
+ my @out_msg_l = ( $out_msg );
+
+ return @out_msg_l;
+
+
+}
+
sub trigger_reload_ntp_config {
my ($msg, $msg_hash, $session_id) = @_ ;
- my $target = @{$msg_hash->{target}}[0];
# Sanity check of macaddress
# TODO
index 870e54927003a3f7c5523d69c0d59b5a7bb5782c..105c9b450c2b2885e6cef37c8ab7f09d66f80731 100644 (file)
my $description= xml_quote($tres->{'description'});
$name=~ s/\//\\\//;
$description=~ s/\//\\\//;
- $xml_msg=~ s/<xxx><\/xxx>/<item><productId>$r<\/productId><name><\/name><description>$description<\/description><\/item>$state<xxx><\/xxx>/;
+ $xml_msg=~ s/<xxx><\/xxx>/\n<item><productId>$r<\/productId><name><\/name><description>$description<\/description><\/item>$state<xxx><\/xxx>/;
}
}
}
my $description= xml_quote($tres->{'description'});
$name=~ s/\//\\\//;
$description=~ s/\//\\\//;
- $xml_msg=~ s/<xxx><\/xxx>/<item><productId>$r<\/productId><name><\/name><description>$description<\/description><\/item><xxx><\/xxx>/;
+ $xml_msg=~ s/<xxx><\/xxx>/\n<item><productId>$r<\/productId><name><\/name><description>$description<\/description><\/item><xxx><\/xxx>/;
}
}
if (not &check_opsi_res($res)){
my $r= $res->result;
foreach my $key (keys %{$r}) {
- my $item= "<item>";
+ my $item= "\n<item>";
my $value= $r->{$key};
if (UNIVERSAL::isa( $value, "ARRAY" )){
foreach my $subval (@{$value}){
if (not &check_opsi_res($res)){
my $result= $res->result;
foreach my $r (keys %{$result}){
- my $item= "<item><id>".xml_quote($r)."</id>";
+ my $item= "\n<item><id>".xml_quote($r)."</id>";
my $value= $result->{$r};
foreach my $sres (@{$value}){
my $description= xml_quote($tres->{'description'});
$name=~ s/\//\\\//;
$description=~ s/\//\\\//;
- $xml_msg=~ s/<xxx><\/xxx>/<item><productId>$r<\/productId><name><\/name><description>$description<\/description><\/item>$state<xxx><\/xxx>/;
+ $xml_msg=~ s/<xxx><\/xxx>/\n<item><productId>$r<\/productId><name><\/name><description>$description<\/description><\/item>$state<xxx><\/xxx>/;
}
}
my $description= xml_quote($tres->{'description'});
$name=~ s/\//\\\//;
$description=~ s/\//\\\//;
- $xml_msg=~ s/<xxx><\/xxx>/<item><productId>$r<\/productId><name><\/name><description>$description<\/description><\/item><xxx><\/xxx>/;
+ $xml_msg=~ s/<xxx><\/xxx>/\n<item><productId>$r<\/productId><name><\/name><description>$description<\/description><\/item><xxx><\/xxx>/;
}
}
index 772cc39f682456b75c2e11681e5d57c5b52088a7..8e3179e606740916f5d5a1da85f34f606f7a2f06 100755 (executable)
--- a/gosa-si/tests/client.php
+++ b/gosa-si/tests/client.php
# Add product to Opsi client
#$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>winxppro</productId> </xml>";
+ #$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>preloginloader</productId> </xml>";
+ #$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>opsi-adminutils</productId> </xml>";
+ #$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>xpconfig</productId> </xml>";
+ #$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>hwaudit</productId> </xml>";
+ #$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>javavm</productId> </xml>";
+ #$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>firefox</productId> </xml>";
+ #$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>flashplayer</productId> </xml>";
# Delete product from Opsi client
- #$data = "<xml> <header>gosa_opsi_del_product_from_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <hostId>linux-cl-1.intranet.gonicus.de</hostId> <macaddress>00:11:25:4b:8c:e5</macaddress> <productId>softprod</productId> </xml>";
+ #$data = "<xml> <header>gosa_opsi_del_product_from_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <hostId>linux-cl-1.intranet.gonicus.de</hostId> <macaddress>00:11:25:4b:8c:e5</macaddress> <productId>wipedisk</productId> </xml>";
#########################
##############################
# NTP reload
- $data = "<xml> <header>gosa_trigger_reload_ntp_config</header> <source>GOSA</source> <target>GOSA</target> <macaddress>00:11:25:4B:8C:E5</macaddress> </xml>";
+ #$data = "<xml> <header>gosa_trigger_reload_ntp_config</header> <source>GOSA</source> <target>GOSA</target> <macaddress>00:11:25:4B:8C:E5</macaddress> </xml>";
+
+ ##############################
+ # SYSLOG reload
+ $data = "<xml> <header>gosa_trigger_reload_syslog_config</header> <source>GOSA</source> <target>GOSA</target> <macaddress>00:01:6c:9d:b9:fa</macaddress> </xml>";
$sock->write($data);
$answer = "nothing";