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