-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall.php
More file actions
135 lines (121 loc) · 4.67 KB
/
Copy pathinstall.php
File metadata and controls
135 lines (121 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
if (!defined('FREEPBX_IS_AUTH')) { die('No direct script access allowed'); }
// License for all code of this FreePBX module can be found in the license file inside the module directory
// Copyright 2013 Schmooze Com Inc.
//
// HELPER FUNCTIONS:
function fw_langpacks_print_errors($src, $dst, $errors) {
out("error copying files:");
out(sprintf(_("'cp -ru' from src: '%s' to dst: '%s'...details follow"), $src, $dst));
freepbx_log(FPBX_LOG_ERROR, sprintf(_("fw_langpacks couldn't copy file to %s"),$dst));
foreach ($errors as $error) {
out("$error");
freepbx_log(FPBX_LOG_ERROR, _("cp error output: $error"));
}
}
global $amp_conf;
$debug = false;
$dryrun = false;
/** verison_compare that works with freePBX version numbers
* included here because there are some older versions of functions.inc.php that do not have
* it included as it was added during 2.3.0beta1
*/
if (!function_exists('version_compare_freepbx')) {
function version_compare_freepbx($version1, $version2, $op = null) {
$version1 = str_replace("rc","RC", strtolower($version1));
$version2 = str_replace("rc","RC", strtolower($version2));
if (!is_null($op)) {
return version_compare($version1, $version2, $op);
} else {
return version_compare($version1, $version2);
}
}
}
$htdocs_dest = $amp_conf['AMPWEBROOT'];
/*
* fw_langpacks install script
*
* for each installed component on the target system, copy localization files using the -u option
* on copy which will only copy them if our copy is newer then the destination which protects
* from overwriting destination files that have been updated by the user.
*/
$htdocs_mo_source = dirname(__FILE__)."/mo";
if (!file_exists($htdocs_mo_source)) {
out(sprintf(_("No directory %s, install script not needed"),$htdocs_mo_source));
return true;
}
foreach(glob(dirname(__FILE__).'/mo/*',GLOB_ONLYDIR) as $language) {
$lang = basename($language);
foreach(glob($language.'/*.mo') as $mo) {
$modinfo = pathinfo($mo);
$module = ($modinfo['filename'] == 'amp') ? 'framework' : $modinfo['filename'];
if($module != 'framework') {
$i18n = $htdocs_dest."/admin/modules/".$module."/i18n";
if(!file_exists($htdocs_dest."/admin/modules/".$module)) {
continue;
}
} else {
$i18n = $htdocs_dest."/admin/i18n";
}
if(!file_exists($i18n."/".$lang."/LC_MESSAGES")) {
mkdir($i18n."/".$lang."/LC_MESSAGES",0777,true);
}
exec("cp -ru ".$mo." ".$i18n."/".$lang."/LC_MESSAGES/".basename($mo)." 2>&1",$out,$ret);
if ($ret != 0) {
fw_langpacks_print_errors($mo, $i18n."/".$lang."/LC_MESSAGES/".basename($mo), $out);
} else {
out(sprintf(_("Updated %s"),basename($mo)));
}
}
}
// We now delete the files, this makes sure that if someone had an unprotected system where they have not enabled
// the .htaccess files or otherwise allowed direct access, that these files are not around to possibly cause problems
//
out(_("fw_langpacks mo file install done, removing packages from module"));
unset($out);
exec("rm -rf $htdocs_mo_source 2>&1",$out,$ret);
if ($ret != 0) {
out(_("an error occured removing the packaged files"));
} else {
out(_("files removed successfully"));
}
$htdocs_po_source = dirname(__FILE__)."/po";
if (!file_exists($htdocs_po_source)) {
out(sprintf(_("No directory %s, install script not needed"),$htdocs_po_source));
return true;
}
foreach(glob(dirname(__FILE__).'/po/*',GLOB_ONLYDIR) as $language) {
$lang = basename($language);
foreach(glob($language.'/*.po') as $po) {
$modinfo = pathinfo($po);
$module = ($modinfo['filename'] == 'amp') ? 'framework' : $modinfo['filename'];
if($module != 'framework') {
$i18n = $htdocs_dest."/admin/modules/".$module."/i18n";
if(!file_exists($htdocs_dest."/admin/modules/".$module)) {
continue;
}
} else {
$i18n = $htdocs_dest."/admin/i18n";
}
if(!file_exists($i18n."/".$lang."/LC_MESSAGES")) {
mkdir($i18n."/".$lang."/LC_MESSAGES",0777,true);
}
exec("cp -ru ".$po." ".$i18n."/".$lang."/LC_MESSAGES/".basename($po)." 2>&1",$out,$ret);
if ($ret != 0) {
fw_langpacks_print_errors($po, $i18n."/".$lang."/LC_MESSAGES/".basename($po), $out);
} else {
out(sprintf(_("Updated %s"),basename($po)));
}
}
}
// We now delete the files, this makes sure that if someone had an unprotected system where they have not enabled
// the .htaccess files or otherwise allowed direct access, that these files are not around to possibly cause problems
//
out(_("fw_langpacks po file install done, removing packages from module"));
unset($out);
exec("rm -rf $htdocs_po_source 2>&1",$out,$ret);
if ($ret != 0) {
out(_("an error occured removing the packaged files"));
} else {
out(_("files removed successfully"));
}