2005-05-30 06:15:01 +00:00
/ *
js functions and code common to all pages
* /
/* define some global variables for this request */
global . page = new Object ( ) ;
/* fill in some defaults */
global . page . title = "Samba Web Administration Tool" ;
2005-07-20 07:04:07 +00:00
libinclude ( "base.js" ) ;
2005-05-30 12:21:30 +00:00
/ * t o c o p e w i t h b r o w s e r s t h a t d o n ' t s u p p o r t c o o k i e s w e a p p e n d t h e s e s s i o n i d
to the URI * /
global . SESSIONURI = "" ;
if ( request [ 'COOKIE_SUPPORT' ] != "True" ) {
global . SESSIONURI = "?SwatSessionId=" + request [ 'SESSION_ID' ] ;
}
/ *
possibly adjust a local URI to have the session id appended
used for browsers that don ' t support cookies
* /
function session _uri ( uri ) {
return uri + global . SESSIONURI ;
}
2005-07-12 11:46:34 +00:00
/ *
like printf , but to the web page
* /
function writef ( )
{
write ( vsprintf ( arguments ) ) ;
}
/ *
like writef with a < br >
* /
function writefln ( )
{
write ( vsprintf ( arguments ) ) ;
write ( "<br/>\n" ) ;
}
2005-05-30 12:21:30 +00:00
2005-05-30 06:22:56 +00:00
/ * i f t h e b r o w s e r w a s t o o d u m b t o s e t t h e H O S T h e a d e r , t h e n
set it now * /
if ( headers [ 'HOST' ] == undefined ) {
headers [ 'HOST' ] = server [ 'SERVER_HOST' ] + ":" + server [ 'SERVER_PORT' ] ;
}
2005-05-30 06:15:01 +00:00
/ *
show the page header . page types include "plain" and "column"
* /
2005-07-19 09:34:11 +00:00
function page _header ( pagetype , title , menu ) {
2005-05-30 06:15:01 +00:00
global . page . pagetype = pagetype ;
global . page . title = title ;
2005-07-19 09:34:11 +00:00
global . page . menu = menu ;
2005-05-30 06:15:01 +00:00
include ( "/scripting/header_" + pagetype + ".esp" ) ;
}
/ *
show the page footer , getting the page type from page . pagetype
set in page _header ( )
* /
function page _footer ( ) {
include ( "/scripting/footer_" + global . page . pagetype + ".esp" ) ;
}
2005-05-30 12:21:30 +00:00
2005-05-30 06:15:01 +00:00
/ *
check if a uri is one of the 'always allowed' pages , even when not logged in
This allows the login page to use the same style sheets and images
* /
function always _allowed ( uri ) {
var allowed = new Array ( "/images/favicon.ico" ,
2005-07-13 00:43:00 +00:00
"/images/linkpad.gif" ,
2005-05-30 06:15:01 +00:00
"/images/logo.png" ,
2005-07-14 19:21:02 +00:00
"/images/stripes.png" ,
"/style/columns.css" ,
"/style/swat.css" ,
2005-05-30 06:15:01 +00:00
"/style/common.css" ) ;
for ( i in allowed ) {
if ( allowed [ i ] == uri ) {
return true ;
}
}
return false ;
}
2005-05-30 06:55:25 +00:00
/ *
2005-05-31 02:24:50 +00:00
display a table element
* /
function table _element ( i , o ) {
write ( "<tr><td>" + i + "</td><td>" ) ;
if ( typeof ( o [ i ] ) == "object" ) {
2005-07-09 05:31:38 +00:00
var j , first ;
2005-05-31 02:24:50 +00:00
first = true ;
for ( j in o [ i ] ) {
if ( first == false ) {
write ( "<br />" ) ;
}
write ( o [ i ] [ j ] ) ;
first = false ;
}
} else {
write ( o [ i ] ) ;
}
write ( "</td></tr>\n" ) ;
}
2005-05-31 03:37:01 +00:00
2005-05-31 02:24:50 +00:00
/ *
display a ejs object as a table . The header is optional
2005-05-30 06:55:25 +00:00
* /
function simple _table ( v ) {
2005-07-09 05:31:38 +00:00
if ( v . length == 0 ) {
2005-05-31 03:37:01 +00:00
return ;
}
2005-05-30 06:55:25 +00:00
write ( "<table class=\"data\">\n" ) ;
2005-07-09 05:31:38 +00:00
var r ;
2005-05-30 06:55:25 +00:00
for ( r in v ) {
2005-05-31 02:24:50 +00:00
table _element ( r , v ) ;
2005-05-30 06:55:25 +00:00
}
write ( "</table>\n" ) ;
}
/ *
display an array of objects , with the header for each element from the given
attribute
* /
function multi _table ( array , header ) {
2005-07-09 05:31:38 +00:00
var i , n ;
2005-05-30 06:55:25 +00:00
write ( "<table class=\"data\">\n" ) ;
2005-07-09 05:31:38 +00:00
for ( i = 0 ; i < array . length ; i ++ ) {
var r , v = array [ i ] ;
2005-05-31 03:37:01 +00:00
write ( '<tr><th colspan="2">' + v [ header ] + "</th></tr>\n" ) ;
2005-05-30 06:55:25 +00:00
for ( r in v ) {
if ( r != header ) {
2005-05-31 02:24:50 +00:00
table _element ( r , v ) ;
2005-05-30 06:55:25 +00:00
}
}
}
write ( "</table>\n" ) ;
}
2005-05-30 08:13:34 +00:00