|
|
|
@ -126,7 +126,9 @@ function csrfSafeMethod(method) {
|
|
|
|
|
|
|
|
|
|
function setAjaxCSRFToken() {
|
|
|
|
|
let prefix = getCookie('SESSION_COOKIE_NAME_PREFIX');
|
|
|
|
|
if (!prefix || [`""`, `''`].indexOf(prefix) > -1) { prefix = ''; }
|
|
|
|
|
if (!prefix || [`""`, `''`].indexOf(prefix) > -1) {
|
|
|
|
|
prefix = '';
|
|
|
|
|
}
|
|
|
|
|
var csrftoken = getCookie(`${prefix}csrftoken`);
|
|
|
|
|
var sessionid = getCookie(`${prefix}sessionid`);
|
|
|
|
|
|
|
|
|
@ -469,28 +471,7 @@ function parseTableFilter(value) {
|
|
|
|
|
var jumpserver = {};
|
|
|
|
|
jumpserver.checked = false;
|
|
|
|
|
jumpserver.selected = {};
|
|
|
|
|
jumpserver.language = {
|
|
|
|
|
processing: gettext('Loading') + '...',
|
|
|
|
|
search: gettext('Search'),
|
|
|
|
|
select: {
|
|
|
|
|
rows: {
|
|
|
|
|
_: gettext("Selected item %d"),
|
|
|
|
|
0: ""
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
lengthMenu: gettext("Per page _MENU_"),
|
|
|
|
|
info: gettext('Displays the results of items _START_ to _END_; A total of _TOTAL_ entries'),
|
|
|
|
|
infoFiltered: "",
|
|
|
|
|
infoEmpty: "",
|
|
|
|
|
zeroRecords: gettext("No match"),
|
|
|
|
|
emptyTable: gettext('No record'),
|
|
|
|
|
paginate: {
|
|
|
|
|
first: "«",
|
|
|
|
|
previous: "‹",
|
|
|
|
|
next: "›",
|
|
|
|
|
last: "»"
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
jumpserver.language = {};
|
|
|
|
|
|
|
|
|
|
function setDataTablePagerLength(num) {
|
|
|
|
|
$.fn.DataTable.ext.pager.numbers_length = num;
|
|
|
|
@ -730,8 +711,7 @@ jumpserver.initServerSideDataTable = function (options) {
|
|
|
|
|
if (select.style === 'multi') {
|
|
|
|
|
table.selected.push(row.id);
|
|
|
|
|
table.selected_rows.push(row);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
} else {
|
|
|
|
|
table.selected = [row.id];
|
|
|
|
|
table.selected_rows = [row];
|
|
|
|
|
}
|
|
|
|
@ -915,14 +895,6 @@ var rules_short_map_id = {
|
|
|
|
|
'special': 'id_security_password_special_char'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var rules_id_map_label = {
|
|
|
|
|
'id_security_password_min_length': gettext('Password minimum length {N} bits'),
|
|
|
|
|
'id_security_password_upper_case': gettext('Must contain capital letters'),
|
|
|
|
|
'id_security_password_lower_case': gettext('Must contain lowercase letters'),
|
|
|
|
|
'id_security_password_number': gettext('Must contain numeric characters'),
|
|
|
|
|
'id_security_password_special_char': gettext('Must contain special characters')
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function getRuleLabel(rule) {
|
|
|
|
|
var label = '';
|
|
|
|
|
if (rule.key === rules_short_map_id['min']) {
|
|
|
|
@ -1030,7 +1002,6 @@ function initPopover($container, $progress, $idPassword, $el, password_check_rul
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function rootNodeAddDom(ztree, callback) {
|
|
|
|
|
var refreshIcon = "<a id='tree-refresh'><i class='fa fa-refresh'></i></a>";
|
|
|
|
|
var rootNode = ztree.getNodes()[0];
|
|
|
|
@ -1048,146 +1019,6 @@ function rootNodeAddDom(ztree, callback) {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function APIExportCSV(props) {
|
|
|
|
|
/*
|
|
|
|
|
{
|
|
|
|
|
listUrl:
|
|
|
|
|
objectsId:
|
|
|
|
|
template:
|
|
|
|
|
table:
|
|
|
|
|
params:
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
var _listUrl = props.listUrl;
|
|
|
|
|
var _objectsId = props.objectsId;
|
|
|
|
|
var _template = props.template;
|
|
|
|
|
var _table = props.table;
|
|
|
|
|
var _params = props.params || {};
|
|
|
|
|
|
|
|
|
|
var tableParams = _table.ajax.params();
|
|
|
|
|
var exportUrl = setUrlParam(_listUrl, 'format', 'csv');
|
|
|
|
|
if (_template) {
|
|
|
|
|
exportUrl = setUrlParam(exportUrl, 'template', _template)
|
|
|
|
|
}
|
|
|
|
|
for (var k in tableParams) {
|
|
|
|
|
if (datatableInternalParams.includes(k)) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if (!tableParams[k]) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
exportUrl = setUrlParam(exportUrl, k, tableParams[k])
|
|
|
|
|
}
|
|
|
|
|
for (var k in _params) {
|
|
|
|
|
exportUrl = setUrlParam(exportUrl, k, tableParams[k])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_objectsId) {
|
|
|
|
|
console.log(exportUrl);
|
|
|
|
|
window.open(exportUrl);
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
requestApi({
|
|
|
|
|
url: '/api/v1/common/resources/cache/',
|
|
|
|
|
data: JSON.stringify({resources: _objectsId}),
|
|
|
|
|
method: "POST",
|
|
|
|
|
flash_message: false,
|
|
|
|
|
success: function (data) {
|
|
|
|
|
exportUrl = setUrlParam(exportUrl, 'spm', data.spm);
|
|
|
|
|
console.log(exportUrl);
|
|
|
|
|
window.open(exportUrl);
|
|
|
|
|
},
|
|
|
|
|
failed: function () {
|
|
|
|
|
toastr.error(gettext('Export failed'));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function APIExportData(props) {
|
|
|
|
|
props = props || {};
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: '/api/common/v1/resources/cache/',
|
|
|
|
|
type: props.method || "POST",
|
|
|
|
|
data: props.body,
|
|
|
|
|
contentType: props.content_type || "application/json; charset=utf-8",
|
|
|
|
|
dataType: props.data_type || "json",
|
|
|
|
|
success: function (data) {
|
|
|
|
|
var export_url = props.success_url;
|
|
|
|
|
var params = props.params || {};
|
|
|
|
|
params['format'] = props.format;
|
|
|
|
|
params['spm'] = data.spm;
|
|
|
|
|
for (var k in params) {
|
|
|
|
|
export_url = setUrlParam(export_url, k, params[k])
|
|
|
|
|
}
|
|
|
|
|
window.open(export_url);
|
|
|
|
|
},
|
|
|
|
|
error: function () {
|
|
|
|
|
toastr.error(gettext('Export failed'));
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function APIImportData(props) {
|
|
|
|
|
props = props || {};
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: props.url,
|
|
|
|
|
type: props.method || "POST",
|
|
|
|
|
processData: false,
|
|
|
|
|
data: props.body,
|
|
|
|
|
contentType: props.content_type || 'text/csv',
|
|
|
|
|
success: function (data) {
|
|
|
|
|
if (props.method === 'POST') {
|
|
|
|
|
$('#created_failed').html('');
|
|
|
|
|
$('#created_failed_detail').html('');
|
|
|
|
|
$('#success_created').html(gettext("Import Success"));
|
|
|
|
|
$('#success_created_detail').html("Count" + ": " + data.length);
|
|
|
|
|
} else {
|
|
|
|
|
$('#updated_failed').html('');
|
|
|
|
|
$('#updated_failed_detail').html('');
|
|
|
|
|
$('#success_updated').html(gettext("Update Success"));
|
|
|
|
|
$('#success_updated_detail').html(gettext("Count") + ": " + data.length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
props.data_table.ajax.reload()
|
|
|
|
|
},
|
|
|
|
|
error: function (error) {
|
|
|
|
|
var data = error.responseJSON;
|
|
|
|
|
console.log(data);
|
|
|
|
|
if (data instanceof Array) {
|
|
|
|
|
var html = '';
|
|
|
|
|
var li = '';
|
|
|
|
|
var err = '';
|
|
|
|
|
$.each(data, function (index, item) {
|
|
|
|
|
err = '';
|
|
|
|
|
for (var prop in item) {
|
|
|
|
|
err += prop + ": " + item[prop][0] + " "
|
|
|
|
|
}
|
|
|
|
|
if (err) {
|
|
|
|
|
li = "<li>" + "Line " + (++index) + ". " + err + "</li>";
|
|
|
|
|
html += li
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
html = "<ul>" + html + "</ul>"
|
|
|
|
|
} else {
|
|
|
|
|
html = error.responseText
|
|
|
|
|
}
|
|
|
|
|
if (props.method === 'POST') {
|
|
|
|
|
$('#success_created').html('');
|
|
|
|
|
$('#success_created_detail').html('');
|
|
|
|
|
$('#created_failed').html(gettext("Import failed"));
|
|
|
|
|
$('#created_failed_detail').html(html);
|
|
|
|
|
} else {
|
|
|
|
|
$('#success_updated').html('');
|
|
|
|
|
$('#success_updated_detail').html('');
|
|
|
|
|
$('#updated_failed').html(gettext("Update failed"));
|
|
|
|
|
$('#updated_failed_detail').html(html);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function htmlEscape(d) {
|
|
|
|
|
return typeof d === 'string' ?
|
|
|
|
|
d.replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"') :
|
|
|
|
@ -1329,7 +1160,6 @@ function readFile(ref) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function select2AjaxInit(option) {
|
|
|
|
|
/*
|
|
|
|
|
{
|
|
|
|
@ -1385,9 +1215,11 @@ function usersSelect2Init(selector, url, disabledData) {
|
|
|
|
|
if (!url) {
|
|
|
|
|
url = '/api/v1/users/users/'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function displayFormat(v) {
|
|
|
|
|
return v.name + '(' + v.username + ')';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var option = {
|
|
|
|
|
url: url,
|
|
|
|
|
selector: selector,
|
|
|
|
@ -1402,9 +1234,11 @@ function nodesSelect2Init(selector, url, disabledData) {
|
|
|
|
|
if (!url) {
|
|
|
|
|
url = '/api/v1/assets/nodes/'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function displayFormat(v) {
|
|
|
|
|
return v.full_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var option = {
|
|
|
|
|
url: url,
|
|
|
|
|
selector: selector,
|
|
|
|
@ -1423,8 +1257,7 @@ function getUserLang(){
|
|
|
|
|
let userLangEN = document.cookie.indexOf('django_language=en');
|
|
|
|
|
if (userLangEN === -1) {
|
|
|
|
|
return 'zh-CN'
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
} else {
|
|
|
|
|
return 'en-US'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1460,8 +1293,7 @@ function initDateRangePicker(selector, options) {
|
|
|
|
|
};
|
|
|
|
|
if (getUserLang() === 'zh-CN') {
|
|
|
|
|
defaultOption.locale = zhLocale;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
} else {
|
|
|
|
|
// en-US
|
|
|
|
|
defaultOption.locale = enLocale;
|
|
|
|
|
}
|
|
|
|
@ -1470,7 +1302,9 @@ function initDateRangePicker(selector, options) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function reloadPage() {
|
|
|
|
|
setTimeout( function () {window.location.reload();}, 300);
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
window.location.reload();
|
|
|
|
|
}, 300);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isEmptyObject(obj) {
|
|
|
|
|