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