r1656 + don't try calling stripslashes() on arrays
[racktables] / inc / init.php
CommitLineData
b325120a 1<?php
e673ee24
DO
2/*
3*
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.
8*
9*/
10
11$root = (empty($_SERVER['HTTPS'])?'http':'https').
12 '://'.
13 (isset($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:($_SERVER['SERVER_NAME'].($_SERVER['SERVER_PORT']=='80'?'':$_SERVER['SERVER_PORT']))).
9c6e7a97
DO
14 dirname($_SERVER['PHP_SELF']);
15if (substr ($root, -1) != '/')
16 $root .= '/';
e673ee24
DO
17
18// This is the first thing we need to do.
19require_once 'inc/config.php';
20
21// What we need first is database and interface functions.
22require_once 'inc/interface.php';
23require_once 'inc/functions.php';
24require_once 'inc/database.php';
25if (file_exists ('inc/secret.php'))
26 require_once 'inc/secret.php';
27else
28{
29 showError
30 (
31 "Database connection parameters are read from inc/secret.php file, " .
e6093686
DO
32 "which cannot be found.\nYou probably need to complete the installation " .
33 "procedure by following <a href='${root}install.php'>this link</a>."
e673ee24
DO
34 );
35 die;
36}
37
38// Now try to connect...
39try
40{
41 $dbxlink = new PDO ($pdo_dsn, $db_username, $db_password);
42}
43catch (PDOException $e)
44{
45 showError ("Database connection failed:\n\n" . $e->getMessage());
46 die();
47}
48
b8d1ab66
DO
49if (get_magic_quotes_gpc())
50 foreach ($_REQUEST as $key => $value)
f4d511df
DO
51 if (gettype ($value) == 'string')
52 $_REQUEST[$key] = stripslashes ($value);
b8d1ab66
DO
53
54if (!set_magic_quotes_runtime (0))
55{
56 showError ('Failed to turn magic quotes off');
57 die;
58}
6bae5fbb 59
e673ee24
DO
60// Escape any globals before we ever try to use them.
61foreach ($_REQUEST as $key => $value)
f4d511df 62 if (gettype ($value) == 'string')
b8d1ab66 63 $_REQUEST[$key] = escapeString ($value);
6bae5fbb 64
e673ee24
DO
65if (isset ($_SERVER['PHP_AUTH_USER']))
66 $_SERVER['PHP_AUTH_USER'] = escapeString ($_SERVER['PHP_AUTH_USER']);
67if (isset ($_SERVER['PHP_AUTH_PW']))
68 $_SERVER['PHP_AUTH_PW'] = escapeString ($_SERVER['PHP_AUTH_PW']);
69
fbbb74fb
DO
70$dbver = getDatabaseVersion();
71if ($dbver != CODE_VERSION)
72{
73 echo '<p align=justify>This Racktables installation seems to be ' .
74 'just upgraded to version ' . CODE_VERSION . ', while the '.
db914a6c 75 'database version is ' . $dbver . '. No user will be ' .
fbbb74fb
DO
76 'either authenticated or shown any page until the upgrade is ' .
77 "finished. Follow <a href='${root}upgrade.php'>this link</a> and " .
78 'authenticate as administrator to finish the upgrade.</p>';
79 die;
80}
81
06f23fd4
DO
82$configCache = loadConfigCache();
83if (!count ($configCache))
84{
85 showError ('Failed to load configuration from the database.');
86 die();
87}
88
e673ee24
DO
89// Now init authentication.
90
91require_once 'inc/auth.php';
92// Load access database once.
93$accounts = getUserAccounts();
94$perms = getUserPermissions();
95if ($accounts === NULL or $perms === NULL)
96{
97 showError ('Failed to initialize access database.');
98 die();
99}
100
101authenticate();
102
103// Authentication passed.
104// Note that we don't perform autorization here, so each 1st level page
105// has to do it in its way, e.g. to call authorize().
106
9c0b0016
DO
107
108
e673ee24
DO
109$remote_username = $_SERVER['PHP_AUTH_USER'];
110$pageno = (isset ($_REQUEST['page'])) ? $_REQUEST['page'] : 'index';
111$tabno = (isset ($_REQUEST['tab'])) ? $_REQUEST['tab'] : 'default';
112
113require_once 'inc/navigation.php';
114require_once 'inc/pagetitles.php';
115require_once 'inc/pagehandlers.php';
116require_once 'inc/ophandlers.php';
641fe9b0 117require_once 'inc/triggers.php';
d33645ff 118require_once 'inc/gateways.php';
d96c1e17 119require_once 'inc/help.php';
e673ee24
DO
120
121?>