* 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

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
@ -15,7 +14,7 @@ function renderApi(appName) {
// now render the api
var ct = docApp.renderApi();
writeln("rendered " + ct + " files");
// cleanup
this.stopApplication(appName);
}
@ -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");
}