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)  

databasemanager.class.php
Go to the documentation of this file.
1 <?php
24 class DatabaseManager extends FOGCore
25 {
31  public static function establish()
32  {
37  $noDBpattern = array(
38  'status\/bandwidth\.php$',
39  'status\/freespace\.php$',
40  'status\/getfiles\.php$',
41  'status\/gethash\.php$',
42  'status\/getservertime\.php$',
43  'status\/getsize\.php$',
44  'status\/hw\.php$',
45  'status\/newtoken\.php$'
46  );
47  $noDBpattern = '#'.implode($noDBpattern, "|").'#';
48  if (preg_match($noDBpattern, self::$scriptname)) {
49  return;
50  }
55  if (self::$DB) {
56  return new self;
57  }
61  self::$DB = new PDODB();
66  $testscript = preg_match(
67  '#/service|status/#',
68  self::$scriptname
69  );
70  if (strtolower(self::$reqmethod) === 'post'
71  && !self::getLink()
72  ) {
73  http_response_code(406);
74  }
80  if (($testscript
81  && !self::getLink()
82  && false === strpos(self::$scriptname, 'dbrunning'))
83  ) {
84  echo json_encode(_('A valid database connection could not be made'));
85  exit(10);
86  }
95  if (self::$mySchema >= FOG_SCHEMA) {
96  return new self;
97  }
101  global $sub;
105  $okayFiles = array(
106  'checkcredentials.php',
107  'getversion.php',
108  'kernelvers.php',
109  );
113  $filename = basename(self::$scriptname);
117  if (!in_array($filename, $okayFiles)) {
122  if (!preg_match('#schema#i', self::$querystring)) {
123  self::redirect('?node=schema');
124  }
125  }
129  $subs = array(
130  'configure',
131  'authorize',
132  'requestClientInfo'
133  );
138  if (in_array($sub, $subs)) {
139  $test = true;
140  }
146  if (true === $test) {
153  if (self::$json) {
154  die(
155  json_encode(
156  array(
157  'error' => 'db'
158  )
159  )
160  );
161  } else {
162  die('#!db');
163  }
164  }
165  return new self;
166  }
172  public static function getLink()
173  {
174  return self::$DB->link();
175  }
181  public static function getDB()
182  {
183  return self::$DB;
184  }
190  private static function _getVersion()
191  {
192  $query = sprintf(
193  'SELECT `vValue` FROM `%s`.`schemaVersion`',
194  self::$DB->dbName()
195  );
196  self::$mySchema = (int)self::$DB
197  ->query($query)
198  ->fetch()
199  ->get('vValue');
200  return self::$mySchema;
201  }
210  public static function getColumns(
211  $table_name,
212  $column_name
213  ) {
214  $sql = sprintf(
215  "SELECT COUNT(`%s`)AS`%s`FROM`%s`.`%s`WHERE`%s`='%s'%s",
216  'COLUMN_NAME',
217  'total',
218  'information_schema',
219  'COLUMNS',
220  'TABLE_SCHEMA',
221  self::$DB->dbName(),
222  sprintf(
223  str_repeat("AND`%s`='%s'", 2),
224  'TABLE_NAME',
225  $table_name,
226  'COLUMN_NAME',
227  $column_name
228  )
229  );
230  return self::$DB
231  ->query($sql)
232  ->fetch()
233  ->get('total');
234  }
235 }
exit
exit
Definition: download.php:102
DatabaseManager\getLink
static getLink()
Definition: databasemanager.class.php:172
FOGCore
Definition: fogcore.class.php:23
PDODB
Definition: pdodb.class.php:27
$test
$test
Definition: freespace.php:37
DatabaseManager\establish
static establish()
Definition: databasemanager.class.php:31
FOGBase\$DB
static $DB
Definition: fogbase.class.php:157
DatabaseManager
Definition: databasemanager.class.php:25
FOGBase\$mySchema
static $mySchema
Definition: fogbase.class.php:286
DatabaseManager\getDB
static getDB()
Definition: databasemanager.class.php:181
FOGBase\redirect
static redirect($url='')
Definition: fogbase.class.php:831
DatabaseManager\_getVersion
static _getVersion()
Definition: databasemanager.class.php:190
DatabaseManager\getColumns
static getColumns( $table_name, $column_name)
Definition: databasemanager.class.php:210