/****************************************************************/ /* Ban a domain or IP address in Weasel */ /* */ /* Author: Peter Moylan (peter@pmoylan.org) */ /* Started: 10 April 2012 */ /* Last revised: 16 November 2020 */ /* */ /* Usage: */ /* ban arg */ /* */ /* The acceptable forms of "arg" are described in the */ /* "Editing a list of host names" section of the Weasel */ /* manual. Note that this script does only minimal */ /* legality checking on the argument. */ /* */ /* Installation: */ /* Put this file anywhere you like, but run it from the */ /* directory containing WEASEL.INI or WEASEL.TNI */ /* */ /****************************************************************/ CALL RxFuncAdd SysLoadFuncs, rexxutil, sysloadfuncs CALL SysLoadFuncs CALL CheckPrerequisites rxu SelectTNI INI_get INI_put PARSE ARG param IF (param = '') THEN CALL SayUsage tni = SelectTNI("Weasel") /* Add the new banned domain or IP address (or range) */ param = IsLegal(param) CALL AddBannedEntry param, tni /* Tell Weasel that a change has occurred, then exit. */ SemName = "\SEM32\WEASEL\UPDATED" IF RxOpenEventSem(hev, SemName) \= 0 THEN rc = RxCreateEventSem( hev ,'Shared', SemName, 'Reset') CALL RxPostEventSem hev CALL RxResetEventSem hev CALL RxCloseEventSem hev EXIT 0 /****************************************************************/ /* A USEFUL HELP MESSAGE */ /* We will exit if this is called */ /****************************************************************/ SayUsage: PROCEDURE SAY "Usage: ban arg" SAY "where arg is a domain name or numeric address" SAY "(some ranges and wildcards allowed, see Weasel manual)" EXIT 1 /****************************************************************/ /* SANITY CHECK ON THE NEW ENTRY */ /* For now there is no checking */ /****************************************************************/ IsLegal: PROCEDURE PARSE ARG newstring RETURN newstring /****************************************************************/ /* ADDING A NEW ENTRY */ /****************************************************************/ AddBannedEntry: PROCEDURE expose (Globals) /* Prerequisite: none */ PARSE ARG newentry, tni Nul = D2C(0) SAY "tni = '"tni"'" IF tni THEN INIFile = 'WEASEL.TNI' ELSE INIFile = 'WEASEL.INI' /* Read the existing list of banned domains. */ list = INI_get(INIFile, '$SYS', 'Banned') /* Add the new entry to the list. */ IF list = '' THEN list = newentry||Nul||Nul ELSE list = newentry||Nul||list CALL INI_put INIFile, '$SYS', 'Banned', list RETURN /****************************************************************/ /* CHECKING PREREQUISITES */ /****************************************************************/ CheckPrerequisites: PROCEDURE /* The argument is a space-separated list of prerequisite */ /* functions, for example */ /* CALL CheckPrerequisites rxu SelectTNI INI_get */ /* where (at least in this version) each list item is */ /* either 'rxu' or a function from my TNItools package. */ /* If any is missing then we exit with an error message. */ PARSE UPPER ARG funclist funclist = STRIP(funclist) needrxu = 0 needtools = 0 DO WHILE funclist \= '' PARSE VAR funclist func funclist funclist = STRIP(funclist) IF func = 'RXU' THEN DO /* Initialise RXU if not already available, fail if */ /* the RxFuncAdd operation fails. We must */ /* RxFuncQuery RxuTerm because RxuTerm does not */ /* deregister RxuInit. The RxFuncDrop is needed */ /* because RxFuncAdd seems to report failure if the */ /* function is already registered. */ IF RxFuncQuery('RxuTerm') THEN DO CALL RxFuncDrop('RxuInit') CALL RxFuncAdd 'RxuInit','RXU','RxuInit' IF result THEN DO SAY 'Cannot load RXU' needrxu = 1 END ELSE CALL RxuInit END END ELSE DO func = func||'.CMD' IF SysSearchPath('PATH', func) = '' THEN DO SAY 'ERROR: 'func' must be in your PATH' needtools = 1 END END END IF needrxu THEN SAY 'You can find RXU1a.zip at Hobbes' IF needtools THEN SAY 'Please install the GenINI package' IF needrxu | needtools THEN EXIT 1 RETURN /****************************************************************/