@ -0,0 +1,171 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<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/maven-v4_0_0.xsd">
|
||||
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||
<artifactId>device-mgt-iot-feature</artifactId>
|
||||
<version>1.9.2-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.device.mgt.iot.feature</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.9.2-SNAPSHOT</version>
|
||||
<name>WSO2 Carbon - IoT Server - Features</name>
|
||||
<url>http://wso2.org</url>
|
||||
<description>This feature contains the core bundles required for IoT Server</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.iot</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.iot.api</artifactId>
|
||||
<type>war</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.json.wso2</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--Dependencies on XMPP Client Library-->
|
||||
<dependency>
|
||||
<groupId>org.igniterealtime.smack.wso2</groupId>
|
||||
<artifactId>smack</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.igniterealtime.smack.wso2</groupId>
|
||||
<artifactId>smackx</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sf.ehcache.wso2</groupId>
|
||||
<artifactId>ehcache</artifactId>
|
||||
<version>1.5.0.wso2v3</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-resources</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>src/main/resources</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>resources</directory>
|
||||
<includes>
|
||||
<include>build.properties</include>
|
||||
<include>p2.inf</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactItems>
|
||||
<artifactItem>
|
||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.iot.api</artifactId>
|
||||
<type>war</type>
|
||||
<overWrite>true</overWrite>
|
||||
<outputDirectory>${basedir}/src/main/resources/webapps/</outputDirectory>
|
||||
<destFileName>common.war</destFileName>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.wso2.maven</groupId>
|
||||
<artifactId>carbon-p2-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>p2-feature-generation</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>p2-feature-gen</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<id>org.wso2.carbon.device.mgt.iot</id>
|
||||
<propertiesFile>../../../features/etc/feature.properties</propertiesFile>
|
||||
<adviceFile>
|
||||
<properties>
|
||||
<propertyDef>org.wso2.carbon.p2.category.type:server</propertyDef>
|
||||
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
|
||||
</properties>
|
||||
</adviceFile>
|
||||
<bundles>
|
||||
<bundleDef>
|
||||
org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.iot:${carbon.iot.device.mgt.version}
|
||||
</bundleDef>
|
||||
<bundleDef>
|
||||
org.json.wso2:json:${commons-json.version}
|
||||
</bundleDef>
|
||||
<bundleDef>
|
||||
org.igniterealtime.smack.wso2:smack:${smack.wso2.version}
|
||||
</bundleDef>
|
||||
<bundleDef>
|
||||
org.igniterealtime.smack.wso2:smackx:${smackx.wso2.version}
|
||||
</bundleDef>
|
||||
<bundleDef>
|
||||
net.sf.ehcache.wso2:ehcache
|
||||
</bundleDef>
|
||||
</bundles>
|
||||
<importFeatures>
|
||||
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}
|
||||
</importFeatureDef>
|
||||
<importFeatureDef>org.wso2.carbon.device.mgt.server:${carbon.device.mgt.version}
|
||||
</importFeatureDef>
|
||||
</importFeatures>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1 @@
|
||||
custom = true
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"appContext" : "/iotserver/",
|
||||
"apiContext" : "api",
|
||||
"httpsURL": "%https.ip%",
|
||||
"httpURL": "%http.ip%",
|
||||
"ssoConfiguration": {
|
||||
"enabled": false,
|
||||
"issuer": "iot",
|
||||
"appName": "iot",
|
||||
"identityProviderURL": "%https.ip%/sso/samlsso.jag",
|
||||
"responseSigningEnabled": "true",
|
||||
"keyStorePassword": "wso2carbon",
|
||||
"identityAlias": "wso2carbon",
|
||||
"keyStoreName": "/repository/resources/security/wso2carbon.jks"
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 config = function () {
|
||||
var conf = application.get("PINCH_CONFIG");
|
||||
if (!conf) {//if not in cache
|
||||
var pinch = require('/modules/pinch.min.js').pinch;
|
||||
var server = require('carbon').server;
|
||||
var config = require('/config/config.json');
|
||||
pinch(config, /^/, function (path, key, value) {
|
||||
if ((typeof value === 'string') && value.indexOf('%https.ip%') > -1) {
|
||||
return value.replace('%https.ip%', server.address("https"));
|
||||
} else if ((typeof value === 'string') && value.indexOf('%http.ip%') > -1) {
|
||||
return value.replace('%http.ip%', server.address("http"));
|
||||
}
|
||||
return value;
|
||||
});
|
||||
application.put("PINCH_CONFIG", config);//caching
|
||||
conf = config;
|
||||
}
|
||||
return conf;
|
||||
};
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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 carbonModule = require("carbon");
|
||||
var dcProps = require('/config/dc-props.js').config();
|
||||
var carbonServer = new carbonModule.server.Server({
|
||||
tenanted: true,
|
||||
url: dcProps.httpsURL + '/admin'
|
||||
});
|
||||
application.put("carbonServer", carbonServer);
|
||||
var userModule = require("/modules/user.js").userModule;
|
||||
var utility = require("/modules/utility.js").utility;
|
||||
utility.insertAppPermissions(userModule, "init");
|
@ -0,0 +1,67 @@
|
||||
{
|
||||
"displayName": "Fuse Sample",
|
||||
"logLevel": "info",
|
||||
"initScripts": ["/config/init.js"],
|
||||
"urlMappings": [
|
||||
{
|
||||
"url" : "/testb/*",
|
||||
"path" : "test.jag"
|
||||
},
|
||||
{
|
||||
"url" : "/test/*",
|
||||
"path" : "test/testExecutor.jag"
|
||||
},
|
||||
{
|
||||
"url": "/api/device/*",
|
||||
"path": "/api/device-api.jag"
|
||||
},
|
||||
{
|
||||
"url": "/api/devices/*",
|
||||
"path": "/api/device-api.jag"
|
||||
},
|
||||
{
|
||||
"url": "/api/group/*",
|
||||
"path": "/api/group-api.jag"
|
||||
},
|
||||
{
|
||||
"url": "/api/event/*",
|
||||
"path": "/api/event-api.jag"
|
||||
},
|
||||
{
|
||||
"url": "/api/operation/*",
|
||||
"path": "/api/operation-api.jag"
|
||||
},
|
||||
{
|
||||
"url": "/api/user/*",
|
||||
"path": "/api/user-api.jag"
|
||||
},
|
||||
{
|
||||
"url": "/api/users/*",
|
||||
"path": "/api/user-api.jag"
|
||||
},
|
||||
{
|
||||
"url": "/api/stats/*",
|
||||
"path": "/api/stats-api.jag"
|
||||
},
|
||||
{
|
||||
"url": "/api/policies/*",
|
||||
"path": "/api/policy-api.jag"
|
||||
},
|
||||
{
|
||||
"url": "/sso/login",
|
||||
"path": "/lib/login.jag"
|
||||
},
|
||||
{
|
||||
"url": "/sso/logout",
|
||||
"path": "/lib/logout.jag"
|
||||
},
|
||||
{
|
||||
"url": "/sso/acs",
|
||||
"path": "/lib/acs.jag"
|
||||
},
|
||||
{
|
||||
"url": "/*",
|
||||
"path": "/lib/fuse.jag"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>
|
||||
{{ defineZone "title"}}
|
||||
</title>
|
||||
{{ defineZone "topLibCss"}}
|
||||
{{ defineZone "topCss"}}
|
||||
</head>
|
||||
<body>
|
||||
<div class="container col-lg-12 col-md-12 col-sm-12">
|
||||
<!-- header -->
|
||||
<header>
|
||||
<div class="row wr-global-header">
|
||||
<div class="col-sm-8 app-logo">
|
||||
{{ defineZone "brand"}}
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<!-- /header -->
|
||||
{{ defineZone "body"}}
|
||||
{{ defineZone "footer"}}
|
||||
</div>
|
||||
{{ defineZone "bottomjquery" }}
|
||||
{{ defineZone "bottomLibJs" }}
|
||||
{{ defineZone "bottomJs" }}
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,44 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>{{ defineZone "title"}}</title>
|
||||
{{ defineZone "topCss"}}
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
|
||||
<div class="container-liquid">
|
||||
<div class="navbar-header">
|
||||
<a class="navbar-brand" href="#">{{defineZone "brand"}}</a>
|
||||
</div>
|
||||
<div class="navbar-collapse collapse">
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li><a href="/login">Login</a></li>
|
||||
{{ defineZone "upperRight"}}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="wrap">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
{{ defineZone "content"}}
|
||||
</div>
|
||||
</div>
|
||||
<!-- /container -->
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
{{ defineZone "footer"}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,40 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="icon" href="favicon.png" type="image/x-icon" />
|
||||
{{defineZone "favicon"}}
|
||||
<title>
|
||||
{{ defineZone "title"}}
|
||||
</title>
|
||||
{{ defineZone "topLibCss"}}
|
||||
{{ defineZone "topCss"}}
|
||||
</head>
|
||||
<body>
|
||||
<div class="wr-modalpopup">
|
||||
<div class="modalpopup-container">
|
||||
<div class="modalpopup-close-btn" onclick="hidePopup();">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-ring fw-stack-2x"></i>
|
||||
<i class="fw fw-left-arrow fw-stack-1x"></i>
|
||||
</span>
|
||||
GO BACK
|
||||
</div>
|
||||
<div class="modalpopup-content"><!-- dynamic content --></div>
|
||||
</div>
|
||||
<div class="modalpopup-bg"></div>
|
||||
</div>
|
||||
{{ defineZone "notification"}}
|
||||
<div class="container col-lg-12 col-md-12 col-sm-12">
|
||||
<!-- header -->
|
||||
{{ defineZone "header"}}
|
||||
<!-- /header -->
|
||||
{{ defineZone "body"}}
|
||||
{{ defineZone "footer"}}
|
||||
</div>
|
||||
{{ defineZone "bottomjquery" }}
|
||||
{{ defineZone "bottomLibJs" }}
|
||||
{{ defineZone "bottomJs" }}
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,50 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>{{ defineZone "title"}}</title>
|
||||
{{ defineZone "topCss"}}
|
||||
</head>
|
||||
<body>
|
||||
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
|
||||
<div class="container-liquid">
|
||||
<div class="navbar-header">
|
||||
<a class="navbar-brand" href="#">{{defineZone "brand"}}</a>
|
||||
</div>
|
||||
<div class="navbar-collapse collapse">
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li><a href="/login">Login</a></li>
|
||||
{{ defineZone "upperRight"}}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="wrap">
|
||||
<div class="container-fluid">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-2">
|
||||
{{ defineZone "left"}}
|
||||
</div>
|
||||
|
||||
<div class="col-sm-10">
|
||||
{{ defineZone "content"}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- /container -->
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
{{ defineZone "footer"}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
var apiWrapperUtil = function () {
|
||||
var module = {};
|
||||
var tokenUtil = require("/modules/util.js").util;
|
||||
module.refreshToken = function () {
|
||||
var tokenPair = session.get("accessTokenPair");
|
||||
tokenPair = tokenUtil.refreshToken(tokenPair);
|
||||
session.put("accessTokenPair", tokenPair);
|
||||
response.addCookie({'name': 'accessToken', 'value': tokenPair.accessToken});
|
||||
};
|
||||
module.setupAccessTokenPair = function (type, properties) {
|
||||
var tokenPair;
|
||||
var clientId = "pY0FbBUC_GI7mfHVS1FvhWAifEwa";
|
||||
var clientSecret = "Tu5Za1R3fHtGc5yH4KK8TNiLVSca";
|
||||
if (type == "password") {
|
||||
//tokenPair = tokenUtil.getTokenWithPasswordGrantType(properties.username, properties.password, clientId, clientSecret);
|
||||
} else if (type == "saml") {
|
||||
|
||||
}
|
||||
//session.put("accessTokenPair", tokenPair);
|
||||
//response.addCookie({'name': 'accessToken', 'value': tokenPair.accessToken});
|
||||
};
|
||||
return module;
|
||||
}();
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 WEB_APP_TITLE = "WSO2 IoT - IoT Server";
|
||||
var WEB_APP_CONTEXT = "/iotserver";
|
||||
var USER_SESSION_KEY = "USER";
|
||||
var UNSPECIFIED = "Unspecified";
|
||||
var DEVICES_UNIT_PATH="/units/";
|
||||
var POLICY_REGISTRY_PATH="/_system/governance/policy_declarations/";
|
||||
|
||||
var DEVICE_IDENTIFIER = "deviceIdentifier";
|
||||
var DEVICE_NAME = "name";
|
||||
var DEVICE_OWNERSHIP = "ownership";
|
||||
var DEVICE_OWNER = "owner";
|
||||
var DEVICE_TYPE = "type";
|
||||
var DEVICE_VENDOR = "vendor";
|
||||
var DEVICE_MODEL = "model";
|
||||
var DEVICE_PRODUCT = "PRODUCT";
|
||||
var DEVICE_OS_VERSION = "osVersion";
|
||||
var DEVICE_PROPERTIES = "properties";
|
||||
|
||||
var FEATURE_NAME = "featureName";
|
||||
var FEATURE_DESCRIPTION = "featureDescription";
|
||||
|
||||
var PLATFORM_ANDROID = "android";
|
||||
var PLATFORM_IOS = "ios";
|
||||
var DEVICE_ENROLLMENT = "dateOfEnrolment";
|
||||
|
||||
var VENDOR_APPLE = "Apple";
|
||||
var ERRORS = {
|
||||
"USER_NOT_FOUND": "USER_NOT_FOUND"
|
||||
};
|
@ -0,0 +1,279 @@
|
||||
/*
|
||||
* 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 deviceModule;
|
||||
deviceModule = function () {
|
||||
var log = new Log("modules/device.js");
|
||||
|
||||
var constants = require("/modules/constants.js");
|
||||
var utility = require("/modules/utility.js").utility;
|
||||
|
||||
var carbon = require('carbon');
|
||||
var carbonHttpServletTransport = carbon.server.address('http');
|
||||
var carbonHttpsServletTransport = carbon.server.address('https');
|
||||
|
||||
var ArrayList = Packages.java.util.ArrayList;
|
||||
var Properties = Packages.java.util.Properties;
|
||||
var DeviceIdentifier = Packages.org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
var DeviceManagerUtil = Packages.org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||
var SimpleOperation = Packages.org.wso2.carbon.device.mgt.core.operation.mgt.SimpleOperation;
|
||||
var ConfigOperation = Packages.org.wso2.carbon.device.mgt.core.operation.mgt.ConfigOperation;
|
||||
var CommandOperation = Packages.org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
||||
var deviceManagementDAOFactory = Packages.org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
|
||||
var deviceManagementService = utility.getDeviceManagementService();
|
||||
|
||||
var publicMethods = {};
|
||||
var privateMethods = {};
|
||||
|
||||
privateMethods.validateAndReturn = function (value) {
|
||||
return (value == undefined || value == null) ? constants.UNSPECIFIED : value;
|
||||
};
|
||||
|
||||
privateMethods.getStoreDefinition = function (deviceTypeStr) {
|
||||
var storeJSON = new File(constants.DEVICES_UNIT_PATH + deviceTypeStr + "/public/store.json");
|
||||
if (storeJSON.isExists()) {
|
||||
storeJSON.open('r');
|
||||
log.debug('reading file "' + storeJSON.getPath() + '"');
|
||||
var content = storeJSON.readAll().trim();
|
||||
storeJSON.close();
|
||||
return parse(content);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
publicMethods.listDevices = function () {
|
||||
var devices = deviceManagementService.getAllDevices();
|
||||
var deviceList = [];
|
||||
var i, device, propertiesList, deviceObject;
|
||||
for (i = 0; i < devices.size(); i++) {
|
||||
device = devices.get(i);
|
||||
propertiesList = DeviceManagerUtil.convertDevicePropertiesToMap(device.getProperties());
|
||||
|
||||
deviceObject = {};
|
||||
deviceObject[constants.DEVICE_IDENTIFIER] =
|
||||
privateMethods.validateAndReturn(device.getDeviceIdentifier());
|
||||
deviceObject[constants.DEVICE_NAME] =
|
||||
privateMethods.validateAndReturn(device.getName());
|
||||
deviceObject[constants.DEVICE_OWNERSHIP] =
|
||||
privateMethods.validateAndReturn(device.getOwnership());
|
||||
deviceObject[constants.DEVICE_OWNER] =
|
||||
privateMethods.validateAndReturn(device.getOwner());
|
||||
deviceObject[constants.DEVICE_TYPE] =
|
||||
privateMethods.validateAndReturn(device.getType());
|
||||
deviceObject[constants.DEVICE_PROPERTIES] = {};
|
||||
if (device.getType() == constants.PLATFORM_IOS) {
|
||||
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_MODEL] =
|
||||
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_PRODUCT));
|
||||
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_VENDOR] = constants.VENDOR_APPLE;
|
||||
} else {
|
||||
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_MODEL] =
|
||||
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_MODEL));
|
||||
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_VENDOR] =
|
||||
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_VENDOR));
|
||||
}
|
||||
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_OS_VERSION] =
|
||||
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_OS_VERSION));
|
||||
|
||||
deviceList.push(deviceObject);
|
||||
}
|
||||
return deviceList;
|
||||
};
|
||||
|
||||
publicMethods.listDevicesForUser = function (username) {
|
||||
var devices = deviceManagementService.getDeviceListOfUser(username);
|
||||
var deviceList = [];
|
||||
var i, device, propertiesList, deviceObject;
|
||||
for (i = 0; i < devices.size(); i++) {
|
||||
device = devices.get(i);
|
||||
propertiesList = DeviceManagerUtil.convertDevicePropertiesToMap(device.getProperties());
|
||||
|
||||
deviceObject = {};
|
||||
deviceObject[constants.DEVICE_IDENTIFIER] =
|
||||
privateMethods.validateAndReturn(device.getDeviceIdentifier());
|
||||
deviceObject[constants.DEVICE_NAME] =
|
||||
privateMethods.validateAndReturn(device.getName());
|
||||
deviceObject[constants.DEVICE_OWNERSHIP] =
|
||||
privateMethods.validateAndReturn(device.getOwnership());
|
||||
deviceObject[constants.DEVICE_OWNER] =
|
||||
privateMethods.validateAndReturn(device.getOwner());
|
||||
deviceObject[constants.DEVICE_TYPE] =
|
||||
privateMethods.validateAndReturn(device.getType());
|
||||
deviceObject[constants.DEVICE_PROPERTIES] = {};
|
||||
if (device.getType() == constants.PLATFORM_IOS) {
|
||||
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_MODEL] =
|
||||
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_PRODUCT));
|
||||
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_VENDOR] = constants.VENDOR_APPLE;
|
||||
} else {
|
||||
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_MODEL] =
|
||||
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_MODEL));
|
||||
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_VENDOR] =
|
||||
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_VENDOR));
|
||||
}
|
||||
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_OS_VERSION] =
|
||||
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_OS_VERSION));
|
||||
|
||||
deviceList.push(deviceObject);
|
||||
}
|
||||
return deviceList;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return list of device types.
|
||||
* Device types should be registered in CDMF and specific unit with name of '{devicetype}' should be presented.
|
||||
* @returns {Array}
|
||||
*/
|
||||
publicMethods.listDeviceTypes = function () {
|
||||
deviceManagementDAOFactory.openConnection();
|
||||
var deviceTypes = deviceManagementDAOFactory.getDeviceTypeDAO().getDeviceTypes();
|
||||
deviceManagementDAOFactory.closeConnection();
|
||||
var deviceTypesList = [];
|
||||
var i, deviceType, deviceTypeObject;
|
||||
for (i = 0; i < deviceTypes.size(); i++) {
|
||||
deviceType = deviceTypes.get(i);
|
||||
var deviceUnit = new File(constants.DEVICES_UNIT_PATH + deviceType.getName());
|
||||
if (deviceUnit.isExists()) {
|
||||
deviceTypeObject = {};
|
||||
deviceTypeObject["name"] = deviceType.getName();
|
||||
deviceTypeObject["id"] = deviceType.getId();
|
||||
var storeProperties = privateMethods.getStoreDefinition(deviceType.getName());
|
||||
if (storeProperties) {
|
||||
deviceTypeObject["storeTitle"] = storeProperties.title;
|
||||
deviceTypeObject["storeDescription"] = storeProperties.description;
|
||||
}
|
||||
deviceTypesList.push(deviceTypeObject);
|
||||
} else {
|
||||
log.warn("Device type `" + deviceType.getName() + "` is missing unit implementation at: " + constants.DEVICES_UNIT_PATH);
|
||||
}
|
||||
}
|
||||
return deviceTypesList;
|
||||
};
|
||||
|
||||
publicMethods.removeDevice = function (deviceType, deviceId) {
|
||||
//URL: https://localhost:9443/{deviceType}/manager/device/remove/{deviceId}
|
||||
var deviceCloudService = carbonHttpsServletTransport + "/" + deviceType + "/manager",
|
||||
removeDeviceEndpoint = deviceCloudService + "/device/remove/" + deviceId;
|
||||
|
||||
var data = {};
|
||||
//XMLHTTPRequest's GET
|
||||
//log.info(removeDeviceEndpoint);
|
||||
return del(removeDeviceEndpoint, data, "text");
|
||||
};
|
||||
|
||||
publicMethods.updateDevice = function (deviceType, deviceId, device) {
|
||||
//URL: https://localhost:9443/{deviceType}/manager/device/update/{deviceId}
|
||||
var deviceCloudService = carbonHttpsServletTransport + "/" + deviceType + "/manager",
|
||||
updateDeviceEndpoint = deviceCloudService + "/device/update/" + deviceId;
|
||||
|
||||
var data = {};
|
||||
//XMLHTTPRequest's POST
|
||||
//log.info(updateDeviceEndpoint+ "?name="+device.name);
|
||||
return post(updateDeviceEndpoint + "?name=" + encodeURIComponent(device.name), data, "text");
|
||||
};
|
||||
|
||||
/*
|
||||
Get the supported features by the device type
|
||||
*/
|
||||
publicMethods.getFeatures = function (deviceType) {
|
||||
var features = deviceManagementService.getFeatureManager(deviceType).getFeatures();
|
||||
var featuresConverted = {};
|
||||
|
||||
if (features) {
|
||||
var i, feature, featureObject;
|
||||
for (i = 0; i < features.size(); i++) {
|
||||
feature = features.get(i);
|
||||
featureObject = {};
|
||||
featureObject[constants.FEATURE_NAME] = feature.getName();
|
||||
featureObject[constants.FEATURE_DESCRIPTION] = feature.getDescription();
|
||||
featuresConverted[feature.getName()] = featureObject;
|
||||
}
|
||||
}
|
||||
return featuresConverted;
|
||||
};
|
||||
|
||||
publicMethods.performOperation = function (devices, operation) {
|
||||
var operationInstance;
|
||||
if (operation.type == "COMMAND") {
|
||||
operationInstance = new CommandOperation();
|
||||
} else if (operation.type == "CONFIG") {
|
||||
operationInstance = new ConfigOperation();
|
||||
} else {
|
||||
operationInstance = new SimpleOperation();
|
||||
}
|
||||
operationInstance.setCode(operation.featureName);
|
||||
var props = new Properties();
|
||||
var i, object;
|
||||
for (i = 0; i < operation.properties.length; i++) {
|
||||
object = properties[i];
|
||||
props.setProperty(object.key, object.value);
|
||||
}
|
||||
operationInstance.setProperties(props);
|
||||
var deviceList = new ArrayList();
|
||||
var j, device, deviceIdentifier;
|
||||
for (j = 0; j < devices.length; i++) {
|
||||
device = devices[j];
|
||||
deviceIdentifier = new DeviceIdentifier();
|
||||
deviceIdentifier.setId(device.id);
|
||||
deviceIdentifier.setType(device.type);
|
||||
deviceList.add(deviceIdentifier);
|
||||
}
|
||||
deviceManagementService.addOperation(operationInstance, deviceList);
|
||||
};
|
||||
|
||||
publicMethods.getDevice = function (type, deviceId) {
|
||||
var deviceIdentifier = new DeviceIdentifier();
|
||||
deviceIdentifier.setType(type);
|
||||
deviceIdentifier.setId(deviceId);
|
||||
return deviceManagementService.getDevice(deviceIdentifier);
|
||||
};
|
||||
|
||||
publicMethods.viewDevice = function (type, deviceId) {
|
||||
var device = publicMethods.getDevice(type, deviceId);
|
||||
if (device) {
|
||||
var propertiesList = DeviceManagerUtil.convertDevicePropertiesToMap(device.getProperties());
|
||||
var entries = propertiesList.entrySet();
|
||||
var iterator = entries.iterator();
|
||||
var properties = {};
|
||||
var entry, key, value;
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
entry = iterator.next();
|
||||
key = entry.getKey();
|
||||
value = entry.getValue();
|
||||
properties[key] = privateMethods.validateAndReturn(value);
|
||||
}
|
||||
|
||||
var deviceObject = {};
|
||||
deviceObject[constants.DEVICE_IDENTIFIER] = device.getDeviceIdentifier();
|
||||
deviceObject[constants.DEVICE_NAME] = privateMethods.validateAndReturn(device.getName());
|
||||
deviceObject[constants.DEVICE_OWNERSHIP] = privateMethods.validateAndReturn(device.getEnrolmentInfo().getOwnership());
|
||||
deviceObject[constants.DEVICE_OWNER] = device.getEnrolmentInfo().getOwner();
|
||||
deviceObject[constants.DEVICE_TYPE] = device.getType();
|
||||
if (device.getType() == constants.PLATFORM_IOS) {
|
||||
properties[constants.DEVICE_MODEL] = properties[constants.DEVICE_PRODUCT];
|
||||
delete properties[constants.DEVICE_PRODUCT];
|
||||
properties[constants.DEVICE_VENDOR] = constants.VENDOR_APPLE;
|
||||
}
|
||||
deviceObject[constants.DEVICE_PROPERTIES] = properties;
|
||||
deviceObject[constants.DEVICE_ENROLLMENT] = device.getEnrolmentInfo().getDateOfEnrolment();
|
||||
return deviceObject;
|
||||
}
|
||||
};
|
||||
|
||||
return publicMethods;
|
||||
|
||||
}();
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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 downloadModule;
|
||||
var Handlebars = require('../lib/handlebars-v2.0.0.js').Handlebars;
|
||||
downloadModule = function () {
|
||||
var log = new Log("modules/download.js");
|
||||
|
||||
var constants = require("/modules/constants.js");
|
||||
|
||||
var publicMethods = {};
|
||||
var privateMethods = {};
|
||||
|
||||
/**
|
||||
* Downloading a specified sketch file.
|
||||
*
|
||||
* @param file File name or file object of the downloading file
|
||||
* @param replaceParams
|
||||
*/
|
||||
publicMethods.downloadSketch = function (file, response, replaceParams) {
|
||||
var file = new File("../sketch/" + file);
|
||||
|
||||
file.open('r');
|
||||
log.debug("Reading file '" + file.getPath() + "'");
|
||||
var content = file.readAll().trim();
|
||||
file.close();
|
||||
|
||||
var downloadFile = privateMethods.allReplace(content,replaceParams);
|
||||
|
||||
response.contentType = "application/octet-stream";
|
||||
response.addHeader("Content-Disposition", "attachment; filename='sketch.hbs'");
|
||||
response.addHeader("Content-Length", String(downloadFile.length));
|
||||
response.content = downloadFile;
|
||||
};
|
||||
|
||||
/**
|
||||
* Find and replace all occurrences.
|
||||
* @param inStr input string
|
||||
* @param replaceParams key value array
|
||||
* @returns retStr replaced string
|
||||
*/
|
||||
privateMethods.allReplace = function (inStr, replaceParams) {
|
||||
var retStr = inStr;
|
||||
for (var x in replaceParams) {
|
||||
retStr = retStr.replace(new RegExp(x, 'g'), replaceParams[x])
|
||||
}
|
||||
return retStr;
|
||||
};
|
||||
|
||||
return publicMethods;
|
||||
}();
|
||||
|
||||
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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 eventModule;
|
||||
eventModule = function () {
|
||||
var log = new Log("modules/event.js");
|
||||
|
||||
var constants = require("/modules/constants.js");
|
||||
var utility = require("/modules/utility.js").utility;
|
||||
|
||||
var publicMethods = {};
|
||||
var privateMethods = {};
|
||||
|
||||
var statsClient = new Packages.org.wso2.carbon.device.mgt.iot.common.analytics.statistics.IoTEventsStatisticsClient;
|
||||
|
||||
publicMethods.getEventsData = function (username, recordLimit) {
|
||||
var fetchedData = null;
|
||||
|
||||
try {
|
||||
fetchedData = statsClient.getRecentDeviceStats(username, recordLimit);
|
||||
} catch (error) {
|
||||
log.error(error);
|
||||
}
|
||||
|
||||
var eventsData = [];
|
||||
|
||||
for (var i = 0; i < fetchedData.size(); i++) {
|
||||
eventsData.push({
|
||||
time: fetchedData.get(i).getTime(),
|
||||
deviceId: fetchedData.get(i).getDeviceId(),
|
||||
activity: fetchedData.get(i).getDeviceActivity()
|
||||
});
|
||||
};
|
||||
|
||||
return eventsData;
|
||||
};
|
||||
|
||||
|
||||
return publicMethods;
|
||||
}();
|
||||
|
||||
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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
|
||||
* Pinch is a small JavaScript utility which is able to replace any data in a JavaScript object (or JSON).
|
||||
* */
|
||||
(function(){var k=function(a,c){return a.length!==c.length?!1:a.every(function(a,b){return c[b]===a})},j=function(a,c,d){var b,e;if("[object Array]"===Object.prototype.toString.call(a)){b=0;for(e=a.length;b<e;b++)c.apply(d,[b,a[b],a])}else for(b in a)a.hasOwnProperty(b)&&c.apply(d,[b,a[b],a])},h=function(a){for(var c=[],d=!1,b=0,e=a.length,f="",g=function(){f&&(c.push(f),f="")};b<e;b++)a[b].match(/\[|\]/)?(g(),d="]"===a[b]?!1:!0):'"'!==a[b]&&"'"!==a[b]&&("."===a[b]&&!d?g():f+=a[b]),b===e-1&&g();return c},
|
||||
g=function(a,c,d){var b=-1!==["string","object"].indexOf(typeof a),e="string"===typeof c||c&&c.test&&c.exec,f=-1!==["string","object","function"].indexOf(typeof d);b&&e&&f&&("string"===typeof a?(this.instance=JSON.parse(a),this.json=!0):this.instance=a,this.pattern="string"===typeof c?c.replace(/'/g,'"'):c,this.replacement=d,this.createIndex(this.instance))};g.prototype.createIndex=function(a,c){var d=this;this.index=this.index||[];c=c||"";j(a,function(a,e){var f,a=a+"";f=a.match(/^[a-zA-Z]+$/)?c?
|
||||
c+"."+a:a:a.match(/\d+/)?c+"["+a+"]":c+'["'+a+'"]';d.index.push(f);"object"===typeof e&&d.createIndex(e,f)})};g.prototype.replace=function(){var a=this;j(this.index,function(c,d){if(a.pattern&&a.pattern.test&&a.pattern.exec&&d.match(a.pattern))return a.replaceValue(d);if("string"===typeof a.pattern){var b=h(d),e=h(a.pattern);if(k(b,e))return a.replaceValue(d)}});return this.json?JSON.stringify(this.instance):this.instance};g.prototype.replaceValue=function(a){var c=this,d=h(a);d.reduce(function(b,
|
||||
e,f){if(f===d.length-1)f="function"===typeof c.replacement?c.replacement(a,e,b[e]):c.replacement,b[e]=f;else return b[e]},this.instance)};var i=function(a,c,d,b){a=(new g(a,c,d)).replace();return"function"===typeof b?b(null,a):a};"undefined"!==typeof module&&module.exports?module.exports=i:"undefined"!==typeof define?define(function(){return i}):this.pinch=i})();
|
@ -0,0 +1,156 @@
|
||||
/*
|
||||
* 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 policyModule;
|
||||
policyModule = function () {
|
||||
var log = new Log("modules/policy.js");
|
||||
|
||||
var constants = require("/modules/constants.js");
|
||||
var utility = require("/modules/utility.js").utility;
|
||||
|
||||
var publicMethods = {};
|
||||
var privateMethods = {};
|
||||
|
||||
publicMethods.addPolicy = function (policyName, deviceType, policyDefinition, policyDescription) {
|
||||
if (policyName && deviceType) {
|
||||
|
||||
var carbonModule = require("carbon");
|
||||
var carbonServer = application.get("carbonServer");
|
||||
var options = {system: true};
|
||||
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||
|
||||
var resource = {
|
||||
name: policyName,
|
||||
mediaType: 'text/plain',
|
||||
content: policyDefinition,
|
||||
description: policyDescription,
|
||||
properties:{owner: carbonUser.username}
|
||||
};
|
||||
|
||||
if (carbonUser) {
|
||||
options.tenantId = carbonUser.tenantId;
|
||||
var registry = new carbonModule.registry.Registry(carbonServer, options);
|
||||
log.info("########### Policy name : " + policyName);
|
||||
log.info("########### Policy type : " + deviceType);
|
||||
log.info("########### Policy Declaration : " + policyDefinition);
|
||||
log.info("########### Policy policyDescription: " + policyDescription);
|
||||
registry.put(constants.POLICY_REGISTRY_PATH + deviceType + "/" + policyName, resource);
|
||||
}
|
||||
|
||||
var mqttsenderClass = Packages.org.wso2.device.mgt.mqtt.policy.push.MqttPush;
|
||||
var mqttsender = new mqttsenderClass();
|
||||
|
||||
var result = mqttsender.pushToMQTT("/iot/policymgt/govern/" + deviceType + "/" + carbonUser.username, policyDefinition, "tcp://localhost:1883", "Raspberry-Policy-sender");
|
||||
|
||||
mqttsender = null;
|
||||
|
||||
return true;
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
publicMethods.getPolicies = function () {
|
||||
var carbonModule = require("carbon");
|
||||
var carbonServer = application.get("carbonServer");
|
||||
var options = {system: true};
|
||||
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||
|
||||
var policies = [];
|
||||
|
||||
if (carbonUser) {
|
||||
options.tenantId = carbonUser.tenantId;
|
||||
var registry = new carbonModule.registry.Registry(carbonServer, options);
|
||||
var allPolicies = registry.get(constants.POLICY_REGISTRY_PATH);
|
||||
|
||||
if (allPolicies) {
|
||||
|
||||
//loop through all device types
|
||||
for (var i = 0; i < allPolicies.content.length; i++) {
|
||||
var deviceType = allPolicies.content[i].replace(constants.POLICY_REGISTRY_PATH, "");
|
||||
var deviceTypePolicies = registry.get(allPolicies.content[i]);
|
||||
|
||||
//loop through policies
|
||||
for (var j = 0; j < deviceTypePolicies.content.length; j++) {
|
||||
var deviceTypePolicy = registry.get(deviceTypePolicies.content[j]);
|
||||
|
||||
if(stringify(registry.properties(deviceTypePolicies.content[j]).owner) != '["'+carbonUser.username+'"]'){
|
||||
//not owned by current user, skip it
|
||||
continue;
|
||||
}
|
||||
|
||||
var policyObj = {
|
||||
"id": deviceTypePolicy.uuid, // Identifier of the policy.
|
||||
//"priorityId": 1, // Priority of the policies. This will be used only for simple evaluation.
|
||||
//"profile": {}, // Profile
|
||||
"policyName": deviceTypePolicy.name, // Name of the policy.
|
||||
"updated": deviceTypePolicy.updated.time,
|
||||
"deviceType": deviceType
|
||||
//"generic": true, // If true, this should be applied to all related device.
|
||||
//"roles": {}, // Roles which this policy should be applied.
|
||||
//"ownershipType": {}, // Ownership type (COPE, BYOD, CPE)
|
||||
//"devices": {}, // Individual devices this policy should be applied
|
||||
//"users": {}, // Individual users this policy should be applied
|
||||
//"Compliance": {},
|
||||
//"policyCriterias": {},
|
||||
//"startTime": 283468236, // Start time to apply the policy.
|
||||
//"endTime": 283468236, // After this time policy will not be applied
|
||||
//"startDate": "", // Start date to apply the policy
|
||||
//"endDate": "", // After this date policy will not be applied.
|
||||
//"tenantId": -1234,
|
||||
//"profileId": 1
|
||||
};
|
||||
|
||||
policies.push(policyObj);
|
||||
}//end of policy loop
|
||||
}//end of device type policy loop
|
||||
}
|
||||
}
|
||||
|
||||
return policies;
|
||||
|
||||
};
|
||||
|
||||
publicMethods.removePolicy = function (name, deviceType) {
|
||||
var carbonModule = require("carbon");
|
||||
var carbonServer = application.get("carbonServer");
|
||||
var options = {system: true};
|
||||
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||
var bool = false;
|
||||
|
||||
if (carbonUser) {
|
||||
options.tenantId = carbonUser.tenantId;
|
||||
var registry = new carbonModule.registry.Registry(carbonServer, options);
|
||||
log.info("########### Policy name : " + name);
|
||||
log.info("########### Policy type : " + deviceType);
|
||||
try {
|
||||
registry.remove(constants.POLICY_REGISTRY_PATH + deviceType + "/" + name);
|
||||
bool = true;
|
||||
} catch (err) {
|
||||
log.error("Error while trying to remove policy :" + name, err);
|
||||
}
|
||||
}
|
||||
|
||||
return bool;
|
||||
};
|
||||
|
||||
return publicMethods;
|
||||
}();
|
||||
|
||||
|
@ -0,0 +1,161 @@
|
||||
/*
|
||||
* 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 sso = {};
|
||||
var ssoMod = require("sso");
|
||||
var log = new Log();
|
||||
(function () {
|
||||
var carbon = require("carbon");
|
||||
var process = require("process");
|
||||
var getSSOSessions = function () {
|
||||
var sso_sessions = application.get('sso_sessions');
|
||||
|
||||
if (!sso_sessions) {
|
||||
application.put('sso_sessions', {});
|
||||
sso_sessions = application.get('sso_sessions');
|
||||
}
|
||||
return sso_sessions;
|
||||
};
|
||||
|
||||
sso.configure = function (issuer, appName, keyStoreParams, address, transport, ssoService, responseSign) {
|
||||
sso.issuer = issuer;
|
||||
sso.appName = appName;
|
||||
sso.relayState = "/" + appName;
|
||||
sso.transport = (transport ? transport : "https");
|
||||
sso.ssoService = (ssoService ? ssoService : "/samlsso");
|
||||
sso.responseSign = (responseSign ? responseSign : true);
|
||||
sso.log = new Log("SSO Module");
|
||||
sso.address = carbon.server.address(sso.transport);
|
||||
sso.keyStoreProps = {
|
||||
KEY_STORE_NAME: process.getProperty('carbon.home') + keyStoreParams.keyStoreName,
|
||||
KEY_STORE_PASSWORD: keyStoreParams.keyStorePassword,
|
||||
IDP_ALIAS: keyStoreParams.identityAlias
|
||||
};
|
||||
};
|
||||
|
||||
sso.login = function () {
|
||||
sso.sessionId = session.getId();
|
||||
var referer = request.getHeader("referer");
|
||||
sso.relayState = (referer ? referer : sso.relayState);
|
||||
sso.relayState = sso.relayState;// append query string
|
||||
var log = new Log();
|
||||
|
||||
if (request.getQueryString()) {
|
||||
|
||||
sso.relayState += request.getQueryString();
|
||||
}
|
||||
sso.encodedSAMLAuthRequest = ssoMod.client.getEncodedSAMLAuthRequest(sso.issuer);
|
||||
var postUrl = sso.address + sso.ssoService;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request sent to IdP");
|
||||
}
|
||||
print("<div><p>You are now being redirected to SSO Provider. If the redirection fails, please click on the "+
|
||||
"button below.</p> <form method='post' action='" + postUrl + "'><p><input type='hidden' " +
|
||||
"name='SAMLRequest' value='" + sso.encodedSAMLAuthRequest + "'/><input type='hidden' " +
|
||||
"name='RelayState' value='" + sso.relayState + "'/><input type='hidden' name='SSOAuthSessionID' " +
|
||||
"value='" + sso.sessionId + "'/><button type='submit'>Redirect manually</button></p></form></div>" +
|
||||
"<script type = 'text/javascript' >document.forms[0].submit();</script>");
|
||||
};
|
||||
|
||||
sso.logout = function (user) {
|
||||
var sso_sessions = getSSOSessions();
|
||||
sso.sessionId = session.getId();
|
||||
sso.sessionIndex = sso_sessions[sso.sessionId];
|
||||
|
||||
var referer = request.getHeader("referer");
|
||||
sso.relayState = (referer ? referer : sso.relayState);
|
||||
sso.relayState = sso.relayState + request.getQueryString(); // append query string
|
||||
sso.encodedSAMLLogoutRequest = ssoMod.client.getEncodedSAMLLogoutRequest(user, sso.sessionIndex, sso.issuer);
|
||||
var postUrl = sso.address + sso.ssoService;
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
sso.log.debug("Logout request recieved from session id ::: " + sso.sessionId);
|
||||
}
|
||||
print("<div><p>You are now redirected to Stratos Identity. If theredirection fails, please click the post " +
|
||||
"button.</p> <form id='logoutForm' method='post' action='" + postUrl + "'> <p> <input type='hidden' " +
|
||||
"name='SAMLRequest' value='" + sso.encodedSAMLLogoutRequest + "'/> <input type='hidden' " +
|
||||
"name='RelayState' value='" + sso.relayState + "'/> <input type='hidden' name='SSOAuthSessionID' " +
|
||||
"value='" + sso.sessionId + "'/> <button type='submit'>POST</button> </p> </form> </div> <script " +
|
||||
"type = 'text/javascript' > document.forms[0].submit(); </script>");
|
||||
};
|
||||
|
||||
sso.acs = function (loginCallback, logoutCallback) {
|
||||
var sso_sessions = getSSOSessions();
|
||||
sso.sessionId = session.getId();
|
||||
var samlResponse = request.getParameter('SAMLResponse');
|
||||
var samlRequest = request.getParameter('SAMLRequest');
|
||||
var relayState = request.getParameter('RelayState');
|
||||
var samlRespObj;
|
||||
|
||||
if (samlResponse != null) {
|
||||
samlRespObj = ssoMod.client.getSamlObject(samlResponse);
|
||||
if (ssoMod.client.isLogoutResponse(samlRespObj)) {
|
||||
logoutCallback();
|
||||
if (log.isDebugEnabled()) {
|
||||
sso.log.debug('Session Id Invalidated :::' + sso.sessionId);
|
||||
}
|
||||
// Invalidating the session after the callback
|
||||
session.invalidate();
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
sso.log.debug("Login request");
|
||||
}
|
||||
// validating the signature
|
||||
if (sso.responseSign) {
|
||||
if (ssoMod.client.validateSignature(samlRespObj, sso.keyStoreProps)) {
|
||||
var sessionObj = ssoMod.client.decodeSAMLLoginResponse(samlRespObj, samlResponse,
|
||||
sso.sessionId);
|
||||
if (log.isDebugEnabled()) {
|
||||
sso.log.debug("Saml object session ID :::" + sessionObj.sessionId);
|
||||
}
|
||||
if (sessionObj.sessionIndex != null || sessionObj.sessionIndex != 'undefined') {
|
||||
sso_sessions[sso_sessions[sessionObj.sessionIndex] = sessionObj.sessionId] =
|
||||
sessionObj.sessionIndex;
|
||||
if (log.isDebugEnabled()) {
|
||||
sso.log.debug("Login successful");
|
||||
sso.log.debug('User is set :::' + sessionObj.loggedInUser);
|
||||
}
|
||||
loginCallback(sessionObj.loggedInUser);
|
||||
} else {
|
||||
sso.log.error("Session index invalid");
|
||||
}
|
||||
} else {
|
||||
sso.log.error("Response Signing failed");
|
||||
}
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
sso.log.debug("Response Signing is disabled");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
Executed for single logout requests
|
||||
*/
|
||||
if (samlRequest != null) {
|
||||
var index = ssoMod.client.decodeSAMLLogoutRequest(ssoMod.client.getSamlObject(samlRequest));
|
||||
var jSessionId = getSSOSessions()[index];
|
||||
delete getSSOSessions()[index];
|
||||
if (log.isDebugEnabled()) {
|
||||
sso.log.debug('Backend logout received from store. The index is :::' + index);
|
||||
sso.log.debug('Session Id Invalidated :::' + jSessionId);
|
||||
}
|
||||
session.invalidate();
|
||||
}
|
||||
}
|
||||
})();
|
@ -0,0 +1,357 @@
|
||||
/*
|
||||
* 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 userModule;
|
||||
userModule = function () {
|
||||
var log = new Log("modules/user.js");
|
||||
|
||||
var constants = require("/modules/constants.js");
|
||||
var utility = require("/modules/utility.js").utility;
|
||||
|
||||
var publicMethods = {};
|
||||
var privateMethods = {};
|
||||
|
||||
/**
|
||||
* Authenticate a user when he or she attempts to login to DC.
|
||||
*
|
||||
* @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 {
|
||||
// get tenant specific full user name.
|
||||
username = username + "@" + carbonModule.server.tenantDomain();
|
||||
// check if the user is an authenticated user.
|
||||
var isAuthenticated = carbonServer.authenticate(username, password);
|
||||
if (isAuthenticated) {
|
||||
var tenantUser = carbonModule.server.tenantUser(username);
|
||||
session.put(constants.USER_SESSION_KEY, tenantUser);
|
||||
successCallback(tenantUser);
|
||||
} else {
|
||||
failureCallback();
|
||||
}
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 409;
|
||||
} 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 201;
|
||||
}
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Add 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 userRoles Roles assigned to the user
|
||||
*
|
||||
* @returns {number} HTTP Status code 201 if succeeded, 409 if user already exists
|
||||
*/
|
||||
publicMethods.addUser = function (username, firstname, lastname, emailAddress, userRoles) {
|
||||
var 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 409;
|
||||
} else {
|
||||
var initialUserPassword = privateMethods.generateInitialUserPassword();
|
||||
var defaultUserClaims = privateMethods.buildDefaultUserClaims(firstname, lastname, emailAddress);
|
||||
|
||||
userManager.addUser(username, initialUserPassword, userRoles, defaultUserClaims, "default");
|
||||
privateMethods.inviteUserToEnroll(username, initialUserPassword);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("A new user with name '" + username + "' was created.");
|
||||
}
|
||||
// http status code 201 refers to - created.
|
||||
return 201;
|
||||
}
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove an existing user from mdm-user-store.
|
||||
*
|
||||
* @param username Username of the user
|
||||
* @returns {number} HTTP Status code 200 if succeeded, 409 if the user does not exist
|
||||
*/
|
||||
publicMethods.removeUser = function (username) {
|
||||
var 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)) {
|
||||
userManager.removeUser(username);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("An existing user with name '" + username + "' was removed.");
|
||||
}
|
||||
// http status code 200 refers to - success.
|
||||
return 200;
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("A user with name '" + username + "' does not exist to remove.");
|
||||
}
|
||||
// http status code 409 refers to - conflict.
|
||||
return 409;
|
||||
}
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Private method to be used by addUser() to
|
||||
* generate an initial user password for a user.
|
||||
* This will be the password used by a user for his initial login to the system.
|
||||
*
|
||||
* @returns {string} Initial User Password
|
||||
*/
|
||||
privateMethods.generateInitialUserPassword = function () {
|
||||
var passwordLength = 6;
|
||||
//defining the pool of characters to be used for initial password generation
|
||||
var lowerCaseCharset = "abcdefghijklmnopqrstuvwxyz";
|
||||
var upperCaseCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
var numericCharset = "0123456789";
|
||||
|
||||
var totalCharset = lowerCaseCharset + upperCaseCharset + numericCharset;
|
||||
var totalCharsetLength = totalCharset.length;
|
||||
|
||||
var initialUserPassword = "";
|
||||
for (var i = 0; i < passwordLength; ++i) {
|
||||
initialUserPassword += totalCharset.charAt(Math.floor(Math.random() * totalCharsetLength));
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Initial password created for new user : " + initialUserPassword);
|
||||
}
|
||||
return String(initialUserPassword);
|
||||
};
|
||||
|
||||
/**
|
||||
* 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;
|
||||
};
|
||||
|
||||
publicMethods.addPermissions = function (permissionList, path, init) {
|
||||
var carbonModule = require("carbon");
|
||||
var carbonServer = application.get("carbonServer");
|
||||
var options = {system: true};
|
||||
if (init == "login") {
|
||||
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||
if (carbonUser) {
|
||||
options.tenantId = carbonUser.tenantId;
|
||||
}
|
||||
}
|
||||
var registry = new carbonModule.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
|
||||
}
|
||||
};
|
||||
registry.put("/_system/governance/permission/" + path + "/" + permission.key, resource);
|
||||
}
|
||||
};
|
||||
|
||||
publicMethods.getUsers = function () {
|
||||
var users = [];
|
||||
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||
if (!carbonUser) {
|
||||
log.error("User object was not found in the session");
|
||||
throw constants.ERRORS.USER_NOT_FOUND;
|
||||
}
|
||||
var carbon = require('carbon');
|
||||
var tenantId = carbon.server.tenantId();
|
||||
var url = carbon.server.address('https') + "/admin/services";
|
||||
var server = new carbon.server.Server(url);
|
||||
var userManager = new carbon.user.UserManager(server, tenantId);
|
||||
var userList = userManager.listUsers();
|
||||
var i, username, userObject, email, firstname, lastname;
|
||||
for (i = 0; i < userList.length; i++) {
|
||||
username = userList[i];
|
||||
userObject = userManager.getUser(username);
|
||||
email = userManager.getClaim(username,"http://wso2.org/claims/emailaddress", null);
|
||||
firstname = userManager.getClaim(username,"http://wso2.org/claims/givenname", null);
|
||||
lastname = userManager.getClaim(username,"http://wso2.org/claims/lastname", null);
|
||||
//log.info(userManager.getClaimsForSet(username, "http://wso2.org/claims/emailaddress,http://wso2.org/claims/givenname,http://wso2.org/claims/lastname".split(","), null));
|
||||
userObj = {
|
||||
"username" : userObject.username,
|
||||
"email" : email,
|
||||
"name" : firstname + " " + lastname
|
||||
};
|
||||
if(userObj.username == "admin"){
|
||||
userObj.name = "admin";
|
||||
}
|
||||
users.push(userObj);
|
||||
}
|
||||
return users;
|
||||
};
|
||||
|
||||
publicMethods.isAuthorized = function (permission) {
|
||||
var carbonModule = require("carbon");
|
||||
var carbonServer = application.get("carbonServer");
|
||||
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||
if (!carbonUser) {
|
||||
log.error("User object was not found in the session");
|
||||
throw constants.ERRORS.USER_NOT_FOUND;
|
||||
}
|
||||
var userManager = new carbonModule.user.UserManager(carbonServer, carbonUser.tenantId);
|
||||
var user = new carbonModule.user.User(userManager, carbonUser.username);
|
||||
return user.isAuthorized(permission, "ui.execute");
|
||||
};
|
||||
|
||||
publicMethods.getUIPermissions = function(){
|
||||
var permissions = {};
|
||||
if (publicMethods.isAuthorized("/permission/device-mgt/admin/devices/list") ||
|
||||
publicMethods.isAuthorized("/permission/device-mgt/user/devices/list")) {
|
||||
permissions.LIST_DEVICES = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/device-mgt/admin/users/list")) {
|
||||
permissions.LIST_USERS = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/device-mgt/admin/users/add")) {
|
||||
permissions.ADD_USER = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/device-mgt/admin/policies/add")) {
|
||||
permissions.ADD_POLICY = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/device-mgt/admin/policies/list")) {
|
||||
permissions.LIST_POLICIES = true;
|
||||
}
|
||||
if (publicMethods.isAuthorized("/permission/device-mgt/admin/dashboard/view")) {
|
||||
permissions.DASHBOARD_VIEW = true;
|
||||
}
|
||||
//TO-DO Apply followings in to carbon permissions
|
||||
permissions.ADD_DEVICE = true;
|
||||
return permissions;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get User Roles from user store.
|
||||
* If "Internal/Everyone" role is required - true param needs to be passed.
|
||||
* @param enableInternalEveryone boolean value true/false to enable Internal/Everyone role
|
||||
*/
|
||||
publicMethods.getRoles = function (enableInternalEveryone) {
|
||||
var carbonModule = require("carbon");
|
||||
var carbonServer = application.get("carbonServer");
|
||||
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||
if (!carbonUser) {
|
||||
log.error("User object was not found in the session");
|
||||
throw constants.ERRORS.USER_NOT_FOUND;
|
||||
}
|
||||
var userManager = new carbonModule.user.UserManager(carbonServer, carbonUser.tenantId);
|
||||
var allRoles = userManager.allRoles();
|
||||
var filteredRoles = [];
|
||||
var i;
|
||||
for (i = 0; i < allRoles.length; i++) {
|
||||
if (enableInternalEveryone && allRoles[i] == "Internal/everyone") {
|
||||
filteredRoles.push(allRoles[i]);
|
||||
}
|
||||
if (allRoles[i].indexOf("Internal/") != 0) {
|
||||
filteredRoles.push(allRoles[i]);
|
||||
}
|
||||
}
|
||||
return filteredRoles;
|
||||
};
|
||||
|
||||
publicMethods.logout = function (successCallback) {
|
||||
session.invalidate();
|
||||
successCallback();
|
||||
};
|
||||
|
||||
|
||||
|
||||
return publicMethods;
|
||||
}();
|
||||
|
||||
|
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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 util = function () {
|
||||
var module = {};
|
||||
var Base64 = Packages.org.apache.commons.codec.binary.Base64;
|
||||
var String = Packages.java.lang.String;
|
||||
var log = new Log();
|
||||
|
||||
/**
|
||||
* Encode the payload in Base64
|
||||
* @param payload
|
||||
* @returns {Packages.java.lang.String}
|
||||
*/
|
||||
function encode(payload){
|
||||
return new String(Base64.encodeBase64(new String(payload).getBytes()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an AccessToken pair based on username and password
|
||||
* @param username
|
||||
* @param password
|
||||
* @param clientId
|
||||
* @param clientSecret
|
||||
* @param scope
|
||||
* @returns {{accessToken: "", refreshToken: ""}}
|
||||
*/
|
||||
module.getTokenWithPasswordGrantType = function (username, password, clientId, clientSecret, scope) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
var tokenEndpoint = "https://localhost:9443/oauth2/token";
|
||||
var encodedClientKeys = encode(clientId + ":" + clientSecret);
|
||||
xhr.open("POST", tokenEndpoint, false);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.setRequestHeader("Authorization", "Basic " + encodedClientKeys);
|
||||
xhr.send("grant_type=password&username=" + username + "&password=" + password + "&scope=" + scope);
|
||||
delete password, delete clientSecret, delete encodedClientKeys;
|
||||
var tokenPair = {};
|
||||
if (xhr.status == 200) {
|
||||
var data = parse(xhr.responseText);
|
||||
tokenPair.refreshToken = data.refresh_token;
|
||||
tokenPair.accessToken = data.access_token;
|
||||
} else if (xhr.status == 403) {
|
||||
throw "Error in obtaining token with Password Grant Type";
|
||||
} else {
|
||||
throw "Error in obtaining token with Password Grant Type";
|
||||
}
|
||||
return tokenPair;
|
||||
};
|
||||
module.getTokenWithSAMLGrantType = function () {
|
||||
|
||||
};
|
||||
module.refreshToken = function(tokenPair){
|
||||
var xhr = new XMLHttpRequest();
|
||||
var tokenEndpoint = "https://localhost:9443/oauth2/token";
|
||||
var encodedClientKeys = encode(clientId + ":" + clientSecret);
|
||||
xhr.open("POST", tokenEndpoint, false);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.setRequestHeader("Authorization", "Basic " + encodedClientKeys);
|
||||
xhr.send("grant_type=refresh_token&refresh_token=" + tokenPair.refreshToken + "&scope=" + scope);
|
||||
delete password, delete clientSecret, delete encodedClientKeys;
|
||||
var tokenPair = {};
|
||||
if (xhr.status == 200) {
|
||||
var data = parse(xhr.responseText);
|
||||
tokenPair.refreshToken = data.refresh_token;
|
||||
tokenPair.accessToken = data.access_token;
|
||||
} else if (xhr.status == 403) {
|
||||
throw "Error in obtaining token with Password Grant Type";
|
||||
} else {
|
||||
throw "Error in obtaining token with Password Grant Type";
|
||||
}
|
||||
return tokenPair;
|
||||
};
|
||||
return module;
|
||||
}();
|
@ -0,0 +1,139 @@
|
||||
/*
|
||||
* 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 utility;
|
||||
utility = function () {
|
||||
var JavaClass = Packages.java.lang.Class;
|
||||
var PrivilegedCarbonContext = Packages.org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
|
||||
var getOsgiService = function (className) {
|
||||
return PrivilegedCarbonContext.getThreadLocalCarbonContext().getOSGiService(JavaClass.forName(className));
|
||||
};
|
||||
|
||||
var publicMethods = {};
|
||||
|
||||
publicMethods.getDeviceManagementService = function () {
|
||||
return getOsgiService('org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService');
|
||||
};
|
||||
|
||||
publicMethods.getPolicyManagementService = function () {
|
||||
return getOsgiService('org.wso2.carbon.policy.mgt.core.PolicyManagerService');
|
||||
};
|
||||
|
||||
publicMethods.insertAppPermissions = function (userModule, type) {
|
||||
userModule.addPermissions([{key: "device-mgt", name: "Device Management"}], "", type);
|
||||
userModule.addPermissions([{
|
||||
key: "admin",
|
||||
name: "Device Management Admin"
|
||||
}], "device-mgt", type);
|
||||
userModule.addPermissions([{
|
||||
key: "user",
|
||||
name: "Device Management User"
|
||||
}], "device-mgt", type);
|
||||
|
||||
userModule.addPermissions([{key: "devices", name: "Devices"}], "device-mgt/admin", type);
|
||||
userModule.addPermissions([{
|
||||
key: "devices/list",
|
||||
name: "List Devices"
|
||||
}], "device-mgt/admin", type);
|
||||
userModule.addPermissions([{
|
||||
key: "devices/operation",
|
||||
name: "Perform Operation"
|
||||
}], "device-mgt/admin", type);
|
||||
|
||||
userModule.addPermissions([{key: "groups", name: "Groups"}], "device-mgt/admin", type);
|
||||
userModule.addPermissions([{
|
||||
key: "groups/add_devices",
|
||||
name: "Add Devices to Group"
|
||||
}], "device-mgt/admin", type);
|
||||
userModule.addPermissions([{
|
||||
key: "groups/remove_devices",
|
||||
name: "Remove Devices from Group"
|
||||
}], "device-mgt/admin", type);
|
||||
userModule.addPermissions([{
|
||||
key: "groups/modify",
|
||||
name: "Modify Group"
|
||||
}], "device-mgt/admin", type);
|
||||
userModule.addPermissions([{
|
||||
key: "groups/share",
|
||||
name: "Change Group Sharing"
|
||||
}], "device-mgt/admin", type);
|
||||
userModule.addPermissions([{
|
||||
key: "groups/delete",
|
||||
name: "Delete Group"
|
||||
}], "device-mgt/admin", type);
|
||||
|
||||
userModule.addPermissions([{key: "users", name: "Users"}], "device-mgt/admin", type);
|
||||
userModule.addPermissions([{
|
||||
key: "users/add",
|
||||
name: "Add New Users"
|
||||
}], "device-mgt/admin", type);
|
||||
userModule.addPermissions([{
|
||||
key: "users/invite",
|
||||
name: "Invite Users"
|
||||
}], "device-mgt/admin", type);
|
||||
userModule.addPermissions([{
|
||||
key: "users/list",
|
||||
name: "List Users"
|
||||
}], "device-mgt/admin", type);
|
||||
userModule.addPermissions([{
|
||||
key: "users/remove",
|
||||
name: "Remove Users"
|
||||
}], "device-mgt/admin", type);
|
||||
|
||||
userModule.addPermissions([{key: "devices", name: "Devices"}], "device-mgt/user", type);
|
||||
userModule.addPermissions([{
|
||||
key: "devices/list",
|
||||
name: "List Devices"
|
||||
}], "device-mgt/user", type);
|
||||
userModule.addPermissions([{
|
||||
key: "devices/operation",
|
||||
name: "Perform Operation"
|
||||
}], "device-mgt/user", "init");
|
||||
|
||||
userModule.addPermissions([{key: "groups", name: "Groups"}], "device-mgt/user", type);
|
||||
userModule.addPermissions([{
|
||||
key: "groups/device_monitor",
|
||||
name: "Monitor Statistics Devices in Group"
|
||||
}], "device-mgt/user", type);
|
||||
userModule.addPermissions([{
|
||||
key: "groups/device_operation",
|
||||
name: "Perform Device Operation"
|
||||
}], "device-mgt/user", type);
|
||||
userModule.addPermissions([{
|
||||
key: "groups/device_policies/add",
|
||||
name: "Apply Device Policies"
|
||||
}], "device-mgt/user", type);
|
||||
userModule.addPermissions([{
|
||||
key: "groups/device_policies/view",
|
||||
name: "View Device Policies"
|
||||
}], "device-mgt/user", type);
|
||||
userModule.addPermissions([{
|
||||
key: "groups/device_events",
|
||||
name: "Monitor Device Events"
|
||||
}], "device-mgt/user", type);
|
||||
userModule.addPermissions([{
|
||||
key: "groups/device_list",
|
||||
name: "List Groups of User"
|
||||
}], "device-mgt/user", type);
|
||||
};
|
||||
|
||||
return publicMethods;
|
||||
}();
|
||||
|
||||
|
@ -0,0 +1,12 @@
|
||||
<%
|
||||
var userModule = require("/modules/user.js").userModule;
|
||||
userModule.addPermissions([{key: "device-mgt/", name: "Device Management"}], "");
|
||||
userModule.addPermissions([{key: "device-mgt/admin", name: "Device Management Admin"}], "");
|
||||
userModule.addPermissions([{key: "device-mgt/user", name: "Device Management User"}], "");
|
||||
|
||||
userModule.addPermissions([{key: "devices", name: "Device"}], "device-mgt/admin");
|
||||
userModule.addPermissions([{key: "devices", name: "Device"}], "device-mgt/user");
|
||||
userModule.addPermissions([{key: "devices/list", name: "List all Devices"}], "device-mgt/admin");
|
||||
userModule.addPermissions([{key: "devices/list", name: "List own Devices"}], "device-mgt/user");
|
||||
new Log().info(userModule.isAuthorized("/permission/device-mgt/admin/devices/list"));
|
||||
%>
|
@ -0,0 +1,4 @@
|
||||
<%
|
||||
var apiWrapperUtil = require("/modules/api-wrapper-util.js").apiWrapperUtil;
|
||||
apiWrapperUtil.refreshToken();
|
||||
%>
|
96
features/device-mgt-iot/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/iotserver/units/alldevices/public/js/alldevices_util.js → features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/iotserver/units/alldevices/public/js/alldevices_util.js
@ -1,49 +1,49 @@
|
||||
function getAllDevices() {
|
||||
var getDevicesRequest = $.ajax({
|
||||
url: "api/devices/all/",
|
||||
method: "GET",
|
||||
contentType: "application/json"
|
||||
});
|
||||
|
||||
getDevicesRequest.done(function (data) {
|
||||
updateDevicesTable(JSON.parse(data));
|
||||
});
|
||||
|
||||
getDevicesRequest.fail(function (jqXHR, textStatus) {
|
||||
var err = jqXHR;
|
||||
alert("Request failed: " + textStatus);
|
||||
});
|
||||
}
|
||||
|
||||
function updateDevicesTable(data) {
|
||||
devices = data.data.device;
|
||||
if (devices.length > 0) {
|
||||
clearTable('devicesTable');
|
||||
for (var i = 0; i < devices.length; i++) {
|
||||
var deviceIdentifier = devices[i].deviceIdentifier;
|
||||
var deviceName = devices[i].name;
|
||||
var deviceType = devices[i].type;
|
||||
$('#devicesTable tbody').append(
|
||||
"<tr class='border-top'><th scope='row'>" + deviceIdentifier + "</th>" +
|
||||
"<td>" + deviceName + "</td>" +
|
||||
"<td>" + deviceType + "</td>" +
|
||||
"<td class='float-right border-top '>" +
|
||||
"<input type='hidden' name='deviceType' value='" + deviceType + "' >" +
|
||||
"<button class='btn-black-action' name='deviceId' value='" + deviceIdentifier + "'>" +
|
||||
"<i class='fw fw-view padding-right'></i>View</button>" +
|
||||
"<button class='btn-black-action' name='deviceId' value='" + deviceIdentifier + "'>" +
|
||||
"<i class='fw fw-edit padding-right'></i>Edit</button>" +
|
||||
"<button class='btn-black-action' name='deviceId' value='" + deviceIdentifier + "'>" +
|
||||
"<i class='fw fw-delete padding-right'></i>Remove</button>" +
|
||||
"</td></tr>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function clearTable(tableId) {
|
||||
$('#' + tableId + ' tbody > tr').remove();
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
getAllDevices();
|
||||
function getAllDevices() {
|
||||
var getDevicesRequest = $.ajax({
|
||||
url: "api/devices/all/",
|
||||
method: "GET",
|
||||
contentType: "application/json"
|
||||
});
|
||||
|
||||
getDevicesRequest.done(function (data) {
|
||||
updateDevicesTable(JSON.parse(data));
|
||||
});
|
||||
|
||||
getDevicesRequest.fail(function (jqXHR, textStatus) {
|
||||
var err = jqXHR;
|
||||
alert("Request failed: " + textStatus);
|
||||
});
|
||||
}
|
||||
|
||||
function updateDevicesTable(data) {
|
||||
devices = data.data.device;
|
||||
if (devices.length > 0) {
|
||||
clearTable('devicesTable');
|
||||
for (var i = 0; i < devices.length; i++) {
|
||||
var deviceIdentifier = devices[i].deviceIdentifier;
|
||||
var deviceName = devices[i].name;
|
||||
var deviceType = devices[i].type;
|
||||
$('#devicesTable tbody').append(
|
||||
"<tr class='border-top'><th scope='row'>" + deviceIdentifier + "</th>" +
|
||||
"<td>" + deviceName + "</td>" +
|
||||
"<td>" + deviceType + "</td>" +
|
||||
"<td class='float-right border-top '>" +
|
||||
"<input type='hidden' name='deviceType' value='" + deviceType + "' >" +
|
||||
"<button class='btn-black-action' name='deviceId' value='" + deviceIdentifier + "'>" +
|
||||
"<i class='fw fw-view padding-right'></i>View</button>" +
|
||||
"<button class='btn-black-action' name='deviceId' value='" + deviceIdentifier + "'>" +
|
||||
"<i class='fw fw-edit padding-right'></i>Edit</button>" +
|
||||
"<button class='btn-black-action' name='deviceId' value='" + deviceIdentifier + "'>" +
|
||||
"<i class='fw fw-delete padding-right'></i>Remove</button>" +
|
||||
"</td></tr>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function clearTable(tableId) {
|
||||
$('#' + tableId + ' tbody > tr').remove();
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
getAllDevices();
|
||||
});
|
@ -0,0 +1,7 @@
|
||||
{{#zone "topCss"}}
|
||||
<link href="{{self.publicURL}}/css/daterangepicker.css" rel="stylesheet"/>
|
||||
<link href="{{self.publicURL}}/css/graph.css" rel="stylesheet"/>
|
||||
<link href="{{self.publicURL}}/css/lines.css" rel="stylesheet"/>
|
||||
<link href="{{self.publicURL}}/css/legend.css" rel="stylesheet"/>
|
||||
<link href="{{self.publicURL}}/css/detail.css" rel="stylesheet"/>
|
||||
{{/zone}}
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"predicate": "urlMatch('/analytics')"
|
||||
}
|
0
features/device-mgt-iot/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/store/extensions/app/store-device-type/themes/store/css/daterangepicker.css → features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/iotserver/units/analiytics-graphs/public/css/daterangepicker.css
@ -0,0 +1,105 @@
|
||||
.rickshaw_graph .detail {
|
||||
pointer-events: none;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
z-index: 2;
|
||||
background: rgba(0, 0, 0, 0.1);
|
||||
bottom: 0;
|
||||
width: 1px;
|
||||
transition: opacity 0.25s linear;
|
||||
-moz-transition: opacity 0.25s linear;
|
||||
-o-transition: opacity 0.25s linear;
|
||||
-webkit-transition: opacity 0.25s linear;
|
||||
}
|
||||
.rickshaw_graph .detail.inactive {
|
||||
opacity: 0;
|
||||
}
|
||||
.rickshaw_graph .detail .item.active {
|
||||
opacity: 1;
|
||||
}
|
||||
.rickshaw_graph .detail .x_label {
|
||||
font-family: Arial, sans-serif;
|
||||
border-radius: 3px;
|
||||
padding: 6px;
|
||||
opacity: 0.5;
|
||||
border: 1px solid #e0e0e0;
|
||||
font-size: 12px;
|
||||
position: absolute;
|
||||
background: white;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.rickshaw_graph .detail .x_label.left {
|
||||
left: 0;
|
||||
}
|
||||
.rickshaw_graph .detail .x_label.right {
|
||||
right: 0;
|
||||
}
|
||||
.rickshaw_graph .detail .item {
|
||||
position: absolute;
|
||||
z-index: 2;
|
||||
border-radius: 3px;
|
||||
padding: 0.25em;
|
||||
font-size: 12px;
|
||||
font-family: Arial, sans-serif;
|
||||
opacity: 0;
|
||||
background: rgba(0, 0, 0, 0.4);
|
||||
color: white;
|
||||
border: 1px solid rgba(0, 0, 0, 0.4);
|
||||
margin-left: 1em;
|
||||
margin-right: 1em;
|
||||
margin-top: -1em;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.rickshaw_graph .detail .item.left {
|
||||
left: 0;
|
||||
}
|
||||
.rickshaw_graph .detail .item.right {
|
||||
right: 0;
|
||||
}
|
||||
.rickshaw_graph .detail .item.active {
|
||||
opacity: 1;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
}
|
||||
.rickshaw_graph .detail .item:after {
|
||||
position: absolute;
|
||||
display: block;
|
||||
width: 0;
|
||||
height: 0;
|
||||
|
||||
content: "";
|
||||
|
||||
border: 5px solid transparent;
|
||||
}
|
||||
.rickshaw_graph .detail .item.left:after {
|
||||
top: 1em;
|
||||
left: -5px;
|
||||
margin-top: -5px;
|
||||
border-right-color: rgba(0, 0, 0, 0.8);
|
||||
border-left-width: 0;
|
||||
}
|
||||
.rickshaw_graph .detail .item.right:after {
|
||||
top: 1em;
|
||||
right: -5px;
|
||||
margin-top: -5px;
|
||||
border-left-color: rgba(0, 0, 0, 0.8);
|
||||
border-right-width: 0;
|
||||
}
|
||||
.rickshaw_graph .detail .dot {
|
||||
width: 4px;
|
||||
height: 4px;
|
||||
margin-left: -3px;
|
||||
margin-top: -3.5px;
|
||||
border-radius: 5px;
|
||||
position: absolute;
|
||||
box-shadow: 0 0 2px rgba(0, 0, 0, 0.6);
|
||||
box-sizing: content-box;
|
||||
-moz-box-sizing: content-box;
|
||||
background: white;
|
||||
border-width: 2px;
|
||||
border-style: solid;
|
||||
display: none;
|
||||
background-clip: padding-box;
|
||||
}
|
||||
.rickshaw_graph .detail .dot.active {
|
||||
display: block;
|
||||
}
|
@ -0,0 +1,197 @@
|
||||
/* graph */
|
||||
|
||||
.rickshaw_graph {
|
||||
position: relative;
|
||||
}
|
||||
.rickshaw_graph svg {
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* ticks */
|
||||
|
||||
.rickshaw_graph .x_tick {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: 0px;
|
||||
border-left: 1px dotted rgba(0, 0, 0, 0.2);
|
||||
pointer-events: none;
|
||||
}
|
||||
.rickshaw_graph .x_tick .title {
|
||||
position: absolute;
|
||||
font-size: 12px;
|
||||
font-family: Arial, sans-serif;
|
||||
opacity: 0.5;
|
||||
white-space: nowrap;
|
||||
margin-left: 3px;
|
||||
bottom: -20px;
|
||||
}
|
||||
|
||||
/* annotations */
|
||||
|
||||
.rickshaw_annotation_timeline {
|
||||
height: 1px;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
margin-top: 10px;
|
||||
position: relative;
|
||||
}
|
||||
.rickshaw_annotation_timeline .annotation {
|
||||
position: absolute;
|
||||
height: 6px;
|
||||
width: 6px;
|
||||
margin-left: -2px;
|
||||
top: -3px;
|
||||
border-radius: 5px;
|
||||
background-color: rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
.rickshaw_graph .annotation_line {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: -6px;
|
||||
width: 0px;
|
||||
border-left: 2px solid rgba(0, 0, 0, 0.3);
|
||||
display: none;
|
||||
}
|
||||
.rickshaw_graph .annotation_line.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.rickshaw_graph .annotation_range {
|
||||
background: rgba(0, 0, 0, 0.1);
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: -6px;
|
||||
}
|
||||
.rickshaw_graph .annotation_range.active {
|
||||
display: block;
|
||||
}
|
||||
.rickshaw_graph .annotation_range.active.offscreen {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.rickshaw_annotation_timeline .annotation .content {
|
||||
background: white;
|
||||
color: black;
|
||||
opacity: 0.9;
|
||||
padding: 5px 5px;
|
||||
box-shadow: 0 0 2px rgba(0, 0, 0, 0.8);
|
||||
border-radius: 3px;
|
||||
position: relative;
|
||||
z-index: 20;
|
||||
font-size: 12px;
|
||||
padding: 6px 8px 8px;
|
||||
top: 18px;
|
||||
left: -11px;
|
||||
width: 160px;
|
||||
display: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
.rickshaw_annotation_timeline .annotation .content:before {
|
||||
content: "\25b2";
|
||||
position: absolute;
|
||||
top: -11px;
|
||||
color: white;
|
||||
text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.8);
|
||||
}
|
||||
.rickshaw_annotation_timeline .annotation.active,
|
||||
.rickshaw_annotation_timeline .annotation:hover {
|
||||
background-color: rgba(0, 0, 0, 0.8);
|
||||
cursor: none;
|
||||
}
|
||||
.rickshaw_annotation_timeline .annotation .content:hover {
|
||||
z-index: 50;
|
||||
}
|
||||
.rickshaw_annotation_timeline .annotation.active .content {
|
||||
display: block;
|
||||
}
|
||||
.rickshaw_annotation_timeline .annotation:hover .content {
|
||||
display: block;
|
||||
z-index: 50;
|
||||
}
|
||||
.rickshaw_graph .y_axis,
|
||||
.rickshaw_graph .x_axis_d3 {
|
||||
fill: none;
|
||||
}
|
||||
.rickshaw_graph .y_ticks .tick line,
|
||||
.rickshaw_graph .x_ticks_d3 .tick {
|
||||
stroke: rgba(0, 0, 0, 0.16);
|
||||
stroke-width: 2px;
|
||||
shape-rendering: crisp-edges;
|
||||
pointer-events: none;
|
||||
}
|
||||
.rickshaw_graph .y_grid .tick,
|
||||
.rickshaw_graph .x_grid_d3 .tick {
|
||||
z-index: -1;
|
||||
stroke: rgba(0, 0, 0, 0.20);
|
||||
stroke-width: 1px;
|
||||
stroke-dasharray: 1 1;
|
||||
}
|
||||
.rickshaw_graph .y_grid .tick[data-y-value="0"] {
|
||||
stroke-dasharray: 1 0;
|
||||
}
|
||||
.rickshaw_graph .y_grid path,
|
||||
.rickshaw_graph .x_grid_d3 path {
|
||||
fill: none;
|
||||
stroke: none;
|
||||
}
|
||||
.rickshaw_graph .y_ticks path,
|
||||
.rickshaw_graph .x_ticks_d3 path {
|
||||
fill: none;
|
||||
stroke: #808080;
|
||||
}
|
||||
.rickshaw_graph .y_ticks text,
|
||||
.rickshaw_graph .x_ticks_d3 text {
|
||||
opacity: 0.5;
|
||||
font-size: 12px;
|
||||
pointer-events: none;
|
||||
}
|
||||
.rickshaw_graph .x_tick.glow .title,
|
||||
.rickshaw_graph .y_ticks.glow text {
|
||||
fill: black;
|
||||
color: black;
|
||||
text-shadow:
|
||||
-1px 1px 0 rgba(255, 255, 255, 0.1),
|
||||
1px -1px 0 rgba(255, 255, 255, 0.1),
|
||||
1px 1px 0 rgba(255, 255, 255, 0.1),
|
||||
0px 1px 0 rgba(255, 255, 255, 0.1),
|
||||
0px -1px 0 rgba(255, 255, 255, 0.1),
|
||||
1px 0px 0 rgba(255, 255, 255, 0.1),
|
||||
-1px 0px 0 rgba(255, 255, 255, 0.1),
|
||||
-1px -1px 0 rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
.rickshaw_graph .x_tick.inverse .title,
|
||||
.rickshaw_graph .y_ticks.inverse text {
|
||||
fill: white;
|
||||
color: white;
|
||||
text-shadow:
|
||||
-1px 1px 0 rgba(0, 0, 0, 0.8),
|
||||
1px -1px 0 rgba(0, 0, 0, 0.8),
|
||||
1px 1px 0 rgba(0, 0, 0, 0.8),
|
||||
0px 1px 0 rgba(0, 0, 0, 0.8),
|
||||
0px -1px 0 rgba(0, 0, 0, 0.8),
|
||||
1px 0px 0 rgba(0, 0, 0, 0.8),
|
||||
-1px 0px 0 rgba(0, 0, 0, 0.8),
|
||||
-1px -1px 0 rgba(0, 0, 0, 0.8);
|
||||
}
|
||||
|
||||
.custom_rickshaw_graph {
|
||||
position: relative;
|
||||
left: 40px;
|
||||
}
|
||||
|
||||
.custom_y_axis {
|
||||
position: absolute;
|
||||
width: 40px;
|
||||
}
|
||||
|
||||
.custom_slider {
|
||||
left: 40px;
|
||||
}
|
||||
|
||||
.custom_x_axis {
|
||||
position: relative;
|
||||
left: 40px;
|
||||
height: 30px;
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
.rickshaw_legend {
|
||||
font-family: Arial;
|
||||
font-size: 12px;
|
||||
color: white;
|
||||
background: #404040;
|
||||
display: inline-block;
|
||||
padding: 12px 5px;
|
||||
border-radius: 2px;
|
||||
position: relative;
|
||||
float: right;
|
||||
}
|
||||
.rickshaw_legend:hover {
|
||||
z-index: 10;
|
||||
}
|
||||
.rickshaw_legend .swatch {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border: 1px solid rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
.rickshaw_legend .line {
|
||||
clear: both;
|
||||
line-height: 140%;
|
||||
padding-right: 15px;
|
||||
}
|
||||
.rickshaw_legend .line .swatch {
|
||||
display: inline-block;
|
||||
margin-right: 3px;
|
||||
border-radius: 2px;
|
||||
}
|
||||
.rickshaw_legend .label {
|
||||
margin: 0;
|
||||
white-space: nowrap;
|
||||
display: inline;
|
||||
font-size: inherit;
|
||||
background-color: transparent;
|
||||
color: inherit;
|
||||
font-weight: normal;
|
||||
line-height: normal;
|
||||
padding: 0px;
|
||||
text-shadow: none;
|
||||
}
|
||||
.rickshaw_legend .action:hover {
|
||||
opacity: 0.6;
|
||||
}
|
||||
.rickshaw_legend .action {
|
||||
margin-right: 0.2em;
|
||||
font-size: 10px;
|
||||
opacity: 0.2;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
}
|
||||
.rickshaw_legend .line.disabled {
|
||||
opacity: 0.4;
|
||||
}
|
||||
.rickshaw_legend ul {
|
||||
list-style-type: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
margin: 2px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.rickshaw_legend li {
|
||||
padding: 0 0 0 2px;
|
||||
min-width: 80px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.rickshaw_legend li:hover {
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
border-radius: 3px;
|
||||
}
|
||||
.rickshaw_legend li:active {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-radius: 3px;
|
||||
}
|
||||
.legend {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
left: 8px;
|
||||
}
|
||||
.legend_container {
|
||||
float: right;
|
||||
padding-right: 10px;
|
||||
width: 0;
|
||||
z-index: 1;
|
||||
position: relative;
|
||||
opacity: 0.7;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
div, span, p, td {
|
||||
font-family: Arial, sans-serif;
|
||||
}
|
||||
#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;
|
||||
}
|
0
features/device-mgt-iot/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/iotserver/units/analytics/public/images/bulb-off.png → features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/iotserver/units/analytics/public/images/bulb-off.png
Before Width: | Height: | Size: 516 B After Width: | Height: | Size: 516 B |
0
features/device-mgt-iot/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/iotserver/units/analytics/public/images/bulb-on.png → features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/iotserver/units/analytics/public/images/bulb-on.png
Before Width: | Height: | Size: 451 B After Width: | Height: | Size: 451 B |
Before Width: | Height: | Size: 650 B After Width: | Height: | Size: 650 B |
Before Width: | Height: | Size: 373 B After Width: | Height: | Size: 373 B |
0
features/device-mgt-iot/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/iotserver/units/analytics/public/js/d3.min.js → features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/iotserver/units/analytics/public/js/d3.min.js
vendored
0
features/device-mgt-iot/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/iotserver/units/analytics/public/js/jquery-ui-timepicker-addon.js → features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/iotserver/units/analytics/public/js/jquery-ui-timepicker-addon.js
vendored
0
features/device-mgt-iot/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/iotserver/units/analytics/public/js/jquery.daterangepicker.js → features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/iotserver/units/analytics/public/js/jquery.daterangepicker.js
0
features/device-mgt-iot/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/iotserver/units/analytics/public/js/moment.min.js → features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/iotserver/units/analytics/public/js/moment.min.js
vendored
0
features/device-mgt-iot/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/iotserver/units/analytics/public/js/rickshaw.min.js → features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/iotserver/units/analytics/public/js/rickshaw.min.js
vendored
@ -1,56 +1,56 @@
|
||||
{{#zone "main"}}
|
||||
|
||||
<!-- new markup -->
|
||||
<!-- secondary header - app bar -->
|
||||
<div id="nav" class="row wr-app-bar">
|
||||
<div class="wr-action-container">
|
||||
<div class="wr-action-btn-bar">
|
||||
<a href="javascript:openCollapsedNav()" class="cu-btn wr-hidden-nav-toggle-btn">
|
||||
<i class="fw fw-tiles fw-2x"></i>
|
||||
</a><a class="cu-btn page-title" href='javascript:location.reload();'>
|
||||
<span class="fw-stack"></span>
|
||||
{{title}}
|
||||
</a>{{#each currentActions}}<a href="{{url}}" class="cu-btn {{class}}">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-ring fw-stack-2x"></i>
|
||||
<i class="fw {{icon}} fw-stack-1x"></i>
|
||||
</span>
|
||||
{{title}}
|
||||
</a>
|
||||
{{/each}}{{#if enableBack}}<a href="javascript:history.go(-1)" class="cu-btn">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-ring fw-stack-2x"></i>
|
||||
<i class="fw fw-left-arrow fw-stack-1x"></i>
|
||||
</span>
|
||||
Go Back
|
||||
</a>
|
||||
{{/if}}
|
||||
<a href="javascript:toggleNotificationbar()" class="cu-btn wr-notification-toggle-btn">
|
||||
<span class="fw-stack-md">
|
||||
<i class="fw fw-bell fw-stack-1-5x"></i>
|
||||
</span>
|
||||
<span class="wr-notification-bubble">0</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- secondary header - app bar -->
|
||||
|
||||
<!-- common navigation -->
|
||||
<div id="hiddenNav" class="wr-hidden-nav">
|
||||
<ul>
|
||||
<li><a href="/iotserver/dashboard"><i class="fw fw-dashboard"></i>Dashboard</a></li>
|
||||
<li><a href="/iotserver/devices"><i class="fw fw-devices"></i>My Devices</a></li>
|
||||
<li><a href="/iotserver/groups"><i class="fw fw-grouping"></i>My Groups</a></li>
|
||||
{{#if permissions.ADD_USER}}
|
||||
<li><a href="/iotserver/users"><i class="fw fw-user"></i>User Management</a></li>
|
||||
{{/if}}
|
||||
<li><a href="/iotserver/policies"><i class="fw fw-policy"></i>Policy Management</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<!-- /common navigation -->
|
||||
|
||||
|
||||
|
||||
|
||||
{{#zone "main"}}
|
||||
|
||||
<!-- new markup -->
|
||||
<!-- secondary header - app bar -->
|
||||
<div id="nav" class="row wr-app-bar">
|
||||
<div class="wr-action-container">
|
||||
<div class="wr-action-btn-bar">
|
||||
<a href="javascript:openCollapsedNav()" class="cu-btn wr-hidden-nav-toggle-btn">
|
||||
<i class="fw fw-tiles fw-2x"></i>
|
||||
</a><a class="cu-btn page-title" href='javascript:location.reload();'>
|
||||
<span class="fw-stack"></span>
|
||||
{{title}}
|
||||
</a>{{#each currentActions}}<a href="{{url}}" class="cu-btn {{class}}">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-ring fw-stack-2x"></i>
|
||||
<i class="fw {{icon}} fw-stack-1x"></i>
|
||||
</span>
|
||||
{{title}}
|
||||
</a>
|
||||
{{/each}}{{#if enableBack}}<a href="javascript:history.go(-1)" class="cu-btn">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-ring fw-stack-2x"></i>
|
||||
<i class="fw fw-left-arrow fw-stack-1x"></i>
|
||||
</span>
|
||||
Go Back
|
||||
</a>
|
||||
{{/if}}
|
||||
<a href="javascript:toggleNotificationbar()" class="cu-btn wr-notification-toggle-btn">
|
||||
<span class="fw-stack-md">
|
||||
<i class="fw fw-bell fw-stack-1-5x"></i>
|
||||
</span>
|
||||
<span class="wr-notification-bubble">0</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- secondary header - app bar -->
|
||||
|
||||
<!-- common navigation -->
|
||||
<div id="hiddenNav" class="wr-hidden-nav">
|
||||
<ul>
|
||||
<li><a href="/iotserver/dashboard"><i class="fw fw-dashboard"></i>Dashboard</a></li>
|
||||
<li><a href="/iotserver/devices"><i class="fw fw-devices"></i>My Devices</a></li>
|
||||
<li><a href="/iotserver/groups"><i class="fw fw-grouping"></i>My Groups</a></li>
|
||||
{{#if permissions.ADD_USER}}
|
||||
<li><a href="/iotserver/users"><i class="fw fw-user"></i>User Management</a></li>
|
||||
{{/if}}
|
||||
<li><a href="/iotserver/policies"><i class="fw fw-policy"></i>Policy Management</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<!-- /common navigation -->
|
||||
|
||||
|
||||
|
||||
|
||||
{{/zone}}
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"predicate": "false"
|
||||
}
|
0
features/device-mgt-iot/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/iotserver/units/device-detail/public/img/device_icons/android.png → features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/iotserver/units/device-detail/public/img/device_icons/android.png
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
0
features/device-mgt-iot/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/iotserver/units/device-detail/public/img/device_icons/arduino.png → features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/iotserver/units/device-detail/public/img/device_icons/arduino.png
Before Width: | Height: | Size: 9.6 KiB After Width: | Height: | Size: 9.6 KiB |