Control Skripe korrigiert
[people/pmueller/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
25 &Header::showhttpheaders();
26
27 $pakfiresettings{'ACTION'} = '';
28 $pakfiresettings{'VALID'} = '';
29
30 $pakfiresettings{'INSPAKS'} = '';
31 $pakfiresettings{'DELPAKS'} = '';
32 $pakfiresettings{'AUTOUPDATE'} = 'off';
33 $pakfiresettings{'UUID'} = 'on';
34
35 &Header::getcgihash(\%pakfiresettings);
36
37 &Header::openpage($Lang::tr{'pakfire configuration'}, 1);
38 &Header::openbigbox('100%', 'left', '', $errormessage);
39
40 if ($pakfiresettings{'ACTION'} eq 'install'){
41 $pakfiresettings{'INSPAKS'} =~ s/\|/\ /g;
42 if ("$pakfiresettings{'FORCE'}" eq "on") {
43 my $command = "/usr/local/bin/pakfire install --non-interactive $pakfiresettings{'INSPAKS'} &>/dev/null &";
44 system("$command");
45 sleep(2);
46 } else {
47 &Header::openbox("100%", "center", "Abfrage");
48 my @output = `/usr/local/bin/pakfire resolvedeps $pakfiresettings{'INSPAKS'}`;
49 print <<END;
50 <table><tr><td colspan='2'>$Lang::tr{'pakfire install package'}.$pakfiresettings{'INSPAKS'}.$Lang::tr{'pakfire possible dependency'}
51 <pre>
52 END
53 foreach (@output) {
54 print "$_\n";
55 }
56 print <<END;
57 </pre>
58 <tr><td colspan='2'>$Lang::tr{'pakfire accept all'}
59 <tr><td colspan='2'>&nbsp;
60 <tr><td align='right'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
61 <input type='hidden' name='INSPAKS' value='$pakfiresettings{'INSPAKS'}' />
62 <input type='hidden' name='FORCE' value='on' />
63 <input type='hidden' name='ACTION' value='install' />
64 <input type='image' alt='$Lang::tr{'install'}' src='/images/go-next.png' />
65 </form>
66 <td align='left'>
67 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
68 <input type='hidden' name='ACTION' value='' />
69 <input type='image' alt='$Lang::tr{'abort'}' src='/images/dialog-error.png' />
70 </form>
71 </table>
72 END
73 &Header::closebox();
74 &Header::closebigbox();
75 &Header::closepage();
76 exit;
77 }
78 } elsif ($pakfiresettings{'ACTION'} eq 'remove') {
79
80 } elsif ($pakfiresettings{'ACTION'} eq 'update') {
81
82 system("/usr/local/bin/pakfire update --force");
83
84 } elsif ($pakfiresettings{'ACTION'} eq 'upgrade') {
85
86 system("/usr/local/bin/pakfire upgrade -y");
87
88 } elsif ($pakfiresettings{'ACTION'} eq "$Lang::tr{'save'}") {
89
90 &General::writehash("${General::swroot}/pakfire/settings", \%pakfiresettings);
91
92 }
93
94 &General::readhash("${General::swroot}/pakfire/settings", \%pakfiresettings);
95
96 my %selected=();
97 my %checked=();
98
99 $checked{'AUTOUPDATE'}{'off'} = '';
100 $checked{'AUTOUPDATE'}{'on'} = '';
101 $checked{'AUTOUPDATE'}{$pakfiresettings{'AUTOUPDATE'}} = "checked='checked'";
102 $checked{'UUID'}{'off'} = '';
103 $checked{'UUID'}{'on'} = '';
104 $checked{'UUID'}{$pakfiresettings{'UUID'}} = "checked='checked'";
105
106 # DPC move error message to top so it is seen!
107 if ($errormessage) {
108 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
109 print "<font class='base'>$errormessage&nbsp;</font>\n";
110 &Header::closebox();
111 }
112
113 my $return = `pidof pakfire`;
114 chomp($return);
115 if ($return) {
116 &Header::openbox("100%", "center", "Aktiv");
117 print <<END;
118 <table>
119 <tr><td>
120 <img src='/images/indicator.gif' alt='$Lang::tr{'aktiv'}' />&nbsp;
121 <td>
122 $Lang::tr{'pakfire working'}
123 <tr><td colspan='2' align='center'>
124 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
125 <input type='image' alt='$Lang::tr{'reload'}' src='/images/view-refresh.png' />
126 </form>
127 ### TO BE CONTINUED.... WE HAVE TO BEAUTIFY THIS A LITTLE BIT :D
128 <tr><td colspan='2' align='left'><pre>
129 END
130 my @output = `tail /var/log/messages | grep pakfire`;
131 foreach (@output) {
132 print "$_";
133 }
134 print <<END;
135 </pre>
136 </table>
137 END
138 ### TO BE CONTINUED.... WE HAVE TO BEAUTIFY THIS A LITTLE BIT :D
139 &Header::closebox();
140 &Header::closebigbox();
141 &Header::closepage();
142 exit;
143 }
144
145 &Header::openbox("100%", "center", "Pakfire");
146
147 system("pakfire update &>dev/null");
148
149 print <<END;
150 <table width='100%'>
151 <tr><td width='40%' align="center">Verfuegbare Addons:<br />
152 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
153 <select name="INSPAKS" size="10" multiple>
154 END
155 &Pakfire::dblist("notinstalled", "forweb");
156
157 print <<END;
158 </select>
159 </td>
160 <td width='20%' align="center">
161 <input type='hidden' name='ACTION' value='install' />
162 <input type='image' alt='$Lang::tr{'install'}' src='/images/list-add.png' />
163 </form><br />
164
165 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
166 <input type='hidden' name='ACTION' value='update' />
167 <input type='submit' value='Liste aktualisieren' /><br />
168 </form>
169
170 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
171 <input type='hidden' name='ACTION' value='remove' />
172 <input type='image' alt='$Lang::tr{'remove'}' src='/images/list-remove.png' />
173 </td>
174 <td width='40%' align="center">$Lang::tr{'pakfire installed addons'}<br />
175 <select name="DELPAKS" size="10" multiple>
176 END
177
178 &Pakfire::dblist("installed", "forweb");
179
180 print <<END;
181 </select>
182 </table></form>
183 <br /><hr /><br />
184 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
185 <table width='100%'>
186 <tr><td colspan='2'>$Lang::tr{'pakfire updates'}
187 <tr><td width='20%'>&nbsp;<td width='60%' align='center'>
188 <select name="UPDPAKS" size="5" disabled>
189 END
190
191 &Pakfire::dblist("upgrade", "forweb");
192
193 print <<END;
194 </select>
195 <td width='20%' align='center' valign='middle'><input type='hidden' name='ACTION' value='upgrade' />
196 <input type='image' alt='$Lang::tr{'upgrade'}' src='/images/document-save.png' />
197 </table></form>
198 <br /><hr /><br />
199 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
200 <table width='100%'>
201 <tr><td width='40%' align="right">$Lang::tr{'pakfire update daily'}
202 <td width='10%' align="left"><input type="checkbox" name="AUTOUPDATE" $checked{'AUTOUPDATE'}{'on'} />
203 <td width='40%' align="right">$Lang::tr{'pakfire register'}
204 <td width='10%' align="left"><input type="checkbox" name="UUID" $checked{'UUID'}{'on'} />
205 <tr><td width='100%' colspan="4" align="right"><input type="submit" name="ACTION" value="$Lang::tr{'save'}" />
206 </table>
207 </form>
208 END
209
210 &Header::closebox();
211 &Header::closebigbox();
212 &Header::closepage();