Project

General

Profile

Download (38.2 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
				if($referrer_host == "127.0.0.1" || $referrer_host == "localhost") {
134
					// allow SSH port forwarded connections and links from localhost
135
					$found_host = true;
136
				}
137
			}
138
		}
139
		if($found_host == false) {
140
			if(!security_checks_disabled()) {
141
				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.");
142
				exit;
143
			}
144
			$security_passed = false;
145
		}
146
	} else
147
		$security_passed = false;
148
}
149

    
150
if (function_exists("display_error_form") && $security_passed)
151
	/* Security checks passed, so it should be OK to turn them back on */
152
	restore_security_checks();
153
unset($security_passed);
154

    
155
$groupindex = index_groups();
156
$userindex = index_users();
157

    
158
function index_groups() {
159
	global $g, $debug, $config, $groupindex;
160

    
161
	$groupindex = array();
162

    
163
	if (is_array($config['system']['group'])) {
164
		$i = 0;
165
		foreach($config['system']['group'] as $groupent) {
166
			$groupindex[$groupent['name']] = $i;
167
			$i++;
168
		}
169
	}
170

    
171
	return ($groupindex);
172
}
173

    
174
function index_users() {
175
	global $g, $debug, $config;
176

    
177
	if (is_array($config['system']['user'])) {
178
		$i = 0;
179
		foreach($config['system']['user'] as $userent) {
180
			$userindex[$userent['name']] = $i;
181
			$i++;
182
		}
183
	}
184

    
185
	return ($userindex);
186
}
187

    
188
function & getUserEntry($name) {
189
	global $debug, $config, $userindex;
190
	if (isset($userindex[$name]))
191
		return $config['system']['user'][$userindex[$name]];
192
}
193

    
194
function & getUserEntryByUID($uid) {
195
	global $debug, $config;
196
	foreach ($config['system']['user'] as & $user)
197
		if ($user['uid'] == $uid)
198
			return $user;
199

    
200
	return false;
201
}
202

    
203
function & getGroupEntry($name) {
204
	global $debug, $config, $groupindex;
205
	if (isset($groupindex[$name]))
206
		return $config['system']['group'][$groupindex[$name]];
207
}
208

    
209
function & getGroupEntryByGID($gid) {
210
	global $debug, $config;
211
	foreach ($config['system']['group'] as & $group)
212
		if ($group['gid'] == $gid)
213
			return $group;
214

    
215
	return false;
216
}
217

    
218
function get_user_privileges(& $user) {
219

    
220
        $privs = $user['priv'];
221
        if (!is_array($privs))
222
                $privs = array();
223

    
224
        $names = local_user_get_groups($user, true);
225

    
226
        foreach ($names as $name) {
227
                $group = getGroupEntry($name);
228
                if (is_array($group['priv']))
229
                        $privs = array_merge( $privs, $group['priv']);
230
        }
231

    
232
        return $privs;
233
}
234

    
235
function userHasPrivilege($userent, $privid = false) {
236

    
237
        if (!$privid || !is_array($userent))
238
                return false;
239

    
240
        $privs = get_user_privileges($userent);
241

    
242
        if (!is_array($privs))
243
                return false;
244

    
245
        if (!in_array($privid, $privs))
246
                return false;
247

    
248
        return true;
249
}
250

    
251
function local_backed($username, $passwd) {
252

    
253
	$user = getUserEntry($username);
254
	if (!$user)
255
		return false;
256

    
257
	if (is_account_disabled($username) || is_account_expired($username))
258
		return false;
259

    
260
	if ($user['password'])
261
	{
262
		$passwd = crypt($passwd, $user['password']);
263
		if ($passwd == $user['password'])
264
			return true;
265
	}
266

    
267
	if ($user['md5-hash'])
268
	{
269
		$passwd = md5($passwd);
270
		if ($passwd == $user['md5-hash'])
271
			return true;
272
	}
273

    
274
	return false;
275
}
276

    
277
function local_sync_accounts() {
278
	global $debug, $config;
279
	conf_mount_rw();
280

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

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

    
320
	/* make sure the all group exists */
321
	$allgrp = getGroupEntryByGID(1998);
322
	local_group_set($allgrp, true);
323

    
324
	/* sync all local users */
325
	if (is_array($config['system']['user']))
326
		foreach ($config['system']['user'] as $user)
327
			local_user_set($user);
328

    
329
	/* sync all local groups */
330
	if (is_array($config['system']['group']))
331
		foreach ($config['system']['group'] as $group)
332
			local_group_set($group);
333

    
334
	conf_mount_ro();
335

    
336
}
337

    
338
function local_user_set(& $user) {
339
	global $g, $debug;
340

    
341
	conf_mount_rw();
342

    
343
	$home_base = "/home/";	
344
	$user_uid = $user['uid'];
345
	$user_name = $user['name'];
346
	$user_home = "{$home_base}{$user_name}";
347
	$user_shell = "/etc/rc.initial";
348
	$user_group = "nobody";
349

    
350
	// Ensure $home_base exists and is writable
351
	if (!is_dir($home_base)) 
352
		mkdir($home_base, 0755);
353

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

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

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

    
387
	/* read from pw db */
388
	$fd = popen("/usr/sbin/pw usershow {$user_name} 2>&1", "r");
389
	$pwread = fgets($fd);
390
	pclose($fd);
391

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

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

    
404
	if($debug)
405
		log_error("Running: {$cmd}");
406
	$fd = popen($cmd, "w");
407
	fwrite($fd, $user['password']);
408
	pclose($fd);
409

    
410
	/* create user directory if required */
411
	if (!is_dir($user_home)) {
412
		mkdir($user_home, 0700);
413
		mwexec("/bin/cp /root/.* {$home_base}/", true);
414
	}
415
	chown($user_home, $user_name);
416
	chgrp($user_home, $user_group);
417

    
418
	/* write out ssh authorized key file */
419
	if($user['authorizedkeys']) {
420
		if (!is_dir("{$user_home}/.ssh")) {
421
			mkdir("{$user_home}/.ssh", 0700);
422
			chown("{$user_home}/.ssh", $user_name);
423
		}
424
		$keys = base64_decode($user['authorizedkeys']);
425
		file_put_contents("{$user_home}/.ssh/authorized_keys", $keys);
426
		chown("{$user_home}/.ssh/authorized_keys", $user_name);
427
	} else
428
		unlink_if_exists("{$user_home}/.ssh/authorized_keys");
429

    
430
	$un = $lock_account ? "" : "un";
431
	exec("/usr/sbin/pw {$un}lock {$user_name} -q");
432
	
433
	conf_mount_ro();
434
}
435

    
436
function local_user_del($user) {
437
	global $debug;
438

    
439
	/* remove all memberships */
440
	local_user_set_groups($user);
441

    
442
	/* Don't remove /root */
443
	if ($user['uid'] != 0)
444
		$rmhome = "-r";
445

    
446
	/* delete from pw db */
447
	$cmd = "/usr/sbin/pw userdel {$user['name']} {$rmhome}";
448

    
449
	if($debug)
450
		log_error("Running: {$cmd}");
451
	mwexec($cmd);
452

    
453
	/* Delete user from groups needs a call to write_config() */
454
	local_group_del_user($user);
455
}
456

    
457
function local_user_set_password(& $user, $password) {
458

    
459
	$user['password'] = crypt($password);
460
	$user['md5-hash'] = md5($password);
461

    
462
	// Converts ascii to unicode.
463
	$astr = (string) $password;
464
	$ustr = '';
465
	for ($i = 0; $i < strlen($astr); $i++) {
466
		$a = ord($astr{$i}) << 8;
467
		$ustr.= sprintf("%X", $a);
468
	}
469

    
470
	// Generate the NT-HASH from the unicode string
471
	$user['nt-hash'] = bin2hex(mhash(MHASH_MD4, $ustr));
472
}
473

    
474
function local_user_get_groups($user, $all = false) {
475
	global $debug, $config;
476

    
477
	$groups = array();
478
	if (!is_array($config['system']['group']))
479
		return $groups;
480

    
481
	foreach ($config['system']['group'] as $group)
482
		if ( $all || ( !$all && ($group['name'] != "all")))
483
			if (is_array($group['member']))
484
				if (in_array($user['uid'], $group['member']))
485
					$groups[] = $group['name'];
486

    
487
	if ( $all )
488
		$groups[] = "all";
489

    
490
	sort($groups);
491

    
492
	return $groups;
493
	
494
}
495

    
496
function local_user_set_groups($user, $new_groups = NULL ) {
497
	global $debug, $config, $groupindex;
498

    
499
	if (!is_array($config['system']['group']))
500
		return;
501

    
502
	$cur_groups = local_user_get_groups($user, true);
503
	$mod_groups = array();
504

    
505
	if (!is_array($new_groups))
506
		$new_groups = array();
507

    
508
	if (!is_array($cur_groups))
509
		$cur_groups = array();
510

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

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

    
536
	/* sync all modified groups */
537
	foreach ($mod_groups as $group)
538
		local_group_set($group);
539
}
540

    
541
function local_group_del_user($user) {
542
	global $config;
543

    
544
	if (!is_array($config['system']['group']))
545
                return;
546

    
547
        foreach ($config['system']['group'] as $group) {
548
		if (is_array($group['member'])) {
549
			foreach ($group['member'] as $idx => $uid) {
550
				if ($user['uid'] == $uid)
551
					unset($config['system']['group']['member'][$idx]);
552
			}
553
		}
554
	}
555
}
556

    
557
function local_group_set($group, $reset = false) {
558
	global $debug;
559

    
560
	$group_name = $group['name'];
561
	$group_gid = $group['gid'];
562
	$group_members = "''";
563
	if (!$reset && !empty($group['member']) && count($group['member']) > 0)
564
		$group_members = implode(",",$group['member']);
565

    
566
	/* read from group db */
567
	$fd = popen("/usr/sbin/pw groupshow {$group_name} 2>&1", "r");
568
	$pwread = fgets($fd);
569
	pclose($fd);
570

    
571
	/* determine add or mod */
572
	if (!strncmp($pwread, "pw:", 3))
573
		$group_op = "groupadd";
574
	else
575
		$group_op = "groupmod";
576

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

    
580
	if($debug)
581
		log_error("Running: {$cmd}");
582
	mwexec($cmd);
583

    
584
}
585

    
586
function local_group_del($group) {
587
	global $debug;
588

    
589
	/* delete from group db */
590
	$cmd = "/usr/sbin/pw groupdel {$group['name']}";
591

    
592
	if($debug)
593
		log_error("Running: {$cmd}");
594
	mwexec($cmd);
595
}
596

    
597
function ldap_test_connection($authcfg) {
598
	global $debug, $config, $g;
599

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

    
613
        /* first check if there is even an LDAP server populated */
614
        if(!$ldapserver)
615
                return false;
616

    
617
        /* connect and see if server is up */
618
        putenv('LDAPTLS_REQCERT=never');
619
        $error = false;
620
        if (empty($ldapport)) {
621
                if (!($ldap = ldap_connect($ldapserver)))
622
                        $error = true;
623
        } else if (!($ldap = ldap_connect($ldapserver, $ldapport)))
624
                $error = true;
625

    
626
        if ($error == true) {
627
                log_error("ERROR!  Could not connect to server {$ldapname}.");
628
                return false;
629
        }
630

    
631
	return true;
632
}
633

    
634
function ldap_test_bind($authcfg) {
635
	global $debug, $config, $g;
636

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

    
655
	/* first check if there is even an LDAP server populated */
656
        if(!$ldapserver)
657
                return false;
658

    
659
        /* connect and see if server is up */
660
        putenv('LDAPTLS_REQCERT=never');
661
        $error = false;
662
        if (empty($ldapport)) {
663
                if (!($ldap = ldap_connect($ldapserver)))
664
                        $error = true;
665
        } else if (!($ldap = ldap_connect($ldapserver, $ldapport)))
666
                $error = true;
667

    
668
        if ($error == true) {
669
                log_error("ERROR!  Could not connect to server {$ldapname}.");
670
                return false;
671
        }
672

    
673
	ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
674
	ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, (int)$ldapver);
675
 
676
	if ($ldapanon == true) {
677
		if (!($res = @ldap_bind($ldap))) {
678
			@ldap_close($ldap);
679
			return false;
680
		}
681
	} else if (!($res = @ldap_bind($ldap, $ldapbindun, $ldapbindpw))) {
682
		@ldap_close($ldap);
683
		return false;
684
	}
685

    
686
	@ldap_unbind($ldap);
687

    
688
	return true;
689
}
690

    
691
function ldap_get_user_ous($show_complete_ou=true, $authcfg) {
692
	global $debug, $config, $g;
693

    
694
	if(!function_exists("ldap_connect"))
695
		return;
696

    
697
	$ous = array();
698

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

    
720
        /* first check if there is even an LDAP server populated */
721
        if(!$ldapserver) {
722
                log_error("ERROR!  ldap_get_user_ous() backed selected with no LDAP authentication server defined.");
723
                return $ous;
724
        }
725

    
726
	/* connect and see if server is up */
727
        putenv('LDAPTLS_REQCERT=never');
728
        $error = false;
729
        if (empty($ldapport)) {
730
                if (!($ldap = ldap_connect($ldapserver)))
731
                        $error = true;
732
        } else if (!($ldap = ldap_connect($ldapserver, $ldapport)))
733
                $error = true;
734

    
735
        if ($error == true) {
736
		log_error("ERROR!  Could not connect to server {$ldapname}.");
737
                return $ous;
738
        }
739

    
740
	$ldapfilter = "(|(ou=*)(cn=Users))";
741

    
742
	ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
743
	ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, (int)$ldapver);
744

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

    
757
	if ($ldapscope == "one")
758
		$ldapfunc = "ldap_list";
759
	else
760
		$ldapfunc = "ldap_search";
761

    
762
	$search = @$ldapfunc($ldap, $ldapbasedn, $ldapfilter);
763
	$info = @ldap_get_entries($ldap, $search);
764

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

    
780
	@ldap_unbind($ldap);
781

    
782
	return $ous;
783
}
784

    
785
function ldap_get_groups($username, $authcfg) {
786
	global $debug, $config;
787
	
788
	if(!function_exists("ldap_connect"))
789
		return;
790
	
791
	if(!$username) 
792
		return false;
793

    
794
	if(stristr($username, "@")) {
795
		$username_split=split("\@", $username);
796
		$username = $username_split[0];		
797
	}
798

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

    
831
	$ldapdn             = $_SESSION['ldapdn'];
832

    
833
	/*Convert attribute to lowercase.  php ldap arrays put everything in lowercase */
834
	$ldapgroupattribute = strtolower($ldapgroupattribute);
835
	$memberof = array();
836

    
837
	/* connect and see if server is up */
838
	putenv('LDAPTLS_REQCERT=never');
839
	$error = false;
840
        if (empty($ldapport)) {
841
                if (!($ldap = ldap_connect($ldapserver)))
842
                        $error = true;
843
        } else if (!($ldap = ldap_connect($ldapserver, $ldapport)))
844
                $error = true;
845

    
846
	if ($error == true) {
847
		log_error("ERROR! ldap_get_groups() Could not connect to server {$ldapname}.");
848
                return memberof;
849
        }
850
    
851
	ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
852
	ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, (int)$ldapver);
853

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

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

    
876
	$search    = @$ldapfunc($ldap, $ldapdn, $ldapfilter, array($ldapgroupattribute));
877
	$info      = @ldap_get_entries($ldap, $search);
878

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

    
901
function ldap_backed($username, $passwd, $authcfg) {
902
	global $debug, $config;
903
	
904
	if(!$username) 
905
		return;
906

    
907
	if(!function_exists("ldap_connect"))
908
		return;
909

    
910
	if(stristr($username, "@")) {
911
		$username_split=split("\@", $username);
912
		$username = $username_split[0];        
913
	}
914
	if(stristr($username, "\\")) {
915
		$username_split=split("\\", $username);
916
		$username = $username_split[0];        
917
	}
918

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

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

    
951
		return false;
952
	}
953
	
954
	ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
955
	ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, (int)$ldapver);
956

    
957
	/* Make sure we can connect to LDAP */
958
	putenv('LDAPTLS_REQCERT=never');
959
	$error = false;
960
	if (empty($ldapport)) {
961
		if (!($ldap = ldap_connect($ldapserver)))
962
			$error = true;
963
	} else if (!($ldap = ldap_connect($ldapserver, $ldapport)))
964
		$error = true;
965

    
966
	if ($error == true) {
967
		log_error("ERROR!  Could not connect to server {$ldapname}.");
968
		return false;
969
	}
970

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

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

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

    
1027
	if ($usercount != 1){
1028
		@ldap_unbind($ldap);
1029
		log_error("ERROR! Either LDAP search failed, or multiple users were found.");
1030
		return false;                         
1031
	}
1032

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

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

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

    
1045
	return true;
1046
}
1047

    
1048
function radius_backed($username, $passwd, $authcfg){
1049
	global $debug, $config;
1050
	$ret = false;
1051

    
1052
	require_once("radius.inc");
1053

    
1054
	$rauth = new Auth_RADIUS_PAP($username, $passwd);
1055
	if ($authcfg) {
1056
		$radiusservers = array();
1057
		$radiusservers[0]['ipaddr'] = $authcfg['host'];
1058
		$radiusservers[0]['port'] = $authcfg['radius_auth_port'];
1059
		$radiusservers[0]['sharedsecret'] = $authcfg['radius_secret'];
1060
	} else
1061
		return false;
1062

    
1063
	/* Add a new servers to our instance */
1064
	foreach ($radiusservers as $radsrv)
1065
		$rauth->addServer($radsrv['ipaddr'], $radsrv['port'], $radsrv['sharedsecret']);
1066

    
1067
	if (PEAR::isError($rauth->start())) {
1068
		$retvalue['auth_val'] = 1;
1069
		$retvalue['error'] = $rauth->getError();
1070
		if ($debug)
1071
			printf("Radius start: %s<br>\n", $retvalue['error']);
1072
	}
1073

    
1074
	// XXX - billm - somewhere in here we need to handle securid challenge/response
1075

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

    
1094
	// close OO RADIUS_AUTHENTICATION
1095
	$rauth->close();
1096

    
1097
	return $ret;
1098
}
1099

    
1100
function get_user_expiration_date($username) {
1101
	$user = getUserEntry($username);
1102
	if ($user['expires']) 
1103
		return $user['expires'];
1104
}
1105

    
1106
function is_account_expired($username) {
1107
	$expirydate = get_user_expiration_date($username);
1108
	if ($expirydate) {
1109
		if (strtotime("-1 day") > strtotime(date("m/d/Y",strtotime($expirydate))))
1110
			return true;
1111
	}
1112

    
1113
	return false;
1114
}
1115

    
1116
function is_account_disabled($username) {
1117
	$user = getUserEntry($username);
1118
	if (isset($user['disabled']))
1119
		return true;
1120

    
1121
	return false;
1122
}
1123

    
1124
function auth_get_authserver($name) {
1125
        global $config;
1126

    
1127
        if (is_array($config['system']['authserver'])) {
1128
                foreach ($config['system']['authserver'] as $authcfg) {
1129
                        if ($authcfg['name'] == $name)
1130
                                return $authcfg;
1131
                }
1132
        }
1133
	if ($name == "Local Database")
1134
		return array("name" => "Local Database", "type" => "Local Auth", "host" => $config['system']['hostname']);
1135
}
1136

    
1137
function auth_get_authserver_list() {
1138
        global $config;
1139

    
1140
	$list = array();
1141

    
1142
        if (is_array($config['system']['authserver'])) {
1143
                foreach ($config['system']['authserver'] as $authcfg) {
1144
			/* Add support for disabled entries? */
1145
			$list[$authcfg['name']] = $authcfg;
1146
                }
1147
        }
1148

    
1149
	$list["Local Database"] = array( "name" => "Local Database", "type" => "Local Auth", "host" => $config['system']['hostname']);
1150
	return $list;
1151
}
1152

    
1153
function getUserGroups($username, $authcfg) {
1154
	global $config;
1155

    
1156
	$allowed_groups = array();
1157

    
1158
	switch($authcfg['type']) {
1159
        case 'ldap':
1160
		$allowed_groups = @ldap_get_groups($username, $authcfg);
1161
		break;
1162
	case 'radius':
1163
		break;
1164
	default:
1165
		$user = getUserEntry($username);
1166
		$allowed_groups = @local_user_get_groups($user, true);
1167
		break;
1168
	}
1169

    
1170
	$member_groups = array();
1171
        if (is_array($config['system']['group'])) {
1172
                foreach ($config['system']['group'] as $group)
1173
                        if (in_array($group['name'], $allowed_groups))
1174
				$member_groups[] = $group['name'];
1175
	}
1176

    
1177
	return $member_groups;
1178
}
1179

    
1180
function authenticate_user($username, $password, $authcfg = NULL) {
1181

    
1182
	if (!$authcfg) {
1183
		return local_backed($username, $password);
1184
	}
1185

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

    
1203
	return $authenticated;
1204
}
1205

    
1206
function session_auth() {
1207
	global $HTTP_SERVER_VARS, $config, $_SESSION, $page;
1208

    
1209
	session_start();
1210

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

    
1240
	/* Show login page if they aren't logged in */
1241
	if (empty($_SESSION['Logged_In']))
1242
		return false;
1243

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

    
1268
	/* user hit the logout button */
1269
	if (isset($_GET['logout'])) {
1270

    
1271
		if ($_SESSION['Logout'])
1272
			log_error("Session timed out for user '{$_SESSION['Username']}' from: {$_SERVER['REMOTE_ADDR']}");
1273
		else
1274
			log_error("User logged out for user '{$_SESSION['Username']}' from: {$_SERVER['REMOTE_ADDR']}");
1275

    
1276
		/* wipe out $_SESSION */
1277
		$_SESSION = array();
1278

    
1279
		if (isset($_COOKIE[session_name()]))
1280
			setcookie(session_name(), '', time()-42000, '/');
1281

    
1282
		/* and destroy it */
1283
		session_destroy();
1284

    
1285
		$scriptName = split("/", $_SERVER["SCRIPT_FILENAME"]);
1286
		$scriptElms = count($scriptName);
1287
		$scriptName = $scriptName[$scriptElms-1];
1288

    
1289
		if (isAjax())
1290
			return false;
1291

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

    
1295
		return false;
1296
	}
1297

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

    
1306
	/*
1307
	 * Same to re-enable Ajax.
1308
	 */
1309
	if ($_GET['enable_ajax'])
1310
		unset($_SESSION['NO_AJAX']);
1311

    
1312
	$HTTP_SERVER_VARS['AUTH_USER'] = $_SESSION['Username'];
1313
	return true;
1314
}
1315

    
1316
?>
(4-4/61)