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