fogproject  1.5.9
About: FOG is a Linux-based network computer cloning solution for Windows, Mac OSX and various Linux distributions that ties together a few open-source tools with a PHP-based web interface. FOG doesn’t use any boot disks, or CDs; everything is done via TFTP and PXE.
  Fossies Dox: fogproject-1.5.9.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

fileintegrity.class.php
Go to the documentation of this file.
1 <?php
23 {
29  protected $databaseTable = 'fileChecksums';
35  protected $databaseFields = array(
36  'id' => 'fcsID',
37  'storagenodeID' => 'fcsStorageNodeID',
38  'modtime' => 'fcsFileModTime',
39  'checksum' => 'fcsFileChecksum',
40  'path' => 'fcsFilePath',
41  'status' => 'fcsStatus',
42  );
48  protected $databaseFieldsRequired = array(
49  'storagenodeID',
50  'path',
51  );
57  protected $additionalFields = array(
58  'storagenode',
59  );
65  private $_imagePaths = array();
71  private $_snapinFiles = array();
77  public function getThisNode()
78  {
79  $this->set('storagenode', self::getClass('StorageNode'));
81  foreach ((array)self::getClass('StorageNodeManager')
82  ->find(array('isEnabled' => 1)) as &$StorageNode
83  ) {
84  $ip = self::resolveHostname($StorageNode->get('ip'));
85  if (!in_array($ip, self::$ips)) {
86  continue;
87  }
88  $this->set('storagenode', $StorageNode);
89  break;
90  }
91  if (!$this->get('storagenode')->isValid()) {
92  throw new Exception(
93  _('No node associated with any addresses of this system')
94  );
95  }
96  }
104  private function _getHash($item)
105  {
106  if (!is_dir($item)) {
107  return hash_file(
108  'sha512',
109  $item
110  );
111  }
112  $files = array();
113  $dir = dir($item);
114  while (false !== ($file = $dir->read())) {
115  if (in_array($file, array('.', '..'))) {
116  continue;
117  }
118  $files[] = $this->_getHash(
119  sprintf(
120  '%s%s%s',
121  $item,
122  DS,
123  $file
124  )
125  );
126  }
127  $dir->close();
128  return hash(
129  'sha512',
130  implode('', $files)
131  );
132  }
140  private function _getModTime($item)
141  {
142  $stat = stat($item);
143  return self::formatTime($stat['mtime'], 'Y-m-d H:i:s');
144  }
150  public function getImagePaths()
151  {
152  $imagePaths = self::getSubObjectIDs(
153  'Image',
154  array('id' => $this->get('storagenode')->get('images')),
155  'path'
156  );
157  $str = sprintf(
158  '%s%s%s',
159  $this->get('storagenode')->get('path'),
160  DS,
161  '%s'
162  );
163  foreach ((array)$imagePaths as &$path) {
164  self::$imagePaths[] = sprintf(
165  $str,
166  $path
167  );
168  unset($path);
169  }
170  }
176  public function getSnapinFiles()
177  {
178  self::$snapinFiles = $this
179  ->get('storagenode')
180  ->get('snapinfiles');
181  }
187  public function processPathFiles()
188  {
189  $files = self::fastmerge(
190  (array)self::$imagePaths,
191  (array)self::$snapinFiles
192  );
193  foreach ((array)$files as &$file) {
194  $this
195  ->set(
196  'storagenodeID',
197  $this->get('storagenode')->get('id')
198  )->set(
199  'modtime',
200  $this->_getModTime($file)
201  )->set(
202  'checksum',
203  $this->_getHash($file)
204  )->set(
205  'path',
206  $file
207  )->save();
208  unset($file);
209  }
210  }
211 }
FileIntegrity\$databaseFields
$databaseFields
Definition: fileintegrity.class.php:35
FileIntegrity\$databaseFieldsRequired
$databaseFieldsRequired
Definition: fileintegrity.class.php:48
FOGBase\getClass
static getClass($class, $data='', $props=false)
Definition: fogbase.class.php:439
FOGBase\getIPAddress
static getIPAddress($force=false)
Definition: fogbase.class.php:2242
FOGBase\fastmerge
static fastmerge($array1)
Definition: fogbase.class.php:2415
$file
if(isset($_REQUEST['legclient'])) if(isset($_REQUEST['newclient'])) if(isset($_REQUEST['fogprep'])) if(isset($_REQUEST['fogcrypt'])) if(isset($_REQUEST['smartinstaller'])) if(!file_exists($filename)) $file
Definition: download.php:61
FileIntegrity\processPathFiles
processPathFiles()
Definition: fileintegrity.class.php:187
FileIntegrity\$databaseTable
$databaseTable
Definition: fileintegrity.class.php:29
FileIntegrity\$additionalFields
$additionalFields
Definition: fileintegrity.class.php:57
FileIntegrity\$_imagePaths
$_imagePaths
Definition: fileintegrity.class.php:65
FOGBase\formatTime
static formatTime($time, $format=false, $utc=false)
Definition: fogbase.class.php:1124
FileIntegrity\getImagePaths
getImagePaths()
Definition: fileintegrity.class.php:150
FileIntegrity\getSnapinFiles
getSnapinFiles()
Definition: fileintegrity.class.php:176
FOGBase\resolveHostname
static resolveHostname($host)
Definition: fogbase.class.php:2497
FileIntegrity\_getModTime
_getModTime($item)
Definition: fileintegrity.class.php:140
$str
if(! $Image->isValid()) $str
Definition: progress.php:41
FOGController
Definition: fogcontroller.class.php:29
$path
if(!is_string($_GET['path'])) $path
Definition: getfiles.php:31
FileIntegrity\$_snapinFiles
$_snapinFiles
Definition: fileintegrity.class.php:71
FOGBase\getSubObjectIDs
static getSubObjectIDs( $object='Host', $findWhere=array(), $getField='id', $not=false, $operator='AND', $orderBy='name', $groupBy=false, $filter='array_unique')
Definition: fogbase.class.php:2006
FileIntegrity
Definition: fileintegrity.class.php:23
FileIntegrity\getThisNode
getThisNode()
Definition: fileintegrity.class.php:77
FileIntegrity\_getHash
_getHash($item)
Definition: fileintegrity.class.php:104
$ip
if(!(isset($_POST['ip']) &&is_string($_POST['ip']))) if(!(isset($_POST['file']) &&is_string($_POST['file']))) if(!(isset($_POST['lines']) &&is_numeric($_POST['lines']))) if(!(isset($_POST['reverse']) &&is_numeric($_POST['reverse']))) $ip
Definition: logtoview.php:149