summaryrefslogtreecommitdiff
path: root/source4/scripting
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-07-12 02:36:07 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:20:08 -0500
commit2dce83de0c4de67f15e95456d6a63864d2f6ad85 (patch)
tree77a0e6cb42e8a508a1ca31be7eaa619bed3eca0e /source4/scripting
parentb1e93b296ea8f62ce0f15ccef5f6ae5339f4929f (diff)
downloadsamba-2dce83de0c4de67f15e95456d6a63864d2f6ad85.tar.gz
samba-2dce83de0c4de67f15e95456d6a63864d2f6ad85.tar.bz2
samba-2dce83de0c4de67f15e95456d6a63864d2f6ad85.zip
r8338: - added a substitute_var() js library function for doing hash driven
substitution of variables in strings - the js provision script now correctly processes provision.ldif (This used to be commit c2946003e06c4898ba0444cd0b69d3203753be94)
Diffstat (limited to 'source4/scripting')
-rw-r--r--source4/scripting/libjs/base.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/source4/scripting/libjs/base.js b/source4/scripting/libjs/base.js
index f5498789c5..c6b05755c4 100644
--- a/source4/scripting/libjs/base.js
+++ b/source4/scripting/libjs/base.js
@@ -50,3 +50,32 @@ function check_array_zero(a)
assert(a[i] == 0);
}
}
+
+/*
+ substitute strings of the form ${NAME} in str, replacing
+ with substitutions from subobj
+*/
+function substitute_var(str, subobj)
+{
+ var list = split("${", str);
+ var i;
+ for (i=1;i<list.length;i++) {
+ var list2 = split("}", list[i]);
+ if (list2.length < 2) {
+ return undefined;
+ }
+ var key = list2[0];
+ var val;
+ if (typeof(subobj[key]) == "undefined") {
+ val = "${" + key + "}";
+ } else if (typeof(subobj[key]) == "string") {
+ val = subobj[key];
+ } else {
+ var fn = subobj[key];
+ val = fn(key);
+ }
+ list2[0] = "" + val;
+ list[i] = join("", list2);
+ }
+ return join("", list);
+}