openConsole.DynamicForm.create({ ID: "certs_generate_form", fields: [ {name: "cn", title:"Common Name", type:"text", required:true, hint: "(e.g. server FQDN or YOUR name)", wrapTitle:false, wrapHintText: false}, {name: "country", title:"Country Name", required:false,hint: "(2 letter code)", validators:[{type:"lengthRange",errorMessage:"Value must be 2 characters long.",max:2}], wrapTitle:false, wrapHintText: false}, {name: "state", title:"State or Province Name", type:"text", required:false, hint: "(full name)", wrapTitle:false, wrapHintText: false}, {name: "locality", title:"Locality Name", type:"text", required:false, hint: "(eg, city)", wrapTitle:false, wrapHintText: false}, {name: "org", title:"Organization Name", type:"text", required:false, hint: "(eg, company)", wrapTitle:false, wrapHintText: false}, {name: "ou", title:"Organizational Unit Name", type:"text", required:false, hint: "(eg, section)", wrapTitle:false, wrapHintText: false}, {name: "email", title:"Email Address", type:"text", required:false, wrapTitle:false,wrapHintText: false} ], doSubmit : function () { certs_generateResponse.setContents("Generating client configuration...") openConsole.RPCManager.sendRequest({ data: JSON.stringify(certs_generate_form.getValues()), actionURL: "/generate_cert", callback: 'certs_downloadClientPackage(rpcResponse, data)', willHandleError: true }) } }); openConsole.Form.VLayout.create({ ID: "certs_layout", members: [ "certs_generate_form", openConsole.Form.HLayout.create({ members: [ openConsole.IButton.create({ title: "Generate", click : function () { certs_generate_form.submit(); } }), openConsole.Form.StatusHTMLFlow.create({ ID: "certs_generateResponse" }) ] }) ] }); openConsole.ModuleWindow.create({ ID:"certs_stack", title: "Generate Client Configuration", items: [ "certs_layout" ] }); /** * Converts the response data to bytes and saves the dxl client package into a zip file * * @param {Object} rpcResponse * @param {Object} data */ function certs_downloadClientPackage(rpcResponse, data) { if(rpcResponse.httpResponseCode == 200) { certs_generateResponse.setContents("Downloading cert package for...") var filedata = Base64Binary.decodeArrayBuffer(data); certs_saveByteArrayToFile([filedata], 'opendxlclientconfig.zip'); certs_generateResponse.setContents("Successfully downloaded client package.") } else { //failure response certs_generateResponse.setContents(rpcResponse.httpResponseText) } } /** * saves the dxl client package data into zip file * @param {bytes} data * @param {String} filename */ var certs_saveByteArrayToFile = (function () { var a = document.createElement("a"); document.body.appendChild(a); a.style = "display: none"; return function (data, name) { var blob = new Blob(data, {type: "application/octet-stream"}), url = window.URL.createObjectURL(blob); if (window.navigator && window.navigator.msSaveOrOpenBlob) { window.navigator.msSaveOrOpenBlob(blob, name); } else { a.href = url; a.download = name; a.click(); window.URL.revokeObjectURL(url); } }; }());