packages.htm 8.0 KB

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