Punishments.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <div>
  3. <metadata title="Admin | Punishments" />
  4. <div class="container">
  5. <table class="table is-striped">
  6. <thead>
  7. <tr>
  8. <td>Type</td>
  9. <td>Value</td>
  10. <td>Reason</td>
  11. <td>Status</td>
  12. <td>Options</td>
  13. </tr>
  14. </thead>
  15. <tbody>
  16. <tr
  17. v-for="punishment in sortedPunishments"
  18. :key="punishment._id"
  19. >
  20. <td v-if="punishment.type === 'banUserId'">User ID</td>
  21. <td v-else>IP Address</td>
  22. <td>{{ punishment.value }}</td>
  23. <td>{{ punishment.reason }}</td>
  24. <td>
  25. {{
  26. punishment.active &&
  27. new Date(punishment.expiresAt).getTime() >
  28. Date.now()
  29. ? "Active"
  30. : "Inactive"
  31. }}
  32. </td>
  33. <td>
  34. <button
  35. class="button is-primary"
  36. @click="view(punishment)"
  37. >
  38. View
  39. </button>
  40. </td>
  41. </tr>
  42. </tbody>
  43. </table>
  44. <div class="card is-fullwidth">
  45. <header class="card-header">
  46. <p class="card-header-title">Ban an IP</p>
  47. </header>
  48. <div class="card-content">
  49. <div class="content">
  50. <label class="label">Expires In</label>
  51. <select v-model="ipBan.expiresAt">
  52. <option value="1h">1 Hour</option>
  53. <option value="12h">12 Hours</option>
  54. <option value="1d">1 Day</option>
  55. <option value="1w">1 Week</option>
  56. <option value="1m">1 Month</option>
  57. <option value="3m">3 Months</option>
  58. <option value="6m">6 Months</option>
  59. <option value="1y">1 Year</option>
  60. </select>
  61. <label class="label">IP</label>
  62. <p class="control is-expanded">
  63. <input
  64. v-model="ipBan.ip"
  65. class="input"
  66. type="text"
  67. placeholder="IP address (xxx.xxx.xxx.xxx)"
  68. />
  69. </p>
  70. <label class="label">Reason</label>
  71. <p class="control is-expanded">
  72. <input
  73. v-model="ipBan.reason"
  74. class="input"
  75. type="text"
  76. placeholder="Reason"
  77. />
  78. </p>
  79. </div>
  80. </div>
  81. <footer class="card-footer">
  82. <a class="card-footer-item" @click="banIP()" href="#"
  83. >Ban IP</a
  84. >
  85. </footer>
  86. </div>
  87. </div>
  88. <view-punishment
  89. v-if="modals.viewPunishment"
  90. :punishment-id="viewingPunishmentId"
  91. sector="admin"
  92. />
  93. </div>
  94. </template>
  95. <script>
  96. import { mapState, mapGetters, mapActions } from "vuex";
  97. import Toast from "toasters";
  98. import ws from "@/ws";
  99. export default {
  100. components: {
  101. ViewPunishment: () => import("@/components/modals/ViewPunishment.vue")
  102. },
  103. data() {
  104. return {
  105. viewingPunishmentId: "",
  106. punishments: [],
  107. ipBan: {
  108. expiresAt: "1h"
  109. }
  110. };
  111. },
  112. computed: {
  113. sortedPunishments() {
  114. // return _.orderBy(this.punishments, -1);
  115. return this.punishments;
  116. },
  117. ...mapState("modalVisibility", {
  118. modals: state => state.modals
  119. }),
  120. ...mapGetters({
  121. socket: "websockets/getSocket"
  122. })
  123. },
  124. mounted() {
  125. if (this.socket.readyState === 1) this.init();
  126. ws.onConnect(() => this.init());
  127. this.socket.on("event:admin.punishment.added", res =>
  128. this.punishments.push(res.data.punishment)
  129. );
  130. },
  131. methods: {
  132. view(punishment) {
  133. // this.viewPunishment(punishment);
  134. this.viewingPunishmentId = punishment._id;
  135. this.openModal("viewPunishment");
  136. },
  137. banIP() {
  138. this.socket.dispatch(
  139. "punishments.banIP",
  140. this.ipBan.ip,
  141. this.ipBan.reason,
  142. this.ipBan.expiresAt,
  143. res => {
  144. new Toast(res.message);
  145. }
  146. );
  147. },
  148. init() {
  149. this.socket.dispatch("punishments.index", res => {
  150. if (res.status === "success")
  151. this.punishments = res.data.punishments;
  152. });
  153. this.socket.dispatch("apis.joinAdminRoom", "punishments", () => {});
  154. },
  155. ...mapActions("modalVisibility", ["openModal"]),
  156. ...mapActions("admin/punishments", ["viewPunishment"])
  157. }
  158. };
  159. </script>
  160. <style lang="scss" scoped>
  161. .night-mode {
  162. .table {
  163. color: var(--light-grey-2);
  164. background-color: var(--dark-grey-3);
  165. thead tr {
  166. background: var(--dark-grey-3);
  167. td {
  168. color: var(--white);
  169. }
  170. }
  171. tbody tr:hover {
  172. background-color: var(--dark-grey-4) !important;
  173. }
  174. tbody tr:nth-child(even) {
  175. background-color: var(--dark-grey-2);
  176. }
  177. strong {
  178. color: var(--light-grey-2);
  179. }
  180. }
  181. .card {
  182. background: var(--dark-grey-3);
  183. .card-header {
  184. box-shadow: 0 1px 2px rgba(10, 10, 10, 0.8);
  185. }
  186. p,
  187. .label {
  188. color: var(--light-grey-2);
  189. }
  190. }
  191. }
  192. body {
  193. font-family: "Hind", sans-serif;
  194. }
  195. td {
  196. vertical-align: middle;
  197. }
  198. select {
  199. margin-bottom: 10px;
  200. }
  201. </style>