diff options
author | Luiz G. Costa <luizgustavo@luizgustavo.pro.br> | 2013-09-26 15:50:34 -0300 |
---|---|---|
committer | Luiz G. Costa <luizgustavo@luizgustavo.pro.br> | 2013-09-26 15:50:34 -0300 |
commit | f1d24481b1af528e74d4c96c6af2c56e3b976a69 (patch) | |
tree | f95a9864abe569c74da0beaf4559e1a5c1c988d0 /config/squidGuard-devel/squidguard_blacklist.php | |
parent | 2b744d1d50383d698e198aa5e8f65b95c7399c25 (diff) | |
download | pfsense-packages-f1d24481b1af528e74d4c96c6af2c56e3b976a69.tar.gz pfsense-packages-f1d24481b1af528e74d4c96c6af2c56e3b976a69.tar.bz2 pfsense-packages-f1d24481b1af528e74d4c96c6af2c56e3b976a69.zip |
Add package Squidguard 1.5 beta option
Diffstat (limited to 'config/squidGuard-devel/squidguard_blacklist.php')
-rw-r--r-- | config/squidGuard-devel/squidguard_blacklist.php | 329 |
1 files changed, 329 insertions, 0 deletions
diff --git a/config/squidGuard-devel/squidguard_blacklist.php b/config/squidGuard-devel/squidguard_blacklist.php new file mode 100644 index 00000000..98e0aecd --- /dev/null +++ b/config/squidGuard-devel/squidguard_blacklist.php @@ -0,0 +1,329 @@ +<?php +/* $Id$ */ +/* + squidguard_blacklist.php + 2006-2011 Serg Dvoriancev + + part of pfSense (www.pfSense.com) + + 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 + elseif ($request['blacklist_clear_log']) squidguard_blacklist_update_clearlog(); # clear log + + # 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 ($sz && $sz != 100) $status .= "Completed {$sz} %"; + } + if ($status) { + $status = str_replace("\n", "\\r\\n", trim($status)); + $res .= "el('update_state').innerHTML = '{$status}';"; + $res .= "el('update_state_cls').style.display='';"; + $res .= "el('update_state_row').style.display='';"; + } else { + $res .= "el('update_state').innerHTML = '';"; + $res .= "el('update_state_cls').style.display='none';"; + $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 }'"); +} + +# ------------------------------------------------------------------------------ +# 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=' + encodeURIComponent(el('blacklist_url').value); + if (action == 'cancel') pars = pars + '&blacklist_download_cancel=yes'; + if (action == 'restore_default') pars = pars + '&blacklist_restore_default=yes'; + if (action == 'clear_log') pars = pars + '&blacklist_clear_log=yes'; + + var myAjax = new Ajax.Request( url, + { + method: 'get', + 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); +} + +window.setTimeout('getactivity()', 150); + +</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("Groups 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"); + $tab_array[] = array(gettext("XMLRPC Sync"), false, "/pkg_edit.php?xml=squidguard_sync.xml&id=0"); + 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_cls' name='update_state_cls' style='display:none;'> + <td> </td> + <td> + <span style="cursor: pointer;"> + <img src=<?php echo "'/themes/{$g['theme']}/images/icons/icon_block.gif'" ?> onClick="getactivity('clear_log');" title='Clear Log and Close'> + </span> + <big><b>Blacklist update Log</b></big> + </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> + |