79bb3fb887e7315eae6d91ac6c75b74f13e0ee22
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / pakfire.cgi
1 #!/usr/bin/perl
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 ###############################################################################
21
22 use strict;
23
24 # enable only the following on debugging purpose
25 #use warnings;
26 #use CGI::Carp 'fatalsToBrowser';
27
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
31 require "/opt/pakfire/lib/functions.pl";
32
33 my %pakfiresettings=();
34 my $errormessage = '';
35 my %color = ();
36 my %mainsettings = ();
37
38 &Header::showhttpheaders();
39
40 $pakfiresettings{'ACTION'} = '';
41 $pakfiresettings{'VALID'} = '';
42
43 $pakfiresettings{'INSPAKS'} = '';
44 $pakfiresettings{'DELPAKS'} = '';
45 $pakfiresettings{'AUTOUPDATE'} = 'off';
46 $pakfiresettings{'AUTOUPGRADE'} = 'off';
47 $pakfiresettings{'UUID'} = 'on';
48
49 sub refreshpage{&Header::openbox( 'Waiting', 1, "<meta http-equiv='refresh' content='1;'>" );print "<center><img src='/images/clock.gif' alt='' /><br/><font color='red'>$Lang::tr{'pagerefresh'}</font></center>";&Header::closebox();}
50
51 &Header::getcgihash(\%pakfiresettings);
52
53 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
54 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
55
56 &Header::openpage($Lang::tr{'pakfire configuration'}, 1);
57 &Header::openbigbox('100%', 'left', '', $errormessage);
58
59 if ($pakfiresettings{'ACTION'} eq 'install'){
60 $pakfiresettings{'INSPAKS'} =~ s/\|/\ /g;
61 if ("$pakfiresettings{'FORCE'}" eq "on") {
62 my $command = "/usr/local/bin/pakfire install --non-interactive --no-colors $pakfiresettings{'INSPAKS'} &>/dev/null &";
63 system("$command");
64 } else {
65 &Header::openbox("100%", "center", "Abfrage");
66 my @output = `/usr/local/bin/pakfire resolvedeps --no-colors $pakfiresettings{'INSPAKS'}`;
67 print <<END;
68 <table><tr><td colspan='2'>$Lang::tr{'pakfire install package'}.$pakfiresettings{'INSPAKS'}.$Lang::tr{'pakfire possible dependency'}
69 <pre>
70 END
71 foreach (@output) {
72 $_ =~ s/\\e\[[0-1]\;[0-9]+m//g;
73 print "$_\n";
74 }
75 print <<END;
76 </pre>
77 <tr><td colspan='2'>$Lang::tr{'pakfire accept all'}
78 <tr><td colspan='2'>&nbsp;
79 <tr><td align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
80 <input type='hidden' name='INSPAKS' value='$pakfiresettings{'INSPAKS'}' />
81 <input type='hidden' name='FORCE' value='on' />
82 <input type='hidden' name='ACTION' value='install' />
83 <input type='image' alt='$Lang::tr{'install'}' src='/images/go-next.png' />
84 </form>
85 <td align='left'>
86 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
87 <input type='hidden' name='ACTION' value='' />
88 <input type='image' alt='$Lang::tr{'abort'}' src='/images/dialog-error.png' />
89 </form>
90 </table>
91 END
92 &Header::closebox();
93 &Header::closebigbox();
94 &Header::closepage();
95 exit;
96 }
97 } elsif ($pakfiresettings{'ACTION'} eq 'remove') {
98
99 $pakfiresettings{'DELPAKS'} =~ s/\|/\ /g;
100 if ("$pakfiresettings{'FORCE'}" eq "on") {
101 my $command = "/usr/local/bin/pakfire remove --non-interactive --no-colors $pakfiresettings{'DELPAKS'} &>/dev/null &";
102 system("$command");
103 } else {
104 &Header::openbox("100%", "center", "Abfrage");
105 my @output = `/usr/local/bin/pakfire resolvedeps --no-colors $pakfiresettings{'DELPAKS'}`;
106 print <<END;
107 <table><tr><td colspan='2'>$Lang::tr{'pakfire uninstall package'}.$pakfiresettings{'DELPAKS'}.$Lang::tr{'pakfire possible dependency'}
108 <pre>
109 END
110 foreach (@output) {
111 $_ =~ s/\\e\[[0-1]\;[0-9]+m//g;
112 print "$_\n";
113 }
114 print <<END;
115 </pre>
116 <tr><td colspan='2'>$Lang::tr{'pakfire accept all'}
117 <tr><td colspan='2'>&nbsp;
118 <tr><td align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
119 <input type='hidden' name='DELPAKS' value='$pakfiresettings{'DELPAKS'}' />
120 <input type='hidden' name='FORCE' value='on' />
121 <input type='hidden' name='ACTION' value='remove' />
122 <input type='image' alt='$Lang::tr{'uninstall'}' src='/images/go-next.png' />
123 </form>
124 <td align='left'>
125 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
126 <input type='hidden' name='ACTION' value='' />
127 <input type='image' alt='$Lang::tr{'abort'}' src='/images/dialog-error.png' />
128 </form>
129 </table>
130 END
131 &Header::closebox();
132 &Header::closebigbox();
133 &Header::closepage();
134 exit;
135 }
136
137 } elsif ($pakfiresettings{'ACTION'} eq 'update') {
138
139 system("/usr/local/bin/pakfire update --force --no-colors &>/dev/null &");
140
141 } elsif ($pakfiresettings{'ACTION'} eq 'upgrade') {
142 my $command = "/usr/local/bin/pakfire upgrade -y --no-colors &>/dev/null &";
143 system("$command");
144 } elsif ($pakfiresettings{'ACTION'} eq "$Lang::tr{'save'}") {
145
146 if ($pakfiresettings{'AUTOUPDATE'} eq 'on') {
147 system("/usr/local/bin/pakfire enable updates >/dev/null 2>&1");
148 } else {
149 system("/usr/local/bin/pakfire disable updates >/dev/null 2>&1");
150 }
151
152 if ($pakfiresettings{'AUTOUPGRADE'} eq 'on') {
153 system("/usr/local/bin/pakfire enable upgrades >/dev/null 2>&1");
154 } else {
155 system("/usr/local/bin/pakfire disable upgrades >/dev/null 2>&1");
156 }
157
158 &General::writehash("${General::swroot}/pakfire/settings", \%pakfiresettings);
159 }
160
161 &General::readhash("${General::swroot}/pakfire/settings", \%pakfiresettings);
162
163 my %selected=();
164 my %checked=();
165
166 $checked{'AUTOUPDATE'}{'off'} = '';
167 $checked{'AUTOUPDATE'}{'on'} = '';
168 $checked{'AUTOUPDATE'}{$pakfiresettings{'AUTOUPDATE'}} = "checked='checked'";
169 $checked{'AUTOUPGRADE'}{'off'} = '';
170 $checked{'AUTOUPGRADE'}{'on'} = '';
171 $checked{'AUTOUPGRADE'}{$pakfiresettings{'AUTOUPGRADE'}} = "checked='checked'";
172 $checked{'UUID'}{'off'} = '';
173 $checked{'UUID'}{'on'} = '';
174 $checked{'UUID'}{$pakfiresettings{'UUID'}} = "checked='checked'";
175
176 # DPC move error message to top so it is seen!
177 if ($errormessage) {
178 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
179 print "<font class='base'>$errormessage&nbsp;</font>\n";
180 &Header::closebox();
181 }
182
183 my $return = `pidof pakfire`;
184 chomp($return);
185 if ($return) {
186 &Header::openbox( 'Waiting', 1, "<meta http-equiv='refresh' content='10;'>" );
187 print <<END;
188 <table>
189 <tr><td>
190 <img src='/images/indicator.gif' alt='$Lang::tr{'aktiv'}' />&nbsp;
191 <td>
192 $Lang::tr{'pakfire working'}
193 <tr><td colspan='2' align='center'>
194 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
195 <input type='image' alt='$Lang::tr{'reload'}' src='/images/view-refresh.png' />
196 </form>
197 <tr><td colspan='2' align='left'><pre>
198 END
199 my @output = `grep pakfire /var/log/messages | tail -20`;
200 foreach (@output) {
201 print "$_";
202 }
203 print <<END;
204 </pre>
205 </table>
206 END
207 &Header::closebox();
208 &Header::closebigbox();
209 &Header::closepage();
210 exit;
211 refreshpage();
212 }
213
214 my $core_release = `cat /opt/pakfire/db/core/mine 2>/dev/null`;
215 chomp($core_release);
216 my $core_update_age = &General::age("/opt/pakfire/db/core/mine");
217 my $corelist_update_age = &General::age("/opt/pakfire/db/lists/core-list.db");
218 my $server_update_age = &General::age("/opt/pakfire/db/lists/server-list.db");
219 my $packages_update_age = &General::age("/opt/pakfire/db/lists/packages_list.db");
220
221 &Header::openbox("100%", "center", "Pakfire");
222
223 print <<END;
224 <table width='95%' cellpadding='5' >
225 <tr><td width="50%" bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'pakfire system state'}:</b>
226 <td width="50%">
227 <tr><td align="center">$Lang::tr{'pakfire core update level'}: $core_release<hr />
228 $Lang::tr{'pakfire last update'} $core_update_age ago<br />
229 $Lang::tr{'pakfire last serverlist update'} $server_update_age ago<br />
230 $Lang::tr{'pakfire last core list update'} $corelist_update_age ago<br />
231 $Lang::tr{'pakfire last package update'} $packages_update_age ago
232 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
233 <input type='hidden' name='ACTION' value='update' />
234 <input type='submit' value='Liste aktualisieren' /><br />
235 </form>
236 <td align="center">
237 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
238 <select name="UPDPAKS" size="5" disabled>
239 END
240 &Pakfire::dblist("upgrade", "forweb");
241 print <<END;
242 </select>
243 <br />
244 <input type='hidden' name='ACTION' value='upgrade' />
245 <input type='image' alt='$Lang::tr{'upgrade'}' src='/images/document-save.png' />
246 </form>
247
248 <tr><td colspan="2"><!-- Just an empty line -->&nbsp;
249 <tr><td bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'pakfire available addons'}</b>
250 <td bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'pakfire installed addons'}</b>
251 <tr><td align="center">
252 <p>$Lang::tr{'pakfire install description'}</p>
253 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
254 <select name="INSPAKS" size="10" multiple>
255 END
256 &Pakfire::dblist("notinstalled", "forweb");
257
258 print <<END;
259 </select>
260 <br />
261 <input type='hidden' name='ACTION' value='install' />
262 <input type='image' alt='$Lang::tr{'install'}' src='/images/list-add.png' />
263 </form>
264
265 <td align="center">
266 <p>$Lang::tr{'pakfire uninstall description'}</p>
267 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
268 <select name="DELPAKS" size="10" multiple>
269 END
270
271 &Pakfire::dblist("installed", "forweb");
272
273 print <<END;
274 </select>
275 <br />
276 <input type='hidden' name='ACTION' value='remove' />
277 <input type='image' alt='$Lang::tr{'remove'}' src='/images/list-remove.png' />
278 </form>
279 </table>
280 END
281
282 &Header::closebox();
283 &Header::openbox("100%", "center", "$Lang::tr{'settings'}");
284
285 print <<END;
286 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
287 <table width='95%'>
288 <tr><td colspan='2' bgcolor='$color{'color20'}'><b>$Lang::tr{'basic options'}</b></td></tr>
289 <tr><td align='left' width='40%'>$Lang::tr{'pakfire update daily'}</td><td align="left">
290 on <input type='radio' name='AUTOUPDATE' value='on' $checked{'AUTOUPDATE'}{'on'} />/
291 <input type='radio' name='AUTOUPDATE' value='off' $checked{'AUTOUPDATE'}{'off'} /> off </td></tr>
292 <tr><td align='left' width='40%'>$Lang::tr{'pakfire core update auto'}</td><td align="left">
293 on <input type='radio' name='AUTOUPGRADE' value='on' $checked{'AUTOUPGRADE'}{'on'} />/
294 <input type='radio' name='AUTOUPGRADE' value='off' $checked{'AUTOUPGRADE'}{'off'} /> off </td></tr>
295 <tr><td align='left' width='40%'>$Lang::tr{'pakfire register'}</td><td align="left">
296 on <input type='radio' name='UUID' value='on' $checked{'UUID'}{'on'} />/
297 <input type='radio' name='UUID' value='off' $checked{'UUID'}{'off'} /> off </td></tr>
298 <tr><td width='100%' colspan="2" align="center"><input type="submit" name="ACTION" value="$Lang::tr{'save'}" /></td></tr>
299 </table>
300 </form>
301 END
302
303 &Header::closebox();
304 &Header::closebigbox();
305 &Header::closepage();