Button to init ldap server
authorJamie Cameron <jcameron@webmin.com>
Sat, 15 Dec 2007 02:15:01 +0000 (02:15 +0000)
committerJamie Cameron <jcameron@webmin.com>
Sat, 15 Dec 2007 02:15:01 +0000 (02:15 +0000)
ldap-server/create.cgi
ldap-server/edit_slapd.cgi
ldap-server/index.cgi
ldap-server/lang/en
ldap-server/ldap-server-lib.pl
ldap-server/save_slapd.cgi

index 4998b0b..f8475ba 100644 (file)
@@ -19,12 +19,32 @@ else {
        $dn = $in{'dn'};
        }
 
+# Work out class for the DN
+$schema = $ldap->schema();
+@allocs = map { $_->{'name'} }
+          grep { $_->{'structural'} }
+               $schema->all_objectclasses();
+@ocs = ( );
+foreach my $poc ("top", "domain") {
+       if (&indexof($poc, @allocs) >= 0) {
+               push(@ocs, $poc);
+               }
+       }
+@ocs || &error(&text('create_eoc'));
+
 # Do it, while showing the user
 &ui_print_unbuffered_header(undef, $text{'create_title'}, "");
 
 # Create the DN
 print &text('create_doingdn', "<tt>".&html_escape($dn)."</tt>"),"<br>\n";
-$rv = $ldap->add($dn, attr => [ "objectClass", "top" ]);
+@attrs = ( "objectClass", \@ocs );
+if (&indexof("domain", @ocs) >= 0) {
+       # Domain class needs dc
+       if ($dn =~ /^([^=]+)=([^, ]+)/) {
+               push(@attrs, $1, $2);
+               }
+       }
+$rv = $ldap->add($dn, attr => \@attrs);
 if (!$rv || $rv->code) {
        print &text('create_edoingdn', &ldap_error($rv)),"<p>\n";
        }
index 8e8f740..bea7054 100644 (file)
@@ -46,6 +46,7 @@ print &ui_table_row($text{'slapd_rootpw'},
                    $rootmode == 1 ? &text('slapd_root1', $rootcrypt) :
                    $rootmode == 2 ? &text('slapd_root2', $rootsha1) :
                    $rootmode == 3 ? &text('slapd_root3', $rootenc) :
+                   $rootplain eq '' ? $text{'slapd_noroot'} :
                                     $rootplain);
 
 # Set to new
@@ -56,10 +57,10 @@ print &ui_table_row($text{'slapd_rootchange'},
 # Cache sizes
 $cachesize = &find_value('cachesize', $conf);
 print &ui_table_row($text{'slapd_cachesize'},
-                   &ui_textbox("cachesize", $cachesize, 10));
+           &ui_opt_textbox("cachesize", $cachesize, 10, $text{'default'}));
 $dbcachesize = &find_value('dbcachesize', $conf);
 print &ui_table_row($text{'slapd_dbcachesize'},
-                   &ui_textbox("dbcachesize", $dbcachesize, 10));
+           &ui_opt_textbox("dbcachesize", $dbcachesize, 10, $text{'default'}));
 
 # Access control options
 $allowdir = &find("allow", $conf);
index 7426d6b..ad1ce77 100644 (file)
@@ -14,10 +14,21 @@ $vermsg = &text('index_version', $ver) if ($ver);
 # Is it installed and usable?
 $local = &local_ldap_server();
 if ($local == -1) {
-       &ui_print_endpage(&text('index_eslapd', "<tt>$config{'slapd'}</tt>",
-                               "../config.cgi?$module_name"));
+       # Expected, but not installed
+       print &text('index_eslapd', "<tt>$config{'slapd'}</tt>",
+                               "../config.cgi?$module_name"),"<p>\n";
+
+       &foreign_require("software", "software-lib.pl");
+       $lnk = &software::missing_install_link("openldap",
+                       $text{'index_openldap'},
+                       "../$module_name/", $module_info{'desc'});
+       print $lnk,"<p>\n" if ($lnk);
+
+       &ui_print_footer("/", $text{'index'});
+       return;
        }
 elsif ($local == -2) {
+       # Installed but config missing
        &ui_print_endpage(&text('index_econfig',
                                "<tt>$config{'config_file'}</tt>",
                                "../config.cgi?$module_name"));
@@ -31,8 +42,26 @@ elsif ($local == 0) {
                }
        }
 
-# Check if need to init new install
-# XXX
+# Check if need to init new install, by creating the root DN
+$ldap = &connect_ldap_db();
+if (ref($ldap) && $access{'browser'}) {
+       $conf = &get_config();
+       $base = &find_value("suffix", $conf);
+       $rv = $ldap->search(base => $base,
+                           filter => '(objectClass=*)',
+                           scope => 'base');
+       if ($rv->code) {
+               # Not found .. offer to init
+               print "<center>\n";
+               print &ui_form_start("create.cgi");
+               print &ui_hidden('mode', 1);
+               print &ui_hidden('dn', $base);
+               print &text('index_setupdesc', "<tt>$base</tt>"),"<p>\n";
+               print &ui_form_end([ [ undef, $text{'index_setup'} ] ]);
+               print "</center>\n";
+               print "<hr>\n";
+               }
+       }
 
 # Work out icons
 if ($local) {
index e82974f..c6a9f8d 100644 (file)
@@ -1,4 +1,5 @@
 index_version=OpenLDAP $1
+index_openldap=OpenLDAP
 index_eslapd=The OpenLDAP server program $1 was not found on your system. Perhaps the path on the <a href='$2'>module configuration</a> page is incorrect?
 index_econfig=The OpenLDAP server configuration file $1 was not found on your system. Perhaps the path on the <a href='$2'>module configuration</a> page is incorrect?
 index_econnect=An error occurred connection to the LDAP server : $1. You may need to adjust settings on the <a href='$2'>module configuration</a> page.
@@ -11,6 +12,8 @@ index_startdesc=Click this button to start up the OpenLDAP server with the curre
 index_return=module index
 index_boot=Start at boot?
 index_bootdesc=Change this selection to determine if the OpenLDAP server is started at boot time or not.
+index_setupdesc=Your LDAP server's database does not contain the root DN $1 yet, which means that no data can be added until you create it. However, Webmin can do this for you by clicking the button below.
+index_setup=Create Root DN
 
 connect_eserver=The LDAP server $1 does not exist
 connect_euser=No user to login as has been configured
@@ -23,6 +26,7 @@ connect_emod=The Perl module $1 needed to connect to the LDAP server is not inst
 connect_eldap=Failed to connect to LDAP server $1 on port $2
 connect_essl=Failed to start TLS encryption with LDAP server $1 : $2
 connect_elogin=Failed to login to LDAP server $1 as $2 : $3
+connect_cpan=You can have the <tt>$1</tt> Perl module <a href='$2'>automatically installed</a> from CPAN.
 
 slapd_title=OpenLDAP Server Configuration
 slapd_header=Global LDAP server options
@@ -32,6 +36,7 @@ slapd_rootpw=Administration password
 slapd_root1=Unix encrypted <tt>$1</tt>
 slapd_root2=SHA1 encrypted <tt>$1</tt>
 slapd_root3=Encrypted <tt>$1</tt>
+slapd_noroot=<i>No password set</i>
 slapd_rootchange=New administration password
 slapd_leave=Don't change
 slapd_set=Set to
@@ -180,6 +185,7 @@ create_edoingdn=.. failed : $1
 create_done=.. done
 create_doingex=Creating example object with DN $1 ..
 create_edoingex=.. failed : $1. However, the tree can still be used.
+create_eoc=Could not find a suitable object class for the new DN
 
 eunknown=Unknown error
 
index 7777c3d..e33c5e3 100644 (file)
@@ -1,7 +1,7 @@
 # Functions for configuring and talking to an LDAP server
 # XXX help pages
-# XXX init ldap server
 # XXX acl section
+# XXX /var/lib/ldap/* files are owned by root on redhat
 
 do '../web-lib.pl';
 &init_config();
@@ -22,8 +22,17 @@ return $connect_ldap_db_cache if (defined($connect_ldap_db_cache));
 
 # Do we have the module?
 if ($net_ldap_error) {
-       return &text('connect_emod', "<tt>Net::LDAP</tt>",
+       local $msg = &text('connect_emod', "<tt>Net::LDAP</tt>",
                     "<pre>".&html_escape($net_ldap_error)."</pre>");
+       if (foreign_available("cpan")) {
+               $msg .= "<p>\n";
+               $msg .= &text('connect_cpan', "Net::LDAP",
+                     "../cpan/download.cgi?source=3&cpan=Net::LDAP&".
+                     "cpan=Convert::ASN1&".
+                     "return=../$module_name/&returndesc=".
+                     &urlize($module_info{'desc'}));
+               }
+       return $msg;
        }
 
 # Work out server name, login and TLS mode
@@ -49,7 +58,7 @@ else {
        $user = $config{'user'} || &find_value("rootdn", $conf);
        $user || return $text{'connect_euser2'};
        $pass = $config{'pass'} || &find_value("rootpw", $conf);
-       $pass || return $text{'connect_epass2'};
+       #$pass || return $text{'connect_epass2'};
        $pass =~ /^\{/ && return $text{'connect_epass3'};
        }
 $ssl = $config{'ssl'};
@@ -78,7 +87,9 @@ foreach $ssl (@ssls) {
 $ldap || return "This can't happen!";
 
 # Login to server
-local $mesg = $ldap->bind(dn => $user, password => $pass);
+local $mesg = $pass eq '' ? 
+               $ldap->bind(dn => $user, anonymous => 1) :
+               $ldap->bind(dn => $user, password => $pass);
 if (!$mesg || $mesg->code) {
        return &text('connect_elogin', "<tt>$server</tt>", "<tt>$user</tt>",
                     &ldap_error($mesg));
@@ -112,7 +123,8 @@ return 0;
 sub get_ldap_server_version
 {
 return undef if (&local_ldap_server() != 1);
-local $out = &backquote_command("$config{'slapd'} -V 2>&1 </dev/null");
+local $out = &backquote_with_timeout(
+               "$config{'slapd'} -V -d 1 2>&1 </dev/null", 1, 1, 1);
 if ($out =~ /slapd\s+([0-9\.]+)/) {
        return $1;
        }
index c5834ae..6dfb39f 100644 (file)
@@ -30,10 +30,20 @@ if (!$in{'rootchange_def'}) {
        }
 
 # Cache sizes
-$in{'cachesize'} =~ /^\d+$/ || &error($text{'slapd_ecachesize'});
-&save_directive($conf, 'cachesize', $in{'cachesize'});
-$in{'dbcachesize'} =~ /^\d+$/ || &error($text{'slapd_edbcachesize'});
-&save_directive($conf, 'dbcachesize', $in{'dbcachesize'});
+if (!$in{'cachesize_def'}) {
+       $in{'cachesize'} =~ /^\d+$/ || &error($text{'slapd_ecachesize'});
+       &save_directive($conf, 'cachesize', $in{'cachesize'});
+       }
+else {
+       &save_directive($conf, 'cachesize', undef);
+       }
+if (!$in{'dbcachesize_def'}) {
+       $in{'dbcachesize'} =~ /^\d+$/ || &error($text{'slapd_edbcachesize'});
+       &save_directive($conf, 'dbcachesize', $in{'dbcachesize'});
+       }
+else {
+       &save_directive($conf, 'dbcachesize', undef);
+       }
 
 # Access control options
 @allow = split(/\0/, $in{'allow'});