51c50500a88598779b5ddb0e5a31f3fe4b41bcb0
[project/luci.git] / modules / admin-full / luasrc / view / admin_system / packages.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2008 Steven Barth <steven@midlink.org>
4 Copyright 2008-2010 Jo-Philipp Wich <xm@subsignal.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13
14 -%>
15 <%-
16 local bit = require "bit"
17 local opkg = require "luci.model.ipkg"
18 local fs = require "nixio.fs"
19 local wa = require "luci.tools.webadmin"
20 local rowcnt = 1
21
22 function rowstyle()
23         rowcnt = rowcnt + 1
24         return (rowcnt % 2) + 1
25 end
26
27 function opkg_error(code)
28         code = bit.rshift(tonumber(code), 8)
29         return translate("OPKG error code %i" % code)
30 end
31
32 local fstat = fs.statvfs(opkg.overlay_root())
33 local space_total = fstat and fstat.blocks or 0
34 local space_free  = fstat and fstat.bfree  or 0
35 local space_used  = space_total - space_free
36
37 local used_perc = math.floor(0.5 + ((space_total > 0) and ((100 / space_total) * space_used) or 100))
38 local free_byte = space_free * fstat.frsize
39
40 local filter = { }
41
42 -%>
43 <%+header%>
44 <h2><a id="content" name="content"><%:System%> - <%:Software%></a></h2>
45
46 <form method="post" action="<%=REQUEST_URI%>">
47         <div class="cbi-map">
48                 <fieldset class="cbi-section">
49                         <ul>
50                                 <li><a href="<%=REQUEST_URI%>/ipkg"><%:Edit package lists and installation targets%></a></li>
51                                 <li><a href="<%=REQUEST_URI%>?update=1"><%:Update package lists%></a></li>
52                         </ul>
53                         <br />
54                         <fieldset class="cbi-section-node">
55                                 <div class="cbi-value">
56                                         <label class="cbi-value-title"><%:Download and install package%>:</label>
57                                         <div class="cbi-value-field">
58                                                 <input type="text" name="url" size="30" value="" />
59                                                 <input class="cbi-input-save" type="submit" name="submit" value="<%:OK%>" />
60                                         </div>
61                                 </div>
62
63                                 <div class="cbi-value">
64                                         <label class="cbi-value-title"><%:Filter%>:</label>
65                                         <div class="cbi-value-field">
66                                                 <input type="text" name="query" size="20" value="<%=pcdata(query)%>" />
67                                                 <input type="submit" class="cbi-input-find" name="search" value="<%:Find package%>" />
68                                         </div>
69                                 </div>
70                         </fieldset>
71                 </fieldset>
72                 <br />
73
74                 <h3><%:Status%></h3>
75                 <fieldset class="cbi-section">
76                         <%:Free space%>: <strong><%=(100-used_perc)%>%</strong> (<strong><%=wa.byte_format(free_byte)%></strong>)
77                         <div style="margin:3px 0; width:300px; height:10px; border:1px solid #000000; background-color:#80C080">
78                                 <div style="background-color:#F08080; border-right:1px solid #000000; height:100%; width:<%=used_perc%>%">&#160;</div>
79                         </div>
80
81                         <% if (install and next(install)) or (remove and next(remove)) or update or upgrade then %>
82                                 <br /><hr /><br />
83                                 <% if update then %>
84                                         <%:Package lists updated%>: <% if update == 0 then %><span class="ok"><%:OK%></span><% else %><span class="error"><%:Error%> (<%=opkg_error(update)%>)</span><% end %><br />
85                                 <% end %>
86                                 <% if upgrade then%>
87                                         <%:Upgrade installed packages%>: <% if upgrade == 0 then %><span class="ok"><%:OK%></span><% else %><span class="error"><%:Error%> (<%=opkg_error(upgrade)%>)</span><% end %><br />
88                                 <% end %>
89                                 <% if install then for k,v in pairs(install) do %>
90                                         <%:Install%> '<%=k%>': <% if v == 0 then %><span class="ok"><%:OK%></span><% else %><span class="error"><%:Error%> (<%=opkg_error(v)%>)</span><% end %><br />
91                                 <% end end %>
92                                 <% if remove then for k,v in pairs(remove) do %>
93                                         <%:Remove%> '<%=k%>': <% if v == 0 then %><span class="ok"><%:OK%></span><% else %><span class="error"><%:Error%> (<%=opkg_error(v)%>)</span><% end %><br />
94                                 <% end end %>
95                         <% end %>
96                 </fieldset>
97                 <br />
98
99                 <h3><%:Installed packages%><% if query then %> (<%=pcdata(query)%>)<% end %></h3>
100
101                 <fieldset class="cbi-section">
102                         <table class="cbi-section-table" style="width:100%">
103                                 <tr class="cbi-section-table-titles">
104                                         <th class="cbi-section-table-cell" style="text-align:left">&#160;</th>
105                                         <th class="cbi-section-table-cell" style="text-align:left"><%:Package name%></th>
106                                         <th class="cbi-section-table-cell" style="text-align:left"><%:Version%></th>
107                                 </tr>
108                                 <% local empty = true; luci.model.ipkg.list_installed(query, function(n, v, d) empty = false; filter[n] = true %>
109                                 <tr class="cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>">
110                                         <td style="text-align:left; width:10%"><a onclick="return window.confirm('<%:Remove%> &quot;<%=luci.util.pcdata(n)%>&quot; ?')" href="<%=REQUEST_URI%>?submit=1&amp;remove=<%=luci.util.pcdata(n)%>"><%:Remove%></a></td>
111                                         <td style="text-align:left"><%=luci.util.pcdata(n)%></td>
112                                         <td style="text-align:left"><%=luci.util.pcdata(v)%></td>
113                                 </tr>
114                                 <% end) %>
115                                 <% if empty then %>
116                                 <tr class="cbi-section-table-row">
117                                         <td style="text-align:left">&#160;</td>
118                                         <td style="text-align:left"><em><%:none%></em></td>
119                                         <td style="text-align:left"><em><%:none%></em></td>
120                                 </tr>
121                                 <% end %>
122                         </table>
123                 </fieldset>
124                 <br />
125
126
127                 <h3><%:Available packages%><% if query then %> (<%=pcdata(query)%>)<% end %></h3>
128
129                 <fieldset class="cbi-section">
130                         <table class="cbi-section-table" style="width:100%">
131                                 <tr class="cbi-section-table-titles">
132                                         <th class="cbi-section-table-cell" style="text-align:left">&#160;</th>
133                                         <th class="cbi-section-table-cell" style="text-align:left"><%:Package name%></th>
134                                         <th class="cbi-section-table-cell" style="text-align:left"><%:Version%></th>
135                                         <th class="cbi-section-table-cell" style="text-align:left"><%:Description%></th>
136                                 </tr>
137                                 <% local empty = true; luci.model.ipkg.list_all(query, function(n, v, d) if filter[n] then return end; empty = false %>
138                                 <tr class="cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>">
139                                         <td style="text-align:left; width:10%"><a onclick="return window.confirm('<%:Install%> &quot;<%=luci.util.pcdata(n)%>&quot; ?')" href="<%=REQUEST_URI%>?submit=1&amp;install=<%=luci.util.pcdata(n)%>"><%:Install%></a></td>
140                                         <td style="text-align:left"><%=luci.util.pcdata(n)%></td>
141                                         <td style="text-align:left"><%=luci.util.pcdata(v)%></td>
142                                         <td style="text-align:left"><%=luci.util.pcdata(d)%></td>
143                                 </tr>
144                                 <% end) %>
145                                 <% if empty then %>
146                                 <tr class="cbi-section-table-row">
147                                         <td style="text-align:left">&#160;</td>
148                                         <td style="text-align:left"><em><%:none%></em></td>
149                                         <td style="text-align:left"><em><%:none%></em></td>
150                                         <td style="text-align:left"><em><%:none%></em></td>
151                                 </tr>
152                                 <% end %>
153                         </table>
154                 </fieldset>
155         </div>
156 </form>
157 <%+footer%>