d62be482f4335f67163e78c71baaf750485ea693
[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{'UUID'} = 'on';
36
37 system("/usr/local/bin/pakfire update >/dev/null") if not -e "/opt/pakfire/db/lists/packages_list.db";
38
39 &Header::getcgihash(\%pakfiresettings);
40 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
41 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
42
43 &Header::openpage($Lang::tr{'pakfire configuration'}, 1);
44 &Header::openbigbox('100%', 'left', '', $errormessage);
45
46 if ($pakfiresettings{'ACTION'} eq 'install'){
47         $pakfiresettings{'INSPAKS'} =~ s/\|/\ /g;
48         if ("$pakfiresettings{'FORCE'}" eq "on") {
49                 my $command = "/usr/local/bin/pakfire install --non-interactive --no-colors $pakfiresettings{'INSPAKS'} &>/dev/null &";
50                 system("$command");
51                 sleep(2);
52         } else {
53                 &Header::openbox("100%", "center", "Abfrage");
54         my @output = `/usr/local/bin/pakfire resolvedeps --no-colors $pakfiresettings{'INSPAKS'}`;
55                 print <<END;
56                 <table><tr><td colspan='2'>$Lang::tr{'pakfire install package'}.$pakfiresettings{'INSPAKS'}.$Lang::tr{'pakfire possible dependency'}
57                 <pre>           
58 END
59                 foreach (@output) {
60                         print "$_\n";
61                 }
62                 print <<END;
63                 </pre>
64                 <tr><td colspan='2'>$Lang::tr{'pakfire accept all'}
65                 <tr><td colspan='2'>&nbsp;
66                 <tr><td align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
67                                                         <input type='hidden' name='INSPAKS' value='$pakfiresettings{'INSPAKS'}' />
68                                                         <input type='hidden' name='FORCE' value='on' />
69                                                         <input type='hidden' name='ACTION' value='install' />
70                                                         <input type='image' alt='$Lang::tr{'install'}' src='/images/go-next.png' />
71                                                 </form>
72                                 <td align='left'>
73                                                 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
74                                                         <input type='hidden' name='ACTION' value='' />
75                                                         <input type='image' alt='$Lang::tr{'abort'}' src='/images/dialog-error.png' />
76                                                 </form>
77                 </table>
78 END
79                 &Header::closebox();
80                 &Header::closebigbox();
81                 &Header::closepage();
82                 exit;
83         }
84 } elsif ($pakfiresettings{'ACTION'} eq 'remove') {
85
86         $pakfiresettings{'DELPAKS'} =~ s/\|/\ /g;
87         if ("$pakfiresettings{'FORCE'}" eq "on") {
88                 my $command = "/usr/local/bin/pakfire remove --non-interactive --no-colors $pakfiresettings{'DELPAKS'} &>/dev/null &";
89                 system("$command");
90                 sleep(2);
91         } else {
92                 &Header::openbox("100%", "center", "Abfrage");
93         my @output = `/usr/local/bin/pakfire resolvedeps --no-colors $pakfiresettings{'DELPAKS'}`;
94                 print <<END;
95                 <table><tr><td colspan='2'>$Lang::tr{'pakfire uninstall package'}.$pakfiresettings{'DELPAKS'}.$Lang::tr{'pakfire possible dependency'}
96                 <pre>           
97 END
98                 foreach (@output) {
99                         print "$_\n";
100                 }
101                 print <<END;
102                 </pre>
103                 <tr><td colspan='2'>$Lang::tr{'pakfire accept all'}
104                 <tr><td colspan='2'>&nbsp;
105                 <tr><td align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
106                                                         <input type='hidden' name='DELPAKS' value='$pakfiresettings{'DELPAKS'}' />
107                                                         <input type='hidden' name='FORCE' value='on' />
108                                                         <input type='hidden' name='ACTION' value='remove' />
109                                                         <input type='image' alt='$Lang::tr{'uninstall'}' src='/images/go-next.png' />
110                                                 </form>
111                                 <td align='left'>
112                                                 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
113                                                         <input type='hidden' name='ACTION' value='' />
114                                                         <input type='image' alt='$Lang::tr{'abort'}' src='/images/dialog-error.png' />
115                                                 </form>
116                 </table>
117 END
118                 &Header::closebox();
119                 &Header::closebigbox();
120                 &Header::closepage();
121                 exit;
122         }
123
124 } elsif ($pakfiresettings{'ACTION'} eq 'update') {
125         
126         system("/usr/local/bin/pakfire update --force --no-colors");
127
128 } elsif ($pakfiresettings{'ACTION'} eq 'upgrade') {
129         
130         system("/usr/local/bin/pakfire upgrade -y --no-colors");
131         
132 } elsif ($pakfiresettings{'ACTION'} eq "$Lang::tr{'save'}") {
133
134         &General::writehash("${General::swroot}/pakfire/settings", \%pakfiresettings);
135
136 }
137
138 &General::readhash("${General::swroot}/pakfire/settings", \%pakfiresettings);
139
140 my %selected=();
141 my %checked=();
142
143 $checked{'AUTOUPDATE'}{'off'} = '';
144 $checked{'AUTOUPDATE'}{'on'} = '';
145 $checked{'AUTOUPDATE'}{$pakfiresettings{'AUTOUPDATE'}} = "checked='checked'";
146 $checked{'UUID'}{'off'} = '';
147 $checked{'UUID'}{'on'} = '';
148 $checked{'UUID'}{$pakfiresettings{'UUID'}} = "checked='checked'";
149
150 # DPC move error message to top so it is seen!
151 if ($errormessage) {
152         &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
153         print "<font class='base'>$errormessage&nbsp;</font>\n";
154         &Header::closebox();
155 }
156
157 my $return = `pidof pakfire`;
158 chomp($return);
159 if ($return) {
160         &Header::openbox( 'Waiting', 1, "<meta http-equiv='refresh' content='10;'>" );
161         print <<END;
162         <table>
163                 <tr><td>
164                                 <img src='/images/indicator.gif' alt='$Lang::tr{'aktiv'}' />&nbsp;
165                         <td>
166                                 $Lang::tr{'pakfire working'}
167                 <tr><td colspan='2' align='center'>
168                         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
169                                 <input type='image' alt='$Lang::tr{'reload'}' src='/images/view-refresh.png' />
170                         </form>
171                 <tr><td colspan='2' align='left'><pre>
172 END
173         my @output = `tail -20 /var/log/pakfire.log`;
174         foreach (@output) {
175                 print "$_";
176         }
177         print <<END;
178                         </pre>
179                 </table>
180 END
181         &Header::closebox();
182         &Header::closebigbox();
183         &Header::closepage();
184         exit;
185 }
186
187 &Header::openbox("100%", "center", "Pakfire");
188
189 print <<END;
190         <table width='100%'>
191                 <tr><td bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'pakfire available addons'}</b></td><td bgcolor='$color{'color20'}'></td><td bgcolor='$color{'color20'}' align="center"><b>$Lang::tr{'pakfire installed addons'}</b>
192                 <tr><td width='40%' align="center">
193                         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
194                                 <select name="INSPAKS" size="10" multiple>
195 END
196                         &Pakfire::dblist("notinstalled", "forweb");
197                 
198 print <<END;
199                                 </select>
200                 </td>
201                 <td width='20%' align="center">
202                                 <input type='hidden' name='ACTION' value='install' />
203                                 <input type='image' alt='$Lang::tr{'install'}' src='/images/list-add.png' />
204                         </form><br />
205                         
206                         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
207                                 <input type='hidden' name='ACTION' value='update' />
208                                 <input type='submit' value='Liste aktualisieren' /><br />
209                         </form>
210                         
211                         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
212                                 <input type='hidden' name='ACTION' value='remove' />
213                                 <input type='image' alt='$Lang::tr{'remove'}' src='/images/list-remove.png' />
214                 </td>
215                 <td width='40%' align="center">
216                         <select name="DELPAKS" size="10" multiple>
217 END
218
219                         &Pakfire::dblist("installed", "forweb");
220
221 print <<END;
222                 </select>
223         </table></form>
224         <br />
225         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
226         <table width='100%'>
227                 <tr><td colspan='3' bgcolor='$color{'color20'}'><b>$Lang::tr{'pakfire updates'}</b></br>
228                 <tr><td width='20%'>&nbsp;<td width='60%' align='center'>
229                         <select name="UPDPAKS" size="5" disabled>
230 END
231
232                         &Pakfire::dblist("upgrade", "forweb");
233
234 print <<END;
235                         </select>
236                 <td width='20%' align='center' valign='middle'><input type='hidden' name='ACTION' value='upgrade' />
237                         <input type='image' alt='$Lang::tr{'upgrade'}' src='/images/document-save.png' />
238         </table></form>
239         <br />
240         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
241                 <table width='100%'>
242                         <tr><td colspan='4' bgcolor='$color{'color20'}'><b>$Lang::tr{'basic options'}</b></br>
243                         <tr><td width='40%' align="right">$Lang::tr{'pakfire update daily'}
244                                         <td width='10%' align="left"><input type="checkbox" name="AUTOUPDATE" $checked{'AUTOUPDATE'}{'on'} />
245                                         <td width='40%' align="right">$Lang::tr{'pakfire register'} 
246                                         <td width='10%' align="left"><input type="checkbox" name="UUID" $checked{'UUID'}{'on'} />
247                         <tr><td width='100%' colspan="4" align="center"><input type="submit" name="ACTION" value="$Lang::tr{'save'}" />
248                 </table>
249         </form>
250 END
251
252 &Header::closebox();
253 &Header::closebigbox();
254 &Header::closepage();