aboutsummaryrefslogtreecommitdiffstats
path: root/config/syslog-ng
diff options
context:
space:
mode:
authorJim P <jim@pingle.org>2012-09-25 12:55:36 -0700
committerJim P <jim@pingle.org>2012-09-25 12:55:36 -0700
commit45c2b3e5c39a72834921475162584727b7d3543e (patch)
tree7cad5db75de67e34eaf435aa07bbba065a0fa787 /config/syslog-ng
parent7623e022c458816bc28608b0c4344bd319e4629f (diff)
parentd18b6591cb16504ce201b49d9c4fe03ed81d1c00 (diff)
downloadpfsense-packages-45c2b3e5c39a72834921475162584727b7d3543e.tar.gz
pfsense-packages-45c2b3e5c39a72834921475162584727b7d3543e.tar.bz2
pfsense-packages-45c2b3e5c39a72834921475162584727b7d3543e.zip
Merge pull request #320 from laleger/master
Initial syslog-ng package submission (ALPHA)
Diffstat (limited to 'config/syslog-ng')
-rw-r--r--config/syslog-ng/syslog-ng.inc432
-rw-r--r--config/syslog-ng/syslog-ng.xml192
-rw-r--r--config/syslog-ng/syslog-ng_advanced.xml135
-rw-r--r--config/syslog-ng/syslog-ng_log_viewer.php167
4 files changed, 926 insertions, 0 deletions
diff --git a/config/syslog-ng/syslog-ng.inc b/config/syslog-ng/syslog-ng.inc
new file mode 100644
index 00000000..b56cef39
--- /dev/null
+++ b/config/syslog-ng/syslog-ng.inc
@@ -0,0 +1,432 @@
+<?php
+/* $Id$ */
+/*
+ syslog-ng.inc
+ Copyright (C) 2012 Lance Leger
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+require_once('globals.inc');
+require_once('config.inc');
+require_once('util.inc');
+require_once('pfsense-utils.inc');
+require_once('pkg-utils.inc');
+require_once('service-utils.inc');
+
+if(!function_exists("filter_configure"))
+ require_once("filter.inc");
+
+function syslogng_get_real_interface_address($interface) {
+ $interface = convert_friendly_interface_to_real_interface_name($interface);
+ $line = trim(shell_exec("ifconfig $interface | grep inet | grep -v inet6 | awk '{ print \$2, \$4 }'"));
+ list($ip, $netmask) = explode(" ", $line);
+
+ return array($ip, long2ip(hexdec($netmask)));
+}
+
+function syslogng_install_command() {
+ conf_mount_rw();
+ syslogng_install_cron(true);
+ conf_mount_ro();
+ syslogng_resync();
+}
+
+function syslogng_deinstall_command() {
+ conf_mount_rw();
+ exec("/usr/local/etc/rc.d/syslog-ng.sh stop");
+ unlink_if_exists("/usr/local/etc/rc.d/syslog-ng.sh");
+ syslogng_install_cron(false);
+ conf_mount_ro();
+ filter_configure();
+}
+
+function syslogng_validate_general($post, $input_errors) {
+ global $config;
+
+ $objects = $config['installedpackages']['syslogngadvanced']['config'];
+
+ if(empty($post['interfaces'])) {
+ $input_errors[] = 'You must select at least one interface in \'Interfaces\' field';
+ } else {
+ $post['interfaces'] = implode(",", $post['interfaces']);
+ }
+
+ if(!is_port($post['default_port']))
+ $input_errors[] = 'You must enter a valid port number in the \'Default Port\' field';
+
+ $sockstat = trim(shell_exec("sockstat -l -P " . $post['default_protocol'] . " -p " . $post['default_port'] . " | grep -v ^USER | grep -v syslog-ng"));
+ if(!empty($sockstat))
+ $input_errors[] = 'The port specified in the \'Default Port\' field is already in use';
+
+ if(!preg_match("/^\\/[^?*:;{}\\\\]+[^\\/]$/", $post['default_logdir'])) {
+ $input_errors[] = 'You must enter a valid directory in the \'Default Log Directory\' field';
+ } elseif($post['default_logdir'] == "/var/log") {
+ $input_errors[] = 'You must enter a valid directory in the \'Default Log Directory\' field -- /var/log is reserved for pfSense';
+ }
+
+ if(!preg_match("/^[^\\/?*:;{}\\\\]+$/", $post['default_logfile']))
+ $input_errors[] = 'You must enter a valid file in the \'Default Log File\' field';
+
+ $default_objects = syslogng_build_default_objects($post);
+
+ if(empty($objects)) {
+ $objects = $default_objects;
+ } else {
+ $objects = syslogng_merge_objects($objects, $default_objects);
+ }
+
+ if($errors = syslogng_test_object_syntax($objects))
+ $input_errors[] = "Syslog-ng syntax test failed:\n" . $errors;
+}
+
+function syslogng_validate_advanced($post, $input_errors) {
+ global $config;
+
+ $objects = $config['installedpackages']['syslogngadvanced']['config'];
+
+ if($post['objectname'] == '_DEFAULT') {
+ $input_errors[] = 'Creation or modification of \'_DEFAULT\' objects not permitted. Change default settings under \'General\' tab.';
+ }
+
+ $new_object[] = array("objecttype"=>$post['objecttype'], "objectname"=>$post['objectname'], "objectparameters"=>$post['objectparameters']);
+
+ if(empty($objects)) {
+ $objects = $new_object;
+ } else {
+ $objects = syslogng_merge_objects($objects, $new_object);
+ }
+
+ if($errors = syslogng_test_object_syntax($objects))
+ $input_errors[] = "Syslog-ng syntax test failed:\n" . $errors;
+}
+
+function syslogng_install_cron($should_install) {
+ global $config, $g;
+
+ if($g['booting']==true)
+ return;
+
+ if(!$config['cron']['item'])
+ return;
+
+ $x=0;
+ $rotate_job_id=-1;
+ $rotate_is_installed = false;
+
+ foreach($config['cron']['item'] as $item) {
+ if(strstr($item['task_name'], "syslogng_rotate_logs")) {
+ $rotate_job_id = $x;
+ }
+ $x++;
+ }
+ $need_write = false;
+ switch($should_install) {
+ case true:
+ if($rotate_job_id < 0) {
+ $cron_item = array();
+ $cron_item['task_name'] = "syslogng_rotate_logs";
+ $cron_item['minute'] = "0";
+ $cron_item['hour'] = "*";
+ $cron_item['mday'] = "*";
+ $cron_item['month'] = "*";
+ $cron_item['wday'] = "*";
+ $cron_item['who'] = "root";
+ $cron_item['command'] = "/usr/bin/nice -n20 /usr/local/sbin/logrotate /usr/local/etc/logrotate.conf";
+ $config['cron']['item'][] = $cron_item;
+ $need_write = true;
+ }
+ if($need_write) {
+ parse_config(true);
+ write_config("Adding syslog-ng Cron Jobs");
+ }
+ break;
+ case false:
+ if($rotate_job_id >= 0) {
+ unset($config['cron']['item'][$rotate_job_id]);
+ $need_write = true;
+ }
+ if($need_write) {
+ parse_config(true);
+ write_config("Removing syslog-ng Cron Jobs");
+ }
+ break;
+ }
+ configure_cron();
+}
+
+function syslogng_build_default_objects($settings) {
+ $default_objects = array();
+
+ $interfaces = $settings['interfaces'];
+ $default_protocol = $settings['default_protocol'];
+ $default_port = $settings['default_port'];
+ $default_logdir = $settings['default_logdir'];
+ $default_logfile = $settings['default_logfile'];
+
+ $default_objects[0] = array("objecttype"=>"source", "objectname"=>"_DEFAULT", "objectparameters"=>"{ internal(); syslog(transport($default_protocol) port($default_port)");
+ foreach (explode(",", $interfaces) as $interface) {
+ $interface_address = syslogng_get_real_interface_address($interface);
+ if($interface_address[0]) {
+ $default_objects[0]['objectparameters'] .= " ip({$interface_address[0]})";
+ }
+ }
+ $default_objects[0]['objectparameters'] .= "); };";
+ $default_objects[1] = array("objecttype"=>"destination", "objectname"=>"_DEFAULT", "objectparameters"=>"{ file(\"$default_logdir/$default_logfile\"); };");
+ $default_objects[2] = array("objecttype"=>"log", "objectname"=>"_DEFAULT", "objectparameters"=>"{ source(_DEFAULT); destination(_DEFAULT); };");
+
+ return $default_objects;
+}
+
+
+function syslogng_merge_objects($objects1, $objects2)
+{
+ foreach($objects2 as $object2) {
+ $match = 0;
+ foreach($objects1 as &$object1) {
+ if(($object2['objecttype'] == $object1['objecttype']) && ($object2['objectname'] == $object1['objectname'])) {
+ $object1 = $object2;
+ $match = 1;
+ }
+ }
+ if($match == 0)
+ array_push($objects1, $object2);
+ }
+
+ return $objects1;
+}
+
+function syslogng_test_object_syntax($objects) {
+ exec("mv /usr/local/etc/syslog-ng.conf /usr/local/etc/syslog-ng.conf.backup");
+ syslogng_build_conf($objects);
+ $errors = trim(shell_exec('/usr/local/sbin/syslog-ng --syntax-only 2>&1'));
+ exec("mv /usr/local/etc/syslog-ng.conf /usr/local/etc/syslog-ng.conf.tested");
+ exec("mv /usr/local/etc/syslog-ng.conf.backup /usr/local/etc/syslog-ng.conf");
+
+ return $errors;
+}
+
+function syslogng_get_log_files($objects) {
+ $log_files = array();
+
+ foreach($objects as $object) {
+ if($object['objecttype'] == 'destination') {
+ preg_match("/file\(['\"]([^'\"]*)['\"]/", $object['objectparameters'], $match);
+ if($match) {
+ $log_file = $match[1];
+ array_push($log_files, $log_file);
+ }
+ }
+ }
+
+ return $log_files;
+}
+
+function syslogng_build_conf($objects) {
+ $conf = "# This file is automatically generated by pfSense\n";
+ $conf .= "# Do not edit manually !\n";
+ $conf .= "@version:3.3\n";
+
+ foreach($objects as $object) {
+ if($object['objecttype'] == 'log' || $object['objecttype'] == 'options') {
+ $conf .= $object['objecttype'] . " " . $object['objectparameters'] . "\n";
+ } else {
+ $conf .= $object['objecttype'] . " " . $object['objectname'] . " " . $object['objectparameters'] . "\n";
+ }
+ }
+
+ file_put_contents('/usr/local/etc/syslog-ng.conf', $conf);
+}
+
+function syslogng_build_logrotate_conf($settings, $objects) {
+ $conf = "# This file is automatically generated by pfSense\n";
+ $conf .= "# Do not edit manually !\n";
+
+ $compress_archives = $settings['compress_archives'];
+ $compress_type = $settings['compress_type'];
+ $archive_frequency = $settings['archive_frequency'];
+ $max_archives = $settings['max_archives'];
+
+ $log_files = syslogng_get_log_files($objects);
+
+ foreach($log_files as $log_file) {
+ $conf .= "$log_file ";
+ }
+
+ $conf .= "{\n";
+ $conf .= "\trotate $max_archives\n";
+ $conf .= "\t$archive_frequency\n";
+
+ if($compress_archives == 'on') {
+ $conf .= "\tcompress\n";
+ if($compress_type == 'bz2') {
+ $conf .= "\tcompresscmd bzip2\n";
+ }
+ }
+
+ $conf .= "\tpostrotate\n";
+ $conf .= "\t\tkill -s HUP `cat /var/run/syslog-ng.pid`\n";
+ $conf .= "\tendscript\n";
+ $conf .= "}\n";
+
+ file_put_contents('/usr/local/etc/logrotate.conf', $conf);
+}
+
+function syslogng_generate_rules($type) {
+ global $config;
+
+ $settings = $config['installedpackages']['syslogng']['config'][0];
+
+ $interfaces = ($settings['interfaces'] ? $settings['interfaces'] : 'lan');
+ $default_protocol = ($settings['default_protocol'] ? $settings['default_protocol'] : 'udp');
+ $default_port = ($settings['default_port'] ? $settings['default_port'] : 5140);
+
+ $rules = "";
+ switch($type) {
+ case 'rule':
+ foreach ($interfaces as $interface) {
+ $rules .= "pass in quick on $interface proto $default_protocol from any to !($interface) port $default_port no state label\n";
+ }
+ break;
+ }
+
+ return $rules;
+}
+
+function syslogng_resync() {
+ global $config;
+ conf_mount_rw();
+
+ $settings = $config['installedpackages']['syslogng']['config'][0];
+ $objects = $config['installedpackages']['syslogngadvanced']['config'];
+
+ if(!isset($settings['enable']))
+ $settings['enable'] = 'off';
+ if(!isset($settings['interfaces']))
+ $settings['interfaces'] = 'lan';
+ if(!isset($settings['default_protocol']))
+ $settings['default_protocol'] = 'udp';
+ if(!isset($settings['default_port']))
+ $settings['default_port'] = 5140;
+ if(!isset($settings['default_logdir']))
+ $settings['default_logdir'] = '/var/syslog-ng';
+ if(!isset($settings['default_logfile']))
+ $settings['default_logfile'] = 'default.log';
+ if(!isset($settings['archive_frequency']))
+ $settings['archive_frequency'] = 'daily';
+ if(!isset($settings['compress_archives']))
+ $settings['compress_archives'] = 'on';
+ if(!isset($settings['compress_type']))
+ $settings['compress_type'] = 'gz';
+ if(!isset($settings['max_archives']))
+ $settings['max_archives'] = 30;
+
+ $default_objects = syslogng_build_default_objects($settings);
+
+ if(empty($objects)) {
+ $objects = $default_objects;
+ } else {
+ $objects = syslogng_merge_objects($objects, $default_objects);
+ }
+
+ $sort = array();
+ foreach($objects as $k=>$v) {
+ $sort['objecttype'][$k] = $v['objecttype'];
+ $sort['objectname'][$k] = $v['objectname'];
+ }
+ array_multisort($sort['objecttype'], SORT_ASC, $sort['objectname'], SORT_ASC, $objects);
+
+ syslogng_build_conf($objects);
+ syslogng_build_logrotate_conf($settings, $objects);
+
+ $config['installedpackages']['syslogng']['config'][0] = $settings;
+ $config['installedpackages']['syslogngadvanced']['config'] = $objects;
+
+ if($settings['enable'] == 'on') {
+ if(!file_exists($settings['default_logdir'])) {
+ exec("mkdir -p " . $settings['default_logdir']);
+ }
+
+ syslogng_write_rcfile();
+
+ if(!is_service_running('syslog-ng')) {
+ log_error("Starting syslog-ng");
+ exec("/usr/local/etc/rc.d/syslog-ng.sh start");
+ } else {
+ log_error("Reloading syslog-ng for configuration sync");
+ exec("/usr/local/etc/rc.d/syslog-ng.sh restart");
+ }
+
+ // Sleep for a couple seconds to give syslog-ng a chance to fire up fully.
+ for ($i=0; $i < 10; $i++) {
+ if(!is_service_running('syslog-ng'))
+ sleep(1);
+ }
+ } else {
+ if(is_service_running('syslog-ng')) {
+ log_error("Stopping syslog-ng");
+ exec("/usr/local/etc/rc.d/syslog-ng.sh stop");
+
+ unlink_if_exists("/usr/local/etc/rc.d/syslog-ng.sh");
+ }
+ }
+
+ write_config();
+ conf_mount_ro();
+ filter_configure();
+}
+
+function syslogng_write_rcfile() {
+ $rc = array();
+ $pid_file = "/var/run/syslog-ng.pid";
+ $rc['file'] = 'syslog-ng.sh';
+ $rc['start'] = <<<EOD
+if [ -z "`ps auxw | grep "syslog-ng" | grep -v "syslog-ng.sh"`" ]; then
+ /usr/local/sbin/syslog-ng -p {$pid_file}
+fi
+
+EOD;
+ $rc['stop'] = <<<EOD
+if [ -s "{$pid_file}" ]; then
+ kill `cat {$pid_file}` 2>/dev/null
+fi
+# Just in case pid file didn't exist or process is still running...
+sleep 5
+killall -9 syslog-ng 2>/dev/null
+
+EOD;
+ $rc['restart'] = <<<EOD
+if [ -z "`ps auxw | grep "syslog-ng" | grep -v "syslog-ng.sh"`" ]; then
+ /usr/local/sbin/syslog-ng -p {$pid_file}
+elif [ -s "{$pid_file}" ]; then
+ kill -s HUP `cat {$pid_file}` 2>/dev/null
+else
+ killall -9 syslog-ng 2>/dev/null
+ /usr/local/sbin/syslog-ng -p {$pid_file}
+fi
+
+EOD;
+ conf_mount_rw();
+ write_rcfile($rc);
+}
+?> \ No newline at end of file
diff --git a/config/syslog-ng/syslog-ng.xml b/config/syslog-ng/syslog-ng.xml
new file mode 100644
index 00000000..dbdd4a8d
--- /dev/null
+++ b/config/syslog-ng/syslog-ng.xml
@@ -0,0 +1,192 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!DOCTYPE packagegui SYSTEM "../schema/packages.dtd">
+<?xml-stylesheet type="text/xsl" href="../xsl/package.xsl"?>
+<packagegui>
+ <copyright>
+ <![CDATA[
+/* $Id$ */
+/* ========================================================================== */
+/*
+ syslog-ng.xml
+ part of pfSense (http://www.pfSense.com)
+ Copyright (C) 2012 Lance Leger
+ All rights reserved.
+ */
+/* ========================================================================== */
+/*
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+ */
+/* ========================================================================== */
+ ]]>
+ </copyright>
+ <description>Describe your package here</description>
+ <requirements>Describe your package requirements here</requirements>
+ <faq>Currently there are no FAQ items provided.</faq>
+ <name>Syslog-ng</name>
+ <version>3.3.4_1</version>
+ <title>Services: Syslog-ng</title>
+ <include_file>/usr/local/pkg/syslog-ng.inc</include_file>
+ <menu>
+ <name>Syslog-ng</name>
+ <tooltiptext>Setup Syslog-ng</tooltiptext>
+ <section>Services</section>
+ <url>/syslog-ng_log_viewer.php</url>
+ </menu>
+ <service>
+ <name>syslog-ng</name>
+ <rcfile>syslog-ng.sh</rcfile>
+ <executable>syslog-ng</executable>
+ </service>
+ <tabs>
+ <tab>
+ <text>General</text>
+ <url>/pkg_edit.php?xml=syslog-ng.xml&amp;id=0</url>
+ <active/>
+ </tab>
+ <tab>
+ <text>Advanced</text>
+ <url>/pkg.php?xml=syslog-ng_advanced.xml</url>
+ </tab>
+ <tab>
+ <text>Log Viewer</text>
+ <url>/syslog-ng_log_viewer.php</url>
+ </tab>
+ </tabs>
+ <additional_files_needed>
+ <prefix>/usr/local/pkg/</prefix>
+ <chmod>0755</chmod>
+ <item>http://www.pfsense.com/packages/config/syslog-ng/syslog-ng.inc</item>
+ </additional_files_needed>
+ <additional_files_needed>
+ <prefix>/usr/local/pkg/</prefix>
+ <chmod>0755</chmod>
+ <item>http://www.pfsense.org/packages/config/syslog-ng/syslog-ng_advanced.xml</item>
+ </additional_files_needed>
+ <additional_files_needed>
+ <prefix>/usr/local/www/</prefix>
+ <chmod>0755</chmod>
+ <item>http://www.pfsense.org/packages/config/syslog-ng/syslog-ng_log_viewer.php</item>
+ </additional_files_needed>
+ <fields>
+ <field>
+ <fielddescr>Enable</fielddescr>
+ <fieldname>enable</fieldname>
+ <type>checkbox</type>
+ <description>Select this option to enable syslog-ng</description>
+ </field>
+ <field>
+ <fielddescr>Interface Selection</fielddescr>
+ <fieldname>interfaces</fieldname>
+ <type>interfaces_selection</type>
+ <description>Select interfaces you want to listen on</description>
+ <required/>
+ <multiple/>
+ </field>
+ <field>
+ <fielddescr>Default Protocol</fielddescr>
+ <fieldname>default_protocol</fieldname>
+ <description>Select the default protocol you want to listen on</description>
+ <type>select</type>
+ <value>udp</value>
+ <options>
+ <option><name>UDP</name><value>udp</value></option>
+ <option><name>TCP</name><value>tcp</value></option>
+ </options>
+ <required/>
+ </field>
+ <field>
+ <fielddescr>Default Port</fielddescr>
+ <fieldname>default_port</fieldname>
+ <type>input</type>
+ <description>Enter default port number you want to listen on</description>
+ <default_value>514</default_value>
+ <required/>
+ </field>
+ <field>
+ <fielddescr>Default Log Directory</fielddescr>
+ <fieldname>default_logdir</fieldname>
+ <type>input</type>
+ <description>Enter default log directory (no trailing slash)</description>
+ <default_value>/var/syslog-ng</default_value>
+ <required/>
+ </field>
+ <field>
+ <fielddescr>Default Log File</fielddescr>
+ <fieldname>default_logfile</fieldname>
+ <type>input</type>
+ <description>Enter default log file</description>
+ <default_value>default.log</default_value>
+ <required/>
+ </field>
+ <field>
+ <fielddescr>Archive Frequency</fielddescr>
+ <fieldname>archive_frequency</fieldname>
+ <description>Select the frequency to archive (rotate) log files</description>
+ <type>select</type>
+ <value>daily</value>
+ <options>
+ <option><name>Daily</name><value>daily</value></option>
+ <option><name>Weekly</name><value>weekly</value></option>
+ <option><name>Monthly</name><value>monthly</value></option>
+ </options>
+ <required/>
+ </field>
+ <field>
+ <fielddescr>Compress Archives</fielddescr>
+ <fieldname>compress_archives</fieldname>
+ <type>checkbox</type>
+ <description>Select this option to compress archived log files</description>
+ </field>
+ <field>
+ <fielddescr>Compress Type</fielddescr>
+ <fieldname>compress_type</fieldname>
+ <description>Select the type of compression for archived log files</description>
+ <type>select</type>
+ <value>gz</value>
+ <options>
+ <option><name>Gzip</name><value>gz</value></option>
+ <option><name>Bzip2</name><value>bz2</value></option>
+ </options>
+ </field>
+ <field>
+ <fielddescr>Max Archives</fielddescr>
+ <fieldname>max_archives</fieldname>
+ <type>input</type>
+ <description>Enter the number of max archived log files</description>
+ <default_value>30</default_value>
+ <required/>
+ </field>
+ </fields>
+ <custom_php_validation_command>
+ syslogng_validate_general($_POST, &amp;$input_errors);
+ </custom_php_validation_command>
+ <custom_php_resync_config_command>
+ syslogng_resync();
+ </custom_php_resync_config_command>
+ <custom_php_install_command>
+ syslogng_install_command();
+ </custom_php_install_command>
+ <custom_php_deinstall_command>
+ syslogng_deinstall_command();
+ </custom_php_deinstall_command>
+ <filter_rules_needed>syslogng_generate_rules</filter_rules_needed>
+</packagegui>
diff --git a/config/syslog-ng/syslog-ng_advanced.xml b/config/syslog-ng/syslog-ng_advanced.xml
new file mode 100644
index 00000000..36a02a07
--- /dev/null
+++ b/config/syslog-ng/syslog-ng_advanced.xml
@@ -0,0 +1,135 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!DOCTYPE packagegui SYSTEM "./schema/packages.dtd">
+<?xml-stylesheet type="text/xsl" href="./xsl/package.xsl"?>
+<packagegui>
+ <copyright>
+ <![CDATA[
+/* $Id$ */
+/* ========================================================================== */
+/*
+ syslog-ng_advanced.xml
+ part of pfSense (http://www.pfSense.com)
+ Copyright (C) 2012 Lance Leger
+ All rights reserved.
+ */
+/* ========================================================================== */
+/*
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+ */
+/* ========================================================================== */
+ ]]>
+ </copyright>
+ <description>Describe your package here</description>
+ <requirements>Describe your package requirements here</requirements>
+ <faq>Currently there are no FAQ items provided.</faq>
+ <name>Syslog-ng Advanced</name>
+ <version>0.1.0</version>
+ <title>Services: Syslog-ng Advanced</title>
+ <include_file>/usr/local/pkg/syslog-ng.inc</include_file>
+ <delete_string>An object has been deleted.</delete_string>
+ <addedit_string>An object has been created/modified.</addedit_string>
+ <menu>
+ <name>Syslog-ng</name>
+ <tooltiptext>Setup Syslog-ng</tooltiptext>
+ <section>Services</section>
+ </menu>
+ <tabs>
+ <tab>
+ <text>General</text>
+ <url>/pkg_edit.php?xml=syslog-ng.xml&amp;id=0</url>
+ </tab>
+ <tab>
+ <text>Advanced</text>
+ <url>/pkg.php?xml=syslog-ng_advanced.xml</url>
+ <active/>
+ </tab>
+ <tab>
+ <text>Log Viewer</text>
+ <url>/syslog-ng_log_viewer.php</url>
+ </tab>
+ </tabs>
+ <adddeleteeditpagefields>
+ <columnitem>
+ <fielddescr>Object Type</fielddescr>
+ <fieldname>objecttype</fieldname>
+ </columnitem>
+ <columnitem>
+ <fielddescr>Object Name</fielddescr>
+ <fieldname>objectname</fieldname>
+ </columnitem>
+ <columnitem>
+ <fielddescr>Description</fielddescr>
+ <fieldname>description</fieldname>
+ </columnitem>
+ </adddeleteeditpagefields>
+ <fields>
+ <field>
+ <fielddescr>Object Name</fielddescr>
+ <fieldname>objectname</fieldname>
+ <description>Enter the object name</description>
+ <type>input</type>
+ <required/>
+ </field>
+ <field>
+ <fielddescr>Object Type</fielddescr>
+ <fieldname>objecttype</fieldname>
+ <description>Select the object type</description>
+ <type>select</type>
+ <value></value>
+ <options>
+ <option><name>Options</name><value>options</value></option>
+ <option><name>Source</name><value>source</value></option>
+ <option><name>Destination</name><value>destination</value></option>
+ <option><name>Log</name><value>log</value></option>
+ <option><name>Filter</name><value>filter</value></option>
+ <option><name>Parser</name><value>parser</value></option>
+ <option><name>Rewrite</name><value>rewrite</value></option>
+ <option><name>Template</name><value>template</value></option>
+ </options>
+ <required/>
+ </field>
+ <field>
+ <fielddescr>Object Parameters</fielddescr>
+ <fieldname>objectparameters</fieldname>
+ <description>Enter the object parameters</description>
+ <type>textarea</type>
+ <cols>65</cols>
+ <rows>5</rows>
+ <required/>
+ </field>
+ <field>
+ <fielddescr>Description</fielddescr>
+ <fieldname>description</fieldname>
+ <description>Enter the description for this item</description>
+ <type>input</type>
+ </field>
+ </fields>
+ <custom_delete_php_command>
+ syslogng_resync();
+ </custom_delete_php_command>
+ <custom_php_validation_command>
+ syslogng_validate_advanced($_POST, &amp;$input_errors);
+ </custom_php_validation_command>
+ <custom_php_resync_config_command>
+ syslogng_resync();
+ </custom_php_resync_config_command>
+</packagegui> \ No newline at end of file
diff --git a/config/syslog-ng/syslog-ng_log_viewer.php b/config/syslog-ng/syslog-ng_log_viewer.php
new file mode 100644
index 00000000..c8183f14
--- /dev/null
+++ b/config/syslog-ng/syslog-ng_log_viewer.php
@@ -0,0 +1,167 @@
+<?php
+/* $Id$ */
+/* ========================================================================== */
+/*
+ syslog-ng_log_viewer.xml
+ part of pfSense (http://www.pfSense.com)
+ Copyright (C) 2012 Lance Leger
+ All rights reserved.
+ */
+/* ========================================================================== */
+/*
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+ */
+/* ========================================================================== */
+
+require("guiconfig.inc");
+require("/usr/local/pkg/syslog-ng.inc");
+
+$objects = $config['installedpackages']['syslogngadvanced']['config'];
+$default_logdir = $config['installedpackages']['syslogng']['config'][0]['default_logdir'];
+$default_logfile = $config['installedpackages']['syslogng']['config'][0]['default_logfile'];
+$compress_archives = $config['installedpackages']['syslogng']['config'][0]['compress_archives'];
+$compress_type = $config['installedpackages']['syslogng']['config'][0]['compress_type'];
+
+if($_POST['logfile'])
+ $logfile = $_POST['logfile'];
+else
+ $logfile = $default_logdir . "/" . $default_logfile;
+
+if($_POST['limit'])
+ $limit = intval($_POST['limit']);
+else
+ $limit = "10";
+
+if($_POST['archives'])
+ $archives = true;
+
+if($_POST['filter'])
+ $filter = $_POST['filter'];
+
+if($_POST['not'])
+ $not = true;
+
+$log_messages = array();
+if(file_exists($logfile) && (filesize($logfile) > 0)) {
+ $grep = "grep -ih";
+
+ if(($compress_archives == 'on') && glob($logfile . "*" . $compress_type) && $archives) {
+ if($compress_type == 'bz2') {
+ $grep = "bzgrep -ih";
+ } else {
+ $grep = "zgrep -ih";
+ }
+ }
+
+ if(isset($filter) && $not) {
+ $grepcmd = "$grep -v '$filter' $logfile";
+ } else {
+ $grepcmd = "$grep '$filter' $logfile";
+ }
+
+ if($archives)
+ $grepcmd = $grepcmd . "*";
+
+ $log_lines = trim(shell_exec("$grepcmd | wc -l"));
+ $log_output = trim(shell_exec("$grepcmd | sort -M | tail -n $limit"));
+
+ if(!empty($log_output)) {
+ $log_messages = explode("\n", $log_output);
+ $log_messages_count = sizeof($log_messages);
+ }
+}
+
+$pgtitle = "Services: Syslog-ng Log Viewer";
+include("head.inc");
+?>
+<body link="#000000" vlink="#000000" alink="#000000">
+<?php include("fbegin.inc"); ?>
+<?php if ($savemsg) print_info_box($savemsg); ?>
+<form action="syslog-ng_log_viewer.php" method="post" name="iform">
+<table width="99%" border="0" cellpadding="0" cellspacing="0">
+ <tr><td>
+<?php
+ $tab_array = array();
+ $tab_array[] = array("General", false, "/pkg_edit.php?xml=syslog-ng.xml&amp;id=0");
+ $tab_array[] = array("Advanced", false, "/pkg.php?xml=syslog-ng_advanced.xml");
+ $tab_array[] = array("Log Viewer", true, "/syslog-ng_log_viewer.php");
+ display_top_tabs($tab_array);
+?>
+ </td></tr>
+ <tr><td>
+ <div id="mainarea">
+ <table id="maintable" name="maintable" class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
+ <tr><td>
+
+ <table>
+ <tr><td width="22%">Log File</td><td width="78%"><select name="logfile">
+ <?php
+ $log_files = syslogng_get_log_files($objects);
+ foreach($log_files as $log_file) {
+ if($log_file == $logfile) {
+ echo "<option value=\"$log_file\" selected=\"selected\">$log_file</option>\n";
+ } else {
+ echo "<option value=\"$log_file\">$log_file</option>\n";
+ }
+ }
+ ?>
+ </select></td></tr>
+ <tr><td width="22%">Limit</td><td width="78%"><select name="limit">
+ <?php
+ $limit_options = array("10", "20", "50");
+ foreach($limit_options as $limit_option) {
+ if($limit_option == $limit) {
+ echo "<option value=\"$limit_option\" selected=\"selected\">$limit_option</option>\n";
+ } else {
+ echo "<option value=\"$limit_option\">$limit_option</option>\n";
+ }
+ }
+ ?>
+ </select></td></tr>
+ <tr><td width="22%">Include Archives</td><td width="78%"><input type="checkbox" name="archives" <?php if($archives) echo " CHECKED"; ?> /></td></tr>
+ <tr><td colspan="2">
+ <table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
+ <?php
+ if(!empty($log_messages)) {
+ echo "<tr><td class=\"listtopic\">Showing $log_messages_count of $log_lines messages</td></tr>\n";
+ foreach($log_messages as $log_message) {
+ echo "<tr><td class=\"listr\">$log_message</td></tr>\n";
+ }
+ } else {
+ echo "<tr><td><span class=\"red\">No log messages found or log file is empty.</span></td></tr>\n";
+ }
+ ?>
+ </table>
+ </td></tr>
+ <tr><td width="22%">Filter</td><td width="78%"><input name="filter" value="<?=$filter?>" /></td></tr>
+ <tr><td width="22%">Inverse Filter (NOT)</td><td width="78%"><input type="checkbox" name="not" <?php if($not) echo " CHECKED"; ?> /></td></tr>
+ <tr><td colspan="2"><input type="submit" value="Refresh" /></td></tr>
+ </table>
+
+ </td></tr>
+ </table>
+ </div>
+ </td></tr>
+</table>
+</form>
+<?php include("fend.inc"); ?>
+</body> \ No newline at end of file