From 0accef5356f62331bac034641a7926754800484d Mon Sep 17 00:00:00 2001
From: 90N45 <79598596+90N45-d3v@users.noreply.github.com>
Date: Sat, 17 Jun 2023 16:03:13 +0200
Subject: [PATCH] Fix missing dependency
- Auto check for dependency ipset
- Install ipset if missing
---
.../src/lib/components/DenyIP.component.html | 27 +++++++++++++-
.../src/lib/components/DenyIP.component.ts | 37 +++++++++++++++++--
DenyIP/projects/DenyIP/src/module.json | 2 +-
DenyIP/projects/DenyIP/src/module.py | 22 +++++++++++
4 files changed, 82 insertions(+), 6 deletions(-)
diff --git a/DenyIP/projects/DenyIP/src/lib/components/DenyIP.component.html b/DenyIP/projects/DenyIP/src/lib/components/DenyIP.component.html
index 4f17d9b..df842bf 100644
--- a/DenyIP/projects/DenyIP/src/lib/components/DenyIP.component.html
+++ b/DenyIP/projects/DenyIP/src/lib/components/DenyIP.component.html
@@ -1,8 +1,31 @@
-
+
-
+
+
+ Welcome To DenyIP
+ Lets get started.
+
+
+ To manage the firewall, DenyIP needs the ipset package. The download of ipset will make a request to the internet.
+
+
+
+
+ Install ipset
+
+
+
+
+
+
+
+
You can find out more about ipset at openwrt.org/packages/pkgdata/ipset If you have installed ipset and this window does not update, please reload this module/page a few times and be patient...
+
+
+
+
DenyIP
diff --git a/DenyIP/projects/DenyIP/src/lib/components/DenyIP.component.ts b/DenyIP/projects/DenyIP/src/lib/components/DenyIP.component.ts
index a1406a4..4987493 100644
--- a/DenyIP/projects/DenyIP/src/lib/components/DenyIP.component.ts
+++ b/DenyIP/projects/DenyIP/src/lib/components/DenyIP.component.ts
@@ -15,11 +15,42 @@ export class DenyIPComponent implements OnInit {
userIP = "";
userType = "";
+ hasIpset: boolean = true;
hasInit: boolean = false;
+ isInstalling: boolean = false;
isAdding: boolean = false;
isResetting: boolean = false;
isUpdating: boolean = false;
+ ipsetCheck(): void {
+ this.API.request({
+ module: 'DenyIP',
+ action: "ipsetCheck"
+ }, (response) => {
+ if (response == "ok") {
+ this.hasIpset = true;
+ this.init();
+ } else {
+ this.hasIpset = false;
+ }
+ })
+ }
+
+ ipsetInstall(): void {
+ this.isInstalling = true;
+ this.API.request({
+ module: 'DenyIP',
+ action: "ipsetInstall"
+ }, (response) => {
+ if (response == "ok") {
+ this.ipsetCheck()
+ } else {
+ this.error = response;
+ }
+ this.isInstalling = false;
+ })
+ }
+
init(): void {
this.API.request({
module: 'DenyIP',
@@ -29,6 +60,8 @@ export class DenyIPComponent implements OnInit {
this.error = response;
} else {
this.hasInit = true;
+ this.get4();
+ this.get6();
}
})
}
@@ -100,8 +133,6 @@ export class DenyIPComponent implements OnInit {
}
ngOnInit() {
- this.init();
- this.get4();
- this.get6();
+ this.ipsetCheck();
}
}
diff --git a/DenyIP/projects/DenyIP/src/module.json b/DenyIP/projects/DenyIP/src/module.json
index 3998b01..c2c6659 100644
--- a/DenyIP/projects/DenyIP/src/module.json
+++ b/DenyIP/projects/DenyIP/src/module.json
@@ -2,7 +2,7 @@
"name": "DenyIP",
"title": "DenyIP",
"description": "Declare IP addresses and refuse their traffic",
- "version": "1.0.0",
+ "version": "1.0.1",
"author": "90N45",
"firmware_required": "1.0.0",
"devices": ["wifipineapplemk7", "wifipineappleent1"]
diff --git a/DenyIP/projects/DenyIP/src/module.py b/DenyIP/projects/DenyIP/src/module.py
index 21a7f85..fccc32d 100644
--- a/DenyIP/projects/DenyIP/src/module.py
+++ b/DenyIP/projects/DenyIP/src/module.py
@@ -4,12 +4,34 @@
import os
import subprocess
from pineapple.modules import Module, Request
+import pineapple.helpers.opkg_helpers as opkg
module = Module('DenyIP', logging.DEBUG)
addresses_4 = []
addresses_6 = []
+@module.handles_action("ipsetCheck")
+def ipset_check(request):
+ try:
+ if opkg.check_if_installed("ipset", module.logger) == True:
+ return "ok"
+ else:
+ return "Not installed"
+ except Exception as e:
+ return "Error: " + str(e)
+
+@module.handles_action("ipsetInstall")
+def ipset_install(request):
+ try:
+ status, error = opkg.install_dependency("ipset", module.logger)
+ if status == True:
+ return "ok"
+ else:
+ return "Error: " + error
+ except Exception as e:
+ return "Error: " + str(e)
+
@module.handles_action("init")
def init(request):
try: