#!/usr/local/bin/php
$cfg) {
if (isset($cfg['iplist'])) {
$tconf[$key][F_SOURCE] .= " " . $cfg['iplist'];
unset($tconf[$key]['iplist']);
$conf_changed = true;
}
if (isset($cfg[F_DOMAINS])) {
$tconf[$key][F_SOURCE] .= " " . $cfg[F_DOMAINS];
unset($tconf[$key][F_DOMAINS]);
$conf_changed = true;
}
}
if ($conf_changed) write_config('Convert old ver. squidguard config.');
}
}
# -----------------------------------------------------------------
# convert_pfxml_to_sgxml_source
# sgxml_source: [name][ip][desc][log]
# -----------------------------------------------------------------
# Changes 04-01-2008 :
# Source fields moved to ACL page. Source page - will remove
# But in XML internal config nothing to change
# -----------------------------------------------------------------
# Changes 21-07-2008 :
# Source IP and domain move to one field, added 'username'.
function convert_pfxml_to_sgxml_source($pfconfig) {
$sgxml = array();
$pfxml = $pfconfig['installedpackages'][MODULE_ACL]['config'];
if (is_array($pfxml)) {
foreach($pfxml as $pfx) {
$sgx = array();
$sgx[F_NAME] = $pfx['name'];
$sgx[F_SOURCE] = $pfx[F_SOURCE];
$sgx[F_LOG] = $pfx[F_ENABLELOG];
$sgx[F_DESCRIPTION] = $pfx['description'];
$sgxml[F_ITEM][] = $sgx;
}
}
return $sgxml;
}
# -----------------------------------------------------------------
# convert_pfxml_to_sgxml_destination
# sgxml_destination: [name][domains][expr][urls][redir][desc][log]
# -----------------------------------------------------------------
function convert_pfxml_to_sgxml_destination($pfconfig) {
$sgxml = array();
$pfxml = $pfconfig['installedpackages'][MODULE_DESTINATION]['config'];
if (is_array($pfxml)) {
foreach($pfxml as $pfx) {
$sgx = array();
$sgx[F_NAME] = $pfx['name'];
$sgx[F_URLS] = $pfx['urls'];
$sgx[F_DOMAINS] = $pfx[F_DOMAINS];
$sgx[F_EXPRESSIONS] = $pfx['expressions'];
$sgx[F_RMOD] = isset($pfx[F_RMOD]) ? $pfx[F_RMOD] : RMOD_NONE;
$sgx[F_REDIRECT] = $pfx[F_REDIRECT];
$sgx[F_DESCRIPTION] = $pfx['description'];
$sgx[F_LOG] = $pfx[F_ENABLELOG];
$sgxml[F_ITEM][] = $sgx;
}
}
return $sgxml;
}
# -----------------------------------------------------------------
# convert_pfxml_to_sgxml_rewrite
# sgxml_rewrite: [name][desc][log][items(array): [targeturl][replaceto]]
# -----------------------------------------------------------------
function convert_pfxml_to_sgxml_rewrite($pfconfig) {
$sgxml = array();
$pfxml = $pfconfig['installedpackages'][MODULE_REWRITE]['config'];
if (is_array($pfxml)) {
foreach($pfxml as $pfx) {
$sgx = array();
$sgx[F_NAME] = $pfx['name'];
$sgx[F_DESCRIPTION] = $pfx['description'];
$sgx[F_LOG] = $pfx[F_ENABLELOG];
if (is_array($pfx['row'])) {
foreach($pfx['row'] as $pfx_row) {
$sgx_row = array();
$sgx_row[F_TARGETURL] = $pfx_row['targeturl'];
$sgx_row[F_REPLACETO] = $pfx_row['replaceto'];
$mode = '';
if (strpos($pfx_row[F_MODE], 'nocase') !== false) $mode .= 'i';
if (strpos($pfx_row[F_MODE], 'redirect') !== false) $mode .= 'r';
$sgx_row[F_MODE] = $mode; # ! sys options only - not for GUI !
$sgx[F_ITEM][] = $sgx_row;
}
}
$sgxml[F_ITEM][] = $sgx;
}
}
# additional: google safeserach
$sgxml[F_ITEM][] = squidguard_adt_rewrite_safesrch();
return $sgxml;
}
# ==================================================================
# additional
# ==================================================================
# safesearch rewrite
function squidguard_adt_rewrite_safesrch() {
$res = array();
# safesearch
$res[F_NAME] = SAFESEARCH;
$res[F_DESCRIPTION] = "Google, Yandex safesearch";
$res[F_LOG] = 'on';
squidguard_adt_safesrch_add(&$res[F_ITEM]);
return $res;
}
function squidguard_adt_safesrch_add($rewrite_item) {
if (!is_array($rewrite_item)) $rewrite_item = array();
# Google
$rewrite_item[] = array(F_TARGETURL => '(google\..*/search?.*q=.*)', F_REPLACETO => '\1\&safe=active', F_MODE => 'i');
$rewrite_item[] = array(F_TARGETURL => '(google\..*/images.*q=.*)', F_REPLACETO => '\1\&safe=active', F_MODE => 'i');
$rewrite_item[] = array(F_TARGETURL => '(google\..*/groups.*q=.*)', F_REPLACETO => '\1\&safe=active', F_MODE => 'i');
$rewrite_item[] = array(F_TARGETURL => '(google\..*/news.*q=.*)', F_REPLACETO => '\1\&safe=active', F_MODE => 'i');
# Yandex
$rewrite_item[] = array(F_TARGETURL => '(yandex\..*/yandsearch?.*text=.*)', F_REPLACETO => '\1\&fyandex=1', F_MODE => 'i');
# Yahoo
$rewrite_item[] = array(F_TARGETURL => '(search\.yahoo\..*/search.*p=.*)', F_REPLACETO => '\1\&vm=r&v=1', F_MODE => 'i');
# MSN Live search, Bing
$rewrite_item[] = array(F_TARGETURL => '(search\.live\..*/.*q=.*)', F_REPLACETO => '\1\&adlt=strict', F_MODE => 'i');
$rewrite_item[] = array(F_TARGETURL => '(search\.msn\..*/.*q=.*)', F_REPLACETO => '\1\&adlt=strict', F_MODE => 'i');
$rewrite_item[] = array(F_TARGETURL => '(\.bing\..*/.*q=.*)', F_REPLACETO => '\1\&adlt=strict', F_MODE => 'i');
return $rewrite_item;
}
# -----------------------------------------------------------------
# convert_pfxml_to_sgxml_time
# sgxml_time: [name][desc][items(array): [timetype][timedays][daterange][timerange]]
# -----------------------------------------------------------------
function convert_pfxml_to_sgxml_time($pfconfig) {
$sgxml = array();
$pfxml = $pfconfig['installedpackages'][MODULE_TIME]['config'];
if (is_array($pfxml)) {
foreach($pfxml as $pfx) {
$sgx = array();
$sgx[F_NAME] = $pfx[F_NAME];
$sgx[F_DESCRIPTION] = $pfx[F_DESCRIPTION];
if (is_array($pfx['row'])) {
foreach($pfx['row'] as $pfx_row) {
$sgx_row = array();
$sgx_row[F_TIMETYPE] = $pfx_row[F_TIMETYPE];
$sgx_row[F_TIMEDAYS] = $pfx_row[F_TIMEDAYS];
$sgx_row[F_DATERANGE] = $pfx_row[F_DATERANGE];
$sgx_row[F_TIMERANGE] = $pfx_row[F_TIMERANGE];
$sgx[F_ITEM][] = $sgx_row;
}
}
$sgxml[F_ITEM][] = $sgx;
}
}
return $sgxml;
}
# -----------------------------------------------------------------
# convert_pfxml_to_sgxml_acl
# sgxml_acl: [name][desc][disabled][timename][destname][redirect][rewritename][over_redirect][over_rewritename]
# -----------------------------------------------------------------
function convert_pfxml_to_sgxml_acl($pfconfig) {
$sgxml = array();
$pfxml = $pfconfig['installedpackages'][MODULE_ACL]['config'];
if (is_array($pfxml)) {
foreach($pfxml as $pfx) {
$sgx = array();
$sgx[F_NAME] = $pfx[F_NAME]; # [04-01-2008] new ver
$sgx[F_DESCRIPTION] = $pfx[F_DESCRIPTION];
$sgx[F_DISABLED] = $pfx[F_DISABLED];
$sgx[F_TIMENAME] = $pfx[F_TIME];
$sgx[F_REDIRECT] = $pfx[F_REDIRECT];
$sgx[F_RMOD] = isset($pfx[F_RMOD]) ? $pfx[F_RMOD] : RMOD_NONE;
$sgx[F_REWRITENAME] = $pfx[F_REWRITE];
$sgx[F_LOG] = $pfx[F_ENABLELOG];
$sgx[F_NOTALLOWINGIP] = $pfx[F_NOTALLOWINGIP];
$sgx[F_ORDER] = $pfx[F_ORDER];
# for overtime
$sgx[F_OVERREDIRECT] = $pfx[F_REDIRECT]; # disabled ->- $pfx[F_OVERREDIRECT];
$sgx[F_OVERREWRITENAME] = $pfx[F_OVERREWRITE];
# destinations
if (strpos($pfx['dest'], '[') === false) {
$sgx[F_DESTINATIONNAME] = trim($pfx['dest']);
$sgx[F_OVERDESTINATIONNAME] = '';
}
else {
$sgx[F_DESTINATIONNAME] = trim( substr($pfx['dest'], 0, strpos($pfx['dest'], '[')) );
$sgx[F_OVERDESTINATIONNAME] = trim( strstr($pfx['dest'], '[') );
$sgx[F_OVERDESTINATIONNAME] = trim( str_replace(']', '', $sgx[F_OVERDESTINATIONNAME]) );
$sgx[F_OVERDESTINATIONNAME] = trim( str_replace('[', '', $sgx[F_OVERDESTINATIONNAME]) );
}
# !ATTENTION! '!all' must be convert to 'none'
$sgx[F_DESTINATIONNAME] = str_replace("!all", "none", $sgx[F_DESTINATIONNAME]);
$sgx[F_OVERDESTINATIONNAME] = str_replace("!all", "none", $sgx[F_OVERDESTINATIONNAME]);
# if empty - adding 'none'
if (!$sgx[F_DESTINATIONNAME]) $sgx[F_DESTINATIONNAME] = "none";
if (!$sgx[F_OVERDESTINATIONNAME]) $sgx[F_OVERDESTINATIONNAME] = "none";
# safesearch
if ($pfx[SAFESEARCH] === 'on') {
# assign safesearch rewrite
$sgx[F_REWRITENAME] = SAFESEARCH;
$sgx[F_OVERREWRITENAME] = SAFESEARCH;
}
$sgxml[F_ITEM][] = $sgx;
}
}
return $sgxml;
}
# -----------------------------------------------------------------
# convert_pfxml_to_sgxml_default
# sgxml_acl: [name][desc][disabled][timename][destname][redirect][rewritename][over_redirect][over_rewritename]
# -----------------------------------------------------------------
function convert_pfxml_to_sgxml_default($pfconfig) {
$pfxml = $pfconfig['installedpackages'][MODULE_DEFAULT]['config'];
$pfx = $pfxml[0];
$sgx = array();
$sgx[F_NAME] = 'default';
$sgx[F_DESCRIPTION] = '';
$sgx[F_DISABLED] = '';
$sgx[F_TIMENAME] = $pfx[F_TIME];
$sgx[F_RMOD] = isset($pfx[F_RMOD]) ? $pfx[F_RMOD] : RMOD_INT_ERRORPAGE;
$sgx[F_REDIRECT] = $pfx[F_REDIRECT];
$sgx[F_REWRITENAME] = $pfx[F_REWRITE];
$sgx[F_LOG] = $pfx[F_ENABLELOG];
$sgx[F_NOTALLOWINGIP] = $pfx[F_NOTALLOWINGIP];
# destinations
if (strpos($pfx['dest'], '[') === false)
$sgx[F_DESTINATIONNAME] = trim($pfx['dest']);
else $sgx[F_DESTINATIONNAME] = trim( substr($pfx['dest'], 0, strpos($pfx['dest'], '[')) );
# !ATTENTION! '!all' must be convert to 'none'
$sgx[F_DESTINATIONNAME] = str_replace("!all", "none", $sgx[F_DESTINATIONNAME]);
# if empty - adding 'none'
if (!$sgx[F_DESTINATIONNAME]) $sgx[F_DESTINATIONNAME] = "none";
# safesearch
if ($pfx[SAFESEARCH] === 'on') {
# assign safesearch rewrite
$sgx[F_REWRITENAME] = SAFESEARCH;
}
return $sgx;
}
squidguard_resync();
echo "Done";
?>
quinta-feira, fevereiro 14, 2013
Squidguard blacklist autoupdate script
www.oriontechnologysolutions.com/wp-content/uploads/2011/07/squidguard_update.php_.txt
Assinar:
Postar comentários (Atom)
Nenhum comentário:
Postar um comentário