Handle hostnames with upper-case letters
[webmin.git] / pptp-client / edit.cgi
1 #!/usr/local/bin/perl
2 # edit.cgi
3 # Display a form for editing tunnel details
4
5 require './pptp-client-lib.pl';
6 &ReadParse();
7 if ($in{'new'}) {
8         &ui_print_header(undef, $text{'edit_title1'}, "");
9         }
10 else {
11         &ui_print_header(undef, $text{'edit_title2'}, "");
12         ($tunnel) = grep { $_->{'name'} eq $in{'tunnel'} } &list_tunnels();
13         &parse_comments($tunnel);
14         $login = &find("name", $tunnel->{'opts'});
15         $sn = $login ? $login->{'value'} : &get_system_hostname(1);
16         @secs = &list_secrets();
17         ($sec) = grep { $_->{'client'} eq $sn } @secs;
18         }
19
20 print "<form action=save.cgi method=post>\n";
21 print "<input type=hidden name=new value='$in{'new'}'>\n";
22 print "<input type=hidden name=old value='$in{'tunnel'}'>\n";
23 print "<table border width=100%>\n";
24 print "<tr $tb> <td><b>$text{'edit_header'}</b></td> </tr>\n";
25 print "<tr $cb> <td><table width=100%>\n";
26
27 print "<tr> <td><b>$text{'edit_name'}</b></td>\n";
28 printf "<td><input name=tunnel size=30 value='%s'></td>\n",
29         $tunnel->{'name'};
30
31 print "<td><b>$text{'edit_server'}</b></td>\n";
32 printf "<td><input name=server size=20 value='%s'></td> </tr>\n",
33         $tunnel->{'server'};
34
35 print "<tr> <td><b>$text{'edit_login'}</b></td>\n";
36 printf "<td nowrap><input type=radio name=login_def value=1 %s> %s\n",
37         $login ? "" : "checked", $text{'edit_same'};
38 printf "<input type=radio name=login_def value=0 %s>\n",
39         $login ? "checked" : "";
40 printf "<input name=login size=15 value='%s'></td>\n",
41         $login->{'value'};
42
43 print "<td><b>$text{'edit_pass'}</b></td>\n";
44 printf "<td><input name=pass type=password value='%s'></td> </tr>\n",
45         $sec->{'secret'};
46
47 $remote = &find("remotename", $tunnel->{'opts'});
48 print "<tr> <td><b>$text{'edit_remote'}</b></td>\n";
49 printf "<td nowrap><input type=radio name=remote_def value=1 %s> %s\n",
50         $remote ? "" : "checked", $text{'edit_auto'};
51 printf "<input type=radio name=remote_def value=0 %s>\n",
52         $remote ? "checked" : "";
53 printf "<input name=remote size=15 value='%s'></td>\n",
54         $remote->{'value'};
55
56 print "</tr>\n";
57
58 # Show PPP include file
59 $file = &find("file", $tunnel->{'opts'});
60 $fmode = $in{'new'} ? 1 : !$file ? 0 :
61          $file->{'value'} eq $config{'pptp_options'} ? 1 : 2;
62 print "<tr> <td><b>$text{'edit_file'}</b></td> <td colspan=3>\n";
63 printf "<input type=radio name=file_def value=0 %s> %s\n",
64         $fmode == 0 ? "checked" : "", $text{'edit_none'};
65 printf "<input type=radio name=file_def value=1 %s> %s\n",
66         $fmode == 1 ? "checked" : "", $text{'edit_global'};
67 printf "<input type=radio name=file_def value=2 %s> %s\n",
68         $fmode == 2 ? "checked" : "", $text{'edit_ofile'};
69 printf "<input name=file size=30 value='%s'> %s</td> </tr>\n",
70         $fmode == 2 ? $file->{'value'} : "", &file_chooser_button("file");
71
72 print "<tr> <td colspan=4><hr></td> </tr>\n";
73
74 # Parse all route comments
75 foreach $r (@{$tunnel->{'routes'}}) {
76         if ($r =~ /^\s*add\s+-net\s+(\S+)\s+netmask\s+(\S+)\s+gw\s+(\S+)\s*$/) {
77                 # Net route to specific gateway
78                 push(@kroutes, [ 1, $1, $2, $3 ]);
79                 }
80         elsif ($r =~ /^\s*add\s+-net\s+(\S+)\s+gw\s+(\S+)\s+netmask\s+(\S+)\s*$/) {
81                 # Net route to specific gateway
82                 push(@kroutes, [ 1, $1, $3, $2 ]);
83                 }
84         elsif ($r =~ /^\s*add\s+-net\s+(\S+)\s+netmask\s+(\S+)\s+dev\s+(TUNNEL_DEV)\s*$/) {
85                 # Net route to other end
86                 push(@kroutes, [ 1, $1, $2, 'GW' ]);
87                 }
88         elsif ($r =~ /^\s*add\s+-net\s+(\S+)\s+dev\s+(TUNNEL_DEV)\s+netmask\s+(\S+)\s*$/) {
89                 # Net route to other end
90                 push(@kroutes, [ 1, $1, $3, 'GW' ]);
91                 }
92
93         elsif ($r =~ /^\s*add\s+-host\s+(\S+)\s+gw\s+(\S+)\s*$/) {
94                 # Host route to specific gateway
95                 push(@kroutes, [ 2, $1, undef, $2 ]);
96                 }
97         elsif ($r =~ /^\s*add\s+-host\s+(\S+)\s+dev\s+(TUNNEL_DEV)\s*$/) {
98                 # Host route to specific gateway
99                 push(@kroutes, [ 2, $1, undef, 'GW' ]);
100                 }
101
102         elsif ($r =~ /^\s*add\s+default\s+gw\s+(\S+)\s*$/) {
103                 # Default route to specific gateway
104                 $adddef = $1;
105                 }
106         elsif ($r =~ /^\s*add\s+default\s+dev\s+(TUNNEL_DEV)\s*$/) {
107                 # Default route to other end
108                 $adddef = 'GW';
109                 }
110
111         elsif ($r =~ /^\s*delete\s+default\s*$/) {
112                 # Deleting old default route
113                 $deldef = 1;
114                 }
115         else {
116                 push(@uroutes, $r);
117                 }
118         }
119
120 # Show default route options
121 print "<tr> <td><b>$text{'edit_adddef'}</b></td> <td colspan=3>\n";
122 printf "<input type=radio name=adddef value=1 %s> %s\n",
123         $adddef eq "GW" ? "checked" : "", $text{'edit_def1'};
124 printf "<input type=radio name=adddef value=2 %s> %s\n",
125         $adddef && $adddef ne "GW" ? "checked" : "", $text{'edit_def2'};
126 printf "<input name=def size=15 value='%s'>\n",
127         $adddef eq "GW" ? "" : $adddef;
128 printf "<input type=radio name=adddef value=0 %s> %s\n",
129         $adddef ? "" : "checked", $text{'no'};
130 print "</td> </tr>\n";
131
132 print "<tr> <td><b>$text{'edit_deldef'}</b></td>\n";
133 printf "<td><input type=radio name=deldef value=1 %s> %s\n",
134         $deldef ? "checked" : "", $text{'yes'};
135 printf "<input type=radio name=deldef value=0 %s> %s</td> </tr>\n",
136         $deldef ? "" : "checked", $text{'no'};
137
138 # Show editable routes
139 print "<tr> <td valign=top><b>$text{'edit_routes'}</b></td>\n";
140 print "<td colspan=3><table border width=100%>\n";
141 print "<tr $tb> <td><b>$text{'edit_type'}</b></td> ",
142       "<td><b>$text{'edit_net'}</b></td> ",
143       "<td><b>$text{'edit_mask'}</b></td> ",
144       "<td><b>$text{'edit_gw'}</b></td> </tr>\n";
145 $i = 0;
146 foreach $r (@kroutes, [ 0, undef, undef, 'GW' ]) {
147         print "<tr $cb>\n";
148         print "<td><select name=type_$i>\n";
149         foreach $o (0 .. 2) {
150                 printf "<option value=%d %s>%s\n",
151                         $o, $r->[0] == $o ? "selected" : "",
152                         $text{'edit_type'.$o};
153                 }
154         print "</select></td>\n";
155         print "<td><input name=net_$i size=15 value='$r->[1]'></td>\n";
156         print "<td><input name=mask_$i size=15 value='$r->[2]'></td>\n";
157         printf "<td nowrap><input type=radio name=gw_def_$i value=1 %s> %s\n",
158                 $r->[3] eq 'GW' ? "checked" : "", $text{'edit_gw_def'};
159         printf "<input type=radio name=gw_def_$i value=0 %s>\n",
160                 $r->[3] eq 'GW' ? "" : "checked";
161         printf "<input name=gw_$i size=15 value='%s'></td>\n",
162                 $r->[3] eq 'GW' ? "" : $r->[3];
163         print "</tr>\n";
164         $i++;
165         }
166 print "</table></td> </tr>\n";
167
168 # Show other route commands
169 print "<tr> <td valign=top><b>$text{'edit_unknown'}</b></td>\n";
170 print "<td colspan=3><textarea name=unknown rows=3 cols=60>",
171         join("\n", @uroutes),"</textarea></td> </tr>\n";
172
173 print "<tr> <td colspan=4><hr></td> </tr>\n";
174
175 # Show MPPE options
176 print "<tr> <td colspan=4 align=center>$text{'opts_msdesc'}</td> </tr>\n";
177 &mppe_options_form($tunnel->{'opts'});
178
179 print "</table></td></tr></table>\n";
180 print "<table width=100%><tr>\n";
181 if ($in{'new'}) {
182         print "<td><input type=submit value='$text{'create'}'></td>\n";
183         }
184 else {
185         print "<td><input type=submit value='$text{'save'}'></td>\n";
186         print "<td align=right><input type=submit name=delete ",
187               "value='$text{'delete'}'></td>\n";
188         }
189 print "</tr></table>\n";
190
191 &ui_print_footer("", $text{'index_return'});
192