Handle hostnames with upper-case letters
[webmin.git] / ldap-server / index.cgi
1 #!/usr/local/bin/perl
2 # Show icons for LDAP server configuration options
3
4 require './ldap-server-lib.pl';
5
6 # Try to get OpenLDAP version
7 $ver = &get_ldap_server_version();
8 $vermsg = &text('index_version', $ver) if ($ver);
9
10 # Show title
11 &ui_print_header(undef, $module_info{'desc'}, "", "intro", 1, 1, 0,
12                  undef, undef, undef, $vermsg);
13
14 # Is it installed and usable?
15 $local = &local_ldap_server();
16 if ($local == -1) {
17         # Expected, but not installed
18         print &text('index_eslapd', "<tt>$config{'slapd'}</tt>",
19                                 "../config.cgi?$module_name"),"<p>\n";
20
21         &foreign_require("software", "software-lib.pl");
22         $lnk = &software::missing_install_link("openldap",
23                         $text{'index_openldap'},
24                         "../$module_name/", $module_info{'desc'});
25         print $lnk,"<p>\n" if ($lnk);
26
27         &ui_print_footer("/", $text{'index'});
28         return;
29         }
30 elsif ($local == -2) {
31         # Installed but config missing
32         &ui_print_endpage(&text('index_econfig',
33                                 "<tt>$config{'config_file'}</tt>",
34                                 "../config.cgi?$module_name"));
35         }
36 elsif ($local == 0) {
37         # Can we connect?
38         $ldap = &connect_ldap_db();
39         if (!ref($ldap)) {
40                 &ui_print_endpage(&text('index_econnect', $ldap,
41                                         "../config.cgi?$module_name"));
42                 }
43         }
44
45 # Check if ldap directory permissions are correct
46 $p = &check_ldap_permissions();
47 if (!$p) {
48         print "<center>\n";
49         print &ui_form_start("perms.cgi");
50         print &text('index_permsdesc', "<tt>$config{'data_dir'}</tt>",
51                                        "<tt>$config{'ldap_user'}</tt>"),"<p>\n";
52         print &ui_form_end([ [ undef, $text{'index_perms'} ] ]);
53         print "</center>\n";
54         print &ui_hr();
55         }
56
57 # Check if need to init new install, by creating the root DN
58 $ldap = &connect_ldap_db();
59 if ($p && ref($ldap) && $access{'browser'}) {
60         $conf = &get_config();
61         $base = &find_value("suffix", $conf);
62         $rv = $ldap->search(base => $base,
63                             filter => '(objectClass=*)',
64                             scope => 'base');
65         if ($rv->code) {
66                 # Not found .. offer to init
67                 print "<center>\n";
68                 print &ui_form_start("create.cgi");
69                 print &ui_hidden('mode', 1);
70                 print &ui_hidden('dn', $base);
71                 print &text('index_setupdesc', "<tt>$base</tt>"),"<p>\n";
72                 print &ui_form_end([ [ undef, $text{'index_setup'} ] ]);
73                 print "</center>\n";
74                 print &ui_hr();
75                 }
76         }
77
78 # Work out icons
79 if ($local) {
80         # All local server icons
81         @pages = ( &get_config_type() == 1 ? "slapd" : "ldif",
82                    "schema", "acl", "browser", "create" );
83         }
84 else {
85         # Just browser and DN creator
86         @pages = ( "browser", "create" );
87         }
88 @pages = grep { $access{$_} } @pages;
89 @links = map { "edit_".$_.".cgi" } @pages;
90 @titles = map { $text{$_."_title"} } @pages;
91 @icons = map { "images/$_.gif" } @pages;
92 &icons_table(\@links, \@titles, \@icons, 5);
93
94 if ($local == 1) {
95         # Show stop/restart buttons
96         print &ui_hr();
97         print &ui_buttons_start();
98         if (&is_ldap_server_running()) {
99                 if ($access{'apply'}) {
100                         print &ui_buttons_row("apply.cgi", $text{'index_apply'},
101                                               $text{'index_applydesc'});
102                         }
103                 if ($access{'start'}) {
104                         print &ui_buttons_row("stop.cgi", $text{'index_stop'},
105                                               $text{'index_stopdesc'});
106                         }
107                 }
108         else {
109                 if ($access{'start'}) {
110                         print &ui_buttons_row("start.cgi", $text{'index_start'},
111                                               $text{'index_startdesc'});
112                         }
113                 }
114
115         # Start at boot button
116         if (&foreign_check("init") && $access{'start'}) {
117                 &foreign_require("init", "init-lib.pl");
118                 $iname = $config{'init_name'} || $module_name;
119                 $st = &init::action_status($iname);
120                 print &ui_buttons_row("bootup.cgi", $text{'index_boot'},
121                                       $text{'index_bootdesc'},
122                                       undef,
123                                       &ui_yesno_radio("boot",$st == 2 ? 1 : 0));
124                 }
125         print &ui_buttons_end();
126         }
127
128 &ui_print_footer("/", $text{'index'});