forked from community/device-mgt-core
parent
e9da24c9e8
commit
e537e2d841
@ -0,0 +1,60 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2014, 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>device-mgt</artifactId>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.ui</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<name>WSO2 Carbon - Device Management Base UI</name>
|
||||||
|
<description>WSO2 Carbon - Device Management Base UI</description>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<version>2.5.5</version>
|
||||||
|
<configuration>
|
||||||
|
<finalName>${project.artifactId}-${carbon.device.mgt.version}</finalName>
|
||||||
|
<appendAssemblyId>false</appendAssemblyId>
|
||||||
|
<descriptors>
|
||||||
|
<descriptor>src/assembly/src.xml</descriptor>
|
||||||
|
</descriptors>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>create-archive</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,36 @@
|
|||||||
|
<!--
|
||||||
|
~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
~
|
||||||
|
~ WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
~ Version 2.0 (the "License"); you may not use this file except
|
||||||
|
~ in compliance with the License.
|
||||||
|
~ You may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing,
|
||||||
|
~ software distributed under the License is distributed on an
|
||||||
|
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
~ KIND, either express or implied. See the License for the
|
||||||
|
~ specific language governing permissions and limitations
|
||||||
|
~ under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<assembly
|
||||||
|
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
|
||||||
|
<id>src</id>
|
||||||
|
<formats>
|
||||||
|
<format>zip</format>
|
||||||
|
</formats>
|
||||||
|
<includeBaseDirectory>false</includeBaseDirectory>
|
||||||
|
<baseDirectory>${basedir}/src</baseDirectory>
|
||||||
|
<fileSets>
|
||||||
|
<fileSet>
|
||||||
|
<directory>${basedir}/src/main/resources/jaggeryapps/devicemgt</directory>
|
||||||
|
<outputDirectory>/</outputDirectory>
|
||||||
|
<useDefaultExcludes>true</useDefaultExcludes>
|
||||||
|
</fileSet>
|
||||||
|
</fileSets>
|
||||||
|
</assembly>
|
@ -0,0 +1,173 @@
|
|||||||
|
<%
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var uri = request.getRequestURI();
|
||||||
|
var uriMatcher = new URIMatcher(String(uri));
|
||||||
|
|
||||||
|
var log = new Log("api/device-api.jag");
|
||||||
|
var constants = require("/app/modules/constants.js");
|
||||||
|
var deviceModule = require("/app/modules/device.js").deviceModule;
|
||||||
|
var utility = require("/app/modules/utility.js").utility;
|
||||||
|
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
||||||
|
|
||||||
|
var CarbonUtils = Packages.org.wso2.carbon.utils.CarbonUtils;
|
||||||
|
var user = session.get(constants.USER_SESSION_KEY);
|
||||||
|
var result;
|
||||||
|
|
||||||
|
response.contentType = 'application/json';
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
response.sendRedirect("/devicemgt/login?#login-required");
|
||||||
|
exit();
|
||||||
|
} else {
|
||||||
|
if (uriMatcher.match("/{context}/api/devices/sketch/download/{downloadId}")) {
|
||||||
|
downloadId = uriMatcher.elements().downloadId;
|
||||||
|
//Just download the already created zip archive
|
||||||
|
var sketchFolder = "repository/resources/sketches";
|
||||||
|
var archivesPath = "file://" + CarbonUtils.getCarbonHome() + "/" + sketchFolder + "/archives/" +
|
||||||
|
downloadId + ".zip";
|
||||||
|
var zipFile = new File(archivesPath);
|
||||||
|
response.addHeader('Content-type', "application/zip, application/octet-stream");
|
||||||
|
response.addHeader('Cache-Control', 'public,max-age=12960000');
|
||||||
|
response.addHeader("Content-Disposition", "attachment; filename=\"" + downloadId + ".zip\"");
|
||||||
|
|
||||||
|
try {
|
||||||
|
zipFile.open('r');
|
||||||
|
var stream = zipFile.getStream();
|
||||||
|
print(stream);
|
||||||
|
} catch (err) {
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
if (zipFile != null) {
|
||||||
|
zipFile.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/devices/sketch/download")) {
|
||||||
|
//Create a new zip archive and register user calling endpoint
|
||||||
|
|
||||||
|
/* This should match with $CARBON_HOME/repository/resources/sketches/{sketchType} */
|
||||||
|
sketchType = request.getParameter("sketchType");
|
||||||
|
/* This should be registered device type of the CDMF(Connected Device Management Framework) */
|
||||||
|
deviceType = request.getParameter("deviceType");
|
||||||
|
deviceName = request.getParameter("deviceName");
|
||||||
|
|
||||||
|
if (!sketchType) {
|
||||||
|
log.error("Sketch Type is empty!");
|
||||||
|
// HTTP status code 400 refers to - Bad request.
|
||||||
|
result = 400;
|
||||||
|
} else {
|
||||||
|
/**
|
||||||
|
URL: {serverURL}/{deviceType}/{downloadAgentUri}?owner={username}&deviceName={deviceName}
|
||||||
|
{serverURL} - devicemgt/app/conf/config.json
|
||||||
|
{deviceType} - from the request
|
||||||
|
{downloadAgentUri} - device_type_specific_unit/private/conf/device-type.json
|
||||||
|
{username} - from request
|
||||||
|
{deviceName} - from request
|
||||||
|
**/
|
||||||
|
|
||||||
|
var deviceManagerService = devicemgtProps["httpsURL"] + "/" + deviceType + "_mgt" + "/manager";
|
||||||
|
var sketchDownloadEndPoint = deviceManagerService + "/device/" + sketchType + "/download";
|
||||||
|
deviceTypeConfig = utility.getDeviceTypeConfig(deviceType);
|
||||||
|
|
||||||
|
if (deviceTypeConfig && deviceTypeConfig.deviceType.downloadAgentUri) {
|
||||||
|
sketchDownloadEndPoint = devicemgtProps["httpsURL"] + "/" + deviceType + "_mgt" +
|
||||||
|
"/" + deviceTypeConfig.deviceType.downloadAgentUri;
|
||||||
|
}
|
||||||
|
var tokenPair = session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER);
|
||||||
|
if (tokenPair) {
|
||||||
|
response.addHeader(constants.AUTHORIZATION_HEADER, constants.BEARER_PREFIX +
|
||||||
|
tokenPair.accessToken);
|
||||||
|
response.sendRedirect(sketchDownloadEndPoint + "?owner=" + user.username + "&deviceName=" +
|
||||||
|
deviceName);
|
||||||
|
} else {
|
||||||
|
response.sendRedirect(devicemgtProps["httpsURL"] + "/devicemgt/login");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/devices/sketch/generate_link")) {
|
||||||
|
|
||||||
|
var contents = request.getContent();
|
||||||
|
sketchType = contents.sketchType;
|
||||||
|
deviceType = contents.deviceType;
|
||||||
|
deviceName = contents.deviceName;
|
||||||
|
generateLink = contents.generateLink;
|
||||||
|
|
||||||
|
if (!sketchType) {
|
||||||
|
log.error("Sketch Type is empty!");
|
||||||
|
// HTTP status code 400 refers to - Bad request.
|
||||||
|
result = 400;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
/**
|
||||||
|
URL: {serverURL}/{deviceType}/{downloadAgentUri}?owner={username}&deviceName={deviceName}
|
||||||
|
{serverURL} - devicemgt/app/conf/config.json
|
||||||
|
{deviceType} - from the request
|
||||||
|
{downloadAgentUri} - device_type_specific_unit/private/conf/device-type.json
|
||||||
|
{username} - from request
|
||||||
|
{deviceName} - from request
|
||||||
|
**/
|
||||||
|
|
||||||
|
deviceManagerService = devicemgtProps["httpsURL"] + "/" + deviceType + "_mgt" + "/manager";
|
||||||
|
sketchGenerateLinkEndPoint = deviceManagerService + "/device/" + sketchType + "/generate_link";
|
||||||
|
var deviceTypeConfig = utility.getDeviceTypeConfig(deviceType);
|
||||||
|
//replace download endpoint
|
||||||
|
if (deviceTypeConfig && deviceTypeConfig.deviceType.downloadAgentLinkGenUri) {
|
||||||
|
sketchGenerateLinkEndPoint = devicemgtProps["httpsURL"] + "/" + deviceType + "_mgt" +
|
||||||
|
"/" + deviceTypeConfig.deviceType.downloadAgentLinkGenUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
var fileId = get(sketchGenerateLinkEndPoint + "?owner=" + user.username + "&deviceName=" +
|
||||||
|
deviceName, null, "text");
|
||||||
|
result = "curl -k " + devicemgtProps["httpsURL"] + constants.WEB_APP_CONTEXT +
|
||||||
|
"/api/devices/sketch/download/" + fileId.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/devices/all")) {
|
||||||
|
result = deviceModule.getOwnDevices();
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/devices/count")) {
|
||||||
|
var count = deviceModule.getOwnDevicesCount().data;
|
||||||
|
result = count.toString();
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/devices/types")) {
|
||||||
|
result = deviceModule.listDeviceTypes();
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/devices/{deviceType}/{deviceId}/remove")) {
|
||||||
|
var elements = uriMatcher.elements();
|
||||||
|
var deviceId = elements.deviceId;
|
||||||
|
var deviceType = elements.deviceType;
|
||||||
|
result = deviceModule.removeDevice(deviceType, deviceId);
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/devices/{deviceType}/{deviceId}/update")) {
|
||||||
|
var elements = uriMatcher.elements();
|
||||||
|
var deviceId = elements.deviceId;
|
||||||
|
var deviceType = elements.deviceType;
|
||||||
|
var deviceName = request.getParameter("name");
|
||||||
|
result = deviceModule.updateDevice(deviceType, deviceId, deviceName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returning the result.
|
||||||
|
if (result) {
|
||||||
|
print(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
%>
|
@ -0,0 +1,133 @@
|
|||||||
|
<%
|
||||||
|
/*
|
||||||
|
* 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 uri = request.getRequestURI();
|
||||||
|
var uriMatcher = new URIMatcher(String(uri));
|
||||||
|
|
||||||
|
var log = new Log("apis/group-api.jag");
|
||||||
|
|
||||||
|
var constants = require("/app/modules/constants.js");
|
||||||
|
|
||||||
|
var utility = require("/app/modules/utility.js").utility;
|
||||||
|
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
||||||
|
var responseProcessor = require('utils').response;
|
||||||
|
|
||||||
|
var deviceCloudService = devicemgtProps["httpsURL"] + "/common/group_manager";
|
||||||
|
|
||||||
|
var user = session.get(constants.USER_SESSION_KEY);
|
||||||
|
|
||||||
|
var groupModule = require("/app/modules/group.js").groupModule;
|
||||||
|
|
||||||
|
var result, endPoint, data, groupId, group, role;
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
response = responseProcessor.buildErrorResponse(response, 401, "Unauthorized");
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (uriMatcher.match("/{context}/api/group/add")) {
|
||||||
|
group = request.getContent();
|
||||||
|
result = groupModule.addGroup(group);
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/update")) {
|
||||||
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
group = request.getContent();
|
||||||
|
result = groupModule.updateGroup(groupId, group);
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/remove")) {
|
||||||
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
result = groupModule.removeGroup(groupId);
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}")) {
|
||||||
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
result = groupModule.getGroup(groupId);
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/group/name/{groupName}")) {
|
||||||
|
var groupName = uriMatcher.elements().groupName;
|
||||||
|
result = groupModule.findGroups(groupName);
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/group/all")) {
|
||||||
|
result = groupModule.getGroups();
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/group/all/count")) {
|
||||||
|
result = groupModule.getGroupCount();
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/share")) {
|
||||||
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
var shareUser = request.getContent()["shareUser"];
|
||||||
|
role = request.getContent()["role"];
|
||||||
|
result = groupModule.shareGroup(groupId, shareUser, role);
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/unshare")) {
|
||||||
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
var unShareUser = request.getContent()["unShareUser"];
|
||||||
|
role = request.getContent()["role"];
|
||||||
|
result = groupModule.unshareGroup(groupId, unShareUser, role);
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/role/add")) {
|
||||||
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
var permissions = request.getContent()["permissions"];
|
||||||
|
role = request.getContent()["role"];
|
||||||
|
result = groupModule.addRole(groupId, role, permissions);
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/role/delete")) {
|
||||||
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
role = request.getContent()["role"];
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId + "/role/" + role;
|
||||||
|
result = groupModule.deleteRole(groupId, role);
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/role/all")) {
|
||||||
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
result = groupModule.getGroupRoles(groupId);
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/{userId}/role/all")) {
|
||||||
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
var userId = uriMatcher.elements().userId;
|
||||||
|
result = groupModule.getUserRoles(groupId, userId);
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/{userId}/rolemapping")) {
|
||||||
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
userId = uriMatcher.elements().userId;
|
||||||
|
result = groupModule.getRoleMapping(groupId, userId);
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/{userId}/roleupdate")) {
|
||||||
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
userId = uriMatcher.elements().userId;
|
||||||
|
var roleMap = request.getContent();
|
||||||
|
result = groupModule.setRoleMapping(groupId, userId, roleMap);
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/user/all")) {
|
||||||
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
result = groupModule.getUsers(groupId);
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/device/all")) {
|
||||||
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
result = groupModule.getDevices(groupId);
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/assign")) {
|
||||||
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
var deviceId = request.getContent()["deviceId"];
|
||||||
|
var deviceType = request.getContent()["deviceType"];
|
||||||
|
result = groupModule.assignDevice(groupId, deviceId, deviceType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// returning the result.
|
||||||
|
if (result) {
|
||||||
|
print(result);
|
||||||
|
}
|
||||||
|
%>
|
@ -0,0 +1,93 @@
|
|||||||
|
<%
|
||||||
|
/*
|
||||||
|
* 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 uri = request.getRequestURI();
|
||||||
|
var uriMatcher = new URIMatcher(String(uri));
|
||||||
|
|
||||||
|
var log = new Log("api/invoker-api.jag");
|
||||||
|
|
||||||
|
var constants = require("/app/modules/constants.js");
|
||||||
|
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
||||||
|
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
|
||||||
|
|
||||||
|
var result;
|
||||||
|
|
||||||
|
if (uriMatcher.match("/{context}/api/invoker/execute/")) {
|
||||||
|
var method = request.getContent().actionMethod;
|
||||||
|
var targetURL = devicemgtProps.httpsURL + request.getContent().actionUrl;
|
||||||
|
var payload = request.getContent().actionPayload;
|
||||||
|
if (method == undefined && payload == undefined) {
|
||||||
|
method = parse(request.getContent()).actionMethod;
|
||||||
|
targetURL = devicemgtProps.httpsURL + parse(request.getContent()).actionUrl;
|
||||||
|
payload = parse(request.getContent()).actionPayload;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
switch (method) {
|
||||||
|
case constants.HTTP_GET:
|
||||||
|
var responseData = serviceInvokers.XMLHttp.get(
|
||||||
|
targetURL, function (responsePayload) {
|
||||||
|
response.status = 200;
|
||||||
|
response.content = responsePayload;
|
||||||
|
},
|
||||||
|
function (responsePayload) {
|
||||||
|
response.status = responsePayload.status;
|
||||||
|
response.content = responsePayload.responseText;
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case constants.HTTP_POST:
|
||||||
|
var responseData = serviceInvokers.XMLHttp.post(
|
||||||
|
targetURL, payload, function (responsePayload) {
|
||||||
|
response.status = 200;
|
||||||
|
response.content = responsePayload;
|
||||||
|
},
|
||||||
|
function (responsePayload) {
|
||||||
|
response.status = responsePayload.status;
|
||||||
|
response.content = responsePayload.responseText;
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case constants.HTTP_PUT:
|
||||||
|
var responseData = serviceInvokers.XMLHttp.put(
|
||||||
|
targetURL, payload, function (responsePayload) {
|
||||||
|
response.status = 200;
|
||||||
|
response.content = responsePayload;
|
||||||
|
},
|
||||||
|
function (responsePayload) {
|
||||||
|
response.status = responsePayload.status;
|
||||||
|
response.content = responsePayload.responseText;
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case constants.HTTP_DELETE:
|
||||||
|
var responseData =
|
||||||
|
serviceInvokers.XMLHttp.delete(
|
||||||
|
targetURL, function (responsePayload) {
|
||||||
|
response.status = 200;
|
||||||
|
response.content = responsePayload;
|
||||||
|
},
|
||||||
|
function (responsePayload) {
|
||||||
|
response.status = responsePayload.status;
|
||||||
|
response.content = responsePayload.responseText;
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.error("Exception occurred while accessing sevices", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%>
|
@ -0,0 +1,62 @@
|
|||||||
|
<%
|
||||||
|
/*
|
||||||
|
* 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 uri = request.getRequestURI();
|
||||||
|
var uriMatcher = new URIMatcher(String(uri));
|
||||||
|
|
||||||
|
var log = new Log("/api/operation-api.jag");
|
||||||
|
|
||||||
|
var utility = require('/app/modules/utility.js').utility;
|
||||||
|
var constants = require('/app/modules/constants.js');
|
||||||
|
var operationModule = require("/app/modules/operation.js").operationModule;
|
||||||
|
|
||||||
|
response.contentType = 'application/json';
|
||||||
|
|
||||||
|
var user = session.get(constants.USER_SESSION_KEY);
|
||||||
|
|
||||||
|
var result;
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
response.sendRedirect("/devicemgt/login?#login-required");
|
||||||
|
exit();
|
||||||
|
} else {
|
||||||
|
if (uriMatcher.match("/{context}/api/operations/{deviceType}/stats")) {
|
||||||
|
var deviceType = uriMatcher.elements().deviceType;
|
||||||
|
var deviceId = request.getParameter("deviceId");
|
||||||
|
var monitor_operations = operationModule.getMonitorOperations(deviceType);
|
||||||
|
var stats = [];
|
||||||
|
result = {};
|
||||||
|
for (var op in monitor_operations) {
|
||||||
|
result = operationModule.handleGETOperation(deviceType, monitor_operations[op].operation, monitor_operations[op].name, deviceId);
|
||||||
|
stats.push(result.data);
|
||||||
|
}
|
||||||
|
result.data = stats;
|
||||||
|
} else if (uriMatcher.match("/{context}/api/operations/{deviceType}/{operation}")) {
|
||||||
|
var deviceType = uriMatcher.elements().deviceType;
|
||||||
|
var operation = uriMatcher.elements().operation;
|
||||||
|
var deviceId = request.getParameter("deviceId");
|
||||||
|
var params = request.getAllParameters();
|
||||||
|
result = operationModule.handlePOSTOperation(deviceType, operation, deviceId, params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// returning the result.
|
||||||
|
if (result) {
|
||||||
|
print(result);
|
||||||
|
}
|
||||||
|
%>
|
@ -0,0 +1,55 @@
|
|||||||
|
<%
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var uri = request.getRequestURI();
|
||||||
|
var uriMatcher = new URIMatcher(String(uri));
|
||||||
|
|
||||||
|
var log = new Log("api/policy-api.jag");
|
||||||
|
|
||||||
|
var constants = require("/app/modules/constants.js");
|
||||||
|
var policyModule = require("/app/modules/policy.js").policyModule;
|
||||||
|
|
||||||
|
var deviceType, deviceId;
|
||||||
|
|
||||||
|
var user = session.get(constants.USER_SESSION_KEY);
|
||||||
|
|
||||||
|
var responseProcessor = require('utils').response;
|
||||||
|
response.contentType = 'application/json';
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
response = responseProcessor.buildErrorResponse(response, 401, "Unauthorized");
|
||||||
|
} else {
|
||||||
|
if (uriMatcher.match("/{context}/api/policies/add")) {
|
||||||
|
var content = request.getContent();
|
||||||
|
var policyName = content.policyName;
|
||||||
|
var policyDefinition = content.profile.policyDefinition;
|
||||||
|
var policyDescription = content.profile.policyDescription;
|
||||||
|
deviceType = content.profile.deviceType.name;
|
||||||
|
deviceId = content.deviceId;
|
||||||
|
try {
|
||||||
|
response.content = policyModule.addPolicy(policyName, deviceType, policyDefinition,
|
||||||
|
policyDescription, deviceId);
|
||||||
|
} catch (e) {
|
||||||
|
log.error("Exception occurred while trying to add new policy under name:" + policyName, e);
|
||||||
|
// http status code 500 refers to - Internal Server Error.
|
||||||
|
responseProcessor.buildErrorResponse(response, 500, "Internal server error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%>
|
@ -0,0 +1,124 @@
|
|||||||
|
<%
|
||||||
|
/*
|
||||||
|
* 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 uri = request.getRequestURI();
|
||||||
|
var uriMatcher = new URIMatcher(String(uri));
|
||||||
|
|
||||||
|
var log = new Log("api/stats-api.jag");
|
||||||
|
|
||||||
|
var from = request.getParameter("from");
|
||||||
|
var to = request.getParameter("to");
|
||||||
|
|
||||||
|
var constants = require("/app/modules/constants.js");
|
||||||
|
var utility = require("/app/modules/utility.js").utility;
|
||||||
|
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
||||||
|
|
||||||
|
var deviceCloudGroupService = devicemgtProps["httpsURL"] + "/common/group_manager";
|
||||||
|
var deviceCloudDeviceService = devicemgtProps["httpsURL"] + "/common/device_manager";
|
||||||
|
var deviceCloudStatsService = devicemgtProps["httpsURL"] + "/common/stats_manager";
|
||||||
|
|
||||||
|
var stats = {};
|
||||||
|
var deviceId;
|
||||||
|
var deviceType;
|
||||||
|
|
||||||
|
var responseProcessor = require('utils').response;
|
||||||
|
response.contentType = 'application/json';
|
||||||
|
|
||||||
|
var user = session.get(constants.USER_SESSION_KEY);
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
response = responseProcessor.buildErrorResponse(response, 401, "Unauthorized");
|
||||||
|
} else {
|
||||||
|
if (uriMatcher.match("/{context}/api/stats")) {
|
||||||
|
deviceId = request.getParameter("deviceId");
|
||||||
|
deviceType = request.getParameter("deviceType");
|
||||||
|
|
||||||
|
getDeviceData(deviceType, deviceId);
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/stats/group")) {
|
||||||
|
var groupId = request.getParameter("groupId");
|
||||||
|
|
||||||
|
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/device/all
|
||||||
|
var endPoint = deviceCloudGroupService + "/group/id/" + groupId + "/device/all";
|
||||||
|
var data = {"username": user};
|
||||||
|
var devices = get(endPoint, data, "json").data;
|
||||||
|
|
||||||
|
for (var device in devices) {
|
||||||
|
deviceId = devices[device].deviceIdentifier;
|
||||||
|
deviceType = devices[device].type;
|
||||||
|
getDeviceData(deviceType, deviceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.info(stats);
|
||||||
|
// returning the result.
|
||||||
|
if (stats) {
|
||||||
|
print(stats);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDeviceData(deviceType, deviceId) {
|
||||||
|
//URL: GET https://localhost:9443/devicecloud/device_manager/device/type/{type}/identifier/{identifier}
|
||||||
|
var endPoint = deviceCloudDeviceService + "/device/type/" + deviceType + "/identifier/" + deviceId;
|
||||||
|
var data = {"username": user};
|
||||||
|
var device = get(endPoint, data, "json").data;
|
||||||
|
log.info(device);
|
||||||
|
if (!device) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var uname = device.enrolmentInfo.owner;
|
||||||
|
|
||||||
|
var analyticStreams = utility.getDeviceTypeConfig(deviceType)["analyticStreams"];
|
||||||
|
|
||||||
|
if (analyticStreams) {
|
||||||
|
var streamTableName;
|
||||||
|
for (var stream in analyticStreams) {
|
||||||
|
streamTableName = analyticStreams[stream]["table"];
|
||||||
|
if (stats[streamTableName] == null) {
|
||||||
|
stats[streamTableName] = [];
|
||||||
|
}
|
||||||
|
stats[streamTableName].push({
|
||||||
|
"device": device.name,
|
||||||
|
"stats": getSensorData(streamTableName, analyticStreams[stream]["ui_unit"]["data"][1]["column"]["name"], uname, device.type, device.deviceIdentifier, from, to),
|
||||||
|
"stream": analyticStreams[stream]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSensorData(table, column, user, type, deviceIdentifier, from, to) {
|
||||||
|
|
||||||
|
var fetchedData = [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
///stats/device/type/{type}/identifier/{identifier}
|
||||||
|
var endPoint = deviceCloudStatsService + "/stats/device/type/" + type + "/identifier/" + deviceIdentifier;
|
||||||
|
var query = "?table=" + encodeURIComponent(table)
|
||||||
|
+ "&column=" + encodeURIComponent(column)
|
||||||
|
+ "&username=" + encodeURIComponent(user)
|
||||||
|
+ "&from=" + from
|
||||||
|
+ "&to=" + to;
|
||||||
|
endPoint = endPoint + query;
|
||||||
|
fetchedData = get(endPoint, {}, "json").data;
|
||||||
|
return fetchedData;
|
||||||
|
} catch (error) {
|
||||||
|
log.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%>
|
@ -0,0 +1,22 @@
|
|||||||
|
<%
|
||||||
|
/*
|
||||||
|
* 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 apiWrapperUtil = require("/app/modules/api-wrapper-util.js").apiWrapperUtil;
|
||||||
|
var tokenCookie = apiWrapperUtil.refreshToken();
|
||||||
|
print(tokenCookie);
|
||||||
|
%>
|
@ -0,0 +1,189 @@
|
|||||||
|
<%
|
||||||
|
/*
|
||||||
|
* 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 uri = request.getRequestURI();
|
||||||
|
var uriMatcher = new URIMatcher(String(uri));
|
||||||
|
|
||||||
|
var log = new Log("api/user-api.jag");
|
||||||
|
|
||||||
|
var constants = require("/app/modules/constants.js");
|
||||||
|
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
||||||
|
var userModule = require("/app/modules/user.js").userModule;
|
||||||
|
var deviceModule = require("/app/modules/device.js").deviceModule;
|
||||||
|
var utility = require("/app/modules/utility.js").utility;
|
||||||
|
var apiWrapperUtil = require("/app/modules/api-wrapper-util.js").apiWrapperUtil;
|
||||||
|
var util = require("/app/modules/util.js").util;
|
||||||
|
|
||||||
|
var responseProcessor = require('utils').response;
|
||||||
|
|
||||||
|
var result;
|
||||||
|
|
||||||
|
if (uriMatcher.match("/{context}/api/user/authenticate")) {
|
||||||
|
var username = request.getParameter("username");
|
||||||
|
var password = request.getParameter("password");
|
||||||
|
//Check if a username and password is provided
|
||||||
|
if ((!username) || (!password)) {
|
||||||
|
response = responseProcessor.buildErrorResponse(response, 400, 'Username and Password must be provided');
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
userModule.login(username, password, function (user) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("User Logged In : " + user);
|
||||||
|
}
|
||||||
|
utility.insertAppPermissions(userModule, "login");
|
||||||
|
apiWrapperUtil.setupAccessTokenPair("password", {
|
||||||
|
"username": username,
|
||||||
|
"password": password
|
||||||
|
});
|
||||||
|
}, function () {
|
||||||
|
response = responseProcessor.buildSuccessResponse(response, 200, {'sessionId': session.getId()});
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
log.error("Exception occurred while a user tried to login to MDM", e);
|
||||||
|
response = responseProcessor.buildErrorResponse(response, 401, 'username/password is incorrect');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (uriMatcher.match("/{context}/api/user/login/")) {
|
||||||
|
username = request.getParameter("username");
|
||||||
|
password = request.getParameter("password");
|
||||||
|
username = util.decode(username);
|
||||||
|
password = util.decode(password);
|
||||||
|
try {
|
||||||
|
userModule.login(username, password, function (user) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("User Logged In : " + user);
|
||||||
|
}
|
||||||
|
utility.insertAppPermissions(userModule, "login");
|
||||||
|
apiWrapperUtil.setupAccessTokenPair("password", {"username": username, "password": password});
|
||||||
|
var permissions = userModule.getUIPermissions();
|
||||||
|
if (permissions.VIEW_DASHBOARD) {
|
||||||
|
response.sendRedirect(constants.WEB_APP_CONTEXT);
|
||||||
|
} else {
|
||||||
|
response.sendRedirect(constants.WEB_APP_CONTEXT + "/devices");
|
||||||
|
}
|
||||||
|
}, function () {
|
||||||
|
response.sendRedirect(devicemgtProps.appContext + "login?#auth-failed");
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
log.error("Exception occurred while a user tried to login to MDM", e);
|
||||||
|
response.sendRedirect(devicemgtProps.appContext + "login?#error");
|
||||||
|
}
|
||||||
|
} else if (uriMatcher.match("/{context}/api/user/logout/")) {
|
||||||
|
userModule.logout(function () {
|
||||||
|
response.sendRedirect(devicemgtProps.appContext + "login");
|
||||||
|
});
|
||||||
|
} else if (uriMatcher.match("/{context}/api/user/devices/")) {
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
if (userModule.isAuthorized("/permission/admin/device-mgt/user/devices/list")) {
|
||||||
|
carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
result = deviceModule.listDevicesForUser(carbonUser.username);
|
||||||
|
} else {
|
||||||
|
response.sendError(403);
|
||||||
|
}
|
||||||
|
} else if (uriMatcher.match("/{context}/api/user/{username}/invite")) {
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/user/invite")) {
|
||||||
|
elements = uriMatcher.elements();
|
||||||
|
username = elements.username;
|
||||||
|
userModule.inviteUser(username);
|
||||||
|
} else {
|
||||||
|
response.sendError(403);
|
||||||
|
}
|
||||||
|
} else if (uriMatcher.match("/{context}/api/user/add")) {
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/user/add")) {
|
||||||
|
addUserFormData = request.getContent();
|
||||||
|
username = addUserFormData.username;
|
||||||
|
firstname = addUserFormData.firstname;
|
||||||
|
lastname = addUserFormData.lastname;
|
||||||
|
emailAddress = addUserFormData.emailAddress;
|
||||||
|
|
||||||
|
if (!addUserFormData.userRoles) {
|
||||||
|
userRoles = null;
|
||||||
|
} else {
|
||||||
|
userRoles = String(addUserFormData.userRoles).split(",");
|
||||||
|
}
|
||||||
|
if (username.length < devicemgtProps.usernameLength) {
|
||||||
|
log.error("Username Must be between 1 and " + devicemgtProps.usernameLength + " characters long");
|
||||||
|
result = "Username Must be between 1 and " + devicemgtProps.usernameLength + " characters long";
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
result = userModule.addUser(username, firstname, lastname, emailAddress, userRoles);
|
||||||
|
} catch (e) {
|
||||||
|
log.error("Exception occurred while trying to add a user to MDM User Store", e);
|
||||||
|
// http status code 400 refers to - Bad request.
|
||||||
|
result = 400;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// http status code 403 refers to - forbidden.
|
||||||
|
result = 403;
|
||||||
|
}
|
||||||
|
} else if (uriMatcher.match("/{context}/api/user/register")) {
|
||||||
|
|
||||||
|
addUserFormData = request.getContent();
|
||||||
|
username = addUserFormData.username;
|
||||||
|
firstname = addUserFormData.firstname;
|
||||||
|
lastname = addUserFormData.lastname;
|
||||||
|
emailAddress = addUserFormData.emailAddress;
|
||||||
|
password = addUserFormData.password;
|
||||||
|
userRoles = ["devicemgt-user"];
|
||||||
|
|
||||||
|
try {
|
||||||
|
result = userModule.registerUser(username, firstname, lastname, emailAddress, password,
|
||||||
|
userRoles);
|
||||||
|
} catch (e) {
|
||||||
|
log.error("Exception occurred while trying to registering a new user to DC User Store", e);
|
||||||
|
// http status code 400 refers to - Bad request.
|
||||||
|
result = 400;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/user/{username}/remove")) {
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/user/remove")) {
|
||||||
|
elements = uriMatcher.elements();
|
||||||
|
username = elements.username;
|
||||||
|
try {
|
||||||
|
result = userModule.removeUser(username);
|
||||||
|
} catch (e) {
|
||||||
|
log.error("Exception occurred while trying to remove a user from MDM User Store", e);
|
||||||
|
// http status code 400 refers to - Bad request.
|
||||||
|
result = 400;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// http status code 403 refers to - forbidden.
|
||||||
|
result = 403;
|
||||||
|
}
|
||||||
|
} else if (uriMatcher.match("/{context}/api/user/all")) {
|
||||||
|
result = userModule.getUsers();
|
||||||
|
}
|
||||||
|
|
||||||
|
// returning the result.
|
||||||
|
if (result) {
|
||||||
|
print(result);
|
||||||
|
}
|
||||||
|
%>
|
@ -0,0 +1,36 @@
|
|||||||
|
{
|
||||||
|
"appName": "CDMF",
|
||||||
|
"cachingEnabled": false,
|
||||||
|
"debuggingEnabled": false,
|
||||||
|
"permissionRoot": "/",
|
||||||
|
"loginPage": "cdmf.page.sign-in",
|
||||||
|
"adminServicesUrl": "https://${server.ip}:${server.https_port}/admin/services/",
|
||||||
|
"authModule": {
|
||||||
|
"enabled": true,
|
||||||
|
"login": {
|
||||||
|
"onSuccess": {
|
||||||
|
"script": "/app/modules/login.js",
|
||||||
|
"page": "cdmf.page.dashboard"
|
||||||
|
},
|
||||||
|
"onFail": {
|
||||||
|
"script": "/app/modules/login.js",
|
||||||
|
"page": "cdmf.page.sign-in"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"logout": {
|
||||||
|
"onSuccess": {
|
||||||
|
"page": "cdmf.page.sign-in"
|
||||||
|
},
|
||||||
|
"onFail": {
|
||||||
|
"page": "cdmf.page.dashboard"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"sso": {
|
||||||
|
"enabled": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"errorPages": {
|
||||||
|
"404": "cdmf.page.error-404",
|
||||||
|
"default": "uuf.page.error"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
{
|
||||||
|
"appContext" : "/devicemgt/",
|
||||||
|
"webAgentContext" : "/devicemgt-web-agent/",
|
||||||
|
"apiContext" : "api",
|
||||||
|
"httpsURL" : "%https.ip%",
|
||||||
|
"httpURL" : "%http.ip%",
|
||||||
|
"enrollmentDir": "/emm-web-agent/enrollment",
|
||||||
|
"iOSConfigRoot" : "%https.ip%/ios-enrollment/",
|
||||||
|
"iOSAPIRoot" : "%https.ip%/ios/",
|
||||||
|
"dynamicClientRegistrationEndPoint" : "%https.ip%/dynamic-client-web/register/",
|
||||||
|
"adminService":"%https.ip%",
|
||||||
|
"idPServer":"%https.ip%",
|
||||||
|
"callBackUrl":"%https.ip%/devicemgt_admin",
|
||||||
|
"adminUser":"admin",
|
||||||
|
"adminRole":"admin",
|
||||||
|
"usernameLength":30,
|
||||||
|
"ssoConfiguration" : {
|
||||||
|
"enabled" : false,
|
||||||
|
"issuer" : "devicemgt",
|
||||||
|
"appName" : "devicemgt",
|
||||||
|
"identityProviderURL" : "%https.ip%/sso/samlsso.jag",
|
||||||
|
"responseSigningEnabled" : "true",
|
||||||
|
"keyStorePassword" : "wso2carbon",
|
||||||
|
"identityAlias" : "wso2carbon",
|
||||||
|
"keyStoreName" : "/repository/resources/security/wso2carbon.jks"
|
||||||
|
},
|
||||||
|
"userValidationConfig" : {
|
||||||
|
"usernameJSRegEx" : "^[\\S]{3,30}$",
|
||||||
|
"usernameRegExViolationErrorMsg" : "Provided username is invalid.",
|
||||||
|
"usernameHelpMsg" : "Should be in minimum 3 characters long and do not include any whitespaces.",
|
||||||
|
"firstnameJSRegEx" : "^[\\S]{3,30}$",
|
||||||
|
"firstnameRegExViolationErrorMsg" : "Provided first name is invalid.",
|
||||||
|
"lastnameJSRegEx" : "^[\\S]{3,30}$",
|
||||||
|
"lastnameRegExViolationErrorMsg" : "Provided last name is invalid.",
|
||||||
|
"emailJSRegEx" : "/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/",
|
||||||
|
"emailRegExViolationErrorMsg" : "Provided email is invalid."
|
||||||
|
},
|
||||||
|
"roleValidationConfig" : {
|
||||||
|
"rolenameJSRegEx" : "^[\\S]{3,30}$",
|
||||||
|
"rolenameRegExViolationErrorMsg" : "Provided role name is invalid.",
|
||||||
|
"rolenameHelpMsg" : "should be in minimum 3 characters long and do not include any whitespaces."
|
||||||
|
},
|
||||||
|
"generalConfig" : {
|
||||||
|
"host" : "https://localhost:9443",
|
||||||
|
"companyName" : "WSO2 Carbon Device Manager",
|
||||||
|
"browserTitle" : "WSO2 Device Manager",
|
||||||
|
"copyrightPrefix" : "\u00A9 %date-year%, ",
|
||||||
|
"copyrightOwner" : "WSO2 Inc.",
|
||||||
|
"copyrightOwnersSite" : "http://www.wso2.org",
|
||||||
|
"copyrightSuffix" : " All Rights Reserved."
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var config = function () {
|
||||||
|
var conf = application.get("PINCH_CONFIG");
|
||||||
|
if (!conf) {
|
||||||
|
var pinch = require('/app/modules/pinch.min.js').pinch;
|
||||||
|
var server = require('carbon').server;
|
||||||
|
var config = require('/app/conf/config.json');
|
||||||
|
pinch(config, /^/, function (path, key, value) {
|
||||||
|
if ((typeof value === 'string') && value.indexOf('%https.ip%') > -1) {
|
||||||
|
return value.replace('%https.ip%', server.address("https"));
|
||||||
|
} else if ((typeof value === 'string') && value.indexOf('%http.ip%') > -1) {
|
||||||
|
return value.replace('%http.ip%', server.address("http"));
|
||||||
|
} else if ((typeof value === 'string') && value.indexOf('%date-year%') > -1) {
|
||||||
|
var year = new Date().getFullYear();
|
||||||
|
return value.replace("%date-year%", year);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
});
|
||||||
|
application.put("PINCH_CONFIG", config);
|
||||||
|
conf = config;
|
||||||
|
}
|
||||||
|
return conf;
|
||||||
|
};
|
@ -0,0 +1,64 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
|
||||||
|
<title>{{#defineZone "title"}}WSO2 Template{{/defineZone}}</title>
|
||||||
|
{{defineZone "favicon"}}
|
||||||
|
{{defineZone "topCss"}}
|
||||||
|
{{defineZone "topJs"}}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<!--modal-->
|
||||||
|
<div class="wr-modalpopup">
|
||||||
|
<div class="modalpopup-container">
|
||||||
|
<div class="modalpopup-close-btn" onclick="hidePopup();">
|
||||||
|
<span class="fw-stack">
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
<i class="fw fw-left-arrow fw-stack-1x"></i>
|
||||||
|
</span>
|
||||||
|
GO BACK
|
||||||
|
</div>
|
||||||
|
<div class="modalpopup-content"><!-- dynamic content --></div>
|
||||||
|
</div>
|
||||||
|
<div class="modalpopup-bg"></div>
|
||||||
|
</div>
|
||||||
|
<!--modal-->
|
||||||
|
|
||||||
|
<!-- header -->
|
||||||
|
{{defineZone "header"}}
|
||||||
|
<!-- /header -->
|
||||||
|
|
||||||
|
<!-- navbars -->
|
||||||
|
<div class="navbar-wrapper">
|
||||||
|
{{defineZone "navbars"}}
|
||||||
|
</div>
|
||||||
|
<!-- /navbars -->
|
||||||
|
|
||||||
|
<!-- sidepanes -->
|
||||||
|
{{defineZone "sidePanes"}}
|
||||||
|
<!-- /sidepanes -->
|
||||||
|
|
||||||
|
<!-- page-content-wrapper -->
|
||||||
|
<div class="page-content-wrapper">
|
||||||
|
{{defineZone "contentTitle"}}
|
||||||
|
<div class="container-fluid body-wrapper">
|
||||||
|
{{defineZone "content"}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- /page-content-wrapper -->
|
||||||
|
|
||||||
|
<!-- footer -->
|
||||||
|
<footer class="footer">
|
||||||
|
<div class="container-fluid">
|
||||||
|
{{defineZone "footer"}}
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
<!-- /footer -->
|
||||||
|
|
||||||
|
{{defineZone "bottomJs"}}
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var apiWrapperUtil = function () {
|
||||||
|
var module = {};
|
||||||
|
var tokenUtil = require("/app/modules/util.js").util;
|
||||||
|
var constants = require("/app/modules/constants.js");
|
||||||
|
|
||||||
|
module.refreshToken = function () {
|
||||||
|
var tokenPair = session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER);
|
||||||
|
var clientData = session.get(constants.ENCODED_CLIENT_KEYS_IDENTIFIER);
|
||||||
|
tokenPair = tokenUtil.refreshToken(tokenPair, clientData);
|
||||||
|
session.put(constants.ACCESS_TOKEN_PAIR_IDENTIFIER, tokenPair);
|
||||||
|
};
|
||||||
|
module.setupAccessTokenPair = function (type, properties) {
|
||||||
|
var tokenPair;
|
||||||
|
var clientData = tokenUtil.getDyanmicCredentials(properties);
|
||||||
|
var encodedClientKeys = tokenUtil.encode(clientData.clientId + ":" + clientData.clientSecret);
|
||||||
|
session.put(constants.ENCODED_CLIENT_KEYS_IDENTIFIER, encodedClientKeys);
|
||||||
|
if (type == "password") {
|
||||||
|
tokenPair =
|
||||||
|
tokenUtil.getTokenWithPasswordGrantType(properties.username, encodeURIComponent(properties.password), encodedClientKeys);
|
||||||
|
} else if (type == "saml") {
|
||||||
|
tokenPair = tokenUtil.
|
||||||
|
getTokenWithSAMLGrantType(properties.samlToken, encodedClientKeys, "PRODUCTION");
|
||||||
|
}
|
||||||
|
session.put(constants.ACCESS_TOKEN_PAIR_IDENTIFIER, tokenPair);
|
||||||
|
};
|
||||||
|
return module;
|
||||||
|
}();
|
@ -0,0 +1,328 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This backendServiceInvoker contains the wrappers for back end jaggary calls.
|
||||||
|
*/
|
||||||
|
var backendServiceInvoker = function () {
|
||||||
|
var log = new Log("/app/modules/backend-service-invoker.js")
|
||||||
|
var publicXMLHTTPInvokers = {};
|
||||||
|
var privateMethods = {};
|
||||||
|
var publicWSInvokers = {};
|
||||||
|
var publicHTTPClientInvokers = {};
|
||||||
|
var IS_OAUTH_ENABLED = true;
|
||||||
|
var TOKEN_EXPIRED = "Access token expired";
|
||||||
|
var TOKEN_INVALID = "Invalid input. Access token validation failed";
|
||||||
|
var constants = require("/app/modules/constants.js");
|
||||||
|
var tokenUtil = require("/app/modules/api-wrapper-util.js").apiWrapperUtil;
|
||||||
|
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This methoad reads the token pair from the session and return the access token.
|
||||||
|
* If the token pair s not set in the session this will send a redirect to the login page.
|
||||||
|
*/
|
||||||
|
privateMethods.getAccessToken = function () {
|
||||||
|
var tokenPair = session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER);
|
||||||
|
if (tokenPair) {
|
||||||
|
return tokenPair.accessToken;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method add Oauth authentication header to outgoing XMLHTTP Requests if Oauth authentication is enabled.
|
||||||
|
* @param method HTTP request type.
|
||||||
|
* @param url target url.
|
||||||
|
* @param payload payload/data which need to be send.
|
||||||
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
|
* @param count a counter which hold the number of recursive execution
|
||||||
|
*/
|
||||||
|
privateMethods.execute = function (method, url, successCallback, errorCallback, payload, count) {
|
||||||
|
var xmlHttpRequest = new XMLHttpRequest();
|
||||||
|
xmlHttpRequest.open(method, url);
|
||||||
|
xmlHttpRequest.setRequestHeader(constants.CONTENT_TYPE_IDENTIFIER, constants.APPLICATION_JSON);
|
||||||
|
xmlHttpRequest.setRequestHeader(constants.ACCEPT_IDENTIFIER, constants.APPLICATION_JSON);
|
||||||
|
if (IS_OAUTH_ENABLED) {
|
||||||
|
var accessToken = privateMethods.getAccessToken();
|
||||||
|
if (!accessToken) {
|
||||||
|
response.sendRedirect(devicemgtProps["httpsURL"] + "/devicemgt/login");
|
||||||
|
} else {
|
||||||
|
xmlHttpRequest.setRequestHeader(constants.AUTHORIZATION_HEADER, constants.BEARER_PREFIX + accessToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (payload) {
|
||||||
|
xmlHttpRequest.send(payload);
|
||||||
|
} else {
|
||||||
|
xmlHttpRequest.send();
|
||||||
|
}
|
||||||
|
log.debug("Service Invoker-URL: " + url);
|
||||||
|
log.debug("Service Invoker-Method: " + method);
|
||||||
|
|
||||||
|
if ((xmlHttpRequest.status >= 200 && xmlHttpRequest.status < 300) || xmlHttpRequest.status == 302) {
|
||||||
|
if (xmlHttpRequest.responseText != null) {
|
||||||
|
return successCallback(parse(xmlHttpRequest.responseText));
|
||||||
|
} else {
|
||||||
|
return successCallback({"statusCode": 200, "messageFromServer": "Operation Completed"});
|
||||||
|
}
|
||||||
|
} else if (xmlHttpRequest.status == 401 && (xmlHttpRequest.responseText == TOKEN_EXPIRED ||
|
||||||
|
xmlHttpRequest.responseText == TOKEN_INVALID ) && count < 5) {
|
||||||
|
tokenUtil.refreshToken();
|
||||||
|
return privateMethods.execute(method, url, successCallback, errorCallback, payload, (count + 1));
|
||||||
|
} else if (xmlHttpRequest.status == 500) {
|
||||||
|
return errorCallback(xmlHttpRequest);
|
||||||
|
} else {
|
||||||
|
return errorCallback(xmlHttpRequest);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method add Oauth authentication header to outgoing XMLHTTP Requests if Oauth authentication is enabled.
|
||||||
|
* @param method HTTP request type.
|
||||||
|
* @param url target url.
|
||||||
|
* @param payload payload/data which need to be send.
|
||||||
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
|
*/
|
||||||
|
privateMethods.initiateXMLHTTPRequest = function (method, url, successCallback, errorCallback, payload) {
|
||||||
|
if (privateMethods.getAccessToken()) {
|
||||||
|
return privateMethods.execute(method, url, successCallback, errorCallback, payload, 0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method add Oauth authentication header to outgoing HTTPClient Requests if Oauth authentication is enabled.
|
||||||
|
* @param method HTTP request type.
|
||||||
|
* @param url target url.
|
||||||
|
* @param payload payload/data which need to be send.
|
||||||
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
|
*/
|
||||||
|
privateMethods.initiateHTTPClientRequest = function (method, url, successCallback, errorCallback, payload) {
|
||||||
|
var HttpClient = Packages.org.apache.commons.httpclient.HttpClient;
|
||||||
|
var httpMethodObject;
|
||||||
|
switch (method) {
|
||||||
|
case constants.HTTP_POST:
|
||||||
|
var PostMethod = Packages.org.apache.commons.httpclient.methods.PostMethod;
|
||||||
|
httpMethodObject = new PostMethod(url);
|
||||||
|
break;
|
||||||
|
case constants.HTTP_PUT:
|
||||||
|
var PutMethod = Packages.org.apache.commons.httpclient.methods.PutMethod;
|
||||||
|
httpMethodObject = new PutMethod(url);
|
||||||
|
break;
|
||||||
|
case constants.HTTP_GET:
|
||||||
|
var GetMethod = Packages.org.apache.commons.httpclient.methods.GetMethod;
|
||||||
|
httpMethodObject = new GetMethod(url);
|
||||||
|
break;
|
||||||
|
case constants.HTTP_DELETE:
|
||||||
|
var DeleteMethod = Packages.org.apache.commons.httpclient.methods.DeleteMethod;
|
||||||
|
httpMethodObject = new DeleteMethod(url);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Invalid HTTP request type: " + method);
|
||||||
|
}
|
||||||
|
var Header = Packages.org.apache.commons.httpclient.Header;
|
||||||
|
var header = new Header();
|
||||||
|
header.setName(constants.CONTENT_TYPE_IDENTIFIER);
|
||||||
|
header.setValue(constants.APPLICATION_JSON);
|
||||||
|
httpMethodObject.addRequestHeader(header);
|
||||||
|
header = new Header();
|
||||||
|
header.setName(constants.ACCEPT_IDENTIFIER);
|
||||||
|
header.setValue(constants.APPLICATION_JSON);
|
||||||
|
httpMethodObject.addRequestHeader(header);
|
||||||
|
if (IS_OAUTH_ENABLED) {
|
||||||
|
var accessToken = privateMethods.getAccessToken();
|
||||||
|
if (accessToken) {
|
||||||
|
header = new Header();
|
||||||
|
header.setName(constants.AUTHORIZATION_HEADER);
|
||||||
|
header.setValue(constants.BEARER_PREFIX + accessToken);
|
||||||
|
httpMethodObject.addRequestHeader(header);
|
||||||
|
} else {
|
||||||
|
response.sendRedirect(devicemgtProps["httpsURL"] + "/devicemgt/login");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
var stringRequestEntity = new StringRequestEntity(stringify(payload));
|
||||||
|
httpMethodObject.setRequestEntity(stringRequestEntity);
|
||||||
|
var client = new HttpClient();
|
||||||
|
try {
|
||||||
|
client.executeMethod(httpMethodObject);
|
||||||
|
var status = httpMethodObject.getStatusCode();
|
||||||
|
if (status == 200) {
|
||||||
|
return successCallback(httpMethodObject.getResponseBody());
|
||||||
|
} else {
|
||||||
|
return errorCallback(httpMethodObject.getResponseBody());
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return errorCallback(response);
|
||||||
|
} finally {
|
||||||
|
method.releaseConnection();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method add Oauth authentication header to outgoing WS Requests if Oauth authentication is enabled.
|
||||||
|
* @param action
|
||||||
|
* @param endpoint service end point to be triggered.
|
||||||
|
* @param payload soap payload which need to be send.
|
||||||
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
|
* @param soapVersion soapVersion which need to used.
|
||||||
|
*/
|
||||||
|
privateMethods.initiateWSRequest = function (action, endpoint, successCallback, errorCallback, soapVersion, payload) {
|
||||||
|
var ws = require('ws');
|
||||||
|
var wsRequest = new ws.WSRequest();
|
||||||
|
var options = new Array();
|
||||||
|
if (IS_OAUTH_ENABLED) {
|
||||||
|
var accessToken = privateMethods.getAccessToken();
|
||||||
|
if (accessToken) {
|
||||||
|
var authenticationHeaderName = String(constants.AUTHORIZATION_HEADER);
|
||||||
|
var authenticationHeaderValue = String(constants.BEARER_PREFIX + accessToken);
|
||||||
|
var headers = [];
|
||||||
|
var oAuthAuthenticationData = {};
|
||||||
|
oAuthAuthenticationData.name = authenticationHeaderName;
|
||||||
|
oAuthAuthenticationData.value = authenticationHeaderValue;
|
||||||
|
headers.push(oAuthAuthenticationData);
|
||||||
|
options.HTTPHeaders = headers;
|
||||||
|
} else {
|
||||||
|
response.sendRedirect(devicemgtProps["httpsURL"] + "/devicemgt/login");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
options.useSOAP = soapVersion;
|
||||||
|
options.useWSA = constants.WEB_SERVICE_ADDRESSING_VERSION;
|
||||||
|
options.action = action;
|
||||||
|
var wsResponse;
|
||||||
|
try {
|
||||||
|
wsRequest.open(options, endpoint, false);
|
||||||
|
if (payload) {
|
||||||
|
wsRequest.send(payload);
|
||||||
|
} else {
|
||||||
|
wsRequest.send();
|
||||||
|
}
|
||||||
|
wsResponse = wsRequest.responseE4X;
|
||||||
|
} catch (e) {
|
||||||
|
return errorCallback(e);
|
||||||
|
}
|
||||||
|
return successCallback(wsResponse);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method invokes return initiateXMLHttpRequest for get calls
|
||||||
|
* @param url target url.
|
||||||
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
|
*/
|
||||||
|
publicXMLHTTPInvokers.get = function (url, successCallback, errorCallback) {
|
||||||
|
return privateMethods.initiateXMLHTTPRequest(constants.HTTP_GET, url, successCallback, errorCallback);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method invokes return initiateXMLHttpRequest for post calls
|
||||||
|
* @param url target url.
|
||||||
|
* @param payload payload/data which need to be send.
|
||||||
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
|
*/
|
||||||
|
publicXMLHTTPInvokers.post = function (url, payload, successCallback, errorCallback) {
|
||||||
|
return privateMethods.initiateXMLHTTPRequest(constants.HTTP_POST, url, successCallback, errorCallback, payload);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method invokes return initiateXMLHttpRequest for put calls
|
||||||
|
* @param url target url.
|
||||||
|
* @param payload payload/data which need to be send.
|
||||||
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
|
*/
|
||||||
|
publicXMLHTTPInvokers.put = function (url, payload, successCallback, errorCallback) {
|
||||||
|
return privateMethods.initiateXMLHTTPRequest(constants.HTTP_PUT, url, successCallback, errorCallback, payload);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method invokes return initiateXMLHttpRequest for delete calls
|
||||||
|
* @param url target url.
|
||||||
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
|
*/
|
||||||
|
publicXMLHTTPInvokers.delete = function (url, successCallback, errorCallback) {
|
||||||
|
return privateMethods.initiateXMLHTTPRequest(constants.HTTP_DELETE, url, successCallback, errorCallback);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method invokes return initiateWSRequest for soap calls
|
||||||
|
* @param endpoint service end point to be triggered.
|
||||||
|
* @param payload soap payload which need to be send.
|
||||||
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
|
* @param soapVersion soapVersion which need to used.
|
||||||
|
*/
|
||||||
|
publicWSInvokers.soapRequest = function (action, endpoint, payload, successCallback, errorCallback, soapVersion) {
|
||||||
|
return privateMethods.initiateWSRequest(action, endpoint, successCallback, errorCallback, soapVersion, payload);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method invokes return initiateHTTPClientRequest for get calls
|
||||||
|
* @param url target url.
|
||||||
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
|
*/
|
||||||
|
publicHTTPClientInvokers.get = function (url, successCallback, errorCallback) {
|
||||||
|
return privateMethods.initiateHTTPClientRequest(constants.HTTP_GET, url, successCallback, errorCallback);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method invokes return initiateHTTPClientRequest for post calls
|
||||||
|
* @param url target url.
|
||||||
|
* @param payload payload/data which need to be send.
|
||||||
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
|
*/
|
||||||
|
publicHTTPClientInvokers.post = function (url, payload, successCallback, errorCallback) {
|
||||||
|
return privateMethods.
|
||||||
|
initiateHTTPClientRequest(constants.HTTP_POST, url, successCallback, errorCallback, payload);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method invokes return initiateHTTPClientRequest for put calls
|
||||||
|
* @param url target url.
|
||||||
|
* @param payload payload/data which need to be send.
|
||||||
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
|
*/
|
||||||
|
publicHTTPClientInvokers.put = function (url, payload, successCallback, errorCallback) {
|
||||||
|
return privateMethods.initiateHTTPClientRequest(constants.HTTP_PUT, url, successCallback, errorCallback, payload);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method invokes return initiateHTTPClientRequest for delete calls
|
||||||
|
* @param url target url.
|
||||||
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
|
*/
|
||||||
|
publicHTTPClientInvokers.delete = function (url, successCallback, errorCallback) {
|
||||||
|
return privateMethods.initiateHTTPClientRequest(constants.HTTP_DELETE, url, successCallback, errorCallback);
|
||||||
|
};
|
||||||
|
|
||||||
|
var publicInvokers = {};
|
||||||
|
publicInvokers.XMLHttp = publicXMLHTTPInvokers;
|
||||||
|
publicInvokers.WS = publicWSInvokers;
|
||||||
|
publicInvokers.HttpClient = publicHTTPClientInvokers;
|
||||||
|
return publicInvokers;
|
||||||
|
}();
|
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var WEB_APP_TITLE = "WSO2 CDM";
|
||||||
|
var WEB_APP_CONTEXT = "/devicemgt";
|
||||||
|
var ADMIN_SERVICE_CONTEXT = "/devicemgt_admin";
|
||||||
|
var USER_SESSION_KEY = "_UUF_USER";
|
||||||
|
var UNSPECIFIED = "Unspecified";
|
||||||
|
var httpURL = "httpURL";
|
||||||
|
var httpsURL = "httpsURL";
|
||||||
|
|
||||||
|
var DEVICE_IDENTIFIER = "deviceIdentifier";
|
||||||
|
var DEVICE_NAME = "name";
|
||||||
|
var DEVICE_OWNERSHIP = "ownership";
|
||||||
|
var DEVICE_OWNER = "owner";
|
||||||
|
var DEVICE_TYPE = "type";
|
||||||
|
var DEVICE_VENDOR = "vendor";
|
||||||
|
var DEVICE_MODEL = "model";
|
||||||
|
var DEVICE_PRODUCT = "PRODUCT";
|
||||||
|
var DEVICE_OS_VERSION = "osVersion";
|
||||||
|
var DEVICE_PROPERTIES = "properties";
|
||||||
|
var DEVICE_ENROLLMENT_INFO = "enrolmentInfo";
|
||||||
|
var DEVICE_STATUS = "status";
|
||||||
|
|
||||||
|
var FEATURE_NAME = "featureName";
|
||||||
|
var FEATURE_DESCRIPTION = "featureDescription";
|
||||||
|
|
||||||
|
var PLATFORM_ANDROID = "android";
|
||||||
|
var PLATFORM_WINDOWS = "windows";
|
||||||
|
var PLATFORM_IOS = "ios";
|
||||||
|
|
||||||
|
var LANGUAGE_US = "en_US";
|
||||||
|
|
||||||
|
var VENDOR_APPLE = "Apple";
|
||||||
|
var ERRORS = {
|
||||||
|
"USER_NOT_FOUND": "USER_NOT_FOUND"
|
||||||
|
};
|
||||||
|
|
||||||
|
var USER_STORES_NOISY_CHAR = "\"";
|
||||||
|
var USER_STORES_SPLITTING_CHAR = "\\n";
|
||||||
|
var USER_STORE_CONFIG_ADMIN_SERVICE_END_POINT =
|
||||||
|
"/services/UserStoreConfigAdminService.UserStoreConfigAdminServiceHttpsSoap12Endpoint/";
|
||||||
|
|
||||||
|
var SOAP_VERSION = 1.2;
|
||||||
|
var WEB_SERVICE_ADDRESSING_VERSION = 1.0;
|
||||||
|
var ACCESS_TOKEN_PAIR_IDENTIFIER = "accessTokenPair";
|
||||||
|
var ENCODED_CLIENT_KEYS_IDENTIFIER = "encodedClientKey";
|
||||||
|
var CONTENT_TYPE_IDENTIFIER = "Content-Type";
|
||||||
|
var APPLICATION_JSON = "application/json";
|
||||||
|
var ACCEPT_IDENTIFIER = "Accept";
|
||||||
|
var AUTHORIZATION_HEADER= "Authorization";
|
||||||
|
var BEARER_PREFIX = "Bearer ";
|
||||||
|
var HTTP_GET = "GET";
|
||||||
|
var HTTP_POST = "POST";
|
||||||
|
var HTTP_PUT = "PUT";
|
||||||
|
var HTTP_DELETE = "DELETE";
|
||||||
|
|
||||||
|
var MQTT_QUEUE_CONFIG_NAME = "MQTT";
|
||||||
|
|
||||||
|
var HTTP_CONFLICT = 409;
|
||||||
|
var HTTP_CREATED = 201;
|
@ -0,0 +1,450 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var deviceModule;
|
||||||
|
deviceModule = function () {
|
||||||
|
var log = new Log("/app/modules/device.js");
|
||||||
|
|
||||||
|
var utility = require('/app/modules/utility.js').utility;
|
||||||
|
var constants = require('/app/modules/constants.js');
|
||||||
|
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
||||||
|
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
|
||||||
|
|
||||||
|
var ArrayList = Packages.java.util.ArrayList;
|
||||||
|
var Properties = Packages.java.util.Properties;
|
||||||
|
var DeviceIdentifier = Packages.org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
var DeviceManagerUtil = Packages.org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||||
|
var SimpleOperation = Packages.org.wso2.carbon.device.mgt.core.operation.mgt.SimpleOperation;
|
||||||
|
var ConfigOperation = Packages.org.wso2.carbon.device.mgt.core.operation.mgt.ConfigOperation;
|
||||||
|
var CommandOperation = Packages.org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
||||||
|
|
||||||
|
var deviceManagementService = utility.getDeviceManagementService();
|
||||||
|
|
||||||
|
var publicMethods = {};
|
||||||
|
var privateMethods = {};
|
||||||
|
|
||||||
|
var deviceCloudService = devicemgtProps["httpsURL"] + "/common/device_manager";
|
||||||
|
|
||||||
|
privateMethods.validateAndReturn = function (value) {
|
||||||
|
return (value == undefined || value == null) ? constants.UNSPECIFIED : value;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
publicMethods.listDevices = function () {
|
||||||
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
var utility = require('/app/modules/utility.js').utility;
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants.ERRORS.USER_NOT_FOUND;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var deviceManagementService = utility.getDeviceManagementService();
|
||||||
|
var devices = deviceManagementService.getAllDevices();
|
||||||
|
var deviceList = [];
|
||||||
|
var i, device, propertiesList, deviceObject;
|
||||||
|
for (i = 0; i < devices.size(); i++) {
|
||||||
|
device = devices.get(i);
|
||||||
|
propertiesList = DeviceManagerUtil.convertDevicePropertiesToMap(device.getProperties());
|
||||||
|
|
||||||
|
deviceObject = {};
|
||||||
|
deviceObject[constants.DEVICE_IDENTIFIER] =
|
||||||
|
privateMethods.validateAndReturn(device.getDeviceIdentifier());
|
||||||
|
deviceObject[constants.DEVICE_NAME] =
|
||||||
|
privateMethods.validateAndReturn(device.getName());
|
||||||
|
deviceObject[constants.DEVICE_OWNERSHIP] =
|
||||||
|
privateMethods.validateAndReturn(device.getEnrolmentInfo().getOwnership());
|
||||||
|
deviceObject[constants.DEVICE_OWNER] =
|
||||||
|
privateMethods.validateAndReturn(device.getEnrolmentInfo().getOwner());
|
||||||
|
deviceObject[constants.DEVICE_TYPE] =
|
||||||
|
privateMethods.validateAndReturn(device.getType());
|
||||||
|
deviceObject[constants.DEVICE_PROPERTIES] = {};
|
||||||
|
if (device.getType() == constants.PLATFORM_IOS) {
|
||||||
|
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_MODEL] =
|
||||||
|
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_PRODUCT));
|
||||||
|
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_VENDOR] = constants.VENDOR_APPLE;
|
||||||
|
} else {
|
||||||
|
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_MODEL] =
|
||||||
|
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_MODEL));
|
||||||
|
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_VENDOR] =
|
||||||
|
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_VENDOR));
|
||||||
|
}
|
||||||
|
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_OS_VERSION] =
|
||||||
|
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_OS_VERSION));
|
||||||
|
|
||||||
|
deviceList.push(deviceObject);
|
||||||
|
}
|
||||||
|
return deviceList;
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
publicMethods.listDevicesForUser = function (username) {
|
||||||
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
var utility = require('/app/modules/utility.js').utility;
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants.ERRORS.USER_NOT_FOUND;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var deviceManagementService = utility.getDeviceManagementService();
|
||||||
|
var devices = deviceManagementService.getDevicesOfUser(username);
|
||||||
|
var deviceList = [];
|
||||||
|
var i, device, propertiesList, deviceObject;
|
||||||
|
for (i = 0; i < devices.size(); i++) {
|
||||||
|
device = devices.get(i);
|
||||||
|
propertiesList = DeviceManagerUtil.convertDevicePropertiesToMap(device.getProperties());
|
||||||
|
|
||||||
|
deviceObject = {};
|
||||||
|
deviceObject[constants.DEVICE_IDENTIFIER] =
|
||||||
|
privateMethods.validateAndReturn(device.getDeviceIdentifier());
|
||||||
|
deviceObject[constants.DEVICE_NAME] =
|
||||||
|
privateMethods.validateAndReturn(device.getName());
|
||||||
|
deviceObject[constants.DEVICE_OWNERSHIP] =
|
||||||
|
privateMethods.validateAndReturn(device.getEnrolmentInfo().getOwnership());
|
||||||
|
deviceObject[constants.DEVICE_OWNER] =
|
||||||
|
privateMethods.validateAndReturn(device.getEnrolmentInfo().getOwner());
|
||||||
|
deviceObject[constants.DEVICE_TYPE] =
|
||||||
|
privateMethods.validateAndReturn(device.getType());
|
||||||
|
deviceObject[constants.DEVICE_PROPERTIES] = {};
|
||||||
|
if (device.getType() == constants.PLATFORM_IOS) {
|
||||||
|
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_MODEL] =
|
||||||
|
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_PRODUCT));
|
||||||
|
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_VENDOR] = constants.VENDOR_APPLE;
|
||||||
|
} else {
|
||||||
|
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_MODEL] =
|
||||||
|
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_MODEL));
|
||||||
|
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_VENDOR] =
|
||||||
|
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_VENDOR));
|
||||||
|
}
|
||||||
|
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_OS_VERSION] =
|
||||||
|
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_OS_VERSION));
|
||||||
|
|
||||||
|
deviceList.push(deviceObject);
|
||||||
|
}
|
||||||
|
return deviceList;
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
Get the supported features by the device type
|
||||||
|
*/
|
||||||
|
publicMethods.getFeatures = function (deviceType) {
|
||||||
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
var utility = require('/app/modules/utility.js').utility;
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants.ERRORS.USER_NOT_FOUND;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var deviceManagementService = utility.getDeviceManagementService();
|
||||||
|
var features = deviceManagementService.getFeatureManager(deviceType).getFeatures();
|
||||||
|
var featuresConverted = {};
|
||||||
|
if (features) {
|
||||||
|
var i, feature, featureObject;
|
||||||
|
for (i = 0; i < features.size(); i++) {
|
||||||
|
feature = features.get(i);
|
||||||
|
featureObject = {};
|
||||||
|
featureObject[constants.FEATURE_NAME] = feature.getName();
|
||||||
|
featureObject[constants.FEATURE_DESCRIPTION] = feature.getDescription();
|
||||||
|
featuresConverted[feature.getName()] = featureObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return featuresConverted;
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
publicMethods.performOperation = function (devices, operation) {
|
||||||
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
var utility = require('/app/modules/utility.js').utility;
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants.ERRORS.USER_NOT_FOUND;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var deviceManagementService = utility.getDeviceManagementService();
|
||||||
|
var operationInstance;
|
||||||
|
if (operation.type == "COMMAND") {
|
||||||
|
operationInstance = new CommandOperation();
|
||||||
|
} else if (operation.type == "CONFIG") {
|
||||||
|
operationInstance = new ConfigOperation();
|
||||||
|
} else {
|
||||||
|
operationInstance = new SimpleOperation();
|
||||||
|
}
|
||||||
|
operationInstance.setCode(operation.featureName);
|
||||||
|
var props = new Properties();
|
||||||
|
var i, object;
|
||||||
|
for (i = 0; i < operation.properties.length; i++) {
|
||||||
|
object = properties[i];
|
||||||
|
props.setProperty(object.key, object.value);
|
||||||
|
}
|
||||||
|
operationInstance.setProperties(props);
|
||||||
|
var deviceList = new ArrayList();
|
||||||
|
var j, device, deviceIdentifier;
|
||||||
|
for (j = 0; j < devices.length; i++) {
|
||||||
|
device = devices[j];
|
||||||
|
deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setId(device.id);
|
||||||
|
deviceIdentifier.setType(device.type);
|
||||||
|
deviceList.add(deviceIdentifier);
|
||||||
|
}
|
||||||
|
deviceManagementService.addOperation(operationInstance, deviceList);
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
privateMethods.getDevice = function (type, deviceId) {
|
||||||
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
var utility = require('/app/modules/utility.js').utility;
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants.ERRORS.USER_NOT_FOUND;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var deviceManagementService = utility.getDeviceManagementService();
|
||||||
|
var deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setType(type);
|
||||||
|
deviceIdentifier.setId(deviceId);
|
||||||
|
return deviceManagementService.getDevice(deviceIdentifier);
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Updated
|
||||||
|
*/
|
||||||
|
publicMethods.viewDevice = function (deviceType, deviceId) {
|
||||||
|
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants["ERRORS"]["USER_NOT_FOUND"];
|
||||||
|
}
|
||||||
|
var utility = require('/app/modules/utility.js')["utility"];
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
|
||||||
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/view?type=" + deviceType + "&id=" + deviceId;
|
||||||
|
var dataNew = serviceInvokers.XMLHttp.get(
|
||||||
|
url, function (responsePayload) {
|
||||||
|
var device = responsePayload.responseContent;
|
||||||
|
if (device) {
|
||||||
|
var propertiesList = device["properties"];
|
||||||
|
var properties = {};
|
||||||
|
for (var i = 0; i < propertiesList.length; i++) {
|
||||||
|
properties[propertiesList[i]["name"]] =
|
||||||
|
propertiesList[i]["value"];
|
||||||
|
}
|
||||||
|
var deviceObject = {};
|
||||||
|
deviceObject[constants["DEVICE_IDENTIFIER"]] = device["deviceIdentifier"];
|
||||||
|
deviceObject[constants["DEVICE_NAME"]] = device["name"];
|
||||||
|
deviceObject[constants["DEVICE_OWNERSHIP"]] = device["enrolmentInfo"]["ownership"];
|
||||||
|
deviceObject[constants["DEVICE_OWNER"]] = device["enrolmentInfo"]["owner"];
|
||||||
|
deviceObject[constants["DEVICE_STATUS"]] = device["enrolmentInfo"]["status"];
|
||||||
|
deviceObject[constants["DEVICE_TYPE"]] = device["type"];
|
||||||
|
if (device["type"] == constants["PLATFORM_IOS"]) {
|
||||||
|
properties[constants["DEVICE_MODEL"]] = properties[constants["DEVICE_PRODUCT"]];
|
||||||
|
delete properties[constants["DEVICE_PRODUCT"]];
|
||||||
|
properties[constants["DEVICE_VENDOR"]] = constants["VENDOR_APPLE"];
|
||||||
|
}
|
||||||
|
deviceObject[constants["DEVICE_PROPERTIES"]] = properties;
|
||||||
|
return deviceObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
,
|
||||||
|
function (responsePayload) {
|
||||||
|
var response = {};
|
||||||
|
response["status"] = "error";
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return dataNew;
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Updated
|
||||||
|
*/
|
||||||
|
publicMethods.getLicense = function (deviceType) {
|
||||||
|
var url;
|
||||||
|
var license;
|
||||||
|
if (deviceType == "windows") {
|
||||||
|
url = devicemgtProps["httpURL"] + "/mdm-windows-agent/services/device/license";
|
||||||
|
} else if (deviceType == "ios") {
|
||||||
|
url = devicemgtProps["httpsURL"] + "/ios-enrollment/license/";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url != null && url != undefined) {
|
||||||
|
serviceInvokers.XMLHttp.get(url, function (responsePayload) {
|
||||||
|
license = responsePayload.text;
|
||||||
|
}, function (responsePayload) {
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return license;
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.getOwnDevices = function () {
|
||||||
|
var listAllDevicesEndPoint = deviceCloudService + "/device/user/" + user.username + "/all";
|
||||||
|
var result = get(listAllDevicesEndPoint, {}, "json");
|
||||||
|
var devices = result.data;
|
||||||
|
var device;
|
||||||
|
for (var d in devices){
|
||||||
|
device = devices[d];
|
||||||
|
device.assetId = publicMethods.getAssetId(device.deviceType);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.getOwnDevicesCount = function () {
|
||||||
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
var listAllDevicesEndPoint = deviceCloudService + "/device/user/" + carbonUser.username + "/all/count";
|
||||||
|
return get(listAllDevicesEndPoint, {}, "json").data;
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.getUnGroupedDevices = function () {
|
||||||
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
var listAllDevicesEndPoint = deviceCloudService + "/device/user/" + carbonUser.username + "/ungrouped";
|
||||||
|
return get(listAllDevicesEndPoint, {}, "json").data;
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.getUnGroupedDevicesCount = function () {
|
||||||
|
var result = publicMethods.getUnGroupedDevices();
|
||||||
|
var devices = result.data;
|
||||||
|
var count = 0;
|
||||||
|
if (devices) {
|
||||||
|
count = devices.length;
|
||||||
|
}
|
||||||
|
result.data = count;
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.getAllPermittedDevices = function () {
|
||||||
|
var groupModule = require("/app/modules/group.js").groupModule;
|
||||||
|
|
||||||
|
var result = publicMethods.getUnGroupedDevices();
|
||||||
|
var unGroupedDevices = result.data;
|
||||||
|
var user_groups = groupModule.getGroups().data;
|
||||||
|
var allDevices = [];
|
||||||
|
var deviceCount = unGroupedDevices.length;
|
||||||
|
for (var g in user_groups) {
|
||||||
|
var deviceInGroup = user_groups[g].devices;
|
||||||
|
deviceCount += deviceInGroup.length;
|
||||||
|
if (deviceInGroup && deviceInGroup.length == 0) {
|
||||||
|
delete user_groups[g]["devices"];
|
||||||
|
}
|
||||||
|
var device;
|
||||||
|
for (var d in deviceInGroup){
|
||||||
|
device = deviceInGroup[d];
|
||||||
|
device.assetId = publicMethods.getAssetId(device.type);
|
||||||
|
}
|
||||||
|
allDevices.push(user_groups[g]);
|
||||||
|
}
|
||||||
|
allDevices.push({id: 0, devices: unGroupedDevices});
|
||||||
|
result.data = allDevices;
|
||||||
|
result.device_count = deviceCount;
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.getDeviceTypes = function () {
|
||||||
|
var deviceTypesEndPoint = deviceCloudService + "/device/type/all";
|
||||||
|
return get(deviceTypesEndPoint, {}, "json");
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.removeDevice = function (deviceType, deviceId) {
|
||||||
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants.ERRORS.USER_NOT_FOUND;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var deviceManagementService = utility.getDeviceManagementService();
|
||||||
|
var deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setType(deviceType);
|
||||||
|
deviceIdentifier.setId(deviceId);
|
||||||
|
return deviceManagementService.disenrollDevice(deviceIdentifier);
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.updateDevice = function (deviceType, deviceId, deviceName) {
|
||||||
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants.ERRORS.USER_NOT_FOUND;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var deviceManagementService = utility.getDeviceManagementService();
|
||||||
|
var deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setType(deviceType);
|
||||||
|
deviceIdentifier.setId(deviceId);
|
||||||
|
var device = deviceManagementService.getDevice(deviceIdentifier);
|
||||||
|
device.setName(deviceName);
|
||||||
|
return deviceManagementService.modifyEnrollment(device);
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return publicMethods;
|
||||||
|
}();
|
@ -0,0 +1,191 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var groupModule = {};
|
||||||
|
(function (groupModule) {
|
||||||
|
var log = new Log("/app/modules/group.js");
|
||||||
|
|
||||||
|
var constants = require('/app/modules/constants.js');
|
||||||
|
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
||||||
|
var utility = require("/app/modules/utility.js").utility;
|
||||||
|
|
||||||
|
var deviceCloudService = devicemgtProps["httpsURL"] + "/common/group_manager";
|
||||||
|
|
||||||
|
var user = session.get(constants.USER_SESSION_KEY);
|
||||||
|
var deviceModule = require("/app/modules/device.js").deviceModule;
|
||||||
|
|
||||||
|
var endPoint, data, response;
|
||||||
|
|
||||||
|
groupModule.addGroup = function (group) {
|
||||||
|
var name = group["name"];
|
||||||
|
var description = group["description"];
|
||||||
|
//URL: POST https://localhost:9443/devicecloud/group_manager/group
|
||||||
|
endPoint = deviceCloudService + "/group";
|
||||||
|
data = {"name": name, "username": user.username, "description": description};
|
||||||
|
return post(endPoint, data, "json");
|
||||||
|
};
|
||||||
|
|
||||||
|
groupModule.updateGroup = function (groupId, group) {
|
||||||
|
var name = group["name"];
|
||||||
|
var description = group["description"];
|
||||||
|
//URL: PUT https://localhost:9443/devicecloud/group_manager/group/id/{groupId}
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId;
|
||||||
|
data = {"name": name, "username": user.username, "description": description};
|
||||||
|
return put(endPoint, data, "json");
|
||||||
|
};
|
||||||
|
|
||||||
|
groupModule.removeGroup = function (groupId) {
|
||||||
|
//URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId}
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId + "?username=" + user.username;
|
||||||
|
return del(endPoint, {}, "json");
|
||||||
|
};
|
||||||
|
|
||||||
|
groupModule.getGroup = function (groupId) {
|
||||||
|
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId;
|
||||||
|
data = {"username": user.username};
|
||||||
|
return get(endPoint, data, "json");
|
||||||
|
};
|
||||||
|
|
||||||
|
groupModule.findGroups = function (name) {
|
||||||
|
//URL: GET https://localhost:9443/devicecloud/group_manager/group/name/{name}
|
||||||
|
endPoint = deviceCloudService + "/group/name/" + name;
|
||||||
|
data = {"username": user.username};
|
||||||
|
return get(endPoint, data, "json");
|
||||||
|
};
|
||||||
|
|
||||||
|
groupModule.getGroups = function () {
|
||||||
|
//URL: GET https://localhost:9443/devicecloud/group_manager/group/all
|
||||||
|
endPoint = deviceCloudService + "/group/user/" + user.username + "/all";
|
||||||
|
data = {"username": user.username};
|
||||||
|
return get(endPoint, data, "json");
|
||||||
|
};
|
||||||
|
|
||||||
|
groupModule.getGroupCount = function () {
|
||||||
|
//URL: GET https://localhost:9443/devicecloud/group_manager/group/all/count
|
||||||
|
endPoint = deviceCloudService + "/group/user/" + user.username + "/all/count";
|
||||||
|
data = {"username": user.username};
|
||||||
|
response = get(endPoint, data, "json");
|
||||||
|
if (response) {
|
||||||
|
return response.data;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
groupModule.shareGroup = function (groupId, shareUser, role) {
|
||||||
|
//URL: POST https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/share
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId + "/share";
|
||||||
|
data = {"username": user.username, "shareUser": shareUser, "role": role};
|
||||||
|
return post(endPoint, data, "json");
|
||||||
|
};
|
||||||
|
|
||||||
|
groupModule.unshareGroup = function (groupId, shareUser, role) {
|
||||||
|
//URL: POST https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/unshare
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId + "/unshare";
|
||||||
|
data = {"username": user.username, "unShareUser": unShareUser, "role": role};
|
||||||
|
return post(endPoint, data, "json");
|
||||||
|
};
|
||||||
|
|
||||||
|
groupModule.addRole = function (groupId, role, permissions) {
|
||||||
|
//URL: POST https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/role
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId + "/role";
|
||||||
|
data = {"username": user.username, "permissions": permissions, "role": role};
|
||||||
|
return post(endPoint, data, "json");
|
||||||
|
};
|
||||||
|
|
||||||
|
groupModule.deleteRole = function (groupId, role) {
|
||||||
|
//URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/role
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId + "/role/" + role;
|
||||||
|
return del(endPoint, {}, "json");
|
||||||
|
};
|
||||||
|
|
||||||
|
groupModule.getGroupRoles = function (groupId) {
|
||||||
|
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/role/all
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId + "/role/all";
|
||||||
|
data = {"username": user.username};
|
||||||
|
return get(endPoint, data, "json");
|
||||||
|
};
|
||||||
|
|
||||||
|
groupModule.getUserRoles = function (groupId, userId) {
|
||||||
|
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/{user}/role/all
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId + "/" + userId + "/role/all";
|
||||||
|
data = {"username": user.username};
|
||||||
|
return get(endPoint, data, "json");
|
||||||
|
};
|
||||||
|
|
||||||
|
groupModule.getRoleMapping = function (groupId, userId) {
|
||||||
|
var allRoles = groupModule.getGroupRoles(groupId).data;
|
||||||
|
var userRolesObj = groupModule.getUserRoles(groupId, userId);
|
||||||
|
var userRoles = userRolesObj.data;
|
||||||
|
var roleMap = [];
|
||||||
|
for (var role in allRoles) {
|
||||||
|
var objRole = {"role": allRoles[role], "assigned": false};
|
||||||
|
for (var usrRole in userRoles) {
|
||||||
|
if (allRoles[role] == userRoles[usrRole]) {
|
||||||
|
objRole.assigned = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
roleMap.push(objRole);
|
||||||
|
}
|
||||||
|
var result = {};
|
||||||
|
result.data = roleMap;
|
||||||
|
result.xhr = userRolesObj.xhr;
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
groupModule.setRoleMapping = function (groupId, userId, roleMap) {
|
||||||
|
var result;
|
||||||
|
for (var role in roleMap) {
|
||||||
|
if (roleMap[role].assigned == true) {
|
||||||
|
result = groupModule.shareGroup(groupId,userId,roleMap[role].role);
|
||||||
|
} else {
|
||||||
|
result = groupModule.unshareGroup(groupId,userId,roleMap[role].role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
groupModule.getUsers = function (groupId) {
|
||||||
|
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/user/all
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId + "/user/all";
|
||||||
|
data = {"username": user.username};
|
||||||
|
return get(endPoint, data, "json");
|
||||||
|
};
|
||||||
|
|
||||||
|
groupModule.getDevices = function (groupId) {
|
||||||
|
var result = groupModule.getGroup(groupId);
|
||||||
|
var group = result.data;
|
||||||
|
if (group) {
|
||||||
|
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/device/all
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId + "/device/all";
|
||||||
|
data = {"username": user.username};
|
||||||
|
result = get(endPoint, data, "json");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
groupModule.assignDevice = function (groupId, deviceId, deviceType) {
|
||||||
|
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/device/assign
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId + "/device/assign";
|
||||||
|
data = {"username": user.username, "deviceId": deviceId, "deviceType": deviceType};
|
||||||
|
return put(endPoint, data, "json");
|
||||||
|
};
|
||||||
|
|
||||||
|
}(groupModule));
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var carbonModule = require("carbon");
|
||||||
|
var devicemgtProps = require("/app/conf/devicemgt-props.js").config();
|
||||||
|
var carbonServer = new carbonModule.server.Server({
|
||||||
|
tenanted: true,
|
||||||
|
url: devicemgtProps["httpsURL"] + "/admin"
|
||||||
|
});
|
||||||
|
application.put("carbonServer", carbonServer);
|
||||||
|
|
||||||
|
var userModule = require("/app/modules/user.js")["userModule"];
|
||||||
|
var utility = require("/app/modules/utility.js")["utility"];
|
||||||
|
utility.insertAppPermissions(userModule, "init");
|
||||||
|
|
||||||
|
var permissions = {
|
||||||
|
'/permission/admin/device-mgt/devices': ['ui.execute'],
|
||||||
|
'/permission/admin/device-mgt/operations': ['ui.execute'],
|
||||||
|
'/permission/admin/device-mgt/policies': ['ui.execute'],
|
||||||
|
'/permission/admin/device-mgt/user': ['ui.execute'],
|
||||||
|
'/permission/admin/device-mgt/users': ['ui.execute'],
|
||||||
|
'/permission/admin/device-mgt/admin/devices': ['ui.execute'],
|
||||||
|
'/permission/admin/device-mgt/admin/groups': ['ui.execute'],
|
||||||
|
'/permission/admin/device-mgt/admin/policies': ['ui.execute']
|
||||||
|
};
|
||||||
|
userModule.addRole("devicemgt-user", ["admin"], permissions);
|
@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This invokerRequestWrapper contains the wrappers for invoker util requests.
|
||||||
|
*/
|
||||||
|
var invokerRequestWrapper = function () {
|
||||||
|
|
||||||
|
var constants = require("/modules/constants.js");
|
||||||
|
var serviceInvokers = require("/modules/backend-service-invoker.js").backendServiceInvoker;
|
||||||
|
|
||||||
|
var publicWrappers = [];
|
||||||
|
|
||||||
|
publicWrappers.initiate = function (method, url, payload) {
|
||||||
|
switch (method) {
|
||||||
|
case constants.HTTP_GET:
|
||||||
|
var response = serviceInvokers.XMLHttp.get(url, function (responsePayload) {
|
||||||
|
var response = {};
|
||||||
|
response.content = responsePayload["responseContent"];
|
||||||
|
response.status = "success";
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
function (responsePayload) {
|
||||||
|
var response = {};
|
||||||
|
response.content = responsePayload;
|
||||||
|
response.status = "error";
|
||||||
|
return response;
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
break;
|
||||||
|
case constants.HTTP_POST:
|
||||||
|
var response = serviceInvokers.XMLHttp.post(url, payload, function (responsePayload) {
|
||||||
|
var response = {};
|
||||||
|
response.content = responsePayload["responseContent"];
|
||||||
|
response.status = "success";
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
function (responsePayload) {
|
||||||
|
var response = {};
|
||||||
|
response.content = responsePayload;
|
||||||
|
response.status = "error";
|
||||||
|
return response;
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
break;
|
||||||
|
case constants.HTTP_PUT:
|
||||||
|
var response = serviceInvokers.XMLHttp.put(url, payload, function (responsePayload) {
|
||||||
|
var response = {};
|
||||||
|
response.content = responsePayload["responseContent"];
|
||||||
|
response.status = "success";
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
function (responsePayload) {
|
||||||
|
var response = {};
|
||||||
|
response.content = responsePayload;
|
||||||
|
response.status = "error";
|
||||||
|
return response;
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
break;
|
||||||
|
case constants.HTTP_DELETE:
|
||||||
|
var response = serviceInvokers.XMLHttp.delete(url, function (responsePayload) {
|
||||||
|
var response = {};
|
||||||
|
response.content = responsePayload["responseContent"];
|
||||||
|
response.status = "success";
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
function (responsePayload) {
|
||||||
|
var response = {};
|
||||||
|
response.content = responsePayload;
|
||||||
|
response.status = "error";
|
||||||
|
return response;
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}();
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var onSuccess;
|
||||||
|
var onFail;
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
var log = new Log("api/user-api.jag");
|
||||||
|
|
||||||
|
onSuccess = function (context) {
|
||||||
|
var utility = require("/app/modules/utility.js").utility;
|
||||||
|
var apiWrapperUtil = require("/app/modules/api-wrapper-util.js").apiWrapperUtil;
|
||||||
|
var userModule = require("/app/modules/user.js").userModule;
|
||||||
|
|
||||||
|
utility.insertAppPermissions(userModule, "login");
|
||||||
|
var properties = {username: context.input.username, password: context.input.password};
|
||||||
|
apiWrapperUtil.setupAccessTokenPair("password", properties);
|
||||||
|
};
|
||||||
|
|
||||||
|
onFail = function (error) {
|
||||||
|
log.error(error.message);
|
||||||
|
}
|
||||||
|
})();
|
@ -0,0 +1,143 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var operationModule = function () {
|
||||||
|
var log = new Log("/app/modules/operation.js");
|
||||||
|
var utility = require('/app/modules/utility.js').utility;
|
||||||
|
var constants = require('/app/modules/constants.js');
|
||||||
|
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
||||||
|
|
||||||
|
var publicMethods = {};
|
||||||
|
var privateMethods = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method reads the token from the Token client and return the access token.
|
||||||
|
* If the token pair s not set in the session this will send a redirect to the login page.
|
||||||
|
*/
|
||||||
|
function getAccessToken(deviceType, owner, deviceId) {
|
||||||
|
var TokenClient = Packages.org.wso2.carbon.device.mgt.iot.apimgt.TokenClient;
|
||||||
|
var accessTokenClient = new TokenClient(deviceType);
|
||||||
|
var accessTokenInfo = accessTokenClient.getAccessToken(owner, deviceId);
|
||||||
|
return accessTokenInfo.getAccess_token();
|
||||||
|
}
|
||||||
|
|
||||||
|
privateMethods.getOperationsFromFeatures = function (deviceType, operationType) {
|
||||||
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/features/" + deviceType;
|
||||||
|
var featuresList = serviceInvokers.XMLHttp.get(url, function (responsePayload) {
|
||||||
|
var features = responsePayload.responseContent;
|
||||||
|
var featureList = [];
|
||||||
|
var feature;
|
||||||
|
for (var i = 0; i < features.size(); i++) {
|
||||||
|
feature = {};
|
||||||
|
if (features.get(i).getType() != operationType) {
|
||||||
|
continue;
|
||||||
|
} else if (features.get(i).getType() == 'monitor') {
|
||||||
|
var analyticStreams = utility.getDeviceTypeConfig(deviceType)["analyticStreams"];
|
||||||
|
if (analyticStreams) {
|
||||||
|
for (var stream in analyticStreams) {
|
||||||
|
if (analyticStreams[stream].name == features.get(i).getName()) {
|
||||||
|
feature.ui_unit = analyticStreams[stream].ui_unit;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
feature["operation"] = new String(features.get(i).getCode());
|
||||||
|
feature["name"] = new String(features.get(i).getName());
|
||||||
|
feature["description"] = new String(features.get(i).getDescription());
|
||||||
|
feature["deviceType"] = new String(features.get(i).getDeviceType());
|
||||||
|
feature["params"] = [];
|
||||||
|
var metaData = features.get(i).getMetadataEntries();
|
||||||
|
if (metaData && metaData != null) {
|
||||||
|
for (var j = 0; j < metaData.size(); j++) {
|
||||||
|
feature["params"].push(new String(metaData.get(j).getValue()));
|
||||||
|
}
|
||||||
|
featureList.push(feature);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return featureList;
|
||||||
|
}
|
||||||
|
,
|
||||||
|
function (responsePayload) {
|
||||||
|
var response = {};
|
||||||
|
response["status"] = "error";
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return featuresList;
|
||||||
|
return featureList;
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.getControlOperations = function (deviceType) {
|
||||||
|
var operations = privateMethods.getOperationsFromFeatures(deviceType, "operation");
|
||||||
|
for (var op in operations) {
|
||||||
|
var iconPath = utility.getOperationIcon(deviceType, operations[op].operation);
|
||||||
|
if (iconPath) {
|
||||||
|
operations[op]["icon"] = iconPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return operations;
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.getMonitorOperations = function (deviceType) {
|
||||||
|
return privateMethods.getOperationsFromFeatures(deviceType, "monitor");
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.handlePOSTOperation = function (deviceType, operation, deviceId, params) {
|
||||||
|
var user = session.get(constants.USER_SESSION_KEY);
|
||||||
|
var endPoint = devicemgtProps["httpsURL"] + '/' + deviceType + "/controller/" + operation;
|
||||||
|
var header = '{"owner":"' + user.username + '","deviceId":"' + deviceId +
|
||||||
|
'","protocol":"mqtt", "sessionId":"' + session.getId() + '", "' +
|
||||||
|
constants.AUTHORIZATION_HEADER + '":"' + constants.BEARER_PREFIX +
|
||||||
|
getAccessToken(deviceType, user.username, deviceId) + '"}';
|
||||||
|
log.warn("header: " + header);
|
||||||
|
return post(endPoint, params, JSON.parse(header), "json");
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.handleGETOperation = function (deviceType, operation, operationName, deviceId) {
|
||||||
|
var user = session.get(constants.USER_SESSION_KEY);
|
||||||
|
var endPoint = devicemgtProps["httpsURL"] + '/' + deviceType + "/controller/" + operation;
|
||||||
|
var header = '{"owner":"' + user.username + '","deviceId":"' + deviceId +
|
||||||
|
'","protocol":"mqtt", "' + constants.AUTHORIZATION_HEADER + '":"' +
|
||||||
|
constants.BEARER_PREFIX + getAccessToken(deviceType, user.username, deviceId) +
|
||||||
|
'"}';
|
||||||
|
var result = get(endPoint, {}, JSON.parse(header), "json");
|
||||||
|
if (result.data) {
|
||||||
|
var values = result.data.sensorValue.split(',');
|
||||||
|
if (operationName == 'gps') {
|
||||||
|
result.data.map = {
|
||||||
|
lat: parseFloat(values[0]),
|
||||||
|
lng: parseFloat(values[1])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var sqSum = 0;
|
||||||
|
for (var v in values) {
|
||||||
|
sqSum += Math.pow(values[v], 2);
|
||||||
|
}
|
||||||
|
result.data[operationName] = Math.sqrt(sqSum);
|
||||||
|
}
|
||||||
|
delete result.data['sensorValue'];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
return publicMethods;
|
||||||
|
}();
|
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2011 František Hába <hello@frantisekhaba.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the 'Software'), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to use,
|
||||||
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||||
|
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
* Reference:- https://github.com/Baggz/Pinch
|
||||||
|
* */
|
||||||
|
(function(){var k=function(a,c){return a.length!==c.length?!1:a.every(function(a,b){return c[b]===a})},j=function(a,c,d){var b,e;if("[object Array]"===Object.prototype.toString.call(a)){b=0;for(e=a.length;b<e;b++)c.apply(d,[b,a[b],a])}else for(b in a)a.hasOwnProperty(b)&&c.apply(d,[b,a[b],a])},h=function(a){for(var c=[],d=!1,b=0,e=a.length,f="",g=function(){f&&(c.push(f),f="")};b<e;b++)a[b].match(/\[|\]/)?(g(),d="]"===a[b]?!1:!0):'"'!==a[b]&&"'"!==a[b]&&("."===a[b]&&!d?g():f+=a[b]),b===e-1&&g();return c},
|
||||||
|
g=function(a,c,d){var b=-1!==["string","object"].indexOf(typeof a),e="string"===typeof c||c&&c.test&&c.exec,f=-1!==["string","object","function"].indexOf(typeof d);b&&e&&f&&("string"===typeof a?(this.instance=JSON.parse(a),this.json=!0):this.instance=a,this.pattern="string"===typeof c?c.replace(/'/g,'"'):c,this.replacement=d,this.createIndex(this.instance))};g.prototype.createIndex=function(a,c){var d=this;this.index=this.index||[];c=c||"";j(a,function(a,e){var f,a=a+"";f=a.match(/^[a-zA-Z]+$/)?c?
|
||||||
|
c+"."+a:a:a.match(/\d+/)?c+"["+a+"]":c+'["'+a+'"]';d.index.push(f);"object"===typeof e&&d.createIndex(e,f)})};g.prototype.replace=function(){var a=this;j(this.index,function(c,d){if(a.pattern&&a.pattern.test&&a.pattern.exec&&d.match(a.pattern))return a.replaceValue(d);if("string"===typeof a.pattern){var b=h(d),e=h(a.pattern);if(k(b,e))return a.replaceValue(d)}});return this.json?JSON.stringify(this.instance):this.instance};g.prototype.replaceValue=function(a){var c=this,d=h(a);d.reduce(function(b,
|
||||||
|
e,f){if(f===d.length-1)f="function"===typeof c.replacement?c.replacement(a,e,b[e]):c.replacement,b[e]=f;else return b[e]},this.instance)};var i=function(a,c,d,b){a=(new g(a,c,d)).replace();return"function"===typeof b?b(null,a):a};"undefined"!==typeof module&&module.exports?module.exports=i:"undefined"!==typeof define?define(function(){return i}):this.pinch=i})();
|
@ -0,0 +1,275 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Refactored
|
||||||
|
*/
|
||||||
|
var policyModule;
|
||||||
|
policyModule = function () {
|
||||||
|
var log = new Log("/app/modules/policy.js");
|
||||||
|
|
||||||
|
var constants = require('/app/modules/constants.js');
|
||||||
|
var utility = require("/app/modules/utility.js")["utility"];
|
||||||
|
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
||||||
|
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
|
||||||
|
|
||||||
|
var publicMethods = {};
|
||||||
|
var privateMethods = {};
|
||||||
|
|
||||||
|
privateMethods.handleGetAllPoliciesError = function (responsePayload) {
|
||||||
|
var response = {};
|
||||||
|
response.status = "error";
|
||||||
|
/* responsePayload == "Scope validation failed"
|
||||||
|
Here the response.context("Scope validation failed") is used other then response.status(401).
|
||||||
|
Reason for this is IDP return 401 as the status in 4 different situations such as,
|
||||||
|
1. UnAuthorized.
|
||||||
|
2. Scope Validation Failed.
|
||||||
|
3. Permission Denied.
|
||||||
|
4. Access Token Expired.
|
||||||
|
5. Access Token Invalid.
|
||||||
|
In these cases in order to identify the correct situation we have to compare the unique value from status and
|
||||||
|
context which is context.
|
||||||
|
*/
|
||||||
|
if (responsePayload == "Scope validation failed") {
|
||||||
|
response.content = "Permission Denied";
|
||||||
|
} else {
|
||||||
|
response.content = responsePayload;
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
};
|
||||||
|
|
||||||
|
privateMethods.handleGetAllPoliciesSuccess = function (responsePayload) {
|
||||||
|
var isUpdated = false;
|
||||||
|
var policyListFromRestEndpoint = responsePayload["responseContent"];
|
||||||
|
var policyListToView = [];
|
||||||
|
var i, policyObjectFromRestEndpoint, policyObjectToView;
|
||||||
|
for (i = 0; i < policyListFromRestEndpoint.length; i++) {
|
||||||
|
// get list object
|
||||||
|
policyObjectFromRestEndpoint = policyListFromRestEndpoint[i];
|
||||||
|
// populate list object values to view-object
|
||||||
|
policyObjectToView = {};
|
||||||
|
policyObjectToView["id"] = policyObjectFromRestEndpoint["id"];
|
||||||
|
policyObjectToView["priorityId"] = policyObjectFromRestEndpoint["priorityId"];
|
||||||
|
policyObjectToView["name"] = policyObjectFromRestEndpoint["policyName"];
|
||||||
|
policyObjectToView["platform"] = policyObjectFromRestEndpoint["profile"]["deviceType"]["name"];
|
||||||
|
policyObjectToView["icon"] = devicemgtProps["httpsURL"] + devicemgtProps["appContext"] +
|
||||||
|
"public/cdmf.unit.device.type." + policyObjectToView["platform"] + ".type-view/images/thumb.png";
|
||||||
|
policyObjectToView["ownershipType"] = policyObjectFromRestEndpoint["ownershipType"];
|
||||||
|
policyObjectToView["roles"] = privateMethods.
|
||||||
|
getElementsInAString(policyObjectFromRestEndpoint["roles"]);
|
||||||
|
policyObjectToView["users"] = privateMethods.
|
||||||
|
getElementsInAString(policyObjectFromRestEndpoint["users"]);
|
||||||
|
policyObjectToView["compliance"] = policyObjectFromRestEndpoint["compliance"];
|
||||||
|
|
||||||
|
if (policyObjectFromRestEndpoint["active"] == true && policyObjectFromRestEndpoint["updated"] == true) {
|
||||||
|
policyObjectToView["status"] = "Active/Updated";
|
||||||
|
isUpdated = true;
|
||||||
|
} else if (policyObjectFromRestEndpoint["active"] == true &&
|
||||||
|
policyObjectFromRestEndpoint["updated"] == false) {
|
||||||
|
policyObjectToView["status"] = "Active";
|
||||||
|
} else if (policyObjectFromRestEndpoint["active"] == false &&
|
||||||
|
policyObjectFromRestEndpoint["updated"] == true) {
|
||||||
|
policyObjectToView["status"] = "Inactive/Updated";
|
||||||
|
isUpdated = true;
|
||||||
|
} else if (policyObjectFromRestEndpoint["active"] == false &&
|
||||||
|
policyObjectFromRestEndpoint["updated"] == false) {
|
||||||
|
policyObjectToView["status"] = "Inactive";
|
||||||
|
}
|
||||||
|
// push view-objects to list
|
||||||
|
policyListToView.push(policyObjectToView);
|
||||||
|
}
|
||||||
|
// generate response
|
||||||
|
var response = {};
|
||||||
|
response.updated = isUpdated;
|
||||||
|
response.status = "success";
|
||||||
|
response.content = policyListToView;
|
||||||
|
return response;
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.addPolicy = function (policyName, deviceType, policyDefinition, policyDescription,
|
||||||
|
deviceId) {
|
||||||
|
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants["ERRORS"]["USER_NOT_FOUND"];
|
||||||
|
}
|
||||||
|
if (policyName && deviceType) {
|
||||||
|
var queName = "WSO2IoTServer/" + carbonUser.username + "/" + deviceType;
|
||||||
|
var deviceQueName;
|
||||||
|
if (deviceId) {
|
||||||
|
deviceQueName = queName + "/" + deviceId;
|
||||||
|
privateMethods.publish(deviceQueName, policyName, deviceType, policyDefinition);
|
||||||
|
} else {
|
||||||
|
var deviceManagementService = utility.getDeviceManagementService();
|
||||||
|
var devices = deviceManagementService.getDevicesOfUser(carbonUser.username);
|
||||||
|
var device;
|
||||||
|
for (var i = 0; i < devices.size(); i++) {
|
||||||
|
device = devices.get(i);
|
||||||
|
deviceId = device.getDeviceIdentifier();
|
||||||
|
deviceQueName = queName + "/" + deviceId;
|
||||||
|
privateMethods.publish(deviceQueName, policyName, deviceType, policyDefinition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
privateMethods.publish = function (queName, policyName, deviceType, policyDefinition) {
|
||||||
|
var configurationService = utility.getConfigurationService();
|
||||||
|
var mqttEndPointDeviceConfig = configurationService.getControlQueue(constants.MQTT_QUEUE_CONFIG_NAME);
|
||||||
|
var mqttBrokerURL = mqttEndPointDeviceConfig.getServerURL();
|
||||||
|
var mqttBrokerPort = mqttEndPointDeviceConfig.getPort();
|
||||||
|
var mqttQueueEndpoint = mqttBrokerURL + ":" + mqttBrokerPort;
|
||||||
|
|
||||||
|
var mqttsenderClass = Packages.org.wso2.carbon.device.mgt.iot.mqtt.PolicyPush;
|
||||||
|
var mqttsender = new mqttsenderClass();
|
||||||
|
|
||||||
|
var policyPayload = "POLICY:" + policyDefinition;
|
||||||
|
var result = mqttsender.pushToMQTT(queName, policyPayload, mqttQueueEndpoint, "MQTT_Agent");
|
||||||
|
mqttsender = null;
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Updated
|
||||||
|
*/
|
||||||
|
publicMethods.getAllPolicies = function () {
|
||||||
|
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants["ERRORS"]["USER_NOT_FOUND"];
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/policies";
|
||||||
|
return serviceInvokers.XMLHttp.
|
||||||
|
get(url, privateMethods.handleGetAllPoliciesSuccess, privateMethods.handleGetAllPoliciesError);
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Updated - used by getAllPolicies
|
||||||
|
*/
|
||||||
|
privateMethods.getElementsInAString = function (elementList) {
|
||||||
|
var i, elementsInAString = "";
|
||||||
|
for (i = 0; i < elementList.length; i++) {
|
||||||
|
if (i == elementList.length - 1) {
|
||||||
|
elementsInAString += elementList[i];
|
||||||
|
} else {
|
||||||
|
elementsInAString += elementList[i] + ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return elementsInAString;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
publicMethods.getProfiles = function () {
|
||||||
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
var utility = require('/app/modules/utility.js').utility;
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants.ERRORS.USER_NOT_FOUND;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var policyManagementService = utility.getPolicyManagementService();
|
||||||
|
var policyAdminPoint = policyManagementService.getPAP();
|
||||||
|
var profiles = policyAdminPoint.getProfiles();
|
||||||
|
var profileList = [];
|
||||||
|
var i, profile, profileObject;
|
||||||
|
for (i = 0; i < profiles.size(); i++) {
|
||||||
|
profile = profiles.get(i);
|
||||||
|
profileObject = {};
|
||||||
|
profileObject.name = profile.getProfileName();
|
||||||
|
profileObject.id = profile.getProfileId();
|
||||||
|
profileList.push(profileObject);
|
||||||
|
}
|
||||||
|
return profileList;
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
publicMethods.updatePolicyPriorities = function (payload) {
|
||||||
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants.ERRORS.USER_NOT_FOUND;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var policyManagementService = utility.getPolicyManagementService();
|
||||||
|
var policyAdminPoint = policyManagementService.getPAP();
|
||||||
|
var policyCount = payload.length;
|
||||||
|
var policyList = new java.util.ArrayList();
|
||||||
|
var i, policyObject;
|
||||||
|
for (i = 0; i < policyCount; i++) {
|
||||||
|
policyObject = new Policy();
|
||||||
|
policyObject.setId(payload[i].id);
|
||||||
|
policyObject.setPriorityId(payload[i].priority);
|
||||||
|
policyList.add(policyObject);
|
||||||
|
}
|
||||||
|
policyAdminPoint.updatePolicyPriorities(policyList);
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
publicMethods.deletePolicy = function (policyId) {
|
||||||
|
var isDeleted;
|
||||||
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
var utility = require('/app/modules/utility.js').utility;
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants.ERRORS.USER_NOT_FOUND;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var policyManagementService = utility.getPolicyManagementService();
|
||||||
|
var policyAdminPoint = policyManagementService.getPAP();
|
||||||
|
isDeleted = policyAdminPoint.deletePolicy(policyId);
|
||||||
|
if (isDeleted) {
|
||||||
|
// http status code 200 refers to - success.
|
||||||
|
return 200;
|
||||||
|
} else {
|
||||||
|
// http status code 409 refers to - conflict.
|
||||||
|
return 409;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return publicMethods;
|
||||||
|
}();
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var serverAddress = function () {
|
||||||
|
var log = new Log("serverAddress.js");
|
||||||
|
var process = require("process"),
|
||||||
|
host = process.getProperty('server.host'),
|
||||||
|
ip = process.getProperty('carbon.local.ip');
|
||||||
|
var publicMethods = {};
|
||||||
|
publicMethods.getHTTPSAddress = function () {
|
||||||
|
var port = process.getProperty('mgt.transport.https.proxyPort');
|
||||||
|
if (!port) {
|
||||||
|
port = process.getProperty('mgt.transport.https.port');
|
||||||
|
}
|
||||||
|
if (host === "localhost") {
|
||||||
|
return "https://" + ip + ":" + port;
|
||||||
|
} else {
|
||||||
|
return "https://" + host + ":" + port;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
publicMethods.getHPPTAddress = function () {
|
||||||
|
var port = process.getProperty('mgt.transport.http.proxyPort');
|
||||||
|
if (!port) {
|
||||||
|
port = process.getProperty('mgt.transport.http.port');
|
||||||
|
}
|
||||||
|
if (host === "localhost") {
|
||||||
|
return "http://" + ip + ":" + port;
|
||||||
|
} else {
|
||||||
|
return "http://" + host + ":" + port;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
publicMethods.getWSSAddress = function () {
|
||||||
|
var port = process.getProperty('mgt.transport.https.proxyPort');
|
||||||
|
if (!port) {
|
||||||
|
port = process.getProperty('mgt.transport.https.port');
|
||||||
|
}
|
||||||
|
if (host === "localhost") {
|
||||||
|
return "wss://" + ip + ":" + port;
|
||||||
|
} else {
|
||||||
|
return "wss://" + host + ":" + port;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
publicMethods.getWSAddress = function () {
|
||||||
|
var port = process.getProperty('mgt.transport.http.proxyPort');
|
||||||
|
if (!port) {
|
||||||
|
port = process.getProperty('mgt.transport.http.port');
|
||||||
|
}
|
||||||
|
if (host === "localhost") {
|
||||||
|
return "ws://" + ip + ":" + port;
|
||||||
|
} else {
|
||||||
|
return "ws://" + host + ":" + port;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return publicMethods;
|
||||||
|
}();
|
@ -0,0 +1,788 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This module contains user and roles related functionality
|
||||||
|
*/
|
||||||
|
var userModule = function () {
|
||||||
|
var log = new Log("/app/modules/user.js");
|
||||||
|
|
||||||
|
var constants = require("/app/modules/constants.js");
|
||||||
|
var utility = require("/app/modules/utility.js")["utility"];
|
||||||
|
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
||||||
|
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
|
||||||
|
|
||||||
|
/* Initializing user manager */
|
||||||
|
var carbon = require('carbon');
|
||||||
|
var tenantId = carbon.server.tenantId();
|
||||||
|
var url = carbon.server.address('https') + "/admin/services";
|
||||||
|
var server = new carbon.server.Server(url);
|
||||||
|
var userManager = new carbon.user.UserManager(server, tenantId);
|
||||||
|
|
||||||
|
var deviceManagementService = utility.getDeviceManagementService();
|
||||||
|
var EmailMessageProperties = Packages.org.wso2.carbon.device.mgt.common.EmailMessageProperties;
|
||||||
|
|
||||||
|
var publicMethods = {};
|
||||||
|
var privateMethods = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the carbon user object from the session. If not found - it will throw a user not found error.
|
||||||
|
* @returns {carbon user object}
|
||||||
|
*/
|
||||||
|
privateMethods.getCarbonUser = function () {
|
||||||
|
var carbon = require('carbon');
|
||||||
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
var utility = require('/app/modules/utility.js').utility;
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants.ERRORS.USER_NOT_FOUND;
|
||||||
|
}
|
||||||
|
return carbonUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only GET method is implemented for now since there are no other type of methods used this method.
|
||||||
|
* @param url - URL to call the backend without the host
|
||||||
|
* @param method - HTTP Method (GET, POST)
|
||||||
|
* @returns {
|
||||||
|
* 'status': 'success'|'error',
|
||||||
|
* 'content': {}
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
privateMethods.callBackend = function (url, method) {
|
||||||
|
if (constants.HTTP_GET == method) {
|
||||||
|
var response = serviceInvokers.XMLHttp.get(url, function (responsePayload) {
|
||||||
|
var response = {};
|
||||||
|
response.content = responsePayload["responseContent"];
|
||||||
|
if (responsePayload["responseContent"] == null && responsePayload != null) {
|
||||||
|
response.content = responsePayload;
|
||||||
|
}
|
||||||
|
response.status = "success";
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
function (responsePayload) {
|
||||||
|
var response = {};
|
||||||
|
response.content = responsePayload;
|
||||||
|
response.status = "error";
|
||||||
|
return response;
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
} else {
|
||||||
|
log.error("Programming error : This method only support HTTP GET requests.");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Add user to mdm-user-store.
|
||||||
|
*
|
||||||
|
* @param username Username of the user
|
||||||
|
* @param firstname First name of the user
|
||||||
|
* @param lastname Last name of the user
|
||||||
|
* @param emailAddress Email address of the user
|
||||||
|
* @param userRoles Roles assigned to the user
|
||||||
|
*
|
||||||
|
* @returns {number} HTTP Status code 201 if succeeded, 409 if user already exists
|
||||||
|
*/
|
||||||
|
publicMethods.addUser = function (username, firstname, lastname, emailAddress, userRoles) {
|
||||||
|
var statusCode, carbon = require('carbon');
|
||||||
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
var utility = require('/app/modules/utility.js').utility;
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants.ERRORS.USER_NOT_FOUND;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var tenantId = carbon.server.tenantId();
|
||||||
|
var userManager = new carbon.user.UserManager(server, tenantId);
|
||||||
|
if (userManager.userExists(username)) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("A user with name '" + username + "' already exists.");
|
||||||
|
}
|
||||||
|
// http status code 409 refers to - conflict.
|
||||||
|
statusCode = 409;
|
||||||
|
} else {
|
||||||
|
var initialUserPassword = privateMethods.generateInitialUserPassword();
|
||||||
|
var defaultUserClaims = privateMethods.buildDefaultUserClaims(firstname, lastname, emailAddress);
|
||||||
|
|
||||||
|
userManager.addUser(username, initialUserPassword, userRoles, defaultUserClaims, "default");
|
||||||
|
privateMethods.inviteUserToEnroll(username, initialUserPassword);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("A new user with name '" + username + "' was created.");
|
||||||
|
}
|
||||||
|
// http status code 201 refers to - created.
|
||||||
|
statusCode = 201;
|
||||||
|
}
|
||||||
|
return statusCode;
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register user to dc-user-store.
|
||||||
|
*
|
||||||
|
* @param username Username of the user
|
||||||
|
* @param firstname First name of the user
|
||||||
|
* @param lastname Last name of the user
|
||||||
|
* @param emailAddress Email address of the user
|
||||||
|
* @param password Password of the user
|
||||||
|
* @param userRoles Roles assigned to the user
|
||||||
|
*
|
||||||
|
* @returns {number} HTTP Status code 201 if succeeded, 409 if user already exists
|
||||||
|
*/
|
||||||
|
publicMethods.registerUser = function (username, firstname, lastname, emailAddress, password, userRoles) {
|
||||||
|
var carbon = require('carbon');
|
||||||
|
var tenantId = carbon.server.tenantId();
|
||||||
|
var url = carbon.server.address('https') + "/admin/services";
|
||||||
|
var server = new carbon.server.Server(url);
|
||||||
|
var userManager = new carbon.user.UserManager(server, tenantId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (userManager.userExists(username)) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("A user with name '" + username + "' already exists.");
|
||||||
|
}
|
||||||
|
// http status code 409 refers to - conflict.
|
||||||
|
return constants.HTTP_CONFLICT;
|
||||||
|
} else {
|
||||||
|
var defaultUserClaims = privateMethods.buildDefaultUserClaims(firstname, lastname, emailAddress);
|
||||||
|
userManager.addUser(username, password, userRoles, defaultUserClaims, "default");
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("A new user with name '" + username + "' was created.");
|
||||||
|
}
|
||||||
|
// http status code 201 refers to - created.
|
||||||
|
return constants.HTTP_CREATED;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Remove an existing user from mdm-user-store.
|
||||||
|
*
|
||||||
|
* @param username Username of the user
|
||||||
|
* @returns {number} HTTP Status code 200 if succeeded, 409 if the user does not exist
|
||||||
|
*/
|
||||||
|
publicMethods.removeUser = function (username) {
|
||||||
|
var statusCode, carbon = require('carbon');
|
||||||
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
var utility = require('/app/modules/utility.js').utility;
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants.ERRORS.USER_NOT_FOUND;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var tenantId = carbon.server.tenantId();
|
||||||
|
var userManager = new carbon.user.UserManager(server, tenantId);
|
||||||
|
if (userManager.userExists(username)) {
|
||||||
|
userManager.removeUser(username);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("An existing user with name '" + username + "' was removed.");
|
||||||
|
}
|
||||||
|
// http status code 200 refers to - success.
|
||||||
|
statusCode = 200;
|
||||||
|
} else {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("A user with name '" + username + "' does not exist to remove.");
|
||||||
|
}
|
||||||
|
// http status code 409 refers to - conflict.
|
||||||
|
statusCode = 409;
|
||||||
|
}
|
||||||
|
return statusCode;
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Private method to be used by addUser() to
|
||||||
|
* generate an initial user password for a user.
|
||||||
|
* This will be the password used by a user for his initial login to the system.
|
||||||
|
*
|
||||||
|
* @returns {string} Initial User Password
|
||||||
|
*/
|
||||||
|
privateMethods.generateInitialUserPassword = function () {
|
||||||
|
var passwordLength = 6;
|
||||||
|
//defining the pool of characters to be used for initial password generation
|
||||||
|
var lowerCaseCharset = "abcdefghijklmnopqrstuvwxyz";
|
||||||
|
var upperCaseCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
var numericCharset = "0123456789";
|
||||||
|
|
||||||
|
var totalCharset = lowerCaseCharset + upperCaseCharset + numericCharset;
|
||||||
|
var totalCharsetLength = totalCharset.length;
|
||||||
|
|
||||||
|
var initialUserPassword = "";
|
||||||
|
for (var i = 0; i < passwordLength; ++i) {
|
||||||
|
initialUserPassword += totalCharset.charAt(Math.floor(Math.random() * totalCharsetLength));
|
||||||
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Initial password created for new user : " + initialUserPassword);
|
||||||
|
}
|
||||||
|
return String(initialUserPassword);
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Build default user claims.
|
||||||
|
*
|
||||||
|
* @param firstname First name of the user
|
||||||
|
* @param lastname Last name of the user
|
||||||
|
* @param emailAddress Email address of the user
|
||||||
|
*
|
||||||
|
* @returns {Object} Default user claims to be provided
|
||||||
|
*/
|
||||||
|
privateMethods.buildDefaultUserClaims = function (firstname, lastname, emailAddress) {
|
||||||
|
var defaultUserClaims = {
|
||||||
|
"http://wso2.org/claims/givenname": firstname,
|
||||||
|
"http://wso2.org/claims/lastname": lastname,
|
||||||
|
"http://wso2.org/claims/emailaddress": emailAddress
|
||||||
|
};
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("ClaimMap created for new user : " + stringify(defaultUserClaims));
|
||||||
|
}
|
||||||
|
return defaultUserClaims;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Send an initial invitation email to a user with username/password attached
|
||||||
|
* for the very-first enrollment with WSO2 MDM.
|
||||||
|
*
|
||||||
|
* @param username Username of the user
|
||||||
|
* @param password Password of the user
|
||||||
|
*/
|
||||||
|
privateMethods.inviteUserToEnroll = function (username, password) {
|
||||||
|
var carbon = require('carbon');
|
||||||
|
var enrollmentURL = devicemgtProps.generalConfig.host + devicemgtProps.webAgentContext + "download-agent";
|
||||||
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
var utility = require('/app/modules/utility.js').utility;
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants.ERRORS.USER_NOT_FOUND;
|
||||||
|
}
|
||||||
|
//var user = userManagementService.getUser(username, carbonUser.tenantId);
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var tenantId = carbon.server.tenantId();
|
||||||
|
var userManager = new carbon.user.UserManager(server, tenantId);
|
||||||
|
var emailTo = [];
|
||||||
|
var user = userManager.getUser(username);
|
||||||
|
emailTo[0] = privateMethods.getEmail(username, userManager);
|
||||||
|
var emailMessageProperties = new EmailMessageProperties();
|
||||||
|
emailMessageProperties.setMailTo(emailTo);
|
||||||
|
emailMessageProperties.setFirstName(privateMethods.getFirstName(username, userManager));
|
||||||
|
emailMessageProperties.setUserName(username);
|
||||||
|
emailMessageProperties.setPassword(password);
|
||||||
|
emailMessageProperties.setEnrolmentUrl(enrollmentURL);
|
||||||
|
deviceManagementService.sendRegistrationEmail(emailMessageProperties);
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
privateMethods.getEmail = function (username, userManager) {
|
||||||
|
return userManager.getClaim(username, "http://wso2.org/claims/emailaddress", null)
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
privateMethods.getFirstName = function (username, userManager) {
|
||||||
|
return userManager.getClaim(username, "http://wso2.org/claims/givenname", null)
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
privateMethods.getLastName = function (username, userManager) {
|
||||||
|
return userManager.getClaim(username, "http://wso2.org/claims/lastname", null)
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
publicMethods.inviteUser = function (username) {
|
||||||
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
var utility = require('/app/modules/utility.js').utility;
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants.ERRORS.USER_NOT_FOUND;
|
||||||
|
}
|
||||||
|
var enrollmentURL = devicemgtProps.generalConfig.host + devicemgtProps.webAgentContext + "download-agent";
|
||||||
|
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var tenantId = carbon.server.tenantId();
|
||||||
|
var userManager = new carbon.user.UserManager(server, tenantId);
|
||||||
|
var user = userManager.getUser(username);
|
||||||
|
var emailProperties = new EmailMessageProperties();
|
||||||
|
var emailTo = [];
|
||||||
|
emailTo[0] = privateMethods.getEmail(username, userManager);
|
||||||
|
emailProperties.setMailTo(emailTo);
|
||||||
|
//emailProperties.setFirstName(user.getFirstName());
|
||||||
|
emailProperties.setFirstName(privateMethods.getFirstName(username, userManager));
|
||||||
|
emailProperties.setEnrolmentUrl(enrollmentURL);
|
||||||
|
deviceManagementService.sendEnrolmentInvitation(emailProperties);
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Updated
|
||||||
|
*/
|
||||||
|
publicMethods.getUsers = function () {
|
||||||
|
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
|
||||||
|
var utility = require("/app/modules/utility.js")["utility"];
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants["ERRORS"]["USER_NOT_FOUND"];
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/users";
|
||||||
|
return privateMethods.callBackend(url, constants.HTTP_GET);
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a User object from the backend by calling the JAX-RS
|
||||||
|
* @param username
|
||||||
|
* @returns {
|
||||||
|
* 'status': 'success'|'error',
|
||||||
|
* 'content': {
|
||||||
|
"username": "abc",
|
||||||
|
"firstname": "abc",
|
||||||
|
"lastname": "efj",
|
||||||
|
"emailAddress": "abc@abc.com"
|
||||||
|
}
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
publicMethods.getUser = function (username) {
|
||||||
|
var carbonUser = privateMethods.getCarbonUser();
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/users/view?username=" + username;
|
||||||
|
var response = privateMethods.callBackend(url, constants.HTTP_GET);
|
||||||
|
response["userDomain"] = carbonUser.domain;
|
||||||
|
return response;
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* TODO: comment
|
||||||
|
* @param username
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
publicMethods.getRolesByUsername = function (username) {
|
||||||
|
var carbonUser = privateMethods.getCarbonUser();
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/users/roles?username=" + username;
|
||||||
|
var response = privateMethods.callBackend(url, constants.HTTP_GET);
|
||||||
|
return response;
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
@NewlyAdded
|
||||||
|
*/
|
||||||
|
publicMethods.getUsersByUsername = function () {
|
||||||
|
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
|
||||||
|
var utility = require("/app/modules/utility.js")["utility"];
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants["ERRORS"]["USER_NOT_FOUND"];
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/users/users-by-username";
|
||||||
|
return privateMethods.callBackend(url, constants.HTTP_GET)
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Updated
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Get User Roles from user store (Internal roles not included).
|
||||||
|
*/
|
||||||
|
publicMethods.getRoles = function () {
|
||||||
|
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
|
||||||
|
var utility = require('/app/modules/utility.js')["utility"];
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants["ERRORS"]["USER_NOT_FOUND"];
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/roles";
|
||||||
|
return privateMethods.callBackend(url, constants.HTTP_GET);
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Updated
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Get User Roles from user store (Internal roles not included).
|
||||||
|
*/
|
||||||
|
publicMethods.getRolesByUserStore = function (userStore) {
|
||||||
|
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
|
||||||
|
var utility = require('/app/modules/utility.js')["utility"];
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants["ERRORS"]["USER_NOT_FOUND"];
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/roles/" + encodeURIComponent(userStore);
|
||||||
|
return privateMethods.callBackend(url, constants.HTTP_GET);
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Platforms.
|
||||||
|
*/
|
||||||
|
publicMethods.getPlatforms = function () {
|
||||||
|
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
|
||||||
|
var utility = require('/app/modules/utility.js')["utility"];
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants["ERRORS"]["USER_NOT_FOUND"];
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/types";
|
||||||
|
return privateMethods.callBackend(url, constants.HTTP_GET);
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/*
|
||||||
|
@Updated
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Get role
|
||||||
|
*/
|
||||||
|
publicMethods.getRole = function (roleName) {
|
||||||
|
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
|
||||||
|
var utility = require('/app/modules/utility.js')["utility"];
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants["ERRORS"]["USER_NOT_FOUND"];
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/roles/role?rolename=" + encodeURIComponent(roleName);
|
||||||
|
var response = privateMethods.callBackend(url, constants.HTTP_GET);
|
||||||
|
return response;
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Authenticate a user when he or she attempts to login to MDM.
|
||||||
|
*
|
||||||
|
* @param username Username of the user
|
||||||
|
* @param password Password of the user
|
||||||
|
* @param successCallback Function to be called at the event of successful authentication
|
||||||
|
* @param failureCallback Function to be called at the event of failed authentication
|
||||||
|
*/
|
||||||
|
publicMethods.login = function (username, password, successCallback, failureCallback) {
|
||||||
|
var carbonModule = require("carbon");
|
||||||
|
var carbonServer = application.get("carbonServer");
|
||||||
|
try {
|
||||||
|
// check if the user is an authenticated user.
|
||||||
|
var isAuthenticated = carbonServer.authenticate(username, password);
|
||||||
|
if (!isAuthenticated) {
|
||||||
|
failureCallback("authentication");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var tenantUser = carbonModule.server.tenantUser(username);
|
||||||
|
var isAuthorizedToLogin = privateMethods.isAuthorizedToLogin(tenantUser);
|
||||||
|
if (!isAuthorizedToLogin) {
|
||||||
|
failureCallback("authorization");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
session.put(constants.USER_SESSION_KEY, tenantUser);
|
||||||
|
successCallback(tenantUser);
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.logout = function (successCallback) {
|
||||||
|
session.invalidate();
|
||||||
|
successCallback();
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.isAuthorized = function (permission) {
|
||||||
|
var carbon = require("carbon");
|
||||||
|
var carbonServer = application.get("carbonServer");
|
||||||
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
var utility = require('/app/modules/utility.js').utility;
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
response.sendError(401, constants.ERRORS.USER_NOT_FOUND);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var tenantId = carbon.server.tenantId();
|
||||||
|
var userManager = new carbon.user.UserManager(server, tenantId);
|
||||||
|
var user = new carbon.user.User(userManager, carbonUser.username);
|
||||||
|
return user.isAuthorized(permission, "ui.execute");
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
privateMethods.isAuthorizedToLogin = function(carbonUser) {
|
||||||
|
var utility = require('/app/modules/utility.js').utility;
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var tenantId = carbon.server.tenantId();
|
||||||
|
var userManager = new carbon.user.UserManager(server, tenantId);
|
||||||
|
var user = new carbon.user.User(userManager, carbonUser.username);
|
||||||
|
return user.isAuthorized("/permission/admin/login", "ui.execute");
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.getUIPermissions = function () {
|
||||||
|
var permissions = {};
|
||||||
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/devices/list") ||
|
||||||
|
publicMethods.isAuthorized("/permission/admin/device-mgt/user/devices/list")) {
|
||||||
|
permissions["LIST_DEVICES"] = true;
|
||||||
|
}
|
||||||
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/groups/list")) {
|
||||||
|
permissions["LIST_GROUPS"] = true;
|
||||||
|
}
|
||||||
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/users/list")) {
|
||||||
|
permissions["LIST_USERS"] = true;
|
||||||
|
}
|
||||||
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/roles/list")) {
|
||||||
|
permissions["LIST_ROLES"] = true;
|
||||||
|
}
|
||||||
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/policies/list")) {
|
||||||
|
permissions["LIST_POLICIES"] = true;
|
||||||
|
}
|
||||||
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/groups/add")) {
|
||||||
|
permissions["ADD_GROUP"] = true;
|
||||||
|
}
|
||||||
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/users/add")) {
|
||||||
|
permissions["ADD_USER"] = true;
|
||||||
|
}
|
||||||
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/users/remove")) {
|
||||||
|
permissions["REMOVE_USER"] = true;
|
||||||
|
}
|
||||||
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/roles/add")) {
|
||||||
|
permissions["ADD_ROLE"] = true;
|
||||||
|
}
|
||||||
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/policies/add")) {
|
||||||
|
permissions["ADD_POLICY"] = true;
|
||||||
|
}
|
||||||
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/policies/priority")) {
|
||||||
|
permissions["CHANGE_POLICY_PRIORITY"] = true;
|
||||||
|
}
|
||||||
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/dashboard/view")) {
|
||||||
|
permissions["VIEW_DASHBOARD"] = true;
|
||||||
|
}
|
||||||
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/platform-configs/view")) {
|
||||||
|
permissions["TENANT_CONFIGURATION"] = true;
|
||||||
|
}
|
||||||
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/devices/list")) {
|
||||||
|
permissions["LIST_OWN_DEVICES"] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return permissions;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add new role with permissions.
|
||||||
|
*
|
||||||
|
* @param roleName Name of the role
|
||||||
|
* @param users List of users to assign the role
|
||||||
|
* @param permissions List of permissions
|
||||||
|
*/
|
||||||
|
publicMethods.addRole = function (roleName, users, permissions) {
|
||||||
|
var carbon = require('carbon');
|
||||||
|
var tenantId = carbon.server.tenantId();
|
||||||
|
var url = carbon.server.address('https') + "/admin/services";
|
||||||
|
var server = new carbon.server.Server(url);
|
||||||
|
var userManager = new carbon.user.UserManager(server, tenantId);
|
||||||
|
try {
|
||||||
|
if (!userManager.roleExists(roleName)) {
|
||||||
|
userManager.addRole(roleName, users, permissions);
|
||||||
|
} else {
|
||||||
|
log.info("Role exist with name: " + roleName);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.addPermissions = function (permissionList, path, init) {
|
||||||
|
var registry, carbon = require("carbon");
|
||||||
|
var carbonServer = application.get("carbonServer");
|
||||||
|
var utility = require('/app/modules/utility.js').utility;
|
||||||
|
var options = {system: true};
|
||||||
|
if (init == "login") {
|
||||||
|
try {
|
||||||
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants.ERRORS.USER_NOT_FOUND;
|
||||||
|
}
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var tenantId = carbon.server.tenantId();
|
||||||
|
if (carbonUser) {
|
||||||
|
options.tenantId = tenantId;
|
||||||
|
}
|
||||||
|
registry = new carbon.registry.Registry(carbonServer, options);
|
||||||
|
var i, permission, resource;
|
||||||
|
for (i = 0; i < permissionList.length; i++) {
|
||||||
|
permission = permissionList[i];
|
||||||
|
resource = {
|
||||||
|
collection: true,
|
||||||
|
name: permission.name,
|
||||||
|
properties: {
|
||||||
|
name: permission.name
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (path != "") {
|
||||||
|
registry.put("/_system/governance/permission/admin/" + path + "/" + permission.key, resource);
|
||||||
|
} else {
|
||||||
|
registry.put("/_system/governance/permission/admin/" + permission.key, resource);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
registry = new carbon.registry.Registry(carbonServer, options);
|
||||||
|
var i, permission, resource;
|
||||||
|
for (i = 0; i < permissionList.length; i++) {
|
||||||
|
permission = permissionList[i];
|
||||||
|
resource = {
|
||||||
|
collection: true,
|
||||||
|
name: permission.name,
|
||||||
|
properties: {
|
||||||
|
name: permission.name
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (path != "") {
|
||||||
|
registry.put("/_system/governance/permission/admin/" + path + "/" + permission.key, resource);
|
||||||
|
} else {
|
||||||
|
registry.put("/_system/governance/permission/admin/" + permission.key, resource);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private method to be used by addUser() to
|
||||||
|
* retrieve secondary user stores.
|
||||||
|
* This needs Authentication since the method access admin services.
|
||||||
|
*
|
||||||
|
* @returns {string array} Array of secondary user stores.
|
||||||
|
*/
|
||||||
|
publicMethods.getSecondaryUserStores = function () {
|
||||||
|
var returnVal = [];
|
||||||
|
var endpoint = devicemgtProps.adminService + constants.USER_STORE_CONFIG_ADMIN_SERVICE_END_POINT;
|
||||||
|
var wsPayload = "<xsd:getSecondaryRealmConfigurations xmlns:xsd='http://org.apache.axis2/xsd'/>";
|
||||||
|
serviceInvokers.WS.soapRequest(
|
||||||
|
"urn:getSecondaryRealmConfigurations", endpoint, wsPayload, function (wsResponse) {
|
||||||
|
var domainIDs = stringify(wsResponse.*::['return']. *::domainId.text());
|
||||||
|
if (domainIDs != "\"\"") {
|
||||||
|
var regExpForSearch = new RegExp(constants.USER_STORES_NOISY_CHAR, "g");
|
||||||
|
domainIDs = domainIDs.replace(regExpForSearch, "");
|
||||||
|
returnVal = domainIDs.split(constants.USER_STORES_SPLITTING_CHAR);
|
||||||
|
}
|
||||||
|
}, function (e) {
|
||||||
|
log.error("Error retrieving secondary user stores", e);
|
||||||
|
}, constants.SOAP_VERSION);
|
||||||
|
return returnVal;
|
||||||
|
};
|
||||||
|
return publicMethods;
|
||||||
|
}();
|
@ -0,0 +1,166 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var util = function () {
|
||||||
|
var module = {};
|
||||||
|
var Base64 = Packages.org.apache.commons.codec.binary.Base64;
|
||||||
|
var String = Packages.java.lang.String;
|
||||||
|
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
||||||
|
var carbon = require('carbon');
|
||||||
|
var realmService = carbon.server.osgiService('org.wso2.carbon.user.core.service.RealmService');
|
||||||
|
var adminUserName = realmService.getBootstrapRealmConfiguration().getAdminUserName();
|
||||||
|
var constants = require("/app/modules/constants.js");
|
||||||
|
|
||||||
|
module.getDyanmicCredentials = function (owner) {
|
||||||
|
var payload = {
|
||||||
|
"callbackUrl": devicemgtProps.callBackUrl,
|
||||||
|
"clientName": "devicemgt",
|
||||||
|
"tokenScope": "admin",
|
||||||
|
"owner": adminUserName,
|
||||||
|
"applicationType": "webapp",
|
||||||
|
"grantType": "password refresh_token urn:ietf:params:oauth:grant-type:saml2-bearer",
|
||||||
|
"saasApp" :true
|
||||||
|
};
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
var tokenEndpoint = devicemgtProps.dynamicClientRegistrationEndPoint;
|
||||||
|
xhr.open("POST", tokenEndpoint, false);
|
||||||
|
xhr.setRequestHeader("Content-Type", "application/json");
|
||||||
|
xhr.send(payload);
|
||||||
|
var clientData = {};
|
||||||
|
if (xhr.status == 201) {
|
||||||
|
var data = parse(xhr.responseText);
|
||||||
|
clientData.clientId = data.client_id;
|
||||||
|
clientData.clientSecret = data.client_secret;
|
||||||
|
} else if (xhr.status == 400) {
|
||||||
|
throw "Invalid client meta data";
|
||||||
|
} else {
|
||||||
|
throw "Error in obtaining client id and secret";
|
||||||
|
}
|
||||||
|
return clientData;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode the payload in Base64
|
||||||
|
* @param payload
|
||||||
|
* @returns {Packages.java.lang.String}
|
||||||
|
*/
|
||||||
|
module.encode = function (payload) {
|
||||||
|
return new String(Base64.encodeBase64(new String(payload).getBytes()));
|
||||||
|
}
|
||||||
|
|
||||||
|
module.decode = function (payload) {
|
||||||
|
return new String(Base64.decodeBase64(new String(payload).getBytes()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an AccessToken pair based on username and password
|
||||||
|
* @param username
|
||||||
|
* @param password
|
||||||
|
* @param clientId
|
||||||
|
* @param clientSecret
|
||||||
|
* @param scope
|
||||||
|
* @returns {{accessToken: "", refreshToken: ""}}
|
||||||
|
*/
|
||||||
|
module.getTokenWithPasswordGrantType = function (username, password, encodedClientKeys, scope) {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
var tokenEndpoint = devicemgtProps.idPServer + "/oauth2/token";
|
||||||
|
xhr.open("POST", tokenEndpoint, false);
|
||||||
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||||
|
xhr.setRequestHeader("Authorization", "Basic " + encodedClientKeys);
|
||||||
|
xhr.send("grant_type=password&username=" + username + "&password=" + password + "&scope=" + scope);
|
||||||
|
delete password, delete clientSecret, delete encodedClientKeys;
|
||||||
|
var tokenPair = {};
|
||||||
|
if (xhr.status == 200) {
|
||||||
|
var data = parse(xhr.responseText);
|
||||||
|
tokenPair.refreshToken = data.refresh_token;
|
||||||
|
tokenPair.accessToken = data.access_token;
|
||||||
|
} else if (xhr.status == 403) {
|
||||||
|
log.error("Error in obtaining token with Password grant type");
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
log.error("Error in obtaining token with Password grant type");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return tokenPair;
|
||||||
|
};
|
||||||
|
module.getTokenWithSAMLGrantType = function (assertion, clientKeys, scope) {
|
||||||
|
|
||||||
|
var assertionXML = module.decode(assertion) ;
|
||||||
|
var encodedExtractedAssertion;
|
||||||
|
var extractedAssertion;
|
||||||
|
//TODO: make assertion extraction with proper parsing. Since Jaggery XML parser seem to add formatting
|
||||||
|
//which causes signature verification to fail.
|
||||||
|
var assertionStartMarker = "<saml2:Assertion";
|
||||||
|
var assertionEndMarker = "<\/saml2:Assertion>";
|
||||||
|
var assertionStartIndex = assertionXML.indexOf(assertionStartMarker);
|
||||||
|
var assertionEndIndex = assertionXML.indexOf(assertionEndMarker);
|
||||||
|
if (assertionStartIndex != -1 && assertionEndIndex != -1) {
|
||||||
|
extractedAssertion = assertionXML.substring(assertionStartIndex, assertionEndIndex) + assertionEndMarker;
|
||||||
|
} else {
|
||||||
|
throw "Invalid SAML response. SAML response has no valid assertion string";
|
||||||
|
}
|
||||||
|
|
||||||
|
encodedExtractedAssertion = this.encode(extractedAssertion);
|
||||||
|
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
var tokenEndpoint = devicemgtProps.idPServer + "/oauth2/token";
|
||||||
|
xhr.open("POST", tokenEndpoint, false);
|
||||||
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||||
|
xhr.setRequestHeader("Authorization", "Basic " + clientKeys);
|
||||||
|
xhr.send("grant_type=urn:ietf:params:oauth:grant-type:saml2-bearer&assertion=" +
|
||||||
|
encodeURIComponent(encodedExtractedAssertion) + "&scope=" + "PRODUCTION");
|
||||||
|
var tokenPair = {};
|
||||||
|
if (xhr.status == 200) {
|
||||||
|
var data = parse(xhr.responseText);
|
||||||
|
tokenPair.refreshToken = data.refresh_token;
|
||||||
|
tokenPair.accessToken = data.access_token;
|
||||||
|
} else if (xhr.status == 403) {
|
||||||
|
throw "Error in obtaining token with SAML extension grant type";
|
||||||
|
} else {
|
||||||
|
throw "Error in obtaining token with SAML extension grant type";
|
||||||
|
}
|
||||||
|
return tokenPair;
|
||||||
|
};
|
||||||
|
module.refreshToken = function (tokenPair, clientData, scope) {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
var tokenEndpoint = devicemgtProps.idPServer + "/oauth2/token";
|
||||||
|
xhr.open("POST", tokenEndpoint, false);
|
||||||
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||||
|
xhr.setRequestHeader("Authorization", "Basic " + clientData);
|
||||||
|
var url = "grant_type=refresh_token&refresh_token=" + tokenPair.refreshToken;
|
||||||
|
if (scope) {
|
||||||
|
url = url + "&scope=" + scope
|
||||||
|
}
|
||||||
|
xhr.send(url);
|
||||||
|
delete clientData;
|
||||||
|
var tokenPair = {};
|
||||||
|
if (xhr.status == 200) {
|
||||||
|
var data = parse(xhr.responseText);
|
||||||
|
tokenPair.refreshToken = data.refresh_token;
|
||||||
|
tokenPair.accessToken = data.access_token;
|
||||||
|
} else if (xhr.status == 400) {
|
||||||
|
tokenPair = session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER);
|
||||||
|
} else if (xhr.status == 403) {
|
||||||
|
throw "Error in obtaining token with Refresh Token Grant Type";
|
||||||
|
} else {
|
||||||
|
throw "Error in obtaining token with Refresh Token Type";
|
||||||
|
}
|
||||||
|
return tokenPair;
|
||||||
|
};
|
||||||
|
return module;
|
||||||
|
}();
|
@ -0,0 +1,282 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var utility;
|
||||||
|
utility = function () {
|
||||||
|
var log = new Log("/app/modules/utility.js");
|
||||||
|
var JavaClass = Packages.java.lang.Class;
|
||||||
|
var PrivilegedCarbonContext = Packages.org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
|
||||||
|
var getOsgiService = function (className) {
|
||||||
|
return PrivilegedCarbonContext.getThreadLocalCarbonContext().getOSGiService(JavaClass.forName(className));
|
||||||
|
};
|
||||||
|
|
||||||
|
var deviceTypeConfigMap = {};
|
||||||
|
|
||||||
|
var publicMethods = {};
|
||||||
|
|
||||||
|
publicMethods.startTenantFlow = function (userInfo) {
|
||||||
|
var context, carbon = require('carbon');
|
||||||
|
PrivilegedCarbonContext.startTenantFlow();
|
||||||
|
context = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
context.setTenantDomain(carbon.server.tenantDomain({
|
||||||
|
tenantId: userInfo.tenantId
|
||||||
|
}));
|
||||||
|
context.setTenantId(userInfo.tenantId);
|
||||||
|
context.setUsername(userInfo.username || null);
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.endTenantFlow = function () {
|
||||||
|
PrivilegedCarbonContext.endTenantFlow();
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.getConfigurationService = function () {
|
||||||
|
return getOsgiService('org.wso2.carbon.device.mgt.iot.service.ConfigurationService');
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.getDeviceManagementService = function () {
|
||||||
|
return getOsgiService('org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService');
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.getUserManagementService = function () {
|
||||||
|
return getOsgiService("org.wso2.carbon.device.mgt.user.core.UserManager");
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.getPolicyManagementService = function () {
|
||||||
|
return getOsgiService("org.wso2.carbon.policy.mgt.core.PolicyManagerService");
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.insertAppPermissions = function (userModule, type) {
|
||||||
|
// Below are the 2 types of users:- Normal users and Admins
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "admin",
|
||||||
|
name: "Device Management Admin"
|
||||||
|
}], "device-mgt", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "user",
|
||||||
|
name: "Device Management User"
|
||||||
|
}], "device-mgt", type);
|
||||||
|
|
||||||
|
// adding permission definitions for device-mgt/admin
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "dashboard",
|
||||||
|
name: "Dashboard"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "dashboard/view",
|
||||||
|
name: "View Dashboard"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "devices",
|
||||||
|
name: "Devices"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "devices/list",
|
||||||
|
name: "List All Devices"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "devices/add",
|
||||||
|
name: "Add Device"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "devices/edit",
|
||||||
|
name: "Edit Device"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "devices/remove",
|
||||||
|
name: "Remove Device"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "groups",
|
||||||
|
name: "Groups"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "groups/list",
|
||||||
|
name: "List All Groups"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "groups/add",
|
||||||
|
name: "Add Group"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "devices/operation",
|
||||||
|
name: "Perform Operation on Any Device"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
|
||||||
|
userModule.addPermissions([{key: "users", name: "Users"}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "users/add",
|
||||||
|
name: "Add New Users"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "users/invite",
|
||||||
|
name: "Invite Users"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "users/list",
|
||||||
|
name: "List Users"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "users/update",
|
||||||
|
name: "Update Users"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "users/remove",
|
||||||
|
name: "Remove Users"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "users/reset-password",
|
||||||
|
name: "Reset User Passwords"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
|
||||||
|
userModule.addPermissions([{key: "roles", name: "Roles"}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "roles/add",
|
||||||
|
name: "Add New Roles"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "roles/invite",
|
||||||
|
name: "Invite Roles"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "roles/list",
|
||||||
|
name: "List Roles"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "roles/remove",
|
||||||
|
name: "Remove Roles"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "roles/permission",
|
||||||
|
name: "Update Role Permission"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
|
||||||
|
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "policies",
|
||||||
|
name: "Policy"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "policies/add",
|
||||||
|
name: "Add Policy"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "policies/list",
|
||||||
|
name: "List Policy"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "policies/edit",
|
||||||
|
name: "Edit Policy"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "policies/remove",
|
||||||
|
name: "Remove Policy"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "policies/priority",
|
||||||
|
name: "Policy Priority"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
|
||||||
|
// adding permission definitions for device-mgt/user
|
||||||
|
userModule.addPermissions([{key: "devices", name: "Devices"}], "device-mgt/user", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "devices/list",
|
||||||
|
name: "List Individual Devices"
|
||||||
|
}], "device-mgt/user", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "devices/operation",
|
||||||
|
name: "Perform Operation on an Individual Device"
|
||||||
|
}], "device-mgt/user", type);
|
||||||
|
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "platform-configs",
|
||||||
|
name: "Platform Configurations"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
userModule.addPermissions([{
|
||||||
|
key: "platform-configs/view",
|
||||||
|
name: "View Configurations"
|
||||||
|
}], "device-mgt/admin", type);
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.getIoTServerConfig = function (configName) {
|
||||||
|
var path = "/config/iot-config.json";
|
||||||
|
var file = new File(path);
|
||||||
|
try {
|
||||||
|
file.open("r");
|
||||||
|
var content = file.readAll();
|
||||||
|
} catch (err) {
|
||||||
|
log.error("Error while reading IoT server config file `" + path + "`: " + err);
|
||||||
|
} finally {
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
var json = parse(content);
|
||||||
|
return json[configName];
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.getDeviceTypeConfig = function (deviceType) {
|
||||||
|
var JFile = Packages.java.io.File;
|
||||||
|
var sep = JFile.separator;
|
||||||
|
|
||||||
|
var systemProcess = require('process');
|
||||||
|
var parent = 'file:///' + (systemProcess.getProperty('jaggery.home') || systemProcess.getProperty('carbon.home')).replace(/[\\]/g, '/').replace(/^[\/]/g, '');
|
||||||
|
|
||||||
|
if (deviceType in deviceTypeConfigMap) {
|
||||||
|
return deviceTypeConfigMap[deviceType];
|
||||||
|
}
|
||||||
|
var deviceTypeConfig;
|
||||||
|
var deviceTypeConfigFile = new File(parent + sep + "repository" + sep + "conf" + sep
|
||||||
|
+ "device-types" + sep + deviceType + ".json");
|
||||||
|
if (deviceTypeConfigFile.isExists()) {
|
||||||
|
try {
|
||||||
|
deviceTypeConfigFile.open("r");
|
||||||
|
deviceTypeConfig = parse(deviceTypeConfigFile.readAll());
|
||||||
|
} catch (err) {
|
||||||
|
log.error("Error while reading device config file for `" + deviceType + "`: " + err);
|
||||||
|
} finally {
|
||||||
|
deviceTypeConfigFile.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deviceTypeConfigMap[deviceType] = deviceTypeConfig;
|
||||||
|
return deviceTypeConfig;
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.getOperationIcon = function (deviceType, operation) {
|
||||||
|
var iconPath = "/app/units/cdmf.unit.device.type."
|
||||||
|
+ deviceType + ".type-view/public/images/operations/" + operation + ".png";
|
||||||
|
var icon = new File(iconPath);
|
||||||
|
if (icon.isExists()) {
|
||||||
|
return "public/cdmf.unit.device.type." + deviceType + ".type-view/images/operations/" + operation + ".png";
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.getDeviceThumb = function (deviceType) {
|
||||||
|
var iconPath = "/app/units/cdmf.unit.device.type."
|
||||||
|
+ deviceType + ".type-view/public/images/thumb.png";
|
||||||
|
var icon = new File(iconPath);
|
||||||
|
if (icon.isExists()) {
|
||||||
|
return "/devicemgt/public/cdmf.unit.device.type." + deviceType + ".type-view/images/thumb.png";
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return publicMethods;
|
||||||
|
}();
|
@ -0,0 +1,42 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Analytics"}}
|
||||||
|
{{unit "cdmf.unit.ui.content.title" pageHeader=title}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{#if groupName}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/groups">
|
||||||
|
Groups
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/devices?groupId={{groupId}}&groupName={{groupName}}">
|
||||||
|
{{groupName}}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{else}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/devices">
|
||||||
|
Devices
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/device/{{deviceType}}?id={{deviceId}}">
|
||||||
|
{{deviceName}}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/if}}
|
||||||
|
<li>
|
||||||
|
<a href="#">
|
||||||
|
Analytics
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
{{unit "cdmf.unit.analytics"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context) {
|
||||||
|
var groupName = request.getParameter("groupName");
|
||||||
|
var groupId = request.getParameter("groupId");
|
||||||
|
var deviceName = request.getParameter("deviceName");
|
||||||
|
var deviceId = request.getParameter("deviceId");
|
||||||
|
var deviceType = request.getParameter("deviceType");
|
||||||
|
var title = "Analytics";
|
||||||
|
if (groupName) {
|
||||||
|
title = "Group " + title;
|
||||||
|
} else {
|
||||||
|
title = "Device " + title;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
"title": title,
|
||||||
|
"groupName": groupName,
|
||||||
|
"groupId": groupId,
|
||||||
|
"deviceName": deviceName,
|
||||||
|
"deviceId": deviceId,
|
||||||
|
"deviceType": deviceType
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/analytics",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Dashboard"}}
|
||||||
|
{{unit "cdmf.unit.ui.content.title" pageHeader="Dashboard"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
{{unit "cdmf.unit.dashboard"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Device Types"}}
|
||||||
|
{{unit "cdmf.unit.ui.content.title" pageHeader="Device List"}}
|
||||||
|
|
||||||
|
{{unit "cdmf.unit.lib.data-table"}}
|
||||||
|
{{unit "cdmf.unit.lib.handlebars"}}
|
||||||
|
{{unit "cdmf.unit.lib.service-invoker-utility"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/devices">
|
||||||
|
Devices
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/device/enroll">
|
||||||
|
Enroll Device
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
<div class="wr-device-list row">
|
||||||
|
<div class="wr-hidden-operations wr-advance-operations"></div>
|
||||||
|
<div class="col-md-12 wr-page-content">
|
||||||
|
<div>
|
||||||
|
{{unit "cdmf.unit.device.types.listing"}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/zone}}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/device/enroll",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Device"}}
|
||||||
|
{{! unit "cdmf.unit.ui.content.title" pageHeader="Device Download"}}
|
||||||
|
|
||||||
|
{{unit "cdmf.unit.data-tables-extended"}}
|
||||||
|
{{unit "cdmf.unit.lib.handlebars"}}
|
||||||
|
{{unit "cdmf.unit.lib.service-invoker-utility"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/devices">
|
||||||
|
Devices
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/device/enroll">
|
||||||
|
Enroll Device
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/device/{{deviceType}}/enroll">
|
||||||
|
{{label}}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
<div class="wr-device-list row">
|
||||||
|
<div class="wr-hidden-operations wr-advance-operations"></div>
|
||||||
|
<div class="col-md-12 wr-page-content">
|
||||||
|
<div>
|
||||||
|
{{! dynamically resolves device type-view unit according to deviceType URI param }}
|
||||||
|
{{unit deviceTypeViewUnitName}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/zone}}
|
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context) {
|
||||||
|
/**
|
||||||
|
* {{#itr context}}key : {{key}} value : {{value}}{{/itr}}
|
||||||
|
*/
|
||||||
|
context.handlebars.registerHelper("itr", function (obj, options) {
|
||||||
|
var key, buffer = '';
|
||||||
|
for (key in obj) {
|
||||||
|
if (obj.hasOwnProperty(key)) {
|
||||||
|
buffer += options.fn({key: key, value: obj[key]});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buffer;
|
||||||
|
});
|
||||||
|
|
||||||
|
var utility = require("/app/modules/utility.js").utility;
|
||||||
|
var deviceType = context.uriParams.deviceType;
|
||||||
|
|
||||||
|
var configs = utility.getDeviceTypeConfig(deviceType);
|
||||||
|
if(!configs["deviceType"]){
|
||||||
|
throw new Error("Invalid Device Type Configurations Found!","");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
"deviceTypeViewUnitName": "cdmf.unit.device.type." + deviceType + ".type-view",
|
||||||
|
"deviceType": deviceType,
|
||||||
|
"label" : configs["deviceType"]["label"]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/device/{deviceType}/enroll",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Device Details"}}
|
||||||
|
{{unit "cdmf.unit.lib.service-invoker-utility"}}
|
||||||
|
{{unit "cdmf.unit.lib.handlebars"}}
|
||||||
|
|
||||||
|
{{unit deviceViewUnitName}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/devices">
|
||||||
|
Devices
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#">
|
||||||
|
Device Details
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
{{unit "cdmf.unit.lib.data-table"}}
|
||||||
|
{{unit "cdmf.unit.device.operation-mod"}}
|
||||||
|
{{unit "cdmf.unit.device.view"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context){
|
||||||
|
context.handlebars.registerHelper('equal', function (lvalue, rvalue, options) {
|
||||||
|
if (arguments.length < 3)
|
||||||
|
throw new Error("Handlebars Helper equal needs 2 parameters");
|
||||||
|
if( lvalue!=rvalue ) {
|
||||||
|
return options.inverse(this);
|
||||||
|
} else {
|
||||||
|
return options.fn(this);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var deviceType = context.uriParams.deviceType;
|
||||||
|
|
||||||
|
return {"deviceViewUnitName" : "cdmf.unit.device.type." + deviceType + ".device-view"};
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/device/{deviceType}",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,67 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Device Management"}}
|
||||||
|
|
||||||
|
{{unit "uuf.unit.lib.data-table"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{#if groupName}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/groups">
|
||||||
|
Groups
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#">
|
||||||
|
{{groupName}}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{else}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/devices">
|
||||||
|
Devices
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/if}}
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "navbarActions"}}
|
||||||
|
{{#if groupName}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/devices" class="cu-btn">
|
||||||
|
<span class="icon fw-stack">
|
||||||
|
<i class="fw fw-add fw-stack-1x"></i>
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
</span>
|
||||||
|
Assign from My Devices
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{else}}
|
||||||
|
{{#if permissions.addDevice}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/device/enroll" class="cu-btn">
|
||||||
|
<span class="icon fw-stack">
|
||||||
|
<i class="fw fw-add fw-stack-1x"></i>
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
</span>
|
||||||
|
Enroll Device
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/if}}
|
||||||
|
{{/if}}
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
<div class="wr-device-list row">
|
||||||
|
<div class="wr-hidden-operations wr-advance-operations"></div>
|
||||||
|
<div class="col-md-12 wr-page-content">
|
||||||
|
<div>
|
||||||
|
{{unit "cdmf.unit.device.operation-mod"}}
|
||||||
|
{{unit "cdmf.unit.device.listing"}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/zone}}
|
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context) {
|
||||||
|
var constants = require("/app/modules/constants.js");
|
||||||
|
var page = {};
|
||||||
|
var groupName = request.getParameter("groupName");
|
||||||
|
var title = "Devices";
|
||||||
|
if (groupName) {
|
||||||
|
title = groupName + " " + title;
|
||||||
|
page.groupName = groupName;
|
||||||
|
}
|
||||||
|
page.title =title;
|
||||||
|
var currentUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
if (currentUser) {
|
||||||
|
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/add")) {
|
||||||
|
page.addDevice = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return page;
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/devices",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
{{#zone "title"}}Error | {{@app.conf.appName}}{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
<div class="message message-danger">
|
||||||
|
<h4><i class="icon fw fw-error"></i>An Error Occurred!</h4>
|
||||||
|
|
||||||
|
<div style="padding-left: 25px;">
|
||||||
|
<h5><b>HTTP Status : {{@page.params.status}}</b></h5>
|
||||||
|
|
||||||
|
<p style="white-space: pre-wrap;">{{@page.params.message}}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/zone}}
|
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/error/404",
|
||||||
|
"layout": "uuf.layout.default",
|
||||||
|
"isAnonymous": true
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Group Management"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/groups">
|
||||||
|
Groups
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/group/add">
|
||||||
|
Add
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
{{unit "cdmf.unit.group.create"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/group/add",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Group Management"}}
|
||||||
|
{{unit "cdmf.unit.ui.content.title" pageHeader="Groups"}}
|
||||||
|
|
||||||
|
{{unit "cdmf.unit.lib.data-table"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/groups">
|
||||||
|
Groups
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "navbarActions"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/group/add" class="cu-btn">
|
||||||
|
<span class="icon fw-stack">
|
||||||
|
<i class="fw fw-add fw-stack-1x"></i>
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
</span>
|
||||||
|
Add Group
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
<div class="wr-device-list row">
|
||||||
|
<div class="wr-hidden-operations wr-advance-operations"></div>
|
||||||
|
<div class="col-md-12 wr-page-content">
|
||||||
|
<div>
|
||||||
|
{{unit "cdmf.unit.group.listing"}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/zone}}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/groups",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Notification Listing"}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
{{unit "cdmf.unit.notification.listing"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/notification-listing",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Platform Configuration"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/platform-configuration">
|
||||||
|
Platform Configuration
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
{{unit "cdmf.unit.platform.configuration"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/platform-configuration",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Policy Management"}}
|
||||||
|
|
||||||
|
{{unit "cdmf.unit.data-tables-extended"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/policies">
|
||||||
|
Policies
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "navbarActions"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/policy/add" class="cu-btn">
|
||||||
|
<span class="icon fw-stack">
|
||||||
|
<i class="fw fw-add fw-stack-1x"></i>
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
</span>
|
||||||
|
Add Policy
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/policy/priority" class="cu-btn">
|
||||||
|
<span class="icon fw-stack">
|
||||||
|
<i class="fw fw-throttling-policy fw-stack-1x"></i>
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
</span>
|
||||||
|
Policy Priority
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#" class="cu-btn" id="appbar-btn-apply-changes">
|
||||||
|
<span class="icon fw-stack">
|
||||||
|
<i class="fw fw-check fw-stack-1x"></i>
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
</span>
|
||||||
|
Apply Changes To Devices
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
{{unit "cdmf.unit.policy.listing"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context){
|
||||||
|
context.handlebars.registerHelper('equal', function (lvalue, rvalue, options) {
|
||||||
|
if (arguments.length < 3)
|
||||||
|
throw new Error("Handlebars Helper equal needs 2 parameters");
|
||||||
|
if( lvalue!=rvalue ) {
|
||||||
|
return options.inverse(this);
|
||||||
|
} else {
|
||||||
|
return options.fn(this);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/policies",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Policy Management"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/policies">
|
||||||
|
Policies
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/policy/add">
|
||||||
|
Add
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
{{unit policyWizardUnitName}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context){
|
||||||
|
context.handlebars.registerHelper('equal', function (lvalue, rvalue, options) {
|
||||||
|
if (arguments.length < 3)
|
||||||
|
throw new Error("Handlebars Helper equal needs 2 parameters");
|
||||||
|
if( lvalue!=rvalue ) {
|
||||||
|
return options.inverse(this);
|
||||||
|
} else {
|
||||||
|
return options.fn(this);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var deviceType = context.uriParams.deviceType;
|
||||||
|
|
||||||
|
return {"policyWizardUnitName" : "cdmf.unit.device.type." + deviceType + ".policy-wizard"};
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/policy/add/{deviceType}",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Policy Management"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/policies">
|
||||||
|
Policies
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#">
|
||||||
|
Add
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
{{unit "cdmf.unit.policy.create"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context){
|
||||||
|
context.handlebars.registerHelper('equal', function (lvalue, rvalue, options) {
|
||||||
|
if (arguments.length < 3)
|
||||||
|
throw new Error("Handlebars Helper equal needs 2 parameters");
|
||||||
|
if( lvalue!=rvalue ) {
|
||||||
|
return options.inverse(this);
|
||||||
|
} else {
|
||||||
|
return options.fn(this);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/policy/add",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Policy Management"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/policies">
|
||||||
|
Policies
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#">
|
||||||
|
Edit
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
{{unit deviceTypePolicyEdit}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context) {
|
||||||
|
var deviceType = request.getParameter("type");
|
||||||
|
return {"deviceTypePolicyEdit" : "cdmf.unit.device.type." + deviceType + ".policy-edit"};
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/policy/edit",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Policy Management"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/policies">
|
||||||
|
Policies
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
{{unit "cdmf.unit.policy.priority"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context){
|
||||||
|
context.handlebars.registerHelper('equal', function (lvalue, rvalue, options) {
|
||||||
|
if (arguments.length < 3)
|
||||||
|
throw new Error("Handlebars Helper equal needs 2 parameters");
|
||||||
|
if( lvalue!=rvalue ) {
|
||||||
|
return options.inverse(this);
|
||||||
|
} else {
|
||||||
|
return options.fn(this);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/policy/priority",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Policy Management"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/policies">
|
||||||
|
Policies
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#">
|
||||||
|
View
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
{{unit deviceTypePolicyView}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context) {
|
||||||
|
var deviceType = request.getParameter("type");
|
||||||
|
return {"deviceTypePolicyView" : "cdmf.unit.device.type." + deviceType + ".policy-view"};
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/policy/view",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Role Management"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/roles">
|
||||||
|
Roles
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/roles/add-role">
|
||||||
|
Add
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
{{unit "cdmf.unit.role.create"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/roles/add-role",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Role Management"}}
|
||||||
|
|
||||||
|
{{unit "cdmf.unit.lib.service-invoker-utility"}}
|
||||||
|
{{unit "cdmf.unit.lib.data-table"}}
|
||||||
|
{{unit "cdmf.unit.lib.handlebars"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/roles">
|
||||||
|
Roles
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#">
|
||||||
|
Edit Permission
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
{{unit "cdmf.unit.role.edit.permission"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/role/edit-permission/{+any}",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Role Management"}}
|
||||||
|
|
||||||
|
{{unit "cdmf.unit.lib.select2"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/roles">
|
||||||
|
Roles
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#">
|
||||||
|
Edit
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
{{unit "cdmf.unit.role.edit"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/role/edit/{+any}",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Role Management"}}
|
||||||
|
|
||||||
|
{{unit "cdmf.unit.data-tables-extended"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/roles">
|
||||||
|
Roles
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "navbarActions"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/roles/add-role" class="cu-btn">
|
||||||
|
<span class="icon fw-stack">
|
||||||
|
<i class="fw fw-add fw-stack-1x"></i>
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
</span>
|
||||||
|
Add Role
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
{{unit "cdmf.unit.role.listing"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/roles",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
{{#zone "title"}}{{! to override parent page title }}{{/zone}}
|
||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Login"}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
<div class="container col-xs-12 col-sm-6 col-md-6 col-lg-3 col-centered wr-content wr-login col-centered">
|
||||||
|
|
||||||
|
<p class="page-sub-title">Login</p>
|
||||||
|
<hr />
|
||||||
|
{{#if message}}
|
||||||
|
<div class="alert alert-danger" style="padding-right: 15px;">
|
||||||
|
<i class="icon fw fw-warning"></i> {{message}}!
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
<div class="panel-body">
|
||||||
|
<form id="signInForm" method="POST" action="{{@app.context}}/uuf/login">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="username">Username *</label>
|
||||||
|
<input type="text" name="username" class="form-control" placeholder="Enter your username"
|
||||||
|
autofocus="autofocus" required="required" />
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="password">Password *</label>
|
||||||
|
<input type="password" name="password" class="form-control" placeholder="Enter your password"
|
||||||
|
required="required" />
|
||||||
|
</div>
|
||||||
|
{{#if referer}}
|
||||||
|
<input type="hidden" name="referer" value="{{referer}}" />
|
||||||
|
{{/if}}
|
||||||
|
<div class="wr-input-control wr-btn-grp">
|
||||||
|
<button class="wr-btn btn-download-agent">
|
||||||
|
Login
|
||||||
|
</button>
|
||||||
|
{{defineZone "signInForm-below" scope="protected"}}
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/zone}}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/login",
|
||||||
|
"extends": "uuf.page.sign-in"
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/logout",
|
||||||
|
"extends": "uuf.page.sign-out"
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="User Management"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/users">
|
||||||
|
Users
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/user/add">
|
||||||
|
Add
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
{{unit "cdmf.unit.user.create"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/user/add",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="User Management"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/users">
|
||||||
|
Users
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#">
|
||||||
|
Edit
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
{{unit "cdmf.unit.user.edit"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context) {
|
||||||
|
var userModule = require("/app/modules/user.js").userModule;
|
||||||
|
var username = request.getParameter("username");
|
||||||
|
var user = userModule.getUser(username)["content"];
|
||||||
|
if (user) {
|
||||||
|
var title;
|
||||||
|
if (user.firstname || user.lastname) {
|
||||||
|
title = user.firstname + " " + user.lastname;
|
||||||
|
} else {
|
||||||
|
title = user.username;
|
||||||
|
}
|
||||||
|
return {"user": user, "title": title};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/user/edit",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="User Management"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/users">
|
||||||
|
Users
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#">
|
||||||
|
{{username}}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
{{unit "cdmf.unit.user.view"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context) {
|
||||||
|
var userModule = require("/app/modules/user.js").userModule;
|
||||||
|
var username = request.getParameter("username");
|
||||||
|
var user = userModule.getUser(username)["content"];
|
||||||
|
if (user) {
|
||||||
|
return {"username": user.username};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/user/view",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="User Management"}}
|
||||||
|
|
||||||
|
{{unit "cdmf.unit.data-tables-extended"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/users">
|
||||||
|
Users
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "navbarActions"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/user/add" class="cu-btn">
|
||||||
|
<span class="icon fw-stack">
|
||||||
|
<i class="fw fw-add fw-stack-1x"></i>
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
</span>
|
||||||
|
Add User
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
{{unit "cdmf.unit.user.listing"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context) {
|
||||||
|
context.handlebars.registerHelper('unequal', function (lvalue, rvalue, options) {
|
||||||
|
if (arguments.length < 3)
|
||||||
|
throw new Error("Handlebars Helper equal needs 2 parameters");
|
||||||
|
if (lvalue == rvalue) {
|
||||||
|
return options.inverse(this);
|
||||||
|
} else {
|
||||||
|
return options.fn(this);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/users",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
{{#zone "topCss"}}
|
||||||
|
{{css "css/analytics.css"}}
|
||||||
|
{{css "css/daterangepicker.css"}}
|
||||||
|
{{css "css/graph.css"}}
|
||||||
|
{{/zone}}
|
||||||
|
<span id="request-group-id" data-groupid="{{groupId}}"></span>
|
||||||
|
<div class="container container-bg white-bg">
|
||||||
|
<div class=" margin-top-double">
|
||||||
|
<div class="row padding-top-double padding-bottom-double margin-bottom-double">
|
||||||
|
<div class="col-lg-3 margin-top-double">
|
||||||
|
<h1 class="grey ">{{title}}</h1>
|
||||||
|
</div>
|
||||||
|
<div id="rangeSliderWrapper" class="pull-right col-lg-9">
|
||||||
|
<div id="dateRangePickerContainer">
|
||||||
|
<div class="btn-group" role="group">
|
||||||
|
<button id="hour-btn" type="button"
|
||||||
|
class="btn btn-default date-range">Hour
|
||||||
|
</button>
|
||||||
|
<button id="h12-btn" type="button"
|
||||||
|
class="btn btn-default date-range">12 Hours
|
||||||
|
</button>
|
||||||
|
<button id="h24-btn" type="button"
|
||||||
|
class="btn btn-default date-range">24 Hours
|
||||||
|
</button>
|
||||||
|
<button id="h48-btn" type="button"
|
||||||
|
class="btn btn-default date-range">48 Hours
|
||||||
|
</button>
|
||||||
|
<button id="date-range" type="button"
|
||||||
|
class="btn btn-default date-range last-child"
|
||||||
|
data-toggle="popup"
|
||||||
|
title="Click to set custom date range"></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
<div class="clear"></div>
|
||||||
|
<div id="div-chart">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{#zone "bottomJs"}}
|
||||||
|
{{js "js/d3.min.js"}}
|
||||||
|
{{js "js/rickshaw.min.js"}}
|
||||||
|
{{js "js/moment.min.js"}}
|
||||||
|
{{js "js/jquery.daterangepicker.js"}}
|
||||||
|
{{js "js/graph_util.js"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context) {
|
||||||
|
var groupId = request.getParameter("groupId");
|
||||||
|
var title;
|
||||||
|
if (groupId) {
|
||||||
|
title = request.getParameter("groupName") + " Group";
|
||||||
|
} else {
|
||||||
|
groupId = 0;
|
||||||
|
var deviceId = request.getParameter("deviceId");
|
||||||
|
var deviceType = request.getParameter("deviceType");
|
||||||
|
var deviceName = request.getParameter("deviceName");
|
||||||
|
|
||||||
|
//title = deviceModule.getDevice(deviceType, deviceId).name;
|
||||||
|
title = deviceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {"title": title, "groupId": groupId};
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0"
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#rangeSliderWrapper {
|
||||||
|
margin-top: 25px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#chart {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
#legend {
|
||||||
|
display: inline-block;
|
||||||
|
position: relative;
|
||||||
|
left: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#legend_container {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
bottom: 26px;
|
||||||
|
width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#chart_container {
|
||||||
|
float: left;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ast-container {
|
||||||
|
padding-bottom: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shrink {
|
||||||
|
margin-right: 20px;
|
||||||
|
margin-left: 20px;
|
||||||
|
}
|
||||||
|
.date-range{
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
#dateRangePickerContainer button.active{
|
||||||
|
background-color: #e6e6e6 !important;
|
||||||
|
}
|
@ -0,0 +1,348 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
.date-picker {
|
||||||
|
width: 170px;
|
||||||
|
height: 25px;
|
||||||
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
line-height: 25px;
|
||||||
|
padding-left: 10px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-family: Arial;
|
||||||
|
font-weight: bold;
|
||||||
|
cursor: pointer;
|
||||||
|
color: #303030;
|
||||||
|
position: relative;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 1;
|
||||||
|
border: 1px solid #bfbfbf;
|
||||||
|
background-color: #efefef;
|
||||||
|
width: 448px;
|
||||||
|
padding: 5px 12px;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 20px;
|
||||||
|
color: #aaa;
|
||||||
|
font-family: Arial;
|
||||||
|
box-shadow: 3px 3px 10px rgba(0, 0, 0, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper.single-date {
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper.no-shortcuts {
|
||||||
|
padding-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .footer {
|
||||||
|
display: none;
|
||||||
|
font-size: 11px;
|
||||||
|
padding-top: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper b {
|
||||||
|
color: #666;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper a {
|
||||||
|
color: rgb(107, 180, 214);
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .month-wrapper {
|
||||||
|
border: 1px solid #bfbfbf;
|
||||||
|
border-radius: 3px;
|
||||||
|
background-color: #fff;
|
||||||
|
padding: 5px;
|
||||||
|
cursor: default;
|
||||||
|
position: relative;
|
||||||
|
_overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .month-wrapper table {
|
||||||
|
width: 190px;
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .month-wrapper table.month2 {
|
||||||
|
width: 190px;
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .month-wrapper table th,
|
||||||
|
.date-picker-wrapper .month-wrapper table td {
|
||||||
|
vertical-align: middle;
|
||||||
|
text-align: center;
|
||||||
|
line-height: 14px;
|
||||||
|
margin: 0px;
|
||||||
|
padding: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .month-wrapper table .day {
|
||||||
|
height: 19px;
|
||||||
|
line-height: 19px;
|
||||||
|
font-size: 12px;
|
||||||
|
margin-bottom: 1px;
|
||||||
|
color: #999;
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .month-wrapper table div.day.lastMonth,
|
||||||
|
.date-picker-wrapper .month-wrapper table div.day.nextMonth {
|
||||||
|
color: #999;
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .month-wrapper table .day.checked {
|
||||||
|
background-color: rgb(156, 219, 247);
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .month-wrapper table .week-name {
|
||||||
|
height: 20px;
|
||||||
|
line-height: 20px;
|
||||||
|
font-weight: 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .month-wrapper table .day.has-tooltip {
|
||||||
|
cursor: help !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .month-wrapper table .day.toMonth.valid {
|
||||||
|
color: #333;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .month-wrapper table .day.real-today {
|
||||||
|
background-color: rgb(255, 230, 132);
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .month-wrapper table .day.real-today.checked {
|
||||||
|
background-color: rgb(112, 204, 213);
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper table .caption {
|
||||||
|
height: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper table .caption .next,
|
||||||
|
.date-picker-wrapper table .caption .prev {
|
||||||
|
padding: 0 5px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper table .caption .next:hover,
|
||||||
|
.date-picker-wrapper table .caption .prev:hover {
|
||||||
|
background-color: #ccc;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .gap {
|
||||||
|
position: absolute;
|
||||||
|
display: none;
|
||||||
|
top: 0px;
|
||||||
|
left: 204px;
|
||||||
|
z-index: 1;
|
||||||
|
width: 15px;
|
||||||
|
height: 100%;
|
||||||
|
background-color: red;
|
||||||
|
font-size: 0;
|
||||||
|
line-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .gap .gap-lines {
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .gap .gap-line {
|
||||||
|
height: 15px;
|
||||||
|
width: 15px;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .gap .gap-line .gap-1 {
|
||||||
|
z-index: 1;
|
||||||
|
height: 0;
|
||||||
|
border-left: 8px solid white;
|
||||||
|
border-top: 8px solid #eee;
|
||||||
|
border-bottom: 8px solid #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .gap .gap-line .gap-2 {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: 0px;
|
||||||
|
z-index: 2;
|
||||||
|
height: 0;
|
||||||
|
border-left: 8px solid transparent;
|
||||||
|
border-top: 8px solid white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .gap .gap-line .gap-3 {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: 8px;
|
||||||
|
z-index: 2;
|
||||||
|
height: 0;
|
||||||
|
border-left: 8px solid transparent;
|
||||||
|
border-bottom: 8px solid white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .gap .gap-top-mask {
|
||||||
|
width: 6px;
|
||||||
|
height: 1px;
|
||||||
|
position: absolute;
|
||||||
|
top: -1px;
|
||||||
|
left: 1px;
|
||||||
|
background-color: #eee;
|
||||||
|
z-index: 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .gap .gap-bottom-mask {
|
||||||
|
width: 6px;
|
||||||
|
height: 1px;
|
||||||
|
position: absolute;
|
||||||
|
bottom: -1px;
|
||||||
|
left: 7px;
|
||||||
|
background-color: #eee;
|
||||||
|
z-index: 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .selected-days {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .drp_top-bar {
|
||||||
|
line-height: 40px;
|
||||||
|
height: 40px;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .drp_top-bar .error-top {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .drp_top-bar .normal-top {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .drp_top-bar .default-top {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .drp_top-bar.error .default-top {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .drp_top-bar.error .error-top {
|
||||||
|
display: block;
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .drp_top-bar.normal .default-top {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .drp_top-bar.normal .normal-top {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .drp_top-bar .apply-btn {
|
||||||
|
position: absolute;
|
||||||
|
right: 0px;
|
||||||
|
top: 6px;
|
||||||
|
padding: 3px 5px;
|
||||||
|
margin: 0;
|
||||||
|
font-size: 12px;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
color: #d9eef7;
|
||||||
|
border: solid 1px #0076a3;
|
||||||
|
background: #0095cd;
|
||||||
|
background: -webkit-gradient(linear, left top, left bottom, from(#00adee), to(#0078a5));
|
||||||
|
background: -moz-linear-gradient(top, #00adee, #0078a5);
|
||||||
|
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00adee', endColorstr='#0078a5');
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper .drp_top-bar .apply-btn.disabled {
|
||||||
|
pointer-events: none;
|
||||||
|
color: #606060;
|
||||||
|
border: solid 1px #b7b7b7;
|
||||||
|
background: #fff;
|
||||||
|
background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#ededed));
|
||||||
|
background: -moz-linear-gradient(top, #fff, #ededed);
|
||||||
|
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ededed');
|
||||||
|
}
|
||||||
|
|
||||||
|
/*time styling*/
|
||||||
|
.time {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.time input[type=range] {
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
.time1, .time2 {
|
||||||
|
width: 180px;
|
||||||
|
padding: 0 5px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.time1 {
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.time2 {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hour, .minute {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hide {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
input.hour-range, input.minute-range {
|
||||||
|
width: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#dateRangePickerContainer .date-range, #dateRangePickerContainer .input-append {
|
||||||
|
background: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#date-range {
|
||||||
|
padding-right: 30px;
|
||||||
|
width: 300px;
|
||||||
|
height: 100%;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
#dateRangePickerContainer {
|
||||||
|
float: right;
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue