r12892: Add a 'Migrate from Windows' page to our installation section in SWAT.
[jra/samba/.git] / swat / install / vampire.esp
1 <% page_header("columns", "Windows to Samba Migration", "install"); 
2
3   include("/scripting/forms.js");
4   libinclude("base.js");
5   libinclude("provision.js");
6
7   var misc = misc_init();
8 %>
9
10 <h1>Windows to Samba4 domain migration</h1>
11
12 <%
13 var f = FormObj("Provisioning", 0, 2);
14 var i;
15 var lp = loadparm_init();
16
17 if (lp.get("realm") == "") {
18         lp.set("realm", lp.get("workgroup") + ".example.com");
19 }
20
21
22 var subobj = provision_guess();
23 /* Don't supply default password for web interface */
24 subobj.ADMINPASS = "";
25
26 f.add("REALM", "Realm");
27 f.add("DOMAIN", "Domain Name");
28 f.add("ADMIN", "Administrator Username");
29 f.add("ADMINPASS", "Administrator Password", "password");
30 f.add("HOSTNAME", "My Hostname");
31 f.add("HOSTGUID", "Host GUID");
32 f.add("HOSTIP", "Host IP");
33 f.add("DEFAULTSITE", "Default Site");
34 f.submit[0] = "Migrate";
35 f.submit[1] = "Cancel";
36
37 if (form['submit'] == "Cancel") {
38         redirect("/");
39 }
40
41 if (form['submit'] == "Migrate") {
42         for (r in form) {
43                 subobj[r] = form[r];
44         }
45 }
46
47 for (i=0;i<f.element.length;i++) {
48         f.element[i].value = subobj[f.element[i].name];
49 }
50
51 if (form['submit'] == "Migrate") {
52         lp.set("realm", subobj.REALM);
53         if (subobj.ADMINPASS == "") {
54                 write("<h3>We need the administrator password for the " + subobj.DOMAIN + " domain to proceed.  Please try again.</h3>");
55                 f.display();
56         } else if (!provision_validate(subobj, writefln)) {
57                 f.display();
58         } else {
59                 var creds = credentials_init();
60                 creds.set_username(form.ADMIN);
61                 creds.set_password(form.ADMINPASS);
62                 creds.set_domain(form.DOMAIN);
63                 creds.set_realm(form.REALM);
64
65                 /* Setup a basic database structure, but don't setup any users */
66                 if (!provision(subobj, writefln, true, provision_default_paths(subobj),
67                               session.authinfo.session_info, session.authinfo.credentials)) {
68                         writefln("Provision failed!");
69
70                 /* Join domain */
71                 } else if (!join_domain(form.DOMAIN, form.HOSTNAME, misc.SEC_CHAN_BDC, creds, writefln)) {
72                         writefln("Domain Join failed!");
73                         
74                 } else {
75                         /* Vampire */
76                         var machine_creds = credentials_init();
77                         machine_creds.set_domain(form.DOMAIN);
78                         if (!machine_creds.set_machine_account()) {
79                                 writefln("Failed to access newly setup domain join!");
80                         } else if (!vampire(machine_creds, writefln)) {
81                                 writefln("Failed to syncronsise remote domain into local database!");
82                         }
83                 }
84         }
85 } else {
86         f.display();
87 }
88 %>
89
90
91 <% page_footer(); %>