3 # Edit or create an SSL tunnel run from inetd
5 require './stunnel-lib.pl';
9 &ui_print_header(undef, $text{'create_title'}, "");
10 $st = { 'active' => 1 };
13 &ui_print_header(undef, $text{'edit_title'}, "");
14 @stunnels = &list_stunnels();
15 $st = $stunnels[$in{'idx'}];
18 print "<form action=save_stunnel.cgi>\n";
19 print "<input type=hidden name=new value='$in{'new'}'>\n";
20 print "<input type=hidden name=idx value='$in{'idx'}'>\n";
22 print "<table border width=100%>\n";
23 print "<tr $tb> <td><b>$text{'edit_header1'}</b></td> </tr>\n";
24 print "<tr $cb> <td><table width=100%>\n";
26 print "<tr> <td><b>$text{'edit_name'}</b></td>\n";
27 printf "<td><input name=name size=15 value='%s'></td>\n",
30 print "<td><b>$text{'edit_port'}</b></td>\n";
31 printf "<td><input name=port size=6 value='%s'></td> </tr>\n",
34 print "<tr> <td><b>$text{'edit_active'}</b></td>\n";
35 printf "<td><input type=radio name=active value=1 %s> %s\n",
36 $st->{'active'} ? "checked" : "", $text{'yes'};
37 printf "<input type=radio name=active value=0 %s> %s</td>\n",
38 $st->{'active'} ? "" : "checked", $text{'no'};
41 print "<td><b>$text{'edit_type'}</b></td>\n";
42 print "<td><tt>$st->{'type'}</tt></td>\n";
44 elsif ($has_inetd && $has_xinetd) {
45 print "<td><b>$text{'edit_type'}</b></td>\n";
46 print "<td><select name=type>\n";
47 print "<option selected>xinetd\n";
48 print "<option>inetd\n";
49 print "</select></td>\n";
53 print "</table></td></tr></table><br>\n";
54 print "<table border width=100%>\n";
55 print "<tr $tb> <td><b>$text{'edit_header2'}</b></td> </tr>\n";
56 print "<tr $cb> <td><table width=100%>\n";
61 elsif (&get_stunnel_version() >= 4) {
62 # Parse new-style stunnel configuration file
63 if ($st->{'args'} =~ /^(\S+)\s+(\S+)/) {
65 @conf = &get_stunnel_config($cfile);
66 ($conf) = grep { !$_->{'name'} } @conf;
67 if ($cmd = $conf->{'values'}->{'exec'}) {
68 $args = $conf->{'values'}->{'execargs'};
69 $ptymode = $conf->{'values'}->{'pty'} eq 'yes' ? "L"
73 $rport = $conf->{'values'}->{'connect'};
74 if ($rport =~ /^(\S+):(\d+)/) {
79 $pem = $conf->{'values'}->{'cert'};
80 $cmode = $conf->{'values'}->{'client'} =~ /yes/i;
81 $tcpw = $conf->{'values'}->{'service'};
82 $iface = $conf->{'values'}->{'local'};
86 # Parse old-style stunnel parameters
87 if ($st->{'args'} =~ s/\s*-([lL])\s+(\S+)\s+--\s+(.*)// ||
88 $st->{'args'} =~ s/\s*-([lL])\s+(\S+)//) {
93 if ($st->{'args'} =~ s/\s*-r\s+((\S+):)?(\d+)//) {
97 if ($st->{'args'} =~ s/\s*-p\s+(\S+)//) {
100 if ($st->{'args'} =~ s/\s*-c//) {
103 if ($st->{'args'} =~ s/\s*-N\s+(\S+)//) {
106 if ($st->{'args'} =~ s/\s*-I\s+(\S+)//) {
111 printf "<tr> <td><input type=radio name=mode value=0 %s> %s</td>\n",
112 $ptymode eq 'l' ? 'checked' : '', $text{'edit_mode0'};
113 printf "<td nowrap><b>%s</b> <input name=cmd0 size=15 value='%s'>\n",
114 $text{'edit_cmd'}, $ptymode eq 'l' ? $cmd : '';
115 printf "<b>%s</b> <input name=args0 size=20 value='%s'></td> </tr>\n",
116 $text{'edit_args'}, $ptymode eq 'l' ? $args : '';
118 printf "<tr> <td><input type=radio name=mode value=1 %s> %s</td>\n",
119 $ptymode eq 'L' ? 'checked' : '', $text{'edit_mode1'};
120 printf "<td nowrap><b>%s</b> <input name=cmd1 size=15 value='%s'>\n",
121 $text{'edit_cmd'}, $ptymode eq 'L' ? $cmd : '';
122 printf "<b>%s</b> <input name=args1 size=20 value='%s'></td> </tr>\n",
123 $text{'edit_args'}, $ptymode eq 'L' ? $args : '';
125 printf "<tr> <td><input type=radio name=mode value=2 %s> %s</td>\n",
126 $rport ? 'checked' : '', $text{'edit_mode2'};
127 printf "<td nowrap><b>%s</b> <input name=rhost size=20 value='%s'>\n",
128 $text{'edit_rhost'}, !$rport ? '' : $rhost ? $rhost : 'localhost';
129 printf "<b>%s</b> <input name=rport size=6 value='%s'></td> </tr>\n",
130 $text{'edit_rport'}, $rport;
132 print "</table></td></tr></table><br>\n";
133 print "<table border width=100%>\n";
134 print "<tr $tb> <td><b>$text{'edit_header3'}</b></td> </tr>\n";
135 print "<tr $cb> <td><table width=100%>\n";
137 print "<tr> <td><b>$text{'edit_pem'}</b></td> <td nowrap>\n";
138 $haspem = $config{'pem_path'} && -r $config{'pem_path'};
140 printf "<input type=radio name=pmode value=0 %s> %s\n",
141 "", $text{'edit_pem0'};
142 printf "<input type=radio name=pmode value=1 %s> %s\n",
143 $haspem ? "" : "checked", $text{'edit_pem1'};
144 printf "<input type=radio name=pmode value=2 %s> %s\n",
145 $haspem ? "checked" : "", $text{'edit_pem2'};
146 printf "<input name=pem size=25 value='%s'> %s</td> </tr>\n",
147 $haspem ? $config{'pem_path'} : "", &file_chooser_button("pem");
150 local $pmode = $pem eq $webmin_pem ? 1 :
152 printf "<input type=radio name=pmode value=0 %s> %s\n",
153 $pmode == 0 ? "checked" : "", $text{'edit_pem0'};
154 printf "<input type=radio name=pmode value=1 %s> %s\n",
155 $pmode == 1 ? "checked" : "", $text{'edit_pem1'};
156 printf "<input type=radio name=pmode value=2 %s> %s\n",
157 $pmode == 2 ? "checked" : "", $text{'edit_pem2'};
158 printf "<input name=pem size=25 value='%s'> %s</td> </tr>\n",
159 $pmode == 2 ? $pem : "", &file_chooser_button("pem");
162 print "<tr> <td><b>$text{'edit_tcpw'}</b></td> <td>\n";
163 printf "<input type=radio name=tcpw_def value=1 %s> %s\n",
164 $tcpw ? "" : "checked", $text{'edit_auto'};
165 printf "<input type=radio name=tcpw_def value=0 %s>\n",
166 $tcpw ? "checked" : "";
167 printf "<input name=tcpw size=15 value='%s'></td> </tr>\n", $tcpw;
169 print "<tr> <td><b>$text{'edit_cmode'}</b></td> <td>\n";
170 printf "<input type=radio name=cmode value=0 %s> %s\n",
171 $cmode ? "" : "checked", $text{'edit_cmode0'};
172 printf "<input type=radio name=cmode value=1 %s> %s</td> </tr>\n",
173 $cmode ? "checked" : "", $text{'edit_cmode1'};
175 print "<tr> <td><b>$text{'edit_iface'}</b></td> <td>\n";
176 printf "<input type=radio name=iface_def value=1 %s> %s\n",
177 $iface ? "" : "checked", $text{'edit_auto'};
178 printf "<input type=radio name=iface_def value=0 %s>\n",
179 $iface ? "checked" : "";
180 printf "<input name=iface size=25 value='%s'></td> </tr>\n", $iface;
182 print "</table></td></tr></table>\n";
183 print "<input type=hidden name=args value='$st->{'args'}'>\n";
184 print "<table width=100%><tr>\n";
186 print "<td><input type=submit value='$text{'create'}'></td>\n";
189 print "<td><input type=submit value='$text{'save'}'></td>\n";
190 print "<td align=right><input type=submit name=delete ",
191 "value='$text{'delete'}'></td>\n";
193 print "</tr></table></form>\n";
195 &ui_print_footer("", $text{'index_return'});