]>
Commit | Line | Data |
---|---|---|
cf29614f | 1 | #!/usr/bin/perl |
70df8302 MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2007 Michael Tremer & Christian Schmidt # | |
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 | ############################################################################### | |
cf29614f CS |
21 | |
22 | require '/var/ipfire/general-functions.pl'; | |
23 | require "${General::swroot}/lang.pl"; | |
24 | require "${General::swroot}/header.pl"; | |
e0800c21 | 25 | use File::Path; |
cf29614f CS |
26 | my $debug = 1; |
27 | my @include = ""; | |
28 | my ($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat, $Jahr, $Wochentag, $Jahrestag, $Sommerzeit) = localtime(time); | |
29 | $Jahr = $Jahr + 1900;$Monat = $Monat + 1; | |
30 | $Monat = sprintf("%02d", $Monat); | |
31 | $Monatstag = sprintf("%02d", $Monatstag); | |
32 | $Stunden = sprintf("%02d", $Stunden); | |
33 | $Minuten = sprintf("%02d", $Minuten); | |
34 | ||
f31d3c1f | 35 | if (($ARGV[0] eq 'include') || ($ARGV[0] eq 'iso')) { |
8e8bbd9d | 36 | &createinclude; |
d39a5cb6 CS |
37 | my @files = `find / -name *.log* 2>/dev/null`; |
38 | foreach (@files){ | |
39 | push(@include,$_); | |
40 | } | |
41 | my @files = `find /var/log/ -name *messages* 2>/dev/null`; | |
8e8bbd9d CS |
42 | foreach (@files){ |
43 | push(@include,$_); | |
44 | } | |
45 | open(DATEI, ">/tmp/include") || die "Could not save temp include file"; | |
46 | print DATEI @include; | |
d39a5cb6 | 47 | print "/var/log/messages"; |
8e8bbd9d | 48 | close(DATEI); |
cb13f50d | 49 | system("tar -cvzf /var/ipfire/backup/$Jahr$Monat$Monatstag-$Stunden$Minuten.ipf --files-from='/tmp/include' --exclude-from='/var/ipfire/backup/exclude' --files-from='/var/ipfire/backup/include.user' --exclude-from='/var/ipfire/backup/exclude.user'"); |
8e8bbd9d | 50 | system("rm /tmp/include"); |
f31d3c1f DG |
51 | if ($ARGV[0] eq 'iso') { |
52 | system("/usr/local/bin/backupiso $Jahr$Monat$Monatstag-$Stunden$Minuten &"); | |
53 | } | |
8e8bbd9d | 54 | } |
69addbb8 | 55 | elsif ($ARGV[0] eq 'exclude') { |
cf29614f CS |
56 | &createinclude; |
57 | open(DATEI, ">/tmp/include") || die "Could not save temp include file"; | |
58 | print DATEI @include; | |
59 | close(DATEI); | |
cb13f50d | 60 | system("tar -cvzf /var/ipfire/backup/$Jahr$Monat$Monatstag-$Stunden$Minuten.ipf --files-from='/tmp/include' --exclude-from='/var/ipfire/backup/exclude' --files-from='/var/ipfire/backup/include.user' --exclude-from='/var/ipfire/backup/exclude.user'"); |
cf29614f CS |
61 | system("rm /tmp/include"); |
62 | } | |
69addbb8 | 63 | elsif ($ARGV[0] eq 'restore') { |
c0faa0ef | 64 | system("cd / && tar -xvz -p -f /tmp/restore.ipf"); |
c490c6e8 AM |
65 | #Here some converter scripts to correct old Backups (before core 65) |
66 | system("/usr/sbin/ovpn-ccd-convert"); | |
a60dbb4b | 67 | #OUTGOINGFW CONVERTER |
9edb1d7a AM |
68 | if( -d "${General::swroot}/outgoing"){ |
69 | if( -f "${General::swroot}/forward/config" ){ | |
70 | unlink("${General::swroot}/forward/config"); | |
71 | system("touch ${General::swroot}/forward/config"); | |
72 | chown 99,99,"${General::swroot}/forward/config"; | |
73 | } | |
a60dbb4b AM |
74 | if( -f "${General::swroot}/forward/outgoing" ){ |
75 | unlink("${General::swroot}/forward/outgoing"); | |
76 | system("touch ${General::swroot}/forward/outgoing"); | |
77 | chown 99,99,"${General::swroot}/forward/outgoing"; | |
78 | } | |
79 | unlink("${General::swroot}/fwhosts/*"); | |
80 | system("touch ${General::swroot}/fwhosts/customgroups"); | |
81 | system("touch ${General::swroot}/fwhosts/customhosts"); | |
82 | system("touch ${General::swroot}/fwhosts/customnetworks"); | |
83 | system("touch ${General::swroot}/fwhosts/customservicegrp"); | |
84 | system("touch ${General::swroot}/fwhosts/customservices"); | |
85 | chown 99,99,"${General::swroot}/fwhosts/*"; | |
86 | #START CONVERTER "OUTGOINGFW" | |
99e698d0 | 87 | system("/usr/sbin/convert-outgoingfw"); |
9edb1d7a | 88 | rmtree("${General::swroot}/outgoing"); |
e0800c21 | 89 | } |
a60dbb4b | 90 | #XTACCESS CONVERTER |
9edb1d7a | 91 | if( -d "${General::swroot}/xtaccess"){ |
a60dbb4b AM |
92 | if( -f "${General::swroot}/forward/input" ){ |
93 | unlink("${General::swroot}/forward/input"); | |
94 | system("touch ${General::swroot}/forward/input"); | |
95 | chown 99,99,"${General::swroot}/forward/input"; | |
96 | } | |
97 | #START CONVERTER "XTACCESS" | |
99e698d0 | 98 | system("/usr/sbin/convert-xtaccess"); |
9edb1d7a | 99 | rmtree("${General::swroot}/xtaccess"); |
e0800c21 | 100 | } |
a60dbb4b AM |
101 | #DMZ-HOLES CONVERTER |
102 | if( -d "${General::swroot}/dmz-holes"){ | |
103 | if( -f "${General::swroot}/forward/dmz" ){ | |
104 | unlink("${General::swroot}/forward/dmz"); | |
105 | system("touch ${General::swroot}/forward/dmz"); | |
106 | chown 99,99,"${General::swroot}/forward/dmz"; | |
107 | } | |
108 | #START CONVERTER "DMZ-HOLES" | |
109 | system("/usr/sbin/convert-dmz"); | |
110 | rmtree("${General::swroot}/xtaccess"); | |
111 | } | |
112 | #PORTFORWARD CONVERTER | |
113 | if( -d "${General::swroot}/portfw"){ | |
114 | if( -f "${General::swroot}/forward/nat" ){ | |
115 | unlink("${General::swroot}/forward/nat"); | |
116 | system("touch ${General::swroot}/forward/nat"); | |
117 | chown 99,99,"${General::swroot}/forward/nat"; | |
118 | } | |
119 | #START CONVERTER "PORTFW" | |
120 | system("/usr/sbin/convert-portfw"); | |
121 | rmtree("${General::swroot}/portfw"); | |
122 | } | |
123 | system("/usr/local/bin/forwardfwctrl"); | |
e0800c21 | 124 | } |
5ad5a6bc | 125 | elsif ($ARGV[0] eq 'restoreaddon') { |
b8e5a9c5 | 126 | if ( -e "/tmp/$ARGV[1]" ){system("mv /tmp/$ARGV[1] /var/ipfire/backup/addons/backup/$ARGV[1]");} |
c0faa0ef | 127 | system("cd / && tar -xvz -p -f /var/ipfire/backup/addons/backup/$ARGV[1]"); |
5ad5a6bc | 128 | } |
69addbb8 | 129 | elsif ($ARGV[0] eq 'cli') { |
75abe7e9 | 130 | system("tar -cvzf /var/ipfire/backup/$Jahr$Monat$Monatstag-$Stunden$Minuten-$ARGV[1].ipf --files-from='$ARGV[2]' --exclude-from='$ARGV[3]'"); |
cf29614f | 131 | } |
901a50cf CS |
132 | elsif ($ARGV[0] eq 'addonbackup') { |
133 | system("tar -cvzf /var/ipfire/backup/addons/backup/$ARGV[1].ipf --files-from='/var/ipfire/backup/addons/includes/$ARGV[1]'"); | |
134 | } | |
69addbb8 CS |
135 | elsif ($ARGV[0] =~ /ipf$/ ) { |
136 | system("rm /var/ipfire/backup/$ARGV[0]"); | |
8e8bbd9d | 137 | } |
b90a7e56 DG |
138 | elsif ($ARGV[0] =~ /iso$/ ) { |
139 | system("rm /var/tmp/backupiso/$ARGV[0]"); | |
140 | } | |
69addbb8 CS |
141 | elsif ($ARGV[0] eq '') { |
142 | printf "No argument given, please use <include><exclude><cli>\n" | |
8e8bbd9d | 143 | } |
a609bfb0 | 144 | elsif ($ARGV[0] eq 'makedirs') { |
2a1f6aa7 CS |
145 | system("mkdir -p /var/ipfire/backup/addons"); |
146 | system("mkdir -p /var/ipfire/backup/addons/backup"); | |
147 | system("mkdir -p /var/ipfire/backup/addons/includes"); | |
a609bfb0 | 148 | } |
8e8bbd9d | 149 | |
cf29614f CS |
150 | sub createinclude(){ |
151 | ||
152 | open(DATEI, "<${General::swroot}/backup/include") || die "Can not open include file"; | |
153 | my @Zeilen = <DATEI>; | |
154 | close(DATEI); | |
155 | ||
156 | foreach (@Zeilen){ | |
157 | if ( $_ =~ /\*/){ | |
158 | my @files = `ls $_`; | |
159 | foreach (@files){ | |
160 | push(@include,$_); | |
8e8bbd9d CS |
161 | } |
162 | } | |
cf29614f CS |
163 | else {push(@include,$_);} |
164 | } | |
165 | } |