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