diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.wizard/wizard.js b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.wizard/wizard.js index dfe34da91c..a08faad088 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.wizard/wizard.js +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.wizard/wizard.js @@ -23,6 +23,7 @@ function onRequest(context) { var DTYPE_CONF_DEVICE_TYPE_LABEL_KEY = "label"; var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; + var deviceModule = require("/app/modules/business-controllers/device.js").deviceModule; var utility = require('/app/modules/utility.js').utility; var response = userModule.getRoles(); var wizardPage = {}; @@ -30,7 +31,7 @@ function onRequest(context) { wizardPage["roles"] = response["content"]; } var deviceType = context.uriParams.deviceType; - var typesListResponse = userModule.getPlatforms(); + var typesListResponse = deviceModule.getDeviceTypes(); if (typesListResponse["status"] == "success") { for (var type in typesListResponse["content"]) { if (deviceType == typesListResponse["content"][type]["name"]) { diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.platform.configuration/public/js/platform-configuration.js b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.platform.configuration/public/js/platform-configuration.js index 7641365479..57013c1a3e 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.platform.configuration/public/js/platform-configuration.js +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.platform.configuration/public/js/platform-configuration.js @@ -39,16 +39,6 @@ $(document).ready(function () { }); - -// Start of HTML embedded invoke methods -var showAdvanceOperation = function (operation, button) { - $(button).addClass('selected'); - $(button).siblings().removeClass('selected'); - var hiddenOperation = ".wr-hidden-operations-content > div"; - $(hiddenOperation + '[data-operation="' + operation + '"]').show(); - $(hiddenOperation + '[data-operation="' + operation + '"]').siblings().hide(); -}; - // Start of HTML embedded invoke methods var addConfiguration = function () { var errorMsgWrapper = "#virtual_firelarm-config-error-msg"; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/META-INF/permissions.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/META-INF/permissions.xml index 399d5c8035..d85ab6971a 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/META-INF/permissions.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/META-INF/permissions.xml @@ -50,7 +50,7 @@ Add Tenant configuration /device-mgt/admin/platform-configs/add /configuration - POST + PUT 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.platform.configuration/configuration.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.platform.configuration/configuration.hbs new file mode 100644 index 0000000000..3e598fb0a5 --- /dev/null +++ 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.platform.configuration/configuration.hbs @@ -0,0 +1,92 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} + +
+
+ +

+ Communication Protocol Configuration +
+

+
+ + +
+ +
+
+ + +
+
+ +
+
+ + +
+ +
+ + +
+
+

+ End User License Agreement ( EULA ) +
+

+ +
+ +
+
+ +
+
+
+ +{{#zone "bottomJs"}} + {{js "js/platform-configuration.js"}} +{{/zone}} 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.platform.configuration/configuration.json 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.platform.configuration/configuration.json new file mode 100644 index 0000000000..fd25901297 --- /dev/null +++ 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.platform.configuration/configuration.json @@ -0,0 +1,3 @@ +{ + "version" : "1.0.0" +} \ No newline at end of file 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.platform.configuration/public/js/platform-configuration.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.platform.configuration/public/js/platform-configuration.js new file mode 100644 index 0000000000..4ad5d5341a --- /dev/null +++ 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.platform.configuration/public/js/platform-configuration.js @@ -0,0 +1,249 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * Checks if provided input is valid against RegEx input. + * + * @param regExp Regular expression + * @param inputString Input string to check + * @returns {boolean} Returns true if input matches RegEx + */ +function isPositiveInteger(str) { + return /^\+?(0|[1-9]\d*)$/.test(str); +} + +var notifierTypeConstants = { + "LOCAL": "1", + "GCM": "2" +}; +// Constants to define platform types available +var platformTypeConstants = { + "ANDROID": "android", + "IOS": "ios", + "WINDOWS": "windows" +}; + +var responseCodes = { + "CREATED": "Created", + "SUCCESS": "201", + "INTERNAL_SERVER_ERROR": "Internal Server Error" +}; + +var configParams = { + "NOTIFIER_TYPE": "notifierType", + "NOTIFIER_FREQUENCY": "notifierFrequency", + "GCM_API_KEY": "gcmAPIKey", + "GCM_SENDER_ID": "gcmSenderId", + "ANDROID_EULA": "androidEula", + "IOS_EULA": "iosEula", + "CONFIG_COUNTRY": "configCountry", + "CONFIG_STATE": "configState", + "CONFIG_LOCALITY": "configLocality", + "CONFIG_ORGANIZATION": "configOrganization", + "CONFIG_ORGANIZATION_UNIT": "configOrganizationUnit", + "MDM_CERT_PASSWORD": "MDMCertPassword", + "MDM_CERT_TOPIC_ID": "MDMCertTopicID", + "APNS_CERT_PASSWORD": "APNSCertPassword", + "MDM_CERT": "MDMCert", + "MDM_CERT_NAME": "MDMCertName", + "APNS_CERT": "APNSCert", + "APNS_CERT_NAME": "APNSCertName", + "ORG_DISPLAY_NAME": "organizationDisplayName", + "GENERAL_EMAIL_HOST": "emailHost", + "GENERAL_EMAIL_PORT": "emailPort", + "GENERAL_EMAIL_USERNAME": "emailUsername", + "GENERAL_EMAIL_PASSWORD": "emailPassword", + "GENERAL_EMAIL_SENDER_ADDRESS": "emailSender", + "GENERAL_EMAIL_TEMPLATE": "emailTemplate", + "COMMON_NAME": "commonName", + "KEYSTORE_PASSWORD": "keystorePassword", + "PRIVATE_KEY_PASSWORD": "privateKeyPassword", + "BEFORE_EXPIRE": "beforeExpire", + "AFTER_EXPIRE": "afterExpire", + "WINDOWS_EULA": "windowsLicense", + "IOS_CONFIG_MDM_MODE": "iOSConfigMDMMode", + "IOS_CONFIG_APNS_MODE": "iOSConfigAPNSMode" +}; + +$(document).ready(function () { + $("#gcm-inputs").hide(); + tinymce.init({ + selector: "textarea", + height:500, + theme: "modern", + plugins: [ + "autoresize", + "advlist autolink lists link image charmap print preview anchor", + "searchreplace visualblocks code fullscreen", + "insertdatetime image table contextmenu paste" + ], + toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image" + }); + + var androidConfigAPI = "/api/device-mgt/android/v1.0/configuration"; + + /** + * Following requests would execute + * on page load event of platform configuration page in WSO2 EMM Console. + * Upon receiving the response, the parameters will be set to the fields, + * in case those configurations are already set. + */ + + invokerUtil.get( + androidConfigAPI, + function (data) { + data = JSON.parse(data); + if (data != null && data.configuration != null) { + for (var i = 0; i < data.configuration.length; i++) { + var config = data.configuration[i]; + if (config.name == configParams["NOTIFIER_TYPE"]) { + $("#android-config-notifier").val(config.value); + if (config.value != notifierTypeConstants["GCM"]) { + $("#gcm-inputs").hide(); + $("#local-inputs").show(); + } else { + $("#gcm-inputs").show(); + $("#local-inputs").hide(); + } + } else if (config.name == configParams["NOTIFIER_FREQUENCY"]) { + $("input#android-config-notifier-frequency").val(config.value / 1000); + } else if (config.name == configParams["GCM_API_KEY"]) { + $("input#android-config-gcm-api-key").val(config.value); + } else if (config.name == configParams["GCM_SENDER_ID"]) { + $("input#android-config-gcm-sender-id").val(config.value); + } else if (config.name == configParams["ANDROID_EULA"]) { + $("#android-eula").val(config.value); + } + } + } + }, function (data) { + console.log(data); + }); + + $("select.select2[multiple=multiple]").select2({ + tags: true + }); + + $("#android-config-notifier").change(function () { + var notifierType = $("#android-config-notifier").find("option:selected").attr("value"); + if (notifierType != notifierTypeConstants["GCM"]) { + $("#gcm-inputs").hide(); + $("#local-inputs").show(); + } else { + $("#local-inputs").hide(); + $("#gcm-inputs").show(); + } + }); + + /** + * Following click function would execute + * when a user clicks on "Save" button + * on Android platform configuration page in WSO2 EMM Console. + */ + $("button#save-android-btn").click(function () { + var notifierType = $("#android-config-notifier").find("option:selected").attr("value"); + var notifierFrequency = $("input#android-config-notifier-frequency").val(); + var gcmAPIKey = $("input#android-config-gcm-api-key").val(); + var gcmSenderId = $("input#android-config-gcm-sender-id").val(); + var androidLicense = tinyMCE.activeEditor.getContent(); + var errorMsgWrapper = "#android-config-error-msg"; + var errorMsg = "#android-config-error-msg span"; + if (notifierType == notifierTypeConstants["LOCAL"] && !notifierFrequency) { + $(errorMsg).text("Notifier frequency is a required field. It cannot be empty."); + $(errorMsgWrapper).removeClass("hidden"); + } else if (notifierType == notifierTypeConstants["LOCAL"] && !isPositiveInteger(notifierFrequency)) { + $(errorMsg).text("Provided notifier frequency is invalid. "); + $(errorMsgWrapper).removeClass("hidden"); + } else if (notifierType == notifierTypeConstants["GCM"] && !gcmAPIKey) { + $(errorMsg).text("GCM API Key is a required field. It cannot be empty."); + $(errorMsgWrapper).removeClass("hidden"); + } else if (notifierType == notifierTypeConstants["GCM"] && !gcmSenderId) { + $(errorMsg).text("GCM Sender ID is a required field. It cannot be empty."); + $(errorMsgWrapper).removeClass("hidden"); + } else { + + var addConfigFormData = {}; + var configList = new Array(); + + var type = { + "name": configParams["NOTIFIER_TYPE"], + "value": notifierType, + "contentType": "text" + }; + + var frequency = { + "name": configParams["NOTIFIER_FREQUENCY"], + "value": String(notifierFrequency * 1000), + "contentType": "text" + }; + + var gcmKey = { + "name": configParams["GCM_API_KEY"], + "value": gcmAPIKey, + "contentType": "text" + }; + + var gcmId = { + "name": configParams["GCM_SENDER_ID"], + "value": gcmSenderId, + "contentType": "text" + }; + + var androidEula = { + "name": configParams["ANDROID_EULA"], + "value": androidLicense, + "contentType": "text" + }; + + configList.push(type); + configList.push(frequency); + configList.push(androidEula); + if (notifierType == notifierTypeConstants["GCM"]) { + configList.push(gcmKey); + configList.push(gcmId); + } + + addConfigFormData.type = platformTypeConstants["ANDROID"]; + addConfigFormData.configuration = configList; + + var addConfigAPI = androidConfigAPI; + + invokerUtil.put( + addConfigAPI, + addConfigFormData, + function (data, textStatus, jqXHR) { + data = JSON.parse(data); + if (jqXHR.status == 201) { + $("#config-save-form").addClass("hidden"); + $("#record-created-msg").removeClass("hidden"); + } + + }, function (data) { + if (data.status == 500) { + $(errorMsg).text("Exception occurred at backend."); + } else if (data.status == 403) { + $(errorMsg).text("Action was not permitted."); + } else { + $(errorMsg).text("An unexpected error occurred."); + } + $(errorMsgWrapper).removeClass("hidden"); + } + ); + } + }); +}); \ No newline at end of file diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.hbs b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.hbs deleted file mode 100644 index e8b1fdfbdf..0000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.hbs +++ /dev/null @@ -1,501 +0,0 @@ -{{! - Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - - WSO2 Inc. licenses this file to you under the Apache License, - Version 2.0 (the "License"); you may not use this file except - in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -}} -
-
- -
-
- General and Platform Specific Server Settings for the Tenant -
-
-
-
- - -
- - - -
-
-
- -

- Policy Compliance Monitoring -
-

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

- Communication Protocol Configuration -
-

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

- End User License Agreement ( EULA ) -
-

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

- iOS SCEP Certificate Configurations -
-

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

- iOS Profile Configurations -
-

- - -
- - -
- -

- iOS MDM Configurations -
-

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

- iOS APNS Configurations -
-

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

- End User License Agreement (EULA) -
-

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

- Device Polling Configuration -
-

-
-
- - -
-
-

- End User License Agreement ( EULA ) -
-

-
- -
-
- -
-
-
-
- -
-
-
-
- - - -
-
-{{#zone "bottomJs"}} - {{js "js/platform-configuration.js"}} -{{/zone}} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.js b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.js deleted file mode 100644 index 6265d60478..0000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.js +++ /dev/null @@ -1,9 +0,0 @@ -function onRequest(context) { - // var log = new Log("platform-configuration-unit backend js"); - var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; - var typesListResponse = userModule.getPlatforms(); - if (typesListResponse["status"] == "success") { - context["types"] = typesListResponse["content"]; - } - return context; -} \ No newline at end of file diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.json b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.json deleted file mode 100644 index be0496bf61..0000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "version" : "1.0.0", - "extends": "cdmf.unit.platform.configuration" -} \ No newline at end of file diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/public/js/platform-configuration.js b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/public/js/platform-configuration.js deleted file mode 100644 index 7bbbad0b42..0000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/public/js/platform-configuration.js +++ /dev/null @@ -1,878 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * Checks if provided input is valid against RegEx input. - * - * @param regExp Regular expression - * @param inputString Input string to check - * @returns {boolean} Returns true if input matches RegEx - */ -function inputIsValid(regExp, inputString) { - return regExp.test(inputString); -} - -/** - * Checks if provided input is valid against RegEx input. - * - * @param regExp Regular expression - * @param inputString Input string to check - * @returns {boolean} Returns true if input matches RegEx - */ -function isPositiveInteger(str) { - return /^\+?(0|[1-9]\d*)$/.test(str); -} - -/** - * Get valid param. - * - * @param certificate - * @param cached param (in the registry) - * @returns {String} Returns the valid param - */ -function validateCertificateParams(param, cachedParam) { - if (param == '' && cachedParam != null) { - return cachedParam; - } else { - return param; - } -} - -/** - * Checks if an email address has the valid format or not. - * - * @param email Email address - * @returns {boolean} true if email has the valid format, otherwise false. - */ -function emailIsValid(email) { - var regExp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; - return regExp.test(email); -} - -var iOSMDMCertificateName = null; -var iOSMDMCertificate = null; -var iOSAPNSCertificateName = null; -var iOSAPNSCertificate = null; - -var notifierTypeConstants = { - "LOCAL": "1", - "GCM": "2" -}; -// Constants to define platform types available -var platformTypeConstants = { - "ANDROID": "android", - "IOS": "ios", - "WINDOWS": "windows" -}; - -var responseCodes = { - "CREATED": "Created", - "SUCCESS": "201", - "INTERNAL_SERVER_ERROR": "Internal Server Error" -}; - -var configParams = { - "NOTIFIER_TYPE": "notifierType", - "NOTIFIER_FREQUENCY": "notifierFrequency", - "GCM_API_KEY": "gcmAPIKey", - "GCM_SENDER_ID": "gcmSenderId", - "ANDROID_EULA": "androidEula", - "IOS_EULA": "iosEula", - "CONFIG_COUNTRY": "configCountry", - "CONFIG_STATE": "configState", - "CONFIG_LOCALITY": "configLocality", - "CONFIG_ORGANIZATION": "configOrganization", - "CONFIG_ORGANIZATION_UNIT": "configOrganizationUnit", - "MDM_CERT_PASSWORD": "MDMCertPassword", - "MDM_CERT_TOPIC_ID": "MDMCertTopicID", - "APNS_CERT_PASSWORD": "APNSCertPassword", - "MDM_CERT": "MDMCert", - "MDM_CERT_NAME": "MDMCertName", - "APNS_CERT": "APNSCert", - "APNS_CERT_NAME": "APNSCertName", - "ORG_DISPLAY_NAME": "organizationDisplayName", - "GENERAL_EMAIL_HOST": "emailHost", - "GENERAL_EMAIL_PORT": "emailPort", - "GENERAL_EMAIL_USERNAME": "emailUsername", - "GENERAL_EMAIL_PASSWORD": "emailPassword", - "GENERAL_EMAIL_SENDER_ADDRESS": "emailSender", - "GENERAL_EMAIL_TEMPLATE": "emailTemplate", - "COMMON_NAME": "commonName", - "KEYSTORE_PASSWORD": "keystorePassword", - "PRIVATE_KEY_PASSWORD": "privateKeyPassword", - "BEFORE_EXPIRE": "beforeExpire", - "AFTER_EXPIRE": "afterExpire", - "WINDOWS_EULA": "windowsLicense" -}; - -function promptErrorPolicyPlatform(errorMsg) { - var mainErrorMsgWrapper = "#platform-config-main-error-msg"; - var mainErrorMsg = mainErrorMsgWrapper + " span"; - $(mainErrorMsg).text(errorMsg); - $(mainErrorMsgWrapper).show(); -} - -$(document).ready(function () { - - var platformsSupported = $("#typeDiv").attr("typeData"); - $("#gcm-inputs").hide(); - tinymce.init({ - selector: "textarea", - height: 500, - theme: "modern", - plugins: [ - "autoresize", - "advlist autolink lists link image charmap print preview anchor", - "searchreplace visualblocks code fullscreen", - "insertdatetime image table contextmenu paste" - ], - toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image" - }); - - var getAndroidConfigAPI = "/mdm-android-agent/configuration"; - var getGeneralConfigAPI = "/devicemgt_admin/configuration"; - var getIosConfigAPI = "/ios/configuration"; - var getWindowsConfigAPI = "/mdm-windows-agent/services/configuration"; - - /** - * Following requests would execute - * on page load event of platform configuration page in WSO2 EMM Console. - * Upon receiving the response, the parameters will be set to the fields, - * in case those configurations are already set. - */ - - if (platformsSupported.indexOf('android') != -1) { - invokerUtil.get( - getAndroidConfigAPI, - function (data) { - data = JSON.parse(data); - if (data != null && data.configuration != null) { - for (var i = 0; i < data.configuration.length; i++) { - var config = data.configuration[i]; - if (config.name == configParams["NOTIFIER_TYPE"]) { - $("#android-config-notifier").val(config.value); - if (config.value != notifierTypeConstants["GCM"]) { - $("#gcm-inputs").hide(); - $("#local-inputs").show(); - } else { - $("#gcm-inputs").show(); - $("#local-inputs").hide(); - } - } else if (config.name == configParams["NOTIFIER_FREQUENCY"]) { - $("input#android-config-notifier-frequency").val(config.value / 1000); - } else if (config.name == configParams["GCM_API_KEY"]) { - $("input#android-config-gcm-api-key").val(config.value); - } else if (config.name == configParams["GCM_SENDER_ID"]) { - $("input#android-config-gcm-sender-id").val(config.value); - } else if (config.name == configParams["ANDROID_EULA"]) { - $("#android-eula").val(config.value); - } - } - } - }, function (data) { - console.log(data); - }); - } - - invokerUtil.get( - getGeneralConfigAPI, - function (data) { - data = JSON.parse(data); - if (data && data.configuration) { - for (var i = 0; i < data.configuration.length; i++) { - var config = data.configuration[i]; - if (config.name == configParams["NOTIFIER_FREQUENCY"]) { - $("input#monitoring-config-frequency").val(config.value / 1000); - } - } - } - }, function (data) { - console.log(data); - }); - - if (platformsSupported.indexOf('windows') != -1) { - invokerUtil.get( - getWindowsConfigAPI, - function (data) { - data = JSON.parse(data); - if (data != null && data.configuration != null) { - for (var i = 0; i < data.configuration.length; i++) { - var config = data.configuration[i]; - if (config.name == configParams["NOTIFIER_FREQUENCY"]) { - $("input#windows-config-notifier-frequency").val(config.value / 1000); - } else if (config.name == configParams["WINDOWS_EULA"]) { - $("#windows-eula").val(config.value); - } - } - } - }, function (data) { - console.log(data); - } - ); - } - - if (platformsSupported.indexOf('ios') != -1) { - invokerUtil.get( - getIosConfigAPI, - function (data) { - data = JSON.parse(data); - if (data != null && data.configuration != null) { - for (var i = 0; i < data.configuration.length; i++) { - var config = data.configuration[i]; - if (config.name == configParams["CONFIG_COUNTRY"]) { - $("input#ios-config-country").val(config.value); - } else if (config.name == configParams["CONFIG_STATE"]) { - $("input#ios-config-state").val(config.value); - } else if (config.name == configParams["CONFIG_LOCALITY"]) { - $("input#ios-config-locality").val(config.value); - } else if (config.name == configParams["CONFIG_ORGANIZATION"]) { - $("input#ios-config-organization").val(config.value); - } else if (config.name == configParams["CONFIG_ORGANIZATION_UNIT"]) { - $("input#ios-config-organization-unit").val(config.value); - } else if (config.name == configParams["MDM_CERT_PASSWORD"]) { - $("input#ios-config-mdm-certificate-password").val(config.value); - } else if (config.name == configParams["MDM_CERT_TOPIC_ID"]) { - $("input#ios-config-mdm-certificate-topic-id").val(config.value); - } else if (config.name == configParams["APNS_CERT_PASSWORD"]) { - $("input#ios-config-apns-certificate-password").val(config.value); - } else if (config.name == configParams["MDM_CERT_NAME"]) { - $("#mdm-cert-file-name").html(config.value); - iOSMDMCertificateName = config.value; - } else if (config.name == configParams["MDM_CERT"]) { - iOSMDMCertificate = config.value; - } else if (config.name == configParams["APNS_CERT_NAME"]) { - $("#apns-cert-file-name").html(config.value); - iOSAPNSCertificateName = config.value; - } else if (config.name == configParams["APNS_CERT"]) { - iOSAPNSCertificate = config.value; - } else if (config.name == configParams["ORG_DISPLAY_NAME"]) { - $("input#ios-org-display-name").val(config.value); - } else if (config.name == configParams["IOS_EULA"]) { - $("#ios-eula").val(config.value); - } - } - } - }, function (data) { - console.log(data); - } - ); - } - - $("select.select2[multiple=multiple]").select2({ - tags: true - }); - - $("#android-config-notifier").change(function () { - var notifierType = $("#android-config-notifier").find("option:selected").attr("value"); - if (notifierType != notifierTypeConstants["GCM"]) { - $("#gcm-inputs").hide(); - $("#local-inputs").show(); - } else { - $("#local-inputs").hide(); - $("#gcm-inputs").show(); - } - }); - - /** - * Following click function would execute - * when a user clicks on "Save" button - * on Android platform configuration page in WSO2 EMM Console. - */ - $("button#save-android-btn").click(function () { - var notifierType = $("#android-config-notifier").find("option:selected").attr("value"); - var notifierFrequency = $("input#android-config-notifier-frequency").val(); - var gcmAPIKey = $("input#android-config-gcm-api-key").val(); - var gcmSenderId = $("input#android-config-gcm-sender-id").val(); - var androidLicense = tinymce.get('android-eula').getContent(); - - var errorMsgWrapper = "#android-config-error-msg"; - var errorMsg = "#android-config-error-msg span"; - if (notifierType == notifierTypeConstants["LOCAL"] && !notifierFrequency) { - $(errorMsg).text("Notifier frequency is a required field. It cannot be empty."); - $(errorMsgWrapper).removeClass("hidden"); - } else if (notifierType == notifierTypeConstants["LOCAL"] && !isPositiveInteger(notifierFrequency)) { - $(errorMsg).text("Provided notifier frequency is invalid. "); - $(errorMsgWrapper).removeClass("hidden"); - } else if (notifierType == notifierTypeConstants["GCM"] && !gcmAPIKey) { - $(errorMsg).text("GCM API Key is a required field. It cannot be empty."); - $(errorMsgWrapper).removeClass("hidden"); - } else if (notifierType == notifierTypeConstants["GCM"] && !gcmSenderId) { - $(errorMsg).text("GCM Sender ID is a required field. It cannot be empty."); - $(errorMsgWrapper).removeClass("hidden"); - } else { - - var addConfigFormData = {}; - var configList = new Array(); - - var type = { - "name": configParams["NOTIFIER_TYPE"], - "value": notifierType, - "contentType": "text" - }; - - var frequency = { - "name": configParams["NOTIFIER_FREQUENCY"], - "value": String(notifierFrequency * 1000), - "contentType": "text" - }; - - var gcmKey = { - "name": configParams["GCM_API_KEY"], - "value": gcmAPIKey, - "contentType": "text" - }; - - var gcmId = { - "name": configParams["GCM_SENDER_ID"], - "value": gcmSenderId, - "contentType": "text" - }; - - var androidEula = { - "name": configParams["ANDROID_EULA"], - "value": androidLicense, - "contentType": "text" - }; - - configList.push(type); - configList.push(frequency); - configList.push(androidEula); - if (notifierType == notifierTypeConstants["GCM"]) { - configList.push(gcmKey); - configList.push(gcmId); - } - - addConfigFormData.type = platformTypeConstants["ANDROID"]; - addConfigFormData.configuration = configList; - - var addConfigAPI = "/mdm-android-agent/configuration"; - - invokerUtil.post( - addConfigAPI, - addConfigFormData, - function (data) { - data = JSON.parse(data); - if (data.responseCode == responseCodes["CREATED"]) { - $("#config-save-form").addClass("hidden"); - $("#record-created-msg").removeClass("hidden"); - } else if (data == 500) { - $(errorMsg).text("Exception occurred at backend."); - $(errorMsgWrapper).removeClass("hidden"); - } else if (data == 403) { - $(errorMsg).text("Action was not permitted."); - $(errorMsgWrapper).removeClass("hidden"); - } else { - $(errorMsg).text("An unexpected error occurred."); - $(errorMsgWrapper).removeClass("hidden"); - } - - - }, function (data) { - data = data.status; - if (data == 500) { - $(errorMsg).text("Exception occurred at backend."); - } else if (data == 403) { - $(errorMsg).text("Action was not permitted."); - } else { - $(errorMsg).text("An unexpected error occurred."); - } - $(errorMsgWrapper).removeClass("hidden"); - } - ); - } - }); - - /** - * Following click function would execute - * when a user clicks on "Save" button - * on General platform configuration page in WSO2 EMM Console. - */ - $("button#save-general-btn").click(function () { - var notifierFrequency = $("input#monitoring-config-frequency").val(); - var errorMsgWrapper = "#email-config-error-msg"; - var errorMsg = "#email-config-error-msg span"; - - if (!notifierFrequency) { - $(errorMsg).text("Monitoring frequency is a required field. It cannot be empty."); - $(errorMsgWrapper).removeClass("hidden"); - } else if (!isPositiveInteger(notifierFrequency)) { - $(errorMsg).text("Provided monitoring frequency is invalid. "); - $(errorMsgWrapper).removeClass("hidden"); - } else { - var addConfigFormData = {}; - var configList = new Array(); - - var monitorFrequency = { - "name": configParams["NOTIFIER_FREQUENCY"], - "value": String((notifierFrequency * 1000)), - "contentType": "text" - }; - - configList.push(monitorFrequency); - addConfigFormData.configuration = configList; - - var addConfigAPI = "/devicemgt_admin/configuration"; - invokerUtil.post( - addConfigAPI, - addConfigFormData, - function (data) { - data = JSON.parse(data); - if (data.statusCode == responseCodes["SUCCESS"]) { - $("#config-save-form").addClass("hidden"); - $("#record-created-msg").removeClass("hidden"); - } else if (data == 500) { - $(errorMsg).text("Exception occurred at backend."); - } else if (data == 403) { - $(errorMsg).text("Action was not permitted."); - } else { - $(errorMsg).text("An unexpected error occurred."); - } - - $(errorMsgWrapper).removeClass("hidden"); - }, function (data) { - data = data.status; - if (data == 500) { - $(errorMsg).text("Exception occurred at backend."); - } else if (data == 403) { - $(errorMsg).text("Action was not permitted."); - } else { - $(errorMsg).text("An unexpected error occurred."); - } - $(errorMsgWrapper).removeClass("hidden"); - } - ); - } - }); - - var errorMsgWrapper = "#ios-config-error-msg"; - var errorMsg = "#ios-config-error-msg span"; - var fileTypes = ['pfx']; - var notSupportedError = false; - - var base64MDMCert = ""; - var fileInputMDMCert = $('#ios-config-mdm-certificate'); - var fileNameMDMCert = ""; - var invalidFormatMDMCert = false; - - var base64APNSCert = ""; - var fileInputAPNSCert = $('#ios-config-apns-certificate'); - var fileNameAPNSCert = ""; - var invalidFormatAPNSCert = false; - - $(fileInputMDMCert).change(function () { - - if (!window.File || !window.FileReader || !window.FileList || !window.Blob) { - $(errorMsg).text("The File APIs are not fully supported in this browser."); - $(errorMsgWrapper).removeClass("hidden"); - notSupportedError = true; - return; - } - - var file = fileInputMDMCert[0].files[0]; - fileNameMDMCert = file.name; - var extension = file.name.split('.').pop().toLowerCase(), - isSuccess = fileTypes.indexOf(extension) > -1; - - if (isSuccess) { - var fileReader = new FileReader(); - fileReader.onload = function (event) { - base64MDMCert = event.target.result; - }; - fileReader.readAsDataURL(file); - invalidFormatMDMCert = false; - } else { - base64MDMCert = ""; - invalidFormatMDMCert = true; - } - }); - - $(fileInputAPNSCert).change(function () { - - if (!window.File || !window.FileReader || !window.FileList || !window.Blob) { - $(errorMsg).text("The File APIs are not fully supported in this browser."); - $(errorMsgWrapper).removeClass("hidden"); - notSupportedError = true; - return; - } - - var file = fileInputAPNSCert[0].files[0]; - fileNameAPNSCert = file.name; - var extension = file.name.split('.').pop().toLowerCase(), - isSuccess = fileTypes.indexOf(extension) > -1; - - if (isSuccess) { - var fileReader = new FileReader(); - fileReader.onload = function (event) { - base64APNSCert = event.target.result; - }; - fileReader.readAsDataURL(file); - invalidFormatAPNSCert = false; - } else { - base64MDMCert = ""; - invalidFormatAPNSCert = true; - } - }); - - $("button#save-ios-btn").click(function () { - - var configCountry = $("#ios-config-country").val(); - var configState = $("#ios-config-state").val(); - var configLocality = $("#ios-config-locality").val(); - var configOrganization = $("#ios-config-organization").val(); - var configOrganizationUnit = $("#ios-config-organization-unit").val(); - var MDMCertPassword = $("#ios-config-mdm-certificate-password").val(); - var MDMCertTopicID = $("#ios-config-mdm-certificate-topic-id").val(); - var APNSCertPassword = $("#ios-config-apns-certificate-password").val(); - var configOrgDisplayName = $("#ios-org-display-name").val(); - var iosLicense = tinymce.get('ios-eula').getContent(); - - fileNameMDMCert = validateCertificateParams(fileNameMDMCert, iOSMDMCertificateName); - fileNameAPNSCert = validateCertificateParams(fileNameAPNSCert, iOSAPNSCertificateName); - base64MDMCert = validateCertificateParams(base64MDMCert, iOSMDMCertificate); - base64APNSCert = validateCertificateParams(base64APNSCert, iOSAPNSCertificate); - - if (!configCountry) { - $(errorMsg).text("SCEP country is a required field. It cannot be empty."); - $(errorMsgWrapper).removeClass("hidden"); - } else if (!configState) { - $(errorMsg).text("SCEP state is a required field. It cannot be empty."); - $(errorMsgWrapper).removeClass("hidden"); - } else if (!configLocality) { - $(errorMsg).text("SCEP locality is a required field. It cannot be empty."); - $(errorMsgWrapper).removeClass("hidden"); - } else if (!configOrganization) { - $(errorMsg).text("SCEP organization is a required field. It cannot be empty."); - $(errorMsgWrapper).removeClass("hidden"); - } else if (!configOrganizationUnit) { - $(errorMsg).text("SCEP organization unit is a required field. It cannot be empty."); - $(errorMsgWrapper).removeClass("hidden"); - } else if (!MDMCertPassword) { - $(errorMsg).text("MDM certificate password is a required field. It cannot be empty."); - $(errorMsgWrapper).removeClass("hidden"); - } else if (!MDMCertTopicID) { - $(errorMsg).text("MDM certificate topic ID is a required field. It cannot be empty."); - $(errorMsgWrapper).removeClass("hidden"); - } else if (!APNSCertPassword) { - $(errorMsg).text("APNS certificate password is a required field. It cannot be empty."); - $(errorMsgWrapper).removeClass("hidden"); - } else if (notSupportedError) { - $(errorMsg).text("The File APIs are not fully supported in this browser."); - $(errorMsgWrapper).removeClass("hidden"); - } else if (invalidFormatMDMCert) { - $(errorMsg).text("MDM certificate needs to be in pfx format."); - $(errorMsgWrapper).removeClass("hidden"); - } else if (base64MDMCert == '') { - $(errorMsg).text("MDM certificate is a required field. It cannot be empty."); - $(errorMsgWrapper).removeClass("hidden"); - } else if (invalidFormatAPNSCert) { - $(errorMsg).text("APNS certificate needs to be in pfx format."); - $(errorMsgWrapper).removeClass("hidden"); - } else if (base64APNSCert == '') { - $(errorMsg).text("APNS certificate is a required field. It cannot be empty."); - $(errorMsgWrapper).removeClass("hidden"); - } else if (!configOrgDisplayName) { - $(errorMsg).text("Organization display name is a required field. It cannot be empty."); - $(errorMsgWrapper).removeClass("hidden"); - } else { - var addConfigFormData = {}; - var configList = new Array(); - - var configCountry = { - "name": configParams["CONFIG_COUNTRY"], - "value": configCountry, - "contentType": "text" - }; - - var configState = { - "name": configParams["CONFIG_STATE"], - "value": configState, - "contentType": "text" - }; - - var configLocality = { - "name": configParams["CONFIG_LOCALITY"], - "value": configLocality, - "contentType": "text" - }; - - var configOrganization = { - "name": configParams["CONFIG_ORGANIZATION"], - "value": configOrganization, - "contentType": "text" - }; - - var configOrganizationUnit = { - "name": configParams["CONFIG_ORGANIZATION_UNIT"], - "value": configOrganizationUnit, - "contentType": "text" - }; - - var MDMCertPassword = { - "name": configParams["MDM_CERT_PASSWORD"], - "value": MDMCertPassword, - "contentType": "text" - }; - - var MDMCertTopicID = { - "name": configParams["MDM_CERT_TOPIC_ID"], - "value": MDMCertTopicID, - "contentType": "text" - }; - - var APNSCertPassword = { - "name": configParams["APNS_CERT_PASSWORD"], - "value": APNSCertPassword, - "contentType": "text" - }; - - var paramBase64MDMCert = { - "name": configParams["MDM_CERT"], - "value": base64MDMCert, - "contentType": "text" - }; - - var MDMCertName = { - "name": configParams["MDM_CERT_NAME"], - "value": fileNameMDMCert, - "contentType": "text" - }; - - var paramBase64APNSCert = { - "name": configParams["APNS_CERT"], - "value": base64APNSCert, - "contentType": "text" - }; - - var APNSCertName = { - "name": configParams["APNS_CERT_NAME"], - "value": fileNameAPNSCert, - "contentType": "text" - }; - - var paramOrganizationDisplayName = { - "name": configParams["ORG_DISPLAY_NAME"], - "value": configOrgDisplayName, - "contentType": "text" - }; - - var iosEula = { - "name": configParams["IOS_EULA"], - "value": iosLicense, - "contentType": "text" - }; - - configList.push(configCountry); - configList.push(configState); - configList.push(configLocality); - configList.push(configOrganization); - configList.push(configOrganizationUnit); - configList.push(MDMCertPassword); - configList.push(MDMCertTopicID); - configList.push(APNSCertPassword); - configList.push(paramBase64MDMCert); - configList.push(MDMCertName); - configList.push(paramBase64APNSCert); - configList.push(APNSCertName); - configList.push(paramOrganizationDisplayName); - configList.push(iosEula); - - addConfigFormData.type = platformTypeConstants["IOS"]; - addConfigFormData.configuration = configList; - - var addConfigAPI = "/ios/configuration"; - - invokerUtil.post( - addConfigAPI, - addConfigFormData, - function (data) { - data = JSON.parse(data); - if (data.responseCode == responseCodes["CREATED"]) { - $("#config-save-form").addClass("hidden"); - $("#record-created-msg").removeClass("hidden"); - } else if (data == 500) { - $(errorMsg).text("Exception occurred at backend."); - } else if (data == 400) { - $(errorMsg).text("Configurations cannot be empty."); - } else { - $(errorMsg).text("An unexpected error occurred."); - } - - $(errorMsgWrapper).removeClass("hidden"); - }, function (data) { - data = data.status; - if (data == 500) { - $(errorMsg).text("Exception occurred at backend."); - } else if (data == 403) { - $(errorMsg).text("Action was not permitted."); - } else { - $(errorMsg).text("An unexpected error occurred."); - } - $(errorMsgWrapper).removeClass("hidden"); - } - ); - } - - }); - - var errorMsgWrapperWindows = "#windows-config-error-msg"; - var errorMsgWindows = "#windows-config-error-msg span"; - var fileTypesWindows = ['jks']; - var notSupportedError = false; - - var base64WindowsMDMCert = ""; - var fileInputWindowsMDMCert = $('#windows-config-mdm-certificate'); - var fileNameWindowsMDMCert = ""; - var invalidFormatWindowsMDMCert = false; - - $(fileInputWindowsMDMCert).change(function () { - - if (!window.File || !window.FileReader || !window.FileList || !window.Blob) { - $(errorMsgWindows).text("The File APIs are not fully supported in this browser."); - $(errorMsgWrapperWindows).removeClass("hidden"); - notSupportedError = true; - return; - } - - var file = fileInputWindowsMDMCert[0].files[0]; - fileNameWindowsMDMCert = file.name; - var extension = file.name.split('.').pop().toLowerCase(), - isSuccess = fileTypesWindows.indexOf(extension) > -1; - - if (isSuccess) { - var fileReader = new FileReader(); - fileReader.onload = function (event) { - base64WindowsMDMCert = event.target.result; - }; - fileReader.readAsDataURL(file); - invalidFormatWindowsMDMCert = false; - } else { - base64MDMCert = ""; - invalidFormatWindowsMDMCert = true; - } - }); - - $("button#save-windows-btn").click(function () { - - var notifierFrequency = $("#windows-config-notifier-frequency").val(); - var windowsLicense = tinymce.get('windows-eula').getContent(); - - if (!notifierFrequency) { - $(errorMsgWindows).text("Polling Interval is a required field. It cannot be empty."); - $(errorMsgWrapperWindows).removeClass("hidden"); - } else if (!windowsLicense) { - $(errorMsgWindows).text("License is a required field. It cannot be empty."); - $(errorMsgWrapperWindows).removeClass("hidden"); - } else if (!$.isNumeric(notifierFrequency)) { - $(errorMsgWindows).text("Provided Notifier frequency is invalid. It must be a number."); - $(errorMsgWrapperWindows).removeClass("hidden"); - } else { - var addConfigFormData = {}; - var configList = new Array(); - - var paramNotifierFrequency = { - "name": configParams["NOTIFIER_FREQUENCY"], - "value": String(notifierFrequency * 1000), - "contentType": "text" - }; - - var windowsEula = { - "name": configParams["WINDOWS_EULA"], - "value": windowsLicense, - "contentType": "text" - }; - - configList.push(paramNotifierFrequency); - configList.push(windowsEula); - - addConfigFormData.type = platformTypeConstants["WINDOWS"]; - addConfigFormData.configuration = configList; - - var addConfigAPI = "/mdm-windows-agent/services/configuration"; - - invokerUtil.post( - addConfigAPI, - addConfigFormData, - function (data) { - data = JSON.parse(data); - if (data.responseCode == responseCodes["CREATED"]) { - $("#config-save-form").addClass("hidden"); - $("#record-created-msg").removeClass("hidden"); - } else if (data == 500) { - $(errorMsg).text("Exception occurred at backend."); - } else if (data == 400) { - $(errorMsg).text("Configurations cannot be empty."); - } else { - $(errorMsg).text("An unexpected error occurred."); - } - - $(errorMsgWrapperWindows).removeClass("hidden"); - }, function (data) { - data = data.status; - if (data == 500) { - $(errorMsg).text("Exception occurred at backend."); - } else if (data == 403) { - $(errorMsg).text("Action was not permitted."); - } else { - $(errorMsg).text("An unexpected error occurred."); - } - $(errorMsgWrapper).removeClass("hidden"); - } - ); - } - - }); -}); - -// Start of HTML embedded invoke methods -var showAdvanceOperation = function (operation, button) { - $(button).addClass('selected'); - $(button).siblings().removeClass('selected'); - var enabledPlatforms = $("#supportedPlatforms"); - var isPluginEnabled = false; - switch (operation) { - case 'ios': - if (enabledPlatforms.data("ios")) { - isPluginEnabled = true; - } - break; - case 'windows': - if (enabledPlatforms.data("windows")) { - isPluginEnabled = true; - } - break; - case 'android': - if (enabledPlatforms.data("android")) { - isPluginEnabled = true; - } - break; - case 'general': - isPluginEnabled = true; - break; - } - if (isPluginEnabled) { - var hiddenOperation = ".wr-hidden-operations-content > div"; - $(hiddenOperation + '[data-operation="' + operation + '"]').show(); - $(hiddenOperation + '[data-operation="' + operation + '"]').siblings().hide(); - } else { - var hiddenOperation = ".wr-hidden-operations-content > div"; - $(hiddenOperation + '[data-operation="error"]').show(); - $(hiddenOperation + '[data-operation="error"]').siblings().hide(); - promptErrorPolicyPlatform("To use " + operation + " related functionalities you need to configure the server " + - "accordingly.Please refer to the user guiled."); - } -}; diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.wizard/wizard.js b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.wizard/wizard.js index 10372ee19e..e447231cc6 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.wizard/wizard.js +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.wizard/wizard.js @@ -18,6 +18,7 @@ function onRequest(context) { var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; + var deviceModule = require("/app/modules/business-controllers/device.js").deviceModule; var utility = require('/app/modules/utility.js').utility; var response = userModule.getRoles(); var wizardPage = {}; @@ -25,7 +26,7 @@ function onRequest(context) { wizardPage["roles"] = response["content"]; } var deviceType = context.uriParams.deviceType; - var typesListResponse = userModule.getPlatforms(); + var typesListResponse = deviceModule.getDeviceTypes(); if (typesListResponse["status"] == "success") { for (var type in typesListResponse["content"]) { if (deviceType == typesListResponse["content"][type]["name"]) { diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/pom.xml b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/pom.xml index 98ef253530..e509972cfd 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/pom.xml +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/pom.xml @@ -322,6 +322,11 @@ org.wso2.carbon.certificate.mgt.core provided + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.annotations + provided + org.codehaus.jettison.wso2 jettison diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/ConfigurationMgtService.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/ConfigurationMgtService.java index 2c6dc4be77..320b75ad8c 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/ConfigurationMgtService.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/ConfigurationMgtService.java @@ -18,34 +18,33 @@ package org.wso2.carbon.mdm.mobileservices.windows.services.configurationmgtservice; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; +import org.wso2.carbon.apimgt.annotations.api.API; +import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; -import org.wso2.carbon.device.mgt.common.license.mgt.License; -import org.wso2.carbon.mdm.mobileservices.windows.common.PluginConstants; import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsConfigurationException; import org.wso2.carbon.mdm.mobileservices.windows.common.util.Message; -import org.wso2.carbon.mdm.mobileservices.windows.common.util.WindowsAPIUtils; import javax.jws.WebService; -import javax.ws.rs.*; -import javax.ws.rs.core.Response; -import java.util.ArrayList; -import java.util.List; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; /** * Windows Platform Configuration REST-API implementation. * All end points supports JSON, XMl with content negotiation. */ +@API(name = "Windows Configuration Management", version = "1.0.0", + context = "api/device-mgt/windows/v1.0/services/configuration", + tags = {"windows"}) + @WebService @Produces({"application/json", "application/xml"}) @Consumes({"application/json", "application/xml"}) -public class ConfigurationMgtService { - - private static Log log = LogFactory.getLog(ConfigurationMgtService.class); +@Path("services/configuration") +public interface ConfigurationMgtService { /** * Save Tenant configurations. @@ -55,49 +54,8 @@ public class ConfigurationMgtService { * @throws WindowsConfigurationException */ @POST - public Message ConfigureSettings(PlatformConfiguration configuration) throws WindowsConfigurationException { - Message responseMsg = new Message(); - ConfigurationEntry licenseEntry = null; - String message; - - try { - configuration.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - if (!configuration.getConfiguration().isEmpty()) { - List configs = configuration.getConfiguration(); - for (ConfigurationEntry entry : configs) { - if (PluginConstants.TenantConfigProperties.LICENSE_KEY.equals(entry.getName())) { - License license = new License(); - license.setName(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - license.setLanguage(PluginConstants.TenantConfigProperties.LANGUAGE_US); - license.setVersion("1.0.0"); - license.setText(entry.getValue().toString()); - WindowsAPIUtils.getDeviceManagementService().addLicense(DeviceManagementConstants. - MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, license); - licenseEntry = entry; - } - } - - if (licenseEntry != null) { - configs.remove(licenseEntry); - } - configuration.setConfiguration(configs); - WindowsAPIUtils.getDeviceManagementService().saveConfiguration(configuration); - Response.status(Response.Status.CREATED); - responseMsg.setResponseMessage("Windows platform configuration saved successfully."); - responseMsg.setResponseCode(Response.Status.CREATED.toString()); - return responseMsg; - } else { - Response.status(Response.Status.BAD_REQUEST); - responseMsg.setResponseMessage("Windows platform configuration can not be saved."); - responseMsg.setResponseCode(Response.Status.CREATED.toString()); - } - } catch (DeviceManagementException e) { - message = "Error Occurred while configuring Windows Platform."; - log.error(message, e); - throw new WindowsConfigurationException(message, e); - } - return responseMsg; - } + @Scope(key = "configuration:manage", name = "Add configurations", description = "") + Message ConfigureSettings(PlatformConfiguration configuration) throws WindowsConfigurationException; /** * Retrieve Tenant configurations according to the device type. @@ -106,39 +64,8 @@ public class ConfigurationMgtService { * @throws WindowsConfigurationException */ @GET - public PlatformConfiguration getConfiguration() throws WindowsConfigurationException { - String msg; - PlatformConfiguration tenantConfiguration; - List configs; - try { - tenantConfiguration = WindowsAPIUtils.getDeviceManagementService(). - getConfiguration(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - if (tenantConfiguration != null) { - configs = tenantConfiguration.getConfiguration(); - } else { - tenantConfiguration = new PlatformConfiguration(); - configs = new ArrayList<>(); - } - - ConfigurationEntry entry = new ConfigurationEntry(); - License license = WindowsAPIUtils.getDeviceManagementService().getLicense( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, - PluginConstants.TenantConfigProperties.LANGUAGE_US); - - if (license != null && configs != null) { - entry.setContentType(PluginConstants.TenantConfigProperties.CONTENT_TYPE_TEXT); - entry.setName(PluginConstants.TenantConfigProperties.LICENSE_KEY); - entry.setValue(license.getText()); - configs.add(entry); - tenantConfiguration.setConfiguration(configs); - } - } catch (DeviceManagementException e) { - msg = "Error occurred while retrieving the Windows tenant configuration"; - log.error(msg, e); - throw new WindowsConfigurationException(msg, e); - } - return tenantConfiguration; - } + @Scope(key = "configuration:view", name = "View configurations", description = "") + PlatformConfiguration getConfiguration() throws WindowsConfigurationException; /** * Update Tenant Configurations for the specific Device type. @@ -148,39 +75,6 @@ public class ConfigurationMgtService { * @throws WindowsConfigurationException */ @PUT - public Message updateConfiguration(PlatformConfiguration configuration) throws WindowsConfigurationException { - String message; - Message responseMsg = new Message(); - ConfigurationEntry licenseEntry = null; - try { - configuration.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - List configs = configuration.getConfiguration(); - for (ConfigurationEntry entry : configs) { - if (PluginConstants.TenantConfigProperties.LICENSE_KEY.equals(entry.getName())) { - License license = new License(); - license.setName(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - license.setLanguage(PluginConstants.TenantConfigProperties.LANGUAGE_US); - license.setVersion("1.0.0"); - license.setText(entry.getValue().toString()); - WindowsAPIUtils.getDeviceManagementService().addLicense(DeviceManagementConstants. - MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, license); - licenseEntry = entry; - } - } - - if (licenseEntry != null) { - configs.remove(licenseEntry); - } - configuration.setConfiguration(configs); - WindowsAPIUtils.getDeviceManagementService().saveConfiguration(configuration); - Response.status(Response.Status.CREATED); - responseMsg.setResponseMessage("Windows platform configuration succeeded."); - responseMsg.setResponseCode(Response.Status.CREATED.toString()); - } catch (DeviceManagementException e) { - message = "Error occurred while modifying configuration settings of Windows platform."; - log.error(message, e); - throw new WindowsConfigurationException(message, e); - } - return responseMsg; - } + @Scope(key = "configuration:manage", name = "Add configurations", description = "") + Message updateConfiguration(PlatformConfiguration configuration) throws WindowsConfigurationException; } diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/ConfigurationMgtServiceImpl.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/ConfigurationMgtServiceImpl.java new file mode 100644 index 0000000000..c6b94383bd --- /dev/null +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/ConfigurationMgtServiceImpl.java @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.mdm.mobileservices.windows.services.configurationmgtservice; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; +import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; +import org.wso2.carbon.device.mgt.common.license.mgt.License; +import org.wso2.carbon.mdm.mobileservices.windows.common.PluginConstants; +import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsConfigurationException; +import org.wso2.carbon.mdm.mobileservices.windows.common.util.Message; +import org.wso2.carbon.mdm.mobileservices.windows.common.util.WindowsAPIUtils; + +import javax.jws.WebService; +import javax.ws.rs.*; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +@WebService +@Produces({"application/json", "application/xml"}) +@Consumes({"application/json", "application/xml"}) +@Path("/") +public class ConfigurationMgtServiceImpl implements ConfigurationMgtService{ + + private static Log log = LogFactory.getLog(ConfigurationMgtServiceImpl.class); + + /** + * Save Tenant configurations. + * + * @param configuration Tenant Configurations to be saved. + * @return Message type object for the provide save status. + * @throws WindowsConfigurationException + */ + @POST + public Message ConfigureSettings(PlatformConfiguration configuration) throws WindowsConfigurationException { + Message responseMsg = new Message(); + ConfigurationEntry licenseEntry = null; + String message; + + try { + configuration.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); + if (!configuration.getConfiguration().isEmpty()) { + List configs = configuration.getConfiguration(); + for (ConfigurationEntry entry : configs) { + if (PluginConstants.TenantConfigProperties.LICENSE_KEY.equals(entry.getName())) { + License license = new License(); + license.setName(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); + license.setLanguage(PluginConstants.TenantConfigProperties.LANGUAGE_US); + license.setVersion("1.0.0"); + license.setText(entry.getValue().toString()); + WindowsAPIUtils.getDeviceManagementService().addLicense(DeviceManagementConstants. + MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, license); + licenseEntry = entry; + } + } + + if (licenseEntry != null) { + configs.remove(licenseEntry); + } + configuration.setConfiguration(configs); + WindowsAPIUtils.getDeviceManagementService().saveConfiguration(configuration); + Response.status(Response.Status.CREATED); + responseMsg.setResponseMessage("Windows platform configuration saved successfully."); + responseMsg.setResponseCode(Response.Status.CREATED.toString()); + return responseMsg; + } else { + Response.status(Response.Status.BAD_REQUEST); + responseMsg.setResponseMessage("Windows platform configuration can not be saved."); + responseMsg.setResponseCode(Response.Status.CREATED.toString()); + } + } catch (DeviceManagementException e) { + message = "Error Occurred while configuring Windows Platform."; + log.error(message, e); + throw new WindowsConfigurationException(message, e); + } + return responseMsg; + } + + /** + * Retrieve Tenant configurations according to the device type. + * + * @return Tenant configuration object contains specific tenant configurations. + * @throws WindowsConfigurationException + */ + @GET + public PlatformConfiguration getConfiguration() throws WindowsConfigurationException { + String msg; + PlatformConfiguration tenantConfiguration; + List configs; + try { + tenantConfiguration = WindowsAPIUtils.getDeviceManagementService(). + getConfiguration(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); + if (tenantConfiguration != null) { + configs = tenantConfiguration.getConfiguration(); + } else { + tenantConfiguration = new PlatformConfiguration(); + configs = new ArrayList<>(); + } + + ConfigurationEntry entry = new ConfigurationEntry(); + License license = WindowsAPIUtils.getDeviceManagementService().getLicense( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, + PluginConstants.TenantConfigProperties.LANGUAGE_US); + + if (license != null && configs != null) { + entry.setContentType(PluginConstants.TenantConfigProperties.CONTENT_TYPE_TEXT); + entry.setName(PluginConstants.TenantConfigProperties.LICENSE_KEY); + entry.setValue(license.getText()); + configs.add(entry); + tenantConfiguration.setConfiguration(configs); + } + } catch (DeviceManagementException e) { + msg = "Error occurred while retrieving the Windows tenant configuration"; + log.error(msg, e); + throw new WindowsConfigurationException(msg, e); + } + return tenantConfiguration; + } + + /** + * Update Tenant Configurations for the specific Device type. + * + * @param configuration Tenant configurations to be updated. + * @return Response message. + * @throws WindowsConfigurationException + */ + @PUT + public Message updateConfiguration(PlatformConfiguration configuration) throws WindowsConfigurationException { + String message; + Message responseMsg = new Message(); + ConfigurationEntry licenseEntry = null; + try { + configuration.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); + List configs = configuration.getConfiguration(); + for (ConfigurationEntry entry : configs) { + if (PluginConstants.TenantConfigProperties.LICENSE_KEY.equals(entry.getName())) { + License license = new License(); + license.setName(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); + license.setLanguage(PluginConstants.TenantConfigProperties.LANGUAGE_US); + license.setVersion("1.0.0"); + license.setText(entry.getValue().toString()); + WindowsAPIUtils.getDeviceManagementService().addLicense(DeviceManagementConstants. + MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, license); + licenseEntry = entry; + } + } + + if (licenseEntry != null) { + configs.remove(licenseEntry); + } + configuration.setConfiguration(configs); + WindowsAPIUtils.getDeviceManagementService().saveConfiguration(configuration); + Response.status(Response.Status.CREATED); + responseMsg.setResponseMessage("Windows platform configuration succeeded."); + responseMsg.setResponseCode(Response.Status.CREATED.toString()); + } catch (DeviceManagementException e) { + message = "Error occurred while modifying configuration settings of Windows platform."; + log.error(message, e); + throw new WindowsConfigurationException(message, e); + } + return responseMsg; + } +} diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 705ddd524b..e756b20fe7 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -197,7 +197,7 @@ class="org.wso2.carbon.mdm.mobileservices.windows.services.wstep.util.MessageHandler"/> + class="org.wso2.carbon.mdm.mobileservices.windows.services.configurationmgtservice.ConfigurationMgtServiceImpl"/> diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/web.xml b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/web.xml index e9f5de0f80..cfff9d4b35 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/web.xml +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/web.xml @@ -48,7 +48,18 @@ 60 - + + isAdminService + false + + + managed-api-enabled + true + + + managed-api-owner + admin + doAuthentication true diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.platform.configuration/configuration.hbs b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.platform.configuration/configuration.hbs new file mode 100644 index 0000000000..3ca1c1dca5 --- /dev/null +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.platform.configuration/configuration.hbs @@ -0,0 +1,56 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} + +
+
+ +

+ Device Polling Configuration +
+

+
+
+ + +
+
+

+ End User License Agreement ( EULA ) +
+

+
+ +
+
+ +
+
+
+ +{{#zone "bottomJs"}} + {{js "js/platform-configuration.js"}} +{{/zone}} diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.platform.configuration/configuration.json b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.platform.configuration/configuration.json new file mode 100644 index 0000000000..fd25901297 --- /dev/null +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.platform.configuration/configuration.json @@ -0,0 +1,3 @@ +{ + "version" : "1.0.0" +} \ No newline at end of file diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.platform.configuration/public/js/platform-configuration.js b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.platform.configuration/public/js/platform-configuration.js new file mode 100644 index 0000000000..79ce06bcfb --- /dev/null +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.platform.configuration/public/js/platform-configuration.js @@ -0,0 +1,219 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +// Constants to define platform types available +var platformTypeConstants = { + "WINDOWS": "windows" +}; + +var responseCodes = { + "CREATED": "Created", + "SUCCESS": "201", + "INTERNAL_SERVER_ERROR": "Internal Server Error" +}; + +var configParams = { + "NOTIFIER_TYPE": "notifierType", + "NOTIFIER_FREQUENCY": "notifierFrequency", + "GCM_API_KEY": "gcmAPIKey", + "GCM_SENDER_ID": "gcmSenderId", + "ANDROID_EULA": "androidEula", + "IOS_EULA": "iosEula", + "CONFIG_COUNTRY": "configCountry", + "CONFIG_STATE": "configState", + "CONFIG_LOCALITY": "configLocality", + "CONFIG_ORGANIZATION": "configOrganization", + "CONFIG_ORGANIZATION_UNIT": "configOrganizationUnit", + "MDM_CERT_PASSWORD": "MDMCertPassword", + "MDM_CERT_TOPIC_ID": "MDMCertTopicID", + "APNS_CERT_PASSWORD": "APNSCertPassword", + "MDM_CERT": "MDMCert", + "MDM_CERT_NAME": "MDMCertName", + "APNS_CERT": "APNSCert", + "APNS_CERT_NAME": "APNSCertName", + "ORG_DISPLAY_NAME": "organizationDisplayName", + "GENERAL_EMAIL_HOST": "emailHost", + "GENERAL_EMAIL_PORT": "emailPort", + "GENERAL_EMAIL_USERNAME": "emailUsername", + "GENERAL_EMAIL_PASSWORD": "emailPassword", + "GENERAL_EMAIL_SENDER_ADDRESS": "emailSender", + "GENERAL_EMAIL_TEMPLATE": "emailTemplate", + "COMMON_NAME": "commonName", + "KEYSTORE_PASSWORD": "keystorePassword", + "PRIVATE_KEY_PASSWORD": "privateKeyPassword", + "BEFORE_EXPIRE": "beforeExpire", + "AFTER_EXPIRE": "afterExpire", + "WINDOWS_EULA": "windowsLicense", + "IOS_CONFIG_MDM_MODE": "iOSConfigMDMMode", + "IOS_CONFIG_APNS_MODE": "iOSConfigAPNSMode" +}; + +function promptErrorPolicyPlatform(errorMsg) { + var mainErrorMsgWrapper = "#platform-config-main-error-msg"; + var mainErrorMsg = mainErrorMsgWrapper + " span"; + $(mainErrorMsg).text(errorMsg); + $(mainErrorMsgWrapper).show(); +} + +$(document).ready(function () { + tinymce.init({ + selector: "textarea", + height:500, + theme: "modern", + plugins: [ + "autoresize", + "advlist autolink lists link image charmap print preview anchor", + "searchreplace visualblocks code fullscreen", + "insertdatetime image table contextmenu paste" + ], + toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image" + }); + + var windowsConfigAPI = "/api/device-mgt/windows/v1.0/services/configuration"; + + invokerUtil.get( + windowsConfigAPI, + function (data) { + data = JSON.parse(data); + if (data != null && data.configuration != null) { + for (var i = 0; i < data.configuration.length; i++) { + var config = data.configuration[i]; + if (config.name == configParams["NOTIFIER_FREQUENCY"]) { + $("input#windows-config-notifier-frequency").val(config.value / 1000); + } else if (config.name == configParams["WINDOWS_EULA"]) { + $("#windows-eula").val(config.value); + } + } + } + }, function (data) { + console.log(data); + } + ); + + $("select.select2[multiple=multiple]").select2({ + tags: true + }); + + var errorMsgWrapperWindows = "#windows-config-error-msg"; + var errorMsgWindows = "#windows-config-error-msg span"; + var fileTypesWindows = ['jks']; + var notSupportedError = false; + + var base64WindowsMDMCert = ""; + var fileInputWindowsMDMCert = $('#windows-config-mdm-certificate'); + var fileNameWindowsMDMCert = ""; + var invalidFormatWindowsMDMCert = false; + + $(fileInputWindowsMDMCert).change(function () { + + if (!window.File || !window.FileReader || !window.FileList || !window.Blob) { + $(errorMsgWindows).text("The File APIs are not fully supported in this browser."); + $(errorMsgWrapperWindows).removeClass("hidden"); + notSupportedError = true; + return; + } + + var file = fileInputWindowsMDMCert[0].files[0]; + fileNameWindowsMDMCert = file.name; + var extension = file.name.split('.').pop().toLowerCase(), + isSuccess = fileTypesWindows.indexOf(extension) > -1; + + if (isSuccess) { + var fileReader = new FileReader(); + fileReader.onload = function (event) { + base64WindowsMDMCert = event.target.result; + }; + fileReader.readAsDataURL(file); + invalidFormatWindowsMDMCert = false; + } else { + base64MDMCert = ""; + invalidFormatWindowsMDMCert = true; + } + }); + + $("button#save-windows-btn").click(function () { + + var notifierFrequency = $("#windows-config-notifier-frequency").val(); + var windowsLicense = tinyMCE.activeEditor.getContent(); + + if (!notifierFrequency) { + $(errorMsgWindows).text("Polling Interval is a required field. It cannot be empty."); + $(errorMsgWrapperWindows).removeClass("hidden"); + } else if (!windowsLicense) { + $(errorMsgWindows).text("License is a required field. It cannot be empty."); + $(errorMsgWrapperWindows).removeClass("hidden"); + } else if (!$.isNumeric(notifierFrequency)) { + $(errorMsgWindows).text("Provided Notifier frequency is invalid. It must be a number."); + $(errorMsgWrapperWindows).removeClass("hidden"); + } else { + var addConfigFormData = {}; + var configList = new Array(); + + var paramNotifierFrequency = { + "name": configParams["NOTIFIER_FREQUENCY"], + "value": String(notifierFrequency * 1000), + "contentType": "text" + }; + + var windowsEula = { + "name": configParams["WINDOWS_EULA"], + "value": windowsLicense, + "contentType": "text" + }; + + configList.push(paramNotifierFrequency); + configList.push(windowsEula); + + addConfigFormData.type = platformTypeConstants["WINDOWS"]; + addConfigFormData.configuration = configList; + + var addConfigAPI = windowsConfigAPI; + + invokerUtil.put( + addConfigAPI, + addConfigFormData, + function (data, textStatus, jqXHR) { + data = jqXHR.status; + if (data == 200) { + $("#config-save-form").addClass("hidden"); + $("#record-created-msg").removeClass("hidden"); + } else if (data == 500) { + $(errorMsg).text("Exception occurred at backend."); + } else if (data == 400) { + $(errorMsg).text("Configurations cannot be empty."); + } else { + $(errorMsg).text("An unexpected error occurred."); + } + + $(errorMsgWrapperWindows).removeClass("hidden"); + }, function (data) { + data = data.status; + if (data == 500) { + $(errorMsg).text("Exception occurred at backend."); + } else if (data == 403) { + $(errorMsg).text("Action was not permitted."); + } else { + $(errorMsg).text("An unexpected error occurred."); + } + $(errorMsgWrapper).removeClass("hidden"); + } + ); + } + + }); +}); \ No newline at end of file