From 293ea73b6baeaacb93dffe1df78277555292ac49 Mon Sep 17 00:00:00 2001
From: Mathieu Trossevin
Date: Mon, 13 Nov 2023 13:59:47 +0100
Subject: [PATCH 1/3] Initialise CI with PHPStan level 0
---
.Jenkinsfile | 22 ++++++++++++++++++++++
evolibs/Form.php | 12 +++++++-----
inc/accounts.php | 12 ++++++------
inc/common.php | 1 +
phpstan-baseline.neon | 6 ++++++
phpstan.neon | 13 +++++++++++++
tpl/home.tpl.php | 4 +---
tpl/webadmin-edit.tpl.php | 2 +-
tpl/webadmin.tpl.php | 2 +-
9 files changed, 58 insertions(+), 16 deletions(-)
create mode 100644 .Jenkinsfile
create mode 100644 phpstan-baseline.neon
create mode 100644 phpstan.neon
diff --git a/.Jenkinsfile b/.Jenkinsfile
new file mode 100644
index 0000000..99ad40e
--- /dev/null
+++ b/.Jenkinsfile
@@ -0,0 +1,22 @@
+pipeline {
+ agent {
+ docker {
+ image 'php:8.2-cli'
+ }
+ }
+ stages {
+ stage('PHPStan (static analysis)') {
+ steps {
+ script {
+ sh 'curl -fsSL https://github.com/phpstan/phpstan/releases/download/1.10.41/phpstan.phar -o phpstan.phar'
+ sh 'php ./phpstan.phar analyse --configuration=phpstan.neon --memory-limit=512M --error-format=junit > phpstan-results.junit.xml'
+ }
+ }
+ post {
+ always {
+ junit 'phpstan-results.junit.xml'
+ }
+ }
+ }
+ }
+}
diff --git a/evolibs/Form.php b/evolibs/Form.php
index 74aea53..0a050ef 100644
--- a/evolibs/Form.php
+++ b/evolibs/Form.php
@@ -263,6 +263,8 @@ class FormField {
protected $read_only = null;
protected $disabled = null;
private $storage = NULL;
+ protected $mandatory = null;
+ protected $hidden = null;
protected function __construct($label) {
$this->storage = & $_SESSION;
@@ -638,7 +640,7 @@ class EmailInputFormField extends TextInputFormField {
return FALSE;
}
- if(!empty($this->value) && !eregi('^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$',$this->value)){
+ if(!empty($this->value) && !preg_match('/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i', $this->value)){
if($set_error) $this->error = 'Adresse email invalide';
return FALSE;
}
@@ -794,7 +796,7 @@ class MultipleCheckBoxInputFormField extends FormField {
protected $mandatory = NULL;
protected $list = array();
- public function __construct($label, $mandatory=TRUE, $list) {
+ public function __construct($label, $list, $mandatory=TRUE) {
parent::__construct($label);
$this->mandatory = $mandatory;
$this->list = $list;
@@ -877,7 +879,7 @@ class SelectFormField extends FormField {
protected $mandatory = NULL;
protected $list = array();
- public function __construct($label, $mandatory=TRUE, $list) {
+ public function __construct($label, $list, $mandatory=TRUE) {
parent::__construct($label);
$this->mandatory = $mandatory;
$this->list = $list;
@@ -933,7 +935,7 @@ class RadioFormField extends FormField {
protected $mandatory = NULL;
protected $list = array();
- public function __construct($label, $mandatory=TRUE, $list, $default = null) {
+ public function __construct($label, $list, $mandatory=TRUE, $default = null) {
parent::__construct($label);
$this->mandatory = $mandatory;
$this->list = $list;
@@ -995,7 +997,7 @@ class ButtonInputFormField extends FormField {
protected $event = NULL;
protected $action = NULL;
- public function __construct($label,$mandatory=FALSE, $event, $action) {
+ public function __construct($label, $event, $action, $mandatory=FALSE) {
parent::__construct($label);
$this->mandatory = $mandatory;
$this->event = $event;
diff --git a/inc/accounts.php b/inc/accounts.php
index 95980ab..93a4cc3 100644
--- a/inc/accounts.php
+++ b/inc/accounts.php
@@ -74,8 +74,8 @@ function web_add($form, $admin_mail) {
foreach ( $domain_alias as $domain ) {
$exec_cmd = 'web-add.sh add-alias '.escapeshellarg($form->getField('username')->getValue()).' ';
$domain = trim($domain);
- $exec_cmd .= $domain.' '. $server_list;
- sudoexec($exec_cmd, $exec_output, $exec_return);
+ $exec_cmd .= $domain;
+ sudoexec($exec_cmd, $exec_output2, $exec_return2);
}
$exec_return |= $exec_return2; // $exec_return == 0 if $exec_return == 0 && $exec_return2 == 0
array_push($exec_output, $exec_output2);
@@ -254,19 +254,19 @@ $form->addField('username', new AlphaNumericalTextInputFormField("Nom d'utilisat
$form->addField('domain', new DomainInputFormField("Nom de domaine", TRUE));
$form->addField('domain_alias', new DomainListInputFormField("Alias (séparés par une virgule, sans espaces)", FALSE));
$form->addField('password_random',
- new CheckboxInputFormField("Mot de passe aléatoire ?", FALSE));
+ new CheckBoxInputFormField("Mot de passe aléatoire ?", FALSE));
$form->getField('password_random')->setValue(TRUE);
$form->addField('password', new PasswordInputFormField('Mot de passe', FALSE));
$form->getField('password')->setDisabled();
$form->addField('mysql_db',
- new CheckboxInputFormField("Créer une base de données MySQL ?",
+ new CheckBoxInputFormField("Créer une base de données MySQL ?",
FALSE));
$form->getField('mysql_db')->setValue(TRUE);
$form->addField('mysql_dbname',
new AlphaNumericalTextInputFormField("Nom de la base MySQL", FALSE, array(20,16)));
$form->addField('mysql_password_random',
- new CheckboxInputFormField("Mot de passe MySQL aléatoire ?",
+ new CheckBoxInputFormField("Mot de passe MySQL aléatoire ?",
FALSE));
$form->getField('mysql_password_random')->setValue(TRUE);
@@ -344,7 +344,7 @@ if ($conf['cluster']) {
if ($conf['bindadmin']) {
/* Quai13 specific: allow to switch between Gmail MX/Quai13 MX */
- $form->addField('use_gmail_mxs', new CheckboxInputFormField("Utilisation des serveurs Gmail en MX ?", FALSE));
+ $form->addField('use_gmail_mxs', new CheckBoxInputFormField("Utilisation des serveurs Gmail en MX ?", FALSE));
}
if (array_key_exists('php_versions', $conf) && is_array($conf['php_versions'])) {
diff --git a/inc/common.php b/inc/common.php
index 129ae90..2cf493f 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -81,6 +81,7 @@ function is_mcluster_mode() {
function load_config_cluster($cluster) {
global $conf;
$configfile = '../conf/config.'.$cluster.'.php';
+ $clusterconf = array(); // Fix static analysis. It's fully defined by config file.
test_exist($configfile);
require_once($configfile);
$conf = array_merge($conf, $clusterconf);
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
new file mode 100644
index 0000000..3c69015
--- /dev/null
+++ b/phpstan-baseline.neon
@@ -0,0 +1,6 @@
+parameters:
+ ignoreErrors:
+ -
+ message: "#^Undefined variable\\: \\$error$#"
+ count: 3
+ path: lib/bdd.php
diff --git a/phpstan.neon b/phpstan.neon
new file mode 100644
index 0000000..834f2f1
--- /dev/null
+++ b/phpstan.neon
@@ -0,0 +1,13 @@
+includes:
+ - phpstan-baseline.neon
+
+parameters:
+ level: 0
+ paths:
+ - htdocs
+ - lib
+ - evolibs
+ - inc
+ - tpl
+ - conf
+ - bin
diff --git a/tpl/home.tpl.php b/tpl/home.tpl.php
index 5d10005..7f4a0f9 100644
--- a/tpl/home.tpl.php
+++ b/tpl/home.tpl.php
@@ -30,6 +30,4 @@ puis utilisez le menu ci-dessus pour administrer votre compte.
';
else {
echo 'Bienvenue, utilisez le menu ci-dessus pour administrer votre compte.
';
}
-?>
-
-
+?>
\ No newline at end of file
diff --git a/tpl/webadmin-edit.tpl.php b/tpl/webadmin-edit.tpl.php
index 4c57bd3..fc1aa95 100644
--- a/tpl/webadmin-edit.tpl.php
+++ b/tpl/webadmin-edit.tpl.php
@@ -39,7 +39,7 @@
for ( $i=0; $i < count($alias_list); ++$i ) {
print '';
printf('%s | ',
- $alias_list[$i]['alias'], $alias_list[$i]['alias']);
+ $alias_list[$i]['alias']);
if (is_superadmin())
printf('Supprimer | ',
$domain, $alias_list[$i]['alias']);
diff --git a/tpl/webadmin.tpl.php b/tpl/webadmin.tpl.php
index 98b02c8..2c71040 100755
--- a/tpl/webadmin.tpl.php
+++ b/tpl/webadmin.tpl.php
@@ -62,7 +62,7 @@
printf('%s | ', $vhost_info['owner']);
}
printf('%s | ',
- $vhost_info['server_name'], $vhost_info['server_name']);
+ $vhost_info['server_name']);
if ($conf['cluster']) {
if (empty($vhost_info['bdd']))
--
2.39.2
From af94efde45e5b0df24909dbf27c8333f76d743f7 Mon Sep 17 00:00:00 2001
From: Mathieu Trossevin
Date: Mon, 13 Nov 2023 15:14:31 +0100
Subject: [PATCH 2/3] Replace `isset($_POST)` with `!empty($_POST)`
The former is always true (outside of post method it is an empty array
and not null, and it cannot be `unset()`).
The check was as such either meaningless or was supposed to check that
something was sent. This commit assume the later.
---
inc/auth.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/inc/auth.php b/inc/auth.php
index c92dbc6..ad4b9fc 100644
--- a/inc/auth.php
+++ b/inc/auth.php
@@ -12,7 +12,7 @@
* @version 1.0
*/
-if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST)) {
+if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST)) {
$input_username = $_POST['login'];
$input_password = $_POST['passw'];
--
2.39.2
From 7b2942273062c7806509e488808e62056f497987 Mon Sep 17 00:00:00 2001
From: Mathieu Trossevin
Date: Wed, 15 Nov 2023 10:57:20 +0100
Subject: [PATCH 3/3] Attempt to enable use of more than one agent
Primarily so that we could use shellcheck in the future on top of
PHPStan.
---
.Jenkinsfile | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/.Jenkinsfile b/.Jenkinsfile
index 99ad40e..53221aa 100644
--- a/.Jenkinsfile
+++ b/.Jenkinsfile
@@ -1,11 +1,12 @@
pipeline {
- agent {
- docker {
- image 'php:8.2-cli'
- }
- }
+ agent none
stages {
stage('PHPStan (static analysis)') {
+ agent {
+ docker {
+ image 'php:8.2-cli'
+ }
+ }
steps {
script {
sh 'curl -fsSL https://github.com/phpstan/phpstan/releases/download/1.10.41/phpstan.phar -o phpstan.phar'
--
2.39.2