diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/conf/devicecloud-config.xml b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/conf/devicecloud-config.xml index c310d6223d..068dc40a3e 100644 --- a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/conf/devicecloud-config.xml +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/conf/devicecloud-config.xml @@ -4,7 +4,7 @@ WSO2-BAM false - org.wso2.carbon.device.mgt.iot.common.datastore.impl.ThriftDataStoreConnector + org.wso2.carbon.device.mgt.iot.datastore.impl.ThriftDataStoreConnector tcp://localhost 7611 admin @@ -14,7 +14,7 @@ WSO2-CEP false - org.wso2.carbon.device.mgt.iot.common.datastore.impl.ThriftDataStoreConnector + org.wso2.carbon.device.mgt.iot.datastore.impl.ThriftDataStoreConnector tcp://localhost 7611 admin @@ -26,7 +26,7 @@ MQTT true - org.wso2.carbon.device.mgt.iot.common.controlqueue.mqtt.MqttControlPublisher + org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttControlPublisher MQTT tcp://204.232.188.214 1883 @@ -36,8 +36,8 @@ XMPP - true - org.wso2.carbon.device.mgt.iot.common.controlqueue.xmpp.XmppServerClient + false + org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppServerClient XMPP http://204.232.188.215 9090 diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.platform.configuration/configuration.hbs b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.platform.configuration/configuration.hbs new file mode 100644 index 0000000000..302cc5e9a0 --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.platform.configuration/configuration.hbs @@ -0,0 +1,5 @@ +{{unit "cdmf.unit.ui.title" pageTitle="Platform Configuration"}} + +{{#zone "content"}} + {{unit "cdmf.unit.platform.configuration"}} +{{/zone}} \ No newline at end of file diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.platform.configuration/configuration.json b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.platform.configuration/configuration.json new file mode 100644 index 0000000000..10d6483289 --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.platform.configuration/configuration.json @@ -0,0 +1,5 @@ +{ + "version": "1.0.0", + "uri": "/platform-configuration", + "layout": "uuf.layout.default" +} \ No newline at end of file diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/operation-bar.hbs b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/operation-bar.hbs new file mode 100644 index 0000000000..fd1bc3133e --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/operation-bar.hbs @@ -0,0 +1,7 @@ +
+ +{{#zone "bottomJs"}} + + {{js "js/operation-bar.js"}} +{{/zone}} \ No newline at end of file diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/operation-bar.js b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/operation-bar.js new file mode 100644 index 0000000000..3e9c47af0e --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/operation-bar.js @@ -0,0 +1,4 @@ +function onRequest (context) { + // var log = new Log("operation-bar.js"); + return context; +} \ No newline at end of file diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/operation-bar.json b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/operation-bar.json new file mode 100644 index 0000000000..56a988c763 --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/operation-bar.json @@ -0,0 +1,4 @@ +{ + "version": "1.0.0", + "extends": "cdmf.unit.device.operation-bar" +} \ No newline at end of file diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/public/js/operation-bar.js b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/public/js/operation-bar.js new file mode 100644 index 0000000000..26666e1bfb --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/public/js/operation-bar.js @@ -0,0 +1,298 @@ +/* + * 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. + */ + +/* + * Setting-up global variables. + */ + +var operations = '.wr-operations', + modalPopup = '.wr-modalpopup', + modalPopupContainer = modalPopup + ' .modalpopup-container', + modalPopupContent = modalPopup + ' .modalpopup-content', + // deviceCheckbox = '#ast-container .ctrl-wr-asset .itm-select input[type="checkbox"]', + // showOperationsBtn = '#showOperationsBtn', + navHeight = $('#nav').height(), + headerHeight = $('header').height(), + offset = (headerHeight + navHeight), + // maxOperationsLimit = 15, + // hiddenOperation = '.wr-hidden-operations-content > div', + deviceSelection = '.device-select', + dataTableSelection = '.DTTT_selected', + currentOperationList = []; + +/* +* On window resize functions. +*/ +//$(window).resize(function(){ +// toggleMoreOperationsHeight(); +//}); + +/* + * On main div.container resize functions. + * @required jquery.resize.js + */ +//$('.container').resize(function(){ +// toggleMoreOperationsHeight(); +//}); + +/* + * On Show Operations click operation show toggling function. + */ +//function showOperations(){ +// $(operations).toggle('slide'); +//} + +/* + * Function to get selected devices ID's + */ +function getSelectedDeviceIds() { + var deviceIdentifierList = []; + $(deviceSelection).each(function (index) { + var device = $(this); + var deviceId = device.data('deviceid'); + var deviceType = device.data('type'); + deviceIdentifierList.push({ + "id" : deviceId, + "type" : deviceType + }); + }); + if(deviceIdentifierList.length == 0) { + var thisTable = $(".DTTT_selected").closest('.dataTables_wrapper').find('.dataTable').dataTable(); + thisTable.api().rows().every(function () { + if ($(this.node()).hasClass('DTTT_selected')) { + var deviceId = $(thisTable.api().row(this).node()).data('deviceid'); + var deviceType = $(thisTable.api().row(this).node()).data('devicetype'); + deviceIdentifierList.push({ + "id": deviceId, + "type": deviceType + }); + } + }); + } + + return deviceIdentifierList; +} + +/* + * On operation click function. + * @param selection: Selected operation + */ +function operationSelect (selection) { + var deviceIdList = getSelectedDeviceIds(); + if (deviceIdList == 0) { + $(modalPopupContent).html($("#errorOperations").html()); + } else { + $(modalPopupContent).addClass("operation-data"); + $(modalPopupContent).html($(operations + " .operation[data-operation-code=" + selection + "]").html()); + $(modalPopupContent).data("operation-code", selection); + } + showPopup(); +} + +/* + * Function to open hidden device operations list + */ +//function toggleMoreOperations(){ +// $('.wr-hidden-operations, .wr-page-content').toggleClass('toggled'); +// $(showOperationsBtn).toggleClass('selected'); +// //$('.footer').toggleClass('wr-hidden-operations-toggled'); +//} + +/* + * Function to fit hidden device operation window height with the screen + */ +//function toggleMoreOperationsHeight(){ +// $('.wr-hidden-operations').css('min-height', $('html').height() - (offset+140)); +//} + +/* + * Advance operations sub categories show/hide toggle function + */ +//function showAdvanceOperation(operation, button){ +// $(button).addClass('selected'); +// $(button).siblings().removeClass('selected'); +// $(hiddenOperation + '[data-operation-code="' + operation + '"]').show(); +// $(hiddenOperation + '[data-operation-code="' + operation + '"]').siblings().hide(); +//} + +function getDevicesByTypes (deviceList) { + var deviceTypes = {}; + $.each(deviceList, function (index, item) { + deviceTypes[item.type] = []; + if (item.type == "android" || item.type == "ios" || item.type == "windows") { + deviceTypes[item.type].push(item.id); + } +// if(item.type == "TemperatureController"){ +// deviceTypes[item.type].push(item.id); +// } + }); + return deviceTypes; +} + +function unloadOperationBar(){ + $("#showOperationsBtn").addClass("hidden"); + $(".wr-operations").html(""); +} + +function loadOperationBar (deviceType) { + var operationBar = $("#operations-bar"); + var operationBarSrc = operationBar.attr("src"); + var platformType = deviceType; + $.template("operations-bar", operationBarSrc, function (template) { + var serviceURL = "/devicemgt_admin/features/" + platformType; +// if (deviceType == "TemperatureController") { +// serviceURL = "/devicemgt_admin/features/android"; +// } + var successCallback = function (data) { + var viewModel = {}; + // var iconMap = {}; +// if (deviceType == "TemperatureController") { +// data = [{ +// "id": 0, +// "code": "BUZZER", +// "name": "Buzz", +// "description": "Buzz the device", +// "deviceType": "TemperatureController", +// "metadataEntries": null +// }]; +// currentOperationList = viewModel.features = data.reduce(function (total, current) { +// total[current.code] = current; +// return total; +// }, {}); +// } + data = JSON.parse(data).filter(function (current) { + var iconName; + if (deviceType == "android"){ + iconName = operationModule.getAndroidIconForFeature(current.code); + current.type = deviceType; + } if (deviceType == "windows"){ + iconName = operationModule.getWindowsIconForFeature(current.code); + } else if (deviceType == "ios"){ + iconName = operationModule.getIOSIconForFeature(current.code); + } + if (iconName){ + current.icon = iconName; + return current; + } + }); + viewModel.features = data; + var content = template(viewModel); + $(".wr-operations").html(content); + }; + invokerUtil.get(serviceURL, + successCallback, function(message){ + console.log(message); + }); + }); + // var hiddenOperationBar = $("#hidden-operations-bar-" + deviceType); + // var hiddenOperationBarSrc = hiddenOperationBar.attr("src"); +// if (hiddenOperationBarSrc){ +// $.template("hidden-operations-bar-" + deviceType, hiddenOperationBarSrc, function (template) { +// var serviceURL = "/devicemgt_admin/features/" + platformType; +// var successCallback = function (data) { +// var viewModel = {}; +// viewModel.features = data.reduce(function (total, current) { +// total[current.code] = current; +// return total; +// }, {}); +// currentOperationList = viewModel.features; +// var content = template(viewModel); +// $(".wr-hidden-operations").html(content); +// }; +// invokerUtil.get(serviceURL, +// successCallback, function(message){ +// console.log(message); +// }); +// }); +// $("#showOperationsBtn").removeClass("hidden"); +// } + +} + +function runOperation (operationName) { + var deviceIdList = getSelectedDeviceIds(); + var list = getDevicesByTypes(deviceIdList); + + var notificationBubble = ".wr-notification-bubble"; + var successCallback = function (data) { + console.log(data); +// $(".wr-notification-bar").append('
' + currentOperationList[operationName].name + +// '- Operation Successful!

'); + /*var notificationCount = parseInt($(notificationBubble).html()); + notificationCount++; + $(notificationBubble).html(notificationCount);*/ + if(operationName == "NOTIFICATION"){ + $(modalPopupContent).html($("#messageSuccess").html()); + }else { + $(modalPopupContent).html($("#operationSuccess").html()); + } + showPopup(); + }; + + var payload, serviceEndPoint; + if(list["ios"]){ + payload = operationModule.generatePayload("ios", operationName, list["ios"]); + serviceEndPoint = operationModule.getIOSServiceEndpoint(operationName); + } + if(list["android"]){ + payload = operationModule.generatePayload("android", operationName, list["android"]); + serviceEndPoint = operationModule.getAndroidServiceEndpoint(operationName); + } + if(list["windows"]){ + payload = operationModule.generatePayload("windows", operationName, list["windows"]); + serviceEndPoint = operationModule.getWindowsServiceEndpoint(operationName); + } +// if(list["TemperatureController"]){ +// payload = operationModule.generatePayload("TemperatureController", operationName, list["TemperatureController"]); +// serviceEndPoint = operationModule.getTemperatureControllerServiceEndpoint(operationName); +// } + console.log(payload); + invokerUtil.post(serviceEndPoint, payload, + successCallback, function(jqXHR, textStatus, errorThrown){ + console.log(textStatus); + }); + $(modalPopupContent).removeData(); + hidePopup(); +} + +/* + * DOM ready functions. + */ +$(document).ready(function(){ +// if($(operations + "> a").length > maxOperationsLimit){ +// $(showOperationsBtn).show(); +// } +// else{ +// $(operations).show(); +// } + $(operations).show(); + // toggleMoreOperationsHeight(); + //loadOperationBar("ios"); + /** + * Android App type javascript + */ +// $(".wr-modalpopup").on("click", ".appTypesInput", function(){ +// var appType = $(".appTypesInput").val(); +// if (appType == "Public") { +// $('.appURLInput').prop( "disabled", true ); +// }else if (appType == "Enterprise"){ +// $('.appURLInput').prop( "disabled", false ); +// } +// }).trigger("change"); +}); diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/public/templates/hidden-operations-ios.hbs b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/public/templates/hidden-operations-ios.hbs new file mode 100644 index 0000000000..4cb006ef07 --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/public/templates/hidden-operations-ios.hbs @@ -0,0 +1,366 @@ +
+ +
+ + +
+
+ +
+ +
+ +
+ +
+ +
+ + +
+ +
+
+ + +
+
+ + +
+ Install +
+ +
+
+ +
+ +
+ +
+ +
+ +
+ + +
+ +
+
+ + +
+
+ + +
+ Install +
+
+
+ +
+ +
+ +
+ Uninstall +
+
+
+ + + +
+ + +
+ +
+ +
+ + +
+ +
+ + +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ Configure +
+ + + +
+ + +
+ +
+ + + +
+
+ +
+
+ Path Prefix +
+
+
+ + + +
+ +
+ + + +
+ +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + + +
+
+ +
+
+ : +
+
+
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ +
+ + +
+
+ + + +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ Configure +
+ + +
+ +
+ +
+ +
+ +
AirPlay password +
+ +
+ Configure +
+ +
+
\ No newline at end of file diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/public/templates/operations.hbs b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/public/templates/operations.hbs new file mode 100644 index 0000000000..573358a959 --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/public/templates/operations.hbs @@ -0,0 +1,130 @@ +
+
+
+
+

+ + + + + Operation cannot be performed ! +

+

+ Please select a device or a list of devices to perform an operation. +

+ +
+
+
+
+
+
+
+
+

+ + + + + Operation performed successfully ! +

+

+ Operation has been queued to be sent to the device. +

+ +
+
+
+
+ +
+
+
+
+

+ + + + + Message sent successfully ! +

+

+ Message has been queued to be sent to the device. +

+ +
+
+
+
+{{#each features}} + + + {{name}} + +
+
+
+
+

+ + + + + {{name}} +
+

+

+ {{#equal code "WIPE_DATA"}} + {{#equal type "android"}} + Enter PIN code (Optional - This is required only if the device type is BYOD). +

+
+ +
+
+ {{/equal}} + {{/equal}} + {{#equal code "NOTIFICATION"}} + Type your message below. +

+
+ +
+
+ {{/equal}} + {{#equal code "CHANGE_LOCK_CODE"}} + Type new lock-code below. +

+ +
+ {{/equal}} + Do you want to perform this operation on selected device(s) ? +
+

+ +
+
+
+
+{{/each}} +
\ No newline at end of file diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-mod/operation-mod.hbs b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-mod/operation-mod.hbs new file mode 100644 index 0000000000..d193515b46 --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-mod/operation-mod.hbs @@ -0,0 +1,3 @@ +{{#zone "bottomJs"}} + {{js "js/operation-mod.js"}} +{{/zone}} \ No newline at end of file diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-mod/operation-mod.json b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-mod/operation-mod.json new file mode 100644 index 0000000000..62346cb872 --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-mod/operation-mod.json @@ -0,0 +1,4 @@ +{ + "version": "1.0.0", + "extends": "cdmf.unit.device.operation-mod" +} \ No newline at end of file diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-mod/public/js/operation-mod.js b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-mod/public/js/operation-mod.js new file mode 100644 index 0000000000..602354c3c6 --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-mod/public/js/operation-mod.js @@ -0,0 +1,1207 @@ +/* + * 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. + */ + +var operationModule = function () { + var publicMethods = {}; + var privateMethods = {}; + + // Constants to define platform types available + var platformTypeConstants = { + "ANDROID": "android", + "IOS": "ios", + "WINDOWS": "windows" + }; + + // Constants to define operation types available + var operationTypeConstants = { + "PROFILE": "profile", + "CONFIG": "config", + "COMMAND": "command" + }; + + // Constants to define Android Operation Constants + var androidOperationConstants = { + "PASSCODE_POLICY_OPERATION_CODE": "PASSCODE_POLICY", + "CAMERA_OPERATION_CODE": "CAMERA", + "ENCRYPT_STORAGE_OPERATION_CODE": "ENCRYPT_STORAGE", + "WIFI_OPERATION_CODE": "WIFI", + "WIPE_OPERATION_CODE": "WIPE_DATA", + "NOTIFICATION_OPERATION_CODE": "NOTIFICATION", + "CHANGE_LOCK_CODE_OPERATION_CODE": "CHANGE_LOCK_CODE" + }; + + // Constants to define Windows Operation Constants + var windowsOperationConstants = { + "PASSCODE_POLICY_OPERATION_CODE": "PASSCODE_POLICY", + "CAMERA_OPERATION_CODE": "CAMERA", + "ENCRYPT_STORAGE_OPERATION_CODE": "ENCRYPT_STORAGE", + "NOTIFICATION_OPERATION_CODE": "NOTIFICATION", + "CHANGE_LOCK_CODE_OPERATION_CODE": "CHANGE_LOCK_CODE" + }; + + // Constants to define iOS Operation Constants + var iosOperationConstants = { + "PASSCODE_POLICY_OPERATION_CODE": "PASSCODE_POLICY", + "RESTRICTIONS_OPERATION_CODE": "RESTRICTION", + "WIFI_OPERATION_CODE": "WIFI", + "EMAIL_OPERATION_CODE": "EMAIL", + "AIRPLAY_OPERATION_CODE": "AIR_PLAY", + "LDAP_OPERATION_CODE": "LDAP", + "CALENDAR_OPERATION_CODE": "CALDAV", + "CALENDAR_SUBSCRIPTION_OPERATION_CODE": "CALENDAR_SUBSCRIPTION", + "APN_OPERATION_CODE": "APN", + "CELLULAR_OPERATION_CODE": "CELLULAR" + }; + + publicMethods.getIOSServiceEndpoint = function (operationCode) { + var featureMap = { + "DEVICE_LOCK": "lock", + "ALARM": "alarm", + "LOCATION": "location", + "AIR_PLAY": "airplay", + "RESTRICTION": "restriction", + "CELLULAR": "cellular", + "WIFI": "wifi", + "INSTALL_STORE_APPLICATION": "storeapplication", + "INSTALL_ENTERPRISE_APPLICATION": "enterpriseapplication", + "REMOVE_APPLICATION": "removeapplication", + "ENTERPRISE_WIPE": "enterprisewipe" + }; + return "/ios/operation/" + featureMap[operationCode]; + }; + + /** + * Convert the ios platform specific code to the generic payload. + * TODO: think of the possibility to follow a pattern to the key name (namespace?) + * @param operationCode + * @param operationPayload + * @returns {{}} + */ + privateMethods.generateGenericPayloadFromIOSPayload = function (operationCode, operationPayload) { + var payload = {}; + operationPayload = JSON.parse(operationPayload); + switch (operationCode) { + case iosOperationConstants["PASSCODE_POLICY_OPERATION_CODE"]: + payload = { + "passcodePolicyForcePIN": operationPayload["forcePIN"], + "passcodePolicyAllowSimple": operationPayload["allowSimple"], + "passcodePolicyRequireAlphanumeric": operationPayload["requireAlphanumeric"], + "passcodePolicyMinLength": operationPayload["minLength"], + "passcodePolicyMinComplexChars": operationPayload["minComplexChars"], + "passcodePolicyMaxPasscodeAgeInDays": operationPayload["maxPINAgeInDays"], + "passcodePolicyPasscodeHistory": operationPayload["pinHistory"], + "passcodePolicyMaxAutoLock": operationPayload["maxInactivity"], + "passcodePolicyGracePeriod": operationPayload["maxGracePeriod"], + "passcodePolicyMaxFailedAttempts": operationPayload["maxFailedAttempts"] + }; + break; + case iosOperationConstants["RESTRICTIONS_OPERATION_CODE"]: + payload = { + "restrictionsAllowAccountModification": operationPayload["allowAccountModification"], + "restrictionsAllowAddingGameCenterFriends": operationPayload["allowAddingGameCenterFriends"], + "restrictionsAllowAirDrop": operationPayload["allowAirDrop"], + "restrictionsAllowAppCellularDataModification": operationPayload["allowAppCellularDataModification"], + "restrictionsAllowAppInstallation": operationPayload["allowAppInstallation"], + "restrictionsAllowAppRemoval": operationPayload["allowAppRemoval"], + "restrictionsAllowAssistant": operationPayload["allowAssistant"], + "restrictionsAllowAssistantUserGeneratedContent": operationPayload["allowAssistantUserGeneratedContent"], + "restrictionsAllowAssistantWhileLocked": operationPayload["allowAssistantWhileLocked"], + "restrictionsAllowBookstore": operationPayload["allowBookstore"], + "restrictionsAllowBookstoreErotica": operationPayload["allowBookstoreErotica"], + "restrictionsAllowCamera": operationPayload["allowCamera"], + "restrictionsAllowChat": operationPayload["allowChat"], + "restrictionsAllowCloudBackup": operationPayload["allowCloudBackup"], + "restrictionsAllowCloudDocumentSync": operationPayload["allowCloudDocumentSync"], + "restrictionsAllowCloudKeychainSync": operationPayload["allowCloudKeychainSync"], + "restrictionsAllowDiagnosticSubmission": operationPayload["allowDiagnosticSubmission"], + "restrictionsAllowExplicitContent": operationPayload["allowExplicitContent"], + "restrictionsAllowFindMyFriendsModification": operationPayload["allowFindMyFriendsModification"], + "restrictionsAllowFingerprintForUnlock": operationPayload["allowFingerprintForUnlock"], + "restrictionsAllowGameCenter": operationPayload["allowGameCenter"], + "restrictionsAllowGlobalBackgroundFetchWhenRoaming": operationPayload["allowGlobalBackgroundFetchWhenRoaming"], + "restrictionsAllowInAppPurchases": operationPayload["allowInAppPurchases"], + "restrictionsAllowLockScreenControlCenter": operationPayload["allowLockScreenControlCenter"], + "restrictionsAllowHostPairing": operationPayload["allowHostPairing"], + "restrictionsAllowLockScreenNotificationsView": operationPayload["allowLockScreenNotificationsView"], + "restrictionsAllowLockScreenTodayView": operationPayload["allowLockScreenTodayView"], + "restrictionsAllowMultiplayerGaming": operationPayload["allowMultiplayerGaming"], + "restrictionsAllowOpenFromManagedToUnmanaged": operationPayload["allowOpenFromManagedToUnmanaged"], + "restrictionsAllowOpenFromUnmanagedToManaged": operationPayload["allowOpenFromUnmanagedToManaged"], + "restrictionsAllowOTAPKIUpdates": operationPayload["allowOTAPKIUpdates"], + "restrictionsAllowPassbookWhileLocked": operationPayload["allowPassbookWhileLocked"], + "restrictionsAllowPhotoStream": operationPayload["allowPhotoStream"], + "restrictionsAllowSafari": operationPayload["allowSafari"], + "restrictionsSafariAllowAutoFill": operationPayload["safariAllowAutoFill"], + "restrictionsSafariForceFraudWarning": operationPayload["safariForceFraudWarning"], + "restrictionsSafariAllowJavaScript": operationPayload["safariAllowJavaScript"], + "restrictionsSafariAllowPopups": operationPayload["safariAllowPopups"], + "restrictionsAllowScreenShot": operationPayload["allowScreenShot"], + "restrictionsAllowSharedStream": operationPayload["allowSharedStream"], + "restrictionsAllowUIConfigurationProfileInstallation": operationPayload["allowUIConfigurationProfileInstallation"], + "restrictionsAllowUntrustedTLSPrompt": operationPayload["allowUntrustedTLSPrompt"], + "restrictionsAllowVideoConferencing": operationPayload["allowVideoConferencing"], + "restrictionsAllowVoiceDialing": operationPayload["allowVoiceDialing"], + "restrictionsAllowYouTube": operationPayload["allowYouTube"], + "restrictionsAllowITunes": operationPayload["allowiTunes"], + "restrictionsForceAssistantProfanityFilter": operationPayload["forceAssistantProfanityFilter"], + "restrictionsForceEncryptedBackup": operationPayload["forceEncryptedBackup"], + "restrictionsForceITunesStorePasswordEntry": operationPayload["forceITunesStorePasswordEntry"], + "restrictionsForceLimitAdTracking": operationPayload["forceLimitAdTracking"], + "restrictionsForceAirPlayOutgoingRequestsPairingPassword": operationPayload["forceAirPlayOutgoingRequestsPairingPassword"], + "restrictionsForceAirPlayIncomingRequestsPairingPassword": operationPayload["forceAirPlayIncomingRequestsPairingPassword"], + "restrictionsAllowManagedAppsCloudSync": operationPayload["allowManagedAppsCloudSync"], + "restrictionsAllowEraseContentAndSettings": operationPayload["allowEraseContentAndSettings"], + "restrictionsAllowSpotlightInternetResults": operationPayload["allowSpotlightInternetResults"], + "restrictionsAllowEnablingRestrictions": operationPayload["allowEnablingRestrictions"], + "restrictionsAllowActivityContinuation": operationPayload["allowActivityContinuation"], + "restrictionsAllowEnterpriseBookBackup": operationPayload["allowEnterpriseBookBackup"], + "restrictionsAllowEnterpriseBookMetadataSync": operationPayload["allowEnterpriseBookMetadataSync"], + "restrictionsAllowPodcasts": operationPayload["allowPodcasts"], + "restrictionsAllowDefinitionLookup": operationPayload["allowDefinitionLookup"], + "restrictionsAllowPredictiveKeyboard": operationPayload["allowPredictiveKeyboard"], + "restrictionsAllowAutoCorrection": operationPayload["allowAutoCorrection"], + "restrictionsAllowSpellCheck": operationPayload["allowSpellCheck"], + "restrictionsSafariAcceptCookies": operationPayload["safariAcceptCookies"], + "restrictionsAutonomousSingleAppModePermittedAppIDs": operationPayload["autonomousSingleAppModePermittedAppIDs"] + }; + break; + case iosOperationConstants["WIFI_OPERATION_CODE"]: + payload = { + "wifiHiddenNetwork": operationPayload["hiddenNetwork"], + "wifiSSID": operationPayload["ssid"], + "wifiAutoJoin": operationPayload["autoJoin"], + "wifiProxyType": operationPayload["proxyType"], + "wifiEncryptionType": operationPayload["encryptionType"], + "wifiIsHotSpot": operationPayload["hotspot"], + "wifiDomainName": operationPayload["domainName"], + "wifiServiceProviderRoamingEnabled": operationPayload["serviceProviderRoamingEnabled"], + "wifiDisplayedOperatorName": operationPayload["displayedOperatorName"], + "wifiRoamingConsortiumOIs": operationPayload["roamingConsortiumOIs"], + "wifiPassword": operationPayload["password"], + "wifiPayloadCertUUID": operationPayload["payloadCertificateUUID"], + "wifiProxyServer": operationPayload["proxyServer"], + "wifiProxyPort": operationPayload["proxyPort"], + "wifiProxyUsername": operationPayload["proxyUsername"], + "wifiProxyPassword": operationPayload["proxyPassword"], + "wifiProxyPACURL": operationPayload["proxyPACURL"], + "wifiProxyPACFallbackAllowed": operationPayload["proxyPACFallbackAllowed"], + "wifiNAIRealmNames": operationPayload["nairealmNames"], + "wifiMCCAndMNCs": operationPayload["mccandMNCs"], + "wifiEAPUsername": operationPayload.clientConfiguration["username"], + "wifiAcceptedEAPTypes": operationPayload.clientConfiguration["acceptEAPTypes"], + "wifiEAPPassword": operationPayload.clientConfiguration["userPassword"], + "wifiEAPOneTimePassword": operationPayload.clientConfiguration["oneTimePassword"], + "wifiPayloadCertificateAnchorUUIDs": operationPayload.clientConfiguration["payloadCertificateAnchorUUID"], + "wifiEAPOuterIdentity": operationPayload.clientConfiguration["outerIdentity"], + "wifiTLSTrustedServerNames": operationPayload.clientConfiguration["tlstrustedServerNames"], + "wifiEAPTLSAllowTrustExceptions": operationPayload.clientConfiguration["tlsallowTrustExceptions"], + "wifiEAPTLSCertIsRequired": operationPayload.clientConfiguration["tlscertificateIsRequired"], + "wifiEAPTLSInnerAuthType": operationPayload.clientConfiguration["ttlsinnerAuthentication"], + "wifiEAPFastUsePAC": operationPayload.clientConfiguration["eapfastusePAC"], + "wifiEAPFastProvisionPAC": operationPayload.clientConfiguration["eapfastprovisionPAC"], + "wifiEAPFastProvisionPACAnonymously": operationPayload.clientConfiguration["eapfastprovisionPACAnonymously"], + "wifiEAPSIMNoOfRands": operationPayload.clientConfiguration["eapsimnumberOfRANDs"] + }; + break; + case iosOperationConstants["EMAIL_OPERATION_CODE"]: + payload = { + "emailAccountDescription": operationPayload["emailAccountDescription"], + "emailAccountName": operationPayload["emailAccountName"], + "emailAccountType": operationPayload["emailAccountType"], + "emailAddress": operationPayload["emailAddress"], + "emailIncomingMailServerAuthentication": operationPayload["incomingMailServerAuthentication"], + "emailIncomingMailServerHostname": operationPayload["incomingMailServerHostName"], + "emailIncomingMailServerPort": operationPayload["incomingMailServerPortNumber"], + "emailIncomingUseSSL": operationPayload["incomingMailServerUseSSL"], + "emailIncomingMailServerUsername": operationPayload["incomingMailServerUsername"], + "emailIncomingMailServerPassword": operationPayload["incomingPassword"], + "emailOutgoingMailServerPassword": operationPayload["outgoingPassword"], + "emailOutgoingPasswordSameAsIncomingPassword": operationPayload["outgoingPasswordSameAsIncomingPassword"], + "emailOutgoingMailServerAuthentication": operationPayload["outgoingMailServerAuthentication"], + "emailOutgoingMailServerHostname": operationPayload["outgoingMailServerHostName"], + "emailOutgoingMailServerPort": operationPayload["outgoingMailServerPortNumber"], + "emailOutgoingUseSSL": operationPayload["outgoingMailServerUseSSL"], + "emailOutgoingMailServerUsername": operationPayload["outgoingMailServerUsername"], + "emailPreventMove": operationPayload["preventMove"], + "emailPreventAppSheet": operationPayload["preventAppSheet"], + "emailDisableMailRecentSyncing": operationPayload["disableMailRecentSyncing"], + "emailIncomingMailServerIMAPPathPrefix": operationPayload["incomingMailServerIMAPPathPrefix"], + "emailSMIMEEnabled": operationPayload["smimeenabled"], + "emailSMIMESigningCertificateUUID": operationPayload["smimesigningCertificateUUID"], + "emailSMIMEEncryptionCertificateUUID": operationPayload["smimeencryptionCertificateUUID"], + "emailSMIMEEnablePerMessageSwitch": operationPayload["smimeenablePerMessageSwitch"] + }; + break; + case iosOperationConstants["AIRPLAY_OPERATION_CODE"]: + payload = { + "airplayDestinations": operationPayload["airPlayDestinations"], + "airplayCredentials": operationPayload["airPlayCredentials"] + }; + break; + case iosOperationConstants["LDAP_OPERATION_CODE"]: + payload = { + "ldapAccountDescription": operationPayload["accountDescription"], + "ldapAccountHostname": operationPayload["accountHostName"], + "ldapUseSSL": operationPayload["accountUseSSL"], + "ldapAccountUsername": operationPayload["accountUsername"], + "ldapAccountPassword": operationPayload["accountPassword"], + "ldapSearchSettings": operationPayload["ldapSearchSettings"] + }; + break; + case iosOperationConstants["CALENDAR_OPERATION_CODE"]: + payload = { + "calendarAccountDescription": operationPayload["accountDescription"], + "calendarAccountHostname": operationPayload["hostName"], + "calendarAccountUsername": operationPayload["username"], + "calendarAccountPassword": operationPayload["password"], + "calendarUseSSL": operationPayload["useSSL"], + "calendarAccountPort": operationPayload["port"], + "calendarPrincipalURL": operationPayload["principalURL"] + }; + break; + case iosOperationConstants["CALENDAR_SUBSCRIPTION_OPERATION_CODE"]: + payload = { + "calendarSubscriptionDescription": operationPayload["accountDescription"], + "calendarSubscriptionHostname": operationPayload["hostName"], + "calendarSubscriptionUsername": operationPayload["username"], + "calendarSubscriptionPassword": operationPayload["password"], + "calendarSubscriptionUseSSL": operationPayload["useSSL"] + }; + break; + case iosOperationConstants["APN_OPERATION_CODE"]: + payload = { + "apnConfigurations": operationPayload["apnConfigurations"] + }; + break; + case iosOperationConstants["CELLULAR_OPERATION_CODE"]: + payload = { + "cellularAttachAPNName": operationPayload["attachAPNName"], + "cellularAuthenticationType": operationPayload["authenticationType"], + "cellularUsername": operationPayload["username"], + "cellularPassword": operationPayload["password"], + "cellularAPNConfigurations": operationPayload["apnConfigurations"] + }; + break; + } + return payload; + }; + + privateMethods.generateIOSOperationPayload = function (operationCode, operationData, deviceList) { + var payload; + var operationType; + switch (operationCode) { + case iosOperationConstants["PASSCODE_POLICY_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "forcePIN": operationData["passcodePolicyForcePIN"], + "allowSimple": operationData["passcodePolicyAllowSimple"], + "requireAlphanumeric": operationData["passcodePolicyRequireAlphanumeric"], + "minLength": operationData["passcodePolicyMinLength"], + "minComplexChars": operationData["passcodePolicyMinComplexChars"], + "maxPINAgeInDays": operationData["passcodePolicyMaxPasscodeAgeInDays"], + "pinHistory": operationData["passcodePolicyPasscodeHistory"], + "maxInactivity": operationData["passcodePolicyMaxAutoLock"], + "maxGracePeriod": operationData["passcodePolicyGracePeriod"], + "maxFailedAttempts": operationData["passcodePolicyMaxFailedAttempts"] + } + }; + break; + case iosOperationConstants["WIFI_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "ssid": operationData["wifiSSID"], + "hiddenNetwork": operationData["wifiHiddenNetwork"], + "autoJoin": operationData["wifiAutoJoin"], + "proxyType": operationData["wifiProxyType"], + "encryptionType": operationData["wifiEncryptionType"], + "hotspot": operationData["wifiIsHotSpot"], + "domainName": operationData["wifiDomainName"], + "serviceProviderRoamingEnabled": operationData["wifiServiceProviderRoamingEnabled"], + "displayedOperatorName": operationData["wifiDisplayedOperatorName"], + "roamingConsortiumOIs": operationData["wifiRoamingConsortiumOIs"], + "password": operationData["wifiPassword"], + "clientConfiguration": { + "username": operationData["wifiEAPUsername"], + "acceptEAPTypes": operationData["wifiAcceptedEAPTypes"], + "userPassword": operationData["wifiEAPPassword"], + "oneTimePassword": operationData["wifiEAPOneTimePassword"], + "payloadCertificateAnchorUUID": operationData["wifiPayloadCertificateAnchorUUIDs"], + "outerIdentity": operationData["wifiEAPOuterIdentity"], + "tlstrustedServerNames": operationData["wifiTLSTrustedServerNames"], + "tlsallowTrustExceptions": operationData["wifiEAPTLSAllowTrustExceptions"], + "tlscertificateIsRequired": operationData["wifiEAPTLSCertIsRequired"], + "ttlsinnerAuthentication": operationData["wifiEAPTLSInnerAuthType"], + "eapfastusePAC": operationData["wifiEAPFastUsePAC"], + "eapfastprovisionPAC": operationData["wifiEAPFastProvisionPAC"], + "eapfastprovisionPACAnonymously": operationData["wifiEAPFastProvisionPACAnonymously"], + "eapsimnumberOfRANDs": operationData["wifiEAPSIMNoOfRands"] + }, + "payloadCertificateUUID": operationData["wifiPayloadCertUUID"], + "proxyServer": operationData["wifiProxyServer"], + "proxyPort": operationData["wifiProxyPort"], + "proxyUsername": operationData["wifiProxyUsername"], + "proxyPassword": operationData["wifiProxyPassword"], + "proxyPACURL": operationData["wifiProxyPACURL"], + "proxyPACFallbackAllowed": operationData["wifiProxyPACFallbackAllowed"], + "nairealmNames": operationData["wifiNAIRealmNames"], + "mccandMNCs": operationData["wifiMCCAndMNCs"] + } + }; + break; + case iosOperationConstants["RESTRICTIONS_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "allowAccountModification": operationData["restrictionsAllowAccountModification"], + "allowAddingGameCenterFriends": operationData["restrictionsAllowAddingGameCenterFriends"], + "allowAirDrop": operationData["restrictionsAllowAirDrop"], + "allowAppCellularDataModification": operationData["restrictionsAllowAppCellularDataModification"], + "allowAppInstallation": operationData["restrictionsAllowAppInstallation"], + "allowAppRemoval": operationData["restrictionsAllowAppRemoval"], + "allowAssistant": operationData["restrictionsAllowAssistant"], + "allowAssistantUserGeneratedContent": operationData["restrictionsAllowAssistantUserGeneratedContent"], + "allowAssistantWhileLocked": operationData["restrictionsAllowAssistantWhileLocked"], + "allowBookstore": operationData["restrictionsAllowBookstore"], + "allowBookstoreErotica": operationData["restrictionsAllowBookstoreErotica"], + "allowCamera": operationData["restrictionsAllowCamera"], + "allowChat": operationData["restrictionsAllowChat"], + "allowCloudBackup": operationData["restrictionsAllowCloudBackup"], + "allowCloudDocumentSync": operationData["restrictionsAllowCloudDocumentSync"], + "allowCloudKeychainSync": operationData["restrictionsAllowCloudKeychainSync"], + "allowDiagnosticSubmission": operationData["restrictionsAllowDiagnosticSubmission"], + "allowExplicitContent": operationData["restrictionsAllowExplicitContent"], + "allowFindMyFriendsModification": operationData["restrictionsAllowFindMyFriendsModification"], + "allowFingerprintForUnlock": operationData["restrictionsAllowFingerprintForUnlock"], + "allowGameCenter": operationData["restrictionsAllowGameCenter"], + "allowGlobalBackgroundFetchWhenRoaming": operationData["restrictionsAllowGlobalBackgroundFetchWhenRoaming"], + "allowInAppPurchases": operationData["restrictionsAllowInAppPurchases"], + "allowLockScreenControlCenter": operationData["restrictionsAllowLockScreenControlCenter"], + "allowHostPairing": operationData["restrictionsAllowHostPairing"], + "allowLockScreenNotificationsView": operationData["restrictionsAllowLockScreenNotificationsView"], + "allowLockScreenTodayView": operationData["restrictionsAllowLockScreenTodayView"], + "allowMultiplayerGaming": operationData["restrictionsAllowMultiplayerGaming"], + "allowOpenFromManagedToUnmanaged": operationData["restrictionsAllowOpenFromManagedToUnmanaged"], + "allowOpenFromUnmanagedToManaged": operationData["restrictionsAllowOpenFromUnmanagedToManaged"], + "allowOTAPKIUpdates": operationData["restrictionsAllowOTAPKIUpdates"], + "allowPassbookWhileLocked": operationData["restrictionsAllowPassbookWhileLocked"], + "allowPhotoStream": operationData["restrictionsAllowPhotoStream"], + "allowSafari": operationData["restrictionsAllowSafari"], + "safariAllowAutoFill": operationData["restrictionsSafariAllowAutoFill"], + "safariForceFraudWarning": operationData["restrictionsSafariForceFraudWarning"], + "safariAllowJavaScript": operationData["restrictionsSafariAllowJavaScript"], + "safariAllowPopups": operationData["restrictionsSafariAllowPopups"], + "allowScreenShot": operationData["restrictionsAllowScreenShot"], + "allowSharedStream": operationData["restrictionsAllowSharedStream"], + "allowUIConfigurationProfileInstallation": operationData["restrictionsAllowUIConfigurationProfileInstallation"], + "allowUntrustedTLSPrompt": operationData["restrictionsAllowUntrustedTLSPrompt"], + "allowVideoConferencing": operationData["restrictionsAllowVideoConferencing"], + "allowVoiceDialing": operationData["restrictionsAllowVoiceDialing"], + "allowYouTube": operationData["restrictionsAllowYouTube"], + "allowiTunes": operationData["restrictionsAllowITunes"], + "forceAssistantProfanityFilter": operationData["restrictionsForceAssistantProfanityFilter"], + "forceEncryptedBackup": operationData["restrictionsForceEncryptedBackup"], + "forceITunesStorePasswordEntry": operationData["restrictionsForceITunesStorePasswordEntry"], + "forceLimitAdTracking": operationData["restrictionsForceLimitAdTracking"], + "forceAirPlayOutgoingRequestsPairingPassword": operationData["restrictionsForceAirPlayOutgoingRequestsPairingPassword"], + "forceAirPlayIncomingRequestsPairingPassword": operationData["restrictionsForceAirPlayIncomingRequestsPairingPassword"], + "allowManagedAppsCloudSync": operationData["restrictionsAllowManagedAppsCloudSync"], + "allowEraseContentAndSettings": operationData["restrictionsAllowEraseContentAndSettings"], + "allowSpotlightInternetResults": operationData["restrictionsAllowSpotlightInternetResults"], + "allowEnablingRestrictions": operationData["restrictionsAllowEnablingRestrictions"], + "allowActivityContinuation": operationData["restrictionsAllowActivityContinuation"], + "allowEnterpriseBookBackup": operationData["restrictionsAllowEnterpriseBookBackup"], + "allowEnterpriseBookMetadataSync": operationData["restrictionsAllowEnterpriseBookMetadataSync"], + "allowPodcasts": operationData["restrictionsAllowPodcasts"], + "allowDefinitionLookup": operationData["restrictionsAllowDefinitionLookup"], + "allowPredictiveKeyboard": operationData["restrictionsAllowPredictiveKeyboard"], + "allowAutoCorrection": operationData["restrictionsAllowAutoCorrection"], + "allowSpellCheck": operationData["restrictionsAllowSpellCheck"], + "safariAcceptCookies": operationData["restrictionsSafariAcceptCookies"], + "autonomousSingleAppModePermittedAppIDs": operationData["restrictionsAutonomousSingleAppModePermittedAppIDs"] + } + }; + break; + case iosOperationConstants["EMAIL_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "emailAccountDescription": operationData["emailAccountDescription"], + "emailAccountName": operationData["emailAccountName"], + "emailAccountType": operationData["emailAccountType"], + "emailAddress": operationData["emailAddress"], + "incomingMailServerAuthentication": operationData["emailIncomingMailServerAuthentication"], + "incomingMailServerHostName": operationData["emailIncomingMailServerHostname"], + "incomingMailServerPortNumber": operationData["emailIncomingMailServerPort"], + "incomingMailServerUseSSL": operationData["emailIncomingUseSSL"], + "incomingMailServerUsername": operationData["emailIncomingMailServerUsername"], + "incomingPassword": operationData["emailIncomingMailServerPassword"], + "outgoingPassword": operationData["emailOutgoingMailServerPassword"], + "outgoingPasswordSameAsIncomingPassword": operationData["emailOutgoingPasswordSameAsIncomingPassword"], + "outgoingMailServerAuthentication": operationData["emailOutgoingMailServerAuthentication"], + "outgoingMailServerHostName": operationData["emailOutgoingMailServerHostname"], + "outgoingMailServerPortNumber": operationData["emailOutgoingMailServerPort"], + "outgoingMailServerUseSSL": operationData["emailOutgoingUseSSL"], + "outgoingMailServerUsername": operationData["emailOutgoingMailServerUsername"], + "preventMove": operationData["emailPreventMove"], + "preventAppSheet": operationData["emailPreventAppSheet"], + "disableMailRecentSyncing": operationData["emailDisableMailRecentSyncing"], + "incomingMailServerIMAPPathPrefix": operationData["emailIncomingMailServerIMAPPathPrefix"], + "smimeenabled": operationData["emailSMIMEEnabled"], + "smimesigningCertificateUUID": operationData["emailSMIMESigningCertificateUUID"], + "smimeencryptionCertificateUUID": operationData["emailSMIMEEncryptionCertificateUUID"], + "smimeenablePerMessageSwitch": operationData["emailSMIMEEnablePerMessageSwitch"] + } + }; + break; + case iosOperationConstants["AIRPLAY_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "airPlayDestinations": operationData["airplayDestinations"], + "airPlayCredentials": operationData["airplayCredentials"] + } + }; + break; + case iosOperationConstants["LDAP_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "accountDescription": operationData["ldapAccountDescription"], + "accountHostName": operationData["ldapAccountHostname"], + "accountUseSSL": operationData["ldapUseSSL"], + "accountUsername": operationData["ldapAccountUsername"], + "accountPassword": operationData["ldapAccountPassword"], + "ldapSearchSettings": operationData["ldapSearchSettings"] + } + }; + break; + case iosOperationConstants["CALENDAR_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "accountDescription": operationData["calendarAccountDescription"], + "hostName": operationData["calendarAccountHostname"], + "username": operationData["calendarAccountUsername"], + "password": operationData["calendarAccountPassword"], + "useSSL": operationData["calendarUseSSL"], + "port": operationData["calendarAccountPort"], + "principalURL": operationData["calendarPrincipalURL"] + } + }; + break; + case iosOperationConstants["CALENDAR_SUBSCRIPTION_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "accountDescription": operationData["calendarSubscriptionDescription"], + "hostName": operationData["calendarSubscriptionHostname"], + "username": operationData["calendarSubscriptionUsername"], + "password": operationData["calendarSubscriptionPassword"], + "useSSL": operationData["calendarSubscriptionUseSSL"] + } + }; + break; + case iosOperationConstants["APN_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "apnConfigurations": operationData["apnConfigurations"] + } + }; + break; + case iosOperationConstants["CELLULAR_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "attachAPNName": operationData["cellularAttachAPNName"], + "authenticationType": operationData["cellularAuthenticationType"], + "username": operationData["cellularUsername"], + "password": operationData["cellularPassword"], + "apnConfigurations": operationData["cellularAPNConfigurations"] + } + }; + break; + default: + // If the operation is neither of above, it is a command operation + operationType = operationTypeConstants["COMMAND"]; + // Operation payload of a command operation is simply an array of device IDs + payload = deviceList; + } + + if (operationType == operationTypeConstants["PROFILE"] && deviceList) { + payload["deviceIDs"] = deviceList; + } + return payload; + }; + + /** + * Convert the android platform specific code to the generic payload. + * TODO: think of the possibility to follow a pattern to the key name (namespace?) + * @param operationCode + * @param operationPayload + * @returns {{}} + */ + privateMethods.generateGenericPayloadFromAndroidPayload = function (operationCode, operationPayload) { + var payload = {}; + operationPayload = JSON.parse(operationPayload); + switch (operationCode) { + case androidOperationConstants["PASSCODE_POLICY_OPERATION_CODE"]: + payload = { + "passcodePolicyAllowSimple": operationPayload["allowSimple"], + "passcodePolicyRequireAlphanumeric": operationPayload["requireAlphanumeric"], + "passcodePolicyMinLength": operationPayload["minLength"], + "passcodePolicyMinComplexChars": operationPayload["minComplexChars"], + "passcodePolicyMaxPasscodeAgeInDays": operationPayload["maxPINAgeInDays"], + "passcodePolicyPasscodeHistory": operationPayload["pinHistory"], + "passcodePolicyMaxFailedAttempts": operationPayload["maxFailedAttempts"] + }; + break; + case androidOperationConstants["CAMERA_OPERATION_CODE"]: + payload = { + "cameraEnabled": operationPayload["enabled"] + }; + break; + case androidOperationConstants["ENCRYPT_STORAGE_OPERATION_CODE"]: + payload = { + "encryptStorageEnabled": operationPayload["encrypted"] + }; + break; + case androidOperationConstants["WIFI_OPERATION_CODE"]: + payload = { + "wifiSSID": operationPayload["ssid"], + "wifiPassword": operationPayload["password"] + }; + break; + } + return payload; + }; + + privateMethods.generateAndroidOperationPayload = function (operationCode, operationData, deviceList) { + var payload; + var operationType; + switch (operationCode) { + case androidOperationConstants["CAMERA_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "enabled" : operationData["cameraEnabled"] + } + }; + break; + case androidOperationConstants["CHANGE_LOCK_CODE_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "lockCode" : operationData["lockCode"] + } + }; + break; + case androidOperationConstants["ENCRYPT_STORAGE_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "encrypted" : operationData["encryptStorageEnabled"] + } + }; + break; + case androidOperationConstants["NOTIFICATION_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "message" : operationData["message"] + } + }; + break; + case androidOperationConstants["WIPE_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "pin" : operationData["pin"] + } + }; + break; + case androidOperationConstants["WIFI_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "ssid": operationData["wifiSSID"], + "password": operationData["wifiPassword"] + } + }; + break; + case androidOperationConstants["PASSCODE_POLICY_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "allowSimple": operationData["passcodePolicyAllowSimple"], + "requireAlphanumeric": operationData["passcodePolicyRequireAlphanumeric"], + "minLength": operationData["passcodePolicyMinLength"], + "minComplexChars": operationData["passcodePolicyMinComplexChars"], + "maxPINAgeInDays": operationData["passcodePolicyMaxPasscodeAgeInDays"], + "pinHistory": operationData["passcodePolicyPasscodeHistory"], + "maxFailedAttempts": operationData["passcodePolicyMaxFailedAttempts"] + } + }; + break; + default: + // If the operation is neither of above, it is a command operation + operationType = operationTypeConstants["COMMAND"]; + // Operation payload of a command operation is simply an array of device IDs + payload = deviceList; + } + + if (operationType == operationTypeConstants["PROFILE"] && deviceList) { + payload["deviceIDs"] = deviceList; + } + + return payload; + }; + + publicMethods.getAndroidServiceEndpoint = function (operationCode) { + var featureMap = { + "WIFI": "wifi", + "CAMERA": "camera", + "DEVICE_LOCK": "lock", + "DEVICE_LOCATION": "location", + "CLEAR_PASSWORD": "clear-password", + "APPLICATION_LIST": "get-application-list", + "DEVICE_RING": "ring-device", + "DEVICE_MUTE": "mute", + "NOTIFICATION": "notification", + "ENCRYPT_STORAGE": "encrypt", + "CHANGE_LOCK_CODE": "change-lock-code", + "WEBCLIP": "webclip", + "INSTALL_APPLICATION": "install-application", + "UNINSTALL_APPLICATION": "uninstall-application", + "BLACKLIST_APPLICATIONS": "blacklist-applications", + "PASSCODE_POLICY": "password-policy", + "ENTERPRISE_WIPE": "enterprise-wipe", + "WIPE_DATA": "wipe-data" + }; + return "/mdm-android-agent/operation/" + featureMap[operationCode]; + }; + + /** + * Convert the windows platform specific code to the generic payload. + * TODO: think of the possibility to follow a pattern to the key name (namespace?) + * @param operationCode + * @param operationPayload + * @returns {{}} + */ + privateMethods.generateGenericPayloadFromWindowsPayload = function (operationCode, operationPayload) { + var payload = {}; + operationPayload = JSON.parse(operationPayload); + switch (operationCode) { + case windowsOperationConstants["PASSCODE_POLICY_OPERATION_CODE"]: + payload = { + "passcodePolicyAllowSimple": operationPayload["allowSimple"], + "passcodePolicyRequireAlphanumeric": operationPayload["requireAlphanumeric"], + "passcodePolicyMinLength": operationPayload["minLength"], + "passcodePolicyMinComplexChars": operationPayload["minComplexChars"], + "passcodePolicyMaxPasscodeAgeInDays": operationPayload["maxPINAgeInDays"], + "passcodePolicyPasscodeHistory": operationPayload["pinHistory"], + "passcodePolicyMaxFailedAttempts": operationPayload["maxFailedAttempts"] + }; + break; + case windowsOperationConstants["CAMERA_OPERATION_CODE"]: + payload = { + "cameraEnabled": operationPayload["enabled"] + }; + break; + case windowsOperationConstants["ENCRYPT_STORAGE_OPERATION_CODE"]: + payload = { + "encryptStorageEnabled": operationPayload["encrypted"] + }; + break; + } + return payload; + }; + + privateMethods.generateWindowsOperationPayload = function (operationCode, operationData, deviceList) { + var payload; + var operationType; + switch (operationCode) { + case windowsOperationConstants["CAMERA_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "enabled" : operationData["cameraEnabled"] + } + }; + break; + case windowsOperationConstants["CHANGE_LOCK_CODE_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "lockCode" : operationData["lockCode"] + } + }; + break; + case windowsOperationConstants["ENCRYPT_STORAGE_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "encrypted" : operationData["encryptStorageEnabled"] + } + }; + break; + case windowsOperationConstants["NOTIFICATION_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "message" : operationData["message"] + } + }; + break; + case windowsOperationConstants["PASSCODE_POLICY_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "allowSimple": operationData["passcodePolicyAllowSimple"], + "requireAlphanumeric": operationData["passcodePolicyRequireAlphanumeric"], + "minLength": operationData["passcodePolicyMinLength"], + "minComplexChars": operationData["passcodePolicyMinComplexChars"], + "maxPINAgeInDays": operationData["passcodePolicyMaxPasscodeAgeInDays"], + "pinHistory": operationData["passcodePolicyPasscodeHistory"], + "maxFailedAttempts": operationData["passcodePolicyMaxFailedAttempts"] + } + }; + break; + default: + // If the operation is neither of above, it is a command operation + operationType = operationTypeConstants["COMMAND"]; + // Operation payload of a command operation is simply an array of device IDs + payload = deviceList; + } + + if (operationType == operationTypeConstants["PROFILE"] && deviceList) { + payload["deviceIDs"] = deviceList; + } + + return payload; + }; + + + publicMethods.getWindowsServiceEndpoint = function (operationCode) { + var featureMap = { + "CAMERA": "camera", + "DEVICE_LOCK": "devicelock", + "DEVICE_LOCATION": "location", + "CLEAR_PASSWORD": "clear-password", + "APPLICATION_LIST": "get-application-list", + "DEVICE_RING": "devicering", + "DEVICE_MUTE": "mute", + "LOCK_RESET": "lockreset", + "NOTIFICATION": "notification", + "ENCRYPT_STORAGE": "encrypt", + "CHANGE_LOCK_CODE": "change-lock-code", + "WEBCLIP": "webclip", + "INSTALL_APPLICATION": "install-application", + "UNINSTALL_APPLICATION": "uninstall-application", + "BLACKLIST_APPLICATIONS": "blacklist-applications", + "PASSCODE_POLICY": "password-policy", + "ENTERPRISE_WIPE": "enterprise-wipe", + "WIPE_DATA": "devicewipe", + "DISENROLL": "devicedisenroll" + }; + return "/mdm-windows-agent/services/windows/operation/" + featureMap[operationCode]; + }; + /** + * Get the icon for the featureCode + * @param operationCode + * @returns icon class + */ + publicMethods.getAndroidIconForFeature = function (operationCode) { + var featureMap = { + "DEVICE_LOCK": "fw-lock", + "DEVICE_LOCATION": "fw-map-location", + "CLEAR_PASSWORD": "fw-key", + "ENTERPRISE_WIPE": "fw-clear", + "WIPE_DATA": "fw-database", + "DEVICE_RING": "fw-dial-up", + "DEVICE_MUTE": "fw-incoming-call", + "NOTIFICATION": "fw-message", + "CHANGE_LOCK_CODE": "fw-security" + }; + return featureMap[operationCode]; + }; + + /** + * Get the icon for the featureCode + * @param operationCode + * @returns icon class + */ + publicMethods.getWindowsIconForFeature = function (operationCode) { + var featureMap = { + "DEVICE_LOCK": "fw-lock", + "DEVICE_LOCATION": "fw-map-location", + "DISENROLL": "fw-delete", + "WIPE_DATA": "fw-clear", + "DEVICE_RING": "fw-dial-up", + "DEVICE_MUTE": "fw-incoming-call", + "NOTIFICATION": "fw-message", + "LOCK_RESET": "fw-key" + }; + return featureMap[operationCode]; + }; + + /** + * Get the icon for the featureCode + * @param operationCode + * @returns icon class + */ + publicMethods.getIOSIconForFeature = function (operationCode) { + var featureMap = { + "DEVICE_LOCK": "fw-lock", + "LOCATION": "fw-map-location", + "ENTERPRISE_WIPE": "fw-clear", + "ALARM": "fw-dial-up" + }; + return featureMap[operationCode]; + }; + + /** + * Filter a list by a data attribute. + * @param prop + * @param val + * @returns {Array} + */ + $.fn.filterByData = function (prop, val) { + return this.filter( + function () {return $(this).data(prop) == val;} + ); + }; + + /** + * Method to generate Platform specific operation payload. + * + * @param platformType Platform Type of the profile + * @param operationCode Operation Codes to generate the profile from + * @param deviceList Optional device list to include in payload body for operations + * @returns {*} + */ + publicMethods.generatePayload = function (platformType, operationCode, deviceList) { + var payload; + var operationData = {}; + // capturing form input data designated by .operationDataKeys + $(".operation-data").filterByData("operation-code", operationCode).find(".operationDataKeys").each( + function () { + var operationDataObj = $(this); + var key = operationDataObj.data("key"); + var value; + if (operationDataObj.is(":text") || operationDataObj.is("textarea") || + operationDataObj.is(":password")) { + value = operationDataObj.val(); + } else if (operationDataObj.is(":checkbox")) { + value = operationDataObj.is(":checked"); + } else if (operationDataObj.is("select")) { + value = operationDataObj.find("option:selected").attr("value"); + } else if (operationDataObj.hasClass("grouped-array-input")) { + value = []; + var childInput; + var childInputValue; + if (operationDataObj.hasClass("one-column-input-array")) { + $(".child-input", this).each(function () { + childInput = $(this); + if (childInput.is(":text") || childInput.is("textarea") || childInput.is(":password")) { + childInputValue = childInput.val(); + } else if (childInput.is(":checkbox")) { + childInputValue = childInput.is(":checked"); + } else if (childInput.is("select")) { + childInputValue = childInput.find("option:selected").attr("value"); + } + // push to value + value.push(childInputValue); + }); + } else if (operationDataObj.hasClass("valued-check-box-array")) { + $(".child-input", this).each(function () { + childInput = $(this); + if (childInput.is(":checked")) { + // get associated value with check-box + childInputValue = childInput.data("value"); + // push to value + value.push(childInputValue); + } + }); + } else if (operationDataObj.hasClass("multi-column-joined-input-array")) { + var columnCount = operationDataObj.data("column-count"); + var inputCount = 0; + var joinedInput; + $(".child-input", this).each(function () { + childInput = $(this); + if (childInput.is(":text") || childInput.is("textarea") || childInput.is(":password")) { + childInputValue = childInput.val(); + } else if (childInput.is(":checkbox")) { + childInputValue = childInput.is(":checked"); + } else if (childInput.is("select")) { + childInputValue = childInput.find("option:selected").attr("value"); + } + inputCount++; + if (inputCount % columnCount == 1) { + // initialize joinedInput value + joinedInput = ""; + // append childInputValue to joinedInput + joinedInput += childInputValue; + } else if ((inputCount % columnCount) >= 2) { + // append childInputValue to joinedInput + joinedInput += childInputValue; + } else { + // append childInputValue to joinedInput + joinedInput += childInputValue; + // push to value + value.push(joinedInput); + } + }); + } else if (operationDataObj.hasClass("multi-column-key-value-pair-array")) { + columnCount = operationDataObj.data("column-count"); + inputCount = 0; + var childInputKey; + var keyValuePairJson; + $(".child-input", this).each(function () { + childInput = $(this); + childInputKey = childInput.data("child-key"); + if (childInput.is(":text") || childInput.is("textarea") || childInput.is(":password")) { + childInputValue = childInput.val(); + } else if (childInput.is(":checkbox")) { + childInputValue = childInput.is(":checked"); + } else if (childInput.is("select")) { + childInputValue = childInput.find("option:selected").attr("value"); + } + inputCount++; + if ((inputCount % columnCount) == 1) { + // initialize keyValuePairJson value + keyValuePairJson = {}; + // set key-value-pair + keyValuePairJson[childInputKey] = childInputValue; + } else if ((inputCount % columnCount) >= 2) { + // set key-value-pair + keyValuePairJson[childInputKey] = childInputValue; + } else { + // set key-value-pair + keyValuePairJson[childInputKey] = childInputValue; + // push to value + value.push(keyValuePairJson); + } + }); + } + } + operationData[key] = value; + } + ); + switch (platformType) { + case platformTypeConstants["ANDROID"]: + payload = privateMethods.generateAndroidOperationPayload(operationCode, operationData, deviceList); + break; + case platformTypeConstants["IOS"]: + payload = privateMethods.generateIOSOperationPayload(operationCode, operationData, deviceList); + break; + case platformTypeConstants["WINDOWS"]: + payload = privateMethods.generateWindowsOperationPayload(operationCode, operationData, deviceList); + break; + } + return payload; + }; + + /** + * Method to populate the Platform specific operation payload. + * + * @param platformType Platform Type of the profile + * @param operationCode Operation Codes to generate the profile from + * @param operationPayload payload + * @returns {*} + */ + publicMethods.populateUI = function (platformType, operationCode, operationPayload) { + var uiPayload; + switch (platformType) { + case platformTypeConstants["ANDROID"]: + uiPayload = privateMethods.generateGenericPayloadFromAndroidPayload(operationCode, operationPayload); + break; + case platformTypeConstants["IOS"]: + uiPayload = privateMethods.generateGenericPayloadFromIOSPayload(operationCode, operationPayload); + break; + case platformTypeConstants["WINDOWS"]: + uiPayload = privateMethods.generateGenericPayloadFromWindowsPayload(operationCode, operationPayload); + break; + } + // capturing form input data designated by .operationDataKeys + $(".operation-data").filterByData("operation-code", operationCode).find(".operationDataKeys").each( + function () { + var operationDataObj = $(this); + //TODO :remove + //operationDataObj.prop('disabled', true) + var key = operationDataObj.data("key"); + // retrieve corresponding input value associated with the key + var value = uiPayload[key]; + // populating input value according to the type of input + if (operationDataObj.is(":text") || + operationDataObj.is("textarea") || + operationDataObj.is(":password")) { + operationDataObj.val(value); + } else if (operationDataObj.is(":checkbox")) { + operationDataObj.prop("checked", value); + } else if (operationDataObj.is("select")) { + operationDataObj.val(value); + /* trigger a change of value, so that if slidable panes exist, + make them slide-down or slide-up accordingly */ + operationDataObj.trigger("change"); + } else if (operationDataObj.hasClass("grouped-array-input")) { + // then value is complex + var i, childInput; + var childInputIndex = 0; + // var childInputValue; + if (operationDataObj.hasClass("one-column-input-array")) { + // generating input fields to populate complex value + for (i = 0; i < value.length; ++i) { + operationDataObj.parent().find("a").filterByData("click-event", "add-form").click(); + } + // traversing through each child input + $(".child-input", this).each(function () { + childInput = $(this); + var childInputValue = value[childInputIndex]; + // populating extracted value in the UI according to the input type + if (childInput.is(":text") || + childInput.is("textarea") || + childInput.is(":password") || + childInput.is("select")) { + childInput.val(childInputValue); + } else if (childInput.is(":checkbox")) { + operationDataObj.prop("checked", childInputValue); + } + // incrementing childInputIndex + childInputIndex++; + }); + } else if (operationDataObj.hasClass("valued-check-box-array")) { + // traversing through each child input + $(".child-input", this).each(function () { + childInput = $(this); + // check if corresponding value of current checkbox exists in the array of values + if (value.indexOf(childInput.data("value")) != -1) { + // if YES, set checkbox as checked + childInput.prop("checked", true); + } + }); + } else if (operationDataObj.hasClass("multi-column-joined-input-array")) { + // generating input fields to populate complex value + for (i = 0; i < value.length; ++i) { + operationDataObj.parent().find("a").filterByData("click-event", "add-form").click(); + } + var columnCount = operationDataObj.data("column-count"); + var multiColumnJoinedInputArrayIndex = 0; + // handling scenarios specifically + if (operationDataObj.attr("id") == "wifi-mcc-and-mncs") { + // traversing through each child input + $(".child-input", this).each(function () { + childInput = $(this); + var multiColumnJoinedInput = value[multiColumnJoinedInputArrayIndex]; + var childInputValue; + if ((childInputIndex % columnCount) == 0) { + childInputValue = multiColumnJoinedInput.substring(3, 0) + } else { + childInputValue = multiColumnJoinedInput.substring(3); + // incrementing childInputIndex + multiColumnJoinedInputArrayIndex++; + } + // populating extracted value in the UI according to the input type + if (childInput.is(":text") || + childInput.is("textarea") || + childInput.is(":password") || + childInput.is("select")) { + childInput.val(childInputValue); + } else if (childInput.is(":checkbox")) { + operationDataObj.prop("checked", childInputValue); + } + // incrementing childInputIndex + childInputIndex++; + }); + } + } else if (operationDataObj.hasClass("multi-column-key-value-pair-array")) { + // generating input fields to populate complex value + for (i = 0; i < value.length; ++i) { + operationDataObj.parent().find("a").filterByData("click-event", "add-form").click(); + } + columnCount = operationDataObj.data("column-count"); + var multiColumnKeyValuePairArrayIndex = 0; + // traversing through each child input + $(".child-input", this).each(function () { + childInput = $(this); + var multiColumnKeyValuePair = value[multiColumnKeyValuePairArrayIndex]; + var childInputKey = childInput.data("child-key"); + var childInputValue = multiColumnKeyValuePair[childInputKey]; + // populating extracted value in the UI according to the input type + if (childInput.is(":text") || + childInput.is("textarea") || + childInput.is(":password") || + childInput.is("select")) { + childInput.val(childInputValue); + } else if (childInput.is(":checkbox")) { + operationDataObj.prop("checked", childInputValue); + } + // incrementing multiColumnKeyValuePairArrayIndex for the next row of inputs + if ((childInputIndex % columnCount) == (columnCount - 1)) { + multiColumnKeyValuePairArrayIndex++; + } + // incrementing childInputIndex + childInputIndex++; + }); + } + } + } + ); + }; + + /** + * generateProfile method is only used for policy-creation UIs. + * + * @param platformType Platform Type of the profile + * @param operationCodes Operation codes to generate the profile from + * @returns {{}} + */ + publicMethods.generateProfile = function (platformType, operationCodes) { + var generatedProfile = {}; + for (var i = 0; i < operationCodes.length; ++i) { + var operationCode = operationCodes[i]; + var payload = publicMethods.generatePayload(platformType, operationCode, null); + generatedProfile[operationCode] = payload["operation"]; + } + return generatedProfile; + }; + + /** + * populateProfile method is used to populate the html ui with saved payload. + * + * @param platformType Platform Type of the profile + * @param payload List of profileFeatures + * @returns [] configuredOperations array + */ + publicMethods.populateProfile = function (platformType, payload) { + var i, configuredOperations = []; + for (i = 0; i < payload.length; ++i) { + var configuredFeature = payload[i]; + var featureCode = configuredFeature["featureCode"]; + var operationPayload = configuredFeature["content"]; + //push the feature-code to the configuration array + configuredOperations.push(featureCode); + publicMethods.populateUI(platformType, featureCode, operationPayload); + } + return configuredOperations; + }; + + return publicMethods; +}(); diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.platform.configuration/configuration.hbs b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.platform.configuration/configuration.hbs new file mode 100644 index 0000000000..18f621a58d --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.platform.configuration/configuration.hbs @@ -0,0 +1,493 @@ +
+
+ +
+
+

+ Platform Configurations +

+
+ General and Platform Specific Server Settings for the Tenant +
+
+
+
+ + +
+ +
+
+ +
+ +
+ + +
+
+ +
+
+ + +
+
+ + + +
+
+
+ + +
+ + +
+ +
+
+ + +
+
+ +
+
+ + +
+ +
+ + +
+
+
+ + +
+
+ +
+
+ +
+
+
+
+ + + +
+
+ + +
+ + +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+ + + +
+ +
+ + +
+
+ + + +
+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+ + + +
+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+
+ + +
+
+ +
+
+ +
+
+
+
+ + + +
+
+
+ + +
+
+ + +
+
+
+ + +
+
+ +
+
+ +
+
+
+
+ +
+
+
+
+ + + +
+
+{{#zone "bottomJs"}} + {{js "js/platform-configuration.js"}} +{{/zone}} diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.platform.configuration/configuration.json b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.platform.configuration/configuration.json new file mode 100644 index 0000000000..be0496bf61 --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.platform.configuration/configuration.json @@ -0,0 +1,4 @@ +{ + "version" : "1.0.0", + "extends": "cdmf.unit.platform.configuration" +} \ No newline at end of file diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.platform.configuration/public/js/platform-configuration.js b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.platform.configuration/public/js/platform-configuration.js new file mode 100644 index 0000000000..184423b97d --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.platform.configuration/public/js/platform-configuration.js @@ -0,0 +1,856 @@ +/* + * 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 inputIsValid(regExp, inputString) { + return regExp.test(inputString); +} + +/** + * 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 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" +}; + +$(document).ready(function () { + $("#gcm-inputs").hide(); + tinymce.init({ + selector: "textarea", + theme: "modern", + plugins: [ + "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. + */ + 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(); + }else{ + $("#gcm-inputs").show(); + } + } else if(config.name == configParams["NOTIFIER_FREQUENCY"]){ + $("input#android-config-notifier-frequency").val(config.value); + } 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 () { + + } + ); + + invokerUtil.get( + getGeneralConfigAPI, + + 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#monitoring-config-frequency").val(config.value); + } + /*if(config.name == configParams["GENERAL_EMAIL_HOST"]){ + $("input#email-config-host").val(config.value); + } else if(config.name == configParams["GENERAL_EMAIL_PORT"]){ + $("input#email-config-port").val(config.value); + } else if(config.name == configParams["GENERAL_EMAIL_USERNAME"]){ + $("input#email-config-username").val(config.value); + } else if(config.name == configParams["GENERAL_EMAIL_PASSWORD"]){ + $("input#email-config-password").val(config.value); + } else if(config.name == configParams["GENERAL_EMAIL_SENDER_ADDRESS"]){ + $("input#email-config-sender-email").val(config.value); + } else if(config.name == configParams["GENERAL_EMAIL_TEMPLATE"]){ + $("input#email-config-template").val(config.value); + }*/ + } + } + + }, function () { + + } + ); + + 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); + } else if(config.name == configParams["APNS_CERT_NAME"]){ + $("#apns-cert-file-name").html(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 () { + + } + ); + + 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); + } else if(config.name == configParams["WINDOWS_EULA"]) { + $("#windows-eula").val(config.value); + } + } + } + + }, function () { + + } + ); + + + $("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 (!notifierFrequency) { + $(errorMsg).text("Notifier frequency is a required field. It cannot be empty."); + $(errorMsgWrapper).removeClass("hidden"); + } else if (!$.isNumeric(notifierFrequency)) { + $(errorMsg).text("Provided notifier frequency is invalid. Please check."); + $(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": notifierFrequency, + "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."); + } else if (data == 403) { + $(errorMsg).text("Action was not permitted."); + } else { + $(errorMsg).text("An unexpected error occurred."); + } + + $(errorMsgWrapper).removeClass("hidden"); + }, function () { + $(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 emailHost = $("input#email-config-host").val(); + var emailPort = $("input#email-config-port").val(); + var emailUsername = $("input#email-config-username").val(); + var emailPassword = $("input#email-config-password").val(); + var emailSenderAddress = $("input#email-config-sender-email").val(); + var emailTemplate = $("input#email-config-template").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 (!$.isNumeric(notifierFrequency)) { + $(errorMsg).text("Provided monitoring frequency is invalid. It must be a number."); + $(errorMsgWrapper).removeClass("hidden"); + } else { + + var addConfigFormData = {}; + var configList = new Array(); + + var monitorFrequency = { + "name": configParams["NOTIFIER_FREQUENCY"], + "value": notifierFrequency, + "contentType": "text" + }; + + /*if (!emailHost) { + $(errorMsg).text("Email Host is a required field. It cannot be empty."); + //$(errorMsgWrapper).removeClass("hidden"); + } else if (!notifierFrequency) { + $(errorMsg).text("Monitoring frequency is a required field. It cannot be empty."); + $(errorMsgWrapper).removeClass("hidden"); + } else if (!$.isNumeric(notifierFrequency)) { + $(errorMsg).text("Provided monitoring frequency is invalid. It must be a number."); + $(errorMsgWrapper).removeClass("hidden"); + }else if (!emailPort) { + $(errorMsg).text("Email Port is a required field. It cannot be empty."); + //$(errorMsgWrapper).removeClass("hidden"); + } else if (!emailUsername) { + $(errorMsg).text("Username is a required field. It cannot be empty."); + //$(errorMsgWrapper).removeClass("hidden"); + } else if (!emailPassword) { + $(errorMsg).text("Password is a required field. It cannot be empty."); + //$(errorMsgWrapper).removeClass("hidden"); + } else if (!emailSenderAddress) { + $(errorMsg).text("Sender Email Address is a required field. It cannot be empty."); + //$(errorMsgWrapper).removeClass("hidden"); + } else if (!emailIsValid(emailSenderAddress)) { + $(errorMsg).text("Provided sender email is invalid. Please check."); + //$(errorMsgWrapper).removeClass("hidden"); + } */ + + /*var host = { + "name": configParams["GENERAL_EMAIL_HOST"], + "value": emailHost, + "contentType": "text" + }; + + var port = { + "name": configParams["GENERAL_EMAIL_PORT"], + "value": emailPort, + "contentType": "text" + }; + + var username = { + "name": configParams["GENERAL_EMAIL_USERNAME"], + "value": emailUsername, + "contentType": "text" + }; + + var password = { + "name": configParams["GENERAL_EMAIL_PASSWORD"], + "value": emailPassword, + "contentType": "text" + }; + + var sender = { + "name": configParams["GENERAL_EMAIL_SENDER_ADDRESS"], + "value": emailSenderAddress, + "contentType": "text" + }; + + var template = { + "name": configParams["GENERAL_EMAIL_TEMPLATE"], + "value": emailTemplate, + "contentType": "text" + };*/ + + configList.push(monitorFrequency); + /*configList.push(host); + configList.push(port); + configList.push(username); + configList.push(password); + configList.push(sender); + configList.push(template);*/ + + 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 () { + $(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(); + + 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"); + } + + 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 () { + $(errorMsg).text("An unexpected error occurred."); + $(errorMsgWrapper).removeClass("hidden"); + } + ); + + }); + + var errorMsgWrapper = "#windows-config-error-msg"; + var errorMsg = "#windows-config-error-msg span"; + var fileTypes = ['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) { + $(errorMsg).text("The File APIs are not fully supported in this browser."); + $(errorMsgWrapper).removeClass("hidden"); + notSupportedError = true; + return; + } + + var file = fileInputWindowsMDMCert[0].files[0]; + fileNameWindowsMDMCert = file.name; + var extension = file.name.split('.').pop().toLowerCase(), + isSuccess = fileTypes.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) { + $(errorMsg).text("Notifier Frequency is a required field. It cannot be empty."); + $(errorMsgWrapper).removeClass("hidden"); + } else if (!windowsLicense) { + $(errorMsg).text("License is a required field. It cannot be empty."); + $(errorMsgWrapper).removeClass("hidden"); + } else if(!$.isNumeric(notifierFrequency)){ + $(errorMsg).text("Provided Notifier frequency is invalid. It must be a number."); + $(errorMsgWrapper).removeClass("hidden"); + } + + var addConfigFormData = {}; + var configList = new Array(); + + var paramNotifierFrequency = { + "name": configParams["NOTIFIER_FREQUENCY"], + "value": notifierFrequency, + "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."); + } + + $(errorMsgWrapper).removeClass("hidden"); + }, function () { + $(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 hiddenOperation = ".wr-hidden-operations-content > div"; + $(hiddenOperation + '[data-operation="' + operation + '"]').show(); + $(hiddenOperation + '[data-operation="' + operation + '"]').siblings().hide(); +}; diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.ui.header.logo/logo.hbs b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.ui.header.logo/logo.hbs new file mode 100644 index 0000000000..5d18e1cfb8 --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.ui.header.logo/logo.hbs @@ -0,0 +1 @@ +{{#zone "productName"}}IoT SERVER{{/zone}} \ No newline at end of file diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.ui.header.logo/logo.json b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.ui.header.logo/logo.json new file mode 100644 index 0000000000..211837ebc3 --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.ui.header.logo/logo.json @@ -0,0 +1,5 @@ +{ + "version": "1.0.0", + "index": 29, + "extends": "iot.unit.ui.header.logo" +} \ No newline at end of file