1
1
using Cantarus . Modules . PolyDeploy . Components ;
2
2
using Cantarus . Modules . PolyDeploy . DataAccess . Models ;
3
+ using DotNetNuke . Services . Log . EventLog ;
3
4
using System ;
4
- using System . Collections ;
5
- using System . Collections . Generic ;
6
5
using System . Linq ;
7
6
using System . Net ;
8
7
using System . Net . Http ;
9
- using System . Web ;
10
8
using System . Web . Http . Controllers ;
11
9
using System . Web . Http . Filters ;
12
10
@@ -21,13 +19,15 @@ public override void OnActionExecuting(HttpActionContext actionContext)
21
19
bool authenticated = false ;
22
20
string message = "Access denied." ;
23
21
22
+ string apiKey = null ;
23
+
24
24
try
25
25
{
26
26
// Is there an api key header present?
27
27
if ( actionContext . Request . Headers . Contains ( "x-api-key" ) )
28
28
{
29
29
// Get the api key from the header.
30
- string apiKey = actionContext . Request . Headers . GetValues ( "x-api-key" ) . FirstOrDefault ( ) ;
30
+ apiKey = actionContext . Request . Headers . GetValues ( "x-api-key" ) . FirstOrDefault ( ) ;
31
31
32
32
// Make sure it's not null and it's 32 characters or we're wasting our time.
33
33
if ( apiKey != null && apiKey . Length == 32 )
@@ -55,6 +55,12 @@ public override void OnActionExecuting(HttpActionContext actionContext)
55
55
// If authentication failure occurs, return a response without carrying on executing actions.
56
56
if ( ! authenticated )
57
57
{
58
+ EventLogController elc = new EventLogController ( ) ;
59
+
60
+ string log = string . Format ( "(APIKey: {1}) {2}" , apiKey , message ) ;
61
+
62
+ elc . AddLog ( "PolyDeploy" , log , EventLogController . EventLogType . HOST_ALERT ) ;
63
+
58
64
actionContext . Response = actionContext . Request . CreateErrorResponse ( HttpStatusCode . Forbidden , message ) ;
59
65
}
60
66
}
0 commit comments