r26389: Merge SWAT changes from alpha2 back into main Samba4 tree.
[ira/wip.git] / swat / install / provision.esp
index 9316445d7fc60b8f0787e6da02aac6305ceb55d0..c6511adb6675ddfc5246c37d9c4473d08761b10e 100644 (file)
@@ -8,63 +8,82 @@
 <h1>Samba4 provisioning</h1>
 
 <%
-var f = FormObj("Provisioning", 9, 2);
+var f = FormObj("Provisioning", 0, 2);
 var i;
 var lp = loadparm_init();
+if ((session.authinfo.user_class == "ADMINISTRATOR")
+        || (session.authinfo.user_class == "SYSTEM")) {
 
-if (lp.get("realm") == "") {
-       lp.set("realm", lp.get("workgroup") + ".example.com");
-}
+       if (lp.get("realm") == "") {
+               lp.set("realm", lp.get("workgroup") + ".example.com");
+       }
 
+       var subobj = provision_guess();
+       /* Don't supply default password for web interface */
+       subobj.ADMINPASS = "";
 
-var subobj = provision_guess();
+       f.add("REALM", "DNS Domain Name");
+       f.add("DOMAIN", "NetBIOS Domain Name");
+       f.add("HOSTNAME", "Hostname");
+       f.add("ADMINPASS", "Administrator Password", "password");
+       f.add("CONFIRM", "Confirm Password", "password");
+       f.add("DOMAINSID", "Domain SID");
+       f.add("HOSTIP", "Host IP");
+       f.add("DEFAULTSITE", "Default Site");
+       f.submit[0] = "Provision";
+       f.submit[1] = "Cancel";
 
-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[3].type  = "password";
-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] = "Initial provision";
-f.submit[1] = "Provision";
-f.submit[2] = "Cancel";
+       if (form['submit'] == "Cancel") {
+               redirect("/");
+       }
 
-if (form['submit'] == "Cancel") {
-       redirect("/");
-}
+       if (form['submit'] == "Provision") {
+               for (r in form) {
+                       subobj[r] = form[r];
+               }
+       }
 
-if ((form['submit'] == "Provision") || (form['submit'] == "Initial provision")) {
-       for (r in form) {
-               subobj[r] = form[r];
+       for (i=0;i<f.element.length;i++) {
+               f.element[i].value = subobj[f.element[i].name];
        }
-}
 
-for (i=0;i<f.element.length;i++) {
-       f.element[i].value = subobj[f.element[i].name];
-}
+       if (form['submit'] == "Provision") {
+       
+               /* overcome an initially blank smb.conf */
+               lp.set("realm", subobj.REALM);
+               lp.set("workgroup", subobj.DOMAIN);
+               lp.reload();
+               var goodpass = (subobj.CONFIRM == subobj.ADMINPASS);
 
-lp.set("realm", subobj.REALM);
+               var paths = provision_default_paths(subobj);
+               provision_fix_subobj(subobj, paths);
 
-if (form['submit'] == "Provision") {
-       provision(subobj, writefln, true);
-} else if (form['submit'] == "Initial provision") {
-       provision(subobj, writefln, false);
+               if (!goodpass) {
+                       write("<h3>Passwords don't match.  Please try again.</h3>");
+                       f.display();
+               } else if (subobj.ADMINPASS == "") {
+                       write("<h3>You must choose an administrator password.  Please try again.</h3>");
+                       f.display();
+               } else if (!provision_validate(subobj, writefln)) {
+                       f.display();
+               } else {
+                       if (!provision(subobj, writefln, false, paths, 
+                                      session.authinfo.session_info, session.authinfo.credentials, false)) {
+                               writefln("Provision failed!");
+                       } else if (!provision_dns(subobj, writefln, paths,
+                                                 session.authinfo.session_info, session.authinfo.credentials)) {
+                               writefln("DNS Provision failed!");
+                       } else {
+                               writefln("Provision Complete!");
+                       }
+               }
+       } else {
+               f.display();
+       }
 } else {
-       f.display();
+       redirect("/");
 }
+
 %>