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