]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
Syslogeinstellungen fuer var log messages per GUI Einstellbar
authormaniacikarus <maniacikarus@ea5c0bd1-69bd-2848-81d8-4f18e57aeed8>
Wed, 22 Aug 2007 08:06:33 +0000 (08:06 +0000)
committermaniacikarus <maniacikarus@ea5c0bd1-69bd-2848-81d8-4f18e57aeed8>
Wed, 22 Aug 2007 08:06:33 +0000 (08:06 +0000)
git-svn-id: http://svn.ipfire.org/svn/ipfire/trunk@798 ea5c0bd1-69bd-2848-81d8-4f18e57aeed8

config/rootfiles/common/misc-progs
html/cgi-bin/logs.cgi/config.dat
langs/de/cgi-bin/de.pl
langs/en/cgi-bin/en.pl
src/misc-progs/Makefile
src/misc-progs/restartsyslogd.c [new file with mode: 0644]

index 419920c04e076fd4d5e834d8d105a360413f502e..fe57e55f7f5aa7f676622a8c3b04e80d0dfe01f9 100644 (file)
@@ -30,3 +30,4 @@ usr/local/bin/squidctrl
 usr/local/bin/timectrl
 #usr/local/bin/tripwirectrl
 usr/local/bin/upnpctrl
+usr/local/bin/restartsyslogd
index 43bc3bcdbd0f1850f5e4734fe4e8f9d47670abf6..4ef89ef75e28bd56c40e49172981c2629d8ae9ca 100644 (file)
@@ -33,6 +33,7 @@ $logsettings{'LOGWATCH_KEEP'} = '56';
 my @VS = ('15','50','100','150','250','500');
 $logsettings{'ENABLE_REMOTELOG'} = 'off';
 $logsettings{'REMOTELOG_ADDR'} = '';
+$logsettings{'VARMESSAGES'} = 'daemon.*;local0.*;local2.*;*.info;mail.none;authpriv.*';
 $logsettings{'ACTION'} = '';
 &Header::getcgihash(\%logsettings);
 
@@ -145,7 +146,16 @@ END
 ;
 &Header::closebox();
 
-
+&Header::openbox('100%', 'left', $Lang::tr{'messages logging'});
+print <<END
+<table width='100%'>
+<tr>
+  <td>$Lang::tr{'log var messages'}</td><td><input type='text' name='VARMESSAGES' size='50' value='$logsettings{'VARMESSAGES'}' /></td>
+</tr>
+</table>
+END
+;
+&Header::closebox();
 
 print <<END
 <div align='center'>
index e72edb92f8a74d728c3d884516adf645953413b1..5246737697c075be8fbc757268d350c0368cad86 100644 (file)
 'log settings' => 'Logdatei-Einstellungen',
 'log summaries' => 'Log Übersicht',
 'log summary' => 'Log Zusammenfassung',
+'log var messages' => 'Einstellungen für /var/log/messages',
 'log view' => 'Log Anzeige',
 'log viewer' => 'Protokollansicht',
 'log viewing options' => 'Log Ansichts-Optionen',
 'memory' => 'Speicher',
 'memory information' => 'Speicherinformationen',
 'memory usage per' => 'Speichernutzung pro',
+'messages logging' => 'Logeinstellungen für /var/log/messages',
 'method' => 'Methode:',
 'min costs' => 'Minimale Kosten',
 'min delay' => 'Minimale Verzoegerung',
index ab36808f6dacae01cef50d11920b64738c81c17f..d80330b6626d464b5e97f018fff8e32d298f53e3 100644 (file)
 'log settings' => 'Log Settings',
 'log summaries' => 'Log summaries',
 'log summary' => 'Log Summary',
+'log var messages' => 'Settings for /var/log/messages',
 'log view' => 'Log View',
 'log viewer' => 'Log viewer',
 'log viewing options' => 'Log viewing options',
 'memory' => 'Memory',
 'memory information' => 'memory information',
 'memory usage per' => 'Memory Usage per',
+'messages logging' => 'Logsettings for /var/log/messages',
 'method' => 'Method:',
 'min costs' => 'Minimum costs',
 'min delay' => 'Minimum delay',
index 01889fe5a9534ea5a1344dbb8178afd887e8d635..96791ad062ef1a6cc8b72b6ed74811c6d3665d97 100644 (file)
@@ -10,7 +10,7 @@ SUID_PROGS = setdmzholes setportfw setfilters setxtaccess \
        applejuicectrl rebuildhosts backupctrl \
        logwatch openvpnctrl outgoingfwctrl \
        restartwireless getipstat qosctrl launch-ether-wake \
-       redctrl extrahdctrl sambactrl upnpctrl tripwirectrl \
+       redctrl restartsyslogd extrahdctrl sambactrl upnpctrl tripwirectrl \
        smartctrl clamavctrl pakfire mpfirectrl
 
 install : all
@@ -123,3 +123,6 @@ mpfirectrl: mpfirectrl.c setuid.o ../install+setup/libsmooth/varval.o
 
 backupctrl: backupctrl.c setuid.o ../install+setup/libsmooth/varval.o
        $(COMPILE) -I../install+setup/libsmooth/ backupctrl.c setuid.o ../install+setup/libsmooth/varval.o -o $@
+
+restartsyslogd: restartsyslogd.c setuid.o ../install+setup/libsmooth/varval.o
+       $(COMPILE) -I../install+setup/libsmooth/ restartsyslogd.c setuid.o ../install+setup/libsmooth/varval.o -o $@
diff --git a/src/misc-progs/restartsyslogd.c b/src/misc-progs/restartsyslogd.c
new file mode 100644 (file)
index 0000000..25222c8
--- /dev/null
@@ -0,0 +1,178 @@
+/* This file is part of the IPCop Firewall.
+ *
+ * This program is distributed under the terms of the GNU General Public
+ * Licence.  See the file COPYING for details.
+ *
+ * Copyright (C) 2003-07-12 Robert Kerr <rkerr@go.to>
+ *
+ * $Id$
+ *
+ * Edited by the IPFire Team to change var log messages 
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <errno.h>
+#include "libsmooth.h"
+#include "setuid.h"
+
+#define ERR_ANY 1
+#define ERR_SETTINGS 2    /* error in settings file */
+#define ERR_ETC 3         /* error with CONFIG_ROOT/etc permissions */
+#define ERR_CONFIG 4      /* error updated sshd_config */
+#define ERR_SYSLOG 5      /* error restarting syslogd */
+
+int main(void)
+{
+   char buffer[STRING_SIZE], hostname[STRING_SIZE], varmessages[STRING_SIZE];
+   int config_fd,rc,fd,pid;
+   struct stat st;
+   struct keyvalue *kv = NULL;
+   memset(buffer, 0, STRING_SIZE);
+   memset(hostname, 0, STRING_SIZE);
+   memset(varmessages, 0, STRING_SIZE);
+
+   if (!(initsetuid()))
+      exit(1);
+
+
+   /* Read in and verify config */
+   kv=initkeyvalues();
+
+   if (!readkeyvalues(kv, CONFIG_ROOT "/logging/settings"))
+   {
+      fprintf(stderr, "Cannot read syslog settings\n");
+      exit(ERR_SETTINGS);
+   }
+
+   if (!findkey(kv, "ENABLE_REMOTELOG", buffer))
+   {
+      fprintf(stderr, "Cannot read ENABLE_REMOTELOG\n");
+      exit(ERR_SETTINGS);
+   }
+
+   if (!findkey(kv, "REMOTELOG_ADDR", hostname))
+   {
+      fprintf(stderr, "Cannot read REMOTELOG_ADDR\n");
+      exit(ERR_SETTINGS);
+   }
+   
+   if (!findkey(kv, "VARMESSAGES", varmessages))
+   {
+      fprintf(stderr, "Cannot read VARMESSAGES\n");
+      exit(ERR_SETTINGS);
+   }
+
+   if (strspn(hostname, VALID_FQDN) != strlen(hostname))
+   {
+      fprintf(stderr, "Bad REMOTELOG_ADDR: %s\n", hostname);
+      exit(ERR_SETTINGS);
+   }
+
+   freekeyvalues(kv);
+
+
+   /* If anyone other than root can write to CONFIG_ROOT/etc this would be totally
+    * insecure - same if anyone other than root owns CONFIG_ROOT/etc, as they could
+    * change the file mode to give themselves or anyone else write access. */
+
+   if(lstat(CONFIG_ROOT "/etc",&st))
+   {
+      perror("Unable to stat" CONFIG_ROOT "/etc");
+      exit(ERR_ETC);
+   }
+   if(!S_ISDIR(st.st_mode))
+   {
+      fprintf(stderr,CONFIG_ROOT "/etc is not a directory?!\n");
+      exit(ERR_ETC);
+   }
+   if ( st.st_uid != 0  ||  st.st_mode & S_IWOTH ||
+      ((st.st_gid != 0) && (st.st_mode & S_IWGRP)) )
+   {
+      fprintf(stderr,CONFIG_ROOT "/etc is owned/writable by non-root users\n");
+      exit(ERR_ETC);
+   }
+
+   /* O_CREAT with O_EXCL will make open() fail if the file already exists -
+    * mostly to prevent 2 copies running at once */
+   if ((config_fd = open( CONFIG_ROOT "/etc/syslog.conf.new", O_WRONLY|O_CREAT|O_EXCL, 0644 )) == -1 )
+   {
+      perror("Unable to open new config file");
+      exit(ERR_CONFIG);
+   }
+
+   if (!strcmp(buffer,"on"))
+      snprintf(buffer, STRING_SIZE - 1, "/bin/sed -e 's/^#\\?\\(\\*\\.\\*[[:blank:]]\\+@\\).\\+$/\\1%s/' " CONFIG_ROOT "/etc/syslog.conf >&%d", hostname, config_fd );
+   else
+      snprintf(buffer, STRING_SIZE - 1, "/bin/sed -e 's/^#\\?\\(\\*\\.\\*[[:blank:]]\\+@.\\+\\)$/#\\1/' " CONFIG_ROOT "/etc/syslog.conf >&%d", config_fd );
+      
+      snprintf(buffer, STRING_SIZE - 1, "&& /bin/sed -e 's/*.\/var\/log\/messages/%s \/var\/log\/messages/' " CONFIG_ROOT "/etc/syslog.conf >&%d", varmessages, config_fd );
+
+   /* if the return code isn't 0 failsafe */
+   if ((rc = unpriv_system(buffer,99,99)) != 0)
+   {
+      fprintf(stderr, "sed returned bad exit code: %d\n", rc);
+      close(config_fd);
+      unlink(CONFIG_ROOT "/etc/syslog.conf.new");
+      exit(ERR_CONFIG);
+   }
+   close(config_fd);
+   if (rename(CONFIG_ROOT "/etc/syslog.conf.new", CONFIG_ROOT "/etc/syslog.conf") == -1)
+   {
+      perror("Unable to replace old config file");
+      unlink(CONFIG_ROOT "/etc/syslog.conf.new");
+      exit(ERR_CONFIG);
+   }
+
+
+   /* Get syslogd to read the new config file */
+   if ((fd = open("/var/run/syslogd.pid", O_RDONLY)) == -1)
+   {
+      if(errno == ENOENT)
+      {
+         /* pid file doesn't exists.. restart syslog */
+         if((rc = safe_system("/usr/sbin/syslogd u syslogd -m 0")) == 0 )
+            return 0;
+         else
+         {
+            fprintf(stderr,
+               "Unable to restart syslogd - returned exit code %d\n", rc);
+            exit(ERR_SYSLOG);
+         }
+      } else {
+         /* Something odd is going on, failsafe */
+         perror("Unable to open pid file");
+         exit(ERR_SYSLOG);
+      }
+   }
+
+   memset(buffer, 0, STRING_SIZE);
+   if (read(fd, buffer, STRING_SIZE - 1) == -1)
+   {
+      close(fd);
+      perror("Couldn't read from pid file");
+      exit(ERR_SYSLOG);
+   }
+   close(fd);
+   /* strtol does sanity checks that atoi doesn't do */
+   errno = 0;
+   pid = (int)strtol(buffer, (char **)NULL, 10);
+   if (errno || pid <= 1)
+   {
+      fprintf(stderr, "Bad pid value\n");
+      exit(ERR_SYSLOG);
+   }
+   if (kill(pid, SIGHUP) == -1)
+   {
+      fprintf(stderr, "Unable to send SIGHUP\n");
+      exit(ERR_SYSLOG);
+   }
+
+   return 0;
+}