From 68a0979bcec92fed2ae34f2e42f7cea8385529ef Mon Sep 17 00:00:00 2001 From: Charitha Goonetilleke Date: Mon, 11 Mar 2019 08:09:09 +0000 Subject: [PATCH] Add OpenVPN policy --- .../android/util/AndroidDeviceUtils.java | 2 + .../public/js/operation-bar.js | 6 +- .../public/js/operation-mod.js | 12 ++-- .../public/js/android-policy-edit.js | 56 +++++++++---------- .../public/templates/android-policy-edit.hbs | 48 +++++----------- .../public/templates/android-policy-view.hbs | 48 +++------------- .../public/js/android-policy-operations.js | 56 +++++++++---------- .../templates/android-policy-operations.hbs | 50 ++++------------- 8 files changed, 88 insertions(+), 190 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java index 0346f94698..d518af5990 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java @@ -379,6 +379,8 @@ public class AndroidDeviceUtils { deviceInfo.getDeviceDetailsMap().put("mac", prop.getValue()); } else if (prop.getName().equalsIgnoreCase("SERIAL")) { deviceInfo.getDeviceDetailsMap().put("serial", prop.getValue()); + } else { + deviceInfo.getDeviceDetailsMap().put(prop.getName(), prop.getValue()); } } 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-bar/public/js/operation-bar.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-bar/public/js/operation-bar.js index 659ec30423..854a2eaee1 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-bar/public/js/operation-bar.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-bar/public/js/operation-bar.js @@ -417,10 +417,8 @@ var generatePayload = function (operationCode, operationData, deviceList) { operationType = operationTypeConstants["PROFILE"]; payload = { "operation": { - "serverAddress": operationData["serverAddress"], - "serverPort": operationData["serverPort"], - "sharedSecret": operationData["sharedSecret"], - "dnsServer": operationData["dnsServer"] + "type": operationData["type"], + "openvpn_config": operationData["openvpn_config"] } }; break; 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 9731a0ddbd..4a4cff3e94 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 @@ -166,10 +166,8 @@ var androidOperationModule = function () { break; case androidOperationConstants["VPN_OPERATION_CODE"]: payload = { - "serverAddress": operationPayload["serverAddress"], - "serverPort": operationPayload["serverPort"], - "sharedSecret": operationPayload["sharedSecret"], - "dnsServer": operationPayload["dnsServer"] + "type": operationPayload["type"], + "openvpn_config": operationPayload["openvpn_config"] }; break; case androidOperationConstants["APPLICATION_OPERATION_CODE"]: @@ -341,10 +339,8 @@ var androidOperationModule = function () { operationType = operationTypeConstants["PROFILE"]; payload = { "operation": { - "serverAddress": operationData["serverAddress"], - "serverPort": operationData["serverPort"], - "sharedSecret": operationData["sharedSecret"], - "dnsServer": operationData["dnsServer"] + "type": operationData["type"], + "openvpn_config": operationData["openvpn_config"] } }; break; 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 7f0560a36a..17d70b0c85 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 @@ -150,6 +150,28 @@ var inputIsValidAgainstRange = function (numberInput, min, max) { return (numberInput == min || (numberInput > min && numberInput < max) || numberInput == max); }; +var ovpnConfigUploaded = function () { + var ovpnFileInput = document.getElementById("ovpn-file"); + if ('files' in ovpnFileInput) { + if (ovpnFileInput.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 ("openvpn-config").value = txt; + console.log(txt); + }; + reader.readAsText(ovpnFileInput.files[0]); + } + } +}; + /** * Validates policy profile operations for the windows platform. * @@ -389,48 +411,20 @@ var validatePolicyProfile = function () { } if ($.inArray(androidOperationConstants["VPN_OPERATION_CODE"], configuredOperations) != -1) { - // if WIFI is configured operation = androidOperationConstants["VPN_OPERATION"]; // initializing continueToCheckNextInputs to true continueToCheckNextInputs = true; - var serverAddress = $("input#vpn-server-address").val(); - if (!serverAddress) { + var openvpnConfig = $("#openvpn-config").val(); + if (!openvpnConfig || openvpnConfig === '') { validationStatus = { "error": true, - "subErrorMsg": "Server address is required. You cannot proceed.", + "subErrorMsg": "ovpn config required. You cannot proceed.", "erroneousFeature": operation }; continueToCheckNextInputs = false; } - if (continueToCheckNextInputs) { - var serverPort = $("input#vpn-server-port").val(); - if (!serverPort) { - validationStatus = { - "error": true, - "subErrorMsg": "VPN server port is required. You cannot proceed.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (!$.isNumeric(serverPort)) { - validationStatus = { - "error": true, - "subErrorMsg": "VPN server port requires a number input.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (!inputIsValidAgainstRange(serverPort, 0, 65535)) { - validationStatus = { - "error": true, - "subErrorMsg": "VPN server port is not within the range " + - "of valid port numbers.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - // at-last, if the value of continueToCheckNextInputs is still true // this means that no error is found if (continueToCheckNextInputs) { 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 b6193123d9..b6f6ddff07 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 @@ -1213,59 +1213,37 @@
- This configurations can be used to configure VPN settings on an Android device. - Once this configuration profile is installed on a device, corresponding users will not be able - to modify these settings on their devices. + Configure the OpenVPN settings on Android devices. + In order to enable this, device needs to have "OpenVPN for Android" application installed.

- Please note that * sign represents required fields of data. -

- - -
-
- - -
-
-
-
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-view/public/templates/android-policy-view.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-view/public/templates/android-policy-view.hbs index 65cd1255fa..a466bec155 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-view/public/templates/android-policy-view.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-view/public/templates/android-policy-view.hbs @@ -1455,60 +1455,26 @@
- This configurations can be used to configure VPN settings on an Android device. - Once this configuration profile is installed on a device, corresponding users will not be able - to modify these settings on their devices. + Configure the OpenVPN settings on Android devices. + In order to enable this, device needs to have "OpenVPN for Android" application installed.

- Please note that * sign represents required fields of data. -

- - -
-
- - -
-
- - -
-
-
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 6fb6d1a45e..e8d8574952 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 @@ -90,6 +90,28 @@ var inputIsValidAgainstRange = function (numberInput, min, max) { return (numberInput == min || (numberInput > min && numberInput < max) || numberInput == max); }; +var ovpnConfigUploaded = function () { + var ovpnFileInput = document.getElementById("ovpn-file"); + if ('files' in ovpnFileInput) { + if (ovpnFileInput.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 ("openvpn-config").value = txt; + console.log(txt); + }; + reader.readAsText(ovpnFileInput.files[0]); + } + } +}; + /** * Validates policy profile operations for the windows platform. * @@ -311,48 +333,20 @@ var validatePolicyProfile = function () { } if ($.inArray(androidOperationConstants["VPN_OPERATION_CODE"], configuredOperations) != -1) { - // if WIFI is configured operation = androidOperationConstants["VPN_OPERATION"]; // initializing continueToCheckNextInputs to true continueToCheckNextInputs = true; - var serverAddress = $("input#vpn-server-address").val(); - if (!serverAddress) { + var openvpnConfig = $("input#openvpn-config").val(); + if (!openvpnConfig || openvpnConfig === '') { validationStatus = { "error": true, - "subErrorMsg": "Server address is required. You cannot proceed.", + "subErrorMsg": "ovpn config file is required. You cannot proceed.", "erroneousFeature": operation }; continueToCheckNextInputs = false; } - if (continueToCheckNextInputs) { - var serverPort = $("input#vpn-server-port").val(); - if (!serverPort) { - validationStatus = { - "error": true, - "subErrorMsg": "VPN server port is required. You cannot proceed.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (!$.isNumeric(serverPort)) { - validationStatus = { - "error": true, - "subErrorMsg": "VPN server port requires a number input.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (!inputIsValidAgainstRange(serverPort, 0, 65535)) { - validationStatus = { - "error": true, - "subErrorMsg": "VPN server port is not within the range " + - "of valid port numbers.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - // at-last, if the value of continueToCheckNextInputs is still true // this means that no error is found if (continueToCheckNextInputs) { 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 6acebef025..0d9f3e6470 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 @@ -1475,59 +1475,29 @@
- Configure the VPN settings on Android devices. - Once this profile is applied, the device owners won't be able to modify the configured settings - on their devices. + Configure the OpenVPN settings on Android devices. + In order to enable this, device needs to have "OpenVPN for Android" application installed.

- Please note that * sign represents required fields of data. -

- - -
-
- - -
-
- - -
-
-