themes: eliminate uses of luci.sys.loadavg()
[project/luci.git] / themes / luci-theme-openwrt / luasrc / view / themes / openwrt.org / header.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 $Id$
13
14 -%>
15 <%
16         local sys  = require "luci.sys"
17         local util = require "luci.util"
18         local http = require "luci.http"
19         local disp = require "luci.dispatcher"
20
21         local sysinfo = util.ubus("system", "info") or { }
22         local loadinfo = sysinfo.load or { 0, 0, 0 }
23         local boardinfo = util.ubus("system", "board") or { }
24
25         local request  = disp.context.path
26         local request2 = disp.context.request
27
28         local category = request[1]
29         local cattree  = category and disp.node(category)
30
31         local leaf = request2[#request2]
32
33         local tree = disp.node()
34         local node = disp.context.dispatched
35
36         local categories = disp.node_childs(tree)
37
38         local c = tree
39         local i, r
40
41         -- tag all nodes leading to this page
42         for i, r in ipairs(request) do
43                 if c.nodes and c.nodes[r] then
44                         c = c.nodes[r]
45                         c._menu_selected = true
46                 end
47         end
48
49         http.prepare_content("application/xhtml+xml")
50
51         local function nodeurl(prefix, name, query)
52                 local url = controller .. prefix .. name .. "/"
53                 if query then
54                         url = url .. http.build_querystring(query)
55                 end
56                 return pcdata(url)
57         end
58
59         local function subtree(prefix, node, level)
60                 if not level then
61                         level = 1
62                 end
63
64                 local childs = disp.node_childs(node)
65                 if #childs > 0 then
66 %>
67         <div class="tabmenu<%=level%>">
68         <ul class="tabmenu l<%=level%>">
69                 <%
70                         local selected_node
71                         local selected_name
72                         local i, v
73
74                         for i, v in ipairs(childs) do
75                                 local nnode = node.nodes[v]
76                                 if nnode._menu_selected then
77                                         selected_node = nnode
78                                         selected_name = v
79                                 end
80                 %>
81                         <li class="tabmenu-item-<%=v%><% if nnode._menu_selected or (node.leaf and v == leaf) then %> active<% end %>">
82                                 <a href="<%=nodeurl(prefix, v, nnode.query)%>"><%=striptags(translate(nnode.title))%></a>
83                         </li>
84                 <%
85                         end
86                 %>
87         </ul>
88         <br style="clear:both" />
89 <%
90                         if selected_node then
91                                 subtree(prefix .. selected_name .. "/", selected_node, level + 1)
92                         end
93 %>
94         </div>
95 <%
96                 end
97         end
98 -%>
99
100 <?xml version="1.0" encoding="utf-8"?>
101 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
102 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<%=luci.i18n.context.lang%>" lang="<%=luci.i18n.context.lang%>">
103 <head>
104 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
105 <meta http-equiv="Content-Script-Type" content="text/javascript" />
106 <link rel="stylesheet" type="text/css" media="screen" href="<%=media%>/cascade.css" />
107 <!--[if IE 6]><link rel="stylesheet" type="text/css" media="screen" href="<%=media%>/ie6.css" /><![endif]-->
108 <!--[if IE 7]><link rel="stylesheet" type="text/css" media="screen" href="<%=media%>/ie7.css" /><![endif]-->
109 <!--[if IE 8]><link rel="stylesheet" type="text/css" media="screen" href="<%=media%>/ie8.css" /><![endif]-->
110 <% if node and node.css then %><link rel="stylesheet" type="text/css" media="screen" href="<%=resource%>/<%=node.css%>" />
111 <% end -%>
112 <% if css then %><style title="text/css">
113 <%= css %>
114 </style>
115 <% end -%>
116 <script type="text/javascript" src="<%=resource%>/xhr.js"></script>
117 <title><%=striptags( (boardinfo.hostname or "?") .. ( (node and node.title) and ' - ' .. translate(node.title) or '')) %> - LuCI</title>
118 </head>
119 <body class="lang_<%=luci.i18n.context.lang%>">
120
121 <p class="skiplink">
122 <span id="skiplink1"><a href="#navigation"><%:Skip to navigation%></a></span>
123 <span id="skiplink2"><a href="#content"><%:Skip to content%></a></span>
124 </p>
125
126 <div id="menubar">
127 <h2 class="navigation"><a id="navigation" name="navigation"><%:Navigation%></a></h2>
128
129 <div class="hostinfo">
130         <%=(boardinfo.hostname or "?")%> | <%=luci.version.distversion%> |
131         <%:Load%>: <%="%.2f" % loadinfo[1] / 65535.0%> <%="%.2f" % loadinfo[2] / 65535.0%> <%="%.2f" % loadinfo[3] / 65535.0%>
132         <span id="xhr_poll_status" style="display:none" onclick="XHR.running() ? XHR.halt() : XHR.run()">
133                 | <%:Auto Refresh%>:
134                 <span id="xhr_poll_status_on"><%:on%></span>
135                 <span id="xhr_poll_status_off" style="display:none"><%:off%></span>
136         </span>
137 </div>
138
139 <% if #categories > 1 then %>
140         <ul id="modemenu">
141                 <% for i, r in ipairs(categories) do %>
142                         <li><a<% if request[1] == r then %> class="active"<%end%> href="<%=controller%>/<%=r%>/"><%=striptags(translate(tree.nodes[r].title))%></a></li>
143                 <% end %>
144         </ul>
145 <% end %>
146
147 <%
148 if tree.nodes[category] and tree.nodes[category].ucidata then
149         local ucic = 0
150         for i, j in pairs(require("luci.model.uci").cursor():changes()) do
151                 for k, l in pairs(j) do
152                         for m, n in pairs(l) do
153                                 ucic = ucic + 1;
154                         end
155                 end
156         end
157 -%>
158 <div id="savemenu">
159         <% if ucic > 0 then %>
160                 <a class="warning" href="<%=controller%>/<%=category%>/uci/changes/?redir=<%=luci.http.urlencode(luci.http.formvalue("redir") or REQUEST_URI)%>"><%:Unsaved Changes%>: <%=ucic%></a>
161         <%- else -%>
162                 <a href="#"><%:Changes%>: 0</a>
163         <% end -%>
164 </div><% end %>
165
166 <div class="clear"></div>
167 </div>
168
169 <div id="maincontainer">
170         <div id="tabmenu">
171                 <% if category then subtree("/" .. category .. "/", cattree) end %>
172         </div>
173
174         <div id="maincontent">
175                 <noscript>
176                         <div class="errorbox">
177                                 <strong><%:Java Script required!%></strong><br />
178                                 <%:You must enable Java Script in your browser or LuCI will not work properly.%>
179                         </div>
180                 </noscript>
181
182                 <%- if luci.sys.process.info("uid") == 0 and luci.sys.user.getuser("root") and not luci.sys.user.getpasswd("root") and category ~= "failsafe" then -%>
183                 <div class="errorbox">
184                         <strong><%:No password set!%></strong><br />
185                         <%:There is no password set on this router. Please configure a root password to protect the web interface and enable SSH.%><br />
186                         <a href="<%=pcdata(luci.dispatcher.build_url("admin/system/admin"))%>"><%:Go to password configuration...%></a>
187                 </div>
188                 <%- end -%>