Merge remote-tracking branch 'manage/master' into subtree
this merges master branch of https://github.com/helma-org/apps-manage-mirror into helma
This commit is contained in:
commit
ca2b08a5df
58 changed files with 2678 additions and 0 deletions
130
apps/manage/Root/actions.js
Normal file
130
apps/manage/Root/actions.js
Normal 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");
|
||||
}
|
||||
}
|
76
apps/manage/Root/functions.js
Normal file
76
apps/manage/Root/functions.js
Normal file
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
* renders the api of a given application. used from commandline.
|
||||
*/
|
||||
function renderApi(appName) {
|
||||
|
||||
// supress security checks when accessing actions
|
||||
res.data.noWeb = true;
|
||||
|
||||
// start the application
|
||||
this.startApplication(appName);
|
||||
var appObj = this.getApp(appName);
|
||||
var docApp = appObj.getChildElement("api");
|
||||
|
||||
// now render the api
|
||||
var ct = docApp.renderApi();
|
||||
writeln("rendered " + ct + " files");
|
||||
|
||||
// cleanup
|
||||
this.stopApplication(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.listFiles();
|
||||
var arr = new Array();
|
||||
var seen = {};
|
||||
// first check apps directory for apps directories
|
||||
if (dir) {
|
||||
for (var i = 0; i < dir.length; i++) {
|
||||
if (dir[i].isDirectory() && dir[i].name.toLowerCase() != "cvs") {
|
||||
arr[arr.length] = this.getApp(dir[i].name);
|
||||
seen[dir[i].name] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// then check entries in apps.properties for apps not currently running
|
||||
var props = wrapJavaMap(root.getAppsProperties(null));
|
||||
for (var i in props) {
|
||||
if (i.indexOf(".") < 0 && !seen[i] && !root.getApplication(i)) {
|
||||
arr[arr.length] = this.getApp(i);
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get application by name, constructs an hopobject of the prototype application
|
||||
* if the app is not running (and therefore can't be access through
|
||||
* helma.main.ApplicationManager).
|
||||
* ATTENTION: javascript should not overwrite helma.main.Server.getApplication() which
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used by Helma path resolution.
|
||||
*/
|
||||
function getChildElement(name) {
|
||||
return this.getApp(name);
|
||||
}
|
||||
|
||||
|
284
apps/manage/Root/macros.js
Normal file
284
apps/manage/Root/macros.js
Normal file
|
@ -0,0 +1,284 @@
|
|||
/**
|
||||
* 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(par) {
|
||||
return this.href((par && par.action)?par.action:"main");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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[arr[i].name];
|
||||
if (obj != null) {
|
||||
sum += obj.requestCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
return sum + formatCount(sum, 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[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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Macro returning hostname of this machine
|
||||
*/
|
||||
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()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Macro returning the number of running applications,
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Macro that lists all running applications,
|
||||
* the manage application being excluded (-1).
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Macro that returns the server's uptime nicely formatted
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Macro that returns the home directory of the hop installation
|
||||
*/
|
||||
function home_macro() {
|
||||
return this.getHopHome().toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Macro that returns the home directory of the java virtual machine
|
||||
*/
|
||||
function jvmHome_macro() {
|
||||
return java.lang.System.getProperty("java.home");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Macro that returns anything from server.properties
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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() + ")";
|
||||
}
|
||||
|
||||
|
111
apps/manage/Root/main.skin
Normal file
111
apps/manage/Root/main.skin
Normal file
|
@ -0,0 +1,111 @@
|
|||
<big><% this.hostname %> (<% this.hostaddress %>)</big><br/><br/>
|
||||
|
||||
<table border="0" cellspacing="0" cellpadding="3">
|
||||
|
||||
<tr>
|
||||
<td class="list_separator" colspan="3">helma</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="list_property">uptime:</td>
|
||||
<td class="list_property" width="5"> </td>
|
||||
<td class="list_property" align="left"><% this.uptime %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="list_property">version:</td>
|
||||
<td class="list_property" width="5"> </td>
|
||||
<td class="list_property" align="left"><% this.version %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="list_property">homedir:</td>
|
||||
<td class="list_property" width="5"> </td>
|
||||
<td class="list_property" align="left"><% this.home %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="list_property" valign="top">total active sessions:</td>
|
||||
<td class="list_property" width="5"> </td>
|
||||
<td class="list_property" align="left"><% this.countSessions default=" " %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="list_property" nowrap valign="top">total requests / 5 min:</td>
|
||||
<td class="list_property" width="5"> </td>
|
||||
<td class="list_property" align="left"><% this.requestCount default=" " %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="list_property" norwrap valign="top">total errors / 5 min:</td>
|
||||
<td class="list_property" width="5"> </td>
|
||||
<td class="list_property" align="left"><% this.errorCount default=" " %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="list_property" valign="top">loaded extensions:</td>
|
||||
<td class="list_property" width="5"> </td>
|
||||
<td class="list_property" align="left"><% this.extensions default=" " %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="list_separator" colspan="3">jre</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="list_property">free memory:</td>
|
||||
<td class="list_property" width="5"> </td>
|
||||
<td class="list_property" align="left"><% this.jvmFreeMemory hr="true" %></td>
|
||||
</tr>
|
||||
|
||||
|
||||
<tr>
|
||||
<td class="list_property">used memory:</td>
|
||||
<td class="list_property" width="5"> </td>
|
||||
<td class="list_property" align="left"><% this.jvmUsedMemory hr="true" %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="list_property">total memory:</td>
|
||||
<td class="list_property" width="5"> </td>
|
||||
<td class="list_property" align="left"><% this.jvmTotalMemory hr="true" %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="list_property">java:</td>
|
||||
<td class="list_property" width="5"> </td>
|
||||
<td class="list_property" align="left"><% this.jvm %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="list_property">javahome:</td>
|
||||
<td class="list_property" width="5"> </td>
|
||||
<td class="list_property" align="left"><% this.jvmHome %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="list_property">os:</td>
|
||||
<td class="list_property" width="5"> </td>
|
||||
<td class="list_property" align="left"><% this.os %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="list_property">localtime:</td>
|
||||
<td class="list_property" width="5"> </td>
|
||||
<td class="list_property" align="left"><% now %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="list_property" valign="top">timezone:</td>
|
||||
<td class="list_property" width="5"> </td>
|
||||
<td class="list_property" align="left"><% this.timezone %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="list_property" valign="top">loaded Jars:</td>
|
||||
<td class="list_property" width="5"> </td>
|
||||
<td class="list_property" align="left"><% this.jvmJars %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="list_separator" colspan="3">server.properties</td>
|
||||
</tr>
|
||||
|
||||
<% this.properties itemprefix='<tr><td class="list_property">' separator='</td><td class="list_property" width="5"> </td><td class="list_property" align="left">' itemsuffix='</td></tr>' %>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue