From 72998cd8fe186325c1440ae44236d4e738e04fff Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 3 Jan 2022 12:26:57 +0100 Subject: [PATCH] Debug v15 --- dev/tools/fixdosfiles.sh | 6 +-- dev/tools/optimize_images.sh | 7 ++-- .../generate/modGeneratePassNone.class.php | 16 +++++++- .../generate/modGeneratePassPerso.class.php | 19 +++++++-- .../modGeneratePassStandard.class.php | 16 +++++++- .../security/generate/modules_genpassword.php | 3 +- htdocs/salaries/card.php | 4 +- htdocs/salaries/class/salariesstats.class.php | 22 +++++----- htdocs/salaries/document.php | 2 +- htdocs/salaries/info.php | 2 +- htdocs/user/card.php | 2 +- htdocs/user/class/user.class.php | 41 ++++++++++++++++++- 12 files changed, 107 insertions(+), 33 deletions(-) mode change 100755 => 100644 htdocs/salaries/card.php diff --git a/dev/tools/fixdosfiles.sh b/dev/tools/fixdosfiles.sh index 6fd152127fb..4be867aea98 100755 --- a/dev/tools/fixdosfiles.sh +++ b/dev/tools/fixdosfiles.sh @@ -17,14 +17,14 @@ fi # To detec if [ "x$1" = "xlist" ] then - find . \( -iname "functions" -o -iname "*.md" -o -iname "*.html" -o -iname "*.htm" -o -iname "*.php" -o -iname "*.sh" -o -iname "*.cml" -o -iname "*.css" -o -iname "*.js" -o -iname "*.lang" -o -iname "*.pl" -o -iname "*.sql" -o -iname "*.txt" -o -iname "*.xml" -o -iname "*.pml" \) -exec file "{}" + | grep -v 'documents\/website' | grep -v 'documents\/mdedias' | grep CRLF -# find . \( -iname "*.md" -o -iname "*.html" -o -iname "*.htm" -o -iname "*.php" -o -iname "*.sh" -o -iname "*.cml" -o -iname "*.css" -o -iname "*.js" -o -iname "*.lang" -o -iname "*.pl" -o -iname "*.sql" -o -iname "*.txt" -o -iname "*.xml" \) -exec file "{}" + | grep -v 'documents\/website' | grep -v 'documents\/mdedias' | grep -v 'htdocs\/includes' | grep CRLF + find . \( -iname "functions" -o -iname "*.md" -o -iname "*.html" -o -iname "*.htm" -o -iname "*.php" -o -iname "*.sh" -o -iname "*.cml" -o -iname "*.css" -o -iname "*.js" -o -iname "*.lang" -o -iname "*.pl" -o -iname "*.sql" -o -iname "*.txt" -o -iname "*.xml" -o -iname "*.pml" \) -exec file "{}" + | grep -v 'custom\/' | grep -v 'documents\/website' | grep -v 'documents\/medias' | grep -v 'documents\/sellyoursaas' | grep CRLF +# find . \( -iname "*.md" -o -iname "*.html" -o -iname "*.htm" -o -iname "*.php" -o -iname "*.sh" -o -iname "*.cml" -o -iname "*.css" -o -iname "*.js" -o -iname "*.lang" -o -iname "*.pl" -o -iname "*.sql" -o -iname "*.txt" -o -iname "*.xml" \) -exec file "{}" + | grep -v 'custom\/' | grep -v 'documents\/website' | grep -v 'documents\/medias' | grep -v 'documents\/sellyoursaas' | grep -v 'htdocs\/includes' | grep CRLF fi # To convert if [ "x$1" = "xfix" ] then - for fic in `find . \( -iname "functions" -o -iname "*.md" -o -iname "*.html" -o -iname "*.htm" -o -iname "*.php" -o -iname "*.sh" -o -iname "*.cml" -o -iname "*.css" -o -iname "*.js" -o -iname "*.lang" -o -iname "*.pl" -o -iname "*.sql" -o -iname "*.txt" -o -iname "*.xml" -o -iname "*.pml" \) -exec file "{}" + | grep -v 'documents\/website' | grep -v 'documents\/mdedias' | grep CRLF | awk -F':' '{ print $1 }' ` + for fic in `find . \( -iname "functions" -o -iname "*.md" -o -iname "*.html" -o -iname "*.htm" -o -iname "*.php" -o -iname "*.sh" -o -iname "*.cml" -o -iname "*.css" -o -iname "*.js" -o -iname "*.lang" -o -iname "*.pl" -o -iname "*.sql" -o -iname "*.txt" -o -iname "*.xml" -o -iname "*.pml" \) -exec file "{}" + | grep -v 'custom\/' | grep -v 'documents\/website' | grep -v 'documents\/medias' | grep -v 'documents\/sellyoursaas' | grep CRLF | awk -F':' '{ print $1 }' ` do echo "Fix file $fic" dos2unix "$fic" diff --git a/dev/tools/optimize_images.sh b/dev/tools/optimize_images.sh index 2f8a84c57e7..dd538c5e1aa 100755 --- a/dev/tools/optimize_images.sh +++ b/dev/tools/optimize_images.sh @@ -14,7 +14,8 @@ max_output_size=0 usage() { cat <id = "none"; $this->length = 0; + $this->length2 = 0; $this->db = $db; $this->conf = $conf; diff --git a/htdocs/core/modules/security/generate/modGeneratePassPerso.class.php b/htdocs/core/modules/security/generate/modGeneratePassPerso.class.php index d49d8b69c46..0ecf814cb35 100644 --- a/htdocs/core/modules/security/generate/modGeneratePassPerso.class.php +++ b/htdocs/core/modules/security/generate/modGeneratePassPerso.class.php @@ -28,8 +28,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/modules/security/generate/modules_genpassw /** - * \class modGeneratePassPerso - * \brief Class to generate a password according to personal rules + * Class to generate a password according to personal rules */ class modGeneratePassPerso extends ModeleGenPassword { @@ -38,8 +37,20 @@ class modGeneratePassPerso extends ModeleGenPassword */ public $id; + /** + * Minimum length (text visible by end user) + * + * @var string + */ public $length; - public $length2; // didn't overright display + + /** + * Minimum length in number of characters + * + * @var integer + */ + public $length2; + public $NbMaj; public $NbNum; public $NbSpe; @@ -81,7 +92,7 @@ class modGeneratePassPerso extends ModeleGenPassword $this->user = $user; if (empty($conf->global->USER_PASSWORD_PATTERN)) { - // default value (10carac, 1maj, 1digit, 1spe, 3 repeat, no ambi at auto generation. + // default value at auto generation (12 chars, 1 upercase, 1 digit, 1 special char, 3 repeat, no ambi). dolibarr_set_const($db, "USER_PASSWORD_PATTERN", '12;1;1;1;3;1', 'chaine', 0, '', $conf->entity); } diff --git a/htdocs/core/modules/security/generate/modGeneratePassStandard.class.php b/htdocs/core/modules/security/generate/modGeneratePassStandard.class.php index a358f916429..1861cc9bb90 100644 --- a/htdocs/core/modules/security/generate/modGeneratePassStandard.class.php +++ b/htdocs/core/modules/security/generate/modGeneratePassStandard.class.php @@ -26,8 +26,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/modules/security/generate/modules_genpassw /** - * \class modGeneratePassStandard - * \brief Class to generate a password according to a dolibarr standard rule (8 random chars) + * Class to generate a password according to a dolibarr standard rule (12 random chars) */ class modGeneratePassStandard extends ModeleGenPassword { @@ -36,8 +35,20 @@ class modGeneratePassStandard extends ModeleGenPassword */ public $id; + /** + * Minimum length (text visible by end user) + * + * @var string + */ public $length; + /** + * Minimum length in number of characters + * + * @var integer + */ + public $length2; + /** * @var DoliDB Database handler. */ @@ -60,6 +71,7 @@ class modGeneratePassStandard extends ModeleGenPassword { $this->id = "standard"; $this->length = 12; + $this->length2 = 12; $this->db = $db; $this->conf = $conf; diff --git a/htdocs/core/modules/security/generate/modules_genpassword.php b/htdocs/core/modules/security/generate/modules_genpassword.php index 37bb37ad092..40bebc0fb2d 100644 --- a/htdocs/core/modules/security/generate/modules_genpassword.php +++ b/htdocs/core/modules/security/generate/modules_genpassword.php @@ -25,8 +25,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php'; /** - * \class ModeleGenPassword - * \brief Parent class for password rules/management modules + * Parent class for password rules/management modules */ abstract class ModeleGenPassword { diff --git a/htdocs/salaries/card.php b/htdocs/salaries/card.php old mode 100755 new mode 100644 index 4cf5caf97ce..89676e50140 --- a/htdocs/salaries/card.php +++ b/htdocs/salaries/card.php @@ -746,7 +746,7 @@ if ($id) { $userstatic = new User($db); $result = $userstatic->fetch($object->fk_user); if ($result > 0) { - $morehtmlref .= '
' .$langs->trans('Employee').' : '.$userstatic->getNomUrl(1); + $morehtmlref .= '
' .$langs->trans('Employee').' : '.$userstatic->getNomUrl(-1); } } else { $morehtmlref .= '
' . $form->editfieldkey("Employee", 'fk_user', $object->label, $object, $user->rights->salaries->write, 'string', '', 0, 1); @@ -755,7 +755,7 @@ if ($id) { $userstatic = new User($db); $result = $userstatic->fetch($object->fk_user); if ($result > 0) { - $morehtmlref .= $userstatic->getNomUrl(1); + $morehtmlref .= $userstatic->getNomUrl(-1); } else { dol_print_error($db); exit(); diff --git a/htdocs/salaries/class/salariesstats.class.php b/htdocs/salaries/class/salariesstats.class.php index b3e6c20a0ca..a1109e071e5 100644 --- a/htdocs/salaries/class/salariesstats.class.php +++ b/htdocs/salaries/class/salariesstats.class.php @@ -20,10 +20,10 @@ /** * \file htdocs/salaries/class/salariesstats.class.php * \ingroup salaries - * \brief Fichier de la classe de gestion des stats des salaires + * \brief File of class for statistics on salaries */ include_once DOL_DOCUMENT_ROOT.'/core/class/stats.class.php'; -include_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php'; +include_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; /** * Classe permettant la gestion des stats des salaires @@ -58,7 +58,7 @@ class SalariesStats extends Stats $this->socid = $socid; $this->userid = $userid; - $object = new PaymentSalary($this->db); + $object = new Salary($this->db); $this->from = MAIN_DB_PREFIX.$object->table_element; $this->field = 'amount'; @@ -81,7 +81,7 @@ class SalariesStats extends Stats */ public function getNbByYear() { - $sql = "SELECT YEAR(datep) as dm, count(*)"; + $sql = "SELECT YEAR(dateep) as dm, count(*)"; $sql .= " FROM ".$this->from; $sql .= " WHERE ".$this->where; $sql .= " GROUP BY dm DESC"; @@ -99,9 +99,9 @@ class SalariesStats extends Stats */ public function getNbByMonth($year, $format = 0) { - $sql = "SELECT MONTH(datep) as dm, count(*)"; + $sql = "SELECT MONTH(dateep) as dm, count(*)"; $sql .= " FROM ".$this->from; - $sql .= " WHERE YEAR(datep) = ".((int) $year); + $sql .= " WHERE YEAR(dateep) = ".((int) $year); $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; $sql .= $this->db->order('dm', 'DESC'); @@ -121,9 +121,9 @@ class SalariesStats extends Stats */ public function getAmountByMonth($year, $format = 0) { - $sql = "SELECT date_format(datep,'%m') as dm, sum(".$this->field.")"; + $sql = "SELECT date_format(dateep,'%m') as dm, sum(".$this->field.")"; $sql .= " FROM ".$this->from; - $sql .= " WHERE date_format(datep,'%Y') = '".$this->db->escape($year)."'"; + $sql .= " WHERE date_format(dateep,'%Y') = '".$this->db->escape($year)."'"; $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; $sql .= $this->db->order('dm', 'DESC'); @@ -141,9 +141,9 @@ class SalariesStats extends Stats */ public function getAverageByMonth($year) { - $sql = "SELECT date_format(datep,'%m') as dm, avg(".$this->field.")"; + $sql = "SELECT date_format(dateep,'%m') as dm, avg(".$this->field.")"; $sql .= " FROM ".$this->from; - $sql .= " WHERE date_format(datep,'%Y') = '".$this->db->escape($year)."'"; + $sql .= " WHERE date_format(dateep,'%Y') = '".$this->db->escape($year)."'"; $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; $sql .= $this->db->order('dm', 'DESC'); @@ -158,7 +158,7 @@ class SalariesStats extends Stats */ public function getAllByYear() { - $sql = "SELECT date_format(datep,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg"; + $sql = "SELECT date_format(dateep,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg"; $sql .= " FROM ".$this->from; $sql .= " WHERE ".$this->where; $sql .= " GROUP BY year"; diff --git a/htdocs/salaries/document.php b/htdocs/salaries/document.php index 3181770cfcc..045b77ca0a4 100644 --- a/htdocs/salaries/document.php +++ b/htdocs/salaries/document.php @@ -173,7 +173,7 @@ if ($object->id) { $morehtmlref .= ''; } - $morehtmlref .= '
'.$langs->trans('Employee').' : '.$userstatic->getNomUrl(1); + $morehtmlref .= '
'.$langs->trans('Employee').' : '.$userstatic->getNomUrl(-1); // Project if (!empty($conf->projet->enabled)) { diff --git a/htdocs/salaries/info.php b/htdocs/salaries/info.php index b6a818e6f54..a43d9010d8d 100644 --- a/htdocs/salaries/info.php +++ b/htdocs/salaries/info.php @@ -136,7 +136,7 @@ if ($action != 'editlabel') { $morehtmlref .= ''; } -$morehtmlref .= '
'.$langs->trans('Employee').' : '.$userstatic->getNomUrl(1); +$morehtmlref .= '
'.$langs->trans('Employee').' : '.$userstatic->getNomUrl(-1); // Project if (!empty($conf->projet->enabled)) { diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 4de0a93d440..ac7fad391ef 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -615,7 +615,7 @@ if (empty($reshook)) { ) { $object->fetch($id); - $newpassword = $object->setPassword($user, ''); + $newpassword = $object->setPassword($user, ''); // This will generate a new password if ($newpassword < 0) { // Echec setEventMessages($langs->trans("ErrorFailedToSetNewPassword"), null, 'errors'); diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 7a56804aa71..a5f7a4c30aa 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -2125,8 +2125,47 @@ class User extends CommonObject $password = getRandomPassword(false); } - // Crypt password + // Check and encrypt the password if (empty($passwordalreadycrypted)) { + if (!empty($conf->global->USER_PASSWORD_GENERATED)) { + // Add a check on rules for password syntax using the setup of the password generator + $modGeneratePassClass = 'modGeneratePass'.ucfirst($conf->global->USER_PASSWORD_GENERATED); + /* + include_once DOl_DOCUMENT_ROOT.'/core/modules/security/generate/'.$modGeneratePassClass.'.class.php'; + if (class_exists($modGeneratePassClass)) { + $modGeneratePass = new $modGeneratePassClass($this->db, $conf, $langs, $user); + + // Check length + if (property_exists($modGeneratePass, 'length2') && $modGeneratePass->length2 > 0) { + if (strlen($password) < $modGeneratePass->length2) { + $this->error = "PasswordMustHaveNCharMin"; + return -1; + } + } + + // Check on $modGeneratePass->NbMaj + if (property_exists($modGeneratePass, 'NbMaj') && $modGeneratePass->NbMaj > 0) { + // TODO + } + + } + // Check on $modGeneratePass->NbNum + if (property_exists($modGeneratePass, 'NbNum') && $modGeneratePass->NbNum > 0) { + // TODO + + } + // Check on $modGeneratePass->NbSpe + if (property_exists($modGeneratePass, 'NbSpe') && $modGeneratePass->NbSpe > 0) { + // TODO + } + // Check on $modGeneratePass->NbRepeat + if (property_exists($modGeneratePass, 'NbRepeat') && $modGeneratePass->NbRepeat > 0) { + // TODO + } + }*/ + } + + // Now, we encrypt the new password $password_crypted = dol_hash($password); }