Jump to content
  • CheckCallerInTextFile()

    CheckCallerInTextFile()

    Lua   → VBScript

     

    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.

     

    Please note: the Lua Beta Testing versions of SwyxWare (13.1x) do not limit any file access. In the final release version file access will only be permitted in the SwyxWare CPE (customer premise equipment) version. Within the cloud versions (SDC and SwyxON) file access will not be permitted.

     

     

    ------------------------------------------------------------------
    -- 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
    --                  backslashes in the filename need to get escaped, i.e. C:\\Files\\List.txt
    --
    -- Return:
    --   boolean        true - number in file, false - number not in file or can't access file
    ------------------------------------------------------------------
    function CheckCallerInTextFile ( sFileName )
        PBXScript.OutputTrace ("-----------> CheckCallerInTextFile ( " .. sFileName .. " )")
    
        local bReturn = false
        local sCaller = PBXCall.CallingPartyNumber()
        PBXScript.OutputTrace ("sCaller = " .. sCaller)
    
        local oFile = io.open(sFileName, "r") -- read-only
        if oFile then
            io.input(oFile)
            for sLine in io.lines() do
    
                PBXScript.OutputTrace ("sLine = " .. sLine)
    
                -- does the number in the text file contain the given number?
                if IsInString(sCaller, sLine) then 
                    PBXScript.OutputTrace ("Found caller in file")
                    bReturn = true 
                end
    
                -- does the number in the text file is identical to the given number?
                --if (sCaller == sLine) then
                --    PBXScript.OutputTrace ("Found caller in file")
                --    bReturn = true 
                --end
    
            end
            oFile:close()
        else
            PBXScript.OutputTrace ("Can't open file!")
        end
        
        PBXScript.OutputTrace ("bReturn = " .. tostring(bReturn))
        PBXScript.OutputTrace ("<----------- CheckCallerInTextFile")
    
        return bReturn
    end

     

    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. It also uses the GSE build-in helper function IsInString() to find the caller number in the data from the 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.

     

    Please note, that you have to escape backslashes in the sFileName parameter. So instead of "C:\Files\List.txt" you have to pass "C:\\Files\\List.txt".

     

    The function was originally posted into this forum topic.

     

     


    Tom Wellige
     Share


     Share




    User Feedback

    Recommended Comments

    There are no comments to display.



    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.