Remove the unset($database) statements (#7084)

* Remove the unset($database) statements
The database object is a global variable that contains a database object reference and should not be unset.

* Update event_guard.php

* Update event_guard.php

* Update event_guard.php

---------

Co-authored-by: Tim Fry <tim@fusionpbx.com>
Co-authored-by: FusionPBX <markjcrane@gmail.com>
This commit is contained in:
frytimo
2024-08-06 16:19:45 -03:00
committed by GitHub
parent c960575796
commit 7630056bb8
6 changed files with 34 additions and 44 deletions

View File

@@ -102,6 +102,9 @@
}
}
//connect to the database
$database = database::new();
//test a specific address
//$ip_address = '10.7.0.253';
//$result = access_allowed($ip_address);
@@ -174,11 +177,11 @@
}
//debug info
//if ($debug) {
//if ($debug) {
// print_r($json_array);
//}
//registration failed - block IP address unless they are registered,
//registration failed - block IP address unless they are registered
if (is_array($json_array) && $json_array['Event-Subclass'] == 'sofia::register_failure') {
//not registered so block the address
if (!access_allowed($json_array['network-ip'])) {
@@ -195,9 +198,7 @@
$sql .= "and hostname = :hostname ";
//if ($debug) { echo $sql." ".$hostname."\n"; }
$parameters['hostname'] = $hostname;
$database = new database;
$event_guard_logs = $database->select($sql, $parameters, 'all');
unset($database);
if (is_array($event_guard_logs)) {
foreach($event_guard_logs as $row) {
//unblock the ip address
@@ -222,13 +223,12 @@
if (is_array($array)) {
$p = new permissions;
$p->add('event_guard_log_edit', 'temp');
$database = new database;
$database->app_name = 'event guard';
$database->app_uuid = 'c5b86612-1514-40cb-8e2c-3f01a8f6f637';
$database->save($array);
//$message = $database->message;
$p->delete('event_guard_log_edit', 'temp');
unset($database, $array);
unset($array);
}
}
}
@@ -305,7 +305,7 @@
//block an ip address
function block($ip_address, $filter, $event) {
//define the global variables
global $firewall_path, $firewall_name;
global $database, $debug, $firewall_path, $firewall_name;
//invalid ip address
if (!filter_var($ip_address, FILTER_VALIDATE_IP)) {
@@ -332,6 +332,7 @@
closelog();
//log the blocked ip address to the database
$array = [];
$array['event_guard_logs'][0]['event_guard_log_uuid'] = uuid();
$array['event_guard_logs'][0]['hostname'] = gethostname();
$array['event_guard_logs'][0]['log_date'] = 'now()';
@@ -342,26 +343,22 @@
$array['event_guard_logs'][0]['log_status'] = 'blocked';
$p = new permissions;
$p->add('event_guard_log_add', 'temp');
$database = new database;
$database->app_name = 'event guard';
$database->app_uuid = 'c5b86612-1514-40cb-8e2c-3f01a8f6f637';
$database->save($array);
$p->delete('event_guard_log_add', 'temp');
unset($database, $array);
//send debug information to the console
if ($debug) {
echo "blocked address ".$ip_address .", line ".__line__."\n";
}
//unset the array
unset($event);
}
//unblock the ip address
function unblock($ip_address, $filter) {
//define the global variables
global $firewall_path, $firewall_name;
global $debug, $firewall_path, $firewall_name;
//invalid ip address
if (!filter_var($ip_address, FILTER_VALIDATE_IP)) {
@@ -536,6 +533,8 @@
//determine if the IP address has been allowed by the access control list node cidr
function access_control_allowed($ip_address) {
global $database;
//invalid ip address
if (!filter_var($ip_address, FILTER_VALIDATE_IP)) {
return false;
@@ -547,9 +546,7 @@
$sql .= "where node_type = 'allow' ";
$sql .= "and length(node_cidr) > 0 ";
$parameters = null;
$database = new database;
$allowed_nodes = $database->select($sql, $parameters, 'all');
unset($database);
//default authorized to false
$allowed = false;
@@ -580,6 +577,8 @@
//determine if the IP address has been allowed by a successful authentication
function user_log_allowed($ip_address) {
global $database, $debug;
//invalid ip address
if (!filter_var($ip_address, FILTER_VALIDATE_IP)) {
return false;
@@ -591,10 +590,8 @@
$sql .= "where remote_address = :remote_address ";
$sql .= "and result = 'success' ";
$sql .= "and timestamp > NOW() - INTERVAL '8 days' ";
$parameters['remote_address'] = $ip_address;
$database = new database;
$parameters['remote_address'] = $ip_address;
$user_log_count = $database->select($sql, $parameters, 'column');
unset($database);
//debug info
if ($debug) {
@@ -616,6 +613,8 @@
//determine if the IP address has been unblocked in the event guard log
function event_guard_log_allowed($ip_address) {
global $database, $debug;
//invalid ip address
if (!filter_var($ip_address, FILTER_VALIDATE_IP)) {
return false;
@@ -626,10 +625,8 @@
$sql .= "from v_event_guard_logs ";
$sql .= "where ip_address = :ip_address ";
$sql .= "and log_status = 'unblocked' ";
$parameters['ip_address'] = $ip_address;
$database = new database;
$parameters['ip_address'] = $ip_address;
$user_log_count = $database->select($sql, $parameters, 'column');
unset($database);
//debug info
if ($debug) {
@@ -651,7 +648,7 @@
//add IP table chains
function iptables_chain_add($chain) {
//define the global variables
global $firewall_path, $firewall_name;
global $firewall_path;
//if the chain exists return true
if (iptables_chain_exists($chain)) {
@@ -679,7 +676,7 @@
//check if the iptables chain exists
function iptables_chain_exists($chain) {
//define the global variables
global $firewall_path, $firewall_name;
global $firewall_path;
//build the command to check if the iptables chain exists
$command = $firewall_path."/./iptables --list INPUT --numeric | grep ".$chain." | awk '{print \$1}' | sed ':a;N;\$!ba;s/\\n/,/g' ";