Handle hostnames with upper-case letters
[webmin.git] / ipsec / index.cgi
1 #!/usr/local/bin/perl
2 # index.cgi
3 # Display existing IPsec tunnels
4
5 require './ipsec-lib.pl';
6
7 # Make sure the ipsec command exists
8 if (!&has_command($config{'ipsec'}) ||
9     !(($ipsec_version, $ipsec_program) = &get_ipsec_version(\$out))) {
10         &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, 0,
11                 &help_search_link("freeswan", "doc", "google"));
12         print "<p>",&text('index_eipsec', "<tt>$config{'ipsec'}</tt>",
13                   "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
14         if ($out) {
15                 print &text('index_out',
16                             "<tt>$config{'ipsec'} --version</tt>"),"\n";
17                 print "<pre>$out</pre>\n";
18                 }
19         }
20 else {
21         &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, 0,
22                 &help_search_link("freeswan", "doc", "google"), undef, undef,
23                 &text('index_version2', $ipsec_version, $ipsec_program));
24
25         # Make sure the config file exists
26         if (!-r $config{'file'}) {
27                 print "<p>",&text('index_econfig', "<tt>$config{'file'}</tt>",
28                   "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
29                 }
30         else {
31                 # Check for the host secret
32                 if (!&got_secret()) {
33                         # No key setup yet .. offer to create one
34                         print "<p><b>",&text('index_nokey',
35                                   "<tt>$config{'secrets'}</tt>"),"</b><br>\n";
36                         print "<center><form action=newkey.cgi>\n";
37                         print "<input type=submit ",
38                               "value='$text{'index_newkey'}'>\n";
39                         printf "<input name=host size=20 value='%s'>\n",
40                                 &get_system_hostname();
41                         print "</form></center>\n";
42                         }
43                 else {
44                         # Show icons for connections
45                         print &ui_subheading($text{'index_header1'});
46                         @conf = &get_config();
47                         @conns = grep { $_->{'name'} eq 'conn' } @conf;
48                         if (@conns) {
49                                 foreach $c (@conns) {
50                                         push(@links, "edit.cgi?idx=".
51                                                      $c->{'index'});
52                                         if ($c->{'value'} eq '%default') {
53                                                 push(@titles, "<i>$text{'index_defconn'}</i>");
54                                                 $has_default++;
55                                                 }
56                                         else {
57                                                 push(@titles,
58                                                     &text('index_conn',
59                                                     "<tt>$c->{'value'}</tt>"));
60                                                 push(@start, $c->{'value'});
61                                                 }
62                                         push(@icons, "images/conn.gif");
63                                         }
64                                 &icons_table(\@links, \@titles, \@icons);
65                                 }
66                         else {
67                                 print "<b>$text{'index_none'}</b><p>\n";
68                                 }
69                         print "<a href='edit.cgi?new=1'>$text{'index_add'}</a>";
70                         if (!$has_default) {
71                                 print "&nbsp;" x 3;
72                                 print "<a href='edit.cgi?new=2'>$text{'index_adddef'}</a>";
73                                 }
74                         print "&nbsp;" x 3;
75                         print "<a href=import_form.cgi>$text{'index_import'}</a>";
76                         print "<p>\n";
77
78                         # Show icons for various options
79                         print &ui_hr();
80                         print &ui_subheading($text{'index_header2'});
81                         @links = ( "edit_config.cgi", "showkey.cgi",
82                                    "list_secrets.cgi" );
83                         @titles = ( $text{'config_title'},
84                                     $text{'showkey_title'},
85                                     $text{'secrets_title'} );
86                         @icons = ( "images/config.gif", "images/showkey.gif",
87                                    "images/secrets.gif" );
88                         if ($ipsec_version =~ /(\d+)/ && $1 >= 2) {
89                                 @policies = &list_policies();
90                                 foreach $p (@policies) {
91                                         push(@links, "edit_policy.cgi?policy=$p");
92                                         push(@titles, $text{'policy_desc_'.$p} ||
93                                                       &text('policy_desc', $p));
94                                         push(@icons, "images/policy.gif");
95                                         }
96                                 $got_policies = 1;
97                                 }
98                         &icons_table(\@links, \@titles, \@icons, 4);
99                         if (!@policies && $got_policies) {
100                                 print "<b>",&text('index_nopol',
101                                         "$gconfig{'webprefix'}/config.cgi?$module_name"),"</b><p>\n";
102                                 }
103
104                         print &ui_hr();
105                         print "<table width=100%>\n";
106
107                         # Start connection button
108                         if (@start && &is_ipsec_running()) {
109                                 print "<form action=up.cgi>\n";
110                                 print "<td><input type=submit ",
111                                       "value='$text{'index_up'}'>\n";
112                                 print "<select name=conn>\n";
113                                 foreach $s (@start) {
114                                         printf "<option %s>%s\n",
115                                             $config{'conn'} eq $s ? "selected"
116                                                                   : "", $s;
117                                         }
118                                 print "</select></td>\n";
119                                 print "<td>$text{'index_updesc'}</td>\n";
120                                 print "</tr></form>\n";
121                                 }
122
123                         # Start/stop/restart ipsec buttons
124                         if (&is_ipsec_running()) {
125                                 print "<form action=restart.cgi><tr>\n";
126                                 print "<td><input type=submit ",
127                                       "value='$text{'index_restart'}'></td>\n";
128                                 print "<td>$text{'index_restartdesc'}</td>\n";
129                                 print "</tr></form>\n";
130
131                                 print "<form action=stop.cgi><tr>\n";
132                                 print "<td><input type=submit ",
133                                       "value='$text{'index_stop'}'></td>\n";
134                                 print "<td>$text{'index_stopdesc'}</td>\n";
135                                 print "</tr></form>\n";
136                                 }
137                         else {
138                                 print "<form action=start.cgi><tr>\n";
139                                 print "<td><input type=submit ",
140                                       "value='$text{'index_start'}'></td>\n";
141                                 print "<td>$text{'index_startdesc'}</td>\n";
142                                 print "</tr></form>\n";
143                                 }
144
145                         # Show boot-time start button
146                         if (&foreign_check("init")) {
147                                 &foreign_require("init", "init-lib.pl");
148                                 $starting = &init::action_status("ipsec");
149                                 print "<form action=bootup.cgi>\n";
150                                 print "<input type=hidden name=starting ",
151                                       "value='$starting'>\n";
152                                 print "<td nowrap><input type=submit ",
153                                       "value='$text{'index_boot'}'>\n";
154                                 printf "<input type=radio name=boot ".
155                                        "value=1 %s> %s\n",
156                                         $starting == 2 ? "checked" : "",
157                                         $text{'yes'};
158                                 printf "<input type=radio name=boot ".
159                                        "value=0 %s> %s</td>\n",
160                                         $starting == 2 ? "" : "checked",
161                                         $text{'no'};
162                                 print "<td>$text{'index_bootdesc'}</td>\n";
163                                 print "</form></tr>\n";
164                                 }
165
166                         print "</table>\n";
167                         }
168                 }
169         }
170
171 &ui_print_footer("/", $text{'index'});
172