Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xiaohe Cao
slapos
Commits
72e10a30
Commit
72e10a30
authored
Jul 17, 2013
by
Vivien Alger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
davstorage: Templates for french translation and sendmail
parent
45243101
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
4629 additions
and
9 deletions
+4629
-9
slapos/recipe/davstorage/__init__.py
slapos/recipe/davstorage/__init__.py
+0
-8
software/davstorage/common.cfg
software/davstorage/common.cfg
+20
-0
software/davstorage/instance-davstorage.cfg
software/davstorage/instance-davstorage.cfg
+96
-1
software/davstorage/templates/bootstrap_conf.php
software/davstorage/templates/bootstrap_conf.php
+59
-0
software/davstorage/templates/class.AJXP_Utils.php
software/davstorage/templates/class.AJXP_Utils.php
+1591
-0
software/davstorage/templates/class.phpmailer-lite.php
software/davstorage/templates/class.phpmailer-lite.php
+2075
-0
software/davstorage/templates/main.cf.in
software/davstorage/templates/main.cf.in
+657
-0
software/davstorage/templates/master.cf.in
software/davstorage/templates/master.cf.in
+127
-0
software/davstorage/templates/postfix.in
software/davstorage/templates/postfix.in
+2
-0
software/davstorage/templates/sendmail.in
software/davstorage/templates/sendmail.in
+2
-0
No files found.
slapos/recipe/davstorage/__init__.py
View file @
72e10a30
...
...
@@ -52,14 +52,6 @@ class Recipe(GenericBaseRecipe):
user
,
password
])
htdocs_location
=
self
.
options
[
'htdocs'
]
if
not
(
os
.
path
.
exists
(
htdocs_location
)
and
os
.
listdir
(
htdocs_location
)):
try
:
os
.
rmdir
(
htdocs_location
)
except
:
pass
shutil
.
copytree
(
self
.
options
[
'source'
],
htdocs_location
)
# Install php.ini
php_ini
=
self
.
createFile
(
os
.
path
.
join
(
self
.
options
[
'php-ini-dir'
],
'php.ini'
),
...
...
software/davstorage/common.cfg
View file @
72e10a30
...
...
@@ -13,6 +13,7 @@ extends =
../../component/lxml-python/buildout.cfg
../../component/python-2.7/buildout.cfg
../../component/gzip/buildout.cfg
../../component/postfix/buildout.cfg
find-links +=
http://www.nexedi.org/static/packages/source/slapos.buildout/
...
...
@@ -37,6 +38,7 @@ allow-hosts +=
www.owlfish.com
parts =
postfix
apache-php
application
template
...
...
@@ -80,5 +82,23 @@ md5sum = 699ecf4678386667f58a3391bab7af0f
output = ${buildout:directory}/template-davstorage.cfg
mode = 0644
[mailer-plugin]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/templates/${:filename}
filename = class.phpmailer-lite.php
sendmail-location = ${postfix:location}/usr/sbin/sendmail
output = ${application:location}/plugins/mailer.phpmailer-lite/lib/${:filename}
mode = 0644
#md5sum =
[bootstrap-conf]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/templates/${:filename}
filename = bootstrap_conf.php
translation = fr_FR.UTF-8
output = ${application:location}/conf/${:filename}
mode = 0644
#md5sum =
[lxml-python]
python = python2.7
software/davstorage/instance-davstorage.cfg
View file @
72e10a30
...
...
@@ -8,6 +8,13 @@ parts =
cron-entry-logrotate
logrotate
logrotate-entry-davstorage
copy-app
mailer-plugin
share-url-generation
postfix-conf
postfix-users
postfix-master-conf
postfix-service
request-frontend
eggs-directory = ${buildout:eggs-directory}
...
...
@@ -52,7 +59,6 @@ apache-binary = ${apache:location}/bin/httpd
apache-modules-dir = ${apache:location}/modules/
apache-mime-file = ${apache:location}/conf/mime.types
apache-htpasswd = ${apache:location}/bin/htpasswd
source = ${application:location}
[certificate-authority]
recipe = slapos.cookbook:certificate_authority
...
...
@@ -157,6 +163,23 @@ cronstamps = $${rootdirectory:etc}/cronstamps/
cronoutput = $${basedirectory:log}/cron/
php-ini-dir = $${rootdirectory:etc}/php
tmp-php = $${rootdirectory:tmp}/php
postfix-conf = $${rootdirectory:etc}/postfix
spool = $${rootdirectory:var}/spool/postfix
data = $${rootdirectory:var}/lib/postfix
maildrop = $${directory:spool}/maildrop
active = $${directory:spool}/active
bounce = $${directory:spool}/bounce
corrupt = $${directory:spool}/corrupt
defer = $${directory:spool}/defer
deferred = $${directory:spool}/deferred
flush = $${directory:spool}/flush
hold = $${directory:spool}/hold
incoming = $${directory:spool}/incoming
private = $${directory:spool}/private
public = $${directory:spool}/public
pid = $${directory:spool}/pid
saved = $${directory:spool}/saved
trace = $${directory:spool}/trace
# Request frontend
[request-frontend-ajaxupload]
...
...
@@ -183,6 +206,78 @@ config-https-only = true
config-url = https://$${davstorage:user}:$${davstorage:password}@[$${davstorage:ip}]:$${davstorage:port_webdav}/
return = domain
[copy-app]
recipe = plone.recipe.command
update-command = command
command = cp -R ${application:location}/* $${directory:htdocs}
[mailer-plugin]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/templates/$${:filename}
filename = class.phpmailer-lite.php
sendmail-script = $${sendmail-script:output}
output = $${directory:htdocs}/plugins/mailer.phpmailer-lite/lib/$${:filename}
mode = 0644
#md5sum =
[share-url-generation]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/templates/$${:filename}
filename = class.AJXP_Utils.php
output = $${directory:htdocs}/core/classes/$${:filename}
mode = 0644
#md5sum =
[postfix-service]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/templates/$${:filename}
filename = postfix.in
postfix-location = ${postfix:location}/usr/sbin/postfix
postfix-config-dir = $${directory:postfix-conf}
output = $${basedirectory:services}/postfix
mode = 0755
#md5sum =
[sendmail-script]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/templates/$${:filename}
filename = sendmail.in
sendmail-location = ${postfix:location}/usr/sbin/sendmail
postfix-config-dir = $${directory:postfix-conf}
output = $${rootdirectory:bin}/sendmail
mode = 0755
#md5sum =
[postfix-conf]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/templates/$${:filename}
filename = main.cf.in
queue-directory = $${directory:spool}
command-directory = ${postfix:location}/usr/sbin
bin-directory = ${postfix:location}/usr/bin
daemon-directory = ${postfix:location}/usr/libexec/postfix
data-directory = $${directory:data}
mail-owner = $${slap-connection:partition_id}
mail-group = $${slap-connection:partition_id}
ipv4 = $${slap-network-information:global-ipv6}
output = $${directory:postfix-conf}/main.cf
mode = 0644
#md5sum =
[postfix-users]
recipe = plone.recipe.command
update-command = command
command = sed 's/ slappart/ slapuser/g' $${postfix-conf:output} > main.tmp && mv main.tmp $${postfix-conf:output}
[postfix-master-conf]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/templates/$${:filename}
filename = master.cf.in
port = 2525
output = $${directory:postfix-conf}/master.cf
mode = 0644
#md5sum =
# XXX Vivien: promise not working for now
#[frontend-ajaxupload-promise]
#recipe = slapos.cookbook:check_url_available
...
...
software/davstorage/templates/bootstrap_conf.php
0 → 100644
View file @
72e10a30
<?php
/*
* Copyright 2007-2011 Charles du Jeu <contact (at) cdujeu.me>
* This file is part of AjaXplorer.
*
* AjaXplorer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AjaXplorer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with AjaXplorer. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <http://www.ajaxplorer.info/>.
*
* These configuration must be set at the very root loading of the framework
*/
/*
* If you have a charset warning, or problems displaying filenames with accented characters,
* check your system locale and set it in the form lang_country.charset
* Example : fr_FR.UTF-8, fr_FR.ISO-8859-1, fr_FR.CP1252 (windows), en_EN.UTF-8, etc.
*
* Windows users may define an empty string
* define("AJXP_LOCALE", "");
*/
define
(
"AJXP_LOCALE"
,
"${:translation}"
);
//define("AJXP_LOCALE", "");
/*
* If you encounter problems writing to the standard php tmp directory, you can
* define your own tmp dir here. Suggested value is ajxp_path/data/tmp/
* AJXP_DATA_PATH, AJXP_INSTALL_PATH are replaced automatically.
*
* See php.ini settings below for the session.save_path value as well.
*/
//define("AJXP_TMP_DIR", AJXP_DATA_PATH."/tmp");
/*
* Additionnal php.ini settings
* > Problems with tmp dir : set your own session tmp dir (create it and make it writeable!)
* > Concurrent versions of AjaXplorer : use session.cookie_path to differentiate them.
*/
$AJXP_INISET
=
array
();
//$AJXP_INISET["session.save_path"] = AJXP_DATA_PATH."/tmp/sessions";
//$AJXP_INISET["session.cookie_path"] = "/ajaxplorer";
/*
* If you want to force the https, uncomment the line below. This will automatically
* redirect all calls to ajaxplorer via http to the same URL with https
*/
//define("AJXP_FORCE_SSL_REDIRECT", true);
\ No newline at end of file
software/davstorage/templates/class.AJXP_Utils.php
0 → 100644
View file @
72e10a30
<?php
/*
* Copyright 2007-2011 Charles du Jeu <contact (at) cdujeu.me>
* This file is part of AjaXplorer.
*
* AjaXplorer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AjaXplorer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with AjaXplorer. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <http://www.ajaxplorer.info/>.
*/
defined
(
'AJXP_EXEC'
)
or
die
(
'Access not allowed'
);
define
(
'AJXP_SANITIZE_HTML'
,
1
);
define
(
'AJXP_SANITIZE_HTML_STRICT'
,
2
);
define
(
'AJXP_SANITIZE_ALPHANUM'
,
3
);
define
(
'AJXP_SANITIZE_EMAILCHARS'
,
4
);
/**
* Various functions used everywhere, static library
* @package AjaXplorer
* @subpackage Core
*/
class
AJXP_Utils
{
/**
* Performs a natural sort on the array keys.
* Behaves the same as ksort() with natural sorting added.
*
* @param Array $array The array to sort
* @return boolean
*/
static
function
natksort
(
&
$array
)
{
uksort
(
$array
,
'strnatcasecmp'
);
return
true
;
}
/**
* Performs a reverse natural sort on the array keys
* Behaves the same as krsort() with natural sorting added.
*
* @param Array $array The array to sort
* @return boolean
*/
static
function
natkrsort
(
&
$array
)
{
natksort
(
$array
);
$array
=
array_reverse
(
$array
,
TRUE
);
return
true
;
}
/**
* Remove all "../../" tentatives, replace double slashes
* @static
* @param string $path
* @return string
*/
static
function
securePath
(
$path
)
{
if
(
$path
==
null
)
$path
=
""
;
//
// REMOVE ALL "../" TENTATIVES
//
$dirs
=
explode
(
'/'
,
$path
);
for
(
$i
=
0
;
$i
<
count
(
$dirs
);
$i
++
)
{
if
(
$dirs
[
$i
]
==
'.'
or
$dirs
[
$i
]
==
'..'
)
{
$dirs
[
$i
]
=
''
;
}
}
// rebuild safe directory string
$path
=
implode
(
'/'
,
$dirs
);
//
// REPLACE DOUBLE SLASHES
//
while
(
preg_match
(
'/\/\//'
,
$path
))
{
$path
=
str_replace
(
'//'
,
'/'
,
$path
);
}
return
$path
;
}
/**
* Function to clean a string from specific characters
*
* @static
* @param string $s
* @param int $level Can be AJXP_SANITIZE_ALPHANUM, AJXP_SANITIZE_EMAILCHARS, AJXP_SANITIZE_HTML, AJXP_SANITIZE_HTML_STRICT
* @param string $expand
* @return mixed|string
*/
public
static
function
sanitize
(
$s
,
$level
=
AJXP_SANITIZE_HTML
,
$expand
=
'script|style|noframes|select|option'
)
{
/**/
//prep the string
$s
=
' '
.
$s
;
if
(
$level
==
AJXP_SANITIZE_ALPHANUM
)
{
return
preg_replace
(
"/[^a-zA-Z0-9_\-\.]/"
,
""
,
$s
);
}
else
if
(
$level
==
AJXP_SANITIZE_EMAILCHARS
)
{
return
preg_replace
(
"/[^a-zA-Z0-9_\-\.@!%\+=|~\?]/"
,
""
,
$s
);
}
//begin removal
/**/
//remove comment blocks
while
(
stripos
(
$s
,
'<!--'
)
>
0
)
{
$pos
[
1
]
=
stripos
(
$s
,
'<!--'
);
$pos
[
2
]
=
stripos
(
$s
,
'-->'
,
$pos
[
1
]);
$len
[
1
]
=
$pos
[
2
]
-
$pos
[
1
]
+
3
;
$x
=
substr
(
$s
,
$pos
[
1
],
$len
[
1
]);
$s
=
str_replace
(
$x
,
''
,
$s
);
}
/**/
//remove tags with content between them
if
(
strlen
(
$expand
)
>
0
)
{
$e
=
explode
(
'|'
,
$expand
);
for
(
$i
=
0
;
$i
<
count
(
$e
);
$i
++
)
{
while
(
stripos
(
$s
,
'<'
.
$e
[
$i
])
>
0
)
{
$len
[
1
]
=
strlen
(
'<'
.
$e
[
$i
]);
$pos
[
1
]
=
stripos
(
$s
,
'<'
.
$e
[
$i
]);
$pos
[
2
]
=
stripos
(
$s
,
$e
[
$i
]
.
'>'
,
$pos
[
1
]
+
$len
[
1
]);
$len
[
2
]
=
$pos
[
2
]
-
$pos
[
1
]
+
$len
[
1
];
$x
=
substr
(
$s
,
$pos
[
1
],
$len
[
2
]);
$s
=
str_replace
(
$x
,
''
,
$s
);
}
}
}
$s
=
strip_tags
(
$s
);
if
(
$level
==
AJXP_SANITIZE_HTML_STRICT
)
{
$s
=
preg_replace
(
"/[
\"
,;\/`<>:\*\|\?!\^
\\
\]/"
,
""
,
$s
);
}
else
{
$s
=
str_replace
(
array
(
"<"
,
">"
),
array
(
"<"
,
">"
),
$s
);
}
return
trim
(
$s
);
}
/**
* Perform standard urldecode, sanitization, securepath and magicDequote
* @static
* @param $data
* @param int $sanitizeLevel
* @return string
*/
public
static
function
decodeSecureMagic
(
$data
,
$sanitizeLevel
=
AJXP_SANITIZE_HTML
)
{
return
SystemTextEncoding
::
fromUTF8
(
AJXP_Utils
::
sanitize
(
AJXP_Utils
::
securePath
(
SystemTextEncoding
::
magicDequote
(
$data
)),
$sanitizeLevel
));
}
/**
* Try to load the tmp dir from the CoreConf AJXP_TMP_DIR, or the constant AJXP_TMP_DIR,
* or the sys_get_temp_dir
* @static
* @return mixed|null|string
*/
public
static
function
getAjxpTmpDir
()
{
if
(
ConfService
::
getCoreConf
(
"AJXP_TMP_DIR"
)
!=
null
)
{
return
ConfService
::
getCoreConf
(
"AJXP_TMP_DIR"
);
}
if
(
defined
(
"AJXP_TMP_DIR"
)
&&
AJXP_TMP_DIR
!=
""
)
{
return
AJXP_TMP_DIR
;
}
return
realpath
(
sys_get_temp_dir
());
}
public
static
function
detectApplicationFirstRun
(){
return
!
file_exists
(
AJXP_CACHE_DIR
.
"/first_run_passed"
);
}
public
static
function
setApplicationFirstRunPassed
(){
@
file_put_contents
(
AJXP_CACHE_DIR
.
"/first_run_passed"
,
"true"
);
}
/**
* Parse a Comma-Separated-Line value
* @static
* @param $string
* @param bool $hash
* @return array
*/
public
static
function
parseCSL
(
$string
,
$hash
=
false
)
{
$exp
=
array_map
(
"trim"
,
explode
(
","
,
$string
));
if
(
!
$hash
)
return
$exp
;
$assoc
=
array
();
foreach
(
$exp
as
$explVal
)
{
$reExp
=
explode
(
"|"
,
$explVal
);
if
(
count
(
$reExp
)
==
1
)
$assoc
[
$reExp
[
0
]]
=
$reExp
[
0
];
else
$assoc
[
$reExp
[
0
]]
=
$reExp
[
1
];
}
return
$assoc
;
}
/**
* Parse the $fileVars[] PHP errors
* @static
* @param $boxData
* @return array|null
*/
static
function
parseFileDataErrors
(
$boxData
)
{
$mess
=
ConfService
::
getMessages
();
$userfile_error
=
$boxData
[
"error"
];
$userfile_tmp_name
=
$boxData
[
"tmp_name"
];
$userfile_size
=
$boxData
[
"size"
];
if
(
$userfile_error
!=
UPLOAD_ERR_OK
)
{
$errorsArray
=
array
();
$errorsArray
[
UPLOAD_ERR_FORM_SIZE
]
=
$errorsArray
[
UPLOAD_ERR_INI_SIZE
]
=
array
(
409
,
"File is too big! Max is"
.
ini_get
(
"upload_max_filesize"
));
$errorsArray
[
UPLOAD_ERR_NO_FILE
]
=
array
(
410
,
"No file found on server!"
);
$errorsArray
[
UPLOAD_ERR_PARTIAL
]
=
array
(
410
,
"File is partial"
);
$errorsArray
[
UPLOAD_ERR_INI_SIZE
]
=
array
(
410
,
"No file found on server!"
);
if
(
$userfile_error
==
UPLOAD_ERR_NO_FILE
)
{
// OPERA HACK, do not display "no file found error"
if
(
!
ereg
(
'Opera'
,
$_SERVER
[
'HTTP_USER_AGENT'
]))
{
return
$errorsArray
[
$userfile_error
];
}
}
else
{
return
$errorsArray
[
$userfile_error
];
}
}
if
(
$userfile_tmp_name
==
"none"
||
$userfile_size
==
0
)
{
return
array
(
410
,
$mess
[
31
]);
}
return
null
;
}
/**
* Utilitary to pass some parameters directly at startup :
* + repository_id / folder
* + compile & skipDebug
* + update_i18n, extract, create
* + external_selector_type
* + skipIOS
* + gui
* @static
* @param $parameters
* @param $output
* @param $session
* @return void
*/
public
static
function
parseApplicationGetParameters
(
$parameters
,
&
$output
,
&
$session
)
{
$output
[
"EXT_REP"
]
=
"/"
;
if
(
isSet
(
$parameters
[
"repository_id"
])
&&
isSet
(
$parameters
[
"folder"
])
||
isSet
(
$parameters
[
"goto"
]))
{
if
(
isSet
(
$parameters
[
"goto"
])){
$repoId
=
array_shift
(
explode
(
"/"
,
ltrim
(
$parameters
[
"goto"
],
"/"
)));
$parameters
[
"folder"
]
=
str_replace
(
$repoId
,
""
,
ltrim
(
$parameters
[
"goto"
],
"/"
));
}
else
{
$repoId
=
$parameters
[
"repository_id"
];
}
$repository
=
ConfService
::
getRepositoryById
(
$repoId
);
if
(
$repository
==
null
)
{
$repository
=
ConfService
::
getRepositoryByAlias
(
$repoId
);
if
(
$repository
!=
null
)
{
$parameters
[
"repository_id"
]
=
$repository
->
getId
();
}
}
require_once
(
AJXP_BIN_FOLDER
.
"/class.SystemTextEncoding.php"
);
if
(
AuthService
::
usersEnabled
())
{
$loggedUser
=
AuthService
::
getLoggedUser
();
if
(
$loggedUser
!=
null
&&
$loggedUser
->
canSwitchTo
(
$parameters
[
"repository_id"
]))
{
$output
[
"EXT_REP"
]
=
SystemTextEncoding
::
toUTF8
(
urldecode
(
$parameters
[
"folder"
]));
$loggedUser
->
setArrayPref
(
"history"
,
"last_repository"
,
$parameters
[
"repository_id"
]);
$loggedUser
->
setPref
(
"pending_folder"
,
SystemTextEncoding
::
toUTF8
(
AJXP_Utils
::
decodeSecureMagic
(
$parameters
[
"folder"
])));
$loggedUser
->
save
(
"user"
);
AuthService
::
updateUser
(
$loggedUser
);
}
else
{
$session
[
"PENDING_REPOSITORY_ID"
]
=
$parameters
[
"repository_id"
];
$session
[
"PENDING_FOLDER"
]
=
SystemTextEncoding
::
toUTF8
(
AJXP_Utils
::
decodeSecureMagic
(
$parameters
[
"folder"
]));
}
}
else
{
ConfService
::
switchRootDir
(
$parameters
[
"repository_id"
]);
$output
[
"EXT_REP"
]
=
SystemTextEncoding
::
toUTF8
(
urldecode
(
$parameters
[
"folder"
]));
}
}
if
(
isSet
(
$parameters
[
"skipDebug"
]))
{
ConfService
::
setConf
(
"JS_DEBUG"
,
false
);
}
if
(
ConfService
::
getConf
(
"JS_DEBUG"
)
&&
isSet
(
$parameters
[
"compile"
]))
{
require_once
(
AJXP_BIN_FOLDER
.
"/class.AJXP_JSPacker.php"
);
AJXP_JSPacker
::
pack
();
}
if
(
ConfService
::
getConf
(
"JS_DEBUG"
)
&&
isSet
(
$parameters
[
"update_i18n"
]))
{
if
(
isSet
(
$parameters
[
"extract"
]))
{
self
::
extractConfStringsFromManifests
();
}
self
::
updateAllI18nLibraries
((
isSet
(
$parameters
[
"create"
])
?
$parameters
[
"create"
]
:
""
));
}
if
(
ConfService
::
getConf
(
"JS_DEBUG"
)
&&
isSet
(
$parameters
[
"clear_plugins_cache"
]))
{
@
unlink
(
AJXP_PLUGINS_CACHE_FILE
);
@
unlink
(
AJXP_PLUGINS_REQUIRES_FILE
);
}
if
(
AJXP_SERVER_DEBUG
&&
isSet
(
$parameters
[
"extract_application_hooks"
])){
self
::
extractHooksToDoc
();
}
if
(
isSet
(
$parameters
[
"external_selector_type"
]))
{
$output
[
"SELECTOR_DATA"
]
=
array
(
"type"
=>
$parameters
[
"external_selector_type"
],
"data"
=>
$parameters
);
}
if
(
isSet
(
$parameters
[
"skipIOS"
]))
{
setcookie
(
"SKIP_IOS"
,
"true"
);
}
if
(
isSet
(
$parameters
[
"skipANDROID"
]))
{
setcookie
(
"SKIP_ANDROID"
,
"true"
);
}
if
(
isSet
(
$parameters
[
"gui"
]))
{
setcookie
(
"AJXP_GUI"
,
$parameters
[
"gui"
]);
if
(
$parameters
[
"gui"
]
==
"light"
)
$session
[
"USE_EXISTING_TOKEN_IF_EXISTS"
]
=
true
;
}
else
{
if
(
isSet
(
$session
[
"USE_EXISTING_TOKEN_IF_EXISTS"
]))
{
unset
(
$session
[
"USE_EXISTING_TOKEN_IF_EXISTS"
]);
}
setcookie
(
"AJXP_GUI"
,
null
);
}
}
/**
* Remove windows carriage return
* @static
* @param $fileContent
* @return mixed
*/
static
function
removeWinReturn
(
$fileContent
)
{
$fileContent
=
str_replace
(
chr
(
10
),
""
,
$fileContent
);
$fileContent
=
str_replace
(
chr
(
13
),
""
,
$fileContent
);
return
$fileContent
;
}
/**
* Get the filename extensions using ConfService::getRegisteredExtensions()
* @static
* @param string $fileName
* @param string $mode "image" or "text"
* @param bool $isDir
* @return string Returns the icon name ("image") or the mime label ("text")
*/
static
function
mimetype
(
$fileName
,
$mode
,
$isDir
)
{
$mess
=
ConfService
::
getMessages
();
$fileName
=
strtolower
(
$fileName
);
$EXTENSIONS
=
ConfService
::
getRegisteredExtensions
();
if
(
$isDir
)
{
$mime
=
$EXTENSIONS
[
"ajxp_folder"
];
}
else
{
foreach
(
$EXTENSIONS
as
$ext
)
{
if
(
preg_match
(
"/\.
$ext[0]
$/"
,
$fileName
))
{
$mime
=
$ext
;
break
;
}
}
}
if
(
!
isSet
(
$mime
))
{
$mime
=
$EXTENSIONS
[
"ajxp_empty"
];
}
if
(
is_numeric
(
$mime
[
2
])
||
array_key_exists
(
$mime
[
2
],
$mess
))
{
$mime
[
2
]
=
$mess
[
$mime
[
2
]];
}
return
((
$mode
==
"image"
?
$mime
[
1
]
:
$mime
[
2
]));
}
static
$registeredExtensions
;
static
function
mimeData
(
$fileName
,
$isDir
){
$fileName
=
strtolower
(
$fileName
);
if
(
self
::
$registeredExtensions
==
null
){
self
::
$registeredExtensions
=
ConfService
::
getRegisteredExtensions
();
}
if
(
$isDir
)
{
$mime
=
self
::
$registeredExtensions
[
"ajxp_folder"
];
}
else
{
$pos
=
strrpos
(
$fileName
,
"."
);
if
(
$pos
!==
false
){
$fileExt
=
substr
(
$fileName
,
$pos
+
1
);
if
(
!
empty
(
$fileExt
)
&&
array_key_exists
(
$fileExt
,
self
::
$registeredExtensions
)
&&
$fileExt
!=
"ajxp_folder"
&&
$fileExt
!=
"ajxp_empty"
){
$mime
=
self
::
$registeredExtensions
[
$fileExt
];
}
}
}
if
(
!
isSet
(
$mime
))
{
$mime
=
self
::
$registeredExtensions
[
"ajxp_empty"
];
}
return
array
(
$mime
[
2
],
$mime
[
1
]);
}
/**
* Gather a list of mime that must be treated specially. Used for dynamic replacement in XML mainly.
* @static
* @param string $keyword "editable", "image", "audio", "zip"
* @return string
*/
static
function
getAjxpMimes
(
$keyword
)
{
if
(
$keyword
==
"editable"
)
{
// Gather editors!
$pServ
=
AJXP_PluginsService
::
getInstance
();
$plugs
=
$pServ
->
getPluginsByType
(
"editor"
);
//$plugin = new AJXP_Plugin();
$mimes
=
array
();
foreach
(
$plugs
as
$plugin
)
{
$node
=
$plugin
->
getManifestRawContent
(
"/editor/@mimes"
,
"node"
);
$openable
=
$plugin
->
getManifestRawContent
(
"/editor/@openable"
,
"node"
);
if
(
$openable
->
item
(
0
)
&&
$openable
->
item
(
0
)
->
value
==
"true"
&&
$node
->
item
(
0
))
{
$mimestring
=
$node
->
item
(
0
)
->
value
;
$mimesplit
=
explode
(
","
,
$mimestring
);
foreach
(
$mimesplit
as
$value
)
{
$mimes
[
$value
]
=
$value
;
}
}
}
return
implode
(
","
,
array_values
(
$mimes
));
}
else
if
(
$keyword
==
"image"
)
{
return
"png,bmp,jpg,jpeg,gif"
;
}
else
if
(
$keyword
==
"audio"
)
{
return
"mp3"
;
}
else
if
(
$keyword
==
"zip"
)
{
if
(
ConfService
::
zipEnabled
())
{
return
"zip,ajxp_browsable_archive"
;
}
else
{
return
"none_allowed"
;
}
}
return
""
;
}
/**
* Whether a file is to be considered as an image or not
* @static
* @param $fileName
* @return bool
*/
static
function
is_image
(
$fileName
)
{
if
(
preg_match
(
"/\.png$|\.bmp$|\.jpg$|\.jpeg$|\.gif$/i"
,
$fileName
))
{
return
1
;
}
return
0
;
}
/**
* Whether a file is to be considered as an mp3... Should be DEPRECATED
* @static
* @param string $fileName
* @return bool
* @deprecated
*/
static
function
is_mp3
(
$fileName
)
{
if
(
preg_match
(
"/\.mp3$/i"
,
$fileName
))
return
1
;
return
0
;
}
/**
* Static image mime type headers
* @static
* @param $fileName
* @return string
*/
static
function
getImageMimeType
(
$fileName
)
{
if
(
preg_match
(
"/\.jpg$|\.jpeg$/i"
,
$fileName
))
{
return
"image/jpeg"
;
}
else
if
(
preg_match
(
"/\.png$/i"
,
$fileName
))
{
return
"image/png"
;
}
else
if
(
preg_match
(
"/\.bmp$/i"
,
$fileName
))
{
return
"image/bmp"
;
}
else
if
(
preg_match
(
"/\.gif$/i"
,
$fileName
))
{
return
"image/gif"
;
}
}
/**
* Headers to send when streaming
* @static
* @param $fileName
* @return bool|string
*/
static
function
getStreamingMimeType
(
$fileName
)
{
if
(
preg_match
(
"/\.mp3$/i"
,
$fileName
))
{
return
"audio/mp3"
;
}
else
if
(
preg_match
(
"/\.wav$/i"
,
$fileName
))
{
return
"audio/wav"
;
}
else
if
(
preg_match
(
"/\.aac$/i"
,
$fileName
))
{
return
"audio/aac"
;
}
else
if
(
preg_match
(
"/\.m4a$/i"
,
$fileName
))
{
return
"audio/m4a"
;
}
else
if
(
preg_match
(
"/\.aiff$/i"
,
$fileName
))
{
return
"audio/aiff"
;
}
else
if
(
preg_match
(
"/\.mp4$/i"
,
$fileName
))
{
return
"video/mp4"
;
}
else
if
(
preg_match
(
"/\.mov$/i"
,
$fileName
))
{
return
"video/quicktime"
;
}
else
if
(
preg_match
(
"/\.m4v$/i"
,
$fileName
))
{
return
"video/x-m4v"
;
}
else
if
(
preg_match
(
"/\.3gp$/i"
,
$fileName
))
{
return
"video/3gpp"
;
}
else
if
(
preg_match
(
"/\.3g2$/i"
,
$fileName
))
{
return
"video/3gpp2"
;
}
else
return
false
;
}
static
$sizeUnit
;
/**
* Display a human readable string for a bytesize (1MB, 2,3Go, etc)
* @static
* @param $filesize
* @param bool $phpConfig
* @return string
*/
static
function
roundSize
(
$filesize
,
$phpConfig
=
false
)
{
if
(
self
::
$sizeUnit
==
null
){
$mess
=
ConfService
::
getMessages
();
self
::
$sizeUnit
=
$mess
[
"byte_unit_symbol"
];
}
if
(
$filesize
<
0
)
{
$filesize
=
sprintf
(
"%u"
,
$filesize
);
}
if
(
$filesize
>=
1073741824
)
{
$filesize
=
round
(
$filesize
/
1073741824
*
100
)
/
100
.
(
$phpConfig
?
"G"
:
" G"
.
self
::
$sizeUnit
);
}
elseif
(
$filesize
>=
1048576
)
{
$filesize
=
round
(
$filesize
/
1048576
*
100
)
/
100
.
(
$phpConfig
?
"M"
:
" M"
.
self
::
$sizeUnit
);
}
elseif
(
$filesize
>=
1024
)
{
$filesize
=
round
(
$filesize
/
1024
*
100
)
/
100
.
(
$phpConfig
?
"K"
:
" K"
.
self
::
$sizeUnit
);
}
else
{
$filesize
=
$filesize
.
" "
.
self
::
$sizeUnit
;
}
if
(
$filesize
==
0
)
{
$filesize
=
"-"
;
}
return
$filesize
;
}
/**
* Hidden files start with dot
* @static
* @param string $fileName
* @return bool
*/
static
function
isHidden
(
$fileName
)
{
return
(
substr
(
$fileName
,
0
,
1
)
==
"."
);
}
/**
* Whether a file is a browsable archive
* @static
* @param string $fileName
* @return int
*/
static
function
isBrowsableArchive
(
$fileName
)
{
return
preg_match
(
"/\.zip$/i"
,
$fileName
);
}
/**
* Convert a shorthand byte value from a PHP configuration directive to an integer value
* @param string $value
* @return int
*/
static
function
convertBytes
(
$value
)
{
if
(
is_numeric
(
$value
))
{
return
intval
(
$value
);
}
else
{
$value_length
=
strlen
(
$value
);
$qty
=
substr
(
$value
,
0
,
$value_length
-
1
);
$unit
=
strtolower
(
substr
(
$value
,
$value_length
-
1
));
switch
(
$unit
)
{
case
'k'
:
$qty
*=
1024
;
break
;
case
'm'
:
$qty
*=
1048576
;
break
;
case
'g'
:
$qty
*=
1073741824
;
break
;
}
return
$qty
;
}
}
//Relative Date Function
public
static
function
relativeDate
(
$time
,
$messages
)
{
$today
=
strtotime
(
date
(
'M j, Y'
));
$reldays
=
(
$time
-
$today
)
/
86400
;
$relTime
=
date
(
$messages
[
'date_relative_time_format'
],
$time
);
if
(
$reldays
>=
0
&&
$reldays
<
1
)
{
return
str_replace
(
"TIME"
,
$relTime
,
$messages
[
'date_relative_today'
]);
}
else
if
(
$reldays
>=
1
&&
$reldays
<
2
)
{
return
str_replace
(
"TIME"
,
$relTime
,
$messages
[
'date_relative_tomorrow'
]);
}
else
if
(
$reldays
>=
-
1
&&
$reldays
<
0
)
{
return
str_replace
(
"TIME"
,
$relTime
,
$messages
[
'date_relative_yesterday'
]);
}
if
(
abs
(
$reldays
)
<
7
)
{
if
(
$reldays
>
0
)
{
$reldays
=
floor
(
$reldays
);
return
str_replace
(
"%s"
,
$reldays
,
$messages
[
'date_relative_days_ahead'
]);
//return 'In ' . $reldays . ' day' . ($reldays != 1 ? 's' : '');
}
else
{
$reldays
=
abs
(
floor
(
$reldays
));
return
str_replace
(
"%s"
,
$reldays
,
$messages
[
'date_relative_days_ago'
]);
//return $reldays . ' day' . ($reldays != 1 ? 's' : '') . ' ago';
}
}
return
str_replace
(
"DATE"
,
date
(
$messages
[
"date_relative_date_format"
],
$time
?
$time
:
time
()),
$messages
[
"date_relative_date"
]);
}
/**
* Replace specific chars by their XML Entities, for use inside attributes value
* @static
* @param $string
* @param bool $toUtf8
* @return mixed|string
*/
static
function
xmlEntities
(
$string
,
$toUtf8
=
false
)
{
$xmlSafe
=
str_replace
(
array
(
"&"
,
"<"
,
">"
,
"
\"
"
,
"
\n
"
,
"
\r
"
),
array
(
"&"
,
"<"
,
">"
,
"""
,
" "
,
" "
),
$string
);
if
(
$toUtf8
&&
SystemTextEncoding
::
getEncoding
()
!=
"UTF-8"
)
{
return
SystemTextEncoding
::
toUTF8
(
$xmlSafe
);
}
else
{
return
$xmlSafe
;
}
}
/**
* Replace specific chars by their XML Entities, for use inside attributes value
* @static
* @param $string
* @param bool $toUtf8
* @return mixed|string
*/
static
function
xmlContentEntities
(
$string
,
$toUtf8
=
false
)
{
$xmlSafe
=
str_replace
(
array
(
"&"
,
"<"
,
">"
,
"
\"
"
),
array
(
"&"
,
"<"
,
">"
,
"""
),
$string
);
if
(
$toUtf8
)
{
return
SystemTextEncoding
::
toUTF8
(
$xmlSafe
);
}
else
{
return
$xmlSafe
;
}
}
/**
* Search include path for a given file
* @static
* @param string $file
* @return bool
*/
static
public
function
searchIncludePath
(
$file
)
{
$ps
=
explode
(
PATH_SEPARATOR
,
ini_get
(
'include_path'
));
foreach
(
$ps
as
$path
)
{
if
(
@
file_exists
(
$path
.
DIRECTORY_SEPARATOR
.
$file
))
return
true
;
}
if
(
@
file_exists
(
$file
))
return
true
;
return
false
;
}
/**
* @static
* @param $from
* @param $to
* @return string
*/
static
public
function
getTravelPath
(
$from
,
$to
)
{
$from
=
explode
(
'/'
,
$from
);
$to
=
explode
(
'/'
,
$to
);
$relPath
=
$to
;
foreach
(
$from
as
$depth
=>
$dir
)
{
// find first non-matching dir
if
(
$dir
===
$to
[
$depth
])
{
// ignore this directory
array_shift
(
$relPath
);
}
else
{
// get number of remaining dirs to $from
$remaining
=
count
(
$from
)
-
$depth
;
if
(
$remaining
>
1
)
{
// add traversals up to first matching dir
$padLength
=
(
count
(
$relPath
)
+
$remaining
-
1
)
*
-
1
;
$relPath
=
array_pad
(
$relPath
,
$padLength
,
'..'
);
break
;
}
else
{
$relPath
[
0
]
=
'./'
.
$relPath
[
0
];
}
}
}
return
implode
(
'/'
,
$relPath
);
}
/**
* Build the current server URL
* @param bool $withURI
* @internal param bool $witchURI
* @static
* @return string
*/
static
function
detectServerURL
(
$withURI
=
false
)
{
$setUrl
=
ConfService
::
getCoreConf
(
"SERVER_URL"
);
if
(
!
empty
(
$setUrl
)){
return
$setUrl
;
}
if
(
php_sapi_name
()
==
"cli"
){
AJXP_Logger
::
debug
(
"WARNING, THE SERVER_URL IS NOT SET, WE CANNOT BUILD THE MAIL ADRESS WHEN WORKING IN CLI"
);
}
$protocol
=
(
isset
(
$_SERVER
[
'HTTPS'
])
&&
$_SERVER
[
'HTTPS'
]
!==
'off'
?
'https'
:
'http'
);
$port
=
((
$protocol
===
'http'
&&
$_SERVER
[
'SERVER_PORT'
]
==
80
||
$protocol
===
'https'
&&
$_SERVER
[
'SERVER_PORT'
]
==
443
)
?
""
:
":"
.
$_SERVER
[
'SERVER_PORT'
]);
$name
=
$_SERVER
[
"SERVER_NAME"
];
// removed $port after $name because it interfered with apache frontend
if
(
!
$withURI
){
return
"
$protocol
://
$name
"
;
}
else
{
return
"
$protocol
://
$name
"
.
dirname
(
$_SERVER
[
"REQUEST_URI"
]);
}
}
/**
* Modifies a string to remove all non ASCII characters and spaces.
* @param string $text
* @return string
*/
static
public
function
slugify
(
$text
)
{
if
(
empty
(
$text
))
return
""
;
// replace non letter or digits by -
$text
=
preg_replace
(
'~[^\\pL\d]+~u'
,
'-'
,
$text
);
// trim
$text
=
trim
(
$text
,
'-'
);
// transliterate
if
(
function_exists
(
'iconv'
))
{
$text
=
iconv
(
'utf-8'
,
'us-ascii//TRANSLIT'
,
$text
);
}
// lowercase
$text
=
strtolower
(
$text
);
// remove unwanted characters
$text
=
preg_replace
(
'~[^-\w]+~'
,
''
,
$text
);
if
(
empty
(
$text
))
{
return
'n-a'
;
}
return
$text
;
}
static
function
getHooksFile
(){
return
AJXP_INSTALL_PATH
.
"/"
.
AJXP_DOCS_FOLDER
.
"/hooks.json"
;
}
static
function
extractHooksToDoc
(){
$docFile
=
self
::
getHooksFile
();
if
(
is_file
(
$docFile
)){
copy
(
$docFile
,
$docFile
.
".bak"
);
$existingHooks
=
json_decode
(
file_get_contents
(
$docFile
),
true
);
}
else
{
$existingHooks
=
array
();
}
$allPhpFiles
=
glob_recursive
(
AJXP_INSTALL_PATH
.
"/*.php"
);
$hooks
=
array
();
foreach
(
$allPhpFiles
as
$phpFile
){
$fileContent
=
file
(
$phpFile
);
foreach
(
$fileContent
as
$lineNumber
=>
$line
){
if
(
preg_match_all
(
'/AJXP_Controller::applyHook\("([^"]+)", (.*)\)/'
,
$line
,
$matches
)){
$names
=
$matches
[
1
];
$params
=
$matches
[
2
];
foreach
(
$names
as
$index
=>
$hookName
){
if
(
!
isSet
(
$hooks
[
$hookName
]))
$hooks
[
$hookName
]
=
array
(
"TRIGGERS"
=>
array
(),
"LISTENERS"
=>
array
());
$hooks
[
$hookName
][
"TRIGGERS"
][]
=
array
(
"FILE"
=>
substr
(
$phpFile
,
strlen
(
AJXP_INSTALL_PATH
)),
"LINE"
=>
$lineNumber
);
$hooks
[
$hookName
][
"PARAMETER_SAMPLE"
]
=
$params
[
$index
];
}
}
}
}
$registryHooks
=
AJXP_PluginsService
::
getInstance
()
->
searchAllManifests
(
"//hooks/serverCallback"
,
"xml"
,
false
,
false
,
true
);
$regHooks
=
array
();
foreach
(
$registryHooks
as
$xmlHook
){
$name
=
$xmlHook
->
getAttribute
(
"hookName"
);
$method
=
$xmlHook
->
getAttribute
(
"methodName"
);
$pluginId
=
$xmlHook
->
getAttribute
(
"pluginId"
);
if
(
$pluginId
==
""
)
$pluginId
=
$xmlHook
->
parentNode
->
parentNode
->
parentNode
->
getAttribute
(
"id"
);
if
(
!
isSet
(
$regHooks
[
$name
]))
$regHooks
[
$name
]
=
array
();
$regHooks
[
$name
][]
=
array
(
"PLUGIN_ID"
=>
$pluginId
,
"METHOD"
=>
$method
);
}
foreach
(
$hooks
as
$h
=>
$data
)
{
if
(
isSet
(
$regHooks
[
$h
])){
$data
[
"LISTENERS"
]
=
$regHooks
[
$h
];
}
if
(
isSet
(
$existingHooks
[
$h
])){
$existingHooks
[
$h
][
"TRIGGERS"
]
=
$data
[
"TRIGGERS"
];
$existingHooks
[
$h
][
"LISTENERS"
]
=
$data
[
"LISTENERS"
];
$existingHooks
[
$h
][
"PARAMETER_SAMPLE"
]
=
$data
[
"PARAMETER_SAMPLE"
];
}
else
{
$existingHooks
[
$h
]
=
$data
;
}
}
file_put_contents
(
$docFile
,
self
::
prettyPrintJSON
(
json_encode
(
$existingHooks
)));
}
/**
* Indents a flat JSON string to make it more human-readable.
*
* @param string $json The original JSON string to process.
*
* @return string Indented version of the original JSON string.
*/
function
prettyPrintJSON
(
$json
)
{
$result
=
''
;
$pos
=
0
;
$strLen
=
strlen
(
$json
);
$indentStr
=
' '
;
$newLine
=
"
\n
"
;
$prevChar
=
''
;
$outOfQuotes
=
true
;
for
(
$i
=
0
;
$i
<=
$strLen
;
$i
++
)
{
// Grab the next character in the string.
$char
=
substr
(
$json
,
$i
,
1
);
// Are we inside a quoted string?
if
(
$char
==
'"'
&&
$prevChar
!=
'\\'
)
{
$outOfQuotes
=
!
$outOfQuotes
;
// If this character is the end of an element,
// output a new line and indent the next line.
}
else
if
((
$char
==
'}'
||
$char
==
']'
)
&&
$outOfQuotes
)
{
$result
.=
$newLine
;
$pos
--
;
for
(
$j
=
0
;
$j
<
$pos
;
$j
++
)
{
$result
.=
$indentStr
;
}
}
// Add the character to the result string.
$result
.=
$char
;
// If the last character was the beginning of an element,
// output a new line and indent the next line.
if
((
$char
==
','
||
$char
==
'{'
||
$char
==
'['
)
&&
$outOfQuotes
)
{
$result
.=
$newLine
;
if
(
$char
==
'{'
||
$char
==
'['
)
{
$pos
++
;
}
for
(
$j
=
0
;
$j
<
$pos
;
$j
++
)
{
$result
.=
$indentStr
;
}
}
$prevChar
=
$char
;
}
return
$result
;
}
/**
* i18n utilitary for extracting the CONF_MESSAGE[] strings out of the XML files
* @static
* @return void
*/
static
function
extractConfStringsFromManifests
()
{
$plugins
=
AJXP_PluginsService
::
getInstance
()
->
getDetectedPlugins
();
$plug
=
new
AJXP_Plugin
(
""
,
""
);
foreach
(
$plugins
as
$pType
=>
$plugs
)
{
foreach
(
$plugs
as
$plug
)
{
$lib
=
$plug
->
getManifestRawContent
(
"//i18n"
,
"nodes"
);
if
(
!
$lib
->
length
)
continue
;
$library
=
$lib
->
item
(
0
);
$namespace
=
$library
->
getAttribute
(
"namespace"
);
$path
=
$library
->
getAttribute
(
"path"
);
$xml
=
$plug
->
getManifestRawContent
();
// for core, also load mixins
$refFile
=
AJXP_INSTALL_PATH
.
"/"
.
$path
.
"/conf/en.php"
;
$reference
=
array
();
if
(
preg_match_all
(
"/CONF_MESSAGE(\[.*?\])/"
,
$xml
,
$matches
,
PREG_SET_ORDER
))
{
foreach
(
$matches
as
$match
)
{
$match
[
1
]
=
str_replace
(
array
(
"["
,
"]"
),
""
,
$match
[
1
]);
$reference
[
$match
[
1
]]
=
$match
[
1
];
}
}
if
(
$namespace
==
""
)
{
$mixXml
=
file_get_contents
(
AJXP_INSTALL_PATH
.
"/"
.
AJXP_PLUGINS_FOLDER
.
"/core.ajaxplorer/ajxp_mixins.xml"
);
if
(
preg_match_all
(
"/MIXIN_MESSAGE(\[.*?\])/"
,
$mixXml
,
$matches
,
PREG_SET_ORDER
))
{
foreach
(
$matches
as
$match
)
{
$match
[
1
]
=
str_replace
(
array
(
"["
,
"]"
),
""
,
$match
[
1
]);
$reference
[
$match
[
1
]]
=
$match
[
1
];
}
}
}
if
(
count
(
$reference
))
{
self
::
updateI18nFromRef
(
$refFile
,
$reference
);
}
}
}
}
/**
* Browse the i18n libraries and update the languages with the strings missing
* @static
* @param string $createLanguage
* @return void
*/
static
function
updateAllI18nLibraries
(
$createLanguage
=
""
)
{
// UPDATE EN => OTHER LANGUAGES
$nodes
=
AJXP_PluginsService
::
getInstance
()
->
searchAllManifests
(
"//i18n"
,
"nodes"
);
foreach
(
$nodes
as
$node
)
{
$nameSpace
=
$node
->
getAttribute
(
"namespace"
);
$path
=
AJXP_INSTALL_PATH
.
"/"
.
$node
->
getAttribute
(
"path"
);
if
(
$nameSpace
==
""
)
{
self
::
updateI18nFiles
(
$path
,
false
,
$createLanguage
);
self
::
updateI18nFiles
(
$path
.
"/conf"
,
true
,
$createLanguage
);
}
else
{
self
::
updateI18nFiles
(
$path
,
true
,
$createLanguage
);
self
::
updateI18nFiles
(
$path
.
"/conf"
,
true
,
$createLanguage
);
}
}
}
/**
* Patch the languages files of an i18n library with the references strings from the "en" file.
* @static
* @param $baseDir
* @param bool $detectLanguages
* @param string $createLanguage
* @return
*/
static
function
updateI18nFiles
(
$baseDir
,
$detectLanguages
=
true
,
$createLanguage
=
""
)
{
if
(
!
is_dir
(
$baseDir
)
||
!
is_file
(
$baseDir
.
"/en.php"
))
return
;
if
(
$createLanguage
!=
""
&&
!
is_file
(
$baseDir
.
"/
$createLanguage
.php"
))
{
@
copy
(
AJXP_INSTALL_PATH
.
"/plugins/core.ajaxplorer/i18n-template.php"
,
$baseDir
.
"/
$createLanguage
.php"
);
}
if
(
!
$detectLanguages
)
{
$languages
=
ConfService
::
listAvailableLanguages
();
$filenames
=
array
();
foreach
(
$languages
as
$key
=>
$value
)
{
$filenames
[]
=
$baseDir
.
"/"
.
$key
.
".php"
;
}
}
else
{
$filenames
=
glob
(
$baseDir
.
"/*.php"
);
}
include
(
$baseDir
.
"/en.php"
);
$reference
=
$mess
;
foreach
(
$filenames
as
$filename
)
{
self
::
updateI18nFromRef
(
$filename
,
$reference
);
}
}
/**
* i18n Utilitary
* @static
* @param $filename
* @param $reference
* @return
*/
static
function
updateI18nFromRef
(
$filename
,
$reference
)
{
if
(
!
is_file
(
$filename
))
return
;
include
(
$filename
);
$missing
=
array
();
foreach
(
$reference
as
$messKey
=>
$message
)
{
if
(
!
array_key_exists
(
$messKey
,
$mess
))
{
$missing
[]
=
"
\"
$messKey
\"
=>
\"
$message
\"
,"
;
}
}
//print_r($missing);
if
(
count
(
$missing
))
{
$header
=
array
();
$currentMessages
=
array
();
$footer
=
array
();
$fileLines
=
file
(
$filename
);
$insideArray
=
false
;
foreach
(
$fileLines
as
$line
)
{
if
(
strstr
(
$line
,
"
\"
"
)
!==
false
)
{
$currentMessages
[]
=
trim
(
$line
);
$insideArray
=
true
;
}
else
{
if
(
!
$insideArray
&&
strstr
(
$line
,
");"
)
!==
false
)
$insideArray
=
true
;
if
(
!
$insideArray
)
{
$header
[]
=
trim
(
$line
);
}
else
{
$footer
[]
=
trim
(
$line
);
}
}
}
$currentMessages
=
array_merge
(
$header
,
$currentMessages
,
$missing
,
$footer
);
file_put_contents
(
$filename
,
join
(
"
\n
"
,
$currentMessages
));
}
}
/**
* Generate an HTML table for the tests results. We should use a template somewhere...
* @static
* @param $outputArray
* @param $testedParams
* @param bool $showSkipLink
* @return string
*/
static
function
testResultsToTable
(
$outputArray
,
$testedParams
,
$showSkipLink
=
true
)
{
$dumpRows
=
""
;
$passedRows
=
array
();
$warnRows
=
""
;
$errRows
=
""
;
$errs
=
$warns
=
0
;
$ALL_ROWS
=
array
(
"error"
=>
array
(),
"warning"
=>
array
(),
"dump"
=>
array
(),
"passed"
=>
array
(),
);
$TITLES
=
array
(
"error"
=>
"Failed Tests"
,
"warning"
=>
"Warnings"
,
"dump"
=>
"Server Information"
,
"passed"
=>
"Other tests passed"
,
);
foreach
(
$outputArray
as
$item
)
{
// A test is output only if it hasn't succeeded (doText returned FALSE)
$result
=
$item
[
"result"
]
?
"passed"
:
(
$item
[
"level"
]
==
"info"
?
"dump"
:
(
$item
[
"level"
]
==
"warning"
?
"warning"
:
"error"
));
$success
=
$result
==
"passed"
;
if
(
$result
==
"dump"
)
$result
=
"passed"
;
$ALL_ROWS
[
$result
][
$item
[
"name"
]]
=
$item
[
"info"
];
}
include
(
AJXP_INSTALL_PATH
.
"/core/tests/startup.phtml"
);
}
/**
* @static
* @param $outputArray
* @param $testedParams
* @return bool
*/
static
function
runTests
(
&
$outputArray
,
&
$testedParams
)
{
// At first, list folder in the tests subfolder
chdir
(
AJXP_TESTS_FOLDER
);
$files
=
glob
(
'*.php'
);
$outputArray
=
array
();
$testedParams
=
array
();
$passed
=
true
;
foreach
(
$files
as
$file
)
{
require_once
(
$file
);
// Then create the test class
$testName
=
str_replace
(
".php"
,
""
,
substr
(
$file
,
5
));
if
(
!
class_exists
(
$testName
))
continue
;
$class
=
new
$testName
();
$result
=
$class
->
doTest
();
if
(
!
$result
&&
$class
->
failedLevel
!=
"info"
)
$passed
=
false
;
$outputArray
[]
=
array
(
"name"
=>
$class
->
name
,
"result"
=>
$result
,
"level"
=>
$class
->
failedLevel
,
"info"
=>
$class
->
failedInfo
);
if
(
count
(
$class
->
testedParams
))
{
$testedParams
=
array_merge
(
$testedParams
,
$class
->
testedParams
);
}
}
// PREPARE REPOSITORY LISTS
$repoList
=
array
();
require_once
(
"../classes/class.ConfService.php"
);
require_once
(
"../classes/class.Repository.php"
);
include
(
AJXP_CONF_PATH
.
"/bootstrap_repositories.php"
);
foreach
(
$REPOSITORIES
as
$index
=>
$repo
)
{
$repoList
[]
=
ConfService
::
createRepositoryFromArray
(
$index
,
$repo
);
}
// Try with the serialized repositories
if
(
is_file
(
AJXP_DATA_PATH
.
"/plugins/conf.serial/repo.ser"
))
{
$fileLines
=
file
(
AJXP_DATA_PATH
.
"/plugins/conf.serial/repo.ser"
);
$repos
=
unserialize
(
$fileLines
[
0
]);
$repoList
=
array_merge
(
$repoList
,
$repos
);
}
// NOW TRY THE PLUGIN TESTS
chdir
(
AJXP_INSTALL_PATH
.
"/"
.
AJXP_PLUGINS_FOLDER
);
$files
=
glob
(
'access.*/test.*.php'
);
foreach
(
$files
as
$file
)
{
require_once
(
$file
);
// Then create the test class
list
(
$accessFolder
,
$testFileName
)
=
explode
(
"/"
,
$file
);
$testName
=
str_replace
(
".php"
,
""
,
substr
(
$testFileName
,
5
)
.
"Test"
);
$class
=
new
$testName
();
foreach
(
$repoList
as
$repository
)
{
if
(
$repository
->
isTemplate
||
$repository
->
getParentId
()
!=
null
)
continue
;
$result
=
$class
->
doRepositoryTest
(
$repository
);
if
(
$result
===
false
||
$result
===
true
)
{
if
(
!
$result
&&
$class
->
failedLevel
!=
"info"
)
{
$passed
=
false
;
}
$outputArray
[]
=
array
(
"name"
=>
$class
->
name
.
"
\n
Testing repository : "
.
$repository
->
getDisplay
(),
"result"
=>
$result
,
"level"
=>
$class
->
failedLevel
,
"info"
=>
$class
->
failedInfo
);
if
(
count
(
$class
->
testedParams
))
{
$testedParams
=
array_merge
(
$testedParams
,
$class
->
testedParams
);
}
}
}
}
return
$passed
;
}
/**
* @static
* @param $outputArray
* @param $testedParams
* @return void
*/
static
function
testResultsToFile
(
$outputArray
,
$testedParams
)
{
ob_start
();
echo
'$diagResults = '
;
var_export
(
$testedParams
);
echo
';'
;
echo
'$outputArray = '
;
var_export
(
$outputArray
);
echo
';'
;
$content
=
'<?php '
.
ob_get_contents
()
.
' ?>'
;
ob_end_clean
();
//print_r($content);
file_put_contents
(
TESTS_RESULT_FILE
,
$content
);
}
static
function
isStream
(
$path
){
$wrappers
=
stream_get_wrappers
();
$wrappers_re
=
'('
.
join
(
'|'
,
$wrappers
)
.
')'
;
return
preg_match
(
"!^
$wrappers_re
://!"
,
$path
)
===
1
;
}
/**
* Load an array stored serialized inside a file.
*
* @param String $filePath Full path to the file
* @param Boolean $skipCheck do not test for file existence before opening
* @return Array
*/
static
function
loadSerialFile
(
$filePath
,
$skipCheck
=
false
,
$format
=
"ser"
)
{
$filePath
=
AJXP_VarsFilter
::
filter
(
$filePath
);
$result
=
array
();
if
(
$skipCheck
){
$fileLines
=
@
file
(
$filePath
);
if
(
$fileLines
!==
false
)
{
if
(
$format
==
"ser"
)
$result
=
unserialize
(
implode
(
""
,
$fileLines
));
else
if
(
$format
==
"json"
)
$result
=
json_decode
(
implode
(
""
,
$fileLines
),
true
);
}
return
$result
;
}
if
(
is_file
(
$filePath
))
{
$fileLines
=
file
(
$filePath
);
if
(
$format
==
"ser"
)
$result
=
unserialize
(
implode
(
""
,
$fileLines
));
else
if
(
$format
==
"json"
)
$result
=
json_decode
(
implode
(
""
,
$fileLines
),
true
);
}
return
$result
;
}
/**
* Stores an Array as a serialized string inside a file.
*
* @param String $filePath Full path to the file
* @param Array|Object $value The value to store
* @param Boolean $createDir Whether to create the parent folder or not, if it does not exist.
* @param bool $silent Silently write the file, are throw an exception on problem.
* @param string $format
* @throws Exception
*/
static
function
saveSerialFile
(
$filePath
,
$value
,
$createDir
=
true
,
$silent
=
false
,
$format
=
"ser"
,
$jsonPrettyPrint
=
false
)
{
$filePath
=
AJXP_VarsFilter
::
filter
(
$filePath
);
if
(
$createDir
&&
!
is_dir
(
dirname
(
$filePath
))){
@
mkdir
(
dirname
(
$filePath
),
0755
,
true
);
if
(
!
is_dir
(
dirname
(
$filePath
))){
// Creation failed
if
(
$silent
)
return
;
else
throw
new
Exception
(
"[AJXP_Utils::saveSerialFile] Cannot write into "
.
dirname
(
dirname
(
$filePath
)));
}
}
try
{
$fp
=
fopen
(
$filePath
,
"w"
);
if
(
$format
==
"ser"
)
$content
=
serialize
(
$value
);
else
if
(
$format
==
"json"
)
{
$content
=
json_encode
(
$value
);
if
(
$jsonPrettyPrint
)
$content
=
self
::
prettyPrintJSON
(
$content
);
}
fwrite
(
$fp
,
$content
);
fclose
(
$fp
);
}
catch
(
Exception
$e
)
{
if
(
$silent
)
return
;
else
throw
$e
;
}
}
/**
* Detect mobile browsers
* @static
* @return bool
*/
public
static
function
userAgentIsMobile
()
{
$isMobile
=
false
;
$op
=
strtolower
(
$_SERVER
[
'HTTP_X_OPERAMINI_PHONE'
]
OR
""
);
$ua
=
strtolower
(
$_SERVER
[
'HTTP_USER_AGENT'
]);
$ac
=
strtolower
(
$_SERVER
[
'HTTP_ACCEPT'
]);
$isMobile
=
strpos
(
$ac
,
'application/vnd.wap.xhtml+xml'
)
!==
false
||
$op
!=
''
||
strpos
(
$ua
,
'sony'
)
!==
false
||
strpos
(
$ua
,
'symbian'
)
!==
false
||
strpos
(
$ua
,
'nokia'
)
!==
false
||
strpos
(
$ua
,
'samsung'
)
!==
false
||
strpos
(
$ua
,
'mobile'
)
!==
false
||
strpos
(
$ua
,
'android'
)
!==
false
||
strpos
(
$ua
,
'windows ce'
)
!==
false
||
strpos
(
$ua
,
'epoc'
)
!==
false
||
strpos
(
$ua
,
'opera mini'
)
!==
false
||
strpos
(
$ua
,
'nitro'
)
!==
false
||
strpos
(
$ua
,
'j2me'
)
!==
false
||
strpos
(
$ua
,
'midp-'
)
!==
false
||
strpos
(
$ua
,
'cldc-'
)
!==
false
||
strpos
(
$ua
,
'netfront'
)
!==
false
||
strpos
(
$ua
,
'mot'
)
!==
false
||
strpos
(
$ua
,
'up.browser'
)
!==
false
||
strpos
(
$ua
,
'up.link'
)
!==
false
||
strpos
(
$ua
,
'audiovox'
)
!==
false
||
strpos
(
$ua
,
'blackberry'
)
!==
false
||
strpos
(
$ua
,
'ericsson,'
)
!==
false
||
strpos
(
$ua
,
'panasonic'
)
!==
false
||
strpos
(
$ua
,
'philips'
)
!==
false
||
strpos
(
$ua
,
'sanyo'
)
!==
false
||
strpos
(
$ua
,
'sharp'
)
!==
false
||
strpos
(
$ua
,
'sie-'
)
!==
false
||
strpos
(
$ua
,
'portalmmm'
)
!==
false
||
strpos
(
$ua
,
'blazer'
)
!==
false
||
strpos
(
$ua
,
'avantgo'
)
!==
false
||
strpos
(
$ua
,
'danger'
)
!==
false
||
strpos
(
$ua
,
'palm'
)
!==
false
||
strpos
(
$ua
,
'series60'
)
!==
false
||
strpos
(
$ua
,
'palmsource'
)
!==
false
||
strpos
(
$ua
,
'pocketpc'
)
!==
false
||
strpos
(
$ua
,
'smartphone'
)
!==
false
||
strpos
(
$ua
,
'rover'
)
!==
false
||
strpos
(
$ua
,
'ipaq'
)
!==
false
||
strpos
(
$ua
,
'au-mic,'
)
!==
false
||
strpos
(
$ua
,
'alcatel'
)
!==
false
||
strpos
(
$ua
,
'ericy'
)
!==
false
||
strpos
(
$ua
,
'up.link'
)
!==
false
||
strpos
(
$ua
,
'vodafone/'
)
!==
false
||
strpos
(
$ua
,
'wap1.'
)
!==
false
||
strpos
(
$ua
,
'wap2.'
)
!==
false
;
/*
$isBot = false;
$ip = $_SERVER['REMOTE_ADDR'];
$isBot = $ip == '66.249.65.39'
|| strpos($ua, 'googlebot') !== false
|| strpos($ua, 'mediapartners') !== false
|| strpos($ua, 'yahooysmcm') !== false
|| strpos($ua, 'baiduspider') !== false
|| strpos($ua, 'msnbot') !== false
|| strpos($ua, 'slurp') !== false
|| strpos($ua, 'ask') !== false
|| strpos($ua, 'teoma') !== false
|| strpos($ua, 'spider') !== false
|| strpos($ua, 'heritrix') !== false
|| strpos($ua, 'attentio') !== false
|| strpos($ua, 'twiceler') !== false
|| strpos($ua, 'irlbot') !== false
|| strpos($ua, 'fast crawler') !== false
|| strpos($ua, 'fastmobilecrawl') !== false
|| strpos($ua, 'jumpbot') !== false
|| strpos($ua, 'googlebot-mobile') !== false
|| strpos($ua, 'yahooseeker') !== false
|| strpos($ua, 'motionbot') !== false
|| strpos($ua, 'mediobot') !== false
|| strpos($ua, 'chtml generic') !== false
|| strpos($ua, 'nokia6230i/. fast crawler') !== false;
*/
return
$isMobile
;
}
/**
* Detect iOS browser
* @static
* @return bool
*/
public
static
function
userAgentIsIOS
()
{
if
(
stripos
(
$_SERVER
[
"HTTP_USER_AGENT"
],
"iphone"
)
!==
false
)
return
true
;
if
(
stripos
(
$_SERVER
[
"HTTP_USER_AGENT"
],
"ipad"
)
!==
false
)
return
true
;
if
(
stripos
(
$_SERVER
[
"HTTP_USER_AGENT"
],
"ipod"
)
!==
false
)
return
true
;
return
false
;
}
/**
* Detect Android UA
* @static
* @return bool
*/
public
static
function
userAgentIsAndroid
()
{
return
(
stripos
(
$_SERVER
[
"HTTP_USER_AGENT"
],
"android"
)
!==
false
);
}
/**
* Try to remove a file without errors
* @static
* @param $file
* @return void
*/
public
static
function
silentUnlink
(
$file
)
{
@
unlink
(
$file
);
}
/**
* Try to set an ini config, without errors
* @static
* @param string $paramName
* @param string $paramValue
* @return void
*/
public
static
function
safeIniSet
(
$paramName
,
$paramValue
)
{
$current
=
ini_get
(
$paramName
);
if
(
$current
==
$paramValue
)
return
;
@
ini_set
(
$paramName
,
$paramValue
);
}
/**
* @static
* @param string $url
* @return bool|mixed|string
*/
public
static
function
getRemoteContent
(
$url
){
if
(
ini_get
(
"allow_url_fopen"
)){
return
file_get_contents
(
$url
);
}
else
if
(
function_exists
(
"curl_init"
)){
$ch
=
curl_init
();
$timeout
=
30
;
// set to zero for no timeout
curl_setopt
(
$ch
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$ch
,
CURLOPT_CONNECTTIMEOUT
,
$timeout
);
$return
=
curl_exec
(
$ch
);
curl_close
(
$ch
);
return
$return
;
}
else
{
$i
=
parse_url
(
$url
);
$httpClient
=
new
HttpClient
(
$i
[
"host"
]);
$httpClient
->
timeout
=
30
;
return
$httpClient
->
quickGet
(
$url
);
}
}
public
static
function
parseStandardFormParameters
(
&
$repDef
,
&
$options
,
$userId
=
null
,
$prefix
=
"DRIVER_OPTION_"
,
$binariesContext
=
null
){
if
(
$binariesContext
===
null
){
$binariesContext
=
array
(
"USER"
=>
(
AuthService
::
getLoggedUser
()
!=
null
)
?
AuthService
::
getLoggedUser
()
->
getId
()
:
"shared"
);
}
$replicationGroups
=
array
();
$switchesGroups
=
array
();
foreach
(
$repDef
as
$key
=>
$value
)
{
$value
=
SystemTextEncoding
::
magicDequote
(
$value
);
if
(
(
(
!
empty
(
$prefix
)
&&
strpos
(
$key
,
$prefix
)
!==
false
&&
strpos
(
$key
,
$prefix
)
==
0
)
||
empty
(
$prefix
)
)
&&
strpos
(
$key
,
"ajxptype"
)
===
false
&&
strpos
(
$key
,
"_original_binary"
)
===
false
&&
strpos
(
$key
,
"_replication"
)
===
false
&&
strpos
(
$key
,
"_checkbox"
)
===
false
){
if
(
isSet
(
$repDef
[
$key
.
"_ajxptype"
])){
$type
=
$repDef
[
$key
.
"_ajxptype"
];
if
(
$type
==
"boolean"
){
$value
=
(
$value
==
"true"
?
true
:
false
);
}
else
if
(
$type
==
"integer"
){
$value
=
intval
(
$value
);
}
else
if
(
$type
==
"array"
){
$value
=
explode
(
","
,
$value
);
}
else
if
(
$type
==
"password"
&&
$userId
!=
null
){
if
(
trim
(
$value
!=
""
)
&&
function_exists
(
'mcrypt_encrypt'
))
{
// The initialisation vector is only required to avoid a warning, as ECB ignore IV
$iv
=
mcrypt_create_iv
(
mcrypt_get_iv_size
(
MCRYPT_RIJNDAEL_256
,
MCRYPT_MODE_ECB
),
MCRYPT_RAND
);
// We encode as base64 so if we need to store the result in a database, it can be stored in text column
$value
=
base64_encode
(
mcrypt_encrypt
(
MCRYPT_RIJNDAEL_256
,
md5
(
$userId
.
"
\1
CDAFx¨op#"
),
$value
,
MCRYPT_MODE_ECB
,
$iv
));
}
}
else
if
(
$type
==
"binary"
&&
$binariesContext
!==
null
){
if
(
!
empty
(
$value
)){
if
(
$value
==
"ajxp-remove-original"
){
if
(
!
empty
(
$repDef
[
$key
.
"_original_binary"
])){
ConfService
::
getConfStorageImpl
()
->
deleteBinary
(
$binariesContext
,
$repDef
[
$key
.
"_original_binary"
]);
}
$value
=
""
;
}
else
{
$file
=
AJXP_Utils
::
getAjxpTmpDir
()
.
"/"
.
$value
;
if
(
file_exists
(
$file
)){
$id
=
!
empty
(
$repDef
[
$key
.
"_original_binary"
])
?
$repDef
[
$key
.
"_original_binary"
]
:
null
;
$id
=
ConfService
::
getConfStorageImpl
()
->
saveBinary
(
$binariesContext
,
$file
,
$id
);
$value
=
$id
;
}
}
}
else
if
(
!
empty
(
$repDef
[
$key
.
"_original_binary"
])){
$value
=
$repDef
[
$key
.
"_original_binary"
];
}
}
else
if
(
strpos
(
$type
,
"group_switch:"
)
===
0
){
$tmp
=
explode
(
":"
,
$type
);
$gSwitchName
=
$tmp
[
1
];
$switchesGroups
[
substr
(
$key
,
strlen
(
$prefix
))]
=
$gSwitchName
;
}
else
if
(
$type
==
"text/json"
){
$value
=
json_decode
(
$value
,
true
);
}
if
(
!
in_array
(
$type
,
array
(
"textarea"
,
"boolean"
,
"text/json"
))){
$value
=
AJXP_Utils
::
sanitize
(
$value
,
AJXP_SANITIZE_HTML
);
}
unset
(
$repDef
[
$key
.
"_ajxptype"
]);
}
if
(
isSet
(
$repDef
[
$key
.
"_checkbox"
])){
$checked
=
$repDef
[
$key
.
"_checkbox"
]
==
"checked"
;
unset
(
$repDef
[
$key
.
"_checkbox"
]);
if
(
!
$checked
)
continue
;
}
if
(
isSet
(
$repDef
[
$key
.
"_replication"
])){
$repKey
=
$repDef
[
$key
.
"_replication"
];
if
(
!
is_array
(
$replicationGroups
[
$repKey
]))
$replicationGroups
[
$repKey
]
=
array
();
$replicationGroups
[
$repKey
][]
=
$key
;
}
$options
[
substr
(
$key
,
strlen
(
$prefix
))]
=
$value
;
unset
(
$repDef
[
$key
]);
}
else
{
if
(
$key
==
"DISPLAY"
){
$value
=
SystemTextEncoding
::
fromUTF8
(
AJXP_Utils
::
securePath
(
$value
));
}
$repDef
[
$key
]
=
$value
;
}
}
// DO SOMETHING WITH REPLICATED PARAMETERS?
if
(
count
(
$switchesGroups
)){
foreach
(
$switchesGroups
as
$fieldName
=>
$groupName
){
if
(
isSet
(
$options
[
$fieldName
])){
$gValues
=
array
();
$radic
=
$groupName
.
"_"
.
$options
[
$fieldName
]
.
"_"
;
foreach
(
$options
as
$optN
=>
$optV
){
if
(
strpos
(
$optN
,
$radic
)
===
0
){
$newName
=
substr
(
$optN
,
strlen
(
$radic
));
$gValues
[
$newName
]
=
$optV
;
}
}
}
$options
[
$fieldName
.
"_group_switch"
]
=
$options
[
$fieldName
];
$options
[
$fieldName
]
=
$gValues
;
}
}
}
public
static
function
cleanDibiDriverParameters
(
$params
){
if
(
!
is_array
(
$params
))
return
$params
;
$value
=
$params
[
"group_switch_value"
];
if
(
isSet
(
$value
)){
if
(
$value
==
"core"
){
$bootStorage
=
ConfService
::
getBootConfStorageImpl
();
$configs
=
$bootStorage
->
loadPluginConfig
(
"core"
,
"conf"
);
$params
=
$configs
[
"DIBI_PRECONFIGURATION"
];
}
else
{
unset
(
$params
[
"group_switch_value"
]);
}
foreach
(
$params
as
$k
=>
$v
){
$params
[
array_pop
(
explode
(
"_"
,
$k
,
2
))]
=
AJXP_VarsFilter
::
filter
(
$v
);
unset
(
$params
[
$k
]);
}
}
return
$params
;
}
public
static
function
runCreateTablesQuery
(
$p
,
$file
){
require_once
(
AJXP_BIN_FOLDER
.
"/dibi.compact.php"
);
$result
=
array
();
if
(
$p
[
"driver"
]
==
"sqlite"
||
$p
[
"driver"
]
==
"sqlite3"
){
if
(
!
file_exists
(
dirname
(
$p
[
"database"
]))){
@
mkdir
(
dirname
(
$p
[
"database"
]),
0755
,
true
);
}
dibi
::
connect
(
$p
);
$file
=
dirname
(
$file
)
.
"/"
.
str_replace
(
".sql"
,
".sqlite"
,
basename
(
$file
)
);
$sql
=
file_get_contents
(
$file
);
dibi
::
begin
();
$parts
=
explode
(
"CREATE TABLE"
,
$sql
);
foreach
(
$parts
as
$createPart
){
if
(
empty
(
$createPart
))
continue
;
$sqlPart
=
trim
(
"CREATE TABLE"
.
$createPart
);
try
{
dibi
::
nativeQuery
(
$sqlPart
);
$resKey
=
str_replace
(
"
\n
"
,
""
,
substr
(
$sqlPart
,
0
,
50
))
.
"..."
;
$result
[]
=
"OK:
$resKey
executed successfully"
;
}
catch
(
DibiException
$e
){
$result
[]
=
"ERROR!
$sqlPart
failed"
;
}
}
$message
=
implode
(
"
\n
"
,
$result
);
dibi
::
commit
();
dibi
::
disconnect
();
}
else
{
dibi
::
connect
(
$p
);
$sql
=
file_get_contents
(
$file
);
$parts
=
explode
(
"CREATE TABLE"
,
$sql
);
foreach
(
$parts
as
$createPart
){
if
(
empty
(
$createPart
))
continue
;
$sqlPart
=
trim
(
"CREATE TABLE"
.
$createPart
);
try
{
dibi
::
nativeQuery
(
$sqlPart
);
$resKey
=
str_replace
(
"
\n
"
,
""
,
substr
(
$sqlPart
,
0
,
50
))
.
"..."
;
$result
[]
=
"OK:
$resKey
executed successfully"
;
}
catch
(
DibiException
$e
){
$result
[]
=
"ERROR!
$sqlPart
failed"
;
}
}
$message
=
implode
(
"
\n
"
,
$result
);
dibi
::
disconnect
();
}
if
(
strpos
(
$message
,
"ERROR!"
))
return
$message
;
else
return
"SUCCESS:"
.
$message
;
}
}
\ No newline at end of file
software/davstorage/templates/class.phpmailer-lite.php
0 → 100644
View file @
72e10a30
<?php
/*~ class.phpmailer-lite.php
.---------------------------------------------------------------------------.
| Software: PHPMailer Lite - PHP email class |
| Version: 5.1 |
| Contact: via sourceforge.net support pages (also www.codeworxtech.com) |
| Info: http://phpmailer.sourceforge.net |
| Support: http://sourceforge.net/projects/phpmailer/ |
| ------------------------------------------------------------------------- |
| Admin: Andy Prevost (project admininistrator) |
| Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
| : Marcus Bointon (coolbru) coolbru@users.sourceforge.net |
| Founder: Brent R. Matzelle (original founder) |
| Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved. |
| Copyright (c) 2001-2003, Brent R. Matzelle |
| ------------------------------------------------------------------------- |
| License: Distributed under the Lesser General Public License (LGPL) |
| http://www.gnu.org/copyleft/lesser.html |
| This program is distributed in the hope that it will be useful - WITHOUT |
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| FITNESS FOR A PARTICULAR PURPOSE. |
| ------------------------------------------------------------------------- |
| We offer a number of paid services (www.codeworxtech.com): |
| - Web Hosting on highly optimized fast and secure servers |
| - Technology Consulting |
| - Oursourcing (highly qualified programmers and graphic designers) |
'---------------------------------------------------------------------------'
*/
/**
* PHPMailer Lite - PHP email transport class
* NOTE: Requires PHP version 5 or later
* @package PHPMailer Lite
* @author Andy Prevost
* @author Marcus Bointon
* @copyright 2004 - 2009 Andy Prevost
* @version $Id: class.phpmailer-lite.php 447 2009-09-12 13:21:38Z codeworxtech $
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
if
(
version_compare
(
PHP_VERSION
,
'5.0.0'
,
'<'
)
)
exit
(
"Sorry, this version of PHPMailer will only run on PHP version 5 or greater!
\n
"
);
class
PHPMailerLite
{
/////////////////////////////////////////////////
// PROPERTIES, PUBLIC
/////////////////////////////////////////////////
/**
* Email priority (1 = High, 3 = Normal, 5 = low).
* @var int
*/
public
$Priority
=
3
;
/**
* Sets the CharSet of the message.
* @var string
*/
public
$CharSet
=
'iso-8859-1'
;
/**
* Sets the Content-type of the message.
* @var string
*/
public
$ContentType
=
'text/plain'
;
/**
* Sets the Encoding of the message. Options for this are
* "8bit", "7bit", "binary", "base64", and "quoted-printable".
* @var string
*/
public
$Encoding
=
'8bit'
;
/**
* Holds the most recent mailer error message.
* @var string
*/
public
$ErrorInfo
=
''
;
/**
* Sets the From email address for the message.
* @var string
*/
public
$From
=
'root@localhost'
;
/**
* Sets the From name of the message.
* @var string
*/
public
$FromName
=
'Root User'
;
/**
* Sets the Sender email (Return-Path) of the message. If not empty,
* will be sent via -f to sendmail
* @var string
*/
public
$Sender
=
''
;
/**
* Sets the Subject of the message.
* @var string
*/
public
$Subject
=
''
;
/**
* Sets the Body of the message. This can be either an HTML or text body.
* If HTML then run IsHTML(true).
* @var string
*/
public
$Body
=
''
;
/**
* Sets the text-only body of the message. This automatically sets the
* email to multipart/alternative. This body can be read by mail
* clients that do not have HTML email capability such as mutt. Clients
* that can read HTML will view the normal Body.
* @var string
*/
public
$AltBody
=
''
;
/**
* Sets word wrapping on the body of the message to a given number of
* characters.
* @var int
*/
public
$WordWrap
=
0
;
/**
* Method to send mail: ("mail", or "sendmail").
* @var string
*/
public
$Mailer
=
'sendmail'
;
/**
* Sets the path of the sendmail program.
* @var string
*/
public
$Sendmail
=
'${:sendmail-script}'
;
/**
* Sets the email address that a reading confirmation will be sent.
* @var string
*/
public
$ConfirmReadingTo
=
''
;
/**
* Sets the hostname to use in Message-Id and Received headers
* and as default HELO string. If empty, the value returned
* by SERVER_NAME is used or 'localhost.localdomain'.
* @var string
*/
public
$Hostname
=
''
;
/**
* Sets the message ID to be used in the Message-Id header.
* If empty, a unique id will be generated.
* @var string
*/
public
$MessageID
=
''
;
/**
* Provides the ability to have the TO field process individual
* emails, instead of sending to entire TO addresses
* @var bool
*/
public
$SingleTo
=
true
;
/**
* If SingleTo is true, this provides the array to hold the email addresses
* @var bool
*/
public
$SingleToArray
=
array
();
/**
* Provides the ability to change the line ending
* @var string
*/
public
$LE
=
"
\n
"
;
/**
* Used with DKIM DNS Resource Record
* @var string
*/
public
$DKIM_selector
=
'phpmailer'
;
/**
* Used with DKIM DNS Resource Record
* optional, in format of email address 'you@yourdomain.com'
* @var string
*/
public
$DKIM_identity
=
''
;
/**
* Used with DKIM DNS Resource Record
* required, in format of base domain 'yourdomain.com'
* @var string
*/
public
$DKIM_domain
=
''
;
/**
* Used with DKIM Digital Signing process
* optional
* @var string
*/
public
$DKIM_passphrase
=
''
;
/**
* Used with DKIM DNS Resource Record
* required, private key (read from /.htprivkey)
* @var string
*/
public
$DKIM_private
=
''
;
/**
* Callback Action function name
* the function that handles the result of the send email action. Parameters:
* bool $result result of the send action
* string $to email address of the recipient
* string $cc cc email addresses
* string $bcc bcc email addresses
* string $subject the subject
* string $body the email body
* @var string
*/
public
$action_function
=
''
;
//'callbackAction';
/**
* Sets the PHPMailer Version number
* @var string
*/
public
$Version
=
'Lite 5.1'
;
/////////////////////////////////////////////////
// PROPERTIES, PRIVATE AND PROTECTED
/////////////////////////////////////////////////
private
$to
=
array
();
private
$cc
=
array
();
private
$bcc
=
array
();
private
$ReplyTo
=
array
();
private
$all_recipients
=
array
();
private
$attachment
=
array
();
private
$CustomHeader
=
array
();
private
$message_type
=
''
;
private
$boundary
=
array
();
protected
$language
=
array
();
private
$error_count
=
0
;
private
$sign_cert_file
=
""
;
private
$sign_key_file
=
""
;
private
$sign_key_pass
=
""
;
private
$exceptions
=
false
;
/////////////////////////////////////////////////
// CONSTANTS
/////////////////////////////////////////////////
const
STOP_MESSAGE
=
0
;
// message only, continue processing
const
STOP_CONTINUE
=
1
;
// message?, likely ok to continue processing
const
STOP_CRITICAL
=
2
;
// message, plus full stop, critical error reached
/////////////////////////////////////////////////
// METHODS, VARIABLES
/////////////////////////////////////////////////
/**
* Constructor
* @param boolean $exceptions Should we throw external exceptions?
*/
public
function
__construct
(
$exceptions
=
false
)
{
$this
->
exceptions
=
(
$exceptions
==
true
);
}
/**
* Sets message type to HTML.
* @param bool $ishtml
* @return void
*/
public
function
IsHTML
(
$ishtml
=
true
)
{
if
(
$ishtml
)
{
$this
->
ContentType
=
'text/html'
;
}
else
{
$this
->
ContentType
=
'text/plain'
;
}
}
/**
* Sets Mailer to send message using PHP mail() function.
* @return void
*/
public
function
IsMail
()
{
$this
->
Mailer
=
'mail'
;
}
/**
* Sets Mailer to send message using the $Sendmail program.
* @return void
*/
public
function
IsSendmail
()
{
if
(
!
stristr
(
ini_get
(
'sendmail_path'
),
'sendmail'
))
{
$this
->
Sendmail
=
'/var/qmail/bin/sendmail'
;
}
$this
->
Mailer
=
'sendmail'
;
}
/**
* Sets Mailer to send message using the qmail MTA.
* @return void
*/
public
function
IsQmail
()
{
if
(
stristr
(
ini_get
(
'sendmail_path'
),
'qmail'
))
{
$this
->
Sendmail
=
'/var/qmail/bin/sendmail'
;
}
$this
->
Mailer
=
'sendmail'
;
}
/////////////////////////////////////////////////
// METHODS, RECIPIENTS
/////////////////////////////////////////////////
/**
* Adds a "To" address.
* @param string $address
* @param string $name
* @return boolean true on success, false if address already used
*/
public
function
AddAddress
(
$address
,
$name
=
''
)
{
return
$this
->
AddAnAddress
(
'to'
,
$address
,
$name
);
}
/**
* Adds a "Cc" address.
* Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.
* @param string $address
* @param string $name
* @return boolean true on success, false if address already used
*/
public
function
AddCC
(
$address
,
$name
=
''
)
{
return
$this
->
AddAnAddress
(
'cc'
,
$address
,
$name
);
}
/**
* Adds a "Bcc" address.
* Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.
* @param string $address
* @param string $name
* @return boolean true on success, false if address already used
*/
public
function
AddBCC
(
$address
,
$name
=
''
)
{
return
$this
->
AddAnAddress
(
'bcc'
,
$address
,
$name
);
}
/**
* Adds a "Reply-to" address.
* @param string $address
* @param string $name
* @return boolean
*/
public
function
AddReplyTo
(
$address
,
$name
=
''
)
{
return
$this
->
AddAnAddress
(
'ReplyTo'
,
$address
,
$name
);
}
/**
* Adds an address to one of the recipient arrays
* Addresses that have been added already return false, but do not throw exceptions
* @param string $kind One of 'to', 'cc', 'bcc', 'ReplyTo'
* @param string $address The email address to send to
* @param string $name
* @return boolean true on success, false if address already used or invalid in some way
* @access private
*/
private
function
AddAnAddress
(
$kind
,
$address
,
$name
=
''
)
{
if
(
!
preg_match
(
'/^(to|cc|bcc|ReplyTo)$/'
,
$kind
))
{
echo
'Invalid recipient array: '
.
kind
;
return
false
;
}
$address
=
trim
(
$address
);
$name
=
trim
(
preg_replace
(
'/[\r\n]+/'
,
''
,
$name
));
//Strip breaks and trim
if
(
!
self
::
ValidateAddress
(
$address
))
{
$this
->
SetError
(
$this
->
Lang
(
'invalid_address'
)
.
': '
.
$address
);
if
(
$this
->
exceptions
)
{
throw
new
phpmailerException
(
$this
->
Lang
(
'invalid_address'
)
.
': '
.
$address
);
}
echo
$this
->
Lang
(
'invalid_address'
)
.
': '
.
$address
;
return
false
;
}
if
(
$kind
!=
'ReplyTo'
)
{
if
(
!
isset
(
$this
->
all_recipients
[
strtolower
(
$address
)]))
{
array_push
(
$this
->
$kind
,
array
(
$address
,
$name
));
$this
->
all_recipients
[
strtolower
(
$address
)]
=
true
;
return
true
;
}
}
else
{
if
(
!
array_key_exists
(
strtolower
(
$address
),
$this
->
ReplyTo
))
{
$this
->
ReplyTo
[
strtolower
(
$address
)]
=
array
(
$address
,
$name
);
return
true
;
}
}
return
false
;
}
/**
* Set the From and FromName properties
* @param string $address
* @param string $name
* @return boolean
*/
public
function
SetFrom
(
$address
,
$name
=
''
,
$auto
=
1
)
{
$address
=
trim
(
$address
);
$name
=
trim
(
preg_replace
(
'/[\r\n]+/'
,
''
,
$name
));
//Strip breaks and trim
if
(
!
self
::
ValidateAddress
(
$address
))
{
$this
->
SetError
(
$this
->
Lang
(
'invalid_address'
)
.
': '
.
$address
);
if
(
$this
->
exceptions
)
{
throw
new
phpmailerException
(
$this
->
Lang
(
'invalid_address'
)
.
': '
.
$address
);
}
echo
$this
->
Lang
(
'invalid_address'
)
.
': '
.
$address
;
return
false
;
}
$this
->
From
=
$address
;
$this
->
FromName
=
$name
;
if
(
$auto
)
{
if
(
empty
(
$this
->
ReplyTo
))
{
$this
->
AddAnAddress
(
'ReplyTo'
,
$address
,
$name
);
}
if
(
empty
(
$this
->
Sender
))
{
$this
->
Sender
=
$address
;
}
}
return
true
;
}
/**
* Check that a string looks roughly like an email address should
* Static so it can be used without instantiation
* Tries to use PHP built-in validator in the filter extension (from PHP 5.2), falls back to a reasonably competent regex validator
* Conforms approximately to RFC2822
* @link http://www.hexillion.com/samples/#Regex Original pattern found here
* @param string $address The email address to check
* @return boolean
* @static
* @access public
*/
public
static
function
ValidateAddress
(
$address
)
{
if
(
function_exists
(
'filter_var'
))
{
//Introduced in PHP 5.2
if
(
filter_var
(
$address
,
FILTER_VALIDATE_EMAIL
)
===
FALSE
)
{
return
false
;
}
else
{
return
true
;
}
}
else
{
return
preg_match
(
'/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/'
,
$address
);
}
}
/////////////////////////////////////////////////
// METHODS, MAIL SENDING
/////////////////////////////////////////////////
/**
* Creates message and assigns Mailer. If the message is
* not sent successfully then it returns false. Use the ErrorInfo
* variable to view description of the error.
* @return bool
*/
public
function
Send
()
{
try
{
if
((
count
(
$this
->
to
)
+
count
(
$this
->
cc
)
+
count
(
$this
->
bcc
))
<
1
)
{
throw
new
phpmailerException
(
$this
->
Lang
(
'provide_address'
),
self
::
STOP_CRITICAL
);
}
// Set whether the message is multipart/alternative
if
(
!
empty
(
$this
->
AltBody
))
{
$this
->
ContentType
=
'multipart/alternative'
;
}
$this
->
error_count
=
0
;
// reset errors
$this
->
SetMessageType
();
$header
=
$this
->
CreateHeader
();
$body
=
$this
->
CreateBody
();
if
(
empty
(
$this
->
Body
))
{
throw
new
phpmailerException
(
$this
->
Lang
(
'empty_message'
),
self
::
STOP_CRITICAL
);
}
// digitally sign with DKIM if enabled
if
(
$this
->
DKIM_domain
&&
$this
->
DKIM_private
)
{
$header_dkim
=
$this
->
DKIM_Add
(
$header
,
$this
->
Subject
,
$body
);
$header
=
str_replace
(
"
\r\n
"
,
"
\n
"
,
$header_dkim
)
.
$header
;
}
// Choose the mailer and send through it
switch
(
$this
->
Mailer
)
{
case
'sendmail'
:
$sendAction
=
$this
->
SendmailSend
(
$header
,
$body
);
return
$sendAction
;
default
:
$sendAction
=
$this
->
MailSend
(
$header
,
$body
);
return
$sendAction
;
}
}
catch
(
phpmailerException
$e
)
{
$this
->
SetError
(
$e
->
getMessage
());
if
(
$this
->
exceptions
)
{
throw
$e
;
}
echo
$e
->
getMessage
()
.
"
\n
"
;
return
false
;
}
}
/**
* Sends mail using the $Sendmail program.
* @param string $header The message headers
* @param string $body The message body
* @access protected
* @return bool
*/
protected
function
SendmailSend
(
$header
,
$body
)
{
if
(
$this
->
Sender
!=
''
)
{
$sendmail
=
sprintf
(
"%s -oi -f %s -t"
,
escapeshellcmd
(
$this
->
Sendmail
),
escapeshellarg
(
$this
->
Sender
));
}
else
{
$sendmail
=
sprintf
(
"%s -oi -t"
,
escapeshellcmd
(
$this
->
Sendmail
));
}
if
(
$this
->
SingleTo
===
true
)
{
foreach
(
$this
->
SingleToArray
as
$key
=>
$val
)
{
if
(
!@
$mail
=
popen
(
$sendmail
,
'w'
))
{
throw
new
phpmailerException
(
$this
->
Lang
(
'execute'
)
.
$this
->
Sendmail
,
self
::
STOP_CRITICAL
);
}
fputs
(
$mail
,
"To: "
.
$val
.
"
\n
"
);
fputs
(
$mail
,
$header
);
fputs
(
$mail
,
$body
);
$result
=
pclose
(
$mail
);
// implement call back function if it exists
$isSent
=
(
$result
==
0
)
?
1
:
0
;
$this
->
doCallback
(
$isSent
,
$val
,
$this
->
cc
,
$this
->
bcc
,
$this
->
Subject
,
$body
);
if
(
$result
!=
0
)
{
throw
new
phpmailerException
(
$this
->
Lang
(
'execute'
)
.
$this
->
Sendmail
,
self
::
STOP_CRITICAL
);
}
}
}
else
{
if
(
!@
$mail
=
popen
(
$sendmail
,
'w'
))
{
throw
new
phpmailerException
(
$this
->
Lang
(
'execute'
)
.
$this
->
Sendmail
,
self
::
STOP_CRITICAL
);
}
fputs
(
$mail
,
$header
);
fputs
(
$mail
,
$body
);
$result
=
pclose
(
$mail
);
// implement call back function if it exists
$isSent
=
(
$result
==
0
)
?
1
:
0
;
$this
->
doCallback
(
$isSent
,
$this
->
to
,
$this
->
cc
,
$this
->
bcc
,
$this
->
Subject
,
$body
);
if
(
$result
!=
0
)
{
throw
new
phpmailerException
(
$this
->
Lang
(
'execute'
)
.
$this
->
Sendmail
,
self
::
STOP_CRITICAL
);
}
}
return
true
;
}
/**
* Sends mail using the PHP mail() function.
* @param string $header The message headers
* @param string $body The message body
* @access protected
* @return bool
*/
protected
function
MailSend
(
$header
,
$body
)
{
$toArr
=
array
();
foreach
(
$this
->
to
as
$t
)
{
$toArr
[]
=
$this
->
AddrFormat
(
$t
);
}
$to
=
implode
(
', '
,
$toArr
);
$params
=
sprintf
(
"-oi -f %s"
,
$this
->
Sender
);
if
(
$this
->
Sender
!=
''
&&
strlen
(
ini_get
(
'safe_mode'
))
<
1
)
{
$old_from
=
ini_get
(
'sendmail_from'
);
ini_set
(
'sendmail_from'
,
$this
->
Sender
);
if
(
$this
->
SingleTo
===
true
&&
count
(
$toArr
)
>
1
)
{
foreach
(
$toArr
as
$key
=>
$val
)
{
$rt
=
@
mail
(
$val
,
$this
->
EncodeHeader
(
$this
->
SecureHeader
(
$this
->
Subject
)),
$body
,
$header
,
$params
);
// implement call back function if it exists
$isSent
=
(
$rt
==
1
)
?
1
:
0
;
$this
->
doCallback
(
$isSent
,
$val
,
$this
->
cc
,
$this
->
bcc
,
$this
->
Subject
,
$body
);
}
}
else
{
$rt
=
@
mail
(
$to
,
$this
->
EncodeHeader
(
$this
->
SecureHeader
(
$this
->
Subject
)),
$body
,
$header
,
$params
);
// implement call back function if it exists
$isSent
=
(
$rt
==
1
)
?
1
:
0
;
$this
->
doCallback
(
$isSent
,
$to
,
$this
->
cc
,
$this
->
bcc
,
$this
->
Subject
,
$body
);
}
}
else
{
if
(
$this
->
SingleTo
===
true
&&
count
(
$toArr
)
>
1
)
{
foreach
(
$toArr
as
$key
=>
$val
)
{
$rt
=
@
mail
(
$val
,
$this
->
EncodeHeader
(
$this
->
SecureHeader
(
$this
->
Subject
)),
$body
,
$header
,
$params
);
// implement call back function if it exists
$isSent
=
(
$rt
==
1
)
?
1
:
0
;
$this
->
doCallback
(
$isSent
,
$val
,
$this
->
cc
,
$this
->
bcc
,
$this
->
Subject
,
$body
);
}
}
else
{
$rt
=
@
mail
(
$to
,
$this
->
EncodeHeader
(
$this
->
SecureHeader
(
$this
->
Subject
)),
$body
,
$header
);
// implement call back function if it exists
$isSent
=
(
$rt
==
1
)
?
1
:
0
;
$this
->
doCallback
(
$isSent
,
$to
,
$this
->
cc
,
$this
->
bcc
,
$this
->
Subject
,
$body
);
}
}
if
(
isset
(
$old_from
))
{
ini_set
(
'sendmail_from'
,
$old_from
);
}
if
(
!
$rt
)
{
throw
new
phpmailerException
(
$this
->
Lang
(
'instantiate'
),
self
::
STOP_CRITICAL
);
}
return
true
;
}
/**
* Sets the language for all class error messages.
* Returns false if it cannot load the language file. The default language is English.
* @param string $langcode ISO 639-1 2-character language code (e.g. Portuguese: "br")
* @param string $lang_path Path to the language file directory
* @access public
*/
function
SetLanguage
(
$langcode
=
'en'
,
$lang_path
=
'language/'
)
{
//Define full set of translatable strings
$PHPMAILER_LANG
=
array
(
'provide_address'
=>
'You must provide at least one recipient email address.'
,
'mailer_not_supported'
=>
' mailer is not supported.'
,
'execute'
=>
'Could not execute: '
,
'instantiate'
=>
'Could not instantiate mail function.'
,
'from_failed'
=>
'The following From address failed: '
,
'file_access'
=>
'Could not access file: '
,
'file_open'
=>
'File Error: Could not open file: '
,
'encoding'
=>
'Unknown encoding: '
,
'signing'
=>
'Signing Error: '
,
'empty_message'
=>
'Message body empty'
,
'invalid_address'
=>
'Invalid address'
,
'variable_set'
=>
'Cannot set or reset variable: '
);
//Overwrite language-specific strings. This way we'll never have missing translations - no more "language string failed to load"!
$l
=
true
;
if
(
$langcode
!=
'en'
)
{
//There is no English translation file
$l
=
@
include
$lang_path
.
'phpmailer.lang-'
.
$langcode
.
'.php'
;
}
$this
->
language
=
$PHPMAILER_LANG
;
return
(
$l
==
true
);
//Returns false if language not found
}
/**
* Return the current array of language strings
* @return array
*/
public
function
GetTranslations
()
{
return
$this
->
language
;
}
/////////////////////////////////////////////////
// METHODS, MESSAGE CREATION
/////////////////////////////////////////////////
/**
* Creates recipient headers.
* @access public
* @return string
*/
public
function
AddrAppend
(
$type
,
$addr
)
{
$addr_str
=
$type
.
': '
;
$addresses
=
array
();
foreach
(
$addr
as
$a
)
{
$addresses
[]
=
$this
->
AddrFormat
(
$a
);
}
$addr_str
.=
implode
(
', '
,
$addresses
);
$addr_str
.=
$this
->
LE
;
return
$addr_str
;
}
/**
* Formats an address correctly.
* @access public
* @return string
*/
public
function
AddrFormat
(
$addr
)
{
if
(
empty
(
$addr
[
1
]))
{
return
$this
->
SecureHeader
(
$addr
[
0
]);
}
else
{
return
$this
->
EncodeHeader
(
$this
->
SecureHeader
(
$addr
[
1
]),
'phrase'
)
.
" <"
.
$this
->
SecureHeader
(
$addr
[
0
])
.
">"
;
}
}
/**
* Wraps message for use with mailers that do not
* automatically perform wrapping and for quoted-printable.
* Original written by philippe.
* @param string $message The message to wrap
* @param integer $length The line length to wrap to
* @param boolean $qp_mode Whether to run in Quoted-Printable mode
* @access public
* @return string
*/
public
function
WrapText
(
$message
,
$length
,
$qp_mode
=
false
)
{
$soft_break
=
(
$qp_mode
)
?
sprintf
(
" =%s"
,
$this
->
LE
)
:
$this
->
LE
;
// If utf-8 encoding is used, we will need to make sure we don't
// split multibyte characters when we wrap
$is_utf8
=
(
strtolower
(
$this
->
CharSet
)
==
"utf-8"
);
$message
=
$this
->
FixEOL
(
$message
);
if
(
substr
(
$message
,
-
1
)
==
$this
->
LE
)
{
$message
=
substr
(
$message
,
0
,
-
1
);
}
$line
=
explode
(
$this
->
LE
,
$message
);
$message
=
''
;
for
(
$i
=
0
;
$i
<
count
(
$line
);
$i
++
)
{
$line_part
=
explode
(
' '
,
$line
[
$i
]);
$buf
=
''
;
for
(
$e
=
0
;
$e
<
count
(
$line_part
);
$e
++
)
{
$word
=
$line_part
[
$e
];
if
(
$qp_mode
and
(
strlen
(
$word
)
>
$length
))
{
$space_left
=
$length
-
strlen
(
$buf
)
-
1
;
if
(
$e
!=
0
)
{
if
(
$space_left
>
20
)
{
$len
=
$space_left
;
if
(
$is_utf8
)
{
$len
=
$this
->
UTF8CharBoundary
(
$word
,
$len
);
}
elseif
(
substr
(
$word
,
$len
-
1
,
1
)
==
"="
)
{
$len
--
;
}
elseif
(
substr
(
$word
,
$len
-
2
,
1
)
==
"="
)
{
$len
-=
2
;
}
$part
=
substr
(
$word
,
0
,
$len
);
$word
=
substr
(
$word
,
$len
);
$buf
.=
' '
.
$part
;
$message
.=
$buf
.
sprintf
(
"=%s"
,
$this
->
LE
);
}
else
{
$message
.=
$buf
.
$soft_break
;
}
$buf
=
''
;
}
while
(
strlen
(
$word
)
>
0
)
{
$len
=
$length
;
if
(
$is_utf8
)
{
$len
=
$this
->
UTF8CharBoundary
(
$word
,
$len
);
}
elseif
(
substr
(
$word
,
$len
-
1
,
1
)
==
"="
)
{
$len
--
;
}
elseif
(
substr
(
$word
,
$len
-
2
,
1
)
==
"="
)
{
$len
-=
2
;
}
$part
=
substr
(
$word
,
0
,
$len
);
$word
=
substr
(
$word
,
$len
);
if
(
strlen
(
$word
)
>
0
)
{
$message
.=
$part
.
sprintf
(
"=%s"
,
$this
->
LE
);
}
else
{
$buf
=
$part
;
}
}
}
else
{
$buf_o
=
$buf
;
$buf
.=
(
$e
==
0
)
?
$word
:
(
' '
.
$word
);
if
(
strlen
(
$buf
)
>
$length
and
$buf_o
!=
''
)
{
$message
.=
$buf_o
.
$soft_break
;
$buf
=
$word
;
}
}
}
$message
.=
$buf
.
$this
->
LE
;
}
return
$message
;
}
/**
* Finds last character boundary prior to maxLength in a utf-8
* quoted (printable) encoded string.
* Original written by Colin Brown.
* @access public
* @param string $encodedText utf-8 QP text
* @param int $maxLength find last character boundary prior to this length
* @return int
*/
public
function
UTF8CharBoundary
(
$encodedText
,
$maxLength
)
{
$foundSplitPos
=
false
;
$lookBack
=
3
;
while
(
!
$foundSplitPos
)
{
$lastChunk
=
substr
(
$encodedText
,
$maxLength
-
$lookBack
,
$lookBack
);
$encodedCharPos
=
strpos
(
$lastChunk
,
"="
);
if
(
$encodedCharPos
!==
false
)
{
// Found start of encoded character byte within $lookBack block.
// Check the encoded byte value (the 2 chars after the '=')
$hex
=
substr
(
$encodedText
,
$maxLength
-
$lookBack
+
$encodedCharPos
+
1
,
2
);
$dec
=
hexdec
(
$hex
);
if
(
$dec
<
128
)
{
// Single byte character.
// If the encoded char was found at pos 0, it will fit
// otherwise reduce maxLength to start of the encoded char
$maxLength
=
(
$encodedCharPos
==
0
)
?
$maxLength
:
$maxLength
-
(
$lookBack
-
$encodedCharPos
);
$foundSplitPos
=
true
;
}
elseif
(
$dec
>=
192
)
{
// First byte of a multi byte character
// Reduce maxLength to split at start of character
$maxLength
=
$maxLength
-
(
$lookBack
-
$encodedCharPos
);
$foundSplitPos
=
true
;
}
elseif
(
$dec
<
192
)
{
// Middle byte of a multi byte character, look further back
$lookBack
+=
3
;
}
}
else
{
// No encoded character found
$foundSplitPos
=
true
;
}
}
return
$maxLength
;
}
/**
* Set the body wrapping.
* @access public
* @return void
*/
public
function
SetWordWrap
()
{
if
(
$this
->
WordWrap
<
1
)
{
return
;
}
switch
(
$this
->
message_type
)
{
case
'alt'
:
case
'alt_attachments'
:
$this
->
AltBody
=
$this
->
WrapText
(
$this
->
AltBody
,
$this
->
WordWrap
);
break
;
default
:
$this
->
Body
=
$this
->
WrapText
(
$this
->
Body
,
$this
->
WordWrap
);
break
;
}
}
/**
* Assembles message header.
* @access public
* @return string The assembled header
*/
public
function
CreateHeader
()
{
$result
=
''
;
// Set the boundaries
$uniq_id
=
md5
(
uniqid
(
time
()));
$this
->
boundary
[
1
]
=
'b1_'
.
$uniq_id
;
$this
->
boundary
[
2
]
=
'b2_'
.
$uniq_id
;
$result
.=
$this
->
HeaderLine
(
'Date'
,
self
::
RFCDate
());
if
(
$this
->
Sender
==
''
)
{
$result
.=
$this
->
HeaderLine
(
'Return-Path'
,
trim
(
$this
->
From
));
}
else
{
$result
.=
$this
->
HeaderLine
(
'Return-Path'
,
trim
(
$this
->
Sender
));
}
// To be created automatically by mail()
if
(
$this
->
Mailer
!=
'mail'
)
{
if
(
$this
->
SingleTo
===
true
)
{
foreach
(
$this
->
to
as
$t
)
{
$this
->
SingleToArray
[]
=
$this
->
AddrFormat
(
$t
);
}
}
else
{
if
(
count
(
$this
->
to
)
>
0
)
{
$result
.=
$this
->
AddrAppend
(
'To'
,
$this
->
to
);
}
elseif
(
count
(
$this
->
cc
)
==
0
)
{
$result
.=
$this
->
HeaderLine
(
'To'
,
'undisclosed-recipients:;'
);
}
}
}
$from
=
array
();
$from
[
0
][
0
]
=
trim
(
$this
->
From
);
$from
[
0
][
1
]
=
$this
->
FromName
;
$result
.=
$this
->
AddrAppend
(
'From'
,
$from
);
// sendmail and mail() extract Cc from the header before sending
if
(
count
(
$this
->
cc
)
>
0
)
{
$result
.=
$this
->
AddrAppend
(
'Cc'
,
$this
->
cc
);
}
// sendmail and mail() extract Bcc from the header before sending
if
(
count
(
$this
->
bcc
)
>
0
)
{
$result
.=
$this
->
AddrAppend
(
'Bcc'
,
$this
->
bcc
);
}
if
(
count
(
$this
->
ReplyTo
)
>
0
)
{
$result
.=
$this
->
AddrAppend
(
'Reply-to'
,
$this
->
ReplyTo
);
}
// mail() sets the subject itself
if
(
$this
->
Mailer
!=
'mail'
)
{
$result
.=
$this
->
HeaderLine
(
'Subject'
,
$this
->
EncodeHeader
(
$this
->
SecureHeader
(
$this
->
Subject
)));
}
if
(
$this
->
MessageID
!=
''
)
{
$result
.=
$this
->
HeaderLine
(
'Message-ID'
,
$this
->
MessageID
);
}
else
{
$result
.=
sprintf
(
"Message-ID: <%s@%s>%s"
,
$uniq_id
,
$this
->
ServerHostname
(),
$this
->
LE
);
}
$result
.=
$this
->
HeaderLine
(
'X-Priority'
,
$this
->
Priority
);
$result
.=
$this
->
HeaderLine
(
'X-Mailer'
,
'PHPMailer '
.
$this
->
Version
.
' (phpmailer.codeworxtech.com)'
);
if
(
$this
->
ConfirmReadingTo
!=
''
)
{
$result
.=
$this
->
HeaderLine
(
'Disposition-Notification-To'
,
'<'
.
trim
(
$this
->
ConfirmReadingTo
)
.
'>'
);
}
// Add custom headers
for
(
$index
=
0
;
$index
<
count
(
$this
->
CustomHeader
);
$index
++
)
{
$result
.=
$this
->
HeaderLine
(
trim
(
$this
->
CustomHeader
[
$index
][
0
]),
$this
->
EncodeHeader
(
trim
(
$this
->
CustomHeader
[
$index
][
1
])));
}
if
(
!
$this
->
sign_key_file
)
{
$result
.=
$this
->
HeaderLine
(
'MIME-Version'
,
'1.0'
);
$result
.=
$this
->
GetMailMIME
();
}
return
$result
;
}
/**
* Returns the message MIME.
* @access public
* @return string
*/
public
function
GetMailMIME
()
{
$result
=
''
;
switch
(
$this
->
message_type
)
{
case
'plain'
:
$result
.=
$this
->
HeaderLine
(
'Content-Transfer-Encoding'
,
$this
->
Encoding
);
$result
.=
sprintf
(
"Content-Type: %s; charset=
\"
%s
\"
"
,
$this
->
ContentType
,
$this
->
CharSet
);
break
;
case
'attachments'
:
case
'alt_attachments'
:
if
(
$this
->
InlineImageExists
()){
$result
.=
sprintf
(
"Content-Type: %s;%s
\t
type=
\"
text/html
\"
;%s
\t
boundary=
\"
%s
\"
%s"
,
'multipart/related'
,
$this
->
LE
,
$this
->
LE
,
$this
->
boundary
[
1
],
$this
->
LE
);
}
else
{
$result
.=
$this
->
HeaderLine
(
'Content-Type'
,
'multipart/mixed;'
);
$result
.=
$this
->
TextLine
(
"
\t
boundary=
\"
"
.
$this
->
boundary
[
1
]
.
'"'
);
}
break
;
case
'alt'
:
$result
.=
$this
->
HeaderLine
(
'Content-Type'
,
'multipart/alternative;'
);
$result
.=
$this
->
TextLine
(
"
\t
boundary=
\"
"
.
$this
->
boundary
[
1
]
.
'"'
);
break
;
}
if
(
$this
->
Mailer
!=
'mail'
)
{
$result
.=
$this
->
LE
.
$this
->
LE
;
}
return
$result
;
}
/**
* Assembles the message body. Returns an empty string on failure.
* @access public
* @return string The assembled message body
*/
public
function
CreateBody
()
{
$body
=
''
;
if
(
$this
->
sign_key_file
)
{
$body
.=
$this
->
GetMailMIME
();
}
$this
->
SetWordWrap
();
switch
(
$this
->
message_type
)
{
case
'alt'
:
$body
.=
$this
->
GetBoundary
(
$this
->
boundary
[
1
],
''
,
'text/plain'
,
''
);
$body
.=
$this
->
EncodeString
(
$this
->
AltBody
,
$this
->
Encoding
);
$body
.=
$this
->
LE
.
$this
->
LE
;
$body
.=
$this
->
GetBoundary
(
$this
->
boundary
[
1
],
''
,
'text/html'
,
''
);
$body
.=
$this
->
EncodeString
(
$this
->
Body
,
$this
->
Encoding
);
$body
.=
$this
->
LE
.
$this
->
LE
;
$body
.=
$this
->
EndBoundary
(
$this
->
boundary
[
1
]);
break
;
case
'plain'
:
$body
.=
$this
->
EncodeString
(
$this
->
Body
,
$this
->
Encoding
);
break
;
case
'attachments'
:
$body
.=
$this
->
GetBoundary
(
$this
->
boundary
[
1
],
''
,
''
,
''
);
$body
.=
$this
->
EncodeString
(
$this
->
Body
,
$this
->
Encoding
);
$body
.=
$this
->
LE
;
$body
.=
$this
->
AttachAll
();
break
;
case
'alt_attachments'
:
$body
.=
sprintf
(
"--%s%s"
,
$this
->
boundary
[
1
],
$this
->
LE
);
$body
.=
sprintf
(
"Content-Type: %s;%s"
.
"
\t
boundary=
\"
%s
\"
%s"
,
'multipart/alternative'
,
$this
->
LE
,
$this
->
boundary
[
2
],
$this
->
LE
.
$this
->
LE
);
$body
.=
$this
->
GetBoundary
(
$this
->
boundary
[
2
],
''
,
'text/plain'
,
''
)
.
$this
->
LE
;
// Create text body
$body
.=
$this
->
EncodeString
(
$this
->
AltBody
,
$this
->
Encoding
);
$body
.=
$this
->
LE
.
$this
->
LE
;
$body
.=
$this
->
GetBoundary
(
$this
->
boundary
[
2
],
''
,
'text/html'
,
''
)
.
$this
->
LE
;
// Create the HTML body
$body
.=
$this
->
EncodeString
(
$this
->
Body
,
$this
->
Encoding
);
$body
.=
$this
->
LE
.
$this
->
LE
;
$body
.=
$this
->
EndBoundary
(
$this
->
boundary
[
2
]);
$body
.=
$this
->
AttachAll
();
break
;
}
if
(
$this
->
IsError
())
{
$body
=
''
;
}
elseif
(
$this
->
sign_key_file
)
{
try
{
$file
=
tempnam
(
''
,
'mail'
);
file_put_contents
(
$file
,
$body
);
//TODO check this worked
$signed
=
tempnam
(
""
,
"signed"
);
if
(
@
openssl_pkcs7_sign
(
$file
,
$signed
,
"file://"
.
$this
->
sign_cert_file
,
array
(
"file://"
.
$this
->
sign_key_file
,
$this
->
sign_key_pass
),
NULL
))
{
@
unlink
(
$file
);
@
unlink
(
$signed
);
$body
=
file_get_contents
(
$signed
);
}
else
{
@
unlink
(
$file
);
@
unlink
(
$signed
);
throw
new
phpmailerException
(
$this
->
Lang
(
"signing"
)
.
openssl_error_string
());
}
}
catch
(
phpmailerException
$e
)
{
$body
=
''
;
if
(
$this
->
exceptions
)
{
throw
$e
;
}
}
}
return
$body
;
}
/**
* Returns the start of a message boundary.
* @access private
*/
private
function
GetBoundary
(
$boundary
,
$charSet
,
$contentType
,
$encoding
)
{
$result
=
''
;
if
(
$charSet
==
''
)
{
$charSet
=
$this
->
CharSet
;
}
if
(
$contentType
==
''
)
{
$contentType
=
$this
->
ContentType
;
}
if
(
$encoding
==
''
)
{
$encoding
=
$this
->
Encoding
;
}
$result
.=
$this
->
TextLine
(
'--'
.
$boundary
);
$result
.=
sprintf
(
"Content-Type: %s; charset =
\"
%s
\"
"
,
$contentType
,
$charSet
);
$result
.=
$this
->
LE
;
$result
.=
$this
->
HeaderLine
(
'Content-Transfer-Encoding'
,
$encoding
);
$result
.=
$this
->
LE
;
return
$result
;
}
/**
* Returns the end of a message boundary.
* @access private
*/
private
function
EndBoundary
(
$boundary
)
{
return
$this
->
LE
.
'--'
.
$boundary
.
'--'
.
$this
->
LE
;
}
/**
* Sets the message type.
* @access private
* @return void
*/
private
function
SetMessageType
()
{
if
(
count
(
$this
->
attachment
)
<
1
&&
strlen
(
$this
->
AltBody
)
<
1
)
{
$this
->
message_type
=
'plain'
;
}
else
{
if
(
count
(
$this
->
attachment
)
>
0
)
{
$this
->
message_type
=
'attachments'
;
}
if
(
strlen
(
$this
->
AltBody
)
>
0
&&
count
(
$this
->
attachment
)
<
1
)
{
$this
->
message_type
=
'alt'
;
}
if
(
strlen
(
$this
->
AltBody
)
>
0
&&
count
(
$this
->
attachment
)
>
0
)
{
$this
->
message_type
=
'alt_attachments'
;
}
}
}
/**
* Returns a formatted header line.
* @access public
* @return string
*/
public
function
HeaderLine
(
$name
,
$value
)
{
return
$name
.
': '
.
$value
.
$this
->
LE
;
}
/**
* Returns a formatted mail line.
* @access public
* @return string
*/
public
function
TextLine
(
$value
)
{
return
$value
.
$this
->
LE
;
}
/////////////////////////////////////////////////
// CLASS METHODS, ATTACHMENTS
/////////////////////////////////////////////////
/**
* Adds an attachment from a path on the filesystem.
* Returns false if the file could not be found
* or accessed.
* @param string $path Path to the attachment.
* @param string $name Overrides the attachment name.
* @param string $encoding File encoding (see $Encoding).
* @param string $type File extension (MIME) type.
* @return bool
*/
public
function
AddAttachment
(
$path
,
$name
=
''
,
$encoding
=
'base64'
,
$type
=
'application/octet-stream'
)
{
try
{
if
(
!@
is_file
(
$path
)
)
{
throw
new
phpmailerException
(
$this
->
Lang
(
'file_access'
)
.
$path
,
self
::
STOP_CONTINUE
);
}
$filename
=
basename
(
$path
);
if
(
$name
==
''
)
{
$name
=
$filename
;
}
$this
->
attachment
[]
=
array
(
0
=>
$path
,
1
=>
$filename
,
2
=>
$name
,
3
=>
$encoding
,
4
=>
$type
,
5
=>
false
,
// isStringAttachment
6
=>
'attachment'
,
7
=>
0
);
}
catch
(
phpmailerException
$e
)
{
$this
->
SetError
(
$e
->
getMessage
());
if
(
$this
->
exceptions
)
{
throw
$e
;
}
echo
$e
->
getMessage
()
.
"
\n
"
;
if
(
$e
->
getCode
()
==
self
::
STOP_CRITICAL
)
{
return
false
;
}
}
return
true
;
}
/**
* Return the current array of attachments
* @return array
*/
public
function
GetAttachments
()
{
return
$this
->
attachment
;
}
/**
* Attaches all fs, string, and binary attachments to the message.
* Returns an empty string on failure.
* @access private
* @return string
*/
private
function
AttachAll
()
{
// Return text of body
$mime
=
array
();
$cidUniq
=
array
();
$incl
=
array
();
// Add all attachments
foreach
(
$this
->
attachment
as
$attachment
)
{
// Check for string attachment
$bString
=
$attachment
[
5
];
if
(
$bString
)
{
$string
=
$attachment
[
0
];
}
else
{
$path
=
$attachment
[
0
];
}
if
(
in_array
(
$attachment
[
0
],
$incl
))
{
continue
;
}
$filename
=
$attachment
[
1
];
$name
=
$attachment
[
2
];
$encoding
=
$attachment
[
3
];
$type
=
$attachment
[
4
];
$disposition
=
$attachment
[
6
];
$cid
=
$attachment
[
7
];
$incl
[]
=
$attachment
[
0
];
if
(
$disposition
==
'inline'
&&
isset
(
$cidUniq
[
$cid
])
)
{
continue
;
}
$cidUniq
[
$cid
]
=
true
;
$mime
[]
=
sprintf
(
"--%s%s"
,
$this
->
boundary
[
1
],
$this
->
LE
);
$mime
[]
=
sprintf
(
"Content-Type: %s; name=
\"
%s
\"
%s"
,
$type
,
$this
->
EncodeHeader
(
$this
->
SecureHeader
(
$name
)),
$this
->
LE
);
$mime
[]
=
sprintf
(
"Content-Transfer-Encoding: %s%s"
,
$encoding
,
$this
->
LE
);
if
(
$disposition
==
'inline'
)
{
$mime
[]
=
sprintf
(
"Content-ID: <%s>%s"
,
$cid
,
$this
->
LE
);
}
$mime
[]
=
sprintf
(
"Content-Disposition: %s; filename=
\"
%s
\"
%s"
,
$disposition
,
$this
->
EncodeHeader
(
$this
->
SecureHeader
(
$name
)),
$this
->
LE
.
$this
->
LE
);
// Encode as string attachment
if
(
$bString
)
{
$mime
[]
=
$this
->
EncodeString
(
$string
,
$encoding
);
if
(
$this
->
IsError
())
{
return
''
;
}
$mime
[]
=
$this
->
LE
.
$this
->
LE
;
}
else
{
$mime
[]
=
$this
->
EncodeFile
(
$path
,
$encoding
);
if
(
$this
->
IsError
())
{
return
''
;
}
$mime
[]
=
$this
->
LE
.
$this
->
LE
;
}
}
$mime
[]
=
sprintf
(
"--%s--%s"
,
$this
->
boundary
[
1
],
$this
->
LE
);
return
join
(
''
,
$mime
);
}
/**
* Encodes attachment in requested format.
* Returns an empty string on failure.
* @param string $path The full path to the file
* @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
* @see EncodeFile()
* @access private
* @return string
*/
private
function
EncodeFile
(
$path
,
$encoding
=
'base64'
)
{
try
{
if
(
!
is_readable
(
$path
))
{
throw
new
phpmailerException
(
$this
->
Lang
(
'file_open'
)
.
$path
,
self
::
STOP_CONTINUE
);
}
if
(
function_exists
(
'get_magic_quotes'
))
{
function
get_magic_quotes
()
{
return
false
;
}
}
if
(
PHP_VERSION
<
6
)
{
$magic_quotes
=
get_magic_quotes_runtime
();
set_magic_quotes_runtime
(
0
);
}
$file_buffer
=
file_get_contents
(
$path
);
$file_buffer
=
$this
->
EncodeString
(
$file_buffer
,
$encoding
);
if
(
PHP_VERSION
<
6
)
{
set_magic_quotes_runtime
(
$magic_quotes
);
}
return
$file_buffer
;
}
catch
(
Exception
$e
)
{
$this
->
SetError
(
$e
->
getMessage
());
return
''
;
}
}
/**
* Encodes string to requested format.
* Returns an empty string on failure.
* @param string $str The text to encode
* @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
* @access public
* @return string
*/
public
function
EncodeString
(
$str
,
$encoding
=
'base64'
)
{
$encoded
=
''
;
switch
(
strtolower
(
$encoding
))
{
case
'base64'
:
$encoded
=
chunk_split
(
base64_encode
(
$str
),
76
,
$this
->
LE
);
break
;
case
'7bit'
:
case
'8bit'
:
$encoded
=
$this
->
FixEOL
(
$str
);
//Make sure it ends with a line break
if
(
substr
(
$encoded
,
-
(
strlen
(
$this
->
LE
)))
!=
$this
->
LE
)
$encoded
.=
$this
->
LE
;
break
;
case
'binary'
:
$encoded
=
$str
;
break
;
case
'quoted-printable'
:
$encoded
=
$this
->
EncodeQP
(
$str
);
break
;
default
:
$this
->
SetError
(
$this
->
Lang
(
'encoding'
)
.
$encoding
);
break
;
}
return
$encoded
;
}
/**
* Encode a header string to best (shortest) of Q, B, quoted or none.
* @access public
* @return string
*/
public
function
EncodeHeader
(
$str
,
$position
=
'text'
)
{
$x
=
0
;
switch
(
strtolower
(
$position
))
{
case
'phrase'
:
if
(
!
preg_match
(
'/[\200-\377]/'
,
$str
))
{
// Can't use addslashes as we don't know what value has magic_quotes_sybase
$encoded
=
addcslashes
(
$str
,
"
\0
..
\37\177\\\"
"
);
if
((
$str
==
$encoded
)
&&
!
preg_match
(
'/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/'
,
$str
))
{
return
(
$encoded
);
}
else
{
return
(
"
\"
$encoded
\"
"
);
}
}
$x
=
preg_match_all
(
'/[^\040\041\043-\133\135-\176]/'
,
$str
,
$matches
);
break
;
case
'comment'
:
$x
=
preg_match_all
(
'/[()"]/'
,
$str
,
$matches
);
// Fall-through
case
'text'
:
default
:
$x
+=
preg_match_all
(
'/[\000-\010\013\014\016-\037\177-\377]/'
,
$str
,
$matches
);
break
;
}
if
(
$x
==
0
)
{
return
(
$str
);
}
$maxlen
=
75
-
7
-
strlen
(
$this
->
CharSet
);
// Try to select the encoding which should produce the shortest output
if
(
strlen
(
$str
)
/
3
<
$x
)
{
$encoding
=
'B'
;
if
(
function_exists
(
'mb_strlen'
)
&&
$this
->
HasMultiBytes
(
$str
))
{
// Use a custom function which correctly encodes and wraps long
// multibyte strings without breaking lines within a character
$encoded
=
$this
->
Base64EncodeWrapMB
(
$str
);
}
else
{
$encoded
=
base64_encode
(
$str
);
$maxlen
-=
$maxlen
%
4
;
$encoded
=
trim
(
chunk_split
(
$encoded
,
$maxlen
,
"
\n
"
));
}
}
else
{
$encoding
=
'Q'
;
$encoded
=
$this
->
EncodeQ
(
$str
,
$position
);
$encoded
=
$this
->
WrapText
(
$encoded
,
$maxlen
,
true
);
$encoded
=
str_replace
(
'='
.
$this
->
LE
,
"
\n
"
,
trim
(
$encoded
));
}
$encoded
=
preg_replace
(
'/^(.*)$/m'
,
" =?"
.
$this
->
CharSet
.
"?
$encoding
?
\\
1?="
,
$encoded
);
$encoded
=
trim
(
str_replace
(
"
\n
"
,
$this
->
LE
,
$encoded
));
return
$encoded
;
}
/**
* Checks if a string contains multibyte characters.
* @access public
* @param string $str multi-byte text to wrap encode
* @return bool
*/
public
function
HasMultiBytes
(
$str
)
{
if
(
function_exists
(
'mb_strlen'
))
{
return
(
strlen
(
$str
)
>
mb_strlen
(
$str
,
$this
->
CharSet
));
}
else
{
// Assume no multibytes (we can't handle without mbstring functions anyway)
return
false
;
}
}
/**
* Correctly encodes and wraps long multibyte strings for mail headers
* without breaking lines within a character.
* Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php
* @access public
* @param string $str multi-byte text to wrap encode
* @return string
*/
public
function
Base64EncodeWrapMB
(
$str
)
{
$start
=
"=?"
.
$this
->
CharSet
.
"?B?"
;
$end
=
"?="
;
$encoded
=
""
;
$mb_length
=
mb_strlen
(
$str
,
$this
->
CharSet
);
// Each line must have length <= 75, including $start and $end
$length
=
75
-
strlen
(
$start
)
-
strlen
(
$end
);
// Average multi-byte ratio
$ratio
=
$mb_length
/
strlen
(
$str
);
// Base64 has a 4:3 ratio
$offset
=
$avgLength
=
floor
(
$length
*
$ratio
*
.
75
);
for
(
$i
=
0
;
$i
<
$mb_length
;
$i
+=
$offset
)
{
$lookBack
=
0
;
do
{
$offset
=
$avgLength
-
$lookBack
;
$chunk
=
mb_substr
(
$str
,
$i
,
$offset
,
$this
->
CharSet
);
$chunk
=
base64_encode
(
$chunk
);
$lookBack
++
;
}
while
(
strlen
(
$chunk
)
>
$length
);
$encoded
.=
$chunk
.
$this
->
LE
;
}
// Chomp the last linefeed
$encoded
=
substr
(
$encoded
,
0
,
-
strlen
(
$this
->
LE
));
return
$encoded
;
}
/**
* Encode string to quoted-printable.
* Only uses standard PHP, slow, but will always work
* @access public
* @param string $string the text to encode
* @param integer $line_max Number of chars allowed on a line before wrapping
* @return string
*/
public
function
EncodeQPphp
(
$input
=
''
,
$line_max
=
76
,
$space_conv
=
false
)
{
$hex
=
array
(
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'F'
);
$lines
=
preg_split
(
'/(?:\r\n|\r|\n)/'
,
$input
);
$eol
=
"
\r\n
"
;
$escape
=
'='
;
$output
=
''
;
while
(
list
(,
$line
)
=
each
(
$lines
)
)
{
$linlen
=
strlen
(
$line
);
$newline
=
''
;
for
(
$i
=
0
;
$i
<
$linlen
;
$i
++
)
{
$c
=
substr
(
$line
,
$i
,
1
);
$dec
=
ord
(
$c
);
if
(
(
$i
==
0
)
&&
(
$dec
==
46
)
)
{
// convert first point in the line into =2E
$c
=
'=2E'
;
}
if
(
$dec
==
32
)
{
if
(
$i
==
(
$linlen
-
1
)
)
{
// convert space at eol only
$c
=
'=20'
;
}
else
if
(
$space_conv
)
{
$c
=
'=20'
;
}
}
elseif
(
(
$dec
==
61
)
||
(
$dec
<
32
)
||
(
$dec
>
126
)
)
{
// always encode "\t", which is *not* required
$h2
=
floor
(
$dec
/
16
);
$h1
=
floor
(
$dec
%
16
);
$c
=
$escape
.
$hex
[
$h2
]
.
$hex
[
$h1
];
}
if
(
(
strlen
(
$newline
)
+
strlen
(
$c
))
>=
$line_max
)
{
// CRLF is not counted
$output
.=
$newline
.
$escape
.
$eol
;
// soft line break; " =\r\n" is okay
$newline
=
''
;
// check if newline first character will be point or not
if
(
$dec
==
46
)
{
$c
=
'=2E'
;
}
}
$newline
.=
$c
;
}
// end of for
$output
.=
$newline
.
$eol
;
}
// end of while
return
$output
;
}
/**
* Encode string to RFC2045 (6.7) quoted-printable format
* Uses a PHP5 stream filter to do the encoding about 64x faster than the old version
* Also results in same content as you started with after decoding
* @see EncodeQPphp()
* @access public
* @param string $string the text to encode
* @param integer $line_max Number of chars allowed on a line before wrapping
* @param boolean $space_conv Dummy param for compatibility with existing EncodeQP function
* @return string
* @author Marcus Bointon
*/
public
function
EncodeQP
(
$string
,
$line_max
=
76
,
$space_conv
=
false
)
{
if
(
function_exists
(
'quoted_printable_encode'
))
{
//Use native function if it's available (>= PHP5.3)
return
quoted_printable_encode
(
$string
);
}
$filters
=
stream_get_filters
();
if
(
!
in_array
(
'convert.*'
,
$filters
))
{
//Got convert stream filter?
return
$this
->
EncodeQPphp
(
$string
,
$line_max
,
$space_conv
);
//Fall back to old implementation
}
$fp
=
fopen
(
'php://temp/'
,
'r+'
);
$string
=
preg_replace
(
'/\r\n?/'
,
$this
->
LE
,
$string
);
//Normalise line breaks
$params
=
array
(
'line-length'
=>
$line_max
,
'line-break-chars'
=>
$this
->
LE
);
$s
=
stream_filter_append
(
$fp
,
'convert.quoted-printable-encode'
,
STREAM_FILTER_READ
,
$params
);
fputs
(
$fp
,
$string
);
rewind
(
$fp
);
$out
=
stream_get_contents
(
$fp
);
stream_filter_remove
(
$s
);
$out
=
preg_replace
(
'/^\./m'
,
'=2E'
,
$out
);
//Encode . if it is first char on a line, workaround for bug in Exchange
fclose
(
$fp
);
return
$out
;
}
/**
* Encode string to q encoding.
* @link http://tools.ietf.org/html/rfc2047
* @param string $str the text to encode
* @param string $position Where the text is going to be used, see the RFC for what that means
* @access public
* @return string
*/
public
function
EncodeQ
(
$str
,
$position
=
'text'
)
{
// There should not be any EOL in the string
$encoded
=
preg_replace
(
'/[\r\n]*/'
,
''
,
$str
);
switch
(
strtolower
(
$position
))
{
case
'phrase'
:
$encoded
=
preg_replace
(
"/([^A-Za-z0-9!*+\/ -])/e"
,
"'='.sprintf('%02X', ord('
\\
1'))"
,
$encoded
);
break
;
case
'comment'
:
$encoded
=
preg_replace
(
"/([\(\)
\"
])/e"
,
"'='.sprintf('%02X', ord('
\\
1'))"
,
$encoded
);
case
'text'
:
default
:
// Replace every high ascii, control =, ? and _ characters
//TODO using /e (equivalent to eval()) is probably not a good idea
$encoded
=
preg_replace
(
'/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e'
,
"'='.sprintf('%02X', ord('
\\
1'))"
,
$encoded
);
break
;
}
// Replace every spaces to _ (more readable than =20)
$encoded
=
str_replace
(
' '
,
'_'
,
$encoded
);
return
$encoded
;
}
/**
* Adds a string or binary attachment (non-filesystem) to the list.
* This method can be used to attach ascii or binary data,
* such as a BLOB record from a database.
* @param string $string String attachment data.
* @param string $filename Name of the attachment.
* @param string $encoding File encoding (see $Encoding).
* @param string $type File extension (MIME) type.
* @return void
*/
public
function
AddStringAttachment
(
$string
,
$filename
,
$encoding
=
'base64'
,
$type
=
'application/octet-stream'
)
{
// Append to $attachment array
$this
->
attachment
[]
=
array
(
0
=>
$string
,
1
=>
$filename
,
2
=>
basename
(
$filename
),
3
=>
$encoding
,
4
=>
$type
,
5
=>
true
,
// isStringAttachment
6
=>
'attachment'
,
7
=>
0
);
}
/**
* Adds an embedded attachment. This can include images, sounds, and
* just about any other document. Make sure to set the $type to an
* image type. For JPEG images use "image/jpeg" and for GIF images
* use "image/gif".
* @param string $path Path to the attachment.
* @param string $cid Content ID of the attachment. Use this to identify
* the Id for accessing the image in an HTML form.
* @param string $name Overrides the attachment name.
* @param string $encoding File encoding (see $Encoding).
* @param string $type File extension (MIME) type.
* @return bool
*/
public
function
AddEmbeddedImage
(
$path
,
$cid
,
$name
=
''
,
$encoding
=
'base64'
,
$type
=
'application/octet-stream'
)
{
if
(
!@
is_file
(
$path
)
)
{
$this
->
SetError
(
$this
->
Lang
(
'file_access'
)
.
$path
);
return
false
;
}
$filename
=
basename
(
$path
);
if
(
$name
==
''
)
{
$name
=
$filename
;
}
// Append to $attachment array
$this
->
attachment
[]
=
array
(
0
=>
$path
,
1
=>
$filename
,
2
=>
$name
,
3
=>
$encoding
,
4
=>
$type
,
5
=>
false
,
// isStringAttachment
6
=>
'inline'
,
7
=>
$cid
);
return
true
;
}
/**
* Returns true if an inline attachment is present.
* @access public
* @return bool
*/
public
function
InlineImageExists
()
{
foreach
(
$this
->
attachment
as
$attachment
)
{
if
(
$attachment
[
6
]
==
'inline'
)
{
return
true
;
}
}
return
false
;
}
/////////////////////////////////////////////////
// CLASS METHODS, MESSAGE RESET
/////////////////////////////////////////////////
/**
* Clears all recipients assigned in the TO array. Returns void.
* @return void
*/
public
function
ClearAddresses
()
{
foreach
(
$this
->
to
as
$to
)
{
unset
(
$this
->
all_recipients
[
strtolower
(
$to
[
0
])]);
}
$this
->
to
=
array
();
}
/**
* Clears all recipients assigned in the CC array. Returns void.
* @return void
*/
public
function
ClearCCs
()
{
foreach
(
$this
->
cc
as
$cc
)
{
unset
(
$this
->
all_recipients
[
strtolower
(
$cc
[
0
])]);
}
$this
->
cc
=
array
();
}
/**
* Clears all recipients assigned in the BCC array. Returns void.
* @return void
*/
public
function
ClearBCCs
()
{
foreach
(
$this
->
bcc
as
$bcc
)
{
unset
(
$this
->
all_recipients
[
strtolower
(
$bcc
[
0
])]);
}
$this
->
bcc
=
array
();
}
/**
* Clears all recipients assigned in the ReplyTo array. Returns void.
* @return void
*/
public
function
ClearReplyTos
()
{
$this
->
ReplyTo
=
array
();
}
/**
* Clears all recipients assigned in the TO, CC and BCC
* array. Returns void.
* @return void
*/
public
function
ClearAllRecipients
()
{
$this
->
to
=
array
();
$this
->
cc
=
array
();
$this
->
bcc
=
array
();
$this
->
all_recipients
=
array
();
}
/**
* Clears all previously set filesystem, string, and binary
* attachments. Returns void.
* @return void
*/
public
function
ClearAttachments
()
{
$this
->
attachment
=
array
();
}
/**
* Clears all custom headers. Returns void.
* @return void
*/
public
function
ClearCustomHeaders
()
{
$this
->
CustomHeader
=
array
();
}
/////////////////////////////////////////////////
// CLASS METHODS, MISCELLANEOUS
/////////////////////////////////////////////////
/**
* Adds the error message to the error container.
* @access protected
* @return void
*/
protected
function
SetError
(
$msg
)
{
$this
->
error_count
++
;
$this
->
ErrorInfo
=
$msg
;
}
/**
* Returns the proper RFC 822 formatted date.
* @access public
* @return string
* @static
*/
public
static
function
RFCDate
()
{
$tz
=
date
(
'Z'
);
$tzs
=
(
$tz
<
0
)
?
'-'
:
'+'
;
$tz
=
abs
(
$tz
);
$tz
=
(
int
)(
$tz
/
3600
)
*
100
+
(
$tz
%
3600
)
/
60
;
$result
=
sprintf
(
"%s %s%04d"
,
date
(
'D, j M Y H:i:s'
),
$tzs
,
$tz
);
return
$result
;
}
/**
* Returns the server hostname or 'localhost.localdomain' if unknown.
* @access private
* @return string
*/
private
function
ServerHostname
()
{
if
(
!
empty
(
$this
->
Hostname
))
{
$result
=
$this
->
Hostname
;
}
elseif
(
isset
(
$_SERVER
[
'SERVER_NAME'
]))
{
$result
=
$_SERVER
[
'SERVER_NAME'
];
}
else
{
$result
=
'localhost.localdomain'
;
}
return
$result
;
}
/**
* Returns a message in the appropriate language.
* @access private
* @return string
*/
private
function
Lang
(
$key
)
{
if
(
count
(
$this
->
language
)
<
1
)
{
$this
->
SetLanguage
(
'en'
);
// set the default language
}
if
(
isset
(
$this
->
language
[
$key
]))
{
return
$this
->
language
[
$key
];
}
else
{
return
'Language string failed to load: '
.
$key
;
}
}
/**
* Returns true if an error occurred.
* @access public
* @return bool
*/
public
function
IsError
()
{
return
(
$this
->
error_count
>
0
);
}
/**
* Changes every end of line from CR or LF to CRLF.
* @access private
* @return string
*/
private
function
FixEOL
(
$str
)
{
$str
=
str_replace
(
"
\r\n
"
,
"
\n
"
,
$str
);
$str
=
str_replace
(
"
\r
"
,
"
\n
"
,
$str
);
$str
=
str_replace
(
"
\n
"
,
$this
->
LE
,
$str
);
return
$str
;
}
/**
* Adds a custom header.
* @access public
* @return void
*/
public
function
AddCustomHeader
(
$custom_header
)
{
$this
->
CustomHeader
[]
=
explode
(
':'
,
$custom_header
,
2
);
}
/**
* Evaluates the message and returns modifications for inline images and backgrounds
* @access public
* @return $message
*/
public
function
MsgHTML
(
$message
,
$basedir
=
''
)
{
preg_match_all
(
"/(src|background)=
\"
(.*)
\"
/Ui"
,
$message
,
$images
);
if
(
isset
(
$images
[
2
]))
{
foreach
(
$images
[
2
]
as
$i
=>
$url
)
{
// do not change urls for absolute images (thanks to corvuscorax)
if
(
!
preg_match
(
'#^[A-z]+://#'
,
$url
))
{
$filename
=
basename
(
$url
);
$directory
=
dirname
(
$url
);
(
$directory
==
'.'
)
?
$directory
=
''
:
''
;
$cid
=
'cid:'
.
md5
(
$filename
);
$ext
=
pathinfo
(
$filename
,
PATHINFO_EXTENSION
);
$mimeType
=
self
::
_mime_types
(
$ext
);
if
(
strlen
(
$basedir
)
>
1
&&
substr
(
$basedir
,
-
1
)
!=
'/'
)
{
$basedir
.=
'/'
;
}
if
(
strlen
(
$directory
)
>
1
&&
substr
(
$directory
,
-
1
)
!=
'/'
)
{
$directory
.=
'/'
;
}
if
(
$this
->
AddEmbeddedImage
(
$basedir
.
$directory
.
$filename
,
md5
(
$filename
),
$filename
,
'base64'
,
$mimeType
)
)
{
$message
=
preg_replace
(
"/"
.
$images
[
1
][
$i
]
.
"=
\"
"
.
preg_quote
(
$url
,
'/'
)
.
"
\"
/Ui"
,
$images
[
1
][
$i
]
.
"=
\"
"
.
$cid
.
"
\"
"
,
$message
);
}
}
}
}
$this
->
IsHTML
(
true
);
$this
->
Body
=
$message
;
$textMsg
=
trim
(
strip_tags
(
preg_replace
(
'/<(head|title|style|script)[^>]*>.*?<\/\\1>/s'
,
''
,
$message
)));
if
(
!
empty
(
$textMsg
)
&&
empty
(
$this
->
AltBody
))
{
$this
->
AltBody
=
html_entity_decode
(
$textMsg
);
}
if
(
empty
(
$this
->
AltBody
))
{
$this
->
AltBody
=
'To view this email message, open it in a program that understands HTML!'
.
"
\n\n
"
;
}
}
/**
* Gets the MIME type of the embedded or inline image
* @param string File extension
* @access public
* @return string MIME type of ext
* @static
*/
public
static
function
_mime_types
(
$ext
=
''
)
{
$mimes
=
array
(
'hqx'
=>
'application/mac-binhex40'
,
'cpt'
=>
'application/mac-compactpro'
,
'doc'
=>
'application/msword'
,
'bin'
=>
'application/macbinary'
,
'dms'
=>
'application/octet-stream'
,
'lha'
=>
'application/octet-stream'
,
'lzh'
=>
'application/octet-stream'
,
'exe'
=>
'application/octet-stream'
,
'class'
=>
'application/octet-stream'
,
'psd'
=>
'application/octet-stream'
,
'so'
=>
'application/octet-stream'
,
'sea'
=>
'application/octet-stream'
,
'dll'
=>
'application/octet-stream'
,
'oda'
=>
'application/oda'
,
'pdf'
=>
'application/pdf'
,
'ai'
=>
'application/postscript'
,
'eps'
=>
'application/postscript'
,
'ps'
=>
'application/postscript'
,
'smi'
=>
'application/smil'
,
'smil'
=>
'application/smil'
,
'mif'
=>
'application/vnd.mif'
,
'xls'
=>
'application/vnd.ms-excel'
,
'ppt'
=>
'application/vnd.ms-powerpoint'
,
'wbxml'
=>
'application/vnd.wap.wbxml'
,
'wmlc'
=>
'application/vnd.wap.wmlc'
,
'dcr'
=>
'application/x-director'
,
'dir'
=>
'application/x-director'
,
'dxr'
=>
'application/x-director'
,
'dvi'
=>
'application/x-dvi'
,
'gtar'
=>
'application/x-gtar'
,
'php'
=>
'application/x-httpd-php'
,
'php4'
=>
'application/x-httpd-php'
,
'php3'
=>
'application/x-httpd-php'
,
'phtml'
=>
'application/x-httpd-php'
,
'phps'
=>
'application/x-httpd-php-source'
,
'js'
=>
'application/x-javascript'
,
'swf'
=>
'application/x-shockwave-flash'
,
'sit'
=>
'application/x-stuffit'
,
'tar'
=>
'application/x-tar'
,
'tgz'
=>
'application/x-tar'
,
'xhtml'
=>
'application/xhtml+xml'
,
'xht'
=>
'application/xhtml+xml'
,
'zip'
=>
'application/zip'
,
'mid'
=>
'audio/midi'
,
'midi'
=>
'audio/midi'
,
'mpga'
=>
'audio/mpeg'
,
'mp2'
=>
'audio/mpeg'
,
'mp3'
=>
'audio/mpeg'
,
'aif'
=>
'audio/x-aiff'
,
'aiff'
=>
'audio/x-aiff'
,
'aifc'
=>
'audio/x-aiff'
,
'ram'
=>
'audio/x-pn-realaudio'
,
'rm'
=>
'audio/x-pn-realaudio'
,
'rpm'
=>
'audio/x-pn-realaudio-plugin'
,
'ra'
=>
'audio/x-realaudio'
,
'rv'
=>
'video/vnd.rn-realvideo'
,
'wav'
=>
'audio/x-wav'
,
'bmp'
=>
'image/bmp'
,
'gif'
=>
'image/gif'
,
'jpeg'
=>
'image/jpeg'
,
'jpg'
=>
'image/jpeg'
,
'jpe'
=>
'image/jpeg'
,
'png'
=>
'image/png'
,
'tiff'
=>
'image/tiff'
,
'tif'
=>
'image/tiff'
,
'css'
=>
'text/css'
,
'html'
=>
'text/html'
,
'htm'
=>
'text/html'
,
'shtml'
=>
'text/html'
,
'txt'
=>
'text/plain'
,
'text'
=>
'text/plain'
,
'log'
=>
'text/plain'
,
'rtx'
=>
'text/richtext'
,
'rtf'
=>
'text/rtf'
,
'xml'
=>
'text/xml'
,
'xsl'
=>
'text/xml'
,
'mpeg'
=>
'video/mpeg'
,
'mpg'
=>
'video/mpeg'
,
'mpe'
=>
'video/mpeg'
,
'qt'
=>
'video/quicktime'
,
'mov'
=>
'video/quicktime'
,
'avi'
=>
'video/x-msvideo'
,
'movie'
=>
'video/x-sgi-movie'
,
'doc'
=>
'application/msword'
,
'word'
=>
'application/msword'
,
'xl'
=>
'application/excel'
,
'eml'
=>
'message/rfc822'
);
return
(
!
isset
(
$mimes
[
strtolower
(
$ext
)]))
?
'application/octet-stream'
:
$mimes
[
strtolower
(
$ext
)];
}
/**
* Set (or reset) Class Objects (variables)
*
* Usage Example:
* $page->set('X-Priority', '3');
*
* @access public
* @param string $name Parameter Name
* @param mixed $value Parameter Value
* NOTE: will not work with arrays, there are no arrays to set/reset
* @todo Should this not be using __set() magic function?
*/
public
function
set
(
$name
,
$value
=
''
)
{
try
{
if
(
isset
(
$this
->
$name
)
)
{
$this
->
$name
=
$value
;
}
else
{
throw
new
phpmailerException
(
$this
->
Lang
(
'variable_set'
)
.
$name
,
self
::
STOP_CRITICAL
);
}
}
catch
(
Exception
$e
)
{
$this
->
SetError
(
$e
->
getMessage
());
if
(
$e
->
getCode
()
==
self
::
STOP_CRITICAL
)
{
return
false
;
}
}
return
true
;
}
/**
* Strips newlines to prevent header injection.
* @access public
* @param string $str String
* @return string
*/
public
function
SecureHeader
(
$str
)
{
$str
=
str_replace
(
"
\r
"
,
''
,
$str
);
$str
=
str_replace
(
"
\n
"
,
''
,
$str
);
return
trim
(
$str
);
}
/**
* Set the private key file and password to sign the message.
*
* @access public
* @param string $key_filename Parameter File Name
* @param string $key_pass Password for private key
*/
public
function
Sign
(
$cert_filename
,
$key_filename
,
$key_pass
)
{
$this
->
sign_cert_file
=
$cert_filename
;
$this
->
sign_key_file
=
$key_filename
;
$this
->
sign_key_pass
=
$key_pass
;
}
/**
* Set the private key file and password to sign the message.
*
* @access public
* @param string $key_filename Parameter File Name
* @param string $key_pass Password for private key
*/
public
function
DKIM_QP
(
$txt
)
{
$tmp
=
""
;
$line
=
""
;
for
(
$i
=
0
;
$i
<
strlen
(
$txt
);
$i
++
)
{
$ord
=
ord
(
$txt
[
$i
]);
if
(
((
0x21
<=
$ord
)
&&
(
$ord
<=
0x3A
))
||
$ord
==
0x3C
||
((
0x3E
<=
$ord
)
&&
(
$ord
<=
0x7E
))
)
{
$line
.=
$txt
[
$i
];
}
else
{
$line
.=
"="
.
sprintf
(
"%02X"
,
$ord
);
}
}
return
$line
;
}
/**
* Generate DKIM signature
*
* @access public
* @param string $s Header
*/
public
function
DKIM_Sign
(
$s
)
{
$privKeyStr
=
file_get_contents
(
$this
->
DKIM_private
);
if
(
$this
->
DKIM_passphrase
!=
''
)
{
$privKey
=
openssl_pkey_get_private
(
$privKeyStr
,
$this
->
DKIM_passphrase
);
}
else
{
$privKey
=
$privKeyStr
;
}
if
(
openssl_sign
(
$s
,
$signature
,
$privKey
))
{
return
base64_encode
(
$signature
);
}
}
/**
* Generate DKIM Canonicalization Header
*
* @access public
* @param string $s Header
*/
public
function
DKIM_HeaderC
(
$s
)
{
$s
=
preg_replace
(
"/
\r\n
\s+/"
,
" "
,
$s
);
$lines
=
explode
(
"
\r\n
"
,
$s
);
foreach
(
$lines
as
$key
=>
$line
)
{
list
(
$heading
,
$value
)
=
explode
(
":"
,
$line
,
2
);
$heading
=
strtolower
(
$heading
);
$value
=
preg_replace
(
"/\s+/"
,
" "
,
$value
)
;
// Compress useless spaces
$lines
[
$key
]
=
$heading
.
":"
.
trim
(
$value
)
;
// Don't forget to remove WSP around the value
}
$s
=
implode
(
"
\r\n
"
,
$lines
);
return
$s
;
}
/**
* Generate DKIM Canonicalization Body
*
* @access public
* @param string $body Message Body
*/
public
function
DKIM_BodyC
(
$body
)
{
if
(
$body
==
''
)
return
"
\r\n
"
;
// stabilize line endings
$body
=
str_replace
(
"
\r\n
"
,
"
\n
"
,
$body
);
$body
=
str_replace
(
"
\n
"
,
"
\r\n
"
,
$body
);
// END stabilize line endings
while
(
substr
(
$body
,
strlen
(
$body
)
-
4
,
4
)
==
"
\r\n\r\n
"
)
{
$body
=
substr
(
$body
,
0
,
strlen
(
$body
)
-
2
);
}
return
$body
;
}
/**
* Create the DKIM header, body, as new header
*
* @access public
* @param string $headers_line Header lines
* @param string $subject Subject
* @param string $body Body
*/
public
function
DKIM_Add
(
$headers_line
,
$subject
,
$body
)
{
$DKIMsignatureType
=
'rsa-sha1'
;
// Signature & hash algorithms
$DKIMcanonicalization
=
'relaxed/simple'
;
// Canonicalization of header/body
$DKIMquery
=
'dns/txt'
;
// Query method
$DKIMtime
=
time
()
;
// Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
$subject_header
=
"Subject:
$subject
"
;
$headers
=
explode
(
"
\r\n
"
,
$headers_line
);
foreach
(
$headers
as
$header
)
{
if
(
strpos
(
$header
,
'From:'
)
===
0
)
{
$from_header
=
$header
;
}
elseif
(
strpos
(
$header
,
'To:'
)
===
0
)
{
$to_header
=
$header
;
}
}
$from
=
str_replace
(
'|'
,
'=7C'
,
$this
->
DKIM_QP
(
$from_header
));
$to
=
str_replace
(
'|'
,
'=7C'
,
$this
->
DKIM_QP
(
$to_header
));
$subject
=
str_replace
(
'|'
,
'=7C'
,
$this
->
DKIM_QP
(
$subject_header
))
;
// Copied header fields (dkim-quoted-printable
$body
=
$this
->
DKIM_BodyC
(
$body
);
$DKIMlen
=
strlen
(
$body
)
;
// Length of body
$DKIMb64
=
base64_encode
(
pack
(
"H*"
,
sha1
(
$body
)))
;
// Base64 of packed binary SHA-1 hash of body
$ident
=
(
$this
->
DKIM_identity
==
''
)
?
''
:
" i="
.
$this
->
DKIM_identity
.
";"
;
$dkimhdrs
=
"DKIM-Signature: v=1; a="
.
$DKIMsignatureType
.
"; q="
.
$DKIMquery
.
"; l="
.
$DKIMlen
.
"; s="
.
$this
->
DKIM_selector
.
";
\r\n
"
.
"
\t
t="
.
$DKIMtime
.
"; c="
.
$DKIMcanonicalization
.
";
\r\n
"
.
"
\t
h=From:To:Subject;
\r\n
"
.
"
\t
d="
.
$this
->
DKIM_domain
.
";"
.
$ident
.
"
\r\n
"
.
"
\t
z=
$from
\r\n
"
.
"
\t
|
$to
\r\n
"
.
"
\t
|
$subject
;
\r\n
"
.
"
\t
bh="
.
$DKIMb64
.
";
\r\n
"
.
"
\t
b="
;
$toSign
=
$this
->
DKIM_HeaderC
(
$from_header
.
"
\r\n
"
.
$to_header
.
"
\r\n
"
.
$subject_header
.
"
\r\n
"
.
$dkimhdrs
);
$signed
=
$this
->
DKIM_Sign
(
$toSign
);
return
"X-PHPMAILER-DKIM: phpmailer.sourceforge.net
\r\n
"
.
$dkimhdrs
.
$signed
.
"
\r\n
"
;
}
protected
function
doCallback
(
$isSent
,
$to
,
$cc
,
$bcc
,
$subject
,
$body
)
{
if
(
!
empty
(
$this
->
action_function
)
&&
function_exists
(
$this
->
action_function
))
{
$params
=
array
(
$isSent
,
$to
,
$cc
,
$bcc
,
$subject
,
$body
);
call_user_func_array
(
$this
->
action_function
,
$params
);
}
}
}
class
phpmailerException
extends
Exception
{
public
function
errorMessage
()
{
$errorMsg
=
'<strong>'
.
$this
->
getMessage
()
.
"</strong><br />
\n
"
;
return
$errorMsg
;
}
}
?>
\ No newline at end of file
software/davstorage/templates/main.cf.in
0 → 100644
View file @
72e10a30
# Global Postfix configuration file. This file lists only a subset
# of all parameters. For the syntax, and for a complete parameter
# list, see the postconf(5) manual page (command: "man 5 postconf").
#
# For common configuration examples, see BASIC_CONFIGURATION_README
# and STANDARD_CONFIGURATION_README. To find these documents, use
# the command "postconf html_directory readme_directory", or go to
# http://www.postfix.org/.
#
# For best results, change no more than 2-3 parameters at a time,
# and test if Postfix still works after every change.
# SOFT BOUNCE
#
# The soft_bounce parameter provides a limited safety net for
# testing. When soft_bounce is enabled, mail will remain queued that
# would otherwise bounce. This parameter disables locally-generated
# bounces, and prevents the SMTP server from rejecting mail permanently
# (by changing 5xx replies into 4xx replies). However, soft_bounce
# is no cure for address rewriting mistakes or mail routing mistakes.
#
#soft_bounce = no
# LOCAL PATHNAME INFORMATION
#
# The queue_directory specifies the location of the Postfix queue.
# This is also the root directory of Postfix daemons that run chrooted.
# See the files in examples/chroot-setup for setting up Postfix chroot
# environments on different UNIX systems.
#
queue_directory = ${:queue-directory}
# The command_directory parameter specifies the location of all
# postXXX commands.
#
command_directory = ${:command-directory}
# The daemon_directory parameter specifies the location of all Postfix
# daemon programs (i.e. programs listed in the master.cf file). This
# directory must be owned by root.
#
daemon_directory = ${:daemon-directory}
# The data_directory parameter specifies the location of Postfix-writable
# data files (caches, random numbers). This directory must be owned
# by the mail_owner account (see below).
#
data_directory = ${:data-directory}
# QUEUE AND PROCESS OWNERSHIP
#
# The mail_owner parameter specifies the owner of the Postfix queue
# and of most Postfix daemon processes. Specify the name of a user
# account THAT DOES NOT SHARE ITS USER OR GROUP ID WITH OTHER ACCOUNTS
# AND THAT OWNS NO OTHER FILES OR PROCESSES ON THE SYSTEM. In
# particular, don't specify nobody or daemon. PLEASE USE A DEDICATED
# USER.
#
mail_owner = ${:mail-owner}
# The default_privs parameter specifies the default rights used by
# the local delivery agent for delivery to external file or command.
# These rights are used in the absence of a recipient user context.
# DO NOT SPECIFY A PRIVILEGED USER OR THE POSTFIX OWNER.
#
#default_privs = nobody
# INTERNET HOST AND DOMAIN NAMES
#
# The myhostname parameter specifies the internet hostname of this
# mail system. The default is to use the fully-qualified domain name
# from gethostname(). $myhostname is used as a default value for many
# other configuration parameters.
#
#myhostname = host.domain.tld
#myhostname = virtual.domain.tld
# The mydomain parameter specifies the local internet domain name.
# The default is to use $myhostname minus the first component.
# $mydomain is used as a default value for many other configuration
# parameters.
#
#mydomain = domain.tld
# SENDING MAIL
#
# The myorigin parameter specifies the domain that locally-posted
# mail appears to come from. The default is to append $myhostname,
# which is fine for small sites. If you run a domain with multiple
# machines, you should (1) change this to $mydomain and (2) set up
# a domain-wide alias database that aliases each user to
# user@that.users.mailhost.
#
# For the sake of consistency between sender and recipient addresses,
# myorigin also specifies the default domain name that is appended
# to recipient addresses that have no @domain part.
#
#myorigin = $myhostname
#myorigin = $mydomain
# RECEIVING MAIL
# The inet_interfaces parameter specifies the network interface
# addresses that this mail system receives mail on. By default,
# the software claims all active interfaces on the machine. The
# parameter also controls delivery of mail to user@[ip.address].
#
# See also the proxy_interfaces parameter, for network addresses that
# are forwarded to us via a proxy or network address translator.
#
# Note: you need to stop/start Postfix when this parameter changes.
#
#inet_interfaces = all
inet_interfaces = ${:ipv4}
#inet_interfaces = $myhostname, localhost
# The proxy_interfaces parameter specifies the network interface
# addresses that this mail system receives mail on by way of a
# proxy or network address translation unit. This setting extends
# the address list specified with the inet_interfaces parameter.
#
# You must specify your proxy/NAT addresses when your system is a
# backup MX host for other domains, otherwise mail delivery loops
# will happen when the primary MX host is down.
#
#proxy_interfaces =
#proxy_interfaces = 1.2.3.4
# The mydestination parameter specifies the list of domains that this
# machine considers itself the final destination for.
#
# These domains are routed to the delivery agent specified with the
# local_transport parameter setting. By default, that is the UNIX
# compatible delivery agent that lookups all recipients in /etc/passwd
# and /etc/aliases or their equivalent.
#
# The default is $myhostname + localhost.$mydomain. On a mail domain
# gateway, you should also include $mydomain.
#
# Do not specify the names of virtual domains - those domains are
# specified elsewhere (see VIRTUAL_README).
#
# Do not specify the names of domains that this machine is backup MX
# host for. Specify those names via the relay_domains settings for
# the SMTP server, or use permit_mx_backup if you are lazy (see
# STANDARD_CONFIGURATION_README).
#
# The local machine is always the final destination for mail addressed
# to user@[the.net.work.address] of an interface that the mail system
# receives mail on (see the inet_interfaces parameter).
#
# Specify a list of host or domain names, /file/name or type:table
# patterns, separated by commas and/or whitespace. A /file/name
# pattern is replaced by its contents; a type:table is matched when
# a name matches a lookup key (the right-hand side is ignored).
# Continue long lines by starting the next line with whitespace.
#
# See also below, section "REJECTING MAIL FOR UNKNOWN LOCAL USERS".
#
#mydestination = $myhostname, localhost.$mydomain, localhost
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
# mail.$mydomain, www.$mydomain, ftp.$mydomain
# REJECTING MAIL FOR UNKNOWN LOCAL USERS
#
# The local_recipient_maps parameter specifies optional lookup tables
# with all names or addresses of users that are local with respect
# to $mydestination, $inet_interfaces or $proxy_interfaces.
#
# If this parameter is defined, then the SMTP server will reject
# mail for unknown local users. This parameter is defined by default.
#
# To turn off local recipient checking in the SMTP server, specify
# local_recipient_maps = (i.e. empty).
#
# The default setting assumes that you use the default Postfix local
# delivery agent for local delivery. You need to update the
# local_recipient_maps setting if:
#
# - You define $mydestination domain recipients in files other than
# /etc/passwd, /etc/aliases, or the $virtual_alias_maps files.
# For example, you define $mydestination domain recipients in
# the $virtual_mailbox_maps files.
#
# - You redefine the local delivery agent in master.cf.
#
# - You redefine the "local_transport" setting in main.cf.
#
# - You use the "luser_relay", "mailbox_transport", or "fallback_transport"
# feature of the Postfix local delivery agent (see local(8)).
#
# Details are described in the LOCAL_RECIPIENT_README file.
#
# Beware: if the Postfix SMTP server runs chrooted, you probably have
# to access the passwd file via the proxymap service, in order to
# overcome chroot restrictions. The alternative, having a copy of
# the system passwd file in the chroot jail is just not practical.
#
# The right-hand side of the lookup tables is conveniently ignored.
# In the left-hand side, specify a bare username, an @domain.tld
# wild-card, or specify a user@domain.tld address.
#
#local_recipient_maps = unix:passwd.byname $alias_maps
#local_recipient_maps = proxy:unix:passwd.byname $alias_maps
#local_recipient_maps =
# The unknown_local_recipient_reject_code specifies the SMTP server
# response code when a recipient domain matches $mydestination or
# $proxy/$inet_interfaces, while $local_recipient_maps is non-empty
# and the recipient address or address local-part is not found.
#
# The default setting is 550 (reject mail) but it is safer to start
# with 450 (try again later) until you are certain that your
# local_recipient_maps settings are OK.
#
unknown_local_recipient_reject_code = 550
# TRUST AND RELAY CONTROL
# The mynetworks parameter specifies the list of "trusted" SMTP
# clients that have more privileges than "strangers".
#
# In particular, "trusted" SMTP clients are allowed to relay mail
# through Postfix. See the smtpd_recipient_restrictions parameter
# in postconf(5).
#
# You can specify the list of "trusted" network addresses by hand
# or you can let Postfix do it for you (which is the default).
#
# By default (mynetworks_style = subnet), Postfix "trusts" SMTP
# clients in the same IP subnetworks as the local machine.
# On Linux, this does works correctly only with interfaces specified
# with the "ifconfig" command.
#
# Specify "mynetworks_style = class" when Postfix should "trust" SMTP
# clients in the same IP class A/B/C networks as the local machine.
# Don't do this with a dialup site - it would cause Postfix to "trust"
# your entire provider's network. Instead, specify an explicit
# mynetworks list by hand, as described below.
#
# Specify "mynetworks_style = host" when Postfix should "trust"
# only the local machine.
#
#mynetworks_style = class
#mynetworks_style = subnet
#mynetworks_style = host
# Alternatively, you can specify the mynetworks list by hand, in
# which case Postfix ignores the mynetworks_style setting.
#
# Specify an explicit list of network/netmask patterns, where the
# mask specifies the number of bits in the network part of a host
# address.
#
# You can also specify the absolute pathname of a pattern file instead
# of listing the patterns here. Specify type:table for table-based lookups
# (the value on the table right-hand side is not used).
#
#mynetworks = 168.100.189.0/28, 127.0.0.0/8
#mynetworks = $config_directory/mynetworks
#mynetworks = hash:/etc/postfix/network_table
# The relay_domains parameter restricts what destinations this system will
# relay mail to. See the smtpd_recipient_restrictions description in
# postconf(5) for detailed information.
#
# By default, Postfix relays mail
# - from "trusted" clients (IP address matches $mynetworks) to any destination,
# - from "untrusted" clients to destinations that match $relay_domains or
# subdomains thereof, except addresses with sender-specified routing.
# The default relay_domains value is $mydestination.
#
# In addition to the above, the Postfix SMTP server by default accepts mail
# that Postfix is final destination for:
# - destinations that match $inet_interfaces or $proxy_interfaces,
# - destinations that match $mydestination
# - destinations that match $virtual_alias_domains,
# - destinations that match $virtual_mailbox_domains.
# These destinations do not need to be listed in $relay_domains.
#
# Specify a list of hosts or domains, /file/name patterns or type:name
# lookup tables, separated by commas and/or whitespace. Continue
# long lines by starting the next line with whitespace. A file name
# is replaced by its contents; a type:name table is matched when a
# (parent) domain appears as lookup key.
#
# NOTE: Postfix will not automatically forward mail for domains that
# list this system as their primary or backup MX host. See the
# permit_mx_backup restriction description in postconf(5).
#
#relay_domains = $mydestination
# INTERNET OR INTRANET
# The relayhost parameter specifies the default host to send mail to
# when no entry is matched in the optional transport(5) table. When
# no relayhost is given, mail is routed directly to the destination.
#
# On an intranet, specify the organizational domain name. If your
# internal DNS uses no MX records, specify the name of the intranet
# gateway host instead.
#
# In the case of SMTP, specify a domain, host, host:port, [host]:port,
# [address] or [address]:port; the form [host] turns off MX lookups.
#
# If you're connected via UUCP, see also the default_transport parameter.
#
#relayhost = $mydomain
#relayhost = [gateway.my.domain]
#relayhost = [mailserver.isp.tld]
#relayhost = uucphost
#relayhost = [an.ip.add.ress]
# REJECTING UNKNOWN RELAY USERS
#
# The relay_recipient_maps parameter specifies optional lookup tables
# with all addresses in the domains that match $relay_domains.
#
# If this parameter is defined, then the SMTP server will reject
# mail for unknown relay users. This feature is off by default.
#
# The right-hand side of the lookup tables is conveniently ignored.
# In the left-hand side, specify an @domain.tld wild-card, or specify
# a user@domain.tld address.
#
#relay_recipient_maps = hash:/etc/postfix/relay_recipients
# INPUT RATE CONTROL
#
# The in_flow_delay configuration parameter implements mail input
# flow control. This feature is turned on by default, although it
# still needs further development (it's disabled on SCO UNIX due
# to an SCO bug).
#
# A Postfix process will pause for $in_flow_delay seconds before
# accepting a new message, when the message arrival rate exceeds the
# message delivery rate. With the default 100 SMTP server process
# limit, this limits the mail inflow to 100 messages a second more
# than the number of messages delivered per second.
#
# Specify 0 to disable the feature. Valid delays are 0..10.
#
#in_flow_delay = 1s
# ADDRESS REWRITING
#
# The ADDRESS_REWRITING_README document gives information about
# address masquerading or other forms of address rewriting including
# username->Firstname.Lastname mapping.
# ADDRESS REDIRECTION (VIRTUAL DOMAIN)
#
# The VIRTUAL_README document gives information about the many forms
# of domain hosting that Postfix supports.
# "USER HAS MOVED" BOUNCE MESSAGES
#
# See the discussion in the ADDRESS_REWRITING_README document.
# TRANSPORT MAP
#
# See the discussion in the ADDRESS_REWRITING_README document.
# ALIAS DATABASE
#
# The alias_maps parameter specifies the list of alias databases used
# by the local delivery agent. The default list is system dependent.
#
# On systems with NIS, the default is to search the local alias
# database, then the NIS alias database. See aliases(5) for syntax
# details.
#
# If you change the alias database, run "postalias /etc/aliases" (or
# wherever your system stores the mail alias file), or simply run
# "newaliases" to build the necessary DBM or DB file.
#
# It will take a minute or so before changes become visible. Use
# "postfix reload" to eliminate the delay.
#
#alias_maps = dbm:/etc/aliases
#alias_maps = hash:/etc/aliases
#alias_maps = hash:/etc/aliases, nis:mail.aliases
#alias_maps = netinfo:/aliases
# The alias_database parameter specifies the alias database(s) that
# are built with "newaliases" or "sendmail -bi". This is a separate
# configuration parameter, because alias_maps (see above) may specify
# tables that are not necessarily all under control by Postfix.
#
#alias_database = dbm:/etc/aliases
#alias_database = dbm:/etc/mail/aliases
#alias_database = hash:/etc/aliases
#alias_database = hash:/etc/aliases, hash:/opt/majordomo/aliases
# ADDRESS EXTENSIONS (e.g., user+foo)
#
# The recipient_delimiter parameter specifies the separator between
# user names and address extensions (user+foo). See canonical(5),
# local(8), relocated(5) and virtual(5) for the effects this has on
# aliases, canonical, virtual, relocated and .forward file lookups.
# Basically, the software tries user+foo and .forward+foo before
# trying user and .forward.
#
#recipient_delimiter = +
# DELIVERY TO MAILBOX
#
# The home_mailbox parameter specifies the optional pathname of a
# mailbox file relative to a user's home directory. The default
# mailbox file is /var/spool/mail/user or /var/mail/user. Specify
# "Maildir/" for qmail-style delivery (the / is required).
#
#home_mailbox = Mailbox
#home_mailbox = Maildir/
# The mail_spool_directory parameter specifies the directory where
# UNIX-style mailboxes are kept. The default setting depends on the
# system type.
#
#mail_spool_directory = /var/mail
#mail_spool_directory = /var/spool/mail
# The mailbox_command parameter specifies the optional external
# command to use instead of mailbox delivery. The command is run as
# the recipient with proper HOME, SHELL and LOGNAME environment settings.
# Exception: delivery for root is done as $default_user.
#
# Other environment variables of interest: USER (recipient username),
# EXTENSION (address extension), DOMAIN (domain part of address),
# and LOCAL (the address localpart).
#
# Unlike other Postfix configuration parameters, the mailbox_command
# parameter is not subjected to $parameter substitutions. This is to
# make it easier to specify shell syntax (see example below).
#
# Avoid shell meta characters because they will force Postfix to run
# an expensive shell process. Procmail alone is expensive enough.
#
# IF YOU USE THIS TO DELIVER MAIL SYSTEM-WIDE, YOU MUST SET UP AN
# ALIAS THAT FORWARDS MAIL FOR ROOT TO A REAL USER.
#
#mailbox_command = /some/where/procmail
#mailbox_command = /some/where/procmail -a "$EXTENSION"
# The mailbox_transport specifies the optional transport in master.cf
# to use after processing aliases and .forward files. This parameter
# has precedence over the mailbox_command, fallback_transport and
# luser_relay parameters.
#
# Specify a string of the form transport:nexthop, where transport is
# the name of a mail delivery transport defined in master.cf. The
# :nexthop part is optional. For more details see the sample transport
# configuration file.
#
# NOTE: if you use this feature for accounts not in the UNIX password
# file, then you must update the "local_recipient_maps" setting in
# the main.cf file, otherwise the SMTP server will reject mail for
# non-UNIX accounts with "User unknown in local recipient table".
#
# Cyrus IMAP over LMTP. Specify ``lmtpunix cmd="lmtpd"
# listen="/var/imap/socket/lmtp" prefork=0'' in cyrus.conf.
#mailbox_transport = lmtp:unix:/var/imap/socket/lmtp
#
# Cyrus IMAP via command line. Uncomment the "cyrus...pipe" and
# subsequent line in master.cf.
#mailbox_transport = cyrus
# The fallback_transport specifies the optional transport in master.cf
# to use for recipients that are not found in the UNIX passwd database.
# This parameter has precedence over the luser_relay parameter.
#
# Specify a string of the form transport:nexthop, where transport is
# the name of a mail delivery transport defined in master.cf. The
# :nexthop part is optional. For more details see the sample transport
# configuration file.
#
# NOTE: if you use this feature for accounts not in the UNIX password
# file, then you must update the "local_recipient_maps" setting in
# the main.cf file, otherwise the SMTP server will reject mail for
# non-UNIX accounts with "User unknown in local recipient table".
#
#fallback_transport = lmtp:unix:/file/name
#fallback_transport = cyrus
#fallback_transport =
# The luser_relay parameter specifies an optional destination address
# for unknown recipients. By default, mail for unknown@$mydestination,
# unknown@[$inet_interfaces] or unknown@[$proxy_interfaces] is returned
# as undeliverable.
#
# The following expansions are done on luser_relay: $user (recipient
# username), $shell (recipient shell), $home (recipient home directory),
# $recipient (full recipient address), $extension (recipient address
# extension), $domain (recipient domain), $local (entire recipient
# localpart), $recipient_delimiter. Specify $name?value or
# $name:value to expand value only when $name does (does not) exist.
#
# luser_relay works only for the default Postfix local delivery agent.
#
# NOTE: if you use this feature for accounts not in the UNIX password
# file, then you must specify "local_recipient_maps =" (i.e. empty) in
# the main.cf file, otherwise the SMTP server will reject mail for
# non-UNIX accounts with "User unknown in local recipient table".
#
#luser_relay = $user@other.host
#luser_relay = $local@other.host
#luser_relay = admin+$local
# JUNK MAIL CONTROLS
#
# The controls listed here are only a very small subset. The file
# SMTPD_ACCESS_README provides an overview.
# The header_checks parameter specifies an optional table with patterns
# that each logical message header is matched against, including
# headers that span multiple physical lines.
#
# By default, these patterns also apply to MIME headers and to the
# headers of attached messages. With older Postfix versions, MIME and
# attached message headers were treated as body text.
#
# For details, see "man header_checks".
#
#header_checks = regexp:/etc/postfix/header_checks
# FAST ETRN SERVICE
#
# Postfix maintains per-destination logfiles with information about
# deferred mail, so that mail can be flushed quickly with the SMTP
# "ETRN domain.tld" command, or by executing "sendmail -qRdomain.tld".
# See the ETRN_README document for a detailed description.
#
# The fast_flush_domains parameter controls what destinations are
# eligible for this service. By default, they are all domains that
# this server is willing to relay mail to.
#
#fast_flush_domains = $relay_domains
# SHOW SOFTWARE VERSION OR NOT
#
# The smtpd_banner parameter specifies the text that follows the 220
# code in the SMTP server's greeting banner. Some people like to see
# the mail version advertised. By default, Postfix shows no version.
#
# You MUST specify $myhostname at the start of the text. That is an
# RFC requirement. Postfix itself does not care.
#
#smtpd_banner = $myhostname ESMTP $mail_name
#smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
# PARALLEL DELIVERY TO THE SAME DESTINATION
#
# How many parallel deliveries to the same user or domain? With local
# delivery, it does not make sense to do massively parallel delivery
# to the same user, because mailbox updates must happen sequentially,
# and expensive pipelines in .forward files can cause disasters when
# too many are run at the same time. With SMTP deliveries, 10
# simultaneous connections to the same domain could be sufficient to
# raise eyebrows.
#
# Each message delivery transport has its XXX_destination_concurrency_limit
# parameter. The default is $default_destination_concurrency_limit for
# most delivery transports. For the local delivery agent the default is 2.
#local_destination_concurrency_limit = 2
#default_destination_concurrency_limit = 20
# DEBUGGING CONTROL
#
# The debug_peer_level parameter specifies the increment in verbose
# logging level when an SMTP client or server host name or address
# matches a pattern in the debug_peer_list parameter.
#
debug_peer_level = 2
# The debug_peer_list parameter specifies an optional list of domain
# or network patterns, /file/name patterns or type:name tables. When
# an SMTP client or server host name or address matches a pattern,
# increase the verbose logging level by the amount specified in the
# debug_peer_level parameter.
#
#debug_peer_list = 127.0.0.1
#debug_peer_list = some.domain
# The debugger_command specifies the external command that is executed
# when a Postfix daemon program is run with the -D option.
#
# Use "command .. & sleep 5" so that the debugger can attach before
# the process marches on. If you use an X-based debugger, be sure to
# set up your XAUTHORITY environment variable before starting Postfix.
#
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
ddd $daemon_directory/$process_name $process_id & sleep 5
# If you can't use X, use this to capture the call stack when a
# daemon crashes. The result is in a file in the configuration
# directory, and is named after the process name and the process ID.
#
# debugger_command =
# PATH=/bin:/usr/bin:/usr/local/bin; export PATH; (echo cont;
# echo where) | gdb $daemon_directory/$process_name $process_id 2>&1
# >$config_directory/$process_name.$process_id.log & sleep 5
#
# Another possibility is to run gdb under a detached screen session.
# To attach to the screen sesssion, su root and run "screen -r
# <id_string>" where <id_string> uniquely matches one of the detached
# sessions (from "screen -list").
#
# debugger_command =
# PATH=/bin:/usr/bin:/sbin:/usr/sbin; export PATH; screen
# -dmS $process_name gdb $daemon_directory/$process_name
# $process_id & sleep 1
# INSTALL-TIME CONFIGURATION INFORMATION
#
# The following parameters are used when installing a new Postfix version.
#
# sendmail_path: The full pathname of the Postfix sendmail command.
# This is the Sendmail-compatible mail posting interface.
#
sendmail_path = ${:command-directory}/sendmail
# newaliases_path: The full pathname of the Postfix newaliases command.
# This is the Sendmail-compatible command to build alias databases.
#
newaliases_path = ${:bin-directory}/newaliases
# mailq_path: The full pathname of the Postfix mailq command. This
# is the Sendmail-compatible mail queue listing command.
#
mailq_path = ${:bin-directory}/mailq
# setgid_group: The group for mail submission and queue management
# commands. This must be a group name with a numerical group ID that
# is not shared with other accounts, not even with the Postfix account.
#
setgid_group = ${:mail-group}
# html_directory: The location of the Postfix HTML documentation.
#
html_directory = no
# manpage_directory: The location of the Postfix on-line manual pages.
#
manpage_directory = /usr/local/man
# sample_directory: The location of the Postfix sample configuration files.
# This parameter is obsolete as of Postfix 2.1.
#
sample_directory = /etc/postfix
# readme_directory: The location of the Postfix README files.
#
readme_directory = no
inet_protocols = all
software/davstorage/templates/master.cf.in
0 → 100644
View file @
72e10a30
#
# Postfix master process configuration file. For details on the format
# of the file, see the master(5) manual page (command: "man 5 master").
#
# Do not forget to execute "postfix reload" after editing this file.
#
# ==========================================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (yes) (never) (100)
# ==========================================================================
${:port} inet n - n - - smtpd
#smtp inet n - n - 1 postscreen
#smtpd pass - - n - - smtpd
#dnsblog unix - - n - 0 dnsblog
#tlsproxy unix - - n - 0 tlsproxy
#submission inet n - n - - smtpd
# -o syslog_name=postfix/submission
# -o smtpd_tls_security_level=encrypt
# -o smtpd_sasl_auth_enable=yes
# -o smtpd_reject_unlisted_recipient=no
# -o smtpd_client_restrictions=$mua_client_restrictions
# -o smtpd_helo_restrictions=$mua_helo_restrictions
# -o smtpd_sender_restrictions=$mua_sender_restrictions
# -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
#smtps inet n - n - - smtpd
# -o syslog_name=postfix/smtps
# -o smtpd_tls_wrappermode=yes
# -o smtpd_sasl_auth_enable=yes
# -o smtpd_reject_unlisted_recipient=no
# -o smtpd_client_restrictions=$mua_client_restrictions
# -o smtpd_helo_restrictions=$mua_helo_restrictions
# -o smtpd_sender_restrictions=$mua_sender_restrictions
# -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
#628 inet n - n - - qmqpd
pickup unix n - n 60 1 pickup
cleanup unix n - n - 0 cleanup
qmgr unix n - n 300 1 qmgr
#qmgr unix n - n 300 1 oqmgr
tlsmgr unix - - n 1000? 1 tlsmgr
rewrite unix - - n - - trivial-rewrite
bounce unix - - n - 0 bounce
defer unix - - n - 0 bounce
trace unix - - n - 0 bounce
verify unix - - n - 1 verify
flush unix n - n 1000? 0 flush
proxymap unix - - n - - proxymap
proxywrite unix - - n - 1 proxymap
smtp unix - - n - - smtp
relay unix - - n - - smtp
# -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
showq unix n - n - - showq
error unix - - n - - error
retry unix - - n - - error
discard unix - - n - - discard
local unix - n n - - local
virtual unix - n n - - virtual
lmtp unix - - n - - lmtp
anvil unix - - n - 1 anvil
scache unix - - n - 1 scache
#
# ====================================================================
# Interfaces to non-Postfix software. Be sure to examine the manual
# pages of the non-Postfix software to find out what options it wants.
#
# Many of the following services use the Postfix pipe(8) delivery
# agent. See the pipe(8) man page for information about $recipient
# and other message envelope options.
# ====================================================================
#
# maildrop. See the Postfix MAILDROP_README file for details.
# Also specify in main.cf: maildrop_destination_recipient_limit=1
#
#maildrop unix - n n - - pipe
# flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d $recipient
#
# ====================================================================
#
# Recent Cyrus versions can use the existing "lmtp" master.cf entry.
#
# Specify in cyrus.conf:
# lmtp cmd="lmtpd -a" listen="localhost:lmtp" proto=tcp4
#
# Specify in main.cf one or more of the following:
# mailbox_transport = lmtp:inet:localhost
# virtual_transport = lmtp:inet:localhost
#
# ====================================================================
#
# Cyrus 2.1.5 (Amos Gouaux)
# Also specify in main.cf: cyrus_destination_recipient_limit=1
#
#cyrus unix - n n - - pipe
# user=cyrus argv=/cyrus/bin/deliver -e -r $sender -m $extension $user
#
# ====================================================================
#
# Old example of delivery via Cyrus.
#
#old-cyrus unix - n n - - pipe
# flags=R user=cyrus argv=/cyrus/bin/deliver -e -m $extension $user
#
# ====================================================================
#
# See the Postfix UUCP_README file for configuration details.
#
#uucp unix - n n - - pipe
# flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
#
# ====================================================================
#
# Other external delivery methods.
#
#ifmail unix - n n - - pipe
# flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
#
#bsmtp unix - n n - - pipe
# flags=Fq. user=bsmtp argv=/usr/local/sbin/bsmtp -f $sender $nexthop $recipient
#
#scalemail-backend unix - n n - 2 pipe
# flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store
# $nexthop $user $extension
#
#mailman unix - n n - - pipe
# flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
# $nexthop $user
software/davstorage/templates/postfix.in
0 → 100644
View file @
72e10a30
#!/bin/sh
${
:postfix-location
}
-c
${
:postfix-config-dir
}
start
\ No newline at end of file
software/davstorage/templates/sendmail.in
0 → 100644
View file @
72e10a30
#!/bin/sh
${
:sendmail-location
}
-C
${
:postfix-config-dir
}
$*
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment