From adb7fd18e5e58bc466bdd31d68423e5f958a1d5d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 12 Jul 2005 11:46:34 +0000 Subject: r8372: - split out provisioning logic into a separate ejs library - added a provisioning web page (This used to be commit 7476cb94132cf2849ec19360468904ca6fe8de2c) --- source4/scripting/ejs/smbcalls_string.c | 15 +++ source4/scripting/libjs/provision.js | 222 ++++++++++++++++++++++++++++++++ source4/setup/provision | 205 ++--------------------------- swat/esptest/menu.js | 1 + swat/esptest/provision.esp | 55 ++++++++ swat/scripting/common.js | 31 ++++- 6 files changed, 330 insertions(+), 199 deletions(-) create mode 100644 source4/scripting/libjs/provision.js create mode 100644 swat/esptest/provision.esp diff --git a/source4/scripting/ejs/smbcalls_string.c b/source4/scripting/ejs/smbcalls_string.c index ad998701f6..6597f3b27b 100644 --- a/source4/scripting/ejs/smbcalls_string.c +++ b/source4/scripting/ejs/smbcalls_string.c @@ -25,6 +25,20 @@ #include "lib/ejs/ejs.h" #include "system/passwd.h" +/* + usage: + var len = strlen(str); +*/ +static int ejs_strlen(MprVarHandle eid, int argc, char **argv) +{ + if (argc != 1) { + ejsSetErrorMsg(eid, "strlen invalid arguments"); + return -1; + } + mpr_Return(eid, mprCreateIntegerVar(strlen_m(argv[0]))); + return 0; +} + /* usage: var s = strlower("UPPER"); @@ -311,6 +325,7 @@ static int ejs_vsprintf(MprVarHandle eid, int argc, struct MprVar **argv) */ void smb_setup_ejs_string(void) { + ejsDefineStringCFunction(-1, "strlen", ejs_strlen, NULL, MPR_VAR_SCRIPT_HANDLE); ejsDefineStringCFunction(-1, "strlower", ejs_strlower, NULL, MPR_VAR_SCRIPT_HANDLE); ejsDefineStringCFunction(-1, "strupper", ejs_strupper, NULL, MPR_VAR_SCRIPT_HANDLE); ejsDefineStringCFunction(-1, "split", ejs_split, NULL, MPR_VAR_SCRIPT_HANDLE); diff --git a/source4/scripting/libjs/provision.js b/source4/scripting/libjs/provision.js new file mode 100644 index 0000000000..ba6807ce44 --- /dev/null +++ b/source4/scripting/libjs/provision.js @@ -0,0 +1,222 @@ +/* + backend code for provisioning a Samba4 server + Copyright Andrew Tridgell 2005 + Released under the GNU GPL v2 or later +*/ + +/* used to generate sequence numbers for records */ +provision_next_usn = 1; + +/* + find a user or group from a list of possibilities +*/ +function findnss() +{ + var i; + assert(arguments.length >= 2); + var nssfn = arguments[0]; + for (i=1;i= 2); - var nssfn = arguments[0]; - var name = arguments[1]; - if (options[name] != undefined) { - return options[name]; - } - for (i=2;i + +

Samba4 provisioning

+ +<% +var f = FormObj("Provisioning", 9, 2); +var i, subobj = provision_guess(); + +f.element[0].label = "Realm"; +f.element[0].name = "REALM"; +f.element[1].label = "Domain Name"; +f.element[1].name = "DOMAIN"; +f.element[2].label = "Host Name"; +f.element[2].name = "HOSTNAME"; +f.element[3].label = "Administrator Password"; +f.element[3].name = "ADMINPASS"; +f.element[4].label = "Domain SID"; +f.element[4].name = "DOMAINSID"; +f.element[5].label = "Host GUID"; +f.element[5].name = "HOSTGUID"; +f.element[6].label = "Base DN"; +f.element[6].name = "BASEDN"; +f.element[7].label = "Host IP"; +f.element[7].name = "HOSTIP"; +f.element[8].label = "Default Site"; +f.element[8].name = "DEFAULTSITE"; +f.submit[0] = "Provision"; +f.submit[1] = "Cancel"; + +if (form['submit'] == "Cancel") { + redirect("/"); +} + +if (form['submit'] == "Provision") { + for (r in form) { + subobj[r] = form[r]; + } +} + +for (i=0;i + + +<% page_footer(); %> diff --git a/swat/scripting/common.js b/swat/scripting/common.js index 2e90c1b469..0e297d7d99 100644 --- a/swat/scripting/common.js +++ b/swat/scripting/common.js @@ -23,6 +23,22 @@ function session_uri(uri) { return uri + global.SESSIONURI; } +/* + like printf, but to the web page +*/ +function writef() +{ + write(vsprintf(arguments)); +} + +/* + like writef with a
+*/ +function writefln() +{ + write(vsprintf(arguments)); + write("
\n"); +} /* if the browser was too dumb to set the HOST header, then @@ -196,6 +212,7 @@ function FormObj(name, num_elements, num_submits) f.element[i].value = current value (optional, defaults to "") */ function display_form(f) { + var i, size = 20; write('
\n'); @@ -210,6 +227,12 @@ function display_form(f) { if (e.value == undefined) { e.value = ""; } + if (strlen(e.value) > size) { + size = strlen(e.value) + 4; + } + } + for (i in f.element) { + var e = f.element[i]; write(""); write("" + e.label + ""); if (e.type == "select") { @@ -223,8 +246,12 @@ function display_form(f) { } write('\n'); } else { - write('\n'); + var sizestr = ""; + if (e.type == "text" || e.type == "password") { + sizestr = sprintf('size="%d"', size); + } + writef('\n', + e.name, e.type, e.value, sizestr); } write(""); } -- cgit