| 
									
										
										
										
											2019-01-16 11:37:35 +01:00
										 |  |  | <?php | 
					
						
							|  |  |  | 	error_reporting(E_ALL ^ E_NOTICE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	include_once('../include/lucidAuth.functions.php'); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2019-01-28 11:48:05 +01:00
										 |  |  | 	if ($_POST['do'] === 'login') { | 
					
						
							| 
									
										
										
										
											2019-01-16 11:37:35 +01:00
										 |  |  | 		$result = authenticateLDAP($_POST['username'], $_POST['password']); | 
					
						
							| 
									
										
										
										
											2019-01-28 11:48:05 +01:00
										 |  |  | 		if ($result['status'] === 'Success') { | 
					
						
							| 
									
										
										
										
											2019-02-19 15:31:02 +01:00
										 |  |  | 			// Store authentication token; in database serverside & in cookie clientside
 | 
					
						
							|  |  |  | 			if (storeToken($result['token'], $settings->LDAP['Domain'] . '\\' . $_POST['username'], $_SERVER['HTTP_HOST'])['status'] !== 'Success') { | 
					
						
							|  |  |  | 				// Since this action is only ever called through an AJAX-request; return JSON object
 | 
					
						
							|  |  |  | 				echo '{"Result":"Fail","Reason":"Failed storing authentication token in database and/or cookie"}' . PHP_EOL; | 
					
						
							|  |  |  | 				exit; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-01-24 17:17:53 +01:00
										 |  |  |              | 
					
						
							| 
									
										
										
										
											2019-01-23 22:08:30 +01:00
										 |  |  | 			// Convert base64 encoded string back from JSON;
 | 
					
						
							|  |  |  | 			//   forcing it into an associative array (instead of javascript's default StdClass object)
 | 
					
						
							|  |  |  | 			try { | 
					
						
							|  |  |  | 				$proxyHeaders = json_decode(base64_decode($_POST['ref']), JSON_OBJECT_AS_ARRAY); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			catch (Exception $e) { | 
					
						
							| 
									
										
										
										
											2019-02-19 15:31:02 +01:00
										 |  |  | 				// Since this action is only ever called through an AJAX-request; return JSON object
 | 
					
						
							| 
									
										
										
										
											2019-01-23 22:08:30 +01:00
										 |  |  | 				echo '{"Result":"Fail","Reason":"Original request URI lost in transition"}' . PHP_EOL; | 
					
						
							|  |  |  | 				exit; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-01-24 17:17:53 +01:00
										 |  |  | 			$originalUri = !empty($proxyHeaders) ? $proxyHeaders['XForwardedProto'] . '://' . $proxyHeaders['XForwardedHost'] . $proxyHeaders['XForwardedUri'] : 'lucidAuth.manage.php'; | 
					
						
							| 
									
										
										
										
											2019-01-23 22:08:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-19 15:31:02 +01:00
										 |  |  | 			// Since this action is only ever called through an AJAX-request; return JSON object
 | 
					
						
							| 
									
										
										
										
											2019-01-23 22:08:30 +01:00
										 |  |  | 			echo '{"Result":"Success","Location":"' . $originalUri . '"}' . PHP_EOL; | 
					
						
							| 
									
										
										
										
											2019-01-16 11:37:35 +01:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			switch ($result['reason']) { | 
					
						
							|  |  |  | 				case '1': | 
					
						
							|  |  |  | 					echo '{"Result":"Fail","Reason":"Invalid username and/or password"}' . PHP_EOL; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				default: | 
					
						
							|  |  |  | 					echo '{"Result":"Fail","Reason":"Uncaught error"}' . PHP_EOL; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		$stylevar['content']['top'] = '-125px'; | 
					
						
							|  |  |  | 		$stylevar['content']['margin-left'] = '-225px'; | 
					
						
							|  |  |  | 		$stylevar['content']['height'] = '220px'; | 
					
						
							|  |  |  | 		$stylevar['content']['width'] = '450px'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		include_once('../include/lucidAuth.template.php'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$pageLayout = str_replace('<!--REPL_MAIN-->', $contentLayout['login'], $pageLayout); | 
					
						
							|  |  |  | 		echo $pageLayout; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ?>
 |