Skip to content

Commit

Permalink
:fix sonar: corrections suite à analyse Sonar Scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
equinton committed Sep 23, 2021
1 parent 107dd59 commit 7c72f27
Show file tree
Hide file tree
Showing 21 changed files with 60 additions and 126 deletions.
1 change: 0 additions & 1 deletion display/templates/framework/droits/groupChange.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<input type="hidden" name="moduleBase" value="group">
<input type="hidden" name="action" value="Write">
<input type="hidden" name="aclgroup_id" value="{$data.aclgroup_id}">
<!--input type="hidden" name="aclgroup_id_parent" value="{$data.aclgroup_id_parent}"-->
<div class="form-group center">
<button type="submit" class="btn btn-primary button-valid">{t}Valider{/t}</button>
{if $data.aclgroup_id > 0 }
Expand Down
3 changes: 0 additions & 3 deletions display/templates/main_js.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<!-- Jquery -->
<script src="display/node_modules/jquery/dist/jquery.min.js"></script>
<!--script src="display/javascript/jquery-3.3.1.min.js"></!--script-->
<script src="display/node_modules/jquery-ui-dist/jquery-ui.min.js"></script>
<script src="display/node_modules/jquery-ui/ui/widgets/tooltip.js"></script>

Expand All @@ -14,8 +13,6 @@
<script type="text/javascript" src="display/node_modules/handlebars/dist/handlebars.runtime.min.js"></script>
<script type="text/javascript" src="display/node_modules/alpaca/dist/alpaca/bootstrap/alpaca.min.js"></script>
<link rel="stylesheet" href="display/node_modules/alpaca/dist/alpaca/bootstrap/alpaca.min.css">
<!--<script type="text/javascript" src="display/javascript/alpaca/js/alpaca-1.5.23.min.js"></script>
<link rel="stylesheet" href="display/javascript/alpaca/css/alpaca-1.5.23.min.css" >-->

<!-- leaflet -->
<link rel="stylesheet" href="display/node_modules/leaflet/dist/leaflet.css">
Expand Down
27 changes: 0 additions & 27 deletions framework/common.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,19 +197,6 @@
*/
if (strlen($BDD_schema) > 0) {
$bdd->exec("set search_path = " . $BDD_schema);
/*
* Positionnement des messages dans la langue courante
*/
/*switch ($LANG["date"]["locale"]) {
case "en":
$bdd->exec("set lc_messages to 'en_US.UTF-8'");
break;
case "fr":
default:
$bdd->exec("set lc_messages to 'fr_FR.UTF-8'");
break;
}
*/
}
/*
* Connexion a la base de gestion des droits
Expand All @@ -231,20 +218,6 @@
if (strlen($GACL_schema) > 0) {
$bdd_gacl->exec("set search_path = " . $GACL_schema);
}
/*
* Positionnement des messages dans la langue courante
*/
/*
switch ($LANG["date"]["locale"]) {
case "en":
$bdd_gacl->exec("set lc_messages to 'en_US.UTF-8'");
break;
case "fr":
default:
$bdd_gacl->exec("set lc_messages to 'fr_FR.UTF-8'");
break;
}
*/
} else {
$message->set(_("Echec de connexion à la base de données de gestion des droits (GACL)"),true);
}
Expand Down
11 changes: 2 additions & 9 deletions framework/fonctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function dataDelete($dataClass, $id, $isPartOfTransaction = false)
}
$message->setSyslog($e->getMessage());
if ($isPartOfTransaction) {
throw new Exception(sprintf("Suppression impossible de l'enregistrement %s"), $id);
throw new ObjetBDDException(sprintf("Suppression impossible de l'enregistrement %s"), $id);
}
$ret = -1;
}
Expand Down Expand Up @@ -459,7 +459,7 @@ function is_cli()
if (defined('STDIN')) {
return true;
}
if (empty($_SERVER['REMOTE_ADDR']) and !isset($_SERVER['HTTP_USER_AGENT']) and count($_SERVER['argv']) > 0) {
if (empty($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['HTTP_USER_AGENT']) && count($_SERVER['argv']) > 0) {
return true;
}
return false;
Expand All @@ -485,11 +485,4 @@ function getLineFeed()
function phpeol()
{
return getLineFeed();
/*
if (PHP_SAPI == "cli") {
return PHP_EOL;
} else {
return "<br>";
}
*/
}
27 changes: 14 additions & 13 deletions framework/identification/identification.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* Classe maîtrisant les aspects identification.
*/
class IdentificationException extends Exception
{ }
{
}

/**
* @class Identification
Expand Down Expand Up @@ -324,7 +325,7 @@ public function verifyLogin($loginEntered = "", $password = "", $modeAdmin = fal
global $ident_header_vars;
$headers = getHeaders($ident_header_vars["radical"]);
$login = $headers[$ident_header_vars["login"]];
if (strlen($login) > 0 && count($headers) > 0) {
if (strlen($login) > 0 && !empty($headers)) {
/**
* Verify if the login exists
*/
Expand All @@ -350,14 +351,14 @@ public function verifyLogin($loginEntered = "", $password = "", $modeAdmin = fal
$createUser = true;
if (count($ident_header_vars["organizationGranted"]) > 0 && !in_array($headers[$ident_header_vars["organization"]], $ident_header_vars["organizationGranted"])) {
$createUser = false;
$log->setLog($login, "connexion", "HEADER-ko. The ".$headers[$ident_header_vars["organization"]]. " is not authorized to connect to this application");
$log->setLog($login, "connexion", "HEADER-ko. The " . $headers[$ident_header_vars["organization"]] . " is not authorized to connect to this application");
}
if ($createUser) {
$dlogin = array (
"login"=>$login,
"nom"=>$headers[$ident_header_vars["cn"]],
"mail"=>$headers[$ident_header_vars["mail"]],
"actif"=>0
$dlogin = array(
"login" => $login,
"nom" => $headers[$ident_header_vars["cn"]],
"mail" => $headers[$ident_header_vars["mail"]],
"actif" => 0
);
$login_id = $loginGestion->ecrire($dlogin);
if ($login_id > 0) {
Expand All @@ -371,16 +372,16 @@ public function verifyLogin($loginEntered = "", $password = "", $modeAdmin = fal
* Send mail to administrators
*/
global $APPLI_nom, $APPLI_mail;
$subject = $APPLI_nom." "._("Nouvel utilisateur");
$contents = "<html><body>".sprintf(_("%1$s a créé son compte avec le login %2$s dans l'application %3$s.
$subject = $APPLI_nom . " " . _("Nouvel utilisateur");
$contents = "<html><body>" . sprintf(_("%1$s a créé son compte avec le login %2$s dans l'application %3$s.
<br>Il est rattaché à l'organisation %5$s.
<br>Le compte est inactif jusqu'à ce que vous l'activiez.
<br>Pour activer le compte, connectez-vous à l'application
<a href='%4$s'>%4$s</a>
<br>Ne répondez pas à ce mail, qui est généré automatiquement")."</body></html>",$login,$headers[$ident_header_vars["cn"]],$APPLI_nom, $APPLI_mail, $headers[$ident_header_vars["organization"]]);
<br>Ne répondez pas à ce mail, qui est généré automatiquement") . "</body></html>", $login, $headers[$ident_header_vars["cn"]], $APPLI_nom, $APPLI_mail, $headers[$ident_header_vars["organization"]]);

$log->sendMailToAdmin($subject,$contents,"loginCreateByHeader",$login);
$message->set(_("Votre compte a été créé, mais est inactif. Un mail a été adressé aux administrateurs pour son activation") );
$log->sendMailToAdmin($subject, $contents, "loginCreateByHeader", $login);
$message->set(_("Votre compte a été créé, mais est inactif. Un mail a été adressé aux administrateurs pour son activation"));
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions framework/identification/loginGestion.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public function changePassword($oldpassword, $pass1, $pass2)
if (isset($_SESSION["login"])) {
$oldData = $this->lireByLogin($_SESSION["login"]);
if ($log->getLastConnexionType($_SESSION["login"]) == "db") {
if ($this->_testPassword($_SESSION["login"], $oldpassword, $oldData["password"]) == true) {
if ($this->_testPassword($_SESSION["login"], $oldpassword, $oldData["password"])) {
/*
* Verifications de validite du mot de passe
*/
Expand Down Expand Up @@ -279,10 +279,8 @@ public function changePassword($oldpassword, $pass1, $pass2)
public function changePasswordAfterLost($login, $pass1, $pass2)
{
$retour = 0;
if (strlen($login) > 0) {
if ($this->_passwordVerify($pass1, $pass2)) {
$retour = $this->writeNewPassword($login, $pass1);
}
if (strlen($login) > 0 && $this->_passwordVerify($pass1, $pass2)) {
$retour = $this->writeNewPassword($login, $pass1);
}
return $retour;
}
Expand Down
11 changes: 6 additions & 5 deletions framework/identification/token.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

/**
* Class for generate a identification token or read id
*
*
* Token is crypted with private key of server, and decrypted with public key
* Token is encoded in JSON format. It contain 2 fields : login and expire (timestamp)
* @author quinton
*
*/
class TokenException extends Exception
{ }
{
}

class Token
{
Expand All @@ -20,7 +21,7 @@ class Token

/**
* validityDuration : default duration validity of the token
*
*
* @var int
*/
private $validityDuration = 86400;
Expand Down Expand Up @@ -84,7 +85,7 @@ function createToken($login, $validityDuration = 0)
"token" => base64_encode($crypted),
"expire" => $expire,
"timestamp" => $data["timestamp"],
"ip"=>$data["ip"]
"ip" => $data["ip"]
);
$token = json_encode($dataToken);
} else {
Expand Down Expand Up @@ -178,7 +179,7 @@ private function getKey($type = "priv")
$type == "priv" ? $filename = $this->privateKey : $filename = $this->pubKey;
if (file_exists($filename)) {
$handle = fopen($filename, "r");
if ($handle != false) {
if ($handle) {
$contents = fread($handle, filesize($filename));
if (!$contents) {
throw new TokenException("key " . $filename . " is empty");
Expand Down
5 changes: 2 additions & 3 deletions framework/log/log.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,15 @@ public function getLastConnections($duration = 36000)
and nom_module like '%connexion' and commentaire like '%-ok' and commentaire <> 'token-ok'
and log_date > :datefrom
order by log_id desc";
$date = new DateTime(now);
$date = new DateTime();
$date->sub(new DateInterval("PT" . $duration . "S"));
$data = $this->getListeParamAsPrepared(
return $this->getListeParamAsPrepared(
$sql,
array(
"login" => $_SESSION["login"],
"datefrom" => $date->format(DATELONGMASK),
)
);
return $data;
}
}

Expand Down
4 changes: 2 additions & 2 deletions framework/news.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
$doc = "";
$file = file($filename);
foreach ($file as $value) {
if (substr($value, 1, 1) == "*" or substr($value, 0, 1) == "*") {
if (substr($value, 1, 1) == "*" || substr($value, 0, 1) == "*") {
$doc .= "&nbsp;&nbsp;&nbsp;";
}
utf8_encode($value);
Expand All @@ -19,4 +19,4 @@

$vue->set($doc, "texteNews");
$vue->set("framework/news.tpl", "corps");
?>
?>
33 changes: 10 additions & 23 deletions framework/objetbdd/ObjetBDD.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ function lire($id, $getDefault = true, $parentValue = 0)
$sql = "select * from " . $this->table . " where " . $where;
}
$collection = $this->executeAsPrepared($sql, $data);
if (count($collection) == 0) {
if (empty($collection)) {
if ($getDefault) {
$collection = $this->getDefaultValue($parentValue);
} else {
Expand Down Expand Up @@ -801,7 +801,7 @@ function ecrire($dataBrute)
}
$sql = "select " . $cle . " from " . $this->table . " where " . $where;
$rs = $this->executeAsPrepared($sql, $ds);
if (count($rs) == 0) {
if (empty($rs)) {
/**
* nouveau avec id passe
*/
Expand Down Expand Up @@ -948,7 +948,7 @@ function ecrire($dataBrute)
}
$rs = $this->executeAsPrepared($sql, $ds);
if ($mode == "ajout" && $this->id_auto == 1) {
if ($this->typeDatabase == 'pgsql' && count($rs) > 0) {
if ($this->typeDatabase == 'pgsql' && !empty($rs)) {
$ret = $rs[0][$this->cle];
} else {
$last_id = $this->execute('SELECT LAST_INSERT_ID() as last_id');
Expand Down Expand Up @@ -1492,16 +1492,6 @@ private function htmlEncode($data)
private function utf8Encode($data)
{
return $data;
/*
* if (is_array ( $data )) {
* foreach ( $data as $key => $value ) {
* $data [$key] = $this->utf8Encode ( $value );
* }
* } else {
* $data = utf8_encode ( $data );
* }
* return $data;
*/
}

/**
Expand Down Expand Up @@ -1750,11 +1740,9 @@ function encodeData($data)
/*
* Traitement des chaines individuelles
*/
if ($this->typeDatabase == 'pgsql') {
if ($this->UTF8) {
if (mb_detect_encoding($data) != "UTF-8") {
$data = mb_convert_encoding($data, 'UTF-8');
}
if ($this->typeDatabase == 'pgsql' && $this->UTF8) {
if (mb_detect_encoding($data) != "UTF-8") {
$data = mb_convert_encoding($data, 'UTF-8');
}
$data = pg_escape_string($data);
} else {
Expand Down Expand Up @@ -1929,11 +1917,10 @@ function getUUID()
* @param bool $pathAbsolute: if false, the path of the class is $this->classpath/$classFile (default: false)
* @return void
*/
function classInstanciate( $className, $classFile, bool $pathAbsolute = false)
function classInstanciate($className, $classFile, bool $pathAbsolute = false)
{
$pathAbsolute ? $path = $classFile : $path = $this->classpath."/".$classFile;
include_once $path;
$instance = new $className($this->connection, $this->paramori);
return $instance;
$pathAbsolute ? $path = $classFile : $path = $this->classpath . "/" . $classFile;
include_once $path;
return new $className($this->connection, $this->paramori);
}
}
12 changes: 5 additions & 7 deletions framework/objetbdd/ObjetBDD_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function objetBDDparamInit()
} else {
$ObjetBDDParam["formatDate"] = $DEFAULT_formatdate;
}

$ObjetBDDParam["debug_mode"] = $OBJETBDD_debugmode;
$_SESSION["ObjetBDDParam"] = $ObjetBDDParam;
}
Expand All @@ -37,7 +37,7 @@ function objetBDDparamInit()
* function _new
* initialisation d'une classe basee sur ObjetBDD,
* avec passage des parametres adequats
*
*
* @param
* $classe
* @return instance
Expand All @@ -53,7 +53,7 @@ function _new($classe)
* declaree precedemment avec la fonction _new.
* Affiche les messages d'erreur le cas echeant
* Retourne le resultat de la fonction d'ecriture.
*
*
* @param
* $instance
* @param
Expand All @@ -62,9 +62,7 @@ function _new($classe)
*/
function _ecrire($instance, $data)
{
$rep = $instance->ecrire($data);
//$instance->getErrorData(1);
return $rep;
return $instance->ecrire($data);
}

?>
?>
1 change: 0 additions & 1 deletion framework/utils/structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
)
);
$vue->setParam(array("filename"=>"collec-dbstructure.tex"));
//$vue->htmlVars[] = "data";
break;
case "gacl":
$dataclass = new Structure($bdd_gacl, array(), $t_module["schemas"]);
Expand Down
4 changes: 2 additions & 2 deletions framework/version
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version_number=3.2.0
version_date=2020-04-01
version_number=3.3.0
version_date=2021-09-23
Loading

0 comments on commit 7c72f27

Please sign in to comment.