]> source.dussan.org Git - nextcloud-server.git/commitdiff
LDAP Wizard: fix couple more or less nasty bugs aka polishing
authorArthur Schiwon <blizzz@owncloud.com>
Thu, 10 Oct 2013 17:37:12 +0000 (19:37 +0200)
committerArthur Schiwon <blizzz@owncloud.com>
Thu, 17 Oct 2013 17:13:28 +0000 (19:13 +0200)
apps/user_ldap/js/settings.js
apps/user_ldap/lib/configuration.php
apps/user_ldap/lib/wizard.php
apps/user_ldap/settings.php

index 6b1f363bbaf6d54abfe9b7325f6f484f8165e06e..df5de87460142e58c4f2905f431b9fc371d510d1 100644 (file)
@@ -155,14 +155,16 @@ var LdapWizard = {
                                $('#'+id).val(result.changes[id]);
                        }
                }
+               LdapWizard.functionalityCheck();
        },
 
        checkBaseDN: function() {
                host = $('#ldap_host').val();
+               port = $('#ldap_port').val();
                user = $('#ldap_dn').val();
                pass = $('#ldap_agent_password').val();
 
-               if(host && user && pass) {
+               if(host && port && user && pass) {
                        param = 'action=guessBaseDN'+
                                        '&ldap_serverconfig_chooser='+$('#ldap_serverconfig_chooser').val();
 
@@ -195,6 +197,7 @@ var LdapWizard = {
                                function(result) {
                                        LdapWizard.applyChanges(result);
                                        if($('#ldap_port').val()) {
+                                               LdapWizard.checkBaseDN();
                                                $('#ldap_port').removeClass('invisible');
                                                LdapWizard.hideInfoBox();
                                        }
@@ -346,6 +349,29 @@ var LdapWizard = {
                );
        },
 
+       functionalityCheck: function() {
+               //criterias to enable the connection:
+               // - host, port, user filter, login filter
+               host        = $('#ldap_host').val();
+               port        = $('#ldap_port').val();
+               userfilter  = $('#ldap_dn').val();
+               loginfilter = $('#ldap_agent_password').val();
+
+               //FIXME: activates a manually deactivated configuration.
+               if(host && port && userfilter && loginfilter) {
+                       if($('#ldap_configuration_active').is(':checked')) {
+                               return;
+                       }
+                       $('#ldap_configuration_active').prop('checked', true);
+                       LdapWizard.save($('#ldap_configuration_active')[0]);
+               } else {
+                       if($('#ldap_configuration_active').is(':checked')) {
+                               $('#ldap_configuration_active').prop('checked', false);
+                               LdapWizard.save($('#ldap_configuration_active')[0]);
+                       }
+               }
+       },
+
        hideInfoBox: function() {
                if(LdapWizard.checkInfoShown) {
                        $('#ldapWizard1 .ldapWizardInfo').addClass('invisible');
@@ -362,11 +388,13 @@ var LdapWizard = {
        initGroupFilter: function() {
                LdapWizard.findObjectClasses('ldap_groupfilter_objectclass', 'Group');
                LdapWizard.findAvailableGroups('ldap_groupfilter_groups', 'Groups');
+               LdapWizard.composeFilter('group');
                LdapWizard.countGroups();
        },
 
        initLoginFilter: function() {
                LdapWizard.findAttributes();
+               LdapWizard.composeFilter('login');
        },
 
        initMultiSelect: function(object, id, caption) {
@@ -384,6 +412,7 @@ var LdapWizard = {
        initUserFilter: function() {
                LdapWizard.findObjectClasses('ldap_userfilter_objectclass', 'User');
                LdapWizard.findAvailableGroups('ldap_userfilter_groups', 'Users');
+               LdapWizard.composeFilter('user');
                LdapWizard.countUsers();
        },
 
@@ -403,7 +432,10 @@ var LdapWizard = {
                   || triggerObj.id == 'ldap_dn'
                   || triggerObj.id == 'ldap_agent_password') {
                        LdapWizard.checkPort();
-                       LdapWizard.checkBaseDN();
+                       if($('#ldap_port').val()) {
+                               //if Port is already set, check BaseDN
+                               LdapWizard.checkBaseDN();
+                       }
                }
 
                if(triggerObj.id == 'ldap_userlist_filter') {
@@ -442,6 +474,9 @@ var LdapWizard = {
                if(originalObj == 'ldap_userfilter_objectclass'
                   || originalObj == 'ldap_userfilter_groups') {
                        LdapWizard.composeFilter('user');
+                       //when user filter is changed afterwards, login filter needs to
+                       //be adjusted, too
+                       LdapWizard.composeFilter('login');
                } else if(originalObj == 'ldap_loginfilter_attributes') {
                        LdapWizard.composeFilter('login');
                } else if(originalObj == 'ldap_groupfilter_objectclass'
index e1e5d2b65d6757574b9029e933e3f626fd62c740..2fb566aec6fe4067b8cb35380b6374432a472807 100644 (file)
@@ -287,7 +287,7 @@ class Configuration {
        public function getDefaults() {
                return array(
                        'ldap_host'                                                     => '',
-                       'ldap_port'                                                     => '389',
+                       'ldap_port'                                                     => '',
                        'ldap_backup_host'                                      => '',
                        'ldap_backup_port'                                      => '',
                        'ldap_override_main_server'                     => '',
@@ -296,14 +296,14 @@ class Configuration {
                        'ldap_base'                                                     => '',
                        'ldap_base_users'                                       => '',
                        'ldap_base_groups'                                      => '',
-                       'ldap_userlist_filter'                          => 'objectClass=person',
+                       'ldap_userlist_filter'                          => '',
                        'ldap_userfilter_objectclass'           => '',
                        'ldap_userfilter_groups'                        => '',
                        'ldap_login_filter'                                     => 'uid=%uid',
                        'ldap_loginfilter_email'                        => 0,
                        'ldap_loginfilter_username'                     => 1,
                        'ldap_loginfilter_attributes'           => '',
-                       'ldap_group_filter'                                     => 'objectClass=posixGroup',
+                       'ldap_group_filter'                                     => '',
                        'ldap_groupfilter_objectclass'          => '',
                        'ldap_groupfilter_groups'                       => '',
                        'ldap_display_name'                                     => 'displayName',
@@ -319,7 +319,7 @@ class Configuration {
                        'ldap_override_uuid_attribute'          => 0,
                        'home_folder_naming_rule'                       => '',
                        'ldap_turn_off_cert_check'                      => 0,
-                       'ldap_configuration_active'                     => 1,
+                       'ldap_configuration_active'                     => 0,
                        'ldap_attributes_for_user_search'       => '',
                        'ldap_attributes_for_group_search'      => '',
                        'ldap_expert_username_attr'                     => '',
index 2538fe4a2c5cc1a97188373293ce5d95b3c5a4e3..a1d635faaea1745a32ebc9a55e360ad0e37106b5 100644 (file)
@@ -38,6 +38,8 @@ class Wizard extends LDAPUtility {
        const LFILTER_USER_LIST  = 3;
        const LFILTER_GROUP_LIST = 4;
 
+       const LDAP_NW_TIMEOUT = 4;
+
        /**
         * @brief Constructor
         * @param $configuration an instance of Configuration
@@ -222,6 +224,7 @@ class Wizard extends LDAPUtility {
 
                if($testMemberOf) {
                        $this->configuration->hasMemberOfFilterSupport = $this->testMemberOf();
+                       $this->result->markChange();
                        if(!$this->configuration->hasMemberOfFilterSupport) {
                                throw new \Exception('memberOf is not supported by the server');
                        }
@@ -375,7 +378,6 @@ class Wizard extends LDAPUtility {
                }
                $this->checkHost();
                $portSettings = $this->getPortSettingsToTry();
-               file_put_contents('/tmp/ps', print_r($portSettings, true).PHP_EOL, FILE_APPEND);
 
                if(!is_array($portSettings)) {
                        throw new \Exception(print_r($portSettings, true));
@@ -763,10 +765,10 @@ class Wizard extends LDAPUtility {
 
                \OCP\Util::writeLog('user_ldap', 'Wiz: Setting LDAP Options ', \OCP\Util::DEBUG);
                //set LDAP options
-               if($this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3)) {
-                       if($tls) {
-                               $this->ldap->startTls($cr);
-                       }
+               $a = $this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3);
+               $c = $this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT);
+               if($tls) {
+                       $this->ldap->startTls($cr);
                }
 
                \OCP\Util::writeLog('user_ldap', 'Wiz: Attemping to Bind ', \OCP\Util::DEBUG);
@@ -915,7 +917,7 @@ class Wizard extends LDAPUtility {
                        //pre-select objectclass with most result entries
                        $maxEntryObjC = str_replace($p, '', $maxEntryObjC);
                        $this->applyFind($dbkey, $maxEntryObjC);
-//                     $this->result->addChange($dbkey, $maxEntryObjC);
+                       $this->result->addChange($dbkey, $maxEntryObjC);
                }
 
                return $availableFeatures;
@@ -962,10 +964,10 @@ class Wizard extends LDAPUtility {
                        $this->configuration->ldapHost.':'.$this->configuration->ldapPort,
                        $this->configuration->ldapPort);
 
-               if($this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3)) {
-                       if($this->configuration->ldapTLS === 1) {
-                               $this->ldap->startTls($cr);
-                       }
+               $this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3);
+               $this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT);
+               if($this->configuration->ldapTLS === 1) {
+                       $this->ldap->startTls($cr);
                }
 
                $lo = @$this->ldap->bind($cr,
index 5d3306246df97e1f9964491859c269db49b695f0..d077eafdde9c0d09507afedf82578b50b74ee759 100644 (file)
@@ -64,6 +64,7 @@ for($i = 0; $i < count($wizTabs); $i++) {
 
 $tmpl->assign('tabs', $wizardHtml);
 $tmpl->assign('toc', $toc);
+$tmpl->assign('settingControls', $sControls);
 
 // assign default values
 $config = new \OCA\user_ldap\lib\Configuration('', false);