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