~ubuntu-branches/ubuntu/precise/knemo/precise

« back to all changes in this revision

Viewing changes to src/kconf_update/knemo-0.7.0-misc.pl

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-02-22 16:36:22 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20110222163622-d8i62gy1stn7tydv
Tags: 0.7.0-0ubuntu1
* New upstream release.
* Switch to source format 3.0 (quilt).
* Make knemo depend on libqt4-sql-sqlite.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
 
 
3
# Convert to the new statistics and traffic warning rules
 
4
 
 
5
use strict;
 
6
 
 
7
my $currentGroup = "";
 
8
my %configFile;
 
9
while ( <> ) {
 
10
    chomp;
 
11
    next if ( /^$/ );
 
12
    next if ( /^\#/ );
 
13
    if ( /^\[/ ) {
 
14
        $currentGroup = $_;
 
15
        next;
 
16
    } elsif ( $currentGroup ne "" ) {
 
17
        my ($key,$value) = split /=/;
 
18
        $configFile{$currentGroup}{$key}=$value;
 
19
    }
 
20
}
 
21
 
 
22
my @ifaceGroups = grep { /^\[Interface_\S+\]/ } keys %configFile;
 
23
 
 
24
# Make sure we don't replace rules if we run this twice
 
25
my $doStats=1;
 
26
my $doWarn=1;
 
27
if ( grep { /^\[StatsRule_/ } keys %configFile ) {
 
28
    $doStats=0;
 
29
}
 
30
if ( grep { /^\[WarnRule_/ } keys %configFile ) {
 
31
    $doWarn=0;
 
32
}
 
33
 
 
34
foreach my $ifaceGroup (@ifaceGroups) {
 
35
 
 
36
    my $iface;
 
37
    if ( $ifaceGroup =~ /_(.+)\]$/ ) {
 
38
        $iface = $1;
 
39
    }
 
40
 
 
41
    # change the iconset for this interface
 
42
    print "# DELETE ${ifaceGroup}BillingMonths\n";
 
43
    print "# DELETE ${ifaceGroup}BillingStart\n";
 
44
    print "# DELETE ${ifaceGroup}CustomBilling\n";
 
45
    print "# DELETE ${ifaceGroup}BillingWarnRxTx\n";
 
46
    print "# DELETE ${ifaceGroup}BillingWarnThreshold\n";
 
47
    print "# DELETE ${ifaceGroup}BillingWarnType\n";
 
48
    print "# DELETE ${ifaceGroup}BillingWarnUnits\n";
 
49
 
 
50
    if ( $doStats ) {
 
51
        my $statsCount=0;
 
52
        my $customBilling = $configFile{$ifaceGroup}{'CustomBilling'};
 
53
        if ( $customBilling ) {
 
54
            my $billingStart = $configFile{$ifaceGroup}{'BillingStart'};
 
55
            my $billingMonths = $configFile{$ifaceGroup}{'BillingMonths'};
 
56
 
 
57
            print "[StatsRule_$iface #0]\nPeriodCount=$billingMonths\n";
 
58
            print "[StatsRule_$iface #0]\nStartDate=$billingStart\n";
 
59
            $statsCount++;
 
60
        }
 
61
        print "${ifaceGroup}\nStatsRules=${statsCount}\n";
 
62
    }
 
63
 
 
64
    if ( $doWarn ) {
 
65
        my $warnCount=0;
 
66
        my $warnThreshold = $configFile{$ifaceGroup}{'BillingWarnThreshold'};
 
67
        if ( $warnThreshold ) {
 
68
            my $warnDirection = $configFile{$ifaceGroup}{'BillingWarnRxTx'};
 
69
            my $trafficUnits = $configFile{$ifaceGroup}{'BillingWarnUnits'};
 
70
            my $warnUnits = $configFile{$ifaceGroup}{'BillingWarnType'};
 
71
 
 
72
            my $periodCount = 1;
 
73
            my $periodUnits = 0;
 
74
 
 
75
            if ( 0 == $warnUnits ) {
 
76
                $periodUnits = 0;
 
77
            }
 
78
            elsif ( 1 == $warnUnits )
 
79
            {
 
80
                $periodUnits = 1;
 
81
            }
 
82
            elsif ( 2 == $warnUnits ) {
 
83
                if ( $doStats ) {
 
84
                    # if custom stats rule then warn per billing period
 
85
                    $periodUnits = 4;
 
86
                }
 
87
                else {
 
88
                    # otherwise it's per month
 
89
                    $periodUnits = 3;
 
90
                }
 
91
            }
 
92
            elsif ( 3 == $warnUnits ) {
 
93
                $periodUnits = 0;
 
94
                $periodCount = 24;
 
95
            }
 
96
            elsif ( 4 == $warnUnits ) {
 
97
                $periodUnits = 1;
 
98
                $periodCount = 7;
 
99
            }
 
100
            elsif ( 5 == $warnUnits ) {
 
101
                $periodUnits = 1;
 
102
                $periodCount = 30
 
103
            }
 
104
 
 
105
            if ( $warnDirection ) {
 
106
                $warnDirection = 2;
 
107
            }
 
108
            else
 
109
            {
 
110
                $warnDirection = 0;
 
111
            }
 
112
 
 
113
            print "[WarnRule_$iface #0]\nThreshold=$warnThreshold\n";
 
114
            print "[WarnRule_$iface #0]\nTrafficDirection=$warnDirection\n";
 
115
            print "[WarnRule_$iface #0]\nTrafficUnits=$trafficUnits\n";
 
116
            print "[WarnRule_$iface #0]\nPeriodCount=$periodCount\n";
 
117
            print "[WarnRule_$iface #0]\nPeriodUnits=$periodUnits\n";
 
118
 
 
119
            $warnCount++;
 
120
        }
 
121
 
 
122
        print "${ifaceGroup}\nWarnRules=${warnCount}\n";
 
123
    }
 
124
}