mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2025-12-30 00:53:50 +00:00
Websockets (#7393)
* Initial commit of websockets * Move app_menu to the active_calls websockets * Fix hangup function * Remove connection wait-state on web socket server so events can process * Add timestamp and debug level to console for service debug output * Remove debug exit * Fix typo for ws_client instead of ws_server * Update app_config.php * Fix typo and remove empty function * Remove call to empty function * Fix the menu to point to the correct location * Remove Logging Class * Rename service file * Rename service file * Fix the in progress browser request * Fix browser reload and implement 'active_calls' default values * Add apply_filter function * Create new permission_filter object * In progress active calls now use filter * Add invalid_uuid_exception class * add event_key_filter to honor user permissions * add and_link and or_link for filters * Fix disconnected subscriber and add filters to honor permissions * Add $key and $value for filter * define a service name * catch throwable instead of exception * Add $key and $value for filter and allow returning null * Update permission checks when loading page * Add apply_filter function to honor subscriber permissions * Add create_filter_chain_for function to honor subscriber permissions * Add apply_filter function to honor subscriber permissions * Add apply_filter function to honor subscriber permissions * create interface to allow filterable payload * create interface to define functions required for websocket services * Pass in service class when creating a service token * Allow key/name and return null for filter * Adjust subscriber exceptions to return the ID of the subscriber * Add event filter to filter chain * Add command line options for ip and port for websockets and switch * update service to use is_a syntax * initial commit of base class for websockets system services * initial commit of the system cpu status service * remove extra line feed * fix path on active_calls * initial proof of concept for cpu status updated by websockets * Allow returning null * Use default settings to set the interval for cpu status broadcast * Improve the CPU percent function for Linux systems * Show more debug information * Allow child processes to re-connect to the web socket service * Fix websockets as plural instead of singular * Add class name list-row * Update active_calls.php * Update active_calls.php * Update websocket_client.js * Update app_config.php * Update app_menu.php * Update debian-websockets.service * Update debian-active_calls.service --------- Co-authored-by: FusionPBX <markjcrane@gmail.com>
This commit is contained in:
110
resources/classes/filter_chain.php
Normal file
110
resources/classes/filter_chain.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* FusionPBX
|
||||
* Version: MPL 1.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is FusionPBX
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mark J Crane <markjcrane@fusionpbx.com>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008-2025
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Mark J Crane <markjcrane@fusionpbx.com>
|
||||
* Tim Fry <tim@fusionpbx.com>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Builds an event filter chain link of any class implementing an event_filter interface
|
||||
*
|
||||
* @author Tim Fry <tim@fusionpbx.com>
|
||||
*/
|
||||
final class filter_chain {
|
||||
|
||||
/**
|
||||
* Builds a filter chain link for filter objects
|
||||
* @param array $filters Array of filter objects
|
||||
* @return filter
|
||||
*/
|
||||
public static function or_link(array $filters): filter {
|
||||
|
||||
// Create an anonymous object to end the filter
|
||||
$final = new class implements filter {
|
||||
|
||||
public function __invoke(string $key, $value): bool {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// Add the final object
|
||||
$chain = $final;
|
||||
|
||||
// Iterate over the objects to add them in reverse order
|
||||
for ($i = count($filters) - 1; $i >= 0; $i--) {
|
||||
$current = $filters[$i];
|
||||
|
||||
// Remember the chain that will be called next
|
||||
$next = $chain;
|
||||
|
||||
// Create an anonymous object to start the filter
|
||||
$chain = new class($current, $next) implements filter {
|
||||
|
||||
private $current;
|
||||
private $next;
|
||||
|
||||
public function __construct(filter $current, filter $next) {
|
||||
$this->current = $current;
|
||||
$this->next = $next;
|
||||
}
|
||||
|
||||
public function __invoke(string $key, $value): ?bool {
|
||||
if (($this->current)($key, $value)) {
|
||||
// Any filter passed so return true
|
||||
return true;
|
||||
}
|
||||
// Filter did not pass so we check the next one
|
||||
return ($this->next)($key, $value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Return the completed filter chain
|
||||
return $chain;
|
||||
}
|
||||
|
||||
public static function and_link(array $filters): filter {
|
||||
return new class($filters) implements filter {
|
||||
private $filters;
|
||||
|
||||
public function __construct(array $filters) {
|
||||
$this->filters = $filters;
|
||||
}
|
||||
|
||||
public function __invoke(string $key, $value): ?bool {
|
||||
foreach ($this->filters as $filter) {
|
||||
$result = ($filter)($key, $value);
|
||||
// Check if a filter requires a null to be returned
|
||||
if ($result === null) {
|
||||
return null;
|
||||
} elseif(!$result) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// All filters passed so return true
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
38
resources/classes/invalid_uuid_exception.php
Normal file
38
resources/classes/invalid_uuid_exception.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* FusionPBX
|
||||
* Version: MPL 1.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is FusionPBX
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mark J Crane <markjcrane@fusionpbx.com>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008-2025
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Mark J Crane <markjcrane@fusionpbx.com>
|
||||
* Tim Fry <tim@fusionpbx.com>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description of invalid_uuid
|
||||
*
|
||||
* @author Tim Fry <tim@fusionpbx.com>
|
||||
*/
|
||||
class invalid_uuid_exception extends Exception {
|
||||
public function __construct(string $message = "UUID is not valid", int $code = 0, ?\Throwable $previous = null): \Exception {
|
||||
return parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
@@ -391,6 +391,29 @@ abstract class service {
|
||||
}
|
||||
}
|
||||
|
||||
private static function log_level_to_string(int $level = LOG_NOTICE): string {
|
||||
switch ($level){
|
||||
case 0:
|
||||
return 'EMERGENCY';
|
||||
case 1:
|
||||
return 'ALERT';
|
||||
case 2:
|
||||
return 'CRITICAL';
|
||||
case 3:
|
||||
return 'ERROR';
|
||||
case 4:
|
||||
return 'WARNING';
|
||||
case 5:
|
||||
return 'NOTICE';
|
||||
case 6:
|
||||
return 'INFO';
|
||||
case 7:
|
||||
return 'DEBUG';
|
||||
default:
|
||||
return 'INFO';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show memory usage to the user
|
||||
*/
|
||||
@@ -416,7 +439,8 @@ abstract class service {
|
||||
|
||||
//enable sending message to the console directly
|
||||
if (self::$log_level === LOG_DEBUG || !self::$forking_enabled) {
|
||||
echo $message . "\n";
|
||||
$time = date('Y-m-d H:i:s');
|
||||
echo "[$time] [" . self::log_level_to_string($level) . "] " . $message . "\n";
|
||||
}
|
||||
|
||||
// Log the message to syslog
|
||||
|
||||
Reference in New Issue
Block a user