Skip to content

Commit 3adb0a2

Browse files
authored
Merge pull request #88 from intersystems-community/updateAnalytics
check ip
2 parents beb44ef + 9767a5c commit 3adb0a2

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

src/cls/ZPM/REST/Base.cls

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,44 @@ Parameter HandleCorsRequest = 1;
99

1010
Parameter PAGESIZE As INTEGER = 20;
1111

12+
Parameter HTTP451LEGAL = "451 Unavailable For Legal Reasons";
13+
1214
ClassMethod OnPreDispatch(pUrl As %String, pMethod As %String, ByRef pContinue As %Boolean) As %Status
1315
{
14-
SET tSC = $$$OK
15-
TRY {
16-
16+
Set tSC = $$$OK
17+
Try {
1718
// Set the return type according to the Accept type in the request. Default is application/json.
18-
IF ('..AcceptsContentType(..#CONTENTTYPEJSON)) {
19-
SET tSC = ..ReportHttpStatusCode(..#HTTP406NOTACCEPTABLE), pContinue=0
20-
QUIT
21-
} ELSE {
19+
If ('..AcceptsContentType(..#CONTENTTYPEJSON)) {
20+
Set tSC = ..ReportHttpStatusCode(..#HTTP406NOTACCEPTABLE)
21+
Set pContinue = 0
22+
Quit
23+
} Else {
2224
// This always returns json
23-
SET %response.ContentType=..#CONTENTTYPEJSON
24-
}
25-
26-
27-
// read request object into %DynamicObject format
28-
IF ((pMethod'="POST") && (pMethod'="PUT")) || (%request.Content="") {
29-
SET %request.Content = {}
30-
} ELSE {
31-
IF ($IsObject(%request.Content))&&('%request.Content.Size) {
32-
SET %request.Content = {}
33-
} ELSE {
34-
SET %request.Content = ##class(%Library.DynamicObject).%FromJSON(%request.Content)
35-
}
25+
Set %response.ContentType=..#CONTENTTYPEJSON
3626
}
27+
28+
If (##class(%Dictionary.CompiledClass).%ExistsId("ZPM.Analytics.IP")) {
29+
If ('##class(ZPM.Analytics.IP).ValidateIP(..GetRemoteAddr())) {
30+
Set tSC = ..ReportHttpStatusCode(..#HTTP451LEGAL)
31+
Set pContinue = 0
32+
Quit
33+
}
34+
}
3735

38-
} CATCH ex {
39-
SET tSC = ex.AsStatus()
36+
// read request object into %DynamicObject format
37+
If ((pMethod'="POST") && (pMethod'="PUT")) || (%request.Content="") {
38+
Set %request.Content = {}
39+
} Else {
40+
If ($IsObject(%request.Content))&&('%request.Content.Size) {
41+
Set %request.Content = {}
42+
} Else {
43+
Set %request.Content = ##class(%Library.DynamicObject).%FromJSON(%request.Content)
44+
}
45+
}
46+
} Catch ex {
47+
Set tSC = ex.AsStatus()
4048
}
41-
QUIT ##class(%iKnow.REST.Base).%ErrorHandler(tSC, .pContinue)
49+
Quit ##class(%iKnow.REST.Base).%ErrorHandler(tSC, .pContinue)
4250
}
4351

4452
ClassMethod %ProcessResult(pStatus As %Status = {$$$OK}, pResult As %DynamicObject = "") As %Status [ Internal ]

0 commit comments

Comments
 (0)