]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - config/cfgroot/connscheduler-lib.pl
suricata: Change midstream policy to "pass-flow"
[people/pmueller/ipfire-2.x.git] / config / cfgroot / connscheduler-lib.pl
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 package CONNSCHED;
23
24 $CONNSCHED::maxprofiles = 5;
25
26 @CONNSCHED::weekdays = ( 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' );
27 @CONNSCHED::weekdays_pr = ( 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' );
28
29 %CONNSCHED::config;
30 $CONNSCHED::configfile = "/var/ipfire/connscheduler/connscheduler.conf";
31 &ReadConfig;
32
33
34 1;
35
36 #
37 # load the configuration file
38 #
39 sub ReadConfig
40 {
41 # datafileformat:
42 # active,action,profilenr,time,daystype,days,weekdays,,comment
43
44 @CONNSCHED::config = ();
45
46 my @tmpfile = ();
47 if ( open(FILE, "$configfile") )
48 {
49 @tmpfile = <FILE>;
50 close (FILE);
51 }
52
53 foreach $line ( @tmpfile )
54 {
55 chomp($line); # remove newline
56 my @temp = split(/\,/,$line,9);
57 if ( ($temp[0] ne 'on') && ($temp[0] ne 'off') ) { next; }
58
59 my $weekdays_pr = '';
60 for (my $i = 0; $i < 7; $i++)
61 {
62 if ( index($temp[6], $CONNSCHED::weekdays[$i]) != -1 )
63 {
64 $weekdays_pr .= "$Lang::tr{$CONNSCHED::weekdays_pr[$i]} ";
65 }
66 }
67
68 push @CONNSCHED::config, { ACTIVE => $temp[0], ACTION => $temp[1], PROFILENR => $temp[2], TIME => $temp[3],
69 DAYSTYPE => $temp[4], DAYS => $temp[5], WEEKDAYS => $temp[6], WEEKDAYS_PR => $weekdays_pr, COMMENT => $temp[8] };
70 }
71 }
72
73 #
74 # write the configuration file
75 #
76 sub WriteConfig
77 {
78 open(FILE, ">$configfile") or die 'hosts datafile error';
79
80 for my $i ( 0 .. $#CONNSCHED::config )
81 {
82 if ( ($CONNSCHED::config[$i]{'ACTIVE'} ne 'on') && ($CONNSCHED::config[$i]{'ACTIVE'} ne 'off') ) { next; }
83
84 print FILE "$CONNSCHED::config[$i]{'ACTIVE'},$CONNSCHED::config[$i]{'ACTION'},$CONNSCHED::config[$i]{'PROFILENR'},";
85 print FILE "$CONNSCHED::config[$i]{'TIME'},$CONNSCHED::config[$i]{'DAYSTYPE'},";
86 print FILE "$CONNSCHED::config[$i]{'DAYS'},$CONNSCHED::config[$i]{'WEEKDAYS'},,$CONNSCHED::config[$i]{'COMMENT'}\n";
87 }
88 close FILE;
89
90 &ReadConfig();
91 }