Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
CheckEndpoint.cs
1using System;
3using System.Threading.Tasks;
4using System.Xml;
5using Waher.Content;
9using Waher.Script;
12
14{
19 {
24 : base("Intelligence/CheckEndpoint",
25 new KeyValuePair<Type, Expression>(typeof(Dictionary<string, object>), new Expression(jsonPattern)),
26 new KeyValuePair<Type, Expression>(typeof(XmlDocument), new Expression(xmlPattern)))
27 {
28 }
29
33 public static LoginAuditor TestAuditor { get; set; }
34
35 private static readonly string jsonPattern = Resources.LoadResourceAsText(typeof(CheckEndpoint).Namespace + ".JSON.CheckEndpoint.req");
36 private static readonly string xmlPattern = Resources.LoadResourceAsText(typeof(CheckEndpoint).Namespace + ".XML.CheckEndpoint.req");
37
46 public override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary<string, IElement> Parameters)
47 {
49
50 LoginAuditor Auditor = Gateway.LoginAuditor ?? TestAuditor
51 ?? throw new ServiceUnavailableException("Login Auditor not enabled.");
52
53 string Endpoint = (string)Parameters["PEndpoint"].AssociatedObjectValue;
56 {
57 { "endpoint", RemoteEndpoint?.Endpoint ?? Endpoint }
58 };
59
60 if (!(RemoteEndpoint is null))
61 {
62 bool AddMetaInfo = false;
64 {
65 { "created", RemoteEndpoint.Created },
66 { "lastProtocol", RemoteEndpoint.LastProtocol },
67 { "lastFailed", RemoteEndpoint.LastFailed },
68 { "domain", RemoteEndpoint.Domain?.Value ?? string.Empty }
69 };
70 Result["EndpointInfo"] = EndpointInfo;
71
73 {
74 EndpointInfo["permanentBlock"] = true;
75 AddMetaInfo = true;
76 }
78 {
79 DateTime? Next = Auditor.GetEarliestLoginOpportunity(RemoteEndpoint);
80
81 if (Next.HasValue)
82 {
83 if (Next.Value == DateTime.MaxValue)
84 EndpointInfo["permanentBlock"] = true;
85 else
86 EndpointInfo["temporaryBlock"] = Next.Value;
87
88 AddMetaInfo = true;
89 }
90 }
91
92 if (AddMetaInfo)
93 {
94 EndpointInfo["reason"] = RemoteEndpoint.Reason;
95 EndpointInfo["whois"] = RemoteEndpoint.WhoIs;
96 EndpointInfo["city"] = RemoteEndpoint.City;
97 EndpointInfo["region"] = RemoteEndpoint.Region;
98 EndpointInfo["country"] = RemoteEndpoint.Country;
99 EndpointInfo["countryCode"] = RemoteEndpoint.Code;
100 EndpointInfo["flag"] = RemoteEndpoint.Flag;
101 }
102 }
103
104 await Response.Return(Result);
105 }
106 }
107}
A Named dictionary is a dictionary, with a local name and a namespace. Use it to return content that ...
Represents an HTTP request.
Definition: HttpRequest.cs:22
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:23
Task Return(Exception ex)
Returns an error to the client.
The server is currently unable to handle the request due to a temporary overloading or maintenance of...
Static class managing loading of resources stored as embedded resources or in content files.
Definition: Resources.cs:13
static string LoadResourceAsText(string ResourceName)
Loads a text resource from an embedded resource.
Definition: Resources.cs:55
Class managing a script expression.
Definition: Expression.cs:41
Class that monitors login events, and help applications determine malicious intent....
Definition: LoginAuditor.cs:26
async Task< DateTime?> GetEarliestLoginOpportunity(string RemoteEndPoint, string Protocol)
Checks when a remote endpoint can login.
Task< RemoteEndpoint > GetAnnotatedStateObject(string RemoteEndPoint)
Gets an annotated Remote endpoint state object, if one is available.
Login state information relating to a remote endpoint
bool Blocked
If endpoint is blocked or not.
string Region
Region related to the endpoint.
string Endpoint
String-representation of remote endpoint.
string WhoIs
WHOIS information about the remote endpoint.
string Country
Country related to the endpoint.
bool LastFailed
Checks if last login attempt was a failed login attempt.
string Code
Country Code related to the endpoint.
CaseInsensitiveString Domain
Domain where record originated.
string Flag
Flag related to the endpoint.
string Reason
Reason for blocking the endpoint.
string City
City related to the endpoint.
Abstract base class for agent resources supporting the POST method.
static AccountUser AssertUserAuthenticated(HttpRequest Request)
Makes sure the request is made by an authenticated API user.
const string AgentNamespace
https://waher.se/Schema/BrokerAgent.xsd
static LoginAuditor TestAuditor
Login Auditor used for testing, if Gateway.LoginAuditor is not set.
override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary< string, IElement > Parameters)
Executes the POST method on the resource.