Watch for event_guard:unblock and more debug info.

This commit is contained in:
FusionPBX 2022-08-20 12:47:24 -06:00 committed by GitHub
parent 6365b28cf2
commit 01b31dce1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 53 additions and 40 deletions

View File

@ -121,8 +121,8 @@
} }
//preset values //preset values
$interval_seconds = 30; //$interval_seconds = 30;
$previous_time = time() - $interval_seconds; //$previous_time = time() - $interval_seconds;
//loop through the switch events //loop through the switch events
$cmd = "event json ALL"; $cmd = "event json ALL";
@ -130,53 +130,17 @@
while (true) { while (true) {
//check pending unblock requests //check pending unblock requests
/*
if ((time() - $previous_time) > $interval_seconds) { if ((time() - $previous_time) > $interval_seconds) {
//debug info //debug info
if ($debug) { if ($debug) {
echo "time difference: ". (time() - $previous_time)."\n"; echo "time difference: ". (time() - $previous_time)."\n";
} }
//check the database for pending requests
$sql = "select event_guard_log_uuid, log_date, filter, ip_address, extension, user_agent ";
$sql .= "from v_event_guard_logs ";
$sql .= "where log_status = 'pending' ";
$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
unblock($row['ip_address'], $row['filter']);
//log the blocked ip address to the syslog
openlog("fusionpbx", LOG_PID | LOG_PERROR);
syslog(LOG_WARNING, "fusionpbx: unblocked: [ip_address: ".$row['ip_address'].", filter: ".$row['filter'].", to-user: ".$row['extension'].", to-host: ".$row['hostname'].", line: ".__line__."]");
closelog();
//log the blocked ip address to the database
$array['event_guard_logs'][0]['event_guard_log_uuid'] = $row['event_guard_log_uuid'];
$array['event_guard_logs'][0]['log_date'] = 'now()';
$array['event_guard_logs'][0]['log_status'] = 'unblocked';
}
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);
}
}
//update the time //update the time
$previous_time = time(); $previous_time = time();
} }
*/
//reconnect to event socket //reconnect to event socket
if (!$socket) { if (!$socket) {
@ -199,6 +163,9 @@
unset($json_response); unset($json_response);
} }
//debug info
//view_array($json_array, false);
//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') { if (is_array($json_array) && $json_array['Event-Subclass'] == 'sofia::register_failure') {
//not registered so block the address //not registered so block the address
@ -207,6 +174,52 @@
} }
} }
//sendevent CUSTOM event_guard:unblock
if (is_array($json_array) && $json_array['Event-Subclass'] == 'event_guard:unblock') {
//check the database for pending requests
$sql = "select event_guard_log_uuid, log_date, filter, ip_address, extension, user_agent ";
$sql .= "from v_event_guard_logs ";
$sql .= "where log_status = 'pending' ";
$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
unblock($row['ip_address'], $row['filter']);
//log the blocked ip address to the syslog
openlog("fusionpbx", LOG_PID | LOG_PERROR);
syslog(LOG_WARNING, "fusionpbx: unblocked: [ip_address: ".$row['ip_address'].", filter: ".$row['filter'].", to-user: ".$row['extension'].", to-host: ".$row['hostname'].", line: ".__line__."]");
closelog();
//debug info
if ($debug) {
echo "unblocked: [ip_address: ".$row['ip_address'].", filter: ".$row['filter'].", to-user: ".$row['extension'].", to-host: ".$row['hostname'].", line: ".__line__."]\n";
}
//log the blocked ip address to the database
$array['event_guard_logs'][0]['event_guard_log_uuid'] = $row['event_guard_log_uuid'];
$array['event_guard_logs'][0]['log_date'] = 'now()';
$array['event_guard_logs'][0]['log_status'] = 'unblocked';
}
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);
}
}
}
//registration to the IP address //registration to the IP address
if (is_array($json_array) && $json_array['Event-Subclass'] == 'sofia::pre_register') { if (is_array($json_array) && $json_array['Event-Subclass'] == 'sofia::pre_register') {
if (isset($json_array['to-host'])) { if (isset($json_array['to-host'])) {