#!/usr/local/bin/perl
# Show a form for editing or creating a log destination
require './syslog-ng-lib.pl';
&ReadParse();
# Show title and get the destination
$conf = &get_config();
if ($in{'new'}) {
&ui_print_header(undef, $text{'destination_title1'}, "");
}
else {
&ui_print_header(undef, $text{'destination_title2'}, "");
@dests = &find("destination", $conf);
($dest) = grep { $_->{'value'} eq $in{'name'} } @dests;
$dest || &error($text{'destination_egone'});
}
# Form header
print &ui_form_start("save_destination.cgi", "post");
print &ui_hidden("new", $in{'new'}),"\n";
print &ui_hidden("old", $in{'name'}),"\n";
print &ui_table_start($text{'destination_header'}, undef, 2);
# Destination name
print &ui_table_row($text{'destination_name'},
&ui_textbox("name", $dest->{'value'}, 20));
# Work out type
$file = &find("file", $dest->{'members'});
$usertty = &find("usertty", $dest->{'members'});
$program = &find("program", $dest->{'members'});
$pipe = &find("pipe", $dest->{'members'});
$udp = &find("udp", $dest->{'members'});
$tcp = &find("tcp", $dest->{'members'});
$dgram = &find("unix-dgram", $dest->{'members'});
$stream = &find("unix-stream", $dest->{'members'});
$type = $file ? 0 :
$usertty ? 1 :
$program ? 2 :
$pipe ? 3 :
$tcp ? 4 :
$udp ? 5 :
$dgram ? 6 :
$stream ? 7 : 0;
$dtable = "
\n";
# File destination
if ($file) {
$file_name = $file->{'value'};
$file_owner = &find_value("owner", $file->{'members'});
$file_group = &find_value("group", $file->{'members'});
$file_perm = &find_value("perm", $file->{'members'});
$file_create_dirs = &find_value("create_dirs", $file->{'members'});
$file_dir_perm = &find_value("dir_perm", $file->{'members'});
$file_fsync = &find_value("fsync", $file->{'members'});
$file_sync_freq = &find_value("sync_freq", $file->{'members'});
}
$dtable .= " ".&ui_oneradio("type", 0, "$text{'destinations_typef'}", $type == 0)." | \n";
$dtable .= " $text{'destination_file'} | ".
&ui_textbox("file_name", $file_name, 35)." ".
&file_chooser_button("file_name")." | \n";
$dtable .= " $text{'destination_owner'} | ".
&ui_opt_textbox("file_owner", $file_owner, 15, $text{'default'})." ".
&user_chooser_button("file_owner").
" | \n";
$dtable .= " $text{'destination_group'} | ".
&ui_opt_textbox("file_group", $file_group, 15, $text{'default'})." ".
&group_chooser_button("file_owner").
" | \n";
$dtable .= " $text{'destination_perm'} | ".
&ui_opt_textbox("file_perm", $file_perm, 5, $text{'default'}).
" | \n";
$dtable .= " $text{'destination_create_dirs'} | ".
&ui_radio("file_create_dirs", $file_create_dirs,
[ [ 'yes', $text{'yes'} ],
[ 'no', $text{'no'} ],
[ '', $text{'default'} ] ]).
" | \n";
$dtable .= " $text{'destination_dir_perm'} | ".
&ui_opt_textbox("file_dir_perm", $file_dir_perm, 5,$text{'default'}).
" | \n";
$dtable .= " $text{'destination_fsync'} | ".
&ui_radio("file_fsync", $file_fsync,
[ [ 'yes', $text{'yes'} ],
[ 'no', $text{'no'} ],
[ '', $text{'default'} ] ]).
" | \n";
$dtable .= " $text{'destination_sync_freq'} | ".
&ui_opt_textbox("file_sync_freq", $file_sync_freq, 5, $text{'default'}).
" | \n";
$dtable .= " |
";
# User TTY destination
if ($usertty) {
$usertty_user = $usertty->{'value'};
}
$dtable .= " ".&ui_oneradio("type", 1, "$text{'destinations_typeu'}", $type == 1)." | \n";
$dtable .= &ui_opt_textbox("usertty_user", $usertty_user eq "*" ? undef : $usertty_user, 20, $text{'destinations_allusers'}, $text{'destination_users'})." ".&user_chooser_button("usertty_user", 1);
$table .= " |
";
# Program destination
if ($program) {
$program_prog = $program->{'value'};
}
$dtable .= " ".&ui_oneradio("type", 2, "$text{'destinations_typep'}", $type == 2)." | \n";
$dtable .= &ui_textbox("program_prog", $program_prog, 50);
$table .= " |
";
# Pipe destination
if ($pipe) {
$pipe_name = $pipe->{'value'};
}
$dtable .= " ".&ui_oneradio("type", 3, "$text{'destinations_typei'}", $type == 3)." | \n";
$dtable .= &ui_textbox("pipe_name", $pipe_name, 30)." ".
&file_chooser_button("pipe_name");
$dtable .= " |
";
# TCP or UDP socket
$net = $tcp || $udp;
if ($net) {
$net_host = $net->{'value'};
$net_port = &find_value("port", $net->{'members'});
$net_localip = &find_value("localip", $net->{'members'});
$net_localport = &find_value("localport", $net->{'members'});
}
$dtable .= " ".&ui_oneradio("type", 4, "$text{'destination_net'}", $type == 4 || $type == 5)." | \n";
$dtable .= " $text{'destination_proto'} | ".
"".&ui_select("net_proto", $type == 5 ? "udp" : "tcp",
[ [ "tcp", "TCP" ], [ "udp", "UDP" ] ])." | \n";
$dtable .= " $text{'destination_host'} | ".
"".&ui_textbox("net_host", $net_host, 20)." | \n";
$dtable .= " $text{'destination_port'} | ".
"".&ui_opt_textbox("net_port", $net_port, 5, "$text{'default'} (514)")." | \n";
$dtable .= " $text{'destination_localip'} | ".
"".&ui_opt_textbox("net_localip", $net_localip, 15, $text{'default'})." | \n";
$dtable .= " $text{'destination_localport'} | ".
"".&ui_opt_textbox("net_localport", $net_localport, 5, $text{'default'})." | \n";
$dtable .= " |
";
# Datagram or stream socket
$unix = $dgram || $stream;
if ($unix) {
$unix_name = $unix->{'value'};
}
$dtable .= " ".&ui_oneradio("type", 6, "$text{'destination_unix'}", $type == 6 || $type == 7)." | \n";
$dtable .= " $text{'destination_utype'} | ".
"".&ui_select("unix_type",
$type == 6 ? "unix-dgram" : "unix-stream",
[ [ "unix-stream", $text{'destinations_types'} ],
[ "unix-dgram", $text{'destinations_typeg'} ] ]).
" | \n";
$dtable .= " $text{'destination_socket'} | ".
"".&ui_textbox("unix_name", $unix_name, 30)."\n".
&file_chooser_button("unix_name")." | \n";
$dtable .= " |
";
# Actually show the destination
$dtable .= "
\n";
print &ui_table_row($text{'destination_type'}, $dtable);
# Form footer and buttons
print &ui_table_end();
if ($in{'new'}) {
print &ui_form_end([ [ "create", $text{'create'} ] ]);
}
else {
print &ui_form_end([ [ "save", $text{'save'} ],
[ "delete", $text{'delete'} ] ]);
}
&ui_print_footer("list_destinations.cgi", $text{'destinations_return'});