diff options
author | dvserg <dv_serg@mail.ru> | 2011-01-31 08:12:57 +0300 |
---|---|---|
committer | dvserg <dv_serg@mail.ru> | 2011-01-31 08:12:57 +0300 |
commit | 0c13d82ce630cc9b5480971b935353f3277cf65a (patch) | |
tree | c31c2848f14987ff8c9c5c550d77837a01472399 /config | |
parent | 5930b5d48249b3fcde7c6568fbbb3da81861bfaa (diff) | |
download | pfsense-packages-0c13d82ce630cc9b5480971b935353f3277cf65a.tar.gz pfsense-packages-0c13d82ce630cc9b5480971b935353f3277cf65a.tar.bz2 pfsense-packages-0c13d82ce630cc9b5480971b935353f3277cf65a.zip |
squidGuard blacklist fix
Diffstat (limited to 'config')
-rw-r--r-- | config/squidGuard/squidguard_blacklist.php | 333 |
1 files changed, 333 insertions, 0 deletions
diff --git a/config/squidGuard/squidguard_blacklist.php b/config/squidGuard/squidguard_blacklist.php new file mode 100644 index 00000000..a5f95379 --- /dev/null +++ b/config/squidGuard/squidguard_blacklist.php @@ -0,0 +1,333 @@ +<?php +/* $Id$ */ +/* + sg_log.inc + 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("guiconfig.inc"); +require_once("notices.inc"); +if (file_exists("/usr/local/pkg/squidguard.inc")) { + require_once("/usr/local/pkg/squidguard.inc"); +} + +# ------------------------------------------------------------------------------ +# defines +# ------------------------------------------------------------------------------ +define("SGCURL_STATUS", "/tmp/squidguard_download.log"); +define("SGUPD_STATFILE", "/tmp/squidguard_download.stat"); +define("SGBAR_SIZE", "450"); +define("DEBUG_AJAX", "false"); +# ------------------------------------------------------------------------------ +# Requests +# ------------------------------------------------------------------------------ +if ($_REQUEST['getactivity']) +{ + header("Content-type: text/javascript"); + echo squidguard_blacklist_AJAX_response( $_REQUEST ); + exit; +} + +# ------------------------------------------------------------------------------ +# Functions +# ------------------------------------------------------------------------------ + +function squidguard_blacklist_AJAX_response( $request ) +{ + $res = ''; + $sz = 0; + $pcaption = ' '; + + # Actions + if ($request['blacklist_download_start']) squidguard_blacklist_update_start( $request['blacklist_url'] ); # update start + elseif ($request['blacklist_download_cancel']) squidguard_blacklist_update_cancel(); # update cancel + elseif ($request['blacklist_restore_default']) squidguard_blacklist_restore_arcdb(); # restore default db + + # Activity + # Rebuild progress /check SG rebuild process/ + if (is_squidGuardProcess_rebuild_started()) { + $pcaption = 'Blacklist DB rebuild progress'; + $sz = squidguar_blacklist_rebuild_progress(); + } + elseif (squidguard_blacklist_update_IsStarted()) { + $pcaption = 'Blacklist download progress'; + $sz = squidguard_blacklist_update_progress(); + } + + # progress status + $szleft = $sz * SGBAR_SIZE / 100; + $szright = SGBAR_SIZE - $szleft; + + if ($sz < 0) { + # nothing to show + $sz = 0; + $pcaption = ''; + } + $res .= "el('progress_caption').innerHTML = '{$pcaption}';"; + $res .= "el('widtha').width = {$szleft};"; + $res .= "el('widthb').width = {$szright};"; + $res .= "el('progress_text').innerHTML = '{$sz} %';"; + + $status = ''; + if (file_exists(SGUPD_STATFILE)) { + $status = file_get_contents(SGUPD_STATFILE); + } + if ($status) { + $status = str_replace("\n", "\\r\\n", trim($status)); + $res .= "el('update_state').innerHTML = '{$status}';"; + $res .= "el('update_state_row').style.display='';"; + } else { + $res .= "el('update_state').innerHTML = '';"; + $res .= "el('update_state_row').style.display='none';"; + } + + return $res; +} + +function squidguard_blacklist_update_progress() +{ + $p = -1; + + if (file_exists(SGCURL_STATUS)) { + $cn = file_get_contents(SGCURL_STATUS); + if ($cn) { + $cn = explode("\r", $cn); + $cn = array_pop($cn); + $cn = explode(" ", trim($cn)); + $p = intval( $cn[0] ); + } + } + + return $p; +} + +function squidguar_blacklist_rebuild_progress() +{ + $arcdb = "/tmp/squidGuard/arcdb"; + $blfiles = "{$arcdb}/blacklist.files"; + + if (file_exists($arcdb) && file_exists($blfiles)) { + $dirlist = explode("\n", file_get_contents($blfiles)); + for ($i = 0; $i < count($dirlist); $i++) { + if ( !file_exists("$arcdb/{$dirlist[$i]}/domains.db") && + !file_exists("$arcdb/{$dirlist[$i]}/urls.db") ) + { + return intval( $i * 100 / count($dirlist) ); + } + } + } + + return 0; +} + +function is_squidGuardProcess_rebuild_started() +{ + # memo: 'ps -auxw' used 132 columns; 'ps -auxww' used 264 columns + # if cmd more then 132 need use 'ww..' key + return exec("ps -auxwwww | grep 'squidGuard -c .* -C all' | grep -v grep | awk '{print $2}' | wc -l | awk '{ print $1 }'"); +} +/* +function squidguard_blacklist_update_IsStarted() +{ + return exec("ps auxwwww | grep '" . SCR_NAME_BLKUPDATE . "' | grep -v 'grep' | awk '{print $2}' | wc -l | awk '{ print $1 }'"); +} +*/ +# ------------------------------------------------------------------------------ +# HTML Page +# ------------------------------------------------------------------------------ + +$pgtitle = "Proxy filter SquidGuard: Blacklist page"; +$selfpath = "./squidguard_blacklist.php"; +$blacklist_url = ''; + +# get squidGuard config +if (function_exists(sg_init)) { + sg_init(convert_pfxml_to_sgxml()); + $blacklist_url = $squidguard_config[F_BLACKLISTURL]; +} + +include("head.inc"); + +echo "\t<script type=\"text/javascript\" src=\"/javascript/scriptaculous/prototype.js\"></script>\n"; + +?> + +<!-- Ajax Script --> +<script type="text/javascript"> + +function el(id) { + return document.getElementById(id); +} + +function getactivity(action) { + var url = "./squidguard_blacklist.php"; + var pars = 'getactivity=yes'; + + if (action == 'download') pars = pars + '&blacklist_download_start=yes&blacklist_url=' + el('blacklist_url').value; + if (action == 'cancel') pars = pars + '&blacklist_download_cancel=yes'; + if (action == 'restore_default') pars = pars + '&blacklist_restore_default=yes'; + + var myAjax = new Ajax.Request( url, + { + method: 'post', + parameters: pars, + onComplete: activitycallback + }); +} + +function activitycallback(transport) { + +<?php if (DEBUG_AJAX == "true") echo "el('debug_textarea').innerHTML = transport.responseText;"; ?> + + if (200 == transport.status) { + result = transport.responseText; + } + + // refresh 3 sec + setTimeout('getactivity()', 3100); + //alert(transport.responseText); +} + +//document.observe('dom:loaded', function() { + // refresh +// setTimeout('getactivity()', 150); +//}); + +//document.observe('dom:loaded', function() { + // refresh +// setTimeout('getactivity()', 150); +//}); + +window.setTimeout('getactivity()', 150); +//if(!ajaxStarted) { +// try { +// window.setTimeout('getactivity()', 150); +// var ajaxStarted = true; +// }catch(e){} +//} + +</script> + +<!-- HTML --> + +<body link="#0000CC" vlink="#0000CC" alink="#0000CC"> +<form action="./squidguard_blacklist.php" method="post"> + +<?php include("fbegin.inc"); ?> + +<table width="100%" border="0" cellpadding="0" cellspacing="0"> +<!-- Tabs --> + <tr> + <td> +<?php + $tab_array = array(); + $tab_array[] = array(gettext("General settings"), false, "/pkg_edit.php?xml=squidguard.xml&id=0"); + $tab_array[] = array(gettext("Common ACL"), false, "/pkg_edit.php?xml=squidguard_default.xml&id=0"); + $tab_array[] = array(gettext("Special ACL"), false, "/pkg.php?xml=squidguard_acl.xml"); + $tab_array[] = array(gettext("Target categories"),false, "/pkg.php?xml=squidguard_dest.xml"); + $tab_array[] = array(gettext("Times"), false, "/pkg.php?xml=squidguard_time.xml"); + $tab_array[] = array(gettext("Rewrites"), false, "/pkg.php?xml=squidguard_rewr.xml"); + $tab_array[] = array(gettext("Blacklist"), true, "/squidGuard/squidguard_blacklist.php"); + $tab_array[] = array(gettext("Log"), false, "/squidGuard/squidguard_log.php"); + display_top_tabs($tab_array); +?> + </td> + </tr> + <tr> + <td> + <div id="mainarea"> + <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0"> + <tr> + <td> + <table class="tabcont" width="100%"> + <tr> + <td class="vncell" width="22%">Blacklist Update</td> + <td class="vtable"> + <big id='progress_caption' name='progress_caption'> </big><br> +<?php + echo "<nobr>"; + echo "<img src='/themes/".$g['theme']."/images/misc/bar_left.gif' height='10' width='5' border='0' align='absmiddle'>"; + echo "<img src='/themes/".$g['theme']."/images/misc/bar_blue.gif' height='10' name='widtha' id='widtha' width='" . 0 . "' border='0' align='absmiddle'>"; + echo "<img src='/themes/".$g['theme']."/images/misc/bar_gray.gif' height='10' name='widthb' id='widthb' width='" . SGBAR_SIZE . "' border='0' align='absmiddle'>"; + echo "<img src='/themes/".$g['theme']."/images/misc/bar_right.gif' height='10' width='5' border='0' align='absmiddle'> "; + echo " <u id='progress_text' name='progress_text'>0 %</u>"; + echo "</nobr>"; + echo "<br><br>"; + ?> + <nobr> + <input class="formfld unknown" size="70" id="blacklist_url" name="blacklist_url" value= '<?php echo "$blacklist_url"; ?>' >   + <!--input size='70' id='blacklist_download_start' name='blacklist_download_start' value='Download' type='button' onclick="getactivity('download');">  + <input size='70' id='blacklist_download_cancel' name='blacklist_download_cancel' value='Cancel' type='button' onclick="getactivity('cancel');"--> + </nobr><br> + <input size='70' id='blacklist_download_start' name='blacklist_download_start' value='Download' type='button' onclick="getactivity('download');"> + <input size='70' id='blacklist_download_cancel' name='blacklist_download_cancel' value='Cancel' type='button' onclick="getactivity('cancel');"> + + <input size='70' id='blacklist_restore_default' name='blacklist_restore_default' value='Restore default' type='button' onclick="getactivity('restore_default');"> + <br><br> + Enter FTP or HTTP path to the blacklist archive here. + <br><br> + </td> + </tr> + <tr id='update_state_row' name='update_state_row' style='display:none;'> + <td> </td> + <td> + <textarea rows='15' cols='55' name='update_state' id='update_state' wrap='hard' readonly> </textarea> + </td> + </tr> +<?php +# debug +if (DEBUG_AJAX !== "false") { +echo <<<EOD + <tr id='debug_row' name='debug_row'> + <td> </td> + <td> + <textarea rows='15' cols='55' name='debug_textarea' id='debug_textarea' wrap='hard' readonly> </textarea> + </td> + </tr> +EOD; +} +?> + </table> + </td> + </tr> + <tr> + <td> +<?php +#blacklist table +#echo squidguard_blacklist_list(); +?> + </td> + </tr> + </table> + </div> + </td> + </tr> +</table> + +<?php include("fend.inc"); ?> + +</form> +</body> +</html> + |