diff options
author | Andrew Bartlett <abartlet@samba.org> | 2007-09-10 03:44:47 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 15:05:50 -0500 |
commit | 15c1801a5c13479f1bf67e0e3c1ad7c0af8e3af7 (patch) | |
tree | c5bcb824e04cb1de4cccb07a148c113ff1831298 /services | |
parent | 37de963f67a1331b6402f901d2bda79b7119a155 (diff) | |
download | samba-15c1801a5c13479f1bf67e0e3c1ad7c0af8e3af7.tar.gz samba-15c1801a5c13479f1bf67e0e3c1ad7c0af8e3af7.tar.bz2 samba-15c1801a5c13479f1bf67e0e3c1ad7c0af8e3af7.zip |
r25051: Move SWAT back to the old-style form-submit modal.
The Web 2.0, async client tools were really interesting, but without
developer backing they remain impossible to support into a release.
The most interesting app was the LDB browser, and I intend to replace
this with phpLdapAdmin, preconfigured for Apache during provision.
This also removes the need to 'compile' SWAT on SVN checkouts.
Andrew Bartlett
(This used to be commit cda965e908055d45b1c05bc29cc791f7238d2fae)
Diffstat (limited to 'services')
-rw-r--r-- | services/json.esp | 269 | ||||
-rw-r--r-- | services/json_auth.esp | 73 | ||||
-rw-r--r-- | services/jsondate.esp | 200 | ||||
-rw-r--r-- | services/qooxdoo/test.esp | 236 | ||||
-rw-r--r-- | services/request.esp | 540 | ||||
-rw-r--r-- | services/resources.esp | 171 | ||||
-rw-r--r-- | services/samba/adm.esp | 28 | ||||
-rw-r--r-- | services/samba/config.esp | 26 | ||||
-rw-r--r-- | services/samba/ejsnet.esp | 178 | ||||
-rw-r--r-- | services/samba/ldb.esp | 675 | ||||
-rw-r--r-- | services/samba/management.esp | 184 | ||||
-rw-r--r-- | services/samba/system.esp | 118 |
12 files changed, 0 insertions, 2698 deletions
diff --git a/services/json.esp b/services/json.esp deleted file mode 100644 index 6c59db0fca..0000000000 --- a/services/json.esp +++ /dev/null @@ -1,269 +0,0 @@ -<% - -/* - * Copyright: - * (C) 2006 by Derrell Lipman - * All rights reserved - * - * License: - * LGPL 2.1: http://creativecommons.org/licenses/LGPL/2.1/ - */ - -/* - * This module provides a JSON encoder. - */ - - -/* escape a string as required by json */ -function _escape(s) -{ - var i; - var arr = new Array(); - - for (i = 0; i < strlen(s); i++) - { - var c = substr(s, i, 1); - if (c == '\x00') - { - arr[i] = '\\u0000'; - } - if (Json._internal.convert[c] != undefined) - { - arr[i] = Json._internal.convert[c]; - } - else - { - arr[i] = c; - } - } - - if (arr.length == 0) - { - return ""; - } - - return join("", arr); -} - -/* encode an arbitrary object. called recursively, for object and array */ -function _encode(o) -{ - var type = nativeTypeOf(o); - - if (type == "undefined") - { - return "null"; /* you really shouldn't count on this! */ - } - else if (type == "null") - { - return "null"; - } - else if (type == "boolean") - { - if (o) - { - return "true"; - } - else - { - return "false"; - } - } - else if (type == "c_function" || - type == "js_function" || - type == "string_c_function") - { - /* no output */ - } - else if (type == "float" || - type == "integer" || - type == "integer64") - { - return o + 0; - } - else if (type == "pointer") - { - var x = "" + o; - return '"' + substr(x, 16, strlen(x) - 16 - 1) + '"'; - } - else if (type == "object") - { - var buf; - - /* Is this an array or an ordinary object? */ - if (o["length"] != undefined) - { - var i; - - /* Assume it's an array if there's a length field */ - buf = "["; - for (i = 0; i < o.length; i++) - { - /* - * NOTE: We don't support sparse arrays nor associative - * arrays. Should we later want to do either, we're supposed - * to send it as an object rather than as an array. - */ - if (i > 0) - { - buf = buf + ","; - } - buf = buf + this.encode(o[i]); - } - buf = buf + "]"; - } - else if (o["__type"] == "_JSON_Date") - { - buf = "" + o.encoding(); - } - else - { - /* No length field, so it must be an ordinary object */ - var key; - var first = true; - - buf = "{"; - for (key in o) - { - if (! first) - { - buf = buf + ","; - } - buf = buf + '"' + key + '":' + this.encode(o[key]); - first = false; - } - buf = buf + "}"; - } - - return buf; - } - else if (type == "string") - { - return '"' + this._internal.escape(o) + '"'; - } - else - { - return '{ "unknown_object":"' + type + '"}'; - } -} - -/* Allocate the public Json access object */ -Json = new Object(); - -/* Json.encode(): encode an arbitrary object */ -Json.encode = _encode; -_encode = null; - -/* Json.decode(): decode a string into its object form */ -Json.decode = literal_to_var; - -/* Internal stuff, not for external access */ -Json._internal = new Object(); - -Json._internal.escape = _escape; -_escape = null; - -Json._internal.convert = new Object(); -Json._internal.convert['\b'] = '\\b'; -Json._internal.convert['\t'] = '\\t'; -Json._internal.convert['\n'] = '\\n'; -Json._internal.convert['\f'] = '\\f'; -Json._internal.convert['\r'] = '\\r'; -Json._internal.convert['"'] = '\\"'; -Json._internal.convert['\\'] = '\\\\'; -Json._internal.convert['\x01'] = '\\u0001'; -Json._internal.convert['\x02'] = '\\u0002'; -Json._internal.convert['\x03'] = '\\u0003'; -Json._internal.convert['\x04'] = '\\u0004'; -Json._internal.convert['\x05'] = '\\u0005'; -Json._internal.convert['\x06'] = '\\u0006'; -Json._internal.convert['\x07'] = '\\u0007'; -Json._internal.convert['\x08'] = '\\u0008'; -Json._internal.convert['\x09'] = '\\u0009'; -Json._internal.convert['\x0a'] = '\\u000a'; -Json._internal.convert['\x0b'] = '\\u000b'; -Json._internal.convert['\x0c'] = '\\u000c'; -Json._internal.convert['\x0d'] = '\\u000d'; -Json._internal.convert['\x0e'] = '\\u000e'; -Json._internal.convert['\x0f'] = '\\u000f'; -Json._internal.convert['\x10'] = '\\u0010'; -Json._internal.convert['\x11'] = '\\u0011'; -Json._internal.convert['\x12'] = '\\u0012'; -Json._internal.convert['\x13'] = '\\u0013'; -Json._internal.convert['\x14'] = '\\u0014'; -Json._internal.convert['\x15'] = '\\u0015'; -Json._internal.convert['\x16'] = '\\u0016'; -Json._internal.convert['\x17'] = '\\u0017'; -Json._internal.convert['\x18'] = '\\u0018'; -Json._internal.convert['\x19'] = '\\u0019'; -Json._internal.convert['\x1a'] = '\\u001a'; -Json._internal.convert['\x1b'] = '\\u001b'; -Json._internal.convert['\x1c'] = '\\u001c'; -Json._internal.convert['\x1d'] = '\\u001d'; -Json._internal.convert['\x1e'] = '\\u001e'; -Json._internal.convert['\x1f'] = '\\u001f'; -/* - * At some point, we probably want to add \x80-\xff as well, and it's then - * probably more efficient to generate these strings dynamically. (Even now - * it may be, but this was the the way I started, and so it remains.) - */ - - -/* Test it */ -/* -libinclude("base.js"); -function testFormat() -{ - var test = new Object(); - test.int = 23; - test.str = "hello world"; - test.float = 223.1; - test.bool = true; - test.array = new Array(); - test.array[0] = "hello"; - test.array[1] = "world"; - test.obj = new Object(); - test.obj.int = 1000; - test.obj.array = new Array(); - test.obj.array[0] = 42; - test.obj.array[1] = 223; - printf("%s\n", Json.encode(test)); -} -testFormat(); -*/ - -/* -libinclude("base.js"); -function testParse() -{ - var s; - - s = '{ "x" : 23 }'; - obj = Json.decode(s); - printf("Decode/encode of\n\t%s\nyielded\n\t%s\n\n", s, Json.encode(obj)); - - s = '{ "x" : [ 23, 42] }'; - obj = Json.decode(s); - printf("Decode/encode of\n\t%s\nyielded\n\t%s\n\n", s, Json.encode(obj)); - - s = '[ 13, 19, { "x" : [ 23, 42] }, 223 ]'; - obj = Json.decode(s); - printf("Decode/encode of\n\t%s\nyielded\n\t%s\n\n", s, Json.encode(obj)); - - s = '{ "x" : [ "hi" ] }'; - obj = Json.decode(s); - printf("Decode/encode of\n\t%s\nyielded\n\t%s\n\n", s, Json.encode(obj)); - - s = '[ 13, 19, { "x" : [ 23, 42, { "y":{"a":"hello", "b":"world", "c":[1,2,3]}}] }, 223 ]'; - obj = Json.decode(s); - printf("Decode/encode of\n\t%s\nyielded\n\t%s\n\n", s, Json.encode(obj)); -} -testParse(); -*/ - -/* - * Local Variables: - * mode: c - * End: - */ -%> diff --git a/services/json_auth.esp b/services/json_auth.esp deleted file mode 100644 index 57fbd7aaac..0000000000 --- a/services/json_auth.esp +++ /dev/null @@ -1,73 +0,0 @@ -<% -libinclude("auth.js"); - -/* Return true to allow access; false otherwise */ -function json_authenticate(serviceComponents, method, scriptTransportId, error) -{ - // Don't allow any access via ScriptTransport, for now. There are serious - // potential security exploits that will need to be protected against when - // we do want to allow use of ScriptTransport. -- djl - if (scriptTransportId != jsonrpc.Constant.ScriptTransport.NotInUse) - { - error.setError(jsonrpc.Constant.ServerError.PermissionDenied, - "Permission denied"); - return false; - } - - // Does the requested method require authentication? - if (! _authentication_required(serviceComponents, method)) - { - // Nope. Let 'em in. - return true; - } - - // Did our session expire? - if (request['SESSION_EXPIRED'] == "True") - { - // Yup. - error.setError(jsonrpc.Constant.ServerError.SessionExpired, - "Session expired"); - error.setInfo(getDomainList()); - return false; - } - - // Are we authenticated? - if (! session.AUTHENTICATED) - { - // Nope. - error.setError(jsonrpc.Constant.ServerError.NotLoggedIn, - "Not logged in"); - error.setInfo(getDomainList()); - return false; - } - - return true; -} - - -/* - * Return true if authentication is required for the specified method; - * false otherwise. - */ -function _authentication_required(serviceComponents, method) -{ - var m = join(".", serviceComponents) + "." + method; - - // See if this method requires authentication - if (m == "samba.system.login" || - m == "samba.system.logout") - { - // Nope. - return false; - } - - // Anything not listed above requires authentication - return true; -} - -/* - * Local Variables: - * mode: c - * End: - */ -%> diff --git a/services/jsondate.esp b/services/jsondate.esp deleted file mode 100644 index 3467228df6..0000000000 --- a/services/jsondate.esp +++ /dev/null @@ -1,200 +0,0 @@ -<% -/* - * Copyright: - * (C) 2006 by Derrell Lipman - * All rights reserved - * - * License: - * LGPL 2.1: http://creativecommons.org/licenses/LGPL/2.1/ - */ - -/* - * Date class for JSON-RPC - */ - - -function _JSON_Date_create(secondsSinceEpoch) -{ - var o = new Object(); - o.__type = "_JSON_Date"; - - function _setUtcDateTimeFields(year, month, day, hour, minute, second, millisecond) - { - this.year = year + 0; - this.month = month + 0; - this.day = day + 0; - this.hour = hour + 0; - this.minute = minute + 0; - this.second = second + 0; - this.millisecond = millisecond + 0; - } - - o.setUtcYear = _setUtcDateTimeFields; - - function _setUtcYear(year) - { - this.year = year + 0; - } - o.setUtcYear = _setUtcYear; - - function _setUtcMonth(month) - { - this.month = month + 0; - } - o.setUtcMonth = _setUtcMonth; - - function _setUtcDay(day) - { - this.day = day + 0; - } - o.setUtcDay = _setUtcDay; - - function _setUtcHour(hour) - { - this.hour = hour + 0; - } - o.setUtcHour = _setUtcHour; - - function _setUtcMinute(minute) - { - this.minute = minute + 0; - } - o.setUtcMinute = _setUtcMinute; - - function _setUtcSecond(second) - { - this.second = second + 0; - } - o.setUtcSecond = _setUtcSecond; - - function _setUtcMillisecond(millisecond) - { - this.millisecond = millisecond + 0; - } - o.setUtcMillisecond = _setUtcMillisecond; - - function _setEpochTime(secondsSinceEpoch) - { - var microseconds = 0; - - if (typeof(secondsSinceEpoch) != "number") - { - var currentTime = gettimeofday(); - secondsSinceEpoch = currentTime.sec; - microseconds = currentTime.usec; - } - - var tm = gmtime(secondsSinceEpoch); - - this.year = 1900 + tm.tm_year; - this.month = tm.tm_mon; - this.day = tm.tm_mday; - this.hour = tm.tm_hour; - this.minute = tm.tm_min; - this.second = tm.tm_sec; - this.millisecond = 0; - } - o.setEpochTime = _setEpochTime; - - function _getUtcYear() - { - return this.year; - } - o.getUtcYear = _getUtcYear; - - function _getUtcMonth() - { - return this.month; - } - o.getUtcMonth = _getUtcMonth; - - function _getUtcDay() - { - return this.day; - } - o.getUtcDay = _getUtcDay; - - function _getUtcHour() - { - return this.hour; - } - o.getUtcHour = _getUtcHour; - - function _getUtcMinute() - { - return this.minute; - } - o.getUtcMinute = _getUtcMinute; - - function _getUtcSecond() - { - return this.second; - } - o.getUtcSecond = _getUtcSecond; - - function _getUtcMillisecond() - { - return this.millisecond; - } - o.getUtcMillisecond = _getUtcMillisecond; - - function _getEpochTime() - { - var tm = new Object(); - tm.tm_sec = this.second; - tm.tm_min = this.minute; - tm.tm_hour = this.hour; - tm.tm_mday = -1; - tm.tm_mon = this.month; - tm.tm_year = this.year; - tm.tm_wday = -1; - tm.tm_yday = -1; - tm.isdst = 0; - return gmmktime(tm); - } - o.getEpochTime = _getEpochTime; - - function _encoding() - { - /* Encode the date in a well-documented fashion */ - return sprintf("new Date(Date.UTC(%d,%d,%d,%d,%d,%d,%d))", - this.year, - this.month, - this.day, - this.hour, - this.minute, - this.second, - this.millisecond); - } - o.encoding = _encoding; - - if (! secondsSinceEpoch) - { - var now = gettimeofday(); - o.setEpochTime(now.sec); - } - else - { - o.setEpochTime(secondsSinceEpoch); - } - o.year = 0; - o.month = 0; - o.day = 0; - o.hour = 0; - o.minute = 0; - o.second = 0; - o.millisecond = 0; - return o; -} - -JSON_Date = new Object(); -JSON_Date.create = _JSON_Date_create; -_JSON_Date_create = null; - - -/* - * Local Variables: - * mode: c - * End: - */ -%> diff --git a/services/qooxdoo/test.esp b/services/qooxdoo/test.esp deleted file mode 100644 index e8686dcc25..0000000000 --- a/services/qooxdoo/test.esp +++ /dev/null @@ -1,236 +0,0 @@ -<% -/* - * Copyright: - * (C) 2006 by Derrell Lipman - * All rights reserved - * - * License: - * LGPL 2.1: http://creativecommons.org/licenses/LGPL/2.1/ - */ - -/* - * This is the standard qooxdoo test class. There are tests for each of the - * primitive types here, along with standard named tests "echo", "sink" and - * "sleep". - */ - -/** - * Echo the (one and only) parameter. - * - * @param params - * An array containing the parameters to this method - * - * @param error - * An object of class JsonRpcError. - * - * @return - * Success: The object containing the result of the method; - * Failure: null - */ -function _echo(params, error) -{ - if (params.length != 1) - { - error.setError(JsonRpcError_ParameterMismatch, - "Expected 1 parameter; got " + params.length); - return error; - } - return "Client said: [" + params[0] + "]"; -} -jsonrpc.method.echo = _echo; - -/** - * Sink all data and never return. - * - * @param params - * An array containing the parameters to this method (none expected) - * - * @param error - * An object of class JsonRpcError. - * - * @return - * "Never" - */ -function _sink(params, error) -{ - /* We're never supposed to return. Just sleep for a very long time. */ - sleep(240); -} -jsonrpc.method.sink = _sink; - -/** - * Sleep for the number of seconds specified by the parameter. - * - * @param params - * An array containing the parameters to this method (one expected) - * - * @param error - * An object of class JsonRpcError. - * - * @return - * Success: The object containing the result of the method; - * Failure: null - */ -function _sleep(params, error) -{ - if (params.length != 1) - { - error.setError(JsonRpcError_ParameterMismatch, - "Expected 1 parameter; got " + params.length); - return error; - } - - sleep(params[0]); - return params[0]; -} -jsonrpc.method.sleep = _sleep; - -/*************************************************************************/ - -/* - * The remainder of the functions test each individual primitive type, and - * test echoing arbitrary types. Hopefully the name is self-explanatory. - */ - -function _getInteger(params, error) -{ - return 1; -} -jsonrpc.method.getInteger = _getInteger; - -function _getFloat(params, error) -{ - return 1/3; -} -jsonrpc.method.getFloat = _getFloat; - -function _getString(params, error) -{ - return "Hello world"; -} -jsonrpc.method.getString = _getString; - -function _getBadString(params, error) -{ - return "<!DOCTYPE HTML \"-//IETF//DTD HTML 2.0//EN\">"; -} -jsonrpc.method.getBadString = _getBadString; - -function _getArrayInteger(params, error) -{ - return new Array(1, 2, 3, 4); -} -jsonrpc.method.getArrayInteger = _getArrayInteger; - -function _getArrayString(params, error) -{ - return new Array("one", "two", "three", "four"); -} -jsonrpc.method.getArrayString = _getArrayString; - -function _getObject(params, error) -{ - o = new Object(); // some arbitrary object - o.something = 23; - o.garbage = 'lkasjdff;lajsdfkl;sadf'; - return o; -} -jsonrpc.method.getObject = _getObject; - -function _getTrue(params, error) -{ - return true; -} -jsonrpc.method.getTrue = _getTrue; - -function _getFalse(params, error) -{ - return false; -} -jsonrpc.method.getFalse = _getFalse; - -function _getNull(params, error) -{ - return null; -} -jsonrpc.method.getNull = _getNull; - -function _isInteger(params, error) -{ - var type = nativeTypeOf(params[0]); - return type == "integer" || type == "integer64"; -} -jsonrpc.method.isInteger = _isInteger; - -function _isFloat(params, error) -{ - return nativeTypeOf(params[0]) == "float"; -} -jsonrpc.method.isFloat = _isFloat; - -function _isString(params, error) -{ - return nativeTypeOf(params[0]) == "string"; -} -jsonrpc.method.isString = _isString; - -function _isBoolean(params, error) -{ - return nativeTypeOf(params[0]) == "boolean"; -} -jsonrpc.method.isBoolean = _isBoolean; - -function _isArray(params, error) -{ - return nativeTypeOf(params[0]) == "object" && params.length != undefined; -} -jsonrpc.method.isArray = _isArray; - -function _isObject(params, error) -{ - return nativeTypeOf(params[0]) == "object"; -} -jsonrpc.method.isObject = _isObject; - -function _isNull(params, error) -{ - return nativeTypeOf(params[0]) == "null"; -} -jsonrpc.method.isNull = _isNull; - -function _getParams(params, error) -{ - return params; -} -jsonrpc.method.getParams = _getParams; - -function _getParam(params, error) -{ - return params[0]; -} -jsonrpc.method.getParam = _getParam; - -function _getCurrentTimestamp() -{ - now = gettimeofday(); - obj = new Object(); - obj.now = now.sec; - obj.json = JSON_Date.create(now); - return obj; -} -jsonrpc.method.getCurrentTimestamp = _getCurrentTimestamp; - -function _getError(params, error) -{ - error.setError(23, "This is an application-provided error"); - return error; -} -jsonrpc.method.getError = _getError; - - -/* - * Local Variables: - * mode: c - * End: - */ -%> diff --git a/services/request.esp b/services/request.esp deleted file mode 100644 index 03226f975d..0000000000 --- a/services/request.esp +++ /dev/null @@ -1,540 +0,0 @@ -<% - -/* - * Copyright: - * (C) 2006 by Derrell Lipman - * All rights reserved - * - * License: - * LGPL 2.1: http://creativecommons.org/licenses/LGPL/2.1/ - */ - -/* - * This is a simple JSON-RPC server. - */ - -/* Bring in the json format/parse functions */ -jsonrpc_include("json.esp"); - -/* Bring in the date class */ -jsonrpc_include("jsondate.esp"); - -/* Load the authentication script */ -jsonrpc_include("json_auth.esp"); - - -/* bring the string functions into the global frame */ -string_init(global); - -/* Bring the system functions into the global frame */ -sys_init(global); - -/* Bring the session functions into the global frame */ -system_session(global); - - -function printf() -{ - print(vsprintf(arguments)); -} - - -/* - * All of our manipulation of JSON RPC methods will be through this object. - * Each class of methods will assign to here, and all of the constants will - * also be in this object. - */ -jsonrpc = new Object(); -jsonrpc.Constant = new Object(); -jsonrpc.Constant.ErrorOrigin = new Object(); /* error origins */ -jsonrpc.Constant.ServerError = new Object(); /* server-generated error codes */ -jsonrpc.method = new Object(); /* methods available in requested class */ - -/* - * ScriptTransport constants - */ -jsonrpc.Constant.ScriptTransport = new Object(); -jsonrpc.Constant.ScriptTransport.NotInUse = -1; - - -/* - * JSON-RPC error origin constants - */ -jsonrpc.Constant.ErrorOrigin.Server = 1; -jsonrpc.Constant.ErrorOrigin.Application = 2; -jsonrpc.Constant.ErrorOrigin.Transport = 3; -jsonrpc.Constant.ErrorOrigin.Client = 4; - - - -/* - * JSON-RPC server-generated error code constants - */ - -/** - * Error code, value 0: Unknown Error - * - * The default error code, used only when no specific error code is passed to - * the JsonRpcError constructor. This code should generally not be used. - */ -jsonrpc.Constant.ServerError.Unknown = 0; - -/** - * Error code, value 1: Illegal Service - * - * The service name contains illegal characters or is otherwise deemed - * unacceptable to the JSON-RPC server. - */ -jsonrpc.Constant.ServerError.IllegalService = 1; - -/** - * Error code, value 2: Service Not Found - * - * The requested service does not exist at the JSON-RPC server. - */ -jsonrpc.Constant.ServerError.ServiceNotFound = 2; - -/** - * Error code, value 3: Class Not Found - * - * If the JSON-RPC server divides service methods into subsets (classes), this - * indicates that the specified class was not found. This is slightly more - * detailed than "Method Not Found", but that error would always also be legal - * (and true) whenever this one is returned. (Not used in this implementation) - */ -jsonrpc.Constant.ServerError.ClassNotFound = 3; - -/** - * Error code, value 4: Method Not Found - * - * The method specified in the request is not found in the requested service. - */ -jsonrpc.Constant.ServerError.MethodNotFound = 4; - -/* - * Error code, value 5: Parameter Mismatch - * - * If a method discovers that the parameters (arguments) provided to it do not - * match the requisite types for the method's parameters, it should return - * this error code to indicate so to the caller. - * - * This error is also used to indicate an illegal parameter value, in server - * scripts. - */ -jsonrpc.Constant.ServerError.ParameterMismatch = 5; - -/** - * Error code, value 6: Permission Denied - * - * A JSON-RPC service provider can require authentication, and that - * authentication can be implemented such the method takes authentication - * parameters, or such that a method or class of methods requires prior - * authentication. If the caller has not properly authenticated to use the - * requested method, this error code is returned. - */ -jsonrpc.Constant.ServerError.PermissionDenied = 6; - -/*** Errors generated by this server which are not qooxdoo-standard ***/ - -/* - * Error code, value 1000: Unexpected Output - * - * The called method illegally generated output to the browser, which would - * have preceeded the JSON-RPC data. - */ -jsonrpc.Constant.ServerError.UnexpectedOutput = 1000; - -/* - * Error code, value 1001: Resource Error - * - * Too many resources were requested, a system limitation on the total number - * of resources has been reached, or a resource or resource id was misused. - */ -jsonrpc.Constant.ServerError.ResourceError = 1001; - -/* - * Error code, value 1002: Not Logged In - * - * The user has logged out and must re-authenticate, or this is a brand new - * session and the user must log in. - * - */ -jsonrpc.Constant.ServerError.NotLoggedIn = 1002; - -/* - * Error code, value 1003: Session Expired - * - * The session has expired and the user must re-authenticate. - * - */ -jsonrpc.Constant.ServerError.SessionExpired = 1003; - -/* - * Error code, value 1004: Login Failed - * - * An attempt to log in failed. - * - */ -jsonrpc.Constant.ServerError.LoginFailed = 1004; - - - - - -function sendReply(reply, scriptTransportId) -{ - /* If not using ScriptTransport... */ - if (scriptTransportId == jsonrpc.Constant.ScriptTransport.NotInUse) - { - /* ... then just output the reply. */ - write(reply); - } - else - { - /* Otherwise, we need to add a call to a qooxdoo-specific function */ - reply = - "qx.io.remote.ScriptTransport._requestFinished(" + - scriptTransportId + ", " + reply + - ");"; - write(reply); - } -} - - -function _jsonValidRequest(req) -{ - if (req == undefined) - { - return false; - } - - if (typeof(req) != "object") - { - return false; - } - - if (req["id"] == undefined) - { - return false; - } - - if (req["service"] == undefined) - { - return false; - } - - if (req["method"] == undefined) - { - return false; - } - - if (req["params"] == undefined) - { - return false; - } - - return true; -} -jsonrpc.validRequest = _jsonValidRequest; -_jsonValidRequest = null; - -/* - * class JsonRpcError - * - * This class allows service methods to easily provide error information for - * return via JSON-RPC. - */ -function _JsonRpcError_create(origin, code, message) -{ - var o = new Object(); - - o.data = new Object(); - o.data.origin = origin; - o.data.code = code; - o.data.message = message; - o.scriptTransportId = jsonrpc.Constant.ScriptTransport.NotInUse; - o.__type = "_JsonRpcError"; - - function _origin(origin) - { - this.data.origin = origin; - } - o.setOrigin = _origin; - - function _setError(code, message) - { - this.data.code = code; - this.data.message = message; - } - o.setError = _setError; - - function _setId(id) - { - this.id = id; - } - o.setId = _setId; - - function _setScriptTransportId(id) - { - this.scriptTransportId = id; - } - o.setScriptTransportId = _setScriptTransportId; - - function _setInfo(info) - { - // Add the info field only if info is actually provided. - // This is an extension to qooxdoo's normal Error return value. - this.data.info = info; - } - o.setInfo = _setInfo; - - function _Send() - { - var error = this; - var id = this.id; - var ret = new Object(); - ret.error = this.data; - ret.id = this.id; - sendReply(Json.encode(ret), this.scriptTransportId); - } - o.Send = _Send; - - return o; -} - -jsonrpc.createError = _JsonRpcError_create; -_JsonRpcError_create = null; - -/* - * 'input' is the user-provided json-encoded request - * 'jsonInput' is that request, decoded into its object form - */ -var input; -var jsonInput = null; - -/* Allocate a generic error object */ -error = jsonrpc.createError(jsonrpc.Constant.ErrorOrigin.Server, - jsonrpc.Constant.ServerError.Unknown, - "Unknown error"); - -/* Assume (default) we're not using ScriptTransport */ -scriptTransportId = jsonrpc.Constant.ScriptTransport.NotInUse; - -/* What type of request did we receive? */ -if (request["REQUEST_METHOD"] == "POST" && - request["CONTENT_TYPE"] == "application/json") -{ - /* We found literal POSTed json-rpc data (we hope) */ - input = request["POST_DATA"]; - jsonInput = Json.decode(input); -} -else if (request["REQUEST_METHOD"] == "GET" && - form["_ScriptTransport_id"] != undefined && - form["_ScriptTransport_id"] != - jsonrpc.Constant.ScriptTransport.NotInUse && - form["_ScriptTransport_data"] != undefined) -{ - /* We have what looks like a valid ScriptTransport request */ - scriptTransportId = form["_ScriptTransport_id"]; - error.setScriptTransportId(scriptTransportId); - input = form["_ScriptTransport_data"]; - jsonInput = Json.decode(input); -} - -/* Ensure that this was a JSON-RPC service request */ -if (! jsonrpc.validRequest(jsonInput)) -{ - /* - * This request was not issued with JSON-RPC so echo the error rather than - * issuing a JsonRpcError response. - */ - write("JSON-RPC request expected; service, method or params missing<br>"); - return; -} - -/* - * Ok, it looks like JSON-RPC, so we'll return an Error object if we encounter - * errors from here on out. - */ -error.setId(jsonInput.id); - -/* Service and method names may contain these characters */ -var nameChars = - "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; - -/* The first letter of service and method names must be a letter */ -var nameFirstLetter = - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - -/* - * Ensure the method name is kosher. A method name should be: - * - * - first character is in [a-zA-Z] - * - other characters are in [_a-zA-Z0-9] - */ - -/* First check for legal characters */ -if (strspn(jsonInput.method, nameChars) != strlen(jsonInput.method)) -{ - /* There's some illegal character in the service name */ - error.setError(jsonrpc.Constant.ServerError.MethodNotFound, - "Illegal character found in method name."); - error.Send(); - return; -} - -/* Now ensure that it begins with a letter */ -if (strspn(substr(jsonInput.method, 0, 1), nameFirstLetter) != 1) -{ - error.setError(jsonrpc.Constant.ServerError.MethodNotFound, - "The method name does not begin with a letter"); - error.Send(); - return; -} - -/* - * Ensure the requested service name is kosher. A service name should be: - * - * - a dot-separated sequences of strings; no adjacent dots - * - first character of each string is in [a-zA-Z] - * - other characters are in [_a-zA-Z0-9] - */ - -/* First check for legal characters */ -if (strspn(jsonInput.service, "." + nameChars) != strlen(jsonInput.service)) -{ - /* There's some illegal character in the service name */ - error.setError(jsonrpc.Constant.ServerError.IllegalService, - "Illegal character found in service name."); - error.Send(); - return; -} - -/* - * Now ensure there are no double dots. - * - * Frustration with ejs. Result must be NULL, but we can't use the === - * operator: strstr() === null so we have to use typeof. If the result isn't - * null, then it'll be a number and therefore not type "pointer". - */ -if (typeof(strstr(jsonInput.service, "..")) != "pointer") -{ - error.setError(jsonrpc.Constant.ServerError.IllegalService, - "Illegal use of two consecutive dots in service name"); - error.Send(); - return; -} - -/* Explode the service name into its dot-separated parts */ -var serviceComponents = split(".", jsonInput.service); - -/* Ensure that each component begins with a letter */ -for (var i = 0; i < serviceComponents.length; i++) -{ - if (strspn(substr(serviceComponents[i], 0, 1), nameFirstLetter) != 1) - { - error.setError(jsonrpc.Constant.ServerError.IllegalService, - "A service name component does not begin with a letter"); - error.Send(); - return; - } -} - -/* - * Now replace all dots with slashes so we can locate the service script. We - * also retain the split components of the path, as the class name of the - * service is the last component of the path. - */ -var servicePath = join("/", serviceComponents) + ".esp"; - -/* Load the requested class */ -if (jsonrpc_include(servicePath)) -{ - /* Couldn't find the requested service */ - error.setError(jsonrpc.Constant.ServerError.ServiceNotFound, - "Service class `" + servicePath + "` does not exist."); - error.Send(); - return; -} - -/* - * Find the requested method. - * - * What we really want to do here, and could do in any reasonable language, - * is: - * - * method = jsonrpc.method[jsonInput.method]; - * if (method && typeof(method) == "function") ... - * - * The following completely unreasonable sequence of commands is because: - * - * (a) ejs evaluates all OR'ed expressions even if an early one is false, and - * barfs on the typeof(method) call if method is undefined - * - * (b) ejs does not allow comparing against the string "function"!!! What - * the hell is special about that particular string??? - * - * E-gad. What a mess. - */ -var method = jsonrpc.method[jsonInput.method]; -var valid = (method != undefined); -if (valid) -{ - var type = typeof(method); - if (substr(type, 0, 1) != 'f' || substr(type, 1) != "unction") - { - valid = false; - } -} - -if (! valid) -{ - error.setError(jsonrpc.Constant.ServerError.MethodNotFound, - "Method `" + jsonInput.method + "` not found."); - error.Send(); - return; -} - -/* - * Ensure the logged-in user is allowed to issue the requested method. We - * provide the scriptTransportId as one of the determining factors because - * accepting requests via ScriptTransport is dangerous. Only methods which - * one might allow when unauthenticated should be allowed via ScriptTransport - * as it is easy for a rogue site to trick a user into bypassing - * authentication. - */ -if (! json_authenticate(serviceComponents, - jsonInput.method, - scriptTransportId, - error)) -{ - error.Send(); - return; -} - -/* Most errors from here on out will be Application-generated */ -error.setOrigin(jsonrpc.Constant.ErrorOrigin.Application); - -/* Call the requested method passing it the provided params */ -var retval = method(jsonInput.params, error); - -/* See if the result of the function was actually an error object */ -if (retval["__type"] == "_JsonRpcError") -{ - /* Yup, it was. Return the error */ - retval.Send(); - return; -} - -/* Give 'em what they came for! */ -var ret = new Object(); -ret.result = retval; -ret.id = jsonInput.id; -sendReply(Json.encode(ret), scriptTransportId); - -/* - * Local Variables: - * mode: c - * End: - */ -%> diff --git a/services/resources.esp b/services/resources.esp deleted file mode 100644 index b5c4bd3b3d..0000000000 --- a/services/resources.esp +++ /dev/null @@ -1,171 +0,0 @@ -<% - -/* - * Various JSON-RPC calls will want to maintain open resources within a - * session, across multiple calls. We'll provide a standardized way to - * maintain those open resources here, with some protection against rogue - * scripts. - */ - -function _resourcesCreate() -{ - /* The being-created resources object */ - var o = new Object(); - - /* - * The maximum number of resources available to a single session. This - * should be more than is ever needed (even by reasonable recursive - * functions) but limits rogue scripts ability to generate DOS attacks. - */ - o.RESOURCE_LIMIT = 100; - - /* List of current resources */ - o.resourceList = new Object(); - - /* Resource id values will be constantly incrementing; never reset. */ - o.resourceList.id = 0; - - /* We'll maintain our own count of the number of open resources */ - o.resourceList.count = 0; - - - /* - * Set a new saved resource. - */ - function _set(resource, type, error) - { - /* Do they already have the maximum number of resources allocated? */ - if (this.resourceList.count >= this.RESOURCE_LIMIT) - { - /* Yup. */ - error.setOrigin(jsonrpc.Constant.ErrorOrigin.Server); - error.setError(jsonrpc.Constant.ServerError.ResourceError, - "Session limit on resources (" + - RESOURCE_LIMIT + - ") exceeded."); - return error; - } - - /* Allocate an object to hold the new resource and its type */ - var r = new Object(); - - /* Save the resource and its type */ - r.resource = resource; - r.type = type; - r.id = this.resourceList.id; - - /* Add this resource to the list */ - this.resourceList[this.resourceList.id] = r; - - /* There's a new resource in the list! */ - this.resourceList.count++; - - /* - * Return the index of the resource, its resource id, and advance to - * the next resource id for next time. - */ - var id = this.resourceList.id; - this.resourceList.id++; - return id; - } - o.set = _set; - - /* - * Get a previously-saved resource - */ - function _get(resourceId, error) - { - /* Does the specified resource id exist? */ - if (! this.resourceList[resourceId]) - { - /* Nope. */ - error.setOrigin(jsonrpc.Constant.ErrorOrigin.Server); - error.setError(jsonrpc.Constant.ServerError.ResourceError, - "Resource not found."); - return error; - } - - /* Retrieve the resource */ - var r = this.resourceList[resourceId]; - - /* Give 'em what they came for! */ - return r.resource; - } - o.get = _get; - - /* - * Find a previously-saved resource - */ - function _find(type, error) - { - /* Does the specified resource id exist? */ - for (var resourceId in this.resourceList) - { - /* Retrieve the resource */ - var r = this.resourceList[resourceId]; - - /* Ignore "id" and "count" integer fields */ - if (typeof(r) == "object") - { - /* Is the specified resource the correct type? */ - if (r.type == type) - { - /* Yup, this is the one they want. */ - return r.id; - } - } - } - - /* It wasn't found. */ - return undefined; - } - o.find = _find; - - /* - * Release a previously-saved resource, allowing it to be freed - */ - function _release(resourceId, error) - { - /* Does the specified resource id exist? */ - if (! this.resourceList[resourceId]) - { - /* Nope. */ - error.setOrigin(jsonrpc.Constant.ErrorOrigin.Server); - error.setError(jsonrpc.Constant.ServerError.ResourceError, - "Resource not found."); - return error; - } - - /* It exists. Delete it. */ - delete this.resourceList[resourceId]; - - /* There's now one fewer resources in the list */ - this.resourceList.count--; - } - o.release = _release; - - /* - * Retrieve the list of resources (for debugging) */ - */ - function _getList(error) - { - return this.resourceList; - } - o.getList = _getList; - - return o; -} - -/* singleton: create session resources list */ -if (! session.resources) -{ - session.resources = _resourcesCreate(); -} - - -/* - * Local Variables: - * mode: c - * End: - */ -%> diff --git a/services/samba/adm.esp b/services/samba/adm.esp deleted file mode 100644 index 8843a068eb..0000000000 --- a/services/samba/adm.esp +++ /dev/null @@ -1,28 +0,0 @@ -<% - -jsonrpc_include("resources.esp"); - -libinclude("base.js"); -libinclude("management.js"); - -function _echo(params, error) { - var echo_string = params[0]; - return echo_string; -} -jsonrpc.method.echo = _echo; - -function _nbt_packet_stats(params, error) { - var stats = nbtd_statistics(); - stats.server_status = new Object(); - stats.server_status = server_status("nbt"); - return stats; -} -jsonrpc.method.NBTPacketStats = _nbt_packet_stats; - - -/* - * Local Variables: - * mode: c - * End: - */ -%> diff --git a/services/samba/config.esp b/services/samba/config.esp deleted file mode 100644 index bf4b789c13..0000000000 --- a/services/samba/config.esp +++ /dev/null @@ -1,26 +0,0 @@ -<% - -/* - * Copyright (C) Rafal Szczesniak 2007 - */ - -/* Simple JSON-RPC access to the configuration parameters */ - -function _lp_get(params, error) -{ - if (params.length < 1) - { - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "no parameter specified"); - return error; - } - - var lp = loadparm_init(); - var name = params[0]; - var value = lp.get(name); - - return value; -} -jsonrpc.method.lp_get = _lp_get; - -%> diff --git a/services/samba/ejsnet.esp b/services/samba/ejsnet.esp deleted file mode 100644 index 00424f2cae..0000000000 --- a/services/samba/ejsnet.esp +++ /dev/null @@ -1,178 +0,0 @@ -<% - -/* - * Copyright (C) Rafal Szczesniak 2007 - */ - -/* JSON-RPC mappings to the libnet functions */ - -jsonrpc_include("resources.esp"); - - -function _NetContext(params, error) -{ - var hostName, credParams, credentials; - var resName = "netCtx"; - - credentials = session.authinfo.credentials; - - if (params.length > 0) - { - /* first expected argument is host name that this context is going - to be attached to */ - hostName = params[0]; - if (typeof(hostName) != "string" || hostName == "") - { - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "hostName parameter is expected to be a valid non zero-length string"); - return error; - } - - resName = "netCtx[" + hostName + "]"; - - /* check whether credentials are supplied as well */ - if (params.length > 1) - { - /* create user specified credentials object */ - credParams = params[1]; - if (typeof(credParams) != "object") - { - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "credentials parameter is expected to be an object"); - return error; - } - - if (typeof(credParams.domain) != "string") - { - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "a valid string is expected in credentials.domain"); - return error; - } - - if (typeof(credParams.username) != "string") - { - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "a valid string is expected in credentials.username"); - return error; - } - - if (typeof(credParams.username) != "string") - { - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "a valid string is expected in credentials.password"); - return error; - } - - credentials = credentials_init(); - credentials.set_domain(credParams.domain); - credentials.set_username(credParams.username); - credentials.set_password(credParams.password); - } - } - - /* was this NetContext created yet ? */ - var resId = session.resources.find(resName, error); - if (resId != undefined) - { - /* yes, return its resource id */ - return resId; - } - - /* no, create the new context and assign it a resource id */ - var netCtx = NetContext(credentials); - resId = session.resources.set(netCtx, resName, error); - return resId; -} -jsonrpc.method.NetContext = _NetContext; - - -function _NetContextCreds(params, error) -{ - if (params.length != 1) - { - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "missing resource id parameter"); - return error; - } - - var resId = params[0]; - if (typeof(resId) != "number") - { - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "an integer parameter is required"); - return error; - } - - var netCtx = session.resources.get(resId, error); - if (typeof(netCtx) != "object") - { - return null; - } - - var creds = netCtx.credentials; - var result = new Object(); - result.username = creds.get_username(); - result.domain = creds.get_domain(); - - return result; -} -jsonrpc.method.NetContextCreds = _NetContextCreds; - - -function _UserMgr(params, error) -{ - var domainName = null, netCtxId; - var resId = -1; - var resName = "usrCtx"; - var netCtx = undefined; - var usrCtx = undefined; - - if (params.length == 0) - { - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "NetContext parameter missing"); - return error; - } - - /* checking NetContext parameter */ - netCtxId = params[0]; - if (netCtxId == undefined || typeof(netCtxId) != "number") - { - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "NetContext parameter is expected to be a number"); - } - - netCtx = session.resources.get(netCtxId, error); - if (netCtx == undefined || typeof(netCtx) != "object") - { - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "Incorrect NetContext passed"); - return error; - } - - if (params.length > 1) - { - domainName = params[1]; - if (domainName == undefined || typeof(domainName) != "string") - { - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "domainName parameter is expected to be a valid non zero-length string"); - return error; - } - } - - if (domainName == "") - { - usrCtx = netCtx.UserMgr(); - } - else - { - usrCtx = netCtx.UserMgr(domainName); - } - - resId = session.resources.set(usrCtx, resName, error); - return resId; -} -jsonrpc.method.UserMgr = _UserMgr; - -%> diff --git a/services/samba/ldb.esp b/services/samba/ldb.esp deleted file mode 100644 index f69abde388..0000000000 --- a/services/samba/ldb.esp +++ /dev/null @@ -1,675 +0,0 @@ -<% -/* - * Copyright: - * (C) 2006 by Derrell Lipman - * All rights reserved - * - * License: - * LGPL 2.1: http://creativecommons.org/licenses/LGPL/2.1/ - */ - -/* - * JSON-RPC mappings to the ldb ejs functions - */ - -/* We'll be saving resources in the session */ -jsonrpc_include("resources.esp"); - - -/** - * Local function to determine if the requested database is one which we allow - * access to. - * - * @param dbRequested - * Name of the database which is being requested to be opened - * - * @return - * true if access is allowed; false otherwise. - */ -function accessAllowed(dbRequested) -{ - /* Databases allowed to connect to */ - dbAllowed = new Array(); - dbAllowed[dbAllowed.length] = "sam.ldb"; - - for (var i = 0; i < dbAllowed.length; i++) - { - if (dbRequested == dbAllowed[i]) - { - return true; - } - } - - return false; -} - - -/** - * Connect to a database - * - * @param params[0] - * Database name - * - * @param params[1..n] - * Option (e.g. "modules:modlist") - * - * @param error - * An object of class JsonRpcError. - * - * @return - * Success: The resource id to be used for future access to the database - * Failure: error event - * - * @note - * Credentials or session_info may be set up first. - */ -function _connect(params, error) -{ - if (params.length < 1) - { - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "usage: <db_name> [<option> ...]"); - return error; - } - - /* First, see if this database was already opened */ - var resourceId = session.resources.find("ldb:" + params[0], error); - if (resourceId != undefined) - { - /* It was. Give 'em the resource id */ - return resourceId; - } - - /* Ensure that the database name is one that is allowed to be opened */ - if (! accessAllowed(params[0])) - { - error.setError(-1, "Invalid or disallowed database name"); - return error; - } - - /* Get access to loadparm functions */ - var lp = loadparm_init(); - - /* Determine the private directory */ - var private_dir = lp.get("private dir"); - - /* Database was not previously opened. Connect to it. */ - ldb = ldb_init(); - ldb.session_info = session.authinfo.session_info; - ldb.credentials = session.authinfo.credentials; - var ret = ldb.connect(private_dir + "/" + params[0]); - if (ret && ldb.db) - { - return session.resources.set(ldb, "ldb:" + params[0], error); - } - else - { - error.setError(-1, "ldb.connect failed"); - return error; - } -} -jsonrpc.method.connect = _connect; - - -/** - * Close a database - * - * @param params[0] - * The resource id of the open database, previously returned by connect() - * - * @param error - * An object of class JsonRpcError. - * - * @return - * Success: True - * Failure: Will only fail with invalid parameters, and throws an error - */ -function _close(params, error) -{ - if (params.length != 1) - { - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "usage: <resource_id>"); - return error; - } - - ldb = session.resources.get(params[0], error); - if (ldb["__type"] == "_JsonRpcError") - { - return ldb; - } - - var ret = ldb.close(); - - /* If close succeeded, release the stored resource */ - if (ret) - { - session.resources.release(params[0], error); - } - - return ret; -} -jsonrpc.method.close = _close; - - -/** - * Begin a transaction - * - * @param params[0] - * The resource id of the open database, previously returned by connect() - * - * @param error - * An object of class JsonRpcError. - * - * @return - * Success: True - * Failure: False - */ -function _transaction_start(params, error) -{ - if (params.length != 1) - { - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "usage: <resource_id>"); - return error; - } - - ldb = session.resources.get(params[0], error); - if (ldb["__type"] == "_JsonRpcError") - { - return ldb; - } - - return ldb.transaction_start(); -} -jsonrpc.method.transaction_start = _transaction_start; - - -/** - * Cancel a transaction - * - * @param params[0] - * The resource id of the open database, previously returned by connect() - * - * @param error - * An object of class JsonRpcError. - * - * @return - * Success: True - * Failure: False - */ -function _transaction_cancel(params, error) -{ - if (params.length != 1) - { - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "usage: <resource_id>"); - return error; - } - - ldb = session.resources.get(params[0], error); - if (ldb["__type"] == "_JsonRpcError") - { - return ldb; - } - - return ldb.transaction_cancel(); -} -jsonrpc.method.transaction_cancel = _transaction_cancel; - - -/** - * Commit a transaction - * - * @param params[0] - * The resource id of the open database, previously returned by connect() - * - * @param error - * An object of class JsonRpcError. - * - * @return - * Success: True - * Failure: False - */ -function _transaction_commit(params, error) -{ - if (params.length != 1) - { - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "usage: <resource_id>"); - return error; - } - - ldb = session.resources.get(params[0], error); - if (ldb["__type"] == "_JsonRpcError") - { - return ldb; - } - - return ldb.transaction_commit(); -} -jsonrpc.method.transaction_commit = _transaction_commit; - - -/** - * Issue a Search request - * - * @param params[0] - * The resource id of the open database, previously returned by connect() - * - * @param params[1] - * Search expression - * - * @param params[2] - * Base DN - * - * @param params[3] - * Scope: "default", "base", "one" or "subtree" - * - * @param params[4] - * Attributes: an array object - * - * @param error - * An object of class JsonRpcError. - * - * @return - * Success: found object - * Failure: `undefined` - * - * @note - * If params[4] is missing, assume no attributes - * If params[3..4] are missing, also assume "default" scope - * If params[2..4] are missing, also assume null base DN - */ -function _search(params, error) -{ - if (params.length < 2 || params.length > 5) - { - error.setOrigin(jsonrpc.Constant.ErrorOrigin.Server); - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "usage: " + - "<resource_id> <expr> [<baseDN> [<scope> [<attrs>]]]"); - return error; - } - - ldb = session.resources.get(params[0], error); - if (ldb["__type"] == "_JsonRpcError") - { - return ldb; - } - - /* Retrieve parameters */ - var expr = params[1]; - var baseDN = params[2]; - var scope = params[3]; - var attrs = params[4]; - - /* Fill in optional parameters */ - if (params.length < 3) baseDN = null; - if (params.length < 4) scope = "one"; - if (params.length < 5) attrs = null; - - /* Determine scope value */ - if (scope == "base") - { - scope = ldb.SCOPE_BASE; - } - else if (scope == "one") - { - scope = ldb.SCOPE_ONE; - } - else if (scope == "subtree") - { - scope = ldb.SCOPE_SUBTREE; - } - else if (scope == "default") - { - scope = ldb.SCOPE_DEFAULT; - } - else - { - error.setOrigin(jsonrpc.Constant.ErrorOrigin.Server); - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "invalid scope: " + scope); - return error; - } - - var res = ldb.search(expr, baseDN, scope, attrs); - - if (res.error != 0) { - error.setError(res.error, res.errstr); - return error; - } - - return res.msgs; -} -jsonrpc.method.search = _search; - - -/** - * Add data to the database - * - * @param params[0] - * The resource id of the open database, previously returned by connect() - * - * @param params[1] - * An LDIF string representing the data to be added - * - * @param error - * An object of class JsonRpcError. - * - * @return - * Success: True - * Failure: False - */ -function _add(params, error) -{ - if (params.length != 2) - { - error.setOrigin(jsonrpc.Constant.ErrorOrigin.Server); - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "usage: <resource_id> <ldif>"); - return error; - } - - ldb = session.resources.get(params[0], error); - if (ldb["__type"] == "_JsonRpcError") - { - return ldb; - } - - var res = ldb.add(params[1]); - if (res.error != 0) { - error.setError(res.error, res.errstr); - return error; - } - - return true; -} -jsonrpc.method.add = _add; - - -/** - * Modify data in the database - * - * @param params[0] - * The resource id of the open database, previously returned by connect() - * - * @param params[1] - * An LDIF string representing the data to be modified - * - * @param error - * An object of class JsonRpcError. - * - * @return - * Success: True - * Failure: False - */ -function _modify(params, error) -{ - if (params.length != 2) - { - error.setOrigin(jsonrpc.Constant.ErrorOrigin.Server); - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "usage: <resource_id> <ldif>"); - return error; - } - - ldb = session.resources.get(params[0], error); - if (ldb["__type"] == "_JsonRpcError") - { - return ldb; - } - - var res = ldb.modify(params[1]); - if (res.error != 0) { - error.setError(res.error, res.errstr); - return error; - } - - return true; -} -jsonrpc.method.modify = _modify; - - -/** - * Delete data from the database - * - * @param params[0] - * The resource id of the open database, previously returned by connect() - * - * @param params[1] - * The DN to be located and deleted - * - * @param error - * An object of class JsonRpcError. - * - * @return - * Success: True - * Failure: False - */ -function _del(params, error) -{ - if (params.length != 2) - { - error.setOrigin(jsonrpc.Constant.ErrorOrigin.Server); - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "usage: <resource_id> <dn>"); - return error; - } - - ldb = session.resources.get(params[0], error); - if (ldb["__type"] == "_JsonRpcError") - { - return ldb; - } - - var res = ldb.del(params[1]); - if (res.error != 0) { - error.setError(res.error, res.errstr); - return error; - } - - return true; -} -jsonrpc.method.del = _del; - - -/** - * Rename data in the database - * - * @param params[0] - * The resource id of the open database, previously returned by connect() - * - * @param params[1] - * The DN to be renamed - * - * @param params[2] - * The new name for the DN being renamed - * - * @param error - * An object of class JsonRpcError. - * - * @return - * Success: True - * Failure: False - */ -function _rename(params, error) -{ - if (params.length != 3) - { - error.setOrigin(jsonrpc.Constant.ErrorOrigin.Server); - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "usage: <resource_id> <old_dn> <new_dn>"); - return error; - } - - ldb = session.resources.get(params[0], error); - if (ldb["__type"] == "_JsonRpcError") - { - return ldb; - } - - var res = ldb.rename(params[1], params[2]); - if (res.error != 0) { - error.setError(res.error, res.errstr); - return error; - } - - return true; -} -jsonrpc.method.rename = _rename; - - -/** - * Base64-encode a string - * - * @param params[0] - * The resource id of the open database, previously returned by connect() - * - * @param params[1] - * The string to be base64 encoded - * - * @param error - * An object of class JsonRpcError. - * - * @return - * Success: encoded string - * Failure: `undefined` - */ -function _base64encode(params, error) -{ - if (params.length != 2) - { - error.setOrigin(jsonrpc.Constant.ErrorOrigin.Server); - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "usage: <resource_id> <string_to_be_encoded>"); - return error; - } - - ldb = session.resources.get(params[0], error); - if (ldb["__type"] == "_JsonRpcError") - { - return ldb; - } - - return ldb.base64encode(params[1]); -} -jsonrpc.method.base64encode = _base64encode; - - -/** - * Base64-decode a string - * - * @param params[0] - * The resource id of the open database, previously returned by connect() - * - * @param params[1] - * The string to be base64 decoded - * - * @param error - * An object of class JsonRpcError. - * - * @return - * Success: decoded string - * Failure: `undefined` - */ -function _base64decode(params, error) -{ - if (params.length != 2) - { - error.setOrigin(jsonrpc.Constant.ErrorOrigin.Server); - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "usage: <resource_id> <string_to_be_decoded>"); - return error; - } - - ldb = session.resources.get(params[0], error); - if (ldb["__type"] == "_JsonRpcError") - { - return ldb; - } - - return ldb.base64decode(params[1]); -} -jsonrpc.method.base64decode = _base64decode; - - -/** - * escape a DN - * - * @param params[0] - * The resource id of the open database, previously returned by connect() - * - * @param params[1] - * The DN to be escaped - * - * @param error - * An object of class JsonRpcError. - * - * @return - * Success: escaped string - * Failure: undefined - */ -function _base64decode(params, error) -{ - if (params.length != 2) - { - error.setOrigin(jsonrpc.Constant.ErrorOrigin.Server); - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "usage: <resource_id> <string_to_be_decoded>"); - return error; - } - - ldb = session.resources.get(params[0], error); - if (ldb["__type"] == "_JsonRpcError") - { - return ldb; - } - - return ldb.base64decode(params[1]); -} -jsonrpc.method.base64decode = _base64decode; - - -/** - * Retrieve a description of the most recent error - * - * @param params[0] - * The resource id of the open database, previously returned by connect() - * - * @param error - * An object of class JsonRpcError. - * - * @return - * The most recent error string for the ldb specified by the resource id - */ -function _errstring(params, error) -{ - if (params.length != 1) - { - error.setOrigin(jsonrpc.Constant.ErrorOrigin.Server); - error.setError(jsonrpc.Constant.ServerError.ParameterMismatch, - "usage: <resource_id>"); - return error; - } - - ldb = session.resources.get(params[0], error); - if (ldb["__type"] == "_JsonRpcError") - { - return ldb; - } - - return ldb.errstring(); -} -jsonrpc.method.errstring = _errstring; - - - - -/* - * Local Variables: - * mode: c - * End: - */ -%> diff --git a/services/samba/management.esp b/services/samba/management.esp deleted file mode 100644 index 1efd8f6777..0000000000 --- a/services/samba/management.esp +++ /dev/null @@ -1,184 +0,0 @@ -<% -/* - * Copyright: - * (C) 2006 by Derrell Lipman - * All rights reserved - * - * License: - * LGPL 2.1: http://creativecommons.org/licenses/LGPL/2.1/ - */ - -/* - * JSON-RPC mappings to management functions - */ - -libinclude("base.js"); -libinclude("management.js"); - -/** - * Get statistics from each of the servers - * - * @param params[0] - * Optional enum_smb_sessions flag, default false - * - * @param params[1] - * Optional enum_smb_tcons flag, default false - * - * @param error - * An object of class JsonRpcError. - * - * @return - * Success: Object containing all of the statistics - * Failure: error event - */ -function _get_statistics(params, error) -{ - var enum_smb_sessions = false; - var enum_smb_tcons = false; - - if (params.length >= 1) - { - enum_smb_sessions = params[0]; - } - if (params.length >= 2) - { - enum_smb_tcons = params[1]; - } - - var info = new Object(); - - info["nbt"] = new Object(); - info["wins"] = new Object(); - info["cldap"] = new Object(); - info["kdc"] = new Object(); - info["smb"] = new Object(); - info["ldap"] = new Object(); - info["rpc"] = new Object(); - - for (var service in info) - { - var irpc = irpc_init(); - var status; - var obj = info[service]; - obj.status = null; - - if (!service_enabled(service)) - { - obj.status = "DISABLED"; - } - else - { - status = irpc.connect(service + "_server"); - if (status.is_ok != true) - { - obj.status = "INACTIVE"; - } - else - { - var io = irpcObj(); - status = irpc.irpc_uptime(io); - if (status.is_ok != true) - { - obj.status = "NOT RESPONDING"; - } - else - { - obj.status = "RUNNING"; - - if (service == "smb" || - service == "ldap" || - service == "rpc") - { - obj.connections = io.results.length; - } - - if (service == "smb") - { - if (enum_smb_sessions) - { - var io = irpcObj(); - io.input.level = irpc.SMBSRV_INFO_SESSIONS; - status = irpc.smbsrv_information(io); - obj.sessions = new Array(0); - if (status.is_ok == true) - { - /* gather the results into a single array */ - var count = 0; - for (var i = 0; i < io.results.length; i++) - { - var sessions = - io.results[i].info.sessions.sessions; - for (var j = 0; j < sessions.length; j++) - { - obj.sessions[count] = sessions[j]; - - // convert NT times to unix epoch - obj.sessions[count].auth_time = - nttime2unix(obj.sessions[count].auth_time); - obj.sessions[count].last_use_time = - nttime2unix(obj.sessions[count].last_use_time); - obj.sessions[count].connect_time = - nttime2unix(obj.sessions[count].connect_time); - - count++; - } - } - } - } - - if (enum_smb_tcons) - { - var io = irpcObj(); - io.input.level = irpc.SMBSRV_INFO_TCONS; - status = irpc.smbsrv_information(io); - obj.tcons = new Array(0); - - if (status.is_ok == true) - { - /* gather the results into a single array */ - var count=0; - for (var i = 0; i < io.results.length; i++) - { - var tcons = io.results[i].info.tcons.tcons; - for (var j = 0; j < tcons.length; j++) - { - obj.tcons[count] = tcons[j]; - - - // convert NT times to unix epoch - obj.tcons[count].last_use_time = - nttime2unix(obj.tcons[count].last_use_time); - obj.tcons[count].connect_time = - nttime2unix(obj.tcons[count].connect_time); - - count++; - } - } - } - } - } - else if (service == "nbt") - { - var io = irpcObj(); - io.input.level = irpc.NBTD_INFO_STATISTICS; - status = irpc.nbtd_information(io); - if (status.is_ok == true) - { - obj.statistics = io.results[0].info.stats; - } - } - } - } - } - } - - return info; -} -jsonrpc.method.get_statistics = _get_statistics; - -/* - * Local Variables: - * mode: c - * End: - */ -%> diff --git a/services/samba/system.esp b/services/samba/system.esp deleted file mode 100644 index 59844cda39..0000000000 --- a/services/samba/system.esp +++ /dev/null @@ -1,118 +0,0 @@ -<% -/* - * Copyright: - * (C) 2006 by Derrell Lipman - * All rights reserved - * - * License: - * LGPL 2.1: http://creativecommons.org/licenses/LGPL/2.1/ - */ - -/* - * JSON-RPC mappings to system facilities - */ - -/* We'll be accessing session resources */ -jsonrpc_include("resources.esp"); - - -/** - * Authenticate and log in - * - * @param params[0] - * User name - * - * @param params[1] - * Password - * - * @param params[2] - * Domain - * - * @param error - * An object of class JsonRpcError. - * - * @return - * Success: "Logged in" - * Failure: error event, origin=Server, code=LoginFailed - */ -function _login(params, error) -{ - var ret; - var creds = credentials_init(); - - creds.set_username(params[0]); - creds.set_password(params[1]); - creds.set_domain(params[2]); - creds.set_workstation(request['REMOTE_HOST']); - auth = userAuth(creds, request['REMOTE_SOCKET_ADDRESS']); - - if (auth == undefined) - { - error.setOrigin(jsonrpc.Constant.ErrorOrigin.Server); - error.setError(jsonrpc.Constant.ServerError.LoginFailed, - "Invalid login."); - ret = error; - } - else if (auth.result) - { - session.AUTHENTICATED = true; - session.authinfo = new Object(); - - session.authinfo.username = auth.username; - session.authinfo.domain = auth.domain; - session.authinfo.credentials = creds; - session.authinfo.session_info = auth.session_info; - - ret = "Logged in"; - } - else if (auth.report == undefined) - { - error.setOrigin(jsonrpc.Constant.ErrorOrigin.Server); - error.setError(jsonrpc.Constant.ServerError.LoginFailed, - "Login failed."); - ret = error; - } - else - { - error.setOrigin(jsonrpc.Constant.ErrorOrigin.Server); - error.setError(jsonrpc.Constant.ServerError.LoginFailed, - "Login failed: " + auth.report); - ret = error; - } - - return ret; -} -jsonrpc.method.login = _login; - - - -/** - * Retrieve the list of open resources (for debugging) - * - * @return "Logged out" - */ -function _logout(params, error) -{ - session.AUTHENTICATED = false; - return "Logged out"; -} -jsonrpc.method.logout = _logout; - - - -/** - * Retrieve the list of open resources (for debugging) - */ -function _get_open_resources(params, error) -{ - return session.resources.getList(error); -} -jsonrpc.method.get_open_resources = _get_open_resources; - - -/* - * Local Variables: - * mode: c - * End: - */ -%> |