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