ssh_keys_show.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. {% extends "layout.html" %}
  2. {% block head %}
  3. {{ super() }}
  4. <style type="text/css">
  5. @media (min-width: 768px) {
  6. .form-horizontal .control-label {
  7. text-align: left;
  8. }
  9. }
  10. label>span {
  11. color: deepskyblue;
  12. }
  13. .table {
  14. font-size: 12px;
  15. border-width: 1px;
  16. line-height: 20px;
  17. }
  18. .table > thead > tr > th,
  19. .table > tfoot > tr > th {
  20. color: #999999;
  21. font-weight: normal;
  22. border-bottom: 0 solid #e1e6eb;
  23. background-color: #F5F6FA;
  24. }
  25. .table > tbody > tr > td {
  26. color: #424547;
  27. }
  28. .table-bordered > tbody > tr {
  29. padding-top: 10px;
  30. padding-bottom: 10px;
  31. }
  32. .table-bordered > thead > tr > th,
  33. .table-bordered > tbody > tr > th,
  34. .table-bordered > tfoot > tr > th,
  35. .table-bordered > thead > tr > td,
  36. .table-bordered > tbody > tr > td,
  37. .table-bordered > tfoot > tr > td {
  38. border-style: solid;
  39. border-width: 1px 0 0 0;
  40. }
  41. .btn,
  42. .form-control,
  43. .modal-content {
  44. border-radius: 0 !important;
  45. }
  46. .btn-shortcut {
  47. font-size: 12px !important;
  48. padding: 0 26px;
  49. }
  50. .show {
  51. display: inline-block !important;
  52. }
  53. .tr-selected td,
  54. .tr-selected {
  55. color: #000 !important;
  56. background: #fafaff !important;
  57. }
  58. </style>
  59. {% endblock head %}
  60. {% block content %}
  61. <script type="text/javascript">
  62. var page = 1;
  63. var page_size = 10;
  64. var keyword = '';
  65. var resource_path = window.location.pathname;
  66. var cur_url = resource_path;
  67. $(document).ready(function() {
  68. page_size = $('#page_size').val();
  69. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  70. var last_ready = null;
  71. $('#content_search').keydown(function() {
  72. if (last_ready !== null) {
  73. clearTimeout(last_ready);
  74. }
  75. last_ready = setTimeout(function () {
  76. keyword = $('#content_search').val();
  77. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  78. if (keyword.length > 0) {
  79. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  80. }
  81. window.location.href=cur_url;
  82. }, 1000);
  83. });
  84. $('#page_size').change(function () {
  85. keyword = $('#content_search').val();
  86. page_size = $('#page_size').val();
  87. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  88. if (keyword.length > 0) {
  89. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  90. }
  91. window.location.href=cur_url;
  92. });
  93. $("thead").on('click', ".all_selector", function() {
  94. if ($("thead .all_selector").is(':checked')) {
  95. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', true);
  96. $(".all_selector").prop('checked', true);
  97. } else {
  98. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', false);
  99. $(".all_selector").prop('checked', false);
  100. }
  101. select_item_action();
  102. });
  103. $("tfoot").on('click', ".all_selector", function() {
  104. if ($("tfoot .all_selector").is(':checked')) {
  105. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', true);
  106. $(".all_selector").prop('checked', true);
  107. } else {
  108. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', false);
  109. $(".all_selector").prop('checked', false);
  110. }
  111. select_item_action();
  112. });
  113. $("tbody tr").on('click', "input[type='checkbox']", function() {
  114. select_item_action();
  115. });
  116. $('#edit_label_modal').on('show.bs.modal', function (me) {
  117. $('#ssh_key_id').val($(me.relatedTarget).parent().parent().prev().prev().text());
  118. $('#edit_label').val($(me.relatedTarget).prev().text());
  119. });
  120. $('#edit_public_key_modal').on('show.bs.modal', function (me) {
  121. $('#ssh_key_id').val($(me.relatedTarget).parent().parent().prev().prev().prev().prev().text());
  122. $('#edit_public_key').val($(me.relatedTarget).prev().text());
  123. });
  124. $('#add_ssh_key_modal').on('show.bs.modal', function (me) {
  125. //
  126. });
  127. $('#add_ssh_key_form').formValidation({
  128. framework: 'bootstrap4',
  129. icon: {
  130. valid: 'fa fa-check',
  131. invalid: 'fa fa-times',
  132. validating: 'fa fa-refresh'
  133. },
  134. // Since the Bootstrap Button hides the radio and checkbox
  135. // We exclude the disabled elements only
  136. excluded: ':disabled',
  137. locale: 'zh_CN',
  138. fields: {
  139. label: {
  140. validators: {
  141. notEmpty: {},
  142. stringLength: {
  143. min: 2,
  144. max: 255
  145. }
  146. }
  147. },
  148. public_key: {
  149. validators: {
  150. notEmpty: {},
  151. stringLength: {
  152. min: 380,
  153. max: 420
  154. }
  155. }
  156. }
  157. }
  158. })
  159. .on('success.field.fv', function(e, data) {
  160. if (data.fv.getInvalidFields().length > 0) { // There is invalid field
  161. data.fv.disableSubmitButtons(true);
  162. }
  163. })
  164. });
  165. function refresh() {
  166. keyword = $('#content_search').val();
  167. page = $('#pagination li.active a').text();
  168. page_size = $('#page_size').val();
  169. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  170. if (keyword.length > 0) {
  171. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  172. }
  173. window.location.href=cur_url;
  174. }
  175. function row_onmouseover(me) {
  176. $(me).find(".edit_label_trigger, .edit_path_trigger").css('display','inline-flex');
  177. }
  178. function row_onmouseout(me) {
  179. $(me).find(".edit_label_trigger, .edit_path_trigger").css('display','none');
  180. }
  181. function label_update(me) {
  182. var ssh_key_id = $('#ssh_key_id').val();
  183. var label = $('#edit_label').val();
  184. $('#edit_label_modal').modal('hide');
  185. $.ajax({
  186. url : '/api/ssh_keys/' + ssh_key_id,
  187. type : 'PATCH',
  188. contentType: "application/json; charset=utf-8",
  189. data : JSON.stringify({
  190. label: label
  191. }),
  192. error : function() {
  193. alter_danger('SSH Key 名称更新失败!');
  194. },
  195. success : function() {
  196. alter_success('SSH Key 名称更新成功!');
  197. setTimeout(function() {
  198. refresh();
  199. }, 1000);
  200. }
  201. });
  202. }
  203. function public_key_update(me) {
  204. var ssh_key_id = $('#ssh_key_id').val();
  205. var public_key = $('#edit_public_key').val();
  206. $('#edit_public_key_modal').modal('hide');
  207. $.ajax({
  208. url : '/api/ssh_keys/' + ssh_key_id,
  209. type : 'PATCH',
  210. contentType: "application/json; charset=utf-8",
  211. data : JSON.stringify({
  212. public_key: public_key
  213. }),
  214. error : function() {
  215. alter_danger('Public Key 更新失败!');
  216. },
  217. success : function() {
  218. alter_success('Public Key 更新成功!');
  219. setTimeout(function() {
  220. refresh();
  221. }, 1000);
  222. }
  223. });
  224. }
  225. function get_selected_element(checked) {
  226. if (checked === null) {
  227. checked = true;
  228. }
  229. if (checked) {
  230. return $('tbody :checked');
  231. } else {
  232. return $('tbody input:not(:checked)');
  233. }
  234. }
  235. function highlight_selected_element() {
  236. var selected_element = get_selected_element(true);
  237. var no_selected_element = get_selected_element(false);
  238. selected_element.each(function(i, e) {
  239. $(e).parent().parent().toggleClass('tr-selected', true);
  240. });
  241. no_selected_element.each(function(i, e) {
  242. $(e).parent().parent().toggleClass('tr-selected', false);
  243. });
  244. }
  245. function shortcut_bar_enable() {
  246. var selected_element = get_selected_element(true);
  247. if (selected_element.length > 0) {
  248. $('.btn-shortcut').toggleClass('disabled', false);
  249. } else {
  250. $('.btn-shortcut').toggleClass('disabled', true);
  251. }
  252. }
  253. function select_item_action() {
  254. highlight_selected_element();
  255. shortcut_bar_enable();
  256. }
  257. function remove(id) {
  258. $.ajax({
  259. url : '/api/ssh_keys/' + id,
  260. type : 'DELETE',
  261. contentType: "application/json; charset=utf-8",
  262. error : function() {
  263. alter_danger('SSH Key 删除指令发送失败!');
  264. },
  265. success : function() {
  266. alter_success('SSH Key 删除指令发送成功!');
  267. setTimeout(function() {
  268. refresh();
  269. }, 1000);
  270. }
  271. });
  272. }
  273. function delete_at(me) {
  274. var ssh_key_id = $('#ssh_key_id').val();
  275. remove(ssh_key_id);
  276. $('#delete_modal').modal('hide');
  277. }
  278. </script>
  279. <div class="panel">
  280. <div class="panel-body">
  281. <h3 class="title-hero" style="font-size: 24px;">
  282. SSH Keys
  283. </h3>
  284. <div>
  285. <div id="datatable-row-highlight_wrapper" class="dataTables_wrapper form-inline">
  286. <div class="row" style="padding: 10px 10px 10px 0; width: 100%;">
  287. <div class="col-sm-12" style="padding-right: 0;">
  288. <div id="datatable-row-highlight_filter" class="dataTables_filter" style="display: inline-block;">
  289. <input id="content_search" type="search" class="form-control" placeholder="模糊搜索..." value="{%- if keyword -%} {{ keyword }} {%- endif -%}" style="margin-left: 0; border-radius: 0;">
  290. </div>
  291. <div class="pull-right">
  292. <button class="btn btn-default" onclick="refresh()" style="border-radius: 0;"><span class="glyph-icon icon-elusive-arrows-cw"></span></button>
  293. <a class="btn btn-info" href="javascript:;" data-toggle="modal" data-target="#add_ssh_key_modal" style="border-radius: 0; padding-left: 40px; padding-right: 40px;">添加 SSH Key</a>
  294. </div>
  295. </div>
  296. </div>
  297. <table id="ssh_keys_list" class="table table-bordered table-hover" cellspacing="0" width="100%" role="grid"
  298. style="width: 100%; margin-bottom: 0; border-bottom-width: 0; table-layout: fixed;">
  299. <thead>
  300. <tr role="row">
  301. <th style="display: none;">ID</th>
  302. <th><input class="all_selector" title="选取所有" type="checkbox"></th>
  303. <th width="180px;">名称</th>
  304. <th width="480px;">Public Key</th>
  305. <th>创建时间</th>
  306. <th>操作</th>
  307. </tr>
  308. </thead>
  309. <tbody>
  310. {% for item in ssh_keys_ret.data %}
  311. <tr role="row" class="odd" onmouseover="row_onmouseover(this);" onmouseout="row_onmouseout(this);">
  312. <td style="display: none;">{{ item.id }}</td>
  313. <td><input title="选中" type="checkbox"></td>
  314. <td>
  315. <div>
  316. <p style="display: inline-block;">{{ item.label }}</p>
  317. <a href="javascript:;" class="edit_label_trigger" data-toggle="modal" data-target="#edit_label_modal" style="display: none; float: right;">
  318. <span class="glyph-icon icon-elusive-pencil" style="width: 20px; height: 20px; margin-left: 10px; border-radius: 0; border: 1px solid rgb(220, 233, 255); background-color: #ffffff;"></span>
  319. </a>
  320. </div>
  321. </td>
  322. <td class="text-left" style="text-overflow: ellipsis; overflow: hidden;">
  323. {{ item.public_key }}
  324. </td>
  325. <td>
  326. {{ format_datetime_by_tus(item.create_time * 1000000) }}
  327. </td>
  328. <td>
  329. <div class="dropdown inline-block">
  330. <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
  331. 更多
  332. </a>
  333. <ul class="dropdown-menu">
  334. <li>
  335. <a href="javascript:;" data-toggle="modal" data-target="#delete_modal"
  336. onclick="$('#ssh_key_id').val($(this).parent().parent().parent().parent().parent().children()[0].textContent);
  337. $('#delete_instance_desc').text($(this).parent().parent().parent().parent().parent().children()[2].textContent)">
  338. 删除
  339. </a>
  340. </li>
  341. </ul>
  342. </div>
  343. </td>
  344. </tr>
  345. {% endfor %}
  346. </tbody>
  347. </table>
  348. <table class="table table-bordered" style="border-top-width: 0; z-index: 99; position: sticky; bottom: 0;">
  349. <tfoot>
  350. <tr style="height: 70px;">
  351. <th><input type="checkbox" title="选取所有" class="all_selector"></th>
  352. <th>
  353. <div class="row">
  354. <div class="col-sm-6">
  355. </div>
  356. <div class="col-sm-3" style="font-size: 12px; padding-top: 5px; text-align: right;">
  357. 共有{{ ssh_keys_ret.paging.total }}条,每页显示:
  358. <select id="page_size" name="datatable-row-highlight_length" title="page_size" class="form-control" style="height: 22px; vertical-align: baseline;">
  359. <option value="10" {% if page_size == 10 %} selected {% endif %}>10</option>
  360. <option value="20" {% if page_size == 20 %} selected {% endif %}>20</option>
  361. <option value="50" {% if page_size == 50 %} selected {% endif %}>50</option>
  362. </select>&nbsp;&nbsp;条
  363. </div>
  364. <div class="col-sm-3" style="text-align: left;">
  365. <div class="dataTables_paginate paging_bootstrap" id="datatable-row-highlight_paginate">
  366. <ul id="pagination" class="pagination">
  367. <li class="{% if page == 1 %} disabled {% endif %}">
  368. <a href="{{ resource_path }}?page={{ page - 1 }}&page_size={{ page_size }}{% if keyword %}&keyword={{ keyword }}{% endif %}{% if order_by %}&order_by={{ order_by }}{% endif %}{% if order %}&order={{ order }}{% endif %}">«</a>
  369. </li>
  370. {% for item in pages %}
  371. <li class="{% if item == page %} active {% endif %}">
  372. <a href="{{ resource_path }}?page={{ item }}&page_size={{ page_size }}{% if keyword %}&keyword={{ keyword }}{% endif %}{% if order_by %}&order_by={{ order_by }}{% endif %}{% if order %}&order={{ order }}{% endif %}">{{ item }}</a>
  373. </li>
  374. {% endfor %}
  375. <li class="{% if page == last_page %} disabled {% endif %}">
  376. <a href="{{ resource_path }}?page={{ page + 1 }}&page_size={{ page_size }}{% if keyword %}&keyword={{ keyword }}{% endif %}{% if order_by %}&order_by={{ order_by }}{% endif %}{% if order %}&order={{ order }}{% endif %}">»</a>
  377. </li>
  378. </ul>
  379. </div>
  380. </div>
  381. </div>
  382. </th>
  383. </tr>
  384. </tfoot>
  385. </table>
  386. </div>
  387. </div>
  388. </div>
  389. </div>
  390. <input id="ssh_key_id" title="SSH Key ID" class="form-control" name="ssh_key_id" hidden>
  391. <div class="modal" id="edit_label_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  392. <div class="modal-dialog modal-sm">
  393. <div class="modal-content">
  394. <div class="modal-header">
  395. <h4 class="modal-title">编辑 SSH Key 名称:</h4>
  396. </div>
  397. <div class="modal-body">
  398. <input id="edit_label" title="SSH Key 名称" class="form-control" name="ssh_key_label">
  399. </div>
  400. <div class="modal-footer">
  401. <button type="button" class="btn btn-sm btn-primary" onclick="label_update();">确定</button>
  402. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  403. </div>
  404. </div>
  405. </div>
  406. </div>
  407. <div class="modal" id="edit_public_key_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  408. <div class="modal-dialog">
  409. <div class="modal-content">
  410. <div class="modal-header">
  411. <h4 class="modal-title">编辑 SSH Key:</h4>
  412. </div>
  413. <div class="modal-body">
  414. <input id="edit_public_key" title="Public Key" class="form-control" name="public_key">
  415. </div>
  416. <div class="modal-footer">
  417. <button type="button" class="btn btn-sm btn-primary" onclick="public_key_update();">确定</button>
  418. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  419. </div>
  420. </div>
  421. </div>
  422. </div>
  423. <div class="modal" id="delete_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  424. <div class="modal-dialog">
  425. <div class="modal-content">
  426. <div class="modal-header">
  427. <h4 class="modal-title">删除 SSH Key:</h4>
  428. </div>
  429. <div class="modal-body">
  430. <p>你确定要删除该 SSH Key 吗?</p>
  431. <h3 style="color: orangered;" id="delete_instance_desc"></h3>
  432. </div>
  433. <div class="modal-footer">
  434. <button type="button" class="btn btn-sm btn-primary" onclick="delete_at();">确定</button>
  435. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  436. </div>
  437. </div>
  438. </div>
  439. </div>
  440. <div class="modal" id="add_ssh_key_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  441. <div class="modal-dialog modal-lg">
  442. <div class="modal-content">
  443. <div class="modal-header">
  444. <h4 class="modal-title">添加 SSH Key:</h4>
  445. </div>
  446. <div class="modal-body" style="padding-top: 0; padding-bottom: 0;">
  447. <div class="example-box-wrapper">
  448. <form id="add_ssh_key_form" class="form-horizontal bordered-row" action="/ssh_key" method="post">
  449. <div class="form-group">
  450. <div class="col-sm-2"></div>
  451. <label class="col-sm-2 control-label"><span class="glyph-icon icon-elusive-compass-circled"></span>&nbsp;&nbsp;名称</label>
  452. <div class="col-sm-6">
  453. <input id="label" name="label" type="text" title="SSH Key 名称" class="form-control">
  454. </div>
  455. </div>
  456. <div class="form-group">
  457. <div class="col-sm-2"></div>
  458. <label class="col-sm-2 control-label"><span class="glyph-icon icon-newspaper-o"></span>&nbsp;&nbsp;Public Key</label>
  459. <div class="col-sm-6">
  460. <textarea id="public_key" name="public_key" title="Public key" class="form-control"></textarea>
  461. </div>
  462. </div>
  463. <div class="form-group">
  464. <div class="col-sm-4"></div>
  465. <div class="col-sm-6 pull-right">
  466. <button type="submit" class="btn btn-blue-alt" style="width: 180px; height: 40px; font-size: 16px;" disabled>创建</button>
  467. <button class="btn btn-default" style="width: 64px; height: 40px; font-size: 16px;" data-dismiss="modal">取消</button>
  468. </div>
  469. </div>
  470. </form>
  471. </div>
  472. </div>
  473. </div>
  474. </div>
  475. </div>
  476. {% endblock content %}