Fix missing dependency

- Auto check for dependency ipset
- Install ipset if missing
master
90N45 2023-06-17 16:03:13 +02:00 committed by Mike Kershaw / Dragorn
parent 58a088d2dd
commit 0accef5356
4 changed files with 82 additions and 6 deletions

View File

@ -1,8 +1,31 @@
<div style="display: flex; justify-content: center; align-items: center;">
<span *ngIf="!hasInit" style="display: flex; justify-content: center; align-items: center; height: 10vh;">
<span *ngIf="!hasInit && hasIpset" style="display: flex; justify-content: center; align-items: center; height: 10vh;">
<mat-spinner diameter="25"></mat-spinner>
</span>
<mat-card *ngIf="hasInit" style="width: 40%;">
<mat-card *ngIf="!hasIpset" style="width: 40%;">
<mat-card-content>
<mat-card-title>Welcome To DenyIP</mat-card-title>
<mat-card-subtitle>Lets get started.</mat-card-subtitle>
<mat-divider></mat-divider>
<br>
<p>To manage the firewall, DenyIP needs the ipset package. The download of ipset will make a request to the internet.
</p>
<br>
<div style="display: flex; justify-content: center; align-items: center;">
<button style="width: 45%; height: 34px; display: flex; justify-content: center; align-items: center;" mat-flat-button color="accent" (click)="ipsetInstall()">
<span *ngIf="!isInstalling">Install ipset</span>
<span *ngIf="isInstalling">
<mat-spinner [diameter]="20"></mat-spinner>
</span>
</button>
</div>
<br>
<div style="display: flex; justify-content: center; align-items: center;">
<span><small>You can find out more about ipset at <a href="https://openwrt.org/packages/pkgdata/ipset">openwrt.org/packages/pkgdata/ipset</a><br>If you have installed ipset and this window does not update, please reload this module/page a few times and be patient...</small></span>
</div>
</mat-card-content>
</mat-card>
<mat-card *ngIf="hasInit && hasIpset" style="width: 40%;">
<mat-card-content>
<mat-card-title style="text-align: center;">DenyIP</mat-card-title>
<mat-divider></mat-divider>

View File

@ -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();
}
}

View File

@ -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"]

View File

@ -4,12 +4,34 @@ import logging
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: