Skip to content

Commit

Permalink
Merge pull request #16 from NethServer/unbanTable
Browse files Browse the repository at this point in the history
Crowdsec add an Unban Page
  • Loading branch information
stephdl authored Aug 24, 2023
2 parents c4d99e6 + 83d5fca commit 906deb4
Show file tree
Hide file tree
Showing 12 changed files with 1,882 additions and 1,253 deletions.
14 changes: 14 additions & 0 deletions imageroot/actions/list-banned-ip/10jsonList
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
#
# Copyright (C) 2023 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#
# list the current banned IP

list=$(podman exec $MODULE_ID cscli decisions list --output json)

if [[ $list == 'null' ]];then
echo '[]'
else
echo $list
fi
24 changes: 24 additions & 0 deletions imageroot/actions/unban-ip/10unban-ip
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3

#
# Copyright (C) 2023 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

import json
import sys
import agent
import os


request = json.load(sys.stdin)
ip = request['ip']
action = request['action']
module_id = os.environ["MODULE_ID"]

if action == 'unban':
agent.run_helper("podman", "exec", module_id, "cscli", "decision", "delete", "-i", ip).check_returncode()
elif action == 'unban_all':
agent.run_helper("podman", "exec", module_id, "cscli", "decision", "delete", "--all").check_returncode()
else:
sys.exit(2)
33 changes: 33 additions & 0 deletions imageroot/actions/unban-ip/validate-input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "unban-ip input",
"$id": "http://schema.nethserver.org/mail/unban-ip.json",
"description": "flush the postfix queue email",
"examples": [
{
"queue": "1.2.3.4",
"action": "unban"
}
],
"type": "object",
"required": [
"ip",
"action"
],
"additionalProperties": false,
"properties": {
"ip": {
"type": "string",
"title": "IP",
"description": "IP to unban",
"minLength": 1
},
"action": {
"type": "string",
"format": "regex",
"pattern": "^(unban|unban_all)$",
"title": "Unban action",
"description": "Manage to unban IP"
}
}
}
3 changes: 2 additions & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dependencies": {
"@carbon/icons-vue": "^10.37.0",
"@carbon/vue": "^2.40.0",
"@nethserver/ns8-ui-lib": "^0.1.17",
"@nethserver/ns8-ui-lib": "^0.1.25",
"await-to-js": "^3.0.0",
"axios": "^0.21.2",
"carbon-components": "^10.41.0",
Expand All @@ -21,6 +21,7 @@
"vue": "^2.6.11",
"vue-axios": "^3.2.4",
"vue-date-fns": "^2.0.1",
"vue-debounce": "^4.0.0",
"vue-i18n": "^8.24.4",
"vue-router": "^3.2.0",
"vuex": "^3.4.0"
Expand Down
23 changes: 22 additions & 1 deletion ui/public/i18n/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@
"smarthost_is_disabled": "Email notifications are disabled",
"smarthosts_is_needed_to_send_notifications": "Enable Smarthost to receive CrowdSec email notifications"
},
"unban":{
"title": "Banned IP",
"unban_tooltip": "IP addresses that failed multiple login attempts are listed here. You can unban them if needed",
"no_bans": "No active bans",
"reload_bans": "Refresh",
"delete_all": "Unban all",
"delete": "Unban",
"search_bans": "Search",
"col_created_at": "Banned",
"col_value": "IP address",
"col_duration": "Ban time",
"col_scenario": "Reason",
"unban_ip": "Unban IP",
"confirm_unban_ip_message": "Unban IP address?",
"confirm_delete_all_bans_message": "Unban all IP addresses?",
"release_all_ip": "Unban all IP addresses",
"delete_bans": "Unban all"
},
"about": {
"title": "About"
},
Expand All @@ -70,7 +88,10 @@
"get-name": "Get name",
"list-backup-repositories": "List backup repositories",
"list-backups": "List backups",
"list-installed-modules": "List installed modules"
"list-installed-modules": "List installed modules",
"unban_ip_status": "List banned IP addresses",
"unban-ip": "Unban IP address",
"list-banned-ip": "List banned IP"
},
"error": {
"error": "Error",
Expand Down
9 changes: 9 additions & 0 deletions ui/src/components/AppSideMenuContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
<template v-slot:nav-icon><Settings20 /></template>
<span>{{ $t("settings.title") }}</span>
</cv-side-nav-link>
<cv-side-nav-link
@click="goToAppPage(instanceName, 'unban')"
:class="{ 'current-page': isLinkActive('unban') }"
>
<template v-slot:nav-icon><Error20 /></template>
<span>{{ $t("unban.title") }}</span>
</cv-side-nav-link>
<cv-side-nav-link
@click="goToAppPage(instanceName, 'about')"
:class="{ 'current-page': isLinkActive('about') }"
Expand All @@ -43,6 +50,7 @@
import Settings20 from "@carbon/icons-vue/es/settings/20";
import Information20 from "@carbon/icons-vue/es/information/20";
import Activity20 from "@carbon/icons-vue/es/activity/20";
import Error20 from "@carbon/icons-vue/es/error/20";
import { mapState } from "vuex";
import { QueryParamService, UtilService } from "@nethserver/ns8-ui-lib";

Expand All @@ -52,6 +60,7 @@ export default {
Settings20,
Information20,
Activity20,
Error20,
},
mixins: [QueryParamService, UtilService],
data() {
Expand Down
38 changes: 38 additions & 0 deletions ui/src/components/ConfirmReleaseIP.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!--
Copyright (C) 2023 Nethesis S.r.l.
SPDX-License-Identifier: GPL-3.0-or-later
-->
<template>
<NsModal
size="default"
:visible="isShown"
@modal-hidden="$emit('hide')"
@primary-click="$emit('confirm')"
>
<template slot="title"
>{{ $t("unban.unban_ip") }}: {{ ban.value }}</template
>
<template slot="content">
<div>{{ $t("unban.confirm_unban_ip_message") }}</div>
</template>
<template slot="secondary-button">{{ core.$t("common.cancel") }}</template>
<template slot="primary-button">{{ $t('unban.delete') }}</template>
</NsModal>
</template>

<script>
import { UtilService, IconService } from "@nethserver/ns8-ui-lib";
export default {
name: "ConfirmRelaseIP",
mixins: [UtilService, IconService],
props: {
isShown: Boolean,
ban: { type: [Object, null] },
core: { type: Object },
},
};
</script>

<style scoped lang="scss">
@import "../styles/carbon-utils";
</style>
35 changes: 35 additions & 0 deletions ui/src/components/ConfirmReleaseIPAll.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!--
Copyright (C) 2023 Nethesis S.r.l.
SPDX-License-Identifier: GPL-3.0-or-later
-->
<template>
<NsModal
size="default"
:visible="isShown"
@modal-hidden="$emit('hide')"
@primary-click="$emit('confirm')"
>
<template slot="title">{{ $t("unban.release_all_ip") }}</template>
<template slot="content">
<div>{{ $t("unban.confirm_delete_all_bans_message") }}</div>
</template>
<template slot="secondary-button">{{ core.$t("common.cancel") }}</template>
<template slot="primary-button">{{ $t('unban.delete') }}</template>
</NsModal>
</template>

<script>
import { UtilService, IconService } from "@nethserver/ns8-ui-lib";
export default {
name: "UnbanIPAll",
mixins: [UtilService, IconService],
props: {
isShown: Boolean,
core: { type: Object },
},
};
</script>

<style scoped lang="scss">
@import "../styles/carbon-utils";
</style>
3 changes: 3 additions & 0 deletions ui/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Vue.use(VueDateFns);
import LottieAnimation from "lottie-web-vue";
Vue.use(LottieAnimation);

import vueDebounce from "vue-debounce";
Vue.use(vueDebounce);

// filters
import { Filters } from "@nethserver/ns8-ui-lib";
for (const f in Filters) {
Expand Down
6 changes: 6 additions & 0 deletions ui/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ const routes = [
name: "Settings",
component: Settings,
},
{
path: "/unban",
name: "Unban",
component: () =>
import(/* webpackChunkName: "about" */ "../views/Unban.vue"),
},
{
path: "/about",
name: "About",
Expand Down
Loading

0 comments on commit 906deb4

Please sign in to comment.