packages.htm 7.6 KB

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