added certificate units

revert-70aa11f8
ayyoob 8 years ago
parent 058f9e4cfa
commit 217f541991

@ -0,0 +1,101 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file except
in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
}}
{{unit "cdmf.unit.ui.title" pageTitle="Add Certificate"}}
{{#zone "breadcrumbs"}}
<li>
<a href="{{@app.context}}/">
<i class="icon fw fw-home"></i>
</a>
</li>
<li>
<a href="{{@app.context}}/certificates/add">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-document fw-stack-1x"></i>
</span>
Add Certificate
</a>
</li>
{{/zone}}
{{#zone "content"}}
<!-- content/body -->
<div class="row">
<div class="col-md-12">
<!-- content -->
<div id="certificate-create-form" class="container col-centered wr-content">
<div class="wr-form">
<p class="page-sub-title">Add Certificate</p>
<p>Please note that * sign represents required fields of data.</p>
<hr/>
<div class="row">
<div class="col-lg-8">
<div id="certificate-create-error-msg" class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span>
</div>
<label class="wr-input-label ">
Serial Number *
</label>
<br>
<div id="serialNoInputField" class="form-group wr-input-control">
<input type="text" id="serialNo" class="form-control"/>
</div>
<label class="wr-input-label">Certificate *</label>
<div id="certificateField" class="form-group wr-input-control">
<input type="file" id="certificate" class="form-control"/>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-lg-8">
<button id="add-certificate-btn" class="wr-btn">Add Certificate</button>
</div>
</div>
</div>
</div>
<div id="certificate-created-msg" class="container col-centered wr-content hidden">
<div class="wr-form">
<p class="page-sub-title">Certificate was added successfully.</p>
<br>
<br>Please click <b>"Add Another Certificate"</b>, if you wish to add another certificate or
click
<b>"View Certificate List"</b> to complete the process and go back to the certificate list.
<hr/>
<button class="wr-btn" onclick="window.location.href='/emm/certificates'">View Certificate List
</button>
<a href="/emm/certificates/add-certificate" class="cu-btn-inner">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
Add Another Certificate
</a>
</div>
</div>
<!-- /content -->
</div>
</div>
<!-- /content/body -->
{{/zone}}
{{#zone "bottomJs"}}
{{js "/js/certificate-create.js"}}
{{/zone}}

@ -0,0 +1,45 @@
/*
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file except
in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
/**
* Returns the dynamic state to be populated by add-user page.
*
* @param context Object that gets updated with the dynamic state of this page to be presented
* @returns {*} A context object that returns the dynamic state of this page to be presented
*/
function onRequest(context) {
// var log = new Log("units/user-create/create.js");
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var mdmProps = require("/app/modules/conf-reader/main.js")["conf"];
var response = userModule.getRolesByUserStore();
if (response["status"] == "success") {
context["roles"] = response["content"];
}
context["charLimit"] = mdmProps["usernameLength"];
context["usernameJSRegEx"] = mdmProps["userValidationConfig"]["usernameJSRegEx"];
context["usernameHelpText"] = mdmProps["userValidationConfig"]["usernameHelpMsg"];
context["usernameRegExViolationErrorMsg"] = mdmProps["userValidationConfig"]["usernameRegExViolationErrorMsg"];
context["firstnameJSRegEx"] = mdmProps["userValidationConfig"]["firstnameJSRegEx"];
context["firstnameRegExViolationErrorMsg"] = mdmProps["userValidationConfig"]["firstnameRegExViolationErrorMsg"];
context["lastnameJSRegEx"] = mdmProps["userValidationConfig"]["lastnameJSRegEx"];
context["lastnameRegExViolationErrorMsg"] = mdmProps["userValidationConfig"]["lastnameRegExViolationErrorMsg"];
return context;
}

@ -0,0 +1,129 @@
/*
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file except
in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
var pemContent = "";
var errorMsgWrapper = "#certificate-create-error-msg";
var errorMsg = "#certificate-create-error-msg span";
var validateInline = {};
var clearInline = {};
var base_api_url = "/api/device-mgt/v1.0";
var enableInlineError = function (inputField, errorMsg, errorSign) {
var fieldIdentifier = "#" + inputField;
var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
var errorSignIdentifier = "#" + inputField + " ." + errorSign;
if (inputField) {
$(fieldIdentifier).addClass(" has-error has-feedback");
}
if (errorMsg) {
$(errorMsgIdentifier).removeClass(" hidden");
}
if (errorSign) {
$(errorSignIdentifier).removeClass(" hidden");
}
};
var disableInlineError = function (inputField, errorMsg, errorSign) {
var fieldIdentifier = "#" + inputField;
var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
var errorSignIdentifier = "#" + inputField + " ." + errorSign;
if (inputField) {
$(fieldIdentifier).removeClass(" has-error has-feedback");
}
if (errorMsg) {
$(errorMsgIdentifier).addClass(" hidden");
}
if (errorSign) {
$(errorSignIdentifier).addClass(" hidden");
}
};
function readSingleFile(evt) {
var f = evt.target.files[0];
if (f) {
var r = new FileReader();
r.onload = function (e) {
var contents = e.target.result;
if (f.type == "application/x-x509-ca-cert") {
pemContent = contents;
console.log(contents);
console.log(pemContent);
pemContent = pemContent.substring(28, pemContent.length - 27);
console.log(pemContent);
$(errorMsgWrapper).addClass("hidden");
} else {
$(errorMsg).text("Certificate must be a .pem file containing a valid certificate data.");
$(errorMsgWrapper).removeClass("hidden");
}
}
r.readAsText(f);
} else {
//inline error
}
}
$(document).ready(function () {
pemContent = "";
document.getElementById('certificate').addEventListener('change', readSingleFile, false);
/**
* Following click function would execute
* when a user clicks on "Add Certificate" button.
*/
$("button#add-certificate-btn").click(function () {
var serialNoInput = $("input#serialNo");
var serialNo = serialNoInput.val();
if (!serialNo) {
$(errorMsg).text("Serial Number is a required field. It cannot be empty.");
$(errorMsgWrapper).removeClass("hidden");
} else if (!pemContent) {
$(errorMsg).text(" .pem file must contains certificate information.");
$(errorMsgWrapper).removeClass("hidden");
} else {
var addCertificateFormData = {};
addCertificateFormData.serial = serialNo;
addCertificateFormData.pem = pemContent;
var certificateList = [];
certificateList.push(addCertificateFormData);
var serviceUrl = base_api_url + "/admin/certificates";
invokerUtil.post(
serviceUrl,
certificateList,
function (data) {
// Refreshing with success message
$("#certificate-create-form").addClass("hidden");
$("#certificate-created-msg").removeClass("hidden");
}, function (data) {
if (data["status"] == 500) {
$(errorMsg).text("An unexpected error occurred at backend server. Please try again later.");
} else {
$(errorMsg).text(data);
}
$(errorMsgWrapper).removeClass("hidden");
}
);
}
});
});

@ -0,0 +1,177 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file except
in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
}}
{{unit "cdmf.unit.ui.title" pageTitle="Add Certificate"}}
{{#zone "breadcrumbs"}}
<li>
<a href="{{@app.context}}/">
<i class="icon fw fw-home"></i>
</a>
</li>
<li>
<a href="{{@app.context}}/certificates/add">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-document fw-stack-1x"></i>
</span>
Add Certificate
</a>
</li>
{{/zone}}
{{#zone "content"}}
{{unit "cdmf.unit.data-tables-extended"}}
<!-- content -->
<div id="loading-content" class="col-centered">
{{#if removePermitted}}
<input type="hidden" id="can-remove" value="true"/>
{{/if}}
{{#if viewPermitted}}
<input type="hidden" id="can-view" value="true"/>
{{/if}}
<i class="fw fw-settings fw-spin fw-2x"></i>
Loading Certificates . . .
<br>
</div>
<div id="certificate-listing-status" class="raw hidden">
<ul style="list-style-type: none;">
<li class="message message-info" >
<h4>
<i class="icon fw fw-info"></i>
<a id="certificate-listing-status-msg"></a>
</h4>
</li>
</ul>
</div>
<div id="certificate-table" data-user={{adminUser}}>
<table class="table table-striped table-hover list-table display responsive nowrap data-table grid-view"
id="certificate-grid">
<thead>
<tr class="sort-row">
<th class="no-sort"></th>
<th>By Serial Number</th>
<th class="no-sort"></th>
<th class="no-sort"></th>
</tr>
<tr class="filter-row filter-box">
<th colspan="3">
<label class="wr-input-label" for="search-by-certificate">
By Serial Number
</label>
<input id="search-by-certificate" type="text" class="form-control"
placeholder="Search By Serial Number">
</th>
<th style="vertical-align:bottom;">
<button id="search-btn" class="wr-btn">
Search
</button>
</th>
</tr>
</thead>
<tbody id="ast-container">
<br class="c-both"/>
</tbody>
</table>
</div>
<br class="c-both"/>
<div id="content-filter-types" style="display: none">
<div class="sort-title">Sort By</div>
<div class="sort-options">
<a href="#">By Serial Number</a>
</div>
</div>
<div id="remove-certificate-modal-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Do you really want to remove this certificate ?</h3>
<div class="buttons">
<a href="#" id="remove-certificate-yes-link" class="btn-operations">
Remove
</a>
<a href="#" id="remove-certificate-cancel-link" class="btn-operations">
Cancel
</a>
</div>
</div>
</div>
</div>
</div>
<div id="remove-certificate-success-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Done. Certificate was successfully removed.</h3>
<div class="buttons">
<a href="#" id="remove-certificate-success-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="remove-certificate-error-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>An unexpected error occurred. Please try again later.</h3>
<div class="buttons">
<a href="#" id="remove-certificate-error-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="errorCertificateView" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-error fw-stack-1x"></i>
</span>
Unauthorized action!
</h3>
</div>
</div>
</div>
</div>
{{/zone}}
{{#zone "bottomJs"}}
<script id="certificate-listing" data-current-user="{{@user.username}}"
src="{{@unit.publicUri}}/templates/certificate-listing.hbs"
type="text/x-handlebars-template"></script>
{{js "/js/certificate-listing.js"}}
{{/zone}}

@ -0,0 +1,15 @@
function onRequest(context) {
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var mdmProps = require("/app/modules/conf-reader/main.js")["conf"];
context["permissions"] = userModule.getUIPermissions();
if (userModule.isAuthorized("/permission/admin/device-mgt/emm-admin/certificate/Get")) {
context["removePermitted"] = true;
}
if (userModule.isAuthorized("/permission/admin/device-mgt/emm-admin/certificate/Get")) {
context["viewPermitted"] = true;
}
context["adminUser"] = mdmProps.adminUser;
return context;
}

@ -0,0 +1,171 @@
/*
* Sorting function of certificates
* listed on Certificate Management page in WSO2 MDM Console.
*/
$(function () {
var sortableElem = '.wr-sortable';
$(sortableElem).sortable({
beforeStop: function () {
var sortedIDs = $(this).sortable('toArray');
}
});
$(sortableElem).disableSelection();
});
var modalPopup = ".wr-modalpopup";
var modalPopupContainer = modalPopup + " .modalpopup-container";
var modalPopupContent = modalPopup + " .modalpopup-content";
var body = "body";
var isInit = true;
var base_api_url = "/api/certificate-mgt/v1.0";
$(".icon .text").res_text(0.2);
/*
* set popup maximum height function.
*/
function setPopupMaxHeight() {
$(modalPopupContent).css('max-height', ($(body).height() - ($(body).height() / 100 * 30)));
$(modalPopupContainer).css('margin-top', (-($(modalPopupContainer).height() / 2)));
}
/*
* show popup function.
*/
function showPopup() {
$(modalPopup).show();
setPopupMaxHeight();
}
/*
* hide popup function.
*/
function hidePopup() {
$(modalPopupContent).html('');
$(modalPopup).hide();
}
/**
* Following click function would execute
* when a user clicks on "Remove" link
* on Certificate Listing page in WSO2 MDM Console.
*/
function removeCertificate(serialNumber) {
var serviceUrl = base_api_url + "/admin/certificates/" + serialNumber;
$(modalPopupContent).html($('#remove-certificate-modal-content').html());
showPopup();
$("a#remove-certificate-yes-link").click(function () {
invokerUtil.delete(
serviceUrl,
function () {
$("#" + serialNumber).remove();
var newCertificateListCount = $(".user-list > span").length;
$("#certificate-listing-status-msg").text("Total number of Certificates found : " + newCertificateListCount);
$(modalPopupContent).html($('#remove-certificate-success-content').html());
$("a#remove-certificate-success-link").click(function () {
hidePopup();
});
},
function () {
$(modalPopupContent).html($('#remove-certificate-error-content').html());
$("a#remove-certificate-error-link").click(function () {
hidePopup();
});
}
);
});
$("a#remove-certificate-cancel-link").click(function () {
hidePopup();
});
}
/**
* Following on click function would execute
* when a user type on the search field on certificate Listing page in
* WSO2 MDM Console then click on the search button.
*/
$("#search-btn").click(function () {
var searchQuery = $("#search-by-certificate").val();
$("#ast-container").empty();
loadCertificates(searchQuery);
});
/**
* Following function would execute
* when a user clicks on the list item
* initial mode and with out select mode.
*/
function InitiateViewOption() {
if ($("#can-view").val()) {
$(location).attr('href', $(this).data("url"));
} else {
$(modalPopupContent).html($('#errorCertificateView').html());
showPopup();
}
}
function loadCertificates(searchParam) {
$("#loading-content").show();
var certificateListing = $("#certificate-listing");
var certificateListingSrc = certificateListing.attr("src");
$.template("certificate-listing", certificateListingSrc, function (template) {
var serviceURL = base_api_url + "/admin/certificates";
if (searchParam != null && searchParam != undefined && searchParam.trim() != '') {
serviceURL = base_api_url + "/admin/certificates?" + searchParam;
}
var successCallback = function (data, textStatus, jqXHR) {
if (jqXHR.status == 200 && data) {
data = JSON.parse(data);
var viewModel = {};
viewModel.certificates = data.certificates;
for (var i = 0; i < viewModel.certificates.length; i++) {
viewModel.certificates[i].removePermitted = true;
viewModel.certificates[i].viewPermitted = true;
}
if (viewModel.certificates.length > 0) {
$('#ast-container').removeClass('hidden');
$('#certificate-listing-status-msg').text("");
var content = template(viewModel);
$("#ast-container").html(content);
} else {
$('#ast-container').addClass('hidden');
$('#certificate-listing-status-msg').text('No certificate is available to be displayed.');
$('#certificate-listing-status').removeClass('hidden');
}
$("#loading-content").hide();
if (isInit) {
$('#certificate-grid').datatables_extended();
isInit = false;
}
$(".icon .text").res_text(0.2);
}
};
invokerUtil.get(serviceURL,
successCallback,
function (message) {
$('#ast-container').addClass('hidden');
$('#certificate-listing-status-msg').
text('Invalid search query. Try again with a valid search query');
}
);
});
}
$(document).ready(function () {
loadCertificates();
$(".viewEnabledIcon").click(function () {
InitiateViewOption();
});
});

@ -0,0 +1,30 @@
{{#each certificates}}
<tr data-type="selectable" id="{{serialNumber}}" data-username="{{serialNumber}}">
<td class="remove-padding icon-only content-fill viewEnabledIcon" data-username="{{serialNumber}}">
<div class="thumbnail icon">
<i class="square-element text fw fw-document"></i>
</div>
</td>
<td class="fade-edge remove-padding-top" data-search="{{serialNumber}}" data-display="{{serialNumber}}"><i
class="fw-mobile"></i> {{serialNumber}}</td>
<td class="fade-edge remove-padding-top" data-search="{{subject}}" data-display="{{subject}}"><i
class="fw-policy"></i> {{subject}}</td>
<td class="text-right content-fill text-left-on-grid-view no-wrap">
{{#unequal adminUser serialNumber }}
{{#if removePermitted}}
<a href="#" data-username="{{serialNumber}}" data-userid="{{userid}}"
data-click-event="remove-form" onclick="javascript:removeCertificate('{{serialNumber}}')"
class="btn padding-reduce-on-grid-view remove-user-link">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-delete fw-stack-1x"></i>
</span>
<span class="hidden-xs hidden-on-grid-view">Remove</span>
</a>
{{/if}}
{{/unequal}}
</td>
</tr>
{{/each}}
Loading…
Cancel
Save