openConsole.DynamicForm.create({ ID: "certs_generate_form", fields: [ {name: "configType", title:"Configuration Type", type:"select", required:true, value: "client", valueMap: {client: "Client Configuration", broker: "Broker Keystore"}}, {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 () { var formData = certs_generate_form.getValues(); var callbackFunc = "certs_downloadClientPackage"; var message = "client configuration"; if (formData.configType === "broker") { callbackFunc = "certs_downloadBrokerKeystore"; message = "broker keystore"; } certs_generateResponse.setContents("Generating " + message + "..."); openConsole.RPCManager.sendRequest({ data: JSON.stringify(formData), actionURL: "/generate_cert", callback: callbackFunc + "(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 Configuration", items: [ "certs_layout" ] }); /** * Converts the response data to bytes and saves the dxl package into a zip file * * @param {String} packageType * @param {String} packageName * @param {Object} rpcResponse * @param {Object} data */ function certs_downloadPackage(packageType, packageName, rpcResponse, data) { if(rpcResponse.httpResponseCode == 200) { certs_generateResponse.setContents("Downloading cert package for..."); var filedata = Base64Binary.decodeArrayBuffer(data); certs_saveByteArrayToFile([filedata], packageName + ".zip"); certs_generateResponse.setContents("Successfully downloaded " + packageType + " package.") } else { //failure response certs_generateResponse.setContents(rpcResponse.httpResponseText); } } /** * Converts the response data to bytes and saves the dxl client configuration package into a zip file * * @param {Object} rpcResponse * @param {Object} data */ function certs_downloadClientPackage(rpcResponse, data) { certs_downloadPackage("client configuration", "opendxlclientconfig", rpcResponse, data); } /** * Converts the response data to bytes and saves the dxl broker keystore package into a zip file * * @param {Object} rpcResponse * @param {Object} data */ function certs_downloadBrokerKeystore(rpcResponse, data) { certs_downloadPackage("broker keystore", "opendxlbrokerkeystore", rpcResponse, data); } /** * 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); } }; }());