#!/usr/local/bin/perl # edit_stunnel.cgi # Edit or create an SSL tunnel run from inetd require './stunnel-lib.pl'; &ReadParse(); if ($in{'new'}) { &ui_print_header(undef, $text{'create_title'}, ""); $st = { 'active' => 1 }; } else { &ui_print_header(undef, $text{'edit_title'}, ""); @stunnels = &list_stunnels(); $st = $stunnels[$in{'idx'}]; } print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
$text{'edit_header1'}
\n"; print "\n"; printf "\n", $st->{'name'}; print "\n"; printf "\n", $st->{'port'}; print "\n"; printf "\n", $st->{'active'} ? "" : "checked", $text{'no'}; if (!$in{'new'}) { print "\n"; print "\n"; } elsif ($has_inetd && $has_xinetd) { print "\n"; print "\n"; } print "\n"; print "
$text{'edit_name'}$text{'edit_port'}
$text{'edit_active'} %s\n", $st->{'active'} ? "checked" : "", $text{'yes'}; printf " %s$text{'edit_type'}$st->{'type'}$text{'edit_type'}

\n"; print "\n"; print "\n"; print "
$text{'edit_header2'}
\n"; if ($in{'new'}) { $ptymode = 'l'; } elsif (&get_stunnel_version() >= 4) { # Parse new-style stunnel configuration file if ($st->{'args'} =~ /^(\S+)\s+(\S+)/) { $cfile = $2; @conf = &get_stunnel_config($cfile); ($conf) = grep { !$_->{'name'} } @conf; if ($cmd = $conf->{'values'}->{'exec'}) { $args = $conf->{'values'}->{'execargs'}; $ptymode = $conf->{'values'}->{'pty'} eq 'yes' ? "L" : "l"; } else { $rport = $conf->{'values'}->{'connect'}; if ($rport =~ /^(\S+):(\d+)/) { $rhost = $1; $rport = $2; } } $pem = $conf->{'values'}->{'cert'}; $cmode = $conf->{'values'}->{'client'} =~ /yes/i; $tcpw = $conf->{'values'}->{'service'}; $iface = $conf->{'values'}->{'local'}; } } else { # Parse old-style stunnel parameters if ($st->{'args'} =~ s/\s*-([lL])\s+(\S+)\s+--\s+(.*)// || $st->{'args'} =~ s/\s*-([lL])\s+(\S+)//) { $ptymode = $1; $cmd = $2; $args = $3; } if ($st->{'args'} =~ s/\s*-r\s+((\S+):)?(\d+)//) { $rhost = $2; $rport = $3; } if ($st->{'args'} =~ s/\s*-p\s+(\S+)//) { $pem = $1; } if ($st->{'args'} =~ s/\s*-c//) { $cmode = 1; } if ($st->{'args'} =~ s/\s*-N\s+(\S+)//) { $tcpw = $1; } if ($st->{'args'} =~ s/\s*-I\s+(\S+)//) { $iface = $1; } } printf "\n", $ptymode eq 'l' ? 'checked' : '', $text{'edit_mode0'}; printf "\n", $text{'edit_args'}, $ptymode eq 'l' ? $args : ''; printf "\n", $ptymode eq 'L' ? 'checked' : '', $text{'edit_mode1'}; printf "\n", $text{'edit_args'}, $ptymode eq 'L' ? $args : ''; printf "\n", $rport ? 'checked' : '', $text{'edit_mode2'}; printf "\n", $text{'edit_rport'}, $rport; print "
%s%s \n", $text{'edit_cmd'}, $ptymode eq 'l' ? $cmd : ''; printf "%s
%s%s \n", $text{'edit_cmd'}, $ptymode eq 'L' ? $cmd : ''; printf "%s
%s%s \n", $text{'edit_rhost'}, !$rport ? '' : $rhost ? $rhost : 'localhost'; printf "%s

\n"; print "\n"; print "\n"; print "
$text{'edit_header3'}
\n"; print "\n", $haspem ? $config{'pem_path'} : "", &file_chooser_button("pem"); } else { local $pmode = $pem eq $webmin_pem ? 1 : $pem ? 2 : 0; printf " %s\n", $pmode == 0 ? "checked" : "", $text{'edit_pem0'}; printf " %s\n", $pmode == 1 ? "checked" : "", $text{'edit_pem1'}; printf " %s\n", $pmode == 2 ? "checked" : "", $text{'edit_pem2'}; printf " %s\n", $pmode == 2 ? $pem : "", &file_chooser_button("pem"); } print "\n", $tcpw; print "\n", $cmode ? "checked" : "", $text{'edit_cmode1'}; print "\n", $iface; print "
$text{'edit_pem'} \n"; $haspem = $config{'pem_path'} && -r $config{'pem_path'}; if ($in{'new'}) { printf " %s\n", "", $text{'edit_pem0'}; printf " %s\n", $haspem ? "" : "checked", $text{'edit_pem1'}; printf " %s\n", $haspem ? "checked" : "", $text{'edit_pem2'}; printf " %s
$text{'edit_tcpw'} \n"; printf " %s\n", $tcpw ? "" : "checked", $text{'edit_auto'}; printf "\n", $tcpw ? "checked" : ""; printf "
$text{'edit_cmode'} \n"; printf " %s\n", $cmode ? "" : "checked", $text{'edit_cmode0'}; printf " %s
$text{'edit_iface'} \n"; printf " %s\n", $iface ? "" : "checked", $text{'edit_auto'}; printf "\n", $iface ? "checked" : ""; printf "
\n"; print "\n"; print "\n"; if ($in{'new'}) { print "\n"; } else { print "\n"; print "\n"; } print "
\n"; &ui_print_footer("", $text{'index_return'});