Overview
Comment:Utilisation de safe_unlink/safe_mkdir partout
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | stable
Files: files | file ages | folders
SHA1: 933b3302727a3403d2e3c747b2542296316cf3d8
User & Date: bohwaz on 2018-09-22 09:59:55
Other Links: manifest | tags
References
2020-12-08
23:25 Wiki page "Changelog/0.9" artifact: b9c916b4d1 user: bohwaz
Context
2018-10-27
22:56
Merge version développement, sortie 0.9.0 check-in: 07c00c16dd user: bohwaz tags: trunk, stable, 0.9.0
2018-09-22
09:59
Utilisation de safe_unlink/safe_mkdir partout check-in: 933b330272 user: bohwaz tags: trunk, stable
09:56
Ne pas permettre d'avoir 0 comme numéro de membre check-in: a9489029fb user: bohwaz tags: trunk, stable
2018-09-13
22:21
Utilisation de safe_unlink/safe_mkdir partout check-in: 85d5a50a94 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Install.php from [e286e959c9] to [d6545e900e].

125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
	static public function checkAndCreateDirectories()
	{
		// Vérifier que les répertoires vides existent, sinon les créer
		$paths = [DATA_ROOT, PLUGINS_ROOT, CACHE_ROOT, CACHE_ROOT . '/static', CACHE_ROOT . '/compiled'];

		foreach ($paths as $path)
		{
		    if (!file_exists($path))
		    {
		        mkdir($path, 0777, true);
		    }

		    if (!is_dir($path))
		    {
		    	throw new UserException('Le répertoire '.$path.' n\'existe pas ou n\'est pas un répertoire.');
		    }

		    // On en profite pour vérifier qu'on peut y lire et écrire







<
<
|
<







125
126
127
128
129
130
131


132

133
134
135
136
137
138
139
	static public function checkAndCreateDirectories()
	{
		// Vérifier que les répertoires vides existent, sinon les créer
		$paths = [DATA_ROOT, PLUGINS_ROOT, CACHE_ROOT, CACHE_ROOT . '/static', CACHE_ROOT . '/compiled'];

		foreach ($paths as $path)
		{


			Utils::safe_mkdir($path);


		    if (!is_dir($path))
		    {
		    	throw new UserException('Le répertoire '.$path.' n\'existe pas ou n\'est pas un répertoire.');
		    }

		    // On en profite pour vérifier qu'on peut y lire et écrire

Modified src/include/lib/Garradin/Plugin.php from [a13d03f59d] to [d5458d89d2].

547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
		catch (\Exception $e)
		{
			throw new UserException('Le téléchargement du plugin '.$id.' a échoué : ' . $e->getMessage());
		}

		if (!self::checkHash($id))
		{
			unlink(PLUGINS_ROOT . '/' . $id . '.tar.gz');
			throw new \RuntimeException('L\'archive du plugin '.$id.' est corrompue (le hash SHA1 ne correspond pas).');
		}

		self::install($id, true);

		return true;
	}







|







547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
		catch (\Exception $e)
		{
			throw new UserException('Le téléchargement du plugin '.$id.' a échoué : ' . $e->getMessage());
		}

		if (!self::checkHash($id))
		{
			Utils::safe_unlink(PLUGINS_ROOT . '/' . $id . '.tar.gz');
			throw new \RuntimeException('L\'archive du plugin '.$id.' est corrompue (le hash SHA1 ne correspond pas).');
		}

		self::install($id, true);

		return true;
	}

Modified src/include/lib/Garradin/Sauvegarde.php from [ba865c4dc1] to [3200010089].

142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
	{
		if (preg_match('!\.\.+!', $file) || !preg_match('!^[\w\d._-]+\.sqlite$!i', $file) 
			|| $file == basename(DB_FILE))
		{
			throw new UserException('Nom de fichier non valide.');
		}

		return unlink(DATA_ROOT . '/' . $file);
	}

	/**
	 * Renvoie sur la sortie courante le contenu du fichier de base de données courant
	 * @return boolean true
	 */
	public function dump()







|







142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
	{
		if (preg_match('!\.\.+!', $file) || !preg_match('!^[\w\d._-]+\.sqlite$!i', $file) 
			|| $file == basename(DB_FILE))
		{
			throw new UserException('Nom de fichier non valide.');
		}

		return Utils::safe_unlink(DATA_ROOT . '/' . $file);
	}

	/**
	 * Renvoie sur la sortie courante le contenu du fichier de base de données courant
	 * @return boolean true
	 */
	public function dump()
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
			}
		}

		$r = $this->restoreDB($file['tmp_name'], $user_id);

		if ($r)
		{
			unlink($file['tmp_name']);
		}

		return $r;
	}

	/**
	 * Vérifie l'intégrité d'une sauvegarde Garradin







|







227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
			}
		}

		$r = $this->restoreDB($file['tmp_name'], $user_id);

		if ($r)
		{
			Utils::safe_unlink($file['tmp_name']);
		}

		return $r;
	}

	/**
	 * Vérifie l'intégrité d'une sauvegarde Garradin

Modified src/include/lib/Garradin/Squelette.php from [a6a2b8cd25] to [fc1698f7ac].

878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896

897

898
899
900
901
902
903
904

    static private function compile_store($tpl, $content)
    {
        $path = self::compile_get_path($tpl);

        if (!file_exists(dirname($path)))
        {
            mkdir(dirname($path), 0777, true);
        }

        file_put_contents($path, $content);
        return true;
    }

    static public function compile_clear($tpl)
    {
        $path = self::compile_get_path($tpl);

        if (file_exists($path))

            unlink($path);


        return true;
    }

    protected function getVariable($var)
    {
        if (isset($this->current[$var]))







|











>
|
>







878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906

    static private function compile_store($tpl, $content)
    {
        $path = self::compile_get_path($tpl);

        if (!file_exists(dirname($path)))
        {
            Utils::safe_mkdir(dirname($path), 0777, true);
        }

        file_put_contents($path, $content);
        return true;
    }

    static public function compile_clear($tpl)
    {
        $path = self::compile_get_path($tpl);

        if (file_exists($path))
        {
            Utils::safe_unlink($path);
        }

        return true;
    }

    protected function getVariable($var)
    {
        if (isset($this->current[$var]))
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
    static public function resetSource($template)
    {
        if (!preg_match('!^[\w\d_-]+(?:\.[\w\d_-]+)*$!i', $template))
            return false;

        if (file_exists(DATA_ROOT . '/www/squelettes/' . $template))
        {
            return unlink(DATA_ROOT . '/www/squelettes/' . $template);
        }

        return false;
    }

    static public function listSources()
    {
        if (!file_exists(DATA_ROOT . '/www/squelettes'))
        {
            mkdir(DATA_ROOT . '/www/squelettes', 0775, true);
        }

        $sources = [];

        $dir = dir(ROOT . '/www/squelettes-dist');

        while ($file = $dir->read())







|









|







953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
    static public function resetSource($template)
    {
        if (!preg_match('!^[\w\d_-]+(?:\.[\w\d_-]+)*$!i', $template))
            return false;

        if (file_exists(DATA_ROOT . '/www/squelettes/' . $template))
        {
            return Utils::safe_unlink(DATA_ROOT . '/www/squelettes/' . $template);
        }

        return false;
    }

    static public function listSources()
    {
        if (!file_exists(DATA_ROOT . '/www/squelettes'))
        {
            Utils::safe_mkdir(DATA_ROOT . '/www/squelettes', 0775, true);
        }

        $sources = [];

        $dir = dir(ROOT . '/www/squelettes-dist');

        while ($file = $dir->read())

Modified src/include/lib/Garradin/Static_Cache.php from [453588f5aa] to [1abb2553b4].

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

	protected static function _getCacheDir()
	{
		$dir = CACHE_ROOT . '/static';

		if (!file_exists($dir))
		{
			mkdir(CACHE_ROOT . '/static', 0777, true);
		}

		return CACHE_ROOT . '/static';
	}

	protected static function _getCachePath($id)
	{







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

	protected static function _getCacheDir()
	{
		$dir = CACHE_ROOT . '/static';

		if (!file_exists($dir))
		{
			Utils::safe_mkdir(CACHE_ROOT . '/static', 0777, true);
		}

		return CACHE_ROOT . '/static';
	}

	protected static function _getCachePath($id)
	{
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
	{
		return file_exists(self::_getCachePath($id));
	}

	static public function remove($id)
	{
		$path = self::_getCachePath($id);
		return @unlink($path);
	}

	static public function clean($expire = self::CLEAN_EXPIRE)
	{
		$dir = self::_getCacheDir();
		$d = dir($dir);

		$expire = time() - $expire;

		while ($file = $d->read())
		{
			if ($file[0] == '.')
			{
				continue;
			}

			if (filemtime($dir . '/' . $file) > $expire)
			{
				unlink($dir . '/' . $file);
			}
		}

		$d->close();

		return true;
	}
}







|


















|








82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
	{
		return file_exists(self::_getCachePath($id));
	}

	static public function remove($id)
	{
		$path = self::_getCachePath($id);
		return Utils::safe_unlink($path);
	}

	static public function clean($expire = self::CLEAN_EXPIRE)
	{
		$dir = self::_getCacheDir();
		$d = dir($dir);

		$expire = time() - $expire;

		while ($file = $d->read())
		{
			if ($file[0] == '.')
			{
				continue;
			}

			if (filemtime($dir . '/' . $file) > $expire)
			{
				Utils::safe_unlink($dir . '/' . $file);
			}
		}

		$d->close();

		return true;
	}
}

Modified src/include/lib/Garradin/Template.php from [8050b58d78] to [0415690ed3].

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
	{
	}

	public function __construct()
	{
		if (!file_exists(CACHE_ROOT . '/compiled'))
		{
			mkdir(CACHE_ROOT . '/compiled', 0777, true);
		}

		self::setCompileDir(CACHE_ROOT . '/compiled');
		self::setTemplateDir(ROOT . '/templates');

		parent::__construct();








|







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
	{
	}

	public function __construct()
	{
		if (!file_exists(CACHE_ROOT . '/compiled'))
		{
			Utils::safe_mkdir(CACHE_ROOT . '/compiled', 0777, true);
		}

		self::setCompileDir(CACHE_ROOT . '/compiled');
		self::setTemplateDir(ROOT . '/templates');

		parent::__construct();

Modified src/include/lib/Garradin/Utils.php from [4680da7c34] to [df46f1372d].

477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493






















494
495
496
497
498
499
500
        $path = CACHE_ROOT . '/' . $path;
        $dir = dir($path);

        while ($file = $dir->read())
        {
            if ($file[0] != '.')
            {
            	if (file_exists($path . DIRECTORY_SEPARATOR . $file))
            	{
                	unlink($path . DIRECTORY_SEPARATOR . $file);
                }
            }
        }

        $dir->close();
        return true;
    }























    static public function suggestPassword()
    {
        return Security::getRandomPassphrase(ROOT . '/include/data/dictionary.fr');
    }

    static public function checkIBAN($value)







<
<
|
<






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







477
478
479
480
481
482
483


484

485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
        $path = CACHE_ROOT . '/' . $path;
        $dir = dir($path);

        while ($file = $dir->read())
        {
            if ($file[0] != '.')
            {


                self::safe_unlink($path . DIRECTORY_SEPARATOR . $file);

            }
        }

        $dir->close();
        return true;
    }

    static public function safe_unlink($path)
    {
        if (!@unlink($path))
        {
            return true;
        }
        
        if (!file_exists($path))
        {
            return true;
        }

        throw new \RuntimeException(sprintf('Impossible de supprimer le fichier %s: %s', $path, error_get_last()));

        return true;
    }

    static public function safe_mkdir($path, $mode = 0777, $recursive = false)
    {
        return @mkdir($path, $mode, $recursive) || is_dir($path);
    }

    static public function suggestPassword()
    {
        return Security::getRandomPassphrase(ROOT . '/include/data/dictionary.fr');
    }

    static public function checkIBAN($value)
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
            if (is_dir($path . '/' . $file))
            {
                if (!self::deleteRecursive($path . '/' . $file))
                    return false;
            }
            else
            {
                unlink($path . '/' . $file);
            }
        }

        $dir->close();
        rmdir($path);

        return true;







|







678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
            if (is_dir($path . '/' . $file))
            {
                if (!self::deleteRecursive($path . '/' . $file))
                    return false;
            }
            else
            {
                utils::safe_unlink($path . '/' . $file);
            }
        }

        $dir->close();
        rmdir($path);

        return true;