diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml index 703f3ba348..c885da4270 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml @@ -144,6 +144,7 @@ org.wso2.carbon.event.output.adapter.core, org.wso2.carbon.event.output.adapter.core.exception, org.osgi.framework, + org.wso2.carbon.device.mgt.core.operation.mgt, org.wso2.carbon.core diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java index 03f2d8f9d3..93be818999 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java @@ -22,17 +22,21 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.common.policy.mgt.Profile; import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext; import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException; +import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; import org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.internal.MQTTDataHolder; import org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.internal.util.MQTTAdapterConstants; import org.wso2.carbon.event.output.adapter.core.MessageType; import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration; import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException; +import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Properties; @@ -57,7 +61,7 @@ public class MQTTNotificationStrategy implements NotificationStrategy { configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME, config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME)); configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD, - config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD)); + config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD)); configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION, config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION)); configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES, @@ -79,23 +83,48 @@ public class MQTTNotificationStrategy implements NotificationStrategy { @Override public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException { - Map dynamicProperties = new HashMap<>(); + Operation operation = ctx.getOperation(); Properties properties = operation.getProperties(); if (properties != null && properties.get(MQTT_ADAPTER_TOPIC) != null) { + Map dynamicProperties = new HashMap<>(); dynamicProperties.put("topic", (String) properties.get(MQTT_ADAPTER_TOPIC)); + MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties, + operation.getPayLoad()); } else { - String topic = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true) + "/" - + ctx.getDeviceId().getType() + "/" + ctx.getDeviceId().getId() + "/" + operation.getType() - .toString().toLowerCase() + "/" + operation.getCode(); - dynamicProperties.put("topic", topic); - if (operation.getPayLoad() == null) { - operation.setPayLoad(""); + if (PolicyOperation.POLICY_OPERATION_CODE.equals(operation.getCode())) { + PolicyOperation policyOperation = (PolicyOperation) operation; + List profileOperations = policyOperation.getProfileOperations(); + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true); + String deviceType = ctx.getDeviceId().getType(); + String deviceId = ctx.getDeviceId().getId(); + for (ProfileOperation profileOperation : profileOperations) { + Map dynamicProperties = new HashMap<>(); + String topic = tenantDomain + "/" + + deviceType + "/" + deviceId + "/" + profileOperation.getType() + .toString().toLowerCase() + "/" + profileOperation.getCode().toLowerCase(); + dynamicProperties.put("topic", topic); + MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties, + profileOperation.getPayLoad()); + } + + } else { + Map dynamicProperties = new HashMap<>(); + String topic = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true) + "/" + + ctx.getDeviceId().getType() + "/" + ctx.getDeviceId().getId() + "/" + operation.getType() + .toString().toLowerCase() + "/" + operation.getCode(); + dynamicProperties.put("topic", topic); + if (operation.getPayLoad() == null) { + operation.setPayLoad(""); + } + MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties, + operation.getPayLoad()); + } + } - MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties, - operation.getPayLoad()); + } @Override @@ -109,3 +138,4 @@ public class MQTTNotificationStrategy implements NotificationStrategy { } } + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java index c6c7130926..b909ff609b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java @@ -72,7 +72,7 @@ import javax.ws.rs.core.Response; "Further, this is strictly restricted to admin users only ") public interface UserManagementAdminService { - @PUT + @POST @Path("/{username}/credentials") @ApiOperation( consumes = MediaType.APPLICATION_JSON, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/web.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/web.xml index aa49482557..b23f60be4c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/web.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/web.xml @@ -89,7 +89,7 @@ org.wso2.carbon.ui.filters.cache.ContentTypeBasedCachePreventionFilter patterns - "text/html*","application/json*","text/plain*" + text/html" ,application/json" ,text/plain filterAction diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/data-tables-invoker-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/data-tables-invoker-api.jag index 0fb2945cf4..f8cfa13520 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/data-tables-invoker-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/data-tables-invoker-api.jag @@ -24,6 +24,7 @@ var uriMatcher = new URIMatcher(String(uri)); var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; +var utility = require("/app/modules/utility.js")["utility"]; function appendQueryParam (url, queryParam , value) { if (url.indexOf("?") > 0) { @@ -60,7 +61,7 @@ if (uriMatcher.match("/{context}/api/data-tables/invoker")) { // response callback function (backendResponse) { response["status"] = backendResponse["status"]; - response["content"] = backendResponse["responseText"]; + response["content"] = utility.encodeJson(backendResponse["responseText"]); } ); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js index d29498a318..ed40ee7de8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js @@ -117,15 +117,44 @@ var invokers = function () { log.debug("Response status : " + xmlHttpRequest.status); log.debug("Response payload if any : " + xmlHttpRequest.responseText); - if (xmlHttpRequest.status == 401 && (xmlHttpRequest.responseText == TOKEN_EXPIRED || - xmlHttpRequest.responseText == TOKEN_INVALID ) && count < 5) { - tokenUtil.refreshTokenPair(); - return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, ++count, headers); - } else { + if (xmlHttpRequest.status == 401) { + if ((xmlHttpRequest.responseText == TOKEN_EXPIRED || + xmlHttpRequest.responseText == TOKEN_INVALID ) && count < 5) { + tokenUtil.refreshTokenPair(); + return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, ++count, headers); + } else if (privateMethods.isInvalidCredential(xmlHttpRequest.responseText)) { + tokenUtil.refreshTokenPair(); + return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, ++count, headers); + } + } else { return responseCallback(xmlHttpRequest); - } + } }; + + /** + * This method verify whether the access token is expired using response payload. + * This is required when using API gateway. + * @param responsePayload response payload. + * return true if it is invalid otherwise false. + */ + privateMethods["isInvalidCredential"] = + function (responsePayload) { + if (responsePayload) { + try { + payload = parse(responsePayload); + if (payload["fault"]["code"] == 900901) { + log.debug("Access token is invalid: " + payload["fault"]["code"]); + log.debug(payload["fault"]["description"]); + return true; + } + } catch (err) { + // do nothing + } + } + return false; + }; + /** * This method add Oauth authentication header to outgoing XML-HTTP Requests if Oauth authentication is enabled. * @param httpMethod HTTP request type. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js index 49b1a0d5b1..d1658872b3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js @@ -153,5 +153,24 @@ utility = function () { return scopesList; }; + + /** + * Escapes special characters such as <,>,',",...etc + * This will prevent XSS attacks upon JSON. + * @param text + * @returns {*} + */ + publicMethods.encodeJson = function (text) { + return text + .replace(/\\u003c/g, "<") + .replace(//g, ">") + .replace(/\\u0027/g, "'") + .replace(/'/g, "'") + .replace(/\\"/g, """) + .replace(/\\u0022/g, """) + }; + return publicMethods; }(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js index bae88512d5..51c9d92625 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js @@ -375,15 +375,15 @@ function loadDevices(searchType, searchParam) { var fnCreatedRow = function (row, data, dataIndex) { $(row).attr('data-type', 'selectable'); - $(row).attr('data-deviceid', data.deviceIdentifier); - $(row).attr('data-devicetype', data.deviceType); - $(row).attr('data-url', context + '/device/' + data.deviceType + '?id=' + data.deviceIdentifier); - var model = getPropertyValue(data.properties, 'DEVICE_MODEL'); - var vendor = getPropertyValue(data.properties, 'VENDOR'); - var owner = data.user; - var status = data.status; - var ownership = data.ownership; - var deviceType = data.deviceType; + $(row).attr('data-deviceid', htmlspecialchars(data.deviceIdentifier)); + $(row).attr('data-devicetype', htmlspecialchars(data.deviceType)); + $(row).attr('data-url', context + '/device/' + htmlspecialchars(data.deviceType) + '?id=' + htmlspecialchars(data.deviceIdentifier)); + var model = htmlspecialchars(getPropertyValue(data.properties, 'DEVICE_MODEL')); + var vendor = htmlspecialchars(getPropertyValue(data.properties, 'VENDOR')); + var owner = htmlspecialchars(data.user); + var status = htmlspecialchars(data.status); + var ownership = htmlspecialchars(data.ownership); + var deviceType = htmlspecialchars(data.deviceType); var category = getDeviceTypeCategory(deviceType); $.each($('td', row), function (colIndex) { switch (colIndex) { @@ -417,6 +417,10 @@ function loadDevices(searchType, searchParam) { }); }; + function htmlspecialchars(text){ + return jQuery('
').text(text).html(); + } + var dataFilter = function (data) { data = JSON.parse(data); var objects = []; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js index 212bec7521..6566078bf9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js @@ -112,6 +112,10 @@ function toTitleCase(str) { }); } +function htmlspecialchars(text){ + return jQuery('
').text(text).html(); +} + function loadGroups() { var groupListing = $("#group-listing"); var currentUser = groupListing.data("currentUser"); @@ -134,10 +138,10 @@ function loadGroups() { var objects = []; $(data.deviceGroups).each(function (index) { objects.push({ - groupId: data.deviceGroups[index].id, - name: data.deviceGroups[index].name, - description: data.deviceGroups[index].description, - owner: data.deviceGroups[index].owner + groupId: htmlspecialchars(data.deviceGroups[index].id), + name: htmlspecialchars(data.deviceGroups[index].name), + description: htmlspecialchars(data.deviceGroups[index].description), + owner: htmlspecialchars(data.deviceGroups[index].owner) }) }); var json = { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/public/js/policy-list.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/public/js/policy-list.js index 8e31e39ecc..0d94332844 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/public/js/policy-list.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/public/js/policy-list.js @@ -109,6 +109,7 @@ function getSelectedPolicies() { return policyList; } + $(document).ready(function () { /** diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js index 5b5b835d5b..d673e72929 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js @@ -86,6 +86,10 @@ function InitiateViewOption() { // $(location).attr('href', $(this).data("url")); } +function htmlspecialchars(text){ + return jQuery('
').text(text).html(); +} + function loadRoles() { var loadingContent = $("#loading-content"); loadingContent.show(); @@ -98,8 +102,8 @@ function loadRoles() { $(data.roles).each(function (index) { objects.push( { - name: data.roles[index], - DT_RowId: "role-" + data.roles[index] + name: htmlspecialchars(data.roles[index]), + DT_RowId: "role-" + htmlspecialchars(data.roles[index]) } ) }); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js index 95c8b9bbc3..ce89b335f5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js @@ -258,6 +258,10 @@ function InitiateViewOption() { } } +function htmlspecialchars(text){ + return jQuery('
').text(text).html(); +} + function loadUsers() { var loadingContentView = "#loading-content"; $(loadingContentView).show(); @@ -269,11 +273,11 @@ function loadUsers() { $(data.users).each(function (index) { objects.push({ - filter: data.users[index].username, - firstname: data.users[index].firstname ? data.users[index].firstname : "", - lastname: data.users[index].lastname ? data.users[index].lastname : "", - emailAddress: data.users[index].emailAddress ? data.users[index].emailAddress : "", - DT_RowId: "user-" + data.users[index].username + filter: htmlspecialchars(data.users[index].username), + firstname: htmlspecialchars(data.users[index].firstname) ? htmlspecialchars(data.users[index].firstname) : "", + lastname: htmlspecialchars(data.users[index].lastname) ? htmlspecialchars(data.users[index].lastname) : "", + emailAddress: htmlspecialchars(data.users[index].emailAddress) ? htmlspecialchars(data.users[index].emailAddress) : "", + DT_RowId: "user-" + htmlspecialchars(data.users[index].username) }) }); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js index 243df02a4d..9ca788dc43 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js @@ -273,6 +273,7 @@ $.fn.datatables_extended_serverside_paging = function (settings, url, dataFilter thisTable.removeClass("table-selectable"); $(button).addClass("active").html('Select'); $(button).parent().next().children().addClass("disabled"); + $('.DTTT_selected.selected').removeClass(rowSelectedClass); // EMM related function $(document).on('click', '.viewEnabledIcon', InitiateViewOption); //--- End of EMM related codes diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/public/js/listing.js index ba9a4be94a..c68cfbe1f9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/public/js/listing.js @@ -41,22 +41,22 @@ $(document).ready(function () { /* for device list sorting drop down */ $(".ctrl-filter-type-switcher").popover({ - html : true, - content : function () { - return $("#content-filter-types").html(); - } - }); + html: true, + content: function () { + return $("#content-filter-types").html(); + } + }); - $(".ast-container").on("click", ".claim-btn", function(e){ + $(".ast-container").on("click", ".claim-btn", function (e) { e.stopPropagation(); var deviceId = $(this).data("deviceid"); var deviceListing = $("#device-listing"); var currentUser = deviceListing.data("current-user"); var serviceURL = "/temp-controller-agent/enrollment/claim?username=" + currentUser; var deviceIdentifier = {id: deviceId, type: "TemperatureController"}; - invokerUtil.put(serviceURL, deviceIdentifier, function(message){ + invokerUtil.put(serviceURL, deviceIdentifier, function (message) { console.log(message); - }, function(message){ + }, function (message) { console.log(message); }); }); @@ -68,15 +68,15 @@ $(document).ready(function () { * @param button: Select All Device button */ function selectAllDevices(button) { - if(!$(button).data('select')){ - $(deviceCheckbox).each(function(index){ + if (!$(button).data('select')) { + $(deviceCheckbox).each(function (index) { $(this).prop('checked', true); addDeviceSelectedClass(this); }); $(button).data('select', true); $(button).html('Deselect All Devices'); - }else{ - $(deviceCheckbox).each(function(index){ + } else { + $(deviceCheckbox).each(function (index) { $(this).prop('checked', false); addDeviceSelectedClass(this); }); @@ -92,7 +92,7 @@ function selectAllDevices(button) { * @param selection: Selection button */ function changeDeviceView(view, selection) { - $(".view-toggle").each(function() { + $(".view-toggle").each(function () { $(this).removeClass("selected"); }); $(selection).addClass("selected"); @@ -117,27 +117,33 @@ function addDeviceSelectedClass(checkbox) { } function toTitleCase(str) { - return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); + return str.replace(/\w\S*/g, function (txt) { + return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); + }); } var deviceTypeCount, compiledDeviceTypesCount = 0; -function loadDevices(searchType, searchParam){ +function htmlspecialchars(text) { + return jQuery('
').text(text).html(); +} + +function loadDevices(searchType, searchParam) { var deviceListing = $("#device-listing"); var deviceListingSrc = deviceListing.attr("src"); var currentUser = deviceListing.data("currentUser"); $('#ast-container').html(""); deviceTypeCount = deviceTypesList.length; - if(deviceTypesList.length > 0){ + if (deviceTypesList.length > 0) { for (var i = 0; i < deviceTypesList.length; i++) { var viewModel = {}; viewModel.thumb = deviceTypesList[i].thumb; viewModel.appContext = clientJsAppContext; - viewModel.deviceTypeName = deviceTypesList[i].deviceTypeName; - viewModel.deviceTypeId = deviceTypesList[i].deviceTypeId; - viewModel.deviceCategory = deviceTypesList[i].deviceCategory; - viewModel.deviceTypeLabel = deviceTypesList[i].deviceTypeLabel; + viewModel.deviceTypeName = htmlspecialchars(deviceTypesList[i].deviceTypeName); + viewModel.deviceTypeId = htmlspecialchars(deviceTypesList[i].deviceTypeId); + viewModel.deviceCategory = htmlspecialchars(deviceTypesList[i].deviceCategory); + viewModel.deviceTypeLabel = htmlspecialchars(deviceTypesList[i].deviceTypeLabel); compileTemplate(viewModel, deviceListingSrc); } } else { @@ -155,12 +161,12 @@ function loadDevices(searchType, searchParam){ } -function compileTemplate(viewModel, templateSrc){ +function compileTemplate(viewModel, templateSrc) { $.template("device-listing", templateSrc, function (template) { $("#ast-container").html($("#ast-container").html() + template(viewModel)); compiledDeviceTypesCount++; - if(deviceTypeCount == compiledDeviceTypesCount){ - $('#device-type-grid').datatables_extended({"bFilter": false, "order": [[ 1, "asc" ]]}); + if (deviceTypeCount == compiledDeviceTypesCount) { + $('#device-type-grid').datatables_extended({"bFilter": false, "order": [[1, "asc"]]}); } }); } @@ -171,17 +177,16 @@ function compileTemplate(viewModel, templateSrc){ var deviceCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']"; var assetContainer = "#ast-container"; -function openCollapsedNav(){ +function openCollapsedNav() { $('.wr-hidden-nav-toggle-btn').addClass('active'); - $('#hiddenNav').slideToggle('slideDown', function(){ - if($(this).css('display') == 'none'){ + $('#hiddenNav').slideToggle('slideDown', function () { + if ($(this).css('display') == 'none') { $('.wr-hidden-nav-toggle-btn').removeClass('active'); } }); } - /* * DOM ready functions. */ @@ -196,22 +201,22 @@ $(document).ready(function () { /* for device list sorting drop down */ $(".ctrl-filter-type-switcher").popover({ - html : true, - content : function () { - return $("#content-filter-types").html(); - } - }); + html: true, + content: function () { + return $("#content-filter-types").html(); + } + }); - $(".ast-container").on("click", ".claim-btn", function(e){ + $(".ast-container").on("click", ".claim-btn", function (e) { e.stopPropagation(); var deviceId = $(this).data("deviceid"); var deviceListing = $("#device-listing"); var currentUser = deviceListing.data("current-user"); var serviceURL = "/temp-controller-agent/enrollment/claim?username=" + currentUser; var deviceIdentifier = {id: deviceId, type: "TemperatureController"}; - invokerUtil.put(serviceURL, deviceIdentifier, function(message){ + invokerUtil.put(serviceURL, deviceIdentifier, function (message) { console.log(message); - }, function(message){ + }, function (message) { console.log(message); }); }); @@ -222,20 +227,20 @@ $(document).ready(function () { $("[data-toggle=popover]").popover(); $(".ctrl-filter-type-switcher").popover({ - html : true, - content: function() { - return $('#content-filter-types').html(); - } - }); + html: true, + content: function () { + return $('#content-filter-types').html(); + } + }); $('#nav').affix({ - offset: { - top: $('header').height() - } - }); + offset: { + top: $('header').height() + } + }); - $(document).on("click", "tr.clickable-row", function(){ - window.document.location = $(this).data('href'); + $(document).on("click", "tr.clickable-row", function () { + window.document.location = $(this).data('href'); }) }); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.qrcode/qrcode.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.qrcode/qrcode.hbs index d63ee90965..07ee1b4801 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.qrcode/qrcode.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.qrcode/qrcode.hbs @@ -67,11 +67,4 @@ }); } - {{/zone}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.modal/public/js/modal.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.modal/public/js/modal.js index 0e97b964b7..29c29bf7a8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.modal/public/js/modal.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.modal/public/js/modal.js @@ -20,15 +20,15 @@ var modalDialog = (function () { var publicMethoads = {}; publicMethoads.header = function (headerText) { - $("#modal-title-text").html(headerText); + $("#basic-modal-view #modal-title-text").html(headerText); }; publicMethoads.content = function (contentText) { - $("#modal-content-text").html(contentText); + $("#basic-modal-view #modal-content-text").html(contentText); }; publicMethoads.footer = function (footerContent) { - $("#modal-footer-content").html(footerContent); + $("#basic-modal-view #modal-footer-content").html(footerContent); }; publicMethoads.footerButtons = function (buttonList) { @@ -37,7 +37,7 @@ var modalDialog = (function () { footerContent = footerContent + ''; } - $("#modal-footer-content").html(footerContent); + $("#basic-modal-view #modal-footer-content").html(footerContent); }; publicMethoads.show = function () { @@ -62,11 +62,21 @@ var modalDialog = (function () { publicMethoads.hide = function () { $("#basic-modal-view").addClass('hidden'); $("#basic-modal-view").modal('hide'); - $("#modal-title-text").html(""); - $("#modal-content-text").html(""); - $("#modal-footer-content").html(""); - $('body').removeClass('modal-open').css('padding-right', '0px'); $('.modal-backdrop').remove(); }; + + $("#basic-modal-view").on('hidden.bs.modal', function () { + $('#basic-modal-view .modal-dialog').html(''); + $('body').removeClass('modal-open').css('padding-right', '0px'); + }); + return publicMethoads; }(modalDialog)); \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs index 51d087ca34..61655a5f44 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs @@ -80,9 +80,9 @@ @@ -90,9 +90,8 @@ {{/zone}} {{#zone "sidePanes"}} -