Jump to content
Gold Sponsor: Data-Way IT-Consulting, Austria

  • 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.



    Guest
    Add a comment...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.