Handle hostnames with upper-case letters
[webmin.git] / spam / save_score.cgi
1 #!/usr/local/bin/perl
2 # save_score.cgi
3 # Save message scoring options
4
5 require './spam-lib.pl';
6 &error_setup($text{'score_err'});
7 &ReadParse();
8 &set_config_file_in(\%in);
9 &can_use_check("score");
10 &execute_before("score");
11 &lock_spam_files();
12 $conf = &get_config();
13
14 $hits_param = &version_atleast(3.0) ? "required_score" : "required_hits";
15 &parse_opt($conf, $hits_param, \&hits_check);
16 &parse_opt($conf, "auto_whitelist_factor", \&auto_check);
17 &parse_yes_no($conf, "use_bayes");
18 &parse_opt($conf, "check_mx_attempts", \&mx_check);
19 &parse_opt($conf, "check_mx_delay", \&mxdelay_check);
20 &parse_yes_no($conf, "skip_rbl_checks");
21 &parse_opt($conf, "rbl_timeout", \&timeout_check);
22 &parse_opt($conf, "num_check_received", \&received_check);
23
24 if (defined($in{'langs_def'})) {
25         if ($in{'langs_def'} == 2) {
26                 &save_directives($conf, "ok_languages", [ ], 1);
27                 }
28         elsif ($in{'langs_def'} == 1) {
29                 &save_directives($conf, "ok_languages", [ "all" ], 1);
30                 }
31         else {
32                 &save_directives($conf, "ok_languages",
33                                  [ join(" ", split(/\0/, $in{'langs'})) ], 1);
34                 }
35         }
36
37 if (defined($in{'locales_def'})) {
38         if ($in{'locales_def'} == 2) {
39                 &save_directives($conf, "ok_locales", [ ], 1);
40                 }
41         elsif ($in{'locales_def'} == 1) {
42                 &save_directives($conf, "ok_locales", [ "all" ], 1);
43                 }
44         else {
45                 &save_directives($conf, "ok_locales",
46                                  [ join(" ", split(/\0/, $in{'locales'})) ], 1);
47                 }
48         }
49
50 &flush_file_lines();
51 &unlock_spam_files();
52 &execute_after("score");
53 &webmin_log("score");
54 &redirect($redirect_url);
55
56 sub hits_check
57 {
58 $_[0] =~ /^\d+(\.\d+)?$/ || &error($text{'score_ehits'});
59 }
60
61 sub auto_check
62 {
63 $_[0] =~ /^\d+(\.\d+)?$/ && $_[0] >= 0 && $_[0] <= 1 ||
64         &error($text{'score_eauto'});
65 }
66
67 sub mx_check
68 {
69 $_[0] =~ /^\d+$/ || &error($text{'score_emx'});
70 }
71
72 sub mxdelay_check
73 {
74 $_[0] =~ /^\d+$/ || &error($text{'score_emxdelay'});
75 }
76
77 sub timeout_check
78 {
79 $_[0] =~ /^\d+$/ || &error($text{'score_etimeout'});
80 }
81
82 sub received_check
83 {
84 $_[0] =~ /^\d+$/ || &error($text{'score_ereceived'});
85 }
86