| 
									
										
										
										
											2019-02-28 14:31:10 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 	error_reporting(E_ALL ^ E_NOTICE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	include_once('../include/lucidAuth.functions.php'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ($_POST['do'] == 'login') { | 
					
						
							|  |  |  | 		$result = authenticateLDAP($_POST['username'], $_POST['password']); | 
					
						
							|  |  |  | 		if ($result['status'] === 'Success') { | 
					
						
							|  |  |  | 			// Store authentication token; in database serverside & in cookie clientside
 | 
					
						
							|  |  |  | 			if (storeToken($result['token'], $settings->LDAP['Domain'] . '\\' . $_POST['username'], $_SERVER['HTTP_HOST'])['status'] !== 'Success') { | 
					
						
							|  |  |  | 				// Return JSON object
 | 
					
						
							|  |  |  | 				header('Content-Type: application/json'); | 
					
						
							|  |  |  | 				echo json_encode([ | 
					
						
							|  |  |  | 					"Result"			=>	"Failure", | 
					
						
							|  |  |  | 					"Reason"			=>	"Failed storing authentication token in database and/or cookie" | 
					
						
							|  |  |  | 				]); | 
					
						
							|  |  |  | 				exit; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-06-19 10:09:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-28 14:31:10 +00: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) { | 
					
						
							|  |  |  | 				// Return JSON object
 | 
					
						
							|  |  |  | 				header('Content-Type: application/json'); | 
					
						
							|  |  |  | 				echo json_encode([ | 
					
						
							|  |  |  | 					"Result"			=>	"Failure", | 
					
						
							|  |  |  | 					"Reason"			=>	"Original request-URI lost in transition" | 
					
						
							|  |  |  | 				]); | 
					
						
							|  |  |  | 				exit; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			$originalUri = !empty($proxyHeaders) ? $proxyHeaders['XForwardedProto'] . '://' . $proxyHeaders['XForwardedHost'] . $proxyHeaders['XForwardedUri'] : 'lucidAuth.manage.php'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// Return JSON object
 | 
					
						
							|  |  |  | 			header('Content-Type: application/json'); | 
					
						
							|  |  |  | 			echo json_encode([ | 
					
						
							|  |  |  | 				"Result"			=>	"Success", | 
					
						
							|  |  |  | 				"Location"			=>	$originalUri, | 
					
						
							| 
									
										
										
										
											2019-06-19 10:09:46 +00:00
										 |  |  | 				"CrossDomainLogin"	=>	$settings->Session['CrossDomainLogin'], | 
					
						
							|  |  |  |                 "CookieDomains"     =>  json_encode(array_diff($settings->Session['CookieDomains'], [$_SERVER['HTTP_HOST']])), | 
					
						
							|  |  |  |                 "SecureToken"       =>  $result['token'] | 
					
						
							| 
									
										
										
										
											2019-02-28 14:31:10 +00:00
										 |  |  | 			]); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			switch ($result['reason']) { | 
					
						
							|  |  |  | 				case '1': | 
					
						
							|  |  |  | 					header('Content-Type: application/json'); | 
					
						
							|  |  |  | 					echo json_encode([ | 
					
						
							|  |  |  | 						"Result"	=>	"Failure", | 
					
						
							|  |  |  | 						"Reason"	=>	"Invalid username and/or password" | 
					
						
							|  |  |  | 					]); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				default: | 
					
						
							|  |  |  | 					header('Content-Type: application/json'); | 
					
						
							|  |  |  | 					echo json_encode([ | 
					
						
							|  |  |  | 						"Result"	=>	"Failure", | 
					
						
							|  |  |  | 						"Reason"	=>	"Uncaught error" | 
					
						
							|  |  |  | 					]); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		include_once('../include/lucidAuth.template.php'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 10:09:46 +00:00
										 |  |  | 		echo sprintf($pageLayout['full'], | 
					
						
							|  |  |  | 			sprintf($contentLayout['login'], | 
					
						
							| 
									
										
										
										
											2019-02-28 14:31:10 +00:00
										 |  |  | 				$_GET['ref'] | 
					
						
							|  |  |  | 			) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-16 11:37:35 +01:00
										 |  |  | ?>
 |