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