Skip to content

Instantly share code, notes, and snippets.

@os11k
Created November 19, 2021 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save os11k/17258d1d81f4f706b6496f8799a9471a to your computer and use it in GitHub Desktop.
Save os11k/17258d1d81f4f706b6496f8799a9471a to your computer and use it in GitHub Desktop.
Homer7 Lua script to change body of header user-agent in CANCEL method
-- With this Lua code we will substitute body of header "User-Agent" to cisco, if there are more then one User-Agent headers, then we will fix them all.
-- Just add this to your docker compose part for heplify-server:
-- volumes:
-- - ./lua:/lua
-- put your script in ./lua directory and restart docker-container
-- this function will be executed first
function checkRAW()
local protoType = GetHEPProtoType()
-- Check if we have SIP type
if protoType ~= 1 then
return
end
-- original SIP message Payload
local raw = GetRawMessage()
-- https://www.lua.org/pil/20.html
local method = string.sub(raw, 1, 6)
if method == "CANCEL" then
-- https://www.lua.org/pil/20.2.html
-- https://www.ibm.com/docs/sr/ias?topic=manipulation-stringgsub-s-pattern-repl-n
local ripe, count = string.gsub(raw, "(User%-Agent:)(.-)(\n+)", "%1 cisco%3")
if count > 0 then
Logp("ERROR", "ripe", ripe)
SetRawMessage(ripe)
end
end
return
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment