Handle hostnames with upper-case letters
[webmin.git] / jabber / index.cgi
1 #!/usr/local/bin/perl
2 # index.cgi
3 # Display jabber configuration option categories
4
5 require './jabber-lib.pl';
6
7 # Check if config file exists
8 if (!-r $config{'jabber_config'}) {
9         &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, undef,
10                 &help_search_link("jabber", "man", "doc", "google"));
11         print &text('index_econfig', "<tt>$config{'jabber_config'}</tt>",
12                     "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
13         &ui_print_footer("/", $text{"index"});
14         exit;
15         }
16
17 # Check if base directory exists
18 if (!-d $config{'jabber_dir'}) {
19         &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, undef,
20                 &help_search_link("jabber", "man", "doc", "google"));
21         print &text('index_edir', "<tt>$config{'jabber_dir'}</tt>",
22                     "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
23         &ui_print_footer("/", $text{"index"});
24         exit;
25         }
26
27 # Check the version of jabberd
28 $jabberd = $config{'jabber_daemon'} ? $config{'jabber_daemon'}
29                                     : "$config{'jabber_dir'}/bin/jabberd";
30 if (!-x $jabberd) {
31         &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, undef,
32                 &help_search_link("jabber", "man", "doc", "google"));
33         print &text('index_ejabberd', "<tt>$jabberd</tt>",
34                     "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
35         &ui_print_footer("/", $text{"index"});
36         exit;
37         }
38 $ver = &get_jabberd_version(\$out);
39 if (!$ver) {
40         &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, undef,
41                 &help_search_link("jabber", "man", "doc", "google"));
42         print &text('index_eversion', "<pre>$out</pre>", "1.4",
43                     "<tt>$jabberd -v</tt>"),"<p>\n";
44         &ui_print_footer("/", $text{"index"});
45         exit;
46         }
47 elsif ($ver >= 2) {
48         &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, undef,
49                 &help_search_link("jabber", "man", "doc", "google"));
50         print &text('index_eversion2', "<pre>$out</pre>", "2.0",
51                     "<tt>$jabberd -v</tt>"),"<p>\n";
52         &ui_print_footer("/", $text{"index"});
53         exit;
54         }
55
56 &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, undef,
57         &help_search_link("jabber", "man", "doc", "google"),
58         undef, undef, &text('index_version', $ver));
59
60 # Check if the needed Perl module are installed
61 push(@needs, "XML::Parser") if (!$got_xml_parser);
62 push(@needs, "XML::Generator") if (!$got_xml_generator);
63 if (@needs) {
64         $needs = &urlize(join(" ", @needs));
65         print &text(@needs == 2 ? 'index_emodules' : 'index_emodule', @needs,
66             "/cpan/download.cgi?source=3&cpan=$needs&mode=2&return=/$module_name/&returndesc=".&urlize($text{'index_return'})),"<p>\n";
67         print "$text{'index_expat'}<p>\n";
68         print &ui_hr();
69         &ui_print_footer("/", $text{"index"});
70         exit;
71         }
72
73 # Show config category icons
74 $conf = &get_jabber_config();
75 if (!ref($conf)) {
76         print &text('index_eparse', "<tt>XML::Parser</tt>", $conf),"<p>\n";
77         print &ui_hr();
78         &ui_print_footer("/", $text{"index"});
79         exit;
80         }
81 @cats = ( "general", "messages", "modules", "karma", "ips", "filter", "admin", "file" );
82 @links = map { "edit_${_}.cgi" } @cats;
83 @titles = map { $text{"${_}_title"} } @cats;
84 @icons = map { "images/${_}.gif" } @cats;
85 &icons_table(\@links, \@titles, \@icons);
86
87 # Show warning about config file
88 open(CONFIG, $config{'jabber_config'});
89 while(<CONFIG>) {
90         if (/\s+<!--/) {
91                 $has_comment++;
92                 last;
93                 }
94         }
95 close(CONFIG);
96 print "<b>",&text('index_comments',
97           "<tt>$config{'jabber_config'}</tt>"),"</b><p>\n" if ($has_comment);
98
99 # Check if jabber is running and show the correct buttons
100 print &ui_hr();
101 print "<table width=100%>\n";
102 if (&check_pid_file(&jabber_pid_file())) {
103         # Running .. offer to restart and stop
104         print "<form action=restart.cgi><tr>\n";
105         print "<td><input type=submit value=\"$text{'index_restart'}\"></td>\n";
106         print "<td>$text{'index_restartmsg'}</td>\n";
107         print "</tr></form>\n";
108
109         print "<form action=stop.cgi><tr>\n";
110         print "<td><input type=submit value=\"$text{'index_stop'}\"></td>\n";
111         print "<td>$text{'index_stopmsg'}</td>\n";
112         print "</tr></form>\n";
113         }
114 else {
115         # Not running .. offer to start
116         print "<form action=start.cgi><tr>\n";
117         print "<td><input type=submit value=\"$text{'index_start'}\"></td>\n";
118         print "<td>$text{'index_startmsg'}</td>\n";
119         print "</tr></form>\n";
120         }
121 print "</table>\n";
122 close(PID);
123
124 &ui_print_footer("/", $text{'index'});
125