ray-1337
2 years ago
No known key found for this signature in database
GPG Key ID: DED41DCC150FCD32
3 changed files with
10 additions and
6 deletions
src/Util.ts
src/methods/Allow.ts
src/methods/Deny.ts
@ -2,6 +2,10 @@ import { execSync, exec } from "node:child_process";
import { getuid , versions , platform } from "node:process" ;
import { promisify } from "node:util" ;
export function isAddedOrUpdated ( response : string ) {
return /((adde|update)d)/gi . test ( response . toLowerCase ( ) ) ;
} ;
export const shouldDryRunDuringTesting = process . env . npm_lifecycle_event === "test" ? "--dry-run" : "" ;
export async function runCommand ( command : string ) {
@ -1,4 +1,4 @@
import { checkAppropriatePort , checkAppropriateIP , runCommand , shouldDryRunDuringTesting } from "../Util" ;
import { checkAppropriatePort , isAddedOrUpdated , checkAppropriateIP , runCommand , shouldDryRunDuringTesting } from "../Util" ;
import type { PortProtocol } from "../Typings" ;
/ * *
@ -11,7 +11,7 @@ async function port(port: number, protocol?: PortProtocol) {
if ( ! checkPort ) return false ;
let command = await runCommand ( ` echo "y" | sudo ufw ${ shouldDryRunDuringTesting } allow ${ port } ${ protocol ? ` / ${ protocol } ` : "" } ` ) ;
return command ? command . toLowerCase ( ) . match ( /(added)/gi ) !== null : false ;
return command ? isAddedOrUpdated ( command ) : false ;
} catch ( err ) {
throw err ;
} ;
@ -33,7 +33,7 @@ async function address(address: string, port?: number, protocol?: PortProtocol)
} ;
let command = await runCommand ( ` echo "y" | sudo ufw allow from ${ address } ${ port ? ` to any port ${ port } ` : "" } ${ protocol ? ` proto ${ protocol } ` : "" } ` ) ;
return command ? command . toLowerCase ( ) . match ( /(added)/gi ) !== null : false ;
return command ? isAddedOrUpdated ( command ) : false ;
} catch ( err ) {
throw err ;
} ;
@ -1,4 +1,4 @@
import { checkAppropriatePort , checkAppropriateIP , runCommand , shouldDryRunDuringTesting } from "../Util" ;
import { checkAppropriatePort , isAddedOrUpdated , checkAppropriateIP , runCommand , shouldDryRunDuringTesting } from "../Util" ;
import type { PortProtocol } from "../Typings" ;
/ * *
@ -11,7 +11,7 @@ async function port(port: number, protocol?: PortProtocol) {
if ( ! checkPort ) return false ;
let command = await runCommand ( ` echo "y" | sudo ufw ${ shouldDryRunDuringTesting } deny ${ port } ${ protocol ? ` / ${ protocol } ` : "" } ` ) ;
return command ? command . toLowerCase ( ) . match ( /(added)/gi ) !== null : false ;
return command ? isAddedOrUpdated ( command ) : false ;
} catch ( err ) {
throw err ;
} ;
@ -33,7 +33,7 @@ async function address(address: string, port?: number, protocol?: PortProtocol)
} ;
let command = await runCommand ( ` echo "y" | sudo ufw ${ shouldDryRunDuringTesting } deny from ${ address } ${ port ? ` to any port ${ port } ` : "" } ${ protocol ? ` proto ${ protocol } ` : "" } ` ) ;
return command ? command . toLowerCase ( ) . match ( /(added)/gi ) !== null : false ;
return command ? isAddedOrUpdated ( command ) : false ;
} catch ( err ) {
throw err ;
} ;