2 # Create, update or delete a log source
4 require './syslog-ng-lib.pl';
6 &error_setup($text{'source_err'});
11 @sources = &find("source", $conf);
12 ($source) = grep { $_->{'value'} eq $in{'old'} } @sources;
13 $source || &error($text{'source_egone'});
17 $source = { 'name' => 'source',
22 &lock_file($config{'syslogng_conf'});
25 &check_dependencies('source', $in{'old'}) &&
26 &error(&text('sdelete_eused', $in{'old'}));
27 &save_directive($conf, undef, $source, undef, 0);
30 # Validate inputs, and update object
31 $in{'name'} =~ /^[a-z0-9_]+$/i || &error($text{'source_ename'});
32 if ($in{'new'} || $in{'old'} ne $in{'name'}) {
33 ($clash) = grep { $_->{'value'} eq $in{'name'} } @sources;
34 $clash && &error($text{'source_eclash'});
36 $source->{'values'} = [ $in{'name'} ];
38 # Clear out all existing values
39 $source->{'members'} = [ ];
41 if ($in{'internal'}) {
42 # Save internal option
43 $internal = { 'name' => 'internal',
46 &save_directive($conf, $source, undef, $internal, 1);
49 foreach $t ("unix-stream", "unix-dgram") {
50 # Save Unix socket file option
52 $in{$t.'_name'} =~ /^\/\S/ ||
53 &error($text{'source_eunix_name'});
54 $unix = { 'name' => $t,
56 'values' => [ $in{$t.'_name'} ] };
57 &save_directive($conf, $source, undef, $unix, 1);
60 if (!$in{$t.'_owner_def'}) {
61 defined(getpwnam($in{$t.'_owner'})) ||
62 &error($text{'source_eowner'});
63 &save_directive($conf, $unix, "owner",
66 if (!$in{$t.'_group_def'}) {
67 defined(getgrnam($in{$t.'_group'})) ||
68 &error($text{'source_egroup'});
69 &save_directive($conf, $unix, "group",
74 if (!$in{$t.'_perm_def'}) {
75 $in{$t.'_perm'} =~ /^[0-7]+$/ ||
76 &error($text{'source_eperm'});
77 &save_directive($conf, $unix, "perm",
81 if ($t eq "unix-stream") {
82 # Save keep-alive option
83 if ($in{$t.'_keep'}) {
84 &save_directive($conf, $unix, "keep-alive",
88 # Save max connections option
89 if (!$in{$t.'_max_def'}) {
90 $in{$t.'_max'} =~ /^\d+$/ ||
91 &error($text{'source_emax'});
92 &save_directive($conf, $unix, "max-connections",
98 foreach $t ('tcp', 'udp') {
99 # Save network socket file option
101 $net = { 'name' => $t,
104 &save_directive($conf, $source, undef, $net, 1);
106 # Save local IP and port
107 if (!$in{$t.'_ip_def'}) {
108 &check_ipaddress($in{$t.'_ip'}) ||
109 &error($text{'source_eip'});
110 &save_directive($conf, $net, "ip",
113 if (!$in{$t.'_port_def'}) {
114 $in{$t.'_port'} =~ /^\d+$/ ||
115 &error($text{'source_eport'});
116 &save_directive($conf, $net, "port",
120 # Save TCP-specific options and max connections
122 if ($in{$t.'_keep'}) {
123 &save_directive($conf, $net, "keep-alive",
126 if ($in{$t.'_tkeep'}) {
127 &save_directive($conf, $net, "tcp-keep-alive",
128 $in{$t.'_tkeep'}, 1);
131 if (!$in{$t.'_max_def'}) {
132 $in{$t.'_max'} =~ /^\d+$/ ||
133 &error($text{'source_emax'});
134 &save_directive($conf, $net, "max-connections",
139 # Save kernel file option
141 $in{'file_name'} =~ /^\/\S/ ||
142 &error($text{'source_efile_name'});
143 $file = { 'name' => 'file',
145 'values' => [ $in{'file_name'} ] };
146 &save_directive($conf, $source, undef, $file, 1);
149 if (!$in{'file_prefix_def'}) {
150 $in{'file_prefix'} =~ /\S/ ||
151 &error($text{'source_eprefix'});
152 &save_directive($conf, $file, "log_prefix",
153 $in{'file_prefix'}, 1);
157 # Save named pipe option
159 $in{'pipe_name'} =~ /^\/\S/ ||
160 &error($text{'source_epipe_name'});
161 $pipe = { 'name' => 'pipe',
163 'values' => [ $in{'pipe_name'} ] };
164 &save_directive($conf, $source, undef, $pipe, 1);
166 # Save log prefix and pad size
167 if (!$in{'pipe_prefix_def'}) {
168 $in{'pipe_prefix'} =~ /\S/ ||
169 &error($text{'source_eprefix'});
170 &save_directive($conf, $pipe, "log_prefix",
171 $in{'pipe_prefix'}, 1);
173 if (!$in{'pipe_pad_def'}) {
174 $in{'pipe_pad'} =~ /^\d+$/ ||
175 &error($text{'source_epad'});
176 &save_directive($conf, $pipe, "pad_size",
181 # Save Solaris streams option
182 if ($in{'sun-streams'}) {
183 $in{'sun_streams_name'} =~ /^\/\S/ ||
184 &error($text{'source_esun_streams_name'});
185 $sun_streams = { 'name' => 'sun-streams',
187 'values' => [ $in{'sun_streams_name'} ] };
188 &save_directive($conf, $source, undef, $sun_streams, 1);
191 $in{'sun_streams_door'} =~ /\S/ ||
192 &error($text{'source_edoor'});
193 &save_directive($conf, $sun_streams, "door",
194 $in{'sun_streams_door'}, 1);
198 # Actually update the object
199 &save_directive($conf, undef, $old, $source, 0);
201 # Update dependent log targets
203 &rename_dependencies('source', $in{'old'}, $in{'name'});
207 &unlock_file($config{'syslogng_conf'});
208 &webmin_log($in{'delete'} ? 'delete' : $in{'new'} ? 'create' : 'modify',
209 'source', $in{'old'} || $in{'name'});
210 &redirect("list_sources.cgi");