Handle hostnames with upper-case letters
[webmin.git] / pptp-client / index.cgi
1 #!/usr/local/bin/perl
2 # index.cgi
3 # Display icons for defined PPTP tunnels
4
5 require './pptp-client-lib.pl';
6
7 $vers = &get_pppd_version(\$out);
8 &ui_print_header(undef, $text{'index_title'}, undef, "intro", 1, 1, 0, undef, undef, undef,
9         $vers ? &text('index_version', $vers) : undef);
10
11 # Create the PPTP options file if non-existent. This ensures that it can be
12 # used in the peer scripts, even if it is empty
13 if (!-r $config{'pptp_options'} && $config{'pptp_options'}) {
14         &open_tempfile(OPTS, ">>$config{'pptp_options'}");
15         &close_tempfile(OPTS);
16         }
17
18 if (!&has_command($config{'pptp'})) {
19         # The PPTP command is not installed
20         print "<p>",&text('index_epptp', "<tt>$config{'pptp'}</tt>",
21                   "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
22         }
23 elsif (!$vers) {
24         # The PPP daemon is not installed
25         print "<p>",&text('index_epppd', "<tt>pppd</tt>"),"<p>\n";
26         }
27 else {
28         # Show icons
29         @tunnels = &list_tunnels();
30         %tunnels = map { $_->{'name'}, 1 } @tunnels;
31         print &ui_subheading($text{'index_header'});
32         if (@tunnels) {
33                 @links = map { "edit.cgi?tunnel=$_->{'name'}" } @tunnels;
34                 @titles = map { $_->{'name'} } @tunnels;
35                 @icons = map { "images/tunnel.gif" } @tunnels;
36                 &icons_table(\@links, \@titles, \@icons);
37                 }
38         else {
39                 print "<b>$text{'index_none'}</b><p>\n";
40                 }
41         print "<a href='edit.cgi?new=1'>$text{'index_add'}</a><p>\n";
42
43         print &ui_hr();
44         print "<table width=100%>\n";
45         print "<tr><form action=edit_opts.cgi>\n";
46         print "<td><input type=submit ",
47               "value='$text{'index_opts'}'></td>\n";
48         print "<td>$text{'index_optsdesc'}</td>\n";
49         print "</form></tr>\n";
50
51         @conns = grep { $tunnels{$_->[0]} } &list_connected();
52         %conns = map { @$_ } @conns;
53         @notconns = grep { !$conns{$_->{'name'}} } @tunnels;
54
55         if (@notconns) {
56                 # Show connect button, if any are disconnected
57                 print "<tr><form action=conn.cgi><td nowrap>\n";
58                 print "<input type=submit value='$text{'index_conn'}'>\n";
59                 print "<select name=tunnel>\n";
60                 foreach $t (@notconns) {
61                         printf "<option %s>%s\n",
62                           $config{'tunnel'} eq $t->{'name'} ? "selected" : "",
63                           $t->{'name'};
64                         }
65                 print "</select>\n";
66                 print $text{'index_pass'}," ",&ui_password("cpass", undef, 10);
67                 print "</td>\n";
68                 print "<td>$text{'index_conndesc'}</td> </form></tr>\n";
69                 }
70
71         if (@conns) {
72                 # If any tunnels appear to be active, show disconnect button
73                 print "<tr><form action=disc.cgi><td nowrap>\n";
74                 print "<input type=submit value='$text{'index_disc'}'>\n";
75                 print "<select name=tunnel>\n";
76                 foreach $t (@conns) {
77                         printf "<option %s>%s\n",
78                                 $config{'tunnel'} eq $t->[0] ? "selected" : "",
79                                 $t->[0];
80                         }
81                 print "</select></td>\n";
82                 print "<td>$text{'index_discdesc'}</td> </form></tr>\n";
83                 }
84
85         # Show at-boot button
86         if (&foreign_check("init") && @tunnels) {
87                 print "<tr>\n";
88                 &foreign_require("init", "init-lib.pl");
89                 $starting = &init::action_status($module_name);
90                 $config{'boot'} = undef if ($starting != 2);
91                 print "<form action=bootup.cgi>\n";
92                 print "<input type=hidden name=starting value='$starting'>\n";
93                 print "<td nowrap><input type=submit value='$text{'index_boot'}'>\n";
94                 print "<select name=tunnel>\n";
95                 printf "<option value='' %s>%s\n",
96                         $config{'boot'} ? "" : "selected",
97                         $text{'index_noboot'};
98                 foreach $t (@tunnels) {
99                         printf "<option value='%s' %s>%s\n",
100                           $t->{'name'},
101                           $t->{'name'} eq $config{'boot'} ?
102                                 "selected" : "",
103                           $t->{'name'};
104                         }
105                 print "</select></td>\n";
106                 print "<td>$text{'index_bootdesc'}</td>\n";
107                 print "</form></tr>\n";
108                 }
109
110         print "</table>\n";
111         }
112
113 &ui_print_footer("/", $text{'index'});
114