]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - config/cfgroot/connscheduler-lib.pl
Merge remote-tracking branch 'stevee/wlan-client' into next
[people/teissler/ipfire-2.x.git] / config / cfgroot / connscheduler-lib.pl
CommitLineData
4e565351
MT
1#!/usr/bin/perl
2#
3# Library file for Connection Scheduler AddOn
4#
5# This code is distributed under the terms of the GPL
6#
7
8package CONNSCHED;
9
10$CONNSCHED::maxprofiles = 5;
11
12@CONNSCHED::weekdays = ( 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' );
13@CONNSCHED::weekdays_pr = ( 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' );
14
15%CONNSCHED::config;
16$CONNSCHED::configfile = "/var/ipfire/connscheduler/connscheduler.conf";
17&ReadConfig;
18
19
201;
21
22#
23# load the configuration file
24#
25sub ReadConfig
26{
27 # datafileformat:
28 # active,action,profilenr,time,daystype,days,weekdays,,comment
29
30 @CONNSCHED::config = ();
31
32 my @tmpfile = ();
33 if ( open(FILE, "$configfile") )
34 {
35 @tmpfile = <FILE>;
36 close (FILE);
37 }
38
39 foreach $line ( @tmpfile )
40 {
41 chomp($line); # remove newline
42 my @temp = split(/\,/,$line,9);
43 if ( ($temp[0] ne 'on') && ($temp[0] ne 'off') ) { next; }
44
45 my $weekdays_pr = '';
46 for (my $i = 0; $i < 7; $i++)
47 {
48 if ( index($temp[6], $CONNSCHED::weekdays[$i]) != -1 )
49 {
50 $weekdays_pr .= "$Lang::tr{$CONNSCHED::weekdays_pr[$i]} ";
51 }
52 }
53
54 push @CONNSCHED::config, { ACTIVE => $temp[0], ACTION => $temp[1], PROFILENR => $temp[2], TIME => $temp[3],
55 DAYSTYPE => $temp[4], DAYS => $temp[5], WEEKDAYS => $temp[6], WEEKDAYS_PR => $weekdays_pr, COMMENT => $temp[8] };
56 }
57}
58
59#
60# write the configuration file
61#
62sub WriteConfig
63{
64 open(FILE, ">$configfile") or die 'hosts datafile error';
65
66 for my $i ( 0 .. $#CONNSCHED::config )
67 {
68 if ( ($CONNSCHED::config[$i]{'ACTIVE'} ne 'on') && ($CONNSCHED::config[$i]{'ACTIVE'} ne 'off') ) { next; }
69
70 print FILE "$CONNSCHED::config[$i]{'ACTIVE'},$CONNSCHED::config[$i]{'ACTION'},$CONNSCHED::config[$i]{'PROFILENR'},";
71 print FILE "$CONNSCHED::config[$i]{'TIME'},$CONNSCHED::config[$i]{'DAYSTYPE'},";
72 print FILE "$CONNSCHED::config[$i]{'DAYS'},$CONNSCHED::config[$i]{'WEEKDAYS'},,$CONNSCHED::config[$i]{'COMMENT'}\n";
73 }
74 close FILE;
75
76 &ReadConfig();
77}