2012-06-04 16:58:40 +02:00
|
|
|
<?php
|
|
|
|
|
/*
|
|
|
|
|
FusionPBX
|
|
|
|
|
Version: MPL 1.1
|
|
|
|
|
|
|
|
|
|
The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
|
1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
http://www.mozilla.org/MPL/
|
|
|
|
|
|
|
|
|
|
Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
|
for the specific language governing rights and limitations under the
|
|
|
|
|
License.
|
|
|
|
|
|
|
|
|
|
The Original Code is FusionPBX
|
|
|
|
|
|
|
|
|
|
The Initial Developer of the Original Code is
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
2023-06-04 03:50:54 +02:00
|
|
|
Portions created by the Initial Developer are Copyright (C) 2008-2023
|
2012-06-04 16:58:40 +02:00
|
|
|
the Initial Developer. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
Contributor(s):
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
|
|
|
|
*/
|
|
|
|
|
|
2017-02-08 21:29:48 +01:00
|
|
|
//if the recordings directory doesn't exist then create it
|
2025-03-14 23:19:49 +01:00
|
|
|
if (!empty($settings->get('switch','recordings')) && !empty($domain_name)) {
|
|
|
|
|
if (!is_readable($settings->get('switch','recordings')."/".$domain_name)) {
|
|
|
|
|
mkdir($settings->get('switch','recordings')."/".$domain_name."/archive", 0770, true);
|
2021-12-03 03:03:55 +01:00
|
|
|
}
|
2017-02-08 21:29:48 +01:00
|
|
|
}
|
2015-04-25 23:46:01 +02:00
|
|
|
|
2017-02-08 21:29:48 +01:00
|
|
|
//process one time
|
|
|
|
|
if ($domains_processed == 1) {
|
2017-01-10 07:48:15 +01:00
|
|
|
|
2017-02-08 21:29:48 +01:00
|
|
|
//if base64, populate from existing recording files, then remove
|
2025-03-14 23:19:49 +01:00
|
|
|
if (!empty($settings->get('recordings','storage_type')) && $settings->get('recordings','storage_type') == 'base64') {
|
2017-02-08 21:29:48 +01:00
|
|
|
//get recordings without base64 in db
|
|
|
|
|
$sql = "select recording_uuid, domain_uuid, recording_filename ";
|
2019-08-12 15:32:23 +02:00
|
|
|
$sql .= "from v_recordings ";
|
|
|
|
|
$sql .= "where recording_base64 is null ";
|
|
|
|
|
$sql .= "or recording_base64 = '' ";
|
|
|
|
|
$result = $database->select($sql, null, 'all');
|
|
|
|
|
if (is_array($result) && @sizeof($result) != 0) {
|
2024-08-22 20:41:10 +02:00
|
|
|
foreach ($result as $row) {
|
2023-05-17 18:07:49 +02:00
|
|
|
//set the variables
|
|
|
|
|
$recording_uuid = $row['recording_uuid'];
|
|
|
|
|
$recording_domain_uuid = $row['domain_uuid'];
|
|
|
|
|
$recording_filename = $row['recording_filename'];
|
|
|
|
|
|
2017-02-08 21:29:48 +01:00
|
|
|
//set recording directory
|
2025-03-14 23:19:49 +01:00
|
|
|
$recording_directory = $settings->get('switch','recordings').'/'.$domain_name;
|
2023-05-17 18:07:49 +02:00
|
|
|
|
2017-02-08 21:29:48 +01:00
|
|
|
//encode recording file (if exists)
|
|
|
|
|
if (file_exists($recording_directory.'/'.$recording_filename)) {
|
2019-08-12 15:32:23 +02:00
|
|
|
//build array
|
|
|
|
|
$recording_base64 = base64_encode(file_get_contents($recording_directory.'/'.$recording_filename));
|
|
|
|
|
$array['recordings'][0]['recording_uuid'] = $recording_uuid;
|
|
|
|
|
$array['recordings'][0]['domain_uuid'] = $recording_domain_uuid;
|
|
|
|
|
$array['recordings'][0]['recording_base64'] = $recording_base64;
|
|
|
|
|
//grant temporary permissions
|
2024-11-29 21:57:01 +01:00
|
|
|
$p = permissions::new();
|
2019-08-12 15:32:23 +02:00
|
|
|
$p->add('recording_edit', 'temp');
|
2017-02-08 21:29:48 +01:00
|
|
|
//update recording record with base64
|
2019-08-12 15:32:23 +02:00
|
|
|
$database->app_name = 'recordings';
|
|
|
|
|
$database->app_uuid = '83913217-c7a2-9e90-925d-a866eb40b60e';
|
2021-12-24 20:42:16 +01:00
|
|
|
$database->save($array, false);
|
2019-08-12 15:32:23 +02:00
|
|
|
unset($array);
|
|
|
|
|
//revoke temporary permissions
|
|
|
|
|
$p->delete('recording_edit', 'temp');
|
2017-02-08 21:29:48 +01:00
|
|
|
//remove local recording file
|
|
|
|
|
@unlink($recording_directory.'/'.$recording_filename);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-04-25 23:46:01 +02:00
|
|
|
}
|
2019-08-12 15:32:23 +02:00
|
|
|
unset($sql, $result, $row);
|
2017-02-08 21:29:48 +01:00
|
|
|
}
|
|
|
|
|
//if not base64, decode to local files, remove base64 data from db
|
2025-03-14 23:19:49 +01:00
|
|
|
else if (!empty($settings->get('recordings','storage_type')) && $settings->get('recordings','storage_type') != 'base64') {
|
2017-02-08 21:29:48 +01:00
|
|
|
//get recordings with base64 in db
|
|
|
|
|
$sql = "select recording_uuid, domain_uuid, recording_filename, recording_base64 ";
|
2019-08-12 15:32:23 +02:00
|
|
|
$sql .= "from v_recordings ";
|
|
|
|
|
$sql .= "where recording_base64 is not null ";
|
|
|
|
|
$result = $database->select($sql, null, 'all');
|
2023-05-17 18:07:49 +02:00
|
|
|
if (!empty($result)) {
|
2024-08-22 20:41:10 +02:00
|
|
|
foreach ($result as $row) {
|
2023-05-17 18:07:49 +02:00
|
|
|
//set the variables
|
|
|
|
|
$recording_uuid = $row['recording_uuid'];
|
|
|
|
|
$recording_domain_uuid = $row['domain_uuid'];
|
|
|
|
|
$recording_filename = $row['recording_filename'];
|
|
|
|
|
$recording_base64 = $row['recording_base64'];
|
|
|
|
|
|
2017-02-08 21:29:48 +01:00
|
|
|
//set recording directory
|
2025-03-14 23:19:49 +01:00
|
|
|
$recording_directory = $settings->get('switch','recordings').'/'.$domain_name;
|
2023-05-17 18:07:49 +02:00
|
|
|
|
2017-02-08 21:29:48 +01:00
|
|
|
//remove local file, if any
|
|
|
|
|
if (file_exists($recording_directory.'/'.$recording_filename)) {
|
|
|
|
|
@unlink($recording_directory.'/'.$recording_filename);
|
|
|
|
|
}
|
2023-05-17 18:07:49 +02:00
|
|
|
|
2017-02-08 21:29:48 +01:00
|
|
|
//decode base64, save to local file
|
|
|
|
|
$recording_decoded = base64_decode($recording_base64);
|
|
|
|
|
file_put_contents($recording_directory.'/'.$recording_filename, $recording_decoded);
|
2023-05-17 18:07:49 +02:00
|
|
|
|
2019-08-12 15:32:23 +02:00
|
|
|
//build array
|
|
|
|
|
$array['recordings'][0]['recording_uuid'] = $recording_uuid;
|
|
|
|
|
$array['recordings'][0]['domain_uuid'] = $recording_domain_uuid;
|
|
|
|
|
$array['recordings'][0]['recording_base64'] = null;
|
2023-05-17 18:07:49 +02:00
|
|
|
|
2019-08-12 15:32:23 +02:00
|
|
|
//grant temporary permissions
|
2024-11-29 21:57:01 +01:00
|
|
|
$p = permissions::new();
|
2019-08-12 15:32:23 +02:00
|
|
|
$p->add('recording_edit', 'temp');
|
2023-05-17 18:07:49 +02:00
|
|
|
|
2019-08-12 15:32:23 +02:00
|
|
|
//update recording record
|
|
|
|
|
$database->app_name = 'recordings';
|
|
|
|
|
$database->app_uuid = '83913217-c7a2-9e90-925d-a866eb40b60e';
|
2021-12-24 20:42:16 +01:00
|
|
|
$database->save($array, false);
|
2019-08-12 15:32:23 +02:00
|
|
|
unset($array);
|
2023-05-17 18:07:49 +02:00
|
|
|
|
2019-08-12 15:32:23 +02:00
|
|
|
//revoke temporary permissions
|
|
|
|
|
$p->delete('recording_edit', 'temp');
|
2017-02-08 21:29:48 +01:00
|
|
|
}
|
2015-04-25 23:46:01 +02:00
|
|
|
}
|
2019-08-12 15:32:23 +02:00
|
|
|
unset($sql, $result, $row);
|
2017-02-08 21:29:48 +01:00
|
|
|
}
|
|
|
|
|
}
|
2015-04-25 23:46:01 +02:00
|
|
|
|
2017-01-10 07:48:15 +01:00
|
|
|
?>
|