r4910 APCPowerSwitch::getPorts () - change snmpwalk call to snmpwalkoid, fixes #504
[racktables] / wwwroot / inc / init.php
CommitLineData
b325120a 1<?php
e673ee24
DO
2/*
3*
4* This file performs RackTables initialisation. After you include it
da958e52 5* from 1st-level page, don't forget to call fixContext(). This is done
204284ba 6* to enable override of of pageno and tabno variables. pageno and tabno
c3a8284b
DO
7* together participate in forming security context by generating
8* related autotags.
e673ee24
DO
9*
10*/
11
b00cc78c 12require_once 'pre-init.php';
e82deb48
DO
13require_once 'config.php';
14require_once 'functions.php';
15require_once 'database.php';
ca8aa8e9
DO
16require_once 'auth.php';
17require_once 'navigation.php';
18require_once 'triggers.php';
19require_once 'gateways.php';
7cb57a03 20require_once 'remote.php';
ca8aa8e9 21require_once 'IPv6.php';
8b912171 22require_once 'caching.php';
defd92d8 23require_once 'slb.php';
0cc24e9a 24
8774bde5 25// secret.php may be missing, in which case this is a special fatal error
0e9b4fb2 26if (! fileSearchExists ($path_to_secret_php))
3a089a44 27 throw new RackTablesError
e673ee24 28 (
971a2366 29 "Database connection parameters are read from ${path_to_secret_php} file, " .
32da7643 30 "which cannot be found.<br>You probably need to complete the installation " .
e37cfe5f 31 "procedure by following <a href='?module=installer'>this link</a>.",
3a089a44 32 RackTablesError::MISCONFIGURED
e673ee24 33 );
b00cc78c 34
61e79d63 35connectDB();
967e3845 36transformRequestData();
c4ee2310 37loadConfigDefaults();
ca8aa8e9 38$tab['reports']['local'] = getConfigVar ('enterprise');
c4ee2310
DO
39
40if (getConfigVar ('DB_VERSION') != CODE_VERSION)
fbbb74fb
DO
41{
42 echo '<p align=justify>This Racktables installation seems to be ' .
43 'just upgraded to version ' . CODE_VERSION . ', while the '.
c4ee2310 44 'database version is ' . getConfigVar ('DB_VERSION') . '.<br>No user will be ' .
fbbb74fb 45 'either authenticated or shown any page until the upgrade is ' .
964b0388 46 "finished.<br>Follow <a href='?module=upgrade'>this link</a> and " .
fbbb74fb 47 'authenticate as administrator to finish the upgrade.</p>';
7ab82114 48 exit (1);
fbbb74fb
DO
49}
50
0e9da125 51if (!mb_internal_encoding ('UTF-8'))
3a089a44 52 throw new RackTablesError ('Failed setting multibyte string encoding to UTF-8', RackTablesError::INTERNAL);
3540d15c 53
4a6a28f1 54$rackCodeCache = loadScript ('RackCodeCache');
59a83bd8 55if ($rackCodeCache == NULL or !strlen ($rackCodeCache))
4a6a28f1 56{
4a6a28f1 57 $rackCode = getRackCode (loadScript ('RackCode'));
4a6a28f1
DO
58 saveScript ('RackCodeCache', base64_encode (serialize ($rackCode)));
59}
60else
61{
4a6a28f1 62 $rackCode = unserialize (base64_decode ($rackCodeCache));
4a6a28f1
DO
63 if ($rackCode === FALSE) // invalid cache
64 {
65 saveScript ('RackCodeCache', '');
4a6a28f1 66 $rackCode = getRackCode (loadScript ('RackCode'));
4a6a28f1
DO
67 }
68}
69
cf25e649 70// Depending on the 'result' value the 'load' carries either the
3a089a44
DO
71// parse tree or error message. The latter case is a bug, because
72// RackCode saving function was supposed to validate its input.
cf25e649 73if ($rackCode['result'] != 'ACK')
3a089a44 74 throw new RackTablesError ($rackCode['load'], RackTablesError::INTERNAL);
cf25e649 75$rackCode = $rackCode['load'];
7ddbcf59
DO
76// Only call buildPredicateTable() once and save the result, because it will remain
77// constant during one execution for constraints processing.
78$pTable = buildPredicateTable ($rackCode);
79// Constraints parse trees aren't cached in the database, so the least to keep
80// things running is to maintain application cache for them.
81$parseCache = array();
7cfc98b1 82$entityCache = array();
5fd2a004
DO
83// used by getExplicitTagsOnly()
84$tagRelCache = array();
7cfc98b1 85
573214e0
DO
86$taglist = getTagList();
87$tagtree = treeFromList ($taglist);
88sortTree ($tagtree, 'taginfoCmp');
89
d5262485 90$auto_tags = array();
b82cce3f
DO
91// Initial chain for the current user.
92$user_given_tags = array();
e673ee24 93
f15eb3dd
DO
94// This also can be modified in local.php.
95$pageheaders = array
96(
6e5c6947 97 100 => "<link rel='ICON' type='image/x-icon' href='?module=chrome&uri=pix/favicon.ico' />",
f15eb3dd 98);
65e557dd 99addCSS ('css/pi.css');
f15eb3dd 100
deb18b61 101if (!isset ($script_mode) or $script_mode !== TRUE)
b82cce3f 102{
39b0408a
DO
103 // A successful call to authenticate() always generates autotags and somethimes
104 // even given/implicit tags. It also sets remote_username and remote_displayname.
105 authenticate();
b82cce3f
DO
106 // Authentication passed.
107 // Note that we don't perform autorization here, so each 1st level page
108 // has to do it in its way, e.g. by calling authorize() after fixContext().
b82cce3f 109}
39b0408a
DO
110else
111{
112 // Some functions require remote_username to be set to something to act correctly,
113 // even though they don't use the value itself.
114 $admin_account = spotEntity ('user', 1);
115 $remote_username = $admin_account['user_name'];
116 unset ($admin_account);
117}
3540d15c 118
8dc2a6c8
AD
119$virtual_obj_types = explode (',', getConfigVar ('VIRTUAL_OBJ_LISTSRC'));
120
3540d15c 121alterConfigWithUserPreferences();
067d799f 122$op = '';
8774bde5
DO
123// local.php may be missing, this case requires no special treatment
124// and must not generate any warnings
976cf0bd 125ob_start();
0e9b4fb2 126if (fileSearchExists ($path_to_local_php))
929ae23b 127 include_once $path_to_local_php;
976cf0bd
DO
128$tmp = ob_get_clean();
129if ($tmp != '' and ! preg_match ("/^\n+$/D", $tmp))
130 echo $tmp;
131unset ($tmp);
e673ee24 132
4c9b513a 133// These will be filled in by fixContext()
2fb24351
DO
134$expl_tags = array();
135$impl_tags = array();
4c9b513a
DO
136// Initial chain for the current target.
137$target_given_tags = array();
2fb24351 138
e673ee24 139?>