| 
									
										
										
										
											2017-04-16 02:05:18 -06:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Make things happen when buttons are pressed and forms submitted. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-04-29 02:35:49 -06:00
										 |  |  | use LdapTools\LdapManager; | 
					
						
							|  |  |  | use LdapTools\Object\LdapObjectType; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-16 02:05:18 -06:00
										 |  |  | require_once __DIR__ . "/required.php"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-06 23:19:22 -06:00
										 |  |  | // If the user presses Sign Out but we're not logged in anymore,
 | 
					
						
							|  |  |  | // we don't want to show a nasty error.
 | 
					
						
							|  |  |  | if ($VARS['action'] == 'signout' && $_SESSION['loggedin'] != true) { | 
					
						
							|  |  |  |     session_destroy(); | 
					
						
							|  |  |  |     header('Location: index.php'); | 
					
						
							|  |  |  |     die("Logged out (session was expired anyways)."); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-16 02:05:18 -06:00
										 |  |  | dieifnotloggedin(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-29 02:35:49 -06:00
										 |  |  | require_once __DIR__ . "/lib/login.php"; | 
					
						
							| 
									
										
										
										
											2017-04-16 02:05:18 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | function returnToSender($msg, $arg = "") { | 
					
						
							|  |  |  |     global $VARS; | 
					
						
							|  |  |  |     if ($arg == "") { | 
					
						
							| 
									
										
										
										
											2017-05-06 23:19:22 -06:00
										 |  |  |         header("Location: home.php?page=" . urlencode($VARS['source']) . "&msg=$msg"); | 
					
						
							| 
									
										
										
										
											2017-04-16 02:05:18 -06:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2017-05-06 23:19:22 -06:00
										 |  |  |         header("Location: home.php?page=" . urlencode($VARS['source']) . "&msg=$msg&arg=" . urlencode($arg)); | 
					
						
							| 
									
										
										
										
											2017-04-16 02:05:18 -06:00
										 |  |  |     } | 
					
						
							|  |  |  |     die(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | switch ($VARS['action']) { | 
					
						
							|  |  |  |     case "signout": | 
					
						
							| 
									
										
										
										
											2017-04-29 02:35:49 -06:00
										 |  |  |         insertAuthLog(11, $_SESSION['uid']); | 
					
						
							| 
									
										
										
										
											2017-04-16 02:05:18 -06:00
										 |  |  |         session_destroy(); | 
					
						
							|  |  |  |         header('Location: index.php'); | 
					
						
							|  |  |  |         die("Logged out."); | 
					
						
							|  |  |  |     case "chpasswd": | 
					
						
							| 
									
										
										
										
											2017-05-13 16:17:58 -06:00
										 |  |  |         $error = []; | 
					
						
							|  |  |  |         $result = change_password($VARS['oldpass'], $VARS['newpass'], $VARS['conpass'], $error); | 
					
						
							|  |  |  |         if ($result === TRUE) { | 
					
						
							|  |  |  |             returnToSender("password_updated"); | 
					
						
							| 
									
										
										
										
											2017-05-06 23:19:22 -06:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-05-13 16:17:58 -06:00
										 |  |  |         switch (count($error)) { | 
					
						
							|  |  |  |             case 1: | 
					
						
							|  |  |  |                 returnToSender($error[0]); | 
					
						
							|  |  |  |             case 2: | 
					
						
							|  |  |  |                 returnToSender($error[0], $error[1]); | 
					
						
							|  |  |  |             default: | 
					
						
							|  |  |  |                 returnToSender("generic_op_error"); | 
					
						
							| 
									
										
										
										
											2017-04-16 02:05:18 -06:00
										 |  |  |         } | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case "add2fa": | 
					
						
							|  |  |  |         if (is_empty($VARS['secret'])) { | 
					
						
							|  |  |  |             returnToSender("invalid_parameters"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $database->update('accounts', ['authsecret' => $VARS['secret']], ['uid' => $_SESSION['uid']]); | 
					
						
							| 
									
										
										
										
											2017-04-29 02:35:49 -06:00
										 |  |  |         insertAuthLog(9, $_SESSION['uid']); | 
					
						
							| 
									
										
										
										
											2017-04-16 02:05:18 -06:00
										 |  |  |         returnToSender("2fa_enabled"); | 
					
						
							|  |  |  |     case "rm2fa": | 
					
						
							|  |  |  |         $database->update('accounts', ['authsecret' => ""], ['uid' => $_SESSION['uid']]); | 
					
						
							| 
									
										
										
										
											2017-04-29 02:35:49 -06:00
										 |  |  |         insertAuthLog(10, $_SESSION['uid']); | 
					
						
							| 
									
										
										
										
											2017-04-16 02:05:18 -06:00
										 |  |  |         returnToSender("2fa_removed"); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | } |