Browse Source

Merge branch 'Docker' into Docker_msg

Robert 1 year ago
parent
commit
8cdf6557f8

+ 1 - 1
EVCB_OCPP.WSServer/Message/CoreProfileHandler.cs

@@ -1301,7 +1301,7 @@ internal partial class ProfileHandler
 										#region 提供給PHA 過CDFA認證 使用
 										if (tx.CustomerId == Guid.Parse("10C7F5BD-C89A-4E2A-8611-B617E0B41A73"))
 										{
-											var mail_response = httpClient.PostFormDataAsync("https://evcb.zerovatech.com/CDFA/" + tx.Id, new Dictionary<string, string>()
+											var mail_response = httpClient.PostFormDataAsync("https://charge.zerovatech.com/CDFA/" + tx.Id, new Dictionary<string, string>()
 											{
 												{ "email","2"},
 												{ "to","wonderj@phihongusa.com;jessica_tseng@phihong.com.tw"}

+ 1 - 0
EVCB_OCPP.WSServer/Service/HeaderRecordService.cs

@@ -55,6 +55,7 @@ namespace HeaderRecord
         internal void LogResponse(string traceIdentifier, HttpResponse response)
         {
             logger.LogInformation("LogResponse============================================================");
+            logger.LogInformation("{id} {key} {value}", traceIdentifier, "statuscode", response.StatusCode);
             foreach (var headerKey in response.Headers.Keys)
             {
                 logger.LogInformation("{id} {key} {value}", traceIdentifier, headerKey, response.Headers[headerKey]);

+ 1 - 1
EVCB_OCPP.WSServer/Service/MapApiServce.cs

@@ -131,7 +131,7 @@ public static class MapApiServceExtention
         routeHandlerBuilder.AddEndpointFilter(async (context, next) =>
         {
             string key = context.HttpContext.Request.Headers["key"];
-            if (!string.IsNullOrEmpty(key) &&
+            if (!string.IsNullOrEmpty(pass) &&
                 key != pass)
             {
                 return Results.BadRequest();

+ 10 - 5
EVCB_OCPP.WSServer/Service/WsService/OcppWebsocketService.cs

@@ -157,8 +157,8 @@ public class OcppWebsocketService : WebsocketService<WsClientData>
 
         if (!isExistedSN)
         {
+            logger.LogTrace("{id} {func} not found", context.TraceIdentifier, nameof(ValidateHandshake));
             context.Response.StatusCode = StatusCodes.Status404NotFound;
-            logger.LogTrace("{id} {func} {Statuscode}", context.TraceIdentifier, nameof(ValidateHandshake), context.Response.StatusCode);
             return false;
         }
 
@@ -183,10 +183,15 @@ public class OcppWebsocketService : WebsocketService<WsClientData>
             securityProfile = 0;
         }
 
+        if (securityProfile == 0)
+        {
+            authorizated = true;
+        }
+
         if (securityProfile == 3 && session.UriScheme == "ws")
         {
+            logger.LogTrace("{id} {func} {securityProfile} auth failed", context.TraceIdentifier, nameof(ValidateHandshake), securityProfile);
             context.Response.StatusCode = StatusCodes.Status401Unauthorized;
-            logger.LogTrace("{id} {func} {Statuscode}", context.TraceIdentifier, nameof(ValidateHandshake), context.Response.StatusCode);
             return false;
         }
 
@@ -194,16 +199,16 @@ public class OcppWebsocketService : WebsocketService<WsClientData>
         {
             if (securityProfile == 2 && session.UriScheme == "ws")
             {
+                logger.LogTrace("{id} {func} {securityProfile} auth failed", context.TraceIdentifier, nameof(ValidateHandshake), securityProfile);
                 context.Response.StatusCode = StatusCodes.Status401Unauthorized;
-                logger.LogTrace("{id} {func} {Statuscode}", context.TraceIdentifier, nameof(ValidateHandshake), context.Response.StatusCode);
                 return false;
             }
 
             //if (session.Items.ContainsKey("Authorization") || session.Items.ContainsKey("authorization"))
             if (string.IsNullOrEmpty(authHeader))
             {
+                logger.LogTrace("{id} {func} {securityProfile} auth failed", context.TraceIdentifier, nameof(ValidateHandshake), securityProfile);
                 context.Response.StatusCode = StatusCodes.Status401Unauthorized;
-                logger.LogTrace("{id} {func} {Statuscode}", context.TraceIdentifier, nameof(ValidateHandshake), context.Response.StatusCode);
                 return false;
             }
             //authorizationKey = db.MachineConfigurations.Where(x => x.ChargeBoxId == session.ChargeBoxId && x.ConfigureName == StandardConfiguration.AuthorizationKey)
@@ -235,8 +240,8 @@ public class OcppWebsocketService : WebsocketService<WsClientData>
 
             if (!authorizated)
             {
+                logger.LogTrace("{id} {func} {securityProfile} auth failed", context.TraceIdentifier, nameof(ValidateHandshake), securityProfile);
                 context.Response.StatusCode = StatusCodes.Status401Unauthorized;
-                logger.LogTrace("{id} {func} {Statuscode}", context.TraceIdentifier, nameof(ValidateHandshake), context.Response.StatusCode);
                 return false;
             }
         }

+ 28 - 3
EVCB_OCPP.WSServer/Service/WsService/WebsocketService.cs

@@ -1,6 +1,7 @@
 using Microsoft.AspNetCore.Http;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Logging;
+using System.Data.Entity.Core.Common.EntitySql;
 using System.Net;
 using System.Net.Http;
 using System.Net.WebSockets;
@@ -75,9 +76,33 @@ public class WebsocketService<T> where T : WsSession
 
         try
         {
-            var ipaddress = context.Connection.RemoteIpAddress;
-            var port = context.Connection.RemotePort;
-            data.Endpoint = new IPEndPoint(ipaddress, port);
+            var proxyPassClientIp = context.Request.Headers["X-Forwarded-For"];
+            foreach (var infoString in proxyPassClientIp)
+            {
+                foreach (var testIp in infoString.Split(','))
+                {
+                    logger.LogDebug("X-Forwarded-For {ip}", testIp);
+                    if (IPEndPoint.TryParse(testIp, out var parseResult) &&
+                        (parseResult.AddressFamily is System.Net.Sockets.AddressFamily.InterNetwork or System.Net.Sockets.AddressFamily.InterNetworkV6)
+                        )
+                    {
+                        data.Endpoint = parseResult;
+                        break;
+                    }
+                }
+
+                if (data.Endpoint != null)
+                {
+                    break;
+                }
+            }
+
+            if (data.Endpoint is null)
+            {
+                var ipaddress = context.Connection.RemoteIpAddress;
+                var port = context.Connection.RemotePort;
+                data.Endpoint = new IPEndPoint(ipaddress, port);
+            }
         }
         catch
         {

+ 1 - 1
version.txt

@@ -1 +1 @@
-Docker_v1.1.13
+Docker_v1.1.16