#!/usr/local/bin/perl
# index.cgi
# Display existing IPsec tunnels
require './ipsec-lib.pl';
# Make sure the ipsec command exists
if (!&has_command($config{'ipsec'}) ||
!(($ipsec_version, $ipsec_program) = &get_ipsec_version(\$out))) {
&ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, 0,
&help_search_link("freeswan", "doc", "google"));
print "
",&text('index_eipsec', "$config{'ipsec'}",
"$gconfig{'webprefix'}/config.cgi?$module_name"),"
\n";
if ($out) {
print &text('index_out',
"$config{'ipsec'} --version"),"\n";
print "
$out
\n";
}
}
else {
&ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, 0,
&help_search_link("freeswan", "doc", "google"), undef, undef,
&text('index_version2', $ipsec_version, $ipsec_program));
# Make sure the config file exists
if (!-r $config{'file'}) {
print "",&text('index_econfig', "$config{'file'}",
"$gconfig{'webprefix'}/config.cgi?$module_name"),"
\n";
}
else {
# Check for the host secret
if (!&got_secret()) {
# No key setup yet .. offer to create one
print "
",&text('index_nokey',
"$config{'secrets'}"),"
\n";
print "
\n";
}
else {
# Show icons for connections
print &ui_subheading($text{'index_header1'});
@conf = &get_config();
@conns = grep { $_->{'name'} eq 'conn' } @conf;
if (@conns) {
foreach $c (@conns) {
push(@links, "edit.cgi?idx=".
$c->{'index'});
if ($c->{'value'} eq '%default') {
push(@titles, "$text{'index_defconn'}");
$has_default++;
}
else {
push(@titles,
&text('index_conn',
"$c->{'value'}"));
push(@start, $c->{'value'});
}
push(@icons, "images/conn.gif");
}
&icons_table(\@links, \@titles, \@icons);
}
else {
print "$text{'index_none'}\n";
}
print "$text{'index_add'}";
if (!$has_default) {
print " " x 3;
print "$text{'index_adddef'}";
}
print " " x 3;
print "$text{'index_import'}";
print "
\n";
# Show icons for various options
print "
\n";
print &ui_subheading($text{'index_header2'});
@links = ( "edit_config.cgi", "showkey.cgi",
"list_secrets.cgi" );
@titles = ( $text{'config_title'},
$text{'showkey_title'},
$text{'secrets_title'} );
@icons = ( "images/config.gif", "images/showkey.gif",
"images/secrets.gif" );
if ($ipsec_version =~ /(\d+)/ && $1 >= 2) {
@policies = &list_policies();
foreach $p (@policies) {
push(@links, "edit_policy.cgi?policy=$p");
push(@titles, $text{'policy_desc_'.$p} ||
&text('policy_desc', $p));
push(@icons, "images/policy.gif");
}
$got_policies = 1;
}
&icons_table(\@links, \@titles, \@icons, 4);
if (!@policies && $got_policies) {
print "",&text('index_nopol',
"$gconfig{'webprefix'}/config.cgi?$module_name"),"\n";
}
print "
\n";
print "\n";
# Start connection button
if (@start && &is_ipsec_running()) {
print "\n";
}
# Start/stop/restart ipsec buttons
if (&is_ipsec_running()) {
print "\n";
print "\n";
}
else {
print "\n";
}
# Show boot-time start button
if (&foreign_check("init")) {
&foreign_require("init", "init-lib.pl");
$starting = &init::action_status("ipsec");
print "\n";
}
print "
\n";
}
}
}
&ui_print_footer("/", $text{'index'});