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)  

imagesize.class.php
Go to the documentation of this file.
1 <?php
22 class ImageSize extends FOGService
23 {
29  private static $_sizeOn = 0;
35  public static $sleeptime = 'IMAGESIZESLEEPTIME';
41  public function __construct()
42  {
43  parent::__construct();
44  list(
45  $dev,
46  $log,
47  $zzz
49  'Service',
50  array(
51  'name' => array(
52  'IMAGESIZEDEVICEOUTPUT',
53  'IMAGESIZELOGFILENAME',
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  'fogimagesize.log'
75  )
76  );
77  if (file_exists(static::$log)) {
78  unlink(static::$log);
79  }
80  static::$dev = (
81  $dev ?
82  $dev :
83  '/dev/tty3'
84  );
85  static::$zzz = (
86  $zzz ?
87  $zzz :
88  3600
89  );
90  }
97  private function _commonOutput()
98  {
99  try {
100  self::$_sizeOn = self::getSetting('IMAGESIZEGLOBALENABLED');
101  if (self::$_sizeOn < 1) {
102  throw new Exception(_(' * Image size 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 Image Size 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 images associated'),
136  _('with this group'),
137  _('as its primary group')
138  )
139  );
140  $imageIDs = self::getSubObjectIDs(
141  'ImageAssociation',
142  array(
143  'primary' => 1,
144  'storagegroupID' => $myStorageGroupID
145  ),
146  'imageID'
147  );
148  $ImageCount = self::getClass('ImageManager')->count(
149  array(
150  'id' => $imageIDs,
151  'isEnabled' => 1
152  )
153  );
154  if ($ImageCount < 1) {
155  self::outall(
156  sprintf(
157  ' * %s.',
158  _('No images associated with this group as master')
159  )
160  );
161  continue;
162  }
163  self::outall(
164  sprintf(
165  ' * %s %d %s %s.',
166  _('Found'),
167  $ImageCount,
168  (
169  $ImageCount != 1 ?
170  _('images') :
171  _('image')
172  ),
173  _('to update size values as needed')
174  )
175  );
176  foreach ((array)self::getClass('ImageManager')
177  ->find(
178  array(
179  'id' => $imageIDs,
180  'isEnabled' => 1
181  )
182  ) as &$Image
183  ) {
184  self::outall(
185  sprintf(
186  ' * %s: %s, %s: %d',
187  _('Trying image size for'),
188  $Image->get('name'),
189  _('ID'),
190  $Image->get('id')
191  )
192  );
193  $path = sprintf(
194  '/%s',
195  trim($StorageNode->get('path'), '/')
196  );
197  $file = basename($Image->get('path'));
198  $filepath = sprintf(
199  '%s/%s',
200  $path,
201  $file
202  );
203  if (!file_exists($filepath) || !is_readable($filepath)) {
204  self::outall(
205  sprintf(
206  '| %s: %s',
207  $Image->get('name'),
208  _('Path is unavailable')
209  )
210  );
211  continue;
212  }
213  self::outall(
214  sprintf(
215  ' * %s: %s.',
216  _('Getting image size for'),
217  $Image->get('name')
218  )
219  );
220  $size = self::getFilesize($filepath);
221  unset($path, $file);
222  self::outall(
223  sprintf(
224  ' | %s: %s',
225  _('Size'),
226  $size
227  )
228  );
229  $Image
230  ->set('srvsize', $size)
231  ->save();
232  unset($url, $response, $size);
233  unset($Image);
234  }
235  unset($StorageNode);
236  }
237  self::outall(
238  sprintf(
239  ' * %s.',
240  _('Completed')
241  )
242  );
243  unset($StorageNodes);
244  } catch (Exception $e) {
245  self::outall(
246  sprintf(
247  ' * %s',
248  _($e->getMessage())
249  )
250  );
251  }
252  }
258  public function serviceRun()
259  {
260  $this->_commonOutput();
261  parent::serviceRun();
262  }
263 }
$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
ImageSize\$sleeptime
static $sleeptime
Definition: imagesize.class.php:35
$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
ImageSize\$_sizeOn
static $_sizeOn
Definition: imagesize.class.php:29
ImageSize\__construct
__construct()
Definition: imagesize.class.php:41
ImageSize\serviceRun
serviceRun()
Definition: imagesize.class.php:258
FOGBase\getFilesize
static getFilesize($path)
Definition: fogbase.class.php:2319
FOGService\$log
static $log
Definition: fogservice.class.php:41
$path
if(!is_string($_GET['path'])) $path
Definition: getfiles.php:31
ImageSize
Definition: imagesize.class.php:23
$Image
$Image
Definition: hostinfo.php:37
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
$url
$url
Definition: kernelvers.php:27
FOGBase\getSetting
static getSetting($key)
Definition: fogbase.class.php:2063
ImageSize\_commonOutput
_commonOutput()
Definition: imagesize.class.php:97
FOGService\$zzz
static $zzz
Definition: fogservice.class.php:47
FOGService
Definition: fogservice.class.php:23