Handle hostnames with upper-case letters
[webmin.git] / stunnel / index.cgi
1 #!/usr/local/bin/perl
2 # index.cgi
3 # Display all existing SSL tunnels
4
5 require './stunnel-lib.pl';
6
7 # Check if stunnel is installed
8 if (!-x $config{'stunnel_path'}) {
9         &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1);
10         print &text('index_estunnel', "<tt>$config{'stunnel_path'}</tt>",
11                     "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
12         &ui_print_footer("/", $text{"index"});
13         exit;
14         }
15
16 # Check if inetd or xinetd is installed
17 if (!$has_inetd && !$has_xinetd) {
18         &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1);
19         print "$text{'index_einetd'}<p>\n";
20         &ui_print_footer("/", $text{"index"});
21         exit;
22         }
23
24 # Get the version
25 $ver = &get_stunnel_version(\$out);
26 &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, 0,
27         &help_search_link("stunnel", "man", "doc"), undef, undef,
28         &text('index_version', $ver));
29 #if ($ver >= 4) {
30 #       print "<p>",&text('index_eversion', $ver, 4.0),"<p>\n";
31 #       print &ui_hr();
32 #       &ui_print_footer("/", $text{'index'});
33 #       exit;
34 #       }
35
36 # List all tunnels currently setup in inetd
37 @tunnels = &list_stunnels();
38 @links = ( &select_all_link("d"),
39            &select_invert_link("d"),
40            "<a href='edit_stunnel.cgi?new=1'>$text{'index_add'}</a>" );
41 if (@tunnels) {
42         print &ui_form_start("delete_tunnels.cgi", "post");
43         @tds = ( "width=5" );
44         print &ui_links_row(\@links);
45         print &ui_columns_start([ "",
46                                   $text{'index_name'},
47                                   $text{'index_port'},
48                                   $text{'index_active'},
49                                   $text{'index_action'} ], 100, 0, \@tds); 
50         foreach $t (@tunnels) {
51                 local @cols;
52                 if ($ver > 4) {
53                         # Parse new-style stunnel config file
54                         if ($t->{'args'} =~ /^(\S+)\s+(\S+)/) {
55                                 $cfile = $2;
56                                 @conf = &get_stunnel_config($cfile);
57                                 ($conf) = grep { !$_->{'name'} } @conf;
58                                 }
59                         }
60                 if ($ver > 4 && !$cfile) {
61                         push(@cols, &html_escape($t->{'name'}));
62                         }
63                 else {
64                         push(@cols,
65                             "<a href='edit_stunnel.cgi?idx=$t->{'index'}'>".
66                             &html_escape($t->{'name'})."</a>");
67                         }
68                 push(@cols, &html_escape($t->{'port'}));
69                 push(@cols, $t->{'active'} ? $text{'yes'} :
70                         "<font color=#ff0000>$text{'no'}</font>");
71                 if ($ver > 4) {
72                         # Parse new-style stunnel config file
73                         if ($exec = $conf->{'values'}->{'exec'}) {
74                                 $args = $conf->{'values'}->{'execargs'};
75                                 push(@cols, &text('index_cmd',
76                                    $args ? "<tt>".&html_escape($args)."</tt>"
77                                          : "<tt>".&html_escape($exec)."</tt>"));
78                                 }
79                         elsif ($conn = $conf->{'values'}->{'connect'}) {
80                                 push(@cols, &text('index_remote',
81                                     "<tt>".&html_escape($conn)."</tt>"));
82                                 }
83                         elsif ($cfile) {
84                                 push(@cols, &text('index_conf',
85                                         "<tt>$cfile</tt>"));
86                                 }
87                         else {
88                                 push(@cols, $text{'index_noconf'});
89                                 }
90                         }
91                 else {
92                         # Parse old-style stunnel args
93                         if ($t->{'args'} =~ /\s*-([lL])\s+(\S+)\s+--\s+(.*)/ ||
94                             $t->{'args'} =~ /\s*-([lL])\s+(\S+)/) {
95                                 push(@cols, &text('index_cmd',
96                                     $3 ? "<tt>".&html_escape($3)."</tt>"
97                                        : "<tt>".&html_escape($2)."</tt>"));
98                                 }
99                         elsif ($t->{'args'} =~ /-r\s+(\S+):(\d+)/) {
100                                 push(@cols, &text('index_remote',
101                                     "<tt>".&html_escape("$1:$2")."</tt>"));
102                                 }
103                         elsif ($t->{'args'} =~ /-r\s+(\d+)/) {
104                                 push(@cols, &text('index_rport',
105                                     "<tt>".&html_escape($1)."</tt>"));
106                                 }
107                         else {
108                                 push(@cols,
109                                     "<tt>".&html_escape($t->{'args'})."</tt>");
110                                 }
111                         }
112                 print &ui_checked_columns_row(\@cols, \@tds, "d",$t->{'index'});
113                 }
114         print &ui_columns_end();
115         print &ui_links_row(\@links);
116         print &ui_form_end([ [ "delete", $text{'index_delete'} ] ]);
117         }
118 else {
119         print "<b>$text{'index_none'}</b><p>\n";
120         print &ui_links_row([ $links[2] ]);
121         }
122
123 print &ui_hr();
124 print "<table width=100%><tr>\n";
125 print "<form action=apply.cgi>\n";
126 print "<td><input type=submit value='$text{'index_apply'}'></td>\n";
127 if ($has_inetd && $has_xinetd) {
128         print "<td>$text{'index_applymsg1'}</td>\n";
129         }
130 elsif ($has_inetd) {
131         print "<td>$text{'index_applymsg2'}</td>\n";
132         }
133 else {
134         print "<td>$text{'index_applymsg3'}</td>\n";
135         }
136 print "</form></tr></table>\n";
137
138 &ui_print_footer("/", $text{'index'});
139