Skip to content

Commit

Permalink
E2guardian - first fixes for 2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcello Coutinho authored and Marcello Coutinho committed Jul 23, 2023
1 parent 6244c96 commit d53beba
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 24 deletions.
54 changes: 37 additions & 17 deletions pkg-e2guardian5/files/usr/local/pkg/e2guardian.inc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
git <?php
/*
* e2guardian.inc
*
* part of Unofficial packages for pfSense(R) softwate
* Copyright (c) 2015-2017 Marcello Coutinho
* Copyright (c) 2015-2023 Marcello Coutinho
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -31,6 +31,24 @@ $pfs_version = substr(trim(file_get_contents("/etc/version")),0,3);

require_once("xmlrpc_client.inc");

/*Chamadas array*/

function bp_in_array($field, $array) {
if (is_array($array)) {
return in_array($field,$array);
} else {
return false;
}
}

function bp_array_key_exists($field, $array) {
if (is_array($array)) {
return array_key_exists($field,$array);
} else {
return false;
}
}

if (version_compare(PHP_VERSION, "7.3") < 0 && !function_exists("is_countable")) {
function is_countable($var): bool{
return (is_array($var) || is_object($var) || is_iterable($var) || $var instanceof Countable);
Expand Down Expand Up @@ -74,7 +92,7 @@ function e2_text_area_decode($text) {

function e2g_check_sched($iface_sched){
global $config, $e2g_sched_in_use;
$a_schedules = &$config['schedules']['schedule'];
$a_schedules = $config['schedules']/*['schedule']*/;
$e2g_scd = true;
foreach ($a_schedules as $schedule){
if ($schedule['name'] == $iface_sched && $iface_sched <> 'Always active') {
Expand Down Expand Up @@ -181,7 +199,7 @@ function e2g_generate_rules($type) {
$proxy_ifaces = array_map('convert_friendly_interface_to_real_interface_name', $proxy_ifaces);
// Transparent Proxy Interface(s)
if ($e2g_conf['transparent_proxy'] == "on") {
if (! in_array('lo0',$proxy_ifaces)) {
if (! bp_in_array('lo0',$proxy_ifaces)) {
$proxy_ifaces[] = 'lo0';
}
$transparent_ifaces = explode(",", $e2g_conf['transparent_active_interface']);
Expand Down Expand Up @@ -218,7 +236,7 @@ function e2g_generate_rules($type) {
/* Bypass Proxy for Private Address Destination - RFC1918 */
if ($e2g_conf['private_subnet_proxy_off'] == 'on') {
foreach ($transparent_ifaces as $iface) {
$pf_transparent_rule_port = (in_array($iface, $ssl_ifaces) ? "{80,443}" : "80");
$pf_transparent_rule_port = (bp_in_array($iface, $ssl_ifaces) ? "{80,443}" : "80");
$rules .= "no rdr on $iface proto tcp from any to { 192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8 } port {$pf_transparent_rule_port}\n";
}
/* Handle PPPOE case */
Expand All @@ -241,7 +259,7 @@ function e2g_generate_rules($type) {
}
$exempt_ip = substr($exempt_ip, 2);
foreach ($transparent_ifaces as $iface) {
$pf_transparent_rule_port = (in_array($iface, $ssl_ifaces) ? "{80,443}" : "80");
$pf_transparent_rule_port = (bp_in_array($iface, $ssl_ifaces) ? "{80,443}" : "80");
$rules .= "no rdr on $iface proto tcp from { $exempt_ip } to any port {$pf_transparent_rule_port}\n";
}
/* Handle PPPOE case */
Expand All @@ -264,7 +282,7 @@ function e2g_generate_rules($type) {
}
$exempt_dest = substr($exempt_dest, 2);
foreach ($transparent_ifaces as $iface) {
$pf_transparent_rule_port = (in_array($iface, $ssl_ifaces) ? "{80,443}" : "80");
$pf_transparent_rule_port = (bp_in_array($iface, $ssl_ifaces) ? "{80,443}" : "80");
$rules .= "no rdr on $iface proto tcp from any to { $exempt_dest } port {$pf_transparent_rule_port}\n";
}
/* Handle PPPOE case */
Expand All @@ -275,7 +293,7 @@ function e2g_generate_rules($type) {
/* Transparent Proxy Interface(s) */
foreach ($transparent_ifaces as $t_iface) {
$rules .= "rdr on $t_iface proto tcp from any to ! 127.0.0.1 port 80 -> 127.0.0.1 port {$port}\n";
if (in_array($t_iface, $ssl_ifaces)) {
if (bp_in_array($t_iface, $ssl_ifaces)) {
$rules .= "rdr on $t_iface proto tcp from any to ! 127.0.0.1 port 443 -> 127.0.0.1 port {$ssl_port}\n";
}
}
Expand Down Expand Up @@ -379,7 +397,7 @@ function sync_package_e2guardian($via_rpc = "no", $install_process = false) {
'logfileformat' => '1',
'logrotate' => 'on',
'cronminute' => '0',
'cronhour' => '0'
'cronhour' => '0'
);
}
$e2guardian_log = $config['installedpackages']['e2guardianlog']['config'][0];
Expand Down Expand Up @@ -725,7 +743,7 @@ $files = array(
$config['installedpackages']['e2guardianblacklist']['config'][0] = array(
'liston' => 'both',
'cron' => '02days',
'url' => "http://www.shallalist.de/Downloads/shallalist.tar.gz",
'url' => "https://web.archive.org/web/20210502020725/http://www.shallalist.de/Downloads/shallalist.tar.gz", //"http://www.shallalist.de/Downloads/shallalist.tar.gz",
'enable_custom_script' => "",
'update_script' => "");
}
Expand Down Expand Up @@ -1091,7 +1109,7 @@ $files = array(

//Antivirus ACL
//create a default setup if not exists
if (!is_array($config['installedpackages']['e2guardianantivirusacl']['config'])) {
/*if (!is_array($config['installedpackages']['e2guardianantivirusacl']['config'])) {
$config['installedpackages']['e2guardianantivirusacl']['config'][0] = array();
}
Expand All @@ -1116,14 +1134,14 @@ $files = array(
$load_samples++;
}
file_put_contents($e2guardian_dir . "/lists/contentscanners/exceptionvirusurllist", ($e2guardian_antivirus['url_enabled'] ? e2_text_area_decode($config['installedpackages']['e2guardianantivirusacl']['config'][0]['url_list']) : ""), LOCK_EX);

//exceptionvirusextensionlist
if ($e2guardian_antivirus['extension_list'] == "" && file_exists($e2guardian_dir . '/lists/contentscanners/exceptionvirusextensionlist.sample')) {
$config['installedpackages']['e2guardianantivirusacl']['config'][0]['extension_list'] = base64_encode(file_get_contents($e2guardian_dir . '/lists/contentscanners/exceptionvirusextensionlist.sample'));
$load_samples++;
}
file_put_contents($e2guardian_dir . "/lists/contentscanners/exceptionvirusextensionlist", ($e2guardian_antivirus['extension_enabled'] ? e2_text_area_decode($config['installedpackages']['e2guardianantivirusacl']['config'][0]['extension_list']):""), LOCK_EX);

*/
//log report
$rf = "/usr/local/share/e2guardian/languages/{$reportlanguage}/template.html";
if(file_exists($rf) && !file_exists("$rf.sample")) {
Expand Down Expand Up @@ -1941,8 +1959,8 @@ function e2guardian_validate_input($post, &$input_errors) {
}


if ( is_array($post['scan_options']) && in_array('logclienthostnames', $post['scan_options']) &&
!in_array('reverseclientiplookups', $post['scan_options'])) {
if ( is_array($post['scan_options']) && bp_in_array('logclienthostnames', $post['scan_options']) &&
!bp_in_array('reverseclientiplookups', $post['scan_options'])) {
$input_errors[] = "Scan option 'Log client hostnames' needs 'Reverse client ip lookups' to be selected as well.";
}
if (is_array($post['group_options']) && sizeof ($post['group_options']) > 0) {
Expand Down Expand Up @@ -2036,7 +2054,7 @@ function e2guardian_validate_input($post, &$input_errors) {
$a_ifaces = $post['interface'] ?: array();
$s_ifaces = $post['transparent_active_interface'];
foreach ($s_ifaces as $s_iface) {
if (!in_array($s_iface, $a_ifaces)) {
if (!bp_in_array($s_iface, $a_ifaces)) {
$err_iface = convert_friendly_interface_to_friendly_descr($s_iface);
$input_errors[] = "'Transparent proxy Interface(s)' may only contain interfaces also selected in 'Proxy Interface(s)' above. '{$err_iface}' is not valid.";
unset($err_iface);
Expand All @@ -2059,7 +2077,7 @@ function e2guardian_validate_input($post, &$input_errors) {
} else if ($key == "group_options") {
$acls = array("pics", "phrase", "site", "url", "extension", "header", "content", "search");
foreach ($acls as $gacl) {
if (!array_key_exists($gacl . "acl", $post)) {
if (!bp_array_key_exists($gacl . "acl", $post)) {
$input_errors[] = ucfirst($gacl) . " must has at least one acl assigned.";
}
}
Expand Down Expand Up @@ -2199,4 +2217,6 @@ function e2guardian_do_xmlrpc_sync($sync_to_ip, $port, $protocol, $username, $pa

}



?>
6 changes: 3 additions & 3 deletions pkg-e2guardian5/files/usr/local/www/e2gerror.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

include('/usr/local/pkg/e2guardian.inc');
// Created by Marcello Coutinho based on Pfsensation (GitHub @Forid786) template.html

// you can translate via gettext or directly on these vars
Expand Down Expand Up @@ -46,9 +46,9 @@

$bypass = $deniedurl;
$prefix = (preg_match("/\?/",$deniedurl) ? "&" : "?");
if ( array_key_exists('GBYPASS',$in)) {
if ( bp_array_key_exists('GBYPASS',$in)) {
$bypass .= $prefix . "GBYPASS=" . $in['GBYPASS'];
} else if ( array_key_exists('GIBYPASS',$in)) {
} else if ( bp_array_key_exists('GIBYPASS',$in)) {
$bypass .= $prefix . "GIBYPASS=" . $in['GIBYPASS'];
}
$user_info = "-";
Expand Down
10 changes: 6 additions & 4 deletions pkg-e2guardian5/files/usr/local/www/e2guardian_ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
require_once("/etc/inc/pkg-utils.inc");
require_once("/etc/inc/globals.inc");

include('/usr/local/pkg/e2guardian.inc');

function explode_dn ($dn, $with_attributes=0) {
$result = ldap_explode_dn($dn, $with_attributes);
if (is_array($result)) {
Expand Down Expand Up @@ -69,7 +71,7 @@ function get_ldap_members($group, $user, $password) {
$results = ldap_search($ldap, $ldap_dn, $group_cn, $LDAPFieldsToFind);

$member_list = ldap_get_entries($ldap, $results);
if (in_array("debug",$argv)) {
if (bp_in_array("debug",$argv)) {
print "ldap_search $ldap_dn, $group_cn results \n";
var_dump($member_list);
}
Expand Down Expand Up @@ -112,13 +114,13 @@ function get_ldap_members($group, $user, $password) {
echo "Group : {$group['name']}({$group['description']})\n";
if (is_array($config['installedpackages']['e2guardianldap']['config'])) {
foreach ($config['installedpackages']['e2guardianldap']['config'] as $server) {
if (in_array($server['dc'], $ldap_servers)) {
if (bp_in_array($server['dc'], $ldap_servers)) {
$ldap_dn = $server['dn'];
$ldap_host = $server['dc'];
$mask = ( empty($server['mask']) ? "USER" : $server['mask'] );

$result = get_ldap_members($group[$ldap_group_source], $server['username'], $server['password']);
if (in_array("debug",$argv)) {
if (bp_in_array("debug",$argv)) {
print "get_ldap_members for {$group[$ldap_group_source]}, {$server['username']} results in ...\n";
var_dump($result);
}
Expand All @@ -136,7 +138,7 @@ function get_ldap_members($group, $user, $password) {
$replace[2] = "$name";

if (is_array($valid_account_codes)) {
if (in_array($mvalue[2], $valid_account_codes, true)) {
if (bp_in_array($mvalue[2], $valid_account_codes, true)) {
$members .= preg_replace($pattern, $replace, $mask) . "\n";
}
} else {
Expand Down

0 comments on commit d53beba

Please sign in to comment.