modules/admin-full: rework system menu area
[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 local fstat = fs.statvfs(opkg.overlay_root())
28 local space_total = fstat and fstat.blocks or 0
29 local space_free  = fstat and fstat.bfree  or 0
30 local space_used  = space_total - space_free
31
32 local used_perc = math.floor(0.5 + ((space_total > 0) and ((100 / space_total) * space_used) or 100))
33 local free_byte = space_free * fstat.frsize
34
35 local filter = { }
36
37
38 local querypat
39 if query and #query > 0 then
40         querypat = "*%s*" % query
41 end
42
43 local letterpat
44 if letter == 35 then
45         letterpat = "[^a-zA-Z]*"
46 else
47         letterpat = string.char(91, letter, letter + 32, 93, 42) -- '[' 'A' 'a' ']' '*'
48 end
49
50 -%>
51 <%+header%>
52 <h2><a id="content" name="content"><%:System%> - <%:Software%></a></h2>
53
54 <form method="post" action="<%=REQUEST_URI%>">
55         <div class="cbi-map">
56
57                 <ul class="cbi-tabmenu">
58                         <li class="cbi-tab"><a href="#"><%:Actions%></a></li>
59                         <li class="cbi-tab-disabled"><a href="<%=REQUEST_URI%>/ipkg"><%:Configuration%></a></li>
60                 </ul>
61
62                 <fieldset class="cbi-section">
63
64
65                         <fieldset class="cbi-section-node">
66                                 <% if (install and next(install)) or (remove and next(remove)) or update or upgrade then %>
67                                 <div class="cbi-value">
68                                         <% if #stdout > 0 then %><pre><%=pcdata(stdout)%></pre><% end %>
69                                         <% if #stderr > 0 then %><pre class="error"><%=pcdata(stderr)%></pre><% end %>
70                                 </div>
71                                 <% end %>
72
73                                 <% if querypat then %>
74                                 <div class="cbi-value">
75                                         <%:Displaying only packages containing%> <strong>"<%=pcdata(query)%>"</strong>
76                                         <input type="button" onclick="location.href='?display=<%=pcdata(display)%>'" href="#" class="cbi-button cbi-button-reset" style="margin-left:1em" value="<%:Reset%>" />
77                                         <br style="clear:both" />
78                                 </div>
79                                 <% end %>
80
81                                 <% if no_lists or old_lists then %>
82                                 <div class="cbi-value">
83                                         <% if old_lists then %>
84                                                 <%:Package lists are older than 24 hours%>
85                                         <% else %>
86                                                 <%:No package lists available%>
87                                         <% end %>
88                                         <input type="button" onclick="location.href='?update=1'" href="#" class="cbi-button cbi-button-apply" style="margin-left:3em" value="<%:Update lists%>" />
89                                 </div>
90                                 <% end %>
91
92                                 <div class="cbi-value cbi-value-last">
93                                         <%:Free space%>: <strong><%=(100-used_perc)%>%</strong> (<strong><%=wa.byte_format(free_byte)%></strong>)
94                                         <div style="margin:3px 0; width:300px; height:10px; border:1px solid #000000; background-color:#80C080">
95                                                 <div style="background-color:#F08080; border-right:1px solid #000000; height:100%; width:<%=used_perc%>%">&#160;</div>
96                                         </div>
97                                 </div>
98                         </fieldset>
99
100                         <br />
101
102                         <fieldset class="cbi-section-node">
103                                 <input type="hidden" name="display" value="<%=pcdata(display)%>" />
104
105                                 <div class="cbi-value">
106                                         <label class="cbi-value-title"><%:Download and install package%>:</label>
107                                         <div class="cbi-value-field">
108                                                 <input type="text" name="url" size="30" value="" />
109                                                 <input class="cbi-button cbi-input-save" type="submit" name="submit" value="<%:OK%>" />
110                                         </div>
111                                 </div>
112
113                                 <div class="cbi-value cbi-value-last">
114                                         <label class="cbi-value-title"><%:Filter%>:</label>
115                                         <div class="cbi-value-field">
116                                                 <input type="text" name="query" size="20" value="<%=pcdata(query)%>" />
117                                                 <input type="submit" class="cbi-button cbi-input-find" name="search" value="<%:Find package%>" />
118                                         </div>
119                                 </div>
120                         </fieldset>
121                 </fieldset>
122                 <br />
123
124                 <h3><%:Status%></h3>
125
126
127                 <ul class="cbi-tabmenu">
128                         <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>
129                         <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>
130                 </ul>
131
132                 <% if display ~= "available" then %>
133                         <fieldset class="cbi-section">
134                                 <table class="cbi-section-table" style="width:100%">
135                                         <tr class="cbi-section-table-titles">
136                                                 <th class="cbi-section-table-cell" style="text-align:left">&#160;</th>
137                                                 <th class="cbi-section-table-cell" style="text-align:left"><%:Package name%></th>
138                                                 <th class="cbi-section-table-cell" style="text-align:left"><%:Version%></th>
139                                         </tr>
140                                         <% local empty = true; luci.model.ipkg.list_installed(querypat, function(n, v, d) empty = false; filter[n] = true %>
141                                         <tr class="cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>">
142                                                 <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>
143                                                 <td style="text-align:left"><%=luci.util.pcdata(n)%></td>
144                                                 <td style="text-align:left"><%=luci.util.pcdata(v)%></td>
145                                         </tr>
146                                         <% end) %>
147                                         <% if empty then %>
148                                         <tr class="cbi-section-table-row">
149                                                 <td style="text-align:left">&#160;</td>
150                                                 <td style="text-align:left"><em><%:none%></em></td>
151                                                 <td style="text-align:left"><em><%:none%></em></td>
152                                         </tr>
153                                         <% end %>
154                                 </table>
155                         </fieldset>
156                 <% else %>
157                         <fieldset class="cbi-section">
158                         <% if not querypat then %>
159                                 <ul class="cbi-tabmenu">
160                                         <% local i; for i = 65, 90 do %>
161                                         <li class="cbi-tab<% if letter ~= i then %>-disabled<% end %>"><a href="?display=available&amp;letter=<%=string.char(i)%>"><%=string.char(i)%></a></li>
162                                         <% end %>
163                                         <li class="cbi-tab<% if letter ~= 35 then %>-disabled<% end %>"><a href="?display=available&amp;letter=%23">#</a></li>
164                                 </ul>
165                                 <div class="cbi-section-node">
166                         <% end %>
167                                 <table class="cbi-section-table" style="width:100%">
168                                         <tr class="cbi-section-table-titles">
169                                                 <th class="cbi-section-table-cell" style="text-align:left">&#160;</th>
170                                                 <th class="cbi-section-table-cell" style="text-align:left"><%:Package name%></th>
171                                                 <th class="cbi-section-table-cell" style="text-align:left"><%:Version%></th>
172                                                 <th class="cbi-section-table-cell" style="text-align:left"><%:Description%></th>
173                                         </tr>
174                                         <% local empty = true; luci.model.ipkg.list_all(querypat or letterpat, function(n, v, d) if filter[n] then return end; empty = false %>
175                                         <tr class="cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>">
176                                                 <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>
177                                                 <td style="text-align:left"><%=luci.util.pcdata(n)%></td>
178                                                 <td style="text-align:left"><%=luci.util.pcdata(v)%></td>
179                                                 <td style="text-align:left"><%=luci.util.pcdata(d)%></td>
180                                         </tr>
181                                         <% end) %>
182                                         <% if empty then %>
183                                         <tr class="cbi-section-table-row">
184                                                 <td style="text-align:left">&#160;</td>
185                                                 <td style="text-align:left"><em><%:none%></em></td>
186                                                 <td style="text-align:left"><em><%:none%></em></td>
187                                                 <td style="text-align:left"><em><%:none%></em></td>
188                                         </tr>
189                                         <% end %>
190                                 </table>
191                         <% if not querypat then %>
192                                 </div>
193                         <% end %>
194                         </fieldset>
195                 <% end %>
196         </div>
197 </form>
198 <%+footer%>