PEEL Shopping
Open source ecommerce : PEEL Shopping
Integrity.php
Go to the documentation of this file.
1 <?php
2 // This file should be in UTF8 without BOM - Accents examples: éèê
3 // +----------------------------------------------------------------------+
4 // | Copyright (c) 2004-2015 Advisto SAS, service PEEL - contact@peel.fr |
5 // +----------------------------------------------------------------------+
6 // | This file is part of PEEL Shopping 8.0.0, which is subject to an |
7 // | opensource GPL license: you are allowed to customize the code |
8 // | for your own needs, but must keep your changes under GPL |
9 // | More information: https://www.peel.fr/lire/licence-gpl-70.html |
10 // +----------------------------------------------------------------------+
11 // | Author: Advisto SAS, RCS 479 205 452, France, https://www.peel.fr/ |
12 // +----------------------------------------------------------------------+
13 // $Id: Integrity.php 46935 2015-09-18 08:49:48Z gboussin $
14 if (!defined('IN_PEEL')) {
15  die();
16 }
17 
26 class Integrity {
27 
28  protected $_path;
29  protected $_tree = array();
30 
35  public function __construct($path) {
36  if(substr($path,-1) != "/"){
37  $this->_path = $path."/";
38  } else {
39  $this->_path = $path;
40  }
41  $this->_getFileList();
42  }
43 
50  public function checkMD5Hashes($file){
51  if (!is_readable($file)) {
52  return FALSE;
53  }
54  $file = file($file);
55  $hashes = array();
56  foreach ($file as $line) {
57  $temp = explode(' ', $line);
58  $hashes[trim($temp[1])] = $temp[0];
59  }
60  $modifies = array();
61 
62  /* busca los archivos añadidos */
63  foreach($this->_tree as $key => $value){
64  if(!array_key_exists($key, $hashes)) {
65  $modifies[] = $this->_getFileStats($key,'added');
66  }
67  }
68  /* busca archivos eliminados */
69  foreach($hashes as $key => $value){
70  if(!array_key_exists($key, $this->_tree)) {
71  $modifies[] = $this->_reportFileMissing($key);
72  }
73  }
74  /* busca archivos modificados */
75  foreach($this->_tree as $key => $value){
76  if(array_key_exists($key, $hashes)) {
77  if($value != $hashes[$key]){
78  $modifies[] = $this->_getFileStats($key,'modified');
79  }
80  }
81  }
82 
83  return $modifies;
84  }
85 
92  public function getMD5Hashes($file = null){
93  if(!isset($file)){
94  $file = date('YmdHis').".md5";
95  }
96  $hashes = '';
97  foreach ($this->_tree as $key => $value){
98  $hashes .= $value." ".$key."\n";
99  }
100  return file_put_contents($file, $hashes);
101  }
102 
109  private function _getFileList($path = null){
110  if(!$path){
111  $path = $this->_path;
112  }
113  if(!is_dir($path)){
114  return FALSE;
115  }
116  $root = opendir($path);
117  while($entry = readdir($root)) {
118  if ($entry != "." && $entry != ".." && !in_array($entry, array('JShield', 'cache', 'upload', 'compile', 'installation', 'sessions'))) {
119  if (is_dir($path.$entry)){
120  $this->_getFileList($path.$entry."/");
121  } else {
122  $this->_tree[str_replace($this->_path,"",$path.$entry)] = md5_file($path.$entry);
123  }
124  }
125  }
126  closedir($root);
127  return $this->_tree;
128  }
129 
135  private function _getFileStats($file,$stat){
136  if(is_readable($this->_path.$file)) {
137  $mdata = stat($this->_path.$file);
138  return array(
139  'filename' => $file,
140  'stat' => $stat,
141  'uid' => $mdata[4],
142  'gid' => $mdata[5],
143  'size' => $mdata[7],
144  'lastAccess' => date('Y-m-d H:i:s',$mdata[8]),
145  'lastModification' => date('Y-m-d H:i:s',$mdata[9])
146  );
147  }
148  }
149 
155  private function _reportFileMissing($file){
156  return array(
157  'filename' => $file,
158  'stat' => 'deleted',
159  'uid' => null,
160  'gid' => null,
161  'size' => null,
162  'lastAccess' => null,
163  'lastModification' => null
164  );
165  }
166 }
__construct($path)
Prepara la ruta para iniciar la comprobacion.
Definition: Integrity.php:35
getMD5Hashes($file=null)
Genera un archivo con las firmas md5 de los archivos del directorio dado.
Definition: Integrity.php:92
checkMD5Hashes($file)
Verifica las firmas MD5 de los archivos y los cruza con los del archivo dado para ver diferencias...
Definition: Integrity.php:50

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:29:57 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.