packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/index.php
changeset 9 f4bf6556fb9f
parent 7 faf6f7941e8f
equal deleted inserted replaced
8:f68fdcc18df9 9:f4bf6556fb9f
    40 			ldap_bind($_ldapconn, $ldap_manager['dn'], $ldap_manager['password']);
    40 			ldap_bind($_ldapconn, $ldap_manager['dn'], $ldap_manager['password']);
    41 		}
    41 		}
    42 		break;
    42 		break;
    43 	case 'profile-update':
    43 	case 'profile-update':
    44 		// header('Content-type: text/plain'); print_r(!empty($_POST['sshPublicKey']) ? $_POST['sshPublicKey'] : array()); exit;
    44 		// header('Content-type: text/plain'); print_r(!empty($_POST['sshPublicKey']) ? $_POST['sshPublicKey'] : array()); exit;
    45 		$result = ldap_mod_replace($_ldapconn, ldap_make_user_dn($_SERVER['REMOTE_USER']), array(
    45 		$ui = ldap_get_user($_SERVER['REMOTE_USER']);
    46 				'mail' => array($_POST['mail'])
    46 		
    47 				, 'sshPublicKey' => !empty($_POST['sshPublicKey']) ? array_unique($_POST['sshPublicKey']) : array()
    47 		foreach ( array('mail', 'sshPublicKey') as $field )
    48 			));
    48 		{
       
    49 			if ( empty($_POST[$field]) && empty($ui[$field]) )
       
    50 			{
       
    51 				// both empty, do nothing
       
    52 			}
       
    53 			else if ( empty($_POST[$field]) && !empty($ui[$field]) )
       
    54 			{
       
    55 				// POST empty, database not. Delete attr.
       
    56 				$result = ldap_mod_del($_ldapconn, ldap_make_user_dn($_SERVER['REMOTE_USER']), array(
       
    57 						$field => array()
       
    58 					));
       
    59 			}
       
    60 			else if ( !empty($_POST[$field]) && empty($ui[$field]) )
       
    61 			{
       
    62 				// POST filled, database empty. Add attr.
       
    63 				$result = ldap_mod_add($_ldapconn, ldap_make_user_dn($_SERVER['REMOTE_USER']), array(
       
    64 						$field => is_array($_POST[$field]) ? array_unique($_POST[$field]) : array($_POST[$field])
       
    65 					));
       
    66 			}
       
    67 			else if ( !empty($_POST[$field]) && !empty($ui[$field]) )
       
    68 			{
       
    69 				// POST and database filled. Replace attr.
       
    70 				$result = ldap_mod_replace($_ldapconn, ldap_make_user_dn($_SERVER['REMOTE_USER']), array(
       
    71 						$field => is_array($_POST[$field]) ? array_unique($_POST[$field]) : array($_POST[$field])
       
    72 					));
       
    73 			}
       
    74 		}
    49 		
    75 		
    50 		if ( $result || ldap_error($_ldapconn) === 'Success' )
    76 		if ( $result || ldap_error($_ldapconn) === 'Success' )
    51 		{
    77 		{
    52 			queue_message(E_NOTICE, "Your information has been updated.");
    78 			queue_message(E_NOTICE, "Your information has been updated.");
    53 			redirect('/');
    79 			redirect('/');