2 # Create, update or delete a destination
4 require './syslog-ng-lib.pl';
6 &error_setup($text{'destination_err'});
8 # Get the old destination
11 @dests = &find("destination", $conf);
12 ($dest) = grep { $_->{'value'} eq $in{'old'} } @dests;
13 $dest || &error($text{'destination_egone'});
17 $dest = { 'name' => 'destination',
22 &lock_file($config{'syslogng_conf'});
25 &check_dependencies('destination', $in{'old'}) &&
26 &error(&text('ddelete_eused', $in{'old'}));
27 &save_directive($conf, undef, $dest, undef, 0);
30 # Validate inputs, and update object
31 $in{'name'} =~ /^[a-z0-9_]+$/i || &error($text{'destination_ename'});
32 if ($in{'new'} || $in{'old'} ne $in{'name'}) {
33 ($clash) = grep { $_->{'value'} eq $in{'name'} } @dests;
34 $clash && &error($text{'destination_eclash'});
36 $dest->{'values'} = [ $in{'name'} ];
38 # Clear out all existing values
39 $dest->{'members'} = [ ];
41 # Save type-specific values
42 if ($in{'type'} == 0) {
44 $in{'file_name'} =~ /^\/\S/ ||
45 &error($text{'destination_efile_name'});
46 $file = { 'name' => 'file',
48 'values' => [ $in{'file_name'} ] };
49 &save_directive($conf, $dest, undef, $file, 1);
52 if (!$in{'file_owner_def'}) {
53 defined(getpwnam($in{'file_owner'})) ||
54 &error($text{'destination_eowner'});
55 &save_directive($conf, $file, "owner",
56 $in{'file_owner'}, 1);
58 if (!$in{'file_group_def'}) {
59 defined(getgrnam($in{'file_group'})) ||
60 &error($text{'destination_egroup'});
61 &save_directive($conf, $file, "group",
62 $in{'file_group'}, 1);
66 if (!$in{'file_perm_def'}) {
67 $in{'file_perm'} =~ /^[0-7]+$/ ||
68 &error($text{'destination_eperm'});
69 &save_directive($conf, $file, "perm",
73 # Save create dirs option
74 if ($in{'file_create_dirs'}) {
75 &save_directive($conf, $file, "create_dirs",
76 $in{'file_create_dirs'}, 1);
78 if (!$in{'file_dir_perm_def'}) {
79 $in{'file_dir_perm'} =~ /^[0-7]+$/ ||
80 &error($text{'destination_edir_perm'});
81 &save_directive($conf, $file, "dir_perm",
82 $in{'file_dir_perm'}, 1);
86 if ($in{'file_fsync'}) {
87 &save_directive($conf, $file, "fsync",
88 $in{'file_fsync'}, 1);
90 if (!$in{'file_sync_freq_def'}) {
91 $in{'file_sync_freq'} =~ /^\d+$/ ||
92 &error($text{'destination_esync_freq'});
93 &save_directive($conf, $file, "sync_freq",
94 $in{'file_sync_freq'}, 1);
98 elsif ($in{'type'} == 1) {
100 $in{'usertty_user_def'} || $in{'usertty_user'} ||
101 &error($text{'destination_euser'});
102 $usertty = { 'name' => 'usertty',
104 'values' => [ $in{'usertty_user_def'} ? '*' :
105 $in{'usertty_user'} ] };
106 &save_directive($conf, $dest, undef, $usertty, 1);
109 elsif ($in{'type'} == 2) {
110 # Feeding to a program
111 $in{'program_prog'} =~ /^\S/ ||
112 &error($text{'destination_eprog'});
113 $program = { 'name' => 'program',
115 'values' => [ $in{'program_prog'} ] };
116 &save_directive($conf, $dest, undef, $program, 1);
119 elsif ($in{'type'} == 3) {
120 # Writing to a pipe file
121 $in{'pipe_name'} =~ /^\S/ ||
122 &error($text{'destination_epipe'});
123 $pipe = { 'name' => 'pipe',
125 'values' => [ $in{'pipe_name'} ] };
126 &save_directive($conf, $dest, undef, $pipe, 1);
129 elsif ($in{'type'} == 4) {
130 # Writing to a TCP or UDP socket
131 $net = { 'name' => $in{'net_proto'},
133 'values' => [ $in{'net_host'} ] };
134 &to_ipaddress($in{'net_host'}) ||
135 &to_ip6address($in{'net_host'}) ||
136 &error($text{'destination_enet_host'});
137 &save_directive($conf, $dest, undef, $net, 1);
139 # Save other network dest options
140 if (!$in{'net_port_def'}) {
141 $in{'net_port'} =~ /^\d+$/ ||
142 &error($text{'destination_enet_port'});
143 &save_directive($conf, $net, "port",
146 if (!$in{'net_localip_def'}) {
147 &check_ipaddress($in{'net_localip'}) ||
148 &error($text{'destination_enet_localip'});
149 &save_directive($conf, $net, "localip",
150 $in{'net_localip'}, 1);
152 if (!$in{'net_localport_def'}) {
153 $in{'net_localport'} =~ /^\d+$/ ||
154 &error($text{'destination_enet_localport'});
155 &save_directive($conf, $net, "localport",
156 $in{'net_localport'}, 1);
160 elsif ($in{'type'} == 6) {
161 $unix = { 'name' => $in{'unix_type'},
163 'values' => [ $in{'unix_name'} ] };
164 $in{'unix_name'} || &error($text{'destination_eunix'});
165 &save_directive($conf, $dest, undef, $unix, 1);
168 # Actually update the object
169 &save_directive($conf, undef, $old, $dest, 0);
171 # Update dependent log targets
173 &rename_dependencies('destination', $in{'old'}, $in{'name'});
177 &unlock_file($config{'syslogng_conf'});
178 &webmin_log($in{'delete'} ? 'delete' : $in{'new'} ? 'create' : 'modify',
179 'destination', $in{'old'} || $in{'name'});
180 &redirect("list_destinations.cgi");