]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - config/updxlrator/updxlrator-lib.pl
Fix dns dhcp client helper script.
[people/pmueller/ipfire-2.x.git] / config / updxlrator / updxlrator-lib.pl
1 #!/usr/bin/perl
2 #
3 # This code is distributed under the terms of the GPL
4 #
5 # (c) 2006-2008 marco.s - http://update-accelerator.advproxy.net
6 #
7 # Portions (c) 2008 by dotzball - http://www.blockouttraffic.de
8 #
9 # dotzball 2008-05-27:
10 # move functions from all local files to one library file
11 #
12 # $Id: updxlrator-lib.pl,v 1.1 2008/11/29 00:00:00 marco.s Exp $
13 #
14
15 package UPDXLT;
16
17 use strict;
18
19 $|=1; # line buffering
20
21 $UPDXLT::swroot='/var/ipfire';
22 $UPDXLT::apphome="/var/ipfire/updatexlrator";
23
24 $UPDXLT::sfUnknown = "0";
25 $UPDXLT::sfOk = "1";
26 $UPDXLT::sfOutdated = "2";
27 $UPDXLT::sfNoSource = "3";
28
29 $UPDXLT::wget="/usr/bin/wget";
30 $UPDXLT::useragent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
31
32 # -------------------------------------------------------------------
33
34 sub diskfree
35 {
36 open(DF,"/bin/df --block-size=1 $_[0]|");
37 my @dfdata = <DF>;
38 close DF;
39 shift(@dfdata);
40 chomp(@dfdata);
41 my $dfstr = join(' ',@dfdata);
42 my ($device,$size,$used,$free,$percent,$mount) = split(' ',$dfstr);
43 if ($free =~ m/^(\d+)$/)
44 {
45 return $free;
46 }
47 }
48
49 # -------------------------------------------------------------------
50
51 sub diskusage
52 {
53 open(DF,"/bin/df $_[0]|");
54 my @dfdata = <DF>;
55 close DF;
56 shift(@dfdata);
57 chomp(@dfdata);
58 my $dfstr = join(' ',@dfdata);
59 my ($device,$size,$used,$free,$percent,$mount) = split(' ',$dfstr);
60 if ($percent =~ m/^(\d+)%$/)
61 {
62 $percent =~ s/%$//;
63 return $percent;
64 }
65 }
66
67 # -------------------------------------------------------------------
68
69 # dotzball (2008-05-26): Copied from IPCop general-functions.pl
70 sub writehash
71 {
72 my $filename = $_[0];
73 my $hash = $_[1];
74 my ($var, $val);
75
76 # write cgi vars to the file.
77 open(FILE, ">${filename}") or die "Unable to write file $filename";
78 flock FILE, 2;
79 foreach $var (keys %$hash)
80 {
81 $val = $hash->{$var};
82 # Darren Critchley Jan 17, 2003 added the following because when submitting with a graphic, the x and y
83 # location of the mouse are submitted as well, this was being written to the settings file causing
84 # some serious grief! This skips the variable.x and variable.y
85 if (!($var =~ /(.x|.y)$/)) {
86 if ($val =~ / /) {
87 $val = "\'$val\'"; }
88 if (!($var =~ /^ACTION/)) {
89 print FILE "${var}=${val}\n"; }
90 }
91 }
92 close FILE;
93 }
94
95 # -------------------------------------------------------------------
96
97 sub readhash
98 {
99 my $filename = $_[0];
100 my $hash = $_[1];
101 my ($var, $val);
102
103 if (-e $filename)
104 {
105 open(FILE, $filename) or die "Unable to read file $filename";
106 while (<FILE>)
107 {
108 chop;
109 ($var, $val) = split /=/, $_, 2;
110 if ($var)
111 {
112 $val =~ s/^\'//g;
113 $val =~ s/\'$//g;
114
115 # Untaint variables read from hash
116 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
117 $val =~ /([\w\W]*)/; $val = $1;
118 $hash->{$var} = $val;
119 }
120 }
121 close FILE;
122 }
123 }
124
125 # -------------------------------------------------------------------
126
127 sub getmtime
128 {
129 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($_[0]);
130
131 return $mtime;
132 }
133
134 # -------------------------------------------------------------------
135
136 sub setcachestatus
137 {
138 open (FILE,">$_[0]");
139 print FILE "$_[1]\n";
140 close FILE;
141 }
142
143 # -------------------------------------------------------------------
144