Create more documentation (#7627)

* Documentation, format class, no modification.
This commit is contained in:
frytimo
2025-11-18 21:33:07 -04:00
committed by GitHub
parent e619c97ce6
commit adfc4cc469
104 changed files with 24461 additions and 21721 deletions

View File

@@ -54,6 +54,13 @@
}
//define the functions
/**
* Converts an array to a CSV string.
*
* @param array &$array The input array. It should be a multidimensional array where the first level keys are column headers and the second level arrays are rows.
*
* @return string|null The CSV string representation of the input array, or null if the input array is empty.
*/
function array2csv(array &$array) {
if (count($array) == 0) {
return null;
@@ -69,6 +76,13 @@
}
//send download headers
/**
* Sends HTTP headers to force a file download.
*
* @param string $filename The name of the file to be downloaded, excluding the path.
*
* @return void
*/
function download_send_headers($filename) {
// disable caching
$now = gmdate("D, d M Y H:i:s");

View File

@@ -40,6 +40,16 @@
//built in str_getcsv requires PHP 5.3 or higher, this function can be used to reproduce the functionality but requires PHP 5.1.0 or higher
if (!function_exists('str_getcsv')) {
/**
* Parse a CSV string into an array.
*
* @param string $input The CSV data to parse.
* @param string $delimiter The field delimiter (default: ",").
* @param string $enclosure The field enclosure character (default: """).
* @param string $escape The escape character (default: "\"").
*
* @return array An array containing the parsed CSV fields.
*/
function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") {
$fp = fopen("php://memory", 'r+');
fputs($fp, $input);
@@ -212,6 +222,14 @@
}
//get the parent table
/**
* Retrieve the parent table for a given table in a schema.
*
* @param array $schema The database schema to search in.
* @param string $table_name The name of the table for which to find the parent.
*
* @return mixed The name of the parent table, or NULL if not found.
*/
function get_parent($schema,$table_name) {
foreach ($schema as $row) {
if ($row['table'] == $table_name) {

View File

@@ -13,24 +13,30 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_uuid;
@@ -60,7 +66,13 @@
}
/**
* delete records
* Deletes one or multiple records from the access controls table.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
@@ -123,6 +135,14 @@
}
}
/**
* Deletes one or more access control nodes.
*
* @param array $records Array of records to delete, where each record is an associative array containing the
* 'uuid' and 'checked' keys.
*
* @return void
*/
public function delete_nodes($records) {
//assign private variables
@@ -177,7 +197,12 @@
}
/**
* copy records
* Copy access controls and their nodes.
*
* @param array $records An array of records to copy. Each record should contain a 'checked' key with value 'true'
* and a 'uuid' key with the UUID of the access control or node to copy.
*
* @return void
*/
public function copy($records) {

View File

@@ -35,12 +35,29 @@ class caller_context_filter implements filter {
private $domains;
/**
* Initializes the object with an array of domain names.
*
* @param array $domain_names Array of domain names to initialize the object with.
*
* @return void
*/
public function __construct(array $domain_names) {
foreach ($domain_names as $name) {
$this->domains[$name] = true;
}
}
/**
* Invokes this method as a callable.
*
* @param string $key The event key, which is used for validation and filtering.
* @param mixed $value The value associated with the event key, used to determine
* whether the filter chain should drop the payload.
*
* @return bool|null Returns true if the key is not 'caller_context' or the value exists in the domains,
* otherwise returns null to drop the payload.
*/
public function __invoke(string $key, $value): ?bool {
// return true when not on the event key caller_context to validate
if ($key !== 'caller_context') {

View File

@@ -35,10 +35,28 @@ class event_filter implements filter {
private $event_names;
/**
* Initializes the object with the event names to filter on.
*
* @param array $event_names Array of event names to initialize the object with
*/
public function __construct(array $event_names) {
$this->add_event_names($event_names);
}
/**
* Invokes this method to filter events.
*
* @param string $key The key name that will be used for filtering, currently only
* supports the "event_name" key.
* @param mixed $value The value associated with the provided key.
*
* @return bool|null Returns true if the invocation is valid and the event name
* filter has not been applied yet. If the invocation has an "event_name"
* key and its corresponding value, this method will return a boolean
* indicating whether the event name already exists in the list of allowed
* names or not. Otherwise returns null.
*/
public function __invoke(string $key, $value): ?bool {
if ($key !== 'event_name') {
return true;
@@ -69,17 +87,20 @@ class event_filter implements filter {
}
}
/**
* Checks if an event with the given name is present in the filters.
*
* @param string $name The name of the event to check for.
*
* @return bool|null True if the event is found, otherwise null. Returns null
* when the event is not allowed due to permissions constraints.
*/
public function has_event_name(string $name): ?bool {
if (isset($this->event_names[$name]))
if (isset($this->event_names[$name])) {
return true;
//
// If the event name is not allowed by the permissions given in
// this object, then the entire event must be dropped. I could
// not figure out a better way to do this except to throw an
// exception so that the caller can drop the message.
//
// TODO: Find another way not so expensive to reject the payload
//
}
//reject the payload
return null;
}
}

View File

@@ -34,10 +34,23 @@ class event_key_filter implements filter {
private $filters;
/**
* Initializes a new instance of the object with specified filters.
*
* @param array $filters Optional array of initial filters to be applied.
*/
public function __construct(array $filters = []) {
$this->add_filters($filters);
}
/**
* Invokes a filter check with the given key and value.
*
* @param string $key The key of the filter to check
* @param mixed $value The value associated with the filter key
*
* @return bool|null True if the filter exists, false otherwise
*/
public function __invoke(string $key, $value): ?bool {
return $this->has_filter_key($key);
}
@@ -84,6 +97,13 @@ class event_key_filter implements filter {
}
}
/**
* Checks if a filter key exists.
*
* @param string $key The filter key to check for existence.
*
* @return bool True if the filter key exists, false otherwise.
*/
public function has_filter_key(string $key): bool {
return isset($this->filters[$key]);
}

View File

@@ -46,6 +46,11 @@ class event_message implements filterable_payload {
* @var array
*/
private $event;
/**
* Body of the SIP MESSAGE used in SMS
* @var string
*/
private $body;
/**
@@ -102,6 +107,11 @@ class event_message implements filterable_payload {
return $this->event[$name] ?? '';
}
/**
* Return an array representation of this object.
*
* @return array
*/
public function __toArray(): array {
$array = [];
foreach ($this->event as $key => $value) {
@@ -110,10 +120,22 @@ class event_message implements filterable_payload {
return $array;
}
/**
* Convert the current object into an array representation.
*
* @return array
*/
public function to_array(): array {
return $this->__toArray();
}
/**
* Apply a filter to the event collection.
*
* @param filter $filter The filter function to apply
*
* @return self This object for method chaining
*/
public function apply_filter(filter $filter) {
foreach ($this->event as $key => $value) {
$result = ($filter)($key, $value);
@@ -126,6 +148,16 @@ class event_message implements filterable_payload {
return $this;
}
/**
* Parse an active calls JSON string and return a list of event messages.
*
* This method expects a JSON string where each row represents an active call, and returns
* a list of event_message objects populated with the relevant details for each call.
*
* @param string $json_string The JSON string to parse.
*
* @return array A list of event_message objects.
*/
public static function parse_active_calls($json_string): array {
$calls = [];
$json_array = json_decode($json_string, true);
@@ -181,6 +213,15 @@ class event_message implements filterable_payload {
return null;
}
/**
* Creates a new instance from a switch event.
*
* @param array|string $raw_event The raw event data.
* @param filter|null $filter Optional filter to be applied on the created object.
* @param int $flags Flags controlling the creation process (see EVENT_SWAP_API and EVENT_USE_SUBCLASS).
*
* @return self
*/
public static function create_from_switch_event($raw_event, filter $filter = null, $flags = 3): self {
// Set the options from the flags passed
@@ -264,6 +305,14 @@ class event_message implements filterable_payload {
return $this->body;
}
/**
* Convert the event object to an array representation.
*
* This method iterates over the event properties and includes them in the returned array.
* If the body is not null, it will be included as a separate key-value pair in the resulting array.
*
* @return array
*/
public function event_to_array(): array {
$array = [];
foreach ($this->event as $key => $value) {
@@ -275,15 +324,39 @@ class event_message implements filterable_payload {
return $array;
}
/**
* Return an iterator for this object.
*
* This method allows iteration over the event data as a Traversable object.
*
* @return \Traversable
*/
public function getIterator(): \Traversable {
yield from $this->event_to_array();
}
/**
* Check if a specific event key exists in this object.
*
* @param mixed $offset The key of the event to check for existence
*
* @return bool True if the event key exists, false otherwise
*/
public function offsetExists(mixed $offset): bool {
self::sanitize_event_key($offset);
return isset($this->event[$offset]);
}
/**
* Return the value associated with the given key from this event object.
*
* If the key is 'body', returns the event body. Otherwise, returns the value
* stored in the 'event' array for the given key.
*
* @param mixed $offset The key to retrieve the value for.
*
* @return mixed The value associated with the given key.
*/
public function offsetGet(mixed $offset): mixed {
self::sanitize_event_key($offset);
if ($offset === self::BODY_ARRAY_KEY) {
@@ -292,6 +365,16 @@ class event_message implements filterable_payload {
return $this->event[$offset];
}
/**
* Set the value for a given offset in this object.
*
* @param mixed $offset The key or index to set the value for. If it is
* {@link self::BODY_ARRAY_KEY}, this method will replace the
* entire body of the event with the provided value.
* @param mixed $value The new value to be associated with the offset.
*
* @return void
*/
public function offsetSet(mixed $offset, mixed $value): void {
self::sanitize_event_key($offset);
if ($offset === self::BODY_ARRAY_KEY) {
@@ -301,6 +384,15 @@ class event_message implements filterable_payload {
}
}
/**
* Unsets a property from the event array.
*
* This method first sanitizes the provided offset using the sanitize_event_key method to prevent potential security vulnerabilities.
* If the sanitized offset is equal to the BODY_ARRAY_KEY, it sets the body property of this object to null.
* Otherwise, it removes the specified key from the event array.
*
* @param mixed $offset The index or key to be unset from the event array.
*/
public function offsetUnset(mixed $offset): void {
self::sanitize_event_key($offset);
if ($offset === self::BODY_ARRAY_KEY) {

View File

@@ -35,6 +35,11 @@ class extension_filter {
private $extensions;
/**
* Initializes the class with an array of extensions for fast lookup.
*
* @param array $extensions An optional array of extension configurations. Defaults to [].
*/
public function __construct(array $extensions = []) {
//organize the extensions in a way we can use isset for fast lookup
foreach ($extensions as $extension) {
@@ -43,6 +48,14 @@ class extension_filter {
}
}
/**
* Invokes this instance with a key-value pair for fast lookup.
*
* @param string $key The presence ID key to look up in the extensions array.
* @param mixed $value The value associated with the key, which is used as an index in the extensions array.
*
* @return bool|null True if no match was found or the key is not 'channel_presence_id', null otherwise when dropping a message.
*/
public function __invoke(string $key, $value): ?bool {
//only match on channel_presence_id key
if ($key === 'channel_presence_id' && !isset($this->extensions[$value])) {

View File

@@ -2,123 +2,137 @@
class azure {
public static $formats = array (
/**
* Array of available speech formats.
*
* This array contains a list of voice names and their corresponding languages
* and genders. The keys are the voice names, and the values are arrays containing
* the language code and gender.
*
* @var array
*/
public static $formats = [
'English-Zira' =>
array (
[
'lang' => 'en-US',
'gender' => 'Female',
'name' => 'Microsoft Server Speech Text to Speech Voice (en-US, ZiraRUS)'
),
'name' => 'Microsoft Server Speech Text to Speech Voice (en-US, ZiraRUS)',
],
'English-Jessa' =>
array (
[
'lang' => 'en-US',
'gender' => 'Female',
'name' => 'Microsoft Server Speech Text to Speech Voice (en-US, JessaRUS)'
),
'name' => 'Microsoft Server Speech Text to Speech Voice (en-US, JessaRUS)',
],
'English-Benjamin' =>
array (
[
'lang' => 'en-US',
'gender' => 'Male',
'name' => 'Microsoft Server Speech Text to Speech Voice (en-US, BenjaminRUS)'
),
'name' => 'Microsoft Server Speech Text to Speech Voice (en-US, BenjaminRUS)',
],
'British-Susan' =>
array (
[
'lang' => 'en-GB',
'gender' => 'Female',
'name' => 'Microsoft Server Speech Text to Speech Voice (en-GB, Susan, Apollo)'
),
'name' => 'Microsoft Server Speech Text to Speech Voice (en-GB, Susan, Apollo)',
],
'British-Hazel' =>
array (
[
'lang' => 'en-GB',
'gender' => 'Female',
'name' => 'Microsoft Server Speech Text to Speech Voice (en-GB, HazelRUS)'
),
'name' => 'Microsoft Server Speech Text to Speech Voice (en-GB, HazelRUS)',
],
'British-George' =>
array (
[
'lang' => 'en-GB',
'gender' => 'Male',
'name' => 'Microsoft Server Speech Text to Speech Voice (en-GB, George, Apollo)'
),
'name' => 'Microsoft Server Speech Text to Speech Voice (en-GB, George, Apollo)',
],
'Australian-Catherine' =>
array (
[
'lang' => 'en-AU',
'gender' => 'Female',
'name' => 'Microsoft Server Speech Text to Speech Voice (en-AU, Catherine)'
),
'name' => 'Microsoft Server Speech Text to Speech Voice (en-AU, Catherine)',
],
'Spanish-Helena' =>
array (
[
'lang' => 'es-ES',
'gender' => 'Female',
'name' => 'Microsoft Server Speech Text to Speech Voice (es-ES, HelenaRUS)'
),
'name' => 'Microsoft Server Speech Text to Speech Voice (es-ES, HelenaRUS)',
],
'Spanish-Laura' =>
array (
[
'lang' => 'es-ES',
'gender' => 'Female',
'name' => 'Microsoft Server Speech Text to Speech Voice (es-ES, Laura, Apollo)'
),
'name' => 'Microsoft Server Speech Text to Speech Voice (es-ES, Laura, Apollo)',
],
'Spanish-Pablo' =>
array (
[
'lang' => 'es-ES',
'gender' => 'Male',
'name' => 'Microsoft Server Speech Text to Speech Voice (es-ES, Pablo, Apollo)'
),
'name' => 'Microsoft Server Speech Text to Speech Voice (es-ES, Pablo, Apollo)',
],
'French-Julie' =>
array (
[
'lang' => 'fr-FR',
'gender' => 'Female',
'name' => 'Microsoft Server Speech Text to Speech Voice (fr-FR, Julie, Apollo)'
),
'name' => 'Microsoft Server Speech Text to Speech Voice (fr-FR, Julie, Apollo)',
],
'French-Hortense' =>
array (
[
'lang' => 'fr-FR',
'gender' => 'Female',
'name' => 'Microsoft Server Speech Text to Speech Voice (fr-FR, HortenseRUS)'
),
'name' => 'Microsoft Server Speech Text to Speech Voice (fr-FR, HortenseRUS)',
],
'French-Paul' =>
array (
[
'lang' => 'fr-FR',
'gender' => 'Male',
'name' => 'Microsoft Server Speech Text to Speech Voice (fr-FR, Paul, Apollo)'
),
'name' => 'Microsoft Server Speech Text to Speech Voice (fr-FR, Paul, Apollo)',
],
'German-Hedda' =>
array (
[
'lang' => 'de-DE',
'gender' => 'Female',
'name' => 'Microsoft Server Speech Text to Speech Voice (de-DE, Hedda)'
),
'name' => 'Microsoft Server Speech Text to Speech Voice (de-DE, Hedda)',
],
'Russian-Irina' =>
array (
[
'lang' => 'ru-RU',
'gender' => 'Female',
'name' => 'Microsoft Server Speech Text to Speech Voice (ru-RU, Irina, Apollo)'
),
'name' => 'Microsoft Server Speech Text to Speech Voice (ru-RU, Irina, Apollo)',
],
'Russian-Pavel' =>
array (
[
'lang' => 'ru-RU',
'gender' => 'Male',
'name' => 'Microsoft Server Speech Text to Speech Voice (ru-RU, Pavel, Apollo)'
),
'name' => 'Microsoft Server Speech Text to Speech Voice (ru-RU, Pavel, Apollo)',
],
'Chinese-Huihui' =>
array (
[
'lang' => 'zh-CN',
'gender' => 'Female',
'name' => 'Microsoft Server Speech Text to Speech Voice (zh-CN, HuihuiRUS)'
),
'name' => 'Microsoft Server Speech Text to Speech Voice (zh-CN, HuihuiRUS)',
],
'Chinese-Yaoyao' =>
array (
[
'lang' => 'zh-CN',
'gender' => 'Female',
'name' => 'Microsoft Server Speech Text to Speech Voice (zh-CN, Yaoyao, Apollo)'
),
'name' => 'Microsoft Server Speech Text to Speech Voice (zh-CN, Yaoyao, Apollo)',
],
'Chinese-Kangkang' =>
array (
[
'lang' => 'zh-CN',
'gender' => 'Male',
'name' => 'Microsoft Server Speech Text to Speech Voice (zh-CN, Kangkang, Apollo)'
)
);
'name' => 'Microsoft Server Speech Text to Speech Voice (zh-CN, Kangkang, Apollo)',
],
];
/**
* Initializes the object with provided setting array.
*
* @param array $setting_array An optional array of setting values. Defaults to an empty array.
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
$domain_uuid = $setting_array['domain_uuid'] ?? $_SESSION['domain_uuid'] ?? '';
@@ -130,23 +144,47 @@ class azure{
$this->settings = $setting_array['settings'] ?? new settings(['database' => $this->database, 'domain_uuid' => $domain_uuid, 'user_uuid' => $user_uuid]);
}
/**
* Returns the URL for obtaining a token from Microsoft Cognitive Services.
*
* @return string The URL for issuing a token
*/
private static function getTokenUrl() {
return "https://api.cognitive.microsoft.com/sts/v1.0/issueToken";
}
/**
* Returns the URL for interacting with Microsoft Bing Speech API.
*
* @return string The URL for making requests to the Bing Speech API
*/
private static function getApiUrl() {
return "https://speech.platform.bing.com/synthesize";
}
/**
* Returns the subscription key from Azure settings.
*
* @param settings $settings The settings object containing Azure configuration
*
* @return string The subscription key for Azure services
*/
private static function getSubscriptionKey(settings $settings) {
return $settings->get('azure', 'key');
}
/**
* Obtains a token from Microsoft Cognitive Services.
*
* @param settings $settings Settings object containing subscription key and other parameters.
*
* @return string The response from the server, which is expected to be an XML token.
*/
private static function _getToken(settings $settings) {
$url = self::getTokenUrl();
$subscriptionKey = self::getSubscriptionKey($settings);
$headers = array();
$headers = [];
$headers[] = 'Ocp-Apim-Subscription-Key: ' . $subscriptionKey;
$headers[] = 'Content-Length: 0';
@@ -167,6 +205,15 @@ class azure{
return $response;
}
/**
* Synthesizes the given data into a WAV audio file using Microsoft Cognitive Services.
*
* @param object $settings Settings for the API call
* @param string $data The text to be synthesized
* @param string $format_key The key of the format in self::$formats
*
* @return string The path to the generated WAV file
*/
public static function synthesize(settings $settings, $data, $format_key) {
$lang = self::$formats[$format_key]['lang'];
@@ -176,7 +223,7 @@ class azure{
$url = self::getApiUrl();
$headers = array();
$headers = [];
$headers[] = 'Authorization: Bearer ' . $token;
$headers[] = 'Content-Type: application/ssml+xml';
$headers[] = 'X-Microsoft-OutputFormat: riff-16khz-16bit-mono-pcm';

View File

@@ -66,7 +66,9 @@
private $domain_name;
/**
* Called when the object is created
* Initializes the object with domain and user UUIDs, domain name, and database objects.
*
* @param array $setting_array An optional array containing settings for this object. Defaults to an empty array.
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -83,7 +85,10 @@
}
/**
* Get the call activity
* Handles the call activity by retrieving extensions and their user status,
* sending a command to retrieve active calls, and building a response array.
*
* @return mixed The response array containing extension details and active call information.
*/
public function call_activity() {

View File

@@ -68,7 +68,9 @@
private $toggle_values;
/**
* called when the object is created
* Initializes the object with settings and default values.
*
* @param array $setting_array Associative array of setting keys to their respective values (optional)
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -92,7 +94,13 @@
}
/**
* delete records
* Deletes one or multiple records from the access controls table.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->permission_prefix.'delete')) {
@@ -141,7 +149,13 @@
}
/**
* toggle records
* Toggles the state of the specified records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
if (permission_exists($this->permission_prefix.'edit')) {
@@ -212,7 +226,12 @@
}
/**
* copy records
* Copies one or more records
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
if (permission_exists($this->permission_prefix.'add')) {

View File

@@ -456,6 +456,17 @@ if (permission_exists('call_block_all') || permission_exists('call_block_ring_gr
echo " ".$text['label-action']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
/**
* Select a call block action.
*
* This function generates an HTML select element for selecting a call block
* action. It includes options for rejecting, busy, holding, and other actions,
* as well as options for extensions, IVRs, ring groups, and voicemail.
*
* @param bool $label Whether to include the label option or not.
*
* @return void The function does not return any value.
*/
function call_block_action_select($label = false) {
global $select_margin, $text, $call_block_app, $call_block_data, $extensions, $ivrs, $voicemails, $ring_groups;
echo "<select class='formfld' style='".$select_margin."' name='call_block_action'>\n";

View File

@@ -13,30 +13,38 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_uuid;
/**
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_name;
@@ -60,7 +68,12 @@
public $call_block_data;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -83,7 +96,13 @@
}
/**
* delete records
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->permission_prefix . 'delete')) {
@@ -162,7 +181,13 @@
}
/**
* toggle records
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
if (permission_exists($this->permission_prefix . 'edit')) {
@@ -235,7 +260,13 @@
}
/**
* copy records
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
if (permission_exists($this->permission_prefix . 'add')) {
@@ -311,7 +342,13 @@
}
/**
* add records
* Adds one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function add($records) {
if (permission_exists($this->permission_prefix . 'add')) {
@@ -389,12 +426,10 @@
if (substr($row["caller_id_number"], 0, 1) == "+") {
//format e.164
$call_block_number = str_replace("+" . trim($country_code), "", trim($row["caller_id_number"]));
}
elseif (!empty($row["caller_id_number"])) {
} elseif (!empty($row["caller_id_number"])) {
//remove the country code if its the first in the string
$call_block_number = ltrim(trim($row["caller_id_number"]), $country_code ?? '');
}
else {
} else {
$call_block_number = '';
}
@@ -421,8 +456,7 @@
$array['call_block'][$x]['call_block_enabled'] = true;
$array['call_block'][$x]['date_added'] = time();
$x++;
}
else {
} else {
if (is_array($user_extensions)) {
foreach ($user_extensions as $field) {
if (is_uuid($field['extension_uuid'])) {

View File

@@ -61,6 +61,14 @@
$broadcast_toll_allow = '';
//function to Upload CSV/TXT file
/**
* Uploads a file and prepares the SQL query for broadcasting phone numbers.
*
* @param string $sql The initial SQL query.
* @param mixed $broadcast_phone_numbers The phone numbers to broadcast, or an empty value if not applicable.
*
* @return array An array containing the result code ('code') and the prepared SQL query ('sql').
*/
function upload_file($sql, $broadcast_phone_numbers) {
$upload_csv = $sql = '';
if (isset($_FILES['broadcast_phone_numbers_file']) && !empty($_FILES['broadcast_phone_numbers_file']) && $_FILES['broadcast_phone_numbers_file']['size'] > 0) {

View File

@@ -46,6 +46,17 @@
ini_set('max_execution_time',3600);
//define the asynchronous command function
/**
* Asynchronously executes a command.
*
* This method runs the given $cmd as an asynchronous process. On Windows, it uses
* proc_open to create a new process with pipes for stdin, stdout, and stderr. On
* Posix systems (e.g., Linux, macOS), it uses exec to run the command in the background.
*
* @param string $cmd The command to execute asynchronously.
*
* @return int|bool The return value of proc_close() on Windows or false on failure; null if not executed successfully.
*/
function cmd_async($cmd) {
//windows
if (stristr(PHP_OS, 'WIN')) {

View File

@@ -38,18 +38,23 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_uuid;
@@ -63,7 +68,11 @@
private $uuid_prefix;
/**
* called when the object is created
* Initializes the object with the provided settings.
*
* @param array $setting_array An optional array of settings, defaulting to an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -81,7 +90,13 @@
}
/**
* delete records
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->permission_prefix . 'delete')) {
@@ -125,7 +140,13 @@
}
/**
* copy records
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
if (permission_exists($this->permission_prefix . 'add')) {

View File

@@ -60,6 +60,15 @@
}
//convert the string to a named array
/**
* Converts a string into a named array based on the specified delimiter.
*
* @param string $tmp_str The input string to be converted.
* @param string $tmp_delimiter The delimiter used to split the string and field values.
*
* @return array A 2D array where each inner array represents a row in the original string,
* with keys corresponding to the field names from the first line of the string.
*/
function str_to_named_array($tmp_str, $tmp_delimiter) {
$tmp_array = explode ("\n", $tmp_str);
$result = array();

View File

@@ -37,7 +37,9 @@
const app_uuid = '95788e50-9500-079e-2807-fd530b0ea370';
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
public $domain_uuid;
@@ -57,18 +59,23 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_name;
@@ -82,7 +89,11 @@
private $uuid_prefix;
/**
* Called when the object is created
* Initializes the object with provided settings.
*
* @param array $setting_array Optional array containing domain and user UUIDs, and database instance.
* If not provided, default values from session will be used.
* Database instance will be created if it is not set in the array.
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -95,9 +106,13 @@
}
/**
* Add a dialplan for call center
* @var string $domain_uuid the multi-tenant id
* @var string $value string to be cached
* Saves or updates the dial plan.
*
* This method first checks if a previous dial plan exists. If it does, it is deleted.
* Then, a new dial plan array is built with the necessary settings and conditions.
* The new dial plan is then saved to the database.
*
* @return void
*/
public function dialplan() {
@@ -288,7 +303,13 @@
}
/**
* delete records
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete_queues($records) {
@@ -409,6 +430,14 @@
}
}
/**
* Deletes multiple call center agents.
*
* @param array $records A list of records to delete, where each record is an associative array containing a 'uuid'
* key.
*
* @return void
*/
public function delete_agents($records) {
//assign private variables
@@ -487,9 +516,14 @@
}
}
/**
* copy records
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy_queues($records) {

View File

@@ -40,30 +40,38 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_uuid;
/**
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_name;
@@ -78,7 +86,11 @@
private $toggle_values;
/**
* called when the object is created
* Constructor for the class.
*
* This method initializes the object with setting_array and session data.
*
* @param array $setting_array An optional array of settings to override default values. Defaults to [].
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -98,7 +110,13 @@
}
/**
* delete records
* Deletes one or multiple records from the access controls table.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->permission_prefix . 'delete')) {
@@ -195,7 +213,13 @@
}
/**
* toggle records
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
if (permission_exists($this->permission_prefix . 'edit')) {
@@ -305,8 +329,7 @@
$cmd .= "Presence-Call-Direction: outbound\n";
if ($call_flow['state'] == 'true') {
$cmd .= "answer-state: confirmed\n";
}
else {
} else {
$cmd .= "answer-state: terminated\n";
}
@@ -322,7 +345,13 @@
}
/**
* copy records
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
if (permission_exists($this->permission_prefix . 'add')) {

View File

@@ -49,6 +49,15 @@
$text = $language->get();
//define the destination_select function
/**
* Displays a select input element with options for destinations.
*
* @param string $select_name The name attribute of the select input element.
* @param int $select_value The value to be selected in the select input element.
* @param int $select_default The default value if select_value is empty.
*
* @return void
*/
function destination_select($select_name, $select_value, $select_default) {
if (empty($select_value)) { $select_value = $select_default; }
echo " <select class='formfld' style='width: 55px;' name='$select_name'>\n";

View File

@@ -38,13 +38,17 @@
const app_uuid = '19806921-e8ed-dcff-b325-dd3e5da4959d';
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
public $domain_uuid;
/**
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
public $domain_name;
@@ -62,18 +66,22 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
@@ -88,7 +96,12 @@
private $toggle_values;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -105,6 +118,11 @@
$this->toggle_values = ['true', 'false'];
}
/**
* Sets the extension with the provided values.
*
* @return void
*/
public function set() {
//determine whether to update the dial string
@@ -153,8 +171,13 @@
}
/**
* Toggle an array of call_forward records
* @param array $records array of records to toggle
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle(array $records) {

View File

@@ -37,36 +37,46 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Username set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Username set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $username;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_uuid;
/**
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_name;
@@ -82,7 +92,12 @@
public $binary;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -102,7 +117,13 @@
}
/**
* delete rows from the database
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->name . '_delete')) {
@@ -178,7 +199,11 @@
}
/**
* transcribe call recordings
* Transcribes multiple call recordings.
*
* @param array $records An array of records to transcribe.
*
* @return void
*/
public function transcribe($records) {
if (permission_exists($this->name . '_view')) {
@@ -267,7 +292,11 @@
}
/**
* download the recordings
* Downloads one or multiple call recordings.
*
* @param array $records An optional array of recording UUIDs to download. If null, the method will attempt to download a single recording based on the current object's recording_uuid property.
*
* @return void
*/
public function download($records = null) {
if (permission_exists('call_recording_play') || permission_exists('call_recording_download')) {
@@ -280,8 +309,7 @@
//set the time zone
if (!empty($time_zone)) {
$time_zone = $time_zone;
}
else {
} else {
$time_zone = date_default_timezone_get();
}
@@ -372,13 +400,18 @@
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
}
else {
} else {
$file_ext = pathinfo($call_recording_name, PATHINFO_EXTENSION);
switch ($file_ext) {
case "wav" : header("Content-Type: audio/x-wav"); break;
case "mp3" : header("Content-Type: audio/mpeg"); break;
case "ogg" : header("Content-Type: audio/ogg"); break;
case "wav" :
header("Content-Type: audio/x-wav");
break;
case "mp3" :
header("Content-Type: audio/mpeg");
break;
case "ogg" :
header("Content-Type: audio/ogg");
break;
}
}
$call_recording_name_download = preg_replace('#[^a-zA-Z0-9_\-\.]#', '', $call_recording_name_download);
@@ -575,7 +608,7 @@
$c_start = $start;
$c_end = $end;
// Extract the range string
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
[, $range] = explode('=', $_SERVER['HTTP_RANGE'], 2);
// Make sure the client hasn't sent us a multibyte range
if (strpos($range, ',') !== false) {
// (?) Shoud this be issued here, or should the first
@@ -592,8 +625,7 @@
if ($range[0] == '-') {
// The n-number of the last bytes is requested
$c_start = $size - substr($range, 1);
}
else {
} else {
$range = explode('-', $range);
$c_start = $range[0];
$c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;
@@ -639,7 +671,9 @@
/**
* Called by the maintenance service to clean out old call recordings
*
* @param settings $settings
*
* @return void
*/
public static function filesystem_maintenance(settings $settings): void {
@@ -688,8 +722,7 @@
//file is not older - do nothing
}
}
}
else {
} else {
//report the retention days is not set correctly
maintenance_service::log_write(self::class, "Retention days not set or not a valid number", $domain_uuid, maintenance_service::LOG_ERROR);
}

View File

@@ -110,7 +110,14 @@
//set the default
if (empty($profile)) { $profile = "default"; }
//define fucntion get_conference_pin - used to find a unique pin number
/**
* Generates a unique pin number for a conference room.
*
* @param int $length The length of the pin number to be generated.
* @param string $conference_room_uuid The UUID of the conference room.
*
* @return string A unique pin number if available, or generates another one recursively until an available one is found.
*/
function get_conference_pin($length, $conference_room_uuid) {
//set the variable as global
global $database;

View File

@@ -35,6 +35,16 @@
public $agent_uuid;
//feature_event method
/**
* Sends a presence notification to the call center.
*
* This method creates an event socket connection and sends a PRESENCE_IN event
* if the connection is established. The event contains information about the agent's
* presence, including their name, domain, unique ID, and answer state.
*
* @return boolean True if the event was successfully sent, false otherwise.
*/
public function send_call_center_notify() {
$esl = event_socket::create();

View File

@@ -35,7 +35,9 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
const app_uuid = '8d083f5a-f726-42a8-9ffa-8d28f848f10e';
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
public $domain_uuid;
@@ -55,30 +57,38 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Username set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Username set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $username;
/**
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_name;
@@ -94,7 +104,12 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
private $fields;
/**
* Called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -108,7 +123,9 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
}
/**
* count the conference rooms
* Retrieves the count of conference rooms.
*
* @return array|false An array containing a single column named "column" with the room count.
*/
public function room_count() {
//get the room count
@@ -140,7 +157,9 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
}
/**
* get the list of conference rooms
* Retrieves a list of conference rooms based on filtering and sorting criteria.
*
* @return array|null A multidimensional array containing information about each room, or null if no rooms are found.
*/
public function rooms() {
//get variables used to control the order
@@ -201,8 +220,7 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
}
if (empty($this->order_by)) {
$sql .= "order by r.description, r.conference_room_uuid asc ";
}
else {
} else {
$sql .= "order by $order_by $order ";
}
$sql .= "limit :rows_per_page offset :offset ";
@@ -215,7 +233,9 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
$x = 0;
foreach ($conference_rooms as $row) {
//increment the array index
if (isset($previous) && $row["conference_room_uuid"] != $previous) { $x++; }
if (isset($previous) && $row["conference_room_uuid"] != $previous) {
$x++;
}
//build the array
$result[$x]["domain_uuid"] = $row["domain_uuid"];
$result[$x]["conference_room_uuid"] = $row["conference_room_uuid"];
@@ -248,7 +268,9 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
}
/**
* download the recordings
* Downloads a call recording based on the provided ID.
*
* @return void
*/
public function download() {
if (permission_exists('conference_session_play') || permission_exists('call_recording_play') || permission_exists('call_recording_download')) {
@@ -284,8 +306,7 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
//download the file
if (file_exists($record_path . '/' . $record_name . '.wav')) {
$record_name = $record_name . '.wav';
}
else {
} else {
if (file_exists($record_path . '/' . $record_name . '.mp3')) {
$record_name = $record_name . '.mp3';
}
@@ -304,8 +325,7 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
}
else {
} else {
$file_ext = substr($record_name, -3);
if ($file_ext == "wav") {
header("Content-Type: audio/x-wav");
@@ -330,7 +350,12 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
} //end download method
/**
* delete records
* Deletes multiple conference center records.
*
* @param array $records An array of records to delete, where each record is an associative array containing the UUID of
* the conference center and a 'checked' key indicating whether the record should be deleted.
*
* @return void
*/
public function delete_conference_centers($records) {
@@ -416,6 +441,13 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
}
}
/**
* Deletes multiple conference rooms.
*
* @param array $records An array containing the IDs of the records to be deleted. The ID is represented as 'uuid'.
*
* @return void
*/
public function delete_conference_rooms($records) {
//assign private variables
@@ -477,6 +509,14 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
}
}
/**
* Deletes multiple conference sessions.
*
* @param array $records An array of records to delete, where each record is an associative array with a 'uuid' key and a 'checked' key.
* The 'uuid' value must be a valid UUID, and the 'checked' value should be set to 'true' for the session to be deleted.
*
* @return void
*/
public function delete_conference_sessions($records) {
//assign private variables
@@ -539,7 +579,12 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
}
/**
* toggle records
* Toggles the state of multiple conference centers.
*
* @param array $records An array of records to toggle, where each record is an associative array with a 'uuid' key and a 'checked' key.
* The 'uuid' value must be a valid UUID, and the 'checked' value should be set to 'true' for the center to be toggled.
*
* @return void
*/
public function toggle_conference_centers($records) {
@@ -636,6 +681,14 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
}
}
/**
* Toggles the state of multiple conference rooms.
*
* @param array $records An array of records to toggle, where each record is an associative array with a 'uuid' key and a 'checked' key.
* The 'uuid' value must be a valid UUID, and the 'checked' value should be set to 'true' for the room to be toggled.
*
* @return void
*/
public function toggle_conference_rooms($records) {
//assign private variables
@@ -815,10 +868,8 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
}
*/
} //class
//example conference center
/*
$conference_center = new conference_centers;

View File

@@ -53,7 +53,12 @@
public $conference_control_uuid;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set objects
@@ -61,7 +66,13 @@
}
/**
* delete rows from the database
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
@@ -121,6 +132,13 @@
}
}
/**
* Deletes conference control details.
*
* @param array $records An array of records to delete, where each record contains a 'checked' key with value 'true'.
*
* @return void
*/
public function delete_details($records) {
//assign the variables
@@ -174,7 +192,13 @@
}
/**
* toggle a field between two values
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
@@ -245,6 +269,15 @@
}
}
/**
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle_details($records) {
//assign the variables
@@ -317,7 +350,13 @@
}
/**
* copy rows from the database
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
@@ -405,7 +444,8 @@
}
}
unset($sql_2, $parameters_2, $rows_2, $row_2); }
unset($sql_2, $parameters_2, $rows_2, $row_2);
}
}
unset($sql, $parameters, $rows, $row);
}

View File

@@ -53,7 +53,12 @@
public $conference_profile_uuid;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set objects
@@ -61,7 +66,13 @@
}
/**
* delete rows from the database
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
@@ -121,6 +132,13 @@
}
}
/**
* Deletes multiple parameters from the conference profile.
*
* @param array $records An array of records to delete, where each record contains a 'checked' key with value 'true' and an 'uuid' key containing the UUID of the parameter to be deleted.
*
* @return void
*/
public function delete_params($records) {
//assign the variables
@@ -171,7 +189,13 @@
}
/**
* toggle a field between two values
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
@@ -241,6 +265,13 @@
}
}
/**
* Toggles the enabled state of multiple parameters in a conference profile.
*
* @param array $records An array of records to toggle, where each record contains a 'checked' key with value 'true' and an 'uuid' key containing the UUID of the parameter to be toggled.
*
* @return void
*/
public function toggle_params($records) {
//assign the variables
@@ -312,7 +343,13 @@
}
/**
* copy rows from the database
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {

View File

@@ -35,24 +35,31 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_uuid;
/**
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_name;
@@ -68,7 +75,12 @@
private $toggle_values;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -89,7 +101,13 @@
}
/**
* delete records
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->permission_prefix . 'delete')) {
@@ -175,7 +193,13 @@
}
/**
* toggle records
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
if (permission_exists($this->permission_prefix . 'edit')) {
@@ -263,7 +287,13 @@
}
/**
* copy records
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
if (permission_exists($this->permission_prefix . 'add')) {

View File

@@ -143,6 +143,13 @@
}
//define an alternative kick all
/**
* Ends a conference by killing all its members and destroying the session.
*
* @param string $name The name of the conference to end.
*
* @return void
*/
function conference_end($name) {
$switch_cmd = "conference '".$name."' xml_list";
$xml_str = trim(event_socket::api($switch_cmd));

View File

@@ -236,6 +236,20 @@
//define the array _difference function
//this adds old and new values to the array
/**
* Calculates the difference between two arrays.
*
* This function recursively iterates through both input arrays, comparing each key-value pair. If a value in $array2 is not present in $array1,
* it is marked as 'new' in the returned array. If a value in $array1 is not present in $array2, it is also included in the returned array with a marker
* indicating its origin.
*
* The function handles nested arrays by recursively calling itself for matching keys.
*
* @param mixed[] $array1 The first input array to compare.
* @param mixed[] $array2 The second input array to compare.
*
* @return mixed[] An array containing the differences between the two input arrays, with added markers indicating origin.
*/
function array_difference($array1, $array2) {
$array = array();
if (is_array($array1)) {

View File

@@ -36,7 +36,9 @@ class database_transactions {
/**
* Removes old entries for in the database database_transactions table
* see {@link https://github.com/fusionpbx/fusionpbx-app-maintenance/} FusionPBX Maintenance App
*
* @param settings $settings Settings object
*
* @return void
*/
public static function database_maintenance(settings $settings): void {

View File

@@ -73,6 +73,17 @@
$available_columns[] = 'destination_order';
//define the functions
/**
* Converts an associative or numerical array into a CSV string.
*
* This function takes an array and returns its contents as a properly formatted
* CSV string. If the input array is empty, it will return null.
*
* @param array $array The array to be converted into a CSV string.
* It can be either an associative or numerical array.
*
* @return string A CSV string representation of the input array, or null if the array is empty.
*/
function array2csv(array &$array) {
if (count($array) == 0) {
return null;
@@ -87,6 +98,17 @@
return ob_get_clean();
}
/**
* Sends HTTP headers for a file download.
*
* This function sends the necessary HTTP headers to force the browser to download
* a file instead of displaying it in the browser. The filename specified should be
* a path to the file on the server, not a URL.
*
* @param string $filename The name and path to the file that will be downloaded by the client.
*
* @return void This function does not return anything.
*/
function download_send_headers($filename) {
// disable caching
$now = gmdate("D, d M Y H:i:s");

View File

@@ -38,18 +38,6 @@
$language = new text;
$text = $language->get();
//built in str_getcsv requires PHP 5.3 or higher, this function can be used to reproduct the functionality but requirs PHP 5.1.0 or higher
if(!function_exists('str_getcsv')) {
function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") {
$fp = fopen("php://memory", 'r+');
fputs($fp, $input);
rewind($fp);
$data = fgetcsv($fp, null, $delimiter, $enclosure); // $escape only got added in 5.3.0
fclose($fp);
return $data;
}
}
//get the http get values and set them as php variables
$action = $_POST["action"] ?? null;
$from_row = $_POST["from_row"] ?? null;
@@ -132,6 +120,14 @@
}
//get the parent table
/**
* Retrieves the parent table of a given table in a database schema.
*
* @param array $schema Database schema containing table information
* @param string $table_name Name of the table for which to retrieve the parent
*
* @return mixed Parent table name, or null if no matching table is found
*/
function get_parent($schema,$table_name) {
foreach ($schema as $row) {
if ($row['table'] == $table_name) {

View File

@@ -79,6 +79,14 @@
$destination_array = $destination->all('dialplan');
//function to return the action names in the order defined
/**
* Returns a list of actions based on the provided destination array and actions.
*
* @param array $destination_array The array containing the data to process.
* @param array $destination_actions The array of actions to apply to the destination array.
*
* @return array A list of actions resulting from the processing of the destination array and actions.
*/
function action_name($destination_array, $destination_actions) {
global $settings;
$actions = [];
@@ -175,8 +183,8 @@
$page = $_GET['page'];
}
if (!isset($page)) { $page = 0; $_GET['page'] = 0; }
list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
[$paging_controls, $rows_per_page] = paging($num_rows, $param, $rows_per_page);
[$paging_controls_mini, $rows_per_page] = paging($num_rows, $param, $rows_per_page, true);
$offset = $rows_per_page * $page;
//get the list

View File

@@ -51,6 +51,21 @@
$label_required = $text['label-required'];
//define the functions
/**
* Converts a multi-dimensional array to CSV format.
*
* This function assumes that the input array is a collection of devices,
* where each device has an array of columns. The function will take all
* column headers from all devices and use them as the header row in the
* generated CSV file.
*
* If any duplicate column headers are found, they will be removed by
* truncating at the pipe character (|).
*
* @param array &$array A multi-dimensional array of device data.
*
* @return string The CSV formatted data as a string. Returns null if the input array is empty.
*/
function array2csv(array &$array) {
if (count($array) == 0) {
return null;
@@ -86,6 +101,15 @@
return ob_get_clean();
}
/**
* Sends HTTP headers to force a file download.
*
* This function sets various HTTP headers to instruct the browser to download the file instead of displaying it in the browser window.
*
* @param string $filename The filename to use for the downloaded file.
*
* @return void No return value. This function only sends HTTP headers and does not generate any output.
*/
function download_send_headers($filename) {
// disable caching
$now = gmdate("D, d M Y H:i:s");

View File

@@ -38,18 +38,6 @@
$language = new text;
$text = $language->get();
//built in str_getcsv requires PHP 5.3 or higher, this function can be used to reproduct the functionality but requirs PHP 5.1.0 or higher
if (!function_exists('str_getcsv')) {
function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") {
$fp = fopen("php://memory", 'r+');
fputs($fp, $input);
rewind($fp);
$data = fgetcsv($fp, null, $delimiter, $enclosure, $escape);
fclose($fp);
return $data;
}
}
//set the max php execution time
ini_set('max_execution_time',7200);
@@ -225,6 +213,14 @@
}
//get the parent table
/**
* Retrieves the parent table name for a given table in the schema.
*
* @param array $schema An associative array of schema definitions
* @param string $table_name The name of the table to retrieve the parent for
*
* @return string|null The parent table name if found, otherwise null
*/
function get_parent($schema, $table_name) {
foreach ($schema as $row) {
if ($row['table'] == $table_name) {

View File

@@ -34,7 +34,9 @@
const app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e';
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
public $domain_uuid;
@@ -49,30 +51,38 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Username set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Username set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $username;
/**
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_name;
@@ -89,12 +99,12 @@
private $tables;
/**
* Create a settings object using key/value pairs in the $setting_array.
* Initializes the object with setting array.
*
* Valid values are: database.
* @param array setting_array
* @depends database::new()
* @access public
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -107,10 +117,22 @@
$this->settings = $setting_array['settings'] ?? new settings(['database' => $this->database, 'domain_uuid' => $this->domain_uuid, 'user_uuid' => $this->user_uuid]);
}
/**
* Retrieves the domain UUID.
*
* @return string The domain UUID.
*/
public function get_domain_uuid() {
return $this->domain_uuid;
}
/**
* Retrieves the device vendor from a given MAC address.
*
* @param string $mac The MAC address to retrieve the vendor for.
*
* @return string The device vendor, or an empty string if the MAC address is invalid.
*/
public static function get_vendor($mac) {
//return if the mac address is empty
if (empty($mac)) {
@@ -379,6 +401,13 @@
return $device_vendor;
}
/**
* Returns the vendor of a given user agent string.
*
* @param string $agent The user agent string to determine the vendor from.
*
* @return string The identified vendor, or an empty string if no match is found.
*/
public static function get_vendor_by_agent($agent) {
if ($agent) {
//set the user agent string to lower case
@@ -453,6 +482,14 @@
}
}
/**
* Returns the directory where FusionPBX templates are stored.
*
* This method checks various locations on different operating systems to find the default template directory.
* If a domain name subdirectory exists in the selected template directory, it will be used instead.
*
* @return string The path to the template directory.
*/
public function get_template_dir() {
//set the default template directory
if (PHP_OS == "Linux") {
@@ -460,42 +497,34 @@
if (empty($this->template_dir)) {
if (file_exists('/usr/share/fusionpbx/templates/provision')) {
$this->template_dir = '/usr/share/fusionpbx/templates/provision';
}
elseif (file_exists('/etc/fusionpbx/resources/templates/provision')) {
} elseif (file_exists('/etc/fusionpbx/resources/templates/provision')) {
$this->template_dir = '/etc/fusionpbx/resources/templates/provision';
}
else {
} else {
$this->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/resources/templates/provision';
}
}
}
elseif (PHP_OS == "FreeBSD") {
} elseif (PHP_OS == "FreeBSD") {
//if the FreeBSD port is installed use the following paths by default.
if (empty($this->template_dir)) {
if (file_exists('/usr/local/share/fusionpbx/templates/provision')) {
$this->template_dir = '/usr/local/share/fusionpbx/templates/provision';
}
elseif (file_exists('/usr/local/etc/fusionpbx/resources/templates/provision')) {
} elseif (file_exists('/usr/local/etc/fusionpbx/resources/templates/provision')) {
$this->template_dir = '/usr/local/etc/fusionpbx/resources/templates/provision';
}
else {
} else {
$this->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/resources/templates/provision';
}
}
}
elseif (PHP_OS == "NetBSD") {
} elseif (PHP_OS == "NetBSD") {
//set the default template_dir
if (empty($this->template_dir)) {
$this->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/resources/templates/provision';
}
}
elseif (PHP_OS == "OpenBSD") {
} elseif (PHP_OS == "OpenBSD") {
//set the default template_dir
if (empty($this->template_dir)) {
$this->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/resources/templates/provision';
}
}
else {
} else {
//set the default template_dir
if (empty($this->template_dir)) {
$this->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/resources/templates/provision';
@@ -512,7 +541,13 @@
}
/**
* delete records
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
@@ -588,6 +623,14 @@
}
}
/**
* Deletes one or more device lines from the database.
*
* @param array $records A list of records to be deleted, where each record is an associative array containing
* 'uuid' and optionally 'device_uuid'.
*
* @return void
*/
public function delete_lines($records) {
//assign private variables
$this->permission_prefix = 'device_line_';
@@ -632,6 +675,14 @@
}
}
/**
* Deletes multiple device key records.
*
* @param array $records An array of device key records to delete, where each record is an associative array
* containing the uuid and checked status.
*
* @return void
*/
public function delete_keys($records) {
//assign private variables
$this->permission_prefix = 'device_key_';
@@ -676,6 +727,17 @@
}
}
/**
* Deletes multiple device settings records.
*
* This method checks if the user has permission to delete device settings and validates the token.
* It then filters out unchecked device settings, builds a delete array, and executes the deletion.
*
* @param array $records An array of device setting records to be deleted, where each record contains 'uuid' and
* 'checked' keys.
*
* @return void
*/
public function delete_settings($records) {
//assign private variables
$this->permission_prefix = 'device_setting_';
@@ -720,6 +782,14 @@
}
}
/**
* Deletes the specified vendors.
*
* @param array $records The list of vendor records to delete, where each record is an associative array containing
* the vendor's UUID and a 'checked' flag indicating whether the vendor should be deleted.
*
* @return void
*/
public function delete_vendors($records) {
//assign private variables
@@ -781,6 +851,14 @@
}
}
/**
* Deletes vendor functions based on the provided records.
*
* @param array $records An array of records containing information about the rows to delete,
* where each record is an associative array with 'checked' and 'uuid' keys.
*
* @return void
*/
public function delete_vendor_functions($records) {
//assign private variables
@@ -839,6 +917,14 @@
}
}
/**
* Deletes multiple device profiles.
*
* @param array $records The list of records to delete, where each record is an associative array containing the
* UUID and a 'checked' key indicating whether the profile should be deleted.
*
* @return void
*/
public function delete_profiles($records) {
//assign private variables
@@ -900,6 +986,14 @@
}
}
/**
* Deletes multiple records from the device profile keys table.
*
* @param array $records The list of records to delete, where each record is an associative array containing 'uuid'
* and/or 'checked' key(s).
*
* @return bool True if all records were successfully deleted, false otherwise.
*/
public function delete_profile_keys($records) {
//assign private variables
@@ -943,6 +1037,11 @@
}
}
/**
* Deletes multiple profile settings.
*
* @param array $records An array of profile settings to delete, with each setting's 'uuid' key as the identifier.
*/
public function delete_profile_settings($records) {
//assign private variables
@@ -987,7 +1086,13 @@
}
/**
* toggle records
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
@@ -1068,6 +1173,14 @@
}
}
/**
* Toggles the enabled state of one or more vendors.
*
* @param array $records An array of records containing vendor information, where each record
* has a 'checked' property indicating whether to toggle the vendor's state.
*
* @return void
*/
public function toggle_vendors($records) {
//assign private variables
@@ -1138,6 +1251,13 @@
}
}
/**
* Toggles the enabled state of one or more vendor functions.
*
* @param array $records An array of records containing vendor function information, where each record has a 'checked' property indicating whether to toggle the function's state.
*
* @return void
*/
public function toggle_vendor_functions($records) {
//assign private variables
@@ -1208,6 +1328,15 @@
}
}
/**
* Toggle the state of checked device profiles.
*
* @param array $records An array containing the records to toggle, where each record is an associative array
* with a 'checked' key indicating whether the profile should be toggled, and a 'uuid'
* key containing the UUID of the profile.
*
* @return void
*/
public function toggle_profiles($records) {
//assign private variables
@@ -1281,7 +1410,13 @@
}
/**
* copy records
* Copy the specified device profiles.
*
* @param array $records An array containing the records to copy, where each record is an associative array
* with a 'checked' key indicating whether the profile should be copied, and a 'uuid'
* key containing the UUID of the profile.
*
* @return void
*/
public function copy_profiles($records) {
@@ -1444,4 +1579,3 @@
} //class
?>

View File

@@ -44,8 +44,10 @@
//declared functions
/**
* Checks if a dialplan detail record is marked for deletion
*
* @param string $uuid UUID of the dialplan detail record
* @param array $deleted_details array of dialplan detail records marked for deletion
*
* @return bool Returns true if user has permission and dialplan detail is marked for deletion
*/
function marked_for_deletion(string $uuid, array $deleted_details): bool {

View File

@@ -34,7 +34,9 @@
const app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db';
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
public $domain_uuid;
@@ -81,18 +83,22 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
@@ -106,7 +112,14 @@
private $toggle_field;
private $toggle_values;
//class constructor
/**
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
$this->domain_uuid = $setting_array['domain_uuid'] ?? $_SESSION['domain_uuid'] ?? '';
@@ -128,7 +141,11 @@
$this->toggle_values = ['true', 'false'];
}
/**
* Checks if a specific dialplan exists in the database.
*
* @return bool True if the dialplan exists, False otherwise
*/
public function dialplan_exists() {
$sql = "select count(*) from v_dialplans ";
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null)";
@@ -139,6 +156,14 @@
unset($sql, $parameters);
}
/**
* Imports dialplans from XML files for the specified domains.
*
* @param array $domains An array of domain data, where each domain is an associative array containing 'domain_uuid' and
* other relevant information.
*
* @return void
*/
public function import($domains) {
//set the row id
$x = 0;
@@ -240,8 +265,7 @@
//dialplan global
if (isset($dialplan['@attributes']['global']) && $dialplan['@attributes']['global'] == "true") {
$dialplan_global = true;
}
else {
} else {
$dialplan_global = false;
}
@@ -252,8 +276,7 @@
//set the domain_uuid
if ($dialplan_global) {
$domain_uuid = null;
}
else {
} else {
$domain_uuid = $domain['domain_uuid'];
}
@@ -275,8 +298,7 @@
$array['dialplans'][$x]['dialplan_order'] = $dialplan['@attributes']['order'];
if (!empty($dialplan['@attributes']['enabled'])) {
$array['dialplans'][$x]['dialplan_enabled'] = $dialplan['@attributes']['enabled'];
}
else {
} else {
$array['dialplans'][$x]['dialplan_enabled'] = true;
}
$array['dialplans'][$x]['dialplan_description'] = $dialplan['@attributes']['description'] ?? null;
@@ -300,8 +322,7 @@
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_group'] = $group;
if (isset($row['@attributes']['enabled'])) {
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_enabled'] = $row['@attributes']['enabled'];
}
else {
} else {
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_enabled'] = true;
}
$y++;
@@ -333,15 +354,13 @@
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_data'] = $row2['@attributes']['data'] ?? null;
if (!empty($row2['@attributes']['inline'])) {
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_inline'] = $row2['@attributes']['inline'];
}
else {
} else {
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_inline'] = null;
}
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_group'] = $group;
if (isset($row2['@attributes']['enabled'])) {
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_enabled'] = $row2['@attributes']['enabled'];
}
else {
} else {
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_enabled'] = true;
}
$y++;
@@ -360,15 +379,13 @@
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_data'] = $row2['@attributes']['data'];
if (!empty($row2['@attributes']['inline'])) {
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_inline'] = $row2['@attributes']['inline'];
}
else {
} else {
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_inline'] = null;
}
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_group'] = $group;
if (isset($row2['@attributes']['enabled'])) {
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_enabled'] = $row2['@attributes']['enabled'];
}
else {
} else {
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_enabled'] = true;
}
$y++;
@@ -377,8 +394,7 @@
$order = $order + 5;
}
}
}
else {
} else {
$condition_self_closing_tag = true;
}
@@ -431,6 +447,13 @@
}
}
/**
* Retrieves the outbound routes for a given destination number.
*
* @param string $destination_number The destination number to retrieve the outbound routes for.
*
* @return void
*/
public function outbound_routes($destination_number) {
//normalize the destination number
@@ -464,15 +487,19 @@
$parameters['domain_uuid'] = $this->domain_uuid;
$dialplans = $this->database->select($sql, $parameters ?? null, 'all');
unset($sql, $parameters);
$x = 0; $y = 0;
$x = 0;
$y = 0;
if (!empty($dialplans)) {
foreach ($dialplans as $row) {
//if the previous dialplan uuid has not been set then set it
if (!isset($previous_dialplan_uuid)) { $previous_dialplan_uuid = $row['dialplan_uuid']; }
if (!isset($previous_dialplan_uuid)) {
$previous_dialplan_uuid = $row['dialplan_uuid'];
}
//increment dialplan ordinal number
if ($previous_dialplan_uuid != $row['dialplan_uuid']) {
$x++; $y = 0;
$x++;
$y = 0;
}
//build the array
@@ -513,8 +540,7 @@
preg_match($pattern, $destination_number, $matches, PREG_OFFSET_CAPTURE);
if (count($matches) == 0) {
$regex_match = false;
}
else {
} else {
$regex_match = true;
$regex_match_1 = $matches[1][0];
$regex_match_2 = $matches[2][0];
@@ -546,6 +572,13 @@
} //function
//combines array dialplans and dialplan details arrays to match results from the database
/**
* Prepares an array of dialplan details from the provided database array.
*
* @param array $database_array An array containing database connections and dialplan data.
*
* @return void
*/
public function prepare_details($database_array) {
$array = [];
$id = 0;
@@ -585,6 +618,12 @@
}
//reads dialplan details from the database to build the xml
/**
* Generates XML representation of dialplans.
*
* @return string XML string representing the dialplans.
*/
public function xml() {
//set the xml array and then concatenate the array to a string
@@ -608,13 +647,11 @@
if (is_uuid($this->uuid)) {
$sql .= "where dialplan_uuid = :dialplan_uuid ";
$parameters['dialplan_uuid'] = $this->uuid;
}
else {
} else {
if (!empty($this->context)) {
if ($this->context == "public" || substr($this->context, 0, 7) == "public@" || substr($this->context, -7) == ".public") {
$sql .= "where dialplan_context = :dialplan_context ";
}
else {
} else {
$sql .= "where (dialplan_context = :dialplan_context or dialplan_context = '\${domain_name}' or dialplan_context = 'global') ";
}
$sql .= "and dialplan_enabled = true ";
@@ -667,8 +704,7 @@
if (isset($this->context)) {
if ($this->context == "public" || substr($this->context, 0, 7) == "public@" || substr($this->context, -7) == ".public") {
$sql .= "and p.dialplan_context = :dialplan_context \n";
}
else {
} else {
$sql .= "and (p.dialplan_context = :dialplan_context or p.dialplan_context = '\${domain_name}' or dialplan_context = 'global') \n";
}
$parameters['dialplan_context'] = $this->context;
@@ -758,18 +794,15 @@
$xml .= " <condition " . $condition_attribute . $condition_break . "/>\n";
$condition_attribute = "";
$condition_tag_status = "closed";
}
else if (!empty($condition) && substr($condition, -1) == ">") {
} elseif (!empty($condition) && substr($condition, -1) == ">") {
$xml .= " " . $condition;
$condition = "";
$condition_tag_status = "closed";
}
else if (!empty($condition)) {
} elseif (!empty($condition)) {
$xml .= " " . $condition . "/>";
$condition = "";
$condition_tag_status = "closed";
}
else if ($condition_tag_status != "closed") {
} elseif ($condition_tag_status != "closed") {
$xml .= " </condition>\n";
$condition_tag_status = "closed";
}
@@ -805,41 +838,29 @@
//determine the type of condition
if ($dialplan_detail_type == "hour") {
$condition_type = 'time';
}
else if ($dialplan_detail_type == "minute") {
} elseif ($dialplan_detail_type == "minute") {
$condition_type = 'time';
}
else if ($dialplan_detail_type == "minute-of-day") {
} elseif ($dialplan_detail_type == "minute-of-day") {
$condition_type = 'time';
}
else if ($dialplan_detail_type == "mday") {
} elseif ($dialplan_detail_type == "mday") {
$condition_type = 'time';
}
else if ($dialplan_detail_type == "mweek") {
} elseif ($dialplan_detail_type == "mweek") {
$condition_type = 'time';
}
else if ($dialplan_detail_type == "mon") {
} elseif ($dialplan_detail_type == "mon") {
$condition_type = 'time';
}
else if ($dialplan_detail_type == "time-of-day") {
} elseif ($dialplan_detail_type == "time-of-day") {
$condition_type = 'time';
}
else if ($dialplan_detail_type == "yday") {
} elseif ($dialplan_detail_type == "yday") {
$condition_type = 'time';
}
else if ($dialplan_detail_type == "year") {
} elseif ($dialplan_detail_type == "year") {
$condition_type = 'time';
}
else if ($dialplan_detail_type == "wday") {
} elseif ($dialplan_detail_type == "wday") {
$condition_type = 'time';
}
else if ($dialplan_detail_type == "week") {
} elseif ($dialplan_detail_type == "week") {
$condition_type = 'time';
}
else if ($dialplan_detail_type == "date-time") {
} elseif ($dialplan_detail_type == "date-time") {
$condition_type = 'time';
}
else {
} else {
$condition_type = 'default';
}
@@ -849,13 +870,11 @@
$xml .= $condition . "\n";
$condition = '';
$condition_tag_status = "closed";
}
else if (!empty($condition)) {
} elseif (!empty($condition)) {
$xml .= $condition . "/>\n";
$condition = '';
$condition_tag_status = "closed";
}
else if (!empty($condition_attribute) && $condition_tag_status == "open") {
} elseif (!empty($condition_attribute) && $condition_tag_status == "open") {
// previous condition(s) must have been of type time
// do not finalize if new condition is also of type time
if ($condition_type != 'time') {
@@ -883,24 +902,19 @@
if ($condition_type == "default") {
if (isset($dialplan_detail_type) && $dialplan_detail_tag == 'condition' && $dialplan_detail_type == 'regex') {
$condition = " <condition regex=\"" . $dialplan_detail_data . "\"" . $condition_break . ">";
}
elseif (isset($dialplan_detail_type) && $dialplan_detail_tag == 'regex') {
} elseif (isset($dialplan_detail_type) && $dialplan_detail_tag == 'regex') {
$condition = " <regex field=\"" . $dialplan_detail_type . "\" expression=\"" . $dialplan_detail_data . "\"" . $condition_break . "/>";
}
else {
} else {
$condition = " <condition field=\"" . $dialplan_detail_type . "\" expression=\"" . $dialplan_detail_data . "\"" . $condition_break;
}
}
else if ($condition_type == "time") {
} elseif ($condition_type == "time") {
if ($condition_attribute) {
$condition_attribute = $condition_attribute . $dialplan_detail_type . "=\"" . $dialplan_detail_data . "\" ";
}
else {
} else {
$condition_attribute = $dialplan_detail_type . "=\"" . $dialplan_detail_data . "\" ";
}
$condition = ""; //prevents a duplicate time condition
}
else {
} else {
$condition = " <condition field=\"" . $dialplan_detail_type . "\" expression=\"" . $dialplan_detail_data . "\"" . $condition_break;
}
$condition_tag_status = "open";
@@ -911,12 +925,10 @@
if ($condition_attribute && (!empty($condition_attribute))) {
$xml .= " <condition " . $condition_attribute . $condition_break . ">\n";
$condition_attribute = "";
}
else if (!empty($condition) && !empty($condition_tag_status) && substr($condition, -1) == ">") {
} elseif (!empty($condition) && !empty($condition_tag_status) && substr($condition, -1) == ">") {
$xml .= $condition . "\n";
$condition = "";
}
else if (!empty($condition) && !empty($condition_tag_status)) {
} elseif (!empty($condition) && !empty($condition_tag_status)) {
$xml .= $condition . ">\n";
$condition = "";
}
@@ -976,14 +988,11 @@
if ($condition_tag_status == "open") {
if ($condition_attribute && (!empty($condition_attribute))) {
$xml .= " <condition " . $condition_attribute . $condition_break . "/>\n";
}
else if (!empty($condition) && substr($condition, -1) == ">") {
} elseif (!empty($condition) && substr($condition, -1) == ">") {
$xml .= $condition . "\n";
}
else if (!empty($condition)) {
} elseif (!empty($condition)) {
$xml .= $condition . "/>\n";
}
else {
} else {
$xml .= " </condition>\n";
}
}
@@ -1032,6 +1041,14 @@
}
/**
* Initializes the object with default settings and updates the database.
*
* This method processes XML files, imports domains, and updates dialplan orders in the database.
* It also adds XML for each dialplan where the dialplan XML is empty.
*
* @return void
*/
public function defaults() {
//get the array of xml files and then process thm
@@ -1044,8 +1061,7 @@
$name_array = explode('_', basename($xml_file));
if (is_numeric($name_array[0])) {
$dialplan_order = $name_array[0];
}
else {
} else {
$dialplan_order = 0;
}
@@ -1079,7 +1095,13 @@
}
/**
* delete records
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
@@ -1157,6 +1179,13 @@
}
}
/**
* Deletes multiple records from the dialplan details table.
*
* @param array $records An array of record IDs to delete, each containing a 'checked' and 'uuid' key
*
* @return void
*/
public function delete_details($records) {
//set private variables
$this->table = 'dialplan_details';
@@ -1228,7 +1257,13 @@
}
/**
* toggle records
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
@@ -1318,7 +1353,13 @@
}
/**
* copy records
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
@@ -1375,11 +1416,16 @@
//except for inbound and outbound routes, fifo, time conditions
$app_uuid = $row['app_uuid'];
switch ($app_uuid) {
case "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4": break;
case "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3": break;
case "16589224-c876-aeb3-f59f-523a1c0801f7": break;
case "4b821450-926b-175a-af93-a03c441818b1": break;
default: $app_uuid = uuid();
case "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4":
break;
case "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3":
break;
case "16589224-c876-aeb3-f59f-523a1c0801f7":
break;
case "4b821450-926b-175a-af93-a03c441818b1":
break;
default:
$app_uuid = uuid();
}
//dialplan copy should have a unique app_uuid
@@ -1458,5 +1504,4 @@
}
} //method
} //class

View File

@@ -13,24 +13,30 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_uuid;
@@ -45,7 +51,12 @@
private $location;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -65,7 +76,13 @@
}
/**
* delete rows from the database
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->name . '_delete')) {
@@ -113,7 +130,16 @@
}
/**
* resend emails in the queue
* Resend multiple records.
*
* This method will resend the specified records if the permission to edit exists.
* It first checks if the token is valid, then it iterates over the records and
* updates their status to 'waiting' and resets the retry count. Finally, it saves
* the changes to the database.
*
* @param array $records The records to resend.
*
* @return void
*/
public function resend($records) {
if (permission_exists($this->name . '_edit')) {
@@ -162,7 +188,13 @@
}
/**
* toggle a field between two values
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
if (permission_exists($this->name . '_edit')) {
@@ -228,7 +260,13 @@
}
/**
* copy rows from the database
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
if (permission_exists($this->name . '_add')) {

View File

@@ -37,24 +37,30 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_uuid;
@@ -69,7 +75,12 @@
private $location;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -88,7 +99,13 @@
}
/**
* delete rows from the database
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->name . '_delete')) {
@@ -134,7 +151,11 @@
}
/**
* update rows from the database change status to pending
* Unblocks multiple records.
*
* @param array $records An array of records to unblock, each containing 'event_guard_log_uuid' and 'checked' keys.
*
* @return void
*/
public function unblock($records) {
if (permission_exists($this->name . '_unblock')) {
@@ -191,7 +212,13 @@
}
/**
* toggle a field between two values
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
if (permission_exists($this->name . '_edit')) {
@@ -255,7 +282,13 @@
}
/**
* copy rows from the database
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
if (permission_exists($this->name . '_add')) {

View File

@@ -115,6 +115,13 @@
echo "pid_file: ".$pid_file."\n";
//function to check if the process exists
/**
* Checks if a process exists.
*
* @param string $file Path to the file containing the process ID (PID)
*
* @return bool True if the process exists, false otherwise
*/
function process_exists($file) {
//set the default exists to false
@@ -373,6 +380,13 @@
}
//run command and capture standard output
/**
* Execute a shell command and capture its output.
*
* @param string $command The shell command to execute
*
* @return string The output of the executed command
*/
function shell($command) {
ob_start();
$result = system($command);
@@ -381,6 +395,15 @@
}
//block an ip address
/**
* Execute a block command for iptables or pf based on the firewall type.
*
* @param string $ip_address The IP address to block
* @param string $filter The filter name for iptables or pf
* @param array $event The event data containing 'to-user' and 'to-host'
*
* @return boolean True if the block command was executed successfully, false otherwise
*/
function block($ip_address, $filter, $event) {
//define the global variables
global $database, $debug, $firewall_path, $firewall_name;
@@ -434,6 +457,14 @@
}
//unblock the ip address
/**
* Unblock a specified IP address from a firewall.
*
* @param string $ip_address The IP address to unblock.
* @param string $filter The filter name used in the firewall configuration.
*
* @return bool True if the IP address was successfully unblocked, false otherwise.
*/
function unblock($ip_address, $filter) {
//define the global variables
global $debug, $firewall_path, $firewall_name;
@@ -470,6 +501,13 @@
}
//is the ip address blocked
/**
* Check if an IP address is blocked in the configured firewall.
*
* @param string $ip_address The IP address to check
*
* @return bool True if the address is blocked, False otherwise
*/
function is_blocked($ip_address) {
//define the global variables
global $firewall_path, $firewall_name;
@@ -502,6 +540,17 @@
}
//determine if the IP address has been allowed by the access control list node cidr
/**
* Determine if access is allowed for a given IP address.
*
* This method checks the cache, user logs, event guard logs, access controls,
* and registration to determine if access should be granted. If no valid reason
* is found to deny access, it will be automatically allowed.
*
* @param string $ip_address The IP address to check for access.
*
* @return boolean True if access is allowed, false otherwise.
*/
function access_allowed($ip_address) {
//define global variables
global $debug;
@@ -586,6 +635,13 @@
}
//is the ip address registered
/**
* Checks if the given IP address is registered on the network.
*
* @param string $ip_address The IP address to check for registration.
*
* @return bool True if the IP address is registered, false otherwise.
*/
function is_registered($ip_address) {
//invalid ip address
if (!filter_var($ip_address, FILTER_VALIDATE_IP)) {
@@ -609,6 +665,13 @@
}
//determine if the IP address has been allowed by the access control list node cidr
/**
* Checks if the given IP address is authorized by any access control node.
*
* @param string $ip_address The IP address to check for authorization.
*
* @return bool True if the IP address is authorized, false otherwise.
*/
function access_control_allowed($ip_address) {
global $database;
@@ -653,6 +716,13 @@
}
//determine if the IP address has been allowed by a successful authentication
/**
* Determines if a user's IP address is allowed based on their login history.
*
* @param string $ip_address The IP address to check for access.
*
* @return bool True if the IP address is allowed, false otherwise.
*/
function user_log_allowed($ip_address) {
global $database, $debug;
@@ -689,6 +759,13 @@
}
//determine if the IP address has been unblocked in the event guard log
/**
* Determines if an IP address is allowed based on event guard logs.
*
* @param string $ip_address The IP address to check for access.
*
* @return bool True if the IP address is allowed, false otherwise.
*/
function event_guard_log_allowed($ip_address) {
global $database, $debug;
@@ -724,6 +801,13 @@
}
//check if the iptables chain exists
/**
* Determines if a pf table exists in the firewall configuration.
*
* @param string $table The name of the pf table to check for existence.
*
* @return bool True if the pf table exists, false otherwise.
*/
function pf_table_exists($table) {
//define the global variables
global $firewall_path, $firewall_name;
@@ -741,6 +825,13 @@
}
//add IP table chains
/**
* Adds a new IPtables chain and inserts it into the INPUT table.
*
* @param string $chain The name of the IPtables chain to add.
*
* @return bool True if the chain was successfully added, false otherwise.
*/
function iptables_chain_add($chain) {
//define the global variables
global $firewall_path;
@@ -769,6 +860,13 @@
}
//check if the iptables chain exists
/**
* Determines if a specified iptables chain exists.
*
* @param string $chain The name of the iptables chain to check for existence.
*
* @return bool True if the iptables chain exists, false otherwise.
*/
function iptables_chain_exists($chain) {
//define the global variables
global $firewall_path;
@@ -784,5 +882,3 @@
return false;
}
}
?>

View File

@@ -42,24 +42,30 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_uuid;
@@ -75,7 +81,12 @@
private $location;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -96,7 +107,13 @@
}
/**
* delete rows from the database
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->name . '_delete')) {
@@ -168,7 +185,13 @@
}
/**
* toggle a field between two values
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
if (permission_exists($this->name . '_edit')) {
@@ -244,7 +267,13 @@
}
/**
* copy rows from the database
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
if (permission_exists($this->name . '_add')) {

View File

@@ -93,6 +93,13 @@
$available_columns[] = 'forward_user_not_registered_enabled';
//define the functions
/**
* Converts a multi-dimensional array into a CSV string.
*
* @param array &$array The input array to be converted. It is expected that all rows of the array have the same number of columns.
*
* @return string|null The CSV string representation of the input array, or null if the input array is empty.
*/
function array2csv(array &$array) {
if (count($array) == 0) {
return null;
@@ -107,6 +114,11 @@
return ob_get_clean();
}
/**
* Sets the headers for a file download.
*
* @param string $filename The name of the file to be downloaded.
*/
function download_send_headers($filename) {
// disable caching
$now = gmdate("D, d M Y H:i:s");

View File

@@ -50,6 +50,16 @@
$page = isset($_REQUEST['page']) && is_numeric($_REQUEST['page']) ? $_REQUEST['page'] : 0;
//return the first item if data type = array, returns value if data type = text
/**
* Returns the first item of a given value.
*
* If the value is an array, returns the first element of the array.
* Otherwise, returns the value as is.
*
* @param mixed $value The value to retrieve the first item from.
*
* @return mixed The first item of the value.
*/
function get_first_item($value) {
return is_array($value) ? $value[0] : $value;
}

View File

@@ -38,18 +38,6 @@
$language = new text;
$text = $language->get();
//built in str_getcsv requires PHP 5.3 or higher, this function can be used to reproduct the functionality but requirs PHP 5.1.0 or higher
if (!function_exists('str_getcsv')) {
function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") {
$fp = fopen("php://memory", 'r+');
fputs($fp, $input);
rewind($fp);
$data = fgetcsv($fp, null, $delimiter, $enclosure, $escape);
fclose($fp);
return $data;
}
}
//get the http get values and set them as php variables
$action = $_POST["action"] ?? null;
$from_row = $_POST["from_row"] ?? null;
@@ -224,6 +212,14 @@
}
//get the parent table
/**
* Retrieves the parent table name for a given table in the database schema.
*
* @param array $schema The database schema, where each element is an associative array containing 'table' and 'parent' keys.
* @param string $table_name The name of the table for which to retrieve the parent table name.
*
* @return mixed|null The parent table name if found, otherwise null.
*/
function get_parent($schema,$table_name) {
foreach ($schema as $row) {
if ($row['table'] == $table_name) {

View File

@@ -34,13 +34,17 @@
const app_uuid = 'e68d9689-2769-e013-28fa-6214bf47fca3';
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
public $domain_uuid;
/**
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
public $domain_name;
@@ -91,18 +95,22 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
@@ -118,7 +126,12 @@
private $toggle_values;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -139,6 +152,14 @@
$this->toggle_values = ['true', 'false'];
}
/**
* Checks if an extension exists for a given domain UUID.
*
* @param string $domain_uuid The unique identifier of the domain.
* @param string $extension The name or alias of the extension to check.
*
* @return bool True if the extension exists, false otherwise.
*/
public function exists($domain_uuid, $extension) {
$sql = "select count(*) from v_extensions ";
$sql .= "where domain_uuid = :domain_uuid ";
@@ -150,23 +171,38 @@
$parameters['domain_uuid'] = $domain_uuid;
$parameters['extension'] = $extension;
return $this->database->select($sql, $parameters, 'column') != 0 ? true : false;
unset($sql, $parameters);
}
/**
* Retrieves the domain UUID associated with this object.
*
* @return string The domain UUID as a string.
*/
public function get_domain_uuid() {
return $this->domain_uuid;
}
/**
* Sets the domain UUID for the current session.
*
* @param string $domain_uuid The UUID of the domain to be set.
*
* @return void
*/
public function set_domain_uuid($domain_uuid) {
$this->domain_uuid = $domain_uuid;
}
/**
* Updates or inserts the voicemail settings in the database.
*
* @return void
*/
public function voicemail() {
//determine the voicemail_id
if (is_numeric($this->number_alias)) {
$this->voicemail_id = $this->number_alias;
}
else {
} else {
$this->voicemail_id = $this->extension;
}
@@ -185,8 +221,7 @@
//grant temporary permissions
$p = permissions::new();
$p->add('voicemail_edit', 'temp');
}
else {
} else {
//build insert array
$array['voicemails'][0]['voicemail_uuid'] = uuid();
$array['voicemails'][0]['domain_uuid'] = $this->domain_uuid;
@@ -216,6 +251,11 @@
unset($voicemail_uuid);
}
/**
* Generates XML files for extensions.
*
* @return void
*/
public function xml() {
if (!empty($this->settings->get('switch', 'extensions'))) {
//declare global variables
@@ -252,8 +292,7 @@
if (!empty($tmp_call_group)) {
if (empty($call_group_array[$tmp_call_group])) {
$call_group_array[$tmp_call_group] = $row['extension'];
}
else {
} else {
$call_group_array[$tmp_call_group] = $call_group_array[$tmp_call_group] . ',' . $row['extension'];
}
}
@@ -275,8 +314,7 @@
if (empty($dial_string)) {
if (!empty($this->settings->get('domain', 'dial_string'))) {
$dial_string = $this->settings->get('domain', 'dial_string');
}
else {
} else {
$dial_string = "{sip_invite_domain=\${domain_name},leg_timeout=" . $call_timeout . ",presence_id=\${dialed_user}@\${dialed_domain}}\${sofia_contact(\${dialed_user}@\${dialed_domain})}";
}
}
@@ -366,8 +404,7 @@
}
if (!empty($switch_account_code)) {
$xml .= " <variable name=\"accountcode\" value=\"" . $switch_account_code . "\"/>\n";
}
else {
} else {
$xml .= " <variable name=\"accountcode\" value=\"" . $row['accountcode'] . "\"/>\n";
}
$xml .= " <variable name=\"user_context\" value=\"" . $row['user_context'] . "\"/>\n";
@@ -397,8 +434,7 @@
}
if (!empty($row['limit_max'])) {
$xml .= " <variable name=\"limit_max\" value=\"" . $row['limit_max'] . "\"/>\n";
}
else {
} else {
$xml .= " <variable name=\"limit_max\" value=\"5\"/>\n";
}
if (!empty($row['limit_destination'])) {
@@ -502,8 +538,7 @@
$xml .= " <!--the domain or ip (the right hand side of the @ in the addr-->\n";
if ($user_context == "default") {
$xml .= " <domain name=\"\$\${domain}\">\n";
}
else {
} else {
$xml .= " <domain name=\"" . $user_context . "\">\n";
}
$xml .= " <params>\n";
@@ -569,7 +604,13 @@
}
/**
* delete records
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->permission_prefix . 'delete')) {
@@ -635,8 +676,12 @@
//create array of voicemail ids
if ($this->delete_voicemail && permission_exists('voicemail_delete')) {
if (is_numeric($extensions[$x]['extension'])) { $voicemail_ids[] = $extensions[$x]['extension']; }
if (is_numeric($extensions[$x]['number_alias'])) { $voicemail_ids[] = $extensions[$x]['number_alias']; }
if (is_numeric($extensions[$x]['extension'])) {
$voicemail_ids[] = $extensions[$x]['extension'];
}
if (is_numeric($extensions[$x]['number_alias'])) {
$voicemail_ids[] = $extensions[$x]['number_alias'];
}
}
}
@@ -724,7 +769,13 @@
}
/**
* toggle records
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
if (permission_exists($this->permission_prefix . 'enabled')) {

View File

@@ -40,6 +40,13 @@ $sql .= "and fax_email_outbound_subject_tag is not null ";
$result = $database->select($sql, null, 'all');
unset($sql);
/**
* Converts an array to a map where each unique value in the array is mapped to true.
*
* @param array &$arr The input array
*
* @return array|false A map where each unique value in the array is mapped to true, or false if the input array is empty.
*/
function arr_to_map(&$arr){
if (!empty($arr)){
$map = Array();

View File

@@ -127,6 +127,13 @@
//define function correct_path
if (!function_exists('correct_path')) {
/**
* Corrects a file path to match the current operating system's conventions.
*
* @param string $p The file path to correct
*
* @return string The corrected file path
*/
function correct_path($p) {
global $IS_WINDOWS;
if ($IS_WINDOWS) {
@@ -138,6 +145,17 @@ if (!function_exists('correct_path')) {
//define function gs_cmd
if (!function_exists('gs_cmd')) {
/**
* Generates a command to execute Ghostscript.
*
* The command is constructed based on the value of $IS_WINDOWS, which indicates
* whether the script is running under Windows. If it is, the command includes
* the 'gswin32c' executable, otherwise it uses 'gs'.
*
* @param string $args Command line arguments to be passed to Ghostscript.
*
* @return string The constructed command as a string.
*/
function gs_cmd($args) {
global $IS_WINDOWS;
if ($IS_WINDOWS) {
@@ -149,6 +167,16 @@ if (!function_exists('gs_cmd')) {
//define function fax_split dtmf
if (!function_exists('fax_split_dtmf')) {
/**
* Splits a fax number string into its numeric and DTMF (Dual-Tone Multi-Frequency) parts.
*
* If the input fax number is in the format '12345678 (DTMF_digits)', this function
* extracts the numeric part and stores it in $fax_number, while storing the DTMF digits
* in $fax_dtmf.
*
* @param string &$fax_number The fax number to be split. Modified to contain only the numeric part.
* @param string &$fax_dtmf The extracted DTMF digits from the input fax number.
*/
function fax_split_dtmf(&$fax_number, &$fax_dtmf) {
$tmp = array();
$fax_dtmf = '';

View File

@@ -34,7 +34,9 @@
const app_uuid = '24108154-4ac3-1db6-1551-4731703a4440';
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
public $domain_uuid;
@@ -56,24 +58,30 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_name;
@@ -90,7 +98,12 @@
private $forward_prefix;
/**
* Called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -104,9 +117,13 @@
}
/**
* Add a dialplan for call center
* @var string $domain_uuid the multi-tenant id
* @var string $value string to be cached
* Processes and saves a dial plan for faxing.
*
* This method normalizes fax forward numbers, sets the forward prefix,
* builds an XML dial plan, and saves it to the database. It also clears
* any existing cache and removes temporary permissions after saving.
*
* @return mixed|null The UUID of the saved dialplan or null if not saved.
*/
public function dialplan() {
@@ -137,8 +154,7 @@
//set the dialplan_uuid
if (empty($this->dialplan_uuid)) {
$this->dialplan_uuid = uuid();
}
else {
} else {
//build previous details delete array
$array['dialplan_details'][0]['dialplan_uuid'] = $this->dialplan_uuid;
$array['dialplan_details'][0]['domain_uuid'] = $this->domain_uuid;
@@ -163,8 +179,7 @@
//set the last fax
if (!empty($this->settings->get('fax', 'last_fax'))) {
$last_fax = "last_fax=" . xml::sanitize($this->settings->get('fax', 'last_fax'));
}
else {
} else {
$last_fax = "last_fax=\${caller_id_number}-\${strftime(%Y-%m-%d-%H-%M-%S)}";
}
@@ -180,9 +195,8 @@
foreach ($_SESSION['fax']['variable'] as $data) {
if (substr($data, 0, 8) == "inbound:") {
$dialplan_xml .= " <action application=\"set\" data=\"" . xml::sanitize(substr($data, 8, strlen($data))) . "\"/>\n";
}
elseif (substr($data,0,9) == "outbound:") {}
else {
} elseif (substr($data, 0, 9) == "outbound:") {
} else {
$dialplan_xml .= " <action application=\"set\" data=\"" . xml::sanitize($data) . "\"/>\n";
}
}
@@ -238,7 +252,13 @@
}
/**
* delete records
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
@@ -296,8 +316,12 @@
$rows = $this->database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) {
if ($row['fax_mode'] == 'rx') { $fax_files[$row['uuid']]['folder'] = 'inbox'; }
if ($row['fax_mode'] == 'tx') { $fax_files[$row['uuid']]['folder'] = 'sent'; }
if ($row['fax_mode'] == 'rx') {
$fax_files[$row['uuid']]['folder'] = 'inbox';
}
if ($row['fax_mode'] == 'tx') {
$fax_files[$row['uuid']]['folder'] = 'sent';
}
$fax_files[$row['uuid']]['path'] = $row['fax_file_path'];
$fax_files[$row['uuid']]['type'] = $row['fax_file_type'];
}
@@ -319,8 +343,7 @@
if (file_exists($fax_file['path'])) {
@unlink($fax_file['path']);
}
}
else if ($fax_file['type'] == 'pdf') {
} elseif ($fax_file['type'] == 'pdf') {
$fax_file['path'] = str_replace('.pdf', '.tif', $fax_file['path']);
if (file_exists($fax_file['path'])) {
@unlink($fax_file['path']);
@@ -393,6 +416,13 @@
}
}
/**
* Deletes multiple fax files.
*
* @param array $records An array of records to delete, where each record is an associative array containing the 'checked' and 'uuid' keys.
*
* @return void
*/
public function delete_files($records) {
//set private variables
@@ -434,8 +464,12 @@
$rows = $this->database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) {
if ($row['fax_mode'] == 'rx') { $fax_files[$row['uuid']]['folder'] = 'inbox'; }
if ($row['fax_mode'] == 'tx') { $fax_files[$row['uuid']]['folder'] = 'sent'; }
if ($row['fax_mode'] == 'rx') {
$fax_files[$row['uuid']]['folder'] = 'inbox';
}
if ($row['fax_mode'] == 'tx') {
$fax_files[$row['uuid']]['folder'] = 'sent';
}
$fax_files[$row['uuid']]['path'] = $row['fax_file_path'];
$fax_files[$row['uuid']]['type'] = $row['fax_file_type'];
}
@@ -457,8 +491,7 @@
if (file_exists($fax_file['path'])) {
@unlink($fax_file['path']);
}
}
else if ($fax_file['type'] == 'pdf') {
} elseif ($fax_file['type'] == 'pdf') {
$fax_file['path'] = str_replace('.pdf', '.tif', $fax_file['path']);
if (file_exists($fax_file['path'])) {
@unlink($fax_file['path']);
@@ -490,6 +523,16 @@
}
}
/**
* Deletes multiple fax log records based on user input.
*
* @param array $records An array of record data, where each record is an associative array containing
* information about the log entry to delete. Each array should have a 'checked'
* key with a value of either true or false indicating whether the log entry
* should be deleted, and a 'uuid' key containing the UUID of the log entry.
*
* @return void No return value; method only deletes records if permission is granted.
*/
public function delete_logs($records) {
//set private variables
@@ -539,7 +582,13 @@
}
/**
* copy records
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
@@ -708,7 +757,13 @@
} //method
/**
* toggle read/unread
* Toggles the read state of multiple fax file records based on user input.
*
* @param array $records An array of record data, where each record is an associative array containing information about the log entry to toggle.
* Each array should have a 'checked' key with a value of either true or false indicating whether the log entry
* should be toggled, and a 'uuid' key containing the UUID of the log entry.
*
* @return int The number of fax files toggled (0 if none were toggled).
*/
public function fax_file_toggle($records) {

View File

@@ -1,5 +1,12 @@
<?php
/**
* Recursively converts an object or array to a multi-dimensional array.
*
* @param mixed $obj The object or array to be converted. If the value is neither an object nor an array, it will be returned as is.
*
* @return array A multi-dimensional array representation of the input object or array.
*/
function object_to_array($obj) {
if (!is_object($obj) && !is_array($obj)) { return $obj; }
if (is_object($obj)) { $obj = get_object_vars($obj); }

View File

@@ -1,5 +1,16 @@
<?php
/**
* Parse attachments from a given email message.
*
* @param imap connection object $connection The IMAP connection to use for fetching the email message.
* @param int $message_number The number of the email message to parse attachments from.
* @param string $option Optional flag to pass to the imap_fetchstructure function.
*
* @return array An array of attachment details, where each element is an associative array containing
* 'filename', 'name', and 'attachment' keys. The return value will be a reindexed array,
* with keys starting from 0.
*/
function parse_attachments($connection, $message_number, $option = '') {
$attachments = array();
$structure = imap_fetchstructure($connection, $message_number, $option);

View File

@@ -1,5 +1,15 @@
<?php
/**
* Parse a message from the email connection.
*
* @param resource $connection IMAP connection to the mailbox
* @param int $message_number The message number of the message to parse
* @param string|null $option Optional argument for imap_fetchstructure()
* @param string $to_charset Charset to decode messages into, default is 'UTF-8'
*
* @return array An array containing two keys: 'messages' and 'attachments'. Each key contains an array of parsed messages or attachments.
*/
function parse_message($connection, $message_number, $option = null, $to_charset = 'UTF-8') {
$result = Array('messages'=>Array(),'attachments'=>Array());
$structure = imap_fetchstructure($connection, $message_number, $option);
@@ -33,6 +43,18 @@ function parse_message($connection, $message_number, $option = null, $to_charset
return $result;
}
/**
* Decode the text part of a message from the email connection.
*
* @param resource $connection IMAP connection to the mailbox
* @param array &$part The text part of the message, retrieved using imap_fetchstructure()
* @param int $message_number The message number of the message to parse
* @param int $id Unique identifier for this part of the message
* @param string|null $option Optional argument for imap_fetchbody()
* @param string $to_charset Charset to decode messages into, default is 'UTF-8'
*
* @return array An array containing three keys: 'data', 'type', and 'size'. The 'data' key contains the decoded message text.
*/
function parse_message_decode_text($connection, &$part, $message_number, $id, $option, $to_charset){
$msg = parse_message_fetch_body($connection, $part, $message_number, $id, $option);
@@ -63,6 +85,17 @@ function parse_message_decode_text($connection, &$part, $message_number, $id, $o
);
}
/**
* Parse an attachment from the email connection.
*
* @param resource $connection IMAP connection to the mailbox
* @param object &$part The email part to parse
* @param int $message_number The message number of the message containing the attachment
* @param string $id The internal ID of the attachment in the message
* @param string|null $option Optional argument for imap_fetchbody()
*
* @return array|false An array containing information about the parsed attachment, or false if no valid filename is found.
*/
function parse_message_decode_attach($connection, &$part, $message_number, $id, $option){
$filename = false;
@@ -99,6 +132,17 @@ function parse_message_decode_attach($connection, &$part, $message_number, $id,
);
}
/**
* Retrieves and decodes the body of a message from an email server.
*
* @param resource $connection IMAP connection to the email server
* @param object & $part Part of the email being processed
* @param int $message_number The number of the message to retrieve
* @param string $id Unique identifier for the part
* @param int $option Option flag (default value is not documented)
*
* @return string The decoded body of the message
*/
function parse_message_fetch_body($connection, &$part, $message_number, $id, $option){
$body = imap_fetchbody($connection, $message_number, $id, $option);
if($part->encoding == ENCBASE64){
@@ -110,6 +154,13 @@ function parse_message_fetch_body($connection, &$part, $message_number, $id, $op
return $body;
}
/**
* Returns the type and subtype of a message part.
*
* @param object $part Message part object containing type and subtype information.
*
* @return string Type and subtype of the message part, separated by a slash. (e.g., "message/plain")
*/
function parse_message_get_type(&$part){
$types = Array(
TYPEMESSAGE => 'message',
@@ -126,6 +177,17 @@ function parse_message_get_type(&$part){
return $types[$part->type] . '/' . strtolower($part->subtype);
}
/**
* Recursively flattens a hierarchical message structure into a single-level array.
*
* @param object $structure Message structure containing nested parts and subparts.
* @param array &$result Resulting flattened array of message parts.
* @param string $prefix Prefix for each part in the result array (optional).
* @param int $index Index of the current part (used for generating prefixes, optional).
* @param bool $fullPrefix Whether to include the index in the prefix or not (optional).
*
* @return array Flattened message structure.
*/
function parse_message_flatten(&$structure, &$result = array(), $prefix = '', $index = 1, $fullPrefix = true) {
foreach ($structure as $part) {
if(isset($part->parts)) {

View File

@@ -37,12 +37,15 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_uuid;
@@ -57,7 +60,12 @@
private $location;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -75,7 +83,13 @@
}
/**
* delete rows from the database
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->name . '_delete')) {
@@ -122,7 +136,11 @@
}
/**
* resend selected faxes in the fax queue
* Resend multiple faxes.
*
* @param array $records Array of records to resend, where each record contains a 'checked' and 'fax_queue_uuid' key.
*
* @return void
*/
public function resend($records) {
if (permission_exists($this->name . '_edit')) {
@@ -174,7 +192,13 @@
}
/**
* toggle a field between two values
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
if (permission_exists($this->name . '_edit')) {
@@ -240,7 +264,13 @@
}
/**
* copy rows from the database
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
if (permission_exists($this->name . '_add')) {
@@ -315,7 +345,9 @@
/**
* Removes records from the v_fax_files and v_fax_logs tables. Called by the maintenance application.
*
* @param settings $settings Settings object
*
* @return void
*/
public static function database_maintenance(settings $settings): void {

View File

@@ -34,6 +34,13 @@
//echo "pid_file: ".$pid_file."\n";
//function to check if the process exists
/**
* Checks if a process is running.
*
* @param string $file The path to the file containing the process ID, or false for no check.
*
* @return bool True if the process is running, false otherwise.
*/
function process_exists($file = false) {
//set the default exists to false

View File

@@ -40,6 +40,16 @@
//extract dtmf from the fax number
if (!function_exists('fax_split_dtmf')) {
/**
* Splits the fax number and DTMF tone string.
*
* This function takes a fax number with an optional DTMF tone string as input,
* extracts the fax number and the DTMF tone string, and stores them separately in
* the provided references.
*
* @param string &$fax_number The fax number to split. May contain an embedded DTMF tone string.
* @param string &$fax_dtmf The extracted DTMF tone string.
*/
function fax_split_dtmf(&$fax_number, &$fax_dtmf) {
$tmp = array();
$fax_dtmf = '';
@@ -62,6 +72,16 @@
}
//shutdown call back function
/**
* Performs a clean shutdown of the system.
*
* This function prepares for graceful termination by updating the fax queue status
* and removing the pid file. It is intended to be called when the application needs
* to shut down cleanly.
*
* @return void
* @see \register_shutdown_function()
*/
function shutdown() {
//add global variables
global $database, $fax_queue_uuid;
@@ -89,6 +109,16 @@
//echo "pid_file: ".$pid_file."\n";
//function to check if the process exists
/**
* Checks if a process exists.
*
* This function checks the existence of a file containing a valid process ID,
* then verifies that the corresponding process is running using the `ps` command.
*
* @param string $file The path to the file containing the process ID. Defaults to an empty string, which means the function will return false.
*
* @return bool True if the process exists and is running, false otherwise.
*/
function process_exists($file = '') {
//check if the file exists return false if not found
if (!file_exists($file)) {
@@ -112,6 +142,15 @@
}
//remove single quote
/**
* Escapes single quotes in a string.
*
* This function removes all occurrences of single quotes from the input value.
*
* @param string $value The value to remove single quotes from. May be empty.
*
* @return boolean|string True if the value was not empty, otherwise false.
*/
function escape_quote($value) {
if (!empty($value)) {
return str_replace("'", "", $value);

View File

@@ -37,6 +37,16 @@
//echo "pid_file: ".$pid_file."\n";
//function to check if the process exists
/**
* Checks if a process exists.
*
* This function checks if a process with the specified PID file exists, and returns true if it does,
* or false otherwise. If no PID file is provided, the function defaults to returning false.
*
* @param string|false $file The path to the PID file of the process to check for, or false to default to not checking any process.
*
* @return bool True if a process with the specified PID exists, false otherwise.
*/
function process_exists($file = false) {
//set the default exists to false

View File

@@ -13,12 +13,15 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_uuid;
@@ -35,7 +38,12 @@
private $uuid_prefix;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -55,17 +63,13 @@
}
/**
* called when there are no references to a particular object
* unset the variables used in the class
*/
public function __destruct() {
foreach ($this as $key => $value) {
unset($this->$key);
}
}
/**
* delete rows from the database
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->name . '_delete')) {
@@ -147,7 +151,13 @@
}
/**
* toggle a field between two values
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
if (permission_exists($this->name . '_edit')) {
@@ -213,7 +223,13 @@
}
/**
* copy rows from the database
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
if (permission_exists($this->name . '_add')) {

View File

@@ -91,6 +91,18 @@
//gateway status function
if (!function_exists('switch_gateway_status')) {
/**
* Switches the status of a gateway.
*
* This function sends an API request to retrieve the status of a gateway.
* If the first request fails, it attempts to send the same request with the
* gateway UUID in uppercase.
*
* @param string $gateway_uuid The unique identifier of the gateway.
* @param string $result_type The type of response expected (default: 'xml').
*
* @return string The status of the gateway, or an error message if the request fails.
*/
function switch_gateway_status($gateway_uuid, $result_type = 'xml') {
global $esl;
if ($esl->is_connected()) {

View File

@@ -35,24 +35,30 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_uuid;
@@ -68,7 +74,12 @@
private $toggle_values;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -89,7 +100,15 @@
}
/**
* start gateways
* Starts the checked gateways.
*
* This method checks for permission to edit and validates the token. It then
* filters out unchecked gateways and retrieves their details from the database.
* If necessary, it creates an event socket connection and starts the gateways.
*
* @param array $records A list of gateway records.
*
* @return void
*/
public function start($records) {
if (permission_exists($this->permission_prefix . 'edit')) {
@@ -121,8 +140,7 @@
$sql = "select " . $this->uuid_prefix . "uuid as uuid, gateway, profile, enabled from v_" . $this->table . " ";
if (permission_exists('gateway_all')) {
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
}
else {
} else {
$sql .= "where (domain_uuid = :domain_uuid) ";
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
$parameters['domain_uuid'] = $this->domain_uuid;
@@ -176,7 +194,15 @@
}
/**
* stop gateways
* Stops the checked gateways.
*
* This method checks for permission to edit and validates the token. It then
* filters out unchecked gateways and retrieves their details from the database.
* If necessary, it creates an event socket connection and stops the gateways.
*
* @param array $records A list of gateway records.
*
* @return void
*/
public function stop($records) {
if (permission_exists($this->permission_prefix . 'edit')) {
@@ -208,8 +234,7 @@
$sql = "select " . $this->uuid_prefix . "uuid as uuid, gateway, profile, enabled from v_" . $this->table . " ";
if (permission_exists('gateway_all')) {
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
}
else {
} else {
$sql .= "where (domain_uuid = :domain_uuid) ";
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
$parameters['domain_uuid'] = $this->domain_uuid;
@@ -253,7 +278,13 @@
}
/**
* delete records
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->permission_prefix . 'delete')) {
@@ -285,8 +316,7 @@
$sql = "select " . $this->uuid_prefix . "uuid as uuid, gateway, profile from v_" . $this->table . " ";
if (permission_exists('gateway_all')) {
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
}
else {
} else {
$sql .= "where (domain_uuid = :domain_uuid) ";
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
$parameters['domain_uuid'] = $this->domain_uuid;
@@ -375,7 +405,13 @@
}
/**
* toggle records
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
if (permission_exists($this->permission_prefix . 'edit')) {
@@ -405,8 +441,7 @@
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as state, gateway, profile from v_" . $this->table . " ";
if (permission_exists('gateway_all')) {
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
}
else {
} else {
$sql .= "where (domain_uuid = :domain_uuid) ";
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
$parameters['domain_uuid'] = $this->domain_uuid;
@@ -442,8 +477,7 @@
foreach ($gateways as $gateway_uuid => $gateway) {
if ($gateway['state'] == 'true') {
$_SESSION['gateways'][$gateway_uuid] = $gateway['name'];
}
else {
} else {
unset($_SESSION['gateways'][$gateway_uuid]);
//remove the xml file (if any)
@@ -494,7 +528,13 @@
}
/**
* copy records
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
if (permission_exists($this->permission_prefix . 'add')) {
@@ -526,8 +566,7 @@
$sql = "select * from v_" . $this->table . " ";
if (permission_exists('gateway_all')) {
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
}
else {
} else {
$sql .= "where (domain_uuid = :domain_uuid) ";
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
$parameters['domain_uuid'] = $this->domain_uuid;

View File

@@ -34,37 +34,45 @@
const app_uuid = 'a5788e9b-58bc-bd1b-df59-fff5d51253ab';
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
public $domain_uuid;
/**
* declare ivr menu primary uuid key
*
* @var string
*/
public $ivr_menu_uuid;
/**
* declare order_by variables
*
* @var string
*/
public $order_by;
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_name;
@@ -80,7 +88,12 @@
private $toggle_values;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -94,6 +107,11 @@
$this->list_page = 'ivr_menus.php';
}
/**
* Finds records in the v_ivr_menus table.
*
* @return array An array of menu items or an empty array if no records are found.
*/
public function find() {
$sql = "select * from v_ivr_menus ";
$sql .= "where domain_uuid = :domain_uuid ";
@@ -109,7 +127,13 @@
}
/**
* delete records
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
//assign private variables
@@ -207,6 +231,13 @@
}
/**
* Deletes one or more ivr menu options.
*
* @param array $records An associative array containing the uuids and checked status of the records to delete.
*
* @return bool True if the operation was successful, false otherwise.
*/
public function delete_options($records) {
//assign private variables
$this->permission_prefix = 'ivr_menu_option_';
@@ -273,7 +304,13 @@
}
/**
* toggle records
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
//assign private variables
@@ -369,7 +406,13 @@
}
/**
* copy records
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
//assign private variables

View File

@@ -25,8 +25,16 @@
*/
if (!function_exists('save_ivr_menu_xml')) {
/**
* Saves IVR menu XML configuration files.
*
* This function deletes all existing dialplan .xml files in the ivr_menus directory,
* then creates new IVR menu XML files based on the database records for the current domain.
*
* @return void
*/
function save_ivr_menu_xml() {
global $domain_uuid;
global $domain_uuid, $settings;
//prepare for dialplan .xml files to be written. delete all dialplan files that are prefixed with dialplan_ and have a file extension of .xml
if (count($_SESSION["domains"]) > 1) {

View File

@@ -167,6 +167,11 @@
echo "<div class='card'>\n";
echo "<table class='list'>\n";
/**
* Writes the header for a list of modules.
*
* @param string $modifier The modifier to use in the checkbox ID and other attributes.
*/
function write_header($modifier) {
global $text, $modules, $list_row_edit_button;
$modifier = str_replace('/', '', $modifier);

View File

@@ -43,24 +43,30 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_uuid;
@@ -77,7 +83,12 @@
private $active_modules;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -103,7 +114,13 @@
}
/**
* get the additional information about a specific module
* Get additional information about a specific module
*
* Retrieves and formats information about a module.
*
* @param string $name The name of the module to retrieve information for.
*
* @return array An array containing the formatted module information.
*/
public function info($name) {
$module_label = substr($name, 4);
@@ -768,6 +785,14 @@
}
//check to see if the module exists in the array
/**
* Check if a module exists in the collection of modules.
*
* @param string $name The name of the module to check for existence.
*
* @return bool True if the module exists, false otherwise.
*/
public function exists($name) {
//set the default
$result = false;
@@ -782,7 +807,13 @@
return $result;
}
//check the status of the module
/**
* Check the status of the module
*
* @param string $name Module name to check for activity
*
* @return bool True if the module is active, false otherwise
*/
public function active($name) {
foreach ($this->active_modules['rows'] as $row) {
if ($row['ikey'] === $name) {
@@ -792,15 +823,28 @@
return false;
}
//get the list of modules
/**
* Sets a list of modules in the object property modules.
*
* @return void
*/
public function get_modules() {
$sql = "select * from v_modules ";
$sql .= "order by module_category, module_label";
$this->modules = $this->database->select($sql, null, 'all');
unset($sql);
}
//add missing modules for more module info see http://wiki.freeswitch.com/wiki/Modules
/**
* Synchronize modules with the database.
*
* Scans the module directory for new or updated modules and inserts them into
* the database. If a module is found, it is added to the database with its label,
* name, description, category, order, enabled status, and default enabled status.
*
* @return void
*/
public function synch() {
if (false !== ($handle = opendir($this->dir ?? ''))) {
$modules_new = '';
@@ -862,6 +906,11 @@
}
//save the modules.conf.xml file
/**
* Composes the XML configuration for modules and saves it to modules.conf.xml file in the switch/autoload_configs
* directory configured in the global default settings.
*/
function xml() {
//set the globals
global $config, $domain_uuid;
@@ -906,21 +955,32 @@
}
/**
* start modules
* Initiates the starting process.
*
* @param mixed[] $records Data required for the starting process
*
* @see modules::control()
*/
public function start($records) {
$this->control('start', $records);
}
/**
* stop modules
* Stops a module from the switch.
*
* @param mixed[] $records Data required for the termination process
*
* @see modules::control()
*/
public function stop($records) {
$this->control('stop', $records);
}
/**
* control (load/unload) modules
* Performs the specified control action on the checked modules.
*
* @param string $action The type of control to be performed ('start' or 'stop')
* @param mixed[] $records An array of records containing information about the modules to be controlled
*/
private function control($action, $records) {
if (permission_exists($this->permission_prefix . 'edit')) {
@@ -985,8 +1045,7 @@
if ($module['enabled'] == 'true') {
$responses[$module_uuid]['module'] = $module['name'];
$responses[$module_uuid]['message'] = trim(event_socket::api($action . ' ' . $module['name']));
}
else {
} else {
$responses[$module_uuid]['module'] = $module['name'];
$responses[$module_uuid]['message'] = $text['label-disabled'];
}
@@ -1008,7 +1067,13 @@
}
/**
* delete modules
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->permission_prefix . 'delete')) {
@@ -1096,7 +1161,13 @@
}
/**
* toggle records
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
if (permission_exists($this->permission_prefix . 'edit')) {
@@ -1186,7 +1257,6 @@
}
} //method
} //class
/*

View File

@@ -612,6 +612,16 @@
require_once "resources/footer.php";
//define the download function (helps safari play audio sources)
/**
* Downloads a file in chunks as requested by the client.
*
* This function is used to handle byte-range requests, allowing clients
* to request specific parts of the file.
*
* @param string $file The path to the file being downloaded.
*
* @return void
*/
function range_download($file) {
$fp = @fopen($file, 'rb');
@@ -640,7 +650,7 @@
$c_start = $start;
$c_end = $end;
// Extract the range string
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
[, $range] = explode('=', $_SERVER['HTTP_RANGE'], 2);
// Make sure the client hasn't sent us a multibyte range
if (strpos($range, ',') !== false) {
// (?) Shoud this be issued here, or should the first

View File

@@ -37,36 +37,46 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $this->settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $this->settings_array associative array or
* set in the session global array
*
* @var string
*/
private $user_uuid;
/**
* Username set in the constructor. This can be passed in through the $this->settings_array associative array or set in the session global array
* Username set in the constructor. This can be passed in through the $this->settings_array associative array or
* set in the session global array
*
* @var string
*/
private $username;
/**
* Domain UUID set in the constructor. This can be passed in through the $this->settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $this->settings_array associative array or
* set in the session global array
*
* @var string
*/
private $domain_uuid;
/**
* Domain name set in the constructor. This can be passed in through the $this->settings_array associative array or set in the session global array
* Domain name set in the constructor. This can be passed in through the $this->settings_array associative array or
* set in the session global array
*
* @var string
*/
private $domain_name;
@@ -83,7 +93,12 @@
private $uuid_prefix;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -101,6 +116,15 @@
$this->uuid_prefix = 'music_on_hold_';
}
/**
* Generates a HTML select element.
*
* @param string $name The name of the select field.
* @param string $selected The currently selected value.
* @param array $options Additional options to include in the select.
*
* @return string A HTML select element as a string.
*/
public function select($name, $selected, $options) {
//add multi-lingual support
$language = new text;
@@ -169,6 +193,11 @@
return $select;
}
/**
* Retrieves moh records and builds an array.
*
* @return array|false An array of moh records.
*/
public function get() {
//get moh records, build array
$sql = "select ";
@@ -182,6 +211,9 @@
return $this->database->select($sql, $parameters, 'all');
}
/**
* Reloads the module and establishes a connection to the Event Socket.
*/
public function reload() {
//add multi-lingual support
$language = new text;
@@ -203,12 +235,17 @@
}
}
/**
* Saves the music on hold configuration.
*
* This method retrieves the contents of the template, replaces variables,
* and writes the updated XML config file to disk. The XML is then reloaded.
*/
public function save() {
//get the contents of the template
if (file_exists('/usr/share/examples/fusionpbx')) {
$file_contents = file_get_contents("/usr/share/examples/fusionpbx/resources/templates/conf/autoload_configs/local_stream.conf.xml");
}
else {
} else {
$file_contents = file_get_contents($_SERVER["PROJECT_ROOT"] . "/app/switch/resources/conf/autoload_configs/local_stream.conf.xml");
}
//check where the default music is stored
@@ -230,7 +267,10 @@
}
/**
* read the music files to add the music on hold into the database
* Imports music on hold records.
*
* Retrieves domain and music on hold data, builds an array of sound files,
* and saves the data to the database.
*/
public function import() {
//get the domains
@@ -311,7 +351,13 @@
}
/**
* delete records/files
* Deletes one or more records/files.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->permission_prefix . 'delete')) {
@@ -438,7 +484,6 @@
} //class
//build and save the XML
//$moh = new switch_music_on_hold;
//$moh->xml();

View File

@@ -52,9 +52,13 @@
private $xml;
private $display_type;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set objects
@@ -70,7 +74,11 @@
}
/**
* Check to see if the number translation already exists
* Checks if a given name exists as a number translation.
*
* @param string $name The name to check for existence.
*
* @return bool True if the number translation exists, false otherwise.
*/
public function number_translation_exists($name) {
$sql = "select count(*) from v_number_translations ";
@@ -80,7 +88,9 @@
}
/**
* Import the number translation rules from the resources directory
* Imports a number translation from either XML or JSON format.
*
* @return void
*/
public function import() {
//get the xml from the number templates
@@ -91,12 +101,10 @@
$json = json_encode($xml);
//convert to an array
$number_translation = json_decode($json, true);
}
else if (!empty($this->json)) {
} elseif (!empty($this->json)) {
//convert to an array
$number_translation = json_decode($this->json, true);
}
else {
} else {
throw new Exception("require either json or xml to import");
}
//check if the number_translation exists
@@ -134,8 +142,7 @@
if (!empty($this->display_type) && $this->display_type == "text") {
if ($this->database->message['code'] != '200') {
echo "number_translation:" . $number_translation['@attributes']['name'] . ": failed: " . $this->database->message['message'] . "\n";
}
else {
} else {
echo "number_translation:" . $number_translation['@attributes']['name'] . ": added with " . (($order / 5) - 1) . " entries\n";
}
}
@@ -147,7 +154,13 @@
}
/**
* delete records
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->permission_prefix . 'delete')) {
@@ -197,6 +210,15 @@
}
}
/**
* Deletes multiple records from the number_translation_details table.
*
* @param array $records An array of records to be deleted, where each record is an associative array containing 'checked' and 'uuid' keys.
* The 'checked' key should contain a boolean value indicating whether the record should be deleted,
* while the 'uuid' key contains the unique identifier of the record.
*
* @return void
*/
public function delete_details($records) {
//assign private variables
@@ -243,7 +265,13 @@
}
/**
* toggle records
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
if (permission_exists($this->permission_prefix . 'edit')) {
@@ -307,7 +335,13 @@
}
/**
* copy records
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
if (permission_exists($this->permission_prefix . 'add')) {

View File

@@ -40,12 +40,15 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_uuid;
@@ -61,7 +64,12 @@
private $toggle_values;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -80,7 +88,13 @@
}
/**
* delete records
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->permission_prefix . 'delete')) {
@@ -168,6 +182,15 @@
}
}
/**
* Delete multiple details records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array containing
* the 'uuid' and optionally a 'checked' field. The 'checked' field should be set to true if the record
* should be deleted.
*
* @return void
*/
public function delete_details($records) {
//assign private variables
$this->permission_prefix = 'phrase_';
@@ -239,7 +262,13 @@
}
/**
* toggle records
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
if (permission_exists($this->permission_prefix . 'edit')) {
@@ -320,7 +349,13 @@
}
/**
* copy records
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
if (permission_exists($this->permission_prefix . 'add')) {

View File

@@ -51,6 +51,13 @@
$available_columns[] = 'description';
//define the functions
/**
* Converts a multi-dimensional PHP array into a CSV string.
*
* @param array &$array The input data to be converted. It is expected to have at least one row and one column.
*
* @return string|null The CSV representation of the input data, or null if the input array is empty.
*/
function array2csv(array &$array) {
if (count($array) == 0) {
return null;
@@ -65,6 +72,13 @@
return ob_get_clean();
}
/**
* Sends HTTP headers for a file download.
*
* @param string $filename The name of the file to be downloaded.
*
* @return void
*/
function download_send_headers($filename) {
// disable caching
$now = gmdate("D, d M Y H:i:s");

View File

@@ -35,18 +35,22 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_uuid;
@@ -62,7 +66,12 @@
private $toggle_values;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -81,7 +90,13 @@
}
/**
* delete records
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->permission_prefix . 'delete')) {
@@ -125,7 +140,13 @@
}
/**
* toggle records
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
if (permission_exists($this->permission_prefix . 'edit')) {
@@ -191,7 +212,13 @@
}
/**
* copy records
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
if (permission_exists($this->permission_prefix . 'add')) {

View File

@@ -72,6 +72,13 @@
}
//send http error
/**
* Displays a custom HTTP error page with the specified error code and message.
*
* @param int $error The HTTP error code (e.g., 400, 401, etc.)
*
* @return void The script exits after displaying the error page
*/
function http_error($error) {
//$error_int_val = intval($error);
$http_errors = [
@@ -272,6 +279,13 @@
if (!empty($provision["http_auth_username"]) && empty($provision["http_auth_type"])) { $provision["http_auth_type"] = "digest"; }
if (!empty($provision["http_auth_username"]) && $provision["http_auth_type"] === "digest" && !empty($provision["http_auth_enabled"]) && $provision["http_auth_enabled"]) {
//function to parse the http auth header
/**
* Parses the specified HTTP Digest authentication text and extracts relevant data.
*
* @param string $txt The HTTP Digest authentication text to parse
*
* @return array|false An array of extracted data if successful, or false if data is incomplete
*/
function http_digest_parse($txt) {
//protect against missing data
$needed_parts = array('nonce'=>1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1);
@@ -286,6 +300,13 @@
}
//function to request digest authentication
/**
* Sends an HTTP Digest authentication request with the specified realm.
*
* @param string $realm The name of the protected resource's realm
*
* @return void The script exits after sending the authentication request
*/
function http_digest_request($realm) {
header('HTTP/1.1 401 Authorization Required');
header('WWW-Authenticate: Digest realm="'.$realm.'", qop="auth", nonce="'.uniqid().'", opaque="'.md5($realm).'"');
@@ -447,8 +468,8 @@
$file_size = strlen($file_contents);
if (isset($_SERVER['HTTP_RANGE'])) {
$ranges = $_SERVER['HTTP_RANGE'];
list($unit, $range) = explode('=', $ranges, 2);
list($start, $end) = explode('-', $range, 2);
[$unit, $range] = explode('=', $ranges, 2);
[$start, $end] = explode('-', $range, 2);
$start = empty($start) ? 0 : (int)$start;
$end = empty($end) ? $file_size - 1 : min((int)$end, $file_size - 1);

View File

@@ -35,13 +35,17 @@
const app_uuid = 'abf28ead-92ef-3de6-ebbb-023fbc2b6dd3';
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
public $domain_uuid;
/**
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
public $domain_name;
@@ -56,24 +60,33 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -94,42 +107,34 @@
if (empty($this->template_dir)) {
if (file_exists('/usr/share/fusionpbx/templates/provision')) {
$this->template_dir = '/usr/share/fusionpbx/templates/provision';
}
elseif (file_exists('/etc/fusionpbx/resources/templates/provision')) {
} elseif (file_exists('/etc/fusionpbx/resources/templates/provision')) {
$this->template_dir = '/etc/fusionpbx/resources/templates/provision';
}
else {
} else {
$this->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/resources/templates/provision';
}
}
}
elseif (PHP_OS == "FreeBSD") {
} elseif (PHP_OS == "FreeBSD") {
//if the FreeBSD port is installed use the following paths by default.
if (empty($this->template_dir)) {
if (file_exists('/usr/local/share/fusionpbx/templates/provision')) {
$this->template_dir = '/usr/local/share/fusionpbx/templates/provision';
}
elseif (file_exists('/usr/local/etc/fusionpbx/resources/templates/provision')) {
} elseif (file_exists('/usr/local/etc/fusionpbx/resources/templates/provision')) {
$this->template_dir = '/usr/local/etc/fusionpbx/resources/templates/provision';
}
else {
} else {
$this->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/resources/templates/provision';
}
}
}
else if (PHP_OS == "NetBSD") {
} elseif (PHP_OS == "NetBSD") {
//set the default template_dir
if (empty($this->template_dir)) {
$this->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/resources/templates/provision';
}
}
else if (PHP_OS == "OpenBSD") {
} elseif (PHP_OS == "OpenBSD") {
//set the default template_dir
if (empty($this->template_dir)) {
$this->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/resources/templates/provision';
}
}
else {
} else {
//set the default template_dir
if (empty($this->template_dir)) {
$this->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/resources/templates/provision';
@@ -143,13 +148,23 @@
}
/**
* get the domain uuid
* Retrieves the domain UUID associated with the object instance.
*
* @return string The domain UUID of the current domain.
*/
public function get_domain_uuid() {
return $this->domain_uuid;
}
//define the function which checks to see if the device address exists in devices
/**
* Checks if a device exists in the database.
*
* @param string $device_address The MAC address of the device to check for existence.
*
* @return bool True if the device is found in the database, false otherwise.
*/
private function device_exists($device_address) {
//normalize the device address
$device_address = strtolower(preg_replace('#[^a-fA-F0-9./]#', '', $device_address));
@@ -161,14 +176,21 @@
$num_rows = $this->database->select($sql, $parameters, 'column');
if ($num_rows > 0) {
return true;
}
else {
} else {
return false;
}
unset($sql, $parameters, $num_rows);
}
//set the device address in the correct format for the specific vendor
/**
* Formats the device address according to the vendor.
*
* @param string $device_address The IP address or hostname of the device.
* @param string $vendor The vendor of the device, e.g. "cisco", "linksys", etc.
*
* @return string The formatted device address.
*/
public function format_address($device_address, $vendor) {
switch (strtolower($vendor)) {
case "algo":
@@ -199,6 +221,14 @@
}
//send http error
/**
* Handles HTTP errors and displays a 404 Not Found page if the error code is '404'.
*
* @param string $error The HTTP error code.
*
* @return void Exits the script with an HTTP status code of 404 if the error code is '404', otherwise continues execution.
*/
private function http_error($error) {
if ($error === "404") {
header("HTTP/1.0 404 Not Found");
@@ -214,15 +244,34 @@
}
//define a function to check if a contact exists in the contacts array
/**
* Checks if a contact exists in the given array of contacts.
*
* @param array $contacts The array of contacts to search in.
* @param string $uuid The unique identifier (UUID) of the contact to look for.
*
* @return bool True if the contact exists, false otherwise.
*/
private function contact_exists($contacts, $uuid) {
if (is_array($contacts[$uuid])) {
return true;
}
else {
} else {
return false;
}
}
/**
* Appends contacts from the database to the given array of contacts.
*
* @param array $contacts The array of contacts to append to.
* @param string $line The current line being processed (used for phone numbers).
* @param string $domain_uuid The UUID of the domain to filter by.
* @param string $device_user_uuid The UUID of the device user to filter by.
* @param string $category The category of contacts to append (one of 'groups', 'users', or 'all').
*
* @return void
*/
private function contact_append(&$contacts, &$line, $domain_uuid, $device_user_uuid, $category) {
$sql = "select c.contact_uuid, c.contact_organization, c.contact_name_given, c.contact_name_family, ";
@@ -259,7 +308,7 @@
$phone_label = strtolower($row['phone_label'] ?? '');
$contact_category = strtolower($row['contact_category'] ?? '');
$contact = array();
$contact = [];
$contacts[] = &$contact;
$contact['category'] = ($category == 'all') ? 'groups' : $category;
$contact['contact_uuid'] = $row['contact_uuid'];
@@ -269,7 +318,7 @@
$contact['contact_name_given'] = $row['contact_name_given'];
$contact['contact_name_family'] = $row['contact_name_family'];
$contact['numbers'] = array();
$contact['numbers'] = [];
$numbers = &$contact['numbers'];
if (($row['phone_primary'] == '1') || (!isset($contact['phone_number']))) {
@@ -293,6 +342,15 @@
}
}
/**
* Renders the provision page for a device.
*
* This method checks if the device address exists in the database, and if so,
* it retrieves the corresponding device information and template. If not, it
* attempts to assign a default template based on the user agent.
*
* @return void
*/
public function render() {
//debug
@@ -318,7 +376,7 @@
//}
//remove ../ and slashes in the file name
$search = array('..', '/', '\\', '/./', '//');
$search = ['..', '/', '\\', '/./', '//'];
$file = str_replace($search, "", $file);
//get the domain_name
@@ -359,8 +417,7 @@
syslog(LOG_WARNING, '[' . $_SERVER['REMOTE_ADDR'] . "] provision attempted but the device is not enabled for " . escape($device_address));
if ($this->settings->get('provision', 'debug', false)) {
echo "<br/>device disabled<br/>";
}
else {
} else {
$this->http_error('404');
}
exit;
@@ -419,8 +476,7 @@
}
unset($sql, $row, $parameters);
}
}
else {
} else {
//use the user_agent to pre-assign a template for 1-hit provisioning. Enter the a unique string to match in the user agent, and the template it should match.
$templates['Linksys/SPA-2102'] = 'linksys/spa2102';
$templates['Linksys/SPA-3102'] = 'linksys/spa3102';
@@ -735,8 +791,7 @@
$sql .= "where device_profile_uuid = :device_profile_uuid ";
if (strtolower($device_vendor) == 'escene') {
$sql .= "and (lower(profile_key_vendor) = 'escene' or lower(profile_key_vendor) = 'escene programmable' or profile_key_vendor is null) ";
}
else {
} else {
$sql .= "and (lower(profile_key_vendor) = :device_vendor or profile_key_vendor is null) ";
$parameters['device_vendor'] = $device_vendor;
}
@@ -750,8 +805,7 @@
$sql .= "else 100 end, ";
if ($GLOBALS['db_type'] == "mysql") {
$sql .= "profile_key_id asc ";
}
else {
} else {
$sql .= "cast(profile_key_id as numeric) asc ";
}
$parameters['device_profile_uuid'] = $device_profile_uuid;
@@ -788,8 +842,7 @@
$sql .= "where device_uuid = :device_uuid ";
if (strtolower($device_vendor) == 'escene') {
$sql .= "and (lower(device_key_vendor) = 'escene' or lower(device_key_vendor) = 'escene programmable' or device_key_vendor is null) ";
}
else {
} else {
$sql .= "and (lower(device_key_vendor) = :device_vendor or device_key_vendor is null) ";
$parameters['device_vendor'] = $device_vendor;
}
@@ -803,8 +856,7 @@
$sql .= "else 100 end, ";
if ($GLOBALS['db_type'] == "mysql") {
$sql .= "device_key_id asc ";
}
else {
} else {
$sql .= "cast(device_key_id as numeric) asc ";
}
$parameters['device_uuid'] = $device_uuid;
@@ -845,7 +897,7 @@
if (in_array($device_key_vendor, ['cisco', 'spa']) && $row['device_key_type'] == 'disabled') {
$device_key_array = explode(';', $row['device_key_value']);
foreach ($device_key_array as $sub_row) {
list($key, $value) = explode('=', $sub_row);
[$key, $value] = explode('=', $sub_row);
if ($key == 'sub') {
$extension = explode('@', $value)[0]; //remove the @PROXY
$caller_id_name = $extension_labels[$extension]['caller_id_name'];
@@ -876,7 +928,9 @@
$sip_port = $row['sip_port'] ?? '5060';
//set defaults
if (empty($register_expires)) { $register_expires = "120"; }
if (empty($register_expires)) {
$register_expires = "120";
}
//convert seconds to minutes for grandstream
if ($device_vendor == 'grandstream') {
@@ -950,8 +1004,7 @@
if (is_uuid($device_user_uuid) && $this->settings->get('contact', 'contact_users', false)) {
$this->contact_append($contacts, $line, $domain_uuid, $device_user_uuid, 'users');
}
}
else {
} else {
//show all contacts for the domain
$this->contact_append($contacts, $line, $domain_uuid, null, 'all');
}
@@ -987,8 +1040,7 @@
//get the phone_extension
if (is_numeric($row['extension'])) {
$phone_extension = $row['extension'];
}
else {
} else {
$phone_extension = $row['number_alias'];
}
//save the contact array values
@@ -1046,7 +1098,7 @@
//update the device keys by replacing variables with their values
if (!empty($device_keys['line']) && is_array($device_keys)) {
$types = array("line", "memory", "expansion", "programmable");
$types = ["line", "memory", "expansion", "programmable"];
foreach ($types as $type) {
if (!empty($device_keys[$type]) && is_array($device_keys[$type])) {
foreach ($device_keys[$type] as $row) {
@@ -1090,7 +1142,7 @@
}
//set the variables
$types = array("line", "memory", "expansion", "programmable");
$types = ["line", "memory", "expansion", "programmable"];
foreach ($types as $type) {
if (!empty($device_keys[$type]) && is_array($device_keys[$type])) {
foreach ($device_keys[$type] as $row) {
@@ -1114,39 +1166,97 @@
if ($device_vendor == "grandstream") {
if ($device_key_category == "line") {
switch ($device_key_type) {
case "line": $device_key_type = "0"; break;
case "shared line": $device_key_type = "1"; break;
case "speed dial": $device_key_type = "10"; break;
case "blf": $device_key_type = "11"; break;
case "presence watcher": $device_key_type = "12"; break;
case "eventlist blf": $device_key_type = "13"; break;
case "speed dial active": $device_key_type = "14"; break;
case "dial dtmf": $device_key_type = "15"; break;
case "voicemail": $device_key_type = "16"; break;
case "call return": $device_key_type = "17"; break;
case "transfer": $device_key_type = "18"; break;
case "call park": $device_key_type = "19"; break;
case "monitored call park": $device_key_type = "26"; break;
case "intercom": $device_key_type = "20"; break;
case "ldap search": $device_key_type = "21"; break;
case "phonebook": $device_key_type = "30"; break;
case "line":
$device_key_type = "0";
break;
case "shared line":
$device_key_type = "1";
break;
case "speed dial":
$device_key_type = "10";
break;
case "blf":
$device_key_type = "11";
break;
case "presence watcher":
$device_key_type = "12";
break;
case "eventlist blf":
$device_key_type = "13";
break;
case "speed dial active":
$device_key_type = "14";
break;
case "dial dtmf":
$device_key_type = "15";
break;
case "voicemail":
$device_key_type = "16";
break;
case "call return":
$device_key_type = "17";
break;
case "transfer":
$device_key_type = "18";
break;
case "call park":
$device_key_type = "19";
break;
case "monitored call park":
$device_key_type = "26";
break;
case "intercom":
$device_key_type = "20";
break;
case "ldap search":
$device_key_type = "21";
break;
case "phonebook":
$device_key_type = "30";
break;
}
}
if ($device_key_category == "memory" || $device_key_category == "expansion") {
switch ($device_key_type) {
case "speed dial": $device_key_type = "0"; break;
case "blf": $device_key_type = "1"; break;
case "presence watcher": $device_key_type = "2"; break;
case "eventlist blf": $device_key_type = "3"; break;
case "speed dial active": $device_key_type = "4"; break;
case "dial dtmf": $device_key_type = "5"; break;
case "voicemail": $device_key_type = "6"; break;
case "call return": $device_key_type = "7"; break;
case "transfer": $device_key_type = "8"; break;
case "call park": $device_key_type = "9"; break;
case "monitored call park": $device_key_type = "16"; break;
case "intercom": $device_key_type = "10"; break;
case "ldap search": $device_key_type = "11"; break;
case "speed dial":
$device_key_type = "0";
break;
case "blf":
$device_key_type = "1";
break;
case "presence watcher":
$device_key_type = "2";
break;
case "eventlist blf":
$device_key_type = "3";
break;
case "speed dial active":
$device_key_type = "4";
break;
case "dial dtmf":
$device_key_type = "5";
break;
case "voicemail":
$device_key_type = "6";
break;
case "call return":
$device_key_type = "7";
break;
case "transfer":
$device_key_type = "8";
break;
case "call park":
$device_key_type = "9";
break;
case "monitored call park":
$device_key_type = "16";
break;
case "intercom":
$device_key_type = "10";
break;
case "ldap search":
$device_key_type = "11";
break;
}
}
}
@@ -1160,8 +1270,7 @@
$view->assign("key_extension_" . $device_key_id, $device_key_extension);
$view->assign("key_label_" . $device_key_id, $device_key_label);
$view->assign("key_icon_" . $device_key_id, $device_key_icon);
}
else {
} else {
$view->assign($device_key_category . "_key_id_" . $device_key_id, $device_key_id);
$view->assign($device_key_category . "_key_type_" . $device_key_id, $device_key_type);
$view->assign($device_key_category . "_key_line_" . $device_key_id, $device_key_line);
@@ -1297,25 +1406,19 @@
if (empty($file)) {
if (file_exists($template_dir . "/" . $device_template . "/{\$address}")) {
$file = "{\$address}";
}
elseif (file_exists($template_dir."/".$device_template ."/{\$address}.xml")) {
} elseif (file_exists($template_dir . "/" . $device_template . "/{\$address}.xml")) {
$file = "{\$address}.xml";
}
elseif (file_exists($template_dir."/".$device_template ."/{\$mac}")) {
} elseif (file_exists($template_dir . "/" . $device_template . "/{\$mac}")) {
$file = "{\$mac}";
}
elseif (file_exists($template_dir."/".$device_template ."/{\$mac}.xml")) {
} elseif (file_exists($template_dir . "/" . $device_template . "/{\$mac}.xml")) {
$file = "{\$mac}.xml";
}
elseif (file_exists($template_dir."/".$device_template ."/{\$mac}.cfg")) {
} elseif (file_exists($template_dir . "/" . $device_template . "/{\$mac}.cfg")) {
$file = "{\$mac}.cfg";
}
else {
} else {
$this->http_error('404');
exit;
}
}
else {
} else {
//make sure the file exists
if (!file_exists($template_dir . "/" . $device_template . "/" . $file)) {
$this->http_error('404');
@@ -1348,6 +1451,15 @@
} //end render function
/**
* Writes configuration files for devices based on the provided provision template.
*
* This method iterates over a list of devices in the database, retrieves their configuration
* from the provision array, and writes the corresponding files to disk. If a device is
* disabled, any existing files with a MAC address placeholder are removed.
*
* @return void
*/
function write() {
//build the provision array
$provision = $this->settings->get('provision', null, []);
@@ -1401,7 +1513,7 @@
clearstatcache();
//loop through the provision template directory
$dir_array = array();
$dir_array = [];
if (!empty($device_template)) {
$template_path = path_join($this->template_dir, $device_template);
$dir_list = opendir($template_path);
@@ -1412,7 +1524,9 @@
substr($file, -4) == ".svn" || substr($file, -4) == ".git";
if (!$ignore) {
$dir_array[] = path_join($template_path, $file);
if ($x > 1000) { break; };
if ($x > 1000) {
break;
};
$x++;
}
}
@@ -1461,8 +1575,7 @@
$fh = fopen($dest_path, "w") or die("Unable to write to $directory for provisioning. Make sure the path exists and permissons are set correctly.");
fwrite($fh, $file_contents);
fclose($fh);
}
else { // device disabled
} else { // device disabled
//remove only files with `{$mac}` name
if (strpos($template_path, '{$mac}') !== false) {
unlink($dest_path);

View File

@@ -328,8 +328,8 @@
}
$param .= "&order_by=".$order_by."&order=".$order;
$page = isset($_GET['page']) ? $_GET['page'] : 0;
list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
[$paging_controls, $rows_per_page] = paging($num_rows, $param, $rows_per_page);
[$paging_controls_mini, $rows_per_page] = paging($num_rows, $param, $rows_per_page, true);
$offset = $rows_per_page * $page;
//set the time zone
@@ -622,6 +622,13 @@
require_once "resources/footer.php";
//define the download function (helps safari play audio sources)
/**
* Downloads a file in range mode, allowing the client to request specific byte ranges.
*
* @param string $file Path to the file being downloaded
*
* @return void
*/
function range_download($file) {
$fp = @fopen($file, 'rb');
@@ -650,7 +657,7 @@
$c_start = $start;
$c_end = $end;
// Extract the range string
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
[, $range] = explode('=', $_SERVER['HTTP_RANGE'], 2);
// Make sure the client hasn't sent us a multibyte range
if (strpos($range, ',') !== false) {
// (?) Shoud this be issued here, or should the first

View File

@@ -35,31 +35,39 @@
const app_uuid = '83913217-c7a2-9e90-925d-a866eb40b60e';
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
public $domain_uuid;
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_name;
@@ -75,7 +83,12 @@
private $toggle_values;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -95,7 +108,14 @@
}
/**
* list recordings
* Retrieves a list of recordings.
*
* This method queries the database for recordings associated with the current domain UUID
* and populates an array with the recording filenames. The array keys are constructed using
* the directory path specified in the 'switch' settings, relative to the domain name.
*
* @return array|false An array of recording filenames where the keys represent the file paths on disk,
* or false if no recordings were found.
*/
public function list_recordings() {
$sql = "select recording_uuid, recording_filename ";
@@ -108,8 +128,7 @@
foreach ($result as $row) {
$recordings[$switch_recordings_domain_dir . "/" . $row['recording_filename']] = $row['recording_filename'];
}
}
else {
} else {
$recordings = false;
}
unset($sql, $parameters, $result, $row);
@@ -117,7 +136,13 @@
}
/**
* delete records
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->permission_prefix . 'delete')) {

View File

@@ -34,30 +34,37 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_uuid;
/**
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_name;
/**
* Set in the constructor. Must be an event_socket object and cannot be null.
*
* @var event_socket Event Socket Connection Object
*/
private $event_socket;
@@ -70,7 +77,12 @@
public $show;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -94,7 +106,11 @@
}
/**
* get the registrations
* Retrieves the registration list for a given SIP profile.
*
* @param string|null $profile The name of the SIP profile to retrieve. Defaults to 'all'.
*
* @return array|null The registration list, or null if no profiles are found.
*/
public function get($profile = 'all') {
@@ -149,7 +165,9 @@
}
//sanitize the XML
if (function_exists('iconv')) { $xml_response = iconv("utf-8", "utf-8//IGNORE", $xml_response); }
if (function_exists('iconv')) {
$xml_response = iconv("utf-8", "utf-8//IGNORE", $xml_response);
}
$xml_response = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/u', '', $xml_response);
$xml_response = str_replace("<profile-info>", "<profile_info>", $xml_response);
$xml_response = str_replace("</profile-info>", "</profile_info>", $xml_response);
@@ -158,8 +176,7 @@
if (strlen($xml_response) > 101) {
try {
$xml = new SimpleXMLElement($xml_response);
}
catch(Exception $e) {
} catch (Exception $e) {
echo basename(__FILE__) . "<br />\n";
echo "line: " . __line__ . "<br />\n";
echo "error: " . $e->getMessage() . "<br />\n";
@@ -202,8 +219,7 @@
//get network-ip to url or blank
if (isset($row['network-ip'])) {
$registrations[$id]['network-ip'] = $row['network-ip'];
}
else {
} else {
$registrations[$id]['network-ip'] = '';
}
@@ -214,34 +230,30 @@
$lan_ip = $call_id_array[1];
if (!empty($agent) && (false !== stripos($agent, 'grandstream') || false !== stripos($agent, 'ooma'))) {
$lan_ip = str_ireplace(
array('A','B','C','D','E','F','G','H','I','J'),
array('0','1','2','3','4','5','6','7','8','9'),
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'],
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
$lan_ip);
}
elseif (!empty($agent) && 1 === preg_match('/\ACL750A/', $agent)) {
} elseif (!empty($agent) && 1 === preg_match('/\ACL750A/', $agent)) {
//required for GIGASET Sculpture CL750A puts _ in it's lan ip account
$lan_ip = preg_replace('/_/', '.', $lan_ip);
}
$registrations[$id]['lan-ip'] = $lan_ip;
}
else if (preg_match('/real=\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $row['contact'] ?? '', $ip_match)) {
} elseif (preg_match('/real=\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $row['contact'] ?? '', $ip_match)) {
//get ip address for snom phones
$lan_ip = str_replace('real=', '', $ip_match[0]);
$registrations[$id]['lan-ip'] = $lan_ip;
}
else if (preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $row['contact'] ?? '', $ip_match)) {
} elseif (preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $row['contact'] ?? '', $ip_match)) {
$lan_ip = preg_replace('/_/', '.', $ip_match[0]);
$registrations[$id]['lan-ip'] = $lan_ip;
}
else {
} else {
$registrations[$id]['lan-ip'] = '';
}
//remove unrelated domains
if (!permission_exists('registration_all') || $this->show != 'all') {
if ($registrations[$id]['sip-auth-realm'] == $this->domain_name) {}
else if ($user_array[1] == $this->domain_name) {}
else {
if ($registrations[$id]['sip-auth-realm'] == $this->domain_name) {
} elseif ($user_array[1] == $this->domain_name) {
} else {
unset($registrations[$id]);
}
}
@@ -260,7 +272,11 @@
}
/**
* get the registration count
* Retrieves the registration count for a given SIP profile.
*
* @param string|null $profile The name of the SIP profile to retrieve. Defaults to 'all'.
*
* @return int The registration count, or 0 if no profiles are found.
*/
public function count($profile = 'all') {
@@ -276,28 +292,47 @@
}
/**
* unregister registrations
* Unregisters a list of registrations from a given SIP profile or all profiles if no profile is specified.
*
* @param array $registrations The list of registrations to unregister, keyed by SIP URI.
*
* @return void This method does not return any value.
*/
public function unregister($registrations) {
$this->switch_api('unregister', $registrations);
}
/**
* provision registrations
* Provision a set of SIP registrations.
*
* @param array $registrations The list of registrations to provision.
*
* @returnvoid This method does not return any value.
*/
public function provision($registrations) {
$this->switch_api('provision', $registrations);
}
/**
* reboot registrations
* Initiates a system reboot with the specified registrations.
*
* @param array $registrations The list of registrations to persist before rebooting.
*
* @return void This method does not return any value.
*/
public function reboot($registrations) {
$this->switch_api('reboot', $registrations);
}
/**
* switch api calls
* Processes API commands for a list of registered devices.
*
* This will cause execution to exit.
*
* @param string $action The action to perform (unregister, provision, reboot).
* @param array $records The list of registered devices.
*
* @return void
*/
private function switch_api($action, $records) {
if (permission_exists($this->permission_prefix . 'domain') || permission_exists($this->permission_prefix . 'all') || if_group('superadmin')) {
@@ -348,8 +383,7 @@
break;
}
}
}
else {
} else {
header('Location: ' . $this->list_page);
exit;
}
@@ -414,8 +448,7 @@
$message .= "<br>\n<strong>" . escape($registration_user) . "</strong>: " . escape($response_message);
}
}
}
else {
} else {
if (!empty($response['command']) && $response['command'] !== '-ERR no reply') {
$message .= "<br>\n<strong>" . escape($registration_user) . "</strong>: " . escape($response_message);
}
@@ -423,8 +456,7 @@
}
message::add($message, 'positive', '7000');
}
}
else {
} else {
message::add($text['error-event-socket'], 'negative', 5000);
}

View File

@@ -35,30 +35,37 @@
/**
* Ring group primary key
*
* @var uuid
*/
public $ring_group_uuid;
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_uuid;
@@ -74,7 +81,12 @@
private $toggle_values;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -94,7 +106,13 @@
}
/**
* delete records
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->permission_prefix . 'delete')) {
@@ -196,6 +214,13 @@
}
}
/**
* Deletes multiple destination records from the database.
*
* @param array $records An array of destination records to delete, where each record contains 'uuid' and 'checked' keys.
*
* @return void
*/
public function delete_destinations($records) {
//assign private variables
@@ -271,7 +296,13 @@
}
/**
* toggle records
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
if (permission_exists($this->permission_prefix . 'edit')) {
@@ -365,7 +396,13 @@
}
/**
* copy records
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
if (permission_exists($this->permission_prefix . 'add')) {

View File

@@ -35,24 +35,30 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_uuid;
@@ -73,7 +79,12 @@
public $sip_profile_uuid;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -94,7 +105,13 @@
}
/**
* delete records
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->permission_prefix . 'delete')) {
@@ -176,8 +193,7 @@
foreach ($sip_profiles as $sip_profile_uuid => $sip_profile) {
if ($sip_profile['hostname'] != '') {
$hostnames[] = $sip_profile['hostname'];
}
else {
} else {
$empty_hostname = true;
}
}
@@ -202,6 +218,13 @@
}
}
/**
* Deletes specified domains from the system.
*
* @param array $records An array of records to be deleted, each containing 'checked' and 'uuid' keys.
*
* @return void
*/
public function delete_domains($records) {
//assign private variables
$this->permission_prefix = 'sip_profile_domain_';
@@ -273,6 +296,14 @@
}
}
/**
* Deletes settings for one or more sip profiles.
*
* @param array $records An associative array containing the records to delete, where each record is an associative array
* with 'uuid' and optionally 'checked' keys. Defaults to an empty array.
*
* @return void
*/
public function delete_settings($records) {
//assign private variables
$this->permission_prefix = 'sip_profile_setting_';
@@ -345,7 +376,13 @@
}
/**
* toggle records
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
if (permission_exists($this->permission_prefix . 'edit')) {
@@ -405,8 +442,7 @@
foreach ($sip_profiles as $sip_profile_uuid => $sip_profile) {
if ($sip_profile['hostname'] != '') {
$hostnames[] = $sip_profile['hostname'];
}
else {
} else {
$empty_hostname = true;
}
}

View File

@@ -88,6 +88,14 @@
}
//sort the array
/**
* Compares two XML elements based on their names and sorts them in a natural order.
*
* @param object $a The first XML element to compare.
* @param object $b The second XML element to compare.
*
* @return int A negative integer, zero, or a positive integer if $a's name is less than, equal to, or greater than $b's name respectively.
*/
function sort_xml($a, $b) {
return strnatcmp($a->name, $b->name);
}

View File

@@ -48,7 +48,12 @@
private $location;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set objects
@@ -64,7 +69,13 @@
}
/**
* delete rows from the database
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->name . '_delete')) {
@@ -110,7 +121,13 @@
}
/**
* toggle a field between two values
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
if (permission_exists($this->name . '_edit')) {
@@ -174,7 +191,13 @@
}
/**
* copy rows from the database
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
if (permission_exists($this->name . '_add')) {

View File

@@ -35,36 +35,46 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Username set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Username set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $username;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_uuid;
/**
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_name;
@@ -80,7 +90,12 @@
private $toggle_values;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -99,7 +114,13 @@
}
/**
* delete records
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->permission_prefix . 'delete')) {
@@ -142,7 +163,13 @@
}
/**
* toggle records
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
if (permission_exists($this->permission_prefix . 'edit')) {
@@ -208,7 +235,13 @@
}
/**
* copy records
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
if (permission_exists($this->permission_prefix . 'add')) {

View File

@@ -27,8 +27,11 @@
class presence {
/**
* active presence
* @var string $presence_id
* Check if presence is active
*
* @param string $presence_id Presence ID to check for activity
*
* @return bool True if presence is active, False otherwise
*/
public function active($presence_id) {
$json = event_socket::api('show calls as json');
@@ -54,7 +57,14 @@
}
/**
* show presence
* Retrieves and processes data from the event socket API.
*
* This method sends a 'show calls as json' request to the event socket API,
* decodes the response, and returns an array containing presence information
* for each user. The array is indexed by the index of the row in the original
* JSON response, with keys for presence_id, presence_user, and domain_name.
*
* @return array An array of arrays containing presence information.
*/
public function show() {
$array = [];

View File

@@ -34,7 +34,9 @@
const app_uuid = 'b63db353-e1c6-4401-8f10-101a6ee73b74';
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
public $domain_uuid;
@@ -46,30 +48,38 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Username set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Username set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $username;
/**
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_name;
@@ -84,7 +94,12 @@
private $streams;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -110,8 +125,7 @@
$ringtone = $ringtone['var_name'];
if (isset($text['label-' . $ringtone])) {
$label = $text['label-' . $ringtone];
}
else {
} else {
$label = $ringtone;
}
$ringtones_list[$ringtone] = $label;
@@ -162,6 +176,13 @@
}
}
/**
* Checks if a given value is valid.
*
* @param mixed $value The value to check for validity
*
* @return bool True if the value is valid, false otherwise
*/
public function valid($value) {
foreach ($this->ringtones_list as $ringtone_value => $ringtone_name) {
if ($value == "\${" . $ringtone_value . "}") {
@@ -201,6 +222,14 @@
return false;
}
/**
* Generates a HTML <select> element based on given name and selected value.
*
* @param string $name The name of the select element
* @param mixed $selected The currently selected value for the select element
*
* @return string A fully formed HTML <select> element with options populated from various lists (music, recordings, streams, ringtones, tones)
*/
public function select($name, $selected) {
//add multi-lingual support
$language = new text;

View File

@@ -32,7 +32,12 @@
private $config;
/**
* Called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set objects
@@ -40,12 +45,20 @@
}
/**
* Corrects the path for specifically for windows
* Converts the given path to a platform-agnostic format.
*
* @param string $path The path to be converted.
*
* @return string The converted path. If running on Windows, backslashes are replaced with forward slashes.
*/
private function correct_path($path) {
global $IS_WINDOWS;
if ($IS_WINDOWS == null) {
if (stristr(PHP_OS, 'WIN')) { $IS_WINDOWS = true; } else { $IS_WINDOWS = false; }
if (stristr(PHP_OS, 'WIN')) {
$IS_WINDOWS = true;
} else {
$IS_WINDOWS = false;
}
}
if ($IS_WINDOWS) {
return str_replace('\\', '/', $path);
@@ -55,31 +68,31 @@
/**
* Copy the switch scripts to the switch directory
*
* The function attempts to find the source and destination directories by checking various system locations. If
* neither is found, it throws an exception.
*
* @return void
*/
public function copy_scripts() {
//get the source directory
if (file_exists('/usr/share/examples/fusionpbx/scripts')) {
$source_directory = '/usr/share/examples/fusionpbx/scripts';
}
elseif (file_exists('/usr/local/www/fusionpbx/app/switch/resources/scripts')) {
} elseif (file_exists('/usr/local/www/fusionpbx/app/switch/resources/scripts')) {
$source_directory = '/usr/local/www/fusionpbx/app/switch/resources/scripts';
}
elseif (file_exists('/var/www/fusionpbx/app/switch/resources/scripts')) {
} elseif (file_exists('/var/www/fusionpbx/app/switch/resources/scripts')) {
$source_directory = '/var/www/fusionpbx/app/switch/resources/scripts';
}
else {
} else {
$source_directory = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/app/switch/resources/scripts';
}
//get the destination directory
if (file_exists($this->config->get('switch.scripts.dir'))) {
$destination_directory = $this->config->get('switch.scripts.dir');
}
elseif (file_exists('/etc/freeswitch/scripts')) {
} elseif (file_exists('/etc/freeswitch/scripts')) {
$destination_directory = '/etc/freeswitch/scripts';
}
elseif (file_exists('/usr/local/freeswitch/scripts')) {
} elseif (file_exists('/usr/local/freeswitch/scripts')) {
$destination_directory = '/usr/local/freeswitch/scripts';
}
@@ -95,8 +108,7 @@
recursive_copy($app_script, $destination_directory);
}
unset($app_scripts);
}
else {
} else {
throw new Exception("Cannot read from '$source_directory' to get the scripts");
}
chmod($destination_directory, 0775);
@@ -104,34 +116,30 @@
}
/**
* Copy the switch languages to the switch directory
*
* @return void
*/
public function copy_languages() {
//get the source directory
if (file_exists('/usr/share/examples/freeswitch/conf/languages')) {
$source_directory = '/usr/share/examples/fusionpbx/conf/languages';
}
elseif (file_exists('/usr/local/www/fusionpbx/app/switch/resources/conf/languages')) {
} elseif (file_exists('/usr/local/www/fusionpbx/app/switch/resources/conf/languages')) {
$source_directory = '/usr/local/www/fusionpbx/app/switch/resources/conf/languages';
}
elseif (file_exists('/var/www/fusionpbx/app/switch/resources/conf/languages')) {
} elseif (file_exists('/var/www/fusionpbx/app/switch/resources/conf/languages')) {
$source_directory = '/var/www/fusionpbx/app/switch/resources/conf/languages';
}
else {
} else {
$source_directory = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/app/switch/resources/conf/languages';
}
//get the destination directory
if (file_exists($this->config->get('switch.conf.dir') . '/languages')) {
$destination_directory = $this->config->get('switch.conf.dir') . '/languages';
}
elseif (file_exists('/etc/freeswitch/languages')) {
} elseif (file_exists('/etc/freeswitch/languages')) {
$destination_directory = '/usr/local/share/freeswitch/languages';
}
elseif (file_exists('/usr/local/freeswitch/conf/languages')) {
} elseif (file_exists('/usr/local/freeswitch/conf/languages')) {
$destination_directory = '/usr/local/freeswitch/conf/languages';
}
@@ -140,8 +148,7 @@
//copy the main languages
recursive_copy($source_directory, $destination_directory);
unset($source_directory);
}
else {
} else {
throw new Exception("Cannot read from '$source_directory' to get the scripts");
}
chmod($destination_directory, 0775);

View File

@@ -95,6 +95,13 @@
}
//define the download function (helps safari play audio sources)
/**
* Downloads a specified range of bytes from the given file.
*
* @param string $file The path to the file to download.
*
* @return void
*/
function range_download($file) {
$fp = @fopen($file, 'rb');
@@ -123,7 +130,7 @@
$c_start = $start;
$c_end = $end;
// Extract the range string
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
[, $range] = explode('=', $_SERVER['HTTP_RANGE'], 2);
// Make sure the client hasn't sent us a multibyte range
if (strpos($range, ',') !== false) {
// (?) Shoud this be issued here, or should the first

View File

@@ -31,6 +31,11 @@
*/
class bsd_system_information extends system_information {
/**
* Returns the number of CPU cores available on the system.
*
* @return int The number of CPU cores.
*/
public function get_cpu_cores(): int {
$result = shell_exec("dmesg | grep -i --max-count 1 CPUs | sed 's/[^0-9]*//g'");
$cpu_cores = trim($result);
@@ -38,6 +43,12 @@ class bsd_system_information extends system_information {
}
//get the CPU details
/**
* Returns the current CPU usage percentage.
*
* @return float The current CPU usage percentage.
*/
public function get_cpu_percent(): float {
$result = shell_exec('ps -A -o pcpu');
$percent_cpu = 0;
@@ -49,10 +60,20 @@ class bsd_system_information extends system_information {
return $percent_cpu;
}
/**
* Returns the system uptime in seconds.
*
* @return string The system uptime in seconds.
*/
public function get_uptime() {
return shell_exec('uptime');
}
/**
* Returns the current CPU usage percentage per core.
*
* @return array An associative array where keys are core indices and values are their respective CPU usage percentages.
*/
public function get_cpu_percent_per_core(): array {
static $last = [];
$results = [];
@@ -94,11 +115,11 @@ class bsd_system_information extends system_information {
}
/**
* Returns the current network speed for a given interface.
*
* @staticvar array $last
* @param string $interface
* @return array
* @depends FreeBSD Version 12
* @param string $interface The network interface to query (default: 'em0')
*
* @return array An array containing the current receive and transmit speeds in bytes per second.
*/
public function get_network_speed(string $interface = 'em0'): array {
static $last = [];

View File

@@ -31,6 +31,13 @@
*/
class linux_system_information extends system_information {
/**
* Returns the number of CPU cores available on the system.
*
* This method executes a shell command to parse the /proc/cpuinfo file and counts the number of processor entries found.
*
* @return int The total number of CPU cores
*/
public function get_cpu_cores(): int {
$result = @trim(shell_exec("grep -P '^processor' /proc/cpuinfo"));
$cpu_cores = count(explode("\n", $result));
@@ -38,6 +45,16 @@ class linux_system_information extends system_information {
}
//get the CPU details
/**
* Returns the current CPU usage as a percentage.
*
* This method reads the CPU statistics from /proc/stat and calculates
* the CPU usage by comparing the total and idle time of each core.
* The result is rounded to two decimal places.
*
* @return float The current CPU usage in percent.
*/
public function get_cpu_percent(): float {
$stat1 = file_get_contents('/proc/stat');
usleep(500000);
@@ -73,10 +90,27 @@ class linux_system_information extends system_information {
return round($percent_cpu / $core_count, 2);
}
/**
* Returns the current system uptime as reported by the 'uptime' command.
*
* This method executes the 'uptime' command and returns its output.
*
* @return string The current system uptime.
*/
public function get_uptime() {
return shell_exec('uptime');
}
/**
* Returns the current CPU usage as a percentage per core.
*
* This method reads the CPU statistics from /proc/stat and calculates
* the CPU usage by comparing the total and idle time of each core.
* The result is rounded to two decimal places.
*
* @return array An array where the keys are the core numbers (starting at 0)
* and the values are the current CPU usage for each core in percent.
*/
public function get_cpu_percent_per_core(): array {
static $last = [];
@@ -107,6 +141,16 @@ class linux_system_information extends system_information {
return $results;
}
/**
* Returns the current network speed for the specified interface.
*
* This method reads the network statistics from /proc/net/dev and calculates
* the network speed by comparing the received and transmitted bytes between two measurements.
*
* @param string $interface The network interface to read stats from. Defaults to 'eth0'.
*
* @return array An array containing the current receive (rx_bps) and transmit (tx_bps) speeds in bits per second.
*/
public function get_network_speed(string $interface = 'eth0'): array {
static $last = [];

View File

@@ -35,7 +35,9 @@ class session {
/**
* Removes old php session files. Called by the maintenance application.
*
* @param settings $settings A settings object
*
* @return void
*/
public static function filesystem_maintenance(settings $settings): void {

View File

@@ -38,6 +38,11 @@ class system_dashboard_service extends base_websocket_system_service {
private $network_status_refresh_interval;
private $network_interface;
/**
* Reloads settings from database, config file and websocket server.
*
* @return void
*/
protected function reload_settings(): void {
static::set_system_information();
@@ -64,8 +69,12 @@ class system_dashboard_service extends base_websocket_system_service {
}
/**
* Executes once
* @return void
* Registers topics for broadcasting system information.
*
* This method is responsible for setting up the system information object,
* registering callback functions for cpu and network status requests, and
* configuring timer callbacks to refresh these statuses at regular intervals.
* It is only called once during initial startup.
*/
protected function register_topics(): void {
@@ -90,6 +99,17 @@ class system_dashboard_service extends base_websocket_system_service {
$this->info("Broadcasting Network Status every {$this->network_status_refresh_interval}s");
}
/**
* Handles the network status request.
*
* This method retrieves the current network interface and speeds, constructs a response message,
* logs the request for debugging purposes, and attempts to send the broadcast. If the Websocket server
* is disconnected, it waits until reconnection before attempting to send again.
*
* @param string|null $message The original message that triggered this response (optional).
*
* @return int The refresh interval for network status in seconds.
*/
public function on_network_status($message = null): int {
// Get RX (receive) and TX (transmit) bps
$network_rates = self::$system_information->get_network_speed($this->network_interface);
@@ -134,6 +154,15 @@ class system_dashboard_service extends base_websocket_system_service {
return $this->network_status_refresh_interval;
}
/**
* Handles the selection of a network interface from a message.
*
* This method checks if the message is an instance of WebSocketMessage and if it contains
* a 'network_interface' payload. If both conditions are true, it sets the network interface
* property to the value of the payload.
*
* @param websocket_message|null $message The message containing the selected network interface.
*/
public function on_network_interface_select($message = null): void {
if ($message !== null && $message instanceof websocket_message) {
$payload = $message->payload();
@@ -143,6 +172,17 @@ class system_dashboard_service extends base_websocket_system_service {
}
}
/**
* Handles cpu status requests.
*
* This method is called to respond to incoming requests for the current CPU usage,
* both total and per-core. It prepares a response message with the requested data
* and sends it to all connected clients.
*
* @param null|websocket_message $message The request message, if responding to a specific request.
*
* @return int The interval at which this method should be called again to refresh the cpu status.
*/
public function on_cpu_status($message = null): int {
// Get total and per-core CPU usage
$cpu_percent_total = self::$system_information->get_cpu_percent();
@@ -192,10 +232,27 @@ class system_dashboard_service extends base_websocket_system_service {
return $this->cpu_status_refresh_interval;
}
/**
* Returns the service name for system information.
*
* This method provides a unique identifier for the dashboard system information service.
*
* @return string The service name as a string, in this case "dashboard.system.information".
*/
public static function get_service_name(): string {
return "dashboard.system.information";
}
/**
* Creates a filter chain for broadcasting system information.
*
* This method generates a filter based on the subscriber's permissions,
* allowing them to receive only relevant system view information.
*
* @param subscriber $subscriber The subscriber object with permission data.
*
* @return ?filter A filter chain that matches the subscriber's permissions, or null if no match is found.
*/
public static function create_filter_chain_for(subscriber $subscriber): ?filter {
// Get the subscriber permissions
$permissions = $subscriber->get_permissions();
@@ -216,6 +273,15 @@ class system_dashboard_service extends base_websocket_system_service {
return $filter;
}
/**
* Sets the system information object.
*
* This method creates a new instance of `SystemInformation` and stores it in
* the class's static property `$system_information`. It is typically called once
* during initial startup to establish the system information source.
*
* @return void
*/
public static function set_system_information(): void {
self::$system_information = system_information::new();
}

View File

@@ -37,10 +37,20 @@ abstract class system_information {
abstract public function get_cpu_percent_per_core(): array;
abstract public function get_network_speed(string $interface = 'eth0'): array;
/**
* Returns the system load average.
*
* @return array Three most recent one-minute load averages.
*/
public function get_load_average() {
return sys_getloadavg();
}
/**
* Returns a system information object based on the underlying operating system.
*
* @return ?system_information The system information object for the current OS, or null if not supported.
*/
public static function new(): ?system_information {
if (stristr(PHP_OS, 'BSD')) {
return new bsd_system_information();

View File

@@ -38,6 +38,13 @@
//function to parse a FusionPBX service from a .service file
if (!function_exists('get_classname')) {
/**
* Retrieves the name of a PHP class from an ExecStart directive in a service file.
*
* @param string $file Path to the service file.
*
* @return string The name of the PHP class, or empty string if not found.
*/
function get_classname(string $file) {
if (!file_exists($file)) {
return '';
@@ -55,6 +62,14 @@
//function to check for running process: returns [running, pid, etime]
if (!function_exists('is_running')) {
/**
* Checks if a process with the given name is currently running.
*
* @param string $name The name of the process to check for.
*
* @return array An array containing information about the process's status,
* including whether it's running, its PID, and how long it's been running.
*/
function is_running(string $name) {
$name = escapeshellarg($name);
$pid = trim(shell_exec("ps -aux | grep $name | grep -v grep | awk '{print \$2}' | head -n 1") ?? '');
@@ -68,6 +83,21 @@
//function to format etime into friendly display
if (!function_exists('format_etime')) {
/**
* Formats a time duration string into a human-readable format.
*
* The input string can be in one of the following formats:
* - dd-hh:mm:ss
* - hh:mm:ss
* - mm:ss
* - seconds (no units)
*
* If the input string is empty or invalid, an empty string will be returned.
*
* @param string $etime Time duration string to format.
*
* @return string Formatted time duration string in human-readable format.
*/
function format_etime($etime) {
// Format: [[dd-]hh:]mm:ss
if (empty($etime)) return '-';

View File

@@ -83,6 +83,14 @@
//
//system information
/**
* Retrieves system information.
*
* @return array An array containing various system information such as PHP and switch versions,
* git repository details, operating system name, version, uptime, kernel, and type,
* memory usage, CPU usage, and disk space. The keys of the returned array are
* 'version', 'git', 'path', 'switch', 'php', 'os', 'mem', and 'cpu'.
*/
function system_information(): array {
global $database, $db_type;
$system_information = [];

View File

@@ -35,36 +35,46 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Username set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Username set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $username;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_uuid;
/**
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_name;
@@ -80,6 +90,14 @@
private $toggle_values;
private $dialplan_global;
/**
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
$this->domain_uuid = $setting_array['domain_uuid'] ?? $_SESSION['domain_uuid'] ?? '';
@@ -100,7 +118,13 @@
}
/**
* delete records
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->permission_prefix . 'delete')) {
@@ -178,7 +202,13 @@
}
/**
* toggle records
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
if (permission_exists($this->permission_prefix . 'edit')) {
@@ -266,7 +296,13 @@
}
/**
* copy records
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
if (permission_exists($this->permission_prefix . 'add')) {
@@ -391,5 +427,4 @@
}
} //method
} //class

View File

@@ -990,6 +990,13 @@ echo " ".$text['description-extension']."<br />\n";
echo "</td>\n";
echo "</tr>\n";
/**
* Adds a custom condition to the given group.
*
* @param object $destination The destination object being processed.
* @param int $group_id The ID of the group to which the condition is being added.
* @param string $dialplan_action The dialplan action for the group (optional).
*/
function add_custom_condition($destination, $group_id, $dialplan_action = '') {
global $text, $v_link_label_add;
echo "<tr>\n";

View File

@@ -46,7 +46,12 @@
private $toggle_values;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set objects
@@ -62,7 +67,13 @@
}
/**
* delete records
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->permission_prefix.'delete')) {
@@ -111,7 +122,13 @@
}
/**
* toggle records
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function toggle($records) {
if (permission_exists($this->permission_prefix.'edit')) {
@@ -181,7 +198,13 @@
}
/**
* copy records
* Copies one or more records
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function copy($records) {
if (permission_exists($this->permission_prefix.'add')) {

View File

@@ -105,8 +105,8 @@
$param = $search ? "&search=".$search : null;
$param = $order_by ? "&order_by=".$order_by."&order=".$order : null;
$page = empty($_GET['page']) ? $page = 0 : $page = $_GET['page'];
list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
[$paging_controls, $rows_per_page] = paging($num_rows, $param, $rows_per_page);
[$paging_controls_mini, $rows_per_page] = paging($num_rows, $param, $rows_per_page, true);
$offset = $rows_per_page * $page;
//get the list
@@ -191,6 +191,13 @@
echo "<div class='card'>\n";
echo "<table class='list'>\n";
/**
* Writes the header for a list of variables.
*
* @param string $modifier The modifier to be used in the header, with slashes and extra spaces removed.
*
* @return void
*/
function write_header($modifier) {
global $text, $order_by, $order, $vars, $list_row_edit_button;
$modifier = str_replace('/', '', $modifier);

View File

@@ -35,30 +35,38 @@
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
*
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $user_uuid;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_uuid;
/**
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
private $domain_name;
@@ -77,7 +85,12 @@
public $voicemail_id;
/**
* called when the object is created
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
@@ -93,8 +106,7 @@
$this->permission_prefix = 'voicemail_greeting_';
if (is_numeric($this->voicemail_id)) {
$this->list_page = 'voicemail_greetings.php?id=' . urlencode($this->voicemail_id) . '&back=' . urlencode(PROJECT_PATH . '/app/voicemail/voicemails.php');
}
else {
} else {
$this->list_page = PROJECT_PATH . '/app/voicemails/voicemails.php';
}
$this->table = 'voicemail_greetings';
@@ -102,7 +114,13 @@
}
/**
* delete records
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function delete($records) {
if (permission_exists($this->permission_prefix . 'delete')) {

View File

@@ -62,6 +62,13 @@
}
//used (above) to search the array to determine if an extension is assigned to the user
/**
* Checks if the given extension number is assigned to the user.
*
* @param string $number The extension number to check.
*
* @return bool True if the extension number is assigned, False otherwise.
*/
function extension_assigned($number) {
foreach ($_SESSION['user']['extension'] as $row) {
if ((is_numeric($row['number_alias']) && $row['number_alias'] == $number) || $row['user'] == $number) {
@@ -506,6 +513,11 @@
require_once "resources/footer.php";
//define the download function (helps safari play audio sources)
/**
* Handles a range download request for the given file.
*
* @param string $file The path to the file being downloaded.
*/
function range_download($file) {
$fp = @fopen($file, 'rb');
@@ -534,7 +546,7 @@
$c_start = $start;
$c_end = $end;
// Extract the range string
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
[, $range] = explode('=', $_SERVER['HTTP_RANGE'], 2);
// Make sure the client hasn't sent us a multibyte range
if (strpos($range, ',') !== false) {
// (?) Shoud this be issued here, or should the first

View File

@@ -34,19 +34,25 @@
const app_uuid = 'b523c2d2-64cd-46f1-9520-ca4b4098e044';
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
public $domain_uuid;
/**
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
* in the session global array
*
* @var string
*/
public $domain_name;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
public $user_uuid;
@@ -64,18 +70,22 @@
/**
* Internal array structure that is populated from the database
*
* @var settings A settings object loaded from Default Settings
*/
private $settings;
/**
* Set in the constructor. Must be a database object and cannot be null.
*
* @var database Database Object
*/
private $database;
/**
* Username set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* Username set in the constructor. This can be passed in through the $settings_array associative array or set in
* the session global array
*
* @var string
*/
private $username;
@@ -90,6 +100,14 @@
private $toggle_field;
private $toggle_values;
/**
* Initializes the object with setting array.
*
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
* an empty array.
*
* @return void
*/
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
$this->domain_uuid = $setting_array['domain_uuid'] ?? $_SESSION['domain_uuid'] ?? '';
@@ -111,6 +129,11 @@
}
/**
* retrieves the voicemail id
*
* @return int|null the voicemail id if it exists, otherwise null
*/
public function get_voicemail_id() {
//check if for valid input
@@ -133,6 +156,11 @@
}
}
/**
* retrieves the list of assigned voicemails
*
* @return array|false list of assigned voicemail boxes
*/
public function voicemails() {
//check if for valid input
@@ -166,7 +194,9 @@
$sql = "select * from v_voicemails ";
$sql .= "where voicemail_id in (";
foreach ($voicemail_ids as $i => $voicemail_id) {
if ($i > 0) { $sql .= ","; }
if ($i > 0) {
$sql .= ",";
}
$sql .= ":voicemail_id_" . $i;
$parameters['voicemail_id_' . $i] = $voicemail_id;
}
@@ -195,8 +225,7 @@
//view specific voicemail box usually reserved for an admin or superadmin
$sql .= "and voicemail_uuid = :voicemail_uuid ";
$parameters['voicemail_uuid'] = $this->voicemail_uuid;
}
else {
} else {
//ensure that the requested voicemail box is assigned to this user
$found = false;
foreach ($voicemail_uuids as $row) {
@@ -211,16 +240,14 @@
$sql .= "and voicemail_uuid is null ";
}
}
}
else {
} else {
if (!empty($voicemail_ids) && @sizeof($voicemail_ids) != 0) {
//show only the assigned voicemail ids
$sql .= "and ";
if (is_numeric($this->voicemail_id) && in_array($this->voicemail_id, $voicemail_ids)) {
$sql_where = 'voicemail_id = :voicemail_id ';
$parameters['voicemail_id'] = $this->voicemail_id;
}
else {
} else {
$x = 0;
$sql_where = '';
foreach ($voicemail_ids as $voicemail_id) {
@@ -232,8 +259,7 @@
}
$sql .= $sql_where;
unset($sql_where_or);
}
else {
} else {
//no assigned voicemail ids so return no results
$sql .= "and voicemail_uuid is null ";
}
@@ -245,6 +271,11 @@
return $result;
}
/**
* retrieve all voicemail messages for a given list of voicemails
*
* @return array|false an array containing voicemail message data, keyed by voicemail id
*/
public function messages() {
//get the voicemails
@@ -264,6 +295,15 @@
return $voicemails;
}
/**
* Retrieve voicemail messages.
*
* @param int|string|array $voicemail_id if not array, then will be used as the primary filter for voicemails,
* if array and contains at least one id, then used for filtering
* to retrieve multiple voicemail records with specified ids
*
* @return array list of voicemail messages with additional information such as file path, size and length
*/
private function voicemail_messages($voicemail_id): array {
//check if for valid input
@@ -292,15 +332,13 @@
$sql .= implode(' or ', $sql_where_or);
$sql .= ") ";
unset($sql_where_or);
}
else {
} else {
$sql .= "and v.voicemail_id = :voicemail_id ";
$parameters['voicemail_id'] = $voicemail_id;
}
if (empty($this->order_by)) {
$sql .= "order by v.voicemail_id, m.created_epoch desc ";
}
else {
} else {
$sql .= "order by v.voicemail_id, m." . $this->order_by . " " . $this->order . " ";
}
//if paging offset defined, apply it along with rows per page
@@ -336,13 +374,21 @@
$result[$i]['message_length_label'] = ($message_minutes > 0 ? $message_minutes . ' min' : '') . ($message_seconds > 0 ? ' ' . $message_seconds . ' s' : '');
$result[$i]['created_date'] = date("j M Y g:i a", $row['created_epoch']);
}
}
else {
} else {
$result = [];
}
return $result;
}
/**
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function voicemail_delete($records) {
if (permission_exists($this->permission_prefix . 'delete')) {
@@ -456,6 +502,15 @@
}
}
/**
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function voicemail_options_delete($records) {
//assign private variables
$this->permission_prefix = 'voicemail_option_';
@@ -501,6 +556,15 @@
}
}
/**
* Deletes one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function voicemail_destinations_delete($records) {
//assign private variables
$this->list_page = 'voicemail_edit.php?id=' . $this->voicemail_uuid;
@@ -552,6 +616,15 @@
}
}
/**
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function voicemail_toggle($records) {
if (permission_exists($this->permission_prefix . 'edit')) {
@@ -633,6 +706,11 @@
}
}
/**
* Return the count of messages for a given voicemail and domain
*
* @return int|false|null The message count or null if invalid input is provided
*/
public function message_count() {
//check if for valid input
@@ -647,10 +725,13 @@
$parameters['domain_uuid'] = $this->domain_uuid;
$parameters['voicemail_uuid'] = $this->voicemail_uuid;
return $this->database->select($sql, $parameters, 'column');
unset($sql, $parameters);
}
/**
* Send the message waiting status using the switch api command
*
* @return void
*/
public function message_waiting() {
//get the voicemail id
$this->get_voicemail_id();
@@ -664,6 +745,13 @@
}
}
/**
* deletes a voicemail message
*
* Object properties voicemail_id, voicemail_uuid, domain_uuid, voicemail_message_uuid must be set.
*
* @return bool True if successful, False otherwise
*/
public function message_delete() {
//get the voicemail id
@@ -690,8 +778,7 @@
foreach (glob($file_path . "/msg_" . $this->voicemail_message_uuid . ".*") as $file_name) {
unlink($file_name);
}
}
else {
} else {
foreach (glob($file_path . "/msg_*.*") as $file_name) {
unlink($file_name); //remove all recordings
}
@@ -717,8 +804,19 @@
//check the message waiting status
$this->message_waiting();
return true;
}
/**
* Toggles the state of one or more records.
*
* @param array $records An array of record IDs to delete, where each ID is an associative array
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
* whether the corresponding checkbox was checked for deletion.
*
* @return void No return value; this method modifies the database state and sets a message.
*/
public function message_toggle() {
//check if for valid input
@@ -755,6 +853,11 @@
$this->message_waiting();
}
/**
* Resend a voicemail message
*
* @return boolean true if the voicemail message was resent successfully, false otherwise.
*/
public function message_resend() {
//check if for valid input
@@ -839,8 +942,7 @@
$template['template_subject'] = str_replace('${voicemail_description}', $message['voicemail_description'], $template['template_subject']);
$template['template_subject'] = str_replace('${voicemail_name_formatted}', $voicemail_name_formatted, $template['template_subject']);
$template['template_subject'] = str_replace('${domain_name}', $message['domain_name'], $template['template_subject']);
}
else {
} else {
$template['template_subject'] = $text['label-voicemail_from'] . ' ' . $message['caller_id_name'] . ' <' . $message['caller_id_number'] . '> 0' . gmdate("G:i:s", ($message['message_length'] ?? 0));
}
@@ -872,10 +974,13 @@
}
rename($voicemail_message_path . '/msg_' . $message['voicemail_message_uuid'] . '.ext', $voicemail_message_path . '/msg_' . $message['voicemail_message_uuid'] . '.' . $voicemail_message_file_ext);
$voicemail_message_file = 'msg_' . $message['voicemail_message_uuid'] . '.' . $voicemail_message_file_ext;
} else {
if (file_exists($voicemail_message_path . '/msg_' . $message['voicemail_message_uuid'] . '.wav')) {
$voicemail_message_file_ext = 'wav';
}
if (file_exists($voicemail_message_path . '/msg_' . $message['voicemail_message_uuid'] . '.mp3')) {
$voicemail_message_file_ext = 'mp3';
}
else {
if (file_exists($voicemail_message_path.'/msg_'.$message['voicemail_message_uuid'].'.wav')) { $voicemail_message_file_ext = 'wav'; }
if (file_exists($voicemail_message_path.'/msg_'.$message['voicemail_message_uuid'].'.mp3')) { $voicemail_message_file_ext = 'mp3'; }
$voicemail_message_file = 'msg_' . $message['voicemail_message_uuid'] . '.' . $voicemail_message_file_ext;
$voicemail_message_file_mime = mime_content_type($voicemail_message_path . '/msg_' . $message['voicemail_message_uuid'] . '.' . $voicemail_message_file_ext);
}
@@ -889,8 +994,7 @@
$voicemail_intro_decoded = base64_decode($message['message_intro_base64']);
file_put_contents($voicemail_message_path . '/intro_' . $message['voicemail_message_uuid'] . '.' . $voicemail_message_file_ext, $voicemail_intro_decoded);
$voicemail_intro_file = 'intro_' . $message['voicemail_message_uuid'] . '.' . $voicemail_message_file_ext;
}
else {
} else {
$voicemail_intro_file = 'intro_' . $message['voicemail_message_uuid'] . '.' . $voicemail_message_file_ext;
}
@@ -921,16 +1025,13 @@
if (!empty($message['voicemail_file'])) {
if ($message['voicemail_file'] == 'attach' && (file_exists($voicemail_message_path . '/' . $voicemail_combined_file) || file_exists($voicemail_message_path . '/' . $voicemail_message_file))) {
$template['template_body'] = str_replace('${message}', $text['label-attached'], $template['template_body']);
}
else if ($message['voicemail_file'] == 'link') {
} elseif ($message['voicemail_file'] == 'link') {
$template['template_body'] = str_replace('${message}', "<a href='https://" . $message['domain_name'] . PROJECT_PATH . '/app/voicemails/voicemail_messages.php?action=download&id=' . $message['voicemail_id'] . '&voicemail_uuid=' . $message['voicemail_uuid'] . '&uuid=' . $message['voicemail_message_uuid'] . "&t=bin'>" . $text['label-download'] . "</a>", $template['template_body']);
}
else { // listen
} else { // listen
$template['template_body'] = str_replace('${message}', "<a href='https://" . $message['domain_name'] . PROJECT_PATH . '/app/voicemails/voicemail_messages.php?action=autoplay&id=' . $message['voicemail_uuid'] . '&uuid=' . $message['voicemail_message_uuid'] . '&vm=' . $message['voicemail_id'] . "'>" . $text['label-listen'] . "</a>", $template['template_body']);
}
}
}
else {
} else {
$template['template_body'] = "<html>\n<body>\n";
if (!empty($message['caller_id_name']) && $message['caller_id_name'] != $message['caller_id_number']) {
$template['template_body'] .= $message['caller_id_name'] . "<br>\n";
@@ -940,11 +1041,9 @@
if (!empty($message['voicemail_file'])) {
if ($message['voicemail_file'] == 'attach' && (file_exists($voicemail_message_path . '/' . $voicemail_combined_file) || file_exists($voicemail_message_path . '/' . $voicemail_message_file))) {
$template['template_body'] .= "<br>\n" . $text['label-attached'];
}
else if ($message['voicemail_file'] == 'link') {
} elseif ($message['voicemail_file'] == 'link') {
$template['template_body'] .= "<br>\n<a href='https://" . $message['domain_name'] . PROJECT_PATH . '/app/voicemails/voicemail_messages.php?action=download&id=' . $message['voicemail_id'] . '&voicemail_uuid=' . $message['voicemail_uuid'] . '&uuid=' . $message['voicemail_message_uuid'] . "&t=bin'>" . $text['label-download'] . '</a>';
}
else { // listen
} else { // listen
$template['template_body'] .= "<br>\n<a href='https://" . $message['domain_name'] . PROJECT_PATH . '/app/voicemails/voicemail_messages.php?action=autoplay&id=' . $message['voicemail_uuid'] . '&uuid=' . $message['voicemail_message_uuid'] . '&vm=' . $message['voicemail_id'] . "'>" . $text['label-listen'] . '</a>';
}
}
@@ -1001,8 +1100,14 @@
@unlink($voicemail_message_path . '/' . $voicemail_combined_file);
}
return true;
}
/**
* Transcribes a voicemail message
*
* @return bool True if transcription was successful, false otherwise
*/
public function message_transcribe() {
//get the voicemail id
@@ -1059,10 +1164,13 @@
unset($voicemail_message_decoded, $voicemail_message_file_mime);
rename($voicemail_message_path . '/msg_' . $this->voicemail_message_uuid . '.ext', $voicemail_message_path . '/msg_' . $this->voicemail_message_uuid . '.' . $voicemail_message_file_ext);
$voicemail_message_file = 'msg_' . $this->voicemail_message_uuid . '.' . $voicemail_message_file_ext;
} else {
if (file_exists($voicemail_message_path . '/msg_' . $this->voicemail_message_uuid . '.wav')) {
$voicemail_message_file_ext = 'wav';
}
if (file_exists($voicemail_message_path . '/msg_' . $this->voicemail_message_uuid . '.mp3')) {
$voicemail_message_file_ext = 'mp3';
}
else {
if (file_exists($voicemail_message_path.'/msg_'.$this->voicemail_message_uuid.'.wav')) { $voicemail_message_file_ext = 'wav'; }
if (file_exists($voicemail_message_path.'/msg_'.$this->voicemail_message_uuid.'.mp3')) { $voicemail_message_file_ext = 'mp3'; }
$voicemail_message_file = 'msg_' . $this->voicemail_message_uuid . '.' . $voicemail_message_file_ext;
}
unset($voicemail_message_file_ext);
@@ -1106,8 +1214,14 @@
}
return false;
}
/**
* Update message status to 'saved' in database.
*
* @return bool true if update is successful, false otherwise.
*/
public function message_saved() {
//check if for valid input
@@ -1139,7 +1253,9 @@
/**
* download the voicemail message intro
* @param string domain_name if domain name is not passed, then will be used from the session variable (if available) to generate the voicemail file path
*
* @param string domain_name if domain name is not passed, then will be used from the session variable (if
* available) to generate the voicemail file path
*/
public function message_intro_download(string $domain_name = '') {
@@ -1189,11 +1305,9 @@
//prepare and stream the file
if (file_exists($path . '/intro_' . $this->voicemail_message_uuid . '.wav')) {
$file_path = $path . '/intro_' . $this->voicemail_message_uuid . '.wav';
}
else if (file_exists($path.'/intro_'.$this->voicemail_message_uuid.'.mp3')) {
} elseif (file_exists($path . '/intro_' . $this->voicemail_message_uuid . '.mp3')) {
$file_path = $path . '/intro_' . $this->voicemail_message_uuid . '.mp3';
}
else {
} else {
return false;
}
@@ -1209,17 +1323,28 @@
header("Content-Description: File Transfer");
$file_ext = pathinfo($file_path, PATHINFO_EXTENSION);
switch ($file_ext) {
case "wav": header('Content-Disposition: attachment; filename="intro_'.$this->voicemail_message_uuid.'.wav"'); break;
case "mp3": header('Content-Disposition: attachment; filename="intro_'.$this->voicemail_message_uuid.'.mp3"'); break;
case "ogg": header('Content-Disposition: attachment; filename="intro_'.$this->voicemail_message_uuid.'.ogg"'); break;
case "wav":
header('Content-Disposition: attachment; filename="intro_' . $this->voicemail_message_uuid . '.wav"');
break;
case "mp3":
header('Content-Disposition: attachment; filename="intro_' . $this->voicemail_message_uuid . '.mp3"');
break;
case "ogg":
header('Content-Disposition: attachment; filename="intro_' . $this->voicemail_message_uuid . '.ogg"');
break;
}
}
else {
} else {
$file_ext = pathinfo($file_path, PATHINFO_EXTENSION);
switch ($file_ext) {
case "wav": header("Content-Type: audio/x-wav"); break;
case "mp3": header("Content-Type: audio/mpeg"); break;
case "ogg": header("Content-Type: audio/ogg"); break;
case "wav":
header("Content-Type: audio/x-wav");
break;
case "mp3":
header("Content-Type: audio/mpeg");
break;
case "ogg":
header("Content-Type: audio/ogg");
break;
}
}
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
@@ -1245,7 +1370,9 @@
/**
* download the voicemail message
* @param string domain_name if domain name is not passed, then will be used from the session variable (if available) to generate the voicemail file path
*
* @param string domain_name if domain name is not passed, then will be used from the session variable (if
* available) to generate the voicemail file path
*/
public function message_download(string $domain_name = '') {
@@ -1295,11 +1422,9 @@
//prepare and stream the file
if (file_exists($path . '/msg_' . $this->voicemail_message_uuid . '.wav')) {
$file_path = $path . '/msg_' . $this->voicemail_message_uuid . '.wav';
}
else if (file_exists($path.'/msg_'.$this->voicemail_message_uuid.'.mp3')) {
} elseif (file_exists($path . '/msg_' . $this->voicemail_message_uuid . '.mp3')) {
$file_path = $path . '/msg_' . $this->voicemail_message_uuid . '.mp3';
}
else {
} else {
return false;
}
@@ -1315,17 +1440,28 @@
header("Content-Description: File Transfer");
$file_ext = pathinfo($file_path, PATHINFO_EXTENSION);
switch ($file_ext) {
case "wav": header('Content-Disposition: attachment; filename="msg_'.$this->voicemail_message_uuid.'.wav"'); break;
case "mp3": header('Content-Disposition: attachment; filename="msg_'.$this->voicemail_message_uuid.'.mp3"'); break;
case "ogg": header('Content-Disposition: attachment; filename="msg_'.$this->voicemail_message_uuid.'.ogg"'); break;
case "wav":
header('Content-Disposition: attachment; filename="msg_' . $this->voicemail_message_uuid . '.wav"');
break;
case "mp3":
header('Content-Disposition: attachment; filename="msg_' . $this->voicemail_message_uuid . '.mp3"');
break;
case "ogg":
header('Content-Disposition: attachment; filename="msg_' . $this->voicemail_message_uuid . '.ogg"');
break;
}
}
else {
} else {
$file_ext = pathinfo($file_path, PATHINFO_EXTENSION);
switch ($file_ext) {
case "wav": header("Content-Type: audio/x-wav"); break;
case "mp3": header("Content-Type: audio/mpeg"); break;
case "ogg": header("Content-Type: audio/ogg"); break;
case "wav":
header("Content-Type: audio/x-wav");
break;
case "mp3":
header("Content-Type: audio/mpeg");
break;
case "ogg":
header("Content-Type: audio/ogg");
break;
}
}
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
@@ -1352,6 +1488,11 @@
/*
* range download method (helps safari play audio sources)
*/
/**
* Downloads the specified file in range mode.
*
* @param string $file The path to the file to be downloaded.
*/
private function range_download($file) {
$esl = @fopen($file, 'rb');
@@ -1380,7 +1521,7 @@
$c_start = $start;
$c_end = $end;
// Extract the range string
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
[, $range] = explode('=', $_SERVER['HTTP_RANGE'], 2);
// Make sure the client hasn't sent us a multibyte range
if (strpos($range, ',') !== false) {
// (?) Shoud this be issued here, or should the first
@@ -1397,8 +1538,7 @@
if (!empty($range0) && $range0 == '-') {
// The n-number of the last bytes is requested
$c_start = $size - substr($range, 1);
}
else {
} else {
$range = explode('-', $range);
$c_start = $range[0];
$c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;
@@ -1444,7 +1584,9 @@
/**
* Removes old entries for in the database voicemails table
* see {@link https://github.com/fusionpbx/fusionpbx-app-maintenance/} FusionPBX Maintenance App
*
* @param settings $settings Settings object
*
* @return void
*/
public static function database_maintenance(settings $settings): void {
@@ -1482,7 +1624,10 @@
/**
* Called by the maintenance system to remove old files
*
* @param settings $settings Settings object
*
* @return void
*/
public static function filesystem_maintenance(settings $settings): void {
//get a list of domains
@@ -1524,8 +1669,7 @@
}
}
}
}
else {
} else {
//log retention days not valid
maintenance_service::log_write(self::class, "Retention days not set or not a valid number", $domain_uuid, maintenance_service::LOG_ERROR);
}

View File

@@ -61,6 +61,13 @@
$available_columns[] = 'voicemail_tutorial';
//define the functions
/**
* Converts a 2D array into a CSV string.
*
* @param array &$array The input array to convert. Each inner array represents a row in the CSV output.
*
* @return string|null The CSV data as a string, or null if the input array is empty.
*/
function array2csv(array &$array) {
if (count($array) == 0) {
return null;
@@ -75,6 +82,13 @@
return ob_get_clean();
}
/**
* Sends HTTP headers to initiate a file download.
*
* @param string $filename The name of the file to be downloaded.
*
* @return void
*/
function download_send_headers($filename) {
// disable caching
$now = gmdate("D, d M Y H:i:s");

View File

@@ -38,18 +38,6 @@
$language = new text;
$text = $language->get();
//built in str_getcsv requires PHP 5.3 or higher, this function can be used to reproduct the functionality but requirs PHP 5.1.0 or higher
if (!function_exists('str_getcsv')) {
function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") {
$fp = fopen("php://memory", 'r+');
fputs($fp, $input);
rewind($fp);
$data = fgetcsv($fp, null, $delimiter, $enclosure); // $escape only got added in 5.3.0
fclose($fp);
return $data;
}
}
//set the max php execution time
ini_set('max_execution_time', 7200);
@@ -230,6 +218,14 @@
}
//get the parent table
/**
* Retrieves the parent table for a given table name from a schema.
*
* @param array $schema A multidimensional array representing the schema of tables.
* @param string $table_name The name of the table to retrieve the parent for.
*
* @return string|null The name of the parent table, or null if not found in the schema.
*/
function get_parent($schema, $table_name) {
foreach ($schema as $row) {
if ($row['table'] == $table_name) {

Some files were not shown because too many files have changed in this diff Show More