LSaddons: Code cleaning

This commit is contained in:
Benjamin Renard 2023-06-20 19:42:12 +02:00
parent 425df3da3a
commit 0eb0143921
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC
8 changed files with 1093 additions and 1078 deletions

View file

@ -39,14 +39,14 @@ LSerror :: defineError('ASTERISK_04',
___("Asterisk: The LDAP attribute type of the attribute %{attr} is incorrect: its must be password.") ___("Asterisk: The LDAP attribute type of the attribute %{attr} is incorrect: its must be password.")
); );
/** /**
* Check support of Asterisk by LdapSaisie * Check support of Asterisk by LdapSaisie
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
* *
* @return boolean true if Asterisk is totally supported, false in other case * @return boolean true if Asterisk is totally supported, false in other case
*/ */
function LSaddon_asterisk_support() { function LSaddon_asterisk_support() {
$retval=true; $retval=true;
$MUST_DEFINE_CONST= array( $MUST_DEFINE_CONST= array(
@ -62,11 +62,11 @@ LSerror :: defineError('ASTERISK_04',
} }
return $retval; return $retval;
} }
/** /**
* Make asterisk password hash * Make asterisk password hash
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
@ -80,7 +80,7 @@ LSerror :: defineError('ASTERISK_04',
* *
* @return string|false The hashed password, or false * @return string|false The hashed password, or false
*/ */
function hashAsteriskPassword($ldapObject,$clearPassword) { function hashAsteriskPassword($ldapObject,$clearPassword) {
if (!is_a($ldapObject,'LSldapObject')) { if (!is_a($ldapObject,'LSldapObject')) {
LSerror :: addErrorCode('ASTERISK_01',array('function' => 'hashAsteriskPassword', 'objectName' => 'LSldapObject')); LSerror :: addErrorCode('ASTERISK_01',array('function' => 'hashAsteriskPassword', 'objectName' => 'LSldapObject'));
return false; return false;
@ -90,9 +90,9 @@ LSerror :: defineError('ASTERISK_04',
} }
$ldapObject -> registerOtherValue('clearPassword',$clearPassword); $ldapObject -> registerOtherValue('clearPassword',$clearPassword);
return md5($ldapObject->getFData(LS_ASTERISK_HASH_PWD_FORMAT)); return md5($ldapObject->getFData(LS_ASTERISK_HASH_PWD_FORMAT));
} }
/** /**
* Generate asterisk MD5 hashed password * Generate asterisk MD5 hashed password
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
@ -101,7 +101,7 @@ LSerror :: defineError('ASTERISK_04',
* *
* @return string|false asterisk MD5 hashed password or False * @return string|false asterisk MD5 hashed password or False
*/ */
function generate_asteriskMD5HashedPassword($ldapObject) { function generate_asteriskMD5HashedPassword($ldapObject) {
if ( get_class($ldapObject -> attrs[ LS_ASTERISK_USERPASSWORD_ATTR ]) != 'LSattribute' ) { if ( get_class($ldapObject -> attrs[ LS_ASTERISK_USERPASSWORD_ATTR ]) != 'LSattribute' ) {
LSerror :: addErrorCode('ASTERISK_02',array(LS_ASTERISK_USERPASSWORD_ATTR)); LSerror :: addErrorCode('ASTERISK_02',array(LS_ASTERISK_USERPASSWORD_ATTR));
return false; return false;
@ -123,4 +123,4 @@ LSerror :: defineError('ASTERISK_04',
return false; return false;
} }
return hashAsteriskPassword($ldapObject,(string)$password); return hashAsteriskPassword($ldapObject,(string)$password);
} }

View file

@ -45,14 +45,14 @@ LSerror :: defineError('LS_EXPORTSEARCHRESULTASCSV_03',
); );
/** /**
* Check support of exportSearchResultAsCSV * Check support of exportSearchResultAsCSV
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
* *
* @return boolean true if exportSearchResultAsCSV is fully supported, false in other case * @return boolean true if exportSearchResultAsCSV is fully supported, false in other case
*/ */
function LSaddon_exportSearchResultAsCSV_support() { function LSaddon_exportSearchResultAsCSV_support() {
$retval=true; $retval=true;
// Check fputcsv function // Check fputcsv function
@ -74,9 +74,9 @@ LSerror :: defineError('LS_EXPORTSEARCHRESULTASCSV_03',
} }
return $retval; return $retval;
} }
/** /**
* Write LSsearch result as CSV and force download of it. * Write LSsearch result as CSV and force download of it.
* *
* @param LSsearch $LSsearch The LSsearch object * @param LSsearch $LSsearch The LSsearch object
@ -85,7 +85,7 @@ LSerror :: defineError('LS_EXPORTSEARCHRESULTASCSV_03',
* *
* @return boolean Void if CSV file is successfully generated and upload, false in other case * @return boolean Void if CSV file is successfully generated and upload, false in other case
*/ */
function exportSearchResultAsCSV($LSsearch) { function exportSearchResultAsCSV($LSsearch) {
$csv = fopen('php://temp/maxmemory:'. (5*1024*1024), 'r+'); $csv = fopen('php://temp/maxmemory:'. (5*1024*1024), 'r+');
if ($csv === false) { if ($csv === false) {
@ -134,9 +134,9 @@ LSerror :: defineError('LS_EXPORTSEARCHRESULTASCSV_03',
print stream_get_contents($csv); print stream_get_contents($csv);
@fclose($csv); @fclose($csv);
exit(); exit();
} }
/** /**
* Write CSV row in file * Write CSV row in file
* *
* @param resource &$csv The CSV file description reference * @param resource &$csv The CSV file description reference
@ -146,9 +146,9 @@ LSerror :: defineError('LS_EXPORTSEARCHRESULTASCSV_03',
* *
* @return boolean True if CSV row is successfully writed, false in other case * @return boolean True if CSV row is successfully writed, false in other case
*/ */
function writeRowInCSV(&$csv, &$row) { function writeRowInCSV(&$csv, &$row) {
if (!defined('PHP_VERSION_ID') or PHP_VERSION_ID < 50504) { if (!defined('PHP_VERSION_ID') or PHP_VERSION_ID < 50504) {
return (fputcsv($csv, $row, LS_EXPORTSEARCHRESULTASCSV_DELIMITER, LS_EXPORTSEARCHRESULTASCSV_ENCLOSURE) !== false); return (fputcsv($csv, $row, LS_EXPORTSEARCHRESULTASCSV_DELIMITER, LS_EXPORTSEARCHRESULTASCSV_ENCLOSURE) !== false);
} }
return (fputcsv($csv, $row, LS_EXPORTSEARCHRESULTASCSV_DELIMITER, LS_EXPORTSEARCHRESULTASCSV_ENCLOSURE, LS_EXPORTSEARCHRESULTASCSV_ESCAPE_CHAR) !== false); return (fputcsv($csv, $row, LS_EXPORTSEARCHRESULTASCSV_DELIMITER, LS_EXPORTSEARCHRESULTASCSV_ENCLOSURE, LS_EXPORTSEARCHRESULTASCSV_ESCAPE_CHAR) !== false);
} }

View file

@ -53,165 +53,170 @@ LSerror :: defineError('FTP_05',
___("FTP Support : Unable to rename folder from %{old} to %{new} on the remote server.") ___("FTP Support : Unable to rename folder from %{old} to %{new} on the remote server.")
); );
/** /**
* Verification du support FTP par ldapSaisie * Check support of FTP addon
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
* *
* @return boolean true si FTP est pleinement supporté, false sinon * @return boolean true if FTP addon is fully supported, false in other case
*/ */
function LSaddon_ftp_support() { function LSaddon_ftp_support() {
$retval=true; $retval = true;
// Dependance de librairie // Net_FTP lib dependency
if (!class_exists('Net_FTP')) { if (!class_exists('Net_FTP')) {
if (!defined('NET_FTP')) { if (!defined('NET_FTP')) {
LSerror :: addErrorCode('FTP_SUPPORT_02','NET_FTP'); LSerror :: addErrorCode('FTP_SUPPORT_02', 'NET_FTP');
$retval=false; $retval = false;
} else if(!LSsession::includeFile(NET_FTP, true)) { } else if(!LSsession::includeFile(NET_FTP, true)) {
LSerror :: addErrorCode('FTP_SUPPORT_01'); LSerror :: addErrorCode('FTP_SUPPORT_01');
$retval=false; $retval = false;
} }
} }
return $retval; return $retval;
} }
/** /**
* Connexion a un serveur FTP * Connect to FTP server
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
* *
* @param string $host Le nom ou l'IP du serveur FTP * @param string $host FTP server FQDN or IP address
* @param string $port Le port de connexion au serveur ftp * @param string $port The TCP port of the FTP server
* @param string $user Le nom d'utilidateur de connexion * @param string $user The username
* @param string $pwd Le mot de passe de connexion * @param string $pwd The password
* *
* @return Net_FTP|false Net_FTP object en cas de succès, false sinon * @return Net_FTP|false Net_FTP object in case of success, false otherwise
*/ */
function connectToFTP($host,$port,$user,$pwd) { function connectToFTP($host, $port, $user, $pwd) {
$cnx = new Net_FTP(); $cnx = new Net_FTP();
$do = $cnx -> connect($host,$port); $do = $cnx -> connect($host, $port);
if (! $do instanceof PEAR_Error){ if (!$do instanceof PEAR_Error){
$do = $cnx -> login($user,$pwd); $do = $cnx -> login($user, $pwd);
if (! $do instanceof PEAR_Error) { if (!$do instanceof PEAR_Error) {
return $cnx; return $cnx;
} }
else { else {
LSerror :: addErrorCode('FTP_01',"2"); LSerror :: addErrorCode('FTP_01', "2");
LSerror :: addErrorCode('FTP_00',$do -> getMessage()); LSerror :: addErrorCode('FTP_00', $do -> getMessage());
return false; return false;
} }
} }
else { else {
LSerror :: addErrorCode('FTP_01',"1"); LSerror :: addErrorCode('FTP_01', "1");
LSerror :: addErrorCode('FTP_00',$do -> getMessage()); LSerror :: addErrorCode('FTP_00', $do -> getMessage());
return false; return false;
} }
} }
/** /**
* Creation d'un ou plusieurs dossiers via FTP * Creation d'un ou plusieurs dossiers via FTP
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param string $host Le nom ou l'IP du serveur FTP
* @param string $port Le port de connexion au serveur ftp
* @param string $user Le nom d'utilidateur de connexion
* @param string $pwd Le mot de passe de connexion
* @param array $dirs ou string Le(s) dossier(s) à ajouter
*
* @return bool True ou false si il y a un problème durant la création du/des dossier(s)
* Create one or more directories throught FTP
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
* *
* @param string $host Le nom ou l'IP du serveur FTP * @param string $host FTP server FQDN or IP address
* @param string $port Le port de connexion au serveur ftp * @param string $port The TCP port of the FTP server
* @param string $user Le nom d'utilidateur de connexion * @param string $user The username
* @param string $pwd Le mot de passe de connexion * @param string $pwd The password
* @param array $dirs ou string Le(s) dossier(s) à ajouter * @param array|string $dirs The directory/ies to add
* @param int $chmod The directory/ies mode as an octal number (do not forget leading zero,
* example: 0755 or 02755, default : default umask on the SSH server)
* *
* @return bool True ou false si il y a un problème durant la création du/des dossier(s) * @return boolean
*/ */
function createDirsByFTP($host,$port,$user,$pwd,$dirs,$chmod=NULL) { function createDirsByFTP($host, $port, $user, $pwd, $dirs, $chmod=NULL) {
$cnx = connectToFTP($host,$port,$user,$pwd); $cnx = connectToFTP($host, $port, $user, $pwd);
if (!$cnx) return false; if (!$cnx) return false;
if (!is_array($dirs)) { foreach(ensureIsArray($dirs) as $dir) {
$dirs = array($dirs); $do = $cnx -> mkdir($dir, true);
}
foreach($dirs as $dir) {
$do = $cnx -> mkdir($dir,true);
if ($do instanceof PEAR_Error) { if ($do instanceof PEAR_Error) {
LSerror :: addErrorCode('FTP_02',$dir); LSerror :: addErrorCode('FTP_02', $dir);
LSerror :: addErrorCode('FTP_00',$do -> getMessage()); LSerror :: addErrorCode('FTP_00', $do -> getMessage());
return false; return false;
} }
if ($chmod) { if ($chmod) {
$do = $cnx -> chmod($dir,$chmod); $do = $cnx -> chmod($dir, $chmod);
if ($do instanceof PEAR_Error) { if ($do instanceof PEAR_Error) {
LSerror :: addErrorCode('FTP_04',$dir); LSerror :: addErrorCode('FTP_04', $dir);
LSerror :: addErrorCode('FTP_00',$do -> getMessage()); LSerror :: addErrorCode('FTP_00', $do -> getMessage());
} }
} }
} }
return true; return true;
} }
/** /**
* Suppression d'un ou plusieurs dossiers via FTP * Delete one or more directories throught FTP
* *
* Note : Attention : suppression récursive. Cela veut dire que les sous-dossiers * Caution : recursive deletion ! The content of the directory will be listed and deleted before the
* lister par un LS FTP seront supprimé d'abord. Attention : Si votre serveur * directory. If your FTP server is configured to mask some files or directories (for instance,
* FTP est configuré pour caché certains fichiers ou dossiers (dont le nom * starting by '.'), they will not be listed and deleted and this may cause the deletion to fail.
* commence par un '.' par exempl), ces fichiers ne seront pas supprimés et la * With VsFTPd, you have to add force_dot_files=1 in configuration.
* suppression du dossier parent échoura.
*
* Pour VsFTPd : Ajouter force_dot_files=1 dans la configuration.
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
* *
* @param string $host Le nom ou l'IP du serveur FTP * @param string $host FTP server FQDN or IP address
* @param string $port Le port de connexion au serveur ftp * @param string $port The TCP port of the FTP server
* @param string $user Le nom d'utilidateur de connexion * @param string $user The username
* @param string $pwd Le mot de passe de connexion * @param string $pwd The password
* @param array $dirs ou string Le(s) dossier(s) à supprimer * @param array|string $dirs The directory/ies to remove
* *
* @return bool True ou false si il y a un problème durant la suppression du/des dossier(s) * @return boolean
*/ */
function removeDirsByFTP($host,$port,$user,$pwd,$dirs) { function removeDirsByFTP($host, $port, $user, $pwd, $dirs) {
$cnx = connectToFTP($host,$port,$user,$pwd); $cnx = connectToFTP($host, $port, $user, $pwd);
if (!$cnx) return false; if (!$cnx) return false;
if (!is_array($dirs)) { foreach(ensureIsArray($dirs) as $dir) {
$dirs = array($dirs); if ($dir[strlen($dir)-1] != '/') {
} $dir .= '/';
foreach($dirs as $dir) {
if ($dir[strlen($dir)-1]!='/') {
$dir.='/';
} }
$do = $cnx -> rm($dir,true); $do = $cnx -> rm($dir,true);
if ($do instanceof PEAR_Error) { if ($do instanceof PEAR_Error) {
LSerror :: addErrorCode('FTP_03',$dir); LSerror :: addErrorCode('FTP_03', $dir);
LSerror :: addErrorCode('FTP_00',$do -> getMessage()); LSerror :: addErrorCode('FTP_00', $do -> getMessage());
return false; return false;
} }
} }
return true; return true;
} }
/** /**
* Renomage d'un dossier via FTP * Rename a directory throught FTP
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
* *
* @param string $host Le nom ou l'IP du serveur FTP * @param string $host FTP server FQDN or IP address
* @param string $port Le port de connexion au serveur ftp * @param string $port The TCP port of the FTP server
* @param string $user Le nom d'utilidateur de connexion * @param string $user The username
* @param string $pwd Le mot de passe de connexion * @param string $pwd The password
* @param string $old Le dossier à renomer * @param string $old The actual directory path to rename
* @param string $new Le nouveau nom du dossier à renomer * @param string $new The new directory path
* *
* @return bool True ou false si il y a un problème durant le renomage du/des dossier(s) * @return boolean
*/ */
function renameDirByFTP($host,$port,$user,$pwd,$old,$new) { function renameDirByFTP($host, $port, $user, $pwd, $old, $new) {
$cnx = connectToFTP($host,$port,$user,$pwd); $cnx = connectToFTP($host, $port, $user, $pwd);
if (!$cnx) return false; if (!$cnx) return false;
$do = $cnx -> rename($old,$new); $do = $cnx -> rename($old, $new);
if ($do instanceof PEAR_Error) { if ($do instanceof PEAR_Error) {
LSerror :: addErrorCode('FTP_05',array('old' => $old,'new' => $new)); LSerror :: addErrorCode('FTP_05', array('old' => $old, 'new' => $new));
LSerror :: addErrorCode('FTP_00',$do -> getMessage()); LSerror :: addErrorCode('FTP_00', $do -> getMessage());
return false; return false;
} }
return true; return true;
} }

View file

@ -39,14 +39,14 @@ LSerror :: defineError('MAIL_01',
___("MAIL : Error sending your email") ___("MAIL : Error sending your email")
); );
/** /**
* Check support of this LSaddon * Check support of this LSaddon
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
* *
* @return boolean true if this LSaddon is fully supported, false otherwise * @return boolean true if this LSaddon is fully supported, false otherwise
*/ */
function LSaddon_mail_support() { function LSaddon_mail_support() {
$retval=true; $retval=true;
// Lib dependencies (check/load) // Lib dependencies (check/load)
@ -80,9 +80,9 @@ LSerror :: defineError('MAIL_01',
); );
return $retval; return $retval;
} }
/** /**
* Send an email * Send an email
* *
* @param string|array<string> $to Email recipient(s) * @param string|array<string> $to Email recipient(s)
@ -99,7 +99,7 @@ LSerror :: defineError('MAIL_01',
* *
* @return boolean true si MAIL est pleinement supporté, false sinon * @return boolean true si MAIL est pleinement supporté, false sinon
*/ */
function sendMail($to, $subject, $msg, $headers=null, $attachments=null, function sendMail($to, $subject, $msg, $headers=null, $attachments=null,
$eol=null, $encoding=null, $html=false) { $eol=null, $encoding=null, $html=false) {
global $MAIL_SEND_PARAMS, $MAIL_HEARDERS, $MAIL_CATCH_ALL; global $MAIL_SEND_PARAMS, $MAIL_HEARDERS, $MAIL_CATCH_ALL;
$mail_obj = Mail::factory(MAIL_SEND_METHOD, (isset($MAIL_SEND_PARAMS)?$MAIL_SEND_PARAMS:null)); $mail_obj = Mail::factory(MAIL_SEND_METHOD, (isset($MAIL_SEND_PARAMS)?$MAIL_SEND_PARAMS:null));
@ -203,7 +203,7 @@ LSerror :: defineError('MAIL_01',
return false; return false;
} }
return true; return true;
} }
if (php_sapi_name() != 'cli') if (php_sapi_name() != 'cli')

View file

@ -44,25 +44,25 @@ LSerror :: defineError('MAILDIR_04',
___("MAILDIR : Error retrieving remote path of the maildir.") ___("MAILDIR : Error retrieving remote path of the maildir.")
); );
/** /**
* Verification du support Maildir par ldapSaisie * Verification du support Maildir par ldapSaisie
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
* *
* @return boolean true si Maildir est pleinement supporté, false sinon * @return boolean true si Maildir est pleinement supporté, false sinon
*/ */
function LSaddon_maildir_support() { function LSaddon_maildir_support() {
$retval=true; $retval = true;
// Dependance de librairie // Dependance de librairie
if (!function_exists('createDirsByFTP')) { if (!function_exists('createDirsByFTP')) {
if(!LSsession :: loadLSaddon('ftp')) { if(!LSsession :: loadLSaddon('ftp')) {
LSerror :: addErrorCode('MAILDIR_SUPPORT_01'); LSerror :: addErrorCode('MAILDIR_SUPPORT_01');
$retval=false; $retval = false;
} }
} }
$MUST_DEFINE_CONST= array( $MUST_DEFINE_CONST = array(
'LS_MAILDIR_FTP_HOST', 'LS_MAILDIR_FTP_HOST',
'LS_MAILDIR_FTP_USER', 'LS_MAILDIR_FTP_USER',
'LS_MAILDIR_FTP_MAILDIR_PATH', 'LS_MAILDIR_FTP_MAILDIR_PATH',
@ -71,14 +71,14 @@ LSerror :: defineError('MAILDIR_04',
foreach($MUST_DEFINE_CONST as $const) { foreach($MUST_DEFINE_CONST as $const) {
if ( (!defined($const)) || (constant($const) == "")) { if ( (!defined($const)) || (constant($const) == "")) {
LSerror :: addErrorCode('MAILDIR_SUPPORT_02',$const); LSerror :: addErrorCode('MAILDIR_SUPPORT_02', $const);
$retval=false; $retval = false;
} }
} }
return $retval; return $retval;
} }
/** /**
* Creation d'une Maildir via FTP * Creation d'une Maildir via FTP
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
@ -89,26 +89,31 @@ LSerror :: defineError('MAILDIR_04',
* *
* @return bool True ou false si il y a un problème durant la création de la Maildir * @return bool True ou false si il y a un problème durant la création de la Maildir
*/ */
function createMaildirByFTP($ldapObject,$dir=null) { function createMaildirByFTP($ldapObject,$dir=null) {
if (!$dir) { if (!$dir) {
$dir = getMaildirPath($ldapObject); $dir = getMaildirPath($ldapObject);
if (!$dir) { if (!$dir)
return false; return false;
} }
}
$dirs = array( $dirs = array(
$dir.'/cur', $dir.'/cur',
$dir.'/new', $dir.'/new',
$dir.'/tmp' $dir.'/tmp'
); );
if (!createDirsByFTP(LS_MAILDIR_FTP_HOST,LS_MAILDIR_FTP_PORT,LS_MAILDIR_FTP_USER,LS_MAILDIR_FTP_PWD,$dirs,LS_MAILDIR_FTP_MAILDIR_CHMOD)) { if (
!createDirsByFTP(
LS_MAILDIR_FTP_HOST, LS_MAILDIR_FTP_PORT,
LS_MAILDIR_FTP_USER, LS_MAILDIR_FTP_PWD,
$dirs, LS_MAILDIR_FTP_MAILDIR_CHMOD
)
) {
LSerror :: addErrorCode('MAILDIR_01'); LSerror :: addErrorCode('MAILDIR_01');
return false; return false;
} }
return true; return true;
} }
/** /**
* Suppression d'une Maildir via FTP * Suppression d'une Maildir via FTP
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
@ -119,21 +124,26 @@ LSerror :: defineError('MAILDIR_04',
* *
* @return bool True ou false si il y a un problème durant la suppression de la Maildir * @return bool True ou false si il y a un problème durant la suppression de la Maildir
*/ */
function removeMaildirByFTP($ldapObject,$dir=null) { function removeMaildirByFTP($ldapObject,$dir=null) {
if (!$dir) { if (!$dir) {
$dir = getMaildirPath($ldapObject); $dir = getMaildirPath($ldapObject);
if (!$dir) { if (!$dir)
return false; return false;
} }
} if (
if (!removeDirsByFTP(LS_MAILDIR_FTP_HOST,LS_MAILDIR_FTP_PORT,LS_MAILDIR_FTP_USER,LS_MAILDIR_FTP_PWD,$dir)) { !removeDirsByFTP(
LS_MAILDIR_FTP_HOST, LS_MAILDIR_FTP_PORT,
LS_MAILDIR_FTP_USER, LS_MAILDIR_FTP_PWD,
$dir
)
) {
LSerror :: addErrorCode('MAILDIR_02'); LSerror :: addErrorCode('MAILDIR_02');
return false; return false;
} }
return true; return true;
} }
/** /**
* Retourne le chemin distant de la maildir * Retourne le chemin distant de la maildir
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
@ -142,27 +152,25 @@ LSerror :: defineError('MAILDIR_04',
* *
* @return string|false Le chemin distant de la maildir ou false si il y a un problème * @return string|false Le chemin distant de la maildir ou false si il y a un problème
*/ */
function getMaildirPath($ldapObject) { function getMaildirPath($ldapObject) {
$dir = getFData(LS_MAILDIR_FTP_MAILDIR_PATH,$ldapObject,'getValue'); $dir = getFData(LS_MAILDIR_FTP_MAILDIR_PATH, $ldapObject, 'getValue');
if (LS_MAILDIR_FTP_MAILDIR_PATH_REGEX != "") { if (constant("LS_MAILDIR_FTP_MAILDIR_PATH_REGEX")) {
if (preg_match(LS_MAILDIR_FTP_MAILDIR_PATH_REGEX,$dir,$regs)) { $dir = (
$dir = $regs[1]; preg_match(LS_MAILDIR_FTP_MAILDIR_PATH_REGEX, $dir, $regs)?
} $regs[1]:false
else { );
$dir = "";
}
} }
if ($dir=="") { if (!$dir) {
LSerror :: addErrorCode('MAILDIR_04'); LSerror :: addErrorCode('MAILDIR_04');
return false; return false;
} }
return $dir; return $dir;
} }
/** /**
* Rename Maildir via FTP * Rename Maildir via FTP
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
@ -172,10 +180,16 @@ LSerror :: defineError('MAILDIR_04',
* *
* @return bool True ou false si il y a un problème durant le renomage de la Maildir * @return bool True ou false si il y a un problème durant le renomage de la Maildir
*/ */
function renameMaildirByFTP($old,$new) { function renameMaildirByFTP($old, $new) {
if (!renameDirByFTP(LS_MAILDIR_FTP_HOST,LS_MAILDIR_FTP_PORT,LS_MAILDIR_FTP_USER,LS_MAILDIR_FTP_PWD,$old,$new)) { if (
!renameDirByFTP(
LS_MAILDIR_FTP_HOST, LS_MAILDIR_FTP_PORT,
LS_MAILDIR_FTP_USER, LS_MAILDIR_FTP_PWD,
$old, $new
)
) {
LSerror :: addErrorCode('MAILDIR_03'); LSerror :: addErrorCode('MAILDIR_03');
return false; return false;
} }
return true; return true;
} }

View file

@ -36,26 +36,25 @@ LSerror :: defineError('POSIX_01',
___("POSIX : The attribute %{dependency} is missing. Unable to forge the attribute %{attr}.") ___("POSIX : The attribute %{dependency} is missing. Unable to forge the attribute %{attr}.")
); );
/** /**
* Verification du support POSIX par ldapSaisie * Verification du support POSIX par ldapSaisie
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
* *
* @return boolean true si POSIX est pleinement supporté, false sinon * @return boolean true si POSIX est pleinement supporté, false sinon
*/ */
function LSaddon_posix_support() { function LSaddon_posix_support() {
$retval = true;
$retval=true;
// Dependance de librairie // Dependance de librairie
if (!function_exists('createDirsByFTP')) { if (!function_exists('createDirsByFTP')) {
if(!LSsession :: loadLSaddon('ftp')) { if(!LSsession :: loadLSaddon('ftp')) {
LSerror :: addErrorCode('POSIX_SUPPORT_02'); LSerror :: addErrorCode('POSIX_SUPPORT_02');
$retval=false; $retval = false;
} }
} }
$MUST_DEFINE_CONST= array( $MUST_DEFINE_CONST = array(
'LS_POSIX_UID_ATTR', 'LS_POSIX_UID_ATTR',
'LS_POSIX_UIDNUMBER_ATTR', 'LS_POSIX_UIDNUMBER_ATTR',
'LS_POSIX_GIDNUMBER_ATTR', 'LS_POSIX_GIDNUMBER_ATTR',
@ -72,15 +71,15 @@ LSerror :: defineError('POSIX_01',
foreach($MUST_DEFINE_CONST as $const) { foreach($MUST_DEFINE_CONST as $const) {
if ( (!defined($const)) || (constant($const) == "")) { if ( (!defined($const)) || (constant($const) == "")) {
LSerror :: addErrorCode('POSIX_SUPPORT_O1',$const); LSerror :: addErrorCode('POSIX_SUPPORT_O1', $const);
$retval=false; $retval = false;
} }
} }
return $retval; return $retval;
} }
/** /**
* Generation de uidNumber * Generation de uidNumber
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
@ -89,8 +88,7 @@ LSerror :: defineError('POSIX_01',
* *
* @return integer|false uidNumber ou false si il y a un problème durant la génération * @return integer|false uidNumber ou false si il y a un problème durant la génération
*/ */
function generate_uidNumber($ldapObject) { function generate_uidNumber($ldapObject) {
$objects = LSldap :: search ( $objects = LSldap :: search (
LS_POSIX_UIDNUMBER_ATTR.'=*', LS_POSIX_UIDNUMBER_ATTR.'=*',
NULL, NULL,
@ -112,10 +110,9 @@ LSerror :: defineError('POSIX_01',
$uidNumber++; $uidNumber++;
return $uidNumber; return $uidNumber;
}
} /**
/**
* Generation de gidNumber * Generation de gidNumber
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
@ -124,10 +121,9 @@ LSerror :: defineError('POSIX_01',
* *
* @return integer|false gidNumber ou false si il y a un problème durant la génération * @return integer|false gidNumber ou false si il y a un problème durant la génération
*/ */
function generate_gidNumber($ldapObject) { function generate_gidNumber($ldapObject) {
$objects = LSldap :: search ( $objects = LSldap :: search (
LS_POSIX_GIDNUMBER_ATTR.'=*', LS_POSIX_GIDNUMBER_ATTR . '=*',
NULL, NULL,
array( array(
'attributes' => array( 'attributes' => array(
@ -147,10 +143,9 @@ LSerror :: defineError('POSIX_01',
$gidNumber++; $gidNumber++;
return $gidNumber; return $gidNumber;
}
} /**
/**
* Generation de homeDirectory * Generation de homeDirectory
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
@ -159,19 +154,18 @@ LSerror :: defineError('POSIX_01',
* *
* @return string|false homeDirectory ou false si il y a un problème durant la génération * @return string|false homeDirectory ou false si il y a un problème durant la génération
*/ */
function generate_homeDirectory($ldapObject) { function generate_homeDirectory($ldapObject) {
if ( get_class($ldapObject -> attrs[ LS_POSIX_UID_ATTR ]) != 'LSattribute' ) { if ( get_class($ldapObject -> attrs[ LS_POSIX_UID_ATTR ]) != 'LSattribute' ) {
LSerror :: addErrorCode('POSIX_01',array('dependency' => 'uid', 'attr' => 'homeDirectory')); LSerror :: addErrorCode('POSIX_01', array('dependency' => 'uid', 'attr' => 'homeDirectory'));
return false; return false;
} }
$uid = $ldapObject -> attrs[ LS_POSIX_UID_ATTR ] -> getValue(); $uid = $ldapObject -> attrs[ LS_POSIX_UID_ATTR ] -> getValue();
$home = LS_POSIX_HOMEDIRECTORY . $uid[0]; $home = LS_POSIX_HOMEDIRECTORY . $uid[0];
return $home; return $home;
}
} /**
/**
* Create home directory by FTP * Create home directory by FTP
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
@ -180,16 +174,22 @@ LSerror :: defineError('POSIX_01',
* *
* @return bool True on success, false otherwise * @return bool True on success, false otherwise
*/ */
function createHomeDirectoryByFTP($ldapObject) { function createHomeDirectoryByFTP($ldapObject) {
$dir = getFData(LS_POSIX_HOMEDIRECTORY_FTP_PATH,$ldapObject,'getValue'); $dir = getFData(LS_POSIX_HOMEDIRECTORY_FTP_PATH, $ldapObject, 'getValue');
if (!createDirsByFTP(LS_POSIX_HOMEDIRECTORY_FTP_HOST,LS_POSIX_HOMEDIRECTORY_FTP_PORT,LS_POSIX_HOMEDIRECTORY_FTP_USER,LS_POSIX_HOMEDIRECTORY_FTP_PWD,$dir)) { if (
!createDirsByFTP(
LS_POSIX_HOMEDIRECTORY_FTP_HOST, LS_POSIX_HOMEDIRECTORY_FTP_PORT,
LS_POSIX_HOMEDIRECTORY_FTP_USER, LS_POSIX_HOMEDIRECTORY_FTP_PWD,
$dir
)
) {
LSerror :: addErrorCode('POSIX_02'); LSerror :: addErrorCode('POSIX_02');
return false; return false;
} }
return true; return true;
} }
/** /**
* Generate member attribute value from memberUid * Generate member attribute value from memberUid
* *
* IMPORTANT : The attribute memberUid must be define in configuration * IMPORTANT : The attribute memberUid must be define in configuration
@ -201,18 +201,20 @@ LSerror :: defineError('POSIX_01',
* *
* @return array|false array of member attribute values or false in case of error * @return array|false array of member attribute values or false in case of error
*/ */
function generateMemberFromMemberUid($ldapObject) { function generateMemberFromMemberUid($ldapObject) {
if ( get_class($ldapObject -> attrs[ 'memberUid' ]) != 'LSattribute' ) { if ( get_class($ldapObject -> attrs[ 'memberUid' ]) != 'LSattribute' ) {
LSerror :: addErrorCode('POSIX_01',array('dependency' => 'memberUid', 'attr' => 'member')); LSerror :: addErrorCode('POSIX_01', array('dependency' => 'memberUid', 'attr' => 'member'));
return false; return false;
} }
if ( get_class($ldapObject -> attrs[ 'member' ]) != 'LSattribute' ) { if ( get_class($ldapObject -> attrs[ 'member' ]) != 'LSattribute' ) {
LSerror :: addErrorCode('POSIX_01',array('dependency' => 'member', 'attr' => 'member')); LSerror :: addErrorCode('POSIX_01', array('dependency' => 'member', 'attr' => 'member'));
return false; return false;
} }
$obj_type=LSconfig::get('LSobjects.'.get_class($ldapObject).'.attrs.memberUid.html_options.selectable_object.object_type'); $obj_type = LSconfig::get(
'LSobjects.'.get_class($ldapObject).'.attrs.memberUid.html_options.selectable_object.object_type'
);
if (empty($obj_type)) if (empty($obj_type))
return false; return false;
@ -220,14 +222,18 @@ LSerror :: defineError('POSIX_01',
$member = array(); $member = array();
if (is_array($uids)) { if (is_array($uids)) {
foreach ( $uids as $uid ) { foreach ( $uids as $uid ) {
$member[]='uid='.$uid.','.LSconfig::get('LSobjects.'.$obj_type.'.container_dn').','.LSsession::getTopDn(); $member[] = sprintf(
'uid=%s,%s,%s',
$uid,
LSconfig::get('LSobjects.'.$obj_type.'.container_dn'),
LSsession::getTopDn()
);
} }
} }
return $member; return $member;
}
} /**
/**
* Generate memberUid attribute value from uniqueMember * Generate memberUid attribute value from uniqueMember
* *
* IMPORTANT : The attribute uniqueMember must be define in configuration * IMPORTANT : The attribute uniqueMember must be define in configuration
@ -239,14 +245,14 @@ LSerror :: defineError('POSIX_01',
* *
* @return array|false array of memberUid values or false in case of error * @return array|false array of memberUid values or false in case of error
*/ */
function generate_memberUidFromUniqueMember($ldapObject) { function generate_memberUidFromUniqueMember($ldapObject) {
if ( get_class($ldapObject -> attrs[ 'memberUid' ]) != 'LSattribute' ) { if (get_class($ldapObject -> attrs[ 'memberUid' ]) != 'LSattribute') {
LSerror :: addErrorCode('POSIX_01',array('dependency' => 'memberUid', 'attr' => 'memberUid')); LSerror :: addErrorCode('POSIX_01', array('dependency' => 'memberUid', 'attr' => 'memberUid'));
return false; return false;
} }
if ( get_class($ldapObject -> attrs[ 'uniqueMember' ]) != 'LSattribute' ) { if (get_class($ldapObject -> attrs[ 'uniqueMember' ]) != 'LSattribute') {
LSerror :: addErrorCode('POSIX_01',array('dependency' => 'uniqueMember', 'attr' => 'memberUid')); LSerror :: addErrorCode('POSIX_01', array('dependency' => 'uniqueMember', 'attr' => 'memberUid'));
return false; return false;
} }
@ -254,14 +260,13 @@ LSerror :: defineError('POSIX_01',
$uids = array(); $uids = array();
if (is_array($dns)) { if (is_array($dns)) {
foreach($dns as $dn) { foreach($dns as $dn) {
if(preg_match(LS_POSIX_DN_TO_UID_PATTERN,$dn,$matches)) { if(preg_match(LS_POSIX_DN_TO_UID_PATTERN, $dn, $matches)) {
$uids[]=$matches[1]; $uids[] = $matches[1];
} }
} }
} }
return $uids; return $uids;
} }
/** /**
* Generate shadowLastChange attribute value * Generate shadowLastChange attribute value

View file

@ -229,8 +229,7 @@ function generate_sambaPrimaryGroupSID($ldapObject) {
return generate_sambaSID($ldapObject, LS_SAMBA_GIDNUMBER_ATTR, LS_SAMBA_SID_BASE_GROUP); return generate_sambaSID($ldapObject, LS_SAMBA_GIDNUMBER_ATTR, LS_SAMBA_SID_BASE_GROUP);
} }
/**
/**
* Generation de sambaNTPassword * Generation de sambaNTPassword
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
@ -239,7 +238,7 @@ function generate_sambaPrimaryGroupSID($ldapObject) {
* *
* @return string|false sambaNTPassword value on success, false otherwise * @return string|false sambaNTPassword value on success, false otherwise
*/ */
function generate_sambaNTPassword($ldapObject) { function generate_sambaNTPassword($ldapObject) {
if ( get_class($ldapObject -> attrs[ LS_SAMBA_USERPASSWORD_ATTR ]) != 'LSattribute' ) { if ( get_class($ldapObject -> attrs[ LS_SAMBA_USERPASSWORD_ATTR ]) != 'LSattribute' ) {
LSerror :: addErrorCode('SAMBA_01',array('dependency' => LS_SAMBA_USERPASSWORD_ATTR, 'attr' => 'sambaNTPassword')); LSerror :: addErrorCode('SAMBA_01',array('dependency' => LS_SAMBA_USERPASSWORD_ATTR, 'attr' => 'sambaNTPassword'));
return false; return false;
@ -258,13 +257,10 @@ function generate_sambaPrimaryGroupSID($ldapObject) {
$sambapassword = new smbHash; $sambapassword = new smbHash;
$sambaNTPassword = $sambapassword -> nthash($password); $sambaNTPassword = $sambapassword -> nthash($password);
if($sambaNTPassword == '') { return $sambaNTPassword?$sambaNTPassword:false;
return false; }
}
return $sambaNTPassword;
}
/** /**
* Generation de sambaLMPassword * Generation de sambaLMPassword
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
@ -273,7 +269,7 @@ function generate_sambaPrimaryGroupSID($ldapObject) {
* *
* @return string|false sambaLMPassword value on success, false otherwise * @return string|false sambaLMPassword value on success, false otherwise
*/ */
function generate_sambaLMPassword($ldapObject) { function generate_sambaLMPassword($ldapObject) {
if ( get_class($ldapObject -> attrs[ LS_SAMBA_USERPASSWORD_ATTR ]) != 'LSattribute' ) { if ( get_class($ldapObject -> attrs[ LS_SAMBA_USERPASSWORD_ATTR ]) != 'LSattribute' ) {
LSerror :: addErrorCode( LSerror :: addErrorCode(
'SAMBA_01', 'SAMBA_01',
@ -296,11 +292,8 @@ function generate_sambaPrimaryGroupSID($ldapObject) {
$sambapassword = new smbHash; $sambapassword = new smbHash;
$sambaLMPassword = $sambapassword -> lmhash($password); $sambaLMPassword = $sambapassword -> lmhash($password);
if($sambaLMPassword == '') { return $sambaLMPassword?$sambaLMPassword:false;
return false; }
}
return $sambaLMPassword;
}
/** /**
* Generate UNIX ID value from sambaUnixIdPool object * Generate UNIX ID value from sambaUnixIdPool object

View file

@ -59,14 +59,14 @@ LSerror :: defineError('SSH_07',
___("SSH : Unable to rename folder from %{old} to %{new} on the remote server.") ___("SSH : Unable to rename folder from %{old} to %{new} on the remote server.")
); );
/** /**
* Check LdapSaisie SSH support * Check LdapSaisie SSH support
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
* *
* @return boolean true if SSH is fully supported, false otherwise * @return boolean true if SSH is fully supported, false otherwise
*/ */
function LSaddon_ssh_support() { function LSaddon_ssh_support() {
$retval=true; $retval=true;
// Check PhpSecLib library // Check PhpSecLib library
@ -79,11 +79,9 @@ LSerror :: defineError('SSH_07',
} }
return $retval; return $retval;
} }
/**
/**
* Connect to an SFTP server * Connect to an SFTP server
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
@ -113,7 +111,7 @@ LSerror :: defineError('SSH_07',
* *
* @return SSH2|SFTP|false SSH2/SFTP object or false * @return SSH2|SFTP|false SSH2/SFTP object or false
*/ */
function connectToSSH($params, $sftp=false) { function connectToSSH($params, $sftp=false) {
$logger = LSlog :: get_logger('LSaddon_ssh'); $logger = LSlog :: get_logger('LSaddon_ssh');
if (!isset($params['host'])) { if (!isset($params['host'])) {
LSerror :: addErrorCode('SSH_01',"host"); LSerror :: addErrorCode('SSH_01',"host");
@ -175,9 +173,9 @@ LSerror :: defineError('SSH_07',
$logger -> debug("Connected."); $logger -> debug("Connected.");
return $cnx; return $cnx;
} }
/** /**
* Create one or more directories throught SFTP * Create one or more directories throught SFTP
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
@ -191,7 +189,7 @@ LSerror :: defineError('SSH_07',
* *
* @return boolean * @return boolean
*/ */
function createDirsBySFTP($connection_params, $dirs, $chmod=-1, $recursive=false, $continue=false) { function createDirsBySFTP($connection_params, $dirs, $chmod=-1, $recursive=false, $continue=false) {
$cnx = connectToSSH($connection_params, true); $cnx = connectToSSH($connection_params, true);
if (!$cnx instanceof SFTP) return false; if (!$cnx instanceof SFTP) return false;
if (!is_array($dirs)) { if (!is_array($dirs)) {
@ -207,9 +205,9 @@ LSerror :: defineError('SSH_07',
} }
} }
return $retval; return $retval;
} }
/** /**
* Delete one or more directories throught SFTP * Delete one or more directories throught SFTP
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
@ -221,7 +219,7 @@ LSerror :: defineError('SSH_07',
* *
* @return boolean * @return boolean
*/ */
function removeDirsBySFTP($connection_params, $dirs, $recursive=false, $continue=false) { function removeDirsBySFTP($connection_params, $dirs, $recursive=false, $continue=false) {
$cnx = connectToSSH($connection_params, true); $cnx = connectToSSH($connection_params, true);
if (!$cnx instanceof SFTP) return false; if (!$cnx instanceof SFTP) return false;
if (!is_array($dirs)) { if (!is_array($dirs)) {
@ -237,9 +235,9 @@ LSerror :: defineError('SSH_07',
} }
} }
return $retval; return $retval;
} }
/** /**
* Rename a directory throught SFTP * Rename a directory throught SFTP
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
@ -250,7 +248,7 @@ LSerror :: defineError('SSH_07',
* *
* @return boolean * @return boolean
*/ */
function renameDirBySFTP($connection_params, $old, $new) { function renameDirBySFTP($connection_params, $old, $new) {
$cnx = connectToSSH($connection_params, true); $cnx = connectToSSH($connection_params, true);
if (!$cnx instanceof SFTP) return false; if (!$cnx instanceof SFTP) return false;
LSlog :: get_logger('LSaddon_ssh') -> debug("rename($old, $new)"); LSlog :: get_logger('LSaddon_ssh') -> debug("rename($old, $new)");
@ -259,9 +257,9 @@ LSerror :: defineError('SSH_07',
return false; return false;
} }
return true; return true;
} }
/** /**
* Exec a command throught SSH * Exec a command throught SSH
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
@ -273,11 +271,11 @@ LSerror :: defineError('SSH_07',
* exit code as first value and the command outup as second * exit code as first value and the command outup as second
* one (stdout + stderr). * one (stdout + stderr).
*/ */
function execBySSH($connection_params, $cmd) { function execBySSH($connection_params, $cmd) {
$cnx = connectToSSH($connection_params); $cnx = connectToSSH($connection_params);
if (!$cnx instanceof SSH2) return false; if (!$cnx instanceof SSH2) return false;
LSlog :: get_logger('LSaddon_ssh') -> debug("exec($cmd)"); LSlog :: get_logger('LSaddon_ssh') -> debug("exec($cmd)");
$result = $cnx -> exec($cmd); $result = $cnx -> exec($cmd);
$exit_status = $cnx->getExitStatus(); $exit_status = $cnx->getExitStatus();
return array($exit_status, $result); return array($exit_status, $result);
} }