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