summaryrefslogtreecommitdiffstats
path: root/news_wizard/scripts/Newsconf.pm
blob: 55e9972919f1eb983e2d9381e54965eb341588ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl

package Newsconf;
require "__WIZ_HOME__/common/scripts/Vareqval.pm";
use MDK::Common;
use strict;

sub	normalize_freq {
    my	($freq) = @_;

    if ($freq =~ /(\d*)/) {
	$freq = $1;
    }
    if ($freq <= 0) {
	$freq = 0;
    }
    if ($freq >= 24) {
	$freq = 24;
    }
    $freq;
}

sub	get_server {
    my %mdk = Vareqval->get("/etc/leafnode/config");
    $mdk{server};
}

sub	normalize_server {
    my	($server) = @_;
    
    $server;
}

sub	do_it {
    $ENV{wiz_news_freq} and my $freq = normalize_freq($ENV{wiz_news_freq}) or
      die "freq not defined: $!";
    $ENV{wiz_news_server} and my $server = normalize_server($ENV{wiz_news_server}) or
      die "server not defined: $!";
    my $file = "/etc/leafnode/config";
    output($file, map { 
	s|__server__|$server|g;
	$_;
    } cat_("__WIZ_HOME__/news_wizard/scripts/config.default"));
    $file = "/var/spool/cron/news";
    -f $file and MDK::Common::cp_af($file, "/etc/leafnode/crontab");
    $file = "/etc/leafnode/crontab";
    MDK::Common::cp_af($file, $file . ".orig");
    my $file = "/etc/leafnode/crontab";
    output($file, map { 
	s|__freq__|$freq|g;
	$_;
    } cat_("__WIZ_HOME__/news_wizard/scripts/news.cron"));
    system("crontab -u news /etc/leafnode/crontab");
    10;
}

1;