Completed
Push — master ( 37aa61...be7234 )
by cam
01:24
created
ecrire/src/Chiffrer/Chiffrement.php 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -18,76 +18,76 @@
 block discarded – undo
18 18
  * @link https://www.php.net/manual/fr/book.sodium.php
19 19
  */
20 20
 class Chiffrement {
21
-	/** Chiffre un message en utilisant une clé ou un mot de passe */
22
-	public static function chiffrer(
23
-		string $message,
24
-		#[\SensitiveParameter]
25
-		string $key
26
-	): ?string {
27
-		// create a random salt for key derivation
28
-		$salt = random_bytes(SODIUM_CRYPTO_PWHASH_SALTBYTES);
29
-		$key = self::deriveKeyFromPassword($key, $salt);
30
-		$nonce = random_bytes(\SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
31
-		$padded_message = sodium_pad($message, 16);
32
-		$encrypted = sodium_crypto_secretbox($padded_message, $nonce, $key);
33
-		$encoded = base64_encode($salt . $nonce . $encrypted);
34
-		sodium_memzero($key);
35
-		sodium_memzero($nonce);
36
-		sodium_memzero($salt);
37
-		#spip_log("chiffrer($message)=$encoded", 'chiffrer' . _LOG_DEBUG);
38
-		return $encoded;
39
-	}
21
+    /** Chiffre un message en utilisant une clé ou un mot de passe */
22
+    public static function chiffrer(
23
+        string $message,
24
+        #[\SensitiveParameter]
25
+        string $key
26
+    ): ?string {
27
+        // create a random salt for key derivation
28
+        $salt = random_bytes(SODIUM_CRYPTO_PWHASH_SALTBYTES);
29
+        $key = self::deriveKeyFromPassword($key, $salt);
30
+        $nonce = random_bytes(\SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
31
+        $padded_message = sodium_pad($message, 16);
32
+        $encrypted = sodium_crypto_secretbox($padded_message, $nonce, $key);
33
+        $encoded = base64_encode($salt . $nonce . $encrypted);
34
+        sodium_memzero($key);
35
+        sodium_memzero($nonce);
36
+        sodium_memzero($salt);
37
+        #spip_log("chiffrer($message)=$encoded", 'chiffrer' . _LOG_DEBUG);
38
+        return $encoded;
39
+    }
40 40
 
41
-	/** Déchiffre un message en utilisant une clé ou un mot de passe */
42
-	public static function dechiffrer(
43
-		string $encoded,
44
-		#[\SensitiveParameter]
45
-		string $key
46
-	): ?string {
47
-		$decoded = base64_decode($encoded);
48
-		$salt = substr($decoded, 0, \SODIUM_CRYPTO_PWHASH_SALTBYTES);
49
-		$nonce = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES, \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
50
-		$encrypted = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES + \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
51
-		$key = self::deriveKeyFromPassword($key, $salt);
52
-		$padded_message = sodium_crypto_secretbox_open($encrypted, $nonce, $key);
53
-		sodium_memzero($key);
54
-		sodium_memzero($nonce);
55
-		sodium_memzero($salt);
56
-		if ($padded_message === false) {
57
-			spip_log("dechiffrer() chiffre corrompu `$encoded`", 'chiffrer' . _LOG_DEBUG);
58
-			return null;
59
-		}
60
-		return sodium_unpad($padded_message, 16);
61
-	}
41
+    /** Déchiffre un message en utilisant une clé ou un mot de passe */
42
+    public static function dechiffrer(
43
+        string $encoded,
44
+        #[\SensitiveParameter]
45
+        string $key
46
+    ): ?string {
47
+        $decoded = base64_decode($encoded);
48
+        $salt = substr($decoded, 0, \SODIUM_CRYPTO_PWHASH_SALTBYTES);
49
+        $nonce = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES, \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
50
+        $encrypted = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES + \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
51
+        $key = self::deriveKeyFromPassword($key, $salt);
52
+        $padded_message = sodium_crypto_secretbox_open($encrypted, $nonce, $key);
53
+        sodium_memzero($key);
54
+        sodium_memzero($nonce);
55
+        sodium_memzero($salt);
56
+        if ($padded_message === false) {
57
+            spip_log("dechiffrer() chiffre corrompu `$encoded`", 'chiffrer' . _LOG_DEBUG);
58
+            return null;
59
+        }
60
+        return sodium_unpad($padded_message, 16);
61
+    }
62 62
 
63
-	/** Génère une clé de la taille attendue pour le chiffrement */
64
-	public static function keygen(): string {
65
-		return sodium_crypto_secretbox_keygen();
66
-	}
63
+    /** Génère une clé de la taille attendue pour le chiffrement */
64
+    public static function keygen(): string {
65
+        return sodium_crypto_secretbox_keygen();
66
+    }
67 67
 
68
-	/**
69
-	 * Retourne une clé de la taille attendue pour le chiffrement
70
-	 *
71
-	 * Notamment si on utilise un mot de passe comme clé, il faut le hacher
72
-	 * pour servir de clé à la taille correspondante.
73
-	 */
74
-	private static function deriveKeyFromPassword(
75
-		#[\SensitiveParameter]
76
-		string $password,
77
-		string $salt
78
-	): string {
79
-		if (strlen($password) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
80
-			return $password;
81
-		}
82
-		$key = sodium_crypto_pwhash(
83
-			\SODIUM_CRYPTO_SECRETBOX_KEYBYTES,
84
-			$password,
85
-			$salt,
86
-			\SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
87
-			\SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE
88
-		);
89
-		sodium_memzero($password);
68
+    /**
69
+     * Retourne une clé de la taille attendue pour le chiffrement
70
+     *
71
+     * Notamment si on utilise un mot de passe comme clé, il faut le hacher
72
+     * pour servir de clé à la taille correspondante.
73
+     */
74
+    private static function deriveKeyFromPassword(
75
+        #[\SensitiveParameter]
76
+        string $password,
77
+        string $salt
78
+    ): string {
79
+        if (strlen($password) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
80
+            return $password;
81
+        }
82
+        $key = sodium_crypto_pwhash(
83
+            \SODIUM_CRYPTO_SECRETBOX_KEYBYTES,
84
+            $password,
85
+            $salt,
86
+            \SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
87
+            \SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE
88
+        );
89
+        sodium_memzero($password);
90 90
 
91
-		return $key;
92
-	}
91
+        return $key;
92
+    }
93 93
 }
Please login to merge, or discard this patch.
ecrire/src/Chiffrer/Password.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -13,49 +13,49 @@
 block discarded – undo
13 13
 
14 14
 /** Vérification et hachage de mot de passe */
15 15
 class Password {
16
-	/**
17
-	 * verifier qu'un mot de passe en clair est correct a l'aide de son hash
18
-	 *
19
-	 * Le mot de passe est poivre via la cle secret_des_auth
20
-	 */
21
-	public static function verifier(
22
-		#[\SensitiveParameter]
23
-		string $password_clair,
24
-		#[\SensitiveParameter]
25
-		string $password_hash,
26
-		#[\SensitiveParameter]
27
-		?string $key = null
28
-	): bool {
29
-		$key ??= self::getDefaultKey();
30
-		if ($key) {
31
-			$pass_poivre = hash_hmac('sha256', $password_clair, $key);
32
-			return password_verify($pass_poivre, $password_hash);
33
-		}
34
-		spip_log('Aucune clé pour vérifier le mot de passe', 'chiffrer' . _LOG_INFO_IMPORTANTE);
35
-		return false;
36
-	}
16
+    /**
17
+     * verifier qu'un mot de passe en clair est correct a l'aide de son hash
18
+     *
19
+     * Le mot de passe est poivre via la cle secret_des_auth
20
+     */
21
+    public static function verifier(
22
+        #[\SensitiveParameter]
23
+        string $password_clair,
24
+        #[\SensitiveParameter]
25
+        string $password_hash,
26
+        #[\SensitiveParameter]
27
+        ?string $key = null
28
+    ): bool {
29
+        $key ??= self::getDefaultKey();
30
+        if ($key) {
31
+            $pass_poivre = hash_hmac('sha256', $password_clair, $key);
32
+            return password_verify($pass_poivre, $password_hash);
33
+        }
34
+        spip_log('Aucune clé pour vérifier le mot de passe', 'chiffrer' . _LOG_INFO_IMPORTANTE);
35
+        return false;
36
+    }
37 37
 
38
-	/**
39
-	 * Calculer un hash salé du mot de passe
40
-	 */
41
-	public static function hacher(
42
-		#[\SensitiveParameter]
43
-		string $password_clair,
44
-		#[\SensitiveParameter]
45
-		?string $key = null
46
-	): ?string {
47
-		$key ??= self::getDefaultKey();
48
-		// ne pas fournir un hash errone si la cle nous manque
49
-		if ($key) {
50
-			$pass_poivre = hash_hmac('sha256', $password_clair, $key);
51
-			return password_hash($pass_poivre, PASSWORD_DEFAULT);
52
-		}
53
-		spip_log('Aucune clé pour chiffrer le mot de passe', 'chiffrer' . _LOG_INFO_IMPORTANTE);
54
-		return null;
55
-	}
38
+    /**
39
+     * Calculer un hash salé du mot de passe
40
+     */
41
+    public static function hacher(
42
+        #[\SensitiveParameter]
43
+        string $password_clair,
44
+        #[\SensitiveParameter]
45
+        ?string $key = null
46
+    ): ?string {
47
+        $key ??= self::getDefaultKey();
48
+        // ne pas fournir un hash errone si la cle nous manque
49
+        if ($key) {
50
+            $pass_poivre = hash_hmac('sha256', $password_clair, $key);
51
+            return password_hash($pass_poivre, PASSWORD_DEFAULT);
52
+        }
53
+        spip_log('Aucune clé pour chiffrer le mot de passe', 'chiffrer' . _LOG_INFO_IMPORTANTE);
54
+        return null;
55
+    }
56 56
 
57
-	private static function getDefaultKey(): ?string {
58
-		$keys = SpipCles::instance();
59
-		return $keys->getSecretAuth();
60
-	}
57
+    private static function getDefaultKey(): ?string {
58
+        $keys = SpipCles::instance();
59
+        return $keys->getSecretAuth();
60
+    }
61 61
 }
Please login to merge, or discard this patch.
ecrire/src/Chiffrer/Cles.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -13,46 +13,46 @@
 block discarded – undo
13 13
 
14 14
 /** Conteneur de clés (chiffrement, authentification) */
15 15
 class Cles implements \Countable /* , ContainerInterface */ {
16
-	public function __construct(private array $keys) {
17
-	}
18
-
19
-	public function has(string $name): bool {
20
-		return array_key_exists($name, $this->keys);
21
-	}
22
-
23
-	public function get(string $name): ?string {
24
-		return $this->keys[$name] ?? null;
25
-	}
26
-
27
-	public function generate(string $name): string {
28
-		$key = Chiffrement::keygen();
29
-		$this->keys[$name] = $key;
30
-		spip_log("Création de la cle $name", 'chiffrer' . _LOG_INFO_IMPORTANTE);
31
-		return $key;
32
-	}
33
-
34
-	public function set(
35
-		string $name,
36
-		#[\SensitiveParameter]
37
-		string $key
38
-	): void {
39
-		$this->keys[$name] = $key;
40
-	}
41
-
42
-	public function delete(string $name): bool {
43
-		if (isset($this->keys[$name])) {
44
-			unset($this->keys[$name]);
45
-			return true;
46
-		};
47
-		return false;
48
-	}
49
-
50
-	public function count(): int {
51
-		return count($this->keys);
52
-	}
53
-
54
-	public function toJson(): string {
55
-		$json = array_map('base64_encode', $this->keys);
56
-		return \json_encode($json);
57
-	}
16
+    public function __construct(private array $keys) {
17
+    }
18
+
19
+    public function has(string $name): bool {
20
+        return array_key_exists($name, $this->keys);
21
+    }
22
+
23
+    public function get(string $name): ?string {
24
+        return $this->keys[$name] ?? null;
25
+    }
26
+
27
+    public function generate(string $name): string {
28
+        $key = Chiffrement::keygen();
29
+        $this->keys[$name] = $key;
30
+        spip_log("Création de la cle $name", 'chiffrer' . _LOG_INFO_IMPORTANTE);
31
+        return $key;
32
+    }
33
+
34
+    public function set(
35
+        string $name,
36
+        #[\SensitiveParameter]
37
+        string $key
38
+    ): void {
39
+        $this->keys[$name] = $key;
40
+    }
41
+
42
+    public function delete(string $name): bool {
43
+        if (isset($this->keys[$name])) {
44
+            unset($this->keys[$name]);
45
+            return true;
46
+        };
47
+        return false;
48
+    }
49
+
50
+    public function count(): int {
51
+        return count($this->keys);
52
+    }
53
+
54
+    public function toJson(): string {
55
+        $json = array_map('base64_encode', $this->keys);
56
+        return \json_encode($json);
57
+    }
58 58
 }
Please login to merge, or discard this patch.
ecrire/src/Chiffrer/SpipCles.php 1 patch
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -13,169 +13,169 @@
 block discarded – undo
13 13
 
14 14
 /** Gestion des clés d’authentification / chiffrement de SPIP */
15 15
 final class SpipCles {
16
-	private static array $instances = [];
17
-
18
-	private string $file = _DIR_ETC . 'cles.php';
19
-	private Cles $cles;
20
-
21
-	public static function instance(string $file = ''): self {
22
-		if (empty(self::$instances[$file])) {
23
-			self::$instances[$file] = new self($file);
24
-		}
25
-		return self::$instances[$file];
26
-	}
27
-
28
-	/**
29
-	 * Retourne le secret du site (shorthand)
30
-	 * @uses self::getSecretSite()
31
-	 */
32
-	public static function secret_du_site(): ?string {
33
-		return (self::instance())->getSecretSite();
34
-	}
35
-
36
-	private function __construct(string $file = '') {
37
-		if ($file) {
38
-			$this->file = $file;
39
-		}
40
-		$this->cles = new Cles($this->read());
41
-	}
42
-
43
-	/**
44
-	 * Renvoyer le secret du site
45
-	 *
46
-	 * Le secret du site doit rester aussi secret que possible, et est eternel
47
-	 * On ne doit pas l'exporter
48
-	 *
49
-	 * Le secret est partagé entre une clé disque et une clé bdd
50
-	 *
51
-	 * @return string
52
-	 */
53
-	public function getSecretSite(bool $autoInit = true): ?string {
54
-		$key = $this->getKey('secret_du_site', $autoInit);
55
-		$meta = $this->getMetaKey('secret_du_site', $autoInit);
56
-		// conserve la même longeur.
57
-		return $key ^ $meta;
58
-	}
59
-
60
-	/** Renvoyer le secret des authentifications */
61
-	public function getSecretAuth(bool $autoInit = false): ?string {
62
-		return $this->getKey('secret_des_auth', $autoInit);
63
-	}
64
-	public function save(): bool {
65
-		return ecrire_fichier_securise($this->file, $this->cles->toJson());
66
-	}
67
-
68
-	/**
69
-	 * Fournir une sauvegarde chiffree des cles (a l'aide d'une autre clé, comme le pass d'un auteur)
70
-	 *
71
-	 * @param string $withKey Clé de chiffrage de la sauvegarde
72
-	 * @return string Contenu de la sauvegarde chiffrée générée
73
-	 */
74
-	public function backup(
75
-		#[\SensitiveParameter]
76
-		string $withKey
77
-	): string {
78
-		if (count($this->cles)) {
79
-			return Chiffrement::chiffrer($this->cles->toJson(), $withKey);
80
-		}
81
-		return '';
82
-	}
83
-
84
-	/**
85
-	 * Restaurer les cles manquantes depuis une sauvegarde chiffree des cles
86
-	 * (si la sauvegarde est bien valide)
87
-	 */
88
-	public function restore(
89
-		/** Sauvegarde chiffrée (générée par backup()) */
90
-		string $backup,
91
-		#[\SensitiveParameter]
92
-		string $password_clair,
93
-		#[\SensitiveParameter]
94
-		string $password_hash,
95
-		int $id_auteur
96
-	): bool {
97
-		if (empty($backup)) {
98
-			return false;
99
-		}
100
-
101
-		$sauvegarde = Chiffrement::dechiffrer($backup, $password_clair);
102
-		$json = json_decode($sauvegarde, true);
103
-		if (!$json) {
104
-			return false;
105
-		}
106
-
107
-		// cela semble une sauvegarde valide
108
-		$cles_potentielles = array_map('base64_decode', $json);
109
-
110
-		// il faut faire une double verif sur secret_des_auth
111
-		// pour s'assurer qu'elle permet bien de decrypter le pass de l'auteur qui fournit la sauvegarde
112
-		// et par extension tous les passwords
113
-		if (
114
-			!empty($cles_potentielles['secret_des_auth'])
115
-			&& !Password::verifier($password_clair, $password_hash, $cles_potentielles['secret_des_auth'])
116
-		) {
117
-			spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer' . _LOG_INFO_IMPORTANTE);
118
-			unset($cles_potentielles['secret_des_auth']);
119
-		}
120
-
121
-		// on merge les cles pour recuperer les cles manquantes
122
-		$restauration = false;
123
-		foreach ($cles_potentielles as $name => $key) {
124
-			if (!$this->cles->has($name)) {
125
-				$this->cles->set($name, $key);
126
-				spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer' . _LOG_INFO_IMPORTANTE);
127
-				$restauration = true;
128
-			}
129
-		}
130
-		return $restauration;
131
-	}
132
-
133
-	private function getKey(string $name, bool $autoInit): ?string {
134
-		if ($this->cles->has($name)) {
135
-			return $this->cles->get($name);
136
-		}
137
-		if ($autoInit) {
138
-			$this->cles->generate($name);
139
-			// si l'ecriture de fichier a bien marche on peut utiliser la cle
140
-			if ($this->save()) {
141
-				return $this->cles->get($name);
142
-			}
143
-			// sinon loger et annule la cle generee car il ne faut pas l'utiliser
144
-			spip_log('Echec ecriture du fichier cle ' . $this->file . " ; impossible de generer une cle $name", 'chiffrer' . _LOG_ERREUR);
145
-			$this->cles->delete($name);
146
-		}
147
-		return null;
148
-	}
149
-
150
-	private function getMetaKey(string $name, bool $autoInit = true): ?string {
151
-		if (!isset($GLOBALS['meta'][$name])) {
152
-			include_spip('base/abstract_sql');
153
-			$GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = ' . sql_quote($name, '', 'string'));
154
-		}
155
-		$key = base64_decode($GLOBALS['meta'][$name] ?? '');
156
-		if (strlen($key) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
157
-			return $key;
158
-		}
159
-		if (!$autoInit) {
160
-			return null;
161
-		}
162
-		$key = Chiffrement::keygen();
163
-		ecrire_meta($name, base64_encode($key), 'non');
164
-		lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas
165
-
166
-		return $key;
167
-	}
168
-
169
-	private function read(): array {
170
-		$json = null;
171
-		lire_fichier_securise($this->file, $json);
172
-		if (
173
-			$json
174
-			&& ($json = \json_decode($json, true))
175
-			&& is_array($json)
176
-		) {
177
-			return array_map('base64_decode', $json);
178
-		}
179
-		return [];
180
-	}
16
+    private static array $instances = [];
17
+
18
+    private string $file = _DIR_ETC . 'cles.php';
19
+    private Cles $cles;
20
+
21
+    public static function instance(string $file = ''): self {
22
+        if (empty(self::$instances[$file])) {
23
+            self::$instances[$file] = new self($file);
24
+        }
25
+        return self::$instances[$file];
26
+    }
27
+
28
+    /**
29
+     * Retourne le secret du site (shorthand)
30
+     * @uses self::getSecretSite()
31
+     */
32
+    public static function secret_du_site(): ?string {
33
+        return (self::instance())->getSecretSite();
34
+    }
35
+
36
+    private function __construct(string $file = '') {
37
+        if ($file) {
38
+            $this->file = $file;
39
+        }
40
+        $this->cles = new Cles($this->read());
41
+    }
42
+
43
+    /**
44
+     * Renvoyer le secret du site
45
+     *
46
+     * Le secret du site doit rester aussi secret que possible, et est eternel
47
+     * On ne doit pas l'exporter
48
+     *
49
+     * Le secret est partagé entre une clé disque et une clé bdd
50
+     *
51
+     * @return string
52
+     */
53
+    public function getSecretSite(bool $autoInit = true): ?string {
54
+        $key = $this->getKey('secret_du_site', $autoInit);
55
+        $meta = $this->getMetaKey('secret_du_site', $autoInit);
56
+        // conserve la même longeur.
57
+        return $key ^ $meta;
58
+    }
59
+
60
+    /** Renvoyer le secret des authentifications */
61
+    public function getSecretAuth(bool $autoInit = false): ?string {
62
+        return $this->getKey('secret_des_auth', $autoInit);
63
+    }
64
+    public function save(): bool {
65
+        return ecrire_fichier_securise($this->file, $this->cles->toJson());
66
+    }
67
+
68
+    /**
69
+     * Fournir une sauvegarde chiffree des cles (a l'aide d'une autre clé, comme le pass d'un auteur)
70
+     *
71
+     * @param string $withKey Clé de chiffrage de la sauvegarde
72
+     * @return string Contenu de la sauvegarde chiffrée générée
73
+     */
74
+    public function backup(
75
+        #[\SensitiveParameter]
76
+        string $withKey
77
+    ): string {
78
+        if (count($this->cles)) {
79
+            return Chiffrement::chiffrer($this->cles->toJson(), $withKey);
80
+        }
81
+        return '';
82
+    }
83
+
84
+    /**
85
+     * Restaurer les cles manquantes depuis une sauvegarde chiffree des cles
86
+     * (si la sauvegarde est bien valide)
87
+     */
88
+    public function restore(
89
+        /** Sauvegarde chiffrée (générée par backup()) */
90
+        string $backup,
91
+        #[\SensitiveParameter]
92
+        string $password_clair,
93
+        #[\SensitiveParameter]
94
+        string $password_hash,
95
+        int $id_auteur
96
+    ): bool {
97
+        if (empty($backup)) {
98
+            return false;
99
+        }
100
+
101
+        $sauvegarde = Chiffrement::dechiffrer($backup, $password_clair);
102
+        $json = json_decode($sauvegarde, true);
103
+        if (!$json) {
104
+            return false;
105
+        }
106
+
107
+        // cela semble une sauvegarde valide
108
+        $cles_potentielles = array_map('base64_decode', $json);
109
+
110
+        // il faut faire une double verif sur secret_des_auth
111
+        // pour s'assurer qu'elle permet bien de decrypter le pass de l'auteur qui fournit la sauvegarde
112
+        // et par extension tous les passwords
113
+        if (
114
+            !empty($cles_potentielles['secret_des_auth'])
115
+            && !Password::verifier($password_clair, $password_hash, $cles_potentielles['secret_des_auth'])
116
+        ) {
117
+            spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer' . _LOG_INFO_IMPORTANTE);
118
+            unset($cles_potentielles['secret_des_auth']);
119
+        }
120
+
121
+        // on merge les cles pour recuperer les cles manquantes
122
+        $restauration = false;
123
+        foreach ($cles_potentielles as $name => $key) {
124
+            if (!$this->cles->has($name)) {
125
+                $this->cles->set($name, $key);
126
+                spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer' . _LOG_INFO_IMPORTANTE);
127
+                $restauration = true;
128
+            }
129
+        }
130
+        return $restauration;
131
+    }
132
+
133
+    private function getKey(string $name, bool $autoInit): ?string {
134
+        if ($this->cles->has($name)) {
135
+            return $this->cles->get($name);
136
+        }
137
+        if ($autoInit) {
138
+            $this->cles->generate($name);
139
+            // si l'ecriture de fichier a bien marche on peut utiliser la cle
140
+            if ($this->save()) {
141
+                return $this->cles->get($name);
142
+            }
143
+            // sinon loger et annule la cle generee car il ne faut pas l'utiliser
144
+            spip_log('Echec ecriture du fichier cle ' . $this->file . " ; impossible de generer une cle $name", 'chiffrer' . _LOG_ERREUR);
145
+            $this->cles->delete($name);
146
+        }
147
+        return null;
148
+    }
149
+
150
+    private function getMetaKey(string $name, bool $autoInit = true): ?string {
151
+        if (!isset($GLOBALS['meta'][$name])) {
152
+            include_spip('base/abstract_sql');
153
+            $GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = ' . sql_quote($name, '', 'string'));
154
+        }
155
+        $key = base64_decode($GLOBALS['meta'][$name] ?? '');
156
+        if (strlen($key) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
157
+            return $key;
158
+        }
159
+        if (!$autoInit) {
160
+            return null;
161
+        }
162
+        $key = Chiffrement::keygen();
163
+        ecrire_meta($name, base64_encode($key), 'non');
164
+        lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas
165
+
166
+        return $key;
167
+    }
168
+
169
+    private function read(): array {
170
+        $json = null;
171
+        lire_fichier_securise($this->file, $json);
172
+        if (
173
+            $json
174
+            && ($json = \json_decode($json, true))
175
+            && is_array($json)
176
+        ) {
177
+            return array_map('base64_decode', $json);
178
+        }
179
+        return [];
180
+    }
181 181
 }
Please login to merge, or discard this patch.
ecrire/src/Admin/Bouton.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -7,32 +7,32 @@
 block discarded – undo
7 7
  * privée ou dans un de ses sous menus
8 8
  */
9 9
 class Bouton {
10
-	/** Sous-barre de boutons / onglets */
11
-	public array $sousmenu = [];
10
+    /** Sous-barre de boutons / onglets */
11
+    public array $sousmenu = [];
12 12
 
13
-	/** Position dans le menu */
14
-	public int $position = 0;
13
+    /** Position dans le menu */
14
+    public int $position = 0;
15 15
 
16
-	/** Entrée favorite (sa position dans les favoris) ? */
17
-	public int $favori = 0;
16
+    /** Entrée favorite (sa position dans les favoris) ? */
17
+    public int $favori = 0;
18 18
 
19 19
 
20
-	/**
21
-	 * Définit un bouton
22
-	 */
23
-	public function __construct(
24
-		/** L'icone à mettre dans le bouton */
25
-		public string $icone,
26
-		/** Le nom de l'entrée d'i18n associé */
27
-		public string $libelle,
28
-		/** L'URL de la page (null => ?exec=nom) */
29
-		public ?string $url = null,
30
-		/** Arguments supplémentaires de l'URL */
31
-		public string|array|null $urlArg = null,
32
-		/** URL du javascript */
33
-		public ?string $url2 = null,
34
-		/** Pour ouvrir une fenêtre à part */
35
-		public ?string $target = null
36
-	) {
37
-	}
20
+    /**
21
+     * Définit un bouton
22
+     */
23
+    public function __construct(
24
+        /** L'icone à mettre dans le bouton */
25
+        public string $icone,
26
+        /** Le nom de l'entrée d'i18n associé */
27
+        public string $libelle,
28
+        /** L'URL de la page (null => ?exec=nom) */
29
+        public ?string $url = null,
30
+        /** Arguments supplémentaires de l'URL */
31
+        public string|array|null $urlArg = null,
32
+        /** URL du javascript */
33
+        public ?string $url2 = null,
34
+        /** Pour ouvrir une fenêtre à part */
35
+        public ?string $target = null
36
+    ) {
37
+    }
38 38
 }
Please login to merge, or discard this patch.
ecrire/src/Css/Vars/Collection.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -7,21 +7,21 @@
 block discarded – undo
7 7
  * @internal
8 8
  */
9 9
 class Collection implements \Stringable {
10
-	private array $vars = [];
10
+    private array $vars = [];
11 11
 
12
-	public function add(string $var, string $value) {
13
-		$this->vars[$var] = $value;
14
-	}
12
+    public function add(string $var, string $value) {
13
+        $this->vars[$var] = $value;
14
+    }
15 15
 
16
-	public function getString(): string {
17
-		$string = '';
18
-		foreach ($this->vars as $key => $value) {
19
-			$string .= "$key: $value;\n";
20
-		}
21
-		return $string;
22
-	}
16
+    public function getString(): string {
17
+        $string = '';
18
+        foreach ($this->vars as $key => $value) {
19
+            $string .= "$key: $value;\n";
20
+        }
21
+        return $string;
22
+    }
23 23
 
24
-	public function __toString(): string {
25
-		return $this->getString();
26
-	}
24
+    public function __toString(): string {
25
+        return $this->getString();
26
+    }
27 27
 }
Please login to merge, or discard this patch.
ecrire/plugins/get_infos.php 1 patch
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -32,110 +32,110 @@  discard block
 block discarded – undo
32 32
  * @return array
33 33
  */
34 34
 function plugins_get_infos_dist($plug = false, $reload = false, $dir = _DIR_PLUGINS, $clean_old = false) {
35
-	$contenu = null;
36
-	$res = null;
37
-	static $cache = '';
38
-	static $filecache = '';
39
-
40
-	if ($cache === '') {
41
-		$filecache = _DIR_TMP . 'plugin_xml_cache.gz';
42
-		if (is_file($filecache)) {
43
-			lire_fichier($filecache, $contenu);
44
-			$cache = unserialize($contenu);
45
-		}
46
-		if (!is_array($cache)) {
47
-			$cache = [];
48
-		}
49
-	}
50
-
51
-	if (defined('_VAR_MODE') && _VAR_MODE == 'recalcul') {
52
-		$reload = true;
53
-	}
54
-
55
-	if ($plug === false) {
56
-		ecrire_fichier($filecache, serialize($cache));
57
-
58
-		return $cache;
59
-	} elseif (is_string($plug)) {
60
-		$res = plugins_get_infos_un($plug, $reload, $dir, $cache);
61
-	} elseif (is_array($plug)) {
62
-		$res = false;
63
-		if (!$reload) {
64
-			$reload = -1;
65
-		}
66
-		foreach ($plug as $nom) {
67
-			$res |= plugins_get_infos_un($nom, $reload, $dir, $cache);
68
-		}
69
-
70
-		// Nettoyer le cache des vieux plugins qui ne sont plus la
71
-		if ($clean_old && isset($cache[$dir]) && (is_countable($cache[$dir]) ? count($cache[$dir]) : 0)) {
72
-			foreach (array_keys($cache[$dir]) as $p) {
73
-				if (!in_array($p, $plug)) {
74
-					unset($cache[$dir][$p]);
75
-				}
76
-			}
77
-		}
78
-	}
79
-	if ($res) {
80
-		ecrire_fichier($filecache, serialize($cache));
81
-	}
82
-	if (!isset($cache[$dir])) {
83
-		return [];
84
-	}
85
-	if (is_string($plug)) {
86
-		return $cache[$dir][$plug] ?? [];
87
-	} else {
88
-		return $cache[$dir];
89
-	}
35
+    $contenu = null;
36
+    $res = null;
37
+    static $cache = '';
38
+    static $filecache = '';
39
+
40
+    if ($cache === '') {
41
+        $filecache = _DIR_TMP . 'plugin_xml_cache.gz';
42
+        if (is_file($filecache)) {
43
+            lire_fichier($filecache, $contenu);
44
+            $cache = unserialize($contenu);
45
+        }
46
+        if (!is_array($cache)) {
47
+            $cache = [];
48
+        }
49
+    }
50
+
51
+    if (defined('_VAR_MODE') && _VAR_MODE == 'recalcul') {
52
+        $reload = true;
53
+    }
54
+
55
+    if ($plug === false) {
56
+        ecrire_fichier($filecache, serialize($cache));
57
+
58
+        return $cache;
59
+    } elseif (is_string($plug)) {
60
+        $res = plugins_get_infos_un($plug, $reload, $dir, $cache);
61
+    } elseif (is_array($plug)) {
62
+        $res = false;
63
+        if (!$reload) {
64
+            $reload = -1;
65
+        }
66
+        foreach ($plug as $nom) {
67
+            $res |= plugins_get_infos_un($nom, $reload, $dir, $cache);
68
+        }
69
+
70
+        // Nettoyer le cache des vieux plugins qui ne sont plus la
71
+        if ($clean_old && isset($cache[$dir]) && (is_countable($cache[$dir]) ? count($cache[$dir]) : 0)) {
72
+            foreach (array_keys($cache[$dir]) as $p) {
73
+                if (!in_array($p, $plug)) {
74
+                    unset($cache[$dir][$p]);
75
+                }
76
+            }
77
+        }
78
+    }
79
+    if ($res) {
80
+        ecrire_fichier($filecache, serialize($cache));
81
+    }
82
+    if (!isset($cache[$dir])) {
83
+        return [];
84
+    }
85
+    if (is_string($plug)) {
86
+        return $cache[$dir][$plug] ?? [];
87
+    } else {
88
+        return $cache[$dir];
89
+    }
90 90
 }
91 91
 
92 92
 
93 93
 function plugins_get_infos_un($plug, $reload, $dir, &$cache) {
94
-	if (!is_readable($file = "$dir$plug/paquet.xml")) {
95
-		return false;
96
-	}
97
-	$time = (int) @filemtime($file);
98
-	if ($time < 0) {
99
-		return false;
100
-	}
101
-	$md5 = md5_file($file);
102
-
103
-	$pcache = $cache[$dir][$plug] ?? ['filemtime' => 0, 'md5_file' => ''];
104
-
105
-	// si le cache est valide
106
-	if (
107
-		(int) $reload <= 0
108
-		&& $time > 0
109
-		&& $time <= $pcache['filemtime']
110
-		&& $md5 == $pcache['md5_file']
111
-	) {
112
-		return false;
113
-	}
114
-
115
-	// si on arrive pas a lire le fichier, se contenter du cache
116
-	if (!($texte = spip_file_get_contents($file))) {
117
-		return false;
118
-	}
119
-
120
-	$f = charger_fonction('infos_paquet', 'plugins');
121
-	$ret = $f($texte, $plug, $dir);
122
-	$ret['filemtime'] = $time;
123
-	$ret['md5_file'] = $md5;
124
-	// Si on lit le paquet.xml de SPIP, on rajoute un procure php afin que les plugins puissent
125
-	// utiliser un necessite php. SPIP procure donc la version php courante du serveur.
126
-	// chaque librairie php est aussi procurée, par exemple 'php:curl'.
127
-	if (isset($ret['prefix']) && $ret['prefix'] == 'spip') {
128
-		$ret['procure']['php'] = ['nom' => 'php', 'version' => phpversion()];
129
-		foreach (get_loaded_extensions() as $ext) {
130
-			$ret['procure']['php:' . $ext] = ['nom' => 'php:' . $ext, 'version' => phpversion($ext)];
131
-		}
132
-	}
133
-	$diff = ($ret != $pcache);
134
-
135
-	if ($diff) {
136
-		$cache[$dir][$plug] = $ret;
94
+    if (!is_readable($file = "$dir$plug/paquet.xml")) {
95
+        return false;
96
+    }
97
+    $time = (int) @filemtime($file);
98
+    if ($time < 0) {
99
+        return false;
100
+    }
101
+    $md5 = md5_file($file);
102
+
103
+    $pcache = $cache[$dir][$plug] ?? ['filemtime' => 0, 'md5_file' => ''];
104
+
105
+    // si le cache est valide
106
+    if (
107
+        (int) $reload <= 0
108
+        && $time > 0
109
+        && $time <= $pcache['filemtime']
110
+        && $md5 == $pcache['md5_file']
111
+    ) {
112
+        return false;
113
+    }
114
+
115
+    // si on arrive pas a lire le fichier, se contenter du cache
116
+    if (!($texte = spip_file_get_contents($file))) {
117
+        return false;
118
+    }
119
+
120
+    $f = charger_fonction('infos_paquet', 'plugins');
121
+    $ret = $f($texte, $plug, $dir);
122
+    $ret['filemtime'] = $time;
123
+    $ret['md5_file'] = $md5;
124
+    // Si on lit le paquet.xml de SPIP, on rajoute un procure php afin que les plugins puissent
125
+    // utiliser un necessite php. SPIP procure donc la version php courante du serveur.
126
+    // chaque librairie php est aussi procurée, par exemple 'php:curl'.
127
+    if (isset($ret['prefix']) && $ret['prefix'] == 'spip') {
128
+        $ret['procure']['php'] = ['nom' => 'php', 'version' => phpversion()];
129
+        foreach (get_loaded_extensions() as $ext) {
130
+            $ret['procure']['php:' . $ext] = ['nom' => 'php:' . $ext, 'version' => phpversion($ext)];
131
+        }
132
+    }
133
+    $diff = ($ret != $pcache);
134
+
135
+    if ($diff) {
136
+        $cache[$dir][$plug] = $ret;
137 137
 #       echo count($cache[$dir]), $dir,$plug, " $reloadc<br>";
138
-	}
138
+    }
139 139
 
140
-	return $diff;
140
+    return $diff;
141 141
 }
Please login to merge, or discard this patch.
ecrire/plugins/afficher_nom_plugin.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -10,59 +10,59 @@
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 include_spip('inc/charsets');
16 16
 include_spip('inc/texte');
17 17
 include_spip('plugins/afficher_plugin');
18 18
 
19 19
 function plugins_afficher_nom_plugin_dist(
20
-	$url_page,
21
-	$plug_file,
22
-	$checked,
23
-	$actif,
24
-	$expose = false,
25
-	$class_li = 'item',
26
-	$dir_plugins = _DIR_PLUGINS
20
+    $url_page,
21
+    $plug_file,
22
+    $checked,
23
+    $actif,
24
+    $expose = false,
25
+    $class_li = 'item',
26
+    $dir_plugins = _DIR_PLUGINS
27 27
 ) {
28
-	static $id_input = 0;
29
-	static $versions = [];
28
+    static $id_input = 0;
29
+    static $versions = [];
30 30
 
31
-	$erreur = false;
32
-	$s = '';
31
+    $erreur = false;
32
+    $s = '';
33 33
 
34
-	$get_infos = charger_fonction('get_infos', 'plugins');
35
-	$info = $get_infos($plug_file, false, $dir_plugins);
34
+    $get_infos = charger_fonction('get_infos', 'plugins');
35
+    $info = $get_infos($plug_file, false, $dir_plugins);
36 36
 
37
-	// numerotons les occurences d'un meme prefix
38
-	$versions[$info['prefix']] = isset($versions[$info['prefix']]) ? $versions[$info['prefix']] + 1 : '';
39
-	$id = $info['prefix'] . $versions[$info['prefix']];
37
+    // numerotons les occurences d'un meme prefix
38
+    $versions[$info['prefix']] = isset($versions[$info['prefix']]) ? $versions[$info['prefix']] + 1 : '';
39
+    $id = $info['prefix'] . $versions[$info['prefix']];
40 40
 
41
-	$class = $class_li;
42
-	$class .= $actif ? ' actif' : '';
43
-	$class .= $expose ? ' on' : '';
44
-	$erreur = isset($info['erreur']);
45
-	if ($erreur) {
46
-		$class .= ' error';
47
-	}
48
-	$s .= "<li id='$id' class='$class'>";
41
+    $class = $class_li;
42
+    $class .= $actif ? ' actif' : '';
43
+    $class .= $expose ? ' on' : '';
44
+    $erreur = isset($info['erreur']);
45
+    if ($erreur) {
46
+        $class .= ' error';
47
+    }
48
+    $s .= "<li id='$id' class='$class'>";
49 49
 
50
-	// Cartouche Resume
51
-	$s .= "<div class='resume'>";
50
+    // Cartouche Resume
51
+    $s .= "<div class='resume'>";
52 52
 
53
-	$prefix = $info['prefix'];
54
-	$dir = "$dir_plugins$plug_file/lang/$prefix";
55
-	$desc = plugin_propre($info['description'], $dir);
56
-	$url_stat = parametre_url($url_page, 'plugin', $dir_plugins . $plug_file);
53
+    $prefix = $info['prefix'];
54
+    $dir = "$dir_plugins$plug_file/lang/$prefix";
55
+    $desc = plugin_propre($info['description'], $dir);
56
+    $url_stat = parametre_url($url_page, 'plugin', $dir_plugins . $plug_file);
57 57
 
58
-	$s .= "<strong class='nom'>" . typo($info['nom']) . '</strong>';
59
-	$s .= " <span class='version'>" . $info['version'] . '</span>';
60
-	$s .= " <span class='etat'> - " . plugin_etat_en_clair($info['etat']) . '</span>';
61
-	$s .= '</div>';
58
+    $s .= "<strong class='nom'>" . typo($info['nom']) . '</strong>';
59
+    $s .= " <span class='version'>" . $info['version'] . '</span>';
60
+    $s .= " <span class='etat'> - " . plugin_etat_en_clair($info['etat']) . '</span>';
61
+    $s .= '</div>';
62 62
 
63
-	if ($erreur) {
64
-		$s .= "<div class='erreur'>" . implode('<br >', $info['erreur']) . '</div>';
65
-	}
63
+    if ($erreur) {
64
+        $s .= "<div class='erreur'>" . implode('<br >', $info['erreur']) . '</div>';
65
+    }
66 66
 
67
-	return $s . '</li>';
67
+    return $s . '</li>';
68 68
 }
Please login to merge, or discard this patch.
prive/formulaires/configurer_reducteur.php 1 patch
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -27,24 +27,24 @@  discard block
 block discarded – undo
27 27
  *     Environnement du formulaire
28 28
  **/
29 29
 function formulaires_configurer_reducteur_charger_dist() {
30
-	$valeurs = [];
31
-	foreach (
32
-		[
33
-			'image_process',
34
-			'formats_graphiques',
35
-			'creer_preview',
36
-			'taille_preview',
37
-		] as $m
38
-	) {
39
-		$valeurs[$m] = $GLOBALS['meta'][$m] ?? null;
40
-	}
41
-
42
-	$valeurs['taille_preview'] = (int) $valeurs['taille_preview'];
43
-	if ($valeurs['taille_preview'] < 10) {
44
-		$valeurs['taille_preview'] = 120;
45
-	}
46
-
47
-	return $valeurs;
30
+    $valeurs = [];
31
+    foreach (
32
+        [
33
+            'image_process',
34
+            'formats_graphiques',
35
+            'creer_preview',
36
+            'taille_preview',
37
+        ] as $m
38
+    ) {
39
+        $valeurs[$m] = $GLOBALS['meta'][$m] ?? null;
40
+    }
41
+
42
+    $valeurs['taille_preview'] = (int) $valeurs['taille_preview'];
43
+    if ($valeurs['taille_preview'] < 10) {
44
+        $valeurs['taille_preview'] = 120;
45
+    }
46
+
47
+    return $valeurs;
48 48
 }
49 49
 
50 50
 
@@ -55,52 +55,52 @@  discard block
 block discarded – undo
55 55
  *     Retours des traitements
56 56
  **/
57 57
 function formulaires_configurer_reducteur_traiter_dist() {
58
-	$res = ['editable' => true];
59
-
60
-	if (is_array($image_process = _request('image_process_'))) {
61
-		$image_process = array_keys($image_process);
62
-		$image_process = reset($image_process);
63
-
64
-		// application du choix de vignette
65
-		if ($image_process) {
66
-			// mettre a jour les formats graphiques lisibles
67
-			switch ($image_process) {
68
-				case 'gd2':
69
-					$formats_graphiques = $GLOBALS['meta']['gd_formats_read'];
70
-					break;
71
-				case 'netpbm':
72
-					$formats_graphiques = $GLOBALS['meta']['netpbm_formats'];
73
-					break;
74
-				case 'convert':
75
-				case 'imagick':
76
-					$formats_graphiques = 'gif,jpg,png,webp';
77
-					break;
78
-				default: #debug
79
-					$formats_graphiques = '';
80
-					$image_process = 'non';
81
-					break;
82
-			}
83
-			ecrire_meta('formats_graphiques', $formats_graphiques, 'non');
84
-			ecrire_meta('image_process', $image_process, 'non');
85
-		}
86
-	}
87
-
88
-	foreach (
89
-		[
90
-			'creer_preview'
91
-		] as $m
92
-	) {
93
-		if (!is_null($v = _request($m))) {
94
-			ecrire_meta($m, $v == 'oui' ? 'oui' : 'non');
95
-		}
96
-	}
97
-	if (!is_null($v = _request('taille_preview'))) {
98
-		ecrire_meta('taille_preview', (int) $v);
99
-	}
100
-
101
-	$res['message_ok'] = _T('config_info_enregistree');
102
-
103
-	return $res;
58
+    $res = ['editable' => true];
59
+
60
+    if (is_array($image_process = _request('image_process_'))) {
61
+        $image_process = array_keys($image_process);
62
+        $image_process = reset($image_process);
63
+
64
+        // application du choix de vignette
65
+        if ($image_process) {
66
+            // mettre a jour les formats graphiques lisibles
67
+            switch ($image_process) {
68
+                case 'gd2':
69
+                    $formats_graphiques = $GLOBALS['meta']['gd_formats_read'];
70
+                    break;
71
+                case 'netpbm':
72
+                    $formats_graphiques = $GLOBALS['meta']['netpbm_formats'];
73
+                    break;
74
+                case 'convert':
75
+                case 'imagick':
76
+                    $formats_graphiques = 'gif,jpg,png,webp';
77
+                    break;
78
+                default: #debug
79
+                    $formats_graphiques = '';
80
+                    $image_process = 'non';
81
+                    break;
82
+            }
83
+            ecrire_meta('formats_graphiques', $formats_graphiques, 'non');
84
+            ecrire_meta('image_process', $image_process, 'non');
85
+        }
86
+    }
87
+
88
+    foreach (
89
+        [
90
+            'creer_preview'
91
+        ] as $m
92
+    ) {
93
+        if (!is_null($v = _request($m))) {
94
+            ecrire_meta($m, $v == 'oui' ? 'oui' : 'non');
95
+        }
96
+    }
97
+    if (!is_null($v = _request('taille_preview'))) {
98
+        ecrire_meta('taille_preview', (int) $v);
99
+    }
100
+
101
+    $res['message_ok'] = _T('config_info_enregistree');
102
+
103
+    return $res;
104 104
 }
105 105
 
106 106
 /**
@@ -113,17 +113,17 @@  discard block
 block discarded – undo
113 113
  *     URL d'action pour tester la librairie graphique en créant une vignette
114 114
  **/
115 115
 function url_vignette_choix(string $process): string {
116
-	$ok = match ($process) {
117
-		'gd2' => function_exists('ImageCreateTrueColor'),
118
-		'netpbm' => !(defined('_PNMSCALE_COMMAND') && _PNMSCALE_COMMAND == ''),
119
-		'imagick' => method_exists(\Imagick::class, 'readImage'),
120
-		'convert' => !(defined('_CONVERT_COMMAND') && _CONVERT_COMMAND == ''),
121
-		default => false,
122
-	};
123
-
124
-	if (!$ok) {
125
-		return '';
126
-	}
127
-
128
-	return generer_url_action('tester', "arg=$process&time=" . time());
116
+    $ok = match ($process) {
117
+        'gd2' => function_exists('ImageCreateTrueColor'),
118
+        'netpbm' => !(defined('_PNMSCALE_COMMAND') && _PNMSCALE_COMMAND == ''),
119
+        'imagick' => method_exists(\Imagick::class, 'readImage'),
120
+        'convert' => !(defined('_CONVERT_COMMAND') && _CONVERT_COMMAND == ''),
121
+        default => false,
122
+    };
123
+
124
+    if (!$ok) {
125
+        return '';
126
+    }
127
+
128
+    return generer_url_action('tester', "arg=$process&time=" . time());
129 129
 }
Please login to merge, or discard this patch.