* Bring manage app up to date with current Helma.

This commit is contained in:
hns 2005-08-31 13:16:21 +00:00
parent c632c8f8bd
commit 437dfb94d3
33 changed files with 1185 additions and 1152 deletions

67
Application/actions.js Normal file
View file

@ -0,0 +1,67 @@
/**
* renders AppManager
*/
function main_action() {
if (checkAddress() == false)
return;
if (checkAuth(this) == false)
return;
res.data.body = this.renderSkinAsString("main");
renderSkin("global");
}
/**
* prints session- and thread-stats for mrtg-tool
* doesn't check username or password, so that we don't have
* to write them cleartext in a mrtg-configfile but checks the
* remote address.
*/
function mrtg_action() {
if (checkAddress() == false)
return;
if (this.isActive() == false) {
res.write("0\n0\n0\n0\n");
return;
}
if (req.data.action == "sessions") {
res.write(this.sessions.size());
res.write("\n0\n0\n0\n");
} else if (req.data.action == "threads") {
res.write(this.countActiveEvaluators() + "\n");
res.write(this.countEvaluators() + "\n");
res.write("0\n0\n");
} else if (req.data.action == "cache") {
res.write(this.getCacheUsage() + "\n");
res.write(this.getProperty("cachesize", "1000") + "\n");
res.write("0\n0\n");
} else if (req.data.action == "requests") {
// res.write (
} else {
res.write("0\n0\n0\n0\n");
}
}
/**
* performs a redirect to the public site
* (workaround, we can't access application object from docapplication for some reason)
* @see application.url_macro
*/
function redirectpublic_action() {
if (checkAddress() == false) return;
if (checkAuth(this) == false) return;
res.redirect(this.url_macro());
}

View file

@ -1,29 +1,28 @@
/**
* construct an application object so that we can use
* skins for non-active applications too
* @arg name
*/
function constructor(name) {
this.name = name;
* construct an application object so that we can use
* skins for non-active applications too
* @arg name
*/
function constructor(name) {
this.name = name;
}
/**
* of no use, just to avoid error message
*/
function onRequest () {
function onRequest() {
}
/**
* return true/false to determine if application is running
*/
function isActive() {
if ( root.getApplication(this.name)==null )
return false;
else
return true;
function isActive() {
if (root.getApplication(this.name) == null)
return false;
else
return true;
}

View file

@ -2,10 +2,10 @@
* macro rendering a skin
* @param name name of skin
*/
function skin_macro(par) {
if ( par && par.name ) {
this.renderSkin(par.name);
}
function skin_macro(par) {
if (par && par.name) {
this.renderSkin(par.name);
}
}
@ -13,8 +13,8 @@ function skin_macro(par) {
* macro-wrapper for href-function
* @param action name of action to call on this prototype, default main
*/
function href_macro(par) {
return this.href( (par&&par.action)?par.action:"main" );
function href_macro(par) {
return this.href((par && par.action) ? par.action : "main");
}
@ -24,12 +24,12 @@ function href_macro(par) {
* the application (which is using baseURI if set)
*/
function url_macro() {
var str = this.getProperty("absoluteuri");
if ( str!=null && str!="" ) {
return str;
} else {
return this.getRootHref();
}
var str = this.getProperty("absoluteuri");
if (str != null && str != "") {
return str;
} else {
return this.getRootHref();
}
}
@ -37,8 +37,8 @@ function url_macro() {
* Macro returning the title of an application
*/
function title_macro() {
var title = this.name;
return(title);
var title = this.name;
return(title);
}
@ -49,25 +49,25 @@ function title_macro() {
* @param Object Macro parameter object
*/
function description_macro(param) {
var str = "";
var appHome = this.getAppDir();
var f = new File(this.getAppDir().toString(), "description.txt");
if (!f.exists())
f = new File(this.getAppDir().toString(), "doc.html");
if (f.exists()) {
str = f.readAll();
if (str.length > 200)
str = str.substring(0, 200) + "...";
}
return(str);
var str = "";
var appHome = this.getAppDir();
var f = new File(this.getAppDir().toString(), "description.txt");
if (!f.exists())
f = new File(this.getAppDir().toString(), "doc.html");
if (f.exists()) {
str = f.readAll();
if (str.length > 200)
str = str.substring(0, 200) + "...";
}
return(str);
}
/**
* Macro returning the server's uptime nicely formatted
*/
function uptime_macro() {
return formatAge( (java.lang.System.currentTimeMillis()-this.starttime) / 1000 );
function uptime_macro() {
return formatAge((java.lang.System.currentTimeMillis() - this.starttime) / 1000);
}
@ -76,11 +76,11 @@ function uptime_macro() {
* parameter used by global.formatCount
* @see global.formatCount
*/
function countSessions_macro(par) {
if ( this.isActive()==true )
return this.sessions.size() + formatCount(this.sessions.size(),par);
else
return 0;
function countSessions_macro(par) {
if (this.isActive() == true)
return this.sessions.size() + formatCount(this.sessions.size(), par);
else
return 0;
}
@ -91,12 +91,12 @@ function countSessions_macro(par) {
* @see application.countUsers_macro
* @see application.listUsers_macro
*/
function users_macro(par) {
if ( req.data.showusers=="true" ) {
this.listUsers_macro(par);
} else {
this.countUsers_macro(par);
}
function users_macro(par) {
if (req.data.showusers == "true") {
this.listUsers_macro(par);
} else {
this.countUsers_macro(par);
}
}
@ -106,11 +106,11 @@ function users_macro(par) {
* parameter used by global.formatCount
* @see global.formatCount
*/
function countUsers_macro(par) {
if ( this.isActive()==true )
return this.activeUsers.size() + formatCount(this.activeUsers.size(),par);
else
return 0;
function countUsers_macro(par) {
if (this.isActive() == true)
return this.activeUsers.size() + formatCount(this.activeUsers.size(), par);
else
return 0;
}
@ -118,93 +118,93 @@ function countUsers_macro(par) {
* Macro rendering the list of logged-in users if application is active
* @param separator html-code written between elements
*/
function listUsers_macro(par) {
var separator = (par && par.separator) ? par.separator : ", ";
if ( this.activeUsers.size()==0 )
return "";
var e = this.activeUsers.keys();
while ( e.hasMoreElements() ) {
res.write ( e.nextElement() );
if ( e.hasMoreElements() ) {
res.write ( separator );
}
}
function listUsers_macro(par) {
var separator = (par && par.separator) ? par.separator : ", ";
if (this.activeUsers.size() == 0)
return "";
var users = this.activeUsers.iterator();
while (users.hasNext()) {
res.write(users.next().__name__);
if (users.hasNext()) {
res.write(separator);
}
}
}
/**
* Macro returning the number of active evaluators (=threads)
*/
function countActiveEvaluators_macro() {
return this.countActiveEvaluators();
function countActiveEvaluators_macro() {
return this.countActiveEvaluators();
}
/**
* Macro returning the number of free evaluators (=threads)
*/
function countFreeEvaluators_macro() {
return this.countFreeEvaluators();
function countFreeEvaluators_macro() {
return this.countFreeEvaluators();
}
/**
* Macro returning the current number of objects in the cache
*/
function cacheusage_macro (param) {
return this.getCacheUsage ();
function cacheusage_macro(param) {
return this.getCacheUsage();
}
/**
* Macro returning the number of objects allowed in the cache
*/
function cachesize_macro (param) {
return this.getProperty ("cachesize", "1000");
function cachesize_macro(param) {
return this.getProperty("cachesize", "1000");
}
/**
* Macro formatting the number of requests in the last 5 minutes
*/
function requestCount_macro(par) {
if (app.data.stat==null || app.data.stat.get (this.name)==null)
return "not available";
if (this.isActive()) {
var obj = app.data.stat.get (this.name);
return obj.requestCount + formatCount (obj.requestCount, par);
} else {
return 0 + formatCount (0,par);
}
function requestCount_macro(par) {
if (app.data.stat == null || app.data.stat[this.name] == null)
return "not available";
if (this.isActive()) {
var obj = app.data.stat[this.name];
return obj.requestCount + formatCount(obj.requestCount, par);
} else {
return 0 + formatCount(0, par);
}
}
/**
* Macro formatting the number of errors in the last 5 minutes
*/
function errorCount_macro(par) {
if (app.data.stat==null || app.data.stat.get (this.name)==null)
return "not available";
if (this.isActive()) {
var obj = app.data.stat.get (this.name);
return obj.errorCount + formatCount (obj.errorCount, par);
} else {
return 0 + formatCount (0,par);
}
function errorCount_macro(par) {
if (app.data.stat == null || app.data.stat[this.name] == null)
return "not available";
if (this.isActive()) {
var obj = app.data.stat[this.name];
return obj.errorCount + formatCount(obj.errorCount, par);
} else {
return 0 + formatCount(0, par);
}
}
/**
* Macro formatting app.properties
*/
function properties_macro(par) {
formatProperties( this.getProperties(), par );
* Macro formatting app.properties
*/
function properties_macro(par) {
formatProperties(this.getProperties(), par);
}
function appdir_macro (param) {
return this.getAppDir ().toString ();
function repositories_macro(param) {
var repos = this.getRepositories().iterator();
while (repos.hasNext())
res.writeln(repos.next().getName());
}

View file

@ -1,12 +0,0 @@
/**
* renders AppManager
*/
if (checkAddress()==false)
return;
if (checkAuth(this)==false)
return;
res.data.body = this.renderSkinAsString("main");
renderSkin ("global");

View file

@ -47,9 +47,9 @@
<td class="list_property" align="left"><% this.uptime %></td>
</tr>
<tr>
<td class="list_property" align="left">app directory</td>
<td class="list_property" align="left" valign="top">repositories</td>
<td class="list_property" width="5">&nbsp;</td>
<td class="list_property" align="left"><% this.appdir %></td>
<td class="list_property" align="left"><% this.repositories %></td>
</tr>
</table>

View file

@ -1,42 +0,0 @@
/**
* prints session- and thread-stats for mrtg-tool
* doesn't check username or password, so that we don't have
* to write them cleartext in a mrtg-configfile but checks the
* remote address.
*/
if ( checkAddress()==false )
return;
if ( this.isActive()==false ) {
res.write ( "0\n0\n0\n0\n");
return;
}
if (req.data.action=="sessions") {
res.write (this.sessions.size());
res.write ("\n0\n0\n0\n");
} else if (req.data.action=="threads") {
res.write (this.countActiveEvaluators () + "\n");
res.write (this.countEvaluators () + "\n");
res.write ("0\n0\n");
} else if (req.data.action=="cache") {
res.write (this.getCacheUsage () + "\n");
res.write (this.getProperty ("cachesize", "1000") + "\n");
res.write ("0\n0\n");
} else if (req.data.action=="requests") {
// res.write (
} else {
res.write ( "0\n0\n0\n0\n");
}

View file

@ -1,10 +0,0 @@
/**
* performs a redirect to the public site
* (workaround, we can't access application object from docapplication for some reason)
* @see application.url_macro
*/
if ( checkAddress()==false ) return;
if ( checkAuth(this)==false ) return;
res.redirect ( this.url_macro() );

View file

@ -1,59 +1,59 @@
function read_action () {
this.readApplication ();
res.redirect (this.href("main"));
function read_action() {
this.readApplication();
res.redirect(this.href("main"));
}
function main_action () {
if (checkAddress()==false)
return;
if (checkAuth(this.getParentElement ())==false)
return;
this.renderSkin ("frameset");
function main_action() {
if (checkAddress() == false)
return;
if (checkAuth(this.getParentElement()) == false)
return;
this.renderSkin("frameset");
}
function prototypes_action () {
if (checkAddress()==false)
return;
if (checkAuth(this.getParentElement ())==false)
return;
res.data.body = this.renderSkinAsString ("prototypes");
renderSkin ("api");
function prototypes_action() {
if (checkAddress() == false)
return;
if (checkAuth(this.getParentElement()) == false)
return;
res.data.body = this.renderSkinAsString("prototypes");
renderSkin("api");
}
function summary_action () {
if (checkAddress()==false)
return;
if (checkAuth(this.getParentElement ())==false)
return;
res.data.body = this.renderSkinAsString ("summary");
renderSkin ("api");
function summary_action() {
if (checkAddress() == false)
return;
if (checkAuth(this.getParentElement()) == false)
return;
res.data.body = this.renderSkinAsString("summary");
renderSkin("api");
}
function functionindex_action () {
if (checkAddress()==false)
return;
if (checkAuth(this.getParentElement ())==false)
return;
res.data.body = this.renderSkinAsString ("functionindex");
renderSkin ("api");
function functionindex_action() {
if (checkAddress() == false)
return;
if (checkAuth(this.getParentElement()) == false)
return;
res.data.body = this.renderSkinAsString("functionindex");
renderSkin("api");
}
function render_action () {
// set res.data.rendering, this will suppress the link back to the manage
// console in the apidocs actions
res.data.rendering = true;
if (checkAddress()==false)
return;
if (checkAuth(this.getParentElement ())==false)
return;
var ct = this.renderApi();
res.data.body = '<body>rendering API ...<br/>wrote ' + ct + ' files<br/><br/>';
res.data.body += '<a href="' + root.href ("main") + '">back to manage console</a>';
res.data.title = "rendering helma api";
res.data.head = renderSkinAsString("head");
renderSkin ("basic");
function render_action() {
// set res.data.rendering, this will suppress the link back to the manage
// console in the apidocs actions
res.data.rendering = true;
if (checkAddress() == false)
return;
if (checkAuth(this.getParentElement()) == false)
return;
var ct = this.renderApi();
res.data.body = '<body>rendering API ...<br/>wrote ' + ct + ' files<br/><br/>';
res.data.body += '<a href="' + root.href("main") + '">back to manage console</a>';
res.data.title = "rendering helma api";
res.data.head = renderSkinAsString("head");
renderSkin("basic");
}

View file

@ -1,90 +1,89 @@
/**
* get the prototype of any doc-object (either a prototype, a function or a tag)
*/
function getDocPrototype (obj) {
var tmp = obj;
while (tmp!=null && tmp.getType () != this.PROTOTYPE) {
tmp = tmp.getParentElement ();
}
return tmp;
* get the prototype of any doc-object (either a prototype, a function or a tag)
*/
function getDocPrototype(obj) {
var tmp = obj;
while (tmp != null && tmp.getType() != this.PROTOTYPE) {
tmp = tmp.getParentElement();
}
return tmp;
}
/**
* get a prototype of this docapplication, ie get on of the children of this object
*/
function getPrototype (name) {
return this.getChildElement ("prototype_" + name);
function getPrototype(name) {
return this.getChildElement("prototype_" + name);
}
function getDir (dir, obj) {
dir.mkdir ();
if (obj.getType () == this.APPLICATION) {
return dir;
} else {
var protoObj = this.getDocPrototype (obj);
var dir = new File (dir, protoObj.getElementName ());
dir.mkdir ();
return dir;
}
function getDir(dir, obj) {
dir.mkdir();
if (obj.getType() == this.APPLICATION) {
return dir;
} else {
var protoObj = this.getDocPrototype(obj);
var dir = new File (dir, protoObj.getElementName());
dir.mkdir();
return dir;
}
}
function renderApi() {
var prefix = this.href ("");
this.storePage (this, "main", "", "index.html");
this.storePage (this, "prototypes");
this.storePage (this, "summary");
this.storePage (this, "functionindex");
var ct = 4;
var arr = this.listChildren ();
for (var i=0; i<arr.length; i++) {
this.storePage (arr[i], "list", "../");
this.storePage (arr[i], "main", "../");
ct += 2;
var subarr = arr[i].listChildren ();
for (var j=0; j<subarr.length; j++) {
this.storePage (subarr[j], "main", "../", subarr[j].getElementName () + ".html");
ct += 1;
}
}
return ct;
var prefix = this.href("");
this.storePage(this, "main", "", "index.html");
this.storePage(this, "prototypes");
this.storePage(this, "summary");
this.storePage(this, "functionindex");
var ct = 4;
var arr = this.listChildren();
for (var i = 0; i < arr.length; i++) {
this.storePage(arr[i], "list", "../");
this.storePage(arr[i], "main", "../");
ct += 2;
var subarr = arr[i].listChildren();
for (var j = 0; j < subarr.length; j++) {
this.storePage(subarr[j], "main", "../", subarr[j].getElementName() + ".html");
ct += 1;
}
}
return ct;
}
function storePage (obj, action, backPath, filename) {
if (filename==null)
var filename = action + ".html";
var str = this.getPage (obj, action, backPath);
var appObj = this.getParentElement ();
var dir = new File (appObj.getAppDir ().getAbsolutePath (), ".docs");
dir = this.getDir (dir, obj);
var f = new File (dir, filename);
f.remove ();
f.open ();
f.write (str);
f.close ();
app.log ("wrote file " + f.getAbsolutePath());
function storePage(obj, action, backPath, filename) {
if (filename == null)
var filename = action + ".html";
var str = this.getPage(obj, action, backPath);
var appObj = this.getParentElement();
var dir = new File (appObj.getAppDir().getAbsolutePath(), ".docs");
dir = this.getDir(dir, obj);
var f = new File (dir, filename);
f.remove();
f.open();
f.write(str);
f.close();
app.log("wrote file " + f.getAbsolutePath());
}
function getPage (obj, action, backPath) {
backPath = (backPath==null) ? "" : backPath;
res.pushStringBuffer ();
eval ("obj." + action + "_action ();");
var str = res.popStringBuffer ();
// get the baseURI out of the url and replace
// it with the given relative prefix
// (keep anchors in regex!)
var reg = new RegExp ("href=\"" + this.href ("") + "([^\"#]+)([^\"]*)\"", "gim");
str = str.replace (reg, "href=\"" + backPath + "$1.html$2\"");
var reg = new RegExp ("src=\"" + this.href ("") + "([^\"#]+)([^\"]*)\"", "gim");
str = str.replace (reg, "src=\"" + backPath + "$1.html$2\"");
// shorten links, so that function files can move up one directory
// in the hierarchy
var reg = new RegExp ("(prototype_[^/]+/[^/]+)/main.html", "gim");
str = str.replace (reg, "$1.html");
function getPage(obj, action, backPath) {
backPath = (backPath == null) ? "" : backPath;
res.pushStringBuffer();
eval("obj." + action + "_action ();");
var str = res.popStringBuffer();
// get the baseURI out of the url and replace
// it with the given relative prefix
// (keep anchors in regex!)
var reg = new RegExp ("href=\"" + this.href("") + "([^\"#]+)([^\"]*)\"", "gim");
str = str.replace(reg, "href=\"" + backPath + "$1.html$2\"");
var reg = new RegExp ("src=\"" + this.href("") + "([^\"#]+)([^\"]*)\"", "gim");
str = str.replace(reg, "src=\"" + backPath + "$1.html$2\"");
// shorten links, so that function files can move up one directory
// in the hierarchy
var reg = new RegExp ("(prototype_[^/]+/[^/]+)/main.html", "gim");
str = str.replace(reg, "$1.html");
return str;
}

View file

@ -1,51 +1,64 @@
/**
* macro rendering a skin
* @param name name of skin
*/
function skin_macro(par) {
if ( par && par.name ) {
this.renderSkin(par.name);
}
* macro rendering a skin
* @param name name of skin
*/
function skin_macro(par) {
if (par && par.name) {
this.renderSkin(par.name);
}
}
/**
* macro-wrapper for href-function
* @param action name of action to call on this prototype, default main
*/
function href_macro(param) { return this.href ((param && param.action) ? param.action : "main"); }
function href_macro(param) {
return this.href((param && param.action) ? param.action : "main");
}
function comment_macro (param) { return renderComment (this, param); }
function content_macro (param) { return this.getContent (); }
function tags_macro (param) { return renderTags (this, param); }
function location_macro (param) { return renderLocation (this, param); }
function link_macro (param) { return renderLink (this, param); }
function comment_macro(param) {
return renderComment(this, param);
}
function content_macro(param) {
return this.getContent();
}
function tags_macro(param) {
return renderTags(this, param);
}
function location_macro(param) {
return renderLocation(this, param);
}
function link_macro(param) {
return renderLink(this, param);
}
//// END OF COPIED FUNCTIONS
function linkToManage_macro (param) {
if (res.data.rendering != true) {
return ('<a href="' + root.href ("main") + '" target="_top">back to manage console</a>');
}
function linkToManage_macro(param) {
if (res.data.rendering != true) {
return ('<a href="' + root.href("main") + '" target="_top">back to manage console</a>');
}
}
function headline_macro (param) {
res.write (this.getName ());
function headline_macro(param) {
res.write(this.getName());
}
function hrefRoot_macro (param) {
var obj = this.getChildElement ("prototype_root");
if (obj == null) {
var obj = this.getChildElement ("prototype_Root");
}
if (obj!=null) {
var action = (param.action) ? param.action : "main";
return obj.href (action);
}
function hrefRoot_macro(param) {
var obj = this.getChildElement("prototype_root");
if (obj == null) {
var obj = this.getChildElement("prototype_Root");
}
if (obj != null) {
var action = (param.action) ? param.action : "main";
return obj.href(action);
}
}
@ -54,15 +67,15 @@ function hrefRoot_macro (param) {
* @param skin name of skin to render on prototype
* @param separator
*/
function prototypes_macro(param) {
var skin = (param.skin) ? param.skin : "asPrototypeList";
var separator = (param.separator) ? param.separator : "";
var arr = this.listChildren ();
for ( var i=0; i<arr.length; i++ ) {
arr[i].renderSkin(skin);
if (i < arr.length-1)
res.write (separator);
}
function prototypes_macro(param) {
var skin = (param.skin) ? param.skin : "asPrototypeList";
var separator = (param.separator) ? param.separator : "";
var arr = this.listChildren();
for (var i = 0; i < arr.length; i++) {
arr[i].renderSkin(skin);
if (i < arr.length - 1)
res.write(separator);
}
}
@ -71,23 +84,23 @@ function prototypes_macro(param) {
* @param skin name of skin to render on each method
* @param skinSeparator name of skin to render as separator between each letters
*/
function functions_macro(param) {
var skinname = (param.skin) ? param.skin : "asListItem";
var skinIndexSeparator = (param.indexSeparator) ? param.indexSeparator : "indexSeparator";
var separator = (param.separator) ? param.separator : "";
var arr = this.listFunctions ();
var lastLetter = "";
for (var i=0; i<arr.length; i++) {
if (arr[i].getName ().substring (0,1)!=lastLetter) {
lastLetter = arr[i].getName ().substring (0,1);
var tmp = new Object ();
tmp.letter = lastLetter.toUpperCase ();
this.renderSkin (skinIndexSeparator, tmp);
}
arr[i].renderSkin (skinname);
if (i < arr.length-1)
res.write (separator);
}
function functions_macro(param) {
var skinname = (param.skin) ? param.skin : "asListItem";
var skinIndexSeparator = (param.indexSeparator) ? param.indexSeparator : "indexSeparator";
var separator = (param.separator) ? param.separator : "";
var arr = this.listFunctions();
var lastLetter = "";
for (var i = 0; i < arr.length; i++) {
if (arr[i].getName().substring(0, 1) != lastLetter) {
lastLetter = arr[i].getName().substring(0, 1);
var tmp = new Object ();
tmp.letter = lastLetter.toUpperCase();
this.renderSkin(skinIndexSeparator, tmp);
}
arr[i].renderSkin(skinname);
if (i < arr.length - 1)
res.write(separator);
}
}

View file

@ -1,10 +1,10 @@
function main_action () {
if (checkAddress()==false)
return;
if (checkAuth()==false)
return;
res.data.body = this.renderSkinAsString ("main");
renderSkin ("api");
function main_action() {
if (checkAddress() == false)
return;
if (checkAuth() == false)
return;
res.data.body = this.renderSkinAsString("main");
renderSkin("api");
}

View file

@ -1,85 +1,97 @@
/**
* macro rendering a skin
* @param name name of skin
*/
function skin_macro(par) {
if ( par && par.name ) {
this.renderSkin(par.name);
}
* macro rendering a skin
* @param name name of skin
*/
function skin_macro(par) {
if (par && par.name) {
this.renderSkin(par.name);
}
}
/**
* macro-wrapper for href-function
* @param action name of action to call on this prototype, default main
*/
function href_macro(param) { return this.href ((param && param.action) ? param.action : "main"); }
function href_macro(param) {
return this.href((param && param.action) ? param.action : "main");
}
function comment_macro (param) { return renderComment (this, param); }
function content_macro (param) { return this.getContent (); }
function tags_macro (param) { return renderTags (this, param); }
function location_macro (param) { return renderLocation (this, param); }
function link_macro (param) { return renderLink (this, param); }
function comment_macro(param) {
return renderComment(this, param);
}
function content_macro(param) {
return this.getContent();
}
function tags_macro(param) {
return renderTags(this, param);
}
function location_macro(param) {
return renderLocation(this, param);
}
function link_macro(param) {
return renderLink(this, param);
}
//// END OF COPIED FUNCTIONS
function headline_macro (param) {
var p = this.getParentElement ();
var handler = (p!=null) ? p.getName () : "";
if (this.getType () == this.ACTION) {
res.write ("/" + this.getName ());
} else if (this.getType () == this.FUNCTION) {
if (handler!="" && handler!="global")
res.write (handler + ".");
res.write (this.getName () + "&nbsp;(");
var arr = this.listParameters ();
for (var i=0; i<arr.length; i++) {
res.write (arr[i]);
if (i<arr.length-1) {
res.write (",&nbsp");
}
}
res.write (")");
} else if (this.getType () == this.MACRO) {
res.write ("&lt;%&nbsp;");
if (handler!="" && handler!="global")
res.write (handler + ".");
var name = this.getName ();
if (name.indexOf("_macro")>-1)
name = name.substring (0, name.length-6);
res.write (name);
res.write ("&nbsp;%&gt;");
} else if (this.getType () == this.SKIN) {
if (handler!="" && handler!="global")
res.write (handler + "/");
res.write (this.getName ());
res.write (".skin");
}
function headline_macro(param) {
var p = this.getParentElement();
var handler = (p != null) ? p.getName() : "";
if (this.getType() == this.ACTION) {
res.write("/" + this.getName());
} else if (this.getType() == this.FUNCTION) {
if (handler != "" && handler != "global")
res.write(handler + ".");
res.write(this.getName() + "&nbsp;(");
var arr = this.listParameters();
for (var i = 0; i < arr.length; i++) {
res.write(arr[i]);
if (i < arr.length - 1) {
res.write(",&nbsp;");
}
}
res.write(")");
} else if (this.getType() == this.MACRO) {
res.write("&lt;%&nbsp;");
if (handler != "" && handler != "global")
res.write(handler + ".");
var name = this.getName();
if (name.indexOf("_macro") > -1)
name = name.substring(0, name.length - 6);
res.write(name);
res.write("&nbsp;%&gt;");
} else if (this.getType() == this.SKIN) {
if (handler != "" && handler != "global")
res.write(handler + "/");
res.write(this.getName());
res.write(".skin");
} else if (this.getType() == this.PROPERTIES) {
res.write(this.getName());
}
}
function skinparameters_macro (param) {
if (this.getType () == this.SKIN) {
this.parameters_macro (param);
}
function skinparameters_macro(param) {
if (this.getType() == this.SKIN) {
this.parameters_macro(param);
}
}
function parameters_macro (param) {
var separator = (param.separator) ? param.separator : ", ";
var arr = this.listParameters ();
for (var i=0; i<arr.length ;i++) {
res.write (arr[i]);
if (i<arr.length-1)
res.write (separator);
}
function parameters_macro(param) {
var separator = (param.separator) ? param.separator : ", ";
var arr = this.listParameters();
for (var i = 0; i < arr.length; i++) {
res.write(arr[i]);
if (i < arr.length - 1)
res.write(separator);
}
}
function type_macro (param) {
return this.getTypeName ();
function type_macro(param) {
return this.getTypeName();
}
@ -89,15 +101,15 @@ function type_macro (param) {
*/
function source_macro(param) {
var sourcecode = this.getContent();
if (param.as=="highlighted") {
if (param.as == "highlighted") {
sourcecode = encode(sourcecode);
// highlight macro tags
r = new RegExp("&lt;%","gim");
r = new RegExp("&lt;%", "gim");
sourcecode = sourcecode.replace(r, '<font color="#aa3300">&lt;%');
r = new RegExp("%&gt;","gim");
r = new RegExp("%&gt;", "gim");
sourcecode = sourcecode.replace(r, '%&gt;</font>');
// highlight js-comments
@ -113,24 +125,24 @@ function source_macro(param) {
}
// remove all CR and LF, just <br> remains
var r = new RegExp("[\\r\\n]","gm");
var r = new RegExp("[\\r\\n]", "gm");
sourcecode = sourcecode.replace(r, "");
var arr = sourcecode.split("<br />");
for (var i=0; i<arr.length; i++) {
res.write('<font color="#aaaaaa">' + (i+1) + ':</font> ');
if (i<99) {
res.write(' ');
}
if (i<9) {
res.write(' ');
}
res.write(arr[i] + "\n");
}
var arr = sourcecode.split("<br />");
for (var i = 0; i < arr.length; i++) {
res.write('<font color="#aaaaaa">' + (i + 1) + ':</font> ');
if (i < 99) {
res.write(' ');
}
if (i < 9) {
res.write(' ');
}
res.write(arr[i] + "\n");
}
} else {
res.write(sourcecode);
}
} else {
res.write(sourcecode);
}
}

View file

@ -1,18 +1,18 @@
function list_action () {
if (checkAddress()==false)
return;
if (checkAuth()==false)
return;
res.data.body = this.renderSkinAsString ("list");
renderSkin ("api");
function list_action() {
if (checkAddress() == false)
return;
if (checkAuth() == false)
return;
res.data.body = this.renderSkinAsString("list");
renderSkin("api");
}
function main_action () {
if (checkAddress()==false)
return;
if (checkAuth()==false)
return;
res.data.body = this.renderSkinAsString ("main");
renderSkin ("api");
function main_action() {
if (checkAddress() == false)
return;
if (checkAuth() == false)
return;
res.data.body = this.renderSkinAsString("main");
renderSkin("api");
}

View file

@ -7,7 +7,6 @@
<% this.methods separator=", " filter="functions" skin="asParentListItem" prefix="<b>Functions: </b>" suffix="<br/>" %>
<% this.methods separator=", " filter="macros" skin="asParentListItem" prefix="<b>Macros: </b>" suffix="<br/>" %>
<% this.methods separator=", " filter="skins" skin="asParentListItem" prefix="<b>Skins: </b>" suffix="<br/>" %>
<% this.methods separator=", " filter="templates" skin="asParentListItem" prefix="<b>Templates: </b>" suffix="<br/>" %>
</td></tr>

View file

@ -1,4 +1,3 @@
///**
// * utility function for head_macro, rendering link to app and to prototype
// */
@ -10,25 +9,24 @@
//}
function translateType (filter) {
if (filter=="actions")
return Packages.helma.doc.DocElement.ACTION;
else if (filter=="templates")
return Packages.helma.doc.DocElement.TEMPLATE;
else if (filter=="functions")
return Packages.helma.doc.DocElement.FUNCTION;
else if (filter=="macros")
return Packages.helma.doc.DocElement.MACRO;
else if (filter=="skins")
return Packages.helma.doc.DocElement.SKIN;
else
return -1;
function translateType(filter) {
if (filter == "actions")
return Packages.helma.doc.DocElement.ACTION;
else if (filter == "functions")
return Packages.helma.doc.DocElement.FUNCTION;
else if (filter == "macros")
return Packages.helma.doc.DocElement.MACRO;
else if (filter == "skins")
return Packages.helma.doc.DocElement.SKIN;
else if (filter == "properties")
return Packages.helma.doc.DocElement.PROPERTIES;
else
return -1;
}
function getApplication () {
return this.getParentElement ();
function getApplication() {
return this.getParentElement();
}

View file

@ -7,5 +7,4 @@
<% this.methods filter="functions" skin="asListItem" prefix="<p><b>Functions:</b><br/>" suffix="</p> %>
<% this.methods filter="macros" skin="asListItem" prefix="<p><b>Macros:</b><br/>" suffix="</p> %>
<% this.methods filter="skins" skin="asListItem" prefix="<p><b>Skins:</b><br/>" suffix="</p> %>
<% this.methods filter="templates" skin="asListItem" prefix="<p><b>Templates:</b><br/>" suffix="</p> %>

View file

@ -1,91 +1,105 @@
/**
* macro rendering a skin
* @param name name of skin
*/
function skin_macro(par) {
if ( par && par.name ) {
this.renderSkin(par.name);
}
* macro rendering a skin
* @param name name of skin
*/
function skin_macro(par) {
if (par && par.name) {
this.renderSkin(par.name);
}
}
/**
* macro-wrapper for href-function
* @param action name of action to call on this prototype, default main
*/
function href_macro(param) { return this.href ((param && param.action) ? param.action : "main"); }
function href_macro(param) {
return this.href((param && param.action) ? param.action : "main");
}
function comment_macro (param) { return renderComment (this, param); }
function content_macro (param) { return this.getContent (); }
function tags_macro (param) { return renderTags (this, param); }
function location_macro (param) { return renderLocation (this, param); }
function link_macro (param) { return renderLink (this, param); }
function comment_macro(param) {
return renderComment(this, param);
}
function content_macro(param) {
return this.getContent();
}
function tags_macro(param) {
return renderTags(this, param);
}
function location_macro(param) {
return renderLocation(this, param);
}
function link_macro(param) {
return renderLink(this, param);
}
//// END OF COPIED FUNCTIONS
function headline_macro (param) {
res.write (this.getName ());
function headline_macro(param) {
res.write(this.getName());
}
/**
* macro formatting list of methods of this prototype
* @param filter actions | functions | macros | templates | skins
* @param filter actions | functions | macros | skins
* @param skin skin to apply to the docfunction object
* @param separator
* @param desc Description that is passed on to the called skin
*/
function methods_macro (param) {
var skinname = (param.skin) ? param.skin : "list";
var separator = (param.separator) ? param.separator : "";
var arr = this.listChildren ();
var type = this.translateType (param.filter);
var sb = new java.lang.StringBuffer ();
for (var i=0; i<arr.length; i++) {
if (arr[i].getType () == type) {
sb.append (arr[i].renderSkinAsString (skinname, param));
sb.append (separator);
}
}
var str = sb.toString ();
if (str.length>0)
return str.substring (0, str.length - separator.length);
else
return str;
function methods_macro(param) {
var skinname = (param.skin) ? param.skin : "list";
var separator = (param.separator) ? param.separator : "";
var arr = this.listChildren();
var type = this.translateType(param.filter);
var sb = new java.lang.StringBuffer ();
for (var i = 0; i < arr.length; i++) {
if (arr[i].getType() == type) {
sb.append(arr[i].renderSkinAsString(skinname, param));
sb.append(separator);
}
}
var str = sb.toString();
if (str.length > 0)
return str.substring(0, str.length - separator.length);
else
return str;
}
function inheritance_macro (param) {
var action = param.action ? param.action : "main";
var target = param.target ? ('target="' + param.target + '" ') : '';
var obj = this.getParentPrototype ();
if (obj!=null) {
obj = this.inheritanceUtil (obj, param);
}
if (param.deep=="true") {
while (obj!=null) {
obj = this.inheritanceUtil (obj, param);
}
}
function inheritance_macro(param) {
var action = param.action ? param.action : "main";
var target = param.target ? ('target="' + param.target + '" ') : '';
var obj = this.getParentPrototype();
if (obj != null) {
obj = this.inheritanceUtil(obj, param);
}
if (param.deep == "true") {
while (obj != null) {
obj = this.inheritanceUtil(obj, param);
}
}
}
function inheritanceUtil (obj, param) {
if (obj.getName ()=="hopobject" && param.hopobject!="true")
return null;
var tmp = new Object ();
for (var i in param)
tmp[i] = param[i];
tmp.href = obj.href ((param.action) ? param.action : "main");
delete tmp.hopobject;
delete tmp.action;
delete tmp.deep;
delete tmp.separator;
res.write (renderLinkTag (tmp));
res.write (obj.getName () + "</a>");
if (obj.getParentPrototype ())
res.write (param.separator);
return obj.getParentPrototype ();
function inheritanceUtil(obj, param) {
if (obj.getName() == "hopobject" && param.hopobject != "true")
return null;
var tmp = new Object ();
for (var i in param)
tmp[i] = param[i];
tmp.href = obj.href((param.action) ? param.action : "main");
delete tmp.hopobject;
delete tmp.action;
delete tmp.deep;
delete tmp.separator;
res.write(renderLinkTag(tmp));
res.write(obj.getName() + "</a>");
if (obj.getParentPrototype())
res.write(param.separator);
return obj.getParentPrototype();
}
@ -94,15 +108,15 @@ function inheritanceUtil (obj, param) {
* if it has got any functions.
* @param skin
*/
function parentPrototype_macro (param) {
var skinname = (param.skin) ? param.skin : "asParentList";
var obj = this.getParentPrototype ();
while (obj!=null) {
if (obj.listChildren ().length>0) {
obj.renderSkin (skinname);
}
obj = obj.getParentPrototype ();
}
function parentPrototype_macro(param) {
var skinname = (param.skin) ? param.skin : "asParentList";
var obj = this.getParentPrototype();
while (obj != null) {
if (obj.listChildren().length > 0) {
obj.renderSkin(skinname);
}
obj = obj.getParentPrototype();
}
}
/**
@ -110,33 +124,42 @@ function parentPrototype_macro (param) {
* type-properties or not.
* @param skin
*/
function typeProperties_macro (param) {
var props = this.getTypeProperties ();
if (props!=null && props.getContent ()!="" ) {
var sb = new java.lang.StringBuffer ();
// map of all mappings....
var mappings = props.getMappings ();
// parse type.properties linewise:
var arr = props.getContent ().split ("\n");
for (var i=0; i<arr.length; i++) {
arr [i] = arr[i].trim ();
// look up in mappings table if line matches:
for (var e = mappings.keys (); e.hasMoreElements (); ) {
var key = e.nextElement ();
var reg = new RegExp ('^' + key + '\\s');
if (arr[i].match (reg)) {
// it matched, wrap line in a link to that prototype:
var docProtoObj = this.getApplication ().getPrototype (mappings.getProperty (key));
if (docProtoObj!=null) {
arr[i] = '<a href="' + docProtoObj.href ("main") + '#typeproperties">' + arr[i] + '</a>';
}
}
}
sb.append (arr[i] + "\n");
}
var tmp = new Object ();
tmp.content = sb.toString ();
var skinname = (param.skinname) ? param.skinname : "typeproperties";
this.renderSkin (skinname, tmp);
}
function typeProperties_macro(param) {
var props = this.getTypeProperties();
var iter = props.getResources();
while (iter.hasNext()) {
var tmp = this.renderTypePropertiesResource(iter.next(), props);
var skinname = (param.skinname) ? param.skinname : "typeproperties";
this.renderSkin(skinname, tmp);
}
}
function renderTypePropertiesResource(res, props) {
if (res.getContent() != "") {
var sb = new java.lang.StringBuffer ();
// map of all mappings....
var mappings = props.getMappings();
// parse type.properties linewise:
var arr = res.getContent().split("\n");
for (var i = 0; i < arr.length; i++) {
arr [i] = arr[i].trim();
// look up in mappings table if line matches:
for (var e = mappings.keys(); e.hasMoreElements();) {
var key = e.nextElement();
var reg = new RegExp ('^' + key + '\\s');
if (arr[i].match(reg)) {
// it matched, wrap line in a link to that prototype:
var docProtoObj = this.getApplication().getPrototype(mappings.getProperty(key));
if (docProtoObj != null) {
arr[i] = '<a href="' + docProtoObj.href("main") + '#typeproperties">' + arr[i] + '</a>';
}
}
}
sb.append(arr[i] + "\n");
}
var tmp = new Object ();
tmp.content = sb.toString();
tmp.source = res.getName();
return tmp;
}
}

View file

@ -11,7 +11,6 @@
<a class="navig" href="#functions">FUNCTIONS</a> |
<a class="navig" href="#macros">MACROS</a> |
<a class="navig" href="#skins">SKINS</a> |
<a class="navig" href="#templates">TEMPLATES</a> |
<a class="navig" href="#typeproperties">TYPE.PROPERTIES</a>
<br/><br/>
@ -62,9 +61,9 @@
%>
<% this.methods separator="<tr><td class='mainbox'><img src='' width=0 height=0></td></tr>"
filter="templates"
skin="asLargeListItem"
prefix="<tr><td class='headline'>Templates<a name='templates'><!-- --></a></td></tr>"
filter="properties"
skin="asLargeListItemSkin"
prefix="<tr><td class='headline'>type.properties<a name='typeproperties'><!-- --></a></td></tr>"
suffix="<tr><td height='8'>&nbsp;</td></tr>
%>
@ -73,7 +72,7 @@
<br/><br/>
<% this.typeProperties %>
<!-- % this.typeProperties % -->

View file

@ -1,6 +1,6 @@
<a name='typeproperties'><!-- --></a>
<table width='90%' border='0' cellspacing='1' cellpadding='5'><tr>
<td class="headline">type.properties</td>
<td class="headline">type.properties in <% param.source %></td>
</tr>
<tr>
<td class="mainbox"><pre><% param.content %></pre></td>

View file

@ -1,11 +1,9 @@
/**
* scheduler function, runs global.appStat every minute
*/
* scheduler function, runs global.appStat every minute
*/
function scheduler() {
appStat();
return 60000;
appStat();
return 60000;
}
@ -14,8 +12,8 @@ function scheduler() {
* creates app.data.addressFilter
*/
function onStart() {
app.data.addressFilter = createAddressFilter();
app.data.addressString = root.getProperty ("allowadmin");
app.data.addressFilter = createAddressFilter();
app.data.addressString = root.getProperty("allowadmin");
}
/**
@ -23,80 +21,80 @@ function onStart() {
* hostnames are converted, wildcards are only allowed in ip-addresses
* (so, no network-names, sorry)
*/
function createAddressFilter() {
var filter = new Packages.helma.util.InetAddressFilter();
var str = root.getProperty("allowadmin");
if ( str!=null && str!="" ) {
var arr = str.split(",");
for ( var i in arr ) {
var str = new java.lang.String(arr[i]);
function createAddressFilter() {
var filter = new Packages.helma.util.InetAddressFilter();
var str = root.getProperty("allowadmin");
if (str != null && str != "") {
var arr = str.split(",");
for (var i in arr) {
str = new java.lang.String(arr[i]);
try {
filter.addAddress(str.trim());
} catch (a) {
try {
var str = java.net.InetAddress.getByName(str.trim()).getHostAddress();
filter.addAddress (str);
str = java.net.InetAddress.getByName(str.trim()).getHostAddress();
filter.addAddress(str);
} catch (b) {
app.log ("error using address " + arr[i] + ": " + b);
app.log("error using address " + arr[i] + ": " + b);
}
}
}
} else {
app.log("no addresses allowed for app manage, all access will be denied");
}
return filter;
}
} else {
app.log("no addresses allowed for app manage, all access will be denied");
}
return filter;
}
/**
* updates the stats in app.data.stat every 5 minutes
*/
function appStat () {
if (app.data.stat==null)
app.data.stat = new HopObject ();
if ((new Date()-300000) < app.data.stat.lastRun)
return;
var arr = root.getApplications ();
for (var i=0; i<arr.length; i++) {
var tmp = app.data.stat.get (arr[i].getName());
if (tmp==null) {
tmp = new HopObject();
tmp.lastTotalRequestCount = 0;
tmp.lastTotalErrorCount = 0;
}
tmp.requestCount = arr[i].getRequestCount () - tmp.lastTotalRequestCount;
tmp.lastTotalRequestCount = arr[i].getRequestCount ();
tmp.errorCount = arr[i].getErrorCount () - tmp.lastTotalErrorCount;
tmp.lastTotalErrorCount = arr[i].getErrorCount ();
app.data.stat.set (arr[i].getName(), tmp);
}
app.data.stat.lastRun = new Date();
function appStat() {
if (app.data.stat == null)
app.data.stat = new HopObject ();
if ((new Date() - 300000) < app.data.stat.lastRun)
return;
var arr = root.getApplications();
for (var i = 0; i < arr.length; i++) {
var tmp = app.data.stat[arr[i].getName()];
if (tmp == null) {
tmp = new HopObject();
tmp.lastTotalRequestCount = 0;
tmp.lastTotalErrorCount = 0;
}
tmp.requestCount = arr[i].getRequestCount() - tmp.lastTotalRequestCount;
tmp.lastTotalRequestCount = arr[i].getRequestCount();
tmp.errorCount = arr[i].getErrorCount() - tmp.lastTotalErrorCount;
tmp.lastTotalErrorCount = arr[i].getErrorCount();
app.data.stat[arr[i].getName()] = tmp;
}
app.data.stat.lastRun = new Date();
}
/**
* utility function to sort object-arrays by name
*/
function sortByName(a,b) {
if (a.name > b.name)
return 1;
else if (a.name == b.name)
return 0;
else
return -1;
function sortByName(a, b) {
if (a.name > b.name)
return 1;
else if (a.name == b.name)
return 0;
else
return -1;
}
/**
* utility function to sort property-arrays by key
*/
function sortProps(a,b) {
if ( a>b )
return 1;
else if ( a==b )
return 0;
else
return -1;
function sortProps(a, b) {
if (a > b)
return 1;
else if (a == b)
return 0;
else
return -1;
}
/**
@ -106,62 +104,62 @@ function sortProps(a,b) {
* object for http-auth and return false.
* @arg appObj application object to check against (if adminUsername etc are set in app.properties)
*/
function checkAuth(appObj) {
if (res && res.data.noWeb==true) {
function checkAuth(appObj) {
if (res && res.data.noWeb == true) {
return true;
}
var ok = false;
var ok = false;
// check against root
var adminAccess = root.getProperty("adminAccess");
// check against root
var adminAccess = root.getProperty("adminAccess");
if (adminAccess==null || adminAccess=="") {
res.redirect (root.href ("makekey"));
}
if (adminAccess == null || adminAccess == "") {
res.redirect(root.href("makekey"));
}
var uname = req.username;
var pwd = req.password;
var uname = req.username;
var pwd = req.password;
if ( uname==null || uname=="" || pwd==null || pwd=="" )
return forceAuth();
if (uname == null || uname == "" || pwd == null || pwd == "")
return forceAuth();
var md5key = Packages.helma.util.MD5Encoder.encode(uname + "-" + pwd);
var md5key = Packages.helma.util.MD5Encoder.encode(uname + "-" + pwd);
if (md5key==adminAccess)
return true;
if (md5key == adminAccess)
return true;
if (appObj!=null && appObj.isActive()) {
// check against application
adminAccess = appObj.getProperty("adminAccess");
if (md5key==adminAccess)
return true;
}
return forceAuth();
if (appObj != null && appObj.isActive()) {
// check against application
adminAccess = appObj.getProperty("adminAccess");
if (md5key == adminAccess)
return true;
}
return forceAuth();
}
/**
* check access to the manage-app by ip-addresses
*/
function checkAddress() {
if (res && res.data.noWeb==true) {
function checkAddress() {
if (res && res.data.noWeb == true) {
return true;
}
// if allowadmin value in server.properties has changed,
// re-construct the addressFilter
if (app.data.addressString != root.getProperty("allowadmin")) {
app.data.addressFilter = createAddressFilter();
app.data.addressString = root.getProperty("allowadmin");
}
if (!app.data.addressFilter.matches(java.net.InetAddress.getByName(req.data.http_remotehost))) {
app.log("denied request from " + req.data.http_remotehost);
// forceStealth seems a bit like overkill here.
// display a message that the ip address must be added to server.properties
res.write("Access from address " + req.data.http_remotehost + " denied.");
return false;
} else {
return true;
}
// if allowadmin value in server.properties has changed,
// re-construct the addressFilter
if (app.data.addressString != root.getProperty ("allowadmin")){
app.data.addressFilter = createAddressFilter();
app.data.addressString = root.getProperty ("allowadmin");
}
if ( !app.data.addressFilter.matches(java.net.InetAddress.getByName(req.data.http_remotehost)) ) {
app.log("denied request from " + req.data.http_remotehost );
// forceStealth seems a bit like overkill here.
// display a message that the ip address must be added to server.properties
res.write ("Access from address "+req.data.http_remotehost+" denied.");
return false;
} else {
return true;
}
}
@ -169,68 +167,67 @@ function checkAddress() {
* response is reset to 401 / authorization required
* @arg realm realm for http-auth
*/
function forceAuth(realm) {
res.reset();
res.status = 401;
res.realm = (realm!=null) ? realm : "helma";
res.write ("Authorization Required. The server could not verify that you are authorized to access the requested page.");
return false;
function forceAuth(realm) {
res.reset();
res.status = 401;
res.realm = (realm != null) ? realm : "helma";
res.write("Authorization Required. The server could not verify that you are authorized to access the requested page.");
return false;
}
/**
* macro-utility: formatting property lists
*/
function formatProperties(props,par) {
if ( props.size()==0 )
return "";
var e = props.keys();
var arr = new Array();
while ( e.hasMoreElements() ) {
arr[arr.length] = e.nextElement();
}
arr.sort(sortProps);
for ( var i in arr ) {
// don't print the admin-password
if ( arr[i].toLowerCase()=="adminusername" || arr[i].toLowerCase()=="adminpassword" ) continue;
res.write ( par.itemprefix + arr[i] + par.separator + props.getProperty(arr[i]) + par.itemsuffix );
}
* macro-utility: formatting property lists
*/
function formatProperties(props, par) {
if (props.size() == 0)
return "";
var e = props.keys();
var arr = new Array();
while (e.hasMoreElements()) {
arr[arr.length] = e.nextElement();
}
arr.sort(sortProps);
for (var i in arr) {
// don't print the admin-password
if (arr[i].toLowerCase() == "adminusername" || arr[i].toLowerCase() == "adminpassword") continue;
res.write(par.itemprefix + arr[i] + par.separator + props.getProperty(arr[i]) + par.itemsuffix);
}
}
/**
* macro-utility: formatting an integer value as human readable bytes
*/
function formatBytes(bytes) {
if ( bytes > Math.pow(2,30) ) {
res.write( Math.round( 100*bytes/Math.pow(2,30) ) / 100 + "gb" );
} else if ( bytes > Math.pow(2,20) ) {
res.write( Math.round( 100*bytes/Math.pow(2,20) ) / 100 + "mb" );
} else {
res.write( Math.round( 100*bytes/Math.pow(2,10) ) / 100 + "kb" );
}
function formatBytes(bytes) {
if (bytes > Math.pow(2, 30)) {
res.write(Math.round(100 * bytes / Math.pow(2, 30)) / 100 + "gb");
} else if (bytes > Math.pow(2, 20)) {
res.write(Math.round(100 * bytes / Math.pow(2, 20)) / 100 + "mb");
} else {
res.write(Math.round(100 * bytes / Math.pow(2, 10)) / 100 + "kb");
}
}
/**
* macro-utility: formatting time in millis as human readable age
*/
function formatAge(age) {
var str = "";
var days = Math.floor(age/86400);
var age = age - days * 86400;
var hours = Math.floor(age / 3600);
var age = age - hours * 3600;
var minutes = Math.floor(age / 60);
var seconds = Math.floor(age - minutes * 60);
if (days > 0)
str += (days + " days, ");
if (hours>0)
str += (hours + "h, ");
str += (minutes + "min");
if (days == 0) str += (", " + seconds + "sec");
return(str);
function formatAge(age) {
var str = "";
var days = Math.floor(age / 86400);
age = age - days * 86400;
var hours = Math.floor(age / 3600);
age = age - hours * 3600;
var minutes = Math.floor(age / 60);
var seconds = Math.floor(age - minutes * 60);
if (days > 0)
str += (days + " days, ");
if (hours > 0)
str += (hours + "h, ");
str += (minutes + "min");
if (days == 0) str += (", " + seconds + "sec");
return(str);
}
@ -241,23 +238,23 @@ function formatAge(age) {
* @param singular string used for value==1
* @param plural string used for value!=1
*/
function formatCount(ct, par) {
if ( !par || !par.singular || !par.plural ) {
return "";
}
if ( ct==1 )
return par.singular;
else
return par.plural;
function formatCount(ct, par) {
if (!par || !par.singular || !par.plural) {
return "";
}
if (ct == 1)
return par.singular;
else
return par.plural;
}
/**
* tries to make out if this server is running linux from java's system properties
*/
function isLinux () {
var str = java.lang.System.getProperty("os.name");
return (str!=null && str.toLowerCase().indexOf("linux")!=-1);
function isLinux() {
var str = java.lang.System.getProperty("os.name");
return (str != null && str.toLowerCase().indexOf("linux") != -1);
}

View file

@ -2,10 +2,10 @@
* macro rendering a skin
* @param name name of skin
*/
function skin_macro(par) {
if ( par && par.name ) {
renderSkin(par.name);
}
function skin_macro(par) {
if (par && par.name) {
renderSkin(par.name);
}
}
@ -13,6 +13,6 @@ function skin_macro(par) {
* Macro returning the actual date and time.
*/
function now_macro() {
var date = new Date();
return(date.format("dd.MM.yyyy, HH:mm'h' zzz"));
var date = new Date();
return(date.format("dd.MM.yyyy, HH:mm'h' zzz"));
}

View file

@ -11,7 +11,7 @@
<p></p>
<div class="list_apps">
<i>and <% root.appCount filter="disabled" %> disabled apps:</i>
<i>disabled apps:</i>
</div>
<% root.appList filter="disabled" skin="navig_disabled" %>

View file

@ -1,95 +1,85 @@
function renderLink (docEl, param) {
var text = "";
if (docEl.getType () == docEl.APPLICATION || docEl.getType () == docEl.PROTOTYPE) {
text = docEl.getName ();
} else if (docEl.getType () == docEl.SKIN) {
text = docEl.getName () + ".skin";
} else if (docEl.getType () == docEl.MACRO) {
if (param.handler!="false" && docEl.getParentElement () && docEl.getParentElement().getName()!="global") {
text = docEl.getParentElement ().getName () + ".";
}
var str = docEl.getName ();
if (str.indexOf("_macro")) {
text += str.substring (0, str.length-6);
}
} else if (docEl.getType () == docEl.FUNCTION) {
var text = docEl.getName () + "(";
var arr = docEl.listParameters ();
for (var i=0; i<arr.length ;i++) {
text += arr[i];
if (i<arr.length-1)
text += ",&nbsp;";
}
text += ")";
} else {
text = docEl.getName ();
}
param.href = docEl.href ("main");
if (!param.target) {
param.target = "main";
}
return renderLinkTag (param) + text + '</a>';
function renderLink(docEl, param) {
var text = "";
if (docEl.getType() == docEl.APPLICATION || docEl.getType() == docEl.PROTOTYPE) {
text = docEl.getName();
} else if (docEl.getType() == docEl.SKIN) {
text = docEl.getName() + ".skin";
} else if (docEl.getType() == docEl.MACRO) {
if (param.handler != "false" && docEl.getParentElement() && docEl.getParentElement().getName() != "global") {
text = docEl.getParentElement().getName() + ".";
}
var str = docEl.getName();
if (str.indexOf("_macro")) {
text += str.substring(0, str.length - 6);
}
} else if (docEl.getType() == docEl.FUNCTION) {
text = docEl.getName() + "(";
var arr = docEl.listParameters();
for (var i = 0; i < arr.length; i++) {
text += arr[i];
if (i < arr.length - 1)
text += ",&nbsp;";
}
text += ")";
} else {
text = docEl.getName();
}
param.href = docEl.href("main");
if (!param.target) {
param.target = "main";
}
return renderLinkTag(param) + text + '</a>';
}
function renderLinkTag (param) {
var sb = new java.lang.StringBuffer ();
sb.append ('<a');
for (var i in param) {
sb.append (' ');
sb.append (i);
sb.append ('="');
sb.append (param[i]);
sb.append ('"');
}
sb.append ('>');
return sb.toString ();
function renderLinkTag(param) {
var sb = new java.lang.StringBuffer ();
sb.append('<a');
for (var i in param) {
sb.append(' ');
sb.append(i);
sb.append('="');
sb.append(param[i]);
sb.append('"');
}
sb.append('>');
return sb.toString();
}
/**
* renders the name of the location relative to the application
* root.
*/
* renders the name of the location of a doc element.
*/
function renderLocation (docEl, param) {
var f = docEl.getLocation ();
// with repositories, always display full file path
return f.getAbsolutePath();
return docEl.toString();
}
/**
* renders tag list.
* @param param.skin skin to render on found DocTags
* @param param.separator String printed between tags
* @param param.type type string (param|return|author|version|see) to filter tags.
*/
function renderTags (docEl, param) {
var skinname = (param.skin) ? param.skin : "main";
var type = param.type;
if (type=="params")
type = "param";
else if (type=="returns")
type = "return";
else if (type=="arg")
* renders tag list.
* @param param.skin skin to render on found DocTags
* @param param.separator String printed between tags
* @param param.type type string (param|return|author|version|see) to filter tags.
*/
function renderTags(docEl, param) {
var skinname = (param.skin) ? param.skin : "main";
var type = param.type;
if (type == "params")
type = "param";
var str = "";
var arr = docEl.listTags ();
for (var i=0; i<arr.length; i++) {
if (arr[i].getType () == type) {
if (type=="see" || type=="overrides") {
param.link = renderReference (arr[i], docEl);
}
str += arr[i].renderSkinAsString (skinname, param);
str += (param.separator) ? param.separator : "";
}
}
return str;
else if (type == "returns")
type = "return";
else if (type == "arg")
type = "param";
var str = "";
var arr = docEl.listTags();
for (var i = 0; i < arr.length; i++) {
if (arr[i].getType() == type) {
if (type == "see" || type == "overrides") {
param.link = renderReference(arr[i], docEl);
}
str += arr[i].renderSkinAsString(skinname, param);
str += (param.separator) ? param.separator : "";
}
}
return str;
}
@ -100,66 +90,64 @@ function renderTags (docEl, param) {
* @param docTagObj
* @param docEl needed to be able to walk up to application object
*/
function renderReference (docTagObj, docEl) {
// prepare the text:
var text = docTagObj.getText ();
text = new java.lang.String (text);
text = text.trim ();
if (text.indexOf("http://")==0) {
// an url is a simple job
return '<a href="' + text + '" target="_new">' + text + '</a>';
} else {
// make sure we only use the first item in the text so that unlinked comments
// can follow, store & split the that
var tok = new java.util.StringTokenizer (text);
var tmp = tok.nextToken ();
text = " " + text.substring (tmp.length + 1);
var parts = tmp.split(".");
// try to find the application object
var obj = docEl;
while (obj!=null) {
if (obj.getType () == Packages.helma.doc.DocElement.APPLICATION) {
var appObj = obj;
break;
}
obj = obj.getParentElement ();
}
var protoObj = appObj.getChildElement ("prototype_" + parts[0]);
if (protoObj==null) {
// prototype wasn't found, return the unlinked tag
return tmp + text;
}
if (parts.length==1) {
// no function specified, return the linked prototype
return '<a href="' + protoObj.href ("main") + '">' + format (tmp) + '</a>' + text;
}
// try to find a function object:
var arr = protoObj.listChildren ();
for (var i=0; i<arr.length; i++) {
if (arr[i].getName () == parts [1]) {
return '<a href="' + arr[i].href("main") + '">' + format(tmp) + '</a>' + text;
}
}
// function not found:
return tmp + text;
}
function renderReference(docTagObj, docEl) {
// prepare the text:
var text = docTagObj.getText();
text = new java.lang.String (text);
text = text.trim();
if (text.indexOf("http://") == 0) {
// an url is a simple job
return '<a href="' + text + '" target="_new">' + text + '</a>';
} else {
// make sure we only use the first item in the text so that unlinked comments
// can follow, store & split the that
var tok = new java.util.StringTokenizer (text);
var tmp = tok.nextToken();
text = " " + text.substring(tmp.length + 1);
var parts = tmp.split(".");
// try to find the application object
var obj = docEl;
while (obj != null) {
if (obj.getType() == Packages.helma.doc.DocElement.APPLICATION) {
var appObj = obj;
break;
}
obj = obj.getParentElement();
}
var protoObj = appObj.getChildElement("prototype_" + parts[0]);
if (protoObj == null) {
// prototype wasn't found, return the unlinked tag
return tmp + text;
}
if (parts.length == 1) {
// no function specified, return the linked prototype
return '<a href="' + protoObj.href("main") + '">' + format(tmp) + '</a>' + text;
}
// try to find a function object:
var arr = protoObj.listChildren();
for (var i = 0; i < arr.length; i++) {
if (arr[i].getName() == parts [1]) {
return '<a href="' + arr[i].href("main") + '">' + format(tmp) + '</a>' + text;
}
}
// function not found:
return tmp + text;
}
}
/**
* function rendering a comment.
* @param param.length comment is shortened to the given length.
* @returns string
*/
function renderComment (docEl, param) {
var str = docEl.getComment ();
if (param.length) {
if (param.length < str.length) {
return str.substring (0, param.length) + " ...";
}
}
return str;
* function rendering a comment.
* @param param.length comment is shortened to the given length.
* @returns string
*/
function renderComment(docEl, param) {
var str = docEl.getComment();
if (param.length) {
if (param.length < str.length) {
return str.substring(0, param.length) + " ...";
}
}
return str;
}

130
Root/actions.js Normal file
View file

@ -0,0 +1,130 @@
/**
* main action, show server-stats
* perform start, stop, restart and flush-action
*
*/
function main_action() {
if (checkAddress() == false) return;
if (req.data.app != null && req.data.app != "" && req.data.action != null && req.data.action != "") {
var appObj = root.getApp(req.data.app);
// check access for application. md5-encoded uname/pwd can also be put in
// app.properties to limit access to a single app
if (checkAuth(appObj) == false) return;
if (req.data.action == "start") {
this.startApplication(req.data.app);
res.redirect(appObj.href("main"));
} else if (req.data.action == "stop") {
if (checkAuth() == false) return;
this.stopApplication(req.data.app);
res.redirect(root.href("main"));
} else if (req.data.action == "restart") {
this.stopApplication(req.data.app);
this.startApplication(req.data.app);
res.redirect(appObj.href("main"));
} else if (req.data.action == "flush") {
appObj.clearCache();
res.redirect(appObj.href("main"));
}
}
// output only to root
if (checkAuth() == false) return;
res.data.title = "Helma Object Publisher - Serverinfo";
res.data.body = this.renderSkinAsString("main");
renderSkin("global");
}
/**
* return the helma object publisher logo, built into hop core
* to be independent of static html-paths
*/
function image_action() {
if (checkAddress() == false) return;
res.contentType = "image/gif";
res.writeBinary(Packages.helma.util.Logo.hop);
}
function makekey_action() {
if (checkAddress() == false)
return;
var obj = new Object();
obj.msg = "";
if (req.data.username != null && req.data.password != null) {
// we have input from webform
if (req.data.username == "")
obj.msg += "username can't be left empty!<br>";
if (req.data.password == "")
obj.msg += "password can't be left empty!<br>";
if (obj.msg != "") {
obj.username = req.data.username;
res.reset();
res.data.body = renderSkinAsString("pwdform", obj);
} else {
// render the md5-string:
obj.propsString = "adminAccess=" + Packages.helma.util.MD5Encoder.encode(req.data.username + "-" + req.data.password) + "<br>\n";
res.data.body = renderSkinAsString("pwdfeedback", obj);
}
} else {
// no input from webform, so print it
res.data.body = renderSkinAsString("pwdform", obj);
}
res.data.title = "username & password on " + root.hostname_macro();
res.data.head = renderSkinAsString("head");
renderSkin("basic");
}
/**
* prints server-stats for mrtg-tool.
* doesn't check username or password, so that we don't have
* to write them cleartext in a mrtg-configfile but checks the
* remote address.
*/
function mrtg_action() {
if (checkAddress() == false)
return;
if (req.data.action == "memory") {
res.write(this.jvmTotalMemory_macro() + "\n");
res.write(this.jvmFreeMemory_macro() + "\n");
res.write("0\n0\n");
} else if (req.data.action == "netstat" && isLinux()) {
var str = (new File("/proc/net/tcp")).readAll();
var arr = str.split("\n");
res.write(arr.length - 2 + "\n");
res.write("0\n0\n0\n");
} else if (req.data.action == "loadavg" && isLinux()) {
// load average of last 5 minutes:
var str = (new File("/proc/loadavg")).readAll();
var arr = str.split(" ");
res.write(arr[1] * 100 + "\n");
res.write("0\n0\n0\n");
} else {
res.write("0\n0\n0\n0\n");
}
}

View file

@ -1,7 +1,6 @@
/**
* renders the api of a given application. used from commandline.
*/
* renders the api of a given application. used from commandline.
*/
function renderApi(appName) {
// supress security checks when accessing actions
@ -25,15 +24,15 @@ function renderApi(appName) {
* lists all applications in appdir.
* for active apps use this.getApplications() = helma.main.Server.getApplications()
*/
function getAllApplications() {
var appsDir = this.getAppsHome();
var dir = appsDir.list();
var arr = new Array();
for ( var i=0; i<dir.length; i++ ) {
if ( dir[i].toLowerCase()!="cvs" && dir[i].indexOf(".")==-1 )
arr[arr.length] = this.getApp(dir[i]);
}
return arr;
function getAllApplications() {
var appsDir = this.getAppsHome();
var dir = appsDir.list();
var arr = new Array();
for (var i = 0; i < dir.length; i++) {
if (dir[i].toLowerCase() != "cvs" && dir[i].indexOf(".") == -1)
arr[arr.length] = this.getApp(dir[i]);
}
return arr;
}
@ -45,13 +44,13 @@ function getAllApplications() {
* retrieves active applications.
* @arg name of application
*/
function getApp(name) {
if ( name==null || name=="" )
return null;
var appObj = this.getApplication(name);
if ( appObj==null )
appObj = new application(name);
return appObj;
function getApp(name) {
if (name == null || name == "")
return null;
var appObj = this.getApplication(name);
if (appObj == null)
appObj = new Application(name);
return appObj;
}

View file

@ -1,11 +0,0 @@
/**
* return the helma object publisher logo, built into hop core
* to be independent of static html-paths
*/
if ( checkAddress()==false ) return;
res.contentType = "image/gif";
res.writeBinary ( Packages.helma.util.Logo.hop );

View file

@ -2,10 +2,10 @@
* macro rendering a skin
* @param name name of skin
*/
function skin_macro(par) {
if ( par && par.name ) {
this.renderSkin(par.name);
}
function skin_macro(par) {
if (par && par.name) {
this.renderSkin(par.name);
}
}
@ -13,8 +13,8 @@ function skin_macro(par) {
* macro-wrapper for href-function
* @param action name of action to call on this prototype, default main
*/
function href_macro(par) {
return this.href( (par&&par.action)?par.action:"main" );
function href_macro(par) {
return this.href((par && par.action)?par.action:"main");
}
@ -22,15 +22,15 @@ function href_macro(par) {
* macro returning the total number of sessions on this server
* @see global.formatCount
*/
function countSessions_macro(par) {
var arr = this.getApplications();
var sum = 0;
for ( var i=0; i<arr.length; i++ ) {
if ( arr[i].getName()!=app.__app__.getName() ) {
sum += arr[i].sessions.size();
}
}
return sum + formatCount(sum,par);
function countSessions_macro(par) {
var arr = this.getApplications();
var sum = 0;
for (var i = 0; i < arr.length; i++) {
if (arr[i].getName() != app.__app__.getName()) {
sum += arr[i].sessions.size();
}
}
return sum + formatCount(sum, par);
}
@ -38,21 +38,21 @@ function countSessions_macro(par) {
* macro returning the number of requests during the last 5 minutes
* @see global.formatCount
*/
function requestCount_macro(par) {
if (app.data.stat==null) {
return;
}
var arr = this.getApplications ();
var sum = 0;
for (var i=0; i<arr.length; i++) {
if (arr[i].getName() != app.__app__.getName() ) { // don't include manage app
var obj = app.data.stat.get (arr[i].name);
if ( obj!=null ) {
sum += obj.requestCount;
}
}
}
return sum + formatCount (sum,par);
function requestCount_macro(par) {
if (app.data.stat == null) {
return;
}
var arr = this.getApplications();
var sum = 0;
for (var i = 0; i < arr.length; i++) {
if (arr[i].getName() != app.__app__.getName()) { // don't include manage app
var obj = app.data.stat[arr[i].name];
if (obj != null) {
sum += obj.requestCount;
}
}
}
return sum + formatCount(sum, par);
}
@ -60,50 +60,49 @@ function requestCount_macro(par) {
* macro returning the number of errors during the last 5 minutes
* @see global.formatCount
*/
function errorCount_macro(par) {
if (app.data.stat==null) {
return;
}
var arr = this.getApplications ();
var sum = 0;
for (var i=0; i<arr.length; i++) {
if (arr[i].getName() != app.__app__.getName() ) { // don't include manage app
var obj = app.data.stat.get (arr[i].name);
if ( obj!=null ) {
sum += obj.errorCount;
}
}
}
return sum + formatCount (sum,par);
function errorCount_macro(par) {
if (app.data.stat == null) {
return;
}
var arr = this.getApplications();
var sum = 0;
for (var i = 0; i < arr.length; i++) {
if (arr[i].getName() != app.__app__.getName()) { // don't include manage app
var obj = app.data.stat[arr[i].name];
if (obj != null) {
sum += obj.errorCount;
}
}
}
return sum + formatCount(sum, par);
}
function extensions_macro (par) {
var vec = this.getExtensions ();
var str = "";
for (var i=0; i<vec.size(); i++) {
str += vec.elementAt (i).getClass ().getName ();
if (i!=(vec.size()-1)) {
str += (par && par.separator) ? par.separator : ", ";
}
}
return (str=="") ? null : str;
function extensions_macro(par) {
var vec = this.getExtensions();
var str = "";
for (var i = 0; i < vec.size(); i++) {
str += vec.elementAt(i).getClass().getName();
if (i != (vec.size() - 1)) {
str += (par && par.separator) ? par.separator : ", ";
}
}
return (str == "") ? null : str;
}
/**
* Macro returning hostname of this machine
*/
function hostname_macro(par) {
return java.net.InetAddress.getLocalHost().getHostName()
function hostname_macro(par) {
return java.net.InetAddress.getLocalHost().getHostName()
}
/**
* Macro returning address of this machine
*/
function hostaddress_macro(par) {
return java.net.InetAddress.getLocalHost().getHostAddress()
function hostaddress_macro(par) {
return java.net.InetAddress.getLocalHost().getHostAddress()
}
@ -112,14 +111,14 @@ function hostaddress_macro(par) {
* the manage application being excluded.
*/
function appCount_macro(par) {
if ( par && par.filter=="active" ) {
var ct = root.getApplications().length-1;
} else if ( par && par.filter=="disabled" ) {
var ct = root.getAllApplications().length - root.getApplications().length;
} else {
var ct = root.getAllApplications().length-1;
}
return ct + formatCount(ct,par);
if (par && par.filter == "active") {
var ct = root.getApplications().length - 1;
} else if (par && par.filter == "disabled") {
var ct = root.getAllApplications().length - root.getApplications().length;
} else {
var ct = root.getAllApplications().length - 1;
}
return ct + formatCount(ct, par);
}
@ -129,58 +128,58 @@ function appCount_macro(par) {
* @param skin skin of application that will be used.
*/
function appList_macro(par) {
var skin = (par && par.skin) ? par.skin : "navig_active";
var apps = new Array();
if ( par && par.filter=="active" ) {
var arr = root.getApplications();
for ( var i=0; i<arr.length; i++ ) {
apps[apps.length] = arr[i];
}
} else if ( par && par.filter=="disabled" ) {
var arr = root.getAllApplications();
for ( var i in arr ) {
if( arr[i].isActive()==false ) {
apps[apps.length] = arr[i];
}
}
} else {
var apps = root.getAllApplications();
}
apps = apps.sort(sortByName);
var html = "";
var param = new Object();
for (var n in apps) {
var a = apps[n];
if ( apps[n].name==app.__app__.getName() )
continue;
var item = a.renderSkinAsString(skin);
html += item;
}
return(html);
var skin = (par && par.skin) ? par.skin : "navig_active";
var apps = new Array();
if (par && par.filter == "active") {
var arr = root.getApplications();
for (var i = 0; i < arr.length; i++) {
apps[apps.length] = arr[i];
}
} else if (par && par.filter == "disabled") {
var arr = root.getAllApplications();
for (var i in arr) {
if (arr[i].isActive() == false) {
apps[apps.length] = arr[i];
}
}
} else {
var apps = root.getAllApplications();
}
apps = apps.sort(sortByName);
var html = "";
var param = new Object();
for (var n in apps) {
var a = apps[n];
if (apps[n].name == app.__app__.getName())
continue;
var item = a.renderSkinAsString(skin);
html += item;
}
return(html);
}
/**
* Macro that returns the server's uptime nicely formatted
*/
function uptime_macro() {
return formatAge( (java.lang.System.currentTimeMillis()-this.starttime) / 1000 );
function uptime_macro() {
return formatAge((java.lang.System.currentTimeMillis() - this.starttime) / 1000);
}
/**
* Macro that returns the server's version string
*/
function version_macro() {
return this.version;
function version_macro() {
return this.version;
}
/**
* Macro that returns the home directory of the hop installation
*/
function home_macro() {
return this.getHopHome().toString();
function home_macro() {
return this.getHopHome().toString();
}
@ -188,9 +187,9 @@ function home_macro() {
* Macro that returns the free memory in the java virtual machine
* @param format if "hr", value will be printed human readable
*/
function jvmFreeMemory_macro (param) {
var m = java.lang.Runtime.getRuntime ().freeMemory ();
return (param && param.hr) ? formatBytes (m) : m;
function jvmFreeMemory_macro(param) {
var m = java.lang.Runtime.getRuntime().freeMemory();
return (param && param.hr) ? formatBytes(m) : m;
}
@ -198,9 +197,9 @@ function jvmFreeMemory_macro (param) {
* Macro that returns the total memory available to the java virtual machine
* @param format if "hr", value will be printed human readable
*/
function jvmTotalMemory_macro (param) {
var m = java.lang.Runtime.getRuntime().totalMemory();
return (param && param.hr) ? formatBytes (m) : m;
function jvmTotalMemory_macro(param) {
var m = java.lang.Runtime.getRuntime().totalMemory();
return (param && param.hr) ? formatBytes(m) : m;
}
@ -208,25 +207,25 @@ function jvmTotalMemory_macro (param) {
* Macro that returns the used memory in the java virtual machine
* @param format if "hr", value will be printed human readable
*/
function jvmUsedMemory_macro(param) {
var m = java.lang.Runtime.getRuntime ().totalMemory () - java.lang.Runtime.getRuntime ().freeMemory ();
return (param && param.hr) ? formatBytes (m) : m;
function jvmUsedMemory_macro(param) {
var m = java.lang.Runtime.getRuntime().totalMemory() - java.lang.Runtime.getRuntime().freeMemory();
return (param && param.hr) ? formatBytes(m) : m;
}
/**
* Macro that returns the version and type of the java virtual machine
*/
function jvm_macro() {
return java.lang.System.getProperty("java.version") + " " + java.lang.System.getProperty("java.vendor");
function jvm_macro() {
return java.lang.System.getProperty("java.version") + " " + java.lang.System.getProperty("java.vendor");
}
/**
* Macro that returns the home directory of the java virtual machine
*/
function jvmHome_macro() {
return java.lang.System.getProperty("java.home");
function jvmHome_macro() {
return java.lang.System.getProperty("java.home");
}
@ -234,52 +233,52 @@ function jvmHome_macro() {
* Macro that greps all jar-files from the class path variable and lists them.
* @param separator string that is printed between the items
*/
function jvmJars_macro(par) {
var separator = (par && par.separator ) ? par.separator : ", ";
var str = java.lang.System.getProperty("java.class.path");
var arr = str.split(".jar");
for ( var i in arr ) {
var str = arr[i];
var pos = ( str.lastIndexOf('\\') > str.lastIndexOf('/') ) ? str.lastIndexOf('\\') : str.lastIndexOf('/');
res.write ( arr[i].substring(pos+1) + ".jar" );
if ( i < arr.length-1 ) res.write ( separator );
}
function jvmJars_macro(par) {
var separator = (par && par.separator ) ? par.separator : ", ";
var str = java.lang.System.getProperty("java.class.path");
var arr = str.split(".jar");
for (var i in arr) {
var str = arr[i];
var pos = ( str.lastIndexOf('\\') > str.lastIndexOf('/') ) ? str.lastIndexOf('\\') : str.lastIndexOf('/');
res.write(arr[i].substring(pos + 1) + ".jar");
if (i < arr.length - 1) res.write(separator);
}
}
/**
* Macro that returns the name and version of the server's os
*/
function os_macro() {
return java.lang.System.getProperty("os.name") + " " + java.lang.System.getProperty("os.arch") + " " + java.lang.System.getProperty("os.version");
function os_macro() {
return java.lang.System.getProperty("os.name") + " " + java.lang.System.getProperty("os.arch") + " " + java.lang.System.getProperty("os.version");
}
/**
* Macro that returns anything from server.properties
*/
function property_macro(par) {
if ( par && par.key ) {
return this.getProperty(key);
} else {
return "";
}
function property_macro(par) {
if (par && par.key) {
return this.getProperty(key);
} else {
return "";
}
}
/**
* Macro formatting server.properties
*/
function properties_macro(par) {
formatProperties(this.getProperties(),par);
function properties_macro(par) {
formatProperties(this.getProperties(), par);
}
/**
* Macro that returns the timezone of this server
*/
function timezone_macro(par) {
return java.util.TimeZone.getDefault().getDisplayName(false, java.util.TimeZone.LONG) + " (" + java.util.TimeZone.getDefault().getID() + ")";
function timezone_macro(par) {
return java.util.TimeZone.getDefault().getDisplayName(false, java.util.TimeZone.LONG) + " (" + java.util.TimeZone.getDefault().getID() + ")";
}

View file

@ -1,44 +0,0 @@
/**
* main action, show server-stats
* perform start, stop, restart and flush-action
*
*/
if ( checkAddress()==false ) return;
if ( req.data.app!=null && req.data.app!="" && req.data.action!=null && req.data.action!="" ) {
var appObj = root.getApp(req.data.app);
// check access for application. md5-encoded uname/pwd can also be put in
// app.properties to limit access to a single app
if ( checkAuth(appObj)==false ) return;
if ( req.data.action=="start" ) {
this.startApplication(req.data.app);
res.redirect ( appObj.href("main") );
} else if ( req.data.action=="stop" ) {
if ( checkAuth()==false ) return;
this.stopApplication(req.data.app);
res.redirect ( root.href("main") );
} else if ( req.data.action=="restart" ) {
this.stopApplication(req.data.app);
this.startApplication(req.data.app);
res.redirect ( appObj.href("main") );
} else if ( req.data.action=="flush" ) {
appObj.clearCache();
res.redirect ( appObj.href("main") );
}
}
// output only to root
if ( checkAuth()==false ) return;
res.data.title = "Helma Object Publisher - Serverinfo";
res.data.body = this.renderSkinAsString("main");
renderSkin("global");

View file

@ -1,33 +0,0 @@
if (checkAddress()==false)
return;
var obj = new Object();
obj.msg = "";
if (req.data.username!=null && req.data.password!=null) {
// we have input from webform
if ( req.data.username=="" )
obj.msg += "username can't be left empty!<br>";
if ( req.data.password=="" )
obj.msg += "password can't be left empty!<br>";
if ( obj.msg!="" ) {
obj.username = req.data.username;
res.reset();
res.data.body = renderSkinAsString ("pwdform",obj);
} else {
// render the md5-string:
obj.propsString = "adminAccess=" + Packages.helma.util.MD5Encoder.encode(req.data.username + "-" + req.data.password) + "<br>\n";
res.data.body = renderSkinAsString ("pwdfeedback", obj);
}
} else {
// no input from webform, so print it
res.data.body = renderSkinAsString("pwdform",obj);
}
res.data.title = "username & password on " + root.hostname_macro();
res.data.head = renderSkinAsString("head");
renderSkin("basic");

View file

@ -1,37 +0,0 @@
/**
* prints server-stats for mrtg-tool.
* doesn't check username or password, so that we don't have
* to write them cleartext in a mrtg-configfile but checks the
* remote address.
*/
if ( checkAddress()==false )
return;
if (req.data.action=="memory") {
res.write (this.jvmTotalMemory_macro () + "\n");
res.write (this.jvmFreeMemory_macro () + "\n");
res.write ("0\n0\n");
} else if (req.data.action=="netstat" && isLinux ()) {
var str = (new File("/proc/net/tcp")).readAll();
var arr = str.split("\n");
res.write (arr.length-2 + "\n");
res.write ("0\n0\n0\n");
} else if (req.data.action=="loadavg" && isLinux ()) {
// load average of last 5 minutes:
var str = (new File("/proc/loadavg")).readAll();
var arr = str.split(" ");
res.write (arr[1]*100 + "\n");
res.write ("0\n0\n0\n");
} else {
res.write ( "0\n0\n0\n0\n");
}

View file

@ -1,5 +1,5 @@
# Set baseURI for application generated URLs, if necessary.
#baseURI = /manage
# baseURI = /manage
# A short description of what this application is about:
_description = Helma's server management console. Start applications, introspection etc.
@ -8,3 +8,5 @@ _description = Helma's server management console. Start applications, introspect
# might take more than one minute on a slow computer
requestTimeout = 300
# run scheduler function each minute
cron.scheduler.function = scheduler

View file

@ -1,4 +1,3 @@
#
# define the root class of this application
#
@ -17,10 +16,10 @@ root.factory.method = getServer
# and, yes, map the root class again.
#
helma.main.Server = root
helma.framework.core.Application = application
helma.doc.DocApplication = docapplication
helma.doc.DocPrototype = docprototype
helma.doc.DocFunction = docfunction
helma.doc.DocTag = doctag
helma.main.Server = Root
helma.framework.core.Application = Application
helma.doc.DocApplication = DocApplication
helma.doc.DocPrototype = DocPrototype
helma.doc.DocFunction = DocFunction
helma.doc.DocTag = DocTag

View file

@ -3,7 +3,7 @@ To get the manage-application to work you must:
- add it to the apps.properties file with the following line:
manage
- use helma distribution 1.2-RC1 or later.
- use helma distribution 1.5 or later.
- add the following properties to server.properties: