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.
8 local opkg = require "luci.model.ipkg"
9 local fs = require "nixio.fs"
10 local wa = require "luci.tools.webadmin"
15 return (rowcnt % 2) + 1
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
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
29 local opkg_list = luci.model.ipkg.list_all
31 if query and #query > 0 then
32 querypat = '*%s*' % query
33 opkg_list = luci.model.ipkg.find
40 letterpat = string.char(letter, 42) -- 'A' '*'
47 <h2 name="content"><%:Software%></h2>
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>
56 <form method="post" action="<%=REQUEST_URI%>">
57 <input type="hidden" name="exec" value="1" />
58 <input type="hidden" name="token" value="<%=token%>" />
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 %>
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=<%=pcdata(display)%>'" href="#" class="cbi-button cbi-button-reset" style="margin-left:1em" value="<%:Reset%>" />
73 <br style="clear:both" />
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%>
82 <%:No package lists available%>
84 <input type="submit" name="update" href="#" class="cbi-button cbi-button-apply" style="margin-left:3em" value="<%:Update lists%>" />
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%>%"> </div>
98 <fieldset class="cbi-section-node">
99 <input type="hidden" name="display" value="<%=pcdata(display)%>" />
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%>" />
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%>" />
124 <ul class="cbi-tabmenu">
125 <li class="cbi-tab<% if display ~= "installed" then %>-disabled<% end %>"><a href="?display=installed&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&query=<%=pcdata(query)%>"><%:Available packages%><% if query then %> (<%=pcdata(query)%>)<% end %></a></li>
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"> </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>
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%> "<%=luci.util.pcdata(n)%>" ?') && this.parentNode.submit(); return false" href="#"><%:Remove%></a>
147 <td style="text-align:left"><%=luci.util.pcdata(n)%></td>
148 <td style="text-align:left"><%=luci.util.pcdata(v)%></td>
152 <tr class="cbi-section-table-row">
153 <td style="text-align:left"> </td>
154 <td style="text-align:left"><em><%:none%></em></td>
155 <td style="text-align:left"><em><%:none%></em></td>
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&letter=<%=string.char(i)%>"><%=string.char(i)%></a></li>
167 <li class="cbi-tab<% if letter ~= 35 then %>-disabled<% end %>"><a href="?display=available&letter=%23">#</a></li>
169 <div class="cbi-section-node">
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"> </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>
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%> "<%=luci.util.pcdata(n)%>" ?') && this.parentNode.submit(); return false" href="#"><%:Install%></a>
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>
196 <tr class="cbi-section-table-row">
197 <td style="text-align:left"> </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>
205 <% if not querypat then %>