Allow use odbc to store files (record/voicemail) in database. (#1535)
* Change. Allow use odbc to store files (record/voicemail) in database. * Fix. Generate correct default config.
This commit is contained in:
parent
7fae6c9d4e
commit
28d3ebb51f
|
|
@ -1,323 +1,326 @@
|
||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
FusionPBX
|
FusionPBX
|
||||||
Version: MPL 1.1
|
Version: MPL 1.1
|
||||||
|
|
||||||
The contents of this file are subject to the Mozilla Public License Version
|
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
|
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
|
the License. You may obtain a copy of the License at
|
||||||
http://www.mozilla.org/MPL/
|
http://www.mozilla.org/MPL/
|
||||||
|
|
||||||
Software distributed under the License is distributed on an "AS IS" basis,
|
Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||||
for the specific language governing rights and limitations under the
|
for the specific language governing rights and limitations under the
|
||||||
License.
|
License.
|
||||||
|
|
||||||
The Original Code is FusionPBX
|
The Original Code is FusionPBX
|
||||||
|
|
||||||
The Initial Developer of the Original Code is
|
The Initial Developer of the Original Code is
|
||||||
Mark J Crane <markjcrane@fusionpbx.com>
|
Mark J Crane <markjcrane@fusionpbx.com>
|
||||||
Portions created by the Initial Developer are Copyright (C) 2008-2016
|
Portions created by the Initial Developer are Copyright (C) 2008-2016
|
||||||
the Initial Developer. All Rights Reserved.
|
the Initial Developer. All Rights Reserved.
|
||||||
|
|
||||||
Contributor(s):
|
Contributor(s):
|
||||||
Mark J Crane <markjcrane@fusionpbx.com>
|
Mark J Crane <markjcrane@fusionpbx.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* scripts class provides methods for creating the config.lua and copying switch scripts
|
* scripts class provides methods for creating the config.lua and copying switch scripts
|
||||||
*
|
*
|
||||||
* @method string correct_path
|
* @method string correct_path
|
||||||
* @method string copy_files
|
* @method string copy_files
|
||||||
* @method string write_config
|
* @method string write_config
|
||||||
*/
|
*/
|
||||||
if (!class_exists('scripts')) {
|
if (!class_exists('scripts')) {
|
||||||
class scripts {
|
class scripts {
|
||||||
|
|
||||||
public $db;
|
public $db;
|
||||||
public $db_type;
|
public $db_type;
|
||||||
public $db_name;
|
public $db_name;
|
||||||
public $db_host;
|
public $db_host;
|
||||||
public $db_port;
|
public $db_port;
|
||||||
public $db_path;
|
public $db_path;
|
||||||
public $db_username;
|
public $db_username;
|
||||||
public $db_password;
|
public $db_password;
|
||||||
public $dsn_name;
|
public $dsn_name;
|
||||||
public $dsn_username;
|
public $dsn_username;
|
||||||
public $dsn_password;
|
public $dsn_password;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the object is created
|
* Called when the object is created
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
//connect to the database if not connected
|
//connect to the database if not connected
|
||||||
require_once "resources/classes/database.php";
|
require_once "resources/classes/database.php";
|
||||||
$database = new database;
|
$database = new database;
|
||||||
$database->connect();
|
$database->connect();
|
||||||
$this->db = $database->db;
|
$this->db = $database->db;
|
||||||
$this->db_type = $database->type;
|
$this->db_type = $database->type;
|
||||||
$this->db_name = $database->db_name;
|
$this->db_name = $database->db_name;
|
||||||
$this->db_host = $database->host;
|
$this->db_host = $database->host;
|
||||||
$this->db_port = $database->port;
|
$this->db_port = $database->port;
|
||||||
$this->db_path = $database->path;
|
$this->db_path = $database->path;
|
||||||
$this->db_username = $database->username;
|
$this->db_username = $database->username;
|
||||||
$this->db_password = $database->password;
|
$this->db_password = $database->password;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when there are no references to a particular object
|
* Called when there are no references to a particular object
|
||||||
* unset the variables used in the class
|
* unset the variables used in the class
|
||||||
*/
|
*/
|
||||||
public function __destruct() {
|
public function __destruct() {
|
||||||
foreach ($this as $key => $value) {
|
foreach ($this as $key => $value) {
|
||||||
unset($this->$key);
|
unset($this->$key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Corrects the path for specifically for windows
|
* Corrects the path for specifically for windows
|
||||||
*/
|
*/
|
||||||
private function correct_path($path) {
|
private function correct_path($path) {
|
||||||
global $IS_WINDOWS;
|
global $IS_WINDOWS;
|
||||||
if ($IS_WINDOWS == null) {
|
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) {
|
if ($IS_WINDOWS) {
|
||||||
return str_replace('\\', '/', $path);
|
return str_replace('\\', '/', $path);
|
||||||
}
|
}
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy the switch scripts from the web directory to the switch directory
|
* Copy the switch scripts from the web directory to the switch directory
|
||||||
*/
|
*/
|
||||||
public function copy_files() {
|
public function copy_files() {
|
||||||
if (strlen($_SESSION['switch']['scripts']['dir']) > 0) {
|
if (strlen($_SESSION['switch']['scripts']['dir']) > 0) {
|
||||||
$dst_dir = $_SESSION['switch']['scripts']['dir'];
|
$dst_dir = $_SESSION['switch']['scripts']['dir'];
|
||||||
if(strlen($dst_dir) == 0) {
|
if(strlen($dst_dir) == 0) {
|
||||||
throw new Exception("Cannot copy scripts the 'script_dir' is empty");
|
throw new Exception("Cannot copy scripts the 'script_dir' is empty");
|
||||||
}
|
}
|
||||||
if (file_exists($dst_dir)) {
|
if (file_exists($dst_dir)) {
|
||||||
//get the source directory
|
//get the source directory
|
||||||
if (file_exists('/usr/share/examples/fusionpbx/resources/install/scripts')){
|
if (file_exists('/usr/share/examples/fusionpbx/resources/install/scripts')){
|
||||||
$src_dir = '/usr/share/examples/fusionpbx/resources/install/scripts';
|
$src_dir = '/usr/share/examples/fusionpbx/resources/install/scripts';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/scripts';
|
$src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/scripts';
|
||||||
}
|
}
|
||||||
if (is_readable($dst_dir)) {
|
if (is_readable($dst_dir)) {
|
||||||
recursive_copy($src_dir,$dst_dir);
|
recursive_copy($src_dir,$dst_dir);
|
||||||
unset($src_dir);
|
unset($src_dir);
|
||||||
}else{
|
}else{
|
||||||
throw new Exception("Cannot read from '$src_dir' to get the scripts");
|
throw new Exception("Cannot read from '$src_dir' to get the scripts");
|
||||||
}
|
}
|
||||||
chmod($dst_dir, 0775);
|
chmod($dst_dir, 0775);
|
||||||
unset($dst_dir);
|
unset($dst_dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the config.lua
|
* Writes the config.lua
|
||||||
*/
|
*/
|
||||||
public function write_config() {
|
public function write_config() {
|
||||||
if (is_dir($_SESSION['switch']['scripts']['dir'])) {
|
if (is_dir($_SESSION['switch']['scripts']['dir'])) {
|
||||||
|
|
||||||
//replace the backslash with a forward slash
|
//replace the backslash with a forward slash
|
||||||
$this->db_path = str_replace("\\", "/", $this->db_path);
|
$this->db_path = str_replace("\\", "/", $this->db_path);
|
||||||
|
|
||||||
//get the odbc information
|
//get the odbc information
|
||||||
$sql = "select count(*) as num_rows from v_databases ";
|
$sql = "select count(*) as num_rows from v_databases ";
|
||||||
$sql .= "where database_driver = 'odbc' ";
|
$sql .= "where database_driver = 'odbc' ";
|
||||||
$prep_statement = $this->db->prepare($sql);
|
$prep_statement = $this->db->prepare($sql);
|
||||||
if ($prep_statement) {
|
if ($prep_statement) {
|
||||||
$prep_statement->execute();
|
$prep_statement->execute();
|
||||||
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
|
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
|
||||||
unset($prep_statement);
|
unset($prep_statement);
|
||||||
if ($row['num_rows'] > 0) {
|
if ($row['num_rows'] > 0) {
|
||||||
$odbc_num_rows = $row['num_rows'];
|
$odbc_num_rows = $row['num_rows'];
|
||||||
|
|
||||||
$sql = "select * from v_databases ";
|
$sql = "select * from v_databases ";
|
||||||
$sql .= "where database_driver = 'odbc' ";
|
$sql .= "where database_driver = 'odbc' ";
|
||||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||||
$prep_statement->execute();
|
$prep_statement->execute();
|
||||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||||
foreach ($result as &$row) {
|
foreach ($result as &$row) {
|
||||||
$this->dsn_name = $row["database_name"];
|
$this->dsn_name = $row["database_name"];
|
||||||
$this->dsn_username = $row["database_username"];
|
$this->dsn_username = $row["database_username"];
|
||||||
$this->dsn_password = $row["database_password"];
|
$this->dsn_password = $row["database_password"];
|
||||||
break; //limit to 1 row
|
break; //limit to 1 row
|
||||||
}
|
}
|
||||||
unset ($prep_statement);
|
unset ($prep_statement);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$odbc_num_rows = '0';
|
$odbc_num_rows = '0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the recordings directory
|
//get the recordings directory
|
||||||
$recordings_dir = $_SESSION['switch']['recordings']['dir'];
|
$recordings_dir = $_SESSION['switch']['recordings']['dir'];
|
||||||
|
|
||||||
//get the http_protocol
|
//get the http_protocol
|
||||||
if (!isset($_SERVER['HTTP_PROTOCOL'])) {
|
if (!isset($_SERVER['HTTP_PROTOCOL'])) {
|
||||||
$_SERVER['HTTP_PROTOCOL'] = 'http';
|
$_SERVER['HTTP_PROTOCOL'] = 'http';
|
||||||
if (isset($_SERVER['REQUEST_SCHEME'])) { $_SERVER['HTTP_PROTOCOL'] = $_SERVER['REQUEST_SCHEME']; }
|
if (isset($_SERVER['REQUEST_SCHEME'])) { $_SERVER['HTTP_PROTOCOL'] = $_SERVER['REQUEST_SCHEME']; }
|
||||||
if ($_SERVER['HTTPS'] == 'on') { $_SERVER['HTTP_PROTOCOL'] = 'https'; }
|
if ($_SERVER['HTTPS'] == 'on') { $_SERVER['HTTP_PROTOCOL'] = 'https'; }
|
||||||
if ($_SERVER['SERVER_PORT'] == '443') { $_SERVER['HTTP_PROTOCOL'] = 'https'; }
|
if ($_SERVER['SERVER_PORT'] == '443') { $_SERVER['HTTP_PROTOCOL'] = 'https'; }
|
||||||
}
|
}
|
||||||
|
|
||||||
//find the location to write the config.lua
|
//find the location to write the config.lua
|
||||||
if (is_dir("/etc/fusionpbx")){
|
if (is_dir("/etc/fusionpbx")){
|
||||||
$config = "/etc/fusionpbx/config.lua";
|
$config = "/etc/fusionpbx/config.lua";
|
||||||
} elseif (is_dir("/usr/local/etc/fusionpbx")){
|
} elseif (is_dir("/usr/local/etc/fusionpbx")){
|
||||||
$config = "/usr/local/etc/fusionpbx/config.lua";
|
$config = "/usr/local/etc/fusionpbx/config.lua";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$config = $_SESSION['switch']['scripts']['dir']."/resources/config.lua";
|
$config = $_SESSION['switch']['scripts']['dir']."/resources/config.lua";
|
||||||
}
|
}
|
||||||
$fout = fopen($config,"w");
|
$fout = fopen($config,"w");
|
||||||
if(!$fout){
|
if(!$fout){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//make the config.lua
|
//make the config.lua
|
||||||
$tmp = "\n";
|
$tmp = "\n";
|
||||||
$tmp .= "--set the variables\n";
|
$tmp .= "--set the variables\n";
|
||||||
if (strlen($_SESSION['switch']['conf']['dir']) > 0) {
|
if (strlen($_SESSION['switch']['conf']['dir']) > 0) {
|
||||||
$tmp .= $this->correct_path(" conf_dir = [[".$_SESSION['switch']['conf']['dir']."]];\n");
|
$tmp .= $this->correct_path(" conf_dir = [[".$_SESSION['switch']['conf']['dir']."]];\n");
|
||||||
}
|
}
|
||||||
if (strlen($_SESSION['switch']['sounds']['dir']) > 0) {
|
if (strlen($_SESSION['switch']['sounds']['dir']) > 0) {
|
||||||
$tmp .= $this->correct_path(" sounds_dir = [[".$_SESSION['switch']['sounds']['dir']."]];\n");
|
$tmp .= $this->correct_path(" sounds_dir = [[".$_SESSION['switch']['sounds']['dir']."]];\n");
|
||||||
}
|
}
|
||||||
if (strlen($_SESSION['switch']['db']['dir']) > 0) {
|
if (strlen($_SESSION['switch']['db']['dir']) > 0) {
|
||||||
$tmp .= $this->correct_path(" database_dir = [[".$_SESSION['switch']['db']['dir']."]];\n");
|
$tmp .= $this->correct_path(" database_dir = [[".$_SESSION['switch']['db']['dir']."]];\n");
|
||||||
}
|
}
|
||||||
if (strlen($_SESSION['switch']['recordings']['dir']) > 0) {
|
if (strlen($_SESSION['switch']['recordings']['dir']) > 0) {
|
||||||
$tmp .= $this->correct_path(" recordings_dir = [[".$recordings_dir."]];\n");
|
$tmp .= $this->correct_path(" recordings_dir = [[".$recordings_dir."]];\n");
|
||||||
}
|
}
|
||||||
if (strlen($_SESSION['switch']['storage']['dir']) > 0) {
|
if (strlen($_SESSION['switch']['storage']['dir']) > 0) {
|
||||||
$tmp .= $this->correct_path(" storage_dir = [[".$_SESSION['switch']['storage']['dir']."]];\n");
|
$tmp .= $this->correct_path(" storage_dir = [[".$_SESSION['switch']['storage']['dir']."]];\n");
|
||||||
}
|
}
|
||||||
if (strlen($_SESSION['switch']['voicemail']['dir']) > 0) {
|
if (strlen($_SESSION['switch']['voicemail']['dir']) > 0) {
|
||||||
$tmp .= $this->correct_path(" voicemail_dir = [[".$_SESSION['switch']['voicemail']['dir']."]];\n");
|
$tmp .= $this->correct_path(" voicemail_dir = [[".$_SESSION['switch']['voicemail']['dir']."]];\n");
|
||||||
}
|
}
|
||||||
if (strlen($_SESSION['switch']['scripts']['dir']) > 0) {
|
if (strlen($_SESSION['switch']['scripts']['dir']) > 0) {
|
||||||
$tmp .= $this->correct_path(" scripts_dir = [[".$_SESSION['switch']['scripts']['dir']."]];\n");
|
$tmp .= $this->correct_path(" scripts_dir = [[".$_SESSION['switch']['scripts']['dir']."]];\n");
|
||||||
}
|
}
|
||||||
$tmp .= $this->correct_path(" php_dir = [[".PHP_BINDIR."]];\n");
|
$tmp .= $this->correct_path(" php_dir = [[".PHP_BINDIR."]];\n");
|
||||||
if (substr(strtoupper(PHP_OS), 0, 3) == "WIN") {
|
if (substr(strtoupper(PHP_OS), 0, 3) == "WIN") {
|
||||||
$tmp .= " php_bin = \"php.exe\";\n";
|
$tmp .= " php_bin = \"php.exe\";\n";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$tmp .= " php_bin = \"php5\";\n";
|
$tmp .= " php_bin = \"php5\";\n";
|
||||||
}
|
}
|
||||||
$tmp .= $this->correct_path(" document_root = [[".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."]];\n");
|
$tmp .= $this->correct_path(" document_root = [[".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."]];\n");
|
||||||
$tmp .= $this->correct_path(" project_path = [[".PROJECT_PATH."]];\n");
|
$tmp .= $this->correct_path(" project_path = [[".PROJECT_PATH."]];\n");
|
||||||
$tmp .= $this->correct_path(" http_protocol = [[".$_SERVER['HTTP_PROTOCOL']."]];\n");
|
$tmp .= $this->correct_path(" http_protocol = [[".$_SERVER['HTTP_PROTOCOL']."]];\n");
|
||||||
$tmp .= "\n";
|
$tmp .= "\n";
|
||||||
|
|
||||||
$tmp .= "--store settings in memcache\n";
|
$tmp .= "--store settings in memcache\n";
|
||||||
$tmp .= " settings_in_cache = false;\n";
|
$tmp .= " settings_in_cache = false;\n";
|
||||||
$tmp .= "\n";
|
$tmp .= "\n";
|
||||||
|
|
||||||
if ((strlen($this->db_type) > 0) || (strlen($this->dsn_name) > 0)) {
|
if ((strlen($this->db_type) > 0) || (strlen($this->dsn_name) > 0)) {
|
||||||
$tmp .= "--database information\n";
|
$tmp .= "--database information\n";
|
||||||
$tmp .= " database = {}\n";
|
$tmp .= " database = {}\n";
|
||||||
$tmp .= " database.type = \"".$this->db_type."\";\n";
|
$tmp .= " database.type = \"".$this->db_type."\";\n";
|
||||||
$tmp .= " database.name = \"".$this->db_name."\";\n";
|
$tmp .= " database.name = \"".$this->db_name."\";\n";
|
||||||
$tmp .= $this->correct_path(" database.path = [[".$this->db_path."]];\n");
|
$tmp .= $this->correct_path(" database.path = [[".$this->db_path."]];\n");
|
||||||
|
|
||||||
if (strlen($this->dsn_name) > 0) {
|
if (strlen($this->dsn_name) > 0) {
|
||||||
$tmp .= " database.system = \"odbc://".$this->dsn_name.":".$this->dsn_username.":".$this->dsn_password."\";\n";
|
$tmp .= " database.system = \"odbc://".$this->dsn_name.":".$this->dsn_username.":".$this->dsn_password."\";\n";
|
||||||
$tmp .= " database.switch = \"odbc://freeswitch:".$this->dsn_username.":".$this->dsn_password."\";\n";
|
$tmp .= " database.switch = \"odbc://freeswitch:".$this->dsn_username.":".$this->dsn_password."\";\n";
|
||||||
}
|
}
|
||||||
elseif ($this->db_type == "pgsql") {
|
elseif ($this->db_type == "pgsql") {
|
||||||
if ($this->db_host == "localhost") { $this->db_host = "127.0.0.1"; }
|
if ($this->db_host == "localhost") { $this->db_host = "127.0.0.1"; }
|
||||||
$tmp .= " database.system = \"pgsql://hostaddr=".$this->db_host." port=".$this->db_port." dbname=".$this->db_name." user=".$this->db_username." password=".$this->db_password." options='' application_name='".$this->db_name."'\";\n";
|
$tmp .= " database.system = \"pgsql://hostaddr=".$this->db_host." port=".$this->db_port." dbname=".$this->db_name." user=".$this->db_username." password=".$this->db_password." options='' application_name='".$this->db_name."'\";\n";
|
||||||
$tmp .= " database.switch = \"pgsql://hostaddr=".$this->db_host." port=".$this->db_port." dbname=freeswitch user=".$this->db_username." password=".$this->db_password." options='' application_name='freeswitch'\";\n";
|
$tmp .= " database.switch = \"pgsql://hostaddr=".$this->db_host." port=".$this->db_port." dbname=freeswitch user=".$this->db_username." password=".$this->db_password." options='' application_name='freeswitch'\";\n";
|
||||||
}
|
}
|
||||||
elseif ($this->db_type == "sqlite") {
|
elseif ($this->db_type == "sqlite") {
|
||||||
$tmp .= " database.system = \"sqlite://".$this->db_path."/".$this->db_name."\";\n";
|
$tmp .= " database.system = \"sqlite://".$this->db_path."/".$this->db_name."\";\n";
|
||||||
$tmp .= " database.switch = \"sqlite://".$_SESSION['switch']['db']['dir']."\";\n";
|
$tmp .= " database.switch = \"sqlite://".$_SESSION['switch']['db']['dir']."\";\n";
|
||||||
}
|
}
|
||||||
elseif ($this->db_type == "mysql") {
|
elseif ($this->db_type == "mysql") {
|
||||||
$tmp .= " database.system = \"\";\n";
|
$tmp .= " database.system = \"\";\n";
|
||||||
$tmp .= " database.switch = \"\";\n";
|
$tmp .= " database.switch = \"\";\n";
|
||||||
}
|
}
|
||||||
$tmp .= "\n";
|
$tmp .= "\n";
|
||||||
}
|
$tmp .= " database.backend = {}\n";
|
||||||
$tmp .= "--set defaults\n";
|
$tmp .= " database.backend.base64 = 'luasql'\n";
|
||||||
$tmp .= " expire = {}\n";
|
$tmp .= "\n";
|
||||||
$tmp .= " expire.directory = \"3600\";\n";
|
}
|
||||||
$tmp .= " expire.dialplan = \"3600\";\n";
|
$tmp .= "--set defaults\n";
|
||||||
$tmp .= " expire.languages = \"3600\";\n";
|
$tmp .= " expire = {}\n";
|
||||||
$tmp .= " expire.sofia = \"3600\";\n";
|
$tmp .= " expire.directory = \"3600\";\n";
|
||||||
$tmp .= " expire.acl = \"3600\";\n";
|
$tmp .= " expire.dialplan = \"3600\";\n";
|
||||||
$tmp .= "\n";
|
$tmp .= " expire.languages = \"3600\";\n";
|
||||||
$tmp .= "--set xml_handler\n";
|
$tmp .= " expire.sofia = \"3600\";\n";
|
||||||
$tmp .= " xml_handler = {}\n";
|
$tmp .= " expire.acl = \"3600\";\n";
|
||||||
$tmp .= " xml_handler.fs_path = false;\n";
|
$tmp .= "\n";
|
||||||
$tmp .= "\n";
|
$tmp .= "--set xml_handler\n";
|
||||||
$tmp .= "--set settings\n";
|
$tmp .= " xml_handler = {}\n";
|
||||||
$tmp .= " settings = {}\n";
|
$tmp .= " xml_handler.fs_path = false;\n";
|
||||||
$tmp .= " settings.recordings = {}\n";
|
$tmp .= "\n";
|
||||||
$tmp .= " settings.voicemail = {}\n";
|
$tmp .= "--set settings\n";
|
||||||
$tmp .= " settings.fax = {}\n";
|
$tmp .= " settings = {}\n";
|
||||||
if (isset($_SESSION['recordings']['storage_type']['text'])) {
|
$tmp .= " settings.recordings = {}\n";
|
||||||
$tmp .= " settings.recordings.storage_type = \"".$_SESSION['recordings']['storage_type']['text']."\";\n";
|
$tmp .= " settings.voicemail = {}\n";
|
||||||
}
|
$tmp .= " settings.fax = {}\n";
|
||||||
else {
|
if (isset($_SESSION['recordings']['storage_type']['text'])) {
|
||||||
$tmp .= " settings.recordings.storage_type = \"\";\n";
|
$tmp .= " settings.recordings.storage_type = \"".$_SESSION['recordings']['storage_type']['text']."\";\n";
|
||||||
}
|
}
|
||||||
if (isset($_SESSION['voicemail']['storage_type']['text'])) {
|
else {
|
||||||
$tmp .= " settings.voicemail.storage_type = \"".$_SESSION['voicemail']['storage_type']['text']."\";\n";
|
$tmp .= " settings.recordings.storage_type = \"\";\n";
|
||||||
}
|
}
|
||||||
else {
|
if (isset($_SESSION['voicemail']['storage_type']['text'])) {
|
||||||
$tmp .= " settings.voicemail.storage_type = \"\";\n";
|
$tmp .= " settings.voicemail.storage_type = \"".$_SESSION['voicemail']['storage_type']['text']."\";\n";
|
||||||
}
|
}
|
||||||
if (isset($_SESSION['fax']['storage_type']['text'])) {
|
else {
|
||||||
$tmp .= " settings.fax.storage_type = \"".$_SESSION['fax']['storage_type']['text']."\";\n";
|
$tmp .= " settings.voicemail.storage_type = \"\";\n";
|
||||||
}
|
}
|
||||||
else {
|
if (isset($_SESSION['fax']['storage_type']['text'])) {
|
||||||
$tmp .= " settings.fax.storage_type = \"\";\n";
|
$tmp .= " settings.fax.storage_type = \"".$_SESSION['fax']['storage_type']['text']."\";\n";
|
||||||
}
|
}
|
||||||
$tmp .= "\n";
|
else {
|
||||||
$tmp .= "--set the debug options\n";
|
$tmp .= " settings.fax.storage_type = \"\";\n";
|
||||||
$tmp .= " debug.params = false;\n";
|
}
|
||||||
$tmp .= " debug.sql = false;\n";
|
$tmp .= "\n";
|
||||||
$tmp .= " debug.xml_request = false;\n";
|
$tmp .= "--set the debug options\n";
|
||||||
$tmp .= " debug.xml_string = false;\n";
|
$tmp .= " debug.params = false;\n";
|
||||||
$tmp .= " debug.cache = false;\n";
|
$tmp .= " debug.sql = false;\n";
|
||||||
$tmp .= "\n";
|
$tmp .= " debug.xml_request = false;\n";
|
||||||
$tmp .= "--additional info\n";
|
$tmp .= " debug.xml_string = false;\n";
|
||||||
$tmp .= " domain_count = ".count($_SESSION["domains"]).";\n";
|
$tmp .= " debug.cache = false;\n";
|
||||||
$tmp .= $this->correct_path(" temp_dir = [[".$_SESSION['server']['temp']['dir']."]];\n");
|
$tmp .= "\n";
|
||||||
if (isset($_SESSION['domain']['dial_string']['text'])) {
|
$tmp .= "--additional info\n";
|
||||||
$tmp .= " dial_string = \"".$_SESSION['domain']['dial_string']['text']."\";\n";
|
$tmp .= " domain_count = ".count($_SESSION["domains"]).";\n";
|
||||||
}
|
$tmp .= $this->correct_path(" temp_dir = [[".$_SESSION['server']['temp']['dir']."]];\n");
|
||||||
$tmp .= "\n";
|
if (isset($_SESSION['domain']['dial_string']['text'])) {
|
||||||
$tmp .= "--include local.lua\n";
|
$tmp .= " dial_string = \"".$_SESSION['domain']['dial_string']['text']."\";\n";
|
||||||
$tmp .= " require(\"resources.functions.file_exists\");\n";
|
}
|
||||||
$tmp .= " if (file_exists(\"/etc/fusionpbx/local.lua\")) then\n";
|
$tmp .= "\n";
|
||||||
$tmp .= " dofile(\"/etc/fusionpbx/local.lua\");\n";
|
$tmp .= "--include local.lua\n";
|
||||||
$tmp .= " elseif (file_exists(\"/usr/local/etc/fusionpbx/local.lua\")) then\n";
|
$tmp .= " require(\"resources.functions.file_exists\");\n";
|
||||||
$tmp .= " dofile(\"/usr/local/etc/fusionpbx/local.lua\");\n";
|
$tmp .= " if (file_exists(\"/etc/fusionpbx/local.lua\")) then\n";
|
||||||
$tmp .= " elseif (file_exists(scripts_dir..\"/resources/local.lua\")) then\n";
|
$tmp .= " dofile(\"/etc/fusionpbx/local.lua\");\n";
|
||||||
$tmp .= " require(\"resources.local\");\n";
|
$tmp .= " elseif (file_exists(\"/usr/local/etc/fusionpbx/local.lua\")) then\n";
|
||||||
$tmp .= " end\n";
|
$tmp .= " dofile(\"/usr/local/etc/fusionpbx/local.lua\");\n";
|
||||||
fwrite($fout, $tmp);
|
$tmp .= " elseif (file_exists(scripts_dir..\"/resources/local.lua\")) then\n";
|
||||||
unset($tmp);
|
$tmp .= " require(\"resources.local\");\n";
|
||||||
fclose($fout);
|
$tmp .= " end\n";
|
||||||
}
|
fwrite($fout, $tmp);
|
||||||
} //end config_lua
|
unset($tmp);
|
||||||
} //end scripts class
|
fclose($fout);
|
||||||
}
|
}
|
||||||
/*
|
} //end config_lua
|
||||||
//example use
|
} //end scripts class
|
||||||
|
}
|
||||||
//update config.lua
|
/*
|
||||||
$obj = new scripts;
|
//example use
|
||||||
$obj->write_config();
|
|
||||||
*/
|
//update config.lua
|
||||||
?>
|
$obj = new scripts;
|
||||||
|
$obj->write_config();
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
|
|
||||||
|
|
@ -303,14 +303,11 @@
|
||||||
if (fax_success ~= nil) then
|
if (fax_success ~= nil) then
|
||||||
if (fax_success =="1") then
|
if (fax_success =="1") then
|
||||||
if (storage_type == "base64") then
|
if (storage_type == "base64") then
|
||||||
--include the base64 function
|
--include the file io
|
||||||
require "resources.functions.base64";
|
local file = require "resources.functions.file"
|
||||||
|
|
||||||
--base64 encode the file
|
--read file content as base64 string
|
||||||
local f = io.open(fax_file, "rb");
|
fax_base64 = assert(file.read_base64(fax_file));
|
||||||
local file_content = f:read("*all");
|
|
||||||
f:close();
|
|
||||||
fax_base64 = base64.encode(file_content);
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local sql = {}
|
local sql = {}
|
||||||
|
|
@ -363,13 +360,10 @@
|
||||||
freeswitch.consoleLog("notice", "[fax] SQL: " .. sql .. "\n");
|
freeswitch.consoleLog("notice", "[fax] SQL: " .. sql .. "\n");
|
||||||
end
|
end
|
||||||
if (storage_type == "base64") then
|
if (storage_type == "base64") then
|
||||||
array = explode("://", database["system"]);
|
local Database = require "resources.functions.database"
|
||||||
local luasql = require "luasql.postgres";
|
local dbh = Database.new('system', 'base64');
|
||||||
local env = assert (luasql.postgres());
|
dbh:query(sql);
|
||||||
local dbh = env:connect(array[2]);
|
dbh:release();
|
||||||
res, serr = dbh:execute(sql);
|
|
||||||
dbh:close();
|
|
||||||
env:close();
|
|
||||||
else
|
else
|
||||||
result = dbh:query(sql);
|
result = dbh:query(sql);
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -246,18 +246,14 @@
|
||||||
if fax_success == "1" then
|
if fax_success == "1" then
|
||||||
|
|
||||||
if storage_type == "base64" then
|
if storage_type == "base64" then
|
||||||
--include the base64 function
|
--include the file io
|
||||||
require "resources.functions.base64";
|
local file = require "resources.functions.file"
|
||||||
|
|
||||||
--base64 encode the file
|
--read file content as base64 string
|
||||||
local f = io.open(fax_file, "rb");
|
fax_base64 = file.read_base64(fax_file);
|
||||||
if not f then
|
if not fax_base64 then
|
||||||
log.waitng("Can not find file %s", fax_file)
|
log.waitng("Can not find file %s", fax_file)
|
||||||
storage_type = nil
|
storage_type = nil
|
||||||
else
|
|
||||||
local file_content = f:read("*all");
|
|
||||||
f:close()
|
|
||||||
fax_base64 = base64.encode(file_content)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -300,13 +296,10 @@
|
||||||
end
|
end
|
||||||
|
|
||||||
if storage_type == "base64" then
|
if storage_type == "base64" then
|
||||||
local db_type, db_cnn = split_first(database["system"], "://", true)
|
local Database = require "resources.functions.database"
|
||||||
local luasql = require ("luasql." .. db_type);
|
local dbh = Database.new('system', 'base64');
|
||||||
local env = assert (luasql[db_type]());
|
dbh:query(sql);
|
||||||
local dbh = env:connect(db_cnn);
|
dbh:release();
|
||||||
dbh:execute(sql)
|
|
||||||
dbh:close()
|
|
||||||
env:close()
|
|
||||||
else
|
else
|
||||||
result = dbh:query(sql)
|
result = dbh:query(sql)
|
||||||
end
|
end
|
||||||
|
|
@ -397,7 +390,7 @@
|
||||||
os.remove(fax_file);
|
os.remove(fax_file);
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -325,20 +325,19 @@
|
||||||
--show the storage type
|
--show the storage type
|
||||||
freeswitch.consoleLog("notice", "[voicemail] ".. storage_type .. "\n");
|
freeswitch.consoleLog("notice", "[voicemail] ".. storage_type .. "\n");
|
||||||
|
|
||||||
--include the base64 function
|
--include the file io
|
||||||
require "resources.functions.base64";
|
local file = require "resources.functions.file"
|
||||||
|
|
||||||
--base64 encode the file
|
-- build full path to file
|
||||||
if (file_exists(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext)) then
|
local full_path = voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext
|
||||||
--get the base
|
|
||||||
local f = io.open(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext, "rb");
|
if file_exists(full_path) then
|
||||||
local file_content = f:read("*all");
|
--read file content as base64 string
|
||||||
f:close();
|
message_base64 = assert(file.read_base64(full_path));
|
||||||
message_base64 = base64.encode(file_content);
|
|
||||||
--freeswitch.consoleLog("notice", "[voicemail] ".. message_base64 .. "\n");
|
--freeswitch.consoleLog("notice", "[voicemail] ".. message_base64 .. "\n");
|
||||||
|
|
||||||
--delete the file
|
--delete the file
|
||||||
os.remove(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext);
|
os.remove(full_path);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -407,13 +406,10 @@
|
||||||
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
||||||
end
|
end
|
||||||
if (storage_type == "base64") then
|
if (storage_type == "base64") then
|
||||||
array = explode("://", database["system"]);
|
local Database = require "resources.functions.database"
|
||||||
local luasql = require "luasql.postgres";
|
local dbh = Database.new('system', 'base64');
|
||||||
local env = assert (luasql.postgres());
|
dbh:query(sql);
|
||||||
local db = env:connect(array[2]);
|
dbh:release();
|
||||||
res, serr = db:execute(sql);
|
|
||||||
db:close();
|
|
||||||
env:close();
|
|
||||||
else
|
else
|
||||||
dbh:query(sql);
|
dbh:query(sql);
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@
|
||||||
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
-- POSSIBILITY OF SUCH DAMAGE.
|
-- POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
local Database = require "resources.functions.database"
|
||||||
|
|
||||||
--define a function to choose the greeting
|
--define a function to choose the greeting
|
||||||
function choose_greeting()
|
function choose_greeting()
|
||||||
|
|
||||||
|
|
@ -87,6 +89,8 @@
|
||||||
|
|
||||||
--get the greeting from the database
|
--get the greeting from the database
|
||||||
if (storage_type == "base64") then
|
if (storage_type == "base64") then
|
||||||
|
local dbh = Database.new('system', 'base64/read')
|
||||||
|
|
||||||
sql = [[SELECT * FROM v_voicemail_greetings
|
sql = [[SELECT * FROM v_voicemail_greetings
|
||||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||||
AND voicemail_id = ']].. voicemail_id.. [['
|
AND voicemail_id = ']].. voicemail_id.. [['
|
||||||
|
|
@ -95,19 +99,20 @@
|
||||||
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
||||||
end
|
end
|
||||||
status = dbh:query(sql, function(row)
|
status = dbh:query(sql, function(row)
|
||||||
--add functions
|
|
||||||
require "resources.functions.base64";
|
|
||||||
|
|
||||||
--set the voicemail message path
|
--set the voicemail message path
|
||||||
greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext;
|
greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext;
|
||||||
|
|
||||||
--save the greeting to the file system
|
--save the greeting to the file system
|
||||||
if (string.len(row["greeting_base64"]) > 32) then
|
if (string.len(row["greeting_base64"]) > 32) then
|
||||||
local file = io.open(greeting_location, "w");
|
--include the file io
|
||||||
file:write(base64.decode(row["greeting_base64"]));
|
local file = require "resources.functions.file"
|
||||||
file:close();
|
|
||||||
|
--write decoded string to file
|
||||||
|
assert(file.write_base64(greeting_location, row["greeting_base64"]));
|
||||||
end
|
end
|
||||||
end);
|
end);
|
||||||
|
|
||||||
|
dbh:release()
|
||||||
elseif (storage_type == "http_cache") then
|
elseif (storage_type == "http_cache") then
|
||||||
greeting_location = storage_path.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext;
|
greeting_location = storage_path.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext;
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@
|
||||||
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
-- POSSIBILITY OF SUCH DAMAGE.
|
-- POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
local Database = require "resources.functions.database"
|
||||||
|
|
||||||
--define function to listen to the recording
|
--define function to listen to the recording
|
||||||
function listen_to_recording (message_number, uuid, created_epoch, caller_id_name, caller_id_number)
|
function listen_to_recording (message_number, uuid, created_epoch, caller_id_name, caller_id_number)
|
||||||
|
|
||||||
|
|
@ -72,6 +74,8 @@
|
||||||
end
|
end
|
||||||
--get the recordings from the database
|
--get the recordings from the database
|
||||||
if (storage_type == "base64") then
|
if (storage_type == "base64") then
|
||||||
|
local dbh = Database.new('system', 'base64/read')
|
||||||
|
|
||||||
sql = [[SELECT * FROM v_voicemail_messages
|
sql = [[SELECT * FROM v_voicemail_messages
|
||||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||||
AND voicemail_message_uuid = ']].. uuid.. [[' ]];
|
AND voicemail_message_uuid = ']].. uuid.. [[' ]];
|
||||||
|
|
@ -79,9 +83,6 @@
|
||||||
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n");
|
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n");
|
||||||
end
|
end
|
||||||
status = dbh:query(sql, function(row)
|
status = dbh:query(sql, function(row)
|
||||||
--add functions
|
|
||||||
require "resources.functions.base64";
|
|
||||||
|
|
||||||
--set the voicemail message path
|
--set the voicemail message path
|
||||||
mkdir(voicemail_dir.."/"..voicemail_id);
|
mkdir(voicemail_dir.."/"..voicemail_id);
|
||||||
message_intro_location = voicemail_dir.."/"..voicemail_id.."/intro_"..uuid.."."..vm_message_ext;
|
message_intro_location = voicemail_dir.."/"..voicemail_id.."/intro_"..uuid.."."..vm_message_ext;
|
||||||
|
|
@ -94,11 +95,14 @@
|
||||||
file:close();
|
file:close();
|
||||||
end
|
end
|
||||||
if (string.len(row["message_base64"]) > 32) then
|
if (string.len(row["message_base64"]) > 32) then
|
||||||
local file = io.open(message_location, "w");
|
--include the file io
|
||||||
file:write(base64.decode(row["message_base64"]));
|
local file = require "resources.functions.file"
|
||||||
file:close();
|
|
||||||
|
--write decoded string to file
|
||||||
|
assert(file.write_base64(message_location, row["message_base64"]));
|
||||||
end
|
end
|
||||||
end);
|
end);
|
||||||
|
dbh:release()
|
||||||
elseif (storage_type == "http_cache") then
|
elseif (storage_type == "http_cache") then
|
||||||
message_location = storage_path.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext;
|
message_location = storage_path.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext;
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@
|
||||||
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
-- POSSIBILITY OF SUCH DAMAGE.
|
-- POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
local Database = require"resources.functions.database"
|
||||||
|
|
||||||
--play the greeting
|
--play the greeting
|
||||||
function play_greeting()
|
function play_greeting()
|
||||||
--voicemail prompt
|
--voicemail prompt
|
||||||
|
|
@ -43,6 +45,8 @@
|
||||||
|
|
||||||
--get the greeting from the database
|
--get the greeting from the database
|
||||||
if (storage_type == "base64") then
|
if (storage_type == "base64") then
|
||||||
|
local dbh = Database.new('system', 'base64/read')
|
||||||
|
|
||||||
sql = [[SELECT * FROM v_voicemail_greetings
|
sql = [[SELECT * FROM v_voicemail_greetings
|
||||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||||
AND voicemail_id = ']].. voicemail_id.. [['
|
AND voicemail_id = ']].. voicemail_id.. [['
|
||||||
|
|
@ -50,29 +54,33 @@
|
||||||
if (debug["sql"]) then
|
if (debug["sql"]) then
|
||||||
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
||||||
end
|
end
|
||||||
|
local saved
|
||||||
status = dbh:query(sql, function(row)
|
status = dbh:query(sql, function(row)
|
||||||
--add functions
|
|
||||||
require "resources.functions.base64";
|
|
||||||
|
|
||||||
--set the voicemail message path
|
--set the voicemail message path
|
||||||
mkdir(voicemail_dir.."/"..voicemail_id);
|
mkdir(voicemail_dir.."/"..voicemail_id);
|
||||||
greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext;
|
greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext;
|
||||||
|
|
||||||
--if not found, save greeting to local file system
|
--if not found, save greeting to local file system
|
||||||
--if (not file_exists(greeting_location)) then
|
--saved = file_exists(greeting_location)
|
||||||
|
--if not saved then
|
||||||
if (string.len(row["greeting_base64"]) > 32) then
|
if (string.len(row["greeting_base64"]) > 32) then
|
||||||
local file = io.open(greeting_location, "w");
|
--include the file io
|
||||||
file:write(base64.decode(row["greeting_base64"]));
|
local file = require "resources.functions.file"
|
||||||
file:close();
|
|
||||||
|
--write decoded string to file
|
||||||
|
saved = file.write_base64(greeting_location, row["greeting_base64"]);
|
||||||
end
|
end
|
||||||
--end
|
--end
|
||||||
|
end);
|
||||||
|
dbh:release();
|
||||||
|
|
||||||
|
if saved then
|
||||||
--play the greeting
|
--play the greeting
|
||||||
session:execute("playback",voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
session:execute("playback",voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
||||||
|
|
||||||
--delete the greeting (retain local for better responsiveness)
|
--delete the greeting (retain local for better responsiveness)
|
||||||
--os.remove(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
--os.remove(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
||||||
end);
|
end
|
||||||
elseif (storage_type == "http_cache") then
|
elseif (storage_type == "http_cache") then
|
||||||
session:execute("playback",storage_path.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
session:execute("playback",storage_path.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -82,13 +82,11 @@
|
||||||
|
|
||||||
--if base64, encode file
|
--if base64, encode file
|
||||||
if (storage_type == "base64") then
|
if (storage_type == "base64") then
|
||||||
--include the base64 function
|
--include the file io
|
||||||
require "resources.functions.base64";
|
local file = require "resources.functions.file"
|
||||||
--base64 encode the file
|
|
||||||
local f = io.open(real_file, "rb");
|
--read file content as base64 string
|
||||||
local file_content = f:read("*all");
|
greeting_base64 = assert(file.read_base64(real_file));
|
||||||
f:close();
|
|
||||||
greeting_base64 = base64.encode(file_content);
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--delete the previous recording
|
--delete the previous recording
|
||||||
|
|
@ -134,13 +132,10 @@
|
||||||
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
||||||
end
|
end
|
||||||
if (storage_type == "base64") then
|
if (storage_type == "base64") then
|
||||||
array = explode("://", database["system"]);
|
local Database = require "resources.functions.database"
|
||||||
local luasql = require "luasql.postgres";
|
local dbh = Database.new('system', 'base64');
|
||||||
local env = assert (luasql.postgres());
|
dbh:query(sql);
|
||||||
local db = env:connect(array[2]);
|
dbh:release();
|
||||||
res, serr = db:execute(sql);
|
|
||||||
db:close();
|
|
||||||
env:close();
|
|
||||||
else
|
else
|
||||||
dbh:query(sql);
|
dbh:query(sql);
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -43,9 +43,6 @@
|
||||||
|
|
||||||
--record and save the file
|
--record and save the file
|
||||||
if (storage_type == "base64") then
|
if (storage_type == "base64") then
|
||||||
--include the base64 function
|
|
||||||
require "resources.functions.base64";
|
|
||||||
|
|
||||||
--set the location
|
--set the location
|
||||||
voicemail_name_location = voicemail_dir.."/"..voicemail_id.."/recorded_name.wav";
|
voicemail_name_location = voicemail_dir.."/"..voicemail_id.."/recorded_name.wav";
|
||||||
|
|
||||||
|
|
@ -58,10 +55,11 @@
|
||||||
freeswitch.consoleLog("notice", "[recordings] ".. storage_type .. "\n");
|
freeswitch.consoleLog("notice", "[recordings] ".. storage_type .. "\n");
|
||||||
|
|
||||||
--base64 encode the file
|
--base64 encode the file
|
||||||
local f = io.open(voicemail_name_location, "rb");
|
--include the file io
|
||||||
local file_content = f:read("*all");
|
local file = require "resources.functions.file"
|
||||||
f:close();
|
|
||||||
voicemail_name_base64 = base64.encode(file_content);
|
--read file content as base64 string
|
||||||
|
voicemail_name_base64 = assert(file.read_base64(voicemail_name_location));
|
||||||
|
|
||||||
--update the voicemail name
|
--update the voicemail name
|
||||||
sql = "UPDATE v_voicemails ";
|
sql = "UPDATE v_voicemails ";
|
||||||
|
|
@ -72,13 +70,10 @@
|
||||||
freeswitch.consoleLog("notice", "[recording] SQL: " .. sql .. "\n");
|
freeswitch.consoleLog("notice", "[recording] SQL: " .. sql .. "\n");
|
||||||
end
|
end
|
||||||
if (storage_type == "base64") then
|
if (storage_type == "base64") then
|
||||||
array = explode("://", database["system"]);
|
local Database = require "resources.functions.database"
|
||||||
local luasql = require "luasql.postgres";
|
local dbh = Database.new('system', 'base64');
|
||||||
local env = assert (luasql.postgres());
|
dbh:query(sql);
|
||||||
local dbh = env:connect(array[2]);
|
dbh:release();
|
||||||
res, serr = dbh:execute(sql);
|
|
||||||
dbh:close();
|
|
||||||
env:close();
|
|
||||||
else
|
else
|
||||||
dbh:query(sql);
|
dbh:query(sql);
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,12 @@
|
||||||
--include languages file
|
--include languages file
|
||||||
local Text = require "resources.functions.text"
|
local Text = require "resources.functions.text"
|
||||||
local text = Text.new("app.voicemail.app_languages")
|
local text = Text.new("app.voicemail.app_languages")
|
||||||
|
local dbh = dbh
|
||||||
|
|
||||||
|
--connect using other backend if needed
|
||||||
|
if storage_type == "base64" then
|
||||||
|
dbh = Database.new('system', 'base64/read')
|
||||||
|
end
|
||||||
|
|
||||||
--get voicemail message details
|
--get voicemail message details
|
||||||
sql = [[SELECT * FROM v_voicemail_messages
|
sql = [[SELECT * FROM v_voicemail_messages
|
||||||
|
|
@ -82,21 +88,25 @@
|
||||||
--message_priority = row["message_priority"];
|
--message_priority = row["message_priority"];
|
||||||
--get the recordings from the database
|
--get the recordings from the database
|
||||||
if (storage_type == "base64") then
|
if (storage_type == "base64") then
|
||||||
--add functions
|
|
||||||
require "resources.functions.base64";
|
|
||||||
|
|
||||||
--set the voicemail message path
|
--set the voicemail message path
|
||||||
message_location = voicemail_dir.."/"..id.."/msg_"..uuid.."."..vm_message_ext;
|
message_location = voicemail_dir.."/"..id.."/msg_"..uuid.."."..vm_message_ext;
|
||||||
|
|
||||||
--save the recording to the file system
|
--save the recording to the file system
|
||||||
if (string.len(row["message_base64"]) > 32) then
|
if (string.len(row["message_base64"]) > 32) then
|
||||||
local f = io.open(message_location, "w");
|
--include the file io
|
||||||
f:write(base64.decode(row["message_base64"]));
|
local file = require "resources.functions.file"
|
||||||
f:close();
|
|
||||||
|
--write decoded string to file
|
||||||
|
file.write_base64(message_location, row["message_base64"]);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end);
|
end);
|
||||||
|
|
||||||
|
--close temporary connection
|
||||||
|
if storage_type == "base64" then
|
||||||
|
dbh:release()
|
||||||
|
end
|
||||||
|
|
||||||
--format the message length and date
|
--format the message length and date
|
||||||
message_length_formatted = format_seconds(message_length);
|
message_length_formatted = format_seconds(message_length);
|
||||||
if (debug["info"]) then
|
if (debug["info"]) then
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@
|
||||||
--get the ivr name
|
--get the ivr name
|
||||||
ivr_menu_uuid = params:getHeader("Menu-Name");
|
ivr_menu_uuid = params:getHeader("Menu-Name");
|
||||||
|
|
||||||
|
local log = require "resources.functions.log".ivr_menu
|
||||||
|
|
||||||
--get the cache
|
--get the cache
|
||||||
if (trim(api:execute("module_exists", "mod_memcache")) == "true") then
|
if (trim(api:execute("module_exists", "mod_memcache")) == "true") then
|
||||||
XML_STRING = trim(api:execute("memcache", "get configuration:ivr.conf:" .. ivr_menu_uuid));
|
XML_STRING = trim(api:execute("memcache", "get configuration:ivr.conf:" .. ivr_menu_uuid));
|
||||||
|
|
@ -36,9 +38,11 @@
|
||||||
|
|
||||||
--set the cache
|
--set the cache
|
||||||
if (XML_STRING == "-ERR NOT FOUND" or XML_STRING == "-ERR CONNECTION FAILURE") then
|
if (XML_STRING == "-ERR NOT FOUND" or XML_STRING == "-ERR CONNECTION FAILURE") then
|
||||||
|
local Database = require "resources.functions.database"
|
||||||
|
local Settings = require "resources.functions.lazy_settings"
|
||||||
|
|
||||||
--connect to the database
|
--connect to the database
|
||||||
require "resources.functions.database_handle";
|
local dbh = Database.new('system');
|
||||||
dbh = database_handle('system');
|
|
||||||
|
|
||||||
--exits the script if we didn't connect properly
|
--exits the script if we didn't connect properly
|
||||||
assert(dbh:connected());
|
assert(dbh:connected());
|
||||||
|
|
@ -77,112 +81,73 @@
|
||||||
ivr_menu_description = row["ivr_menu_description"];
|
ivr_menu_description = row["ivr_menu_description"];
|
||||||
end);
|
end);
|
||||||
|
|
||||||
|
local settings = Settings.new(dbh, domain_name, domain_uuid)
|
||||||
|
local storage_type = settings:get('recordings', 'storage_type', 'text')
|
||||||
|
|
||||||
--get the recordings from the database
|
--get the recordings from the database
|
||||||
ivr_menu_greet_long_is_base64 = false;
|
ivr_menu_greet_long_is_base64 = false;
|
||||||
ivr_menu_greet_short_is_base64 = false;
|
ivr_menu_greet_short_is_base64 = false;
|
||||||
ivr_menu_invalid_sound_is_base64 = false;
|
ivr_menu_invalid_sound_is_base64 = false;
|
||||||
ivr_menu_exit_sound_is_base64 = false;
|
ivr_menu_exit_sound_is_base64 = false;
|
||||||
if (settings.recordings.storage_type == "base64") then
|
if (storage_type == "base64") then
|
||||||
|
--include the file io
|
||||||
|
local file = require "resources.functions.file"
|
||||||
|
|
||||||
|
--connect to db
|
||||||
|
local dbh = Database.new('system', 'base64/read');
|
||||||
|
|
||||||
|
--base path for recordings
|
||||||
|
local base_path = recordings_dir.."/"..domain_name
|
||||||
|
|
||||||
|
--function to get recording to local fs
|
||||||
|
local function load_record(name)
|
||||||
|
local path, is_base64 = base_path .. "/" .. name
|
||||||
|
|
||||||
|
if not file_exists(path) then
|
||||||
|
local sql = "SELECT recording_base64 FROM v_recordings " ..
|
||||||
|
"WHERE domain_uuid = '" .. domain_uuid .. "' " ..
|
||||||
|
"AND recording_filename = '" .. name .. "' "
|
||||||
|
if (debug["sql"]) then
|
||||||
|
freeswitch.consoleLog("notice", "[ivr_menu] SQL: "..sql.."\n");
|
||||||
|
end
|
||||||
|
|
||||||
|
dbh:query(sql, function(row)
|
||||||
|
--get full path to recording
|
||||||
|
is_base64, name = true, path
|
||||||
|
|
||||||
|
--save the recording to the file system
|
||||||
|
if #row.recording_base64 > 32 then
|
||||||
|
file.write_base64(path, row.recording_base64);
|
||||||
|
end
|
||||||
|
end);
|
||||||
|
else
|
||||||
|
name = path
|
||||||
|
end
|
||||||
|
return name, is_base64
|
||||||
|
end
|
||||||
|
|
||||||
--greet long
|
--greet long
|
||||||
if (string.len(ivr_menu_greet_long) > 1) then
|
if #ivr_menu_greet_long > 1 then
|
||||||
if (not file_exists(recordings_dir.."/"..domain_name.."/"..ivr_menu_greet_long)) then
|
ivr_menu_greet_long, ivr_menu_greet_long_is_base64 = load_record(ivr_menu_greet_long)
|
||||||
sql = [[SELECT recording_base64 FROM v_recordings
|
|
||||||
WHERE domain_uuid = ']]..domain_uuid..[['
|
|
||||||
AND recording_filename = ']]..ivr_menu_greet_long..[[' ]];
|
|
||||||
if (debug["sql"]) then
|
|
||||||
freeswitch.consoleLog("notice", "[ivr_menu] SQL: "..sql.."\n");
|
|
||||||
end
|
|
||||||
status = dbh:query(sql, function(row)
|
|
||||||
--add functions
|
|
||||||
require "resources.functions.base64";
|
|
||||||
--add the path to filename
|
|
||||||
ivr_menu_greet_long = recordings_dir.."/"..domain_name.."/"..ivr_menu_greet_long;
|
|
||||||
ivr_menu_greet_long_is_base64 = true;
|
|
||||||
--save the recording to the file system
|
|
||||||
if (string.len(row["recording_base64"]) > 32) then
|
|
||||||
local file = io.open(ivr_menu_greet_long, "w");
|
|
||||||
file:write(base64.decode(row["recording_base64"]));
|
|
||||||
file:write(row["recording_base64"]);
|
|
||||||
file:close();
|
|
||||||
end
|
|
||||||
end);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
--greet short
|
|
||||||
if (string.len(ivr_menu_greet_short) > 1) then
|
|
||||||
if (not file_exists(recordings_dir.."/"..domain_name.."/"..ivr_menu_greet_short)) then
|
|
||||||
sql = [[SELECT * FROM v_recordings
|
|
||||||
WHERE domain_uuid = ']]..domain_uuid..[['
|
|
||||||
AND recording_filename = ']]..ivr_menu_greet_short..[[' ]];
|
|
||||||
if (debug["sql"]) then
|
|
||||||
freeswitch.consoleLog("notice", "[ivr_menu] SQL: "..sql.."\n");
|
|
||||||
end
|
|
||||||
status = dbh:query(sql, function(row)
|
|
||||||
--add functions
|
|
||||||
require "resources.functions.base64";
|
|
||||||
--add the path to filename
|
|
||||||
ivr_menu_greet_short = recordings_dir.."/"..domain_name.."/"..ivr_menu_greet_short;
|
|
||||||
ivr_menu_greet_short_is_base64 = true;
|
|
||||||
--save the recording to the file system
|
|
||||||
if (string.len(row["recording_base64"]) > 32) then
|
|
||||||
local file = io.open(ivr_menu_greet_short, "w");
|
|
||||||
file:write(base64.decode(row["recording_base64"]));
|
|
||||||
file:close();
|
|
||||||
end
|
|
||||||
end);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
--invalid sound
|
|
||||||
if (string.len(ivr_menu_invalid_sound) > 1) then
|
|
||||||
if (not file_exists(recordings_dir.."/"..domain_name.."/"..ivr_menu_invalid_sound)) then
|
|
||||||
sql = [[SELECT * FROM v_recordings
|
|
||||||
WHERE domain_uuid = ']]..domain_uuid..[['
|
|
||||||
AND recording_filename = ']]..ivr_menu_invalid_sound..[[' ]];
|
|
||||||
if (debug["sql"]) then
|
|
||||||
freeswitch.consoleLog("notice", "[ivr_menu] SQL: "..sql.."\n");
|
|
||||||
end
|
|
||||||
status = dbh:query(sql, function(row)
|
|
||||||
--add functions
|
|
||||||
require "resources.functions.base64";
|
|
||||||
--add the path to filename
|
|
||||||
ivr_menu_invalid_sound = recordings_dir..domain_name.."/".."/"..ivr_menu_invalid_sound;
|
|
||||||
ivr_menu_invalid_sound_is_base64 = true;
|
|
||||||
--save the recording to the file system
|
|
||||||
if (string.len(row["recording_base64"]) > 32) then
|
|
||||||
local file = io.open(ivr_menu_invalid_sound, "w");
|
|
||||||
file:write(base64.decode(row["recording_base64"]));
|
|
||||||
file:close();
|
|
||||||
end
|
|
||||||
end);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
--exit sound
|
|
||||||
if (string.len(ivr_menu_exit_sound) > 1) then
|
|
||||||
if (not file_exists(recordings_dir.."/"..domain_name.."/"..ivr_menu_exit_sound)) then
|
|
||||||
sql = [[SELECT * FROM v_recordings
|
|
||||||
WHERE domain_uuid = ']]..domain_uuid..[['
|
|
||||||
AND recording_filename = ']]..ivr_menu_exit_sound..[[' ]];
|
|
||||||
if (debug["sql"]) then
|
|
||||||
freeswitch.consoleLog("notice", "[ivr_menu] SQL: "..sql.."\n");
|
|
||||||
end
|
|
||||||
status = dbh:query(sql, function(row)
|
|
||||||
--add functions
|
|
||||||
require "resources.functions.base64";
|
|
||||||
--add the path to filename
|
|
||||||
ivr_menu_exit_sound = recordings_dir.."/"..domain_name.."/"..ivr_menu_exit_sound;
|
|
||||||
ivr_menu_exit_sound_is_base64 = true;
|
|
||||||
--save the recording to the file system
|
|
||||||
if (string.len(row["recording_base64"]) > 32) then
|
|
||||||
local file = io.open(ivr_menu_exit_sound, "w");
|
|
||||||
file:write(base64.decode(row["recording_base64"]));
|
|
||||||
file:close();
|
|
||||||
end
|
|
||||||
end);
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif (settings.recordings.storage_type == "http_cache") then
|
--greet short
|
||||||
|
if #ivr_menu_greet_short > 1 then
|
||||||
|
ivr_menu_greet_short, ivr_menu_greet_short_is_base64 = load_record(ivr_menu_greet_short)
|
||||||
|
end
|
||||||
|
|
||||||
|
--invalid sound
|
||||||
|
if #ivr_menu_invalid_sound > 1 then
|
||||||
|
ivr_menu_invalid_sound, ivr_menu_invalid_sound_is_base64 = load_record(ivr_menu_invalid_sound)
|
||||||
|
end
|
||||||
|
|
||||||
|
--exit sound
|
||||||
|
if #ivr_menu_exit_sound > 1 then
|
||||||
|
ivr_menu_exit_sound, ivr_menu_exit_sound_is_base64 = load_record(ivr_menu_exit_sound)
|
||||||
|
end
|
||||||
|
|
||||||
|
dbh:release()
|
||||||
|
elseif (storage_type == "http_cache") then
|
||||||
--add the path to file name
|
--add the path to file name
|
||||||
ivr_menu_greet_long = storage_path.."/"..ivr_menu_greet_long;
|
ivr_menu_greet_long = storage_path.."/"..ivr_menu_greet_long;
|
||||||
ivr_menu_greet_short = storage_path.."/"..ivr_menu_greet_short;
|
ivr_menu_greet_short = storage_path.."/"..ivr_menu_greet_short;
|
||||||
|
|
@ -273,7 +238,7 @@
|
||||||
ivr_menu_option_action = r.ivr_menu_option_action
|
ivr_menu_option_action = r.ivr_menu_option_action
|
||||||
ivr_menu_option_param = r.ivr_menu_option_param
|
ivr_menu_option_param = r.ivr_menu_option_param
|
||||||
ivr_menu_option_description = r.ivr_menu_option_description
|
ivr_menu_option_description = r.ivr_menu_option_description
|
||||||
table.insert(xml, [[<entry action="]]..ivr_menu_option_action..[[" digits="]]..ivr_menu_option_digits..[[" param="]]..ivr_menu_option_param..[[" description="]]..ivr_menu_option_description..[["/>]]);
|
table.insert(xml, [[ <entry action="]]..ivr_menu_option_action..[[" digits="]]..ivr_menu_option_digits..[[" param="]]..ivr_menu_option_param..[[" description="]]..ivr_menu_option_description..[["/>]]);
|
||||||
end);
|
end);
|
||||||
|
|
||||||
--close the extension tag if it was left open
|
--close the extension tag if it was left open
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@
|
||||||
end
|
end
|
||||||
status = dbh:query(sql, function(rows)
|
status = dbh:query(sql, function(rows)
|
||||||
domain_uuid = string.lower(rows["domain_uuid"]);
|
domain_uuid = string.lower(rows["domain_uuid"]);
|
||||||
end);
|
end);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -226,6 +226,9 @@
|
||||||
if (row.first_name) then
|
if (row.first_name) then
|
||||||
--play the recorded name
|
--play the recorded name
|
||||||
if (storage_type == "base64") then
|
if (storage_type == "base64") then
|
||||||
|
local Database = require "resources.functions.database";
|
||||||
|
local dbh = Database.new('system', 'base64/read')
|
||||||
|
|
||||||
sql = [[SELECT * FROM v_voicemails
|
sql = [[SELECT * FROM v_voicemails
|
||||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||||
AND voicemail_id = ']].. row.extension.. [[' ]];
|
AND voicemail_id = ']].. row.extension.. [[' ]];
|
||||||
|
|
@ -233,17 +236,16 @@
|
||||||
freeswitch.consoleLog("notice", "[directory] SQL: " .. sql .. "\n");
|
freeswitch.consoleLog("notice", "[directory] SQL: " .. sql .. "\n");
|
||||||
end
|
end
|
||||||
status = dbh:query(sql, function(field)
|
status = dbh:query(sql, function(field)
|
||||||
--add functions
|
|
||||||
require "resources.functions.base64";
|
|
||||||
|
|
||||||
--set the voicemail message path
|
--set the voicemail message path
|
||||||
file_location = voicemail_dir.."/"..row.extension.."/recorded_name.wav";
|
file_location = voicemail_dir.."/"..row.extension.."/recorded_name.wav";
|
||||||
|
|
||||||
--save the recording to the file system
|
--save the recording to the file system
|
||||||
if (string.len(field["voicemail_name_base64"]) > 32) then
|
if (string.len(field["voicemail_name_base64"]) > 32) then
|
||||||
local file = io.open(file_location, "w");
|
--include the file io
|
||||||
file:write(base64.decode(field["voicemail_name_base64"]));
|
local file = require "resources.functions.file"
|
||||||
file:close();
|
|
||||||
|
--write decoded string to file
|
||||||
|
file.write_base64(file_location, field["voicemail_name_base64"]);
|
||||||
end
|
end
|
||||||
|
|
||||||
--play the recorded name
|
--play the recorded name
|
||||||
|
|
@ -266,6 +268,7 @@
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end);
|
end);
|
||||||
|
dbh:release()
|
||||||
elseif (storage_type == "http_cache") then
|
elseif (storage_type == "http_cache") then
|
||||||
file_location = storage_path.."/"..row.extension.."/recorded_name.wav";
|
file_location = storage_path.."/"..row.extension.."/recorded_name.wav";
|
||||||
if (file_exists(file_location)) then
|
if (file_exists(file_location)) then
|
||||||
|
|
|
||||||
|
|
@ -293,14 +293,11 @@
|
||||||
end
|
end
|
||||||
|
|
||||||
if (storage_type == "base64") then
|
if (storage_type == "base64") then
|
||||||
--include the base64 function
|
--include the file io
|
||||||
require "resources.functions.base64";
|
local file = require "resources.functions.file"
|
||||||
|
|
||||||
--base64 encode the file
|
--read file content as base64 string
|
||||||
local f = io.open(fax_file, "rb");
|
fax_base64 = assert(file.read_base64(fax_file));
|
||||||
local file_content = f:read("*all");
|
|
||||||
f:close();
|
|
||||||
fax_base64 = base64.encode(file_content);
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local sql = {}
|
local sql = {}
|
||||||
|
|
@ -352,13 +349,10 @@
|
||||||
freeswitch.consoleLog("notice", "[FAX] SQL: " .. sql .. "\n");
|
freeswitch.consoleLog("notice", "[FAX] SQL: " .. sql .. "\n");
|
||||||
--end
|
--end
|
||||||
if (storage_type == "base64") then
|
if (storage_type == "base64") then
|
||||||
array = explode("://", database["system"]);
|
local Database = require "resources.functions.database"
|
||||||
local luasql = require "luasql.postgres";
|
local dbh = Database.new('system', 'base64');
|
||||||
local env = assert (luasql.postgres());
|
dbh:query(sql);
|
||||||
local dbh = env:connect(array[2]);
|
dbh:release();
|
||||||
res, serr = dbh:execute(sql);
|
|
||||||
dbh:close();
|
|
||||||
env:close();
|
|
||||||
else
|
else
|
||||||
result = dbh:query(sql);
|
result = dbh:query(sql);
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,8 @@
|
||||||
--include config.lua
|
--include config.lua
|
||||||
require "resources.functions.config";
|
require "resources.functions.config";
|
||||||
|
|
||||||
--connect to the database
|
--include Database class
|
||||||
require "resources.functions.database_handle";
|
local Database = require "resources.functions.database";
|
||||||
dbh = database_handle('system');
|
|
||||||
|
|
||||||
--get logger
|
--get logger
|
||||||
local log = require "resources.functions.log".ivr_menu
|
local log = require "resources.functions.log".ivr_menu
|
||||||
|
|
@ -55,6 +54,9 @@
|
||||||
|
|
||||||
local recordings_dir = recordings_dir .. "/" .. domain_name
|
local recordings_dir = recordings_dir .. "/" .. domain_name
|
||||||
|
|
||||||
|
--connect to the database
|
||||||
|
dbh = Database.new('system');
|
||||||
|
|
||||||
--settings
|
--settings
|
||||||
require "resources.functions.settings";
|
require "resources.functions.settings";
|
||||||
settings = settings(domain_uuid);
|
settings = settings(domain_uuid);
|
||||||
|
|
@ -127,6 +129,9 @@
|
||||||
ivr_menu_cid_prefix = row["ivr_menu_cid_prefix"];
|
ivr_menu_cid_prefix = row["ivr_menu_cid_prefix"];
|
||||||
end);
|
end);
|
||||||
|
|
||||||
|
--disconnect from db
|
||||||
|
dbh:release()
|
||||||
|
|
||||||
--set the caller id name
|
--set the caller id name
|
||||||
if caller_id_name and #caller_id_name > 0 and ivr_menu_cid_prefix and #ivr_menu_cid_prefix > 0 then
|
if caller_id_name and #caller_id_name > 0 and ivr_menu_cid_prefix and #ivr_menu_cid_prefix > 0 then
|
||||||
caller_id_name = ivr_menu_cid_prefix .. "#" .. caller_id_name;
|
caller_id_name = ivr_menu_cid_prefix .. "#" .. caller_id_name;
|
||||||
|
|
@ -164,11 +169,12 @@
|
||||||
ivr_menu_invalid_sound_is_base64 = false;
|
ivr_menu_invalid_sound_is_base64 = false;
|
||||||
ivr_menu_exit_sound_is_base64 = false;
|
ivr_menu_exit_sound_is_base64 = false;
|
||||||
if (storage_type == "base64") then
|
if (storage_type == "base64") then
|
||||||
|
|
||||||
--add functions
|
--add functions
|
||||||
require "resources.functions.base64";
|
|
||||||
require "resources.functions.mkdir";
|
require "resources.functions.mkdir";
|
||||||
|
|
||||||
|
--connect to the database
|
||||||
|
local dbh = Database.new('system', 'base64/read')
|
||||||
|
|
||||||
--make sure the recordings directory exists
|
--make sure the recordings directory exists
|
||||||
mkdir(recordings_dir);
|
mkdir(recordings_dir);
|
||||||
|
|
||||||
|
|
@ -189,13 +195,16 @@
|
||||||
local is_base64
|
local is_base64
|
||||||
dbh:query(sql, function(row)
|
dbh:query(sql, function(row)
|
||||||
if #row.recording_base64 > 32 then
|
if #row.recording_base64 > 32 then
|
||||||
local file, err = io.open(full_path, "w");
|
--include the file io
|
||||||
if not file then
|
local file = require "resources.functions.file"
|
||||||
log.err("can not create file: "..full_path.."; Error - " .. tostring(err));
|
|
||||||
return
|
--write decoded string to file
|
||||||
end
|
local ok, err = file.write_base64(full_path, row.recording_base64);
|
||||||
file:write(base64.decode(row.recording_base64));
|
if not ok then
|
||||||
file:close();
|
log.err("can not create file: "..full_path.."; Error - " .. tostring(err));
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
is_base64 = true;
|
is_base64 = true;
|
||||||
end
|
end
|
||||||
end);
|
end);
|
||||||
|
|
@ -224,6 +233,8 @@
|
||||||
ivr_menu_exit_sound, ivr_menu_exit_sound_is_base64 = load_file(exit_sound_file_name)
|
ivr_menu_exit_sound, ivr_menu_exit_sound_is_base64 = load_file(exit_sound_file_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
dbh:release()
|
||||||
|
|
||||||
elseif (storage_type == "http_cache") then
|
elseif (storage_type == "http_cache") then
|
||||||
--add the path to file name
|
--add the path to file name
|
||||||
ivr_menu_greet_long = storage_path.."/"..ivr_menu_greet_long;
|
ivr_menu_greet_long = storage_path.."/"..ivr_menu_greet_long;
|
||||||
|
|
@ -317,6 +328,10 @@
|
||||||
log.notice("SQL: " .. sql);
|
log.notice("SQL: " .. sql);
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--connect to the database
|
||||||
|
local dbh = Database.new('system')
|
||||||
|
|
||||||
|
--select actions to execute
|
||||||
local actions = {}
|
local actions = {}
|
||||||
dbh:query(sql, function(row)
|
dbh:query(sql, function(row)
|
||||||
-- declare vars
|
-- declare vars
|
||||||
|
|
@ -371,6 +386,7 @@
|
||||||
-- we have unsupported IVR action
|
-- we have unsupported IVR action
|
||||||
log.warning("invalid action in ivr: " .. row.ivr_menu_option_action);
|
log.warning("invalid action in ivr: " .. row.ivr_menu_option_action);
|
||||||
end); --end results
|
end); --end results
|
||||||
|
dbh:release()
|
||||||
|
|
||||||
--execute
|
--execute
|
||||||
if #actions > 0 then
|
if #actions > 0 then
|
||||||
|
|
|
||||||
|
|
@ -126,8 +126,8 @@
|
||||||
|
|
||||||
--begin recording
|
--begin recording
|
||||||
if (storage_type == "base64") then
|
if (storage_type == "base64") then
|
||||||
--include the base64 function
|
--include the file io
|
||||||
require "resources.functions.base64";
|
local file = require "resources.functions.file"
|
||||||
|
|
||||||
--make the directory
|
--make the directory
|
||||||
mkdir(recordings_dir);
|
mkdir(recordings_dir);
|
||||||
|
|
@ -139,11 +139,8 @@
|
||||||
--show the storage type
|
--show the storage type
|
||||||
freeswitch.consoleLog("notice", "[recordings] ".. storage_type .. "\n");
|
freeswitch.consoleLog("notice", "[recordings] ".. storage_type .. "\n");
|
||||||
|
|
||||||
--base64 encode the file
|
--read file content as base64 string
|
||||||
local f = io.open(recordings_dir .."/".. recording_name, "rb");
|
recording_base64 = assert(file.read_base64(recordings_dir .. "/" .. recording_name));
|
||||||
local file_content = f:read("*all");
|
|
||||||
f:close();
|
|
||||||
recording_base64 = base64.encode(file_content);
|
|
||||||
|
|
||||||
elseif (storage_type == "http_cache") then
|
elseif (storage_type == "http_cache") then
|
||||||
freeswitch.consoleLog("notice", "[recordings] ".. storage_type .. " ".. storage_path .."\n");
|
freeswitch.consoleLog("notice", "[recordings] ".. storage_type .. " ".. storage_path .."\n");
|
||||||
|
|
@ -189,13 +186,10 @@
|
||||||
freeswitch.consoleLog("notice", "[recording] SQL: " .. sql .. "\n");
|
freeswitch.consoleLog("notice", "[recording] SQL: " .. sql .. "\n");
|
||||||
end
|
end
|
||||||
if (storage_type == "base64") then
|
if (storage_type == "base64") then
|
||||||
array = explode("://", database["system"]);
|
local Database = require "resources.functions.database"
|
||||||
local luasql = require "luasql.postgres";
|
local dbh = Database.new('system', 'base64');
|
||||||
local env = assert (luasql.postgres());
|
dbh:query(sql);
|
||||||
local dbh = env:connect(array[2]);
|
dbh:release();
|
||||||
res, serr = dbh:execute(sql);
|
|
||||||
dbh:close();
|
|
||||||
env:close();
|
|
||||||
else
|
else
|
||||||
dbh:query(sql);
|
dbh:query(sql);
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,70 +1,50 @@
|
||||||
--get the argv values
|
--get the argv values
|
||||||
script_name = argv[0];
|
local script_name = argv[0];
|
||||||
file_name = table.concat(argv, " ");
|
local file_name = table.concat(argv, " ");
|
||||||
freeswitch.consoleLog("notice", "[streamfile] file_name: " .. file_name .. "\n");
|
freeswitch.consoleLog("notice", "[streamfile] file_name: " .. file_name .. "\n");
|
||||||
|
|
||||||
--include config.lua
|
--include config.lua
|
||||||
require "resources.functions.config";
|
require "resources.functions.config";
|
||||||
|
|
||||||
--connect to the database
|
--load libraries
|
||||||
require "resources.functions.database_handle";
|
local Database = require "resources.functions.database";
|
||||||
dbh = database_handle('system');
|
local Settings = require "resources.functions.lazy_settings";
|
||||||
|
local file = require "resources.functions.file";
|
||||||
|
local log = require "resources.functions.log".streamfile;
|
||||||
|
|
||||||
--get the variables
|
--get the variables
|
||||||
domain_name = session:getVariable("domain_name");
|
local domain_name = session:getVariable("domain_name");
|
||||||
domain_uuid = session:getVariable("domain_uuid");
|
local domain_uuid = session:getVariable("domain_uuid");
|
||||||
|
|
||||||
--get the sounds dir, language, dialect and voice
|
--get the sounds dir, language, dialect and voice
|
||||||
sounds_dir = session:getVariable("sounds_dir");
|
local sounds_dir = session:getVariable("sounds_dir");
|
||||||
default_language = session:getVariable("default_language");
|
local default_language = session:getVariable("default_language") or 'en';
|
||||||
default_dialect = session:getVariable("default_dialect");
|
local default_dialect = session:getVariable("default_dialect") or 'us';
|
||||||
default_voice = session:getVariable("default_voice");
|
local default_voice = session:getVariable("default_voice") or 'callie';
|
||||||
if (not default_language) then default_language = 'en'; end
|
|
||||||
if (not default_dialect) then default_dialect = 'us'; end
|
|
||||||
if (not default_voice) then default_voice = 'callie'; end
|
|
||||||
|
|
||||||
--settings
|
|
||||||
require "resources.functions.settings";
|
|
||||||
settings = settings(domain_uuid);
|
|
||||||
storage_type = "";
|
|
||||||
storage_path = "";
|
|
||||||
if (settings['recordings'] ~= nil) then
|
|
||||||
if (settings['recordings']['storage_type'] ~= nil) then
|
|
||||||
if (settings['recordings']['storage_type']['text'] ~= nil) then
|
|
||||||
storage_type = settings['recordings']['storage_type']['text'];
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if (settings['recordings']['storage_path'] ~= nil) then
|
|
||||||
if (settings['recordings']['storage_path']['text'] ~= nil) then
|
|
||||||
storage_path = settings['recordings']['storage_path']['text'];
|
|
||||||
storage_path = storage_path:gsub("${domain_name}", domain_name);
|
|
||||||
storage_path = storage_path:gsub("${voicemail_id}", voicemail_id);
|
|
||||||
storage_path = storage_path:gsub("${voicemail_dir}", voicemail_dir);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if (not temp_dir) or (#temp_dir == 0) then
|
|
||||||
if (settings['server'] ~= nil) then
|
|
||||||
if (settings['server']['temp'] ~= nil) then
|
|
||||||
if (settings['server']['temp']['dir'] ~= nil) then
|
|
||||||
temp_dir = settings['server']['temp']['dir'];
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--set the recordings directory
|
--set the recordings directory
|
||||||
recordings_dir = recordings_dir .. "/"..domain_name;
|
local recordings_dir = recordings_dir .. "/" .. domain_name;
|
||||||
|
|
||||||
--check if a file exists
|
--parse file name
|
||||||
require "resources.functions.file_exists";
|
local file_name_only = file_name:match("([^/]+)$");
|
||||||
|
|
||||||
|
--settings
|
||||||
|
local dbh = Database.new('system');
|
||||||
|
local settings = Settings.new(dbh, domain_name, domain_uuid);
|
||||||
|
local storage_type = settings:get('recordings', 'storage_type', 'text') or '';
|
||||||
|
|
||||||
|
if (not temp_dir) or (#temp_dir == 0) then
|
||||||
|
temp_dir = settings:get('server', 'temp', 'dir') or '/tmp';
|
||||||
|
end
|
||||||
|
|
||||||
|
dbh:release()
|
||||||
|
|
||||||
--define the on_dtmf call back function
|
--define the on_dtmf call back function
|
||||||
|
-- luacheck: globals on_dtmf, ignore s arg
|
||||||
function on_dtmf(s, type, obj, arg)
|
function on_dtmf(s, type, obj, arg)
|
||||||
if (type == "dtmf") then
|
if (type == "dtmf") then
|
||||||
session:setVariable("dtmf_digits", obj['digit']);
|
session:setVariable("dtmf_digits", obj['digit']);
|
||||||
freeswitch.console_log("info", "[streamfile] dtmf digit: " .. obj['digit'] .. ", duration: " .. obj['duration'] .. "\n");
|
log.info("dtmf digit: " .. obj['digit'] .. ", duration: " .. obj['duration']);
|
||||||
if (obj['digit'] == "*") then
|
if (obj['digit'] == "*") then
|
||||||
return("false"); --return to previous
|
return("false"); --return to previous
|
||||||
elseif (obj['digit'] == "0") then
|
elseif (obj['digit'] == "0") then
|
||||||
|
|
@ -87,50 +67,43 @@
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--parse file name
|
|
||||||
file_name_only = file_name:match("([^/]+)$");
|
|
||||||
|
|
||||||
--if base64, get from db, create temp file
|
--if base64, get from db, create temp file
|
||||||
if (storage_type == "base64") then
|
if (storage_type == "base64") then
|
||||||
if (not file_exists(recordings_dir.."/"..file_name_only)) then
|
local full_path = recordings_dir .. "/" .. file_name_only
|
||||||
sql = [[SELECT * FROM v_recordings
|
if not file.exists(full_path) then
|
||||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
local sql = "SELECT recording_base64 FROM v_recordings "
|
||||||
AND recording_filename = ']].. file_name_only.. [[' ]];
|
.. "WHERE domain_uuid = '" .. domain_uuid .."'"
|
||||||
|
.. "AND recording_filename = '".. file_name_only.. "' ";
|
||||||
if (debug["sql"]) then
|
if (debug["sql"]) then
|
||||||
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n");
|
log.notice("SQL: " .. sql);
|
||||||
|
end
|
||||||
|
|
||||||
|
local dbh = Database.new('system', 'base64/read');
|
||||||
|
local recording_base64 = dbh:first_value(sql);
|
||||||
|
dbh:release();
|
||||||
|
|
||||||
|
if recording_base64 and #recording_base64 > 32 then
|
||||||
|
file_name = full_path;
|
||||||
|
file.write_base64(file_name, recording_base64);
|
||||||
end
|
end
|
||||||
status = dbh:query(sql, function(row)
|
|
||||||
--add functions
|
|
||||||
require "resources.functions.base64";
|
|
||||||
--add the path to filename
|
|
||||||
file_name = recordings_dir.."/"..file_name_only;
|
|
||||||
--save the recording to the file system
|
|
||||||
if (string.len(row["recording_base64"]) > 32) then
|
|
||||||
local file = io.open(file_name, "w");
|
|
||||||
file:write(base64.decode(row["recording_base64"]));
|
|
||||||
file:close();
|
|
||||||
end
|
|
||||||
end);
|
|
||||||
else
|
else
|
||||||
file_name = recordings_dir.."/"..file_name_only;
|
file_name = full_path;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--adjust file path
|
--adjust file path
|
||||||
if (not file_exists(file_name)) then
|
if not file.exists(file_name) then
|
||||||
if (file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..file_name_only)) then
|
file_name = file.exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..file_name_only)
|
||||||
file_name = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..file_name_only;
|
or file.exists(recordings_dir.."/"..file_name_only)
|
||||||
elseif (file_exists(recordings_dir.."/"..file_name_only)) then
|
or file_name
|
||||||
file_name = recordings_dir.."/"..file_name_only;
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--stream file if exists
|
--stream file if exists
|
||||||
if (session:ready()) then
|
if (session:ready()) then
|
||||||
session:answer();
|
session:answer();
|
||||||
slept = session:getVariable("slept");
|
local slept = session:getVariable("slept");
|
||||||
if (slept == nil or slept == "false") then
|
if (slept == nil or slept == "false") then
|
||||||
freeswitch.consoleLog("notice", "[ivr_menu] sleeping (1s)\n");
|
log.notice("sleeping (1s)");
|
||||||
session:sleep(1000);
|
session:sleep(1000);
|
||||||
if (slept == "false") then
|
if (slept == "false") then
|
||||||
session:setVariable("slept", "true");
|
session:setVariable("slept", "true");
|
||||||
|
|
@ -142,8 +115,8 @@
|
||||||
end
|
end
|
||||||
|
|
||||||
--if base64, remove temp file (increases responsiveness when files remain local)
|
--if base64, remove temp file (increases responsiveness when files remain local)
|
||||||
if (storage_type == "base64") then
|
-- if (storage_type == "base64") then
|
||||||
if (file_exists(file_name)) then
|
-- if (file.exists(file_name)) then
|
||||||
--os.remove(file_name);
|
-- file.remove(file_name);
|
||||||
end
|
-- end
|
||||||
end
|
-- end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue