@ -1,4 +1,4 @@
import { checkAppropriatePort , checkAppropriateIP , runCommand } from "../Util" ;
import { checkAppropriatePort , checkAppropriateIP , runCommand , shouldDryRunDuringTesting } from "../Util" ;
import type { PortProtocol } from "../Typings" ;
import type { PortProtocol } from "../Typings" ;
/ * *
/ * *
@ -10,7 +10,7 @@ async function port(port: number, protocol?: PortProtocol) {
let checkPort = checkAppropriatePort ( port ) ;
let checkPort = checkAppropriatePort ( port ) ;
if ( ! checkPort ) return false ;
if ( ! checkPort ) return false ;
let command = await runCommand ( ` echo "y" | sudo ufw deny ${ port } ${ protocol ? ` / ${ protocol } ` : "" } ` ) ;
let command = await runCommand ( ` echo "y" | sudo ufw ${ shouldDryRunDuringTesting } deny ${ port } ${ protocol ? ` / ${ protocol } ` : "" } ` ) ;
return command ? command . toLowerCase ( ) . match ( /(added)/gi ) !== null : false ;
return command ? command . toLowerCase ( ) . match ( /(added)/gi ) !== null : false ;
} catch ( err ) {
} catch ( err ) {
throw err ;
throw err ;
@ -32,7 +32,7 @@ async function address(address: string, port?: number, protocol?: PortProtocol)
if ( ! checkPort ) return false ;
if ( ! checkPort ) return false ;
} ;
} ;
let command = await runCommand ( ` echo "y" | sudo ufw deny from ${ address } ${ port ? ` to any port ${ port } ` : "" } ${ protocol ? ` proto ${ protocol } ` : "" } ` ) ;
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 ? command . toLowerCase ( ) . match ( /(added)/gi ) !== null : false ;
} catch ( err ) {
} catch ( err ) {
throw err ;
throw err ;