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;
2using System.Collections.Generic;
3using System.Threading.Tasks;
4using System.Xml;
5using Waher.Content;
8using Waher.Script;
11
13{
18 {
23 : base("Intelligence/CheckEndpoint",
24 new KeyValuePair<Type, Expression>(typeof(Dictionary<string, object>), new Expression(jsonPattern)),
25 new KeyValuePair<Type, Expression>(typeof(XmlDocument), new Expression(xmlPattern)))
26 {
27 }
28
32 public static LoginAuditor TestAuditor { get; set; }
33
34 private static readonly string jsonPattern = Resources.LoadResourceAsText(typeof(CheckEndpoint).Namespace + ".JSON.CheckEndpoint.req");
35 private static readonly string xmlPattern = Resources.LoadResourceAsText(typeof(CheckEndpoint).Namespace + ".XML.CheckEndpoint.req");
36
45 public override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary<string, IElement> Parameters)
46 {
48
49 LoginAuditor Auditor = Gateway.LoginAuditor ?? TestAuditor
50 ?? throw new ServiceUnavailableException("Login Auditor not enabled.");
51
52 string Endpoint = (string)Parameters["PEndpoint"].AssociatedObjectValue;
55 {
56 { "endpoint", RemoteEndpoint?.Endpoint ?? Endpoint }
57 };
58
59 if (!(RemoteEndpoint is null))
60 {
61 bool AddMetaInfo = false;
63 {
64 { "created", RemoteEndpoint.Created },
65 { "lastProtocol", RemoteEndpoint.LastProtocol },
66 { "lastFailed", RemoteEndpoint.LastFailed },
67 { "domain", RemoteEndpoint.Domain?.Value ?? string.Empty }
68 };
69 Result["EndpointInfo"] = EndpointInfo;
70
72 {
73 EndpointInfo["permanentBlock"] = true;
74 AddMetaInfo = true;
75 }
77 {
79
80 if (Next.HasValue)
81 {
82 if (Next.Value == DateTime.MaxValue)
83 EndpointInfo["permanentBlock"] = true;
84 else
85 EndpointInfo["temporaryBlock"] = Next.Value;
86
87 AddMetaInfo = true;
88 }
89 }
90
91 if (AddMetaInfo)
92 {
93 EndpointInfo["reason"] = RemoteEndpoint.Reason;
94 EndpointInfo["whois"] = RemoteEndpoint.WhoIs;
95 EndpointInfo["city"] = RemoteEndpoint.City;
96 EndpointInfo["region"] = RemoteEndpoint.Region;
97 EndpointInfo["country"] = RemoteEndpoint.Country;
98 EndpointInfo["countryCode"] = RemoteEndpoint.Code;
99 EndpointInfo["flag"] = RemoteEndpoint.Flag;
100 }
101 }
102
103 await Response.Return(Result);
104 }
105 }
106}
A Named dictionary is a dictionary, with a local name and a namespace. Use it to return content that ...
Static class managing loading of resources stored as embedded resources or in content files.
Definition: Resources.cs:15
static string LoadResourceAsText(string ResourceName)
Loads a text resource from an embedded resource.
Definition: Resources.cs:96
Represents an HTTP request.
Definition: HttpRequest.cs:18
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:21
async Task Return(object Object)
Returns an object to the client. This method can only be called once per response,...
The server is currently unable to handle the request due to a temporary overloading or maintenance of...
Class managing a script expression.
Definition: Expression.cs:39
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.
int[] State
Current login state. Null represents no login attempts have been made, or last one successfull.
DateTime[] Timestamps
Timestamps of first attempt in each interval. Null represents no login attempts have been made,...
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.