Project

General

Profile

Download (38 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	Copyright (C) 2010 Ermal Lu?i
5
	All rights reserved.
6

    
7
	Copyright (C) 2007, 2008 Scott Ullrich <sullrich@gmail.com>
8
	All rights reserved.
9

    
10
        Copyright (C) 2005-2006 Bill Marquette <bill.marquette@gmail.com>
11
        All rights reserved.
12

    
13
        Copyright (C) 2006 Paul Taylor <paultaylor@winn-dixie.com>.
14
        All rights reserved.
15

    
16
        Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>.
17
        All rights reserved.
18

    
19
        Redistribution and use in source and binary forms, with or without
20
        modification, are permitted provided that the following conditions are met:
21

    
22
        1. Redistributions of source code must retain the above copyright notice,
23
           this list of conditions and the following disclaimer.
24

    
25
        2. Redistributions in binary form must reproduce the above copyright
26
           notice, this list of conditions and the following disclaimer in the
27
           documentation and/or other materials provided with the distribution.
28

    
29
        THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
30
        INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
31
        AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32
        AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
33
        OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34
        SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35
        INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36
        CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
        ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
        POSSIBILITY OF SUCH DAMAGE.
39

    
40
		DISABLE_PHP_LINT_CHECKING
41
		pfSense_BUILDER_BINARIES:	/usr/sbin/pw	/bin/cp
42
		pfSense_MODULE:	auth
43
*/
44

    
45
/*
46
 * NOTE : Portions of the mschapv2 support was based on the BSD licensed CHAP.php
47
 * file courtesy of Michael Retterklieber.
48
 */
49
if(!$do_not_include_config_gui_inc)
50
	require_once("config.gui.inc");
51

    
52
// Will be changed to false if security checks fail
53
$security_passed = true;
54

    
55
/* If this function doesn't exist, we're being called from Captive Portal or 
56
   another internal subsystem which does not include authgui.inc */
57
if (function_exists("display_error_form") && !isset($config['system']['webgui']['nodnsrebindcheck'])) {
58
	/* DNS ReBinding attack prevention.  http://redmine.pfsense.org/issues/708 */
59
	$found_host = false;
60
	if(strstr($_SERVER['HTTP_HOST'], ":")) {
61
		$http_host_port = explode(":", $_SERVER['HTTP_HOST']);
62
		$http_host = $http_host_port[0];
63
	} else {
64
		$http_host = $_SERVER['HTTP_HOST'];
65
	}
66
	if(is_ipaddr($http_host) or $_SERVER['SERVER_ADDR'] == "127.0.0.1" or
67
			strcasecmp($http_host, "localhost") == 0)
68
		$found_host = true;
69
	if(strcasecmp($http_host, $config['system']['hostname'] . "." . $config['system']['domain']) == 0 or
70
			strcasecmp($http_host, $config['system']['hostname']) == 0)
71
		$found_host = true;
72

    
73
	if(is_array($config['dyndnses']['dyndns']) && !$found_host)
74
		foreach($config['dyndnses']['dyndns'] as $dyndns)
75
			if(strcasecmp($dyndns['host'], $http_host) == 0) {
76
				$found_host = true;
77
				break;
78
			}
79

    
80
	if(!empty($config['system']['webgui']['althostnames']) && !$found_host) {
81
		$althosts = explode(" ", $config['system']['webgui']['althostnames']);
82
		foreach ($althosts as $ah)
83
			if(strcasecmp($ah, $http_host) == 0 or strcasecmp($ah, $_SERVER['SERVER_ADDR']) == 0) {
84
				$found_host = true;
85
				break;
86
			}
87
	}
88

    
89
	if($found_host == false) {
90
		if(!security_checks_disabled()) {
91
			display_error_form("501", "Potential DNS Rebind attack detected, see http://en.wikipedia.org/wiki/DNS_rebinding<br/>Try accessing the router by IP address instead of by hostname.");
92
			exit;
93
		}
94
		$security_passed = false;
95
	}
96
}
97

    
98
// If the HTTP_REFERER is something other than ourselves then disallow.
99
if(function_exists("display_error_form") && !isset($config['system']['webgui']['nohttpreferercheck'])) {
100
	if($_SERVER['HTTP_REFERER']) {
101
		if(file_exists("{$g['tmp_path']}/setupwizard_lastreferrer")) {
102
			if($_SERVER['HTTP_REFERER'] == file_get_contents("{$g['tmp_path']}/setupwizard_lastreferrer")) {
103
				unlink("{$g['tmp_path']}/setupwizard_lastreferrer");
104
				header("Refresh: 1; url=index.php");
105
				echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n        \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
106
				echo "<html><head><title>" . gettext("Redirecting...") . "</title></head><body>" . gettext("Redirecting to the dashboard...") . "</body></html>";
107
				exit;
108
			}
109
		}
110
		$found_host = false;
111
		$referrer_host = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
112
		if($referrer_host) {
113
			if(strcasecmp($referrer_host, $config['system']['hostname'] . "." . $config['system']['domain']) == 0
114
					|| strcasecmp($referrer_host, $config['system']['hostname']) == 0)
115
				$found_host = true;
116
			if(!empty($config['system']['webgui']['althostnames']) && !$found_host) {
117
				$althosts = explode(" ", $config['system']['webgui']['althostnames']);
118
				foreach ($althosts as $ah) {
119
					if(strcasecmp($referrer_host, $ah) == 0) {
120
						$found_host = true;
121
						break;
122
					}
123
				}
124
			}
125
			if(!$found_host) {
126
				$interface_list_ips = get_configured_ip_addresses();
127
				foreach($interface_list_ips as $ilips) {
128
					if(strcasecmp($referrer_host, $ilips) == 0) {
129
						$found_host = true;
130
						break;
131
					}
132
				}
133
			}
134
		}
135
		if($found_host == false) {
136
			if(!security_checks_disabled()) {
137
				display_error_form("501", "An HTTP_REFERER was detected other than what is defined in System -> Advanced (" . htmlspecialchars($_SERVER['HTTP_REFERER']) . ").  You can disable this check if needed in System -> Advanced -> Admin.");
138
				exit;
139
			}
140
			$security_passed = false;
141
		}
142
	} else
143
		$security_passed = false;
144
}
145

    
146
if (function_exists("display_error_form") && $security_passed)
147
	/* Security checks passed, so it should be OK to turn them back on */
148
	restore_security_checks();
149
unset($security_passed);
150

    
151
$groupindex = index_groups();
152
$userindex = index_users();
153

    
154
function index_groups() {
155
	global $g, $debug, $config, $groupindex;
156

    
157
	$groupindex = array();
158

    
159
	if (is_array($config['system']['group'])) {
160
		$i = 0;
161
		foreach($config['system']['group'] as $groupent) {
162
			$groupindex[$groupent['name']] = $i;
163
			$i++;
164
		}
165
	}
166

    
167
	return ($groupindex);
168
}
169

    
170
function index_users() {
171
	global $g, $debug, $config;
172

    
173
	if (is_array($config['system']['user'])) {
174
		$i = 0;
175
		foreach($config['system']['user'] as $userent) {
176
			$userindex[$userent['name']] = $i;
177
			$i++;
178
		}
179
	}
180

    
181
	return ($userindex);
182
}
183

    
184
function & getUserEntry($name) {
185
	global $debug, $config, $userindex;
186
	if (isset($userindex[$name]))
187
		return $config['system']['user'][$userindex[$name]];
188
}
189

    
190
function & getUserEntryByUID($uid) {
191
	global $debug, $config;
192
	foreach ($config['system']['user'] as & $user)
193
		if ($user['uid'] == $uid)
194
			return $user;
195

    
196
	return false;
197
}
198

    
199
function & getGroupEntry($name) {
200
	global $debug, $config, $groupindex;
201
	if (isset($groupindex[$name]))
202
		return $config['system']['group'][$groupindex[$name]];
203
}
204

    
205
function & getGroupEntryByGID($gid) {
206
	global $debug, $config;
207
	foreach ($config['system']['group'] as & $group)
208
		if ($group['gid'] == $gid)
209
			return $group;
210

    
211
	return false;
212
}
213

    
214
function get_user_privileges(& $user) {
215

    
216
        $privs = $user['priv'];
217
        if (!is_array($privs))
218
                $privs = array();
219

    
220
        $names = local_user_get_groups($user, true);
221

    
222
        foreach ($names as $name) {
223
                $group = getGroupEntry($name);
224
                if (is_array($group['priv']))
225
                        $privs = array_merge( $privs, $group['priv']);
226
        }
227

    
228
        return $privs;
229
}
230

    
231
function userHasPrivilege($userent, $privid = false) {
232

    
233
        if (!$privid || !is_array($userent))
234
                return false;
235

    
236
        $privs = get_user_privileges($userent);
237

    
238
        if (!is_array($privs))
239
                return false;
240

    
241
        if (!in_array($privid, $privs))
242
                return false;
243

    
244
        return true;
245
}
246

    
247
function local_backed($username, $passwd) {
248

    
249
	$user = getUserEntry($username);
250
	if (!$user)
251
		return false;
252

    
253
	if (is_account_disabled($username) || is_account_expired($username))
254
		return false;
255

    
256
	if ($user['password'])
257
	{
258
		$passwd = crypt($passwd, $user['password']);
259
		if ($passwd == $user['password'])
260
			return true;
261
	}
262

    
263
	if ($user['md5-hash'])
264
	{
265
		$passwd = md5($passwd);
266
		if ($passwd == $user['md5-hash'])
267
			return true;
268
	}
269

    
270
	return false;
271
}
272

    
273
function local_sync_accounts() {
274
	global $debug, $config;
275
	conf_mount_rw();
276

    
277
	/* remove local users to avoid uid conflicts */
278
	$fd = popen("/usr/sbin/pw usershow -a", "r");
279
	if ($fd) {
280
		while (!feof($fd)) {
281
			$line = explode(":",fgets($fd));
282
			if (!strncmp($line[0], "_", 1))
283
				continue;
284
			if ($line[2] < 2000)
285
				continue;
286
			if ($line[2] > 65000)
287
				continue;
288
			$cmd = "/usr/sbin/pw userdel {$line[2]}";
289
			if($debug)
290
				log_error("Running: {$cmd}");
291
			mwexec($cmd);
292
		}
293
		pclose($fd);
294
	}
295

    
296
	/* remove local groups to avoid gid conflicts */
297
	$gids = array();
298
	$fd = popen("/usr/sbin/pw groupshow -a", "r");
299
	if ($fd) {
300
		while (!feof($fd)) {
301
			$line = explode(":",fgets($fd));
302
			if (!strncmp($line[0], "_", 1))
303
				continue;
304
			if ($line[2] < 2000)
305
				continue;
306
			if ($line[2] > 65000)
307
				continue;
308
			$cmd = "/usr/sbin/pw groupdel {$line[2]}";
309
			if($debug)
310
				log_error("Running: {$cmd}");
311
			mwexec($cmd);
312
		}
313
		pclose($fd);
314
	}
315

    
316
	/* make sure the all group exists */
317
	$allgrp = getGroupEntryByGID(1998);
318
	local_group_set($allgrp, true);
319

    
320
	/* sync all local users */
321
	if (is_array($config['system']['user']))
322
		foreach ($config['system']['user'] as $user)
323
			local_user_set($user);
324

    
325
	/* sync all local groups */
326
	if (is_array($config['system']['group']))
327
		foreach ($config['system']['group'] as $group)
328
			local_group_set($group);
329

    
330
	conf_mount_ro();
331

    
332
}
333

    
334
function local_user_set(& $user) {
335
	global $g, $debug;
336

    
337
	conf_mount_rw();
338

    
339
	$home_base = "/home/";	
340
	$user_uid = $user['uid'];
341
	$user_name = $user['name'];
342
	$user_home = "{$home_base}{$user_name}";
343
	$user_shell = "/etc/rc.initial";
344
	$user_group = "nobody";
345

    
346
	// Ensure $home_base exists and is writable
347
	if (!is_dir($home_base)) 
348
		mkdir($home_base, 0755);
349

    
350
	$lock_account = false;
351
	/* configure shell type */
352
	/* Cases here should be ordered by most privileged to least privileged. */
353
	if (userHasPrivilege($user, "user-shell-access") || userHasPrivilege($user, "page-all")) {
354
		$user_shell = "/bin/tcsh";
355
	} elseif (userHasPrivilege($user, "user-copy-files")) {
356
		$user_shell = "/usr/local/bin/scponly";
357
	} elseif (userHasPrivilege($user, "user-ssh-tunnel")) {
358
		$user_shell = "/usr/local/sbin/ssh_tunnel_shell";
359
	} else {
360
		$user_shell = "/sbin/nologin";
361
		$lock_account = true;
362
	}
363

    
364
	/* Lock out disabled or expired users, unless it's root/admin. */
365
	if ((is_account_disabled($user_name) || is_account_expired($user_name)) && ($user_uid != 0)) {
366
		$user_shell = "/sbin/nologin";
367
		$lock_account = true;
368
	}
369

    
370
	/* root user special handling */
371
	if ($user_uid == 0) {
372
		$cmd = "/usr/sbin/pw usermod -q -n root -s /bin/sh -H 0";
373
		if($debug)
374
			log_error("Running: {$cmd}");
375
		$fd = popen($cmd, "w");
376
		fwrite($fd, $user['password']);
377
		pclose($fd);
378
		$user_group = "wheel";
379
		$user_home = "/root";
380
		$user_shell = "/etc/rc.initial";
381
	}
382

    
383
	/* read from pw db */
384
	$fd = popen("/usr/sbin/pw usershow {$user_name} 2>&1", "r");
385
	$pwread = fgets($fd);
386
	pclose($fd);
387

    
388
	/* determine add or mod */
389
	if (!strncmp($pwread, "pw:", 3)) {
390
		$user_op = "useradd -m -k /etc/skel -o";
391
	} else {
392
		$user_op = "usermod";
393
	}
394

    
395
	/* add or mod pw db */
396
	$cmd = "/usr/sbin/pw {$user_op} -q -u {$user_uid} -n {$user_name}".
397
			" -g {$user_group} -s {$user_shell} -d {$user_home}".
398
			" -c ".escapeshellarg($user['descr'])." -H 0 2>&1";
399

    
400
	if($debug)
401
		log_error("Running: {$cmd}");
402
	$fd = popen($cmd, "w");
403
	fwrite($fd, $user['password']);
404
	pclose($fd);
405

    
406
	/* create user directory if required */
407
	if (!is_dir($user_home)) {
408
		mkdir($user_home, 0700);
409
		mwexec("cp /root/.* {$home_base}/");
410
	}
411
	chown($user_home, $user_name);
412
	chgrp($user_home, $user_group);
413

    
414
	/* write out ssh authorized key file */
415
	if($user['authorizedkeys']) {
416
		if (!is_dir("{$user_home}/.ssh")) {
417
			mkdir("{$user_home}/.ssh", 0700);
418
			chown("{$user_home}/.ssh", $user_name);
419
		}
420
		$keys = base64_decode($user['authorizedkeys']);
421
		file_put_contents("{$user_home}/.ssh/authorized_keys", $keys);
422
		chown("{$user_home}/.ssh/authorized_keys", $user_name);
423
	}
424

    
425
	$un = $lock_account ? "" : "un";
426
	exec("/usr/sbin/pw {$un}lock -q {$user_name}");
427
	
428
	conf_mount_ro();
429
}
430

    
431
function local_user_del($user) {
432
	global $debug;
433

    
434
	/* remove all memberships */
435
	local_user_set_groups($user);
436

    
437
	/* Don't remove /root */
438
	if ($user['uid'] != 0)
439
		$rmhome = "-r";
440

    
441
	/* delete from pw db */
442
	$cmd = "/usr/sbin/pw userdel {$user['name']} {$rmhome}";
443

    
444
	if($debug)
445
		log_error("Running: {$cmd}");
446
	mwexec($cmd);
447

    
448
	/* Delete user from groups needs a call to write_config() */
449
	local_group_del_user($user);
450
}
451

    
452
function local_user_set_password(& $user, $password) {
453

    
454
	$user['password'] = crypt($password);
455
	$user['md5-hash'] = md5($password);
456

    
457
	// Converts ascii to unicode.
458
	$astr = (string) $password;
459
	$ustr = '';
460
	for ($i = 0; $i < strlen($astr); $i++) {
461
		$a = ord($astr{$i}) << 8;
462
		$ustr.= sprintf("%X", $a);
463
	}
464

    
465
	// Generate the NT-HASH from the unicode string
466
	$user['nt-hash'] = bin2hex(mhash(MHASH_MD4, $ustr));
467
}
468

    
469
function local_user_get_groups($user, $all = false) {
470
	global $debug, $config;
471

    
472
	$groups = array();
473
	if (!is_array($config['system']['group']))
474
		return $groups;
475

    
476
	foreach ($config['system']['group'] as $group)
477
		if ( $all || ( !$all && ($group['name'] != "all")))
478
			if (is_array($group['member']))
479
				if (in_array($user['uid'], $group['member']))
480
					$groups[] = $group['name'];
481

    
482
	if ( $all )
483
		$groups[] = "all";
484

    
485
	sort($groups);
486

    
487
	return $groups;
488
	
489
}
490

    
491
function local_user_set_groups($user, $new_groups = NULL ) {
492
	global $debug, $config, $groupindex;
493

    
494
	if (!is_array($config['system']['group']))
495
		return;
496

    
497
	$cur_groups = local_user_get_groups($user, true);
498
	$mod_groups = array();
499

    
500
	if (!is_array($new_groups))
501
		$new_groups = array();
502

    
503
	if (!is_array($cur_groups))
504
		$cur_groups = array();
505

    
506
	/* determine which memberships to add */
507
	foreach ($new_groups as $groupname) {
508
		if (in_array($groupname,$cur_groups))
509
			continue;
510
		$group = & $config['system']['group'][$groupindex[$groupname]];
511
		$group['member'][] = $user['uid'];
512
		$mod_groups[] = $group;
513
	}
514
	unset($group);
515

    
516
	/* determine which memberships to remove */
517
	foreach ($cur_groups as $groupname) {
518
		if (in_array($groupname,$new_groups))
519
			continue;
520
		if (!isset($config['system']['group'][$groupindex[$groupname]]))
521
			continue;
522
		$group = & $config['system']['group'][$groupindex[$groupname]];
523
		if (is_array($group['member'])) {
524
			$index = array_search($user['uid'], $group['member']);
525
			array_splice($group['member'], $index, 1);
526
			$mod_groups[] = $group;
527
		}
528
	}
529
	unset($group);
530

    
531
	/* sync all modified groups */
532
	foreach ($mod_groups as $group)
533
		local_group_set($group);
534
}
535

    
536
function local_group_del_user($user) {
537
	global $config;
538

    
539
	if (!is_array($config['system']['group']))
540
                return;
541

    
542
        foreach ($config['system']['group'] as $group) {
543
		if (is_array($group['member'])) {
544
			foreach ($group['member'] as $idx => $uid) {
545
				if ($user['uid'] == $uid)
546
					unset($config['system']['group']['member'][$idx]);
547
			}
548
		}
549
	}
550
}
551

    
552
function local_group_set($group, $reset = false) {
553
	global $debug;
554

    
555
	$group_name = $group['name'];
556
	$group_gid = $group['gid'];
557
	$group_members = "''";
558
	if (!$reset && !empty($group['member']) && count($group['member']) > 0)
559
		$group_members = implode(",",$group['member']);
560

    
561
	/* read from group db */
562
	$fd = popen("/usr/sbin/pw groupshow {$group_name} 2>&1", "r");
563
	$pwread = fgets($fd);
564
	pclose($fd);
565

    
566
	/* determine add or mod */
567
	if (!strncmp($pwread, "pw:", 3))
568
		$group_op = "groupadd";
569
	else
570
		$group_op = "groupmod";
571

    
572
	/* add or mod group db */
573
	$cmd = "/usr/sbin/pw {$group_op} {$group_name} -g {$group_gid} -M {$group_members} 2>&1";
574

    
575
	if($debug)
576
		log_error("Running: {$cmd}");
577
	mwexec($cmd);
578

    
579
}
580

    
581
function local_group_del($group) {
582
	global $debug;
583

    
584
	/* delete from group db */
585
	$cmd = "/usr/sbin/pw groupdel {$group['name']}";
586

    
587
	if($debug)
588
		log_error("Running: {$cmd}");
589
	mwexec($cmd);
590
}
591

    
592
function ldap_test_connection($authcfg) {
593
	global $debug, $config, $g;
594

    
595
	if ($authcfg) {
596
                if (strstr($authcfg['ldap_urltype'], "Standard"))
597
                        $ldapproto = "ldap";
598
                else
599
                        $ldapproto = "ldaps";
600
                $ldapserver         = "{$ldapproto}://{$authcfg['host']}";
601
                $ldapport           = $authcfg['ldap_port'];
602
                $ldapbasedn         = $authcfg['ldap_basedn'];
603
                $ldapbindun         = $authcfg['ldap_binddn'];
604
                $ldapbindpw         = $authcfg['ldap_bindpw'];
605
        } else
606
		return false;
607

    
608
        /* first check if there is even an LDAP server populated */
609
        if(!$ldapserver)
610
                return false;
611

    
612
        /* connect and see if server is up */
613
        putenv('LDAPTLS_REQCERT=never');
614
        $error = false;
615
        if (empty($ldapport)) {
616
                if (!($ldap = ldap_connect($ldapserver)))
617
                        $error = true;
618
        } else if (!($ldap = ldap_connect($ldapserver, $ldapport)))
619
                $error = true;
620

    
621
        if ($error == true) {
622
                log_error("ERROR!  Could not connect to server {$ldapname}.");
623
                return false;
624
        }
625

    
626
	return true;
627
}
628

    
629
function ldap_test_bind($authcfg) {
630
	global $debug, $config, $g;
631

    
632
	if ($authcfg) {
633
                if (strstr($authcfg['ldap_urltype'], "Standard"))
634
                        $ldapproto = "ldap";
635
                else
636
                        $ldapproto = "ldaps";
637
                $ldapserver         = "{$ldapproto}://{$authcfg['host']}";
638
                $ldapport           = $authcfg['ldap_port'];
639
                $ldapbasedn         = $authcfg['ldap_basedn'];
640
                $ldapbindun         = $authcfg['ldap_binddn'];
641
                $ldapbindpw         = $authcfg['ldap_bindpw'];
642
                $ldapver            = $authcfg['ldap_protver'];
643
		if (empty($ldapbndun) || empty($ldapbindpw))
644
                        $ldapanon = true;
645
                else
646
                        $ldapanon = false;
647
	} else
648
		return false;
649

    
650
	/* first check if there is even an LDAP server populated */
651
        if(!$ldapserver)
652
                return false;
653

    
654
        /* connect and see if server is up */
655
        putenv('LDAPTLS_REQCERT=never');
656
        $error = false;
657
        if (empty($ldapport)) {
658
                if (!($ldap = ldap_connect($ldapserver)))
659
                        $error = true;
660
        } else if (!($ldap = ldap_connect($ldapserver, $ldapport)))
661
                $error = true;
662

    
663
        if ($error == true) {
664
                log_error("ERROR!  Could not connect to server {$ldapname}.");
665
                return false;
666
        }
667

    
668
	ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
669
	ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, (int)$ldapver);
670
 
671
	if ($ldapanon == true) {
672
		if (!($res = @ldap_bind($ldap))) {
673
			@ldap_close($ldap);
674
			return false;
675
		}
676
	} else if (!($res = @ldap_bind($ldap, $ldapbindun, $ldapbindpw))) {
677
		@ldap_close($ldap);
678
		return false;
679
	}
680

    
681
	@ldap_unbind($ldap);
682

    
683
	return true;
684
}
685

    
686
function ldap_get_user_ous($show_complete_ou=true, $authcfg) {
687
	global $debug, $config, $g;
688

    
689
	if(!function_exists("ldap_connect"))
690
		return;
691

    
692
	$ous = array();
693

    
694
	if ($authcfg) {
695
                if (strstr($authcfg['ldap_urltype'], "Standard"))
696
                        $ldapproto = "ldap";
697
                else
698
                        $ldapproto = "ldaps";
699
                $ldapserver         = "{$ldapproto}://{$authcfg['host']}";
700
                $ldapport           = $authcfg['ldap_port'];
701
                $ldapbasedn         = $authcfg['ldap_basedn'];
702
                $ldapbindun         = $authcfg['ldap_binddn'];
703
                $ldapbindpw         = $authcfg['ldap_bindpw'];
704
                $ldapver            = $authcfg['ldap_protver'];
705
		if (empty($ldapbindun) || empty($ldapbindpw))
706
                        $ldapanon = true;
707
                else
708
                        $ldapanon = false;
709
                $ldapname           = $authcfg['name'];
710
                $ldapfallback       = false;
711
		$ldapscope          = $authcfg['ldap_scope'];
712
        } else
713
		return false;
714

    
715
        /* first check if there is even an LDAP server populated */
716
        if(!$ldapserver) {
717
                log_error("ERROR!  ldap_get_user_ous() backed selected with no LDAP authentication server defined.");
718
                return $ous;
719
        }
720

    
721
	/* connect and see if server is up */
722
        putenv('LDAPTLS_REQCERT=never');
723
        $error = false;
724
        if (empty($ldapport)) {
725
                if (!($ldap = ldap_connect($ldapserver)))
726
                        $error = true;
727
        } else if (!($ldap = ldap_connect($ldapserver, $ldapport)))
728
                $error = true;
729

    
730
        if ($error == true) {
731
		log_error("ERROR!  Could not connect to server {$ldapname}.");
732
                return $ous;
733
        }
734

    
735
	$ldapfilter = "(|(ou=*)(cn=Users))";
736

    
737
	ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
738
	ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, (int)$ldapver);
739

    
740
	if ($ldapanon == true) {
741
                if (!($res = @ldap_bind($ldap))) {
742
			log_error("ERROR! ldap_get_user_ous() could not bind anonymously to server {$ldapname}.");
743
			@ldap_close($ldap);
744
                        return $ous;
745
		}
746
	} else if (!($res = @ldap_bind($ldap, $ldapbindun, $ldapbindpw))) {
747
		log_error("ERROR! ldap_get_user_ous() could not bind to server {$ldapname}.");
748
		@ldap_close($ldap);
749
		return $ous;
750
	}
751

    
752
	if ($ldapscope == "one")
753
		$ldapfunc = "ldap_list";
754
	else
755
		$ldapfunc = "ldap_search";
756

    
757
	$search = @$ldapfunc($ldap, $ldapbasedn, $ldapfilter);
758
	$info = @ldap_get_entries($ldap, $search);
759

    
760
	if (is_array($info)) {
761
		foreach ($info as $inf) {
762
			if (!$show_complete_ou) {
763
				$inf_split = split(",", $inf['dn']);
764
				$ou = $inf_split[0];
765
				$ou = str_replace("OU=","", $ou);
766
				$ou = str_replace("CN=","", $ou);
767
			} else
768
				if($inf['dn'])
769
					$ou = $inf['dn'];
770
			if($ou)
771
				$ous[] = $ou;
772
		}
773
	}
774

    
775
	@ldap_unbind($ldap);
776

    
777
	return $ous;
778
}
779

    
780
function ldap_get_groups($username, $authcfg) {
781
	global $debug, $config;
782
	
783
	if(!function_exists("ldap_connect"))
784
		return;
785
	
786
	if(!$username) 
787
		return false;
788

    
789
	if(stristr($username, "@")) {
790
		$username_split=split("\@", $username);
791
		$username = $username_split[0];		
792
	}
793

    
794
	if(stristr($username, "\\")) {
795
		$username_split=split("\\", $username);
796
		$username = $username_split[0];        
797
	}    
798
	
799
	//log_error("Getting LDAP groups for {$username}.");
800
        if ($authcfg) {
801
                if (strstr($authcfg['ldap_urltype'], "Standard"))
802
                        $ldapproto = "ldap";
803
                else
804
                        $ldapproto = "ldaps";
805
                $ldapserver         = "{$ldapproto}://{$authcfg['host']}";
806
                $ldapport           = $authcfg['ldap_port'];
807
                $ldapbasedn         = $authcfg['ldap_basedn'];
808
                $ldapbindun         = $authcfg['ldap_binddn'];
809
                $ldapbindpw         = $authcfg['ldap_bindpw'];
810
                $ldapauthcont       = $authcfg['ldap_authcn'];
811
                $ldapnameattribute  = strtolower($authcfg['ldap_attr_user']);
812
                $ldapgroupattribute  = strtolower($authcfg['ldap_attr_member']);
813
                $ldapfilter         = "({$ldapnameattribute}={$username})";
814
                $ldaptype           = "";
815
                $ldapver            = $authcfg['ldap_protver'];
816
		if (empty($ldapbindun) || empty($ldapbindpw))
817
                        $ldapanon = true;
818
                else
819
                        $ldapanon = false;
820
                $ldapname           = $authcfg['name'];
821
                $ldapfallback       = false;
822
		$ldapscope          = $authcfg['ldap_scope'];
823
	} else
824
		return false;
825

    
826
	$ldapdn             = $_SESSION['ldapdn'];
827

    
828
	/*Convert attribute to lowercase.  php ldap arrays put everything in lowercase */
829
	$ldapgroupattribute = strtolower($ldapgroupattribute);
830
	$memberof = array();
831

    
832
	/* connect and see if server is up */
833
	putenv('LDAPTLS_REQCERT=never');
834
	$error = false;
835
        if (empty($ldapport)) {
836
                if (!($ldap = ldap_connect($ldapserver)))
837
                        $error = true;
838
        } else if (!($ldap = ldap_connect($ldapserver, $ldapport)))
839
                $error = true;
840

    
841
	if ($error == true) {
842
		log_error("ERROR! ldap_get_groups() Could not connect to server {$ldapname}.");
843
                return memberof;
844
        }
845
    
846
	ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
847
	ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, (int)$ldapver);
848

    
849
	/* bind as user that has rights to read group attributes */
850
	if ($ldapanon == true) {
851
                if (!($res = @ldap_bind($ldap))) {
852
			log_error("ERROR! ldap_get_groups() could not bind anonymously to server {$ldapname}.");
853
			@ldap_close($ldap);
854
                        return false;
855
		}
856
	} else if (!($res = @ldap_bind($ldap, $ldapbindun, $ldapbindpw))) {
857
		log_error("ERROR! ldap_get_groups() could not bind to server {$ldapname}.");
858
		@ldap_close($ldap);
859
		return memberof;
860
	}
861

    
862
	/* get groups from DN found */
863
	/* use ldap_read instead of search so we don't have to do a bunch of extra work */
864
	/* since we know the DN is in $_SESSION['ldapdn'] */
865
	//$search    = ldap_read($ldap, $ldapdn, "(objectclass=*)", array($ldapgroupattribute));
866
	if ($ldapscope == "one")
867
                $ldapfunc = "ldap_list";
868
        else
869
                $ldapfunc = "ldap_search";
870

    
871
	$search    = @$ldapfunc($ldap, $ldapdn, $ldapfilter, array($ldapgroupattribute));
872
	$info      = @ldap_get_entries($ldap, $search);
873

    
874
	$countem = $info["count"];	
875
	
876
	if(is_array($info[0][$ldapgroupattribute])) {
877
		/* Iterate through the groups and throw them into an array */
878
		foreach ($info[0][$ldapgroupattribute] as $member) {
879
			if (stristr($member, "CN=") !== false) {
880
				$membersplit = split(",", $member);
881
				$memberof[] = preg_replace("/CN=/i", "", $membersplit[0]);
882
			}
883
		}
884
	}
885
	
886
	/* Time to close LDAP connection */
887
	@ldap_unbind($ldap);
888
	
889
	$groups = print_r($memberof,true);
890
	
891
	//log_error("Returning groups ".$groups." for user $username");
892
	
893
	return $memberof;
894
}
895

    
896
function ldap_backed($username, $passwd, $authcfg) {
897
	global $debug, $config;
898
	
899
	if(!$username) 
900
		return;
901

    
902
	if(!function_exists("ldap_connect"))
903
		return;
904

    
905
	if(stristr($username, "@")) {
906
		$username_split=split("\@", $username);
907
		$username = $username_split[0];        
908
	}
909
	if(stristr($username, "\\")) {
910
		$username_split=split("\\", $username);
911
		$username = $username_split[0];        
912
	}
913

    
914
	if ($authcfg) {
915
		if (strstr($authcfg['ldap_urltype'], "Standard"))
916
			$ldapproto = "ldap";
917
		else
918
			$ldapproto = "ldaps";
919
		$ldapserver         = "{$ldapproto}://{$authcfg['host']}";
920
		$ldapport	    = $authcfg['ldap_port'];
921
                $ldapbasedn         = $authcfg['ldap_basedn'];
922
                $ldapbindun         = $authcfg['ldap_binddn'];
923
                $ldapbindpw         = $authcfg['ldap_bindpw'];
924
		if (empty($ldapbindun) || empty($ldapbindpw))
925
			$ldapanon = true;
926
		else
927
			$ldapanon = false;
928
                $ldapauthcont       = $authcfg['ldap_authcn'];
929
                $ldapnameattribute  = strtolower($authcfg['ldap_attr_user']);
930
                $ldapfilter         = "({$ldapnameattribute}={$username})";
931
                $ldaptype           = "";
932
                $ldapver            = $authcfg['ldap_protver'];
933
		$ldapname	    = $authcfg['name'];
934
		$ldapscope	    = $authcfg['ldap_scope'];
935
	} else
936
		return false;
937

    
938
	/* first check if there is even an LDAP server populated */ 
939
	if(!$ldapserver) {
940
		if ($ldapfallback) {
941
			log_error("ERROR! ldap_backed() called with no LDAP authentication server defined.  Defaulting to local user database. Visit System -> User Manager.");
942
			return local_backed($username, $passwd);
943
		} else
944
			log_error("ERROR! ldap_backed() called with no LDAP authentication server defined.");
945

    
946
		return false;
947
	}
948
	
949
	ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
950
	ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, (int)$ldapver);
951

    
952
	/* Make sure we can connect to LDAP */
953
	putenv('LDAPTLS_REQCERT=never');
954
	$error = false;
955
	if (empty($ldapport)) {
956
		if (!($ldap = ldap_connect($ldapserver)))
957
			$error = true;
958
	} else if (!($ldap = ldap_connect($ldapserver, $ldapport)))
959
		$error = true;
960

    
961
	if ($error == true) {
962
		log_error("ERROR!  Could not connect to server {$ldapname}.");
963
		return false;
964
	}
965

    
966
	/* ok, its up.  now, lets bind as the bind user so we can search it */
967
	$error = false;
968
	if ($ldapanon == true) {
969
                if (!($res = @ldap_bind($ldap)))
970
                        $error = true;
971
	} else if (!($res = ldap_bind($ldap, $ldapbindun, $ldapbindpw)))
972
		$error = true;
973

    
974
	if ($error == true) {
975
		@ldap_close($ldap);
976
		log_error("ERROR! Could not bind to server {$ldapname}.");
977
		return false;
978
	}
979
	
980
	/* Get LDAP Authcontainers and split em up. */
981
	$ldac_splits = split(";", $ldapauthcont);
982
	
983
	/* setup the usercount so we think we havn't found anyone yet */
984
	$usercount  = 0;
985

    
986
	/*****************************************************************/
987
	/*  We First find the user based on username and filter          */
988
	/*  Then, once we find the first occurance of that person        */
989
	/*  We set seesion variables to ponit to the OU and DN of the    */
990
	/*  Person.  To later be used by ldap_get_groups.                */
991
	/*  that way we don't have to search twice.                      */
992
	/*****************************************************************/
993
	log_error("Now Searching for {$username} in directory.");
994
	/* Iterate through the user containers for search */
995
	foreach ($ldac_splits as $i => $ldac_split) {
996
		/* Make sure we just use the first user we find */
997
		log_error("Now Searching in server {$ldapname}, container {$ldac_split} with filter {$ldapfilter}.");
998
		if ($ldapscope == "one")
999
			$ldapfunc = "ldap_list";
1000
		else
1001
			$ldapfunc = "ldap_search";
1002
		/* Support legacy auth container specification. */
1003
		if (stristr($ldac_split, "DC=") || empty($ldapbasedn))
1004
			$search	 = @$ldapfunc($ldap,$ldac_split,$ldapfilter);
1005
		else
1006
			$search  = @$ldapfunc($ldap,"{$ldac_split},{$ldapbasedn}",$ldapfilter);
1007
		if (!$search) {
1008
			log_error("Search resulted in error: " . ldap_error($ldap));
1009
			continue;
1010
		}
1011
		$info	 = ldap_get_entries($ldap,$search);
1012
		$matches = $info['count'];
1013
		if ($matches == 1){
1014
			$userdn = $_SESSION['ldapdn'] = $info[0]['dn'];
1015
			$_SESSION['ldapou'] = $ldac_split[$i];
1016
			$_SESSION['ldapon'] = "true";
1017
			$usercount = 1;
1018
			break;
1019
		}
1020
	}
1021

    
1022
	if ($usercount != 1){
1023
		@ldap_unbind($ldap);
1024
		log_error("ERROR! Either LDAP search failed, or multiple users were found.");
1025
		return false;                         
1026
	}
1027

    
1028
	/* Now lets bind as the user we found */
1029
	if (!($res = @ldap_bind($ldap, $userdn, $passwd))) {
1030
		log_error("ERROR! Could not login to server {$ldapname} as user {$username}.");
1031
		@ldap_unbind($ldap);
1032
		return false;
1033
	}
1034

    
1035
	log_error("Logged in successfully as {$username} via LDAP server {$ldapname} with DN = {$userdn}.");
1036

    
1037
	/* At this point we are bound to LDAP so the user was auth'd okay. Close connection. */
1038
	@ldap_unbind($ldap);
1039

    
1040
	return true;
1041
}
1042

    
1043
function radius_backed($username, $passwd, $authcfg){
1044
	global $debug, $config;
1045
	$ret = false;
1046

    
1047
	require_once("radius.inc");
1048

    
1049
	$rauth = new Auth_RADIUS_PAP($username, $passwd);
1050
	if ($authcfg) {
1051
		$radiusservers = array();
1052
		$radiusservers[0]['ipaddr'] = $authcfg['host'];
1053
		$radiusservers[0]['port'] = $authcfg['radius_auth_port'];
1054
		$radiusservers[0]['sharedsecret'] = $authcfg['radius_secret'];
1055
	} else
1056
		return false;
1057

    
1058
	/* Add a new servers to our instance */
1059
	foreach ($radiusservers as $radsrv)
1060
		$rauth->addServer($radsrv['ipaddr'], $radsrv['port'], $radsrv['sharedsecret']);
1061

    
1062
	if (PEAR::isError($rauth->start())) {
1063
		$retvalue['auth_val'] = 1;
1064
		$retvalue['error'] = $rauth->getError();
1065
		if ($debug)
1066
			printf("Radius start: %s<br>\n", $retvalue['error']);
1067
	}
1068

    
1069
	// XXX - billm - somewhere in here we need to handle securid challenge/response
1070

    
1071
	/* Send request */
1072
	$result = $rauth->send();
1073
	if (PEAR::isError($result)) {
1074
		$retvalue['auth_val'] = 1;
1075
		$retvalue['error'] = $result->getMessage();
1076
		if ($debug)
1077
			printf("Radius send failed: %s<br>\n", $retvalue['error']);
1078
	} else if ($result === true) {
1079
		$retvalue['auth_val'] = 2;
1080
		if ($debug)
1081
			printf(gettext("Radius Auth succeeded")."<br>\n");
1082
		$ret = true;
1083
	} else {
1084
		$retvalue['auth_val'] = 3;
1085
		if ($debug)
1086
			printf(gettext("Radius Auth rejected")."<br>\n");
1087
	}
1088

    
1089
	// close OO RADIUS_AUTHENTICATION
1090
	$rauth->close();
1091

    
1092
	return $ret;
1093
}
1094

    
1095
function get_user_expiration_date($username) {
1096
	$user = getUserEntry($username);
1097
	if ($user['expires']) 
1098
		return $user['expires'];
1099
}
1100

    
1101
function is_account_expired($username) {
1102
	$expirydate = get_user_expiration_date($username);
1103
	if ($expirydate) {
1104
		if (strtotime("-1 day") > strtotime(date("m/d/Y",strtotime($expirydate))))
1105
			return true;
1106
	}
1107

    
1108
	return false;
1109
}
1110

    
1111
function is_account_disabled($username) {
1112
	$user = getUserEntry($username);
1113
	if (isset($user['disabled']))
1114
		return true;
1115

    
1116
	return false;
1117
}
1118

    
1119
function auth_get_authserver($name) {
1120
        global $config;
1121

    
1122
        if (is_array($config['system']['authserver'])) {
1123
                foreach ($config['system']['authserver'] as $authcfg) {
1124
                        if ($authcfg['name'] == $name)
1125
                                return $authcfg;
1126
                }
1127
        }
1128
	if ($name == "Local Database")
1129
		return array("name" => "Local Database", "type" => "Local Auth", "host" => $config['system']['hostname']);
1130
}
1131

    
1132
function auth_get_authserver_list() {
1133
        global $config;
1134

    
1135
	$list = array();
1136

    
1137
        if (is_array($config['system']['authserver'])) {
1138
                foreach ($config['system']['authserver'] as $authcfg) {
1139
			/* Add support for disabled entries? */
1140
			$list[$authcfg['name']] = $authcfg;
1141
                }
1142
        }
1143

    
1144
	$list["Local Database"] = array( "name" => "Local Database", "type" => "Local Auth", "host" => $config['system']['hostname']);
1145
	return $list;
1146
}
1147

    
1148
function getUserGroups($username, $authcfg) {
1149
	global $config;
1150

    
1151
	$allowed_groups = array();
1152

    
1153
	switch($authcfg['type']) {
1154
        case 'ldap':
1155
		$allowed_groups = @ldap_get_groups($username, $authcfg);
1156
		break;
1157
	case 'radius':
1158
		break;
1159
	default:
1160
		$user = getUserEntry($username);
1161
		$allowed_groups = @local_user_get_groups($user, true);
1162
		break;
1163
	}
1164

    
1165
	$member_groups = array();
1166
        if (is_array($config['system']['group'])) {
1167
                foreach ($config['system']['group'] as $group)
1168
                        if (in_array($group['name'], $allowed_groups))
1169
				$member_groups[] = $group['name'];
1170
	}
1171

    
1172
	return $member_groups;
1173
}
1174

    
1175
function authenticate_user($username, $password, $authcfg = NULL) {
1176

    
1177
	if (!$authcfg) {
1178
		return local_backed($username, $password);
1179
	}
1180

    
1181
	$authenticated = false;
1182
	switch($authcfg['type']) {
1183
        case 'ldap':
1184
                if (ldap_backed($username, $password, $authcfg))
1185
                        $authenticated = true;
1186
                break;
1187
        case 'radius':
1188
                if (radius_backed($username, $password, $authcfg))
1189
                        $authenticated = true;
1190
                break;
1191
        default:
1192
                /* lookup user object by name */
1193
                if (local_backed($username, $password))
1194
                        $authenticated = true;
1195
                break;
1196
        }
1197

    
1198
	return $authenticated;
1199
}
1200

    
1201
function session_auth() {
1202
	global $HTTP_SERVER_VARS, $config, $_SESSION, $page;
1203

    
1204
	session_start();
1205

    
1206
	/* Validate incoming login request */
1207
	if (isset($_POST['login'])) {
1208
		$authcfg = auth_get_authserver($config['system']['webgui']['authmode']);
1209
		if (authenticate_user($_POST['usernamefld'], $_POST['passwordfld'], $authcfg) || 
1210
		    authenticate_user($_POST['usernamefld'], $_POST['passwordfld'])) {
1211
			$_SESSION['Logged_In'] = "True";
1212
			$_SESSION['Username'] = $_POST['usernamefld'];
1213
			$_SESSION['last_access'] = time();
1214
			log_error("Successful login for user '{$_POST['usernamefld']}' from: {$_SERVER['REMOTE_ADDR']}");
1215
			$HTTP_SERVER_VARS['AUTH_USER'] = $_SESSION['Username'];
1216
			if (isset($_POST['postafterlogin']))
1217
				return true;
1218
			else {
1219
				if (empty($page))
1220
					$page = "/";
1221
				header("Location: {$page}");
1222
			}
1223
			exit;
1224
		} else {
1225
			/* give the user an error message */
1226
			$_SESSION['Login_Error'] = "Username or Password incorrect";
1227
			log_error("Login attempt with user: '{$_POST['usernamefld']}' from: '{$_SERVER['REMOTE_ADDR']}' failed.");
1228
			if(isAjax()) {
1229
				echo "showajaxmessage('{$_SESSION['Login_Error']}');";
1230
				return;
1231
			}
1232
		}
1233
	}
1234

    
1235
	/* Show login page if they aren't logged in */
1236
	if (empty($_SESSION['Logged_In']))
1237
		return false;
1238

    
1239
	/* If session timeout isn't set, we don't mark sessions stale */
1240
	if (!isset($config['system']['webgui']['session_timeout'])) {
1241
		/* Default to 4 hour timeout if one is not set */
1242
		if ($_SESSION['last_access'] < (time() - 14400)) {
1243
			$_GET['logout'] = true;
1244
			$_SESSION['Logout'] = true;
1245
		} else
1246
			$_SESSION['last_access'] = time();	
1247
	} else if (intval($config['system']['webgui']['session_timeout']) == 0) {
1248
		/* only update if it wasn't ajax */
1249
		if (!isAjax())
1250
			$_SESSION['last_access'] = time();
1251
	} else {
1252
		/* Check for stale session */
1253
		if ($_SESSION['last_access'] < (time() - ($config['system']['webgui']['session_timeout'] * 60))) {
1254
			$_GET['logout'] = true;
1255
			$_SESSION['Logout'] = true;
1256
		} else {
1257
			/* only update if it wasn't ajax */
1258
			if (!isAjax())
1259
				$_SESSION['last_access'] = time();
1260
		}
1261
	}
1262

    
1263
	/* user hit the logout button */
1264
	if (isset($_GET['logout'])) {
1265

    
1266
		if ($_SESSION['Logout'])
1267
			log_error("Session timed out for user '{$_SESSION['Username']}' from: {$_SERVER['REMOTE_ADDR']}");
1268
		else
1269
			log_error("User logged out for user '{$_SESSION['Username']}' from: {$_SERVER['REMOTE_ADDR']}");
1270

    
1271
		/* wipe out $_SESSION */
1272
		$_SESSION = array();
1273

    
1274
		if (isset($_COOKIE[session_name()]))
1275
			setcookie(session_name(), '', time()-42000, '/');
1276

    
1277
		/* and destroy it */
1278
		session_destroy();
1279

    
1280
		$scriptName = split("/", $_SERVER["SCRIPT_FILENAME"]);
1281
		$scriptElms = count($scriptName);
1282
		$scriptName = $scriptName[$scriptElms-1];
1283

    
1284
		if (isAjax())
1285
			return false;
1286

    
1287
		/* redirect to page the user is on, it'll prompt them to login again */
1288
		Header("Location: {$scriptName}");
1289

    
1290
		return false;
1291
	}
1292

    
1293
	/*
1294
	 * this is for debugging purpose if you do not want to use Ajax
1295
	 * to submit a HTML form. It basically diables the observation
1296
	 * of the submit event and hence does not trigger Ajax.
1297
	 */
1298
	if ($_GET['disable_ajax'])
1299
		$_SESSION['NO_AJAX'] = "True";
1300

    
1301
	/*
1302
	 * Same to re-enable Ajax.
1303
	 */
1304
	if ($_GET['enable_ajax'])
1305
		unset($_SESSION['NO_AJAX']);
1306

    
1307
	$HTTP_SERVER_VARS['AUTH_USER'] = $_SESSION['Username'];
1308
	return true;
1309
}
1310

    
1311
?>
(4-4/54)