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