2 # Save scheduled finding of servers
3 # Thanks to OpenCountry for sponsoring this feature
7 require './servers-lib.pl';
8 our (%in, %text, $module_name, $cron_cmd, @cluster_modules, %config, %access);
9 $access{'auto'} || &error($text{'auto_ecannot'});
11 &error_setup($text{'auto_err'});
13 my $job = &find_cron_job();
17 $in{'mins'} =~ /^\d+$/ || &error($text{'auto_emins'});
18 if ($in{'net_def'} == 1) {
19 $config{'auto_net'} = undef;
21 elsif ($in{'net_def'} == 0) {
22 my @nets = split(/\s+/, $in{'net'});
23 foreach my $n (@nets) {
24 &check_ipaddress($n) ||
25 &error($text{'auto_enet'});
27 $config{'auto_net'} = $in{'net'};
30 $in{'iface'} =~ /^[a-z]+\d*(:\d+)?$/ ||
31 &error($text{'auto_eiface'});
32 $config{'auto_net'} = $in{'iface'};
34 $in{'auser'} =~ /\S/ || &error($text{'auto_euser'});
35 $config{'auto_user'} = $in{'auser'};
36 $config{'auto_pass'} = $in{'apass'};
37 $config{'auto_type'} = $in{'type'};
38 foreach my $m (@cluster_modules) {
39 if (&foreign_available($m)) {
40 $config{'auto_'.$m} = $in{$m};
43 $config{'auto_remove'} = $in{'remove'};
44 $config{'auto_self'} = $in{'self'};
45 $in{'email_def'} || $in{'email'} =~ /\S/ ||&error($text{'auto_eemail'});
46 $config{'auto_email'} = $in{'email_def'} ? undef : $in{'email'};
47 $in{'smtp_def'} || &to_ipaddress($in{'smtp'}) ||
48 &to_ip6address($in{'smtp'}) ||
49 &error($text{'auto_esmtp'});
50 $config{'auto_smtp'} = $in{'smtp_def'} ? undef : $in{'smtp'};
51 &save_module_config();
54 # Create or update Cron job
55 &cron::create_wrapper($cron_cmd, $module_name, "auto.pl");
59 for(my $i=0; $i<60; $i+=$in{'mins'}) {
63 if ($in{'sched'} && !$job) {
65 $job = { 'user' => 'root',
66 'command' => $cron_cmd,
68 'mins' => join(",", @mins),
74 &cron::create_cron_job($job);
76 elsif (!$in{'sched'} && $job) {
78 &cron::delete_cron_job($job);
80 elsif ($in{'sched'} && $job) {
82 $job->{'mins'} = join(",", @mins);
83 $job->{'hours'} = $job->{'days'} =
84 $job->{'months'} = $job->{'weekdays'} = '*';
85 &cron::change_cron_job($job);