Improve code to update the scripts directory.
This commit is contained in:
parent
6f9eb6ab29
commit
b8f9b423c7
|
|
@ -17,138 +17,133 @@
|
|||
|
||||
The Initial Developer of the Original Code is
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
Portions created by the Initial Developer are Copyright (C) 2008-2012
|
||||
Portions created by the Initial Developer are Copyright (C) 2008-2015
|
||||
the Initial Developer. All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
*/
|
||||
|
||||
if (strlen($_SESSION['switch']['scripts']['dir']) > 0) {
|
||||
if ($domains_processed == 1) {
|
||||
//if the resource scripts resource directory does not exist then create it
|
||||
if (!is_dir($_SESSION['switch']['scripts']['dir']."/resources")) {
|
||||
|
||||
if ($domains_processed == 1) {
|
||||
//process if the scripts directory exists
|
||||
if (strlen($_SESSION['switch']['scripts']['dir']) > 0) {
|
||||
//if the resource scripts resource directory does not exist then create it
|
||||
if (!is_dir($_SESSION['switch']['scripts']['dir']."/resources")) {
|
||||
mkdir($_SESSION['switch']['scripts']['dir']."/resources",0755,true);
|
||||
}
|
||||
|
||||
//copy the files and directories from resources/install
|
||||
$install = new install;
|
||||
$install->domain_uuid = $domain_uuid;
|
||||
$install->switch_scripts_dir = $_SESSION['switch']['scripts']['dir'];
|
||||
$install->copy_scripts();
|
||||
}
|
||||
|
||||
//update the software table
|
||||
$sql = "select count(*) as num_rows from v_software ";
|
||||
$prep_statement = $db->prepare($sql);
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row['num_rows'] == 0) {
|
||||
$sql = "insert into v_software ";
|
||||
$sql .= "(";
|
||||
$sql .= "software_uuid, ";
|
||||
$sql .= "software_name, ";
|
||||
$sql .= "software_url, ";
|
||||
$sql .= "software_version ";
|
||||
$sql .= ")";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "'".uuid()."', ";
|
||||
$sql .= "'FusionPBX', ";
|
||||
$sql .= "'www.fusionpbx.com', ";
|
||||
$sql .= "'".software_version()."' ";
|
||||
$sql .= ")";
|
||||
$db->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
}
|
||||
|
||||
//copy the files and directories from resources/install
|
||||
//require_once "resources/classes/install.php";
|
||||
$install = new install;
|
||||
$install->domain_uuid = $domain_uuid;
|
||||
$install->domain_name = $domain;
|
||||
//$install->switch_conf_dir = $_SESSION['switch']['conf']['dir'];
|
||||
$install->switch_scripts_dir = $_SESSION['switch']['scripts']['dir'];
|
||||
//$install->switch_sounds_dir = $_SESSION['switch']['sounds']['dir'];
|
||||
$install->copy_scripts();
|
||||
//$install->copy_sounds();
|
||||
//print_r($install->result);
|
||||
|
||||
//update the software table
|
||||
$sql = "select count(*) as num_rows from v_software ";
|
||||
$prep_statement = $db->prepare($sql);
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row['num_rows'] == 0) {
|
||||
$sql = "insert into v_software ";
|
||||
$sql .= "(";
|
||||
$sql .= "software_uuid, ";
|
||||
$sql .= "software_name, ";
|
||||
$sql .= "software_url, ";
|
||||
$sql .= "software_version ";
|
||||
$sql .= ")";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "'".uuid()."', ";
|
||||
$sql .= "'FusionPBX', ";
|
||||
$sql .= "'www.fusionpbx.com', ";
|
||||
$sql .= "'".software_version()."' ";
|
||||
$sql .= ")";
|
||||
$db->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
}
|
||||
else {
|
||||
$sql = "update v_software ";
|
||||
$sql .= "set software_version = '".software_version()."' ";
|
||||
$db->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
}
|
||||
unset($prep_statement, $row);
|
||||
else {
|
||||
$sql = "update v_software ";
|
||||
$sql .= "set software_version = '".software_version()."' ";
|
||||
$db->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
}
|
||||
unset($prep_statement, $row);
|
||||
}
|
||||
|
||||
//ensure the login message is set, if new message exists
|
||||
$sql = "select count(*) as num_rows from v_default_settings ";
|
||||
$sql .= "where default_setting_category = 'login' ";
|
||||
$sql .= "and default_setting_subcategory = 'message' ";
|
||||
$sql .= "and default_setting_name = 'text' ";
|
||||
$prep_statement = $db->prepare($sql);
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
|
||||
unset($prep_statement);
|
||||
if ($row['num_rows'] == 0) {
|
||||
//ensure the login message is set, if new message exists
|
||||
$sql = "select count(*) as num_rows from v_default_settings ";
|
||||
$sql .= "where default_setting_category = 'login' ";
|
||||
$sql .= "and default_setting_subcategory = 'message' ";
|
||||
$sql .= "and default_setting_name = 'text' ";
|
||||
$prep_statement = $db->prepare($sql);
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
|
||||
unset($prep_statement);
|
||||
if ($row['num_rows'] == 0) {
|
||||
|
||||
// insert message
|
||||
$sql = "insert into v_default_settings ";
|
||||
$sql .= "(";
|
||||
$sql .= "default_setting_uuid, ";
|
||||
$sql .= "default_setting_category, ";
|
||||
$sql .= "default_setting_subcategory, ";
|
||||
$sql .= "default_setting_name, ";
|
||||
$sql .= "default_setting_value, ";
|
||||
$sql .= "default_setting_enabled, ";
|
||||
$sql .= "default_setting_description ";
|
||||
$sql .= ")";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "'".uuid()."', ";
|
||||
$sql .= "'login', ";
|
||||
$sql .= "'message', ";
|
||||
$sql .= "'text', ";
|
||||
$sql .= "'".$text['login-message_text']."', ";
|
||||
$sql .= "'true', ";
|
||||
$sql .= "'' ";
|
||||
$sql .= ")";
|
||||
$db->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
// insert message
|
||||
$sql = "insert into v_default_settings ";
|
||||
$sql .= "(";
|
||||
$sql .= "default_setting_uuid, ";
|
||||
$sql .= "default_setting_category, ";
|
||||
$sql .= "default_setting_subcategory, ";
|
||||
$sql .= "default_setting_name, ";
|
||||
$sql .= "default_setting_value, ";
|
||||
$sql .= "default_setting_enabled, ";
|
||||
$sql .= "default_setting_description ";
|
||||
$sql .= ")";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "'".uuid()."', ";
|
||||
$sql .= "'login', ";
|
||||
$sql .= "'message', ";
|
||||
$sql .= "'text', ";
|
||||
$sql .= "'".$text['login-message_text']."', ";
|
||||
$sql .= "'true', ";
|
||||
$sql .= "'' ";
|
||||
$sql .= ")";
|
||||
$db->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
|
||||
}
|
||||
else {
|
||||
}
|
||||
else {
|
||||
|
||||
// get current message value
|
||||
$sql = "select default_setting_uuid, default_setting_value ";
|
||||
$sql .= "from v_default_settings ";
|
||||
$sql .= "where default_setting_category = 'login' ";
|
||||
$sql .= "and default_setting_subcategory = 'message' ";
|
||||
$sql .= "and default_setting_name = 'text' ";
|
||||
$prep_statement = $db->prepare($sql);
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
if (count($result) > 0) {
|
||||
foreach($result as $row) {
|
||||
$current_default_setting_uuid = $row["default_setting_uuid"];
|
||||
$current_default_setting_value = $row["default_setting_value"];
|
||||
break;
|
||||
}
|
||||
|
||||
// compare to message in language file, update and enable if different
|
||||
$new_default_setting_value = str_replace("''", "'", $text['login-message_text']);
|
||||
if ($current_default_setting_value != $new_default_setting_value) {
|
||||
$sql = "update v_default_settings set ";
|
||||
$sql .= "default_setting_value = '".$text['login-message_text']."', ";
|
||||
$sql .= "default_setting_enabled = 'true' ";
|
||||
$sql .= "where default_setting_uuid = '".$current_default_setting_uuid."' ";
|
||||
$db->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
}
|
||||
// get current message value
|
||||
$sql = "select default_setting_uuid, default_setting_value ";
|
||||
$sql .= "from v_default_settings ";
|
||||
$sql .= "where default_setting_category = 'login' ";
|
||||
$sql .= "and default_setting_subcategory = 'message' ";
|
||||
$sql .= "and default_setting_name = 'text' ";
|
||||
$prep_statement = $db->prepare($sql);
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
if (count($result) > 0) {
|
||||
foreach($result as $row) {
|
||||
$current_default_setting_uuid = $row["default_setting_uuid"];
|
||||
$current_default_setting_value = $row["default_setting_value"];
|
||||
break;
|
||||
}
|
||||
|
||||
// compare to message in language file, update and enable if different
|
||||
$new_default_setting_value = str_replace("''", "'", $text['login-message_text']);
|
||||
if ($current_default_setting_value != $new_default_setting_value) {
|
||||
$sql = "update v_default_settings set ";
|
||||
$sql .= "default_setting_value = '".$text['login-message_text']."', ";
|
||||
$sql .= "default_setting_enabled = 'true' ";
|
||||
$sql .= "where default_setting_uuid = '".$current_default_setting_uuid."' ";
|
||||
$db->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
}
|
||||
unset($prep_statement, $result);
|
||||
}
|
||||
unset($prep_statement, $result);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
The Initial Developer of the Original Code is
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
Portions created by the Initial Developer are Copyright (C) 2008-2012
|
||||
Portions created by the Initial Developer are Copyright (C) 2008-2015
|
||||
the Initial Developer. All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
|
|
@ -70,28 +70,18 @@ if (sizeof($_POST) > 0) {
|
|||
}
|
||||
else {
|
||||
//update scripts folder, if allowed (default)
|
||||
if ($_SESSION['switch']['scripts_update']['boolean'] != 'false' && $_SESSION['switch']['scripts']['dir'] != '') {
|
||||
$scripts_dir_target = $_SESSION['switch']['scripts']['dir'];
|
||||
$scripts_dir_source = realpath($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/scripts');
|
||||
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($scripts_dir_source)) as $file_path_source) {
|
||||
if (
|
||||
substr_count($file_path_source, '/..') == 0 &&
|
||||
substr_count($file_path_source, '/.') == 0 &&
|
||||
substr_count($file_path_source, '/.svn') == 0 &&
|
||||
substr_count($file_path_source, '/.git') == 0
|
||||
) {
|
||||
$file_path_target = str_replace($scripts_dir_source, $scripts_dir_target, $file_path_source);
|
||||
if ($file_path_target != $scripts_dir_target.'/resources/config.lua') {
|
||||
//echo $file_path_source.' ---> '.$file_path_target.'<br>';
|
||||
copy($file_path_source, $file_path_target);
|
||||
chmod($file_path_target, 0755);
|
||||
}
|
||||
}
|
||||
}
|
||||
$response_message = $text['message-upgrade_source_scripts'];
|
||||
if ($_SESSION['switch']['scripts']['dir'] != '') {
|
||||
//copy the files and directories from resources/install
|
||||
$install = new install;
|
||||
$install->domain_uuid = $domain_uuid;
|
||||
$install->switch_scripts_dir = $_SESSION['switch']['scripts']['dir'];
|
||||
$install->copy_scripts();
|
||||
//set the message
|
||||
$response_message = $text['message-upgrade_source_scripts'];
|
||||
}
|
||||
else {
|
||||
$response_message = $text['message-upgrade_source'];
|
||||
//set the message
|
||||
$response_message = $text['message-upgrade_source'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
The Initial Developer of the Original Code is
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
Copyright (C) 2010-2014
|
||||
Copyright (C) 2010-2015
|
||||
All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
|
|
@ -35,16 +35,18 @@ include "root.php";
|
|||
var $switch_scripts_dir;
|
||||
var $switch_sounds_dir;
|
||||
|
||||
//$option '-n' --no-clobber
|
||||
public function recursive_copy($src, $dst, $option = '') {
|
||||
//$options '-n' --no-clobber
|
||||
public function recursive_copy($src, $dst, $options = '') {
|
||||
if (file_exists('/bin/cp')) {
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'SUN') {
|
||||
//copy -R recursive, preserve attributes for SUN
|
||||
exec ('cp -Rp '.$src.'/* '.$dst);
|
||||
$cmd = 'cp -Rp '.$src.'/* '.$dst;
|
||||
} else {
|
||||
//copy -R recursive, -L follow symbolic links, -p preserve attributes for other Posix systemss
|
||||
exec ('cp -RLp '.$option.' '.$src.'/* '.$dst);
|
||||
$cmd = 'cp -RLp '.$options.' '.$src.'/* '.$dst;
|
||||
}
|
||||
exec ($cmd);
|
||||
//echo $cmd."\n";
|
||||
}
|
||||
else {
|
||||
$dir = opendir($src);
|
||||
|
|
@ -58,6 +60,23 @@ include "root.php";
|
|||
throw new Exception("recursive_copy() failed to create destination directory '".$dst."'");
|
||||
}
|
||||
}
|
||||
$scripts_dir_target = $_SESSION['switch']['scripts']['dir'];
|
||||
$scripts_dir_source = realpath($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/scripts');
|
||||
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($src)) as $file_path_source) {
|
||||
if (
|
||||
substr_count($file_path_source, '/..') == 0 &&
|
||||
substr_count($file_path_source, '/.') == 0 &&
|
||||
substr_count($file_path_source, '/.svn') == 0 &&
|
||||
substr_count($file_path_source, '/.git') == 0
|
||||
) {
|
||||
if ($dst != $src.'/resources/config.lua') {
|
||||
//echo $file_path_source.' ---> '.$dst.'<br>';
|
||||
copy($file_path_source, $dst);
|
||||
chmod($dst, 0755);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while(false !== ($file = readdir($dir))) {
|
||||
if (($file != '.') && ($file != '..')) {
|
||||
if (is_dir($src.'/'.$file)) {
|
||||
|
|
@ -65,7 +84,7 @@ include "root.php";
|
|||
}
|
||||
else {
|
||||
//copy only missing files -n --no-clobber
|
||||
if ($option == '-n') {
|
||||
if (strpos($options,'-n') !== false) {
|
||||
if (!file_exists($dst.'/'.$file)) {
|
||||
copy($src.'/'.$file, $dst.'/'.$file);
|
||||
//echo "copy(".$src."/".$file.", ".$dst."/".$file.");<br />\n";
|
||||
|
|
@ -126,12 +145,10 @@ include "root.php";
|
|||
}
|
||||
}
|
||||
//copy resources/templates/conf to the freeswitch conf dir
|
||||
// added /examples/ into the string
|
||||
if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf')){
|
||||
$src_dir = "/usr/share/examples/fusionpbx/resources/templates/conf";
|
||||
}
|
||||
else {
|
||||
|
||||
$src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/conf";
|
||||
}
|
||||
$dst_dir = $this->switch_conf_dir;
|
||||
|
|
@ -152,7 +169,7 @@ include "root.php";
|
|||
}
|
||||
$dst_dir = $this->switch_scripts_dir;
|
||||
if (is_readable($this->switch_scripts_dir)) {
|
||||
$this->recursive_copy($src_dir, $dst_dir, "-n");
|
||||
$this->recursive_copy($src_dir, $dst_dir, $_SESSION['scripts']['options']['text']);
|
||||
unset($src_dir, $dst_dir);
|
||||
}
|
||||
chmod($dst_dir, 0774);
|
||||
|
|
|
|||
Loading…
Reference in New Issue