|
@@ -69,103 +69,6 @@ include "root.php";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //$options '-n' --no-clobber
|
|
|
- protected 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
|
|
|
- $cmd = 'cp -Rp '.$src.'/* '.$dst;
|
|
|
- } else {
|
|
|
- //copy -R recursive, -L follow symbolic links, -p preserve attributes for other Posix systemss
|
|
|
- $cmd = 'cp -RLp '.$options.' '.$src.'/* '.$dst;
|
|
|
- }
|
|
|
- $this->write_debug($cmd);
|
|
|
- exec ($cmd);
|
|
|
- }
|
|
|
- elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){
|
|
|
- $src = normalize_path_to_os($src);
|
|
|
- $dst = normalize_path_to_os($dst);
|
|
|
- exec("xcopy /E /Y \"$src\" \"$dst\"");
|
|
|
- }
|
|
|
- else {
|
|
|
- throw new Exception('Could not perform copy operation on this platform, implementation missing');
|
|
|
- $dir = opendir($src);
|
|
|
- if (!$dir) {
|
|
|
- if (!mkdir($src, 0755, true)) {
|
|
|
- throw new Exception("recursive_copy() source directory '".$src."' does not exist.");
|
|
|
- }
|
|
|
- }
|
|
|
- if (!is_dir($dst)) {
|
|
|
- if (!mkdir($dst, 0755, true)) {
|
|
|
- throw new Exception("recursive_copy() failed to create destination directory '".$dst."'");
|
|
|
- }
|
|
|
- }
|
|
|
- //This looks wrong, essentially if we can't use /bin/cp it manually fils dirs, not correct
|
|
|
- $script_dir_target = $_SESSION['switch']['scripts']['dir'];
|
|
|
- $script_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') {
|
|
|
- $this->write_debug($file_path_source.' ---> '.$dst);
|
|
|
- copy($file_path_source, $dst);
|
|
|
- chmod($dst, 0755);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- while(false !== ($file = readdir($dir))) {
|
|
|
- if (($file != '.') && ($file != '..')) {
|
|
|
- if (is_dir($src.'/'.$file)) {
|
|
|
- $this->recursive_copy($src.'/'.$file, $dst.'/'.$file);
|
|
|
- }
|
|
|
- else {
|
|
|
- //copy only missing files -n --no-clobber
|
|
|
- if (strpos($options,'-n') !== false) {
|
|
|
- if (!file_exists($dst.'/'.$file)) {
|
|
|
- $this->write_debug("copy(".$src."/".$file.", ".$dst."/".$file.")");
|
|
|
- copy($src.'/'.$file, $dst.'/'.$file);
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- copy($src.'/'.$file, $dst.'/'.$file);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- closedir($dir);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected function recursive_delete($dir) {
|
|
|
- if (file_exists('/bin/rm')) {
|
|
|
- $this->write_debug('rm -Rf '.$dir.'/*');
|
|
|
- exec ('rm -Rf '.$dir.'/*');
|
|
|
- }
|
|
|
- elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){
|
|
|
- $dst = normalize_path_to_os($dst);
|
|
|
- $this->write_debug("del /S /F /Q \"$dir\"");
|
|
|
- exec("del /S /F /Q \"$dir\"");
|
|
|
- }
|
|
|
- else {
|
|
|
- foreach (glob($dir) as $file) {
|
|
|
- if (is_dir($file)) {
|
|
|
- $this->write_debug("rm dir: ".$file);
|
|
|
- $this->recursive_delete("$file/*");
|
|
|
- rmdir($file);
|
|
|
- } else {
|
|
|
- $this->write_debug("delete file: ".$file);
|
|
|
- unlink($file);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- clearstatcache();
|
|
|
- }
|
|
|
-
|
|
|
protected function backup_dir($dir, $backup_name){
|
|
|
if (!is_readable($dir)) {
|
|
|
throw new Exception("backup_dir() source directory '".$dir."' does not exist.");
|
|
@@ -208,7 +111,7 @@ include "root.php";
|
|
|
//make a backup of the config
|
|
|
if (file_exists($this->global_settings->switch_conf_dir())) {
|
|
|
$this->backup_dir($this->global_settings->switch_conf_dir(), 'fusionpbx_switch_config');
|
|
|
- $this->recursive_delete($this->global_settings->switch_conf_dir());
|
|
|
+ recursive_delete($this->global_settings->switch_conf_dir());
|
|
|
}
|
|
|
//make sure the conf directory exists
|
|
|
if (!is_dir($this->global_settings->switch_conf_dir())) {
|
|
@@ -225,7 +128,7 @@ include "root.php";
|
|
|
}
|
|
|
$dst_dir = $this->global_settings->switch_conf_dir();
|
|
|
if (is_readable($dst_dir)) {
|
|
|
- $this->recursive_copy($src_dir, $dst_dir);
|
|
|
+ recursive_copy($src_dir, $dst_dir);
|
|
|
unset($src_dir, $dst_dir);
|
|
|
}
|
|
|
$fax_dir = join( DIRECTORY_SEPARATOR, array($this->global_settings->switch_storage_dir(), 'fax'));
|
|
@@ -273,7 +176,7 @@ include "root.php";
|
|
|
}
|
|
|
$dst_dir = $script_dir;
|
|
|
if (is_readable($script_dir)) {
|
|
|
- $this->recursive_copy($src_dir, $dst_dir, $_SESSION['scripts']['options']['text']);
|
|
|
+ recursive_copy($src_dir, $dst_dir, $_SESSION['scripts']['options']['text']);
|
|
|
unset($src_dir, $dst_dir);
|
|
|
}else{
|
|
|
throw new Exception("Cannot read from '$src_dir' to get the scripts");
|