4 * This file performs RackTables initialisation. After you include it
5 * from 1st-level page, don't forget to call authorize(). This is done
6 * to allow reloading of pageno and tabno variables. pageno and tabno
7 * together form security context.
11 $root = (empty($_SERVER['HTTPS'])?
'http':'https').
13 (isset($_SERVER['HTTP_HOST'])?
$_SERVER['HTTP_HOST']:($_SERVER['SERVER_NAME'].($_SERVER['SERVER_PORT']=='80'?
'':$_SERVER['SERVER_PORT']))).
14 dirname($_SERVER['PHP_SELF']);
15 if (substr ($root, -1) != '/')
18 // This is the first thing we need to do.
19 require_once 'inc/config.php';
21 // What we need first is database and interface functions.
22 require_once 'inc/interface.php';
23 require_once 'inc/functions.php';
24 require_once 'inc/database.php';
25 if (file_exists ('inc/secret.php'))
26 require_once 'inc/secret.php';
31 "Database connection parameters are read from inc/secret.php file, " .
32 "which cannot be found.\nYou probably need to complete the installation " .
33 "procedure by following <a href='${root}install.php'>this link</a>."
38 // Now try to connect...
41 $dbxlink = new PDO ($pdo_dsn, $db_username, $db_password);
43 catch (PDOException
$e)
45 showError ("Database connection failed:\n\n" . $e->getMessage());
49 $dbxlink->exec ("set names 'utf8'");
51 if (get_magic_quotes_gpc())
52 foreach ($_REQUEST as $key => $value)
53 if (gettype ($value) == 'string')
54 $_REQUEST[$key] = stripslashes ($value);
56 if (!set_magic_quotes_runtime (0))
58 showError ('Failed to turn magic quotes off');
62 // Escape any globals before we ever try to use them.
63 foreach ($_REQUEST as $key => $value)
64 if (gettype ($value) == 'string')
65 $_REQUEST[$key] = escapeString ($value);
67 if (isset ($_SERVER['PHP_AUTH_USER']))
68 $_SERVER['PHP_AUTH_USER'] = escapeString ($_SERVER['PHP_AUTH_USER']);
69 if (isset ($_SERVER['PHP_AUTH_PW']))
70 $_SERVER['PHP_AUTH_PW'] = escapeString ($_SERVER['PHP_AUTH_PW']);
72 $dbver = getDatabaseVersion();
73 if ($dbver != CODE_VERSION
)
75 echo '<p align=justify>This Racktables installation seems to be ' .
76 'just upgraded to version ' . CODE_VERSION
. ', while the '.
77 'database version is ' . $dbver . '. No user will be ' .
78 'either authenticated or shown any page until the upgrade is ' .
79 "finished. Follow <a href='${root}upgrade.php'>this link</a> and " .
80 'authenticate as administrator to finish the upgrade.</p>';
84 $configCache = loadConfigCache();
85 if (!count ($configCache))
87 showError ('Failed to load configuration from the database.');
91 // Now init authentication.
93 require_once 'inc/auth.php';
94 // Load access database once.
95 $accounts = getUserAccounts();
96 $perms = getUserPermissions();
97 if ($accounts === NULL or $perms === NULL)
99 showError ('Failed to initialize access database.');
105 // Authentication passed.
106 // Note that we don't perform autorization here, so each 1st level page
107 // has to do it in its way, e.g. to call authorize().
111 $remote_username = $_SERVER['PHP_AUTH_USER'];
112 $pageno = (isset ($_REQUEST['page'])) ?
$_REQUEST['page'] : 'index';
113 $tabno = (isset ($_REQUEST['tab'])) ?
$_REQUEST['tab'] : 'default';
114 // Order matters here.
115 $taglist = getTagList();
116 $tagtree = getTagTree();
118 require_once 'inc/navigation.php';
119 require_once 'inc/pagetitles.php';
120 require_once 'inc/ophandlers.php';
121 require_once 'inc/triggers.php';
122 require_once 'inc/gateways.php';
125 $expl_tags = array();
126 $impl_tags = array();
127 $auto_tags = getGlobalAutoTags();
129 if (isset ($page[$pageno]['tagloader']) and isset ($page[$pageno]['bypass']) and isset ($_REQUEST[$page[$pageno]['bypass']]))
131 $expl_tags = $page[$pageno]['tagloader'] ($_REQUEST[$page[$pageno]['bypass']]);
132 $impl_tags = getImplicitTags ($expl_tags);
134 if (isset ($page[$pageno]['autotagloader']))
135 $auto_tags = array_merge ($auto_tags, $page[$pageno]['autotagloader'] ());