-
Notifications
You must be signed in to change notification settings - Fork 6
ow.server
- ow.server.auth.add
- ow.server.auth.check
- ow.server.auth.del
- ow.server.auth.dump
- ow.server.auth.dumpEncrypt
- ow.server.auth.getExtra
- ow.server.auth.initialize
- ow.server.auth.is2FA
- ow.server.auth.isLocked
- ow.server.auth.loadFile
- ow.server.auth.saveFile
- ow.server.auth.setCustomFunction
- ow.server.auth.setExtra
- ow.server.auth.setLockTimeout
- ow.server.auth.setTriesToLock
- ow.server.checkIn
- ow.server.daemon
- ow.server.getPid
- ow.server.httpd.addHTTPCode
- ow.server.httpd.addMimeType
- ow.server.httpd.authBasic
- ow.server.httpd.getFromOpenAF
- ow.server.httpd.getFromZip
- ow.server.httpd.getMimeType
- ow.server.httpd.mapRoutesWithLibs
- ow.server.httpd.mapWithExistingRoutes
- ow.server.httpd.replyFile
- ow.server.httpd.replyFileMD
- ow.server.httpd.replyRedirect
- ow.server.httpd.resetRoutes
- ow.server.httpd.route
- ow.server.httpd.start
- ow.server.httpd.stop
- ow.server.jmx.call
- ow.server.jmx.get
- ow.server.jmx.localConnect
- ow.server.jmx.serverExec
- ow.server.jmx.set
- ow.server.ldap
- ow.server.ldap.close
- ow.server.ldap.search
- ow.server.ldap.searchStrings
- ow.server.ldap.startTLS
- ow.server.openafServer.exec
- ow.server.openafServer.load
- ow.server.openafServer.start
- ow.server.openafServer.stop
- ow.server.processArguments
- ow.server.rest.parseIndexes
- ow.server.rest.reply
- ow.server.rest.replyData
- ow.server.rest.writeIndexes
- ow.server.scheduler.addEntry
- ow.server.scheduler.modifyEntry
- ow.server.scheduler.nextUUID
- ow.server.scheduler.resetSchThread
- ow.server.scheduler.scheduler
- ow.server.scheduler.stop
- ow.server.scheduler.timeUntilNext
- ow.server.simpleCheckIn
ow.server.auth.add(aUser, aPass, aKey)
Adds the aUser and aPass to the current authentication list. Optionally a 2FA aKey.
ow.server.auth.check(aUser, aPass) : boolean
Checks if the aUser and aPass provided are authenticated with the current internal list (returns true) or not (returns false). If a 2FA authentication was provided the token should be suffix to the password.
ow.server.auth.del(aUser)
Removes the aUSer from the current authentication list.
ow.server.auth.dump() : Map
Dumps the current authentication list into a Map.
ow.server.auth.dumpEncrypt(aKey) : Map
Dumps the current authentication list into an encrypted string (optionally using an encryption aKey).
ow.server.auth.getExtra(aUser) : Object
Gets the extra object associated with aUser (previously set with ow.server.auth.setExtra).
ow.server.auth.initialize(aPreviousDumpMap, aKey, aCustomFunc)
Initializes with a previous dump from ow.server.auth.dump or ow.server.auth.dumpEncrypt (including an optional aKey if used). Optionally aCustomFunc can be provided as a custom authentication function that receives the provided user and password and should return true if authenticated or false otherwise.
ow.server.auth.is2FA(aUser) : boolean
Returns true if aUser has 2FA authentication, false otherwise.
ow.server.auth.isLocked(aUser) : boolean
For a given aUser returns if the user is currently considered as lock or not.
ow.server.auth.loadFile(aFile, aKey)
Loads aFile (previously saved with ow.server.auth.saveFile), optionally providing aKey, (re)initializing the current authentication information.
ow.server.auth.saveFile(aFile, aKey)
Saves into aFile, optionally providing aKey, the current authentication information. You can use ow.server.auth.loadFile later to reload this info.
ow.server.auth.setCustomFunction(aCustomFunction)
Sets a custom authentication function that receives the provided user and password and should return true if authenticated or false otherwise.
ow.server.auth.setExtra(aUser, aX)
Sets an extra object (aX) to be associated with aUser (for example, the correspondings permissions). You can later retrieve this extra object with ow.server.auth.getExtra.
ow.server.auth.setLockTimeout(aTimeout)
Set the current lock timeout in seconds. Defaults to 15 minutes.
ow.server.auth.setTriesToLock(numberOfTries)
Set the current number of wrong tries until a user is locked. Defaults to 3.
ow.server.checkIn(aPidFile, onAlreadyRunning, onShutdown, anExitCode) : Boolean
Will check if a server for the give aPidFile is running or not. Will return false if it's running and server start shouldn't proceed. Will return true if nothing is running and server start should proceed. Optionally you can provide an onShutdown function to execute any code needed upon controlled shutdown of the server and provide an onAlreadyRunning function (that will received the corresponding aPidFile). If the onAlreadyRunning function returns false the process will exit with -1 (or the anExitCode provided), if true will continue processing. Example:
var params = processExpr();
ow.server.checkIn("server.pid", function(aPid) {
log("there is another me " + aPid + " already running... bye!");
if (isDefined(params.restart)) {
log("I will kill him!");
pidKill(ow.server.getPid(aPid), true);
return true;
} else {
log("... I will die now...");
return false;
}
}, function() {
log("I'm going to die....");
});
ow.server.daemon();
(available after ow.loadServer())
ow.server.daemon(aTimePeriod, aPeriodicFunction)
Will start an infinite cycle to keep a server running. If aTimePeriod (in ms) is not provided a default of 5 seconds will be considered. Optionally you can provide aPeriodicFunction to run every aTimePeriod. If this aPeriodicFunction returns true, the infinite cycle is broken. (available after ow.loadServer())
ow.server.getPid(aPidFile) : String
Retrieve the server pid on the given aPidFile. (available after ow.loadServer())
ow.server.httpd.addHTTPCode(aCodeRef, aCodeNum)
Adds a new HTTP aCodeNum number that will be referenced by the name aCodeRef.
ow.server.httpd.addMimeType(anExtension, aMimeType)
Adds a new aMimeType for the corresponding anExtension.
ow.server.httpd.authBasic(aRealm, aHTTPd, aReq, aAuthFunc, aReplyFunc, aUnAuthFunc) : Map
Wraps a httpd reply with basic HTTP authentication for the provided aRealm on the aHTTPd server. The aReq request map should be provided along with aAuthFunc (that receives the user and password and should return true of false if authentication is successful). If authentication is successful aReplyFunc will be executed receiving aHTTPd and aReq. Otherwise an optional aUnAuthFunc will be executed also receiving aHTTPd and aReq. Example:
ow.server.httpd.route(hs, ow.server.httpd.mapRoutesWithLibs(hs, {
"/f": function(req) {
return ow.server.httpd.authBasic(
"realm", hs, req,
function(user, pass) {
if (user == "adm" && pass == "Password1") return true; else return false;
},
function(hss, areq) {
return ow.server.httpd.replyFile(hss, "/some/path", "/f", areq.uri);
},
function(hss, ar) {
return hss.reply("Not authorized.", "text/plain", ow.server.httpd.codes.UNAUTHORIZED);
}
);
}
}),
function(req) {
return hs.replyOKText("nothing here...");
}
);
ow.server.httpd.getFromOpenAF(aResource, inBytes, anEncoding) : anArrayOfBytes
Retrieves aResource, as anArrayOfBytes, from the openaf.jar. This resource can be inBytes = true or not and anEncoding can be provided.
ow.server.httpd.getFromZip(aZipFile, aResource, inBytes, anEncoding) : anArrayOfBytes
Retrieves aResource, as anArrayOfBytes, from aZipFile. This resource can be inBytes = true or not and anEncoding can be provided.
ow.server.httpd.getMimeType(aFilename) : String
Tries to determine the mime type of aFilename and returns it. If not determined it will default to application/octet-stream.
ow.server.httpd.mapRoutesWithLibs(aHTTPd, aMapOfRoutes) : Map
Helper to use with ow.server.httpd.route to automatically add routes for JQuery, Backbone, Handlebars, jLinq and Underscore from the openaf.jar.
ow.server.httpd.mapWithExistingRoutes(aHTTPd, aMapOfRoutes) : Map
Builds a map of routes taking into account the already defined routes for aHTTPd thus effectively letting add new routes.
ow.server.httpd.replyFile(aHTTPd, aBaseFilePath, aBaseURI, aURI, notFoundFunction, documentRootArray) : Map
Provides a helper aHTTPd reply that will enable the download of a file, from aBaseFilePath, given aURI part of aBaseURI. Optionally you can also provide a notFoundFunction and an array of file strings (documentRootArraY) to replace as documentRoot. Example:
ow.server.httpd.route(hs, ow.server.httpd.mapRoutesWithLibs(hs, {
"/stuff/to/server": function(req) {
return ow.server.httpd.replyFile(hs, "/some/path/to/serve/files", "/stuff/to/server", req.uri);
}
},
function(req) {
return hs.replyOKText("nothing here...");
}
);
ow.server.httpd.replyFileMD(aHTTPd, aBaseFilePath, aBaseURI, aURI, notFoundFunction, documentRootArray) : Map
Provides a helper aHTTPd reply that will enable the parsing markdown file-based sites, from aBaseFilePath, given aURI part of aBaseURI. Optionally you can also provide a notFoundFunction and an array of file strings (documentRootArraY) to replace as documentRoot. Example:
ow.server.httpd.route((hs, ow.server.httpd.mapRoutesWithLibs(hs, {)
"/stuff/to/server": function(req) {
return ow.server.httpd.replyFileMD(hs, "/some/path/to/serve/files", "/stuff/to/server", req.uri);
}
},
function(req) {
return hs.replyOKText("nothing here...");
}
);
ow.server.httpd.replyRedirect(aHTTPd, newLocation) : Map
Provides a helper aHTTPd reply that will redirect the request to the newLocation provided (HTTP code 303).
ow.server.httpd.resetRoutes(aHTTPd)
Given aHTTPd it will reset all internal mapped routes to a reply HTTP code 401 to everything.
ow.server.httpd.route(aHTTPd, aMapOfRoutes, aDefaultRoute, aPath, aPreRouteFunc)
Adds a request router to aHTTPd given aMapOfRoutes. This router will use aPath if defined or /r otherwise. Optionally you can also specify aPreRouteFunc that will run before any routing is made.
Example:
ow.loadServer();
var hs = ow.server.httpd.start(17878);
ow.server.httpd.route(hs, ow.server.httpd.mapRoutesWithLibs(hs, {
"/myapp": function(req) {
return hs.replyOKText("my stuff!!");
}
}),
function(req) {
return hs.replyOKText("nothing here...");
});
log("READY!");
ow.server.daemon();
(available after ow.loadServer())
ow.server.httpd.start(aPort, aHost, keyStorePath, password, errorFunction) : Object
Will prepare a HTTP server to be used returning a HTTPServer object. Optionally you can provide aPort where you want the HTTP server to run. Otherwise a free port will be assigned. (available after ow.loadServer())
ow.server.httpd.stop(aHTTPd)
Will stop the aHTTPd server running. (available after ow.loadServer())
ow.server.jmx.call(aJMXObject, objName, aOperation, param1, ...) : value
Invokes aOperation on the object objName using aJMXObject connected to a server using ow.server.jmx.serverExec. Optionally you can provide extra arguments to be passed to the jmx remote operation. Example (based on ow.server.jmx.serverExec):
var jmx = ow.loadServer().jmx.localConnect("12345");
ow.server.jmx.call(jmx, "com.openaf:type=server", "increment"); // 1
ow.server.jmx.call(jmx, "com.openaf:type=server", "resetTo", 10); // 10
ow.server.jmx.get(aJMXObject, objName, aProperty) : value
Returns the current value of aProperty on the object objName using aJMXObject connected to a JMX server.
ow.server.jmx.localConnect(aPid) : JMX
Tries to connect with a local aPid via JMX and returns a JMX plugin object instance. If no aPid is provided it will try to retrieve the current process pid and connect to it.
ow.server.jmx.serverExec(aParamsArray, aFunction)
Helper function to be used with JMXServers. Receives aParamsArray passed on the JMX bean operations handling function and will call aFunction passing the parameters as arguments and converting the returned result into a JSON string to be transmitted to the calling JMX client. Example:
plugin("JMX");
var jmxs = new JMXServer("com.openaf:type=server");
jmxs.start();
var c = 0;
jmxs.addBean({"count": "long", "increment": "operation", "resetTo": "operation"},
function(key) { if (key == "count") return c; },
function(key, value) { if (key == "count") c = value; },
function(op, params) { switch(op) {
case "increment": return ow.server.jmx.serverExec(params, function() { return ++c; });
case "resetTo" : return ow.server.jmx.serverExec(params, function(v) { c = v; });
}
}
);
ow.server.jmx.set(aJMXObject, objName, aProperty, aNewValue)
Sets aProperty with the value aNewValue on the object objName using aJMXObject connected to a JMX server.
ow.server.ldap(aServer, aUsername, aPassword) : Object
Creates a ow.server.ldap object for the given aServer, aUsername and aPassword. Example:
var ldapAdServer = "ldap://ldap.forumsys.com:389";
var ldapUsername = "cn=read-only-admin,dc=example,dc=com";
var ldapPassword = "password";
var ldap = new ow.server.ldap(ldapAdServer, ldapUsername, ldapPassword);
var res = ldap.search("dc=example,dc=com", "(uid=*)");
print(beautifier(res));
ow.server.ldap.close()
Closes the current connection.
ow.server.ldap.search(baseSearch, searchFilter) : Array
Tries to return the result of using searchFilter under the baseSearh. See also ow.server.ldap
ow.server.ldap.searchStrings(baseSearch, searchFilter) : Array
Tries to return the result of using searchFilter under the baseSearch converting each entry to string See also ow.server.ldap
ow.server.ldap.startTLS()
Starts TLS over the current connection.
ow.server.openafServer.exec(aId, aScript, aServerPid)
Tries to execute the given aScript locally or in the aServerPid provided (created by a ow.server.openafServer.start). Optionally you can also specify aId.
ow.server.openafServer.load(aId, aScriptFilePath, aServerPid)
Tries to execute the given aScriptFilePath locally or in the aServerPid provided (created by a ow.server.openafServer.start). Optionally you can also specify aId.
ow.server.openafServer.start(aId, aPort, notLocal)
Starts an internal JMX server with a give optional aId. If there is a need to access it externally (do keep in mind security) you can provide also aPort. This server allows for the load or execution of OpenAF scripts. In extreme cases you can use notLocal = true to make the server available outside the localhost (NOT ADVISABLE!).
ow.server.openafServer.stop()
Attempts to stop the existing server.
ow.server.processArguments(aRouterFunction, aMainSeparator, aSubSeparator) : Array
Processes the __expr (-e or opack arguments) value for arguments splitting first by aMainSeparator (if not defined defaults to " ") and then splitting by aSubSeparator (if not defined defaults to "="). Example with __expr = "opensomething exec count=5=123 some=1
ow.server.processArguments(function(aParam) { ... });
Will produce function calls where aParam will have the following values:
"opensomething"
"exec"
[ "count", "5", "123" ]
[ "some", "1" ]
(available after ow.loadServer())
ow.server.rest.parseIndexes(aBaseURI, aHTTPRequest) : Map
Given aBaseURI and aHTTPRequest will parse and determine the implicit REST API indexes
ow.server.rest.reply(aBaseURI, aRequest, aCreateFunc, aGetFunc, aSetFunc, aRemoveFunc, returnWithParams) : RequestReply
Provides a REST compliant HTTPServer request replier given a aBaseURI, aRequest, aCreateFunc, aGetFunc, aSetFunc and aRemoveFunc. Each function will receive a map with the provided indexes from the request. Optionally you can specify with returnWithParams = true that each function will not return just the data map but a composed map with: data (the actual json of data), status (the HTTP code to return) and mimetype.
var hs = ow.loadServer().httpd.start(8080);
ow.server.httpd.route(hs, ow.server.httpd.mapRoutesWithLibs(hs, {
"/rest": function(req) { return ow.server.rest.reply("/rest", req,
function(idxs, data) { // Create and return a map },
function(idxs) { // Get and return a map },
function(idxs, data) { // Set and return a map },
function(idxs) { // Remove and return a map }
)}}, function(req) { return hs.replyOKText("nothing here"); });
ow.server.daemon();
\
ow.server.rest.replyData(aBaseURI, aRequest, aDataArray) : RequestReply
Provides a REST JSON compliant HTTPServer request replier given a aBaseURI, aRequest and aDataArray. The data array provided will be manipulated by REST calls.
var hs = ow.loadServer().httpd.start(8080);
ow.server.httpd.route(hs, ow.server.httpd.mapRoutesWithLibs(hs, {
"/rest": function(req) {
return ow.server.rest.replyData("/rest", req, myData);
});
ow.server.daemon();
\
ow.server.rest.writeIndexes(aPropsMap) : String
Given a map of REST API indexes (aPropsMap) will return a corresponding URI. Note: just a shortcut for ow.obj.rest.writeIndexes.
ow.server.scheduler.addEntry(aCronExpr, aFunction, waitForFinish) : String
Adds a new scheduler entry with a given aCronExpr"ession" that will trigger the scheduled execution of aFunction. If waitForFinish = true it will not execute until the previous execution has finished. Returns an UUID that can be used with the function modifyEntry later, if needed.
ow.server.scheduler.modifyEntry(aUUID, aCronExpr, aFunction, waitForFinish) : String
Changes an existing scheduler entry (aUUID) with a given aCronExpr"ession" that will trigger the scheduled execution of aFunction. If waitForFinish = true it will not execute until the previous execution has finished.
ow.server.scheduler.nextUUID() : String
Returns the uuid of the next entry that will be executed.
ow.server.scheduler.resetSchThread(aErrFunction)
Resets the current scheduler thread pool adding a loop cached thread that will sleep until the next execution is due. When it executes it will add a new cached thread to execute the scheduled entry by executing the entry function provided, as argument, it's uuid.
ow.server.scheduler.scheduler()
Creates a new instance of a cron based scheduler with its own thread pool.
ow.server.scheduler.stop()
Attempts to force stop the current scheduler thread pool.
ow.server.scheduler.timeUntilNext() : Number
Returns the number of ms until the next scheduled execution.
ow.server.simpleCheckIn(aName)
If aName is provided it will check for 'aName.pid'. If the pid is running it will stop the current execution unless stop or restart is provided as a script parameter. If stop is provided as a script parameter it will stop execution and try to kill the existing pid (force stop will try to kill it anyway). If restart is provided as a script parameter it will continue execution and try to kill the existing pid.