• 老广's avatar
    Dev2 (#1766) · fe45d839
    老广 authored
    * [Update] 初始化操作日志
    
    * [Feature] 完成操作日志记录
    
    * [Update] 修改mfa失败提示
    
    * [Update] 修改增加created by内容
    
    * [Update] 增加改密日志
    
    * [Update] 登录日志迁移到日志审计中
    
    * [Update] change block user logic, if login success, clean block limit
    
    *  [Update] 更新中/英文翻译(ALL) (#1662)
    
    * Revert "授权页面分页问题"
    
    * 增加命令导出 (#1566)
    
    * [Update] gunicorn不使用eventlet
    
    * [Update] 添加eventlet
    
    * 替换淘宝IP查询接口
    
    * [Feature] 添加命令记录下载功能 (#1559)
    
    * [Feature] 添加命令记录下载功能
    
    * [Update] 文案修改,导出记录、提交,取消全部命令导出
    
    * [Update] 命令导出,修复时间问题
    
    * [Update] paramiko => 2.4.1
    
    * [Update] 修改settings
    
    * [Update] 修改权限判断
    
    * Dev (#1646)
    
    * [Update] 添加org
    
    * [Update] 修改url
    
    * [Update] 完成基本框架
    
    * [Update] 修改一些逻辑
    
    * [Update] 修改用户view
    
    * [Update] 修改资产
    
    * [Update] 修改asset api
    
    * [Update] 修改协议小问题
    
    * [Update] stash it
    
    * [Update] 修改约束
    
    * [Update] 修改外键为org_id
    
    * [Update] 删掉Premiddleware
    
    * [Update] 修改Node
    
    * [Update] 修改get_current_org 为 proxy对象 current_org
    
    * [Bugfix] 解决Node.root() 死循环,移动AdminRequired到permission中 (#1571)
    
    * [Update] 修改permission (#1574)
    
    * Tmp org (#1579)
    
    * [Update] 添加org api, 升级到django 2.0
    
    * [Update] fix some bug
    
    * [Update] 修改一些bug
    
    * [Update] 添加授权规则org (#1580)
    
    * [Update] 修复创建授权规则,显示org_name不是有效UUID的bug
    
    * [Update] 更新org之间隔离授权规则,解决QuerySet与Manager问题;修复创建用户,显示org_name不是有效UUID之bug;
    
    * Tmp org (#1583)
    
    * [Update] 修改一些内容
    
    * [Update] 修改datatable 支持process
    
    * [Bugfix] 修复asset queryset 没有valid方法的bug
    
    * [Update] 在线/历史/命令model添加org;修复命令记录保存org失败bug (#1584)
    
    * [Update] 修复创建授权规则,显示org_name不是有效UUID的bug
    
    * [Update] 更新org之间隔离授权规则,解决QuerySet与Manager问题;修复创建用户,显示org_name不是有效UUID之bug;
    
    * [Update] 在线/历史/命令model添加org
    
    * [Bugfix] 修复命令记录,保存org不成功bug
    
    * [Update] Org功能修改
    
    * [Bugfix] 修复merge带来的问题
    
    * [Update] org admin显示资产详情右侧选项卡;修复资产授权添加用户,会显示其他org用户的bug (#1594)
    
    * [Bugfix] 修复资产授权添加用户,显示其他org的用户bug
    
    * [Update] org admin 显示资产详情右侧选项卡
    
    * Tmp org (#1596)
    
    * [Update] 修改index view
    
    * [Update] 修改nav
    
    * [Update] 修改profile
    
    * [Bugfix] 修复org下普通用户打开web终端看不到已被授权的资产和节点bug
    
    * [Update] 修改get_all_assets
    
    * [Bugfix] 修复节点前面有个空目录
    
    * [Bugfix] 修复merge引起的bug
    
    * [Update] Add init
    
    * [Update] Node get_all_assets 过滤游离资产,条件nodes_key=None -> nodes=None
    
    * [Update] 恢复原来的api地址
    
    * [Update] 修改api
    
    * [Bugfix] 修复org下用户查看我的资产不显示已授权节点/资产的bug
    
    * [Bugfix] Fix perm name unique
    
    * [Bugfix] 修复校验失败api
    
    * [Update] Merge with org
    
    * [Merge] 修改一下bug
    
    * [Update] 暂时修改一些url
    
    * [Update] 修改url 为django 2.0 path
    
    * [Update] 优化datatable 和显示组织优化
    
    * [Update] 升级url
    
    * [Bugfix] 修复coco启动失败(load_config_from_server)、硬件刷新,测试连接,str 没有 decode(… (#1613)
    
    * [Bugfix] 修复coco启动失败(load_config_from_server)、硬件刷新,测试连接,str 没有 decode() method的bug
    
    * [Bugfix] (task任务系统)修复资产连接性测试、硬件刷新和系统用户连接性测试失败等bug
    
    * [Bugfix] 修复一些bug
    
    * [Bugfix] 修复一些bug
    
    *  [Update] 更新org下普通用户的资产详情 (#1619)
    
    * [Update] 更新org下普通用户查看资产详情,只显示数据
    
    * [Update] 优化org下普通用户查看资产详情前端代码
    
    * [Update] 创建/更新用户的role选项;密码强度提示信息中英文; (#1623)
    
    * [Update] 修改 超级管理员/组织管理员 在 创建/更新 用户时role的选项 问题
    
    * [Update] 用户密码强度提示信息支持中英文
    
    * [Update] 修改token返回
    
    * [Update] Asset返回org name
    
    * [Update] 修改支持xpack
    
    * [Update] 修改url
    
    * [Bugfix] 修复不登录就能查看资产的bug
    
    * [Update] 用户修改
    
    * [Bugfix] ...
    
    * [Bugfix] 修复跳转错误的问题
    
    *  [Update] xpack/orgs组织添加删除功能-js; 修复Label继承Org后bug; (#1644)
    
    * [Update] 更新xpack下orgs的翻译信息
    
    * [Update] 更新model Label,继承OrgModelMixin;
    
    * [Update] xpack/orgs组织添加删除功能-js; 修复Label继承Org后bug;
    
    * [Bugfix] 修复小bug
    
    * [Update] 优化一些api
    
    * [Update] 优化用户资产页面
    
    * [Update] 更新 xpack/orgs 删除功能:限制在当前org下删除当前org (#1645)
    
    * [Update] 修改版本号
    
    * [Update] 添加功能: 语言切换(中/英);修改 header_bar <商业支持、文档>显示方式
    
    * [Update] 中/英切换文案修改;修改django_language key 从 settings 中获取
    
    * [Update] 修改Dashboard页面文案,支持英文
    
    * [Update] 更新中/英文翻译(ALL)
    
    * [Update] 解决翻译文件冲突
    
    * [Update] 系统用户支持单独隋松
    
    * [Update] 重置用户MFA
    
    * [Update] 设置session空闲时间
    
    * [Update] 加密setting配置
    
    * [Update] 修改单独推送和测试资产可连接性
    
    *  [Update] 添加功能:用户个人详情页添加 更改MFA操作 (#1748)
    
    * [Update] 添加功能:用户个人详情页添加 更改MFA操作
    
    * [Update] 删除print
    
    * [Bugfix] 添加部分views的权限控制;从组织移除用户,同时从授权规则和用户组中移除此用户。 (#1746)
    
    * [Bugfix] 修复上传command log 为空
    
    * [Update] 修复执行任务的bug
    
    * [Bugfix] 修复将用户从组内移除,其依然具有之前的组权限的bug, perms and user_groups
    
    * [Bugfix] 修复组管理员可以访问部分url-views的bug(如: /settings/)添加views权限控制
    
    * [Update] 修改日志滚动
    
    * [Bugfix] 修复组织权限控制的bug (#1763)
    
    * [Bugfix] 修复将用户从组内移除,其依然具有之前的组权限的bug, perms and user_groups
    
    * [Bugfix] 修复组管理员可以访问部分url-views的bug(如: /settings/)添加views权限控制
    Unverified
    fe45d839
jumpserver.js 23.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
//jumpserver 自定义js 2015-01-29

//此函数用于checkbox的全选和反选
var checked=false;
function check_all(form) {
    var checkboxes = document.getElementById(form);
    if (checked === false) {
        checked = true;
    } else {
        checked = false;
    }
    for (var i = 0; i < checkboxes.elements.length; i++) {
        if (checkboxes.elements[i].type == "checkbox") {
            checkboxes.elements[i].checked = checked;
        }
    }
}

function checkAll(id, name){
    var checklist = document.getElementsByName(name);
    if(document.getElementById(id).checked)
        {
        for(var i=0;i<checklist.length;i++)
        {
          checklist[i].checked = 1;
        }
    }else{
        for(var j=0;j<checklist.length;j++)
        {
         checklist[j].checked = 0;
        }
    }
}

//提取指定行的数据,JSON格式
function GetRowData(row){
    var rowData = {};
    for(var j=0;j<row.cells.length; j++) {
        name = row.parentNode.rows[0].cells[j].getAttribute("Name");
        if (name) {
            var value = row.cells[j].getAttribute("Value");
            if (!value) {
                value = row.cells[j].innerHTML;
            }
            rowData[name] = value;
        }
    }
    return rowData;
}

//此函数用于在多选提交时至少要选择一行
function GetTableDataBox() {
    var tabProduct = document.getElementById("editable");
    var tableData = [];
    var returnData = [];
    var checkboxes = document.getElementById("contents_form");
    var id_list = [];
    len = checkboxes.elements.length;
    for (var i=0; i < len; i++) {
        if (checkboxes.elements[i].type == "checkbox" && checkboxes.elements[i].checked === true && checkboxes.elements[i].value != "checkall") {
            id_list.push(i);
         }
        }
    for (i in id_list) {
        tableData.push(GetRowData(tabProduct.rows[id_list[i]]));
    }

    if (id_list.length === 0){
        alert('请至少选择一行!');
    }
    returnData.push(tableData);
    returnData.push(id_list.length);
    return returnData;
}

function move(from, to, from_o, to_o) {
    $("#" + from + " option").each(function () {
        if ($(this).prop("selected") === true) {
            $("#" + to).append(this);
            if( typeof from_o !== 'undefined'){
                $("#"+to_o).append($("#"+from_o +" option[value='"+this.value+"']"));
            }
        }
    });
}

function move_left(from, to, from_o, to_o) {
    $("#" + from + " option").each(function () {
        if ($(this).prop("selected") === true) {
            $("#" + to).append(this);
            if( typeof from_o !== 'undefined'){
                $("#"+to_o).append($("#"+from_o +" option[value='"+this.value+"']"));
            }
        }
        $(this).attr("selected",'true');
    });
}


function selectAll(){
    // Select all check box
    $('option').each(function(){
        $(this).attr('selected', true);
    });
}


function getCookie(name) {
    var cookieValue = null;
    if (document.cookie && document.cookie !== '') {
        var cookies = document.cookie.split(';');
        for (var i = 0; i < cookies.length; i++) {
            var cookie = jQuery.trim(cookies[i]);
            // Does this cookie string begin with the name we want?
            if (cookie.substring(0, name.length + 1) === (name + '=')) {
                cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                // break;
            }
        }
    }
    return cookieValue;
}

function csrfSafeMethod(method) {
    // these HTTP methods do not require CSRF protection
    return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}

function setAjaxCSRFToken() {
    var csrftoken = getCookie('csrftoken');
    var sessionid = getCookie('sessionid');

    $.ajaxSetup({
        beforeSend: function(xhr, settings) {
            if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
                xhr.setRequestHeader("X-CSRFToken", csrftoken);
            }
        }
    });
}

function activeNav() {
    var url_array = document.location.pathname.split("/");
    var app = url_array[1];
    var resource = url_array[2];
    if (app === ''){
        $('#index').addClass('active');
    } else {
        $("#" + app).addClass('active');
        $('#' + app + ' #' + resource).addClass('active');
    }
}

function APIUpdateAttr(props) {
    // props = {url: .., body: , success: , error: , method: ,}
    props = props || {};
    var success_message = props.success_message || gettext('Update is successful!');
    var fail_message = props.fail_message || gettext('An unknown error occurred while updating..');
    var flash_message = props.flash_message || true;
    if (props.flash_message === false){
        flash_message = false;
    }

    $.ajax({
        url: props.url,
        type: props.method || "PATCH",
        data: props.body,
        contentType: props.content_type || "application/json; charset=utf-8",
        dataType: props.data_type || "json"
    }).done(function(data, textStatue, jqXHR) {
        if (flash_message) {
            toastr.success(success_message);
        }
        if (typeof props.success === 'function') {
            return props.success(data);
        }
    }).fail(function(jqXHR, textStatus, errorThrown) {
        if (flash_message) {
            toastr.error(fail_message);
        }
        if (typeof props.error === 'function') {
            return props.error(jqXHR.responseText, jqXHR.status);
        }
    });
  // return true;
}

// Sweet Alert for Delete
function objectDelete(obj, name, url, redirectTo) {
    function doDelete() {
        var body = {};
        var success = function() {
            // swal('Deleted!', "[ "+name+"]"+" has been deleted ", "success");
            if (!redirectTo) {
                $(obj).parent().parent().remove();
            } else {
                window.location.href=redirectTo;
            }
        };
        var fail = function() {
            // swal("错误", "删除"+"[ "+name+" ]"+"遇到错误", "error");
            swal(gettext('Error'), "[ "+name+" ]" + gettext("Being used by the asset, please unbind the asset first."), "error");
        };
        APIUpdateAttr({
            url: url,
            body: JSON.stringify(body),
            method: 'DELETE',
            success_message: gettext("Delete the success"),
            success: success,
            error: fail
        });
    }
    swal({
        title: gettext('Are you sure about deleting it?'),
        text: " [" + name + "] ",
        type: "warning",
        showCancelButton: true,
        cancelButtonText: gettext('Cancel'),
        confirmButtonColor: "#ed5565",
        confirmButtonText: gettext('Confirm'),
        closeOnConfirm: true,
    }, function () {
        doDelete()
    });
}

function orgDelete(obj, name, url, redirectTo){
    function doDelete() {
        var body = {};
        var success = function() {
            if (!redirectTo) {
                $(obj).parent().parent().remove();
            } else {
                window.location.href=redirectTo;
            }
        };
        var fail = function(responseText, status) {
            if (status === 400){
                swal(gettext("Error"),  "[ " + name + " ] " + gettext("The organization contains undeleted information. Please try again after deleting"), "error");
            }
            else if (status === 405){
                swal(gettext("Error"), " [ "+ name + " ] " + gettext("Do not perform this operation under this organization. Try again after switching to another organization"), "error");
            }
        };
        APIUpdateAttr({
            url: url,
            body: JSON.stringify(body),
            method: 'DELETE',
            success_message: gettext("Delete the success"),
            success: success,
            error: fail
        });
    }
    swal({
        title: gettext("Please ensure that the following information in the organization has been deleted"),
        text: gettext("User list、User group、Asset list、Domain list、Admin user、System user、Labels、Asset permission"),
        type: "warning",
        showCancelButton: true,
        cancelButtonText: gettext('Cancel'),
        confirmButtonColor: "#ed5565",
        confirmButtonText: gettext('Confirm'),
        closeOnConfirm: true
    }, function () {
        doDelete();
    });
}

$.fn.serializeObject = function()
{
    var o = {};
    var a = this.serializeArray();
    $.each(a, function() {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};

function makeLabel(data) {
    return "<label class='detail-key'><b>" + data[0] + ": </b></label>" + data[1] + "</br>"
}



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.initDataTable = function (options) {
  // options = {
  //    ele *: $('#dataTable_id'),
  //    ajax_url *: '{% url 'users:user-list-api' %}',
  //    columns *: [{data: ''}, ....],
  //    dom: 'fltip',
  //    i18n_url: '{% static "js/...../en-us.json" %}',
  //    order: [[1, 'asc'], [2, 'asc'], ...],
  //    buttons: ['excel', 'pdf', 'print'],
  //    columnDefs: [{target: 0, createdCell: ()=>{}}, ...],
  //    uc_html: '<a>header button</a>',
  //    op_html: 'div.btn-group?',
  //    paging: true
  // }
  var ele = options.ele || $('.dataTable');
  var columnDefs = [
      {
          targets: 0,
          orderable: false,
          createdCell: function (td, cellData) {
              $(td).html('<input type="checkbox" class="text-center ipt_check" id=99991937>'.replace('99991937', cellData));
          }
      },
      {className: 'text-center', render: $.fn.dataTable.render.text(), targets: '_all'}
  ];
  columnDefs = options.columnDefs ? options.columnDefs.concat(columnDefs) : columnDefs;
  var select = {
            style: 'multi',
            selector: 'td:first-child'
      };
  var table = ele.DataTable({
        pageLength: options.pageLength || 15,
        dom: options.dom || '<"#uc.pull-left">flt<"row m-t"<"col-md-8"<"#op.col-md-6"><"col-md-6 text-center"i>><"col-md-4"p>>',
        order: options.order || [],
        // select: options.select || 'multi',
        buttons: [],
        columnDefs: columnDefs,
        ajax: {
            url: options.ajax_url,
            dataSrc: ""
        },
        columns: options.columns || [],
        select: options.select || select,
        language: jumpserver.language,
        lengthMenu: [[10, 15, 25, 50, -1], [10, 15, 25, 50, "All"]]
    });
    table.on('select', function(e, dt, type, indexes) {
        var $node = table[ type ]( indexes ).nodes().to$();
        $node.find('input.ipt_check').prop('checked', true);
        jumpserver.selected[$node.find('input.ipt_check').prop('id')] = true
    }).on('deselect', function(e, dt, type, indexes) {
        var $node = table[ type ]( indexes ).nodes().to$();
        $node.find('input.ipt_check').prop('checked', false);
        jumpserver.selected[$node.find('input.ipt_check').prop('id')] = false
    }).on('draw', function(){
        $('#op').html(options.op_html || '');
        $('#uc').html(options.uc_html || '');
        $('[data-toggle="popover"]').popover({
            html: true,
            placement: 'bottom',
            // trigger: 'hover',
            container: 'body'
        });
    });
    $('.ipt_check_all').on('click', function() {
      if ($(this).prop("checked")) {
          $(this).closest('table').find('.ipt_check').prop('checked', true);
          jumpserver.checked = true;
          table.rows({search:'applied', page:'current'}).select();
      } else {
          $(this).closest('table').find('.ipt_check').prop('checked', false);
          jumpserver.checked = false;
          table.rows({search:'applied', page:'current'}).deselect();
      }
    });

    return table;
};

jumpserver.initStaticTable = function (selector) {
    $(selector).DataTable({
        "searching": false,
        "bInfo": false,
        "paging": false,
        "order": [],
        "language": jumpserver.language
    });
};

jumpserver.initServerSideDataTable = function (options) {
  // options = {
  //    ele *: $('#dataTable_id'),
  //    ajax_url *: '{% url 'users:user-list-api' %}',
  //    columns *: [{data: ''}, ....],
  //    dom: 'fltip',
  //    i18n_url: '{% static "js/...../en-us.json" %}',
  //    order: [[1, 'asc'], [2, 'asc'], ...],
  //    buttons: ['excel', 'pdf', 'print'],
  //    columnDefs: [{target: 0, createdCell: ()=>{}}, ...],
  //    uc_html: '<a>header button</a>',
  //    op_html: 'div.btn-group?',
  //    paging: true
  // }
  var ele = options.ele || $('.dataTable');
  var columnDefs = [
      {
          targets: 0,
          orderable: false,
          createdCell: function (td, cellData) {
              $(td).html('<input type="checkbox" class="text-center ipt_check" id=99991937>'.replace('99991937', cellData));
          }
      },
      {className: 'text-center', targets: '_all'}
  ];
  columnDefs = options.columnDefs ? options.columnDefs.concat(columnDefs) : columnDefs;
  var select = {
            style: 'multi',
            selector: 'td:first-child'
      };
  var table = ele.DataTable({
        pageLength: options.pageLength || 15,
        dom: options.dom || '<"#uc.pull-left">fltr<"row m-t"<"col-md-8"<"#op.col-md-6"><"col-md-6 text-center"i>><"col-md-4"p>>',
        order: options.order || [],
        buttons: [],
        columnDefs: columnDefs,
        serverSide: true,
        processing: true,
        ajax: {
            url: options.ajax_url ,
            data: function (data) {
                delete data.columns;
                if (data.length !== null ){
                    data.limit = data.length;
                    delete data.length;
                }
                if (data.start !== null) {
                    data.offset = data.start;
                    delete data.start;
                }
                if (data.search !== null) {
                    var search_val = data.search.value;
                    var search_list = search_val.split(" ");
                    var search_attr = {};
                    var search_raw = [];

                    search_list.map(function (val, index) {
                       var kv = val.split(":");
                       if (kv.length === 2) {
                           search_attr[kv[0]] = kv[1]
                       } else {
                           search_raw.push(kv)
                       }
                    });
                    data.search = search_raw.join("");
                    $.each(search_attr, function (k, v) {
                        data[k] = v
                    })
                }
                if (data.order !== null && data.order.length === 1) {
                    var col = data.order[0].column;
                    var order = options.columns[col].data;
                    if (data.order[0].dir = "desc") {
                        order = "-" + order;
                    }
                    data.order = order;
                }
            },
            dataFilter: function(data){
                var json = jQuery.parseJSON( data );
                json.recordsTotal = json.count;
                json.recordsFiltered = json.count;
                return JSON.stringify(json); // return JSON string
            },
            dataSrc: "results"
        },
        columns: options.columns || [],
        select: options.select || select,
        language: jumpserver.language,
        lengthMenu: [[10, 15, 25, 50], [10, 15, 25, 50]]
    });
    table.selected = [];
    table.on('select', function(e, dt, type, indexes) {
        var $node = table[ type ]( indexes ).nodes().to$();
        $node.find('input.ipt_check').prop('checked', true);
        jumpserver.selected[$node.find('input.ipt_check').prop('id')] = true;
        if (type === 'row') {
            var rows = table.rows(indexes).data();
            $.each(rows, function (id, row) {
                if (row.id){
                    table.selected.push(row.id)
                }
            })
        }
    }).on('deselect', function(e, dt, type, indexes) {
        var $node = table[ type ]( indexes ).nodes().to$();
        $node.find('input.ipt_check').prop('checked', false);
        jumpserver.selected[$node.find('input.ipt_check').prop('id')] = false;
        if (type === 'row') {
            var rows = table.rows(indexes).data();
            $.each(rows, function (id, row) {
                if (row.id){
                    var index = table.selected.indexOf(row.id);
                    if (index > -1){
                        table.selected.splice(index, 1)
                    }
                }
            })
        }
    }).on('draw', function(){
        $('#op').html(options.op_html || '');
        $('#uc').html(options.uc_html || '');
        var table_data = [];
        $.each(table.rows().data(), function (id, row) {
            if (row.id) {
                table_data.push(row.id)
            }
        });

        $.each(table.selected, function (id, data) {
            var index = table_data.indexOf(data);
            if (index > -1){
                table.rows(index).select()
            }
        });
    });
    var table_id = table.settings()[0].sTableId;
    $('#' + table_id + ' .ipt_check_all').on('click', function() {
        if ($(this).prop("checked")) {
            $(this).closest('table').find('.ipt_check').prop('checked', true);
            table.rows({search:'applied', page:'current'}).select();
        } else {
            $(this).closest('table').find('.ipt_check').prop('checked', false);
            table.rows({search:'applied', page:'current'}).deselect();
        }
    });

    // jumpserver.table = table;
    return table;
};

/**
 * 替换所有匹配exp的字符串为指定字符串
 * @param exp 被替换部分的正则
 * @param newStr 替换成的字符串
 */
String.prototype.replaceAll = function (exp, newStr) {
    return this.replace(new RegExp(exp, "gm"), newStr);
};

/**
 * 原型:字符串格式化
 * @param args 格式化参数值
 */
String.prototype.format = function(args) {
    var result = this;
    if (arguments.length < 1) {
        return result;
    }

    var data = arguments;
    if (arguments.length == 1 && typeof (args) == "object") {
        data = args;
    }
    for ( var key in data) {
        var value = data[key];
        if (undefined != value) {
            result = result.replaceAll("\\{" + key + "\\}", value);
        }
    }
    return result;
};

function setCookie(key, value) {
    var expires = new Date();
    expires.setTime(expires.getTime() + (24 * 60 * 60 * 1000));
    document.cookie = key + '=' + value + ';expires=' + expires.toUTCString() + ';path=/';
}


function delCookie(key) {
    var expires = new Date();
    expires.setTime(expires.getTime() - 1);
    var val = getCookie(key);
    if (val !== null) {
        document.cookie = key + '=' + val + ";expires" + expires.toUTCString() + ';path=/';
    }
}

function createPopover(dataset, title, callback) {
    if (callback !== undefined){
        var new_dataset = [];
        $.each(dataset, function (index, value) {
            new_dataset.push(callback(value))
        });
        dataset = new_dataset;
    }
    var data_content = dataset.join("</br>");

    var html = "<a data-toggle='popover' data-content='" + data_content + "'>" + dataset.length + "</a>";
    return html;
}


 $(function () {
    (function ($) {
        $.getUrlParam = function (name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }
    })(jQuery);
});

function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}

function setUrlParam(url, name, value) {
    var urlArray = url.split("?");
    if (urlArray.length===1){
        url += "?" + name + "=" + value;
    } else {
        var oriParam = urlArray[1].split("&");
        var oriParamMap = {};
        $.each(oriParam, function (index, value) {
            var v = value.split("=");
            oriParamMap[v[0]] = v[1];
        });
        oriParamMap[name] = value;
        url = urlArray[0] + "?";
        var newParam = [];
        $.each(oriParamMap, function (index, value) {
            newParam.push(index + "=" + value);
        });
        url += newParam.join("&")
    }
    return url
}

// 校验密码-改变规则颜色
function checkPasswordRules(password, minLength) {
    if (wordMinLength(password, minLength)) {
        $('#rule_SECURITY_PASSWORD_MIN_LENGTH').css('color', 'green')
    }
    else {
        $('#rule_SECURITY_PASSWORD_MIN_LENGTH').css('color', '#908a8a')
    }

    if (wordUpperCase(password)) {
        $('#rule_SECURITY_PASSWORD_UPPER_CASE').css('color', 'green');
    }
    else {
        $('#rule_SECURITY_PASSWORD_UPPER_CASE').css('color', '#908a8a')
    }

    if (wordLowerCase(password)) {
        $('#rule_SECURITY_PASSWORD_LOWER_CASE').css('color', 'green')
    }
    else {
        $('#rule_SECURITY_PASSWORD_LOWER_CASE').css('color', '#908a8a')
    }

    if (wordNumber(password)) {
        $('#rule_SECURITY_PASSWORD_NUMBER').css('color', 'green')
    }
    else {
        $('#rule_SECURITY_PASSWORD_NUMBER').css('color', '#908a8a')
    }

    if (wordSpecialChar(password)) {
        $('#rule_SECURITY_PASSWORD_SPECIAL_CHAR').css('color', 'green')
    }
    else {
        $('#rule_SECURITY_PASSWORD_SPECIAL_CHAR').css('color', '#908a8a')
    }
}

// 最小长度
function wordMinLength(word, minLength) {
    //var minLength = {{ min_length }};
    var re = new RegExp("^(.{" + minLength + ",})$");
    return word.match(re)
}
// 大写字母
function wordUpperCase(word) {
    return word.match(/([A-Z]+)/)
}
// 小写字母
function wordLowerCase(word) {
    return word.match(/([a-z]+)/)
}
// 数字字符
function wordNumber(word) {
    return word.match(/([\d]+)/)
}
// 特殊字符
function wordSpecialChar(word) {
    return word.match(/[`,~,!,@,#,\$,%,\^,&,\*,\(,\),\-,_,=,\+,\{,\},\[,\],\|,\\,;,',:,",\,,\.,<,>,\/,\?]+/)
}

// 显示弹窗密码规则
function popoverPasswordRules(password_check_rules, $el) {
    var message = "";
    jQuery.each(password_check_rules, function (idx, rules) {
        message += "<li id=" + rules.id + " style='list-style-type:none;'> <i class='fa fa-check-circle-o' style='margin-right:10px;' ></i>" + rules.label + "</li>";
    });
    //$('#id_password_rules').html(message);
    $el.html(message)
}

// 初始化弹窗popover
function initPopover($container, $progress, $idPassword, $el, password_check_rules, i18n_fallback){
    options = {};
    // User Interface
    options.ui = {
        container: $container,
        viewports: {
            progress: $progress
            //errors: $('.popover-content')
        },
        showProgressbar: true,
        showVerdictsInsideProgressBar: true
    };
    options.i18n = {
        fallback: i18n_fallback,
        t: function (key) {
            var result = '';
            result = options.i18n.fallback[key];
            return result === key ? '' : result;
        }
    };
    $idPassword.pwstrength(options);
    popoverPasswordRules(password_check_rules, $el);
}