r4910 APCPowerSwitch::getPorts () - change snmpwalk call to snmpwalkoid, fixes #504
[racktables] / wwwroot / inc / pre-init.php
CommitLineData
b00cc78c
AA
1<?php
2/*
3*
4* This file is a library needed by all modules of RackTables (installer, upgrader)
5* to make them able to find code and data.
6*
7*/
8
9require_once 'exceptions.php';
669be046 10require_once 'interface-lib.php';
b00cc78c
AA
11
12// Always have default values for these options, so if a user didn't
13// care to set, something would be working anyway.
14$user_auth_src = 'database';
15$require_local_account = TRUE;
16
17$racktables_rootdir = realpath (dirname (__FILE__) . '/..'); // you can not override this
18# Below are default values for several paths. The right way to change these
19# is to add respective line(s) to secret.php, unless this is a "shared
20# code, multiple instances" deploy, in which case the paths could be changed
21# in the custom entry point wrapper (like own index.php)
22if (! isset ($racktables_staticdir)) // the directory containing 'pix', 'js', 'css' dirs
23 $racktables_staticdir = $racktables_rootdir;
7cb57a03 24if (! isset ($racktables_gwdir)) // the directory containing the 'telnet' and 'ssh' scripts
b00cc78c
AA
25 $racktables_gwdir = realpath ($racktables_rootdir . '/../gateways');
26if (! isset ($racktables_confdir)) // the directory containing local.php and secret.php (default is wwwroot/inc)
27 $racktables_confdir = dirname (__FILE__);
28if (! isset ($path_to_secret_php))
29 $path_to_secret_php = $racktables_confdir . '/secret.php';
30if (! isset ($path_to_local_php))
31 $path_to_local_php = $racktables_confdir . '/local.php';
f7efb073
AA
32if (! isset ($local_gwdir))
33 $local_gwdir = $racktables_confdir . '/gateways';
b00cc78c
AA
34
35// secret.php may be missing, generally it is OK
36if (fileSearchExists ($path_to_secret_php))
37{
38 $found_secret_file = TRUE;
39 require_once $path_to_secret_php;
40}
41else
42 $found_secret_file = FALSE;
43
44// (re)connects to DB, stores PDO object in $dbxlink global var
45function connectDB()
46{
47 global $dbxlink, $pdo_dsn, $db_username, $db_password;
48 $dbxlink = NULL;
49 // Now try to connect...
50 try
51 {
52 $dbxlink = new PDO ($pdo_dsn, $db_username, $db_password);
53 }
54 catch (PDOException $e)
55 {
56 throw new RackTablesError ("Database connection failed:\n\n" . $e->getMessage(), RackTablesError::INTERNAL);
57 }
58 $dbxlink->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
59 $dbxlink->exec ("set names 'utf8'");
60}
61
62// tries to guess the existance of the file before the php's include using the same searching method.
63// in addition to calling file_exists, searches the current file's directory if the path is not looks
64// like neither absolute nor relative.
65function fileSearchExists ($filename)
66{
67 if (! preg_match ('@^(\.+)?/@', $filename))
68 {
69 $this_file_dir = dirname (__FILE__);
70 if (file_exists ($this_file_dir . '/' . $filename))
71 return TRUE;
72 }
73 return file_exists ($filename);
74}
75
76?>