diff options
-rw-r--r-- | config/sarg/sarg.inc | 257 | ||||
-rw-r--r-- | config/sarg/sarg.xml | 5 | ||||
-rw-r--r-- | config/sarg/sarg_schedule.xml | 21 | ||||
-rw-r--r-- | pkg_config.10.xml | 2 | ||||
-rw-r--r-- | pkg_config.8.xml | 2 | ||||
-rw-r--r-- | pkg_config.8.xml.amd64 | 2 |
6 files changed, 119 insertions, 170 deletions
diff --git a/config/sarg/sarg.inc b/config/sarg/sarg.inc index d67d11dc..22e70c95 100644 --- a/config/sarg/sarg.inc +++ b/config/sarg/sarg.inc @@ -77,32 +77,111 @@ function sarg_text_area_decode($text) { return preg_replace('/\r\n/', "\n", base64_decode($text)); } -function sarg_resync() { - global $config; - if (($_POST['Submit'] == 'Save') || !isset($_POST['Submit'])) { - sync_package_sarg(); +function sarg_check_dirs() { + // move old reports + if (is_dir("/usr/local/www/sarg-reports") && !is_dir("/usr/local/sarg-reports")) { + rename("/usr/local/www/sarg-reports", "/usr/local/sarg-reports"); } - if ($_POST['Submit'] == 'Force update now') { - run_sarg(); + + // check dirs + $dirs = array("/usr/local/sarg-reports", "/usr/local/www/sarg-images", "/usr/local/www/sarg-images/temp"); + foreach ($dirs as $dir) { + safe_mkdir($dir, 0755, true); + } + // PBI hack + if (SARG_DIR != "/usr/local") { + $pbidir = SARG_DIR . "/local/sarg-reports"; + if (is_dir($pbidir) && !is_link($pbidir)) { + rmdir_recursive($pbidir); + } + symlink("/usr/local/sarg-reports", "{$pbidir}"); + } + + // images + $simages = array("datetime.png", "graph.png", "sarg-squidguard-block.png", "sarg.png"); + $simgdir1 = "/usr/local/www/sarg-images"; + $simgdir2 = SARG_DIR . "/etc/sarg/images"; + foreach ($simages as $simage) { + if (!file_exists("{$simgdir1}/{$simage}")) { + copy("{$simgdir2}/{$simage}","{$simgdir1}/{$simage}"); + } } } -function log_rotate($log_file) { - global $config, $g; +function sarg_configure_cron() { + global $config; + // TODO: Redo this mess to use install_cron_job() instead + $new_cron = array(); + $cron_found = 0; + if (is_array($config['cron']['item'])) { + foreach($config['cron']['item'] as $cron) { + if (preg_match("/usr.local.www.sarg.php/", $cron["command"])) { + $cron_found++; + } else { + $new_cron['item'][] = $cron; + } + } + $cron_cmd="/usr/local/bin/php --no-header /usr/local/www/sarg.php"; + $sarg_schedule_id = 0; + if (is_array($config['installedpackages']['sargschedule']['config'])) { + foreach ($config['installedpackages']['sargschedule']['config'] as $sarg_schedule) { + if (preg_match('/(\d+)m/', $sarg_schedule['frequency'], $matches) && $sarg_schedule['enable']) { + $new_cron['item'][] = array("minute" => "*/" . $matches[1], + "hour" => "*", + "mday" => "*", + "month" => "*", + "wday" => "*", + "who" => "root", + "command" => $cron_cmd . " " . $sarg_schedule_id); + $config['cron'] = $new_cron; + $cron_found++; + } + if (preg_match('/(\d+)h/', $sarg_schedule['frequency'], $matches) && $sarg_schedule['enable']) { + $new_cron['item'][] = array("minute" => "0", + "hour" => "*/" . $matches[1], + "mday" => "*", + "month" => "*", + "wday" => "*", + "who" => "root", + "command" => $cron_cmd . " " . $sarg_schedule_id); + $config['cron'] = $new_cron; + $cron_found++; + } + if (preg_match('/(\d+)d/', $sarg_schedule['frequency'], $matches) && $sarg_schedule['enable']) { + $new_cron['item'][] = array("minute" => "0", + "hour" => "0", + "mday" => "*/" . $matches[1], + "month" => "*", + "wday" => "*", + "who" => "root", + "command"=> $cron_cmd . " " . $sarg_schedule_id); + $config['cron']=$new_cron; + $cron_found++; + } + $sarg_schedule_id++; + } + } - // remove .10 rotate log file - unlink_if_exists("{$log_file}.10"); - // rotate logs from 9 to 0 - $i = 9; - while ($i >= 0) { - if (file_exists("{$log_file}.{$i}")) { - rename("{$log_file}.{$i}", "{$log_file}" . ($i + 1)); + // update cron + if ($cron_found > 0) { + $config['cron'] = $new_cron; + write_config(); + configure_cron(); } - $i = $i - 1; } - // rotate current log - if (file_exists("$log_file")) { - rename("{$log_file}", "{$log_file}.0"); +} + +function sarg_package_install() { + sarg_check_dirs(); +} + +function sarg_resync() { + global $config; + if (($_POST['Submit'] == 'Save') || !isset($_POST['Submit'])) { + sync_package_sarg(); + } + if ($_POST['Submit'] == 'Force update now') { + run_sarg(); } } @@ -113,21 +192,19 @@ function run_sarg($id = -1) { $cmd = SARG_DIR . "/bin/sarg"; if ($id >= 0 && is_array($config['installedpackages']['sargschedule']['config'])) { $args = $config['installedpackages']['sargschedule']['config'][$id]['args']; - $action = $config['installedpackages']['sargschedule']['config'][$id]['action']; $gzip = $config['installedpackages']['sargschedule']['config'][$id]['gzip']; $find = $config['installedpackages']['sargschedule']['config'][$id]['find']; $gziplevel = $config['installedpackages']['sargschedule']['config'][$id]['gziplevel']; $daylimit = $config['installedpackages']['sargschedule']['config'][$id]['daylimit']; } else { $args = $_POST['args']; - $action = $_POST['action']; $gzip = $_POST['gzip']; $find = $_POST['find']; $gziplevel = $_POST['gziplevel']; $daylimit = ""; } $find = (preg_match("/(\d+)/", $find, $find_matches) ? $find_matches[1] : "60"); - log_error("Sarg: force refresh now with {$args} args, compress({$gzip}) and {$action} action after sarg finish."); + log_error("[sarg] Force refresh now with {$args} args, compress({$gzip})."); $gzip_script = "#!/bin/sh\n"; if ($gzip == "on") { // remove old file if exists @@ -155,39 +232,7 @@ EOF; // create a new file to speedup find search file_put_contents("/root/sarg_run_{$id}.sh", $gzip_script, LOCK_EX); mwexec("export LC_ALL=C && " . $cmd . " " . $args); - // check if there is a script to run after file save - if (is_array($config['installedpackages']['sarg'])) { - switch ($config['installedpackages']['sarg']['config'][0]['proxy_server']) { - case "squidguard": - if ($action == "both" || $action == "rotate") { - log_error('Executing squidguard log rotate after sarg.'); - log_rotate($sarg_proxy['squidguard_block_log']); - file_put_contents($sarg_proxy['squidguard_block_log'], "", LOCK_EX); - chown($sarg_proxy['squidguard_block_log'], 'proxy'); - chgrp($sarg_proxy['squidguard_block_log'], 'proxy'); - mwexec(SQUID_DIR . '/sbin/squid -k reconfigure'); - } - // leave this case without break to run squid rotate too. - case "squid": - if ($action == "both" || $action == "rotate") { - log_error('Executing squid log rotate after sarg.'); - mwexec(SQUID_DIR . '/sbin/squid -k rotate'); - } - if ($action == "both" || $action=="restart") { - if (file_exists($sarg_proxy['squid_rc'])) { - mwexec_bg($sarg_proxy['squid_rc'] . ' restart'); - } - } - break; - case "dansguardian": - if (preg_match('/\w+/', $action) && $action != "none") { - log_rotate($sarg_proxy['dansguardian_log']); - log_error('Restarting dansguardian after sarg and log rotate.'); - mwexec('/usr/bin/killall -HUP dansguardian'); - } - break; - } - } + // check compress option if ($gzip == "on") { mwexec_bg("/bin/sh /root/sarg_run_{$id}.sh"); @@ -257,8 +302,8 @@ function sync_package_sarg() { } break; } - if (!file_exists($access_log) && $access_log !="") { - $error = "Sarg config error: " . $sarg['proxy_server'] . " log file ($access_log) does not exists"; + if (!file_exists($access_log) && $access_log != "") { + $error = "[sarg] Config error: " . $sarg['proxy_server'] . " log file ($access_log) does not exists"; log_error($error); file_notice("Sarg", $error, "Sarg Settings", ""); } @@ -323,28 +368,8 @@ function sync_package_sarg() { $LDAPFilterSearch = (empty($sarguser['ldap_filter_search']) ? "" : "LDAPFilterSearch " . $sarguser['ldap_filter_search']); } - // move old reports - if (is_dir("/usr/local/www/sarg-reports") && !is_dir("/usr/local/sarg-reports")) { - rename("/usr/local/www/sarg-reports","/usr/local/sarg-reports"); - } - - // check dirs - $dirs = array("/usr/local/sarg-reports", "/usr/local/www/sarg-images", "/usr/local/www/sarg-images/temp"); - foreach ($dirs as $dir) { - if (!is_dir($dir)) { - mkdir($dir, 0755, true); - } - } - - // images - $simages = array("datetime.png", "graph.png", "sarg-squidguard-block.png", "sarg.png"); - $simgdir1 = "/usr/local/www/sarg-images"; - $simgdir2 = SARG_DIR . "/etc/sarg/images"; - foreach ($simages as $simage) { - if (!file_exists("{$simgdir1}/{$simage}")) { - copy("{$simgdir2}/{$simage}","{$simgdir1}/{$simage}"); - } - } + // check dirs and images + sarg_check_dirs(); // create sarg config files $sarg_dir = SARG_DIR; @@ -356,65 +381,7 @@ function sync_package_sarg() { file_put_contents(SARG_DIR . '/etc/sarg/exclude_users.conf', sarg_text_area_decode($sarguser['exclude_userlist']), LOCK_EX); // check cron_tab - // TODO: Redo this mess to use install_cron_job() instead - $new_cron = array(); - $cron_found = 0; - if (is_array($config['cron']['item'])) { - foreach($config['cron']['item'] as $cron) { - if (preg_match("/usr.local.www.sarg.php/", $cron["command"])) { - $cron_found++; - } else { - $new_cron['item'][] = $cron; - } - } - $cron_cmd="/usr/local/bin/php --no-header /usr/local/www/sarg.php"; - $sarg_schedule_id = 0; - if (is_array($config['installedpackages']['sargschedule']['config'])) { - foreach ($config['installedpackages']['sargschedule']['config'] as $sarg_schedule) { - if (preg_match('/(\d+)m/', $sarg_schedule['frequency'], $matches) && $sarg_schedule['enable']) { - $new_cron['item'][] = array("minute" => "*/" . $matches[1], - "hour" => "*", - "mday" => "*", - "month" => "*", - "wday" => "*", - "who" => "root", - "command" => $cron_cmd . " " . $sarg_schedule_id); - $config['cron'] = $new_cron; - $cron_found++; - } - if (preg_match('/(\d+)h/', $sarg_schedule['frequency'], $matches) && $sarg_schedule['enable']) { - $new_cron['item'][] = array("minute" => "0", - "hour" => "*/" . $matches[1], - "mday" => "*", - "month" => "*", - "wday" => "*", - "who" => "root", - "command" => $cron_cmd . " " . $sarg_schedule_id); - $config['cron'] = $new_cron; - $cron_found++; - } - if (preg_match('/(\d+)d/', $sarg_schedule['frequency'], $matches) && $sarg_schedule['enable']) { - $new_cron['item'][] = array("minute" => "0", - "hour" => "0", - "mday" => "*/" . $matches[1], - "month" => "*", - "wday" => "*", - "who" => "root", - "command"=> $cron_cmd . " " . $sarg_schedule_id); - $config['cron']=$new_cron; - $cron_found++; - } - $sarg_schedule_id++; - } - } - - // update cron - if ($cron_found > 0) { - $config['cron'] = $new_cron; - write_config(); - configure_cron(); - } - } + sarg_configure_cron(); // write config if any file from filesystem was loaded if ($update_conf > 0) { @@ -441,25 +408,23 @@ function sarg_validate_input($post, &$input_errors) { $input_errors[] = 'Please change it on Services -> Dansguardian -> Report and log -> Log file format'; } } else { - $input_errors[]='dansguardian package not detected'; + $input_errors[]='DansGuardian package is not installed'; } } # check squidguard - if (substr($key, 0, 10) == "proxy_server" && $value == "squidguard") { - if (!is_array($config['installedpackages']['squidguardgeneral'])) { - $input_errors[]='squidguard package not detected'; - } - } + if (substr($key, 0, 10) == "proxy_server" && $value == "squidguard") + if (!is_array($config['installedpackages']['squidguardgeneral'])) + $input_errors[]='SquidGuard package is not installed'; # check squid if (substr($key, 0, 5) == "proxy_server" && $value == "squid") { if (is_array($config['installedpackages']['squid'])) { if (!$config['installedpackages']['squid']['log_enabled']) { - $input_errors[] = 'Squid logging not enabled'; + $input_errors[]='Squid logging is not enabled'; } } else { - $input_errors[] = 'Squid package not installed'; + $input_errors[]='Squid package is not installed'; } } diff --git a/config/sarg/sarg.xml b/config/sarg/sarg.xml index 00da6470..cc5c1118 100644 --- a/config/sarg/sarg.xml +++ b/config/sarg/sarg.xml @@ -42,7 +42,7 @@ ]]> </copyright> <name>sarg</name> - <version>0.6.5</version> + <version>0.6.6</version> <title>Status: Sarg Settings</title> <include_file>/usr/local/pkg/sarg.inc</include_file> <menu> @@ -391,6 +391,9 @@ <encoding>base64</encoding> </field> </fields> + <custom_php_install_command> + sarg_package_install(); + </custom_php_install_command> <custom_php_validation_command> sarg_validate_input($_POST, $input_errors); </custom_php_validation_command> diff --git a/config/sarg/sarg_schedule.xml b/config/sarg/sarg_schedule.xml index 7bc02d10..5bd4e8fa 100644 --- a/config/sarg/sarg_schedule.xml +++ b/config/sarg/sarg_schedule.xml @@ -42,7 +42,7 @@ ]]> </copyright> <name>sargschedule</name> - <version>0.6.5</version> + <version>0.6.6</version> <title>Status: Sarg Schedules</title> <include_file>/usr/local/pkg/sarg.inc</include_file> <tabs> @@ -94,10 +94,6 @@ <fieldname>gzip</fieldname> </columnitem> <columnitem> - <fielddescr>Post Action</fielddescr> - <fieldname>action</fieldname> - </columnitem> - <columnitem> <fielddescr>Description</fielddescr> <fieldname>description</fieldname> </columnitem> @@ -106,7 +102,6 @@ <fields> <field> <type>listtopic</type> - <fieldname>temp</fieldname> <name>Schedule Options</name> </field> <field> @@ -154,21 +149,7 @@ <required/> </field> <field> - <fielddescr>Action After Sarg</fielddescr> - <fieldname>action</fieldname> - <description>Choose an action to run after Sarg finishes.</description> - <type>select</type> - <options> - <option><name>None (default)</name><value>none</value></option> - <option><name>Rotate logs</name><value>rotate</value></option> - <option><name>Restart proxy daemon</name><value>restart</value></option> - <option><name>Rotate log and restart proxy daemon</name><value>both</value></option> - </options> - <default_value>none</default_value> - </field> - <field> <type>listtopic</type> - <fieldname>temp</fieldname> <name>Compress Options</name> </field> <field> diff --git a/pkg_config.10.xml b/pkg_config.10.xml index 91f18c7f..1f19e3f6 100644 --- a/pkg_config.10.xml +++ b/pkg_config.10.xml @@ -634,7 +634,7 @@ <config_file>https://packages.pfsense.org/packages/config/sarg/sarg.xml</config_file> <pkginfolink>https://forum.pfsense.org/index.php/topic,47765.0.html</pkginfolink> <depends_on_package_pbi>sarg-2.3.9-##ARCH##.pbi</depends_on_package_pbi> - <version>0.6.8</version> + <version>0.6.9</version> <status>RELEASE</status> <required_version>2.2</required_version> <port_category>www</port_category> diff --git a/pkg_config.8.xml b/pkg_config.8.xml index c71e4442..5b894299 100644 --- a/pkg_config.8.xml +++ b/pkg_config.8.xml @@ -640,7 +640,7 @@ <depends_on_package>sarg-2.3.6_2.tbz</depends_on_package> <depends_on_package>gd-2.0.35_8,1.tbz</depends_on_package> <depends_on_package_pbi>sarg-2.3.6_2-i386.pbi</depends_on_package_pbi> - <version>2.3.6_2 pkg v0.6.7</version> + <version>2.3.6_2 pkg v0.6.9</version> <status>Release</status> <required_version>2.1</required_version> <configurationfile>sarg.xml</configurationfile> diff --git a/pkg_config.8.xml.amd64 b/pkg_config.8.xml.amd64 index 307bf4fd..7c5e3b79 100644 --- a/pkg_config.8.xml.amd64 +++ b/pkg_config.8.xml.amd64 @@ -640,7 +640,7 @@ <depends_on_package>sarg-2.3.6_2.tbz</depends_on_package> <depends_on_package>gd-2.0.35_8,1.tbz</depends_on_package> <depends_on_package_pbi>sarg-2.3.6_2-amd64.pbi</depends_on_package_pbi> - <version>2.3.6_2 pkg v0.6.7</version> + <version>2.3.6_2 pkg v0.6.9</version> <status>Release</status> <required_version>2.1</required_version> <configurationfile>sarg.xml</configurationfile> |