From 8abe0fa7bcf652293d1f874d360b568b49938a4f Mon Sep 17 00:00:00 2001 From: Pahansith Gunathilake Date: Fri, 31 May 2019 10:46:34 +0000 Subject: [PATCH] Add android certificate policy add UI --- .../public/js/operation-mod.js | 22 +++- .../public/js/android-policy-edit.js | 76 +++++++++++- .../public/templates/android-policy-edit.hbs | 110 +++++++++++++++++ .../public/templates/android-policy-view.hbs | 107 +++++++++++++++++ .../public/js/android-policy-operations.js | 53 ++++++++- .../templates/android-policy-operations.hbs | 112 ++++++++++++++++++ 6 files changed, 474 insertions(+), 6 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-mod/public/js/operation-mod.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-mod/public/js/operation-mod.js index 01a609a14b..81fa182a85 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-mod/public/js/operation-mod.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-mod/public/js/operation-mod.js @@ -108,7 +108,8 @@ var androidOperationModule = function () { "DISALLOW_BLUETOOTH": "DISALLOW_BLUETOOTH", "DISALLOW_BLUETOOTH_SHARING": "DISALLOW_BLUETOOTH_SHARING", "DISALLOW_REMOVE_USER": "DISALLOW_REMOVE_USER", - "DISALLOW_DATA_ROAMING": "DISALLOW_DATA_ROAMING" + "DISALLOW_DATA_ROAMING": "DISALLOW_DATA_ROAMING", + "CERT_ADD_OPERATION_CODE": "INSTALL_CERT" }; /** @@ -308,6 +309,17 @@ var androidOperationModule = function () { "enrollmentAppInstall": operationPayload["enrollmentAppInstall"] }; break; + case androidOperationConstants["CERT_ADD_OPERATION_CODE"]: + var certList = operationPayload["CERT_LIST"]; + var listNew = []; + certList.forEach(function (element) { + element["CERT_CONTENT_VIEW"] = element["CERT_NAME"] + " File"; + listNew.push(element); + }); + payload = { + "CERT_LIST": listNew + }; + break; } return payload; }; @@ -668,6 +680,14 @@ var androidOperationModule = function () { } }; break; + case androidOperationConstants["CERT_ADD_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "CERT_LIST": operationData["CERT_LIST"] + } + }; + break; default: // If the operation is neither of above, it is a command operation operationType = operationTypeConstants["COMMAND"]; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/js/android-policy-edit.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/js/android-policy-edit.js index f5b6fc4f44..f8e7c65fa3 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/js/android-policy-edit.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/js/android-policy-edit.js @@ -58,7 +58,8 @@ var androidOperationConstants = { "COSU_PROFILE_CONFIGURATION_OPERATION": "cosu-profile-configuration", "COSU_PROFILE_CONFIGURATION_OPERATION_CODE": "COSU_PROFILE", "ENROLLMENT_APP_INSTALL": "enrollment-app-install", - "ENROLLMENT_APP_INSTALL_CODE": "ENROLLMENT_APP_INSTALL" + "ENROLLMENT_APP_INSTALL_CODE": "ENROLLMENT_APP_INSTALL", + "CERT_ADD_OPERATION_CODE": "INSTALL_CERT" }; /** @@ -172,6 +173,29 @@ var ovpnConfigUploaded = function () { } }; +var certConfigUploaded = function (val) { + var certFileInput = document.getElementById("cert-file-field"); + if ('files' in certFileInput) { + if (certFileInput.files.length === 1) { + var reader = new FileReader(); + reader.onload = function (progressEvent) { + var txt = ""; + var lines = this.result.split('\n'); + for (var line = 0; line < lines.length; line++) { + console.log(lines[line]); + if (lines[line].charAt(0) !== '#') { + txt += lines[line] + '\n'; + } + } + //document.getElementById ("cert-config").value = txt; + //console.log(document.getElementById ("cert-config").value); + $(val).next().val(txt); + }; + reader.readAsText(certFileInput.files[0]); + } + } +}; + /** * Validates policy profile operations for the windows platform. * @@ -828,6 +852,32 @@ var validatePolicyProfile = function () { } validationStatusArray.push(validationStatus); } + if ($.inArray(androidOperationConstants["CERT_ADD_OPERATION_CODE"], configuredOperations) != -1) { + //If enrollment app install configured + let isErrorsFound = false; + operation = androidOperationConstants["CERT_ADD_OPERATION_CODE"]; + var certList = $("#cert-list").find(".child-input"); + for (let j = 0; j < certList.length; j++) { + if ($(certList[j]).val().trim() === "") { + isErrorsFound = true; + break; + } + } + if (isErrorsFound) { + validationStatus = { + "error": true, + "subErrorMsg": "Certificates are not selected to be installed.", + "erroneousFeature": operation + }; + validationStatusArray.push(validationStatus); + } else { + validationStatus = { + "error": false, + "okFeature": operation + }; + validationStatusArray.push(validationStatus); + } + } } // ending validation process @@ -1141,6 +1191,16 @@ var applyDataTable = function() { lengthMenu: [5, 10, 25, 50, 100] }); }; +var myFrom; + +function appendCertInputField(inputElement) { + let element = "\n" + + ""; + inputElement.append(element); +} $(document).ready(function () { // Maintains an array of configured features of the profile @@ -1297,15 +1357,23 @@ $(document).ready(function () { updateGroupedInputVisibility(this); }); + // add form entry click function for grid inputs - $(advanceOperations).on("click", "[data-click-event=add-form]", function () { + $(advanceOperations).on("click", "[data-click-event=add-form]", function (event) { var addFormContainer = $("[data-add-form-container=" + $(this).attr("href") + "]"); var clonedForm = $("[data-add-form=" + $(this).attr("href") + "]").clone().find("[data-add-form-element=clone]") .attr("data-add-form-clone", $(this).attr("href")); - // adding class .child-input to capture text-input-array-values $("input, select", clonedForm).addClass("child-input"); - + if ($(this).attr("href") === "#cert-grid") { + if (event.originalEvent !== undefined) { + let inputElement = $(clonedForm).children('td.cert-file-tr'); + inputElement.find("input[type=text]").remove(); + inputElement.find("input[type=hidden]").remove(); + appendCertInputField(inputElement); + $("input, select", clonedForm).addClass("child-input"); + } + } $(addFormContainer).append(clonedForm); setId(addFormContainer); showHideHelpText(addFormContainer); diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/templates/android-policy-edit.hbs b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/templates/android-policy-edit.hbs index 4d8d7a21e7..faeb8bcb61 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/templates/android-policy-edit.hbs +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/templates/android-policy-edit.hbs @@ -76,6 +76,15 @@ + + + + + Secure Certificates + + + + {{#unless iscloud}} @@ -1417,6 +1426,107 @@ + +
+ +
+ +
+ + + + diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/js/android-policy-operations.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/js/android-policy-operations.js index 5ae4076b3a..ba52e44e61 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/js/android-policy-operations.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/js/android-policy-operations.js @@ -55,7 +55,8 @@ var androidOperationConstants = { "COSU_PROFILE_CONFIGURATION_OPERATION": "cosu-profile-configuration", "COSU_PROFILE_CONFIGURATION_OPERATION_CODE": "COSU_PROFILE", "ENROLLMENT_APP_INSTALL": "enrollment-app-install", - "ENROLLMENT_APP_INSTALL_CODE": "ENROLLMENT_APP_INSTALL" + "ENROLLMENT_APP_INSTALL_CODE": "ENROLLMENT_APP_INSTALL", + "CERTIFICATE_INSTALL": "INSTALL_CERT" }; /** @@ -114,6 +115,30 @@ var ovpnConfigUploaded = function () { } }; + +var certConfigUploaded = function (val) { + var certFileInput = document.getElementById("cert-file-field"); + if ('files' in certFileInput) { + if (certFileInput.files.length === 1) { + var reader = new FileReader(); + reader.onload = function(progressEvent){ + var txt = ""; + var lines = this.result.split('\n'); + for(var line = 0; line < lines.length; line++){ + console.log(lines[line]); + if (lines[line].charAt(0) !== '#') { + txt += lines[line] + '\n'; + } + } + //document.getElementById ("cert-config").value = txt; + //console.log(document.getElementById ("cert-config").value); + $(val).next().val(txt); + }; + reader.readAsText(certFileInput.files[0]); + } + } +}; + /** * Validates policy profile operations for the windows platform. * @@ -761,6 +786,32 @@ var validatePolicyProfile = function () { } validationStatusArray.push(validationStatus); } + if ($.inArray(androidOperationConstants["CERTIFICATE_INSTALL"], configuredOperations) != -1) { + //If enrollment app install configured + let isErrorsFound = false; + operation = androidOperationConstants["CERTIFICATE_INSTALL"]; + var certList = $("#cert-list").find(".child-input"); + for (let j = 0; j < certList.length; j++) { + if ($(certList[j]).val().trim() === "") { + isErrorsFound = true; + break; + } + } + if (isErrorsFound) { + validationStatus = { + "error": true, + "subErrorMsg": "Certificates are not selected to be installed.", + "erroneousFeature": operation + }; + validationStatusArray.push(validationStatus); + } else { + validationStatus = { + "error": false, + "okFeature": operation + }; + validationStatusArray.push(validationStatus); + } + } } // ending validation process diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/templates/android-policy-operations.hbs b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/templates/android-policy-operations.hbs index 00fbf2794b..cd1837cd90 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/templates/android-policy-operations.hbs +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/templates/android-policy-operations.hbs @@ -76,6 +76,15 @@ + + + + + Secure Certificate + + + + {{#unless iscloud}} @@ -2330,6 +2339,109 @@
+ + +
+
+ +
+
+ + +
+ +
+
+ + + + + + Add Certificate + +
+ + + + + + + + + + + + + + +
No:Certificate NameCertificate File
+ No entries added yet . +
+ + + + + + + + + + +
+
+
+
+
+ +