--- /dev/null
+#!/usr/local/bin/perl
+# Show the LDAP server's data tree
+
+require './ldap-server-lib.pl';
+&ui_print_header(undef, $text{'browser_title'}, "", "browser");
+&ReadParse();
+
+# Connect to LDAP server, or die trying
+$ldap = &connect_ldap_db();
+if (!ref($ldap)) {
+ print &text('browser_econn', $ldap),"<p>\n";
+ &ui_print_footer("", $text{'index_return'});
+ exit;
+ }
+
+# Work out the base (current navigation level)
+if ($in{'goparent'}) {
+ $base = $in{'parent'};
+ }
+elsif (!$in{'base'}) {
+ $conf = &get_config();
+ $base = &find_value("suffix", $conf);
+ }
+else {
+ $base = $in{'base'};
+ }
+
+# Show current base (with option to change), and parent button
+print &ui_form_start("edit_browser.cgi"),"\n";
+print "<b>$text{'browser_base'}</b>\n";
+print &ui_textbox("base", $base, 60)," ",&ui_submit($text{'browser_ok'}),"\n";
+$parent = $base;
+$parent =~ s/^[^,]+,\s*//;
+if ($parent =~ /\S/) {
+ print &ui_hidden("parent", $parent),"\n";
+ print " \n";
+ print &ui_submit($text{'browser_parent'}, "goparent"),"\n";
+ }
+print &ui_form_end();
+
+# Show list of objects under the base, and its attributes
+$rv = $ldap->search(base => $base,
+ filter => '(objectClass=*)',
+ scope => 'one');
+if ($rv->code) {
+ # Search failed
+ print &text('browser_esearch', $rv->error),"<p>\n";
+ }
+else {
+ # Table for layout
+ print "<table width=100%><tr>\n";
+ print "<td width=50%><b>$text{'browser_subs'}</b></td>\n";
+ print "<td width=50%><b>$text{'browser_attrs'}</b></td>\n";
+ print "</tr> <tr><td width=50% valign=top>\n";
+
+ # Show sub-objects
+ @tds = ( undef, "width=10%" );
+ if ($in{'rename'}) {
+ print &ui_form_start("rename_browser.cgi", "post");
+ }
+ else {
+ print &ui_form_start("sdelete_browser.cgi", "post");
+ @tds = ( "width=5", @tds );
+ }
+ print &ui_hidden("base", $base);
+ print &ui_links_row(\@links);
+ print &ui_columns_start([ "",
+ $text{'browser_sub'},
+ $text{'browser_acts'},
+ ], 100, 0, \@tds);
+ foreach $dn (sort { lc($a->dn()) cmp lc($b->dn()) } $rv->all_entries) {
+ print "<a href='edit_browser.cgi?base=".&urlize($dn->dn())."'>".
+ &html_escape($dn->dn())."</a><br>\n";
+ }
+ print &ui_columns_end();
+ if (!$rv->all_entries) {
+ print "<i>$text{'browser_none'}</i><br>\n";
+ }
+
+ print "</td><td width=50% valign=top>\n";
+ print "<table>\n";
+
+ # Show attributes
+ $rv2 = $ldap->search(base => $base,
+ filter => '(objectClass=*)',
+ score => 'base');
+ ($bo) = $rv2->all_entries;
+ @attrs = sort { lc($a) cmp lc($b) } $bo->attributes();
+ if (@attrs) {
+ # Show all attributes
+ @tds = ( "valign=top", "valign=top", "width=5% valign=top" );
+ if ($in{'edit'}) {
+ print &ui_form_start("save_browser.cgi", "post");
+ @links = ( );
+ }
+ else {
+ print &ui_form_start("delete_browser.cgi", "post");
+ @links = ( &select_all_link("d", 1),
+ &select_invert_link("d", 1),
+ "<a href='edit_browser.cgi?base=".
+ &urlize($bo->dn())."&add=1'>".
+ "$text{'browser_add'}</a>" );
+ @tds = ( "width=5", @tds );
+ }
+ print &ui_hidden("base", $bo->dn());
+ print &ui_links_row(\@links);
+ print &ui_columns_start([ $in{'edit'} ? ( ) : ( "" ),
+ $text{'browser_name'},
+ $text{'browser_value'},
+ $text{'browser_acts'} ],
+ 100, 0, \@tds);
+ foreach $a (@attrs) {
+ @v = $bo->get_value($a);
+ @alinks = ( "<a href='edit_browser.cgi?base=".
+ &urlize($bo->dn()).
+ "&edit=$a'>$text{'browser_edit'}</a>" );
+ @cols = ( $a, join(", ", @v),
+ &ui_links_row(\@alinks),
+ );
+ if ($in{'edit'} eq $a) {
+ # Edit this one
+ @alinks = ( "<a href='edit_browser.cgi?base=".
+ &urlize($bo->dn()).
+ "'>$text{'browser_cancel'}</a>" );
+ print &ui_columns_row([
+ $a, &ui_textarea($a, join("\n", @v),
+ scalar(@v)+1, 40),
+ &ui_links_row(\@alinks),
+ ], \@tds);
+ }
+ elsif ($in{'edit'}) {
+ # Display, no delete
+ print &ui_columns_row(\@cols, \@tds);
+ }
+ else {
+ # Edit or select for delete
+ print &ui_checked_columns_row(
+ \@cols, \@tds, "d", $a);
+ }
+ }
+ print &ui_columns_end();
+ print &ui_links_row(\@links);
+ print &ui_form_end([ [ undef, $in{'edit'} ? $text{'save'} :
+ $text{'browser_delete'} ] ]);
+ }
+ else {
+ print "<tr> <td><i>$text{'browser_none'}</i></td> </tr>\n";
+ }
+ print "</table>\n";
+
+ print "</td></tr></table><br>\n";
+ }
+
+$ldap->disconnect();
+&ui_print_footer("", $text{'index_return'});
+
--- /dev/null
+#!/usr/local/bin/perl
+# Show icons for LDAP server configuration options
+
+require './ldap-server-lib.pl';
+
+# Try to get OpenLDAP version
+$ver = &get_ldap_server_version();
+$vermsg = &text('index_version', $ver) if ($ver);
+
+# Show title
+&ui_print_header(undef, $module_info{'desc'}, "", "intro", 1, 1, 0,
+ undef, undef, undef, $vermsg);
+
+# 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"));
+ }
+elsif ($local == -2) {
+ &ui_print_endpage(&text('index_econfig',
+ "<tt>$config{'config_file'}</tt>",
+ "../config.cgi?$module_name"));
+ }
+elsif ($local == 0) {
+ # Can we connect?
+ $ldap = &connect_ldap_db();
+ if (!ref($ldap)) {
+ &ui_print_endpage(&text('index_econnect', $ldap,
+ "../config.cgi?$module_name"));
+ }
+ }
+
+# Check if need to init new install
+# XXX
+
+# Work out icons
+if ($local) {
+ # All local server icons
+ @pages = ( "slapd", "schema", "acl", "browser", "create" );
+ }
+else {
+ # Just browser and DN creator?
+ @pages = ( "browse", "create" );
+ }
+@links = map { "edit_".$_.".cgi" } @pages;
+@titles = map { $text{$_."_title"} } @pages;
+@icons = map { "images/$_.gif" } @pages;
+&icons_table(\@links, \@titles, \@icons);
+
+if ($local == 1) {
+ # Show stop/restart buttons
+ print "<hr>\n";
+ print &ui_buttons_start();
+ if (&is_ldap_server_running()) {
+ print &ui_buttons_row("apply.cgi", $text{'index_apply'},
+ $text{'index_applydesc'});
+ print &ui_buttons_row("stop.cgi", $text{'index_stop'},
+ $text{'index_stopdesc'});
+ }
+ else {
+ print &ui_buttons_row("start.cgi", $text{'index_start'},
+ $text{'index_startdesc'});
+ }
+
+ # Start at boot button
+ # XXX
+ print &ui_buttons_end();
+ }
+
+&ui_print_footer("/", $text{'index'});
# Functions for configuring and talking to an LDAP server
-# XXX icon
+# XXX ldap browser should allow searching / limit list size
do '../web-lib.pl';
&init_config();
}
if ($ssl) {
# Switch to TLS mode
- local $mesg = $ldap->start_tls();
- if (!$mesg || $mesg->code) {
+ local $mesg;
+ eval { $mesg = $ldap->start_tls(); };
+ if ($@ || !$mesg || $mesg->code) {
next if (@ssls); # Try non-SSL
}
else {
return &text('connect_essl', "<tt>$server</tt>",
- $mesg ? $mesg->code : "Unknown error");
+ $@ ? %@ : $mesg ? $mesg->code : "Unknown error");
}
}
}
return $ldap;
}
+# local_ldap_server()
+# Returns 1 if OpenLDAP is installed locally and we are configuring it, 0 if
+# remote, or -1 the binary is missing, -2 if the config is missing
+sub local_ldap_server
+{
+if (!$config{'server'} || &to_ipaddress($config{'server'}) eq '127.0.0.1' ||
+ &to_ipaddress($config{'server'}) eq &to_ipaddress(&get_system_hostname())) {
+ # Local .. but is it installed?
+ return !&has_command($config{'slapd'}) ? -1 :
+ !-r $config{'config_file'} ? -2 : 1;
+ }
+return 0;
+}
+
+# get_ldap_server_version()
+# Returns the local LDAP server version number
+sub get_ldap_server_version
+{
+return undef if (&local_ldap_server() != 1);
+local $out = &backquote_command("$config{'slapd'} -V 2>&1 </dev/null");
+if ($out =~ /slapd\s+([0-9\.]+)/) {
+ return $1;
+ }
+# Fall back to -d flag
+local $out = &backquote_with_timeout("$config{'slapd'} -d 255 2>&1 </dev/null",
+ 1, 1, 1);
+if ($out =~ /slapd\s+([0-9\.]+)/) {
+ return $1;
+ }
+return undef;
+}
+
# get_config([file])
# Returns an array ref of LDAP server configuration settings
sub get_config
'line' => $lnum,
'file' => $file };
local $value = $2;
- $dir->{'values'} = &split_quoted_string($value);
+ $dir->{'values'} = [ &split_quoted_string($value) ];
push(@rv, $dir);
}
$lnum++;
{
}
+# is_ldap_server_running()
+# Returns the process ID of the running LDAP server, or undef
sub is_ldap_server_running
{
-}
-
-sub get_ldap_server_pid
-{
+local $conf = &get_config();
+local $pidfile = &find_value("pidfile", $conf);
+if ($pidfile) {
+ return &check_pid_file($pidfile);
+ }
+return undef;
}
1;