Handle hostnames with upper-case letters
[webmin.git] / xinetd / index.cgi
1 #!/usr/local/bin/perl
2 # index.cgi
3 # Display all xinetd services
4
5 require './xinetd-lib.pl';
6 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0,
7         &help_search_link("xinetd", "man", "doc", "google"));
8
9 # Check for config file
10 if (!-r $config{'xinetd_conf'}) {
11         print "<p>",&text('index_econf', "<tt>$config{'xinetd_conf'}</tt>",
12                           "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
13         &ui_print_footer("/", $text{'index'});
14         exit;
15         }
16
17 @conf = &get_xinetd_config();
18 ($defs) = grep { $_->{'name'} eq 'defaults' } @conf;
19 foreach $m (@{$defs->{'members'}}) {
20         $ddisable{$m->{'value'}}++ if ($m->{'name'} eq 'disabled');
21         }
22
23 # Show table header
24 print "<form action=mass_enable.cgi method=post>\n";
25 @links = ( &select_all_link("serv"),
26            &select_invert_link("serv"),
27            "<a href='edit_serv.cgi?new=1'>$text{'index_add_inet'}</a>" );
28 print &ui_links_row(\@links);
29 @tds = ( "width=5" );
30 print &ui_columns_start([ "",
31                           $text{'index_name'},
32                           $text{'index_type'},
33                           $text{'index_port'},
34                           $text{'index_proto'},
35                           $text{'index_user'},
36                           $text{'index_server'},
37                           $text{'index_enabled'} ], 100, 0, \@tds);
38
39 # Show one row for each service
40 foreach $x (@conf) {
41         next if ($x->{'name'} ne 'service');
42         local $q = $x->{'quick'};
43         local @s;
44         if ($q->{'type'}->[0] eq 'UNLISTED') {
45                 # Port and protocol specified
46                 @s = ( $x->{'name'}, undef, $q->{'port'}->[0],
47                        $q->{'protocol'}->[0] );
48                 }
49         elsif ($q->{'protocol'}) {
50                 # Protocol specified, find port from service
51                 if ($config{'lookup_servs'}) {
52                         @s = getservbyname($x->{'value'}, $q->{'protocol'}->[0]);
53                         }
54                 if (!@s) {
55                         @s = ( $x->{'name'}, undef, $q->{'port'}->[0],
56                                $q->{'protocol'}->[0] );
57                         }
58                 }
59         else {
60                 # Only service specified, check protocols based on socket type,
61                 # or failing that all protocols
62                 if ($config{'lookup_servs'}) {
63                         local @protos;
64                         if ($q->{'socket_type'}->[0] eq 'stream') {
65                                 @protos = ( 'tcp' );
66                                 }
67                         elsif ($q->{'socket_type'}->[0] eq 'dgram') {
68                                 @protos = ( 'udp' );
69                                 }
70                         else {
71                                 @protos = &list_protocols();
72                                 }
73                         foreach $p (@protos) {
74                                 @s = getservbyname($x->{'value'}, $p);
75                                 last if (@s);
76                                 }
77                         }
78                 }
79         local @cols;
80         push(@cols, "<a href='edit_serv.cgi?idx=$x->{'index'}'>".
81                     &html_escape($x->{'value'})."</a>");
82         push(@cols, &indexof('RPC', @{$q->{'type'}}) < 0 ?
83                      $text{'index_inet'} : $text{'index_rpc'});
84         if (@s) {
85                 push(@cols, &html_escape($s[2]) ||
86                              "<i>$text{'index_noport'}</i>");
87                 push(@cols, &html_escape(uc($s[3])));
88                 }
89         else {
90                 push(@cols, "<i>$text{'index_noport'}</i>", "");
91                 }
92         push(@cols, $q->{'user'} ? &html_escape($q->{'user'}->[0]) : "");
93         push(@cols, &indexof('INTERNAL', @{$q->{'type'}}) >= 0 ?
94                      $text{'index_internal'} : $q->{'redirect'} ?
95                      &text('index_redirect', "<tt>".&html_escape($q->{'redirect'}->[0])."</tt>") :
96                      &html_escape($q->{'server'}->[0]));
97         $id = $q->{'id'}->[0] || $x->{'value'};
98         push(@cols, $q->{'disable'}->[0] eq 'yes' || $ddisable{$id} ?
99               "<font color=#ff0000>$text{'no'}</font>" : $text{'yes'});
100         print &ui_checked_columns_row(\@cols, \@tds, "serv", $x->{'index'});
101         }
102 print &ui_columns_end();
103 print &ui_links_row(\@links);
104
105 print "<input type=submit name=enable value='$text{'index_enable'}'>\n";
106 print "<input type=submit name=disable value='$text{'index_disable'}'>\n";
107 print "</form>\n";
108
109 print &ui_hr();
110
111 print &ui_buttons_start();
112 print &ui_buttons_row("edit_defaults.cgi", $text{'index_defaults'},
113                       $text{'index_defaultsmsg'});
114
115 if ($pid = &is_xinetd_running()) {
116         print &ui_buttons_row("restart.cgi", $text{'index_apply'},
117                               $text{'index_applymsg'});
118         }
119 else {
120         print &ui_buttons_row("start.cgi", $text{'index_start'},
121                               $text{'index_startmsg'});
122         }
123 print &ui_buttons_end();
124
125 &ui_print_footer("/", $text{'index'});
126