summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/system/vyatta_update_syslog.pl114
-rw-r--r--sysconf/syslog.conf8
-rw-r--r--templates/system/syslog/console/facility/node.def8
-rw-r--r--templates/system/syslog/file/node.def6
-rw-r--r--templates/system/syslog/file/node.tag/facility/node.def9
-rw-r--r--templates/system/syslog/global/facility/node.def10
-rw-r--r--templates/system/syslog/host/node.tag/facility/node.def8
-rw-r--r--templates/system/syslog/node.def11
-rw-r--r--templates/system/syslog/user/node.tag/facility/node.def8
9 files changed, 97 insertions, 85 deletions
diff --git a/scripts/system/vyatta_update_syslog.pl b/scripts/system/vyatta_update_syslog.pl
index d02d8be0..5951875c 100755
--- a/scripts/system/vyatta_update_syslog.pl
+++ b/scripts/system/vyatta_update_syslog.pl
@@ -1,45 +1,103 @@
#!/usr/bin/perl
+# **** License ****
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# This code was originally developed by Vyatta, Inc.
+# Portions created by Vyatta are Copyright (C) 2007 Vyatta, Inc.
+# All Rights Reserved.
+#
+# **** End License ****
+
+# Update /etc/syslog.conf
+# Exit code: 0 - update
+# 1 - no change or error
+
use strict;
+use lib "/opt/vyatta/share/perl5";
+use Vyatta::Config;
+use File::Compare;
+
my $SYSLOG_CONF = '/etc/syslog.conf';
+my $SYSLOG_TMP = "/tmp/syslog.conf.$$";
+my $MESSAGES = '/var/log/messages';
+my $CONSOLE = '/dev/console';
+my %entries = ();
+
+die "$0 expects no arguments\n" if (@ARGV);
+die "Must be run as root!\n" if ($EUID != 0);
+
+# This builds a data structure that maps from target
+# to selector list for that target
+sub add_entries {
+ my ( $config, $level, $target ) = @_;
+
+ foreach my $facility ( $config->listNodes("$level facility") ) {
+ my $loglevel = $config->returnValue("$level facility $facility level");
+ $facility = '*' if ( $facility eq 'all' );
+ $loglevel = '*' if ( $loglevel eq 'all' );
+
+ $entries{$target} = [] unless $entries{$target};
+ push @{ $entries{$target} }, $facility . '.' . $loglevel;
+ }
+}
-my $match1 = shift;
-my $match2 = shift;
-my $update_line = shift;
+my $config = new Vyatta::Config;
+$config->setLevel("system syslog");
-if (!defined($match1) || !defined($match2) || !defined($update_line)) {
- exit 1;
+add_entries( $config, 'global', $MESSAGES );
+
+# Default syslog.conf if no global entry
+%entries = ( $MESSAGES => { '*:notice', 'local7:*' } ) unless (%entries);
+
+add_entries( $config, 'console', $CONSOLE );
+
+foreach my $host ( $config->listNodes('host') ) {
+ add_entries( $config, "host $host", "@$host" );
+}
+
+foreach my $file ( $config->listNodes('file') ) {
+ add_entries( $config, "file $file", $file );
}
-if (system("touch $SYSLOG_CONF")) {
- exit 2;
+foreach my $user ( $config->listNodes('user') ) {
+ add_entries( $config, 'user $user', $user );
}
-my $exp1 = "";
-my $exp2 = "";
-if ($match1 ne "") {
- $exp1 = $match1;
- if ($match2 ne "") {
- $exp2 = $match2;
- }
-} elsif ($match2 ne "") {
- $exp1 = $match2;
+open my $in, '<', $SYSLOG_CONF
+ or die "Can't open $SYSLOG_CONF: $!";
+
+open my $out, '>', $SYSLOG_TMP
+ or die "Can't open $SYSLOG_TMP: $!";
+
+while (<$in>) {
+ chomp;
+ next if /# VYATTA$/;
+ print {$out} $_, "\n";
}
+close $in;
-if ($exp2 ne "") {
- if (system("sed -i '/$exp1/{/$exp2/d}' $SYSLOG_CONF")) {
- exit 2;
- }
-} elsif ($exp1 ne "") {
- if (system("sed -i '/$exp1/d' $SYSLOG_CONF")) {
- exit 3;
- }
+foreach my $target ( keys %entries ) {
+ print $out join( ';', @{ $entries{$target} } ), "\t$target # VYATTA\n";
}
+close $out
+ or die "Can't output $SYSLOG_TMP: $!";
-if ($update_line ne "") {
- open my $out, '>>', $SYSLOG_CONF or exit 4;
- print {$out} "$update_line";
- close $out;
+# Don't need to do anything, save time on boot
+if ( compare( $SYSLOG_CONF, $SYSLOG_TMP ) == 0 ) {
+ unlink($SYSLOG_TMP);
+ exit 1;
}
+system("sudo cp $SYSLOG_TMP $SYSLOG_CONF") == 0
+ or die "Can't copy $SYSLOG_TMP to $SYSLOG_CONF";
+
+unlink($SYSLOG_TMP);
exit 0;
diff --git a/sysconf/syslog.conf b/sysconf/syslog.conf
index 56503e93..0143183d 100644
--- a/sysconf/syslog.conf
+++ b/sysconf/syslog.conf
@@ -4,8 +4,8 @@
# manpage.
#
# WARNING
-# Note: configuration via the Vyatta FusionCLI does not understand
-# full syslog configuration file format, so as administrator either
+# Note: configuration via the Vyatta FusionCLI may overwrite
+# changes to this file; so as administrator either
# use Linux tools (ie edit this file) or use the CLI, not both.
# Standard logfiles by facility
@@ -15,5 +15,5 @@
#kern.* -/var/log/kern.log
#user.* -/var/log/user.log
-# Catch-all log file
-*.notice;local7.* -/var/log/messages
+# Messages file (required)
+*.notice;local7.* -/var/log/messages # VYATTA
diff --git a/templates/system/syslog/console/facility/node.def b/templates/system/syslog/console/facility/node.def
index f505610d..4a565f6e 100644
--- a/templates/system/syslog/console/facility/node.def
+++ b/templates/system/syslog/console/facility/node.def
@@ -2,14 +2,6 @@ tag:
type: txt
help: Set facility for console logging
syntax:expression: $VAR(@) in "auth", "authpriv", "cron", "daemon", "kern", "lpr", "mail", "mark", "news", "security", "syslog", "user", "uucp", "local0", "local1", "local2", "local3", "local4", "local5", "local6", "local7", "all"; "\"$VAR(@)\" is not a valid logging facility"
-create:expression: "sudo sh -c \"LVL=`echo -n $VAR(level/@) | tr '[a-z]' '[A-Z]'` && \
-FAC='$VAR(@)' ; if [ x\\$FAC == xall ]; then FAC='*'; fi && \
-/opt/vyatta/sbin/vyatta_update_syslog.pl \\\"\\$FAC\\.\\\" \
- '\\/dev\\/console' \\\"\\$FAC.\\$LVL\t/dev/console\n\\\"\" "
-delete:expression: "sudo sh -c \"FAC='$VAR(@)' ; \
-if [ x\\$FAC == xall ]; then FAC='*'; fi && \
-/opt/vyatta/sbin/vyatta_update_syslog.pl \\\"\\$FAC\\.\\\" \
- '\\/dev\\/console' ''\" "
comp_help:Available logging facilities:
all All facilities excluding "mark"
auth Authentication and authorization
diff --git a/templates/system/syslog/file/node.def b/templates/system/syslog/file/node.def
index 5486c136..2ff7e359 100644
--- a/templates/system/syslog/file/node.def
+++ b/templates/system/syslog/file/node.def
@@ -1,5 +1,7 @@
tag:
type: txt
help: Set the name of syslog file to save log messages to
-syntax:expression: pattern $VAR(@) "^[-a-zA-Z0-9_.]+$" ; "invalid file name $VAR(@)"
-commit:expression: $VAR(./@/facility/@@) != ""; "At least one facility must be configured to log messages to file $VAR(./@)"
+syntax:expression: pattern $VAR(@) "^\/" ; "File name must be full pathname with leading /"
+commit:expression: $VAR(./@/facility/@@) != ""; \
+ "At least one facility must be configured to log messages to file $VAR(./@)"
+comp_help: Full path name of log file with leading slash
diff --git a/templates/system/syslog/file/node.tag/facility/node.def b/templates/system/syslog/file/node.tag/facility/node.def
index b9279085..f793e9b4 100644
--- a/templates/system/syslog/file/node.tag/facility/node.def
+++ b/templates/system/syslog/file/node.tag/facility/node.def
@@ -2,15 +2,6 @@ tag:
type: txt
help: Set facility for file logging
syntax:expression: $VAR(@) in "auth", "authpriv", "cron", "daemon", "kern", "lpr", "mail", "mark", "news", "security", "syslog", "user", "uucp", "local0", "local1", "local2", "local3", "local4", "local5", "local6", "local7", "all"; "\"$VAR(@)\" is not a valid logging facility"
-create:expression: "sudo sh -c \"LVL=`echo -n $VAR(level/@) | tr '[a-z]' '[A-Z]'` && \
-FAC='$VAR(@)' ; if [ x\\$FAC == xall ]; then FAC='*'; fi && \
-/opt/vyatta/sbin/vyatta_update_syslog.pl \\\"\\$FAC\\.\\\" \
- '\\/var\\/log\\/user\\/$VAR(../@)' \
- \\\"\\$FAC.\\$LVL\t/var/log/user/$VAR(../@) \n\\\"\" "
-delete:expression: "sudo sh -c \"FAC='$VAR(@)' ; \
-if [ x\\$FAC == xall ]; then FAC='*'; fi && \
-/opt/vyatta/sbin/vyatta_update_syslog.pl \\\"\\$FAC\\.\\\" \
- '\\/var\\/log\\/user\\/$VAR(../@)' ''\" "
comp_help:Available logging facilities:
all All facilities excluding "mark"
auth Authentication and authorization
diff --git a/templates/system/syslog/global/facility/node.def b/templates/system/syslog/global/facility/node.def
index d3ee692d..0616179f 100644
--- a/templates/system/syslog/global/facility/node.def
+++ b/templates/system/syslog/global/facility/node.def
@@ -1,15 +1,7 @@
tag:
type: txt
help: Set facility for system logging
-syntax:expression: $VAR(@) in "auth", "authpriv", "cron", "daemon", "kern", "lpr", "mail", "mark", "news", "security", "syslog", "user", "uucp", "local0", "local1", "local2", "local3", "local4", "local5", "local6", "local7", "all"; "\"$VAR(@)\" is not a valid logging facility"
-create:expression: "sudo sh -c \"LVL=`echo -n $VAR(level/@) | tr '[a-z]' '[A-Z]'` && \
-FAC='$VAR(@)' ; if [ x\\$FAC == xall ]; then FAC='*'; fi && \
-/opt/vyatta/sbin/vyatta_update_syslog.pl \\\"\\$FAC\\.\\\" '\\/var\\/log\\/messages' \
- \\\"\\$FAC.\\$LVL\t-/var/log/messages \n\\\"\" "
-delete:expression: "sudo sh -c \"FAC='$VAR(@)' ; \
-if [ x\\$FAC == xall ]; then FAC='*'; fi && \
-/opt/vyatta/sbin/vyatta_update_syslog.pl \
- \\\"\\$FAC\\.\\\" '\\/var\\/log\\/messages' ''\" "
+syntax:expression: $VAR(@) in "auth", "authpriv", "cron", "daemon", "kern", "lpr", "mail", "mark", "news", "security", "syslog", "user", "uucp", "local0", "local1", "local2", "local3", "local4", "local5", "local6", "local7", "all" ; "\"$VAR(@)\" is not a valid logging facility"
comp_help:Available logging facilities:
all All facilities excluding "mark"
auth Authentication and authorization
diff --git a/templates/system/syslog/host/node.tag/facility/node.def b/templates/system/syslog/host/node.tag/facility/node.def
index 32099823..ba18add0 100644
--- a/templates/system/syslog/host/node.tag/facility/node.def
+++ b/templates/system/syslog/host/node.tag/facility/node.def
@@ -2,14 +2,6 @@ tag:
type: txt
help: Set facility for host logging
syntax:expression: $VAR(@) in "auth", "authpriv", "cron", "daemon", "kern", "lpr", "mail", "mark", "news", "security", "syslog", "user", "uucp", "local0", "local1", "local2", "local3", "local4", "local5", "local6", "local7", "all"; "\"$VAR(@)\" is not a valid logging facility"
-create:expression: "sudo sh -c \"LVL=`echo -n $VAR(level/@) | tr '[a-z]' '[A-Z]'` && \
-FAC='$VAR(@)' ; if [ x\\$FAC == xall ]; then FAC='*'; fi && \
-/opt/vyatta/sbin/vyatta_update_syslog.pl \\\"\\$FAC\\.\\\" '@$VAR(../@) ' \
- \\\"\\$FAC.\\$LVL\t@$VAR(../@) \n\\\"\" "
-delete:expression: "sudo sh -c \"FAC='$VAR(@)' ; \
-if [ x\\$FAC == xall ]; then FAC='*'; fi && \
-/opt/vyatta/sbin/vyatta_update_syslog.pl \\\"\\$FAC\\.\\\" \
- '@$VAR(../@) ' ''\" "
comp_help:Available logging facilities:
all All facilities excluding "mark"
auth Authentication and authorization
diff --git a/templates/system/syslog/node.def b/templates/system/syslog/node.def
index 6bca3490..9e3254e1 100644
--- a/templates/system/syslog/node.def
+++ b/templates/system/syslog/node.def
@@ -1,11 +1,4 @@
help: Configure syslog daemon
-end: if [ -n "$VAR(./global/facility/@@)" ]; then
- # remove the default config for global messages
- sudo sh -c "sed -i '/\*\.notice;local7\.\*[[:space:]]*-\/var\/log\/messages/d' /etc/syslog.conf"
- else
- # if not already there then write the default config for global messages
- if ! grep -q "\*\.notice;local7\.\*[[:space:]]*-/var/log/messages" /etc/syslog.conf; then
- sudo sh -c "echo \"*.notice;local7.* -/var/log/messages\" >> /etc/syslog.conf"
- fi
+end: if /opt/vyatta/sbin/vyatta_update_syslog.pl; then
+ sudo /usr/sbin/invoke-rc.d sysklogd reload
fi
- sudo /usr/sbin/invoke-rc.d sysklogd restart
diff --git a/templates/system/syslog/user/node.tag/facility/node.def b/templates/system/syslog/user/node.tag/facility/node.def
index 378671da..0d323521 100644
--- a/templates/system/syslog/user/node.tag/facility/node.def
+++ b/templates/system/syslog/user/node.tag/facility/node.def
@@ -2,14 +2,6 @@ tag:
type: txt
help: Set facility for user logging
syntax:expression: $VAR(@) in "auth", "authpriv", "cron", "daemon", "kern", "lpr", "mail", "mark", "news", "security", "syslog", "user", "uucp", "local0", "local1", "local2", "local3", "local4", "local5", "local6", "local7", "all"; "\"$VAR(@)\" is not a valid logging facility"
-create:expression: "sudo sh -c \"LVL=`echo -n $VAR(level/@) | tr '[a-z]' '[A-Z]'` && \
-FAC='$VAR(@)' ; if [ x\\$FAC == xall ]; then FAC='*'; fi && \
-/opt/vyatta/sbin/vyatta_update_syslog.pl \\\"\\$FAC\\.\\$LVL\\\" \
- ' $VAR(../@) ' \\\"\\$FAC.\\$LVL $VAR(../@) \n\\\"\" "
-delete:expression: "sudo sh -c \"LVL=`echo -n $VAR(level/@) | tr '[a-z]' '[A-Z]'` && \
-FAC='$VAR(@)' ; if [ x\\$FAC == xall ]; then FAC='*'; fi && \
-/opt/vyatta/sbin/vyatta_update_syslog.pl \\\"\\$FAC\\.\\$LVL\\\" \
- ' $VAR(../@) ' ''\" "
comp_help:Available logging facilities:
all All facilities excluding "mark"
auth Authentication and authorization