Improve code to update the scripts directory.
This commit is contained in:
parent
6f9eb6ab29
commit
b8f9b423c7
|
|
@ -17,31 +17,28 @@
|
||||||
|
|
||||||
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-2012
|
Portions created by the Initial Developer are Copyright (C) 2008-2015
|
||||||
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>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (strlen($_SESSION['switch']['scripts']['dir']) > 0) {
|
|
||||||
if ($domains_processed == 1) {
|
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 the resource scripts resource directory does not exist then create it
|
||||||
if (!is_dir($_SESSION['switch']['scripts']['dir']."/resources")) {
|
if (!is_dir($_SESSION['switch']['scripts']['dir']."/resources")) {
|
||||||
mkdir($_SESSION['switch']['scripts']['dir']."/resources",0755,true);
|
mkdir($_SESSION['switch']['scripts']['dir']."/resources",0755,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//copy the files and directories from resources/install
|
//copy the files and directories from resources/install
|
||||||
//require_once "resources/classes/install.php";
|
|
||||||
$install = new install;
|
$install = new install;
|
||||||
$install->domain_uuid = $domain_uuid;
|
$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_scripts_dir = $_SESSION['switch']['scripts']['dir'];
|
||||||
//$install->switch_sounds_dir = $_SESSION['switch']['sounds']['dir'];
|
|
||||||
$install->copy_scripts();
|
$install->copy_scripts();
|
||||||
//$install->copy_sounds();
|
}
|
||||||
//print_r($install->result);
|
|
||||||
|
|
||||||
//update the software table
|
//update the software table
|
||||||
$sql = "select count(*) as num_rows from v_software ";
|
$sql = "select count(*) as num_rows from v_software ";
|
||||||
|
|
@ -147,8 +144,6 @@ if (strlen($_SESSION['switch']['scripts']['dir']) > 0) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
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-2012
|
Portions created by the Initial Developer are Copyright (C) 2008-2015
|
||||||
the Initial Developer. All Rights Reserved.
|
the Initial Developer. All Rights Reserved.
|
||||||
|
|
||||||
Contributor(s):
|
Contributor(s):
|
||||||
|
|
@ -70,27 +70,17 @@ if (sizeof($_POST) > 0) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//update scripts folder, if allowed (default)
|
//update scripts folder, if allowed (default)
|
||||||
if ($_SESSION['switch']['scripts_update']['boolean'] != 'false' && $_SESSION['switch']['scripts']['dir'] != '') {
|
if ($_SESSION['switch']['scripts']['dir'] != '') {
|
||||||
$scripts_dir_target = $_SESSION['switch']['scripts']['dir'];
|
//copy the files and directories from resources/install
|
||||||
$scripts_dir_source = realpath($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/scripts');
|
$install = new install;
|
||||||
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($scripts_dir_source)) as $file_path_source) {
|
$install->domain_uuid = $domain_uuid;
|
||||||
if (
|
$install->switch_scripts_dir = $_SESSION['switch']['scripts']['dir'];
|
||||||
substr_count($file_path_source, '/..') == 0 &&
|
$install->copy_scripts();
|
||||||
substr_count($file_path_source, '/.') == 0 &&
|
//set the message
|
||||||
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'];
|
$response_message = $text['message-upgrade_source_scripts'];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
//set the message
|
||||||
$response_message = $text['message-upgrade_source'];
|
$response_message = $text['message-upgrade_source'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
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>
|
||||||
Copyright (C) 2010-2014
|
Copyright (C) 2010-2015
|
||||||
All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
Contributor(s):
|
Contributor(s):
|
||||||
|
|
@ -35,16 +35,18 @@ include "root.php";
|
||||||
var $switch_scripts_dir;
|
var $switch_scripts_dir;
|
||||||
var $switch_sounds_dir;
|
var $switch_sounds_dir;
|
||||||
|
|
||||||
//$option '-n' --no-clobber
|
//$options '-n' --no-clobber
|
||||||
public function recursive_copy($src, $dst, $option = '') {
|
public function recursive_copy($src, $dst, $options = '') {
|
||||||
if (file_exists('/bin/cp')) {
|
if (file_exists('/bin/cp')) {
|
||||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'SUN') {
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'SUN') {
|
||||||
//copy -R recursive, preserve attributes for SUN
|
//copy -R recursive, preserve attributes for SUN
|
||||||
exec ('cp -Rp '.$src.'/* '.$dst);
|
$cmd = 'cp -Rp '.$src.'/* '.$dst;
|
||||||
} else {
|
} else {
|
||||||
//copy -R recursive, -L follow symbolic links, -p preserve attributes for other Posix systemss
|
//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 {
|
else {
|
||||||
$dir = opendir($src);
|
$dir = opendir($src);
|
||||||
|
|
@ -58,6 +60,23 @@ include "root.php";
|
||||||
throw new Exception("recursive_copy() failed to create destination directory '".$dst."'");
|
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))) {
|
while(false !== ($file = readdir($dir))) {
|
||||||
if (($file != '.') && ($file != '..')) {
|
if (($file != '.') && ($file != '..')) {
|
||||||
if (is_dir($src.'/'.$file)) {
|
if (is_dir($src.'/'.$file)) {
|
||||||
|
|
@ -65,7 +84,7 @@ include "root.php";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//copy only missing files -n --no-clobber
|
//copy only missing files -n --no-clobber
|
||||||
if ($option == '-n') {
|
if (strpos($options,'-n') !== false) {
|
||||||
if (!file_exists($dst.'/'.$file)) {
|
if (!file_exists($dst.'/'.$file)) {
|
||||||
copy($src.'/'.$file, $dst.'/'.$file);
|
copy($src.'/'.$file, $dst.'/'.$file);
|
||||||
//echo "copy(".$src."/".$file.", ".$dst."/".$file.");<br />\n";
|
//echo "copy(".$src."/".$file.", ".$dst."/".$file.");<br />\n";
|
||||||
|
|
@ -126,12 +145,10 @@ include "root.php";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//copy resources/templates/conf to the freeswitch conf dir
|
//copy resources/templates/conf to the freeswitch conf dir
|
||||||
// added /examples/ into the string
|
|
||||||
if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf')){
|
if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf')){
|
||||||
$src_dir = "/usr/share/examples/fusionpbx/resources/templates/conf";
|
$src_dir = "/usr/share/examples/fusionpbx/resources/templates/conf";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
$src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/conf";
|
$src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/conf";
|
||||||
}
|
}
|
||||||
$dst_dir = $this->switch_conf_dir;
|
$dst_dir = $this->switch_conf_dir;
|
||||||
|
|
@ -152,7 +169,7 @@ include "root.php";
|
||||||
}
|
}
|
||||||
$dst_dir = $this->switch_scripts_dir;
|
$dst_dir = $this->switch_scripts_dir;
|
||||||
if (is_readable($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);
|
unset($src_dir, $dst_dir);
|
||||||
}
|
}
|
||||||
chmod($dst_dir, 0774);
|
chmod($dst_dir, 0774);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue