summaryrefslogtreecommitdiff
path: root/webapps/scripting
diff options
context:
space:
mode:
authorDerrell Lipman <derrell@samba.org>2006-12-31 20:05:29 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:30:39 -0500
commit43470b5ec3d451aa75acf2cda40cf2dcc019efab (patch)
treeb5050af45bd3c56a33332b6cbb0a5e0ff69ab6b3 /webapps/scripting
parent4024697a0b7b97acdc5c411ab9fe8c894c66752e (diff)
downloadsamba-43470b5ec3d451aa75acf2cda40cf2dcc019efab.tar.gz
samba-43470b5ec3d451aa75acf2cda40cf2dcc019efab.tar.bz2
samba-43470b5ec3d451aa75acf2cda40cf2dcc019efab.zip
r20444: WEB Application framework / SWAT.
We're now at the stage where the web application framework should build and install automatically. Derrell (This used to be commit 0201baef46c1701007e0a4cdd95edee287939318)
Diffstat (limited to 'webapps/scripting')
-rw-r--r--webapps/scripting/common.js125
-rw-r--r--webapps/scripting/footer_columns.esp7
-rw-r--r--webapps/scripting/footer_desktop.esp6
-rw-r--r--webapps/scripting/footer_plain.esp7
-rw-r--r--webapps/scripting/forms.js112
-rw-r--r--webapps/scripting/header_columns.esp81
-rw-r--r--webapps/scripting/header_desktop.esp20
-rw-r--r--webapps/scripting/header_plain.esp25
-rw-r--r--webapps/scripting/preauth.esp49
9 files changed, 432 insertions, 0 deletions
diff --git a/webapps/scripting/common.js b/webapps/scripting/common.js
new file mode 100644
index 0000000000..523e6fed2f
--- /dev/null
+++ b/webapps/scripting/common.js
@@ -0,0 +1,125 @@
+/*
+ js functions and code common to static pages
+*/
+
+/* define some global variables for this request */
+global.page = new Object();
+
+/* fill in some defaults */
+global.page.title = "Samba Web Administration Tool";
+
+libinclude("base.js");
+
+/* to cope with browsers that don't support cookies we append the sessionid
+ 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;
+}
+
+/*
+ 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");
+}
+
+
+/* if the browser was too dumb to set the HOST header, then
+ set it now */
+if (headers['HOST'] == undefined) {
+ headers['HOST'] = server['SERVER_HOST'] + ":" + server['SERVER_PORT'];
+}
+
+/*
+ show the page header. page types include "plain" and "column"
+*/
+function page_header(pagetype, title, menu) {
+ global.page.pagetype = pagetype;
+ global.page.title = title;
+ global.page.menu = menu;
+ 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");
+}
+
+
+/*
+ display a table element
+*/
+function table_element(i, o) {
+ write("<tr><td>" + i + "</td><td>");
+ if (typeof(o[i]) == "object") {
+ var j, first;
+ 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");
+}
+
+/*
+ display a ejs object as a table. The header is optional
+*/
+function simple_table(v) {
+ if (v.length == 0) {
+ return;
+ }
+ write("<table class=\"data\">\n");
+ var r;
+ for (r in v) {
+ table_element(r, v);
+ }
+ write("</table>\n");
+}
+
+/*
+ display an array of objects, with the header for each element from the given
+ attribute
+*/
+function multi_table(array, header) {
+ var i, n;
+ write("<table class=\"data\">\n");
+ for (i=0;i<array.length;i++) {
+ var r, v = array[i];
+ write('<tr><th colspan="2">' + v[header] + "</th></tr>\n");
+ for (r in v) {
+ if (r != header) {
+ table_element(r, v);
+ }
+ }
+ }
+ write("</table>\n");
+}
+
diff --git a/webapps/scripting/footer_columns.esp b/webapps/scripting/footer_columns.esp
new file mode 100644
index 0000000000..7b5baaf0c8
--- /dev/null
+++ b/webapps/scripting/footer_columns.esp
@@ -0,0 +1,7 @@
+<%
+ /* footer for columns page type */
+%>
+</div>
+</div>
+</body>
+</html>
diff --git a/webapps/scripting/footer_desktop.esp b/webapps/scripting/footer_desktop.esp
new file mode 100644
index 0000000000..5e563dab88
--- /dev/null
+++ b/webapps/scripting/footer_desktop.esp
@@ -0,0 +1,6 @@
+<%
+ /* footer for desktop page type */
+%>
+
+</body>
+</html>
diff --git a/webapps/scripting/footer_plain.esp b/webapps/scripting/footer_plain.esp
new file mode 100644
index 0000000000..31ef8dd4ee
--- /dev/null
+++ b/webapps/scripting/footer_plain.esp
@@ -0,0 +1,7 @@
+<%
+ /* footer for plain page type */
+%>
+</div>
+</div>
+</body>
+</html>
diff --git a/webapps/scripting/forms.js b/webapps/scripting/forms.js
new file mode 100644
index 0000000000..2de9e34462
--- /dev/null
+++ b/webapps/scripting/forms.js
@@ -0,0 +1,112 @@
+/*
+ js functions for forms
+*/
+
+
+/*
+ display a simple form from a ejs Form object
+ caller should fill in
+ f.name = form name
+ f.action = action to be taken on submit (optional, defaults to current page)
+ f.class = css class (optional, defaults to 'form')
+ f.submit = an array of submit labels
+ f.add(name, label, [type], [value]) =
+ Add another element
+ f.element[i].label = element label
+ f.element[i].name = element name (defaults to label)
+ f.element[i].type = element type (defaults to text)
+ f.element[i].value = current value (optional, defaults to "")
+ */
+function form_display() {
+ var f = this;
+ var i, size = 20;
+ write('<form name="' + f.name +
+ '" method="post" action="' + f.action +
+ '" class="' + f.class + '">\n');
+ if (f.element.length > 0) {
+ write("<table>\n");
+ }
+ for (i in f.element) {
+ var e = f.element[i];
+ if (e.name == undefined) {
+ e.name = e.label;
+ }
+ if (e.value == undefined) {
+ e.value = "";
+ }
+ if (strlen(e.value) > size) {
+ size = strlen(e.value) + 4;
+ }
+ }
+ for (i in f.element) {
+ var e = f.element[i];
+ write("<tr>");
+ write("<td>" + e.label + "</td>");
+ if (e.type == "select") {
+ write('<td><select name="' + e.name + '">\n');
+ for (s in e.list) {
+ if (e.value == e.list[s]) {
+ write('<option selected=selected>' + e.list[s] + '</option>\n');
+ } else {
+ write('<option>' + e.list[s] + '</option>\n');
+ }
+ }
+ write('</select></td>\n');
+ } else {
+ var sizestr = "";
+ if (e.type == "text" || e.type == "password") {
+ sizestr = sprintf('size="%d"', size);
+ }
+ writef('<td><input name="%s" type="%s" value="%s" %s /></td>\n',
+ e.name, e.type, e.value, sizestr);
+ }
+ write("</tr>");
+ }
+ if (f.element.length > 0) {
+ write("</table>\n");
+ }
+ for (i in f.submit) {
+ write('<input name="submit" type="submit" value="' + f.submit[i] + '" />\n');
+ }
+ write("</form>\n");
+}
+
+function __addMethod(name, label)
+{
+ var f = this;
+ var i = f.element.length;
+ f.element[i] = new Object();
+ f.element[i].name = name;
+ f.element[i].label = label;
+ f.element[i].type = "text";
+ f.element[i].value = "";
+ if (arguments.length > 2) {
+ f.element[i].type = arguments[2];
+ }
+ if (arguments.length > 3) {
+ f.element[i].value = arguments[3];
+ }
+}
+
+/*
+ create a Form object with the defaults filled in, ready for display()
+ */
+function FormObj(name, num_elements, num_submits)
+{
+ var f = new Object();
+ f.name = name;
+ f.element = new Array(num_elements);
+ f.submit = new Array(num_submits);
+ f.action = session_uri(request.REQUEST_URI);
+ f.class = "defaultform";
+ f.add = __addMethod;
+ for (i in f.element) {
+ f.element[i] = new Object();
+ f.element[i].type = "text";
+ f.element[i].value = "";
+ }
+ f.display = form_display;
+
+ return f;
+}
+
diff --git a/webapps/scripting/header_columns.esp b/webapps/scripting/header_columns.esp
new file mode 100644
index 0000000000..a8ffed984e
--- /dev/null
+++ b/webapps/scripting/header_columns.esp
@@ -0,0 +1,81 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+
+ <title>@@global.page.title</title>
+
+<link rel="stylesheet" href="/style/common.css" type="text/css" media="all" />
+<link rel="stylesheet" href="/style/columns.css" type="text/css" media="all" />
+<link rel="stylesheet" href="/style/swat.css" type="text/css" media="all" />
+
+<!--[if gte IE 5.5]>
+ <style type="text/css">
+ /*<![CDATA[*/
+ .logo_hack {
+filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/logo.png',sizingMethod='scale');
+ }
+ /*]]>*/
+ </style>
+<![endif]-->
+
+<!--[if lte IE 5]>
+ <style type="text/css">
+ /*<![CDATA[*/
+ .logo_hack {
+ background-image:url(/images/logo.gif);
+ background-position:center;
+ background-repeat:no-repeat;
+ top:23.5px;
+ left:-10px;
+ }
+ /*]]>*/
+ </style>
+<![endif]-->
+
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<meta http-equiv="Content-Language" content="en-us" />
+
+</head>
+
+
+<body>
+
+<div id="banner">
+ <div class="stripe"></div>
+ <div class="logout">
+ <b>logged in as @@session.authinfo.username</b>
+ <form method="post" action="/logout.esp@@global.SESSIONURI">
+ <input type="submit" value="Logout" />
+ </form>
+ </div>
+</div>
+
+<div id="logo">
+ <div class="logo_hack"><a href="/@@global.SESSIONURI"><img src="/images/linkpad.gif" alt="SWAT" /></a></div>
+</div>
+
+<div class="slogan">
+ <h4>Samba Web Administration Tool</h4>
+</div>
+
+<div id="nav">
+ <%
+ include("/menu.js");
+ if (form['menu']) {
+ global.page.menu = form['menu'];
+ }
+ swat_menus[global.page.menu].display();
+ if (global.page.menu != "main") {
+ write('<a href="/">Main Menu</a>');
+ }
+ %>
+</div>
+
+<div id="links">
+ <% swat_menus.docs.display(); %>
+</div>
+
+
+<div id="content">
+ <div id="middle" class="center">
diff --git a/webapps/scripting/header_desktop.esp b/webapps/scripting/header_desktop.esp
new file mode 100644
index 0000000000..cf8268f535
--- /dev/null
+++ b/webapps/scripting/header_desktop.esp
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<meta http-equiv="Content-Language" content="en-us" />
+
+ <title>@@global.page.title</title>
+
+<style type="text/css" media="screen">
+body {
+ background-color:#3A6EA5;
+}
+</style>
+
+</head>
+
+<body>
+
diff --git a/webapps/scripting/header_plain.esp b/webapps/scripting/header_plain.esp
new file mode 100644
index 0000000000..ae11b6fc50
--- /dev/null
+++ b/webapps/scripting/header_plain.esp
@@ -0,0 +1,25 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+
+ <title>@@global.page.title</title>
+
+<link rel="stylesheet" href="/style/common.css" type="text/css" media="all" />
+<link rel="stylesheet" href="/style/columns.css" type="text/css" media="all" />
+<link rel="stylesheet" href="/style/swat.css" type="text/css" media="all" />
+</head>
+
+
+<body>
+
+<div id="banner">
+ <div class="stripe"></div>
+</div>
+
+<div class="slogan">
+ <h4>Samba Web Administration Tool</h4>
+</div>
+
+<div id="content">
+ <div class="center">
diff --git a/webapps/scripting/preauth.esp b/webapps/scripting/preauth.esp
new file mode 100644
index 0000000000..84534cacef
--- /dev/null
+++ b/webapps/scripting/preauth.esp
@@ -0,0 +1,49 @@
+<%
+include("/scripting/common.js");
+
+/*
+ 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 str = string_init();
+
+ /* allow the primary web application to do its own authentication */
+ var s = str.split('/', uri);
+ if (s[0] == "" && (s.length == 1 || /* no path provided */
+ s[1] == 'index.html' ||
+ s[1] == "script" ||
+ s[1] == "resource")) {
+ return true;
+ }
+
+ var s = str.split('.', uri);
+ if (s.length < 2) {
+ return false;
+ }
+
+ var ext = s[s.length-1];
+ var allowed = new Array("ico", "gif", "png","css", "js");
+ for (i in allowed) {
+ if (allowed[i] == ext) {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+/* this script is called on every web request. If it produces any
+ output at all then that output is returned and the requested page
+ is not given or processed.
+*/
+if (server['SERVER_PROTOCOL'] == "http" &&
+ server['TLS_SUPPORT'] == "True") {
+ write("redirect to https");
+ redirect("https://" + headers['HOST'] + request['REQUEST_URI']);
+} else if (always_allowed(request['REQUEST_URI']) != true &&
+ session['AUTHENTICATED'] == undefined) {
+ /* present the login page */
+ include("/login.esp");
+}
+%>