Browse Source

Debug v15

Laurent Destailleur 3 years ago
parent
commit
72998cd8fe

+ 3 - 3
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"

+ 4 - 3
dev/tools/optimize_images.sh

@@ -14,7 +14,8 @@ max_output_size=0
 usage()
 {
   cat <<EO
-Usage: $PROGNAME [options]
+Usage:   $PROGNAME (list|fix) [options]
+Example: optimize_images.sh (list|fix) -i dirtoscan
 
 Script to optimize JPG and PNG images in a directory.
 
@@ -183,8 +184,8 @@ ARGS=$(getopt -s bash --options $SHORTOPTS --longoptions $LONGOPTS --name $PROGN
 # Syntax
 if [ "x$1" != "xlist" -a "x$1" != "xfix" ]
 then
-	echo "Usage: optimize_images.sh (list|fix) -i dirtoscan"
-	exit
+	usage
+	exit 0
 fi
 
 eval set -- "$ARGS"

+ 14 - 2
htdocs/core/modules/security/generate/modGeneratePassNone.class.php

@@ -26,8 +26,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/modules/security/generate/modules_genpassw
 
 
 /**
- *	    \class      modGeneratePassNone
- *		\brief      Class to generate a password according to rule 'no password'
+ *	Class to generate a password according to rule 'no password'
  */
 class modGeneratePassNone extends ModeleGenPassword
 {
@@ -36,8 +35,20 @@ class modGeneratePassNone 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 modGeneratePassNone extends ModeleGenPassword
 	{
 		$this->id = "none";
 		$this->length = 0;
+		$this->length2 = 0;
 
 		$this->db = $db;
 		$this->conf = $conf;

+ 15 - 4
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);
 		}
 

+ 14 - 2
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;

+ 1 - 2
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
 {

+ 2 - 2
htdocs/salaries/card.php

@@ -746,7 +746,7 @@ if ($id) {
 			$userstatic = new User($db);
 			$result = $userstatic->fetch($object->fk_user);
 			if ($result > 0) {
-				$morehtmlref .= '<br>' .$langs->trans('Employee').' : '.$userstatic->getNomUrl(1);
+				$morehtmlref .= '<br>' .$langs->trans('Employee').' : '.$userstatic->getNomUrl(-1);
 			}
 		} else {
 			$morehtmlref .= '<br>' . $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();

+ 11 - 11
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";

+ 1 - 1
htdocs/salaries/document.php

@@ -173,7 +173,7 @@ if ($object->id) {
 		$morehtmlref .= '</form>';
 	}
 
-	$morehtmlref .= '<br>'.$langs->trans('Employee').' : '.$userstatic->getNomUrl(1);
+	$morehtmlref .= '<br>'.$langs->trans('Employee').' : '.$userstatic->getNomUrl(-1);
 
 	// Project
 	if (!empty($conf->projet->enabled)) {

+ 1 - 1
htdocs/salaries/info.php

@@ -136,7 +136,7 @@ if ($action != 'editlabel') {
 	$morehtmlref .= '</form>';
 }
 
-$morehtmlref .= '<br>'.$langs->trans('Employee').' : '.$userstatic->getNomUrl(1);
+$morehtmlref .= '<br>'.$langs->trans('Employee').' : '.$userstatic->getNomUrl(-1);
 
 // Project
 if (!empty($conf->projet->enabled)) {

+ 1 - 1
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');

+ 40 - 1
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);
 		}