1#!/usr/local/bin/perl 2# save_opts.cgi 3# Save various sendmail options 4 5require './sendmail-lib.pl'; 6&ReadParse(); 7$access{'opts'} || &error($text{'opts_ecannot'}); 8&error_setup($text{'opts_err'}); 9&lock_file($config{'sendmail_cf'}); 10$conf = &get_sendmailcf(); 11$ver = &check_sendmail_version($conf); 12 13# Save directives 14&save_doption("S", "DS", 1); 15&save_doption("R", "DR", 1); 16&save_doption("H", "DH", 1); 17 18# Save other options 19&save_option("QueueLA", '[\d\.]+', $text{'opts_queuela'}); 20&save_option("RefuseLA", '[\d\.]+', $text{'opts_refusela'}); 21&save_option("MaxDaemonChildren", '\d+', $text{'opts_maxch'}); 22&save_option("ConnectionRateThrottle", '\d+', $text{'opts_throttle'}); 23&save_option("MinQueueAge", '\d+\S', $text{'opts_minqueueage'}); 24&save_option("MaxQueueRunSize", '\d+', $text{'opts_runsize'}); 25&save_option("Timeout.queuereturn", '\d+[dmhwsy]', $text{'opts_queuereturn'}); 26&save_option("Timeout.queuewarn", '\d+[dmhwsy]', $text{'opts_queuewarn'}); 27&save_option("QueueDirectory", '\/\S+', $text{'opts_queue'}); 28&save_option("PostMasterCopy", '\S+', $text{'opts_postmaster'}); 29&save_option("ForwardPath", '\S+', $text{'opts_forward'}); 30&save_option("MinFreeBlocks", '\d+', $text{'opts_minfree'}); 31&save_option("MaxMessageSize", '\d+', $text{'opts_maxmessage'}); 32&save_option("LogLevel", '\d+', $text{'opts_loglevel'}); 33$in{'DontBlameSendmail'} =~ s/\0/ /g; 34&save_option("DontBlameSendmail", '.*\S.*', $text{'opts_blame'}); 35&save_option("SendMimeErrors", '.*'); 36$in{'DeliveryMode_def'} = 1 if (!$in{'DeliveryMode'}); 37&save_option("DeliveryMode", '.*'); 38$in{'QueueSortOrder_def'} = 1 if (!$in{'QueueSortOrder'}); 39&save_option("QueueSortOrder", '.*'); 40&save_option("MaxHopCount", '\d+', $text{'opts_hops'}); 41&save_option("MatchGECOS", '.*'); 42if ($ver >= 10) { 43 &save_option("MaxRecipientsPerMessage", '\d+', $text{'opts_maxrcpt'}); 44 &save_option("BadRcptThrottle", '\d+', $text{'opts_maxbad'}); 45 } 46&flush_file_lines(); 47&unlock_file($config{'sendmail_cf'}); 48&restart_sendmail(); 49&webmin_log("opts", undef, undef, \%in); 50&redirect(""); 51 52# save_doption(type2, input, blank) 53sub save_doption 54{ 55local ($oldstr, $old) = &find_type2("D", $_[0], $conf); 56@oldlist = $oldstr ? ( $oldstr ) : ( ); 57if ($in{"$_[1]_def"}) { 58 @newlist = $_[2] && $oldstr ? 59 ( { 'type' => 'D', 'values' => [ $_[0] ] } ) : ( ); 60 } 61elsif ($in{$_[1]} !~ /^\S+$/) { 62 &error(&text('opts_ehost', $in{$_[1]})); 63 } 64else { 65 @newlist = ( { 'type' => 'D', 'values' => [ $_[0].$in{$_[1]} ] } ); 66 } 67&save_directives($conf, \@oldlist, \@newlist); 68} 69 70# save_option(name, regexp, what) 71sub save_option 72{ 73local ($oldstr, $old) = &find_option($_[0], $conf); 74local @oldlist = $oldstr ? ( $oldstr ) : ( ); 75local (@newlist, $re); $re = $_[1]; 76if ($in{"$_[0]_def"}) { @newlist = (); } 77elsif ($in{$_[0]} !~ /^$re$/) { 78 &error(&text('opts_einvalid', $in{$_[0]}, $_[2])); 79 } 80else { @newlist = ( { 'type' => 'O', 'values' => [ " $_[0]=$in{$_[0]}" ] } ); } 81&save_directives($conf, \@oldlist, \@newlist); 82} 83 84# save_options(name, regexp, what) 85sub save_options 86{ 87local @oldlist = map { $_->[0] } &find_options($_[0], $conf); 88local @newlist; 89if (!$in{"$_[0]_def"}) { 90 local $re = $_[1]; 91 foreach my $v (split(/\r?\n/, $in{$_[0]})) { 92 $v =~ /^$re$/ || 93 &error(&text('opts_einvalid', $in{$_[0]}, $_[2])); 94 push(@newlist, { 'type' => 'O', 'values' => [ " $_[0]=$v" ] }); 95 } 96 } 97&save_directives($conf, \@oldlist, \@newlist); 98} 99 100