[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openser-devel
Subject:    [sr-dev] git:master:ca49dc03: misc/examples/kemi: updated lua script to use dedicated functions
From:       Daniel-Constantin Mierla <miconda () gmail ! com>
Date:       2019-07-31 10:43:37
Message-ID: E1hsm53-0001Gy-32 () www ! kamailio ! org
[Download RAW message or body]

Module: kamailio
Branch: master
Commit: ca49dc0344f2ca4eae1999f6b46e0ab8c30bd1a3
URL: https://github.com/kamailio/kamailio/commit/ca49dc0344f2ca4eae1999f6b46e0ab8c30bd1a3


Author: Daniel-Constantin Mierla <miconda@gmail.com>
Committer: Daniel-Constantin Mierla <miconda@gmail.com>
Date: 2019-07-31T12:42:23+02:00

misc/examples/kemi: updated lua script to use dedicated functions

- replaced fetch of variables with dedicated functions for flood
detection

---

Modified: misc/examples/kemi/kamailio-basic-kemi-lua.lua

---

Diff:  https://github.com/kamailio/kamailio/commit/ca49dc0344f2ca4eae1999f6b46e0ab8c30bd1a3.diff
                
Patch: https://github.com/kamailio/kamailio/commit/ca49dc0344f2ca4eae1999f6b46e0ab8c30bd1a3.patch


---

diff --git a/misc/examples/kemi/kamailio-basic-kemi-lua.lua \
b/misc/examples/kemi/kamailio-basic-kemi-lua.lua index 4ae0b0e6ab..b6544c7d4e 100644
--- a/misc/examples/kemi/kamailio-basic-kemi-lua.lua
+++ b/misc/examples/kemi/kamailio-basic-kemi-lua.lua
@@ -118,24 +118,25 @@ end
 
 -- Per SIP request initial checks
 function ksr_route_reqinit()
-	if not KSR.is_myself(KSR.pv.get("$si")) then
-		if not KSR.pv.is_null("$sht(ipban=>$si)") then
+	if not KSR.is_myself_srcip() then
+		local srcip = KSR.kx.get_srcip();
+		if KSR.htable.sht_match_name("ipban", "eq", srcip) > 0 then
 			-- ip is already blocked
 			KSR.dbg("request from blocked IP - " .. KSR.pv.get("$rm")
-					.. " from " .. KSR.pv.get("$fu") .. " (IP:"
-					.. KSR.pv.get("$si") .. ":" .. KSR.pv.get("$sp") .. ")\n");
+					.. " from " .. KSR.kx.gete_furi() .. " (IP:"
+					.. srcip .. ":" .. KSR.kx.get_srcport() .. ")\n");
 			KSR.x.exit();
 		end
-		if KSR.pike.pike_check_req()<0 then
+		if KSR.pike.pike_check_req() < 0 then
 			KSR.err("ALERT: pike blocking " .. KSR.pv.get("$rm")
-					.. " from " .. KSR.pv.get("$fu") .. " (IP:"
-					.. KSR.pv.get("$si") .. ":" .. KSR.pv.get("$sp") .. ")\n");
-			KSR.pv.seti("$sht(ipban=>$si)", 1);
+					.. " from " .. KSR.kx.gete_furi() .. " (IP:"
+					.. srcip .. ":" .. KSR.kx.get_srcport() .. ")\n");
+			KSR.htable.sht_seti("ipban", srcip, 1);
 			KSR.x.exit();
 		end
 	end
 	if KSR.corex.has_user_agent() > 0 then
-		local ua = KSR.pv.gete("$ua");
+		local ua = KSR.kx.gete_ua();
 		if string.find(ua, "friendly-scanner")
 				or string.find(ua, "sipcli") then
 			KSR.sl.sl_send_reply(200, "OK");
@@ -157,7 +158,7 @@ function ksr_route_reqinit()
 
 	if KSR.sanity.sanity_check(1511, 7)<0 then
 		KSR.err("Malformed SIP message from "
-				.. KSR.pv.get("$si") .. ":" .. KSR.pv.get("$sp") .."\n");
+				.. KSR.kx.get_srcip() .. ":" .. KSR.kx.get_srcport() .."\n");
 		KSR.x.exit();
 	end
 


_______________________________________________
Kamailio (SER) - Development Mailing List
sr-dev@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic