Merge pull request #1818 from dibdot/lxc_fix
[project/luci.git] / modules / luci-mod-admin-full / luasrc / view / admin_system / packages.htm
1 <%#
2  Copyright 2008 Steven Barth <steven@midlink.org>
3  Copyright 2008-2010 Jo-Philipp Wich <jow@openwrt.org>
4  Licensed to the public under the Apache License 2.0.
5 -%>
6
7 <%-
8 local opkg = require "luci.model.ipkg"
9 local fs = require "nixio.fs"
10 local wa = require "luci.tools.webadmin"
11 local rowcnt = 1
12
13 function rowstyle()
14         rowcnt = rowcnt + 1
15         return (rowcnt % 2) + 1
16 end
17
18 local fstat = fs.statvfs(opkg.overlay_root())
19 local space_total = fstat and fstat.blocks or 0
20 local space_free  = fstat and fstat.bfree  or 0
21 local space_used  = space_total - space_free
22
23 local used_perc = math.floor(0.5 + ((space_total > 0) and ((100 / space_total) * space_used) or 100))
24 local free_byte = space_free * fstat.frsize
25
26 local filter = { }
27
28
29 local opkg_list = luci.model.ipkg.list_all
30 local querypat
31 if query and #query > 0 then
32         querypat = '*%s*' % query
33         opkg_list = luci.model.ipkg.find
34 end
35
36 local letterpat
37 if letter == 35 then
38         letterpat = "[^a-z]*"
39 else
40         letterpat = string.char(letter, 42) -- 'A' '*'
41 end
42
43 -%>
44
45 <%+header%>
46
47 <h2 name="content"><%:Software%></h2>
48
49 <div class="cbi-map">
50
51         <ul class="cbi-tabmenu">
52                 <li class="cbi-tab"><a href="#"><%:Actions%></a></li>
53                 <li class="cbi-tab-disabled"><a href="<%=REQUEST_URI%>/ipkg"><%:Configuration%></a></li>
54         </ul>
55
56         <form method="post" action="<%=REQUEST_URI%>">
57                 <input type="hidden" name="exec" value="1" />
58                 <input type="hidden" name="token" value="<%=token%>" />
59
60                 <fieldset class="cbi-section">
61                         <fieldset class="cbi-section-node">
62                                 <% if (install and next(install)) or (remove and next(remove)) or update or upgrade then %>
63                                 <div class="cbi-value">
64                                         <% if #stdout > 0 then %><pre><%=pcdata(stdout)%></pre><% end %>
65                                         <% if #stderr > 0 then %><pre class="error"><%=pcdata(stderr)%></pre><% end %>
66                                 </div>
67                                 <% end %>
68
69                                 <% if querypat then %>
70                                 <div class="cbi-value">
71                                         <%:Displaying only packages containing%> <strong>"<%=pcdata(query)%>"</strong>
72                                         <input type="button" onclick="location.href='?display=<%=luci.http.urlencode(display)%>'" href="#" class="cbi-button cbi-button-reset" style="margin-left:1em" value="<%:Reset%>" />
73                                         <br style="clear:both" />
74                                 </div>
75                                 <% end %>
76
77                                 <% if no_lists or old_lists then %>
78                                 <div class="cbi-value">
79                                         <% if old_lists then %>
80                                                 <%:Package lists are older than 24 hours%>
81                                         <% else %>
82                                                 <%:No package lists available%>
83                                         <% end %>
84                                         <input type="submit" name="update" href="#" class="cbi-button cbi-button-apply" style="margin-left:3em" value="<%:Update lists%>" />
85                                 </div>
86                                 <% end %>
87
88                                 <div class="cbi-value cbi-value-last">
89                                         <%:Free space%>: <strong><%=(100-used_perc)%>%</strong> (<strong><%=wa.byte_format(free_byte)%></strong>)
90                                         <div style="margin:3px 0; width:300px; height:10px; border:1px solid #000000; background-color:#80C080">
91                                                 <div style="background-color:#F08080; border-right:1px solid #000000; height:100%; width:<%=used_perc%>%">&#160;</div>
92                                         </div>
93                                 </div>
94                         </fieldset>
95
96                         <br />
97
98                         <fieldset class="cbi-section-node">
99                                 <input type="hidden" name="display" value="<%=pcdata(display)%>" />
100
101                                 <div class="cbi-value">
102                                         <label class="cbi-value-title"><%:Download and install package%>:</label>
103                                         <div class="cbi-value-field">
104                                                 <input type="text" name="url" size="30" value="" />
105                                                 <input class="cbi-button cbi-input-save" type="submit" name="go" value="<%:OK%>" />
106                                         </div>
107                                 </div>
108
109                                 <div class="cbi-value cbi-value-last">
110                                         <label class="cbi-value-title"><%:Filter%>:</label>
111                                         <div class="cbi-value-field">
112                                                 <input type="text" name="query" size="20" value="<%=pcdata(query)%>" />
113                                                 <input type="submit" class="cbi-button cbi-input-find" name="search" value="<%:Find package%>" />
114                                         </div>
115                                 </div>
116                         </fieldset>
117                 </fieldset>
118         </form>
119
120
121         <h3><%:Status%></h3>
122
123
124         <ul class="cbi-tabmenu">
125                 <li class="cbi-tab<% if display ~= "installed" then %>-disabled<% end %>"><a href="?display=installed&amp;query=<%=pcdata(query)%>"><%:Installed packages%><% if query then %> (<%=pcdata(query)%>)<% end %></a></li>
126                 <li class="cbi-tab<% if display ~= "available" then %>-disabled<% end %>"><a href="?display=available&amp;query=<%=pcdata(query)%>"><%:Available packages%><% if query then %> (<%=pcdata(query)%>)<% end %></a></li>
127         </ul>
128
129         <% if display ~= "available" then %>
130                 <fieldset class="cbi-section">
131                         <table class="cbi-section-table" style="width:100%">
132                                 <tr class="cbi-section-table-titles">
133                                         <th class="cbi-section-table-cell" style="text-align:left">&#160;</th>
134                                         <th class="cbi-section-table-cell" style="text-align:left"><%:Package name%></th>
135                                         <th class="cbi-section-table-cell" style="text-align:left"><%:Version%></th>
136                                 </tr>
137                                 <% local empty = true; luci.model.ipkg.list_installed(querypat, function(n, v, s, d) empty = false; filter[n] = true %>
138                                 <tr class="cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>">
139                                         <td style="text-align:left; width:10%">
140                                                 <form method="post" class="inline" action="<%=REQUEST_URI%>">
141                                                         <input type="hidden" name="exec" value="1" />
142                                                         <input type="hidden" name="token" value="<%=token%>" />
143                                                         <input type="hidden" name="remove" value="<%=pcdata(n)%>" />
144                                                         <a onclick="window.confirm('<%:Remove%> &quot;<%=luci.util.pcdata(n)%>&quot; ?') &#38;&#38; this.parentNode.submit(); return false" href="#"><%:Remove%></a>
145                                                 </form>
146                                         </td>
147                                         <td style="text-align:left"><%=luci.util.pcdata(n)%></td>
148                                         <td style="text-align:left"><%=luci.util.pcdata(v)%></td>
149                                 </tr>
150                                 <% end) %>
151                                 <% if empty then %>
152                                 <tr class="cbi-section-table-row">
153                                         <td style="text-align:left">&#160;</td>
154                                         <td style="text-align:left"><em><%:none%></em></td>
155                                         <td style="text-align:left"><em><%:none%></em></td>
156                                 </tr>
157                                 <% end %>
158                         </table>
159                 </fieldset>
160         <% else %>
161                 <fieldset class="cbi-section">
162                 <% if not querypat then %>
163                         <ul class="cbi-tabmenu">
164                                 <% local i; for i = 65, 90 do %>
165                                 <li class="cbi-tab<% if letter ~= i then %>-disabled<% end %>"><a href="?display=available&amp;letter=<%=string.char(i)%>"><%=string.char(i)%></a></li>
166                                 <% end %>
167                                 <li class="cbi-tab<% if letter ~= 35 then %>-disabled<% end %>"><a href="?display=available&amp;letter=%23">#</a></li>
168                         </ul>
169                         <div class="cbi-section-node">
170                 <% end %>
171                         <table class="cbi-section-table" style="width:100%">
172                                 <tr class="cbi-section-table-titles">
173                                         <th class="cbi-section-table-cell" style="text-align:left">&#160;</th>
174                                         <th class="cbi-section-table-cell" style="text-align:left"><%:Package name%></th>
175                                         <th class="cbi-section-table-cell" style="text-align:left"><%:Version%></th>
176                                         <th class="cbi-section-table-cell" style="text-align:right"><%:Size (.ipk)%></th>
177                                         <th class="cbi-section-table-cell" style="text-align:left"><%:Description%></th>
178                                 </tr>
179                                 <% local empty = true; opkg_list(querypat or letterpat, function(n, v, s, d) if filter[n] then return end; empty = false %>
180                                 <tr class="cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>">
181                                         <td style="text-align:left; width:10%">
182                                                 <form method="post" class="inline" action="<%=REQUEST_URI%>">
183                                                         <input type="hidden" name="exec" value="1" />
184                                                         <input type="hidden" name="token" value="<%=token%>" />
185                                                         <input type="hidden" name="install" value="<%=pcdata(n)%>" />
186                                                         <a onclick="window.confirm('<%:Install%> &quot;<%=luci.util.pcdata(n)%>&quot; ?') &#38;&#38; this.parentNode.submit(); return false" href="#"><%:Install%></a>
187                                                 </form>
188                                         </td>
189                                         <td style="text-align:left"><%=luci.util.pcdata(n)%></td>
190                                         <td style="text-align:left"><%=luci.util.pcdata(v)%></td>
191                                         <td style="text-align:right"><%=luci.util.pcdata(s)%></td>
192                                         <td style="text-align:left"><%=luci.util.pcdata(d)%></td>
193                                 </tr>
194                                 <% end) %>
195                                 <% if empty then %>
196                                 <tr class="cbi-section-table-row">
197                                         <td style="text-align:left">&#160;</td>
198                                         <td style="text-align:left"><em><%:none%></em></td>
199                                         <td style="text-align:left"><em><%:none%></em></td>
200                                         <td style="text-align:right"><em><%:none%></em></td>
201                                         <td style="text-align:left"><em><%:none%></em></td>
202                                 </tr>
203                                 <% end %>
204                         </table>
205                 <% if not querypat then %>
206                         </div>
207                 <% end %>
208                 </fieldset>
209         <% end %>
210 </div>
211
212 <%+footer%>