Merge branch 'qr-prov' into 'master'

Implement QR code provisioning for KIOSK

See merge request entgra/carbon-device-mgt-plugins!13
revert-dabc3590
Inosh Perara 6 years ago
commit 8697bbeb29

@ -71,6 +71,92 @@
<div class="wr-input-control">
<textarea id="android-eula" type="text" class="form-control"></textarea>
</div>
<!-- KIOSK Configs -->
<h4>
Android KIOSK Provisioning Configs
<hr>
</h4>
<div class="kiosk-inputs">
<div class="wr-input-control">
<label class="wr-input-label" for="android-kiosk-config-admin-component">
PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
<!--<span class="helper" title="Time interval after which Android agent will contact IoT Server each time to fetch data">-->
<!--<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>-->
<!--</span>-->
<br>
( ex: org.wso2.iot.agent/org.wso2.iot.agent.services.AgentDeviceAdminReceiver )
</label>
<input id="android-kiosk-config-admin-component" type="text" class="form-control" >
</div>
<div class="wr-input-control">
<label class="wr-input-label" for="android-kiosk-config-checksum">
PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
<!--<span class="helper" title="Time interval after which Android agent will contact IoT Server each time to fetch data">-->
<!--<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>-->
<!--</span>-->
<br>
( ex: gJD2YwtOiWJHkSMkkIfLRlj-quNqG1fb6v100QmzM9w= )
</label>
<input id="android-kiosk-config-checksum" type="text" class="form-control" >
</div>
<div class="wr-input-control">
<label class="wr-input-label" for="android-kiosk-config-download-url">
PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
<!--<span class="helper" title="Time interval after which Android agent will contact IoT Server each time to fetch data">-->
<!--<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>-->
<!--</span>-->
<br>
( ex: http://192.168.8.20:8080/android.apk )
</label>
<input id="android-kiosk-config-download-url" type="text" class="form-control" >
</div>
<div class="wr-input-control">
<label class="wr-input-label" for="android-kiosk-config-wifi-ssid">
PROVISIONING_WIFI_SSID
<!--<span class="helper" title="Time interval after which Android agent will contact IoT Server each time to fetch data">-->
<!--<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>-->
<!--</span>-->
<br>
( ex: Entgra )
</label>
<input id="android-kiosk-config-wifi-ssid" type="text" class="form-control" >
</div>
<div class="wr-input-control">
<label class="wr-input-label" for="android-kiosk-config-wifi-password">
PROVISIONING_WIFI_PASSWORD
<!--<span class="helper" title="Time interval after which Android agent will contact IoT Server each time to fetch data">-->
<!--<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>-->
<!--</span>-->
<br>
</label>
<input id="android-kiosk-config-wifi-password" type="text" class="form-control" >
</div>
<div class="wr-input-control">
<label class="wr-input-label" for="android-kiosk-config-encryption">
PROVISIONING_SKIP_ENCRYPTION
<!--<span class="helper" title="Time interval after which Android agent will contact IoT Server each time to fetch data">-->
<!--<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>-->
<!--</span>-->
<br>
</label>
<select id="android-kiosk-config-encryption" class="form-control" data-default="0">
<option value="false">false</option>
<option value="true">true</option>
</select>
</div>
</div>
<!-- End of KIOSK Configs -->
<div class="wr-input-control wr-btn-grp">
<button id="save-android-btn" class="wr-btn">Save</button>
</div>

@ -80,6 +80,15 @@ var configParams = {
"IOS_CONFIG_APNS_MODE": "iOSConfigAPNSMode"
};
var kioskConfigs = {
"adminComponentName" : "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME",
"wifiSSID" : "android.app.extra.PROVISIONING_WIFI_SSID",
"wifiPassword" : "android.app.extra.PROVISIONING_WIFI_PASSWORD",
"skipEncryption" : "android.app.extra.PROVISIONING_SKIP_ENCRYPTION",
"checksum" : "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM",
"downloadURL" : "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"
};
$(document).ready(function () {
$("#fcm-inputs").hide();
tinymce.init({
@ -111,21 +120,33 @@ $(document).ready(function () {
if (data != null && data.configuration != null) {
for (var i = 0; i < data.configuration.length; i++) {
var config = data.configuration[i];
if (config.name == configParams["NOTIFIER_TYPE"]) {
if (config.name === configParams["NOTIFIER_TYPE"]) {
$("#android-config-notifier").val(config.value);
if (config.value != notifierTypeConstants["FCM"]) {
if (config.value !== notifierTypeConstants["FCM"]) {
$("#fcm-inputs").hide();
$("#local-inputs").show();
} else {
$("#fcm-inputs").show();
$("#local-inputs").hide();
}
} else if (config.name == configParams["NOTIFIER_FREQUENCY"]) {
} else if (config.name === configParams["NOTIFIER_FREQUENCY"]) {
$("input#android-config-notifier-frequency").val(config.value / 1000);
} else if (config.name == configParams["FCM_API_KEY"]) {
} else if (config.name === configParams["FCM_API_KEY"]) {
$("input#android-config-fcm-api-key").val(config.value);
} else if (config.name == configParams["ANDROID_EULA"]) {
} else if (config.name === configParams["ANDROID_EULA"]) {
$("#android-eula").val(config.value);
} else if (config.name === kioskConfigs["adminComponentName"]) {
$("input#android-kiosk-config-admin-component").val(config.value);
} else if (config.name === kioskConfigs["wifiSSID"]) {
$("input#android-kiosk-config-wifi-ssid").val(config.value);
} else if (config.name === kioskConfigs["wifiPassword"]) {
$("input#android-kiosk-config-wifi-password").val(config.value);
} else if (config.name === kioskConfigs["checksum"]) {
$("input#android-kiosk-config-checksum").val(config.value);
} else if (config.name === kioskConfigs["downloadURL"]) {
$("input#android-kiosk-config-download-url").val(config.value);
} else if (config.name === kioskConfigs["skipEncryption"]) {
$("#android-kiosk-config-encryption").val(config.value);
}
}
}
@ -161,13 +182,22 @@ $(document).ready(function () {
var androidLicense = tinyMCE.activeEditor.getContent();
var errorMsgWrapper = "#android-config-error-msg";
var errorMsg = "#android-config-error-msg span";
if (notifierType == notifierTypeConstants["LOCAL"] && !notifierFrequency) {
// KIOSK configs
var adminComponentName = $("input#android-kiosk-config-admin-component").val();
var checksum = $("input#android-kiosk-config-checksum").val();
var downloadUrl = $("input#android-kiosk-config-download-url").val();
var wifiSSID = $("input#android-kiosk-config-wifi-ssid").val();
var wifiPassword = $("input#android-kiosk-config-wifi-password").val();
var encryption = $("#android-kiosk-config-encryption").find("option:selected").attr("value");
if (notifierType === notifierTypeConstants["LOCAL"] && !notifierFrequency) {
$(errorMsg).text("Notifier frequency is a required field. It cannot be empty.");
$(errorMsgWrapper).removeClass("hidden");
} else if (notifierType == notifierTypeConstants["LOCAL"] && !isPositiveInteger(notifierFrequency)) {
} else if (notifierType === notifierTypeConstants["LOCAL"] && !isPositiveInteger(notifierFrequency)) {
$(errorMsg).text("Provided notifier frequency is invalid. ");
$(errorMsgWrapper).removeClass("hidden");
} else if (notifierType == notifierTypeConstants["FCM"] && !fcmAPIKey) {
} else if (notifierType === notifierTypeConstants["FCM"] && !fcmAPIKey) {
$(errorMsg).text("FCM API Key is a required field. It cannot be empty.");
$(errorMsgWrapper).removeClass("hidden");
} else {
@ -205,10 +235,54 @@ $(document).ready(function () {
"contentType": "text"
};
var kioskAdminComponent = {
"name": kioskConfigs["adminComponentName"],
"value": adminComponentName,
"contentType": "text"
};
var kioskChecksum = {
"name": kioskConfigs["checksum"],
"value": checksum,
"contentType": "text"
};
var kioskDownloadURL = {
"name": kioskConfigs["downloadURL"],
"value": downloadUrl,
"contentType": "text"
};
var kioskWifiSSID = {
"name": kioskConfigs["wifiSSID"],
"value": wifiSSID,
"contentType": "text"
};
var kioskWifiPassword = {
"name": kioskConfigs["wifiPassword"],
"value": wifiPassword,
"contentType": "text"
};
var kioskEncryption = {
"name": kioskConfigs["skipEncryption"],
"value": encryption,
"contentType": "text"
};
configList.push(type);
configList.push(frequency);
configList.push(androidEula);
if (notifierType == notifierTypeConstants["FCM"]) {
configList.push(kioskAdminComponent);
configList.push(kioskChecksum);
configList.push(kioskDownloadURL);
configList.push(kioskEncryption);
configList.push(kioskWifiSSID);
configList.push(kioskWifiPassword);
if (notifierType === notifierTypeConstants["FCM"]) {
configList.push(fcmKey);
configList.push(fcmId);
}

@ -31,6 +31,17 @@ var backendEndBasePath = "/api/device-mgt/v1.0";
// });
//}
var kioskConfigs = {
"adminComponentName" : "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME",
"wifiSSID" : "android.app.extra.PROVISIONING_WIFI_SSID",
"wifiPassword" : "android.app.extra.PROVISIONING_WIFI_PASSWORD",
"skipEncryption" : "android.app.extra.PROVISIONING_SKIP_ENCRYPTION",
"checksum" : "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM",
"downloadURL" : "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION",
"androidExtra" : "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE",
"accessToken" : "android.app.extra.token"
};
/*
* set popup maximum height function.
*/
@ -72,6 +83,63 @@ function generateQRCode(qrCodeClass) {
});
}
/*
* QR-code generation function for KIOSK.
*/
function generateKIOSKQRCode(qrCodeClass) {
var androidConfigAPI = "/api/device-mgt/android/v1.0/configuration";
var payload = {};
var isKioskConfigured = false;
invokerUtil.get(
androidConfigAPI,
function (data) {
data = JSON.parse(data);
if (data != null && data.configuration != null) {
for (var i = 0; i < data.configuration.length; i++) {
var config = data.configuration[i];
if (config.name === kioskConfigs["adminComponentName"]) {
isKioskConfigured = true;
payload[config.name] = config.value;
} else if (config.name === kioskConfigs["wifiSSID"]) {
payload[config.name] = config.value;
} else if (config.name === kioskConfigs["wifiPassword"]) {
payload[config.name] = config.value;
} else if (config.name === kioskConfigs["checksum"]) {
payload[config.name] = config.value;
} else if (config.name === kioskConfigs["downloadURL"]) {
payload[config.name] = config.value;
} else if (config.name === kioskConfigs["skipEncryption"]) {
payload[config.name] = Boolean(config.value);
}
}
}
}, function (data) {
console.log(data);
});
var aToken = $(".a-token");
var tokenPair = aToken.data("atoken");
var accessToken = {};
accessToken[kioskConfigs["accessToken"]] = tokenPair["accessToken"];
payload[kioskConfigs["androidExtra"]] = accessToken;
if (isKioskConfigured) {
$(qrCodeClass).qrcode({
text: JSON.stringify(payload),
width: 300,
height: 300
});
} else {
$("#kiosk_heading").hide();
$("#kiosk_content").hide();
}
}
function toggleEnrollment() {
$(".modal-content").html($("#qr-code-modal").html());
generateQRCode(".modal-content .qr-code");
@ -351,6 +419,7 @@ $(document).ready(function () {
$.sidebar_toggle();
generateQRCode(".enrollment-qr-container");
generateKIOSKQRCode(".kiosk-enrollment-qr-container");
if (typeof $.fn.collapse == 'function') {
$('.navbar-collapse.tiles').on('shown.bs.collapse', function () {

@ -207,6 +207,22 @@
{{/if}}
</div>
<div class="row" id="kiosk_heading">
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-12 add-padding-top-2x ">
<h3 class="uppercase">PROVISION YOUR KIOSK DEVICE</h3>
<hr>
</div>
</div>
<div class="a-token" data-atoken="{{accessToken}}"></div>
<div class="row" id="kiosk_content">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 add-padding-top-2x add-padding-bottom-2x">
<h3 class="text-center">Scan to provision the KIOSK device</h3>
<div class="kiosk-enrollment-qr-container text-center"></div>
</div>
</div>
{{#zone "topCss"}}
{{css "css/styles.css"}}
{{/zone}}

@ -23,6 +23,7 @@ function onRequest(context) {
viewModel["isVirtual"] = request.getParameter("type") == 'virtual';
viewModel["isCloud"] = isCloud;
viewModel["hostName"] = devicemgtProps["httpsURL"];
viewModel["accessToken"] = session.get("tokenPair");
if (isCloud) {
viewModel["enrollmentURL"] = "https://play.google.com/store/apps/details?id=org.wso2.iot.agent";
} else {

Loading…
Cancel
Save