Handle hostnames with upper-case letters
[webmin.git] / sentry / save_logcheck.cgi
1 #!/usr/local/bin/perl
2 # save_logcheck.cgi
3 # Save logcheck.sh options
4
5 require './sentry-lib.pl';
6 &ReadParse();
7 &error_setup($text{'logcheck_err'});
8
9 # Get the current cron job
10 &foreign_require("cron", "cron-lib.pl");
11 @jobs = &cron::list_cron_jobs();
12 foreach $j (@jobs) {
13         $job = $j if ($j->{'command'} =~ /$config{'logcheck'}/);
14         }
15
16 # Validate and save inputs
17 $conf = &get_logcheck_config();
18 &lock_config_files($conf);
19 $in{'to'} =~ /^\S+$/ || &error($text{'logcheck_eto'});
20 if ($in{'runparts'}) {
21         # Being run from a script that we cannot change
22         }
23 elsif (!$in{'active'} && !$job) {
24         # Cron job is not setup yet, and doesn't need to be .. do nothing
25         }
26 else {
27         # Create or update the cron job
28         if (!$job) {
29                 $job = { 'command' => $config{'logcheck'},
30                          'user' => 'root' };
31                 $creating++;
32                 }
33         $job->{'active'} = $in{'active'};
34         &cron::parse_times_input($job, \%in);
35         &lock_file(&cron::cron_file($job));
36         if ($creating) {
37                 &cron::create_cron_job($job);
38                 }
39         else {
40                 &cron::change_cron_job($job);
41                 }
42         &unlock_file(&cron::cron_file($job));
43         }
44 $to = &find_value("SYSADMIN", $conf);
45 if ($to =~ /^\$(\S+)$/) {
46         &save_config($conf, $1, $in{'to'});
47         }
48 else {
49         &save_config($conf, "SYSADMIN", $in{'to'});
50         }
51 &flush_file_lines();
52 &unlock_config_files($conf);
53
54 $hacking = &find_value("HACKING_FILE", $conf, 1);
55 $hacking = &find_value("CRACKING_FILE", $conf, 1) if (!$hacking);
56 &lock_file($hacking);
57 $in{'hacking'} =~ s/\r//g;
58 $in{'hacking'} =~ s/\n*$/\n/;
59 &open_tempfile(HACKING, ">$hacking");
60 &print_tempfile(HACKING, $in{'hacking'});
61 &close_tempfile(HACKING);
62 &unlock_file($hacking);
63
64 $violations = &find_value("VIOLATIONS_FILE", $conf, 1);
65 &lock_file($violations);
66 $in{'violations'} =~ s/\r//g;
67 $in{'violations'} =~ s/\n*$/\n/;
68 &open_tempfile(VIOLATIONS, ">$violations");
69 &print_tempfile(VIOLATIONS, $in{'violations'});
70 &close_tempfile(VIOLATIONS);
71 &unlock_file($violations);
72
73 $violations_ign = &find_value("VIOLATIONS_IGNORE_FILE", $conf, 1);
74 &lock_file($violations_ign);
75 $in{'violations_ign'} =~ s/\r//g;
76 $in{'violations_ign'} =~ s/\n*$/\n/;
77 &open_tempfile(IGNORE, ">$violations_ign");
78 &print_tempfile(IGNORE, $in{'violations_ign'});
79 &close_tempfile(IGNORE);
80 &unlock_file($violations_ign);
81
82 $ignore = &find_value("IGNORE_FILE", $conf, 1);
83 &lock_file($ignore);
84 $in{'ignore'} =~ s/\r//g;
85 $in{'ignore'} =~ s/\n*$/\n/;
86 &open_tempfile(IGNORE, ">$ignore");
87 &print_tempfile(IGNORE, $in{'ignore'});
88 &close_tempfile(IGNORE);
89 &unlock_file($ignore);
90
91 &webmin_log("logcheck");
92 &redirect("");
93