Jump to content
  • CheckCallerInTextFile

    CheckCallerInTextFile

    VBScript   → Lua

     

    This function checks if the current caller (i.e. his phone number) can be found in a given text file. It can be used to create black or white lists for incoming calls on a user.

    Please see the Introduction chapter for some usage instructions.

     

    ' FileOpen iomode Values
    Const fsoForReading           = 1     ' Open a file for reading only.
    Const fsoForWriting           = 2     ' Open a file for writing only.
    Const fsoForAppending         = 8     ' Open a file and write to the end of the file.
    Const fsoDontCreateIfNotExist = False
    Const fsoCreateIfNotExist     = True
    Const fsoTristateUseDefault   = -2    ' Opens the file by using the system default.
    Const fsoTristateTrue         = -1    ' Opens the file as Unicode.
    Const fsoTristateFalse        = 0     ' Opens the file as ASCII.
    
    
    '----------------------------------------------------------------
    ' CheckCallerInTextFile
    '
    ' Returns true if the current callers phone number can be found in a given text file.
    ' The text file must be formatted with one number per line.
    '
    ' Parameter:
    '   sFileName       text file (incl. path) that contains the numbers to check
    '
    ' Return:
    '   boolean
    '----------------------------------------------------------------
    Function CheckCallerInTextFile ( sFileName )
    
        PBXScript.OutputTrace "-----------> CheckCallerInTextFile (" & sFileName & ")"
    
        Dim bReturn, sCaller, sLine
        bReturn = False
    
        On Error Resume Next
    
        sCaller = PBXCall.CallingPartyNumber
        PBXScript.OutputTrace "sCaller = " & sCaller
    
        Dim fso, file
        Set fso = CreateObject("Scripting.FileSystemObject") 
        If fso.FileExists( sFileName ) Then
            
            Set file = fso.OpenTextFile(sFileName, fsoForReading, fsoDontCreateIfNotExist, fsoTristateFalse)
            If Err = 0 Then
    
                PBXScript.OutputTrace "File opened"
    
                Do While (Not file.AtEndOfStream) And (Not bReturn)
    
                    sLine = file.ReadLine
                    PBXScript.OutputTrace "sLine = " & sLine
    
                    ' does the number in the text file contain the given number?
                    If InStr(sLine, sCaller) > 0 Then 
                        bReturn = True
                        PBXScript.OutputTrace "Found!"
                    End If
    
                    ' does the number in the text file is identical to the given number?
                    'If sLine = sCaller Then 
                    '    bReturn = True
                    '    PBXScript.OutputTrace "Found!"
                    'End If
    
                Loop
    
                file.Close
    
            Else
                PBXScript.OutputTrace "Error opening file!"
                PBXScript.OutputTrace Hex(Err) &  ": " & Err.Description
            End If
    
            Set file = Nothing 
    
        Else
            PBXScript.OutputTrace "File does not exist!"
        End If
    
        Set fso = Nothing
        
        CheckCallerInTextFile = bReturn
    
        PBXScript.OutputTrace "bReturn = " & bReturn
        PBXScript.OutputTrace "<----------- CheckCallerInTextFile"
    
    End Function

     

    This function makes use of the Server Script API functions PBXCall.CallingPartyNumber to get the callers number and PBXScript.OutputTrace to write trace information into the SwyxServer trace file.

     

    You need to make sure, that the file can be accessed from the call routing script. For this it is necessary, that the Windows users the Swyx Server service is running under (usually SwyxServiceAccount) has at least read privileges on the file.

     

    The function was originally posted into this forum topic.

     

     


    Tom Wellige
     Share


     Share




    User Feedback

    Recommended Comments

    "InStr(sLine, sCaller)" has to be changed to "InStr(sCaller, sLine)" if the blacklisted number should be a part of the caller number. I think this is the way it was meant to be.

    Link to comment
    Share on other sites


    My idea was that it is checked, if the caller number is part of the black listed number. For that logic the order of the both parameters is correct.

     

    If you reverse the logic (is black listed number part of caller number) you need to reverse the parameters of course.

     

    With the reversed order it is actually possible to search for "parts of numbers" in the black list. So it would be possible to easily exclude complete DDI ranges.

     

    Link to comment
    Share on other sites




    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and have taken note of our Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.