/usr/share/pyshared/nwss/webtemplates.py is in python-nwsserver 2.0.0-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | #
# Copyright (c) 2005-2009, REvolution Computing, Inc.
#
# NetWorkSpaces is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
#
'''Templates used in the Web Interface.'''
from urllib import quote_plus
EVEN_ODD = ['even', 'odd']
# modified from twisted's default web file serving.
_STYLE_BLOCK = '''\
<style>
ul.menu {
display: block;
padding: 0 0.3em 0.3em 0.3em;
background-color: #777;
margin: 0 0 1em 0;
}
ul.menu li {
display: inline;
padding: 0 0 0 1em;
}
ul.menu a:hover {
background-color: black;
text-decoration: none;
}
ul.menu a:link, ul.menu a:visited {
color: white;
text-decoration: none;
}
a:link, a:visited {
color: blue;
text-decoration: none;
}
.tableheader {
background-color: #cecece;
}
.even {
background-color: #eee;
}
.odd {
background-color: #dedede;
}
.error {
color: #EE1111;
font-weight: bold;
margin: 20;
}
.warning {
color: #EE1111;
font-weight: bold;
margin: 20;
}
.confirm {
color: #EE1111;
font-weight: bold;
margin: 20;
}
.info {
color: black;
margin: 20;
}
body {
border: 0;
padding: 0;
margin: 0;
background-color: #efefef;
font-family: helvetica, sans-serif;
}
h1 {
padding: 0.3em;
background-color: #777;
color: white;
font-size: 1.6em;
font-style: italic;
font-weight: bold;
margin-bottom: 0;
}
th {
text-align: left;
}
table form {
margin-bottom: 0;
}
input[value=X] {
color: #EE1111;
font-weight: bold;
}
.nwstable {
margin: 0 0 0 1em;
}
</style>
'''
_HEADER_TEMPLATE = '''<html>
<head>
<title>%(title)s</title>
%(refresh)s
%(style)s
</head>
<body>
<h1>%(title)s</h1>
%(menu)s
'''
_FOOTER_TEMPLATE = '''</body>
</html>
'''
_PAGE_TEMPLATE = '''
%(header)s
%(content)s
%(footer)s
'''
_REFRESH = '''<meta http-equiv="Refresh" content="%d;URL=%s">
'''
CONFIRM_DELETE_VAR_TEMPLATE = '''<p>
<table border="0" cellspacing="0" cellpadding="4">
<tr><td colspan="2" class="confirm">Really delete variable "%(varname)s"?</td></tr>
<tr>
<td align="center">
<form action="doit" method="post">
<input type="hidden" name="op" value="deleteVar">
<input type="hidden" name="wsName" value="%(wsname)s">
<input type="hidden" name="varName" value="%(varname)s">
<input type="submit" value="Yes">
</form>
</td>
<td align="center">
<form action="doit" method="get">
<input type="hidden" name="op" value="listVars">
<input type="hidden" name="wsName" value="%(varname)s">
<input type="submit" value="No">
</form>
</td>
</tr>
</table>'''
CONFIRM_DELETE_WS_TEMPLATE = '''
<table border="0" cellspacing="0" cellpadding="4">
<tr><td colspan="2" class="confirm">Really delete workspace "%(wsname)s"?</td></tr>
<tr>
<td align="center">
<form action="doit" method="post">
<input type="hidden" name="op" value="deleteWs">
<input type="hidden" name="wsName" value="%(wsname)s">
<input type="submit" value="Yes">
</form>
</td>
<td align="center">
<form action="doit" method="get">
<input type="hidden" name="op" value="listWss">
<input type="submit" value="No">
</form>
</td>
</tr>
</table>'''
CONFIRM_FETCHTRY_VAR_TEMPLATE = '''
<table border="0" cellspacing="0" cellpadding="4">
<tr><td colspan="2" class="confirm">Really fetchTry (i.e. remove) variable "%(varname)s"?</td></tr>
<tr>
<td align="center">
<form action="doit" method="post">
<input type="hidden" name="op" value="fetchTryVar">
<input type="hidden" name="wsName" value="%(wsname)s">
<input type="hidden" name="varName" value="%(varname)s">
<input type="submit" value="Yes">
</form>
</td>
<td align="center">
<form action="doit" method="get">
<input type="hidden" name="op" value="showVar">
<input type="hidden" name="wsName" value="%(wsname)s">
<input type="hidden" name="varName" value="%(varname)s">
<input type="submit" value="No">
</form>
</td>
</tr>
</table>'''
WS_LIST_TABLE_HEADER = '''
<table cellpadding="4" class="nwstable">
<tr class="tableheader">
<th>Name</th>
<th>Monitor</th>
<th>Owner</th>
<th>Persistent</th>
<th># Variables</th>
<th>Delete?</th>
</tr>
'''
WS_LIST_TABLE_ENTRY_NOMON = '''<tr class="%(class)s">
<td><a href="doit?op=listVars&wsName=%(wsnameQ)s">%(wsname)s</a></td>
<td>[none]</td>
<td>%(owner)s</td>
<td>%(persistent)s</td>
<td>%(numbindings)d</td>
<td>
<form action="doit" method="post">
<input type="hidden" name="op" value="confirmDeleteWs">
<input type="hidden" name="wsName" value="%(wsname)s">
<input type="submit" value="X">
</form>
</td>
</tr>'''
WS_LIST_TABLE_ENTRY_SINGLEMON = '''<tr class="%(class)s">
<td><a href="doit?op=listVars&wsName=%(wsnameQ)s">%(wsname)s</a></td>
<td><a href="doit?op=showMonitor&wsName=%(wsnameQ)s&monName=%(monnameQ)s">%(monname)s</a></td>
<td>%(owner)s</td>
<td>%(persistent)s</td>
<td>%(numbindings)d</td>
<td>
<form action="doit" method="post">
<input type="hidden" name="op" value="confirmDeleteWs">
<input type="hidden" name="wsName" value="%(wsname)s">
<input type="submit" value="X">
</form>
</td>
</tr>'''
WS_LIST_TABLE_ENTRY_MULTIMON = '''<tr class="%(class)s">
<td><a href="doit?op=listVars&wsName=%(wsnameQ)s">%(wsname)s</a></td>
<td><a href="doit?op=listMonitors&wsName=%(wsnameQ)s">list monitors</a></td>
<td>%(owner)s</td>
<td>%(persistent)s</td>
<td>%(numbindings)d</td>
<td>
<form action="doit" method="post">
<input type="hidden" name="op" value="confirmDeleteWs">
<input type="hidden" name="wsName" value="%(wsname)s">
<input type="submit" value="X">
</form>
</td>
</tr>'''
VAR_LIST_HEADER = '''<p>
<table cellpadding="4" class="nwstable">
<tr class="tableheader">
<th>Variable</th>
<th># Values</th>
<th># Fetchers</th>
<th># Finders</th>
<th>Mode</th>
<th>Delete?</th>
</tr>
'''
VAR_LIST_ENTRY = '''<tr class="%(class)s">
<td><a href="doit?op=showVar&wsName=%(wsnameQ)s&varName=%(varnameQ)s">%(varname)s</a></td>
<td align="right">%(numvalues)d</td>
<td align="right">%(numfetchers)d</td>
<td align="right">%(numfinders)d</td>
<td>%(mode)s</td>
<td>
<form action="doit" method="post">
<input type="hidden" name="op" value="confirmDeleteVar">
<input type="hidden" name="wsName" value="%(wsname)s">
<input type="hidden" name="varName" value="%(varname)s">
<input type="submit" value="X">
</form>
</td>
</tr>
'''
VAR_LIST_FOOTER = '''\
</table>
'''
SERVER_INFO_TEMPLATE = '''<p>
<table cellpadding="4" class="nwstable">
<tr class="tableheader">
<th>Parameter</th>
<th>Value</th>
</tr>
<tr class="even">
<td>Version</td>
<td>%(nwsversion)s</td>
</tr>
<tr class="odd">
<td>NWS Server Port</td>
<td>%(nwsport)d</td>
</tr>
<tr class="even">
<td>Web Interface Port</td>
<td>%(webport)d</td>
</tr>
<tr class="odd">
<td>Temp Directory</td>
<td>%(tmpdir)s</td>
</tr>
<tr class="even">
<td>Long Value Size</td>
<td>%(longvaluesize)d</td>
</tr>
</table>
'''
CLIENT_LIST_HEADER = '''<p>
<table cellpadding="4" class="nwstable">
<tr class="tableheader">
<th>Client</th>
<th>Session #</th>
<th># Ops</th>
<th># Long Values</th>
<th># Wss Owned</th>
<th>Last Op</th>
<th>Blocking</th>
<th>Ws and var</th>
<th>Time of Last Op</th>
</tr>
'''
CLIENT_LIST_ENTRY = '''\
<tr class="%(class)s">
<td>%(peer)s</td>
<td>%(sessionno)d</td>
<td>%(numops)d</td>
<td>%(numlong)d</td>
<td>%(numws)d</td>
<td>%(lastop)s</td>
<td>%(blocking)s</td>
<td>%(blockingvar)s</td>
<td>%(lasttime)s</td>
</tr>
'''
CLIENT_LIST_FOOTER = '''\
</table>
'''
def make_div(content, cls):
"""Utility to assemble a DIV html element.
Parameters:
content - html for inside the DIV
cls - CSS class for the DIV
"""
return '<div class="%s">%s</div>' % (cls, content)
def menu_provider_default(nwslabel='NetWorkSpaces',
clientslabel='Clients'):
"""Utility to assemble the default menu.
Parameters:
nwslabel - label override for ``listWss`` page
"""
yield 'doit?op=showServerInfo', 'Server Info'
yield 'doit?op=listClients', clientslabel,
yield 'doit?op=listWss', nwslabel,
def menu_provider_ws(wsname, varslabel='Variables'):
"""Utility to assemble the menu for workspace-specific pages.
Parameters:
wsname - name of the current workspace
nwslabel - label override for ``listVars`` page
"""
for item in menu_provider_default():
yield item
wsname = quote_plus(wsname)
yield ('doit?op=listVars&wsName=%s' % wsname), varslabel
def menu_provider_var(wsname, varname):
"""Utility to assemble the menu for variable-specific pages.
Parameters:
wsname - name of the current workspace
varname - name of the current variable
"""
for item in menu_provider_ws(wsname):
yield item
wsname = quote_plus(wsname)
varname = quote_plus(varname)
url = ('doit?op=showVar&wsName=%s&varName=%s' % (wsname, varname))
yield url, 'Values'
def menu_provider_refresh(url, base):
"""Utility to add a 'Refresh' item to the menu bar.
Parameters:
url - URL for the 'Refresh' item
base - base menu provider
"""
for item in base:
yield item
yield url, 'Refresh'
def make_menu(provider):
"""Generate an appropriate 'menu' for a page.
Parameters:
provider - iterable yielding URL/label pairs for menu
"""
prefix = '<ul class="menu">\n'
content = [' <li><a href="%s">%s</a></li>' % x for x in provider]
suffix = '\n</ul>\n'
return prefix + '\n'.join(content) + suffix
def _make_refresh(page, delay=3):
"""Generate an appropriate <meta refresh=''> tag. If page is None, the
empty string will be returned.
Parameters:
page - page to redirect to
delay - delay in seconds (default: 3)
"""
if page is None:
return ''
return _REFRESH % (delay, page)
def make_header(title, menu=None, refresh_url=None):
"""Build a page header from the given parameters.
Parameters:
title - title for page
menu - content for menu
refresh_url - META refresh URL, if any
"""
if menu is None:
menu = menu_provider_default()
fields = {
'title': title,
'style': _STYLE_BLOCK,
'menu': make_menu(menu),
'refresh': _make_refresh(refresh_url),
}
return _HEADER_TEMPLATE % fields
def make_footer(title):
"""Build a page footer from the given parameters.
Parameters:
title - title for page
"""
fields = {
'title': title,
}
return _FOOTER_TEMPLATE % fields
def make_page(title, content, refresh_url=None, menu=None):
"""Build a complete page from the given parameters.
Parameters:
title - title for page
content - content for page (HTML)
refresh_url - META refresh URL, if any
menu - content for menu
"""
fields = {
'header': make_header(title, menu, refresh_url),
'footer': make_footer(title),
'title': title,
'content': content,
}
return _PAGE_TEMPLATE % fields
def make_errpage(msg, title='Error', **kwargs):
"""Create a stock error page with a given message and title.
Parameters:
msg - error message (HTML)
title - title (HTML)
kwargs - other arguments, as per ``make_page``
"""
error_div = make_div(msg, 'error')
return make_page(title, error_div, **kwargs)
def make_infopage(msg, title='Info', **kwargs):
"""Create a stock info page with a given message and title.
Parameters:
msg - message (HTML)
title - title (HTML)
kwargs - other arguments, as per ``make_page``
"""
info_div = make_div(msg, 'info')
return make_page(title, info_div, **kwargs)
|