mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Remove jaggery modules
This commit is contained in:
parent
1b0ad156b2
commit
8fa8cca776
@ -1,61 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
~
|
||||
~ Entgra (Pvt) Ltd. 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>io.entgra.device.mgt.core</groupId>
|
||||
<version>5.0.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}-${io.entgra.device.mgt.core.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>
|
||||
@ -1,48 +0,0 @@
|
||||
<!--
|
||||
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
~
|
||||
~ Entgra (Pvt) Ltd. 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>
|
||||
<!-- CDMF base app -->
|
||||
<directory>${basedir}/src/main/resources/jaggeryapps/devicemgt</directory>
|
||||
<outputDirectory>/jaggeryapps/devicemgt-cdmf/</outputDirectory>
|
||||
<useDefaultExcludes>true</useDefaultExcludes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<!-- UUF framework app -->
|
||||
<directory>${basedir}/src/main/resources/jaggeryapps/uuf-template-app</directory>
|
||||
<outputDirectory>/jaggeryapps/uuf-template-app/</outputDirectory>
|
||||
<useDefaultExcludes>true</useDefaultExcludes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>${basedir}/src/main/resources/jaggery-modules</directory>
|
||||
<outputDirectory>/jaggery-modules/</outputDirectory>
|
||||
<useDefaultExcludes>true</useDefaultExcludes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
||||
@ -1,56 +0,0 @@
|
||||
<!--
|
||||
~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
~
|
||||
~ Entgra (Pvt) Ltd. 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.
|
||||
-->
|
||||
|
||||
<module name="utils" xmlns="http://wso2.org/projects/jaggery/module.xml">
|
||||
<script>
|
||||
<name>reflection</name>
|
||||
<path>scripts/reflection/reflection.js</path>
|
||||
</script>
|
||||
<script>
|
||||
<name>file</name>
|
||||
<path>scripts/file/file.js</path>
|
||||
</script>
|
||||
<script>
|
||||
<name>patterns</name>
|
||||
<path>scripts/patterns/patterns.js</path>
|
||||
</script>
|
||||
<script>
|
||||
<name>xml</name>
|
||||
<path>scripts/xml/xml.js</path>
|
||||
</script>
|
||||
<script>
|
||||
<name>request</name>
|
||||
<path>scripts/request/request.js</path>
|
||||
</script>
|
||||
<script>
|
||||
<name>response</name>
|
||||
<path>scripts/response/response.js</path>
|
||||
</script>
|
||||
<script>
|
||||
<name>time</name>
|
||||
<path>scripts/time/time.js</path>
|
||||
</script>
|
||||
<script>
|
||||
<name>url</name>
|
||||
<path>scripts/url/url.js</path>
|
||||
</script>
|
||||
<script>
|
||||
<name>exception</name>
|
||||
<path>scripts/exception/exception.js</path>
|
||||
</script>
|
||||
</module>
|
||||
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description: The response of the currently invoked api enpoint is organized
|
||||
*/
|
||||
|
||||
var exception = {};
|
||||
var log = new Log('exception_module');
|
||||
|
||||
(function(exception) {
|
||||
/**
|
||||
*
|
||||
* @param message The exception description
|
||||
* @param code HTTP STATUS CODE related to the exception
|
||||
* @return The error object
|
||||
*/
|
||||
exception.buildExceptionObject = function(message, code) {
|
||||
var error = {};
|
||||
error.message = message;
|
||||
error.code = code;
|
||||
return error;
|
||||
};
|
||||
|
||||
exception.handleError = function (exception, type, code){
|
||||
var constants = require('rxt').constants;
|
||||
|
||||
if (type == constants.THROW_EXCEPTION_TO_CLIENT) {
|
||||
log.debug(exception);
|
||||
var e = exceptionModule.buildExceptionObject(exception, code);
|
||||
throw e;
|
||||
} else if (type == constants.LOG_AND_THROW_EXCEPTION) {
|
||||
log.error(exception);
|
||||
throw exception;
|
||||
} else if (type == constants.LOG_EXCEPTION_AND_TERMINATE) {
|
||||
log.error(exception);
|
||||
var msg = 'An error occurred while serving the request!';
|
||||
var e = exceptionModule.buildExceptionObject(msg, constants.STATUS_CODES.INTERNAL_SERVER_ERROR);
|
||||
throw e;
|
||||
} else if (type == constants.LOG_EXCEPTION_AND_CONTINUE) {
|
||||
log.debug(exception);
|
||||
}
|
||||
else {
|
||||
log.error(exception);
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
}(exception))
|
||||
|
||||
@ -1,166 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 file = {};
|
||||
(function() {
|
||||
var log = new Log('utils-file');
|
||||
var CONTENT_MAP = {
|
||||
'js': 'application/javascript',
|
||||
'css': 'text/css',
|
||||
'csv': 'text/csv',
|
||||
'html': 'text/html',
|
||||
'json': 'application/json',
|
||||
'png': 'image/png',
|
||||
'jpeg': 'image/jpeg',
|
||||
'gif': 'image/gif',
|
||||
'svg': 'image/svg+xml',
|
||||
'ttf': 'application/x-font-ttf',
|
||||
'eot': 'application/vnd.ms-fontobject',
|
||||
'woff': 'application/font-woff',
|
||||
'otf': 'application/x-font-otf',
|
||||
'zip': 'application/zip',
|
||||
'xml': 'text/xml',
|
||||
'xhtml': 'application/xhtml+xml',
|
||||
'pdf': 'application/pdf'
|
||||
};
|
||||
/**
|
||||
* The function checks whether a directory contains a particular file
|
||||
* @param dir The directory in which the file must be checked
|
||||
* @param file A File object if the file exists,else null
|
||||
*/
|
||||
file.getFileInDir = function(dir, fileName) {
|
||||
var isFilePresent = false;
|
||||
var files = dir.listFiles();
|
||||
for (var index in files) {
|
||||
if (files[index].getName() == fileName) {
|
||||
return files[index];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
/**
|
||||
* The function returns the file extension of a filename
|
||||
* @param file
|
||||
* @return: The extension of the file
|
||||
*/
|
||||
file.getExtension = function(file) {
|
||||
var baseFileName = file.getName();
|
||||
//Break up the name by .
|
||||
var baseNameComponents = baseFileName.split('.');
|
||||
var extension = baseNameComponents[baseNameComponents.length - 1];
|
||||
return extension;
|
||||
};
|
||||
/**
|
||||
* The function obtains the MIME type based on the extension
|
||||
* @param The extension
|
||||
* @return The mime type
|
||||
*/
|
||||
file.getMimeType = function(extension) {
|
||||
return CONTENT_MAP[extension];
|
||||
};
|
||||
/**
|
||||
* The function returns the name of the file without the file extension
|
||||
* @param file A file object
|
||||
* @return: The name of the file without the extension
|
||||
*/
|
||||
file.getFileName = function(file) {
|
||||
//Get the name of the file
|
||||
var baseFileName = file.getName();
|
||||
//Break up the name by .
|
||||
var baseNameComponents = baseFileName.split('.');
|
||||
//Get all of the components except the last one
|
||||
baseNameComponents.splice(baseNameComponents.length - 1, 1);
|
||||
return baseNameComponents.join('.');
|
||||
};
|
||||
/**
|
||||
* The function returns the contents of a directory as a JSON object.The name of the
|
||||
* file is used as the property names without the extensions.
|
||||
* NOTE: The method will not traverse sub folders.
|
||||
* @param The directory to be inspected
|
||||
* @return A JSON object which contains the files in the directory
|
||||
*/
|
||||
file.getDirectoryContents = function(dir) {
|
||||
var dirContents = {};
|
||||
//Check if it is a directory
|
||||
if (!dir.isDirectory()) {
|
||||
log.info('Not a directory');
|
||||
return dirContents;
|
||||
}
|
||||
//Obtain a list of all files
|
||||
var files = this.getAllFiles(dir);
|
||||
var name;
|
||||
log.info('Files: ' + files);
|
||||
//Create the directory object with each file been a property
|
||||
for (var index in files) {
|
||||
dirContents[this.getFileName(files[index])] = files[index];
|
||||
}
|
||||
return dirContents;
|
||||
};
|
||||
/**
|
||||
* The function obtains a list of files that are not directories
|
||||
* @param dir The directory to be inspected
|
||||
* @return An array with all of the files in the directory
|
||||
*/
|
||||
file.getAllFiles = function(dir) {
|
||||
var filesInDir = [];
|
||||
if (!dir.isDirectory()) {
|
||||
return filesInDir;
|
||||
}
|
||||
//Obtain a list of all files
|
||||
var files = dir.listFiles();
|
||||
for (var index in files) {
|
||||
log.info('Checking file: ' + files[index].getName());
|
||||
//Check if the file is a directory
|
||||
if (!files[index].isDirectory()) {
|
||||
filesInDir.push(files[index]);
|
||||
}
|
||||
}
|
||||
return filesInDir;
|
||||
};
|
||||
/**
|
||||
* The function returns a list of all file names in a directory
|
||||
* @param dir The directory to be inspected
|
||||
* @return {An array containing the name of all files in a directory
|
||||
*/
|
||||
file.getAllFileNames = function(dir) {
|
||||
var files = dir.listFiles();
|
||||
var list = [];
|
||||
var fileName;
|
||||
for (var index in files) {
|
||||
if (files[index].isDirectory()) {
|
||||
fileName=this.getFileName(files[index].getName());
|
||||
list.push(fileName);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
};
|
||||
/**
|
||||
* The function returns a list of all sub directories in a given directory
|
||||
* @param dir The root directory
|
||||
* @return: An array containing all sub directories
|
||||
*/
|
||||
file.getAllSubDirs = function(dir) {
|
||||
var files = dir.listFiles();
|
||||
var subDirs = [];
|
||||
for (var index in files) {
|
||||
if (files[index].isDirectory()) {
|
||||
subDirs.push(files[index]);
|
||||
}
|
||||
}
|
||||
return subDirs;
|
||||
};
|
||||
}());
|
||||
@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 patterns = {};
|
||||
|
||||
(function () {
|
||||
|
||||
var DEF_ERR_ARITY = 3;
|
||||
var DEF_HANDLE_ARITY = 2;
|
||||
var log = new Log('utils.patterns.GenericPipe');
|
||||
|
||||
function GenericPipe(options) {
|
||||
this.errHandlerArity = DEF_ERR_ARITY || options.errArity;
|
||||
this.handlerArity = DEF_HANDLE_ARITY || options.handlerArity;
|
||||
this.plugins = [];
|
||||
this.finalHandler = function () {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*The function registers the provided plugin
|
||||
*/
|
||||
GenericPipe.prototype.plug = function (plugin, options) {
|
||||
var options = options || {};
|
||||
//Only a function
|
||||
if (plugin instanceof Function) {
|
||||
this.plugins.push({
|
||||
handle: plugin,
|
||||
options: options
|
||||
});
|
||||
}
|
||||
//Is it a plugin object
|
||||
else if (plugin instanceof Object) {
|
||||
plugin.options = options;
|
||||
this.plugins.push(plugin);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
GenericPipe.prototype.finally = function (plugin) {
|
||||
this.finalHandler = plugin;
|
||||
return this;
|
||||
};
|
||||
|
||||
GenericPipe.prototype.resolve = function (data, req, res, session) {
|
||||
var context = {};
|
||||
context.req = req;
|
||||
context.res = res;
|
||||
context.session = session;
|
||||
context.data = data;
|
||||
handle(context, this.plugins, this.errHandlerArity, this.handlerArity, this.finalHandler);
|
||||
};
|
||||
|
||||
var handle = function (context, plugins, errArity, handlerArity, finallyHandler) {
|
||||
var index = 0;
|
||||
var currentPlugin;
|
||||
|
||||
var recursiveHandle = function (err) {
|
||||
|
||||
currentPlugin = plugins[index];
|
||||
|
||||
index++;
|
||||
|
||||
//Check if there is a plugin
|
||||
if (!currentPlugin) {
|
||||
//log.warn('No plugin found at index: ' + index);
|
||||
return;
|
||||
}
|
||||
|
||||
//Populate the options object for the plugin
|
||||
context.options=currentPlugin.options;;
|
||||
|
||||
//Check if an error has been provided
|
||||
if (err) {
|
||||
//Can the current plugin handle the err
|
||||
if (currentPlugin.handle.length == errArity) {
|
||||
try {
|
||||
currentPlugin.handle(err, context,recursiveHandle);
|
||||
}
|
||||
catch (e) {
|
||||
recursiveHandle(e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
recursiveHandle(err);
|
||||
}
|
||||
}
|
||||
//There is no error so try to invoke the current plugin
|
||||
else {
|
||||
if (currentPlugin.handle.length == handlerArity) {
|
||||
try {
|
||||
|
||||
|
||||
currentPlugin.handle(context,recursiveHandle);
|
||||
} catch (e) {
|
||||
recursiveHandle(e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
recursiveHandle();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
recursiveHandle();
|
||||
finallyHandler(context);
|
||||
};
|
||||
|
||||
patterns.GenericPipe = GenericPipe;
|
||||
|
||||
}());
|
||||
@ -1,229 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 reflection = {};
|
||||
/**
|
||||
* Description: The script encapsulates any reflection related utility functions
|
||||
*/
|
||||
(function() {
|
||||
var log = new Log('utils-reflection');
|
||||
reflection.copyPropKeys = function(from, to) {
|
||||
for (var key in from) {
|
||||
if (from.hasOwnProperty(key)) {
|
||||
to[key] = '';
|
||||
}
|
||||
}
|
||||
return to;
|
||||
};
|
||||
/**
|
||||
* The function recursively copies all property keys in an object
|
||||
* @param from
|
||||
* @param to
|
||||
*/
|
||||
reflection.copyAllPropKeys = function(from, to) {
|
||||
recurse(from, to, function(from, to, key) {
|
||||
if (from[key] instanceof Object) {
|
||||
to[key] = from[key];
|
||||
} else {
|
||||
to[key] = null;
|
||||
}
|
||||
});
|
||||
};
|
||||
reflection.copyAllPropValues = function(from, to) {
|
||||
recurse(from, to, function(from, to, key) {
|
||||
//Create an instance if the property does not exist
|
||||
if (!to[key]) {
|
||||
to[key] = {};
|
||||
}
|
||||
//Copy the values over
|
||||
if (!(from[key] instanceof Object)) {
|
||||
to[key] = from[key];
|
||||
} else {
|
||||
log.debug('Not copying values of key: ' + key);
|
||||
}
|
||||
});
|
||||
};
|
||||
/**
|
||||
* The function will only copy public properties
|
||||
* @param from
|
||||
* @param to
|
||||
*/
|
||||
reflection.copyPublicPropValues = function(from, to) {
|
||||
recurse(from, to, function(from, to, key) {
|
||||
//Ignore any hidden properties
|
||||
if (key.charAt(0) == '_') {
|
||||
log.warn('Drop key: ' + key);
|
||||
return;
|
||||
}
|
||||
//Create an instance if the property does not exist
|
||||
if (!to[key]) {
|
||||
to[key] = {};
|
||||
}
|
||||
//Copy the values over
|
||||
if (!(from[key] instanceof Object)) {
|
||||
to[key] = from[key];
|
||||
} else {
|
||||
log.warn('Not copying values of key: ' + key);
|
||||
}
|
||||
});
|
||||
};
|
||||
reflection.inspect = function(from, to, cb) {
|
||||
recurse(from, to, cb);
|
||||
};
|
||||
/**
|
||||
* The function recursively traverses an object and then invokes the provided
|
||||
* callback
|
||||
* @param root
|
||||
* @param clone
|
||||
* @param cb
|
||||
*/
|
||||
var recurse = function(root, clone, cb) {
|
||||
var key;
|
||||
//Check if the root is an object
|
||||
if (!(root instanceof Object)) {
|
||||
return;
|
||||
} else {
|
||||
var keys = Object.keys(root);
|
||||
//Go through all the other keys in the current root
|
||||
for (var index in keys) {
|
||||
key = keys[index];
|
||||
cb(root, clone, key);
|
||||
recurse(root[key], clone[key], cb);
|
||||
}
|
||||
}
|
||||
};
|
||||
reflection.copyProps = function(from, to) {
|
||||
for (var key in from) {
|
||||
if (from.hasOwnProperty(key)) {
|
||||
to[key] = from[key];
|
||||
}
|
||||
}
|
||||
return to;
|
||||
};
|
||||
reflection.getProps = function(obj) {
|
||||
var props = {};
|
||||
for (var key in obj) {
|
||||
if (!(obj[key] instanceof Function)) {
|
||||
props[key] = obj[key];
|
||||
}
|
||||
}
|
||||
return props;
|
||||
};
|
||||
reflection.printProps = function(obj) {
|
||||
for (var key in obj) {
|
||||
if (obj.hasOwnProperty(key)) {
|
||||
log.info('key: ' + key);
|
||||
}
|
||||
}
|
||||
};
|
||||
/**
|
||||
* The function determines if a property is hidden based on _
|
||||
* @param key
|
||||
* @returns {boolean}
|
||||
*/
|
||||
reflection.isHiddenProp = function(key) {
|
||||
if (key == '') {
|
||||
return false;
|
||||
}
|
||||
return (key.charAt(0) == '_') ? true : false;
|
||||
};
|
||||
var getDiff = function(a, b, diff) {};
|
||||
/**
|
||||
* The function calculates the differences between two simple JSON objects
|
||||
* @param a The object with which b is compared
|
||||
* @param b The target of the comparison
|
||||
* @return An object which records the differences between the two objects
|
||||
*/
|
||||
reflection.diff = function(a, b) {};
|
||||
/**
|
||||
* The function merges the two provided objects to create a new
|
||||
* object.In the case where b has the same property as a; the property of b
|
||||
* will have precedence
|
||||
* @param {[type]} a [description]
|
||||
* @param {[type]} b [description]
|
||||
* @return A new object having the properties of both object a and b
|
||||
*/
|
||||
reflection.merge = function(a, b) {
|
||||
var newObj = {};
|
||||
//Copy the properties of a first
|
||||
for (var key in a) {
|
||||
newObj[key] = b[key];
|
||||
}
|
||||
//Override with the properties of b
|
||||
for (var key in b) {
|
||||
newObj[key] = b[key];
|
||||
}
|
||||
return newObj;
|
||||
};
|
||||
/**
|
||||
* The function allows a child class to override a select set of methods of
|
||||
* a parent class.The original methods of the parent can be accessed
|
||||
* using the this._super keyword
|
||||
* @param {[type]} parent The parent class instance to be overriden
|
||||
* @param {[type]} child The child class instance containing methods which will override the parent
|
||||
*/
|
||||
reflection.override = function(parent, child) {
|
||||
//Make a clone of the parent
|
||||
var super = parse(stringify(parent));
|
||||
for (var childKey in child) {
|
||||
for (var parentKey in parent) {
|
||||
//Only override those methods that are common
|
||||
if (childKey === parentKey) {
|
||||
var parentPtr = parent[parentKey];
|
||||
var childPtr = child[childKey];
|
||||
//Update the clone with the old parent method
|
||||
super[parentKey] = parentPtr;
|
||||
parent[parentKey] = childPtr;
|
||||
/*parent[parentKey] = function() {
|
||||
var result=childPtr.apply(this, arguments)||null;
|
||||
return result;
|
||||
};*/
|
||||
}
|
||||
}
|
||||
}
|
||||
//Allow the child object to call methods of the parent
|
||||
parent._super = super;
|
||||
};
|
||||
reflection.overrideAll=function(parent,child){
|
||||
//Make a clone of the parent
|
||||
var super = parse(stringify(parent));
|
||||
for (var childKey in child) {
|
||||
for (var parentKey in parent) {
|
||||
//Only override those methods that are common
|
||||
if ( (child.hasOwnProperty(childKey))&&(parent.hasOwnProperty(parentKey)) ) {
|
||||
var parentPtr = parent[parentKey];
|
||||
var childPtr = child[childKey];
|
||||
//Update the clone with the old parent method
|
||||
super[parentKey] = parentPtr;
|
||||
parent[parentKey] = childPtr;
|
||||
/*parent[parentKey] = function() {
|
||||
var result=childPtr.apply(this, arguments)||null;
|
||||
return result;
|
||||
};*/
|
||||
}
|
||||
}
|
||||
}
|
||||
//Allow the child object to call methods of the parent
|
||||
parent._super = super;
|
||||
};
|
||||
reflection.isArray = function(object) {
|
||||
if (Object.prototype.toString.call(object) === '[object Array]') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}());
|
||||
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 request = {};
|
||||
(function(request) {
|
||||
var hasOwnProperty = function(obj, element) {
|
||||
return Object.prototype.hasOwnProperty.call(obj, element);
|
||||
};
|
||||
var isObject = function(object) {;
|
||||
return typeof object === 'object';
|
||||
};
|
||||
/*
|
||||
* ECMA Standard (ECMA-262 : 5.1 Edition)*/
|
||||
var decodes = function(encodedURI) {
|
||||
return decodeURIComponent(encodedURI);
|
||||
};
|
||||
request.getQueryOptions = function(queryString) {
|
||||
var opt={};
|
||||
var sep = opt.sep || '&',
|
||||
assign = opt.assign || '=',
|
||||
compoArray = [];
|
||||
var obj = {};
|
||||
var decodedURI = decodes(queryString);
|
||||
decodedURI.split(sep).forEach(function(comp) {
|
||||
comp.split(assign).some(function(element, index, array) {
|
||||
if (hasOwnProperty(obj, element.toString())) {
|
||||
compoArray.push(obj[element]);
|
||||
compoArray.push(array[1]);
|
||||
obj[element] = compoArray;
|
||||
} else {
|
||||
Object.defineProperty(obj, element, {
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
value: array[1]
|
||||
});
|
||||
}
|
||||
return true;
|
||||
});
|
||||
});
|
||||
return obj;
|
||||
};
|
||||
}(request))
|
||||
@ -1,98 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description: The response of the currently invoked api endpoint is organized
|
||||
*/
|
||||
|
||||
var response = {};
|
||||
var log = new Log("response");
|
||||
|
||||
(function(response) {
|
||||
|
||||
/**
|
||||
* Build Error response
|
||||
* @param resp jaggery-response object to retrieve to client
|
||||
* @param code status code
|
||||
* @param message message to the client side
|
||||
* @return return response
|
||||
*/
|
||||
response.buildErrorResponse = function(resp,code,message) {
|
||||
var content={};
|
||||
content.error = message;
|
||||
resp = processResponse(resp,code,content);
|
||||
return resp;
|
||||
};
|
||||
|
||||
/**
|
||||
* Build success response
|
||||
* @param resp jaggery response object
|
||||
* @param code status code
|
||||
* @param data the result to client
|
||||
* @return return response
|
||||
*/
|
||||
response.buildSuccessResponse= function(resp, code, data){
|
||||
var content={};
|
||||
content.data = data;
|
||||
resp = processResponse(resp,code,content);
|
||||
return resp;
|
||||
};
|
||||
|
||||
/**
|
||||
* process General response
|
||||
* @param resp jaggery response
|
||||
* @param code status code
|
||||
* @param data success result
|
||||
* @return resp jaggery response
|
||||
*/
|
||||
response.buildSuccessResponseForRxt= function(resp, code, data){
|
||||
resp.status = code;
|
||||
resp.content = data;
|
||||
return resp;
|
||||
};
|
||||
|
||||
/**
|
||||
* General response builder
|
||||
* @param resp jaggery response
|
||||
* @param code status code
|
||||
* @param content what ever the content to be sent as response
|
||||
* @return resp jaggery response
|
||||
*/
|
||||
function processResponse(resp, code, content){
|
||||
resp.status = code;
|
||||
resp.contentType = 'application/json';
|
||||
resp.content = content;
|
||||
return resp;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param resp
|
||||
* @param code
|
||||
* @param data
|
||||
* @return The http response
|
||||
*/
|
||||
response.buildSuccessResponseForRxt= function(resp, code, data){
|
||||
resp.contentType = 'application/json';
|
||||
resp.status = code;
|
||||
resp.content = data;
|
||||
return resp;
|
||||
};
|
||||
|
||||
}(response))
|
||||
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 time = {};
|
||||
(function(time) {
|
||||
time.getCurrentTime = function(dateLength) {
|
||||
var dateLength=dateLength||20;
|
||||
var now = new String(new Date().valueOf());
|
||||
var length = now.length;
|
||||
var prefix = dateLength;
|
||||
var onsetVal = '';
|
||||
if (length != prefix) {
|
||||
var onset = prefix - length;
|
||||
for (var i = 0; i < onset; i++) {
|
||||
onsetVal += '0';
|
||||
}
|
||||
}
|
||||
return onsetVal + now;
|
||||
};
|
||||
}(time));
|
||||
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 url = {};
|
||||
(function() {
|
||||
var log=new Log('utils-url');
|
||||
url.popServerDetails = function(obj) {
|
||||
var process = require('process');
|
||||
var localIP = process.getProperty('server.host');
|
||||
var httpPort = process.getProperty('http.port');
|
||||
var httpsPort = process.getProperty('https.port');
|
||||
var value = '';
|
||||
var carbonLocalIP = process.getProperty('carbon.local.ip');
|
||||
|
||||
for (var key in obj) {
|
||||
if (obj.hasOwnProperty(key)) {
|
||||
value = obj[key];
|
||||
if ((typeof value === 'string') && value.indexOf('%https.host%') > -1) {
|
||||
value=value.replace('%https.host%', 'https://' + localIP + ':' + httpsPort);
|
||||
} else if ((typeof value === 'string') && value.indexOf('%http.host%') > -1) {
|
||||
value=value.replace('%http.host%', 'http://' + localIP + ':' + httpPort);
|
||||
} else if ((typeof value === 'string') && value.indexOf('%https.carbon.local.ip%') > -1) {
|
||||
value=value.replace('%https.carbon.local.ip%', 'https://' + carbonLocalIP + ':' + httpsPort);
|
||||
} else if ((typeof value === 'string') && value.indexOf('%http.carbon.local.ip%') > -1) {
|
||||
value=value.replace('%http.carbon.local.ip%', 'http://' + carbonLocalIP + ':' + httpPort);
|
||||
}
|
||||
obj[key] = value;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
}(url));
|
||||
@ -1,137 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 xml = {};
|
||||
|
||||
(function () {
|
||||
|
||||
var log=new Log('util.xml')
|
||||
|
||||
/*
|
||||
The method is used to create a JSON object using
|
||||
an xml object.
|
||||
@xmlElement: An xml element object to be processed
|
||||
@return: A pseudo object containing the properties of the
|
||||
xml element.
|
||||
*/
|
||||
var createJSONObject = function (xmlElement) {
|
||||
|
||||
var pseudo = {};
|
||||
|
||||
//Extract all attributes
|
||||
var attributes = xmlElement.@*;
|
||||
|
||||
//Fill the pseudo object with the attributes of the element
|
||||
for (var attributeKey in attributes) {
|
||||
var attribute = attributes[attributeKey];
|
||||
pseudo[attribute.localName()] = attribute.toString();
|
||||
}
|
||||
|
||||
return pseudo;
|
||||
};
|
||||
|
||||
/*
|
||||
The function converts an E4X Xml object to a JSON object
|
||||
This function has been adapted from the work of Oleg Podsechin available at
|
||||
https://gist.github.com/olegp/642667
|
||||
It uses a slightly modified version of his algorithm , therefore
|
||||
all credit should be attributed to Oleg Podsechin.
|
||||
IMPORTANT:
|
||||
1. It does not create a 1..1 mapping due to the differences
|
||||
between Xml and JSON.It is IMPORTANT that you verify the structure
|
||||
of the object generated before using it.
|
||||
2. The input xml object must not contain the xml header information
|
||||
This is a known bug 336551 (Mozilla Developer Network)
|
||||
Source: https://developer.mozilla.org/en/docs/E4X
|
||||
Please remove the header prior to sending the xml object for processing.
|
||||
@root: A starting element in an E4X Xml object
|
||||
@return: A JSON object mirroring the provided Xml object
|
||||
*/
|
||||
var recursiveConvertE4XtoJSON = function (root) {
|
||||
|
||||
log.debug('Root: ' + root.localName());
|
||||
|
||||
//Obtain child nodes
|
||||
var children = root.*;
|
||||
|
||||
//The number of children
|
||||
var numChildren = children.length();
|
||||
|
||||
//No children
|
||||
if (numChildren == 0) {
|
||||
|
||||
//Extract contents
|
||||
return createJSONObject(root);
|
||||
}
|
||||
else {
|
||||
|
||||
//Create an empty object
|
||||
var rootObject = createJSONObject(root);
|
||||
|
||||
//Could be multiple children
|
||||
for (var childElementKey in children) {
|
||||
|
||||
var child = children[childElementKey];
|
||||
|
||||
log.debug('Examining child: ' + child.localName());
|
||||
|
||||
//If the child just contains a single value then stop
|
||||
if (child.localName() == undefined) {
|
||||
|
||||
log.debug('Child is undefined: ' + child.toString());
|
||||
|
||||
//Change the object to just a key value pair
|
||||
rootObject[root.localName()] = child.toString();
|
||||
return rootObject;
|
||||
}
|
||||
|
||||
//Make a recursive call to construct the child element
|
||||
var createdObject = recursiveConvertE4XtoJSON(child);
|
||||
|
||||
log.debug('Converted object: ' + stringify(createdObject));
|
||||
|
||||
//Check if the root object has the property
|
||||
if (rootObject.hasOwnProperty(child.localName())) {
|
||||
|
||||
log.debug('key: ' + child.localName() + ' already present.');
|
||||
rootObject[child.localName()].push(createdObject);
|
||||
}
|
||||
else {
|
||||
|
||||
log.debug('key: ' + child.localName() + ' not present.');
|
||||
rootObject[child.localName()] = [];
|
||||
rootObject[child.localName()].push(createdObject);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
log.debug('root: ' + root.localName());
|
||||
|
||||
return rootObject;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The function is used to convert an E4X xml to JSON
|
||||
* @param root
|
||||
*/
|
||||
xml.convertE4XtoJSON = function (root) {
|
||||
return recursiveConvertE4XtoJSON(root);
|
||||
};
|
||||
|
||||
|
||||
}());
|
||||
@ -1,113 +0,0 @@
|
||||
<%
|
||||
/*
|
||||
* 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 log = new Log("api/data-tables-invoker-api.jag");
|
||||
|
||||
var uri = request.getRequestURI();
|
||||
var uriMatcher = new URIMatcher(String(uri));
|
||||
|
||||
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
|
||||
var utility = require("/app/modules/utility.js")["utility"];
|
||||
var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
|
||||
var EnrolmentInfo = Packages.io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
|
||||
|
||||
var DTYPE_CONF_DEVICE_TYPE_KEY = "deviceType";
|
||||
var DTYPE_CONF_DEVICE_TYPE_LABEL_KEY = "label";
|
||||
|
||||
function appendQueryParam (url, queryParam , value) {
|
||||
if (url.indexOf("?") > 0) {
|
||||
return url + "&" + queryParam + "=" + value;
|
||||
}
|
||||
return url + "?" + queryParam + "=" + value;
|
||||
}
|
||||
|
||||
if (uriMatcher.match("/{context}/api/data-tables/invoker/filters")) {
|
||||
var result = {};
|
||||
var i;
|
||||
//Fetching Status types
|
||||
var status = EnrolmentInfo.Status.values();
|
||||
var statusArr = [];
|
||||
for(i = 0; i < status.length; i++){
|
||||
statusArr.push(status[i].name());
|
||||
}
|
||||
result.status = statusArr;
|
||||
//Fetching Ownership types
|
||||
var ownership = EnrolmentInfo.OwnerShip.values();
|
||||
var ownershipArr = [];
|
||||
for(i = 0; i < ownership.length; i++){
|
||||
ownershipArr.push(ownership[i].name());
|
||||
}
|
||||
result.ownership = ownershipArr;
|
||||
//Fetching Device Types
|
||||
result.deviceTypes = [];
|
||||
var deviceTypesRes = deviceModule.getDeviceTypes();
|
||||
if (deviceTypesRes.status === "success") {
|
||||
var deviceTypes = deviceTypesRes["content"];
|
||||
for (i = 0; i < deviceTypes.length; i++) {
|
||||
var deviceTypeName = deviceTypes[i].name;
|
||||
var deviceTypeLabel = deviceTypeName.charAt(0).toUpperCase() + deviceTypeName.slice(1);
|
||||
var configs = utility.getDeviceTypeConfig(deviceTypeLabel);
|
||||
if (configs) {
|
||||
if (configs[DTYPE_CONF_DEVICE_TYPE_KEY][DTYPE_CONF_DEVICE_TYPE_LABEL_KEY]) {
|
||||
deviceTypeLabel = configs[DTYPE_CONF_DEVICE_TYPE_KEY][DTYPE_CONF_DEVICE_TYPE_LABEL_KEY];
|
||||
}
|
||||
}
|
||||
result.deviceTypes.push({"name": deviceTypeLabel, "value": deviceTypeName});
|
||||
}
|
||||
}
|
||||
//Adding policy compliance
|
||||
result.compliance = ["MONITOR", "ENFORCE", "WARN", "BLOCK"];
|
||||
result.depStatus = ["Empty", "Assigned", "Pushed", "Removed"];
|
||||
response["status"] = 200;
|
||||
response["content"] = result;
|
||||
response["contentType"] = "application/json";
|
||||
} else if (uriMatcher.match("/{context}/api/data-tables/invoker")) {
|
||||
var url = request.getParameter("url");
|
||||
var targetURL = devicemgtProps["httpsURL"] + request.getParameter("url");
|
||||
//noinspection JSUnresolvedFunction getAllParameters
|
||||
var allParams = request.getAllParameters();
|
||||
|
||||
for (var allParamsKey in allParams) {
|
||||
if (allParams.hasOwnProperty(allParamsKey)) {
|
||||
if (allParamsKey == "limit" || allParamsKey == "offset") {
|
||||
targetURL = appendQueryParam(targetURL, allParamsKey, allParams[allParamsKey]);
|
||||
} else if (allParamsKey == "filter") {
|
||||
if (allParams[allParamsKey]) {
|
||||
var searchPayload = JSON.parse(allParams[allParamsKey]);
|
||||
for (var searchPayloadKey in searchPayload) {
|
||||
if (searchPayload.hasOwnProperty(searchPayloadKey)) {
|
||||
targetURL = appendQueryParam(targetURL, searchPayloadKey, searchPayload[searchPayloadKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
serviceInvokers.XMLHttp.get(
|
||||
targetURL,
|
||||
// response callback
|
||||
function (backendResponse) {
|
||||
response["status"] = backendResponse["status"];
|
||||
response["content"] = utility.encodeJson(backendResponse["responseText"]);
|
||||
response["contentType"] = "application/json";
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -1,227 +0,0 @@
|
||||
<%
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
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/business-controllers/device.js")["deviceModule"];
|
||||
var utility = require("/app/modules/utility.js").utility;
|
||||
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
|
||||
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
|
||||
|
||||
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")) {
|
||||
// works as a proxy to pass the relavant query string to back end api.
|
||||
var queryString = request.getQueryString();
|
||||
if (!queryString) {
|
||||
queryString = "";
|
||||
} else {
|
||||
queryString = "?" + queryString;
|
||||
}
|
||||
|
||||
var deviceType = request.getParameter("deviceType"); // need a better solution here
|
||||
deviceTypeConfig = utility.getDeviceTypeConfig(deviceType);
|
||||
if (deviceTypeConfig && deviceTypeConfig.deviceType.downloadAgentUri) {
|
||||
hearders = [{"name": constants["ACCEPT_IDENTIFIER"], "value": constants["APPLICATION_ZIP"]}];
|
||||
sketchDownloadEndPoint = devicemgtProps["httpsURL"] + "/" + deviceTypeConfig.deviceType.downloadAgentUri;
|
||||
serviceInvokers.HttpClient.get(sketchDownloadEndPoint + queryString, function (responsePayload, responseHeaders) {
|
||||
if (responseHeaders) {
|
||||
for (var i = 0; i < responseHeaders.length; i++) {
|
||||
var header = responseHeaders[i];
|
||||
var headerName = String(header.getName());
|
||||
var headerValue = String(header.getValue());
|
||||
response.addHeader(headerName, headerValue);
|
||||
}
|
||||
var streamObject = new Stream(responsePayload);
|
||||
print(streamObject);
|
||||
} else {
|
||||
return responsePayload;
|
||||
}
|
||||
}, function (responsePayload) {
|
||||
log.error(responsePayload);
|
||||
var response = {};
|
||||
response["status"] = "error";
|
||||
return response;
|
||||
}
|
||||
, hearders);
|
||||
} else {
|
||||
result = 400;
|
||||
}
|
||||
} else if (uriMatcher.match("/{context}/api/devices/sketch/generate_link")) {
|
||||
|
||||
if (!request.getContent()){
|
||||
log.error("Request Payload Is Empty");
|
||||
// HTTP status code 400 refers to - Bad request.
|
||||
result = 400;
|
||||
} else{
|
||||
deviceType = request.getContent()["deviceType"];
|
||||
queryString = "?deviceName=" + request.getContent()["deviceName"] +"&deviceType="+
|
||||
request.getContent()["deviceType"]+"&sketchType="+request.getContent()["sketchType"];
|
||||
deviceTypeConfig = utility.getDeviceTypeConfig(deviceType);
|
||||
if (deviceTypeConfig && deviceTypeConfig.deviceType.downloadAgentUri) {
|
||||
|
||||
sketchDownloadEndPoint = devicemgtProps["httpsURL"] + "/" + deviceTypeConfig.deviceType.downloadAgentUri;
|
||||
|
||||
var requestUrl = sketchDownloadEndPoint + queryString
|
||||
result = "curl -k -o "+request.getContent()["deviceName"]+".zip -H \"Authorization: Bearer "
|
||||
+JSON.parse(session.get(constants["TOKEN_PAIR"])).accessToken+"\" " +"'"+requestUrl+"'";
|
||||
|
||||
} else {
|
||||
// HTTP status code 400 refers to - Bad request.
|
||||
result = 400;
|
||||
}
|
||||
}
|
||||
|
||||
} 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);
|
||||
} else if (uriMatcher.match("/{context}/api/devices")) {
|
||||
var url = request.getParameter("url");
|
||||
var draw = request.getParameter("draw");
|
||||
var length = request.getParameter("length");
|
||||
var start = request.getParameter("start");
|
||||
var search = request.getParameter("search[value]");
|
||||
var deviceName = request.getParameter("columns[1][search][value]");
|
||||
var owner = request.getParameter("columns[2][search][value]");
|
||||
var status = request.getParameter("columns[3][search][value]");
|
||||
var platform = request.getParameter("columns[4][search][value]");
|
||||
var ownership = request.getParameter("columns[5][search][value]");
|
||||
var targetURL;
|
||||
|
||||
function appendQueryParam (url, queryParam , value) {
|
||||
if (url.indexOf("?") > 0) {
|
||||
return url + "&" + queryParam + "=" + value;
|
||||
}
|
||||
return url + "?" + queryParam + "=" + value;
|
||||
}
|
||||
targetURL = devicemgtProps.httpsURL + request.getParameter("url");
|
||||
targetURL = appendQueryParam(targetURL, "draw", draw);
|
||||
targetURL = appendQueryParam(targetURL, "start", start);
|
||||
targetURL = appendQueryParam(targetURL, "length", length);
|
||||
|
||||
if (search && search !== "") {
|
||||
targetURL = appendQueryParam(targetURL, "search", search);
|
||||
}
|
||||
|
||||
if (deviceName && deviceName !== "") {
|
||||
targetURL = appendQueryParam(targetURL, "device-name", deviceName);
|
||||
}
|
||||
|
||||
if (owner && owner !== "") {
|
||||
targetURL = appendQueryParam(targetURL, "user", owner);
|
||||
}
|
||||
|
||||
if (status && status !== "") {
|
||||
targetURL = appendQueryParam(targetURL, "status", status);
|
||||
}
|
||||
|
||||
if (platform && platform !== "") {
|
||||
targetURL = appendQueryParam(targetURL, "type", platform);
|
||||
}
|
||||
|
||||
if (ownership && ownership !== "") {
|
||||
targetURL = appendQueryParam(targetURL, "ownership", ownership);
|
||||
}
|
||||
|
||||
serviceInvokers.XMLHttp.get(
|
||||
targetURL, function (responsePayload) {
|
||||
response.status = 200;
|
||||
result = responsePayload;
|
||||
},
|
||||
function (responsePayload) {
|
||||
response.status = responsePayload.status;
|
||||
result = responsePayload.responseText;
|
||||
});
|
||||
} else if (uriMatcher.match("/{context}/api/devices/")) {
|
||||
if (userModule.isAuthorized("/permission/admin/device-mgt/devices/list")) {
|
||||
result = deviceModule.listDevices();
|
||||
} else {
|
||||
response.sendError(403);
|
||||
}
|
||||
} else if (uriMatcher.match("/{context}/api/devices/{type}/{deviceId}")) {
|
||||
elements = uriMatcher.elements();
|
||||
deviceId = elements.deviceId;
|
||||
type = elements.type;
|
||||
if (userModule.isAuthorized("/permission/admin/device-mgt/devices/list")) {
|
||||
result = deviceModule.viewDevice(type, deviceId);
|
||||
}else {
|
||||
response.sendError(403);
|
||||
}
|
||||
} else if (uriMatcher.match("/{context}/api/devices/agent/{type}/{deviceId}/config")) {
|
||||
elements = uriMatcher.elements();
|
||||
deviceId = elements.deviceId;
|
||||
type = elements.type;
|
||||
operation = elements.operation;
|
||||
if (userModule.isAuthorized("/permission/admin/device-mgt/devices/owning-device")) {
|
||||
result = deviceModule.getDeviceAgentConfig(type, deviceId);
|
||||
if (!result) {
|
||||
response.sendError(500);
|
||||
}
|
||||
} else {
|
||||
response.sendError(403);
|
||||
}
|
||||
} else if (uriMatcher.match("{context}/api/devices/{type}/{deviceId}/{operation}")) {
|
||||
elements = uriMatcher.elements();
|
||||
deviceId = elements.deviceId;
|
||||
type = elements.type;
|
||||
operation = elements.operation;
|
||||
if (userModule.isAuthorized("/permission/admin/device-mgt/devices/operation")) {
|
||||
result = deviceModule.performOperation(deviceId, operation, [], type);
|
||||
} else {
|
||||
response.sendError(403);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Returning the result.
|
||||
if (result) {
|
||||
print(result);
|
||||
}
|
||||
|
||||
%>
|
||||
@ -1,138 +0,0 @@
|
||||
<%
|
||||
var log = new Log("api/enterprise.jag");
|
||||
|
||||
var uri = request.getRequestURI();
|
||||
var uriMatcher = new URIMatcher(String(uri));
|
||||
|
||||
var constants = require("/app/modules/constants.js");
|
||||
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
|
||||
var restAPIRequestDetails = request.getContent();
|
||||
var result;
|
||||
var user = session.get(constants.USER_SESSION_KEY);
|
||||
|
||||
// This checks if the session is valid
|
||||
getAccessToken = function() {
|
||||
if (session) {
|
||||
var tokenPair = session.get(constants["TOKEN_PAIR"]);
|
||||
if (tokenPair) {
|
||||
return parse(tokenPair)["accessToken"];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
callBackend = function(url, token, method, payload) {
|
||||
var xmlHttpRequest = new XMLHttpRequest();
|
||||
xmlHttpRequest.open(method, url);
|
||||
xmlHttpRequest.setRequestHeader(constants["AUTHORIZATION_HEADER"], constants["BEARER_PREFIX"] + token);
|
||||
xmlHttpRequest.setRequestHeader(constants["CONTENT_TYPE_IDENTIFIER"], constants["APPLICATION_JSON"]);
|
||||
xmlHttpRequest.setRequestHeader(constants["ACCEPT_IDENTIFIER"], constants["APPLICATION_JSON"]);
|
||||
if (payload) {
|
||||
xmlHttpRequest.send(payload);
|
||||
} else {
|
||||
xmlHttpRequest.send();
|
||||
}
|
||||
response["status"] = xmlHttpRequest["status"];
|
||||
if (xmlHttpRequest["responseText"]) {
|
||||
result = xmlHttpRequest["responseText"];
|
||||
response["content"] = xmlHttpRequest["responseText"];
|
||||
}
|
||||
};
|
||||
|
||||
var accessToken = getAccessToken();
|
||||
if (!user || accessToken == null) {
|
||||
response.sendRedirect("/devicemgt/login?#login-required");
|
||||
exit();
|
||||
} else {
|
||||
response.contentType = 'application/json';
|
||||
if (uriMatcher.match("/{context}/api/enterprise/token")) {
|
||||
session.put("externalEndpoint", restAPIRequestDetails["endpoint"]);
|
||||
session.put("externalToken", restAPIRequestDetails["externalToken"]);
|
||||
log.info("Calling get token");
|
||||
callBackend(restAPIRequestDetails["endpoint"], session.get("externalToken"), "POST", restAPIRequestDetails);
|
||||
if (response["status"] && response["status"] == 200) {
|
||||
var completionToken = parse(result)["completionToken"];
|
||||
if (completionToken) {
|
||||
log.info("Token received");
|
||||
session.put("completionToken", completionToken)
|
||||
}
|
||||
}
|
||||
} else if (uriMatcher.match("/{context}/api/enterprise/enroll-complete")) {
|
||||
var tokenEndpoint = session.get("externalEndpoint")
|
||||
var enterpriseEndpoint = tokenEndpoint.replace("signup-url", "complete-signup");
|
||||
|
||||
var completionToken = session.get("completionToken");
|
||||
var enterpriseToken = request.getParameter("enterpriseToken");
|
||||
|
||||
log.debug("completionToken" + completionToken + ", enterpriseEndpoint" + enterpriseEndpoint +
|
||||
", enterpriseToken" + enterpriseToken);
|
||||
|
||||
var requestPayload = {}
|
||||
requestPayload.completionToken = completionToken;
|
||||
requestPayload.enterpriseToken = enterpriseToken;
|
||||
log.info("Calling complete-signup");
|
||||
callBackend(enterpriseEndpoint, session.get("externalToken"), "POST", requestPayload);
|
||||
|
||||
var enterpriseId = parse(result)["id"];
|
||||
if (enterpriseId) {
|
||||
log.info("Calling complete-signup success");
|
||||
var serviceAccountRequest = {};
|
||||
serviceAccountRequest.enterpriseId = enterpriseId;
|
||||
serviceAccountRequest.keyType = "googleCredentials"
|
||||
|
||||
var enterpriseEndpoint = tokenEndpoint.replace("signup-url", "create-esa");
|
||||
|
||||
log.info("Calling create-esa");
|
||||
callBackend(enterpriseEndpoint, session.get("externalToken"), "POST", serviceAccountRequest);
|
||||
var data = parse(result)["data"];
|
||||
log.info("Calling create-esa success" + data);
|
||||
|
||||
var androidConfigAPI = devicemgtProps["httpsURL"] + "/api/device-mgt/android/v1.0/configuration";
|
||||
log.info("fetching platform configs");
|
||||
callBackend(androidConfigAPI, accessToken, "GET");
|
||||
|
||||
var configurationsList = parse(result);
|
||||
|
||||
for (var x = 0; x < configurationsList.configuration.length; x++) {
|
||||
if (configurationsList.configuration[x].name == "esa" || configurationsList.configuration[x].name == "enterpriseId") {
|
||||
configurationsList.configuration.splice(x, 1);
|
||||
}
|
||||
}
|
||||
log.info("fetching platform configs success");
|
||||
var payloadToAdd = {};
|
||||
payloadToAdd.contentType = "text";
|
||||
payloadToAdd.name = "esa";
|
||||
payloadToAdd.value = data;
|
||||
|
||||
var enterpriseIdPayload = {};
|
||||
enterpriseIdPayload.contentType = "text";
|
||||
enterpriseIdPayload.name = "enterpriseId";
|
||||
enterpriseIdPayload.value = enterpriseId;
|
||||
|
||||
configurationsList.configuration[configurationsList.configuration.length] = payloadToAdd;
|
||||
configurationsList.configuration[configurationsList.configuration.length] = enterpriseIdPayload;
|
||||
|
||||
log.info("saving platform configs");
|
||||
callBackend(androidConfigAPI, accessToken, "PUT", configurationsList);
|
||||
log.info("saving platform configs success");
|
||||
if (response["status"] == 200) {
|
||||
log.info("Process successful!! Redirecting...");
|
||||
response.sendRedirect("/devicemgt/platform-configuration?enterprise-success=true");
|
||||
}
|
||||
}
|
||||
} else if (uriMatcher.match("/{context}/api/enterprise/unenroll")) {
|
||||
session.put("externalEndpoint", restAPIRequestDetails["endpoint"]);
|
||||
session.put("externalToken", restAPIRequestDetails["externalToken"]);
|
||||
callBackend(restAPIRequestDetails["endpoint"], session.get("externalToken"), "GET", restAPIRequestDetails);
|
||||
log.info("Calling unenroll");
|
||||
if (response["status"] == 200) {
|
||||
log.info("Unenroll success, wiping devices.");
|
||||
var wipeURL = devicemgtProps["httpsURL"] + "/api/device-mgt/android/v1.0/enterprise/wipe-device"
|
||||
callBackend(wipeURL, accessToken, "GET");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
%>
|
||||
@ -1,87 +0,0 @@
|
||||
<%
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
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 utility = require("/app/modules/utility.js").utility;
|
||||
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
|
||||
|
||||
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/groups")) {
|
||||
var url = request.getParameter("url");
|
||||
var draw = request.getParameter("draw");
|
||||
var length = request.getParameter("length");
|
||||
var start = request.getParameter("start");
|
||||
var search = request.getParameter("search[value]");
|
||||
var groupName = request.getParameter("columns[1][search][value]");
|
||||
var owner = request.getParameter("columns[2][search][value]");
|
||||
var targetURL;
|
||||
|
||||
function appendQueryParam(url, queryParam, value) {
|
||||
if (url.indexOf("?") > 0) {
|
||||
return url + "&" + queryParam + "=" + value;
|
||||
}
|
||||
return url + "?" + queryParam + "=" + value;
|
||||
}
|
||||
|
||||
targetURL = devicemgtProps.httpsURL + request.getParameter("url");
|
||||
targetURL = appendQueryParam(targetURL, "start", start);
|
||||
targetURL = appendQueryParam(targetURL, "length", length);
|
||||
|
||||
if (search && search !== "") {
|
||||
targetURL = appendQueryParam(targetURL, "search", search);
|
||||
}
|
||||
|
||||
if (groupName && groupName !== "") {
|
||||
targetURL = appendQueryParam(targetURL, "group-name", groupName);
|
||||
}
|
||||
|
||||
if (owner && owner !== "") {
|
||||
targetURL = appendQueryParam(targetURL, "user", owner);
|
||||
}
|
||||
|
||||
serviceInvokers.XMLHttp.get(
|
||||
targetURL, function (responsePayload) {
|
||||
response.status = 200;
|
||||
result = responsePayload;
|
||||
},
|
||||
function (responsePayload) {
|
||||
response.status = responsePayload.status;
|
||||
result = responsePayload.responseText;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (result) {
|
||||
print(result);
|
||||
}
|
||||
|
||||
%>
|
||||
@ -1,119 +0,0 @@
|
||||
<%
|
||||
/*
|
||||
* 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 log = new Log("api/invoker-api.jag");
|
||||
|
||||
var uri = request.getRequestURI();
|
||||
var uriMatcher = new URIMatcher(String(uri));
|
||||
|
||||
var constants = require("/app/modules/constants.js");
|
||||
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
|
||||
|
||||
if (uriMatcher.match("/{context}/api/invoker/execute/")) {
|
||||
//NOTE: We are only interested in Content-Type headers. Appending all request headers to the back-end call
|
||||
// will cause unforeseen security issues.
|
||||
var contentType = request.getHeader(constants.CONTENT_TYPE_IDENTIFIER);
|
||||
var acceptType = request.getHeader(constants.ACCEPT_IDENTIFIER);
|
||||
var requestHeaders = [];
|
||||
requestHeaders.push({"name": constants.CONTENT_TYPE_IDENTIFIER, "value" : contentType});
|
||||
requestHeaders.push({"name": constants.ACCEPT_IDENTIFIER, "value" : acceptType});
|
||||
|
||||
var restAPIRequestDetails = request.getContent();
|
||||
|
||||
var requestMethod = restAPIRequestDetails["requestMethod"];
|
||||
var requestURL = restAPIRequestDetails["requestURL"];
|
||||
var requestPayload = restAPIRequestDetails["requestPayload"];
|
||||
|
||||
if (!requestMethod) {
|
||||
requestMethod = parse(restAPIRequestDetails)["requestMethod"];
|
||||
}
|
||||
|
||||
if (!requestURL) {
|
||||
requestURL = parse(restAPIRequestDetails)["requestURL"];
|
||||
}
|
||||
|
||||
if (!requestPayload) {
|
||||
requestPayload = parse(restAPIRequestDetails)["requestPayload"];
|
||||
}
|
||||
|
||||
var restAPIEndpoint = devicemgtProps["httpsURL"] + requestURL;
|
||||
|
||||
try {
|
||||
switch (requestMethod) {
|
||||
case constants["HTTP_GET"]:
|
||||
serviceInvokers.XMLHttp.get(
|
||||
restAPIEndpoint,
|
||||
function (restAPIResponse) {
|
||||
response["status"] = restAPIResponse["status"];
|
||||
if (restAPIResponse["responseText"]) {
|
||||
response["content"] = restAPIResponse["responseText"];
|
||||
}
|
||||
},
|
||||
requestHeaders
|
||||
);
|
||||
break;
|
||||
case constants["HTTP_POST"]:
|
||||
serviceInvokers.XMLHttp.post(
|
||||
restAPIEndpoint,
|
||||
requestPayload,
|
||||
function (restAPIResponse) {
|
||||
response["status"] = restAPIResponse["status"];
|
||||
if (restAPIResponse["responseText"]) {
|
||||
response["content"] = restAPIResponse["responseText"];
|
||||
}
|
||||
},
|
||||
requestHeaders
|
||||
);
|
||||
break;
|
||||
case constants["HTTP_PUT"]:
|
||||
serviceInvokers.XMLHttp.put(
|
||||
restAPIEndpoint,
|
||||
requestPayload,
|
||||
function (restAPIResponse) {
|
||||
response["status"] = restAPIResponse["status"];
|
||||
if (restAPIResponse["responseText"]) {
|
||||
response["content"] = restAPIResponse["responseText"];
|
||||
}
|
||||
},
|
||||
requestHeaders
|
||||
);
|
||||
break;
|
||||
case constants["HTTP_DELETE"]:
|
||||
serviceInvokers.XMLHttp.delete(
|
||||
restAPIEndpoint,
|
||||
function (restAPIResponse) {
|
||||
response["status"] = restAPIResponse["status"];
|
||||
if (restAPIResponse["responseText"]) {
|
||||
response["content"] = restAPIResponse["responseText"];
|
||||
}
|
||||
},
|
||||
requestHeaders
|
||||
);
|
||||
break;
|
||||
}
|
||||
} catch (e) {
|
||||
//Since this is an API we'll log the error message.
|
||||
log.error(e.message); // JavaScript error message
|
||||
log.error(e.stack); // Executed JavaScript file stack
|
||||
throw new Error("Exception occurred while trying to access " +
|
||||
"backend REST API services from Jaggery API invoker layer", e);
|
||||
}
|
||||
}
|
||||
%>
|
||||
@ -1,68 +0,0 @@
|
||||
<%
|
||||
/*
|
||||
* 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 serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
|
||||
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
|
||||
if (uriMatcher.match("/{context}/api/operation/paginate")) {
|
||||
var deviceType = request.getParameter("deviceType");
|
||||
var deviceId = request.getParameter("deviceId");
|
||||
var owner = request.getParameter("owner");
|
||||
var ownership = request.getParameter("ownership");
|
||||
var index = request.getParameter("start");
|
||||
var length = request.getParameter("length");
|
||||
var search = request.getParameter("search[value]");
|
||||
|
||||
var restAPIEndpoint = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
|
||||
"/devices/" + deviceType + "/" + deviceId + "/operations?owner=" + owner + "&ownership=" + ownership +
|
||||
"&offset=" + index + "&limit=" + length;
|
||||
|
||||
serviceInvokers.XMLHttp.get(
|
||||
restAPIEndpoint,
|
||||
function (restAPIResponse) {
|
||||
if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) {
|
||||
var responsePayload = parse(restAPIResponse["responseText"]);
|
||||
|
||||
var paginatedResult = {};
|
||||
paginatedResult["recordsTotal"] = responsePayload["count"];
|
||||
paginatedResult["recordsFiltered"] = responsePayload["count"];
|
||||
paginatedResult["data"] = responsePayload["operations"];
|
||||
|
||||
response["status"] = restAPIResponse["status"];
|
||||
response["content"] = paginatedResult;
|
||||
} else {
|
||||
response["status"] = restAPIResponse["status"];
|
||||
if (restAPIResponse["responseText"]) {
|
||||
var responseText = "";
|
||||
try {
|
||||
response["content"] = parse(restAPIResponse["responseText"]);
|
||||
} catch (e) {
|
||||
responseText = restAPIResponse["responseText"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
%>
|
||||
@ -1,52 +0,0 @@
|
||||
<%
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
@Deprecated
|
||||
*/
|
||||
|
||||
var uri = request.getRequestURI();
|
||||
var uriMatcher = new URIMatcher(String(uri));
|
||||
|
||||
var log = new Log("api/policy-api.jag");
|
||||
|
||||
var constants = require("/modules/constants.js");
|
||||
var policyModule = require("/app/modules/business-controllers/group.js")["groupModule"];
|
||||
|
||||
var result;
|
||||
if (uriMatcher.match("/{context}/api/policies/update")) {
|
||||
payload = request.getContent();
|
||||
policyModule.updatePolicyPriorities(payload);
|
||||
} else if (uriMatcher.match("/{context}/api/policies/{id}/delete")) {
|
||||
elements = uriMatcher.elements();
|
||||
policyId = elements.id;
|
||||
try {
|
||||
result = policyModule.deletePolicy(policyId);
|
||||
} catch (e) {
|
||||
log.error("Exception occurred while trying to delete policy for id:" + policyId, e);
|
||||
// http status code 500 refers to - Internal Server Error.
|
||||
result = 500;
|
||||
}
|
||||
}
|
||||
|
||||
// returning the result.
|
||||
if (result) {
|
||||
response.content = result;
|
||||
}
|
||||
%>
|
||||
@ -1,77 +0,0 @@
|
||||
<%
|
||||
/*
|
||||
* 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 serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
|
||||
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
|
||||
if (uriMatcher.match("/{context}/api/stats/paginate")) {
|
||||
var deviceType = request.getParameter("deviceType");
|
||||
var deviceId = request.getParameter("deviceId");
|
||||
var from = request.getParameter("from");
|
||||
var to = request.getParameter("to");
|
||||
var index = request.getParameter("start");
|
||||
var length = request.getParameter("length");
|
||||
var keys = request.getParameter("attributes");
|
||||
keys = JSON.parse(keys);
|
||||
var restAPIEndpoint = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/events/"
|
||||
+ deviceType + "/" + deviceId + "?offset=" + index +"&limit=" + length + "&from="+ from + "&to=" + to;
|
||||
serviceInvokers.XMLHttp.get(
|
||||
restAPIEndpoint,
|
||||
function (restAPIResponse) {
|
||||
if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) {
|
||||
var responsePayload = parse(restAPIResponse["responseText"]);
|
||||
|
||||
var paginatedResult = {};
|
||||
paginatedResult["recordsTotal"] = responsePayload["count"];
|
||||
paginatedResult["recordsFiltered"] = responsePayload["count"];
|
||||
var records = responsePayload["records"];
|
||||
var dataSet = [];
|
||||
for (var i = 0; i < records.length; i++){
|
||||
var record = records[i];
|
||||
var timestamp = record["timestamp"];
|
||||
var dataRow = [];
|
||||
dataRow.push(timestamp);
|
||||
for (var j = 0; j < keys.length; j++) {
|
||||
var key = keys[j];
|
||||
dataRow.push(record.values[key]);
|
||||
}
|
||||
//dataSet.push(dataRow);
|
||||
dataSet.push(dataRow);
|
||||
}
|
||||
paginatedResult["data"] = dataSet;
|
||||
response["status"] = restAPIResponse["status"];
|
||||
response["content"] = paginatedResult;
|
||||
} else {
|
||||
response["status"] = 204;
|
||||
var paginatedResult = {};
|
||||
var dataSet = [];
|
||||
paginatedResult["recordsTotal"] = 0;
|
||||
paginatedResult["recordsFiltered"] = 0;
|
||||
paginatedResult["data"] = dataSet;
|
||||
response["content"] = paginatedResult;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
%>
|
||||
@ -1,211 +0,0 @@
|
||||
<%
|
||||
/*
|
||||
* 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/modules/conf-reader/main.js")["conf"];
|
||||
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
|
||||
var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
|
||||
var utility = require("/app/modules/utility.js")["utility"];
|
||||
var apiWrapperUtil = require("/app/modules/oauth/token-handlers.js")["handlers"];
|
||||
var util = require("/app/modules/oauth/token-handler-utils.js")["utils"];
|
||||
|
||||
var responseProcessor = require("utils").response;
|
||||
|
||||
var result;
|
||||
if (uriMatcher.match("/{context}/api/user/clearBilling")) {
|
||||
|
||||
carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||
session.put('BILLING_INFO_' + carbonUser.domain, null);
|
||||
log.info("billing info cleared for " + carbonUser.domain);
|
||||
|
||||
} else 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);
|
||||
}
|
||||
apiWrapperUtil.setupTokenPairByPasswordGrantType(username, 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);
|
||||
}
|
||||
|
||||
apiWrapperUtil.setupTokenPairByPasswordGrantType(username, password);
|
||||
var permissions = userModule.getUIPermissions();
|
||||
if (permissions.VIEW_DASHBOARD) {
|
||||
response.sendRedirect(devicemgtProps["appContext"]);
|
||||
} else {
|
||||
response.sendRedirect(devicemgtProps["appContext"] + "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/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/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.userValidationConfig.usernameLength) {
|
||||
log.error("Username Must be between 1 and " + devicemgtProps.userValidationConfig.usernameLength + " characters long");
|
||||
result = "Username Must be between 1 and " + devicemgtProps.userValidationConfig.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 = ["internal/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/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();
|
||||
} else if (uriMatcher.match("/{context}/api/user/environment-loaded")) {
|
||||
try {
|
||||
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||
if (!carbonUser) {
|
||||
response.sendRedirect("/devicemgt/login?#login-required");
|
||||
exit();
|
||||
}
|
||||
utility.startTenantFlow(carbonUser);
|
||||
var APIManagementProviderService = utility.getAPIManagementProviderService();
|
||||
var isLoaded = APIManagementProviderService.isTierLoaded();
|
||||
result = {"isLoaded": isLoaded};
|
||||
if (isLoaded) {
|
||||
var samlToken = session.get(constants.SAML_TOKEN_KEY);
|
||||
if (samlToken) {
|
||||
apiWrapperUtil.setupTokenPairByJWTGrantType(carbonUser.username + '@' + carbonUser.domain, samlToken);
|
||||
}
|
||||
}
|
||||
response.contentType = 'application/json';
|
||||
} finally {
|
||||
utility.endTenantFlow();
|
||||
}
|
||||
}
|
||||
|
||||
// returning the result.
|
||||
if (result) {
|
||||
print(result);
|
||||
}
|
||||
%>
|
||||
@ -1,47 +0,0 @@
|
||||
{
|
||||
"appName": "Entgra IoT Server",
|
||||
"cachingEnabled": false,
|
||||
"debuggingEnabled": false,
|
||||
"permissionRoot": "/",
|
||||
"portalURL": "https://${server.ip}:9445",
|
||||
"loginPage": "cdmf.page.sign-in.login-do",
|
||||
"adminServicesUrl": "https://${server.ip}:${server.https_port}/admin/services/",
|
||||
"authModule": {
|
||||
"enabled": true,
|
||||
"login": {
|
||||
"onSuccess": {
|
||||
"script": "/app/modules/login.js",
|
||||
"page": "cdmf.page.processing"
|
||||
},
|
||||
"onFail": {
|
||||
"script": "/app/modules/login.js",
|
||||
"page": "cdmf.page.sign-in.login-do"
|
||||
}
|
||||
},
|
||||
"logout": {
|
||||
"onSuccess": {
|
||||
"page": "cdmf.page.sign-in.login-do"
|
||||
},
|
||||
"onFail": {
|
||||
"page": "cdmf.page.dashboard"
|
||||
}
|
||||
},
|
||||
"sso": {
|
||||
"enabled": true,
|
||||
"issuer" : "devicemgt",
|
||||
"appName" : "devicemgt",
|
||||
"identityProviderUrl" : "https://%iot.keymanager.host%:%iot.keymanager.https.port%/samlsso",
|
||||
"acs": "https://%iot.manager.host%:%iot.manager.https.port%/devicemgt/uuf/sso/acs",
|
||||
"identityAlias": "wso2carbon",
|
||||
"defaultNameIDPolicy": "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified",
|
||||
"isPassive":false,
|
||||
"responseSigningEnabled" : true,
|
||||
"validateAssertionValidityPeriod": true,
|
||||
"validateAudienceRestriction": true,
|
||||
"assertionSigningEnabled": true
|
||||
}
|
||||
},
|
||||
"errorPages": {
|
||||
"default": "uuf.page.error"
|
||||
}
|
||||
}
|
||||
@ -1,174 +0,0 @@
|
||||
{
|
||||
"appContext": "/devicemgt/",
|
||||
"isCloud": false,
|
||||
"isDeviceOwnerEnabled": false,
|
||||
"managerHTTPSURL": "https://%iot.manager.host%:%iot.manager.https.port%",
|
||||
"httpsURL": "https://%iot.gateway.host%:%iot.gateway.https.port%",
|
||||
"httpURL": "http://%iot.gateway.host%:%iot.gateway.http.port%",
|
||||
"wssURL": "https://%iot.core.host%:%iot.core.https.port%",
|
||||
"remoteSessionWSURL": "https://%iot.manager.host%:%iot.manager.https.port%",
|
||||
"portalURL": "https://%iot.analytics.host%:%iot.analytics.https.port%",
|
||||
"dashboardServerURL": "%https.ip%",
|
||||
"androidAgentDownloadURL": "https://%iot.manager.host%:%iot.manager.https.port%/devicemgt/public/cdmf.unit.device.type.android.type-view/assets/android-agent.apk",
|
||||
"windowsEnrollmentDir": "/windows-web-agent/enrollment",
|
||||
"iOSEnrollmentDir": "/ios-web-agent/enrollment",
|
||||
"iOSConfigRoot": "https://%iot.manager.host%:%iot.manager.https.port%/ios-enrollment/",
|
||||
"iOSAPIRoot": "https://%iot.manager.host%:%iot.manager.https.port%/ios/",
|
||||
"adminService": "https://%iot.manager.host%:%iot.manager.https.port%",
|
||||
"deviceInfoServiceAPI" : "/api/device-mgt/%device-type%/v1.0/admin/devices/info",
|
||||
"deviceLocationServiceAPI" : "/api/device-mgt/%device-type%/v1.0/admin/devices/location",
|
||||
"iOSDeviceInfoServiceAPI" : "/api/device-mgt/%device-type%/v1.0/admin/devices/info",
|
||||
"gatewayEnabled": true,
|
||||
"oauthProvider": {
|
||||
"appRegistration": {
|
||||
"appType": "webapp",
|
||||
"clientName": "iot_ui",
|
||||
"owner": "admin@carbon.super",
|
||||
"dynamicClientAppRegistrationServiceURL": "https://%iot.gateway.host%:%iot.gateway.https.port%/dynamic-client-web/register",
|
||||
"apiManagerClientAppRegistrationServiceURL": "https://%iot.gateway.host%:%iot.gateway.https.port%/api-application-registration/register/tenants",
|
||||
"grantType": "password refresh_token urn:ietf:params:oauth:grant-type:saml2-bearer urn:ietf:params:oauth:grant-type:jwt-bearer",
|
||||
"tokenScope": "admin",
|
||||
"callbackUrl": "https://%iot.gateway.host%:%iot.gateway.https.port%/api/device-mgt/v1.0",
|
||||
"samlGrantTypeName": "urn:ietf:params:oauth:grant-type:saml2-bearer"
|
||||
},
|
||||
"tokenServiceURL": "https://%iot.gateway.host%:%iot.gateway.https.port%/token"
|
||||
},
|
||||
"adminUser": "admin@carbon.super",
|
||||
"adminUserTenantId": "-1234",
|
||||
"adminRole": "admin",
|
||||
"userValidationConfig": {
|
||||
"usernameLength": 30,
|
||||
"usernameJSRegEx": "^[\\S]{3,30}$",
|
||||
"usernameRegExViolationErrorMsg": "Provided username is invalid.",
|
||||
"usernameHelpMsg": "Should be in minimum 3 characters long and do not include any whitespaces.",
|
||||
"firstnameJSRegEx": "^.{3,30}$",
|
||||
"firstnameRegExViolationErrorMsg": "Provided first name is invalid.",
|
||||
"lastnameJSRegEx": "^.{3,30}$",
|
||||
"lastnameRegExViolationErrorMsg": "Provided last name is invalid.",
|
||||
"emailJSRegEx": "/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/",
|
||||
"emailRegExViolationErrorMsg": "Provided email is invalid."
|
||||
},
|
||||
"groupValidationConfig": {
|
||||
"groupNameJSRegEx": "^[\\S]{3,30}$",
|
||||
"groupNameRegExViolationErrorMsg": "Group name should be in minimum 3 characters long and should not include any whitespaces.",
|
||||
"groupNameHelpMsg": "Should be in minimum 3 characters long and should not include any whitespaces."
|
||||
},
|
||||
"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://%iot.manager.host%:%iot.manager.https.port%",
|
||||
"companyName": "Entgra Carbon Device Manager",
|
||||
"browserTitle": "Entgra Device Manager",
|
||||
"copyrightPrefix": "\u00A9 %date-year%, ",
|
||||
"copyrightOwner": "Entgra",
|
||||
"copyrightOwnersSite": "https://www.entgra.io/",
|
||||
"copyrightSuffix": " All Rights Reserved."
|
||||
},
|
||||
"scopes": [
|
||||
"dm:sign-csr",
|
||||
"dm:admin:devices:view",
|
||||
"dm:admin:topics:view",
|
||||
"rm:roles:add",
|
||||
"rm:users:add",
|
||||
"rm:roles:update",
|
||||
"rm:roles:permissions:view",
|
||||
"rm:roles:details:view",
|
||||
"rm:roles:view",
|
||||
"rm:roles:combined:add",
|
||||
"rm:roles:delete",
|
||||
"an:db:vulnerabilities",
|
||||
"an:db:non-compliant:count",
|
||||
"an:db:non-compliant",
|
||||
"an:db:by-groups",
|
||||
"an:db:device:count",
|
||||
"an:db:feature-non-compliant",
|
||||
"an:db:overview:count",
|
||||
"an:db:filtered-count",
|
||||
"an:db:details",
|
||||
"dm:activity:get",
|
||||
"dm:devices:delete",
|
||||
"dm:devices:app:view",
|
||||
"dm:devices:policy:view",
|
||||
"dm:devices:compliance:view",
|
||||
"dm:devices:features:view",
|
||||
"dm:devices:ops:view",
|
||||
"dm:devices:search",
|
||||
"dm:devices:details",
|
||||
"dm:devices:update",
|
||||
"dm:devices:view",
|
||||
"dm:conf:view",
|
||||
"dm:conf:manage",
|
||||
"pm:policies:remove",
|
||||
"pm:policies:priorities:update",
|
||||
"pm:policies:deactivate",
|
||||
"pm:policies:details:view",
|
||||
"pm:policies:add",
|
||||
"pm:policies:activate",
|
||||
"pm:policies:update",
|
||||
"pm:policies:change",
|
||||
"dm:policies:view",
|
||||
"um:users:add",
|
||||
"um:users:details:view",
|
||||
"um:users:count",
|
||||
"um:users:delete",
|
||||
"um:roles:view",
|
||||
"um:users:user-details:view",
|
||||
"um:users:cred:change",
|
||||
"um:users:search",
|
||||
"um:users:is-exist",
|
||||
"um:users:update",
|
||||
"um:users:invite",
|
||||
"um:admin:users:view",
|
||||
"dm:admin:enrollment:update",
|
||||
"gm:devices:view",
|
||||
"gm:groups:update",
|
||||
"gm:groups:add",
|
||||
"gm:groups:device:view",
|
||||
"gm:devices:count",
|
||||
"gm:groups:remove",
|
||||
"gm:groups:view",
|
||||
"gm:groups:groups-view",
|
||||
"gm:roles:share",
|
||||
"gm:groups:count",
|
||||
"gm:roles:view",
|
||||
"gm:devices:remove",
|
||||
"gm:devices:add",
|
||||
"gm:devices:assign",
|
||||
"dm:device-type:conf:view",
|
||||
"dm:device-type:features:view",
|
||||
"dm:device-type:view",
|
||||
"am:admin:app:install",
|
||||
"am:admin:app:uninstall",
|
||||
"gm:admin:groups:count",
|
||||
"gm:admin:groups:view",
|
||||
"dm:notif:mark-checked",
|
||||
"dm:notifications:view",
|
||||
"cm:cert:delete",
|
||||
"cm:cert:details:get",
|
||||
"cm:cert:view",
|
||||
"cm:cert:add",
|
||||
"cm:cert:verify",
|
||||
"dm:admin",
|
||||
"dm:device-type:deploy",
|
||||
"dm:device-type:event:modify",
|
||||
"dm:device-type:event:view",
|
||||
"dm:admin:device-type:modify",
|
||||
"dm:admin:device-type:view",
|
||||
"dm:admin:device-type:conf:add",
|
||||
"dm:device:enroll",
|
||||
"dm:geo:an:view",
|
||||
"dm:geo:alerts:manage",
|
||||
"dm:admin:devices:permanent-delete",
|
||||
"appm:read",
|
||||
"and:enterprise:modify",
|
||||
"and:enterprise:view"
|
||||
],
|
||||
"isOAuthEnabled": true,
|
||||
"backendRestEndpoints": {
|
||||
"deviceMgt": "/api/device-mgt/v1.0",
|
||||
"appMgt": "/api/application-mgt-store/v1.0"
|
||||
}
|
||||
}
|
||||
@ -1,138 +0,0 @@
|
||||
{
|
||||
"Logo": {
|
||||
"name": "Cloud",
|
||||
"url": "https://cloudmgt.cloud.wso2.com/cloudmgt",
|
||||
"target": "_parent"
|
||||
},
|
||||
"Main": {
|
||||
"Domain": {
|
||||
"url": "#",
|
||||
"icon": "fw fw-organization",
|
||||
"isAdminOnly": false,
|
||||
"target": "_parent",
|
||||
"dropDown": {
|
||||
"Organization": {
|
||||
"url": "https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/organization.jag",
|
||||
"icon": "fw fw-organization",
|
||||
"dropDown": "false",
|
||||
"target": "_self"
|
||||
},
|
||||
"Members": {
|
||||
"url": "https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/user.jag",
|
||||
"icon": "fa fa-users",
|
||||
"dropDown": "false",
|
||||
"target": "_self"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Account": {
|
||||
"url": "#",
|
||||
"icon": "fw fw-resource",
|
||||
"isAdminOnly": false,
|
||||
"billingEnabled": true,
|
||||
"billingApi": {
|
||||
"username": "admin",
|
||||
"password": "admin"
|
||||
},
|
||||
"cloudMgtHost" : "https://cloudmgt.cloudstaging.wso2.com",
|
||||
"cloudMgtIndexPage": "https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/index.jag",
|
||||
"dropDown": {
|
||||
"Upgrade Now": {
|
||||
"url": "https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/payment-plans.jag?cloud-type=device_cloud",
|
||||
"icon": "fw fw-export",
|
||||
"dropDown": "true",
|
||||
"target": "_self"
|
||||
},
|
||||
"Request Extension": {
|
||||
"url": "https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/contact-us.jag?cloud-type=device_cloud&request-extension=true",
|
||||
"icon": "fa fa-mail",
|
||||
"dropDown": "true",
|
||||
"target": "_self"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Support": {
|
||||
"url": "https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/contact-us.jag?cloud-type=device_cloud",
|
||||
"icon": "fw fw-mail",
|
||||
"isAdminOnly": false,
|
||||
"target": "_self",
|
||||
"dropDown": "false"
|
||||
},
|
||||
"Documentation": {
|
||||
"url": "#",
|
||||
"icon": "fw fw-document",
|
||||
"isAdminOnly": false,
|
||||
"dropDown": {
|
||||
"Device Cloud": {
|
||||
"id": "device_cloud",
|
||||
"url": "https://docs.wso2.com/display/DeviceCloud/WSO2+Device+Cloud+Documentation",
|
||||
"icon": "fw fw-mobile",
|
||||
"target": "_blank"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"User": {
|
||||
"url": "#",
|
||||
"icon": "fw fw-user",
|
||||
"dropDown": {
|
||||
"Profile": {
|
||||
"url": "https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/user-profile.jag",
|
||||
"icon": "fw fw-user",
|
||||
"dropDown": "true",
|
||||
"target": "_self"
|
||||
},
|
||||
"Change Password": {
|
||||
"url": "https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/change-password.jag",
|
||||
"icon": "fw fw-lock",
|
||||
"dropDown": "true",
|
||||
"target": "_self"
|
||||
},
|
||||
"Logout": {
|
||||
"url": "https://device.cloud.wso2.com/devicemgt/logout",
|
||||
"icon": "fw fw-sign-out",
|
||||
"dropDown": "true",
|
||||
"target": "_self"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Expand": {
|
||||
"Clouds": {
|
||||
"API Cloud": {
|
||||
"id": "api_cloud",
|
||||
"url": "https://api.cloud.wso2.com/publisher",
|
||||
"icon": "fw fw-api fw-3x",
|
||||
"dropDown": "true",
|
||||
"target": "_self"
|
||||
},
|
||||
"Integration Cloud": {
|
||||
"id": "integration_cloud",
|
||||
"url": "https://integration.cloud.wso2.com/appmgt",
|
||||
"icon": "fw fw-service fw-3x",
|
||||
"dropDown": "true",
|
||||
"target": "_self"
|
||||
},
|
||||
"Identity Cloud": {
|
||||
"id": "integration_cloud",
|
||||
"url": "https://identity.cloud.wso2.com/admin",
|
||||
"icon": "fw fw-security fw-3x",
|
||||
"dropDown": "true",
|
||||
"target": "_self"
|
||||
}
|
||||
},
|
||||
"Actions": {
|
||||
"Organization": {
|
||||
"url": "https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/organization.jag",
|
||||
"icon": "fw fw-organization fw-3x",
|
||||
"dropDown": "true",
|
||||
"target": "_self"
|
||||
},
|
||||
"Members": {
|
||||
"url": "https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/user.jag",
|
||||
"icon": "fa fa-users fa-3x",
|
||||
"dropDown": "true",
|
||||
"target": "_self"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,82 +0,0 @@
|
||||
{{!-- 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. --}}
|
||||
|
||||
<!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.0">
|
||||
{{defineZone "favicon"}}
|
||||
<title>
|
||||
{{defineZone "title"}}
|
||||
</title>
|
||||
{{defineZone "topLibCss"}}
|
||||
{{defineZone "topCss"}}
|
||||
{{defineZone "topJs"}}
|
||||
</head>
|
||||
<body>
|
||||
<!--modal-->
|
||||
<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="modalDemo">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content clearfix">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--modal-->
|
||||
|
||||
{{defineZone "header"}}
|
||||
|
||||
{{defineZone "sidePanes"}}
|
||||
|
||||
<!-- page-content-wrapper -->
|
||||
<div class="page-content-wrapper">
|
||||
|
||||
<div class="navbar-wrapper">
|
||||
{{defineZone "navbars"}}
|
||||
</div>
|
||||
|
||||
{{!defineZone "contentTitle"}}
|
||||
|
||||
<div class="container-fluid ">
|
||||
<div class="body-wrapper">
|
||||
{{defineZone "content"}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /page-content-wrapper -->
|
||||
|
||||
<footer class="footer">
|
||||
<div class="container-fluid">
|
||||
{{defineZone "footer"}}
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
{{defineZone "bottomModalContent"}}
|
||||
{{defineZone "bottomLibJs"}}
|
||||
{{defineZone "bottomJs"}}
|
||||
</body>
|
||||
</html>
|
||||
@ -1,48 +0,0 @@
|
||||
{{!-- 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. --}}
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset='UTF-8'>
|
||||
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/style.css">
|
||||
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/font-mf.css">
|
||||
<title>
|
||||
{{defineZone "title"}}
|
||||
</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="sky">
|
||||
<section>
|
||||
<div class="error-400">
|
||||
<img src="https://error.cloud.wso2.com/images/400-error.svg">
|
||||
</div>
|
||||
<div class="text-label">
|
||||
<h1>{{#defineZone "messageTitle"}}Oops something went wrong{{/defineZone}}</h1>
|
||||
<h2>{{defineZone "messageDescription"}}</h2>
|
||||
<div style="clear: both"></div>
|
||||
<div class="button-label">
|
||||
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/index.jag"><label class="label-back">Back to Cloud </label></a>
|
||||
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/contact-us.jag"><label class="label-report"> Report Issue </label></a>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="clouds_one"></div>
|
||||
<div class="clouds_two"></div>
|
||||
<div class="clouds_three"></div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,57 +0,0 @@
|
||||
{{!-- 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. --}}
|
||||
|
||||
<!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.0">
|
||||
{{defineZone "favicon"}}
|
||||
<title>
|
||||
{{defineZone "title"}}
|
||||
</title>
|
||||
{{defineZone "topLibCss"}}
|
||||
{{defineZone "topCss"}}
|
||||
{{defineZone "topJs"}}
|
||||
</head>
|
||||
<body>
|
||||
<!--modal-->
|
||||
<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="modalDemo">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content clearfix">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--modal-->
|
||||
|
||||
{{defineZone "content"}}
|
||||
|
||||
{{defineZone "bottomModalContent"}}
|
||||
{{defineZone "bottomLibJs"}}
|
||||
{{defineZone "bottomJs"}}
|
||||
</body>
|
||||
</html>
|
||||
@ -1,149 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 batchProviders;
|
||||
|
||||
batchProviders = function () {
|
||||
var operations = {};
|
||||
var CONTENT_TYPE_JSON = "application/json";
|
||||
var JS_MAX_VALUE = "9007199254740992";
|
||||
var JS_MIN_VALUE = "-9007199254740992";
|
||||
|
||||
var TABLENAME_ANDROID = "ORG_WSO2_GEO_FUSEDSPATIALEVENT";
|
||||
var TABLENAME_ANDROID_SENSE = "ORG_WSO2_IOT_ANDROID_LOCATION";
|
||||
|
||||
var tableName = function (deviceType) {
|
||||
switch (deviceType) {
|
||||
case "android" :
|
||||
return TABLENAME_ANDROID;
|
||||
break;
|
||||
case "android_sense" :
|
||||
return TABLENAME_ANDROID_SENSE;
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
var typeMap = {
|
||||
"bool": "string",
|
||||
"boolean": "string",
|
||||
"string": "string",
|
||||
"int": "number",
|
||||
"integer": "number",
|
||||
"long": "number",
|
||||
"double": "number",
|
||||
"float": "number",
|
||||
"time": "time"
|
||||
};
|
||||
|
||||
var log = new Log();
|
||||
var carbon = require('carbon');
|
||||
var JSUtils = Packages.org.wso2.carbon.analytics.jsservice.Utils;
|
||||
var AnalyticsCachedJSServiceConnector = Packages.org.wso2.carbon.analytics.jsservice.AnalyticsCachedJSServiceConnector;
|
||||
var AnalyticsCache = Packages.org.wso2.carbon.analytics.jsservice.AnalyticsCachedJSServiceConnector.AnalyticsCache;
|
||||
var cacheTimeoutSeconds = 5;
|
||||
|
||||
var cacheSizeBytes = 1024 * 1024 * 1024; // 1GB
|
||||
response.contentType = CONTENT_TYPE_JSON;
|
||||
|
||||
|
||||
var cache = application.get("AnalyticsWebServiceCache");
|
||||
if (cache == null) {
|
||||
cache = new AnalyticsCache(cacheTimeoutSeconds, cacheSizeBytes);
|
||||
application.put("AnalyticsWebServiceCache", cache);
|
||||
}
|
||||
var connector = new AnalyticsCachedJSServiceConnector(cache);
|
||||
|
||||
|
||||
/**
|
||||
* returns an array of column names & types
|
||||
* @param providerConfig
|
||||
*/
|
||||
operations.getSchema = function (loggedInUser) {
|
||||
var tablename = tableName(deviceType);
|
||||
if (tablename == null) {
|
||||
return [];
|
||||
}
|
||||
var schema = [];
|
||||
var result = connector.getTableSchema(loggedInUser, tablename).getMessage();
|
||||
result = JSON.parse(result);
|
||||
|
||||
var columns = result.columns;
|
||||
Object.getOwnPropertyNames(columns).forEach(function (name, idx, array) {
|
||||
var type = "ordinal";
|
||||
if (columns[name]['type']) {
|
||||
type = columns[name]['type'];
|
||||
}
|
||||
schema.push({
|
||||
fieldName: name,
|
||||
fieldType: typeMap[type.toLowerCase()]
|
||||
});
|
||||
});
|
||||
// log.info(schema);
|
||||
return schema;
|
||||
};
|
||||
|
||||
/**
|
||||
* returns the actual data
|
||||
* @param providerConfig
|
||||
* @param limit
|
||||
*/
|
||||
operations.getData = function (loggedInUser, deviceId, deviceType) {
|
||||
var luceneQuery = "";
|
||||
var limit = 100;
|
||||
var result;
|
||||
var tablename = tableName(deviceType);
|
||||
if (tablename == null) {
|
||||
return [];
|
||||
}
|
||||
//if there's a filter present, we should perform a Lucene search instead of reading the table
|
||||
if (luceneQuery) {
|
||||
luceneQuery = 'id:"' + deviceId + '" AND type:"' + deviceType + '"';
|
||||
var filter = {
|
||||
"query": luceneQuery,
|
||||
"start": 0,
|
||||
"count": limit
|
||||
};
|
||||
result = connector.search(loggedInUser, tablename, stringify(filter)).getMessage();
|
||||
} else {
|
||||
var from = JS_MIN_VALUE;
|
||||
var to = JS_MAX_VALUE;
|
||||
result = connector.getRecordsByRange(loggedInUser, tablename, from, to, 0, limit, null).getMessage();
|
||||
|
||||
}
|
||||
|
||||
// error handling ----
|
||||
var resultString = result.toString();
|
||||
if (resultString.contains("Failed to get records from table")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
result = JSON.parse(result);
|
||||
var data = [];
|
||||
for (var i = 0; i < result.length; i++) {
|
||||
var values = result[i].values;
|
||||
data.push(values);
|
||||
}
|
||||
return data;
|
||||
};
|
||||
|
||||
|
||||
|
||||
return operations;
|
||||
}();
|
||||
@ -1,467 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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/business-controllers/device.js");
|
||||
|
||||
var utility = require('/app/modules/utility.js')["utility"];
|
||||
var constants = require('/app/modules/constants.js');
|
||||
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
|
||||
var batchProvider = require("/app/modules/batch-provider-api.js")["batchProviders"];
|
||||
var process = require("process");
|
||||
var carbon = require("carbon");
|
||||
var publicMethods = {};
|
||||
var privateMethods = {};
|
||||
|
||||
/**
|
||||
* 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 An object with 'status': 'success'|'error', 'content': {}
|
||||
*/
|
||||
privateMethods.callBackend = function (url, method) {
|
||||
if (constants["HTTP_GET"] == method) {
|
||||
return serviceInvokers.XMLHttp.get(url,
|
||||
function (backendResponse) {
|
||||
var response = {};
|
||||
response.content = backendResponse.responseText;
|
||||
if (backendResponse.status == 200) {
|
||||
response.status = "success";
|
||||
} else if (backendResponse.status == 400 || backendResponse.status == 401 ||
|
||||
backendResponse.status == 404 || backendResponse.status == 500) {
|
||||
response.status = "error";
|
||||
}
|
||||
return response;
|
||||
}
|
||||
);
|
||||
} else {
|
||||
log.error("Runtime error : This method only support HTTP GET requests.");
|
||||
}
|
||||
};
|
||||
|
||||
privateMethods.validateAndReturn = function (value) {
|
||||
return (value == undefined || value == null) ? constants["UNSPECIFIED"] : value;
|
||||
};
|
||||
|
||||
/*
|
||||
@Updated
|
||||
*/
|
||||
publicMethods.viewDevice = function (deviceType, deviceId, owner, ownership) {
|
||||
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
|
||||
if (!carbonUser) {
|
||||
log.error("User object was not found in the session");
|
||||
userModule.logout(function () {
|
||||
response.sendRedirect(devicemgtProps["appContext"] + "login");
|
||||
});
|
||||
}
|
||||
var userName = carbonUser.username + "@" + carbonUser.domain;
|
||||
var locationHistory = [];
|
||||
var geoServicesEnabled = devicemgtProps.serverConfig.geoLocationConfiguration.enabled;
|
||||
if (geoServicesEnabled) {
|
||||
try {
|
||||
var fromDate = new Date();
|
||||
fromDate.setHours(fromDate.getHours() - 2);
|
||||
var toDate = new Date();
|
||||
var serviceUrl = devicemgtProps["httpsURL"] + '/api/device-mgt/v1.0/geo-services/stats/' + deviceType + '/' + deviceId + '?from=' + fromDate.getTime() + '&to=' + toDate.getTime();
|
||||
serviceInvokers.XMLHttp.get(serviceUrl,
|
||||
function (backendResponse) {
|
||||
if (backendResponse.status === 200 && backendResponse.responseText) {
|
||||
locationHistory = JSON.parse(backendResponse.responseText);
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
log.error(e.message, e);
|
||||
}
|
||||
}
|
||||
|
||||
var locationInfo = {};
|
||||
try {
|
||||
var url = devicemgtProps["httpsURL"] + "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceId + "/location";
|
||||
serviceInvokers.XMLHttp.get(
|
||||
url,
|
||||
function (backendResponse) {
|
||||
|
||||
if (backendResponse.status == 200 && backendResponse.responseText) {
|
||||
var device = parse(backendResponse.responseText);
|
||||
locationInfo.latitude = device.latitude;
|
||||
locationInfo.longitude = device.longitude;
|
||||
locationInfo.updatedOn = device.updatedTime;
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
log.error(e.message, e);
|
||||
}
|
||||
|
||||
var utility = require('/app/modules/utility.js')["utility"];
|
||||
try {
|
||||
utility.startTenantFlow(carbonUser);
|
||||
var url = devicemgtProps["httpsURL"] + "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceId;
|
||||
if (owner) {
|
||||
url = url + "?owner=" + owner;
|
||||
if (ownership){
|
||||
url = url + "&ownership=" + ownership;
|
||||
}
|
||||
} else if (ownership){
|
||||
url = url + "?ownership=" + ownership;
|
||||
}
|
||||
return serviceInvokers.XMLHttp.get(
|
||||
url,
|
||||
function (backendResponse) {
|
||||
var response = {};
|
||||
if (backendResponse.status == 200 && backendResponse.responseText) {
|
||||
var device = parse(backendResponse.responseText);
|
||||
|
||||
var filteredDeviceData = {};
|
||||
if (device["deviceIdentifier"]) {
|
||||
filteredDeviceData["deviceIdentifier"] = device["deviceIdentifier"];
|
||||
}
|
||||
if (device["type"]) {
|
||||
filteredDeviceData["type"] = device["type"];
|
||||
}
|
||||
if (device["name"]) {
|
||||
filteredDeviceData["name"] = device["name"];
|
||||
}
|
||||
if (device["enrolmentInfo"]) {
|
||||
var enrolmentInfo = {};
|
||||
if (device["enrolmentInfo"]["status"]) {
|
||||
enrolmentInfo["status"] = device["enrolmentInfo"]["status"];
|
||||
}
|
||||
if (device["enrolmentInfo"]["owner"]) {
|
||||
enrolmentInfo["owner"] = device["enrolmentInfo"]["owner"];
|
||||
}
|
||||
if (device["enrolmentInfo"]["ownership"]) {
|
||||
enrolmentInfo["ownership"] = device["enrolmentInfo"]["ownership"];
|
||||
}
|
||||
filteredDeviceData["enrolmentInfo"] = enrolmentInfo;
|
||||
}
|
||||
if (device["properties"] && device["properties"].length > 0) {
|
||||
var propertiesList = device["properties"];
|
||||
var properties = {};
|
||||
if (propertiesList) {
|
||||
for (var i = 0; i < propertiesList.length; i++) {
|
||||
if (propertiesList[i]["value"]) {
|
||||
properties[propertiesList[i]["name"]] =
|
||||
propertiesList[i]["value"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
filteredDeviceData["initialDeviceInfo"] = properties;
|
||||
|
||||
if (properties["DEVICE_INFO"]) {
|
||||
var initialDeviceInfoList = parse(properties["DEVICE_INFO"]);
|
||||
var initialDeviceInfo = {};
|
||||
if (Array.isArray(initialDeviceInfoList)) {
|
||||
for (var j = 0; j < initialDeviceInfoList.length; j++) {
|
||||
if (initialDeviceInfoList[j]["value"]) {
|
||||
initialDeviceInfo[initialDeviceInfoList[j]["name"]] =
|
||||
initialDeviceInfoList[j]["value"];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
initialDeviceInfo = initialDeviceInfoList;
|
||||
}
|
||||
|
||||
|
||||
filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"] = initialDeviceInfo;
|
||||
}
|
||||
}
|
||||
|
||||
if (filteredDeviceData["type"]) {
|
||||
if (filteredDeviceData["type"] == constants["PLATFORM_IOS"]) {
|
||||
if (filteredDeviceData["properties"]) {
|
||||
filteredDeviceData["properties"]["VENDOR"] = "Apple";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (device["deviceInfo"]) {
|
||||
filteredDeviceData["latestDeviceInfo"] = device["deviceInfo"];
|
||||
} else {
|
||||
filteredDeviceData["latestDeviceInfo"] = {};
|
||||
filteredDeviceData["latestDeviceInfo"]["location"] = {};
|
||||
}
|
||||
|
||||
//location related verification and modifications
|
||||
// adding the location histry for the movement path.
|
||||
filteredDeviceData["locationHistory"] = locationHistory;
|
||||
|
||||
//checking for the latest location information based on historical data.
|
||||
if (locationHistory) {
|
||||
var infoDate;
|
||||
var locationDate;
|
||||
var historicalLatestLoc = locationHistory[locationHistory.length - 1];
|
||||
if (historicalLatestLoc && filteredDeviceData.latestDeviceInfo && filteredDeviceData.latestDeviceInfo.location) {
|
||||
infoDate = new Date(filteredDeviceData.latestDeviceInfo.location.updatedTime);
|
||||
locationDate = new Date(historicalLatestLoc.values.timeStamp);
|
||||
}
|
||||
if (infoDate < locationDate || filteredDeviceData.latestDeviceInfo.length === 0) {
|
||||
filteredDeviceData.latestDeviceInfo.location = {};
|
||||
filteredDeviceData.latestDeviceInfo.location.longitude = historicalLatestLoc.values.longitude;
|
||||
filteredDeviceData.latestDeviceInfo.location.latitude = historicalLatestLoc.values.latitude;
|
||||
filteredDeviceData.latestDeviceInfo.location.updatedTime = historicalLatestLoc.values.timeStamp;
|
||||
}
|
||||
}
|
||||
|
||||
//checking for the latest location information.
|
||||
if (filteredDeviceData.latestDeviceInfo.location && locationInfo) {
|
||||
var infoDate = new Date(filteredDeviceData.latestDeviceInfo.location.updatedTime);
|
||||
var locationDate = new Date(locationInfo.updatedOn);
|
||||
if (infoDate < locationDate) {
|
||||
filteredDeviceData.latestDeviceInfo.location.longitude = locationInfo.longitude;
|
||||
filteredDeviceData.latestDeviceInfo.location.latitude = locationInfo.latitude;
|
||||
filteredDeviceData.latestDeviceInfo.location.updatedTime = locationInfo.updatedOn;
|
||||
}
|
||||
}
|
||||
|
||||
response["content"] = filteredDeviceData;
|
||||
response["status"] = "success";
|
||||
return response;
|
||||
} else if (backendResponse.status == 401) {
|
||||
response["status"] = "unauthorized";
|
||||
return response;
|
||||
} else if (backendResponse.status == 404) {
|
||||
response["status"] = "notFound";
|
||||
return response;
|
||||
} else {
|
||||
response["status"] = "error";
|
||||
return response;
|
||||
}
|
||||
}
|
||||
);
|
||||
} catch (e) {
|
||||
throw e;
|
||||
} finally {
|
||||
utility.endTenantFlow();
|
||||
}
|
||||
};
|
||||
|
||||
// Refactored methods
|
||||
publicMethods.getDevicesCount = function () {
|
||||
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||
if (carbonUser) {
|
||||
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
|
||||
var uiPermissions = userModule.getUIPermissions();
|
||||
var url;
|
||||
if (uiPermissions.LIST_DEVICES) {
|
||||
url = devicemgtProps["httpsURL"] +
|
||||
devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices?offset=0&limit=1";
|
||||
} else if (uiPermissions.LIST_OWN_DEVICES) {
|
||||
url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
|
||||
"/devices?offset=0&limit=1&user=" + carbonUser.username;
|
||||
} else {
|
||||
log.error("Access denied for user: " + carbonUser.username);
|
||||
return -1;
|
||||
}
|
||||
return serviceInvokers.XMLHttp.get(
|
||||
url, function (responsePayload) {
|
||||
if(!responsePayload["responseText"]){
|
||||
log.error("Error while fetching device count. API `" + url + "` returns HTTP: " + responsePayload["status"]);
|
||||
userModule.logout(function () {
|
||||
response.sendRedirect(devicemgtProps["appContext"] + "login");
|
||||
});
|
||||
}
|
||||
return parse(responsePayload["responseText"])["count"];
|
||||
},
|
||||
function (responsePayload) {
|
||||
log.error(responsePayload["responseText"]);
|
||||
return -1;
|
||||
}
|
||||
);
|
||||
} else {
|
||||
log.error("User object was not found in the session");
|
||||
userModule.logout(function () {
|
||||
response.sendRedirect(devicemgtProps["appContext"] + "login");
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
publicMethods.getDeviceTypeCount = function () {
|
||||
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||
if (carbonUser) {
|
||||
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
|
||||
var uiPermissions = userModule.getUIPermissions();
|
||||
var url;
|
||||
if (uiPermissions.LIST_OWN_DEVICES) {
|
||||
url = devicemgtProps["httpsURL"] +
|
||||
devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/device-types";
|
||||
} else {
|
||||
log.error("Access denied for user: " + carbonUser.username);
|
||||
return -1;
|
||||
}
|
||||
return serviceInvokers.XMLHttp.get(
|
||||
url, function (responsePayload) {
|
||||
return parse(responsePayload["responseText"]).length;
|
||||
},
|
||||
function (responsePayload) {
|
||||
log.error(responsePayload["responseText"]);
|
||||
return -1;
|
||||
}
|
||||
);
|
||||
} else {
|
||||
log.error("User object was not found in the session");
|
||||
userModule.logout(function () {
|
||||
response.sendRedirect(devicemgtProps["appContext"] + "login");
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
publicMethods.getDeviceTypes = function () {
|
||||
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/device-types";
|
||||
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
|
||||
if (response.status == "success") {
|
||||
response.content = parse(response.content);
|
||||
}
|
||||
return response;
|
||||
};
|
||||
|
||||
/*
|
||||
@Updated
|
||||
*/
|
||||
// publicMethods.getLicense = function (deviceType) {
|
||||
// var url;
|
||||
// var license;
|
||||
// if (deviceType == "windows") {
|
||||
// url = mdmProps["httpURL"] + "/mdm-windows-agent/services/device/license";
|
||||
// } else if (deviceType == "ios") {
|
||||
// url = mdmProps["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.getDevices = function (userName) {
|
||||
var url = devicemgtProps["httpsURL"] +
|
||||
devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices";
|
||||
if (userName && userName !== "") {
|
||||
url = url + "?user=" + userName;
|
||||
}
|
||||
return serviceInvokers.XMLHttp.get(
|
||||
url, function (responsePayload) {
|
||||
var devices = JSON.parse(responsePayload.responseText).devices;
|
||||
for (var i = 0; i < devices.length; i++) {
|
||||
devices[i].thumb = utility.getDeviceThumb(devices[i].type);
|
||||
}
|
||||
return devices;
|
||||
},
|
||||
function (responsePayload) {
|
||||
log.error(responsePayload);
|
||||
return -1;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
publicMethods.getDeviceAgentConfig = function (type, deviceId) {
|
||||
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
|
||||
if (!carbonUser) {
|
||||
log.error("User object was not found in the session");
|
||||
userModule.logout(function () {
|
||||
response.sendRedirect(devicemgtProps["appContext"] + "login");
|
||||
});
|
||||
}
|
||||
var userName = carbonUser.username + "@" + carbonUser.domain;
|
||||
var config = {};
|
||||
config.type = type;
|
||||
config.deviceId = deviceId;
|
||||
// register a tenant based app at API Manager
|
||||
var applicationName = type.replace(" ", "") + "_" + carbonUser.domain;
|
||||
var requestURL = (devicemgtProps["oauthProvider"]["appRegistration"]
|
||||
["apiManagerClientAppRegistrationServiceURL"]).replace("/tenants","");
|
||||
var payload = {applicationName:applicationName, tags:["device_agent"],
|
||||
isAllowedToAllDomains:false, validityPeriod: 3600};
|
||||
|
||||
serviceInvokers.XMLHttp.post(
|
||||
requestURL, payload, function (responsePayload) {
|
||||
var app = JSON.parse(responsePayload.responseText);
|
||||
|
||||
config.clientId = app["client_id"];
|
||||
config.clientSecret = app["client_secret"];
|
||||
if (config.clientId && config.clientSecret) {
|
||||
var JWTClientManagerServicePackagePath =
|
||||
"io.entgra.device.mgt.core.identity.jwt.client.extension.service.JWTClientManagerService";
|
||||
//noinspection JSUnresolvedFunction, JSUnresolvedVariable
|
||||
var JWTClientManagerService = carbon.server.osgiService(JWTClientManagerServicePackagePath);
|
||||
//noinspection JSUnresolvedFunction
|
||||
var jwtClient = JWTClientManagerService.getJWTClient();
|
||||
// returning access token by JWT grant type
|
||||
var deviceScope = "device_" + type.replace(" ", "") + "_" + deviceId + " dm:device:enroll " +
|
||||
"dm:device:disenroll dm:device:modify dm:devices:ops:view dm:device:event:publish";
|
||||
var tokenInfo = jwtClient.getAccessToken(config.clientId, config.clientSecret,
|
||||
userName, deviceScope);
|
||||
config.accessToken = tokenInfo.getAccessToken();
|
||||
config.refreshToken = tokenInfo.getRefreshToken();
|
||||
if (config.accessToken == null) {
|
||||
return null;
|
||||
}
|
||||
config.mqttGateway = "tcp://" + process.getProperty("mqtt.broker.host") + ":" + process.getProperty("mqtt.broker.port");
|
||||
config.httpsGateway = "https://" + process.getProperty("iot.gateway.host") + ":" + process.getProperty("iot.gateway.https.port");
|
||||
config.httpGateway = "http://" + process.getProperty("iot.gateway.host") + ":" + process.getProperty("iot.gateway.http.port");
|
||||
return config;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return config;
|
||||
},
|
||||
function (responsePayload) {
|
||||
log.error(responsePayload);
|
||||
return null;
|
||||
}
|
||||
);
|
||||
return config;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve device info details of a device
|
||||
* @param deviceType - Type of the device i.e ios, android
|
||||
* @param deviceId - Device ID of te device
|
||||
*/
|
||||
publicMethods.getDeviceInfo = function (deviceType, deviceId) {
|
||||
try {
|
||||
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"]
|
||||
+ "/devices/" + deviceType + "/" + deviceId + "/info";
|
||||
var response = {};
|
||||
return serviceInvokers.XMLHttp.get(
|
||||
url,
|
||||
function (backendResponse) {
|
||||
if (backendResponse.status === 200 && backendResponse.responseText) {
|
||||
response["status"] = "success";
|
||||
response["content"] = parse(backendResponse.responseText);
|
||||
} else {
|
||||
log.error("Error occurred while retrieving device info via " + url + ". Error code: "
|
||||
+ backendResponse.status + ". Reason: " + backendResponse.responseText);
|
||||
response["status"] = "error";
|
||||
}
|
||||
return response;
|
||||
});
|
||||
} catch (e) {
|
||||
log.error("Error occurred while retrieving device info via " + url, e);
|
||||
}
|
||||
};
|
||||
|
||||
return publicMethods;
|
||||
}();
|
||||
@ -1,143 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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/business-controllers/group.js");
|
||||
|
||||
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
|
||||
var constants = require('/app/modules/constants.js');
|
||||
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var utility = require("/app/modules/utility.js").utility;
|
||||
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
|
||||
|
||||
var deviceServiceEndpoint = devicemgtProps["httpsURL"] + "/api/device-mgt/v1.0";
|
||||
|
||||
var user = session.get(constants.USER_SESSION_KEY);
|
||||
|
||||
var endPoint;
|
||||
|
||||
groupModule.getGroupCount = function () {
|
||||
var permissions = userModule.getUIPermissions();
|
||||
if (permissions.LIST_ALL_GROUPS) {
|
||||
endPoint = deviceServiceEndpoint + "/admin/groups/count";
|
||||
} else if (permissions.LIST_GROUPS) {
|
||||
endPoint = deviceServiceEndpoint + "/groups/count";
|
||||
} else {
|
||||
if (!user) {
|
||||
log.error("User object was not found in the session");
|
||||
userModule.logout(function () {
|
||||
response.sendRedirect(devicemgtProps["appContext"] + "login");
|
||||
});
|
||||
}
|
||||
log.error("Access denied for user: " + user.username);
|
||||
return -1;
|
||||
}
|
||||
return serviceInvokers.XMLHttp.get(
|
||||
endPoint, function (responsePayload) {
|
||||
return parse(responsePayload["responseText"]);
|
||||
},
|
||||
function (responsePayload) {
|
||||
log.error(responsePayload["responseText"]);
|
||||
return -1;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
groupModule.getGroupDeviceCount = function (groupId) {
|
||||
endPoint = deviceServiceEndpoint + "/groups/id/" + groupId + "/devices/count";
|
||||
return serviceInvokers.XMLHttp.get(
|
||||
endPoint, function (responsePayload) {
|
||||
return responsePayload["responseText"];
|
||||
},
|
||||
function (responsePayload) {
|
||||
log.error(responsePayload);
|
||||
return -1;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
groupModule.getGroupDevices = function (groupId) {
|
||||
endPoint = deviceServiceEndpoint + "/groups/id/" + groupId + "/devices?limit=10";
|
||||
return serviceInvokers.XMLHttp.get(
|
||||
endPoint, function (responsePayload) {
|
||||
return responsePayload;
|
||||
},
|
||||
function (responsePayload) {
|
||||
log.error(responsePayload);
|
||||
return responsePayload;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
groupModule.getGroups = function () {
|
||||
var permissions = userModule.getUIPermissions();
|
||||
if (permissions.LIST_ALL_GROUPS) {
|
||||
endPoint = deviceServiceEndpoint + "/admin/groups";
|
||||
} else if (permissions.LIST_GROUPS) {
|
||||
endPoint = deviceServiceEndpoint + "/groups";
|
||||
} else {
|
||||
log.error("Access denied for user: " + carbonUser.username);
|
||||
return -1;
|
||||
}
|
||||
return serviceInvokers.XMLHttp.get(
|
||||
endPoint, function (responsePayload) {
|
||||
var data = JSON.parse(responsePayload.responseText);
|
||||
if(data) {
|
||||
return data.deviceGroups;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
function (responsePayload) {
|
||||
log.error(responsePayload);
|
||||
return -1;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
groupModule.getGroup = function (groupId) {
|
||||
return serviceInvokers.XMLHttp.get(
|
||||
deviceServiceEndpoint + "/groups/id/" + groupId, function (responsePayload) {
|
||||
return JSON.parse(responsePayload.responseText);
|
||||
},
|
||||
function (responsePayload) {
|
||||
log.error(responsePayload);
|
||||
return -1;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
groupModule.getRolesOfGroup = function (groupId) {
|
||||
return serviceInvokers.XMLHttp.get(
|
||||
deviceServiceEndpoint + "/groups/id/" + groupId + "/roles", function (responsePayload) {
|
||||
var data = JSON.parse(responsePayload.responseText);
|
||||
if(data) {
|
||||
return data.roles;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
function (responsePayload) {
|
||||
log.error(responsePayload);
|
||||
return -1;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
}(groupModule));
|
||||
@ -1,168 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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/business-controllers/operation.js");
|
||||
var utility = require('/app/modules/utility.js').utility;
|
||||
var constants = require('/app/modules/constants.js');
|
||||
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
|
||||
|
||||
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"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/device-types/"
|
||||
+ deviceType + "/features?featureType=" + operationType + "&hidden=false";
|
||||
return serviceInvokers.XMLHttp.get(url, function (responsePayload) {
|
||||
var features = JSON.parse(responsePayload.responseText);
|
||||
var featureList = [];
|
||||
var feature;
|
||||
for (var i = 0; i < features.length; i++) {
|
||||
feature = {};
|
||||
feature["operation"] = features[i].code;
|
||||
feature["name"] = features[i].name;
|
||||
feature["description"] = features[i].description;
|
||||
feature["contentType"] = features[i].contentType;
|
||||
feature["deviceType"] = deviceType;
|
||||
feature["params"] = [];
|
||||
var metaData = features[i].metadataEntries;
|
||||
if (metaData) {
|
||||
for (var j = 0; j < metaData.length; j++) {
|
||||
if (metaData[j].name === "operationMeta") {
|
||||
var operationMeta = metaData[j].value;
|
||||
var params = {};
|
||||
params["method"] = operationMeta.method;
|
||||
params["pathParams"] = operationMeta.pathParams;
|
||||
params["queryParams"] = operationMeta.queryParams;
|
||||
params["formParams"] = operationMeta.formParams ? operationMeta.formParams : [];
|
||||
params["uri"] = operationMeta.uri;
|
||||
params["contentType"] = operationMeta.contentType;
|
||||
feature["params"].push(params);
|
||||
feature["permission"] = operationMeta.permission;
|
||||
if (operationMeta.icon) {
|
||||
//Check if icon is a path or font
|
||||
if (operationMeta.icon.indexOf("path:") === 0) {
|
||||
feature["icon"] = operationMeta.icon.replace("path:", "");
|
||||
} else {
|
||||
feature["iconFont"] = operationMeta.icon;
|
||||
}
|
||||
}
|
||||
if (operationMeta.uiParams && operationMeta.uiParams.length > 0) {
|
||||
feature["uiParams"] = operationMeta.uiParams;
|
||||
}
|
||||
if (operationMeta.filters) {
|
||||
feature["filters"] = operationMeta.filters;
|
||||
}
|
||||
if (operationMeta.ownershipDescription) {
|
||||
feature["ownershipDescription"] = operationMeta.ownershipDescription;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
feature["metadata"].push(metaData[j].value);
|
||||
}
|
||||
featureList.push(feature);
|
||||
}
|
||||
}
|
||||
return featureList;
|
||||
}, function (responsePayload) {
|
||||
var response = {};
|
||||
response["status"] = "error";
|
||||
return response;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
publicMethods.getControlOperations = function (device) {
|
||||
var deviceType = device.type;
|
||||
var operations = privateMethods.getOperationsFromFeatures(deviceType, "operation");
|
||||
for (var op in operations) {
|
||||
if (operations.hasOwnProperty(op)) {
|
||||
operations[op]["isDisabled"] = false;
|
||||
if (device && operations[op].filters && operations[op].filters.length > 0) {
|
||||
var filters = operations[op].filters;
|
||||
for (var filter in filters) {
|
||||
if (filters.hasOwnProperty(filter)) {
|
||||
if (device[filters[filter].property] !== filters[filter].value) {
|
||||
operations[op]["isDisabled"] = true;
|
||||
operations[op]["disabledText"] = operations[op]["disabledText"] ?
|
||||
operations[op]["disabledText"] + ", " + filters[filter].description :
|
||||
filters[filter].description;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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) + '"}';
|
||||
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;
|
||||
}();
|
||||
@ -1,282 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 policyModule;
|
||||
policyModule = function () {
|
||||
var log = new Log("/app/modules/business-controllers/policy.js");
|
||||
|
||||
var constants = require('/app/modules/constants.js');
|
||||
var utility = require("/app/modules/utility.js")["utility"];
|
||||
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
|
||||
|
||||
var publicMethods = {};
|
||||
var privateMethods = {};
|
||||
|
||||
privateMethods.handleGetAllPoliciesResponse = function (backendResponse) {
|
||||
var response = {};
|
||||
if (backendResponse.status == 200 && backendResponse.responseText) {
|
||||
var isUpdated = false;
|
||||
var policyListFromRestEndpoint = parse(backendResponse.responseText)["policies"];
|
||||
|
||||
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"];
|
||||
policyObjectFromRestEndpoint["policyType"] = policyListFromRestEndpoint["policyType"];
|
||||
var payloadVersion = policyObjectFromRestEndpoint["policyPayloadVersion"];
|
||||
if (!parseFloat(payloadVersion) >= 2.0) {
|
||||
policyObjectFromRestEndpoint["correctiveActions"] = policyListFromRestEndpoint["correctiveActions"];
|
||||
}
|
||||
if (policyObjectToView["platform"] == "ios") {
|
||||
policyObjectToView["deviceTypeIcon"] = "apple";
|
||||
} else {
|
||||
policyObjectToView["deviceTypeIcon"] = policyObjectToView["platform"];
|
||||
}
|
||||
var ownershipType = "None";
|
||||
var deviceGroups = policyObjectFromRestEndpoint["deviceGroups"];
|
||||
if (deviceGroups) {
|
||||
for (var j = 0; j < deviceGroups.length; j++) {
|
||||
var deviceGroup = deviceGroups[j];
|
||||
if (deviceGroup.name === "COPE") {
|
||||
ownershipType = (ownershipType === "BYOD") ? "BYOD & COPE" : "COPE";
|
||||
} else if (deviceGroup.name === "BYOD") {
|
||||
ownershipType = (ownershipType === "COPE") ? "BYOD & COPE" : "BYOD";
|
||||
}
|
||||
}
|
||||
}
|
||||
policyObjectToView["ownershipType"] = ownershipType;
|
||||
|
||||
var assignedRoleCount = policyObjectFromRestEndpoint["roles"].length;
|
||||
var assignedUserCount = policyObjectFromRestEndpoint["users"].length;
|
||||
|
||||
if (assignedRoleCount == 0) {
|
||||
policyObjectToView["roles"] = "None";
|
||||
} else if (assignedRoleCount == 1) {
|
||||
policyObjectToView["roles"] = policyObjectFromRestEndpoint["roles"][0];
|
||||
} else if (assignedRoleCount > 1) {
|
||||
policyObjectToView["roles"] = policyObjectFromRestEndpoint["roles"][0] + ", ...";
|
||||
}
|
||||
|
||||
if (assignedUserCount == 0) {
|
||||
policyObjectToView["users"] = "None";
|
||||
} else if (assignedUserCount == 1) {
|
||||
policyObjectToView["users"] = policyObjectFromRestEndpoint["users"][0];
|
||||
} else if (assignedUserCount > 1) {
|
||||
policyObjectToView["users"] = policyObjectFromRestEndpoint["users"][0] + ", ...";
|
||||
}
|
||||
|
||||
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
|
||||
response.updated = isUpdated;
|
||||
response.status = "success";
|
||||
response.content = policyListToView;
|
||||
|
||||
return response;
|
||||
} else {
|
||||
response.status = "error";
|
||||
/* backendResponse.responseText == "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 (backendResponse.responseText == "Scope validation failed") {
|
||||
response.content = "Permission Denied";
|
||||
} else {
|
||||
response.content = backendResponse.responseText;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
@Updated
|
||||
*/
|
||||
publicMethods.getAllPolicies = function () {
|
||||
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
|
||||
if (!carbonUser) {
|
||||
log.error("User object was not found in the session");
|
||||
userModule.logout(function () {
|
||||
response.sendRedirect(devicemgtProps["appContext"] + "login");
|
||||
});
|
||||
}
|
||||
try {
|
||||
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
|
||||
"/policies?offset=0&limit=100";
|
||||
return serviceInvokers.XMLHttp.get(url, privateMethods.handleGetAllPoliciesResponse);
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve all policies based on policy type
|
||||
*/
|
||||
publicMethods.getAllPoliciesByType = function (policyType) {
|
||||
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
|
||||
if (!carbonUser) {
|
||||
log.error("User object was not found in the session");
|
||||
userModule.logout(function () {
|
||||
response.sendRedirect(devicemgtProps["appContext"] + "login");
|
||||
});
|
||||
}
|
||||
try {
|
||||
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
|
||||
"/policies/type/" + policyType + "?offset=0&limit=100";
|
||||
return serviceInvokers.XMLHttp.get(url, privateMethods.handleGetAllPoliciesResponse);
|
||||
} catch (e) {
|
||||
log.error("Error occurred while retrieving policies by policy type " + policyType);
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Get policies count from backend services.
|
||||
*/
|
||||
publicMethods.getPoliciesCount = function () {
|
||||
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
|
||||
if (!carbonUser) {
|
||||
log.error("User object was not found in the session");
|
||||
userModule.logout(function () {
|
||||
response.sendRedirect(devicemgtProps["appContext"] + "login");
|
||||
});
|
||||
}
|
||||
try {
|
||||
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
|
||||
"/policies?offset=0&limit=1";
|
||||
return serviceInvokers.XMLHttp.get(
|
||||
url, function (responsePayload) {
|
||||
return parse(responsePayload["responseText"])["count"];
|
||||
},
|
||||
function (responsePayload) {
|
||||
log.error(responsePayload["responseText"]);
|
||||
return -1;
|
||||
}
|
||||
);
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Get apps available in the store from backend service.
|
||||
*/
|
||||
publicMethods.getStoreAppsForPolicy = function () {
|
||||
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
|
||||
if (!carbonUser) {
|
||||
log.error("User object was not found in the session");
|
||||
userModule.logout(function () {
|
||||
response.sendRedirect(devicemgtProps["appContext"] + "login");
|
||||
});
|
||||
}
|
||||
try {
|
||||
var url = devicemgtProps["managerHTTPSURL"] + devicemgtProps["backendRestEndpoints"]["appMgt"] +
|
||||
"/applications";
|
||||
var data = {
|
||||
limit: -1
|
||||
};
|
||||
return serviceInvokers.XMLHttp.post(url, data,
|
||||
function (backendResponse) {
|
||||
var response = {};
|
||||
if (backendResponse.status === 200 && backendResponse.responseText) {
|
||||
var appListFromRestEndpoint = parse(backendResponse.responseText)["applications"];
|
||||
var storeApps = [];
|
||||
var i, appObjectFromRestEndpoint, appObjectToView;
|
||||
for (i=0; i<appListFromRestEndpoint.length; i++) {
|
||||
appObjectFromRestEndpoint = appListFromRestEndpoint[i];
|
||||
appObjectToView = {};
|
||||
appObjectToView["appName"] = appObjectFromRestEndpoint["name"];
|
||||
appObjectToView["packageName"] = appObjectFromRestEndpoint["packageName"];
|
||||
appObjectToView["appId"] = appObjectFromRestEndpoint["id"];
|
||||
if ("WEB_CLIP" === appObjectFromRestEndpoint["type"]) {
|
||||
appObjectToView["type"] = "Web Clip"
|
||||
} else {
|
||||
appObjectToView["type"] = "Mobile App"
|
||||
}
|
||||
appObjectToView["uuid"] = appObjectFromRestEndpoint["applicationReleases"][0]["uuid"];
|
||||
appObjectToView["version"] = appObjectFromRestEndpoint["applicationReleases"][0]["version"];
|
||||
appObjectToView["platform"] = appObjectFromRestEndpoint["deviceType"];
|
||||
storeApps.push(appObjectToView);
|
||||
}
|
||||
response.status = "success";
|
||||
response.content = storeApps;
|
||||
return response;
|
||||
} else {
|
||||
response.status = "error";
|
||||
if (backendResponse.responseText === "Scope validation failed") {
|
||||
response.content = "Permission Denied";
|
||||
} else {
|
||||
response.content = backendResponse.responseText;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
});
|
||||
} 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;
|
||||
};
|
||||
|
||||
return publicMethods;
|
||||
}();
|
||||
@ -1,760 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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/business-controllers/user.js");
|
||||
|
||||
var constants = require("/app/modules/constants.js");
|
||||
var utility = require("/app/modules/utility.js")["utility"];
|
||||
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
|
||||
|
||||
/* Initializing user manager */
|
||||
var carbon = require("carbon");
|
||||
var url = carbon.server.address("https") + "/admin/services";
|
||||
var server = new carbon.server.Server(url);
|
||||
|
||||
var publicMethods = {};
|
||||
var privateMethods = {};
|
||||
|
||||
/**
|
||||
* Get the carbon user object from the session. If not found - it will throw a user not found error.
|
||||
* @returns {object} carbon user object
|
||||
*/
|
||||
publicMethods.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 An object with 'status': 'success'|'error', 'content': {}
|
||||
*/
|
||||
privateMethods.callBackend = function (url, method) {
|
||||
if (constants["HTTP_GET"] == method) {
|
||||
return serviceInvokers.XMLHttp.get(url,
|
||||
function (backendResponse) {
|
||||
var response = {};
|
||||
response.content = backendResponse.responseText;
|
||||
if (backendResponse.status == 200) {
|
||||
response.status = "success";
|
||||
} else if (backendResponse.status == 400 || backendResponse.status == 401 ||
|
||||
backendResponse.status == 404 || backendResponse.status == 500) {
|
||||
response.status = "error";
|
||||
}
|
||||
return response;
|
||||
}
|
||||
);
|
||||
} else {
|
||||
log.error("Runtime error : This method only support HTTP GET requests.");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
@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"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users?offset=0&limit=100";
|
||||
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
|
||||
if (response.status == "success") {
|
||||
response.content = parse(response.content).users;
|
||||
}
|
||||
return response;
|
||||
} catch (e) {
|
||||
throw e;
|
||||
} finally {
|
||||
utility.endTenantFlow();
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Get users count from backend services.
|
||||
*/
|
||||
publicMethods.getUsersCount = 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"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/count";
|
||||
return serviceInvokers.XMLHttp.get(
|
||||
url, function (responsePayload) {
|
||||
return parse(responsePayload["responseText"])["count"];
|
||||
},
|
||||
function (responsePayload) {
|
||||
log.error(responsePayload["responseText"]);
|
||||
return -1;
|
||||
}
|
||||
);
|
||||
} catch (e) {
|
||||
throw e;
|
||||
} finally {
|
||||
utility.endTenantFlow();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a User object from the backend by calling the JAX-RS
|
||||
* @param username
|
||||
* @returns {object} a response object with status and content on success.
|
||||
*/
|
||||
publicMethods.getUser = function (username) {
|
||||
var carbonUser = publicMethods.getCarbonUser();
|
||||
var domain;
|
||||
if (username.indexOf('/') > 0) {
|
||||
domain = username.substr(0, username.indexOf('/'));
|
||||
username = username.substr(username.indexOf('/') + 1);
|
||||
}
|
||||
try {
|
||||
utility.startTenantFlow(carbonUser);
|
||||
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" +
|
||||
encodeURIComponent(username);
|
||||
if (domain) {
|
||||
url += '?domain=' + encodeURIComponent(domain);
|
||||
}
|
||||
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
|
||||
response["content"] = parse(response.content);
|
||||
response["userDomain"] = carbonUser.domain;
|
||||
return response;
|
||||
} catch (e) {
|
||||
throw e;
|
||||
} finally {
|
||||
utility.endTenantFlow();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a set of roles assigned to a particular user
|
||||
* @param username
|
||||
* @returns {object} a response object with status and content on success.
|
||||
*/
|
||||
publicMethods.getRolesByUsername = function (username) {
|
||||
var carbonUser = publicMethods.getCarbonUser();
|
||||
var domain;
|
||||
if (username.indexOf('/') > 0) {
|
||||
domain = username.substr(0, username.indexOf('/'));
|
||||
username = username.substr(username.indexOf('/') + 1);
|
||||
}
|
||||
try {
|
||||
utility.startTenantFlow(carbonUser);
|
||||
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" +
|
||||
encodeURIComponent(username) + "/roles";
|
||||
if (domain) {
|
||||
url += '?domain=' + encodeURIComponent(domain);
|
||||
}
|
||||
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
|
||||
if (response.status == "success") {
|
||||
response.content = parse(response.content).roles;
|
||||
}
|
||||
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"] + "/mdm-admin/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"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
|
||||
"/roles?offset=0&limit=100&user-store=all";
|
||||
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
|
||||
if (response.status == "success") {
|
||||
response.content = parse(response.content).roles;
|
||||
}
|
||||
return response;
|
||||
} catch (e) {
|
||||
throw e;
|
||||
} finally {
|
||||
utility.endTenantFlow();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get User Roles from user store (Internal roles not included).
|
||||
*/
|
||||
publicMethods.getFilteredRoles = function (prefix) {
|
||||
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"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
|
||||
"/roles/filter/" + prefix + "?offset=0&limit=100&user-store=all";
|
||||
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
|
||||
if (response.status == "success") {
|
||||
response.content = parse(response.content);
|
||||
}
|
||||
return response;
|
||||
} catch (e) {
|
||||
throw e;
|
||||
} finally {
|
||||
utility.endTenantFlow();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get User Roles count from user store (Internal roles not included).
|
||||
*/
|
||||
publicMethods.getRolesCount = 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"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
|
||||
"/roles?offset=0&limit=1&user-store=all";
|
||||
return serviceInvokers.XMLHttp.get(
|
||||
url, function (responsePayload) {
|
||||
return parse(responsePayload["responseText"])["count"];
|
||||
},
|
||||
function (responsePayload) {
|
||||
log.error(responsePayload["responseText"]);
|
||||
return -1;
|
||||
}
|
||||
);
|
||||
} catch (e) {
|
||||
throw e;
|
||||
} finally {
|
||||
utility.endTenantFlow();
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
@Updated
|
||||
*/
|
||||
/**
|
||||
* Get User Roles from user store (Internal roles not included).
|
||||
* @returns {object} a response object with status and content on success.
|
||||
*/
|
||||
publicMethods.getRolesByUserStore = function (userStore) {
|
||||
userStore = userStore ? userStore : "all";
|
||||
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"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
|
||||
"/roles?user-store=" + encodeURIComponent(userStore) + "&limit=100";
|
||||
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
|
||||
if (response.status == "success") {
|
||||
response.content = parse(response.content).roles;
|
||||
}
|
||||
return response;
|
||||
} catch (e) {
|
||||
throw e;
|
||||
} finally {
|
||||
utility.endTenantFlow();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Platforms.
|
||||
* @deprecated moved this device module under getDeviceTypes.
|
||||
*/
|
||||
//TODO Move this piece of logic out of user.js to somewhere else appropriate.
|
||||
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"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/device-types";
|
||||
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
|
||||
if (response.status == "success") {
|
||||
response.content = parse(response.content);
|
||||
}
|
||||
return response;
|
||||
} catch (e) {
|
||||
throw e;
|
||||
} finally {
|
||||
utility.endTenantFlow();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get role
|
||||
*/
|
||||
publicMethods.getRole = function (roleName) {
|
||||
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
|
||||
var utility = require("/app/modules/utility.js")["utility"];
|
||||
var userStore;
|
||||
if (!carbonUser) {
|
||||
log.error("User object was not found in the session");
|
||||
throw constants["ERRORS"]["USER_NOT_FOUND"];
|
||||
}
|
||||
try {
|
||||
utility.startTenantFlow(carbonUser);
|
||||
if (roleName.indexOf('/') > 0) {
|
||||
userStore = roleName.substr(0, roleName.indexOf('/'));
|
||||
roleName = roleName.substr(roleName.indexOf('/') + 1);
|
||||
}
|
||||
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
|
||||
"/roles/" + encodeURIComponent(roleName);
|
||||
if (userStore) {
|
||||
url += "?user-store=" + encodeURIComponent(userStore);
|
||||
}
|
||||
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
|
||||
if (response.status == "success") {
|
||||
response.content = parse(response.content);
|
||||
}
|
||||
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;
|
||||
try {
|
||||
carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||
} catch (e) {
|
||||
log.error("User object was not found in the session");
|
||||
carbonUser = null;
|
||||
}
|
||||
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/devices/any-device")) {
|
||||
permissions["LIST_DEVICES"] = true;
|
||||
permissions["LIST_OWN_DEVICES"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/devices/owning-device/view")) {
|
||||
permissions["LIST_OWN_DEVICES"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/groups/view")) {
|
||||
permissions["LIST_ALL_GROUPS"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/view")) {
|
||||
permissions["LIST_GROUPS"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/users/list")) {
|
||||
permissions["LIST_USERS"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/roles/list")) {
|
||||
permissions["LIST_ROLES"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/policies/list")) {
|
||||
permissions["LIST_ALL_POLICIES"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/policies/list")) {
|
||||
permissions["LIST_POLICIES"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/devices/enroll")) {
|
||||
permissions["ADD_DEVICE"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/add")) {
|
||||
permissions["ADD_GROUP"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/users/add")) {
|
||||
permissions["ADD_USER"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/devices/add")) {
|
||||
permissions["ADD_GROUP_DEVICES"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/devices/remove")) {
|
||||
permissions["REMOVE_GROUP_DEVICES"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/devices/view")) {
|
||||
permissions["VIEW_GROUP_DEVICES"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/roles/view")) {
|
||||
permissions["VIEW_GROUP_ROLES"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/update")) {
|
||||
permissions["UPDATE_GROUP"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/share")) {
|
||||
permissions["SHARE_GROUP"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/users/remove")) {
|
||||
permissions["REMOVE_USER"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/groups/remove")) {
|
||||
permissions["REMOVE_GROUP"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/roles/add")) {
|
||||
permissions["ADD_ROLE"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/policies/add")) {
|
||||
permissions["ADD_ADMIN_POLICY"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/policies/add")) {
|
||||
permissions["ADD_POLICY"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/policies/priority")) {
|
||||
permissions["CHANGE_POLICY_PRIORITY"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/dashboard/view")) {
|
||||
permissions["VIEW_DASHBOARD"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/platform-configurations/view")) {
|
||||
permissions["TENANT_CONFIGURATION"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/certificates/manage")) {
|
||||
permissions["CERTIFICATE_MANAGEMENT"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/devices/change-status")) {
|
||||
permissions["CHANGE_DEVICE_STATUS"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt")) {
|
||||
permissions["IS_ADMIN"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/topics/view")) {
|
||||
permissions["VIEW_TOPICS"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/devices/update-enrollment")) {
|
||||
permissions["UPDATE_ENROLLMENT"] = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/devices/permanent-delete")) {
|
||||
permissions["PERMANENT_DELETE"] = 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 {
|
||||
var array = Object.keys(permissions);
|
||||
var i, permission;
|
||||
for (i = 0; i < array.length; i++) {
|
||||
permission = array[i];
|
||||
userManager.authorizeRole(roleName, permission, "ui.execute");
|
||||
}
|
||||
}
|
||||
} 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 Array of secondary user stores.
|
||||
*/
|
||||
publicMethods.getSecondaryUserStores = function () {
|
||||
var returnVal = [];
|
||||
// To call the userstore admin service, user needs to have admin permission
|
||||
if (publicMethods.isAuthorized("/permission/admin")) {
|
||||
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",
|
||||
wsPayload,
|
||||
endpoint,
|
||||
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"]);
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("User does not have admin permission to get the secondary user store details.");
|
||||
}
|
||||
}
|
||||
return returnVal;
|
||||
};
|
||||
|
||||
return publicMethods;
|
||||
}();
|
||||
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 conf = function () {
|
||||
var cloudConf = application.get("CLOUD_CONF");
|
||||
if (!cloudConf) {
|
||||
cloudConf = require("/app/conf/toplink-menu.json");
|
||||
var pinch = require("/app/modules/conf-reader/pinch.min.js")["pinch"];
|
||||
var server = require("carbon")["server"];
|
||||
var process = require("process");
|
||||
pinch(cloudConf, /^/,
|
||||
function (path, key, value) {
|
||||
if ((typeof value === "string") && value.indexOf("%https.ip%") > -1) {
|
||||
//noinspection JSUnresolvedFunction
|
||||
return value.replace("%https.ip%", server.address("https"));
|
||||
} else if ((typeof value === "string") && value.indexOf("%http.ip%") > -1) {
|
||||
//noinspection JSUnresolvedFunction
|
||||
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);
|
||||
} else if ((typeof value === "string") && value.indexOf("%server.ip%") > -1) {
|
||||
var getProperty = require("process").getProperty;
|
||||
return value.replace("%server.ip%", getProperty("carbon.local.ip"));
|
||||
} else {
|
||||
var paramPattern = new RegExp("%(.*?)%", "g");
|
||||
var out = value;
|
||||
while ((matches = paramPattern.exec(value)) !== null) {
|
||||
// This is necessary to avoid infinite loops with zero-width matches
|
||||
if (matches.index === paramPattern.lastIndex) {
|
||||
paramPattern.lastIndex++;
|
||||
}
|
||||
if (matches.length == 2) {
|
||||
var property = process.getProperty(matches[1]);
|
||||
if (property) {
|
||||
out = out.replace(new RegExp("%" + matches[1] + "%", "g"), property);
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
);
|
||||
application.put("CLOUD_CONF", cloudConf);
|
||||
}
|
||||
return cloudConf;
|
||||
}();
|
||||
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 conf = function () {
|
||||
var conf = application.get("CONF");
|
||||
if (!conf) {
|
||||
conf = require("/app/conf/config.json");
|
||||
var pinch = require("/app/modules/conf-reader/pinch.min.js")["pinch"];
|
||||
var server = require("carbon")["server"];
|
||||
var process = require("process");
|
||||
pinch(conf, /^/,
|
||||
function (path, key, value) {
|
||||
if ((typeof value === "string") && value.indexOf("%https.ip%") > -1) {
|
||||
//noinspection JSUnresolvedFunction
|
||||
return value.replace("%https.ip%", server.address("https"));
|
||||
} else if ((typeof value === "string") && value.indexOf("%http.ip%") > -1) {
|
||||
//noinspection JSUnresolvedFunction
|
||||
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);
|
||||
} else if ((typeof value === "string") && value.indexOf("%server.ip%") > -1) {
|
||||
var getProperty = require("process").getProperty;
|
||||
return value.replace("%server.ip%", getProperty("carbon.local.ip"));
|
||||
} else {
|
||||
var paramPattern = new RegExp("%(.*?)%", "g");
|
||||
var out = value;
|
||||
while ((matches = paramPattern.exec(value)) !== null) {
|
||||
// This is necessary to avoid infinite loops with zero-width matches
|
||||
if (matches.index === paramPattern.lastIndex) {
|
||||
paramPattern.lastIndex++;
|
||||
}
|
||||
if (matches.length == 2) {
|
||||
var property = process.getProperty(matches[1]);
|
||||
if (property) {
|
||||
out = out.replace(new RegExp("%" + matches[1] + "%", "g"), property);
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
);
|
||||
var DeviceConfigurationManager = Packages.io.entgra.device.mgt.core.device.mgt.core.config.DeviceConfigurationManager;
|
||||
conf["serverConfig"] = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
||||
application.put("CONF", conf);
|
||||
}
|
||||
return conf;
|
||||
}();
|
||||
@ -1,26 +0,0 @@
|
||||
/*
|
||||
* 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})();
|
||||
@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 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_OS_BUILD_DATE = "osBuildDate";
|
||||
var DEVICE_PROPERTIES = "properties";
|
||||
var DEVICE_ENROLLMENT_INFO = "enrolmentInfo";
|
||||
var DEVICE_STATUS = "status";
|
||||
var DEVICE_INFO = "deviceInfo";
|
||||
|
||||
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",
|
||||
"UNKNOWN_ERROR": "Unknown Error"
|
||||
};
|
||||
|
||||
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 TOKEN_PAIR = "tokenPair";
|
||||
var ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS = "encodedTenantBasedClientAppCredentials";
|
||||
var CONTENT_TYPE_IDENTIFIER = "Content-Type";
|
||||
var ENCODED_TENANT_BASED_WEB_SOCKET_CLIENT_CREDENTIALS = "encodedTenantBasedWebSocketClientCredentials";
|
||||
|
||||
var CONTENT_DISPOSITION_IDENTIFIER = "Content-Disposition";
|
||||
var APPLICATION_JSON = "application/json";
|
||||
var APPLICATION_ZIP = "application/zip";
|
||||
var STREAMING_FILES_ACCEPT_HEADERS = ["application/zip", "application/pdf", "application/octet-stream"];
|
||||
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 HTTP_CONFLICT = 409;
|
||||
var HTTP_CREATED = 201;
|
||||
|
||||
var CACHED_CREDENTIALS = "tenantBasedCredentials";
|
||||
var CACHED_CREDENTIALS_FOR_WEBSOCKET_APP = "tenantBasedWebSocketClientCredentials";
|
||||
|
||||
var ALLOWED_SCOPES = "scopes";
|
||||
|
||||
var SAML_TOKEN_KEY = "samlToken";
|
||||
var SKIP_WELCOME_SCREEN ="skipWelcomeScreen";
|
||||
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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/modules/conf-reader/main.js")["conf"];
|
||||
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
|
||||
|
||||
//noinspection JSUnresolvedFunction Server
|
||||
var carbonServer = new carbonModule.server.Server({
|
||||
tenanted: true,
|
||||
url: devicemgtProps["httpsURL"] + "/admin"
|
||||
});
|
||||
|
||||
application.put("carbonServer", carbonServer);
|
||||
|
||||
var permissions = {
|
||||
"/permission/admin/Login": ["ui.execute"],
|
||||
"/permission/admin/manage/api/subscribe": ["ui.execute"],
|
||||
"/permission/admin/device-mgt/device/api/subscribe": ["ui.execute"],
|
||||
"/permission/admin/device-mgt/devices/enroll": ["ui.execute"],
|
||||
"/permission/admin/device-mgt/devices/disenroll": ["ui.execute"],
|
||||
"/permission/admin/device-mgt/devices/owning-device/view": ["ui.execute"],
|
||||
"/permission/admin/manage/portal": ["ui.execute"]
|
||||
};
|
||||
|
||||
var adminPermissions = {
|
||||
"/permission/admin/device-mgt": ["ui.execute"],
|
||||
"/permission/admin/manage/api": ["ui.execute"],
|
||||
"/permission/admin/manage/portal": ["ui.execute"]
|
||||
};
|
||||
|
||||
//On Startup, admin user will get both roles: devicemgt-admin and devicemgt-user
|
||||
//Average user through sign-up will only receive the role: devicemgt-user.
|
||||
//Admin can setup necessary permissions for the role: devicemgt-user
|
||||
userModule.addRole("internal/devicemgt-user", ["admin"], permissions);
|
||||
userModule.addRole("internal/devicemgt-admin", ["admin"], adminPermissions);
|
||||
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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("/app/modules/login.js");
|
||||
var constants = require("/app/modules/constants.js");
|
||||
onSuccess = function (context) {
|
||||
var utility = require("/app/modules/utility.js").utility;
|
||||
var apiWrapperUtil = require("/app/modules/oauth/token-handlers.js")["handlers"];
|
||||
try {
|
||||
utility.startTenantFlow(context.user);
|
||||
var APIManagementProviderService = utility.getAPIManagementProviderService();
|
||||
var isLoaded = APIManagementProviderService.isTierLoaded();
|
||||
if(!isLoaded && context.input.samlToken) {
|
||||
session.put(constants.SKIP_WELCOME_SCREEN, false);
|
||||
session.put(constants.SAML_TOKEN_KEY, context.input.samlToken);
|
||||
return;
|
||||
}
|
||||
} finally {
|
||||
utility.endTenantFlow();
|
||||
}
|
||||
session.put(constants.SKIP_WELCOME_SCREEN, true);
|
||||
if (context.input.samlToken) {
|
||||
//apiWrapperUtil.setupTokenPairBySamlGrantType(context.user.username + '@' + context.user.domain, context.input.samlToken);
|
||||
/**
|
||||
* Since the user can be verified using the sso.client.js we can use JWT grant type to issue the token for the user.
|
||||
*/
|
||||
apiWrapperUtil.setupTokenPairByJWTGrantType(context.user.username + '@' + context.user.domain, context.input.samlToken);
|
||||
} else {
|
||||
apiWrapperUtil.setupTokenPairByPasswordGrantType(context.input.username, context.input.password);
|
||||
}
|
||||
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var carbonServer = require("carbon").server;
|
||||
if (!context.input.samlToken) {
|
||||
(new carbonServer.Server({url: devicemgtProps["adminService"]}))
|
||||
.login(context.input.username, context.input.password);
|
||||
}
|
||||
};
|
||||
|
||||
onFail = function (error) {
|
||||
log.error(error.message);
|
||||
}
|
||||
})();
|
||||
@ -1,406 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 utils = function () {
|
||||
var log = new Log("/app/modules/oauth/token-handler-utils.js");
|
||||
|
||||
var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var constants = require("/app/modules/constants.js");
|
||||
var carbon = require("carbon");
|
||||
var authModule = require("/lib/modules/auth/auth.js").module;
|
||||
var utility = require('/app/modules/utility.js').utility;
|
||||
|
||||
//noinspection JSUnresolvedVariable
|
||||
var Base64 = Packages.org.apache.commons.codec.binary.Base64;
|
||||
//noinspection JSUnresolvedVariable
|
||||
var String = Packages.java.lang.String;
|
||||
|
||||
var publicMethods = {};
|
||||
var privateMethods = {};
|
||||
|
||||
publicMethods["encode"] = function (payload) {
|
||||
//noinspection JSUnresolvedFunction
|
||||
return String(Base64.encodeBase64(String(payload).getBytes()));
|
||||
};
|
||||
|
||||
publicMethods["decode"] = function (payload) {
|
||||
//noinspection JSUnresolvedFunction
|
||||
return String(Base64.decodeBase64(String(payload).getBytes()));
|
||||
};
|
||||
|
||||
publicMethods["getDynamicClientAppCredentials"] = function () {
|
||||
// setting up dynamic client application properties
|
||||
var dcAppProperties = {
|
||||
"applicationType": deviceMgtProps["oauthProvider"]["appRegistration"]["appType"],
|
||||
"clientName": deviceMgtProps["oauthProvider"]["appRegistration"]["clientName"],
|
||||
"owner": deviceMgtProps["oauthProvider"]["appRegistration"]["owner"],
|
||||
"tokenScope": deviceMgtProps["oauthProvider"]["appRegistration"]["tokenScope"],
|
||||
"grantType": deviceMgtProps["oauthProvider"]["appRegistration"]["grantType"],
|
||||
"callbackUrl": deviceMgtProps["oauthProvider"]["appRegistration"]["callbackUrl"],
|
||||
"saasApp" : true
|
||||
};
|
||||
// calling dynamic client app registration service endpoint
|
||||
var requestURL = deviceMgtProps["oauthProvider"]["appRegistration"]
|
||||
["dynamicClientAppRegistrationServiceURL"];
|
||||
var requestPayload = dcAppProperties;
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", requestURL, false);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.send(stringify(requestPayload));
|
||||
|
||||
var dynamicClientAppCredentials = {};
|
||||
if (xhr["status"] == 201 && xhr["responseText"]) {
|
||||
var responsePayload = parse(xhr["responseText"]);
|
||||
dynamicClientAppCredentials["clientId"] = responsePayload["client_id"];
|
||||
dynamicClientAppCredentials["clientSecret"] = responsePayload["client_secret"];
|
||||
} else if (xhr["status"] == 400) {
|
||||
log.error("{/app/modules/oauth/token-handler-utils.js - getDynamicClientAppCredentials()} " +
|
||||
"Bad request. Invalid data provided as dynamic client application properties.");
|
||||
dynamicClientAppCredentials = null;
|
||||
} else {
|
||||
log.error("{/app/modules/oauth/token-handler-utils.js - getDynamicClientAppCredentials()} " +
|
||||
"Error in retrieving dynamic client credentials.");
|
||||
dynamicClientAppCredentials = null;
|
||||
}
|
||||
// returning dynamic client credentials
|
||||
return dynamicClientAppCredentials;
|
||||
};
|
||||
|
||||
publicMethods["getTenantBasedClientAppCredentials"] = function (username) {
|
||||
if (!username) {
|
||||
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving tenant " +
|
||||
"based client app credentials. No username " +
|
||||
"as input - getTenantBasedClientAppCredentials(x)");
|
||||
return null;
|
||||
} else {
|
||||
//noinspection JSUnresolvedFunction, JSUnresolvedVariable
|
||||
var tenantDomain = carbon.server.tenantDomain({username: username});
|
||||
if (!tenantDomain) {
|
||||
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving tenant " +
|
||||
"based client application credentials. Unable to obtain a valid tenant domain for provided " +
|
||||
"username - getTenantBasedClientAppCredentials(x, y)");
|
||||
return null;
|
||||
} else {
|
||||
var cachedTenantBasedClientAppCredentials = privateMethods.
|
||||
getCachedTenantBasedClientAppCredentials(tenantDomain);
|
||||
if (cachedTenantBasedClientAppCredentials) {
|
||||
return cachedTenantBasedClientAppCredentials;
|
||||
} else {
|
||||
var adminUsername = deviceMgtProps["adminUser"];
|
||||
var adminUserTenantId = deviceMgtProps["adminUserTenantId"];
|
||||
//claims required for jwtAuthenticator.
|
||||
var claims = {"http://wso2.org/claims/enduserTenantId": adminUserTenantId,
|
||||
"http://wso2.org/claims/enduser": adminUsername};
|
||||
var jwtToken = publicMethods.getJwtToken(adminUsername, claims);
|
||||
|
||||
// register a tenant based client app at API Manager
|
||||
var applicationName = deviceMgtProps["oauthProvider"]["appRegistration"]
|
||||
["clientName"] + "_" + tenantDomain;
|
||||
var requestURL = deviceMgtProps["oauthProvider"]["appRegistration"]
|
||||
["apiManagerClientAppRegistrationServiceURL"] +
|
||||
"?tenantDomain=" + tenantDomain + "&applicationName=" + applicationName;
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", requestURL, false);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.setRequestHeader("X-JWT-Assertion", "" + jwtToken);
|
||||
xhr.send();
|
||||
|
||||
if (xhr["status"] == 201 && xhr["responseText"]) {
|
||||
var responsePayload = parse(xhr["responseText"]);
|
||||
var tenantBasedClientAppCredentials = {};
|
||||
tenantBasedClientAppCredentials["clientId"] = responsePayload["client_id"];
|
||||
tenantBasedClientAppCredentials["clientSecret"] = responsePayload["client_secret"];
|
||||
privateMethods.
|
||||
setCachedTenantBasedClientAppCredentials(tenantDomain, tenantBasedClientAppCredentials);
|
||||
return tenantBasedClientAppCredentials;
|
||||
} else {
|
||||
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving tenant " +
|
||||
"based client application credentials from API " +
|
||||
"Manager - getTenantBasedClientAppCredentials(x, y)");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
publicMethods["getTenantBasedWebSocketClientAppCredentials"] = function (username) {
|
||||
if (!username) {
|
||||
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving tenant " +
|
||||
"based client app credentials. No username " +
|
||||
"as input - getTenantBasedWebSocketClientAppCredentials(x)");
|
||||
return null;
|
||||
} else {
|
||||
//noinspection JSUnresolvedFunction, JSUnresolvedVariable
|
||||
var tenantDomain = carbon.server.tenantDomain({username: username});
|
||||
if (!tenantDomain) {
|
||||
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving tenant " +
|
||||
"based client application credentials. Unable to obtain a valid tenant domain for provided " +
|
||||
"username - getTenantBasedWebSocketClientAppCredentials(x, y)");
|
||||
return null;
|
||||
} else {
|
||||
var cachedBasedWebsocketClientAppCredentials = privateMethods.
|
||||
getCachedBasedWebSocketClientAppCredentials(tenantDomain);
|
||||
if (cachedBasedWebsocketClientAppCredentials) {
|
||||
return cachedBasedWebsocketClientAppCredentials;
|
||||
} else {
|
||||
var adminUsername = deviceMgtProps["adminUser"];
|
||||
var adminUserTenantId = deviceMgtProps["adminUserTenantId"];
|
||||
//claims required for jwtAuthenticator.
|
||||
var claims = {"http://wso2.org/claims/enduserTenantId": adminUserTenantId,
|
||||
"http://wso2.org/claims/enduser": adminUsername};
|
||||
var jwtToken = publicMethods.getJwtToken(adminUsername, claims);
|
||||
|
||||
// register a tenant based app at API Manager
|
||||
var applicationName = "websocket_webapp_" + tenantDomain;
|
||||
var requestURL = (deviceMgtProps["oauthProvider"]["appRegistration"]
|
||||
["apiManagerClientAppRegistrationServiceURL"]).replace("/tenants","");
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", requestURL, false);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.setRequestHeader("X-JWT-Assertion", "" + jwtToken);
|
||||
xhr.send(stringify({applicationName:applicationName, tags:["device_management"],
|
||||
isAllowedToAllDomains:false, isMappingAnExistingOAuthApp:false, validityPeriod: 3600}));
|
||||
if (xhr["status"] == 201 && xhr["responseText"]) {
|
||||
var responsePayload = parse(xhr["responseText"]);
|
||||
var tenantTenantBasedWebsocketClientAppCredentials = {};
|
||||
tenantTenantBasedWebsocketClientAppCredentials["clientId"] = responsePayload["client_id"];
|
||||
tenantTenantBasedWebsocketClientAppCredentials["clientSecret"] =
|
||||
responsePayload["client_secret"];
|
||||
privateMethods.setCachedBasedWebSocketClientAppCredentials(tenantDomain,
|
||||
tenantTenantBasedWebsocketClientAppCredentials);
|
||||
return tenantTenantBasedWebsocketClientAppCredentials;
|
||||
} else {
|
||||
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving tenant " +
|
||||
"based client application credentials from API " +
|
||||
"Manager - getTenantBasedWebSocketClientAppCredentials(x, y)");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
privateMethods["setCachedTenantBasedClientAppCredentials"] = function (tenantDomain, clientAppCredentials) {
|
||||
var cachedTenantBasedClientAppCredentialsMap = application.get(constants["CACHED_CREDENTIALS"]);
|
||||
if (!cachedTenantBasedClientAppCredentialsMap) {
|
||||
cachedTenantBasedClientAppCredentialsMap = {};
|
||||
cachedTenantBasedClientAppCredentialsMap[tenantDomain] = clientAppCredentials;
|
||||
application.put(constants["CACHED_CREDENTIALS"], cachedTenantBasedClientAppCredentialsMap);
|
||||
} else if (!cachedTenantBasedClientAppCredentialsMap[tenantDomain]) {
|
||||
cachedTenantBasedClientAppCredentialsMap[tenantDomain] = clientAppCredentials;
|
||||
}
|
||||
};
|
||||
|
||||
privateMethods["getCachedTenantBasedClientAppCredentials"] = function (tenantDomain) {
|
||||
var cachedTenantBasedClientAppCredentialsMap = application.get(constants["CACHED_CREDENTIALS"]);
|
||||
if (!cachedTenantBasedClientAppCredentialsMap ||
|
||||
!cachedTenantBasedClientAppCredentialsMap[tenantDomain]) {
|
||||
return null;
|
||||
} else {
|
||||
return cachedTenantBasedClientAppCredentialsMap[tenantDomain];
|
||||
}
|
||||
};
|
||||
|
||||
privateMethods["getCachedBasedWebSocketClientAppCredentials"] = function (tenantDomain) {
|
||||
var cachedBasedWebSocketClientAppCredentialsMap
|
||||
= application.get(constants["CACHED_CREDENTIALS_FOR_WEBSOCKET_APP"]);
|
||||
if (!cachedBasedWebSocketClientAppCredentialsMap ||
|
||||
!cachedBasedWebSocketClientAppCredentialsMap[tenantDomain]) {
|
||||
return null;
|
||||
} else {
|
||||
return cachedBasedWebSocketClientAppCredentialsMap[tenantDomain];
|
||||
}
|
||||
};
|
||||
|
||||
privateMethods["setCachedBasedWebSocketClientAppCredentials"] = function (tenantDomain, clientAppCredentials) {
|
||||
var cachedBasedWebSocketClientAppCredentialsMap
|
||||
= application.get(constants["CACHED_CREDENTIALS_FOR_WEBSOCKET_APP"]);
|
||||
if (!cachedBasedWebSocketClientAppCredentialsMap) {
|
||||
cachedBasedWebSocketClientAppCredentialsMap = {};
|
||||
cachedBasedWebSocketClientAppCredentialsMap[tenantDomain] = clientAppCredentials;
|
||||
application.put(constants["CACHED_CREDENTIALS_FOR_WEBSOCKET_APP"]
|
||||
, cachedBasedWebSocketClientAppCredentialsMap);
|
||||
} else if (!cachedBasedWebSocketClientAppCredentialsMap[tenantDomain]) {
|
||||
cachedBasedWebSocketClientAppCredentialsMap[tenantDomain] = clientAppCredentials;
|
||||
}
|
||||
};
|
||||
|
||||
publicMethods["getTokenPairAndScopesByPasswordGrantType"] = function (username, password
|
||||
, encodedClientAppCredentials, scopes) {
|
||||
if (!username || !password || !encodedClientAppCredentials || !scopes) {
|
||||
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving access token by password " +
|
||||
"grant type. No username, password, encoded client app credentials or scopes are " +
|
||||
"found - getTokenPairAndScopesByPasswordGrantType(a, b, c, d)");
|
||||
return null;
|
||||
} else {
|
||||
// calling oauth provider token service endpoint
|
||||
var requestURL = deviceMgtProps["oauthProvider"]["tokenServiceURL"];
|
||||
var requestPayload = "grant_type=password&username=" +
|
||||
username + "&password=" + password + "&scope=" + scopes;
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", requestURL, false);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.setRequestHeader("Authorization", "Basic " + encodedClientAppCredentials);
|
||||
xhr.send(requestPayload);
|
||||
|
||||
if (xhr["status"] == 200 && xhr["responseText"]) {
|
||||
var responsePayload = parse(xhr["responseText"]);
|
||||
var tokenData = {};
|
||||
tokenData["accessToken"] = responsePayload["access_token"];
|
||||
tokenData["refreshToken"] = responsePayload["refresh_token"];
|
||||
tokenData["scopes"] = responsePayload["scope"];
|
||||
return tokenData;
|
||||
} else {
|
||||
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving access token " +
|
||||
"by password grant type - getTokenPairAndScopesByPasswordGrantType(a, b, c, d)");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
publicMethods["getTokenPairAndScopesByJWTGrantType"] = function (assertion, encodedClientAppCredentials, scopes) {
|
||||
if (!assertion || !encodedClientAppCredentials || !scopes) {
|
||||
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving access token by jwt " +
|
||||
"grant type. No assertion, encoded client app credentials or scopes are " +
|
||||
"found - getTokenPairAndScopesByJWTGrantType(x, y, z)");
|
||||
return null;
|
||||
} else {
|
||||
var ssoLoginUser = authModule.ssoLogin(assertion);
|
||||
if (!ssoLoginUser.user.username) {
|
||||
return null;
|
||||
}
|
||||
var endUsername = ssoLoginUser.user.username + "@" + ssoLoginUser.user.domain;
|
||||
var JWTClientManagerServicePackagePath =
|
||||
"io.entgra.device.mgt.core.identity.jwt.client.extension.service.JWTClientManagerService";
|
||||
//noinspection JSUnresolvedFunction, JSUnresolvedVariable
|
||||
var JWTClientManagerService = carbon.server.osgiService(JWTClientManagerServicePackagePath);
|
||||
//noinspection JSUnresolvedFunction
|
||||
var jwtClient = JWTClientManagerService.getJWTClient();
|
||||
// returning access token by JWT grant type
|
||||
var tokenInfo = jwtClient.getAccessToken(encodedClientAppCredentials,
|
||||
endUsername, scopes);
|
||||
if (tokenInfo) {
|
||||
var tokenData = {};
|
||||
tokenData["accessToken"] = tokenInfo.getAccessToken();
|
||||
tokenData["refreshToken"] = tokenInfo.getRefreshToken();
|
||||
tokenData["scopes"] = tokenInfo.getScopes();
|
||||
return tokenData;
|
||||
} else {
|
||||
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving access token " +
|
||||
"by jwt grant type - getTokenPairAndScopesByJWTGrantType()");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
publicMethods["getNewTokenPairByRefreshToken"] = function (refreshToken, encodedClientAppCredentials, scopes) {
|
||||
if (!refreshToken || !encodedClientAppCredentials) {
|
||||
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving new access token " +
|
||||
"by current refresh token. No refresh token or encoded client app credentials are " +
|
||||
"found - getNewTokenPairByRefreshToken(x, y, z)");
|
||||
return null;
|
||||
} else {
|
||||
var requestURL = deviceMgtProps["oauthProvider"]["tokenServiceURL"];
|
||||
var requestPayload = "grant_type=refresh_token&refresh_token=" + refreshToken;
|
||||
if (scopes) {
|
||||
requestPayload = requestPayload + "&scope=" + scopes;
|
||||
}
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", requestURL, false);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.setRequestHeader("Authorization", "Basic " + encodedClientAppCredentials);
|
||||
xhr.send(requestPayload);
|
||||
|
||||
if (xhr["status"] == 200 && xhr["responseText"]) {
|
||||
var responsePayload = parse(xhr["responseText"]);
|
||||
var tokenPair = {};
|
||||
tokenPair["accessToken"] = responsePayload["access_token"];
|
||||
tokenPair["refreshToken"] = responsePayload["refresh_token"];
|
||||
return tokenPair;
|
||||
} else {
|
||||
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving new access token by " +
|
||||
"current refresh token - getNewTokenPairByRefreshToken(x, y, z)");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
publicMethods["getAccessTokenByJWTGrantType"] = function (clientAppCredentials) {
|
||||
if (!clientAppCredentials) {
|
||||
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving new access token " +
|
||||
"by current refresh token. No client app credentials are found " +
|
||||
"as input - getAccessTokenByJWTGrantType(x)");
|
||||
return null;
|
||||
} else {
|
||||
var JWTClientManagerServicePackagePath =
|
||||
"io.entgra.device.mgt.core.identity.jwt.client.extension.service.JWTClientManagerService";
|
||||
//noinspection JSUnresolvedFunction, JSUnresolvedVariable
|
||||
var JWTClientManagerService = carbon.server.osgiService(JWTClientManagerServicePackagePath);
|
||||
//noinspection JSUnresolvedFunction
|
||||
var jwtClient = JWTClientManagerService.getJWTClient();
|
||||
// returning access token by JWT grant type
|
||||
return jwtClient.getAccessToken(clientAppCredentials["clientId"], clientAppCredentials["clientSecret"],
|
||||
deviceMgtProps["oauthProvider"]["appRegistration"]["owner"], null)["accessToken"];
|
||||
}
|
||||
};
|
||||
|
||||
publicMethods["getJwtToken"] = function (username, claims) {
|
||||
if (!username) {
|
||||
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving new jwt token");
|
||||
return null;
|
||||
} else {
|
||||
var JWTClientManagerServicePackagePath =
|
||||
"io.entgra.device.mgt.core.identity.jwt.client.extension.service.JWTClientManagerService";
|
||||
//noinspection JSUnresolvedFunction, JSUnresolvedVariable
|
||||
var JWTClientManagerService = carbon.server.osgiService(JWTClientManagerServicePackagePath);
|
||||
//noinspection JSUnresolvedFunction
|
||||
var jwtClient = JWTClientManagerService.getJWTClient();
|
||||
// returning access token by JWT grant type
|
||||
if (claims) {
|
||||
return jwtClient.getJwtToken(username, claims);
|
||||
} else {
|
||||
return jwtClient.getJwtToken(username);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
publicMethods["removeClientAppCredentials"] = function (tenantDomain) {
|
||||
var cachedTenantBasedClientAppCredentialsMap = application.get(constants["CACHED_CREDENTIALS"]);
|
||||
if (cachedTenantBasedClientAppCredentialsMap) {
|
||||
if (cachedTenantBasedClientAppCredentialsMap[tenantDomain]) {
|
||||
delete cachedTenantBasedClientAppCredentialsMap[tenantDomain];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
publicMethods["getUniqueBrowserScope"] = function () {
|
||||
var deviceScope = "device_" + utility.md5(request.getHeader("User-Agent") + "::" + request.getRemoteAddr());
|
||||
deviceScope = deviceScope + " ";
|
||||
return deviceScope;
|
||||
};
|
||||
|
||||
|
||||
|
||||
return publicMethods;
|
||||
}();
|
||||
@ -1,282 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* -----------------------------------------------------
|
||||
* Following module includes handlers
|
||||
* at Jaggery Layer for handling OAuth tokens.
|
||||
* -----------------------------------------------------
|
||||
*/
|
||||
var handlers = function () {
|
||||
var log = new Log("/app/modules/oauth/token-handlers.js");
|
||||
|
||||
var tokenUtil = require("/app/modules/oauth/token-handler-utils.js")["utils"];
|
||||
var constants = require("/app/modules/constants.js");
|
||||
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var utility = require("/app/modules/utility.js")["utility"];
|
||||
|
||||
var publicMethods = {};
|
||||
var privateMethods = {};
|
||||
|
||||
publicMethods["setupTokenPairByPasswordGrantType"] = function (username, password) {
|
||||
if (!username || !password) {
|
||||
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up access token pair by " +
|
||||
"password grant type. Either username of logged in user, password or both are missing " +
|
||||
"as input - setupTokenPairByPasswordGrantType(x, y)");
|
||||
} else {
|
||||
privateMethods.setUpEncodedTenantBasedClientAppCredentials(username);
|
||||
privateMethods.setUpEncodedTenantBasedWebSocketClientAppCredentials(username);
|
||||
var encodedClientAppCredentials = session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS"]);
|
||||
if (!encodedClientAppCredentials) {
|
||||
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up access token pair by " +
|
||||
"password grant type. Encoded client credentials are " +
|
||||
"missing - setupTokenPairByPasswordGrantType(x, y)");
|
||||
} else {
|
||||
var tokenData;
|
||||
// tokenPair will include current access token as well as current refresh token
|
||||
var arrayOfScopes = devicemgtProps["scopes"];
|
||||
arrayOfScopes = arrayOfScopes.concat(utility.getDeviceTypesScopesList());
|
||||
var stringOfScopes = tokenUtil.getUniqueBrowserScope();
|
||||
arrayOfScopes.forEach(function (entry) {
|
||||
stringOfScopes += entry + " ";
|
||||
});
|
||||
tokenData = tokenUtil.
|
||||
getTokenPairAndScopesByPasswordGrantType(username,
|
||||
encodeURIComponent(password), encodedClientAppCredentials, stringOfScopes);
|
||||
if (!tokenData) {
|
||||
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up " +
|
||||
"token pair by password grant type. Error in token " +
|
||||
"retrieval - setupTokenPairByPasswordGrantType(x, y)");
|
||||
} else {
|
||||
var tokenPair = {};
|
||||
tokenPair["accessToken"] = tokenData["accessToken"];
|
||||
tokenPair["refreshToken"] = tokenData["refreshToken"];
|
||||
// setting up token pair into session context as a string
|
||||
session.put(constants["TOKEN_PAIR"], stringify(tokenPair));
|
||||
|
||||
var scopes = tokenData.scopes.split(" ");
|
||||
// adding allowed scopes to the session
|
||||
session.put(constants["ALLOWED_SCOPES"], scopes);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
publicMethods["setupTokenPairBySamlGrantType"] = function (username, samlToken) {
|
||||
if (!username || !samlToken) {
|
||||
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up access token pair by " +
|
||||
"saml grant type. Either username of logged in user, samlToken or both are missing " +
|
||||
"as input - setupTokenPairBySamlGrantType(x, y)");
|
||||
} else {
|
||||
privateMethods.setUpEncodedTenantBasedClientAppCredentials(username);
|
||||
privateMethods.setUpEncodedTenantBasedWebSocketClientAppCredentials(username);
|
||||
var encodedClientAppCredentials = session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS"]);
|
||||
if (!encodedClientAppCredentials) {
|
||||
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up access token pair " +
|
||||
"by saml grant type. Encoded client credentials are " +
|
||||
"missing - setupTokenPairBySamlGrantType(x, y)");
|
||||
} else {
|
||||
var tokenData;
|
||||
var arrayOfScopes = devicemgtProps["scopes"];
|
||||
arrayOfScopes = arrayOfScopes.concat(utility.getDeviceTypesScopesList());
|
||||
var stringOfScopes = tokenUtil.getUniqueBrowserScope();
|
||||
arrayOfScopes.forEach(function (entry) {
|
||||
stringOfScopes += entry + " ";
|
||||
});
|
||||
|
||||
// accessTokenPair will include current access token as well as current refresh token
|
||||
tokenData = tokenUtil.
|
||||
getTokenPairAndScopesBySAMLGrantType(samlToken, encodedClientAppCredentials, stringOfScopes);
|
||||
if (!tokenData) {
|
||||
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up token " +
|
||||
"pair by password grant type. Error in token " +
|
||||
"retrieval - setupTokenPairBySamlGrantType(x, y)");
|
||||
} else {
|
||||
var tokenPair = {};
|
||||
tokenPair["accessToken"] = tokenData["accessToken"];
|
||||
tokenPair["refreshToken"] = tokenData["refreshToken"];
|
||||
// setting up access token pair into session context as a string
|
||||
session.put(constants["TOKEN_PAIR"], stringify(tokenPair));
|
||||
|
||||
var scopes = tokenData.scopes.split(" ");
|
||||
// adding allowed scopes to the session
|
||||
session.put(constants["ALLOWED_SCOPES"], scopes);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
publicMethods["setupTokenPairByJWTGrantType"] = function (username, samlToken) {
|
||||
//samlToken is used to validate then if the user is a valid user then token is issued with JWT Grant Type.
|
||||
if (!username || !samlToken) {
|
||||
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up access token pair by " +
|
||||
"saml grant type. Either username of logged in user, samlToken or both are missing " +
|
||||
"as input - setupTokenPairBySamlGrantType(x, y)");
|
||||
} else {
|
||||
privateMethods.setUpEncodedTenantBasedClientAppCredentials(username);
|
||||
privateMethods.setUpEncodedTenantBasedWebSocketClientAppCredentials(username);
|
||||
var encodedClientAppCredentials = session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS"]);
|
||||
if (!encodedClientAppCredentials) {
|
||||
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up access token pair " +
|
||||
"by saml grant type. Encoded client credentials are " +
|
||||
"missing - setupTokenPairBySamlGrantType(x, y)");
|
||||
} else {
|
||||
var tokenData;
|
||||
var arrayOfScopes = devicemgtProps["scopes"];
|
||||
arrayOfScopes = arrayOfScopes.concat(utility.getDeviceTypesScopesList());
|
||||
var stringOfScopes = tokenUtil.getUniqueBrowserScope();
|
||||
arrayOfScopes.forEach(function (entry) {
|
||||
stringOfScopes += entry + " ";
|
||||
});
|
||||
|
||||
// accessTokenPair will include current access token as well as current refresh token
|
||||
tokenData = tokenUtil.
|
||||
getTokenPairAndScopesByJWTGrantType(samlToken, encodedClientAppCredentials, stringOfScopes);
|
||||
if (!tokenData) {
|
||||
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up token. Error in token " +
|
||||
"retrieval - setupTokenPairBySamlGrantType(x, y)");
|
||||
} else {
|
||||
var tokenPair = {};
|
||||
tokenPair["accessToken"] = tokenData["accessToken"];
|
||||
tokenPair["refreshToken"] = tokenData["refreshToken"];
|
||||
// setting up access token pair into session context as a string
|
||||
session.put(constants["TOKEN_PAIR"], stringify(tokenPair));
|
||||
|
||||
var scopes = tokenData.scopes.split(" ");
|
||||
// adding allowed scopes to the session
|
||||
session.put(constants["ALLOWED_SCOPES"], scopes);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
publicMethods["refreshTokenPair"] = function () {
|
||||
var currentTokenPair = parse(session.get(constants["TOKEN_PAIR"]));
|
||||
// currentTokenPair includes current access token as well as current refresh token
|
||||
var encodedClientAppCredentials = session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS"]);
|
||||
if (!currentTokenPair || !encodedClientAppCredentials) {
|
||||
throw new Error("{/app/modules/oauth/token-handlers.js} Error in refreshing tokens. Either the " +
|
||||
"token pair, encoded client app credentials or both input are not found under " +
|
||||
"session context - refreshTokenPair()");
|
||||
} else {
|
||||
var newTokenPair = tokenUtil.
|
||||
getNewTokenPairByRefreshToken(currentTokenPair["refreshToken"], encodedClientAppCredentials);
|
||||
if (!newTokenPair) {
|
||||
log.error("{/app/modules/oauth/token-handlers.js} Error in refreshing token pair. " +
|
||||
"Unable to update session context with new access token pair - refreshTokenPair()");
|
||||
userModule.logout(function () {
|
||||
response.sendRedirect(devicemgtProps["appContext"] + "login");
|
||||
});
|
||||
} else {
|
||||
session.put(constants["TOKEN_PAIR"], stringify(newTokenPair));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
privateMethods["setUpEncodedTenantBasedClientAppCredentials"] = function (username) {
|
||||
if (!username) {
|
||||
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up encoded tenant based " +
|
||||
"client credentials to session context. No username of logged in user is found as " +
|
||||
"input - setUpEncodedTenantBasedClientAppCredentials(x)");
|
||||
} else {
|
||||
if (devicemgtProps["gatewayEnabled"]) {
|
||||
var tenantBasedClientAppCredentials = tokenUtil.getTenantBasedClientAppCredentials(username);
|
||||
if (!tenantBasedClientAppCredentials) {
|
||||
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up encoded tenant " +
|
||||
"based client credentials to session context as the server is unable " +
|
||||
"to obtain such credentials - setUpEncodedTenantBasedClientAppCredentials(x)");
|
||||
} else {
|
||||
var encodedTenantBasedClientAppCredentials =
|
||||
tokenUtil.encode(tenantBasedClientAppCredentials["clientId"] + ":" +
|
||||
tenantBasedClientAppCredentials["clientSecret"]);
|
||||
// setting up encoded tenant based client credentials to session context.
|
||||
session.put(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS"],
|
||||
encodedTenantBasedClientAppCredentials);
|
||||
}
|
||||
} else {
|
||||
var dynamicClientAppCredentials = tokenUtil.getDynamicClientAppCredentials();
|
||||
if (!dynamicClientAppCredentials) {
|
||||
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up encoded tenant based " +
|
||||
"client credentials to session context as the server is unable to obtain " +
|
||||
"dynamic client credentials - setUpEncodedTenantBasedClientAppCredentials(x)");
|
||||
}
|
||||
var encodedTenantBasedClientAppCredentials =
|
||||
tokenUtil.encode(dynamicClientAppCredentials["clientId"] + ":" +
|
||||
dynamicClientAppCredentials["clientSecret"]);
|
||||
// setting up encoded tenant based client credentials to session context.
|
||||
session.put(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS"],
|
||||
encodedTenantBasedClientAppCredentials);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
privateMethods["setUpEncodedTenantBasedWebSocketClientAppCredentials"] = function (username) {
|
||||
if (!username) {
|
||||
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up encoded tenant based " +
|
||||
"client credentials to session context. No username of logged in user is found as " +
|
||||
"input - setUpEncodedTenantBasedWebSocketClientAppCredentials(x)");
|
||||
} else {
|
||||
if (devicemgtProps["gatewayEnabled"]) {
|
||||
var tenantBasedWebSocketClientAppCredentials
|
||||
= tokenUtil.getTenantBasedWebSocketClientAppCredentials(username);
|
||||
if (!tenantBasedWebSocketClientAppCredentials) {
|
||||
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up encoded tenant " +
|
||||
"based client credentials to session context as the server is unable " +
|
||||
"to obtain such credentials - setUpEncodedTenantBasedWebSocketClientAppCredentials(x)");
|
||||
} else {
|
||||
var encodedTenantBasedWebSocketClientAppCredentials =
|
||||
tokenUtil.encode(tenantBasedWebSocketClientAppCredentials["clientId"] + ":" +
|
||||
tenantBasedWebSocketClientAppCredentials["clientSecret"]);
|
||||
// setting up encoded tenant based client credentials to session context.
|
||||
session.put(constants["ENCODED_TENANT_BASED_WEB_SOCKET_CLIENT_CREDENTIALS"],
|
||||
encodedTenantBasedWebSocketClientAppCredentials);
|
||||
}
|
||||
} else {
|
||||
var dynamicClientAppCredentials = tokenUtil.getDynamicClientAppCredentials();
|
||||
if (!dynamicClientAppCredentials) {
|
||||
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up encoded tenant based " +
|
||||
"client credentials to session context as the server is unable to obtain " +
|
||||
"dynamic client credentials - setUpEncodedTenantBasedWebSocketClientAppCredentials(x)");
|
||||
}
|
||||
var encodedTenantBasedWebSocketClientAppCredentials =
|
||||
tokenUtil.encode(dynamicClientAppCredentials["clientId"] + ":" +
|
||||
dynamicClientAppCredentials["clientSecret"]);
|
||||
// setting up encoded tenant based client credentials to session context.
|
||||
session.put(constants["ENCODED_TENANT_BASED_WEB_SOCKET_CLIENT_CREDENTIALS"],
|
||||
encodedTenantBasedWebSocketClientAppCredentials);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
publicMethods["removeClientDetails"] = function () {
|
||||
var user = session.get(constants.USER_SESSION_KEY);
|
||||
if (!user) {
|
||||
log.error("User object was not found in the session");
|
||||
throw constants.ERRORS.USER_NOT_FOUND;
|
||||
}
|
||||
tokenUtil.removeClientAppCredentials(user.domain);
|
||||
session.remove(constants["ENCODED_TENANT_BASED_WEB_SOCKET_CLIENT_CREDENTIALS"]);
|
||||
session.remove(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS"]);
|
||||
session.remove(constants["TOKEN_PAIR"]);
|
||||
session.remove(constants["ALLOWED_SCOPES"]);
|
||||
};
|
||||
|
||||
return publicMethods;
|
||||
}();
|
||||
@ -1,503 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* ----------------------------------------------------------------------------
|
||||
* Following module includes invokers
|
||||
* at Jaggery Layer for calling Backend Services, protected by OAuth Tokens.
|
||||
* These Services include both REST and SOAP Services.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
var invokers = function () {
|
||||
var log = new Log("/app/modules/oauth/token-protected-service-invokers.js");
|
||||
|
||||
var publicXMLHTTPInvokers = {};
|
||||
var publicHTTPClientInvokers = {};
|
||||
|
||||
var privateMethods = {};
|
||||
var publicWSInvokers = {};
|
||||
|
||||
var TOKEN_EXPIRED = "Access token expired";
|
||||
var TOKEN_INVALID = "Invalid input. Access token validation failed";
|
||||
|
||||
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var constants = require("/app/modules/constants.js");
|
||||
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
|
||||
var tokenUtil = require("/app/modules/oauth/token-handlers.js")["handlers"];
|
||||
var tokenHandler = require("/app/modules/oauth/token-handler-utils.js")["utils"];
|
||||
/**
|
||||
* This method reads the token pair from the session and return the access token.
|
||||
* If the token pair is not set in the session, this will return null.
|
||||
*/
|
||||
privateMethods.getAccessToken = function () {
|
||||
if (session) {
|
||||
var tokenPair = session.get(constants["TOKEN_PAIR"]);
|
||||
if (tokenPair) {
|
||||
return parse(tokenPair)["accessToken"];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------------------
|
||||
* Start of XML-HTTP-REQUEST based Interceptor implementations
|
||||
* ---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* This method add Oauth authentication header to outgoing XML-HTTP Requests if Oauth authentication is enabled.
|
||||
* @param httpMethod HTTP request type.
|
||||
* @param requestPayload payload/data if exists which is needed to be send.
|
||||
* @param endpoint Backend REST API url.
|
||||
* @param responseCallback a function to be called with response retrieved.
|
||||
* @param count a counter which hold the number of recursive execution
|
||||
* @param headers a list of name value pairs for additional http headers
|
||||
*/
|
||||
privateMethods["execute"] = function (httpMethod, requestPayload, endpoint, responseCallback, count, headers) {
|
||||
var xmlHttpRequest = new XMLHttpRequest();
|
||||
|
||||
xmlHttpRequest.open(httpMethod, endpoint);
|
||||
|
||||
var contentTypeFound = false;
|
||||
var acceptTypeFound = false;
|
||||
for (var i in headers) {
|
||||
xmlHttpRequest.setRequestHeader(headers[i].name, headers[i].value);
|
||||
if(constants["CONTENT_TYPE_IDENTIFIER"] == headers[i].name){
|
||||
contentTypeFound = true;
|
||||
}
|
||||
if(constants["ACCEPT_IDENTIFIER"] == headers[i].name){
|
||||
acceptTypeFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!contentTypeFound) {
|
||||
xmlHttpRequest.setRequestHeader(constants["CONTENT_TYPE_IDENTIFIER"], constants["APPLICATION_JSON"]);
|
||||
}
|
||||
|
||||
if (!acceptTypeFound) {
|
||||
xmlHttpRequest.setRequestHeader(constants["ACCEPT_IDENTIFIER"], constants["APPLICATION_JSON"]);
|
||||
}
|
||||
|
||||
if (devicemgtProps["isOAuthEnabled"]) {
|
||||
var accessToken = privateMethods.getAccessToken();
|
||||
if (accessToken == null) {
|
||||
userModule.logout(function () {
|
||||
response.sendRedirect(devicemgtProps["appContext"] + "login");
|
||||
});
|
||||
} else {
|
||||
xmlHttpRequest.setRequestHeader(constants["AUTHORIZATION_HEADER"],
|
||||
constants["BEARER_PREFIX"] + accessToken);
|
||||
}
|
||||
}
|
||||
|
||||
if (requestPayload) {
|
||||
xmlHttpRequest.send(requestPayload);
|
||||
} else {
|
||||
xmlHttpRequest.send();
|
||||
}
|
||||
|
||||
log.debug("Request : " + httpMethod + " " + endpoint);
|
||||
log.debug("Request payload if any : " + stringify(requestPayload));
|
||||
log.debug("Response status : " + xmlHttpRequest.status);
|
||||
log.debug("Response payload if any : " + xmlHttpRequest.responseText);
|
||||
if (devicemgtProps["isCloud"]) {
|
||||
log.info("Request : " + httpMethod + " " + endpoint);
|
||||
log.info("Request payload if any : " + stringify(requestPayload));
|
||||
log.info("Response status : " + xmlHttpRequest.status);
|
||||
}
|
||||
|
||||
if (xmlHttpRequest.status == 401) {
|
||||
if ((xmlHttpRequest.responseText == TOKEN_EXPIRED ||
|
||||
xmlHttpRequest.responseText == TOKEN_INVALID ) && count < 5) {
|
||||
tokenUtil.refreshTokenPair();
|
||||
return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, ++count, headers);
|
||||
} else if (privateMethods.isInvalidClientCredential(xmlHttpRequest.responseText)) {
|
||||
log.error("API application has been removed.");
|
||||
tokenUtil.removeClientDetails();
|
||||
session.invalidate();
|
||||
response.sendRedirect(devicemgtProps["appContext"] + "login");
|
||||
} else if (privateMethods.isInvalidCredential(xmlHttpRequest.responseText)) {
|
||||
tokenUtil.refreshTokenPair();
|
||||
return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, ++count, headers);
|
||||
}
|
||||
} else {
|
||||
return responseCallback(xmlHttpRequest);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* This method verify whether the access token is expired using response payload.
|
||||
* This is required when using API gateway.
|
||||
* @param responsePayload response payload.
|
||||
* return true if it is invalid otherwise false.
|
||||
*/
|
||||
privateMethods["isInvalidCredential"] =
|
||||
function (responsePayload) {
|
||||
if (responsePayload) {
|
||||
try {
|
||||
payload = parse(responsePayload);
|
||||
if (payload["fault"]["code"] == 900901) {
|
||||
log.debug("Access token is invalid: " + payload["fault"]["code"]);
|
||||
log.debug(payload["fault"]["description"]);
|
||||
return true;
|
||||
}
|
||||
} catch (err) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* This method verify whether the client credential is removed/blocked using response payload.
|
||||
* This is required when using API gateway.
|
||||
* @param responsePayload response payload.
|
||||
* return true if it is invalid otherwise false.
|
||||
*/
|
||||
privateMethods["isInvalidClientCredential"] =
|
||||
function (responsePayload) {
|
||||
if (responsePayload) {
|
||||
try {
|
||||
payload = parse(responsePayload);
|
||||
if (payload["fault"]["message"] == "Invalid Credentials") {
|
||||
return true;
|
||||
}
|
||||
} catch (err) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* This method add Oauth authentication header to outgoing XML-HTTP Requests if Oauth authentication is enabled.
|
||||
* @param httpMethod HTTP request type.
|
||||
* @param requestPayload payload/data if exists which is needed to be send.
|
||||
* @param endpoint Backend REST API url.
|
||||
* @param responseCallback a function to be called with response retrieved.
|
||||
*/
|
||||
privateMethods["initiateXMLHTTPRequest"] =
|
||||
function (httpMethod, requestPayload, endpoint, responseCallback, headers) {
|
||||
return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, 0, headers);
|
||||
};
|
||||
|
||||
/**
|
||||
* This method invokes return initiateXMLHttpRequest for get calls.
|
||||
* @param endpoint Backend REST API url.
|
||||
* @param responseCallback a function to be called with response retrieved.
|
||||
*/
|
||||
publicXMLHTTPInvokers["get"] = function (endpoint, responseCallback, headers) {
|
||||
var requestPayload = null;
|
||||
return privateMethods.initiateXMLHTTPRequest(constants["HTTP_GET"], requestPayload, endpoint, responseCallback,
|
||||
headers);
|
||||
};
|
||||
|
||||
/**
|
||||
* This method invokes return initiateXMLHttpRequest for post calls.
|
||||
* @param endpoint Backend REST API url.
|
||||
* @param requestPayload payload/data if exists which is needed to be send.
|
||||
* @param responseCallback a function to be called with response retrieved.
|
||||
*/
|
||||
publicXMLHTTPInvokers["post"] = function (endpoint, requestPayload, responseCallback, headers) {
|
||||
return privateMethods.initiateXMLHTTPRequest(constants["HTTP_POST"], requestPayload, endpoint, responseCallback,
|
||||
headers);
|
||||
};
|
||||
|
||||
/**
|
||||
* This method invokes return initiateXMLHttpRequest for put calls.
|
||||
* @param endpoint Backend REST API url.
|
||||
* @param requestPayload payload/data if exists which is needed to be send.
|
||||
* @param responseCallback a function to be called with response retrieved.
|
||||
*/
|
||||
publicXMLHTTPInvokers["put"] = function (endpoint, requestPayload, responseCallback, headers) {
|
||||
return privateMethods.initiateXMLHTTPRequest(constants["HTTP_PUT"], requestPayload, endpoint, responseCallback,
|
||||
headers);
|
||||
};
|
||||
|
||||
/**
|
||||
* This method invokes return initiateXMLHttpRequest for delete calls.
|
||||
* @param endpoint Backend REST API url.
|
||||
* @param responseCallback a function to be called with response retrieved.
|
||||
*/
|
||||
publicXMLHTTPInvokers["delete"] = function (endpoint, responseCallback, headers) {
|
||||
var requestPayload = null;
|
||||
return privateMethods.initiateXMLHTTPRequest(constants["HTTP_DELETE"], requestPayload, endpoint,
|
||||
responseCallback, headers);
|
||||
};
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------------------
|
||||
* Start of WS-REQUEST based Interceptor implementations
|
||||
* ---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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");
|
||||
//noinspection JSUnresolvedFunction
|
||||
var wsRequest = new ws.WSRequest();
|
||||
var options = [];
|
||||
if (devicemgtProps["isOAuthEnabled"]) {
|
||||
var adminUsername = devicemgtProps["adminUser"];
|
||||
var accessToken = tokenHandler.getJwtToken(adminUsername);
|
||||
var decoded = tokenHandler.encode(accessToken);
|
||||
if (accessToken) {
|
||||
var authenticationHeaderName = String(constants["AUTHORIZATION_HEADER"]);
|
||||
var authenticationHeaderValue = String(constants["BEARER_PREFIX"] + decoded);
|
||||
var headers = [];
|
||||
var oAuthAuthenticationData = {};
|
||||
oAuthAuthenticationData.name = authenticationHeaderName;
|
||||
oAuthAuthenticationData.value = authenticationHeaderValue;
|
||||
headers.push(oAuthAuthenticationData);
|
||||
options.HTTPHeaders = headers;
|
||||
} else {
|
||||
response.sendRedirect(devicemgtProps["appContext"] + "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 initiateWSRequest for soap calls.
|
||||
* @param action describes particular soap action.
|
||||
* @param requestPayload SOAP request payload which is needed to be send.
|
||||
* @param endpoint service end point to be triggered.
|
||||
* @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, requestPayload, endpoint,
|
||||
successCallback, errorCallback, soapVersion) {
|
||||
return privateMethods.initiateWSRequest(action, endpoint, successCallback,
|
||||
errorCallback, soapVersion, requestPayload);
|
||||
};
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------------------
|
||||
* Start of HTTP-CLIENT-REQUEST based Interceptor implementations
|
||||
* ---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param headers a list of name value pairs for additional http headers.
|
||||
*/
|
||||
privateMethods["initiateHTTPClientRequest"] =
|
||||
function (method, url, successCallback, errorCallback, payload, headers) {
|
||||
//noinspection JSUnresolvedVariable
|
||||
var HttpClient = Packages.org.apache.commons.httpclient.HttpClient;
|
||||
var httpMethodObject;
|
||||
switch (method) {
|
||||
case constants["HTTP_GET"]:
|
||||
//noinspection JSUnresolvedVariable
|
||||
var GetMethod = Packages.org.apache.commons.httpclient.methods.GetMethod;
|
||||
httpMethodObject = new GetMethod(url);
|
||||
break;
|
||||
case constants["HTTP_POST"]:
|
||||
//noinspection JSUnresolvedVariable
|
||||
var PostMethod = Packages.org.apache.commons.httpclient.methods.PostMethod;
|
||||
httpMethodObject = new PostMethod(url);
|
||||
break;
|
||||
case constants["HTTP_PUT"]:
|
||||
//noinspection JSUnresolvedVariable
|
||||
var PutMethod = Packages.org.apache.commons.httpclient.methods.PutMethod;
|
||||
httpMethodObject = new PutMethod(url);
|
||||
break;
|
||||
case constants["HTTP_DELETE"]:
|
||||
//noinspection JSUnresolvedVariable
|
||||
var DeleteMethod = Packages.org.apache.commons.httpclient.methods.DeleteMethod;
|
||||
httpMethodObject = new DeleteMethod(url);
|
||||
break;
|
||||
default:
|
||||
//noinspection JSUnresolvedFunction
|
||||
throw new IllegalArgumentException("Invalid HTTP request method: " + method);
|
||||
}
|
||||
|
||||
//noinspection JSUnresolvedVariable
|
||||
var Header = Packages.org.apache.commons.httpclient.Header;
|
||||
var contentTypeFound = false;
|
||||
var acceptTypeFound = false;
|
||||
var acceptTypeValue = constants["APPLICATION_JSON"];
|
||||
for (var i in headers) {
|
||||
var header = new Header();
|
||||
header.setName(headers[i].name);
|
||||
header.setValue(headers[i].value);
|
||||
httpMethodObject.addRequestHeader(header);
|
||||
|
||||
if(constants["CONTENT_TYPE_IDENTIFIER"] == headers[i].name){
|
||||
contentTypeFound = true;
|
||||
}
|
||||
if(constants["ACCEPT_IDENTIFIER"] == headers[i].name){
|
||||
acceptTypeFound = true;
|
||||
acceptTypeValue = headers[i].value;
|
||||
}
|
||||
}
|
||||
|
||||
var header = new Header();
|
||||
if(!contentTypeFound){
|
||||
header.setName(constants["CONTENT_TYPE_IDENTIFIER"]);
|
||||
header.setValue(constants["APPLICATION_JSON"]);
|
||||
//noinspection JSUnresolvedFunction
|
||||
httpMethodObject.addRequestHeader(header);
|
||||
}
|
||||
|
||||
if(!acceptTypeFound) {
|
||||
header = new Header();
|
||||
header.setName(constants["ACCEPT_IDENTIFIER"]);
|
||||
header.setValue(constants["APPLICATION_JSON"]);
|
||||
//noinspection JSUnresolvedFunction
|
||||
httpMethodObject.addRequestHeader(header);
|
||||
}
|
||||
|
||||
if (devicemgtProps["isOAuthEnabled"]) {
|
||||
var accessToken = privateMethods.getAccessToken();
|
||||
if (accessToken) {
|
||||
header = new Header();
|
||||
header.setName(constants["AUTHORIZATION_HEADER"]);
|
||||
header.setValue(constants["BEARER_PREFIX"] + accessToken);
|
||||
//noinspection JSUnresolvedFunction
|
||||
httpMethodObject.addRequestHeader(header);
|
||||
} else {
|
||||
response.sendRedirect(devicemgtProps["appContext"] + "login");
|
||||
}
|
||||
}
|
||||
//noinspection JSUnresolvedFunction
|
||||
if (payload != null) {
|
||||
var StringRequestEntity = Packages.org.apache.commons.httpclient.methods.StringRequestEntity;
|
||||
var stringRequestEntity = new StringRequestEntity(stringify(payload));
|
||||
//noinspection JSUnresolvedFunction
|
||||
httpMethodObject.setRequestEntity(stringRequestEntity);
|
||||
}
|
||||
var client = new HttpClient();
|
||||
try {
|
||||
//noinspection JSUnresolvedFunction
|
||||
client.executeMethod(httpMethodObject);
|
||||
//noinspection JSUnresolvedFunction
|
||||
var status = httpMethodObject.getStatusCode();
|
||||
if (status >= 200 && status < 300) {
|
||||
if (constants["STREAMING_FILES_ACCEPT_HEADERS"].indexOf(acceptTypeValue) > -1) {
|
||||
return successCallback(httpMethodObject.getResponseBodyAsStream(),
|
||||
httpMethodObject.getResponseHeaders());
|
||||
} else {
|
||||
return successCallback(httpMethodObject.getResponseBodyAsString(),
|
||||
httpMethodObject.getResponseHeaders());
|
||||
}
|
||||
} else {
|
||||
return errorCallback(httpMethodObject.getResponseBodyAsString(),
|
||||
httpMethodObject.getResponseHeaders());
|
||||
}
|
||||
} catch (e) {
|
||||
return errorCallback(response);
|
||||
} finally {
|
||||
//noinspection JSUnresolvedFunction
|
||||
if (method != constants["HTTP_GET"]) {
|
||||
method.releaseConnection();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param headers a list of name value pairs for additional http headers.
|
||||
*/
|
||||
publicHTTPClientInvokers["get"] = function (url, successCallback, errorCallback, headers) {
|
||||
var requestPayload = null;
|
||||
return privateMethods.initiateHTTPClientRequest(constants["HTTP_GET"], url, successCallback, errorCallback,
|
||||
requestPayload, headers);
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param headers a list of name value pairs for additional http headers.
|
||||
*/
|
||||
publicHTTPClientInvokers["post"] = function (url, payload, successCallback, errorCallback, headers) {
|
||||
return privateMethods.initiateHTTPClientRequest(constants["HTTP_POST"], url, successCallback, errorCallback,
|
||||
payload, headers);
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param headers a list of name value pairs for additional http headers.
|
||||
*/
|
||||
publicHTTPClientInvokers["put"] = function (url, payload, successCallback, errorCallback, headers) {
|
||||
return privateMethods.initiateHTTPClientRequest(constants["HTTP_PUT"], url, successCallback, errorCallback,
|
||||
payload, headers);
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param headers a list of name value pairs for additional http headers.
|
||||
*/
|
||||
publicHTTPClientInvokers["delete"] = function (url, successCallback, errorCallback, headers) {
|
||||
var requestPayload = null;
|
||||
return privateMethods.initiateHTTPClientRequest(constants["HTTP_DELETE"], url, successCallback, errorCallback,
|
||||
requestPayload, headers);
|
||||
};
|
||||
|
||||
var publicMethods = {};
|
||||
publicMethods.XMLHttp = publicXMLHTTPInvokers;
|
||||
publicMethods.WS = publicWSInvokers;
|
||||
publicMethods.HttpClient = publicHTTPClientInvokers;
|
||||
|
||||
return publicMethods;
|
||||
}();
|
||||
@ -1,396 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 constants = require('/app/modules/constants.js');
|
||||
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var log = new Log("/app/modules/utility.js");
|
||||
var JavaClass = Packages.java.lang.Class;
|
||||
var PrivilegedCarbonContext = Packages.org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
var server = require("carbon")["server"];
|
||||
|
||||
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.getDeviceManagementService = function () {
|
||||
return getOsgiService('io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService');
|
||||
};
|
||||
|
||||
publicMethods.getAPIManagementProviderService = function () {
|
||||
return getOsgiService('io.entgra.device.mgt.core.apimgt.application.extension.APIManagementProviderService');
|
||||
};
|
||||
|
||||
publicMethods.getUserManagementService = function () {
|
||||
return getOsgiService("org.wso2.carbon.device.mgt.user.core.UserManager");
|
||||
};
|
||||
|
||||
publicMethods.getPolicyManagementService = function () {
|
||||
return getOsgiService("io.entgra.device.mgt.core.policy.mgt.core.PolicyManagerService");
|
||||
};
|
||||
|
||||
publicMethods.getDeviceTypeConfig = function (deviceType) {
|
||||
var unitName = publicMethods.getTenantedDeviceUnitName(deviceType, "type-view");
|
||||
if (!unitName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (deviceType in deviceTypeConfigMap) {
|
||||
return deviceTypeConfigMap[deviceType];
|
||||
}
|
||||
var deviceTypeConfig;
|
||||
var deviceTypeConfigFile = new File("/app/units/" + unitName + "/private/config.json");
|
||||
if (deviceTypeConfigFile.isExists()) {
|
||||
try {
|
||||
deviceTypeConfigFile.open("r");
|
||||
var config = deviceTypeConfigFile.readAll();
|
||||
config = config.replace("%https.ip%", server.address("https"));
|
||||
config = config.replace("%http.ip%", server.address("http"));
|
||||
deviceTypeConfig = parse(config);
|
||||
} 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 unitName = publicMethods.getTenantedDeviceUnitName(deviceType, "type-view");
|
||||
var iconPath = "/app/units/" + unitName + "/public/images/operations/" + operation + ".png";
|
||||
var icon = new File(iconPath);
|
||||
if (icon.isExists()) {
|
||||
return devicemgtProps["appContext"] + "public/" + unitName + "/images/operations/" + operation + ".png";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
publicMethods.getDeviceThumb = function (deviceType) {
|
||||
var unitName = publicMethods.getTenantedDeviceUnitName(deviceType, "type-view");
|
||||
if (!unitName) {
|
||||
unitName = "cdmf.unit.default.device.type.type-view";
|
||||
}
|
||||
var iconPath = "/app/units/" + unitName + "/public/images/thumb.png";
|
||||
var icon = new File(iconPath);
|
||||
if (icon.isExists()) {
|
||||
return devicemgtProps["appContext"] + "public/" + unitName + "/images/thumb.png";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
publicMethods.getTenantedDeviceUnitName = function (deviceType, unitPostfix) {
|
||||
var user = session.get(constants.USER_SESSION_KEY);
|
||||
if (!user) {
|
||||
log.error("User object was not found in the session");
|
||||
throw constants.ERRORS.USER_NOT_FOUND;
|
||||
}
|
||||
var unitName = user.domain + ".cdmf.unit.device.type." + deviceType + "." + unitPostfix;
|
||||
if (new File("/app/units/" + unitName).isExists()) {
|
||||
return unitName;
|
||||
}
|
||||
unitName = "cdmf.unit.device.type." + deviceType + "." + unitPostfix;
|
||||
if (new File("/app/units/" + unitName).isExists()) {
|
||||
return unitName;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
publicMethods.getDeviceTypesScopesList = function () {
|
||||
var dirs = new File("/app/units/").listFiles();
|
||||
var scopesList = [];
|
||||
for (var i = 0; i < dirs.length; i++) {
|
||||
var unitName = dirs[i].getName();
|
||||
if (unitName.match(/^cdmf\.unit\.device\.type\..*\.type-view$/g)) {
|
||||
var deviceTypeConfigFile = new File("/app/units/" + unitName + "/private/config.json");
|
||||
if (deviceTypeConfigFile.isExists()) {
|
||||
try {
|
||||
deviceTypeConfigFile.open("r");
|
||||
var config = deviceTypeConfigFile.readAll();
|
||||
config = config.replace("%https.ip%", server.address("https"));
|
||||
config = config.replace("%http.ip%", server.address("http"));
|
||||
var deviceTypeConfig = parse(config);
|
||||
if (deviceTypeConfig.deviceType && deviceTypeConfig.deviceType.scopes) {
|
||||
scopesList = scopesList.concat(deviceTypeConfig.deviceType.scopes);
|
||||
}
|
||||
} catch (err) {
|
||||
log.error("Error while reading device config file for `" + deviceType + "`: " + err);
|
||||
} finally {
|
||||
deviceTypeConfigFile.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return scopesList;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Escapes special characters such as <,>,',",...etc
|
||||
* This will prevent XSS attacks upon JSON.
|
||||
* @param text
|
||||
* @returns {*}
|
||||
*/
|
||||
publicMethods.encodeJson = function (text) {
|
||||
if (text) {
|
||||
return text
|
||||
.replace(/\\u003c/g, "<")
|
||||
.replace(/</g, "<")
|
||||
.replace(/\\u003e/g, ">")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/\\u0027/g, "'")
|
||||
.replace(/'/g, "'")
|
||||
.replace(/\\"/g, """)
|
||||
.replace(/\\u0022/g, """);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
publicMethods.md5 = function (s) {
|
||||
function L(k, d) {
|
||||
return (k << d) | (k >>> (32 - d))
|
||||
}
|
||||
|
||||
function K(G, k) {
|
||||
var I, d, F, H, x;
|
||||
F = (G & 2147483648);
|
||||
H = (k & 2147483648);
|
||||
I = (G & 1073741824);
|
||||
d = (k & 1073741824);
|
||||
x = (G & 1073741823) + (k & 1073741823);
|
||||
if (I & d) {
|
||||
return (x ^ 2147483648 ^ F ^ H)
|
||||
}
|
||||
if (I | d) {
|
||||
if (x & 1073741824) {
|
||||
return (x ^ 3221225472 ^ F ^ H)
|
||||
} else {
|
||||
return (x ^ 1073741824 ^ F ^ H)
|
||||
}
|
||||
} else {
|
||||
return (x ^ F ^ H)
|
||||
}
|
||||
}
|
||||
|
||||
function r(d, F, k) {
|
||||
return (d & F) | ((~d) & k)
|
||||
}
|
||||
|
||||
function q(d, F, k) {
|
||||
return (d & k) | (F & (~k))
|
||||
}
|
||||
|
||||
function p(d, F, k) {
|
||||
return (d ^ F ^ k)
|
||||
}
|
||||
|
||||
function n(d, F, k) {
|
||||
return (F ^ (d | (~k)))
|
||||
}
|
||||
|
||||
function u(G, F, aa, Z, k, H, I) {
|
||||
G = K(G, K(K(r(F, aa, Z), k), I));
|
||||
return K(L(G, H), F)
|
||||
}
|
||||
|
||||
function f(G, F, aa, Z, k, H, I) {
|
||||
G = K(G, K(K(q(F, aa, Z), k), I));
|
||||
return K(L(G, H), F)
|
||||
}
|
||||
|
||||
function D(G, F, aa, Z, k, H, I) {
|
||||
G = K(G, K(K(p(F, aa, Z), k), I));
|
||||
return K(L(G, H), F)
|
||||
}
|
||||
|
||||
function t(G, F, aa, Z, k, H, I) {
|
||||
G = K(G, K(K(n(F, aa, Z), k), I));
|
||||
return K(L(G, H), F)
|
||||
}
|
||||
|
||||
function e(G) {
|
||||
var Z;
|
||||
var F = G.length;
|
||||
var x = F + 8;
|
||||
var k = (x - (x % 64)) / 64;
|
||||
var I = (k + 1) * 16;
|
||||
var aa = Array(I - 1);
|
||||
var d = 0;
|
||||
var H = 0;
|
||||
while (H < F) {
|
||||
Z = (H - (H % 4)) / 4;
|
||||
d = (H % 4) * 8;
|
||||
aa[Z] = (aa[Z] | (G.charCodeAt(H) << d));
|
||||
H++
|
||||
}
|
||||
Z = (H - (H % 4)) / 4;
|
||||
d = (H % 4) * 8;
|
||||
aa[Z] = aa[Z] | (128 << d);
|
||||
aa[I - 2] = F << 3;
|
||||
aa[I - 1] = F >>> 29;
|
||||
return aa
|
||||
}
|
||||
|
||||
function B(x) {
|
||||
var k = "", F = "", G, d;
|
||||
for (d = 0; d <= 3; d++) {
|
||||
G = (x >>> (d * 8)) & 255;
|
||||
F = "0" + G.toString(16);
|
||||
k = k + F.substr(F.length - 2, 2)
|
||||
}
|
||||
return k
|
||||
}
|
||||
|
||||
function J(k) {
|
||||
k = k.replace(/rn/g, "n");
|
||||
var d = "";
|
||||
for (var F = 0; F < k.length; F++) {
|
||||
var x = k.charCodeAt(F);
|
||||
if (x < 128) {
|
||||
d += String.fromCharCode(x)
|
||||
} else {
|
||||
if ((x > 127) && (x < 2048)) {
|
||||
d += String.fromCharCode((x >> 6) | 192);
|
||||
d += String.fromCharCode((x & 63) | 128)
|
||||
} else {
|
||||
d += String.fromCharCode((x >> 12) | 224);
|
||||
d += String.fromCharCode(((x >> 6) & 63) | 128);
|
||||
d += String.fromCharCode((x & 63) | 128)
|
||||
}
|
||||
}
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
var C = Array();
|
||||
var P, h, E, v, g, Y, X, W, V;
|
||||
var S = 7, Q = 12, N = 17, M = 22;
|
||||
var A = 5, z = 9, y = 14, w = 20;
|
||||
var o = 4, m = 11, l = 16, j = 23;
|
||||
var U = 6, T = 10, R = 15, O = 21;
|
||||
s = J(s);
|
||||
C = e(s);
|
||||
Y = 1732584193;
|
||||
X = 4023233417;
|
||||
W = 2562383102;
|
||||
V = 271733878;
|
||||
for (P = 0; P < C.length; P += 16) {
|
||||
h = Y;
|
||||
E = X;
|
||||
v = W;
|
||||
g = V;
|
||||
Y = u(Y, X, W, V, C[P + 0], S, 3614090360);
|
||||
V = u(V, Y, X, W, C[P + 1], Q, 3905402710);
|
||||
W = u(W, V, Y, X, C[P + 2], N, 606105819);
|
||||
X = u(X, W, V, Y, C[P + 3], M, 3250441966);
|
||||
Y = u(Y, X, W, V, C[P + 4], S, 4118548399);
|
||||
V = u(V, Y, X, W, C[P + 5], Q, 1200080426);
|
||||
W = u(W, V, Y, X, C[P + 6], N, 2821735955);
|
||||
X = u(X, W, V, Y, C[P + 7], M, 4249261313);
|
||||
Y = u(Y, X, W, V, C[P + 8], S, 1770035416);
|
||||
V = u(V, Y, X, W, C[P + 9], Q, 2336552879);
|
||||
W = u(W, V, Y, X, C[P + 10], N, 4294925233);
|
||||
X = u(X, W, V, Y, C[P + 11], M, 2304563134);
|
||||
Y = u(Y, X, W, V, C[P + 12], S, 1804603682);
|
||||
V = u(V, Y, X, W, C[P + 13], Q, 4254626195);
|
||||
W = u(W, V, Y, X, C[P + 14], N, 2792965006);
|
||||
X = u(X, W, V, Y, C[P + 15], M, 1236535329);
|
||||
Y = f(Y, X, W, V, C[P + 1], A, 4129170786);
|
||||
V = f(V, Y, X, W, C[P + 6], z, 3225465664);
|
||||
W = f(W, V, Y, X, C[P + 11], y, 643717713);
|
||||
X = f(X, W, V, Y, C[P + 0], w, 3921069994);
|
||||
Y = f(Y, X, W, V, C[P + 5], A, 3593408605);
|
||||
V = f(V, Y, X, W, C[P + 10], z, 38016083);
|
||||
W = f(W, V, Y, X, C[P + 15], y, 3634488961);
|
||||
X = f(X, W, V, Y, C[P + 4], w, 3889429448);
|
||||
Y = f(Y, X, W, V, C[P + 9], A, 568446438);
|
||||
V = f(V, Y, X, W, C[P + 14], z, 3275163606);
|
||||
W = f(W, V, Y, X, C[P + 3], y, 4107603335);
|
||||
X = f(X, W, V, Y, C[P + 8], w, 1163531501);
|
||||
Y = f(Y, X, W, V, C[P + 13], A, 2850285829);
|
||||
V = f(V, Y, X, W, C[P + 2], z, 4243563512);
|
||||
W = f(W, V, Y, X, C[P + 7], y, 1735328473);
|
||||
X = f(X, W, V, Y, C[P + 12], w, 2368359562);
|
||||
Y = D(Y, X, W, V, C[P + 5], o, 4294588738);
|
||||
V = D(V, Y, X, W, C[P + 8], m, 2272392833);
|
||||
W = D(W, V, Y, X, C[P + 11], l, 1839030562);
|
||||
X = D(X, W, V, Y, C[P + 14], j, 4259657740);
|
||||
Y = D(Y, X, W, V, C[P + 1], o, 2763975236);
|
||||
V = D(V, Y, X, W, C[P + 4], m, 1272893353);
|
||||
W = D(W, V, Y, X, C[P + 7], l, 4139469664);
|
||||
X = D(X, W, V, Y, C[P + 10], j, 3200236656);
|
||||
Y = D(Y, X, W, V, C[P + 13], o, 681279174);
|
||||
V = D(V, Y, X, W, C[P + 0], m, 3936430074);
|
||||
W = D(W, V, Y, X, C[P + 3], l, 3572445317);
|
||||
X = D(X, W, V, Y, C[P + 6], j, 76029189);
|
||||
Y = D(Y, X, W, V, C[P + 9], o, 3654602809);
|
||||
V = D(V, Y, X, W, C[P + 12], m, 3873151461);
|
||||
W = D(W, V, Y, X, C[P + 15], l, 530742520);
|
||||
X = D(X, W, V, Y, C[P + 2], j, 3299628645);
|
||||
Y = t(Y, X, W, V, C[P + 0], U, 4096336452);
|
||||
V = t(V, Y, X, W, C[P + 7], T, 1126891415);
|
||||
W = t(W, V, Y, X, C[P + 14], R, 2878612391);
|
||||
X = t(X, W, V, Y, C[P + 5], O, 4237533241);
|
||||
Y = t(Y, X, W, V, C[P + 12], U, 1700485571);
|
||||
V = t(V, Y, X, W, C[P + 3], T, 2399980690);
|
||||
W = t(W, V, Y, X, C[P + 10], R, 4293915773);
|
||||
X = t(X, W, V, Y, C[P + 1], O, 2240044497);
|
||||
Y = t(Y, X, W, V, C[P + 8], U, 1873313359);
|
||||
V = t(V, Y, X, W, C[P + 15], T, 4264355552);
|
||||
W = t(W, V, Y, X, C[P + 6], R, 2734768916);
|
||||
X = t(X, W, V, Y, C[P + 13], O, 1309151649);
|
||||
Y = t(Y, X, W, V, C[P + 4], U, 4149444226);
|
||||
V = t(V, Y, X, W, C[P + 11], T, 3174756917);
|
||||
W = t(W, V, Y, X, C[P + 2], R, 718787259);
|
||||
X = t(X, W, V, Y, C[P + 9], O, 3951481745);
|
||||
Y = K(Y, h);
|
||||
X = K(X, E);
|
||||
W = K(W, v);
|
||||
V = K(V, g)
|
||||
}
|
||||
var i = B(Y) + B(X) + B(W) + B(V);
|
||||
return i.toLowerCase()
|
||||
};
|
||||
|
||||
return publicMethods;
|
||||
}();
|
||||
@ -1,111 +0,0 @@
|
||||
{{!
|
||||
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
|
||||
WSO2 Inc. licenses this file to you under the Apache License,
|
||||
Version 2.0 (the "License"); you may not use this file except
|
||||
in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
}}
|
||||
{{unit "cdmf.unit.ui.title" pageTitle="Add Certificate"}}
|
||||
|
||||
{{#zone "breadcrumbs"}}
|
||||
<li>
|
||||
<a href="{{@app.context}}/">
|
||||
<i class="icon fw fw-home"></i>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{@app.context}}/certificates">
|
||||
Certificates
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{@app.context}}/certificates/add">
|
||||
Add
|
||||
</a>
|
||||
</li>
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "content"}}
|
||||
{{#if isAuthorized}}
|
||||
<!-- content/body -->
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<!-- content -->
|
||||
<div id="certificate-create-form" class="container col-centered wr-content">
|
||||
<div class="wr-form">
|
||||
<p class="page-sub-title">Add Certificate</p>
|
||||
<p>Please note that * sign represents required fields of data.</p>
|
||||
<hr/>
|
||||
<div class="row">
|
||||
<div class="col-lg-8">
|
||||
<div id="certificate-create-error-msg" class="alert alert-danger hidden" role="alert">
|
||||
<i class="icon fw fw-error"></i><span></span>
|
||||
</div>
|
||||
|
||||
<label class="wr-input-label ">
|
||||
Serial Number *
|
||||
</label>
|
||||
<br>
|
||||
<div id="serialNoInputField" class="form-group wr-input-control">
|
||||
<input type="text" id="serialNo" class="form-control"/>
|
||||
</div>
|
||||
<label class="wr-input-label">Certificate *</label>
|
||||
<div id="certificateField" class="form-group wr-input-control">
|
||||
<input type="file" id="certificate" class="form-control"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<div class="row">
|
||||
<div class="col-lg-8">
|
||||
<button id="add-certificate-btn" class="wr-btn">Add Certificate</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="certificate-created-msg" class="container col-centered wr-content hidden">
|
||||
<div class="wr-form">
|
||||
<p class="page-sub-title">Certificate was added successfully.</p>
|
||||
<br>
|
||||
<br>Please click <b>"Add Another Certificate"</b>, if you wish to add another certificate or
|
||||
click
|
||||
<b>"View Certificate List"</b> to complete the process and go back to the certificate list.
|
||||
<hr/>
|
||||
<button class="wr-btn" onclick="window.location.href='{{@app.context}}/certificates'">View Certificate List
|
||||
</button>
|
||||
<a href="{{@app.context}}/certificates/add" class="cu-btn-inner">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-add fw-stack-1x"></i>
|
||||
</span>
|
||||
Add Another Certificate
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /content -->
|
||||
</div>
|
||||
</div>
|
||||
<!-- /content/body -->
|
||||
{{else}}
|
||||
<h1 class="page-sub-title">
|
||||
Permission Denied
|
||||
</h1>
|
||||
<br>
|
||||
You not authorized to enter Certificate Management Section.
|
||||
<br>
|
||||
{{/if}}
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "bottomJs"}}
|
||||
{{js "/js/certificate-create.js"}}
|
||||
{{/zone}}
|
||||
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the dynamic state to be populated by add-user page.
|
||||
*
|
||||
* @param viewModel Object that gets updated with the dynamic state of this page to be presented
|
||||
* @returns {*} A viewModel object that returns the dynamic state of this page to be presented
|
||||
*/
|
||||
function onRequest(context) {
|
||||
// var log = new Log("units/user-create/create.js");
|
||||
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
|
||||
var mdmProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var viewModel = {};
|
||||
viewModel.isAuthorized = userModule.isAuthorized("/permission/admin/device-mgt/certificates/manage");
|
||||
var response = userModule.getRolesByUserStore();
|
||||
if (response["status"] == "success") {
|
||||
viewModel["roles"] = response["content"];
|
||||
}
|
||||
|
||||
viewModel["charLimit"] = mdmProps["userValidationConfig"]["usernameLength"];
|
||||
viewModel["usernameJSRegEx"] = mdmProps["userValidationConfig"]["usernameJSRegEx"];
|
||||
viewModel["usernameHelpText"] = mdmProps["userValidationConfig"]["usernameHelpMsg"];
|
||||
viewModel["usernameRegExViolationErrorMsg"] = mdmProps["userValidationConfig"]["usernameRegExViolationErrorMsg"];
|
||||
viewModel["firstnameJSRegEx"] = mdmProps["userValidationConfig"]["firstnameJSRegEx"];
|
||||
viewModel["firstnameRegExViolationErrorMsg"] = mdmProps["userValidationConfig"]["firstnameRegExViolationErrorMsg"];
|
||||
viewModel["lastnameJSRegEx"] = mdmProps["userValidationConfig"]["lastnameJSRegEx"];
|
||||
viewModel["lastnameRegExViolationErrorMsg"] = mdmProps["userValidationConfig"]["lastnameRegExViolationErrorMsg"];
|
||||
|
||||
return viewModel;
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"uri": "/certificates/add",
|
||||
"layout": "cdmf.layout.default"
|
||||
}
|
||||
@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 pemContent = "";
|
||||
var errorMsgWrapper = "#certificate-create-error-msg";
|
||||
var errorMsg = "#certificate-create-error-msg span";
|
||||
var validateInline = {};
|
||||
var clearInline = {};
|
||||
|
||||
var base_api_url = "/api/certificate-mgt/v1.0";
|
||||
|
||||
var enableInlineError = function (inputField, errorMsg, errorSign) {
|
||||
var fieldIdentifier = "#" + inputField;
|
||||
var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
|
||||
var errorSignIdentifier = "#" + inputField + " ." + errorSign;
|
||||
|
||||
if (inputField) {
|
||||
$(fieldIdentifier).addClass(" has-error has-feedback");
|
||||
}
|
||||
|
||||
if (errorMsg) {
|
||||
$(errorMsgIdentifier).removeClass(" hidden");
|
||||
}
|
||||
|
||||
if (errorSign) {
|
||||
$(errorSignIdentifier).removeClass(" hidden");
|
||||
}
|
||||
};
|
||||
|
||||
var disableInlineError = function (inputField, errorMsg, errorSign) {
|
||||
var fieldIdentifier = "#" + inputField;
|
||||
var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
|
||||
var errorSignIdentifier = "#" + inputField + " ." + errorSign;
|
||||
|
||||
if (inputField) {
|
||||
$(fieldIdentifier).removeClass(" has-error has-feedback");
|
||||
}
|
||||
|
||||
if (errorMsg) {
|
||||
$(errorMsgIdentifier).addClass(" hidden");
|
||||
}
|
||||
|
||||
if (errorSign) {
|
||||
$(errorSignIdentifier).addClass(" hidden");
|
||||
}
|
||||
};
|
||||
|
||||
function readSingleFile(evt) {
|
||||
var f = evt.target.files[0];
|
||||
if (f) {
|
||||
var r = new FileReader();
|
||||
r.onload = function (e) {
|
||||
var contents = e.target.result;
|
||||
if (f.type == "application/x-x509-ca-cert") {
|
||||
pemContent = contents;
|
||||
console.log(contents);
|
||||
console.log(pemContent);
|
||||
pemContent = pemContent.substring(28, pemContent.length - 27);
|
||||
console.log(pemContent);
|
||||
$(errorMsgWrapper).addClass("hidden");
|
||||
} else {
|
||||
$(errorMsg).text("Certificate must be a .pem file containing a valid certificate data.");
|
||||
$(errorMsgWrapper).removeClass("hidden");
|
||||
}
|
||||
}
|
||||
r.readAsText(f);
|
||||
} else {
|
||||
//inline error
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
pemContent = "";
|
||||
document.getElementById('certificate').addEventListener('change', readSingleFile, false);
|
||||
|
||||
/**
|
||||
* Following click function would execute
|
||||
* when a user clicks on "Add Certificate" button.
|
||||
*/
|
||||
$("button#add-certificate-btn").click(function () {
|
||||
var serialNoInput = $("input#serialNo");
|
||||
var serialNo = serialNoInput.val();
|
||||
if (!serialNo) {
|
||||
$(errorMsg).text("Serial Number is a required field. It cannot be empty.");
|
||||
$(errorMsgWrapper).removeClass("hidden");
|
||||
} else if (!pemContent) {
|
||||
$(errorMsg).text(" .pem file must contains certificate information.");
|
||||
$(errorMsgWrapper).removeClass("hidden");
|
||||
} else {
|
||||
var addCertificateFormData = {};
|
||||
addCertificateFormData.serial = serialNo;
|
||||
addCertificateFormData.pem = pemContent;
|
||||
var certificateList = [];
|
||||
certificateList.push(addCertificateFormData);
|
||||
|
||||
var serviceUrl = base_api_url + "/admin/certificates";
|
||||
invokerUtil.post(
|
||||
serviceUrl,
|
||||
certificateList,
|
||||
function (data) {
|
||||
// Refreshing with success message
|
||||
$("#certificate-create-form").addClass("hidden");
|
||||
$("#certificate-created-msg").removeClass("hidden");
|
||||
}, function (data) {
|
||||
if (data["status"] == 500) {
|
||||
$(errorMsg).text("An unexpected error occurred at backend server. Please try again later.");
|
||||
} else {
|
||||
$(errorMsg).text(data);
|
||||
}
|
||||
$(errorMsgWrapper).removeClass("hidden");
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -1,122 +0,0 @@
|
||||
{{!
|
||||
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
|
||||
WSO2 Inc. licenses this file to you under the Apache License,
|
||||
Version 2.0 (the "License"); you may not use this file except
|
||||
in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
}}
|
||||
{{unit "cdmf.unit.ui.title" pageTitle="Add Certificate"}}
|
||||
{{unit "cdmf.unit.ui.modal"}}
|
||||
|
||||
{{#zone "breadcrumbs"}}
|
||||
<li>
|
||||
<a href="{{@app.context}}/">
|
||||
<i class="icon fw fw-home"></i>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{@app.context}}/certificates">
|
||||
Certificate
|
||||
</a>
|
||||
</li>
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "navbarActions"}}
|
||||
{{#if removePermitted}}
|
||||
<li>
|
||||
<a href="{{@app.context}}/certificates/add">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-document fw-stack-1x"></i>
|
||||
</span>
|
||||
Add Certificate
|
||||
</a>
|
||||
</li>
|
||||
{{/if}}
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "content"}}
|
||||
{{unit "cdmf.unit.data-tables-extended"}}
|
||||
|
||||
<!-- content -->
|
||||
<div id="loading-content" class="col-centered">
|
||||
{{#if removePermitted}}
|
||||
<input type="hidden" id="can-remove" value="true"/>
|
||||
{{/if}}
|
||||
{{#if viewPermitted}}
|
||||
<input type="hidden" id="can-view" value="true"/>
|
||||
{{/if}}
|
||||
<i class="fw fw-settings fw-spin fw-2x"></i>
|
||||
Loading Certificates . . .
|
||||
<br>
|
||||
</div>
|
||||
|
||||
<div id="certificate-listing-status" class="raw hidden">
|
||||
<ul style="list-style-type: none;">
|
||||
<li class="message message-info" >
|
||||
<h4>
|
||||
<i class="icon fw fw-info"></i>
|
||||
<a id="certificate-listing-status-msg"></a>
|
||||
</h4>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div id="certificate-table" class="hidden" data-user={{adminUser}}>
|
||||
<table class="table table-striped table-hover list-table display responsive nowrap data-table grid-view"
|
||||
id="certificate-grid">
|
||||
<thead>
|
||||
<tr class="sort-row">
|
||||
<th class="no-sort"></th>
|
||||
<th>By Serial Number</th>
|
||||
<th class="no-sort"></th>
|
||||
<th class="no-sort"></th>
|
||||
</tr>
|
||||
<tr class="filter-row filter-box">
|
||||
<th colspan="3">
|
||||
<label class="wr-input-label" for="search-by-certificate">
|
||||
By Serial Number
|
||||
</label>
|
||||
<input id="search-by-certificate" type="text" class="form-control"
|
||||
placeholder="Search By Serial Number">
|
||||
</th>
|
||||
<th style="vertical-align:bottom;">
|
||||
<button id="search-btn" class="wr-btn">
|
||||
Search
|
||||
</button>
|
||||
</th>
|
||||
</tr>
|
||||
|
||||
</thead>
|
||||
<tbody id="ast-container">
|
||||
|
||||
<br class="c-both"/>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<br class="c-both"/>
|
||||
<div id="content-filter-types" style="display: none">
|
||||
<div class="sort-title">Sort By</div>
|
||||
<div class="sort-options">
|
||||
<a href="#">By Serial Number</a>
|
||||
</div>
|
||||
</div>
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "bottomJs"}}
|
||||
<script id="certificate-listing" data-current-user="{{@user.username}}"
|
||||
src="{{@page.publicUri}}/templates/certificate-listing.hbs"
|
||||
type="text/x-handlebars-template"></script>
|
||||
|
||||
{{js "/js/certificate-listing.js"}}
|
||||
{{/zone}}
|
||||
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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/business-controllers/user.js")["userModule"];
|
||||
var mdmProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var viewModel = {};
|
||||
|
||||
|
||||
if (userModule.isAuthorized("/permission/admin/device-mgt/certificates/manage")) {
|
||||
viewModel["removePermitted"] = true;
|
||||
}
|
||||
if (userModule.isAuthorized("/permission/admin/device-mgt/certificates/view")) {
|
||||
viewModel["viewPermitted"] = true;
|
||||
}
|
||||
|
||||
viewModel.adminUser = mdmProps.adminUser;
|
||||
return viewModel;
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"uri": "/certificates",
|
||||
"layout": "cdmf.layout.default"
|
||||
}
|
||||
@ -1,201 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Sorting function of certificates
|
||||
* listed on Certificate Management page in WSO2 MDM Console.
|
||||
*/
|
||||
$(function () {
|
||||
var sortableElem = '.wr-sortable';
|
||||
$(sortableElem).sortable({
|
||||
beforeStop: function () {
|
||||
var sortedIDs = $(this).sortable('toArray');
|
||||
}
|
||||
});
|
||||
$(sortableElem).disableSelection();
|
||||
});
|
||||
|
||||
var modalPopup = ".modal";
|
||||
var modalPopupContainer = modalPopup + " .modal-content";
|
||||
var modalPopupContent = modalPopup + " .modal-content";
|
||||
var body = "body";
|
||||
var isInit = true;
|
||||
|
||||
var base_api_url = "/api/certificate-mgt/v1.0";
|
||||
|
||||
$(".icon .text").res_text(0.2);
|
||||
|
||||
/*
|
||||
* set popup maximum height function.
|
||||
*/
|
||||
function setPopupMaxHeight() {
|
||||
$(modalPopupContent).css('max-height', ($(body).height() - ($(body).height() / 100 * 30)));
|
||||
$(modalPopupContainer).css('margin-top', (-($(modalPopupContainer).height() / 2)));
|
||||
}
|
||||
|
||||
/*
|
||||
* show popup function.
|
||||
*/
|
||||
function showPopup() {
|
||||
$(modalPopup).modal('show');
|
||||
}
|
||||
|
||||
/*
|
||||
* hide popup function.
|
||||
*/
|
||||
function hidePopup() {
|
||||
$(modalPopupContent).html('');
|
||||
$(modalPopup).modal('hide');
|
||||
$('body').removeClass('modal-open').css('padding-right','0px');
|
||||
$('.modal-backdrop').remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* Following click function would execute
|
||||
* when a user clicks on "Remove" link
|
||||
* on Certificate Listing page in WSO2 MDM Console.
|
||||
*/
|
||||
function removeCertificate(serialNumber) {
|
||||
var serviceUrl = base_api_url + "/admin/certificates/" + serialNumber;
|
||||
modalDialog.header('Do you really want to remove this certificate ?');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="remove-certificate-yes-link" class="btn-operations">' +
|
||||
'Remove</a><a href="#" id="remove-certificate-cancel-link" class="btn-operations btn-default">Cancel</a>' +
|
||||
'</div>');
|
||||
modalDialog.show();
|
||||
|
||||
$("a#remove-certificate-yes-link").click(function () {
|
||||
invokerUtil.delete(
|
||||
serviceUrl,
|
||||
function () {
|
||||
$("#" + serialNumber).remove();
|
||||
var newCertificateListCount = $(".user-list > span").length;
|
||||
$("#certificate-listing-status-msg").text("Total number of Certificates found : " +
|
||||
newCertificateListCount);
|
||||
modalDialog.header('Done. Certificate was successfully removed.');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="remove-certificate-success-link" ' +
|
||||
'class="btn-operations">Ok</a></div>');
|
||||
$("a#remove-certificate-success-link").click(function () {
|
||||
modalDialog.hide();
|
||||
});
|
||||
},
|
||||
function () {
|
||||
modalDialog.header('An unexpected error occurred. Please try again later.');
|
||||
modalDialog.footer('<div class="buttons"><a href="#" id="remove-certificate-error-link" ' +
|
||||
'class="btn-operations">Ok</a></div>');
|
||||
modalDialog.showAsError();
|
||||
$("a#remove-certificate-error-link").click(function () {
|
||||
modalDialog.hide();
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$("a#remove-certificate-cancel-link").click(function () {
|
||||
modalDialog.hide();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Following on click function would execute
|
||||
* when a user type on the search field on certificate Listing page in
|
||||
* WSO2 MDM Console then click on the search button.
|
||||
*/
|
||||
$("#search-btn").click(function () {
|
||||
var searchQuery = $("#search-by-certificate").val();
|
||||
$("#ast-container").empty();
|
||||
loadCertificates(searchQuery);
|
||||
});
|
||||
|
||||
/**
|
||||
* Following function would execute
|
||||
* when a user clicks on the list item
|
||||
* initial mode and with out select mode.
|
||||
*/
|
||||
function InitiateViewOption() {
|
||||
if ($("#can-view").val()) {
|
||||
$(location).attr('href', $(this).data("url"));
|
||||
} else {
|
||||
modalDialog.header('Unauthorized action!');
|
||||
modalDialog.content('You do not have permission to view this certificate.');
|
||||
modalDialog.showAsAWarning();
|
||||
}
|
||||
}
|
||||
|
||||
function loadCertificates(searchParam) {
|
||||
$("#loading-content").show();
|
||||
var certificateListing = $("#certificate-listing");
|
||||
var certificateListingSrc = certificateListing.attr("src");
|
||||
$.template("certificate-listing", certificateListingSrc, function (template) {
|
||||
var serviceURL = base_api_url + "/admin/certificates";
|
||||
|
||||
if (searchParam != null && searchParam != undefined && searchParam.trim() != '') {
|
||||
serviceURL = base_api_url + "/admin/certificates?" + searchParam;
|
||||
}
|
||||
|
||||
var successCallback = function (data, textStatus, jqXHR) {
|
||||
if (jqXHR.status == 200 && data) {
|
||||
data = JSON.parse(data);
|
||||
|
||||
var viewModel = {};
|
||||
viewModel.certificates = data.certificates;
|
||||
|
||||
for (var i = 0; i < viewModel.certificates.length; i++) {
|
||||
viewModel.certificates[i].removePermitted = true;
|
||||
viewModel.certificates[i].viewPermitted = true;
|
||||
}
|
||||
|
||||
if (viewModel.certificates.length > 0) {
|
||||
$('#certificate-table').removeClass('hidden');
|
||||
$('#ast-container').removeClass('hidden');
|
||||
$('#certificate-listing-status-msg').text("");
|
||||
var content = template(viewModel);
|
||||
$("#ast-container").html(content);
|
||||
} else {
|
||||
$('#certificate-table').addClass('hidden');
|
||||
$('#certificate-listing-status-msg').text('No certificate is available to be displayed.');
|
||||
$('#certificate-listing-status').removeClass('hidden');
|
||||
}
|
||||
|
||||
$("#loading-content").hide();
|
||||
|
||||
if (isInit) {
|
||||
$('#certificate-grid').datatables_extended();
|
||||
isInit = false;
|
||||
}
|
||||
|
||||
$(".icon .text").res_text(0.2);
|
||||
}
|
||||
};
|
||||
invokerUtil.get(serviceURL,
|
||||
successCallback,
|
||||
function (message) {
|
||||
$('#ast-container').addClass('hidden');
|
||||
$('#certificate-listing-status-msg').
|
||||
text('Invalid search query. Try again with a valid search query');
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
loadCertificates();
|
||||
|
||||
$(".viewEnabledIcon").click(function () {
|
||||
InitiateViewOption();
|
||||
});
|
||||
});
|
||||
@ -1,30 +0,0 @@
|
||||
{{#each certificates}}
|
||||
|
||||
<tr data-type="selectable" id="{{serialNumber}}" data-username="{{serialNumber}}">
|
||||
<td class="remove-padding icon-only content-fill viewEnabledIcon" data-username="{{serialNumber}}">
|
||||
<div class="thumbnail icon">
|
||||
<i class="square-element text fw fw-document"></i>
|
||||
</div>
|
||||
</td>
|
||||
<td class="remove-padding-top" data-search="{{serialNumber}}" data-display="{{serialNumber}}"><i
|
||||
class="fw-mobile"></i> {{serialNumber}}</td>
|
||||
<td class="remove-padding-top" data-search="{{subject}}" data-display="{{subject}}"><i
|
||||
class="fw-policy"></i> {{subject}}</td>
|
||||
<td class="text-right content-fill text-left-on-grid-view no-wrap">
|
||||
{{#unequal adminUser serialNumber }}
|
||||
{{#if removePermitted}}
|
||||
<a href="#" data-username="{{serialNumber}}" data-userid="{{userid}}"
|
||||
data-click-event="remove-form" onclick="javascript:removeCertificate('{{serialNumber}}')"
|
||||
class="btn padding-reduce-on-grid-view remove-user-link">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-delete fw-stack-1x"></i>
|
||||
</span>
|
||||
<span class="hidden-xs hidden-on-grid-view">Remove</span>
|
||||
</a>
|
||||
{{/if}}
|
||||
{{/unequal}}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{{/each}}
|
||||
@ -1,172 +0,0 @@
|
||||
{{!
|
||||
Copyright (c) 2018, 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.
|
||||
}}
|
||||
{{#zone "title"}}{{! to override parent page title }}{{/zone}}
|
||||
{{unit "cdmf.unit.ui.title" pageTitle="Consent Page"}}
|
||||
|
||||
{{#zone "content"}}
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 col-sm-offset-2 col-md-offset-2 col-lg-offset-2">
|
||||
|
||||
<div class="alert alert-info"><h3>COOKIE POLICY</h3></div>
|
||||
|
||||
<div class="panel-body">
|
||||
<h3>About Entgra IoT Server</h3>
|
||||
<p>Entgra IoT Server 4.1.0 is a complete solution that enables device manufacturers and enterprises to
|
||||
connect and manage their devices, build apps, manage events, secure devices and data, and visualize
|
||||
sensor data in a scalable manner.</p>
|
||||
<p>It also offers a complete and secure Enterprise Mobility Management (EMM/MDM) solution that aims to
|
||||
address mobile computing challenges faced by enterprises today. Supporting iOS, Android, and Windows
|
||||
devices, it helps organizations deal with both Corporate Owned, Personally Enabled (COPE) and
|
||||
employee-owned devices with the Bring Your Own Device (BYOD) concept.</p>
|
||||
<p>Entgra IoT Server 4.1.0 comes with advanced analytics, enabling users to analyze speed, proximity,
|
||||
and
|
||||
geo-fencing information of devices including details of those in motion and stationary state.</p>
|
||||
</p>
|
||||
<h2>Cookie Policy</h2>
|
||||
<p>IoT Server uses cookies to provide you with the best user experience, and to securely identify you.
|
||||
You can disable cookies if you so wish . However you might not be able to access some of the services
|
||||
if you disable cookies.</p>
|
||||
<h3>What is a cookie?</h3>
|
||||
<p>A browser cookie is a small piece of data that is stored on your device to help websites and mobile
|
||||
apps remember things about you. Other technologies, including Web storage and identifiers associated
|
||||
with your device, may be used for similar purposes. In this policy, we use the term “cookies” to
|
||||
discuss all of these technologies.</p>
|
||||
<h3>How does Entgra IoT Server 4.1.0 process cookies?</h3>
|
||||
<p>Entgra IoT Server 4.1.0 uses cookies to store and retrieve information on your browser. This
|
||||
information is used to provide a better user experience. Some cookies serve the purpose of allowing a
|
||||
user to log in to the system, maintain sessions, and keep track of activities within the login
|
||||
session.</p>
|
||||
<p>Some cookies in Entgra IoT Server 4.1.0 are used to personally identify you. However, the cookie
|
||||
lifetime ends once your session ends, i.e., after you log-out, or after the session expiry time has
|
||||
elapsed.</p>
|
||||
<p>Some cookies are simply used to give you a more personalised web experience, and these cannot be used
|
||||
to identify you or your activities personally.</p>
|
||||
<p>This Cookie Policy is part of the IoT Server <a href="{{@app.context}}/privacy-policy">Privacy Policy.</a>
|
||||
</p>
|
||||
<h3>What does Entgra IoT Server 4.1.0 use cookies for?</h3>
|
||||
<p>Cookies are used for two purposes in Entgra IoT Server 4.1.0.</p>
|
||||
<ol>
|
||||
<li>To identify you and provide security</li>
|
||||
<li>To provide a satisfying user experience.</li>
|
||||
</ol>
|
||||
|
||||
<h4><u>Preferences</u></h4>
|
||||
<p>Entgra IoT Server 4.1.0 uses cookies to remember your settings and preferences and to auto-fill the
|
||||
fields to make your interactions with the site easier.</p>
|
||||
<p>These cookies can not be used to personally identify you.</p>
|
||||
|
||||
<h4><u>Security</u></h4>
|
||||
<ol>
|
||||
<li>Entgra IoT Server 4.1.0 uses selected cookies to identify and prevent security risks. For
|
||||
example,
|
||||
Entgra IoT Server 4.1.0 may use cookies to store your session information to prevent others from
|
||||
changing your password without your username and password.
|
||||
</li>
|
||||
<li>Entgra IoT Server 4.1.0 uses session cookie to maintain your active session.</li>
|
||||
<li>Entgra IoT Server 4.1.0 may use a temporary cookie when performing multi-factor authentication
|
||||
and
|
||||
federated authentication.
|
||||
</li>
|
||||
<li>Entgra IoT Server 4.1.0 may use permanent cookies to detect the devices you have logged in
|
||||
previously. This is to to calculate the <b>risk level</b> associated with your current login
|
||||
attempt. Using these cookies protects you and your account from possible attacks.
|
||||
</li>
|
||||
</ol>
|
||||
<h4><u>Performance</u></h4>
|
||||
<p>Entgra IoT Server 4.1.0 may use cookies to allow <b>Remember Me</b> functionalities.</p>
|
||||
<h4><u>Analytics</u></h4>
|
||||
<p>Entgra IoT Server 4.1.0 as a product does not use cookies for analytical purposes.</p>
|
||||
<h4><u>Third party cookies</u></h4>
|
||||
<p>Using Entgra IoT Server 4.1.0 may cause third-party cookie to be set in your browser. Entgra IoT
|
||||
Server
|
||||
4.1.0 has no control over how any of them operate. The third-party cookies that maybe set
|
||||
include:</p>
|
||||
<ol>
|
||||
<li>Any social login sites. For example, third-party cookies may be set when Entgra IoT Server 4.1.0
|
||||
is configured to use “social” or “federated” login, and you opt to login with your “Social
|
||||
Account”.
|
||||
</li>
|
||||
<li>Any third party federated login.</li>
|
||||
</ol>
|
||||
<p>Entgra strongly advises you to refer the respective cookie policies of such sites carefully as Entgra has
|
||||
no knowledge or use on these cookies.</p>
|
||||
<h3>What type of cookies does Entgra IoT Server 4.1.0 use?</h3>
|
||||
<p>Entgra IoT Server 4.1.0 uses persistent cookies and session cookies. A persistent cookie helps
|
||||
Entgra IS
|
||||
3.8.0 to recognize you as an existing user so that it is easier to return to Entgra or interact with
|
||||
Entgra IS 3.8.0 without signing in again. After you sign in, a persistent cookie stays in your browser
|
||||
and will be read by Entgra IoT Server 4.1.0 when you return to Entgra IoT Server 4.1.0.</p>
|
||||
<p>A session cookie is a cookie that is erased when the user closes the Web browser. The session cookie
|
||||
is stored in temporarily and is not retained after the browser is closed. Session cookies do not
|
||||
collect information from the user’s computer.</p>
|
||||
<h3>How do I control my cookies?</h3>
|
||||
<p>Most browsers allow you to control cookies through settings. However, if you limit the given ability
|
||||
for websites to set cookies, you may worsen your overall user experience since it will no longer be
|
||||
personalized to you. It may also stop you from saving customized settings like login information.
|
||||
Most likely, disabling cookies will make it unable for you to use authentication and authorization
|
||||
functionalities offered by Entgra IoT Server 4.1.0.</p>
|
||||
<p>If you have any questions or concerns regarding the use of cookies, please contact the entity or
|
||||
individuals (or their data protection officer, if applicable) running this Entgra IoT Server 4.1.0
|
||||
instance.</p>
|
||||
<h3>What are the cookies used?</h3>
|
||||
<table class="table table-striped table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Cookie Name</th>
|
||||
<th>Purpose</th>
|
||||
<th>Retention</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>JSESSIONID</td>
|
||||
<td>To keep your session data in order to give you a good user experience.</td>
|
||||
<td>Session</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>commonAuthId</td>
|
||||
<td>Used to authenticate the the logged in session.</td>
|
||||
<td>Session</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>samlssoTokenId</td>
|
||||
<td>Used to map the logged in user with the SAML token.</td>
|
||||
<td>Request</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>requestedURI</td>
|
||||
<td>The URI you are accessing.</td>
|
||||
<td>Session</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h3>Disclaimer</h3>
|
||||
<p>This cookie policy is only for illustrative purposes of the product Entgra IoT Server 4.1.0. The
|
||||
content in the policy is technically correct at the time of the product shipment. The
|
||||
entity,organization or individual that runs this Entgra IoT Server 4.1.0 instance has full authority
|
||||
and responsibility with regard to the effective Cookie Policy. Entgra, its employees, partners, and
|
||||
affiliates do not have access to and do not require, store, process or control any of the data,
|
||||
including personal data contained in Entgra IoT Server 4.1.0. All data, including personal data is
|
||||
controlled and processed by the entity, organization or individual running Entgra IoT Server 4.1.0.
|
||||
Entgra, its employees partners and affiliates are not a data processor or a data controller within the
|
||||
meaning of any data privacy regulations. Entgra does not provide any warranties or undertake any
|
||||
responsibility or liability in connection with the lawfulness or the manner and purposes for which
|
||||
Entgra IoT Server 4.1.0 is used by such entities, organizations or persons.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/zone}}
|
||||
@ -1,6 +0,0 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"layout": "uuf.layout.sign-in",
|
||||
"uri": "/cookie-policy",
|
||||
"isAnonymous": true
|
||||
}
|
||||
@ -1,234 +0,0 @@
|
||||
{{!
|
||||
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
|
||||
WSO2 Inc. licenses this file to you under the Apache License,
|
||||
Version 2.0 (the "License"); you may not use this file except
|
||||
in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
}}
|
||||
{{unit "cdmf.unit.ui.title" pageTitle="Home"}}
|
||||
|
||||
{{#zone "breadcrumbs"}}
|
||||
<li>
|
||||
<a href="{{@app.context}}/">
|
||||
<i class="icon fw fw-home"></i>
|
||||
</a>
|
||||
</li>
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "content"}}
|
||||
<div class="row">
|
||||
{{#if permissions.VIEW_DASHBOARD}}
|
||||
<div class="col-md-3 wr-stats-board">
|
||||
<div class="wr-stats-board-tile">
|
||||
<div class="tile-name">Devices</div>
|
||||
<div>
|
||||
<div class="tile-icon"><i class="fw fw-mobile"></i></div>
|
||||
<div class="tile-stats">
|
||||
<span id="device-count">{{deviceCount}}</span>
|
||||
<span class="tile-stats-free">
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
{{#if deviceCount}}
|
||||
<a href="{{@app.context}}/devices">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-view fw-stack-1x"></i>
|
||||
</span>
|
||||
View
|
||||
</a>
|
||||
{{/if}}
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
<a href="{{@app.context}}/device/enroll">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-add fw-stack-1x"></i>
|
||||
</span>
|
||||
Add
|
||||
</a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3 wr-stats-board">
|
||||
<div class="wr-stats-board-tile">
|
||||
<div class="tile-name">Groups</div>
|
||||
<div>
|
||||
<div class="tile-icon"><i class="fw fw-group"></i></div>
|
||||
<div class="tile-stats">
|
||||
<span id="group-count">{{groupCount}}</span>
|
||||
<span class="tile-stats-free">
|
||||
{{#if groupCount}}
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
<a href="{{@app.context}}/groups">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-view fw-stack-1x"></i>
|
||||
</span>
|
||||
View
|
||||
</a>
|
||||
{{/if}}
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
|
||||
<a href="{{@app.context}}/group/add">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-add fw-stack-1x"></i>
|
||||
</span>
|
||||
Add
|
||||
</a>
|
||||
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3 wr-stats-board">
|
||||
<div class="wr-stats-board-tile">
|
||||
<div class="tile-name">Users</div>
|
||||
<div>
|
||||
<div class="tile-icon"><i class="fw fw-user"></i></div>
|
||||
<div class="tile-stats">
|
||||
<span id="user-count">{{userCount}}</span>
|
||||
<span class="tile-stats-free">
|
||||
{{#if userCount}}
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
<a href="{{@app.context}}/users">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-view fw-stack-1x"></i>
|
||||
</span>
|
||||
View
|
||||
</a>
|
||||
{{/if}}
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
{{#unless isCloud}}
|
||||
<a href="{{@app.context}}/user/add">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-add fw-stack-1x"></i>
|
||||
</span>
|
||||
Add
|
||||
</a>
|
||||
{{/unless}}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3 wr-stats-board">
|
||||
<div class="wr-stats-board-tile">
|
||||
<div class="tile-name">Policies</div>
|
||||
<div>
|
||||
<div class="tile-icon"><i class="fw fw-policy"></i></div>
|
||||
<div class="tile-stats">
|
||||
<span id="policy-count">{{policyCount}}</span>
|
||||
<span class="tile-stats-free">
|
||||
{{#if policyCount}}
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
<a href="{{@app.context}}/policies">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-view fw-stack-1x"></i>
|
||||
</span>
|
||||
View
|
||||
</a>
|
||||
{{/if}}
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
|
||||
<a href="{{@app.context}}/policy/add">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-add fw-stack-1x"></i>
|
||||
</span>
|
||||
Add
|
||||
</a>
|
||||
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3 wr-stats-board">
|
||||
<div class="wr-stats-board-tile">
|
||||
<div class="tile-name">Roles</div>
|
||||
<div>
|
||||
<div class="tile-icon"><i class="fw fw-bookmark"></i></div>
|
||||
<div class="tile-stats">
|
||||
<span id="role-count">{{roleCount}}</span>
|
||||
<span class="tile-stats-free">
|
||||
{{#if roleCount}}
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
<a id="device-count-view-btn" href="{{@app.context}}/roles">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-view fw-stack-1x"></i>
|
||||
</span>
|
||||
View
|
||||
</a>
|
||||
{{/if}}
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
{{#unless isCloud}}
|
||||
<a href="{{@app.context}}/role/add">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-add fw-stack-1x"></i>
|
||||
</span>
|
||||
Add
|
||||
</a>
|
||||
{{/unless}}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{#if permissions.IS_ADMIN}}
|
||||
<div class="col-md-3 wr-stats-board">
|
||||
<div class="wr-stats-board-tile">
|
||||
<div class="tile-name">Device Types</div>
|
||||
<div>
|
||||
<div class="tile-icon"><i class="fw fw-devices"></i></div>
|
||||
<div class="tile-stats">
|
||||
<span id="device-types-count">{{deviceTypeCount}}</span>
|
||||
<span class="tile-stats-free">
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
{{#if deviceTypeCount}}
|
||||
<a href="{{@app.context}}/device-types">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-view fw-stack-1x"></i>
|
||||
</span>
|
||||
View
|
||||
</a>
|
||||
{{/if}}
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
<a href="{{@app.context}}/device-type/add">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-add fw-stack-1x"></i>
|
||||
</span>
|
||||
Add
|
||||
</a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{else}}
|
||||
<h1 class="page-sub-title">
|
||||
Permitted None
|
||||
</h1>
|
||||
{{/if}}
|
||||
</div>
|
||||
{{/zone}}
|
||||
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 userModule = require("/app/modules/business-controllers/user.js")["userModule"];
|
||||
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
|
||||
var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"];
|
||||
var policyModule = require("/app/modules/business-controllers/policy.js")["policyModule"];
|
||||
|
||||
if(!session.get(constants["TOKEN_PAIR"])){
|
||||
response.sendRedirect(context.app.context + "/welcome");
|
||||
return;
|
||||
}
|
||||
|
||||
var user = session.get(constants["USER_SESSION_KEY"]);
|
||||
var permissions = userModule.getUIPermissions();
|
||||
|
||||
if (!permissions.VIEW_DASHBOARD) {
|
||||
response.sendRedirect(devicemgtProps["appContext"] + "devices");
|
||||
return;
|
||||
}
|
||||
|
||||
var viewModel = {};
|
||||
viewModel.permissions = permissions;
|
||||
viewModel.enrollmentURL = devicemgtProps.enrollmentURL;
|
||||
viewModel.deviceCount = deviceModule.getDevicesCount();
|
||||
viewModel.groupCount = groupModule.getGroupCount();
|
||||
viewModel.userCount = userModule.getUsersCount();
|
||||
viewModel.policyCount = policyModule.getPoliciesCount();
|
||||
viewModel.deviceTypeCount = deviceModule.getDeviceTypeCount();
|
||||
viewModel.isCloud = devicemgtProps.isCloud;
|
||||
if (devicemgtProps.isCloud) {
|
||||
viewModel.roleCount = userModule.getFilteredRoles("devicemgt").content.count;
|
||||
} else {
|
||||
viewModel.roleCount = userModule.getRolesCount();
|
||||
}
|
||||
return viewModel;
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"uri": "/",
|
||||
"layout": "cdmf.layout.default"
|
||||
}
|
||||
@ -1,67 +0,0 @@
|
||||
{{!
|
||||
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
|
||||
WSO2 Inc. licenses this file to you under the Apache License,
|
||||
Version 2.0 (the "License"); you may not use this file except
|
||||
in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
}}
|
||||
{{#zone "topCss"}}
|
||||
{{css "css/analytics.css"}}
|
||||
{{/zone}}
|
||||
|
||||
{{unit "cdmf.unit.ui.title" pageTitle="Analytics"}}
|
||||
{{unit "cdmf.unit.ui.content.title" pageHeader=title}}
|
||||
{{unit "cdmf.unit.lib.service-invoker-utility"}}
|
||||
{{unit "cdmf.unit.lib.handlebars"}}
|
||||
{{unit "cdmf.unit.lib.rickshaw-graph"}}
|
||||
|
||||
{{#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/{{deviceType}}?id={{deviceId}}">
|
||||
{{deviceName}}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#">
|
||||
Analytics
|
||||
</a>
|
||||
</li>
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "content"}}
|
||||
<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 ">{{deviceName}} Analytics</h1>
|
||||
</div>
|
||||
{{unit "cdmf.unit.analytics.date-range-picker"}}
|
||||
</div>
|
||||
<hr>
|
||||
<div class="clear"></div>
|
||||
<div id="div-chart">
|
||||
{{unit deviceAnalyticsViewUnitName}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/zone}}
|
||||
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 utility = require("/app/modules/utility.js").utility;
|
||||
var deviceType = context.uriParams.deviceType;
|
||||
var deviceName = request.getParameter("deviceName");
|
||||
var deviceId = request.getParameter("deviceId");
|
||||
var unitName = utility.getTenantedDeviceUnitName(deviceType, "analytics-view");
|
||||
if (!unitName) {
|
||||
unitName = "cdmf.unit.default.device.type.analytics-view";
|
||||
}
|
||||
return {
|
||||
"deviceAnalyticsViewUnitName": unitName,
|
||||
"deviceType": deviceType,
|
||||
"deviceName": deviceName,
|
||||
"deviceId": deviceId
|
||||
};
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"uri": "/device/{deviceType}/analytics",
|
||||
"layout": "cdmf.layout.default"
|
||||
}
|
||||
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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;
|
||||
}
|
||||
@ -1,66 +0,0 @@
|
||||
{{!
|
||||
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
|
||||
WSO2 Inc. licenses this file to you under the Apache License,
|
||||
Version 2.0 (the "License"); you may not use this file except
|
||||
in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
}}
|
||||
{{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 "navbarActions"}}
|
||||
{{#if isCloud}}
|
||||
<li>
|
||||
<a href="{{contact_form_url}}" class="cu-btn">
|
||||
<span class="icon fw-stack">
|
||||
<i class="fw fw-mail fw-stack-1x"></i>
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
</span>
|
||||
Request new device type
|
||||
</a>
|
||||
</li>
|
||||
{{/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.types.listing"}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/zone}}
|
||||
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the dynamic state to be populated by device-enrollment page.
|
||||
*
|
||||
* @param context Object that gets updated with the dynamic state of this page to be presented
|
||||
* @returns {*} A context object that returns the dynamic state of this page to be presented
|
||||
*/
|
||||
function onRequest(context) {
|
||||
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var page = {};
|
||||
page["isCloud"] = devicemgtProps.isCloud;
|
||||
page["contact_form_url"] = "https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/contact-us.jag?cloud-type=device_cloud&subject=Requesting for a new device type";
|
||||
return page;
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"uri": "/device/enroll",
|
||||
"layout": "cdmf.layout.default"
|
||||
}
|
||||
@ -1,227 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 removeCustomParam = function () {
|
||||
$(this).parent().parent().remove();
|
||||
};
|
||||
|
||||
/**
|
||||
* Following function would execute
|
||||
* when a user clicks on the list item
|
||||
* initial mode and with out select mode.
|
||||
*/
|
||||
function InitiateViewOption() {
|
||||
$(location).attr('href', $(this).data("url"));
|
||||
}
|
||||
|
||||
$("#back-to-search").click(function () {
|
||||
$('#advance-search-result').addClass('hidden');
|
||||
$("#advance-search-form").removeClass('hidden');
|
||||
$("#view-search-param").addClass('hidden');
|
||||
$("#back-to-search").addClass('hidden');
|
||||
});
|
||||
|
||||
$("#view-search-param").click(function () {
|
||||
$("#advance-search-form").removeClass('hidden');
|
||||
$(".title-result").addClass('hidden');
|
||||
$("#view-search-param").addClass('hidden');
|
||||
});
|
||||
|
||||
var dynamicForm = '<div class="dynamic-search-param row"><div class="row"><a class="close-button-div icon fw fw-error">'
|
||||
+ '</a></div><div class="form-group wr-input-control col-md-2"><label class="wr-input-label ">State</label>'
|
||||
+ '<select class="state no-tag form-control select2-custom"><option>AND</option><option>OR</option></select></div>'
|
||||
+ '<div class="form-group wr-input-control col-md-4"><label class="wr-input-label ">Key</label><select class='
|
||||
+ '"txt-key form-control select2-custom"><option value = "deviceModel">Device Model</option><option value = '
|
||||
+ '"PhoneNumber">Phone Number</option><option value = "vendor">Vendor</option><option value = "osVersion">'
|
||||
+ 'OS Version</option><option value = "batteryLevel">Battery Level</option><option value ='
|
||||
+ ' "internalTotalMemory">Internal Total Memory</option><option value ="internalAvailableMemory">'
|
||||
+ 'Internal Available Memory</option><option value = "externalTotalMemory">External Total Memory</option>'
|
||||
+ '<option value = "externalAvailableMemory">External Available Memory'
|
||||
+ '</option><option value = "connectionType">Connection Type</option> <option value ='
|
||||
+ ' "ssid">SSID</option><option value= "IMEI">IMEI</option><option value = "cpuUsage">CPU Usage</option><option '
|
||||
+ 'value = "totalRAMMemory">Total RAM Memory</option><option value = "availableRAMMemory">Available RAM Memory'
|
||||
+ '</option><option value = "pluggedIn">Plugged In</option></select></div>'
|
||||
+ '<div class="form-group wr-input-control col-md-2">'
|
||||
+ '<label class="wr-input-label ">Operator</label><select id = "operators" class="form-control'
|
||||
+ ' select2-custom no-tag operator"><option>=</option><option>!=</option><option>%</option>'
|
||||
+ '</select></div><div class="form-group ' + 'wr-input-control col-md-4"><label class="wr-input-label">Value'
|
||||
+ '</label><input type="text" class="form-control txt-value"/></div></div>';
|
||||
|
||||
var nonNumericKeyValuePair = ["deviceModel", "vendor", "osVersion", "connectionType", "ssid", "pluggedIn"];
|
||||
|
||||
$(document).ready(function () {
|
||||
var isInit = true;
|
||||
$("#add-custom-param").click(function () {
|
||||
$("#customSearchParam").prepend(dynamicForm);
|
||||
$(".close-button-div").unbind("click");
|
||||
$(".close-button-div").bind("click", removeCustomParam);
|
||||
$(".no-tag").select2({tags: false});
|
||||
$(".txt-key").select2({tags: true}).on('change', function() {
|
||||
// Based on the selected key, relevant operations are changed
|
||||
var operationsForSelectedKey = getOperators($(this).val());
|
||||
$("#operators").empty();
|
||||
$("#operators").append(operationsForSelectedKey);
|
||||
$("#operators").select2("val", "=");
|
||||
});
|
||||
});
|
||||
|
||||
/** Function to get operators based on the key Value
|
||||
*
|
||||
* @param keyValue
|
||||
*/
|
||||
function getOperators(keyValue) {
|
||||
if (nonNumericKeyValuePair.indexOf(keyValue) < 0) {
|
||||
return '<option> =</option><option> !=</option><option> <</option><option> <=</option><option>' +
|
||||
' ></option><option> >=</option>';
|
||||
} else {
|
||||
return '<option> =</option><option> !=</option><option><option> %</option>';
|
||||
}
|
||||
}
|
||||
|
||||
/** To validate the key and value before sending that to back-end
|
||||
*
|
||||
* @param key Key of the search
|
||||
* @param value value given for the search
|
||||
*/
|
||||
function isValidKeyAndValue(key, value) {
|
||||
if (nonNumericKeyValuePair.indexOf(key) < 0) {
|
||||
if (!isNaN(parseFloat(value)) && isFinite(value)){
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$("#device-search-btn").click(function () {
|
||||
var location = $("#location").val();
|
||||
var payload_obj = {};
|
||||
var conditions = [];
|
||||
var hasError = false;
|
||||
if (location) {
|
||||
var conditionObject = {};
|
||||
conditionObject.key = "LOCATION";
|
||||
conditionObject.value = location;
|
||||
conditionObject.operator = "=";
|
||||
conditionObject.state = "OR";
|
||||
conditions.push(conditionObject)
|
||||
}
|
||||
|
||||
$("#customSearchParam .dynamic-search-param").each(function () {
|
||||
var value = $(this).find(".txt-value").val();
|
||||
var key = $(this).find(".txt-key").val();
|
||||
if (!hasError && value && key ) {
|
||||
if (isValidKeyAndValue(key, value)) {
|
||||
var conditionObject = {};
|
||||
conditionObject.key = key;
|
||||
conditionObject.value = value;
|
||||
conditionObject.operator = $(this).find(".operator").val();
|
||||
conditionObject.state = $(this).find(".state").val();
|
||||
conditions.push(conditionObject);
|
||||
} else {
|
||||
hasError = true;
|
||||
$("#advance-search-result").addClass("hidden");
|
||||
$("#advance-search-form").removeClass(" hidden");
|
||||
$('#device-listing-status').removeClass('hidden');
|
||||
$('#device-listing-status-msg').text('Error in user input values. ' + key + " requires a" +
|
||||
" numerical value as the search value");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Sent the search conditions to back-end only, if all the values compliant with there key values
|
||||
if (hasError) {
|
||||
hasError = false;
|
||||
} else {
|
||||
payload_obj.conditions = conditions;
|
||||
var deviceSearchAPI = "/api/device-mgt/v1.0/devices/search-devices";
|
||||
$("#advance-search-form").addClass(" hidden");
|
||||
$("#loading-content").removeClass('hidden');
|
||||
var deviceListing = $("#device-listing");
|
||||
var deviceListingSrc = deviceListing.attr("src");
|
||||
$.template("device-listing", deviceListingSrc, function (template) {
|
||||
var successCallback = function (data) {
|
||||
if (!data) {
|
||||
$("#loading-content").addClass('hidden');
|
||||
$("#advance-search-result").addClass("hidden");
|
||||
$("#advance-search-form").removeClass(" hidden");
|
||||
$('#device-listing-status').removeClass('hidden');
|
||||
$('#device-listing-status-msg').text('No Device are available to be displayed.');
|
||||
return;
|
||||
}
|
||||
data = JSON.parse(data);
|
||||
if (data.devices.length == 0) {
|
||||
$("#loading-content").addClass('hidden');
|
||||
$("#advance-search-result").addClass("hidden");
|
||||
$("#advance-search-form").removeClass(" hidden");
|
||||
$('#device-listing-status').removeClass('hidden');
|
||||
$('#device-listing-status-msg').text('No Device are available to be displayed.');
|
||||
return;
|
||||
}
|
||||
var viewModel = {};
|
||||
var devices = [];
|
||||
if (data.devices.length > 0) {
|
||||
for (i = 0; i < data.devices.length; i++) {
|
||||
var tempDevice = data.devices[i];
|
||||
var device = {};
|
||||
device.type = tempDevice.type;
|
||||
device.name = tempDevice.name;
|
||||
device.deviceIdentifier = tempDevice.deviceIdentifier;
|
||||
var properties = {};
|
||||
var enrolmentInfo = {};
|
||||
properties.VENDOR = tempDevice.deviceInfo.vendor;
|
||||
properties.DEVICE_MODEL = tempDevice.deviceInfo.deviceModel;
|
||||
device.enrolmentInfo = tempDevice.enrolmentInfo;
|
||||
device.properties = properties;
|
||||
devices.push(device);
|
||||
}
|
||||
viewModel.devices = devices;
|
||||
$('#advance-search-result').removeClass('hidden');
|
||||
$("#view-search-param").removeClass('hidden');
|
||||
$("#back-to-search").removeClass('hidden');
|
||||
$('#device-grid').removeClass('hidden');
|
||||
$('#ast-container').removeClass('hidden');
|
||||
$('#user-listing-status-msg').text("");
|
||||
var content = template(viewModel);
|
||||
$("#ast-container").html(content);
|
||||
} else {
|
||||
$('#device-listing-status').removeClass('hidden');
|
||||
$('#device-listing-status-msg').text('No Device are available to be displayed.');
|
||||
}
|
||||
$("#loading-content").addClass('hidden');
|
||||
if (isInit) {
|
||||
$('#device-grid').datatables_extended();
|
||||
isInit = false;
|
||||
}
|
||||
$(".icon .text").res_text(0.2);
|
||||
};
|
||||
invokerUtil.post(deviceSearchAPI,
|
||||
payload_obj,
|
||||
successCallback,
|
||||
function (message) {
|
||||
$("#loading-content").addClass('hidden');
|
||||
$("#advance-search-result").addClass("hidden");
|
||||
$("#advance-search-form").removeClass(" hidden");
|
||||
$('#device-listing-status').removeClass('hidden');
|
||||
$('#device-listing-status-msg').text('Server is unable to perform the search please enroll at least one device or check the search query');
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -1,44 +0,0 @@
|
||||
|
||||
|
||||
{{#each devices}}
|
||||
|
||||
<tr data-type="selectable" data-deviceid="{{deviceIdentifier}}" data-devicetype="{{type}}">
|
||||
<td class="remove-padding icon-only content-fill viewEnabledIcon"
|
||||
{{#unequal enrolmentInfo.status "REMOVED"}}
|
||||
data-url="../device/{{type}}?id={{deviceIdentifier}}"
|
||||
{{/unequal}}
|
||||
>
|
||||
<div class="thumbnail icon">
|
||||
<i class="square-element text fw fw-mobile"></i>
|
||||
</div>
|
||||
</td>
|
||||
<td data-search="{{properties.DEVICE_MODEL}},{{properties.VENDOR}}" data-display="{{properties.DEVICE_MODEL}}">
|
||||
<h4>Device {{name}}</h4>
|
||||
{{#if properties.DEVICE_MODEL}}
|
||||
<div>({{properties.VENDOR}} - {{properties.DEVICE_MODEL}})</div>
|
||||
{{/if}}
|
||||
</td>
|
||||
<td class="remove-padding-top" data-search="{{enrolmentInfo.owner}}" data-display="{{enrolmentInfo.owner}}" data-grid-label="Owner">{{enrolmentInfo.owner}}</td>
|
||||
<td class="remove-padding-top" data-search="{{enrolmentInfo.status}}" data-display="{{enrolmentInfo.status}}" data-grid-label="Status">
|
||||
{{#equal enrolmentInfo.status "ACTIVE"}}<span><i class="fw fw-success icon-success"></i> Active</span>{{/equal}}
|
||||
{{#equal enrolmentInfo.status "INACTIVE"}}<span><i class="fw fw-warning icon-warning"></i> Inactive</span>{{/equal}}
|
||||
{{#equal enrolmentInfo.status "BLOCKED"}}<span><i class="fw fw-remove icon-danger"></i> Blocked</span>{{/equal}}
|
||||
{{#equal enrolmentInfo.status "REMOVED"}}<span><i class="fw fw-disabled icon-danger"></i> Removed</span>{{/equal}}
|
||||
</td>
|
||||
<td class="remove-padding-top" data-search="{{type}}" data-display="{{type}}" data-grid-label="Type">{{type}}</td>
|
||||
<td class="remove-padding-top" data-search="{{enrolmentInfo.ownership}}" data-display="{{enrolmentInfo.ownership}}" data-grid-label="Ownership">{{enrolmentInfo.ownership}}</td>
|
||||
<td class="text-right content-fill text-left-on-grid-view no-wrap">
|
||||
<!--{{#equal type "TemperatureController"}}
|
||||
{{#equal status "INACTIVE"}}
|
||||
<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view claim-btn" data-deviceid="{{deviceIdentifier}}">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-edit fw-stack-1x"></i>
|
||||
</span>
|
||||
<span class="hidden-xs hidden-on-grid-view">Claim</span>
|
||||
</a>
|
||||
{{/equal}}
|
||||
{{/equal}}-->
|
||||
</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
@ -1,164 +0,0 @@
|
||||
<!--
|
||||
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
WSO2 Inc. licenses this file to you under the Apache License,
|
||||
Version 2.0 (the "License"); you may not use this file except
|
||||
in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
{{unit "cdmf.unit.ui.title" pageTitle="Advanced Search"}}
|
||||
{{unit "cdmf.unit.ui.modal"}}
|
||||
{{unit "cdmf.unit.data-tables-extended"}}
|
||||
{{#zone "breadcrumbs"}}
|
||||
<li>
|
||||
<a href="{{@app.context}}/">
|
||||
<i class="icon fw fw-home"></i>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
<a href="{{@app.context}}/devices">
|
||||
Devices
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
<a href="{{@app.context}}/devices/search">
|
||||
Search
|
||||
</a>
|
||||
</li>
|
||||
{{/zone}}
|
||||
|
||||
|
||||
{{#zone "content"}}
|
||||
<!-- content/body -->
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<!-- content -->
|
||||
<div class="row">
|
||||
<div class="col-md-10 col-centered">
|
||||
<button id="back-to-search" class="wr-btn col-fixed-right hidden">Back to Search Query</button>
|
||||
<button id="view-search-param" class="wr-btn col-fixed-right hidden">View Search Query</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="advance-search-form" class="container col-centered wr-content">
|
||||
<div class="wr-form">
|
||||
<p class="page-sub-title">Advanced Device Search</p>
|
||||
<hr/>
|
||||
<div id="device-listing-status" class="row hidden">
|
||||
<div class="col-lg-12 col-md-12">
|
||||
<ul style="list-style-type: none; padding:0px;">
|
||||
<li class="message message-info">
|
||||
<h4>
|
||||
<i class="icon fw fw-info"></i>
|
||||
<a id="device-listing-status-msg"></a>
|
||||
</h4>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12">
|
||||
<div id="device-search-error-msg" class="alert alert-danger hidden" role="alert">
|
||||
<i class="icon fw fw-error"></i><span></span>
|
||||
</div>
|
||||
|
||||
<label class="wr-input-label ">
|
||||
Location
|
||||
</label>
|
||||
<br>
|
||||
<div class="row">
|
||||
<div id="locationInputField" class=" col-md-10 form-group wr-input-control">
|
||||
<input type="text" id="location" class="form-control"/>
|
||||
<br>
|
||||
<span class=" locationError hidden glyphicon glyphicon-remove form-control-feedback"></span>
|
||||
<label class="error usernameEmpty hidden" for="summary">This field is
|
||||
required.</label>
|
||||
</div>
|
||||
<div class="col-md-2 form-group wr-input-control col-fixed-right">
|
||||
<button id="device-search-btn" class="wr-btn">Search</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button id="add-custom-param" class="wr-btn">Add a custom search parameter</button>
|
||||
<br>
|
||||
</div>
|
||||
<br>
|
||||
<div id="customSearchParam" class="col-lg-10 col-md-10">
|
||||
|
||||
</div>
|
||||
<div class="row">
|
||||
<div id="customSearchParam" class="col-lg-12 col-md-12"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /content -->
|
||||
<div id="group-error-content" class="hide">
|
||||
<div class="modal-content">
|
||||
<div class="row">
|
||||
<div class="col-md-7 col-centered center-container">
|
||||
<h4 id="error-msg">Unexpected error occurred!</h4>
|
||||
<br/>
|
||||
<div class="buttons">
|
||||
<a href="#" id="group-unexpected-error-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- loading -->
|
||||
<div id="loading-content" class="col-centered hidden">
|
||||
<i class="fw fw-settings fw-spin fw-2x"></i>
|
||||
|
||||
Searching for Devices . . .
|
||||
<br>
|
||||
</div>
|
||||
<!--/loading-->
|
||||
|
||||
<!-- result content -->
|
||||
<div id="advance-search-result" class="col-centered hidden">
|
||||
<div class="wr-form">
|
||||
<b class="page-sub-title title-result">Advanced Search Results</b>
|
||||
<hr/>
|
||||
<div id="device-table">
|
||||
<table class="table table-striped table-hover list-table display responsive nowrap data-table grid-view hidden"
|
||||
id="device-grid">
|
||||
<thead class="hidden">
|
||||
<tr>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="ast-container">
|
||||
|
||||
<br class="c-both"/>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- / result content -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /content/body -->
|
||||
{{/zone}}
|
||||
{{#zone "bottomJs"}}
|
||||
{{js "/js/bottomJs.js"}}
|
||||
<script id="device-listing" src="{{@page.publicUri}}/templates/device-listing.hbs"
|
||||
type="text/x-handlebars-template"></script>
|
||||
{{/zone}}
|
||||
@ -1,5 +0,0 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"uri": "/devices/search",
|
||||
"layout": "cdmf.layout.default"
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
{{!
|
||||
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
|
||||
WSO2 Inc. licenses this file to you under the Apache License,
|
||||
Version 2.0 (the "License"); you may not use this file except
|
||||
in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
}}
|
||||
{{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}}
|
||||
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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);
|
||||
var label = deviceType;
|
||||
if (configs) {
|
||||
label = configs["deviceType"]["label"];
|
||||
}
|
||||
var unitName = utility.getTenantedDeviceUnitName(deviceType, "type-view");
|
||||
if (!unitName) {
|
||||
unitName = "cdmf.unit.default.device.type.type-view";
|
||||
}
|
||||
return {
|
||||
"deviceTypeViewUnitName": unitName,
|
||||
"deviceType": deviceType,
|
||||
"label" : label
|
||||
};
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"uri": "/device/{deviceType}/enroll",
|
||||
"layout": "cdmf.layout.default"
|
||||
}
|
||||
@ -1,46 +0,0 @@
|
||||
{{!
|
||||
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
|
||||
WSO2 Inc. licenses this file to you under the Apache License,
|
||||
Version 2.0 (the "License"); you may not use this file except
|
||||
in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
}}
|
||||
{{unit "cdmf.unit.ui.title" pageTitle="Device Details"}}
|
||||
{{unit "cdmf.unit.lib.service-invoker-utility"}}
|
||||
{{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}}/devices">
|
||||
Devices
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#">
|
||||
Device Details
|
||||
</a>
|
||||
</li>
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "content"}}
|
||||
{{unit deviceViewUnitName}}
|
||||
{{unit "cdmf.unit.lib.data-table"}}
|
||||
{{unit "cdmf.unit.device.operation-mod"}}
|
||||
{{unit "cdmf.unit.device.view"}}
|
||||
{{/zone}}
|
||||
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 utility = require("/app/modules/utility.js").utility;
|
||||
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;
|
||||
var unitName = utility.getTenantedDeviceUnitName(deviceType, "device-view");
|
||||
if (!unitName) {
|
||||
unitName = "cdmf.unit.default.device.type.device-view";
|
||||
}
|
||||
return {"deviceViewUnitName": unitName};
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"uri": "/device/{deviceType}",
|
||||
"layout": "cdmf.layout.default"
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
{{!
|
||||
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
|
||||
WSO2 Inc. licenses this file to you under the Apache License,
|
||||
Version 2.0 (the "License"); you may not use this file except
|
||||
in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
}}
|
||||
{{unit "cdmf.unit.ui.title" pageTitle="Device Location"}}
|
||||
|
||||
{{#zone "breadcrumbs"}}
|
||||
<li>
|
||||
<a href="{{@app.context}}/">
|
||||
<i class="icon fw fw-home"></i>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{@app.context}}/device-locations">
|
||||
Device Locations
|
||||
</a>
|
||||
</li>
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "content"}}
|
||||
{{unit "cdmf.unit.geo-devices"}}
|
||||
{{/zone}}
|
||||
@ -1,5 +0,0 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"uri": "/device-locations",
|
||||
"layout": "cdmf.layout.default"
|
||||
}
|
||||
@ -1,760 +0,0 @@
|
||||
{{!
|
||||
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
|
||||
WSO2 Inc. licenses this file to you under the Apache License,
|
||||
Version 2.0 (the "License"); you may not use this file except
|
||||
in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
}}
|
||||
|
||||
{{!
|
||||
Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
|
||||
Entgra (Pvt) Ltd. 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.
|
||||
}}
|
||||
{{unit "cdmf.unit.ui.title" pageTitle="Device Management"}}
|
||||
|
||||
{{unit "cdmf.unit.data-tables-extended"}}
|
||||
{{unit "cdmf.unit.lib.ui-permissions-utility"}}
|
||||
|
||||
{{#zone "breadcrumbs"}}
|
||||
<li>
|
||||
<a href="{{@app.context}}/">
|
||||
<i class="icon fw fw-home"></i>
|
||||
</a>
|
||||
</li>
|
||||
{{#if group}}
|
||||
<li>
|
||||
<a href="{{@app.context}}/groups">
|
||||
Groups
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#">
|
||||
{{group.name}}
|
||||
</a>
|
||||
</li>
|
||||
{{else}}
|
||||
<li>
|
||||
<a href="{{@app.context}}/devices">
|
||||
Devices
|
||||
</a>
|
||||
</li>
|
||||
{{/if}}
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "navbarActions"}}
|
||||
{{#if group}}
|
||||
<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-circle-outline fw-stack-2x"></i>
|
||||
</span>
|
||||
Assign from My Devices
|
||||
</a>
|
||||
</li>
|
||||
<!--<li>
|
||||
<a href="{{@app.context}}/group/{{group.id}}/analytics" class="cu-btn">
|
||||
<span class="icon fw-stack">
|
||||
<i class="fw fw-statistics fw-stack-1x"></i>
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
</span>
|
||||
View Analytics
|
||||
</a>
|
||||
</li>-->
|
||||
{{else}}
|
||||
{{#if permissions.enroll}}
|
||||
<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-circle-outline fw-stack-2x"></i>
|
||||
</span>
|
||||
Enroll Device
|
||||
</a>
|
||||
</li>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "content"}}
|
||||
{{#if group}}
|
||||
<h1 class="page-sub-title">
|
||||
{{group.name}} group
|
||||
</h1>
|
||||
<div class="row no-gutter add-padding-5x add-margin-top-5x" style="border: 1px solid #e4e4e4;">
|
||||
<div class="media">
|
||||
<div id="device_overview">
|
||||
<div class="media-left col-lg-2">
|
||||
<div class="icon">
|
||||
<img src="/devicemgt/public/cdmf.page.groups/images/group-icon.png"
|
||||
style="background-color: #008cc4; height: 152px;">
|
||||
</div>
|
||||
</div>
|
||||
<div class="media-body asset-desc add-padding-left-5x">
|
||||
<div style="background: #008cc4; color: #fff; padding: 10px; margin-bottom: 5px">
|
||||
Overview
|
||||
</div>
|
||||
<table class="table table-responsive table-striped" id="members" style="margin-bottom: 0px;">
|
||||
<tbody>
|
||||
<tr role="row" class="even">
|
||||
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Owner</td>
|
||||
<td id="group_owner" style="padding:10px 15px;">{{group.owner}}</td>
|
||||
</tr>
|
||||
<tr role="row" class="odd">
|
||||
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Shared with roles</td>
|
||||
<td style="padding:10px 15px;">
|
||||
{{#each roles}}
|
||||
{{this}}<br/>
|
||||
{{/each}}
|
||||
</td>
|
||||
</tr>
|
||||
<tr role="row" class="even">
|
||||
<td class="sorting_1" style="padding:10px 15px;width: 15%;">Device Count</td>
|
||||
<td style="padding:10px 15px;">{{deviceCount}}</td>
|
||||
</tr>
|
||||
<tr role="row" class="odd">
|
||||
<td class="sorting_1" style="padding:10px 15px;width: 15%;">Description</td>
|
||||
<td style="padding:10px 15px;">{{group.description}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<br/>
|
||||
<h1 class="page-sub-title add-margin-top-5x">
|
||||
Devices in {{group.name}} group
|
||||
</h1>
|
||||
{{/if}}
|
||||
<div class="wr-device-list row">
|
||||
<div class="wr-hidden-operations wr-advance-operations"></div>
|
||||
<div class="col-md-12 wr-page-content">
|
||||
<div>
|
||||
<span id="permission" data-permission="{{permissions.list}}"></span>
|
||||
{{unit "cdmf.unit.device.operation-mod"}}
|
||||
{{#if deviceCount}}
|
||||
<div id="loading-content" class="col-centered">
|
||||
<i class="fw fw-wso2-logo fw-pulse fw-2x"></i>
|
||||
Loading devices . . .
|
||||
<br>
|
||||
</div>
|
||||
<div id="device-listing-status" class="raw hidden">
|
||||
<ul style="list-style-type: none;">
|
||||
<li class="message message-info">
|
||||
<h4>
|
||||
<i class="icon fw fw-info"></i>
|
||||
<a id="device-listing-status-msg"></a>
|
||||
</h4>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="device-table">
|
||||
<table class="table table-striped table-hover list-table display responsive nowrap data-table grid-view hidden"
|
||||
id="device-grid">
|
||||
<thead>
|
||||
<tr class="sort-row">
|
||||
<th class="no-sort"></th>
|
||||
<th>By Device Name</th>
|
||||
<th>By Owner</th>
|
||||
<th>By Status</th>
|
||||
<th>By Platform</th>
|
||||
<th>By Ownership</th>
|
||||
<th class="no-sort"></th>
|
||||
</tr>
|
||||
<tr class="filter-row filter-box">
|
||||
<th class="no-sort"></th>
|
||||
<th data-for="By Device Name" class="text-filter"></th>
|
||||
<th data-for="By Owner" class="text-filter"></th>
|
||||
<th data-for="By Status" class="select-filter data-status"></th>
|
||||
<th data-for="By Platform" class="select-filter data-platform"></th>
|
||||
<th data-for="By Ownership" class="select-filter data-ownership"></th>
|
||||
<th class="no-sort"></th>
|
||||
</tr>
|
||||
<tr class="bulk-action-row hidden">
|
||||
<th colspan="7">
|
||||
<ul class="tiles">
|
||||
{{#unless group}}
|
||||
<li>
|
||||
<a href="#"
|
||||
data-click-event="remove-form"
|
||||
class="btn square-element add-devices-to-group-link"
|
||||
data-toggle="modal" data-target="#modalDemo">
|
||||
<span class="icon fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-group fw-stack-1x"></i>
|
||||
</span>
|
||||
Add to Group
|
||||
</a>
|
||||
</li>
|
||||
{{/unless}}
|
||||
<li>
|
||||
<a href="#"
|
||||
data-click-event="remove-form"
|
||||
class="btn square-element remove-device-link"
|
||||
data-toggle="modal" data-target="#modalDemo">
|
||||
<span class="icon fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-disabled fw-stack-1x"></i>
|
||||
</span>
|
||||
{{#if group}}
|
||||
Remove from group
|
||||
{{else}}
|
||||
Dis-enroll Device
|
||||
{{/if}}
|
||||
</a>
|
||||
</li>
|
||||
<!--permanent delete-->
|
||||
{{#if permissions.permanentDelete}}
|
||||
<li>
|
||||
<a href="#"
|
||||
data-click-event="remove-form"
|
||||
class="btn square-element delete-device-link"
|
||||
data-toggle="modal" data-target="#modalDemo">
|
||||
<span class="icon fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-delete fw-stack-1x"></i>
|
||||
</span>
|
||||
Delete Device
|
||||
</a>
|
||||
</li>
|
||||
{{/if}}
|
||||
<!--/permanent delete-->
|
||||
<!--update enrollment-->
|
||||
{{#if permissions.updateEnrollment}}
|
||||
<li>
|
||||
<a href="#" style="width: 100px;height: 80px;"
|
||||
data-click-event="remove-form"
|
||||
class="btn square-element update-enrollment-link"
|
||||
data-toggle="modal" data-target="#modalDemo">
|
||||
<span class="icon fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-user fw-stack-1x"></i>
|
||||
</span>
|
||||
Update Enrollment
|
||||
</a>
|
||||
</li>
|
||||
{{/if}}
|
||||
<!--/update enrollment-->
|
||||
<!-- Add operation for selected devices -->
|
||||
<li>
|
||||
<a href="#" data-click-event="remove-form"
|
||||
class="btn square-element add-operation-link"
|
||||
data-toggle="modal" data-target="#modalDemo">
|
||||
<span class="icon fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-dgm-action fw-stack-1x"></i>
|
||||
</span>
|
||||
Add Operation
|
||||
</a>
|
||||
</li>
|
||||
<!-- Add operation for selected devices -->
|
||||
</ul>
|
||||
</th>
|
||||
</tr>
|
||||
<tr id="device-type-operations-bar" class="bulk-action-row sub-action hidden">
|
||||
<th colspan="7">
|
||||
<div id="device-type-operations"></div>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="ast-container">
|
||||
|
||||
<br class="c-both"/>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<br class="c-both"/>
|
||||
<div id="content-filter-types" style="display: none">
|
||||
<div class="sort-title">Sort By</div>
|
||||
<div class="sort-options">
|
||||
<a href="#">By Device Name<span class="ico-sort-asc"></span></a>
|
||||
<a href="#">By Owner</a>
|
||||
<a href="#">By Status</a>
|
||||
<a href="#">By Platform</a>
|
||||
<a href="#">By Ownership</a>
|
||||
</div>
|
||||
</div>
|
||||
{{else}}
|
||||
<div id="ast-container" class="ast-container list-view">
|
||||
<div class="ctrl-info-panel col-centered text-center wr-login">
|
||||
<h3 class="text-muted">
|
||||
<i class="fw fw-devices fw-3x"></i>
|
||||
</h3>
|
||||
<h3 class="text-muted">
|
||||
You don't have any
|
||||
{{#if group}}
|
||||
devices assigned to this group. Let's add a device!
|
||||
{{else}}
|
||||
enrolled devices. Let's enroll a device!
|
||||
{{/if}}
|
||||
|
||||
</h3>
|
||||
<h3>
|
||||
{{#if group}}
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
<a href="{{@app.context}}/devices" class="btn-operations btn-default">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-add fw-stack-1x"></i>
|
||||
</span>
|
||||
Assign from My Devices
|
||||
</a>
|
||||
{{else}}
|
||||
{{#if permissions.enroll}}
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
<a href="{{@app.context}}/device/enroll" class="btn-operations btn-default">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-add fw-stack-1x"></i>
|
||||
</span>
|
||||
Enroll New Device
|
||||
</a>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
<div id="group-device-modal-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">
|
||||
<span>
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-group fw-stack-1x"></i>
|
||||
</span> Device Grouping
|
||||
</span>
|
||||
</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i
|
||||
class="fw fw-cancel"></i></button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
<div id="notification-error-msg" class="alert alert-danger hidden" role="alert">
|
||||
<i class="icon fw fw-error"></i><span></span>
|
||||
</div>
|
||||
<div id="user-groups">Loading...</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="{{@app.context}}/group/add" id="group-add-link" class="btn-operations">
|
||||
Add device group
|
||||
</a>
|
||||
<a href="#" id="group-device-add-link" class="btn-operations">
|
||||
Add devices to group
|
||||
</a>
|
||||
<a href="#" id="group-device-update-link" class="btn-operations">
|
||||
Update assignment
|
||||
</a>
|
||||
<a href="#" id="group-device-cancel-link" class="btn-operations btn-default">
|
||||
Cancel
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="group-associate-device-200-content" class="hide">
|
||||
<div class="modal-content">
|
||||
<div class="row">
|
||||
<div class="col-md-3 col-centered">
|
||||
<h3>Successfully added the device/s to the group!</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="remove-device-modal-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">
|
||||
{{#if group}}
|
||||
Do you really want to remove this device(s) from '{{group.name}}' group?
|
||||
{{else}}
|
||||
Do you really want to remove this device(s) from your Devices?
|
||||
{{/if}}
|
||||
</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i
|
||||
class="fw fw-cancel"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="remove-device-yes-link" class="btn-operations">
|
||||
Yes
|
||||
</a>
|
||||
|
||||
<a href="#" id="remove-device-cancel-link" class="btn-operations">
|
||||
Cancel
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="remove-device-200-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">
|
||||
{{#if group}}
|
||||
Successfully removed from '{{group.name}}' group.
|
||||
{{else}}
|
||||
Successfully removed.
|
||||
{{/if}}
|
||||
</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i
|
||||
class="fw fw-cancel"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="javascript:hidePopup()" class="btn-operations">Ok</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="delete-device-modal-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">
|
||||
{{#if group}}
|
||||
Do you really want to permanently delete this device(s) from '{{group.name}}' group?
|
||||
{{else}}
|
||||
Do you really want to permanently delete this device(s) from your Devices?
|
||||
{{/if}}
|
||||
</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i
|
||||
class="fw fw-cancel"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="delete-device-yes-link" class="btn-operations">
|
||||
Yes
|
||||
</a>
|
||||
|
||||
<a href="#" id="delete-device-cancel-link" class="btn-operations">
|
||||
Cancel
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="delete-device-200-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">
|
||||
{{#if group}}
|
||||
Successfully deleted from '{{group.name}}' group.
|
||||
{{else}}
|
||||
Successfully deleted.
|
||||
{{/if}}
|
||||
</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i
|
||||
class="fw fw-cancel"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="javascript:hidePopup()" class="btn-operations">Ok</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="edit-device-modal-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">
|
||||
Please enter a new name for the device.
|
||||
</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i
|
||||
class="fw fw-cancel"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
<input id="edit-device-name" style="color:#3f3f3f;padding:5px" type="text"
|
||||
value=""
|
||||
placeholder="Type here" size="60">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="edit-device-yes-link" class="btn-operations">
|
||||
Rename
|
||||
</a>
|
||||
|
||||
<a href="#" id="edit-device-cancel-link" class="btn-operations">
|
||||
Cancel
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="edit-device-200-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">
|
||||
Device was successfully updated.
|
||||
</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i
|
||||
class="fw fw-cancel"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
|
||||
<div id="edit-device-200-content" class="hide">
|
||||
<div class="content">
|
||||
<div class="row">
|
||||
<div class="col-lg-5 col-md-6 col-centered">
|
||||
<h3>Device was successfully updated.</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="enrolled-device-delete-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">Could not delete devices since some are still
|
||||
enrolled.</h3>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="enrolled-device-delete-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="device-400-content" class="hide">
|
||||
<div class="modal-content">
|
||||
<div class="row">
|
||||
<div class="col-lg-5 col-md-6 col-centered">
|
||||
<h3>Exception at backend. Try Later.</h3>
|
||||
<br/>
|
||||
<div class="buttons">
|
||||
<a href="#" id="device-400-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="device-403-content" class="hide">
|
||||
<div class="modal-content">
|
||||
<div class="row">
|
||||
<div class="col-lg-5 col-md-6 col-centered">
|
||||
<h3>Operation not permitted.</h3>
|
||||
<br/>
|
||||
<div class="buttons">
|
||||
<a href="#" id="device-403-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="group-404-content" class="hide">
|
||||
<div class="modal-content">
|
||||
<div class="row">
|
||||
<div class="col-lg-5 col-md-6 col-centered">
|
||||
<h3>
|
||||
You don't have any device group to add this device. Let's add a new
|
||||
device group!</h3>
|
||||
<br/>
|
||||
<div class="buttons">
|
||||
<a href="{{@app.context}}/group/add" class="btn-operations">
|
||||
Add New Group
|
||||
</a>
|
||||
|
||||
<a href="#" id="cancel-link" class="btn-operations">
|
||||
Cancel
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="device-409-content" class="hide">
|
||||
<div class="modal-content">
|
||||
<div class="row">
|
||||
<div class="col-lg-5 col-md-6 col-centered">
|
||||
<h3>Device does not exist.</h3>
|
||||
<br/>
|
||||
<div class="buttons">
|
||||
<a href="#" id="remove-device-409-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="no-device-selected" class="hide">
|
||||
<div class="modal-content">
|
||||
<div class="row">
|
||||
<div class="col-lg-5 col-md-6 col-centered">
|
||||
<h3>Please select one or more devices in order to perform this
|
||||
operation.</h3>
|
||||
<br/>
|
||||
<div class="buttons">
|
||||
<a href="#" id="no-device-selected-link" class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="multiple-device-types-selected" class="hide">
|
||||
<div class="modal-content">
|
||||
<div class="row">
|
||||
<div class="col-lg-5 col-md-6 col-centered">
|
||||
<h3>Adding operations to devices of multiple device types is not supported.
|
||||
Please select one or more devices in the same device type.</h3>
|
||||
<br/>
|
||||
<div class="buttons">
|
||||
<a href="#" id="multiple-device-types-selected-link"
|
||||
class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="no-features-available" class="hide">
|
||||
<div class="modal-content">
|
||||
<div class="row">
|
||||
<div class="col-lg-5 col-md-6 col-centered">
|
||||
<h3>No compatible operations are available for the selected device type.</h3>
|
||||
<br/>
|
||||
<div class="buttons">
|
||||
<a href="#" id="no-features-available-selected-link"
|
||||
class="btn-operations">
|
||||
Ok
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--update enrollment modal-->
|
||||
<div id="update-enrollment-modal-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">
|
||||
Please enter the username to update the enrollment device(s).
|
||||
</h3>
|
||||
<div id="update-enrollment-error-content" class="pull-left modal-title hidden"
|
||||
style="color: #d9534f;">
|
||||
<strong>
|
||||
<span><i class="fw fw-error"></i></span>
|
||||
<div id="update-enrollment-error-msg" style="display: inline">
|
||||
</div>
|
||||
</strong>
|
||||
</div>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i
|
||||
class="fw fw-cancel"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
<input id="update-enrollment-name" style="color:#3f3f3f;padding:5px;" type="text"
|
||||
placeholder="[ username ]" size="60" required>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="#" id="update-enrollment-yes-link" class="btn-operations">
|
||||
Update
|
||||
</a>
|
||||
<a href="#" id="update-enrollment-cancel-link" class="btn-operations">
|
||||
Cancel
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="update-enrollment-200-content" class="hide">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">
|
||||
Successfully updated enrollment.
|
||||
</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i
|
||||
class="fw fw-cancel"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="buttons">
|
||||
<a href="javascript:hidePopup()" class="btn-operations">Ok</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--/update enrollment modal-->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "bottomJs"}}
|
||||
<script id="device-listing" data-server-url="{{serverUrl}}" data-current-user="{{@user.username}}" data-device-types="{{deviceTypes}}"
|
||||
data-portal-url="{{portalUrl}}" data-user-domain="{{userDomain}}" data-api-context="{{apiContext}}" type="text/x-handlebars-template"></script>
|
||||
{{js "js/listing.js"}}
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "topCss"}}
|
||||
<style>
|
||||
.select2-dropdown {
|
||||
z-index: 999999999;
|
||||
}
|
||||
|
||||
.wr-input-control {
|
||||
color: black;
|
||||
}
|
||||
|
||||
.select2-selection__choice {
|
||||
font-size: medium;
|
||||
}
|
||||
</style>
|
||||
{{/zone}}
|
||||
@ -1,109 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 userModule = require("/app/modules/business-controllers/user.js")["userModule"];
|
||||
var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
|
||||
var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"];
|
||||
|
||||
var groupId = request.getParameter("groupId");
|
||||
|
||||
var viewModel = {};
|
||||
var title = "Devices";
|
||||
if (groupId) {
|
||||
var group = groupModule.getGroup(groupId);
|
||||
if (group) {
|
||||
title = group.name + " " + title;
|
||||
viewModel.roles = groupModule.getRolesOfGroup(groupId);
|
||||
viewModel.group = group;
|
||||
}
|
||||
}
|
||||
viewModel.title = title;
|
||||
var currentUser = session.get(constants.USER_SESSION_KEY);
|
||||
if (currentUser) {
|
||||
viewModel.permissions = {};
|
||||
var uiPermissions = userModule.getUIPermissions();
|
||||
viewModel.permissions.list = stringify(uiPermissions);
|
||||
if (uiPermissions.ADD_DEVICE) {
|
||||
viewModel.permissions.enroll = true;
|
||||
}
|
||||
if (uiPermissions.UPDATE_ENROLLMENT) {
|
||||
viewModel.permissions.updateEnrollment = true;
|
||||
}
|
||||
if (uiPermissions.PERMANENT_DELETE) {
|
||||
viewModel.permissions.permanentDelete = true;
|
||||
}
|
||||
viewModel.currentUser = currentUser;
|
||||
var deviceCount = 0;
|
||||
if (groupId) {
|
||||
deviceCount = groupModule.getGroupDeviceCount(groupId);
|
||||
} else {
|
||||
deviceCount = deviceModule.getDevicesCount();
|
||||
}
|
||||
if (deviceCount > 0) {
|
||||
viewModel.deviceCount = deviceCount;
|
||||
var utility = require("/app/modules/utility.js").utility;
|
||||
var typesListResponse = deviceModule.getDeviceTypes();
|
||||
var deviceTypes = [];
|
||||
if (typesListResponse["status"] == "success") {
|
||||
var data = typesListResponse.content;
|
||||
if (data) {
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var config = utility.getDeviceTypeConfig(data[i].name);
|
||||
var category = "iot";
|
||||
var label = data[i].name;
|
||||
var analyticsEnabled = "false";
|
||||
var groupingEnabled = "true";
|
||||
var analyticsView = null;
|
||||
if (config) {
|
||||
var deviceType = config.deviceType;
|
||||
category = deviceType.category;
|
||||
label = deviceType.label;
|
||||
analyticsEnabled = deviceType.analyticsEnabled;
|
||||
groupingEnabled = deviceType.groupingEnabled;
|
||||
analyticsView = deviceType.analyticsView;
|
||||
}
|
||||
|
||||
deviceTypes.push({
|
||||
"type": data[i].name,
|
||||
"category": category,
|
||||
"label": label,
|
||||
"thumb": utility.getDeviceThumb(data[i].name),
|
||||
"analyticsEnabled": analyticsEnabled,
|
||||
"groupingEnabled": groupingEnabled,
|
||||
"analyticsView" : analyticsView
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
viewModel.deviceTypes = stringify(deviceTypes);
|
||||
}
|
||||
}
|
||||
|
||||
var mdmProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var serverUrl = mdmProps["httpsURL"];
|
||||
var portalUrl = mdmProps["portalURL"];
|
||||
var backendRestEndpoints = mdmProps["backendRestEndpoints"];
|
||||
var userDomain = context.user.domain;
|
||||
viewModel.serverUrl = serverUrl;
|
||||
viewModel.portalUrl = portalUrl;
|
||||
viewModel.userDomain = userDomain;
|
||||
viewModel.apiContext = backendRestEndpoints["deviceMgt"];
|
||||
return viewModel;
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"uri": "/devices",
|
||||
"layout": "cdmf.layout.default"
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,264 +0,0 @@
|
||||
{{!
|
||||
Copyright (c) 2017, 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.
|
||||
}}
|
||||
{{unit "cdmf.unit.ui.title" pageTitle="Device Type Management"}}
|
||||
|
||||
{{#zone "topCss"}}
|
||||
{{css "css/devicetype.css"}}
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "breadcrumbs"}}
|
||||
<li>
|
||||
<a href="{{@app.context}}/">
|
||||
<i class="icon fw fw-home"></i>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
<a href="{{@app.context}}/device-types">
|
||||
Device Types
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
<a href="{{@app.context}}/device-type/add">
|
||||
Add
|
||||
</a>
|
||||
</li>
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "content"}}
|
||||
{{#if canManage}}
|
||||
<!-- content/body -->
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<!-- content -->
|
||||
<div id="devicetype-create-form" class="container col-centered wr-content">
|
||||
<div class="wr-form">
|
||||
<p class="page-sub-title">Create Device Type</p>
|
||||
<hr/>
|
||||
<div class="">
|
||||
<div class="wr-steps">
|
||||
<div class="col-md-6 col-xs-6">
|
||||
<div class="itm-wiz itm-wiz-current" data-step="policy-platform">
|
||||
<div class="wiz-no">1</div>
|
||||
<div class="wiz-lbl hidden-xs"><span>Create Device Type</span></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6 col-xs-6">
|
||||
<div class="itm-wiz" data-step="policy-profile">
|
||||
<div class="wiz-no">2</div>
|
||||
<div class="wiz-lbl hidden-xs"><span>Create Device Event</span></div>
|
||||
</div>
|
||||
</div>
|
||||
<br class="c-both"/>
|
||||
</div>
|
||||
<br/><br/>
|
||||
<hr/>
|
||||
|
||||
<div id="devicetype-create-error-msg" class="alert alert-danger hidden" role="alert">
|
||||
<i class="icon fw fw-error"></i><span></span>
|
||||
</div>
|
||||
|
||||
|
||||
<label class="wr-input-label">
|
||||
Name *
|
||||
</label>
|
||||
<div class="wr-input-control">
|
||||
<input placeholder="E.g firealarm" aria-describedby="basic-addon1" type="text" id="deviceTypeName"
|
||||
data-error-msg="invalid device type name" class="form-control"/>
|
||||
</div>
|
||||
|
||||
<label class="wr-input-label">
|
||||
Description *
|
||||
</label>
|
||||
<div class="wr-input-control ">
|
||||
<textarea aria-describedby="basic-addon1" type="text" id="deviceTypeDescription"
|
||||
data-error-msg="invalid device type description"
|
||||
class="form-control" rows="3" cols="70"></textarea>
|
||||
</div>
|
||||
|
||||
<label class="wr-input-label">
|
||||
Push Notification Transport
|
||||
</label>
|
||||
<div class="wr-input-control">
|
||||
<select id="pushNotification" class="form-control select">
|
||||
<option>NONE</option>
|
||||
<option>MQTT</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<label class="wr-input-label" for="passcode-policy-min-length">
|
||||
Features (Definition of the operation from server to device)
|
||||
<span class="helper" title="E.g name: fire alarm range control, code: alarm, description: this controls the alarm sound type and range of firealarm">
|
||||
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<div class="form-group feature_field_wrapper" name="deviceFeature">
|
||||
<div class="row">
|
||||
<div class="col-xs-3">
|
||||
<input type="text" class="form-control" id="feature-name" placeholder="name"/>
|
||||
</div>
|
||||
<div class="col-xs-4">
|
||||
<input type="text" class="form-control" id="feature-code" placeholder="code"/>
|
||||
</div>
|
||||
<div class="col-xs-4">
|
||||
<textarea aria-describedby="basic-addon1" type="text" id="feature-description"
|
||||
placeholder="description"
|
||||
data-error-msg="invalid feature description"
|
||||
class="form-control" rows="1" cols="30"></textarea>
|
||||
</div>
|
||||
<button type="button" class="wr-btn wr-btn-horizontal add_feature_button"><i class="fa fa-plus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label class="wr-input-label" for="passcode-policy-min-length">
|
||||
Attributes
|
||||
<span class="helper" title="E.g vendor, model_number ...">
|
||||
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<div class="form-group attribute_field_wrapper">
|
||||
<div class="row">
|
||||
<div class="dontfloat">
|
||||
<div class="col-xs-3">
|
||||
<input type="text" class="form-control" name="attribute[]" />
|
||||
</div>
|
||||
<button type="button" class="wr-btn wr-btn-horizontal add_button"><i class="fa fa-plus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hidden-div">
|
||||
<div id="add-attribute-field" name="add-attribute-field">
|
||||
<div class="row">
|
||||
<div class="dontfloat feature-wrapper">
|
||||
<div class="col-xs-3">
|
||||
<input type="text" class="form-control" name="attribute[]" />
|
||||
</div>
|
||||
<button type="button" class="wr-btn wr-btn-horizontal wr-btn-secondary remove_button"><i class="fa fa-minus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--Commenting enrollment operation capability-->
|
||||
<!--<label class="wr-input-label" for="passcode-policy-min-length">-->
|
||||
<!--Enrolment Operation-->
|
||||
<!--<span class="helper" title="Triggers the operation after the enrolment, E.g alarm">-->
|
||||
<!--<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>-->
|
||||
<!--</span>-->
|
||||
<!--</label>-->
|
||||
|
||||
<div class="form-group operation_field_wrapper hidden-div">
|
||||
<div class="row">
|
||||
<div class="dontfloat">
|
||||
<div class="col-xs-3">
|
||||
<input type="text" class="form-control" name="operation[]" />
|
||||
</div>
|
||||
<button type="button" class="wr-btn wr-btn-horizontal add_operation_button"><i class="fa fa-plus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hidden-div">
|
||||
<div id="add-operation-field" name="add-operation-field">
|
||||
<div class="row">
|
||||
<div class="dontfloat feature-wrapper">
|
||||
<div class="col-xs-3">
|
||||
<input type="text" class="form-control" name="operation[]" />
|
||||
</div>
|
||||
<button type="button" class="wr-btn wr-btn-horizontal wr-btn-secondary remove_operation_button"><i class="fa fa-minus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<span class="roleNameError hidden glyphicon glyphicon-remove form-control-feedback"></span>
|
||||
<label class="error roleNameEmpty hidden" for="summary">
|
||||
Device Type Name is required, should be in minimum 3 characters long and not include any
|
||||
whitespaces or "@" character or "/" character.
|
||||
</label>
|
||||
|
||||
</div>
|
||||
|
||||
<br>
|
||||
<button id="add-devicetype-btn" class="wr-btn">Add Device Type</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="devicetype-created-msg" class="container col-centered wr-content hidden">
|
||||
<div class="wr-form">
|
||||
<p class="page-sub-title">Devicetype was added successfully.</p>
|
||||
<b>"View Device Type List"</b> to complete the process and go back to the devie type list.
|
||||
<hr/>
|
||||
<button class="wr-btn" onclick="window.location.href='{{@app.context}}/device-types'">
|
||||
View Device Type List
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- modal -->
|
||||
<div class="modal fade" id="modalDevice" tabindex="-1" role="dialog" aria-labelledby="modalDevice">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content clearfix">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
<h3 class="modal-title" id="deviceModalLabel">Device Type Updated</h3>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
<p>One fine body…</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-primary">Go To Enrolment Page</button>
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal fade" id="modalDeviceFailed" tabindex="-1" role="dialog" aria-labelledby="modalDeviceFailed">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content clearfix">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
<h3 class="modal-title" id="deviceModalLabel">Device Type Update Failed</h3>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
<p>One fine body…</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /modal -->
|
||||
<!-- /content -->
|
||||
<div id="app-context" data-app-context="{{@app.context}}" class="hidden"></div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /content/body -->
|
||||
{{else}}
|
||||
<h1 class="page-sub-title">
|
||||
Permission Denied
|
||||
</h1>
|
||||
<br>
|
||||
You not authorized to create device type.
|
||||
<br>
|
||||
{{/if}}
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "bottomJs"}}
|
||||
{{js "js/bottomJs.js"}}
|
||||
{{/zone}}
|
||||
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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/business-controllers/user.js")["userModule"];
|
||||
var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var displayData = {};
|
||||
|
||||
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/device-type")) {
|
||||
displayData.canManage = true;
|
||||
}
|
||||
|
||||
return displayData;
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"uri": "/device-type/add",
|
||||
"layout": "cdmf.layout.default"
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
.wr-btn-horizontal{
|
||||
padding: 7px 10px;
|
||||
}
|
||||
|
||||
.dontfloat {
|
||||
clear:both;
|
||||
}
|
||||
|
||||
.hidden-div {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.feature-wrapper{
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.wr-btn-secondary{
|
||||
background-color: #617d8b;
|
||||
}
|
||||
@ -1,243 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks if provided input is valid against RegEx input.
|
||||
*
|
||||
* @param regExp Regular expression
|
||||
* @param inputString Input string to check
|
||||
* @returns {boolean} Returns true if input matches RegEx
|
||||
*/
|
||||
function inputIsValid(regExp, inputString) {
|
||||
regExp = new RegExp(regExp);
|
||||
return regExp.test(inputString);
|
||||
}
|
||||
|
||||
var validateInline = {};
|
||||
var clearInline = {};
|
||||
|
||||
var apiBasePath = "/api/device-mgt/v1.0";
|
||||
|
||||
|
||||
var enableInlineError = function (inputField, errorMsg, errorSign) {
|
||||
var fieldIdentifier = "#" + inputField;
|
||||
var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
|
||||
var errorSignIdentifier = "#" + inputField + " ." + errorSign;
|
||||
|
||||
if (inputField) {
|
||||
$(fieldIdentifier).addClass(" has-error has-feedback");
|
||||
}
|
||||
|
||||
if (errorMsg) {
|
||||
$(errorMsgIdentifier).removeClass(" hidden");
|
||||
}
|
||||
|
||||
if (errorSign) {
|
||||
$(errorSignIdentifier).removeClass(" hidden");
|
||||
}
|
||||
};
|
||||
|
||||
var disableInlineError = function (inputField, errorMsg, errorSign) {
|
||||
var fieldIdentifier = "#" + inputField;
|
||||
var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
|
||||
var errorSignIdentifier = "#" + inputField + " ." + errorSign;
|
||||
|
||||
if (inputField) {
|
||||
$(fieldIdentifier).removeClass(" has-error has-feedback");
|
||||
}
|
||||
|
||||
if (errorMsg) {
|
||||
$(errorMsgIdentifier).addClass(" hidden");
|
||||
}
|
||||
|
||||
if (errorSign) {
|
||||
$(errorSignIdentifier).addClass(" hidden");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
function formatRepo(user) {
|
||||
if (user.loading) {
|
||||
return user.text
|
||||
}
|
||||
if (!user.username) {
|
||||
return;
|
||||
}
|
||||
var markup = '<div class="clearfix">' +
|
||||
'<div class="col-sm-8">' +
|
||||
'<div class="clearfix">' +
|
||||
'<div class="col-sm-4">' + user.username + '</div>';
|
||||
if (user.name || user.name != undefined) {
|
||||
markup += '<div class="col-sm-8"> ( ' + user.name + ' )</div>';
|
||||
}
|
||||
markup += '</div></div></div>';
|
||||
return markup;
|
||||
}
|
||||
|
||||
function formatRepoSelection(user) {
|
||||
return user.username || user.text;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
var appContext = $("#app-context").data("app-context");
|
||||
|
||||
var maxField = 100; //Input fields increment limitation
|
||||
var addButton = $('.add_button'); //Add button selector
|
||||
var wrapper = $('.attribute_field_wrapper'); //Input field wrapper
|
||||
var fieldHTML = $('#add-attribute-field').html(); //New input field html
|
||||
$(addButton).click(function(){ //Once add button is clicked
|
||||
$(wrapper).append(fieldHTML); // Add field html
|
||||
});
|
||||
$(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked
|
||||
e.preventDefault();
|
||||
$(this).parent('div').remove();
|
||||
});
|
||||
|
||||
var addOperationButton = $('.add_operation_button'); //Add button selector
|
||||
var operationWrapper = $('.operation_field_wrapper'); //Input field wrapper
|
||||
var operationFieldHTML = $('#add-operation-field').html(); //New input field html
|
||||
$(addOperationButton).click(function(){ //Once add button is clicked
|
||||
$(operationWrapper).append(operationFieldHTML); // Add field html
|
||||
});
|
||||
$(operationWrapper).on('click', '.remove_operation_button', function(e){ //Once remove button is clicked
|
||||
e.preventDefault();
|
||||
$(this).parent('div').remove();
|
||||
});
|
||||
|
||||
|
||||
var addFeatureButton = $('.add_feature_button'); //Add button selector
|
||||
var featureWrapper = $('.feature_field_wrapper'); //Input field wrapper
|
||||
$(addFeatureButton).click(function(){ //Once add button is clicked
|
||||
var featureFieldHtml = '<div class="row"><div class="dontfloat feature-wrapper" name ="deviceFeature"> <div class="col-xs-3"> <input type="text"' +
|
||||
' class="form-control" id="feature-name" placeholder="name"/> </div> <div class="col-xs-4"> ' +
|
||||
'<input type="text" class="form-control" id="feature-code" placeholder="code"/> </div> ' +
|
||||
'<div class="col-xs-4"> <textarea aria-describedby="basic-addon1" type="text" ' +
|
||||
'id="feature-description" placeholder="description"data-error-msg="invalid ' +
|
||||
'feature description"class="form-control" rows="1" cols="30"></textarea> </div> ' +
|
||||
'<button type="button" class="wr-btn wr-btn-horizontal wr-btn-secondary remove_feature_button"><i class="fa fa-minus"></i></button> </div></div>'
|
||||
$(featureWrapper).append(featureFieldHtml); // Add field html
|
||||
});
|
||||
$(featureWrapper).on('click', '.remove_feature_button', function(e){ //Once remove button is clicked
|
||||
e.preventDefault();
|
||||
$(this).parent('div').remove(); //Remove field html
|
||||
});
|
||||
|
||||
/**
|
||||
* Following click function would execute
|
||||
* when a user clicks on "Add Device type" button.
|
||||
*/
|
||||
$("button#add-devicetype-btn").click(function () {
|
||||
|
||||
var errorMsgWrapper = "#devicetype-create-error-msg";
|
||||
var errorMsg = "#devicetype-create-error-msg span";
|
||||
var deviceType = {};
|
||||
var deviceTypeName = $("#deviceTypeName").val();
|
||||
var deviceTypeDescription = $("#deviceTypeDescription").val();
|
||||
if (!deviceTypeName || deviceTypeName.trim() == "" ) {
|
||||
$(errorMsg).text("Device Type Name Cannot be empty.");
|
||||
$(errorMsgWrapper).removeClass("hidden");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!deviceTypeDescription || deviceTypeDescription.trim() == "" ) {
|
||||
$(errorMsg).text("Device Type Description Cannot be empty.");
|
||||
$(errorMsgWrapper).removeClass("hidden");
|
||||
return
|
||||
}
|
||||
|
||||
deviceType.name = deviceTypeName.trim();
|
||||
deviceType.deviceTypeMetaDefinition = {}
|
||||
deviceType.deviceTypeMetaDefinition.description = deviceTypeDescription.trim();
|
||||
|
||||
var pushNotification = $("#pushNotification").val();
|
||||
if (pushNotification != "NONE") {
|
||||
deviceType.deviceTypeMetaDefinition.pushNotificationConfig = {};
|
||||
deviceType.deviceTypeMetaDefinition.pushNotificationConfig.scheduled = true;
|
||||
deviceType.deviceTypeMetaDefinition.pushNotificationConfig.type = pushNotification;
|
||||
}
|
||||
|
||||
var propertyValues = [];
|
||||
$('input[name^="attribute"]').each(function() {
|
||||
var propertyValue = $(this).val();
|
||||
if (propertyValue.trim() != "") {
|
||||
propertyValues.push(propertyValue.trim());
|
||||
}
|
||||
});
|
||||
deviceType.deviceTypeMetaDefinition.properties = propertyValues;
|
||||
|
||||
var operationValues = [];
|
||||
$('input[name^="operation"]').each(function() {
|
||||
var operationValue = $(this).val();
|
||||
if (operationValue.trim() != "") {
|
||||
operationValues.push(operationValue.trim());
|
||||
}
|
||||
});
|
||||
if (operationValues.length > 0) {
|
||||
deviceType.deviceTypeMetaDefinition.initialOperationConfig = {};
|
||||
deviceType.deviceTypeMetaDefinition.initialOperationConfig.operations = operationValues;
|
||||
}
|
||||
|
||||
var features = [];
|
||||
$('div[name^="deviceFeature"]').each(function() {
|
||||
var featureName = $(this).find("#feature-name").val();
|
||||
var featureCode = $(this).find("#feature-code").val();
|
||||
var featureDescription = $(this).find("#feature-description").val();
|
||||
if (featureName && featureName.trim() != "" && featureCode && featureCode.trim() != "") {
|
||||
var feature = {};
|
||||
feature.name = featureName.trim();
|
||||
feature.code = featureCode.trim();
|
||||
feature.description = featureDescription.trim();
|
||||
features.push(feature);
|
||||
}
|
||||
});
|
||||
deviceType.deviceTypeMetaDefinition.features = features;
|
||||
|
||||
var addRoleAPI = apiBasePath + "/admin/device-types";
|
||||
|
||||
invokerUtil.post(
|
||||
addRoleAPI,
|
||||
deviceType,
|
||||
function (data, textStatus, jqXHR) {
|
||||
if (jqXHR.status == 200) {
|
||||
window.location.href = appContext + "/device-type/edit-event?type=" +
|
||||
encodeURIComponent(deviceTypeName);
|
||||
}
|
||||
},
|
||||
function (jqXHR) {
|
||||
if (jqXHR.status == 500) {
|
||||
$(errorMsg).text("Unexpected error.");
|
||||
$(errorMsgWrapper).removeClass("hidden");
|
||||
}
|
||||
if (jqXHR.status == 400) {
|
||||
$(errorMsg).text("Device type name should not contain whitespaces.");
|
||||
$(errorMsgWrapper).removeClass("hidden");
|
||||
}
|
||||
|
||||
if (jqXHR.status == 409) {
|
||||
$(errorMsg).text("Device type already exists");
|
||||
$(errorMsgWrapper).removeClass("hidden");
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
@ -1,272 +0,0 @@
|
||||
{{!
|
||||
Copyright (c) 2017, 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.
|
||||
}}
|
||||
{{unit "cdmf.unit.ui.title" pageTitle="Device Type Management"}}
|
||||
|
||||
{{#zone "topCss"}}
|
||||
{{css "css/devicetype.css"}}
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "breadcrumbs"}}
|
||||
<li>
|
||||
<a href="{{@app.context}}/">
|
||||
<i class="icon fw fw-home"></i>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
<a href="{{@app.context}}/device-types">
|
||||
Device Types
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
<a href="{{@app.context}}/device-type/edit?type={{name}}">
|
||||
Edit
|
||||
</a>
|
||||
</li>
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "content"}}
|
||||
{{#if canManage}}
|
||||
<!-- content/body -->
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<!-- content -->
|
||||
<div id="devicetype-create-form" class="container col-centered wr-content">
|
||||
<div class="wr-form">
|
||||
<p class="page-sub-title">{{name}}</p>
|
||||
<hr/>
|
||||
<div class="row">
|
||||
<div class="col-lg-8">
|
||||
<div id="devicetype-create-error-msg" class="alert alert-danger hidden" role="alert">
|
||||
<i class="icon fw fw-error"></i><span></span>
|
||||
</div>
|
||||
<br>
|
||||
<input aria-describedby="basic-addon1" type="text" id="deviceTypeName"
|
||||
data-error-msg="invalid device type name" class="form-control hidden-input" value="{{name}}"/>
|
||||
|
||||
<div class="wr-input-control">
|
||||
<label class="wr-input-label">
|
||||
Description *
|
||||
</label>
|
||||
<br>
|
||||
<textarea aria-describedby="basic-addon1" type="text" id="deviceTypeDescription"
|
||||
data-error-msg="invalid device type description"
|
||||
class="form-control" rows="3" cols="70">{{type.deviceTypeMetaDefinition.description}}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="wr-input-control">
|
||||
<label class="wr-input-label">Push Notification Transport</label>
|
||||
<div class="wr-input-control">
|
||||
<!--suppress HtmlFormInputWithoutLabel -->
|
||||
<select id="pushNotification" class="form-control select">
|
||||
{{#if type.deviceTypeMetaDefinition.pushNotificationConfig}}
|
||||
<option>NONE</option>
|
||||
{{#if_eq type.deviceTypeMetaDefinition.pushNotificationConfig.type "MQTT"}}
|
||||
<option selected>MQTT</option>
|
||||
{{/if_eq}}
|
||||
{{else}}
|
||||
<option selected>NONE</option>
|
||||
<option>MQTT</option>
|
||||
{{/if}}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label class="wr-input-label">
|
||||
Features
|
||||
</label>
|
||||
<br>
|
||||
<div class="form-group feature_field_wrapper">
|
||||
{{#if type.deviceTypeMetaDefinition.features}}
|
||||
{{#each type.deviceTypeMetaDefinition.features}}
|
||||
<div class="row">
|
||||
<div class="dontfloat feature-wrapper" name ="deviceFeature">
|
||||
<div class="col-xs-3">
|
||||
<input type="text" class="form-control feature-name" placeholder="name" value="{{this.name}}"/>
|
||||
</div>
|
||||
<div class="col-xs-4">
|
||||
<input type="text" class="form-control feature-code" placeholder="code" value="{{this.code}}"/>
|
||||
</div>
|
||||
<div class="col-xs-4">
|
||||
<textarea aria-describedby="basic-addon1" type="text"
|
||||
placeholder="description" data-error-msg="invalid feature description"
|
||||
class="form-control feature-description" rows="1" cols="30">{{this.description}}</textarea>
|
||||
</div>
|
||||
<button type="button" class="wr-btn wr-btn-horizontal remove_feature_button"><i class="fa fa-minus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
<div class="row">
|
||||
<div class="dontfloat feature-wrapper" name="deviceFeature">
|
||||
<div class="col-xs-3">
|
||||
<input type="text" class="form-control feature-name" placeholder="name"/>
|
||||
</div>
|
||||
<div class="col-xs-4">
|
||||
<input type="text" class="form-control feature-code" placeholder="code"/>
|
||||
</div>
|
||||
<div class="col-xs-4">
|
||||
<textarea aria-describedby="basic-addon1" type="text"
|
||||
placeholder="description"
|
||||
data-error-msg="invalid feature description"
|
||||
class="form-control feature-description" rows="1" cols="30"></textarea>
|
||||
</div>
|
||||
<button type="button" class="wr-btn wr-btn-horizontal add_feature_button"><i class="fa fa-plus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
<label class="wr-input-label">
|
||||
Attributes
|
||||
</label>
|
||||
<br>
|
||||
<div class="form-group attribute_field_wrapper">
|
||||
{{#if type.deviceTypeMetaDefinition.properties}}
|
||||
{{#each type.deviceTypeMetaDefinition.properties}}
|
||||
<div class="row">
|
||||
<div class="dontfloat">
|
||||
<div class="col-xs-3">
|
||||
<input type="text" class="form-control" name="attribute[]" value="{{this}}" />
|
||||
</div>
|
||||
<button type="button" class="wr-btn wr-btn-horizontal wr-btn-secondary remove_button"><i class="fa fa-minus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
<div class="row">
|
||||
<div class="dontfloat feature-wrapper">
|
||||
<div class="col-xs-3">
|
||||
<input type="text" class="form-control" name="attribute[]" />
|
||||
</div>
|
||||
<button type="button" class="wr-btn wr-btn-horizontal add_button"><i class="fa fa-plus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hidden-div">
|
||||
<div id="add-attribute-field" name="add-attribute-field">
|
||||
<div class="row">
|
||||
<div class="dontfloat feature-wrapper">
|
||||
<div class="col-xs-3">
|
||||
<input type="text" class="form-control" name="attribute[]" />
|
||||
</div>
|
||||
<button type="button" class="wr-btn wr-btn-horizontal wr-btn-secondary remove_button"><i class="fa fa-minus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--<label class="wr-input-label">-->
|
||||
<!--Enrolment Operation-->
|
||||
<!--</label>-->
|
||||
<!--<br>-->
|
||||
|
||||
<div class="form-group operation_field_wrapper hidden-div">
|
||||
{{#if type.deviceTypeMetaDefinition.initialOperationConfig}}
|
||||
{{#each type.deviceTypeMetaDefinition.initialOperationConfig.operations}}
|
||||
<div class="row">
|
||||
<div class="dontfloat feature-wrapper">
|
||||
<div class="col-xs-3">
|
||||
<input type="text" class="form-control" name="operation[]" value="{{this}}"/>
|
||||
</div>
|
||||
<button type="button" class="wr-btn wr-btn-horizontal wr-btn-secondary remove_operation_button"><i class="fa fa-minus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
<div class="row">
|
||||
<div class="dontfloat feature-wrapper">
|
||||
<div class="col-xs-3">
|
||||
<input type="text" class="form-control" name="operation[]" />
|
||||
</div>
|
||||
<button type="button" class="wr-btn wr-btn-horizontal add_operation_button"><i class="fa fa-plus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hidden-div">
|
||||
<div id="add-operation-field" name="add-operation-field">
|
||||
<div class="row">
|
||||
<div class="dontfloat feature-wrapper">
|
||||
<div class="col-xs-3">
|
||||
<input type="text" class="form-control" name="operation[]" />
|
||||
</div>
|
||||
<button type="button" class="wr-btn wr-btn-horizontal wr-btn-secondary remove_operation_button"><i class="fa fa-minus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<span class="roleNameError hidden glyphicon glyphicon-remove form-control-feedback"></span>
|
||||
<label class="error roleNameEmpty hidden" for="summary">
|
||||
Device Type Name is required, should be in minimum 3 characters long and not include any
|
||||
whitespaces or "@" character or "/" character.
|
||||
</label>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<br>
|
||||
<button id="edit-devicetype-btn" class="wr-btn">Update</button>
|
||||
<div id="devicetype-create-success-msg" class="alert hidden" role="alert">
|
||||
<i class="icon fw fw-success"></i><span></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="devicetype-created-msg" class="container col-centered wr-content hidden">
|
||||
<div class="wr-form">
|
||||
<p class="page-sub-title">Devicetype was added successfully.</p>
|
||||
<b>"View Device Type List"</b> to complete the process and go back to the devie type list.
|
||||
<hr/>
|
||||
<button class="wr-btn" onclick="window.location.href='{{@app.context}}/device-types'">
|
||||
View Device Type List
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal fade" id="modalDevice" tabindex="-1" role="dialog" aria-labelledby="modalDevice">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content clearfix">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
<h3 class="modal-title" id="deviceModalLabel">Device Type Definition Updated</h3>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-primary" onclick="location.href='{{@app.context}}/device/enroll'">Go To Enrolment Page</button>
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /content -->
|
||||
<div id="app-context" data-app-context="{{@app.context}}" class="hidden"></div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /content/body -->
|
||||
{{else}}
|
||||
<h1 class="page-sub-title">
|
||||
Permission Denied
|
||||
</h1>
|
||||
<br>
|
||||
You not authorized to edit device type.
|
||||
<br>
|
||||
{{/if}}
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "bottomJs"}}
|
||||
{{js "js/bottomJs.js"}}
|
||||
{{/zone}}
|
||||
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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/business-controllers/user.js")["userModule"];
|
||||
var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var displayData = {};
|
||||
|
||||
|
||||
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/device-type")) {
|
||||
displayData.canManage = true;
|
||||
}
|
||||
context.handlebars.registerHelper('if_eq', function(a, b, opts) {
|
||||
if(a == b) // Or === depending on your needs
|
||||
return opts.fn(this);
|
||||
else
|
||||
return opts.inverse(this);
|
||||
});
|
||||
|
||||
var deviceType = request.getParameter("type");
|
||||
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
|
||||
var restAPIEndpoint = deviceMgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"]
|
||||
+ "/device-types/" + deviceType;
|
||||
displayData.name = deviceType;
|
||||
serviceInvokers.XMLHttp.get(
|
||||
restAPIEndpoint,
|
||||
function (restAPIResponse) {
|
||||
if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) {
|
||||
var typeData = parse(restAPIResponse["responseText"]);
|
||||
displayData.type = typeData;
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return displayData;
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"uri": "/device-type/edit",
|
||||
"layout": "cdmf.layout.default"
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
.wr-btn-horizontal{
|
||||
padding: 7px 10px;
|
||||
}
|
||||
|
||||
.dontfloat {
|
||||
clear:both;
|
||||
}
|
||||
|
||||
.hidden-div {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.hidden-input {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.feature-wrapper{
|
||||
margin-top: 10px;
|
||||
}
|
||||
.wr-btn-secondary{
|
||||
background-color: #617d8b;
|
||||
}
|
||||
.wr-btn-secondary{
|
||||
background-color: #617d8b;
|
||||
}
|
||||
@ -1,257 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks if provided input is valid against RegEx input.
|
||||
*
|
||||
* @param regExp Regular expression
|
||||
* @param inputString Input string to check
|
||||
* @returns {boolean} Returns true if input matches RegEx
|
||||
*/
|
||||
function inputIsValid(regExp, inputString) {
|
||||
regExp = new RegExp(regExp);
|
||||
return regExp.test(inputString);
|
||||
}
|
||||
|
||||
var validateInline = {};
|
||||
var clearInline = {};
|
||||
|
||||
var apiBasePath = "/api/device-mgt/v1.0";
|
||||
var domain = $("#domain").val();
|
||||
|
||||
|
||||
var enableInlineError = function (inputField, errorMsg, errorSign) {
|
||||
var fieldIdentifier = "#" + inputField;
|
||||
var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
|
||||
var errorSignIdentifier = "#" + inputField + " ." + errorSign;
|
||||
|
||||
if (inputField) {
|
||||
$(fieldIdentifier).addClass(" has-error has-feedback");
|
||||
}
|
||||
|
||||
if (errorMsg) {
|
||||
$(errorMsgIdentifier).removeClass(" hidden");
|
||||
}
|
||||
|
||||
if (errorSign) {
|
||||
$(errorSignIdentifier).removeClass(" hidden");
|
||||
}
|
||||
};
|
||||
|
||||
var disableInlineError = function (inputField, errorMsg, errorSign) {
|
||||
var fieldIdentifier = "#" + inputField;
|
||||
var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
|
||||
var errorSignIdentifier = "#" + inputField + " ." + errorSign;
|
||||
|
||||
if (inputField) {
|
||||
$(fieldIdentifier).removeClass(" has-error has-feedback");
|
||||
}
|
||||
|
||||
if (errorMsg) {
|
||||
$(errorMsgIdentifier).addClass(" hidden");
|
||||
}
|
||||
|
||||
if (errorSign) {
|
||||
$(errorSignIdentifier).addClass(" hidden");
|
||||
}
|
||||
};
|
||||
|
||||
function formatRepo(user) {
|
||||
if (user.loading) {
|
||||
return user.text
|
||||
}
|
||||
if (!user.username) {
|
||||
return;
|
||||
}
|
||||
var markup = '<div class="clearfix">' +
|
||||
'<div class="col-sm-8">' +
|
||||
'<div class="clearfix">' +
|
||||
'<div class="col-sm-4">' + user.username + '</div>';
|
||||
if (user.name || user.name != undefined) {
|
||||
markup += '<div class="col-sm-8"> ( ' + user.name + ' )</div>';
|
||||
}
|
||||
markup += '</div></div></div>';
|
||||
return markup;
|
||||
}
|
||||
|
||||
function formatRepoSelection(user) {
|
||||
return user.username || user.text;
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
var appContext = $("#app-context").data("app-context");
|
||||
|
||||
var addButton = $('.add_button'); //Add button selector
|
||||
var wrapper = $('.attribute_field_wrapper'); //Input field wrapper
|
||||
var fieldHTML = $('#add-attribute-field').html(); //New input field html
|
||||
$(addButton).click(function(){ //Once add button is clicked
|
||||
$(wrapper).append(fieldHTML); // Add field html
|
||||
});
|
||||
$(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked
|
||||
e.preventDefault();
|
||||
$(this).parent('div').remove(); //Remove field html
|
||||
});
|
||||
|
||||
var addOperationButton = $('.add_operation_button'); //Add button selector
|
||||
var operationWrapper = $('.operation_field_wrapper'); //Input field wrapper
|
||||
var operationFieldHTML = $('#add-operation-field').html(); //New input field html
|
||||
$(addOperationButton).click(function(){ //Once add button is clicked
|
||||
$(operationWrapper).append(operationFieldHTML); // Add field html
|
||||
});
|
||||
$(operationWrapper).on('click', '.remove_operation_button', function(e){ //Once remove button is clicked
|
||||
e.preventDefault();
|
||||
$(this).parent('div').remove();
|
||||
});
|
||||
|
||||
|
||||
var addFeatureButton = $('.add_feature_button'); //Add button selector
|
||||
var featureWrapper = $('.feature_field_wrapper'); //Input field wrapper
|
||||
$(addFeatureButton).click(function(){ //Once add button is clicked
|
||||
var featureFieldHtml = '<div class="row"><div class="dontfloat feature-wrapper" name ="deviceFeature"> ' +
|
||||
'<div class="col-xs-3"> <input type="text"' +
|
||||
' class="form-control feature-name" placeholder="name"/> </div> <div class="col-xs-4"> ' +
|
||||
'<input type="text" class="form-control feature-code" placeholder="code"/> </div> ' +
|
||||
'<div class="col-xs-4"> <textarea aria-describedby="basic-addon1" type="text" ' +
|
||||
'class="feature-description" placeholder="description"data-error-msg="invalid ' +
|
||||
'feature description" class="form-control" rows="1" cols="30"></textarea> </div> ' +
|
||||
'<button type="button" class="wr-btn wr-btn-horizontal wr-btn-secondary remove_feature_button">' +
|
||||
'<i class="fa fa-minus"></i></button> </div></div>';
|
||||
$(featureWrapper).append(featureFieldHtml); // Add field html
|
||||
|
||||
});
|
||||
$(featureWrapper).on('click', '.remove_feature_button', function(e){ //Once remove button is clicked
|
||||
e.preventDefault();
|
||||
$(this).parent('div').remove(); //Remove field html
|
||||
});
|
||||
|
||||
/**
|
||||
* Following click function would execute
|
||||
* when a user clicks on "Add Device type" button.
|
||||
*/
|
||||
$("button#edit-devicetype-btn").click(function () {
|
||||
|
||||
var errorMsgWrapper = "#devicetype-create-error-msg";
|
||||
var errorMsg = "#devicetype-create-error-msg span";
|
||||
var successMsgWrapper = "#devicetype-create-success-msg";
|
||||
var successMsg = "#devicetype-create-success-msg span";
|
||||
var deviceType = {};
|
||||
var deviceTypeName = $("#deviceTypeName").val();
|
||||
var deviceTypeDescription = $("#deviceTypeDescription").val();
|
||||
if (!deviceTypeName || deviceTypeName.trim() == "" ) {
|
||||
$(errorMsg).text("Device Type Name Cannot be empty.");
|
||||
$(errorMsgWrapper).removeClass("hidden");
|
||||
$([document.documentElement, document.body]).animate({
|
||||
scrollTop: $(".page-sub-title").offset().top
|
||||
}, 500);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!deviceTypeDescription || deviceTypeDescription.trim() == "") {
|
||||
$(errorMsg).text("Device Type Description Cannot be empty.");
|
||||
$(errorMsgWrapper).removeClass("hidden");
|
||||
$([document.documentElement, document.body]).animate({
|
||||
scrollTop: $(".page-sub-title").offset().top
|
||||
}, 500);
|
||||
return;
|
||||
}
|
||||
|
||||
deviceType.name = deviceTypeName.trim();
|
||||
deviceType.deviceTypeMetaDefinition = {}
|
||||
deviceType.deviceTypeMetaDefinition.description = deviceTypeDescription.trim();
|
||||
|
||||
var pushNotification = $("#pushNotification").val();
|
||||
if (pushNotification != "NONE") {
|
||||
deviceType.deviceTypeMetaDefinition.pushNotificationConfig = {};
|
||||
deviceType.deviceTypeMetaDefinition.pushNotificationConfig.scheduled = true;
|
||||
deviceType.deviceTypeMetaDefinition.pushNotificationConfig.type = pushNotification;
|
||||
}
|
||||
|
||||
var propertyValues = [];
|
||||
$('input[name^="attribute"]').each(function() {
|
||||
var propertyValue = $(this).val();
|
||||
if (propertyValue.trim() != "") {
|
||||
propertyValues.push(propertyValue.trim());
|
||||
}
|
||||
});
|
||||
deviceType.deviceTypeMetaDefinition.properties = propertyValues;
|
||||
|
||||
var operationValues = [];
|
||||
$('input[name^="operation"]').each(function() {
|
||||
var operationValue = $(this).val();
|
||||
if (operationValue.trim() != "") {
|
||||
operationValues.push(operationValue.trim());
|
||||
}
|
||||
});
|
||||
if (operationValues.length > 0) {
|
||||
deviceType.deviceTypeMetaDefinition.initialOperationConfig = {};
|
||||
deviceType.deviceTypeMetaDefinition.initialOperationConfig.operations = operationValues;
|
||||
}
|
||||
|
||||
var features = [];
|
||||
var featureCodesValidation = true;
|
||||
var regexp = /^[a-zA-Z0-9-_]+$/;
|
||||
$('div[name^="deviceFeature"]').each(function() {
|
||||
var featureName = $(this).find(".feature-name").val();
|
||||
var featureCode = $(this).find(".feature-code").val();
|
||||
var featureDescription = $(this).find(".feature-description").val();
|
||||
if (featureName && featureName.trim() != "" && featureCode && featureCode.trim() != "") {
|
||||
featureCodesValidation = featureCodesValidation && (featureCode.search(regexp) != -1);
|
||||
var feature = {};
|
||||
feature.name = featureName.trim();
|
||||
feature.code = featureCode.trim();
|
||||
feature.description = featureDescription;
|
||||
features.push(feature);
|
||||
}
|
||||
});
|
||||
if (!featureCodesValidation) {
|
||||
$(errorMsg).text("Device Type feature code can only contain alphanumeric, underscore and dash characters.");
|
||||
$(errorMsgWrapper).removeClass("hidden");
|
||||
$([document.documentElement, document.body]).animate({
|
||||
scrollTop: $(".page-sub-title").offset().top
|
||||
}, 500);
|
||||
return;
|
||||
}
|
||||
deviceType.deviceTypeMetaDefinition.features = features;
|
||||
|
||||
var addRoleAPI = apiBasePath + "/admin/device-types/" + deviceType.name;
|
||||
|
||||
invokerUtil.put(
|
||||
addRoleAPI,
|
||||
deviceType,
|
||||
function (data, textStatus, jqXHR) {
|
||||
if (jqXHR.status == 200) {
|
||||
$(errorMsgWrapper).addClass(" hidden");
|
||||
$("#modalDevice").modal('show');
|
||||
}
|
||||
},
|
||||
function (jqXHR) {
|
||||
if (jqXHR.status == 500) {
|
||||
$(errorMsg).text("Unexpected error.");
|
||||
$(errorMsgWrapper).removeClass("hidden");
|
||||
}
|
||||
|
||||
if (jqXHR.status == 409) {
|
||||
$(errorMsg).text("Device type already exists");
|
||||
$(errorMsgWrapper).removeClass("hidden");
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
@ -1,181 +0,0 @@
|
||||
{{!
|
||||
Copyright (c) 2017, 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.
|
||||
}}
|
||||
{{unit "cdmf.unit.ui.title" pageTitle="Device Type Management"}}
|
||||
|
||||
{{#zone "topCss"}}
|
||||
{{css "css/devicetype.css"}}
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "breadcrumbs"}}
|
||||
<li>
|
||||
<a href="{{@app.context}}/">
|
||||
<i class="icon fw fw-home"></i>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
<a href="{{@app.context}}/device-types">
|
||||
Device Types
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
<a href="{{@app.context}}/device-type/edit-event?type={{name}}">
|
||||
Event
|
||||
</a>
|
||||
</li>
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "content"}}
|
||||
{{#if canManage}}
|
||||
<!-- content/body -->
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<!-- content -->
|
||||
<div id="devicetype-create-form" class="container col-centered wr-content">
|
||||
<div class="wr-form">
|
||||
<p class="page-sub-title">{{name}}</p>
|
||||
<hr/>
|
||||
<div class="row">
|
||||
<div class="col-lg-8">
|
||||
<div id="devicetype-create-error-msg" class="alert alert-danger hidden" role="alert">
|
||||
<i class="icon fw fw-error"></i><span></span>
|
||||
</div>
|
||||
<br>
|
||||
<input aria-describedby="basic-addon1" type="text" id="deviceTypeName"
|
||||
data-error-msg="invalid device type name" class="form-control hidden-input" value="{{name}}"/>
|
||||
|
||||
<label class="wr-input-label">Transport</label>
|
||||
<div class="wr-input-control">
|
||||
<!--suppress HtmlFormInputWithoutLabel -->
|
||||
<select id="transport" class="form-control select">
|
||||
{{#if event}}
|
||||
<option {{selected event.transport "HTTP"}}>HTTP</option>
|
||||
<option {{selected event.transport "MQTT"}}>MQTT</option>
|
||||
{{else}}
|
||||
<option>HTTP</option>
|
||||
<option>MQTT</option>
|
||||
{{/if}}
|
||||
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<label class="wr-input-label">
|
||||
Event Attributes (eg: alarm_status, temperature)
|
||||
</label>
|
||||
<br>
|
||||
<div class="form-group event_field_wrapper">
|
||||
{{#if event.eventAttributes}}
|
||||
{{#each event.eventAttributes.attributes}}
|
||||
<div class="row">
|
||||
<div class="dontfloat" name="deviceEvent">
|
||||
<div class="col-xs-3">
|
||||
<input type="text" class="form-control" id="event-name" placeholder="name" value="{{this.name}}"/>
|
||||
</div>
|
||||
<div class="col-xs-4">
|
||||
<select class="form-control select" id="event-type">
|
||||
<option {{selected this.type "STRING"}}>STRING</option>
|
||||
<option {{selected this.type "LONG"}}>LONG</option>
|
||||
<option {{selected this.type "BOOL"}}>BOOL</option>
|
||||
<option {{selected this.type "INT"}}>INT</option>
|
||||
<option {{selected this.type "FLOAT"}}>FLOAT</option>
|
||||
<option {{selected this.type "DOUBLE"}}>DOUBLE</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="button" class="wr-btn wr-btn-horizontal remove_event_button"><i class="fa fa-minus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
<div class="row">
|
||||
<div class="dontfloat event-wrapper" name="deviceEvent">
|
||||
<div class="col-xs-3">
|
||||
<input type="text" class="form-control" id="event-name" placeholder="name"/>
|
||||
</div>
|
||||
<div class="col-xs-4">
|
||||
<select class="form-control select" id="event-type">
|
||||
<option>STRING</option>
|
||||
<option>LONG</option>
|
||||
<option>BOOL</option>
|
||||
<option>INT</option>
|
||||
<option>FLOAT</option>
|
||||
<option>DOUBLE</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="button" class="wr-btn wr-btn-horizontal add_event_button"><i class="fa fa-plus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
{{#if event}}
|
||||
<button id="add-event-btn" class="wr-btn">Update</button>
|
||||
{{else}}
|
||||
<button id="add-event-btn" class="wr-btn">Add</button>
|
||||
{{/if}}
|
||||
|
||||
<div id="devicetype-create-success-msg" class="alert hidden" role="alert">
|
||||
<i class="icon fw fw-success"></i><span></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="devicetype-created-msg" class="container col-centered wr-content hidden">
|
||||
<div class="wr-form">
|
||||
<p class="page-sub-title">Device Type Event was added successfully.</p>
|
||||
<b>"View Device Type List"</b> to complete the process and go back to the devie type list.
|
||||
<hr/>
|
||||
<button class="wr-btn" onclick="window.location.href='{{@app.context}}/device-types'">
|
||||
View Device Type List
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /content -->
|
||||
<div id="app-context" data-app-context="{{@app.context}}" class="hidden"></div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /content/body -->
|
||||
<div class="modal fade" id="modalDevice" tabindex="-1" role="dialog" aria-labelledby="modalDevice">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content clearfix">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
|
||||
<h3 class="modal-title" id="deviceModalLabel">Successfully Deployed Event Definition</h3>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-primary" onclick="location.href='{{@app.context}}/device/enroll'">Go To Enrolment Page</button>
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{else}}
|
||||
<h1 class="page-sub-title">
|
||||
Permission Denied
|
||||
</h1>
|
||||
<br>
|
||||
You not authorized to edit device type.
|
||||
<br>
|
||||
{{/if}}
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "bottomJs"}}
|
||||
{{js "js/bottomJs.js"}}
|
||||
{{/zone}}
|
||||
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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/business-controllers/user.js")["userModule"];
|
||||
var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
var displayData = {};
|
||||
|
||||
|
||||
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/device-type")) {
|
||||
displayData.canManage = true;
|
||||
}
|
||||
context.handlebars.registerHelper('selected', function(a, b, opts) {
|
||||
if(a == b) // Or === depending on your needs
|
||||
return "selected";
|
||||
else
|
||||
return "";
|
||||
});
|
||||
|
||||
var deviceType = request.getParameter("type");
|
||||
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
|
||||
var restAPIEndpoint = deviceMgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"]
|
||||
+ "/events/" + deviceType;
|
||||
displayData.name = deviceType;
|
||||
serviceInvokers.XMLHttp.get(
|
||||
restAPIEndpoint,
|
||||
function (restAPIResponse) {
|
||||
if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) {
|
||||
var typeData = parse(restAPIResponse["responseText"]);
|
||||
displayData.event = typeData;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return displayData;
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"uri": "/device-type/edit-event",
|
||||
"layout": "cdmf.layout.default"
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
.dontfloat {
|
||||
clear:both;
|
||||
}
|
||||
|
||||
.hidden-div {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.hidden-input {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.event-wrapper{
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.wr-btn-horizontal{
|
||||
padding: 7px 10px;
|
||||
}
|
||||
|
||||
.wr-btn-secondary{
|
||||
background-color: #617d8b;
|
||||
}
|
||||
@ -1,181 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks if provided input is valid against RegEx input.
|
||||
*
|
||||
* @param regExp Regular expression
|
||||
* @param inputString Input string to check
|
||||
* @returns {boolean} Returns true if input matches RegEx
|
||||
*/
|
||||
function inputIsValid(regExp, inputString) {
|
||||
regExp = new RegExp(regExp);
|
||||
return regExp.test(inputString);
|
||||
}
|
||||
|
||||
var validateInline = {};
|
||||
var clearInline = {};
|
||||
|
||||
var apiBasePath = "/api/device-mgt/v1.0";
|
||||
var domain = $("#domain").val();
|
||||
|
||||
|
||||
var enableInlineError = function (inputField, errorMsg, errorSign) {
|
||||
var fieldIdentifier = "#" + inputField;
|
||||
var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
|
||||
var errorSignIdentifier = "#" + inputField + " ." + errorSign;
|
||||
|
||||
if (inputField) {
|
||||
$(fieldIdentifier).addClass(" has-error has-feedback");
|
||||
}
|
||||
|
||||
if (errorMsg) {
|
||||
$(errorMsgIdentifier).removeClass(" hidden");
|
||||
}
|
||||
|
||||
if (errorSign) {
|
||||
$(errorSignIdentifier).removeClass(" hidden");
|
||||
}
|
||||
};
|
||||
|
||||
var disableInlineError = function (inputField, errorMsg, errorSign) {
|
||||
var fieldIdentifier = "#" + inputField;
|
||||
var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
|
||||
var errorSignIdentifier = "#" + inputField + " ." + errorSign;
|
||||
|
||||
if (inputField) {
|
||||
$(fieldIdentifier).removeClass(" has-error has-feedback");
|
||||
}
|
||||
|
||||
if (errorMsg) {
|
||||
$(errorMsgIdentifier).addClass(" hidden");
|
||||
}
|
||||
|
||||
if (errorSign) {
|
||||
$(errorSignIdentifier).addClass(" hidden");
|
||||
}
|
||||
};
|
||||
|
||||
function formatRepo(user) {
|
||||
if (user.loading) {
|
||||
return user.text
|
||||
}
|
||||
if (!user.username) {
|
||||
return;
|
||||
}
|
||||
var markup = '<div class="clearfix">' +
|
||||
'<div class="col-sm-8">' +
|
||||
'<div class="clearfix">' +
|
||||
'<div class="col-sm-4">' + user.username + '</div>';
|
||||
if (user.name || user.name != undefined) {
|
||||
markup += '<div class="col-sm-8"> ( ' + user.name + ' )</div>';
|
||||
}
|
||||
markup += '</div></div></div>';
|
||||
return markup;
|
||||
}
|
||||
|
||||
function formatRepoSelection(user) {
|
||||
return user.username || user.text;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
var appContext = $("#app-context").data("app-context");
|
||||
var addEventButton = $('.add_event_button'); //Add button selector
|
||||
var eventWrapper = $('.event_field_wrapper'); //Input field wrapper
|
||||
$(addEventButton).click(function(){ //Once add button is clicked
|
||||
var eventFieldHtml = '<div class="row"><div class="dontfloat event-wrapper" name="deviceEvent"> ' +
|
||||
'<div class="col-xs-3"> <input type="text" class="form-control" id="event-name" placeholder="name"/> ' +
|
||||
'</div> <div class="col-xs-4"> <select class="form-control select" id="event-type"> ' +
|
||||
'<option>STRING</option> <option>LONG</option> <option>BOOL</option> <option>INT</option> <option>FLOAT</option> ' +
|
||||
'<option>DOUBLE</option> </select> </div> ' +
|
||||
'<button type="button" class="wr-btn wr-btn-horizontal wr-btn-secondary remove_event_button"><i class="fa fa-minus"></i></button> </div></div>'
|
||||
$(eventWrapper).append(eventFieldHtml); // Add field html
|
||||
|
||||
});
|
||||
$(eventWrapper).on('click', '.remove_event_button', function(e){ //Once remove button is clicked
|
||||
e.preventDefault();
|
||||
$(this).parent('div').remove();
|
||||
});
|
||||
|
||||
/**
|
||||
* Following click function would execute
|
||||
* when a user clicks on "Add Device type" button.
|
||||
*/
|
||||
$("button#add-event-btn").click(function () {
|
||||
|
||||
var errorMsgWrapper = "#devicetype-create-error-msg";
|
||||
var errorMsg = "#devicetype-create-error-msg span";
|
||||
var successMsgWrapper = "#devicetype-create-success-msg";
|
||||
var successMsg = "#devicetype-create-success-msg span";
|
||||
var deviceTypeEvent = {};
|
||||
var deviceTypeName = $("#deviceTypeName").val();
|
||||
var deviceTypeDescription = $("#deviceTypeDescription").val();
|
||||
if (!deviceTypeName || deviceTypeName.trim() == "" ) {
|
||||
$(errorMsg).text("Device Type Name Cannot be empty.");
|
||||
$(errorMsgWrapper).removeClass("hidden");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
deviceTypeEvent.eventAttributes = {};
|
||||
|
||||
deviceTypeEvent.transport = $("#transport").val();
|
||||
|
||||
var attributes = [];
|
||||
$('div[name^="deviceEvent"]').each(function() {
|
||||
var eventName = $(this).find("#event-name").val();
|
||||
var eventType = $(this).find("#event-type").val();
|
||||
if (eventName && eventName.trim() != "" && eventType && eventType.trim() != "" && eventName != "deviceId") {
|
||||
var attribute = {};
|
||||
attribute.name = eventName.trim();
|
||||
attribute.type = eventType.trim();
|
||||
attributes.push(attribute);
|
||||
}
|
||||
});
|
||||
deviceTypeEvent.eventAttributes.attributes = attributes;
|
||||
|
||||
var addEventsAPI = apiBasePath + "/events/" + deviceTypeName;
|
||||
|
||||
invokerUtil.post(
|
||||
addEventsAPI,
|
||||
deviceTypeEvent,
|
||||
function (data, textStatus, jqXHR) {
|
||||
if (jqXHR.status == 200) {
|
||||
$("#modalDevice").modal('show');
|
||||
}
|
||||
},
|
||||
function (jqXHR) {
|
||||
if (jqXHR.status == 500) {
|
||||
$(errorMsg).text("Failed to deploy event definition, Please Contact Administrator");
|
||||
$(errorMsgWrapper).removeClass("hidden");
|
||||
}
|
||||
|
||||
if (jqXHR.status == 409) {
|
||||
$(errorMsg).text("Device type definition cannot be updated");
|
||||
$(errorMsgWrapper).removeClass("hidden");
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
@ -1,114 +0,0 @@
|
||||
{{!
|
||||
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
|
||||
WSO2 Inc. licenses this file to you under the Apache License,
|
||||
Version 2.0 (the "License"); you may not use this file except
|
||||
in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
}}
|
||||
|
||||
{{unit "cdmf.unit.ui.title" pageTitle="Device Type Management"}}
|
||||
{{unit "cdmf.unit.data-tables-extended"}}
|
||||
{{unit "cdmf.unit.ui.modal"}}
|
||||
|
||||
{{#zone "topCss"}}
|
||||
{{css "css/custom.css"}}
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "breadcrumbs"}}
|
||||
<li>
|
||||
<a href="{{@app.context}}/">
|
||||
<i class="icon fw fw-home"></i>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
<a href="{{@app.context}}/device-types">
|
||||
Device Types
|
||||
</a>
|
||||
</li>
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "navbarActions"}}
|
||||
{{#unless isCloud}}
|
||||
<li>
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
<a href="{{@app.context}}/device-type/add" class="cu-btn">
|
||||
<span class="icon fw-stack">
|
||||
<i class="fw fw-add fw-stack-1x"></i>
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
</span>
|
||||
Create Device Type
|
||||
</a>
|
||||
</li>
|
||||
{{/unless}}
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "content"}}
|
||||
{{#if hasDeviceTypes}}
|
||||
<div id="loading-content" class="col-centered">
|
||||
<input type="hidden" id="can-edit" value="true"/>
|
||||
<i class="fw fw-settings fw-spin fw-2x"></i>
|
||||
Loading device types . . .
|
||||
<br>
|
||||
</div>
|
||||
|
||||
<div id="devicetype-table">
|
||||
<table class="table table-striped table-hover list-table display responsive nowrap data-table grid-view"
|
||||
id="devicetype-grid">
|
||||
<thead>
|
||||
<tr class="sort-row">
|
||||
<th>By Device Type Name</th>
|
||||
</tr>
|
||||
<tr class="bulk-action-row">
|
||||
<th colspan="3"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="ast-container" data-app-context="{{@app.context}}/"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div id="content-filter-types" style="display: none">
|
||||
<div class="sort-title">Sort By</div>
|
||||
<div class="sort-options">
|
||||
<!--suppress HtmlUnknownTag -->
|
||||
<th>By Device Type name</th>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{else}}
|
||||
|
||||
<div id="user-created-msg" class="container col-centered wr-content">
|
||||
<div class="wr-form">
|
||||
<p class="page-sub-title">You Haven't created device types yet.</p>
|
||||
<br>Please click <b>"Create a Device Type"</b>, if you wish to create a device type.
|
||||
<hr/>
|
||||
|
||||
<a href="{{@app.context}}/device-type/add" class="cu-btn-inner">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||
<i class="fw fw-add fw-stack-1x"></i>
|
||||
</span>
|
||||
Create Device Type
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{/if}}
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "bottomJs"}}
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
<script id="devicetype-listing" data-current-user="{{@user.username}}"
|
||||
src="{{@page.publicUri}}/templates/devicetype-listing.hbs" type="text/x-handlebars-template"></script>
|
||||
{{js "js/devicetype-listing.js"}}
|
||||
{{/zone}}
|
||||
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
|
||||
var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
|
||||
context["permissions"] = userModule.getUIPermissions();
|
||||
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/device-type")) {
|
||||
context["editPermitted"] = true;
|
||||
}
|
||||
var deviceTypeCount = deviceModule.getDeviceTypeCount();
|
||||
|
||||
if (deviceTypeCount > 0) {
|
||||
context["hasDeviceTypes"] = true;
|
||||
} else {
|
||||
context["hasDeviceTypes"] = false;
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"uri": "/device-types",
|
||||
"layout": "cdmf.layout.default"
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.
|
||||
*/
|
||||
|
||||
#devicetype-table .dataTablesTop{
|
||||
Display : none;
|
||||
}
|
||||
@ -1,207 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 loadDeviceTypeBasedActionURL = function (action, deviceTypeName) {
|
||||
href = $("#ast-container").data("app-context") + "device-type/" + action + "?type=" + encodeURIComponent(deviceTypeName);
|
||||
$(location).attr('href', href);
|
||||
};
|
||||
|
||||
$(function () {
|
||||
var sortableElem = '.wr-sortable';
|
||||
$(sortableElem).sortable({
|
||||
beforeStop: function () {
|
||||
$(this).sortable('toArray');
|
||||
}
|
||||
});
|
||||
$(sortableElem).disableSelection();
|
||||
});
|
||||
|
||||
var apiBasePath = "/api/device-mgt/v1.0";
|
||||
var modalPopup = ".modal";
|
||||
var modalPopupContainer = modalPopup + " .modal-content";
|
||||
var modalPopupContent = modalPopup + " .modal-content";
|
||||
var body = "body";
|
||||
var isInit = true;
|
||||
var isCloud = false;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Fires the res_text when ever a data table redraw occurs making
|
||||
* the font icons change the size to respective screen resolution.
|
||||
*
|
||||
*/
|
||||
$(document).on('draw.dt', function () {
|
||||
$(".icon .text").res_text(0.2);
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
* set popup maximum height function.
|
||||
*/
|
||||
function setPopupMaxHeight() {
|
||||
$(modalPopupContent).css('max-height', ($(body).height() - ($(body).height() / 100 * 30)));
|
||||
$(modalPopupContainer).css('margin-top', (-($(modalPopupContainer).height() / 2)));
|
||||
}
|
||||
|
||||
/*
|
||||
* show popup function.
|
||||
*/
|
||||
function showPopup() {
|
||||
$(modalPopup).modal('show');
|
||||
//setPopupMaxHeight();
|
||||
}
|
||||
|
||||
/*
|
||||
* hide popup function.
|
||||
*/
|
||||
function hidePopup() {
|
||||
$(modalPopupContent).html('');
|
||||
$(modalPopup).modal('hide');
|
||||
$('body').removeClass('modal-open').css('padding-right', '0px');
|
||||
$('.modal-backdrop').remove();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Following function would execute
|
||||
* when a user clicks on the list item
|
||||
* initial mode and with out select mode.
|
||||
*/
|
||||
function InitiateViewOption() {
|
||||
// $(location).attr('href', $(this).data("url"));
|
||||
}
|
||||
|
||||
function htmlspecialchars(text) {
|
||||
return jQuery('<div/>').text(text).html();
|
||||
}
|
||||
|
||||
function loadDeviceTypes() {
|
||||
var loadingContent = $("#loading-content");
|
||||
loadingContent.show();
|
||||
|
||||
var dataFilter = function (data) {
|
||||
data = JSON.parse(data);
|
||||
var objects = [];
|
||||
$(data).each(function (index) {
|
||||
objects.push(
|
||||
{
|
||||
name: htmlspecialchars(data[index].name),
|
||||
DT_RowId: "devicetype-" + htmlspecialchars(data[index].name),
|
||||
metaDefinition: (data[index].deviceTypeMetaDefinition ? true : false)
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
var json = {
|
||||
"recordsTotal": data.length,
|
||||
"recordsFiltered": data.length,
|
||||
"data": objects
|
||||
};
|
||||
|
||||
return JSON.stringify(json);
|
||||
};
|
||||
|
||||
//noinspection JSUnusedLocalSymbols
|
||||
var fnCreatedRow = function (nRow, aData, iDataIndex) {
|
||||
$(nRow).attr('data-type', 'selectable');
|
||||
};
|
||||
|
||||
//noinspection JSUnusedLocalSymbols
|
||||
var columns = [
|
||||
{
|
||||
class: "remove-padding content-fill",
|
||||
data: null,
|
||||
defaultContent: "<div class='thumbnail icon'>" +
|
||||
"<i class='square-element text fw fw-devices' style='font-size: 74px;'></i>" +
|
||||
"</div>"
|
||||
},
|
||||
{
|
||||
class: "",
|
||||
data: "name",
|
||||
render: function (name, type, row, meta) {
|
||||
return '<h4>' + name.replace("devicemgt", "") + '</h4>';
|
||||
}
|
||||
},
|
||||
{
|
||||
class: "text-right content-fill text-left-on-grid-view no-wrap",
|
||||
data: null,
|
||||
render: function (data, type, row, meta) {
|
||||
var isCloud = false;
|
||||
if ($('#is-cloud').length > 0) {
|
||||
isCloud = true;
|
||||
}
|
||||
|
||||
var innerhtml = '';
|
||||
if (data.metaDefinition) {
|
||||
|
||||
var editLink = '<a onclick="javascript:loadDeviceTypeBasedActionURL(\'edit\', \'' + data.name + '\')" ' +
|
||||
'data-devicetype="' + data.name + '" ' +
|
||||
'data-click-event="edit-form" ' +
|
||||
'class="btn padding-reduce-on-grid-view edit-devicetype-link">' +
|
||||
'<span class="fw-stack">' +
|
||||
'<i class="fw fw-circle-outline fw-stack-2x"></i>' +
|
||||
'<i class="fw fw-devices fw-stack-1x"></i>' +
|
||||
'<span class="fw-stack fw-move-right fw-move-bottom">' +
|
||||
'<i class="fw fw-circle fw-stack-2x fw-stroke fw-inverse"></i>' +
|
||||
'<i class="fw fw-circle fw-stack-2x"></i><i class="fw fw-edit fw-stack-1x fw-inverse"></i>' +
|
||||
'</span>' +
|
||||
'</span>' +
|
||||
'<span class="hidden-xs hidden-on-grid-view">Edit</span>' +
|
||||
'</a>';
|
||||
|
||||
var editEventLink = '<a onclick="javascript:loadDeviceTypeBasedActionURL(\'edit-event\', \'' + data.name + '\')" ' +
|
||||
'data-devicetype="' + data.name + '" ' +
|
||||
'data-click-event="edit-form" ' +
|
||||
'class="btn padding-reduce-on-grid-view edit-event-link">' +
|
||||
'<span class="fw-stack">' +
|
||||
'<i class="fw fw-circle-outline fw-stack-2x"></i>' +
|
||||
'<i class="fw fw-document fw-stack-1x"></i>' +
|
||||
'<span class="fw-stack fw-move-right fw-move-bottom">' +
|
||||
'<i class="fw fw-circle fw-stack-2x fw-stroke fw-inverse"></i>' +
|
||||
'<i class="fw fw-circle fw-stack-2x"></i><i class="fw fw-edit fw-stack-1x fw-inverse"></i>' +
|
||||
'</span>' +
|
||||
'</span>' +
|
||||
'<span class="hidden-xs hidden-on-grid-view">Edit Event</span>' +
|
||||
'</a>';
|
||||
|
||||
innerhtml = editLink + editEventLink;
|
||||
}
|
||||
return innerhtml;
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
var options = {
|
||||
"placeholder": "Search By Device Type Name",
|
||||
"searchKey": "filter",
|
||||
"searching": false
|
||||
};
|
||||
var settings = {
|
||||
"sorting": false
|
||||
};
|
||||
var deviceTypeApiUrl = '/api/device-mgt/v1.0/admin/device-types';
|
||||
|
||||
$('#devicetype-grid').datatables_extended_serverside_paging(settings, deviceTypeApiUrl, dataFilter, columns, fnCreatedRow, null, options);
|
||||
loadingContent.hide();
|
||||
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
loadDeviceTypes();
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user