Punishments.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <div class='container'>
  3. <table class='table is-striped'>
  4. <thead>
  5. <tr>
  6. <td>Type</td>
  7. <td>Value</td>
  8. <td>Reason</td>
  9. <td>Status</td>
  10. <td>Options</td>
  11. </tr>
  12. </thead>
  13. <tbody>
  14. <tr v-for='(index, punishment) in punishments | orderBy "expiresAt" -1' track-by='$index'>
  15. <td v-if='punishment.type === "banUserId"'>User ID</td>
  16. <td v-else>IP Address</td>
  17. <td>{{ punishment.value }}</td>
  18. <td>{{ punishment.reason }}</td>
  19. <td>{{ (punishment.active && new Date(punishment.expiresAt).getTime() > Date.now()) ? 'Active' : 'Inactive' }}</td>
  20. <td>
  21. <button class='button is-primary' @click='view(punishment)'>View</button>
  22. </td>
  23. </tr>
  24. </tbody>
  25. </table>
  26. <div class='card is-fullwidth'>
  27. <header class='card-header'>
  28. <p class='card-header-title'>Ban an IP</p>
  29. </header>
  30. <div class='card-content'>
  31. <div class='content'>
  32. <label class='label'>Expires In</label>
  33. <select v-model='ipBan.expiresAt'>
  34. <option value='1h'>1 Hour</option>
  35. <option value='12h'>12 Hours</option>
  36. <option value='1d'>1 Day</option>
  37. <option value='1w'>1 Week</option>
  38. <option value='1m'>1 Month</option>
  39. <option value='3m'>3 Months</option>
  40. <option value='6m'>6 Months</option>
  41. <option value='1y'>1 Year</option>
  42. </select>
  43. <label class='label'>IP</label>
  44. <p class='control is-expanded'>
  45. <input class='input' type='text' placeholder='IP address (xxx.xxx.xxx.xxx)' v-model='ipBan.ip'>
  46. </p>
  47. <label class='label'>Reason</label>
  48. <p class='control is-expanded'>
  49. <input class='input' type='text' placeholder='Reason' v-model='ipBan.reason'>
  50. </p>
  51. </div>
  52. </div>
  53. <footer class='card-footer'>
  54. <a class='card-footer-item' @click='banIP()' href='#'>Ban IP</a>
  55. </footer>
  56. </div>
  57. </div>
  58. <view-punishment v-show='modals.viewPunishment'></view-punishment>
  59. </template>
  60. <script>
  61. import ViewPunishment from '../Modals/ViewPunishment.vue';
  62. import { Toast } from 'vue-roaster';
  63. import io from '../../io';
  64. export default {
  65. components: { ViewPunishment },
  66. data() {
  67. return {
  68. punishments: [],
  69. modals: { viewPunishment: false },
  70. ipBan: {
  71. expiresAt: '1h'
  72. }
  73. }
  74. },
  75. methods: {
  76. toggleModal: function () {
  77. this.modals.viewPunishment = !this.modals.viewPunishment;
  78. },
  79. view: function (punishment) {
  80. this.$broadcast('viewPunishment', punishment);
  81. },
  82. banIP: function() {
  83. let _this = this;
  84. _this.socket.emit('punishments.banIP', _this.ipBan.ip, _this.ipBan.reason, _this.ipBan.expiresAt, res => {
  85. Toast.methods.addToast(res.message, 6000);
  86. });
  87. },
  88. init: function () {
  89. let _this = this;
  90. _this.socket.emit('punishments.index', result => {
  91. if (result.status === 'success') _this.punishments = result.data;
  92. });
  93. //_this.socket.emit('apis.joinAdminRoom', 'punishments', () => {});
  94. }
  95. },
  96. ready: function () {
  97. let _this = this;
  98. io.getSocket(socket => {
  99. _this.socket = socket;
  100. if (_this.socket.connected) _this.init();
  101. io.onConnect(() => _this.init());
  102. });
  103. }
  104. }
  105. </script>
  106. <style lang='scss' scoped>
  107. body { font-family: 'Roboto', sans-serif; }
  108. td { vertical-align: middle; }
  109. select { margin-bottom: 10px; }
  110. </style>