5using System.Threading.Tasks;
22 public override bool HandlesSubPaths =>
false;
23 public override bool UserSessions =>
true;
35 if (Content.
HasError || !(Content.
Decoded is Dictionary<string, string> Form))
45 string RecaptchaResponse;
48 if (!Form.ContainsKey(
"Name") ||
string.IsNullOrEmpty(Name = Form[
"Name"]?.Trim()))
54 if (!Form.ContainsKey(
"EMail") ||
string.IsNullOrEmpty(EMail = Form[
"EMail"]?.Trim()))
60 if (!Form.ContainsKey(
"Reason") ||
string.IsNullOrEmpty(Reason = Form[
"Reason"]?.Trim()))
66 if (!Form.ContainsKey(
"Text") ||
string.IsNullOrEmpty(Text = Form[
"Text"]?.Trim()))
72 if (!Form.ContainsKey(
"g-recaptcha-response") ||
string.IsNullOrEmpty(RecaptchaResponse = Form[
"g-recaptcha-response"]))
78 if (!Form.ContainsKey(
"ResponseDesired"))
79 ResponseDesired =
false;
89 new KeyValuePair<string, object>(
"Name", Name),
90 new KeyValuePair<string, object>(
"EMail", EMail),
91 new KeyValuePair<string, object>(
"Reason", Reason),
92 new KeyValuePair<string, object>(
"Text", Text),
93 new KeyValuePair<string, object>(
"ResponseDesired", ResponseDesired),
94 new KeyValuePair<string, object>(
"RemoteEndPoint", Request.
RemoteEndPoint));
96 Dictionary<string, object>
Feedback =
new Dictionary<string, object>();
97 foreach (KeyValuePair<string, object> P
in Tags)
102 StringBuilder Markdown =
new StringBuilder();
103 DateTime Now = DateTime.Now;
105 Markdown.AppendLine(
"Feedback received.");
106 Markdown.AppendLine();
108 Markdown.AppendLine(
"| Feedback ||");
109 Markdown.AppendLine(
"|:------|:-------|");
111 Markdown.Append(
"| Name: | ");
113 Markdown.AppendLine(
" |");
115 Markdown.Append(
"| e-Mail: | <a href=\"mailto:");
116 Markdown.Append(EMail.Replace(
"\"",
"""));
117 Markdown.Append(
"\" target=\"_blank\">");
119 Markdown.AppendLine(
"</a> |");
121 Markdown.Append(
"| Reason: | ");
123 Markdown.AppendLine(
" |");
125 Markdown.Append(
"| Response desired: | ");
127 Markdown.Append(
":white_check_mark:");
129 Markdown.Append(
":negative_squared_cross_mark:");
130 Markdown.AppendLine(
" |");
134 Markdown.Append(
"| Date | ");
136 Markdown.AppendLine(
" |");
137 Markdown.Append(
"| Time | ");
139 Markdown.AppendLine(
" |");
141 Markdown.AppendLine();
142 Markdown.AppendLine();
143 Markdown.AppendLine(
"```");
144 Markdown.AppendLine(Text.Replace(
"```",
" ` ` ` "));
145 Markdown.AppendLine(
"```");
150 await IoTGateway.Gateway.SendNotification(Markdown.ToString());
166 public static async Task<bool>
SiteVerify(
string RecaptchaResponse,
string RemoteEndPoint)
168 using HttpClient WebClient =
new HttpClient();
169 Dictionary<string, string> VerificationForm =
new Dictionary<string, string>()
171 {
"secret",
"6LcHNh0UAAAAAI1DwveBT21M4IkSRc5i-QciPUvg" },
172 {
"response", RecaptchaResponse },
173 {
"remoteip", RemoteEndPoint }
176 HttpContent Content =
new FormUrlEncodedContent(VerificationForm);
177 HttpResponseMessage ResponseMsg = await WebClient.PostAsync(
"https://www.google.com/recaptcha/api/siteverify", Content);
178 if (!ResponseMsg.IsSuccessStatusCode)
181 string Json = await ResponseMsg.Content.ReadAsStringAsync();
183 return JSON.
Parse(Json) is Dictionary<string, object> Parsed &&
184 Parsed.ContainsKey(
"success") &&
185 Parsed[
"success"] is
bool Success &&
Helps with parsing of commong data types.
static bool TryParse(string s, out double Value)
Tries to decode a string encoded double.
Contains information about a response to a content request.
bool HasError
If an error occurred.
object Decoded
Decoded object.
Helps with common JSON-related tasks.
static object Parse(string Json)
Parses a JSON string.
Contains a markdown document. This markdown document class supports original markdown,...
static string Encode(string s)
Encodes all special characters in a string so that it can be included in a markdown document without ...
Static class managing the application event log. Applications and services log events on this static ...
static void Notice(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs a notice event.
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
The server understood the request, but is refusing to fulfill it. Authorization will not help and the...
Represents an HTTP request.
string RemoteEndPoint
Remote end-point.
bool HasData
If the request has data.
SessionVariables Session
Contains session states, if the resource requires sessions, or null otherwise.
async Task< ContentResponse > DecodeDataAsync()
Decodes data sent in request.
Represets a response of an HTTP client request.
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
Base class for all synchronous HTTP resources. A synchronous resource responds within the method hand...
The response to the request can be found under a different URI and SHOULD be retrieved using a GET me...
The server is currently unable to handle the request due to a temporary overloading or maintenance of...
Class that monitors login events, and help applications determine malicious intent....
static async Task< string > AppendWhoIsInfo(StringBuilder Markdown, string RemoteEndPoint)
Appends WHOIS information to a Markdown document.
static async Task< KeyValuePair< string, object >[]> Annotate(string RemoteEndPoint, params KeyValuePair< string, object >[] Tags)
Annotates a remote endpoint.
Provides the user with options to control notifications from the Broker.
static BrokerNotificationConfiguration Instance
Current instance of configuration.
bool FeedbackReceived
If a notification should be sent when feedback has been received.
async Task POST(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
static async Task< bool > SiteVerify(string RecaptchaResponse, string RemoteEndPoint)
Allows web pages and web services to verify that Google reCaptcha responses are valid.
bool AllowsPOST
If the POST method is allowed.
Service Module hosting the XMPP broker and its components.
static async Task AppendRemoteEndPointToTable(StringBuilder Markdown, string RemoteEndPoint)
Appends annotated information about a remote endpoint to a Markdown table.
POST Interface for HTTP resources.