From a343050b2b91067d70eafd5ade88d6a3637be236 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 9 Jul 2005 05:31:38 +0000 Subject: r8257: add a samr rpc test page in the web server. It lists all level3 information from QueryUserInfo for all users in the domain. If you want to see why I am putting the effort into ejs, then please read swat/scripting/samr.js, and compare it to other methods of rpc access for our web management interface. Using ejs like this will make building a rich interface _much_ easier. (This used to be commit eb354f6da7ed79eb080f2ba47df2ea655e1891db) --- swat/esptest/menu.js | 1 + swat/esptest/samr.esp | 35 ++++++++++ swat/scripting/common.js | 24 ++----- swat/scripting/samr.js | 167 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 209 insertions(+), 18 deletions(-) create mode 100644 swat/esptest/samr.esp create mode 100644 swat/scripting/samr.js (limited to 'swat') diff --git a/swat/esptest/menu.js b/swat/esptest/menu.js index b78ca68ee84..d46561f311d 100644 --- a/swat/esptest/menu.js +++ b/swat/esptest/menu.js @@ -2,6 +2,7 @@ simple_menu( "ESP Tests", "ldb database", session_uri("/esptest/ldb.esp"), + "samr calls", session_uri("/esptest/samr.esp"), "html forms", session_uri("/esptest/formtest.esp"), "esp includes", session_uri("/esptest/include.esp"), "session variables", session_uri("/esptest/session.esp"), diff --git a/swat/esptest/samr.esp b/swat/esptest/samr.esp new file mode 100644 index 00000000000..f0159fcafa5 --- /dev/null +++ b/swat/esptest/samr.esp @@ -0,0 +1,35 @@ +<% page_header("columns", "ESP samr test"); + + include("/scripting/samr.js"); +%> + +

Samba4 samr rpc test

+ +<% +var conn = new Object(); +var binding = "ncalrpc:"; +status = rpc_connect(conn, binding, "samr"); +check_status_ok(status); + +handle = samrConnect(conn); + +domains = samrEnumDomains(conn, handle); + +for (i=0;iDomain " + domains[i].name + "\n"); + sid = samrLookupDomain(conn, handle, domains[i].name); + dom_handle = samrOpenDomain(conn, handle, sid); + users = samrEnumDomainUsers(conn, dom_handle); + samrFillUserInfo(conn, dom_handle, users, 3); + if (users.length == 0) { + write("no users in domain
\n"); + } else { + multi_table(users, "name"); + } + samrClose(dom_handle); +} + +%> + + +<% page_footer(); %> diff --git a/swat/scripting/common.js b/swat/scripting/common.js index 4fc3884db6f..3321cfb7722 100644 --- a/swat/scripting/common.js +++ b/swat/scripting/common.js @@ -115,7 +115,7 @@ function simple_menu() { function table_element(i, o) { write("" + i + ""); if (typeof(o[i]) == "object") { - var first; + var j, first; first = true; for (j in o[i]) { if (first == false) { @@ -130,25 +130,15 @@ function table_element(i, o) { write("\n"); } -/* - return the number of elements in an object -*/ -function elcount(o) { - var count = 0; - for (i in o) { - count++; - } - return count; -} - /* display a ejs object as a table. The header is optional */ function simple_table(v) { - if (elcount(v) == 0) { + if (v.length == 0) { return; } write("\n"); + var r; for (r in v) { table_element(r, v); } @@ -160,12 +150,10 @@ function simple_table(v) { attribute */ function multi_table(array, header) { - if (elcount(array) == 0) { - return; - } + var i, n; write("
\n"); - for (i in array) { - var v = array[i]; + for (i=0;i\n"); for (r in v) { if (r != header) { diff --git a/swat/scripting/samr.js b/swat/scripting/samr.js new file mode 100644 index 00000000000..474e7045503 --- /dev/null +++ b/swat/scripting/samr.js @@ -0,0 +1,167 @@ +/* + samr rpc utility functions +*/ + +/* + helper function to setup a rpc io object, ready for input +*/ +function irpcObj() +{ + var o = new Object(); + o.input = new Object(); + return o; +} + +/* + check that a status result is OK +*/ +function check_status_ok(status) +{ + if (status.is_ok != true) { + printVars(status); + } + assert(status.is_ok == true); +} + +/* + return a list of names and indexes from a samArray +*/ +function samArray(output) +{ + var list = new Array(output.num_entries); + if (output.sam == NULL) { + return list; + } + var entries = output.sam.entries; + for (i=0;i
' + v[header] + "