forked from domainmod/domainmod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
217 lines (174 loc) · 6.91 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
/**
* /index.php
*
* This file is part of DomainMOD, an open source domain and internet asset manager.
* Copyright (c) 2010-2022 Greg Chetcuti <[email protected]>
*
* Project: http://domainmod.org Author: http://chetcuti.com
*
* DomainMOD 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 3 of the License, or (at your option) any later
* version.
*
* DomainMOD 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 DomainMOD. If not, see
* http://www.gnu.org/licenses/.
*
*/
?>
<?php
require_once __DIR__ . '/_includes/start-session.inc.php';
require_once __DIR__ . '/_includes/init.inc.php';
require_once DIR_INC . '/config.inc.php';
require_once DIR_INC . '/software.inc.php';
require_once DIR_ROOT . '/vendor/autoload.php';
$deeb = DomainMOD\Database::getInstance();
$system = new DomainMOD\System();
$log = new DomainMOD\Log('/index.php');
$maint = new DomainMOD\Maintenance();
$layout = new DomainMOD\Layout();
$login = new DomainMOD\Login();
$user = new DomainMOD\User();
$time = new DomainMOD\Time();
$form = new DomainMOD\Form();
$format = new DomainMOD\Format();
require_once DIR_INC . '/head.inc.php';
require_once DIR_INC . '/config-demo.inc.php';
require_once DIR_INC . '/debug.inc.php';
require_once DIR_INC . '/settings/login.inc.php';
$system->loginCheck();
$pdo = $deeb->cnxx;
$_SESSION['s_installation_mode'] = $system->installMode();
if ($_SESSION['s_installation_mode'] === 1) {
header("Location: install/");
exit;
}
$new_username = $_POST['new_username'];
$new_password = $_POST['new_password'];
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $new_username != "" && $new_password != "") {
$_SESSION['s_read_only'] = '1';
// Check to see if the user's password is using the old md5 hashing
$stmt = $pdo->prepare("
SELECT id
FROM users
WHERE username = :new_username
AND `password` = password(:new_password)
AND active = '1'");
$stmt->bindValue('new_username', $new_username, PDO::PARAM_STR);
$stmt->bindValue('new_password', $new_password, PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetch();
$stmt->closeCursor();
// Update the stored password to use stronger hashing than md5
if ($result) {
$new_hashed_password = $user->generateHash($new_password);
$stmt = $pdo->prepare("
UPDATE `users`
SET password = :new_hashed_password
WHERE username = :new_username
AND `password` = password(:new_password)
AND active = '1'");
$stmt->bindValue('new_hashed_password', $new_hashed_password, PDO::PARAM_STR);
$stmt->bindValue('new_username', $new_username, PDO::PARAM_STR);
$stmt->bindValue('new_password', $new_password, PDO::PARAM_STR);
$stmt->execute();
}
// Check to see if the user's password matches
$stmt = $pdo->prepare("
SELECT `password`
FROM users
WHERE username = :new_username
AND active = '1'");
$stmt->bindValue('new_username', $new_username, PDO::PARAM_STR);
$stmt->execute();
$stored_hash = $stmt->fetchColumn();
if (password_verify($new_password, $stored_hash)) {
$_SESSION['s_user_id'] = $user->getUserId($new_username);
$_SESSION['s_username'] = $new_username;
$_SESSION['s_stored_hash'] = $stored_hash;
$_SESSION['s_system_db_version'] = $system->getDbVersion();
$_SESSION['s_is_logged_in'] = 1;
header("Location: checks.php");
exit;
} else {
$log_message = 'Unable to login';
$log_extra = array('Username' => $new_username, 'Password' => $format->obfusc($new_password));
$log->warning($log_message, $log_extra);
$_SESSION['s_message_danger'] .= _('Login Failed') . '<BR>';
}
} else {
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($new_username == "" && $new_password == "") {
$_SESSION['s_message_danger'] .= _('Enter your username & password') . '<BR>';
} elseif ($new_username == "" || $new_password == "") {
if ($new_username == "") $_SESSION['s_message_danger'] .= _('Enter your username') . '<BR>';
if ($new_password == "") $_SESSION['s_message_danger'] .= _('Enter your password') . '<BR>';
}
}
}
$new_password = "";
?>
<?php require_once DIR_INC . '/doctype.inc.php'; ?>
<html>
<head>
<?php
if ($page_title != "") { ?>
<title><?php echo $layout->pageTitle($page_title); ?></title><?php
} else { ?>
<title><?php echo SOFTWARE_TITLE; ?></title><?php
} ?>
<?php require_once DIR_INC . '/layout/head-tags.inc.php'; ?>
</head>
<body class="hold-transition login-page text-sm">
<?php require_once DIR_INC . '/layout/header-login.inc.php'; ?>
<div class="card card-outline card-danger">
<div class="card-body login-card-body">
<p class="login-box-msg"><?php echo _('Please enter your username and password to sign in'); ?></p><?php
if (DEMO_INSTALLATION == true) { ?>
<strong><?php echo _('Demo Username'); ?>:</strong> demo<BR>
<strong><?php echo _('Demo Password'); ?>:</strong> demo<BR><BR><?php
} ?>
<form action="" method="post">
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Username" name="new_username" maxlength="20">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-user"></span>
</div>
</div>
</div>
<div class="input-group mb-3">
<input type="password" class="form-control" placeholder="Password" name="new_password" maxlength="72">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-lock"></span>
</div>
</div>
</div>
<div class="row">
<div class="col-8">
</div>
<!-- /.col -->
<div class="col-4">
<button type="submit" class="btn btn-danger btn-block">Sign In</button>
</div>
<!-- /.col -->
</div>
</form>
</div>
<!-- /.login-card-body -->
</div><?php
if (DEMO_INSTALLATION == false) { ?>
<BR>
<p class="mb-1">
<a href="reset.php"><?php echo _('Forgot your Password'); ?>?</a>
</p><?php
}
?>
<?php require_once DIR_INC . '/layout/footer-login.inc.php'; ?>
</body>
</html>