forked from opendocman/opendocman
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
157 lines (137 loc) · 4.31 KB
/
index.php
File metadata and controls
157 lines (137 loc) · 4.31 KB
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
<?php
/*
* Copyright (C) 2000-2021. Stephen Lawrence
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// Main login form
session_start();
/*
* Test to see if we have the config.php file. If not, must not be installed yet.
*/
if (!file_exists('config.php') && !file_exists('docker-configs/config.php')) {
if (
!extension_loaded('pdo')
|| !extension_loaded('pdo_mysql')
) {
echo "<p>PHP pdo Extensions not loaded. <a href='./'>try again</a>.</p>";
exit;
}
// A config file doesn't exist
?>
<html>
<head>
<link rel="stylesheet" href="templates/common/css/install.css" type="text/css"/>
</head>
<body>
<h2>Looks like this is a new installation because we did not find a config.php file or we cannot locate the
database. We need to create a config.php file now:</h2>
<p><a href="install/setup-config.php" class="button">Create a Configuration File</a></p>
</body>
</html>
<?php
exit;
}
require_once('odm-load.php');
if (!isset($_REQUEST['last_message'])) {
$_REQUEST['last_message'] = '';
}
// Call the plugin API
callPluginMethod('onBeforeLogin');
if (isset($_SESSION['uid'])) {
// redirect to main page
if (isset($_REQUEST['redirection'])) {
redirect_visitor($_REQUEST['redirection']);
} else {
redirect_visitor('out.php');
}
}
if (isset($_POST['login'])) {
if (!is_dir($GLOBALS['CONFIG']['dataDir']) || !is_writable($GLOBALS['CONFIG']['dataDir'])) {
echo "<font color=red>" . msg('message_datadir_problem') . "</font>";
}
$frmuser = $_POST['frmuser'];
$frmpass = $_POST['frmpass'];
// check login and md5()
// connect and execute query
$query = "
SELECT
id,
username,
password
FROM
{$GLOBALS['CONFIG']['db_prefix']}user
WHERE
username = :frmuser
AND
password = md5(:frmpass)
";
$stmt = $pdo->prepare($query);
$stmt->execute(array(
':frmuser' => $frmuser,
':frmpass' => $frmpass
));
$result = $stmt->fetchAll();
if (count($result) != 1) {
// Check old password() method
$query = "
SELECT
id,
username,
password
FROM
{$GLOBALS['CONFIG']['db_prefix']}user
WHERE
username = :frmuser
AND
password = password(:frmpass)
";
$stmt = $pdo->prepare($query);
$stmt->execute(array(
':frmuser' => $frmuser,
':frmpass' => $frmpass
));
$result = $stmt->fetchAll();
}
// if row exists - login/pass is correct
if (count($result) == 1) {
// register the user's ID
$id = $result[0]['id'];
// initiate a session
$_SESSION['uid'] = $id;
// Run the plugin API
callPluginMethod('onAfterLogin');
// redirect to main page
if (isset($_REQUEST['redirection'])) {
redirect_visitor($_REQUEST['redirection']);
} else {
redirect_visitor('out.php');
}
// close connection
} else {
// Login Failed
// redirect to error page
// Call the plugin API
callPluginMethod('onFailedLogin');
header('Location: error.php?ec=0');
}
} elseif (!isset($_POST['login']) && $GLOBALS['CONFIG']['authen'] == 'mysql') {
$redirection = (isset($_REQUEST['redirection']) ? $_REQUEST['redirection'] : '');
$GLOBALS['smarty']->assign('redirection', htmlentities($redirection, ENT_QUOTES));
display_smarty_template('login.tpl');
} else {
echo 'Check your config';
}
draw_footer();