-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.php
176 lines (161 loc) · 4.37 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
/*
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
ini_set('xdebug.collect_vars', 'on');
ini_set('xdebug.collect_params', '4');
ini_set('xdebug.dump_globals', 'on');
ini_set('xdebug.dump.SERVER', 'REQUEST_URI');
ini_set('xdebug.show_local_vars', 'on');
*/
ini_set("session.gc_maxlifetime", 3600);
session_start();
require_once("db.inc.php");
require_once('authenticate_tools.inc.php');
function reload($adress = "")
{
?>
<script type="text/javascript"> window.location = "<?php echo $adress;?>"</script>
<?php
die(0);
}
try
{
try
{
db_connect($servername,marmottedbname,$serverlogin,$serverpassword);
}
catch(Exception $e)
{
include("header.inc.php");
echo "<h1>Failed to connect to database: ".$e."</h1>";
db_from_scratch();
}
global $dbh;
if($dbh)
{
if(!isset($_SESSION['checked_admin_password']))
{
createAdminPasswordIfNeeded();
$_SESSION['checked_admin_password'] = true;
}
$action = isset($_REQUEST["action"]) ? mysqli_real_escape_string($dbh, $_REQUEST["action"]) : "";
$errorLogin = 0;
$errorMsg = "";
if($action == "auth_marmotte")
{
if(isset($_REQUEST["login"]) and isset($_REQUEST["password"]))
{
$login = mysqli_real_escape_string($dbh, $_REQUEST["login"]);
$pwd = mysqli_real_escape_string($dbh, $_REQUEST["password"]);
addCredentials($login,$pwd);
if(!authenticate())
{
$errorLogin = 1;
$errorMsg = "Mauvaise paire login/mot de passe";
}
}
}
if($action == "auth_janus")
{
if(empty($_SESSION['pmsp_client_random']) && !empty($_POST['pmsp_server_signature']))
unset($_POST['pmsp_server_signature']);
require_once("PMSP/Pmsp.php");
try {
# Fabrique un objet PMSP
$pmsp = new Pmsp(
"https://vigny.dr15.cnrs.fr/secure/pmsp-server.php",
certif_janus,
"Marmotte",
adresse_du_site."/index.php?action=auth_janus",
false);
$pmsp->authentify('mail,cn,ou,givenname,displayname');
$_SESSION['REMOTE_USER'] = $_SERVER['REMOTE_USER'];
} catch (Exception $e) {
removeCredentials();
$errorLogin = 1;
$errorMsg = $e->getMessage();
}
}
if(isset($_SESSION['REMOTE_USER']) && ($_SESSION['REMOTE_USER'] != ''))
addCredentials($_SESSION['REMOTE_USER'], "",true);
if(!authenticate() || $action == 'logout' || ($errorLogin == 1))
{
removeCredentials();
include("header.inc.php");
include("authenticate.inc.php");
if($errorLogin)
echo "<p><alert>".$errorMsg."</alert></p></br>";
}
else
{
init_filter_session();
require_once("utils.inc.php");
require_once("manage_users.inc.php");
/* several actions and condition require reloading of the whole page they ar eput here */
switch($action)
{
case 'adminnewsession':
if (isset($_REQUEST["sessionname"]) and isset($_REQUEST["sessionannee"]))
{
$name = real_escape_string($_REQUEST["sessionname"]);
$annee = real_escape_string($_REQUEST["sessionannee"]);
require_once('manage_sessions.inc.php');
createSession($name,$annee);
}
reload("?action=admin");
break;
case 'sessioncourante':
if(isset($_REQUEST["sessionname"]))
{
require_once('config_tools.inc.php');
$id = $_REQUEST["sessionname"];
set_config('current_session',$id);
set_current_session_id($id);
}
reload("?action=admin");
break;
case 'change_role':
$role = isset($_REQUEST["role"]) ? $_REQUEST["role"] : 0;
$role = min( $role, getUserPermissionLevel("",false));
$_SESSION["permission_mask"] = $role;
reload("?action=");
break;
}
/* should not be here but ... */
if(isset($_REQUEST['filter_section']))
{
change_current_section($_REQUEST['filter_section']);
reload("?action=");
}
if(isset($_REQUEST['filter_id_session']))
{
set_current_session_id($_REQUEST['filter_id_session']);
resetFilterValues();
reload("?action=");
}
try{
include("content.inc.php");
}
catch(Exception $exc)
{
echo '<p>Erreur: '.$exc.'</p>';
}
}
db_disconnect();
}
}
catch(Exception $e)
{
removeCredentials();
//Header("Content-type: text/plain");
echo "<html><head><script>alert(\"".$e->getMessage()."\");";
echo "window.location = \"index.php\";";
echo "</script></head></body></html>";
// Header("Content-type: text/plain");
// include("index.php");
}
?>
</body>
</html>