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)  

snapinhash.class.php
Go to the documentation of this file.
1 <?php
22 class SnapinHash extends FOGService
23 {
29  private static $_hashOn = 0;
35  public static $sleeptime = 'SNAPINHASHSLEEPTIME';
41  public function __construct()
42  {
43  parent::__construct();
44  list(
45  $dev,
46  $log,
47  $zzz
49  'Service',
50  array(
51  'name' => array(
52  'SNAPINHASHDEVICEOUTPUT',
53  'SNAPINHASHLOGFILENAME',
54  self::$sleeptime
55  )
56  ),
57  'value',
58  false,
59  'AND',
60  'name',
61  false,
62  ''
63  );
64  static::$log = sprintf(
65  '%s%s',
66  (
67  self::$logpath ?
68  self::$logpath :
69  '/opt/fog/log/'
70  ),
71  (
72  $log ?
73  $log :
74  'fogsnapinhash.log'
75  )
76  );
77  if (file_exists(static::$log)) {
78  unlink(static::$log);
79  }
80  static::$dev = (
81  $dev ?
82  $dev :
83  '/dev/tty6'
84  );
85  static::$zzz = (
86  $zzz ?
87  $zzz :
88  1800
89  );
90  }
97  private function _commonOutput()
98  {
99  try {
100  self::$_hashOn = self::getSetting('SNAPINHASHGLOBALENABLED');
101  if (self::$_hashOn < 1) {
102  throw new Exception(_(' * Snapin hash is globally disabled'));
103  }
104  foreach ((array)$this->checkIfNodeMaster() as &$StorageNode) {
105  $myStorageGroupID = $StorageNode->get('storagegroupID');
106  $myStorageNodeID = $StorageNode->get('id');
107  $StorageGroup = $StorageNode->getStorageGroup();
108  self::outall(
109  sprintf(
110  ' * %s.',
111  _('Starting Snapin Hashing Service')
112  )
113  );
114  self::outall(
115  sprintf(
116  ' * %s: %d. %s: %s',
117  _('We are group ID'),
118  $StorageGroup->get('id'),
119  _('We are group name'),
120  $StorageGroup->get('name')
121  )
122  );
123  self::outall(
124  sprintf(
125  ' * %s: %d. %s: %s',
126  _('We are node ID'),
127  $StorageNode->get('id'),
128  _('We are node name'),
129  $StorageNode->get('name')
130  )
131  );
132  self::outall(
133  sprintf(
134  ' * %s %s %s',
135  _('Finding any snapins associated'),
136  _('with this group'),
137  _('as its primary group')
138  )
139  );
140  $snapinIDs = self::getSubObjectIDs(
141  'SnapinGroupAssociation',
142  array(
143  'primary' => 1,
144  'storagegroupID' => $myStorageGroupID
145  ),
146  'snapinID'
147  );
148  $SnapinCount = self::getClass('SnapinManager')->count(
149  array(
150  'id' => $snapinIDs,
151  'isEnabled' => 1
152  )
153  );
154  if ($SnapinCount < 1) {
155  self::outall(
156  sprintf(
157  ' * %s.',
158  _('No snapins associated with this group as master')
159  )
160  );
161  continue;
162  }
163  self::outall(
164  sprintf(
165  ' * %s %d %s %s.',
166  _('Found'),
167  $SnapinCount,
168  (
169  $SnapinCount != 1 ?
170  _('snapins') :
171  _('snapin')
172  ),
173  _('to update hash values as needed')
174  )
175  );
176  foreach ((array)self::getClass('SnapinManager')
177  ->find(
178  array(
179  'id' => $snapinIDs,
180  'isEnabled' => 1
181  )
182  ) as &$Snapin
183  ) {
184  self::outall(
185  sprintf(
186  ' * %s: %s, %s: %d',
187  _('Trying Snapin hash for'),
188  $Snapin->get('name'),
189  _('ID'),
190  $Snapin->get('id')
191  )
192  );
193  $path = sprintf(
194  '/%s',
195  trim($StorageNode->get('snapinpath'), '/')
196  );
197  $file = basename($Snapin->get('file'));
198  $filepath = sprintf(
199  '%s/%s',
200  $path,
201  $file
202  );
203  self::outall(
204  sprintf(
205  ' * %s: %s.',
206  _('Getting snapin hash and size for'),
207  $Snapin->get('name')
208  )
209  );
210  $hash = hash_file('sha512', $filepath);
211  $size = self::getFilesize($filepath);
212  unset($path, $file);
213  self::outall(
214  sprintf(
215  ' | %s: %s',
216  _('Hash'),
217  $hash
218  )
219  );
220  $Snapin
221  ->set('hash', $hash)
222  ->set('size', $size)
223  ->save();
224  unset($url, $response, $hash, $size);
225  unset($Snapin);
226  }
227  unset($StorageNode);
228  }
229  self::outall(
230  sprintf(
231  ' * %s.',
232  _('Completed')
233  )
234  );
235  unset($StorageNodes);
236  } catch (Exception $e) {
237  self::outall(
238  sprintf(
239  ' * %s',
240  _($e->getMessage())
241  )
242  );
243  }
244  }
250  public function serviceRun()
251  {
252  $this->_commonOutput();
253  parent::serviceRun();
254  }
255 }
$dev
$dev
Definition: bandwidth.php:49
FOGService\outall
outall($string)
Definition: fogservice.class.php:228
FOGBase\getClass
static getClass($class, $data='', $props=false)
Definition: fogbase.class.php:439
$response
$response
Definition: logtoview.php:185
$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
SnapinHash\__construct
__construct()
Definition: snapinhash.class.php:41
SnapinHash\$_hashOn
static $_hashOn
Definition: snapinhash.class.php:29
FOGBase\getFilesize
static getFilesize($path)
Definition: fogbase.class.php:2319
FOGService\$log
static $log
Definition: fogservice.class.php:41
SnapinHash\_commonOutput
_commonOutput()
Definition: snapinhash.class.php:97
$path
if(!is_string($_GET['path'])) $path
Definition: getfiles.php:31
FOGService\$dev
static $dev
Definition: fogservice.class.php:35
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
FOGService\checkIfNodeMaster
checkIfNodeMaster()
Definition: fogservice.class.php:100
SnapinHash\serviceRun
serviceRun()
Definition: snapinhash.class.php:250
$url
$url
Definition: kernelvers.php:27
SnapinHash\$sleeptime
static $sleeptime
Definition: snapinhash.class.php:35
FOGBase\getSetting
static getSetting($key)
Definition: fogbase.class.php:2063
SnapinHash
Definition: snapinhash.class.php:23
FOGService\$zzz
static $zzz
Definition: fogservice.class.php:47
FOGService
Definition: fogservice.class.php:23