-
Notifications
You must be signed in to change notification settings - Fork 75
/
login.php
275 lines (238 loc) · 8.71 KB
/
login.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<?php
require_once 'includes/translate.php';
require_once 'includes/classes/WebCalendar.php';
$WebCalendar = new WebCalendar( __FILE__ );
require_once 'includes/config.php';
require_once 'includes/dbi4php.php';
require_once 'includes/formvars.php';
require_once 'includes/functions.php';
session_name(getSessionName());
@session_start();
foreach ( $_SESSION as $key => $value ) {
$dummy[$key] = $value; // Copy to a dummy array.
}
if ( ! empty ( $dummy ) ) {
foreach ( $dummy as $key => $value ) {
if ( substr ( $key, 0, 6 ) == 'webcal' )
unset ( $_SESSION[$key] );
}
}
$WebCalendar->initializeFirstPhase();
require_once "includes/$user_inc";
require_once 'includes/access.php';
require_once 'includes/gradient.php';
$WebCalendar->initializeSecondPhase();
load_global_settings();
// Set this true to show "no such user" or "invalid password" on login failures.
$showLoginFailureReason = (!empty($settings['mode']) && $settings['mode'] = 'dev');
$message = '';
if ( ! empty ( $last_login ) )
$login = '';
if ( empty ( $webcalendar_login ) )
$webcalendar_login = '';
if ( $REMEMBER_LAST_LOGIN == 'Y' && empty ( $login ) )
$last_login = $login = $webcalendar_login;
load_user_preferences ( 'guest' );
$WebCalendar->setLanguage();
// Look for action=logout.
$logout = false;
$action = getGetValue('action');
if (!empty($action) && $action == 'logout') {
if (empty($CSRF_PROTECTION) || $CSRF_PROTECTION != 'N') {
if (empty($_REQUEST['csrf_form_key']) || empty($_SESSION['csrf_form_key'])) {
die_miserable_death (translate('Fatal Error') . ': '
. translate('Invalid form request'));
}
$formKey = $_REQUEST['csrf_form_key'];
if ($formKey == $_SESSION['csrf_form_key'] && !empty($_SESSION['csrf_form_key'])) {
// Okay to proceed
} else {
die_miserable_death ( translate ( 'Fatal Error' ) . ': '
. translate ( 'Invalid form request' ) );
}
}
$logout = true;
$return_path = '';
sendCookie('webcalendar_login', '', 0);
sendCookie('webcalendar_last_view', '', 0);
$message = translate('You have been logged out.');
} else
if (empty($return_path)) {
// See if a return path was set.
$return_path = get_last_view(false);
}
if (!empty($return_path)) {
$url = $return_path = clean_whitespace($return_path);
} else {
$url = 'index.php';
}
// If Application Name is set to "Title" then get translation.
// If not, use the Admin defined Application Name.
$appStr = generate_application_name();
$login = getPostValue('login');
$password = getPostValue('password');
$remember = getPostValue('remember');
// Calculate path for cookie.
if (empty($PHP_SELF)) {
$PHP_SELF = $_SERVER['PHP_SELF'];
}
$cookie_path = str_replace('login.php', '', $PHP_SELF);
if ($single_user == 'Y' || $use_http_auth) {
// No login for single-user mode or when using HTTP authorization.
do_redirect('index.php');
} else {
if (!empty($login) && !$logout) {
$login = trim($login);
$badLoginStr = translate('Illegal characters in login XXX.');
if ($login != addslashes($login))
die_miserable_death(
str_replace('XXX', htmlentities($login), $badLoginStr)
);
if (empty($password)) {
if (empty($error) && $showLoginFailureReason) {
$error = translate('You must provide a password.');
} else if (empty($error)) {
$error = translate('Invalid login');
}
} else if (user_valid_login($login, $password)) {
user_load_variables($login, '');
$salt = chr(rand(ord('A'), ord('z')))
. chr(rand(ord('A'), ord('z')));
$encoded_login = encode_string($login . '|' . crypt($password, $salt));
// If $remember, set login to expire in 365 days.
$timeStr = (!empty($remember) && $remember == 'yes'
? time() + 31536000 : 0);
sendCookie('webcalendar_session', $encoded_login, $timeStr, $cookie_path);
// The cookie "webcalendar_login" is provided as a convenience to other
// apps that may wish to know what was the last calendar login,
// so they can use week_ssi.php as a server-side include.
// As such, it's not a security risk to have it un-encoded since it is not
// used to allow logins within this app. It is used to load user
// preferences on the login page (before anyone has logged in)
// if $REMEMBER_LAST_LOGIN is set to "Y" (in admin.php).
sendCookie('webcalendar_login', $login, $timeStr, $cookie_path);
if (!empty($GLOBALS['newUserUrl'])) {
$url = $GLOBALS['newUserUrl'];
}
do_redirect($url);
} else {
// Invalid login.
if (empty($error) || !$showLoginFailureReason) {
$error = translate('Invalid login', true);
echo "ERROR: $error"; exit;
}
activity_log(
0,
'system',
'',
LOG_LOGIN_FAILURE,
str_replace(
['XXX', 'YYY'],
[$login, $_SERVER['REMOTE_ADDR']],
translate('Activity login failure')
)
);
}
} else {
// No login info... just present empty login page.
//$error = "Start";
}
// Delete current user.
sendCookie('webcalendar_session', '', 0, $cookie_path);
// In older versions, the cookie path had no trailing slash and NS 4.78
// thinks "path/" and "path" are different, so the line above does not
// delete the "old" cookie. This prohibits the login. So we also delete the
// cookie with the trailing slash removed.
if (substr($cookie_path, -1) == '/') {
sendCookie('webcalendar_session', '', 0, substr($cookie_path, 0, -1));
}
}
echo send_doctype($appStr);
echo $ASSETS;
// Print custom header (since we do not call print_header function).
if ( ! empty ( $CUSTOM_SCRIPT ) && $CUSTOM_SCRIPT == 'Y' ) {
echo load_template ( $login, 'S' );
}
?>
</head>
<body id="login">
<div class="container">
<?php
// Print custom header (since we do not call print_header function).
if ( ! empty ( $CUSTOM_HEADER ) && $CUSTOM_HEADER == 'Y' ) {
echo load_template ( $login, 'H' );
}
?>
<div id="login-container" class="container">
<div class="row pl-3">
<form id="login-form" class="form" action="login.php" method="post">
<div class="row justify-content-md-center">
<h3><?php echo htmlentities($appStr); ?> Login</h3>
</div>
<?php if ( ! empty ( $message )) { ?>
<div class="alert alert-info" role="alert">
<?php echo $message; ?>
</div>
<?php } ?>
<?php if ( ! empty ( $error )) { ?>
<div class="alert alert-warning" role="alert">
<?php echo $error; ?>
</div>
<?php } ?>
<div class="form-group row">
<label for="login" class="text-info">Username:</label><br>
<input type="text" name="login" id="user" class="form-control">
</div>
<div class="form-group row">
<label for="password" class="text-info">Password:</label><br>
<input type="password" name="password" id="password" class="form-control">
</div>
<div class="form-group form-check row">
<input type="checkbox" class="form-check-input" id="remember-me">
<label class="form-check-label" for="exampleCheck1">Remember me</label>
</div>
<div class="form-group row justify-content-md-center">
<button class="btn btn-primary" type="submit"><?php
etranslate ( 'Submit' )?></button>
</div>
<div id="public-calendar-list">
<?php // Non-user calendars
$nulist = get_nonuser_cals();
$remotelist = get_nonuser_cals('', true);
$cals = array_merge($nulist, $remotelist);
$accessStr = translate ( 'Access XXX calendar' );
for ( $i = 0, $cnt = count ( $cals ); $i < $cnt; $i++ ) {
if ( $cals[$i]['cal_is_public'] == 'Y' ) {
echo '<li id="form_' . $cals[$i]['cal_login'] . '" class="form-group row">' .
'<a class="nav" href="nulogin.php?login=' . $cals[$i]['cal_login'] . '">'
. str_replace ( 'XXX', $cals[$i]['cal_fullname'], $accessStr )
. '</a></li>';
}
}
echo "</div>\n";
// Self registration
if ( ! empty ( $ALLOW_SELF_REGISTRATION ) && $ALLOW_SELF_REGISTRATION == 'Y' ) {
// We can limit what domain is allowed to self register.
// $self_registration_domain should have this format "192.168.220.0:255.255.240.0";
$valid_ip = validate_domain();
if ( ! empty ( $valid_ip ) ) {
echo '<div id="register-link" class="form-group row"><a href="register.php">'
. translate ( 'Not yet registered? Register here!' ) . '</a></div>';
}
}
?>
</form>
</div>
</div>
<br>
<?php
echo '<div id="webcalendarVersion"><a href="' . $PROGRAM_URL . '" target="_blank" id="programname">'
. $PROGRAM_NAME . '</a></div>';
// Print custom trailer (since we do not call print_trailer function).
if ( ! empty ( $CUSTOM_TRAILER ) && $CUSTOM_TRAILER == 'Y' ) {
echo load_template ( $login, 'T' );
}
?>
</div>
</body>
</html>