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