Handle hostnames with upper-case letters
[webmin.git] / heartbeat / index.cgi
1 #!/usr/local/bin/perl
2 # index.cgi
3 # Display heartbeat option categories
4
5 require './heartbeat-lib.pl';
6
7 # Try to work out the version number
8 $heartbeat_version = undef;
9 if ($config{'version'}) {
10         $heartbeat_version = $config{'version'};
11         }
12 elsif (&backquote_command("($config{'heartbeat'} -V) </dev/null 2>&1") =~
13        /(\S+)/) {
14         $heartbeat_version = $1;
15         }
16 elsif (&foreign_check("software")) {
17         &foreign_require("software", "software-lib.pl");
18         local @pinfo = &software::package_info("heartbeat");
19         if (@pinfo) {
20                 $heartbeat_version = $pinfo[4];
21                 $heartbeat_version =~ s/-.*$//;
22                 }
23         }
24 &open_tempfile(VERSION, ">$module_config_directory/version");
25 &print_tempfile(VERSION, $heartbeat_version,"\n");
26 &close_tempfile(VERSION);
27
28 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0,
29         &help_search_link("heartbeat", "man", "doc"),
30         undef, undef, $heartbeat_version ? &text('index_version',
31                                                  $heartbeat_version) : undef);
32
33 # Check if heartbeat is installed
34 if (!-d $config{'ha_dir'}) {
35         print &text('index_edir', "<tt>$config{'ha_dir'}</tt>",
36                   "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
37         &ui_print_footer("/", $text{'index'});
38         exit;
39         }
40
41 # Check if the config files exist, or if they can be copied
42 if (!-r $ha_cf && -r $config{'alt_ha_cf'}) {
43         system("cp '$config{'alt_ha_cf'}' $ha_cf");
44         }
45 if (!-r $ha_cf) {
46         print &text('index_eha_cf', "<tt>$ha_cf</tt>",
47                   "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
48         &ui_print_footer("/", $text{'index'});
49         exit;
50         }
51
52 if (!-r $haresources && -r $config{'alt_haresources'}) {
53         system("cp '$config{'alt_haresources'}' '$haresources'");
54         }
55 if (!-r $haresources) {
56         print &text('index_eharesources', "<tt>$haresources</tt>",
57                   "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
58         &ui_print_footer("/", $text{'index'});
59         exit;
60         }
61
62 if (!-r $authkeys && -r $config{'alt_authkeys'}) {
63         system("cp '$config{'alt_authkeys'}' '$authkeys'");
64         }
65 if (!-r $authkeys) {
66         print &text('index_eauthkeys', "<tt>$authkeys</tt>",
67                   "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
68         &ui_print_footer("/", $text{'index'});
69         exit;
70         }
71 if (!-r $config{'req_resource_cmd'}) {
72         print &text('index_ereq_resource_cmd', "<tt>$config{'req_resource_cmd'}</tt>",
73                   "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
74         &ui_print_footer("/", $text{'index'});
75         exit;
76         }
77
78 @opts = ( 'conf', 'res','auth' );
79 @links = map { "edit_${_}.cgi" } @opts;
80 @titles = map { $text{"${_}_title"} } @opts;
81 @icons = map { "images/${_}.gif" } @opts;
82 &icons_table(\@links, \@titles, \@icons);
83
84 print &ui_hr();
85 print "<table width=100%><tr>\n";
86
87 # Show status
88 $status = `($config{'heartbeat'} -s) </dev/null 2>&1`;
89 print "<tr> <td><b>$text{'index_status'}</b></td>\n";
90 print "<td><tt>$status</tt></td> </tr>\n";
91
92 # Show start/stop button
93 if (&check_pid_file($config{'pid_file'})) {
94         print "<form action=apply.cgi>\n";
95         print "<td><input type=submit value='$text{'index_apply'}'></td>\n";
96         print "<td>$text{'index_applymsg'}</td>\n";
97         print "</form>\n";
98         }
99 else {
100         print "<form action=start.cgi>\n";
101         print "<td><input type=submit value='$text{'index_start'}'></td>\n";
102         print "<td>$text{'index_startmsg'}</td>\n";
103         print "</form>\n";
104         }
105
106 print "</tr></table>\n";
107
108 if (!$heartbeat_version) {
109         print "<center><b>",&text('index_noversion', "../config.cgi?$module_name"),"</b></center>\n";
110         }
111
112 &ui_print_footer("/", $text{'index'});