Handle hostnames with upper-case letters
[webmin.git] / bacula-backup / index.cgi
1 #!/usr/local/bin/perl
2 # Show the Bacula main menu
3
4 require './bacula-backup-lib.pl';
5 $hsl = &help_search_link("bacula", "man", "doc", "google");
6
7 # Make sure it is installed
8 $err = &check_bacula();
9 if ($err) {
10         &ui_print_header(undef, $module_info{'desc'}, "", "intro", 1, 1, 0,
11                          $hsl);
12         print &ui_config_link('index_echeck', [ $err, undef ]),"<p>\n";
13         &ui_print_footer("/", $text{'index'});
14         exit;
15         }
16
17 if (&has_bacula_dir()) {
18         # Test DB connection
19         eval { $dbh = &connect_to_database(); };
20         if ($@) {
21                 $err = $@;
22                 &ui_print_header(undef, $module_info{'desc'}, "", "intro",
23                                  1, 1, 0, $hsl);
24                 print &ui_config_link('index_edb', [ $err, undef ]),"<p>\n";
25                 &ui_print_footer("/", $text{'index'});
26                 exit;
27                 }
28         $dbh->disconnect();
29         }
30
31 # Test node group DB
32 if (&has_bacula_dir() && &has_node_groups()) {
33         $err = &check_node_groups();
34         if ($err) {
35                 &ui_print_header(undef, $module_info{'desc'}, "", "intro",
36                                  1, 1, 0, $hsl);
37                 print &ui_config_link('index_eng', [ $err, undef ]),"<p>\n";
38                 &ui_print_footer("/", $text{'index'});
39                 exit;
40                 }
41         }
42
43 # Get the Bacula version, and check it
44 $ver = &get_bacula_version();
45 &ui_print_header(undef, $module_info{'desc'}, "", "intro", 1, 1, 0,
46                  $hsl, undef, undef,
47                  ($ver ? &text('index_version', $ver)."<br>" : undef).
48                  &text('index_ocmin', 'images/ocmin.gif',
49                        'http://www.linmin.com/'));
50 if ($ver && $ver < 1.36) {
51         print &text('index_eversion', 1.36, $ver),"<p>\n";
52         &ui_print_footer("/", $text{'index'});
53         exit;
54         }
55
56 # Make sure bconsole works
57 if (&is_bacula_running("bacula-dir")) {
58         # Check hostname in console config
59         $conconf = &get_bconsole_config();
60         $condir = &find("Director", $conconf);
61         $conaddr = &find_value("Address", $condir->{'members'});
62         if (!&to_ipaddress($conaddr) && !&to_ip6address($conaddr)) {
63                 # Offer to fix hostname
64                 print &text('index_econsole2',
65                         "<tt>$console_cmd</tt>", "<tt>$conaddr</tt>"),"<p>\n";
66                 print &ui_form_start("fixaddr.cgi");
67                 print &ui_form_end([ [ "fix", $text{'index_fixaddr'} ] ]);
68                 &ui_print_footer("/", $text{'index'});
69                 exit;
70                 }
71
72         # Test run bconsole
73         local $status;
74         eval {
75                 local $h = &open_console();
76                 $status = &console_cmd($h, "version");
77                 &close_console($h);
78                 };
79         if ($status !~ /Version/i) {
80                 # Nope .. check if there is a password mismatch we can fix
81                 print &text('index_econsole',
82                         "<tt>$console_cmd</tt>",
83                         "<tt>$config{'bacula_dir'}/bconsole.conf</tt>"),"<p>\n";
84                 $dirconf = &get_director_config();
85                 $dirdir = &find("Director", $dirconf);
86                 $dirpass = &find_value("Password", $dirdir->{'members'});
87                 $conpass = &find_value("Password", $condir->{'members'});
88                 if ($dirpass && $conpass && $dirpass ne $conpass) {
89                         # Can fix!
90                         print &ui_form_start("fixpass.cgi");
91                         print &ui_form_end([ [ "fix",
92                                                $text{'index_fixpass'} ] ]);
93                         }
94                 &ui_print_footer("/", $text{'index'});
95                 exit;
96                 }
97         }
98
99 # Show director, storage and file daemon icons
100 if (&has_bacula_dir()) {
101         print &ui_subheading($text{'index_dir'});
102         @pages = ( "director", "clients", "filesets", "schedules",
103                    "jobs", "pools", "storages" );
104         &show_icons_from_pages(\@pages);
105         }
106 if (&has_bacula_sd()) {
107         print &ui_subheading($text{'index_sd'});
108         @pages = ( "storagec", "devices" );
109         if (!&has_bacula_dir() || $config{'showdirs'}) {
110                 push(@pages, "sdirectors");
111                 }
112         &show_icons_from_pages(\@pages);
113         }
114 if (&has_bacula_fd()) {
115         print &ui_subheading($text{'index_fd'});
116         @pages = ( "file" );
117         if (!&has_bacula_dir() || $config{'showdirs'}) {
118                 push(@pages, "fdirectors");
119                 }
120         &show_icons_from_pages(\@pages);
121         }
122
123 # Show icons for node group operations
124 if (&has_bacula_dir() && &has_node_groups()) {
125         print &ui_subheading($text{'index_groups'});
126         @pages = ( "groups", "gjobs", "gbackup", "sync" );
127         @links = map { "list_${_}.cgi" } @pages;
128         @titles = map { $text{"${_}_title"} } @pages;
129         @icons = map { "images/${_}.gif" } @pages;
130         &icons_table(\@links, \@titles, \@icons);
131         }
132
133 if (&has_bacula_dir()) {
134         # Show icons for actions
135         print &ui_hr();
136         print &ui_subheading($text{'index_actions'});
137         if (&is_bacula_running("bacula-dir")) {
138                 @actions = ( "backup", "dirstatus", "clientstatus",
139                              "storagestatus", "label", "poolstatus", "mount",
140                              "restore" );
141                 @links = map { "${_}_form.cgi" } @actions;
142                 @titles = map { $text{"${_}_title"} } @actions;
143                 @icons = map { "images/${_}.gif" } @actions;
144                 &icons_table(\@links, \@titles, \@icons);
145                 }
146         else {
147                 print "<b>$text{'index_notrun'}</b><p>\n";
148                 }
149         }
150
151 print &ui_hr();
152
153 # See what processes are running
154 print "<b>$text{'index_status'}</b>\n";
155 foreach $p (@bacula_processes) {
156         print "&nbsp;|&nbsp;\n" if ($p ne $bacula_processes[0]);
157         print $text{'proc_'.$p}," - ";
158         if (&is_bacula_running($p)) {
159                 print "<font color=#00aa00><b>",$text{'index_up'},
160                       "</b></font>\n";
161                 $pcount++;
162                 }
163         else {
164                 print "<font color=#ff0000><b>",$text{'index_down'},
165                       "</b></font>\n";
166                 }
167         }
168 print "<p>\n";
169 print &ui_buttons_start();
170 if ($pcount > 0) {
171         if (!$config{'apply'}) {
172                 print &ui_buttons_row("apply.cgi",
173                               $text{'index_apply'}, $text{'index_applydesc'});
174                 }
175         if (&has_bacula_dir()) {
176                 # Only show restart button if we are running the director, as
177                 # for others the apply does a restart
178                 print &ui_buttons_row("restart.cgi",
179                       $text{'index_restart'}, $text{'index_restartdesc'});
180                 }
181         print &ui_buttons_row("stop.cgi",
182                       $text{'index_stop'}, $text{'index_stopdesc'});
183         }
184 if ($pcount < scalar(@bacula_processes)) {
185         print &ui_buttons_row("start.cgi",
186                       $text{'index_start'}, $text{'index_startdesc'});
187         }
188
189 # See what is started at boot
190 if (&foreign_installed("init")) {
191         &foreign_require("init", "init-lib.pl");
192         $status = &init::action_status($bacula_inits[0]);
193         if ($status) {
194                 print &ui_buttons_row("bootup.cgi",
195                               $text{'index_boot'}, $text{'index_bootdesc'},
196                               undef,
197                               &ui_yesno_radio("boot", $status == 2 ? 1 : 0));
198                 }
199         }
200
201 print &ui_buttons_end();
202
203 &ui_print_footer("/", $text{'index'});
204
205 sub show_icons_from_pages
206 {
207 local ($pages) = @_;
208 local @links = map { $_ eq "director" || $_ eq "file" || $_ eq "storagec" ?
209                         "edit_${_}.cgi" : "list_${_}.cgi" } @$pages;
210 local @titles = map { $text{"${_}_title"} } @$pages;
211 local @icons = map { "images/${_}.gif" } @$pages;
212 &icons_table(\@links, \@titles, \@icons);
213 }
214