2using System.Collections.Generic;
5using System.Threading.Tasks;
21 internal static string whiteListKey =
null;
29 : base(
"/RequestWhiteList")
61 !Expires.StartsWith(
"P") ||
62 !
long.TryParse(Expires.Substring(1), out
long Ticks))
65 new KeyValuePair<string, object>(
"URL", Request.
Header.
GetURL(
true)));
70 StringBuilder sb =
new StringBuilder();
77 if (whiteListKey is
null)
80 if (
string.IsNullOrEmpty(Key))
90 Encoding.UTF8.GetBytes(sb.ToString())),
true) != 0)
92 Log.
Warning(
"White-list request link MAC not valid.", Receiver, Sender,
93 new KeyValuePair<string, object>(
"Sender", Sender),
94 new KeyValuePair<string, object>(
"Receiver", Receiver),
95 new KeyValuePair<string, object>(
"Expires", Ticks),
96 new KeyValuePair<string, object>(
"MAC", MAC));
101 StringBuilder Markdown =
new StringBuilder();
103 Markdown.AppendLine(
"Title: Requesting White-Listing");
104 Markdown.AppendLine(
"Description: Page allows mail-users to request white-listing.");
105 Markdown.AppendLine(
"Author: Peter Waher");
106 Markdown.AppendLine(
"Copyright: Copyright.md");
107 Markdown.AppendLine(
"Master: Master.md");
108 Markdown.AppendLine();
109 Markdown.AppendLine(
"=========");
110 Markdown.AppendLine();
111 Markdown.AppendLine(
"Approval request");
112 Markdown.AppendLine(
"=========================");
113 Markdown.AppendLine();
115 if (Ticks < DateTime.Now.Ticks)
117 Log.
Notice(
"White-list request link old.", Receiver, Sender,
118 new KeyValuePair<string, object>(
"Sender", Sender),
119 new KeyValuePair<string, object>(
"Receiver", Receiver),
120 new KeyValuePair<string, object>(
"Expires", Expires),
121 new KeyValuePair<string, object>(
"MAC", MAC));
123 Markdown.AppendLine(
"The request link is no longer valid.");
127 await this.xmppServer.Presence(
"subscribe",
string.Empty,
new XmppAddress(Receiver),
new XmppAddress(Sender),
string.Empty,
string.Empty, this.xmppServer);
129 StringBuilder Markdown2 =
new StringBuilder();
131 Markdown2.AppendLine(
"Request sent");
132 Markdown2.AppendLine(
"==============");
133 Markdown2.AppendLine();
135 Markdown2.Append(
"A request has been sent to **");
137 Markdown2.Append(
"** to approve messages from **");
139 Markdown2.AppendLine(
"**. You will be notified when an response to the request is provided.");
141 await this.xmppServer.SendMailMessage(Receiver, Sender,
"White-listing request sent", Markdown2.ToString());
143 Log.
Notice(
"White-listing request mail sent.", Sender, Receiver);
145 Markdown.Append(
"A request has been sent to `");
146 Markdown.Append(Receiver);
147 Markdown.Append(
"` to approve that e - mail messages from `");
148 Markdown.Append(Sender);
149 Markdown.AppendLine(
"` be forwarded. You will be notified by e-mail when a response is available.");
154 Settings.RootFolder = Root;
157 Path.Combine(Settings.
RootFolder,
"RequestWhiteList.md"),
string.Empty,
162 await Response.
Write(Html);
const string DefaultContentType
Default Content-Type for HTML: text/html
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 ...
async Task< string > GenerateHTML()
Generates HTML from the markdown text.
static Task< MarkdownDocument > CreateAsync(string MarkdownText, params Type[] TransparentExceptionTypes)
Contains a markdown document. This markdown document class supports original markdown,...
Contains settings that the Markdown parser uses to customize its behavior.
string RootFolder
File system root folder. If file references are absolute, and this property is provided,...
Static class managing the application event log. Applications and services log events on this static ...
static void Warning(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs a warning event.
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...
Represents an HTTP request.
HttpRequestHeader Header
Request header.
string RemoteEndPoint
Remote end-point.
string ResourceName
Name of resource.
Represets a response of an HTTP client request.
async Task Write(byte[] Data)
Returns binary data in the response.
Base class for all synchronous HTTP resources. A synchronous resource responds within the method hand...
Web resource for requesting white-list authentication of a client.
override bool UserSessions
If user sessions are required
bool AllowsGET
If GET is allowed
RequestWhiteList(XmppServer XmppServer)
Web resource for requesting white-list authentication of a client.
override bool HandlesSubPaths
If subpaths are handled
async Task GET(HttpRequest Request, HttpResponse Response)
HTTP GET method is called.
Contains information about one XMPP address.
static byte[] GetRandomNumbers(int NrBytes)
Generates a set of random numbers.
Static class that dynamically manages types and interfaces available in the runtime environment.
static bool TryGetModuleParameter(string Name, out object Value)
Tries to get a module parameter value.
Static class managing persistent settings.
static bool Set(string Key, string Value)
Sets a string-valued setting.
static async Task< string > GetAsync(string Key, string DefaultValue)
Gets a string-valued setting.
Contains methods for simple hash calculations.
static string ComputeHMACSHA256HashString(byte[] Key, byte[] Data)
Computes the HMAC-SHA-256 hash of a block of binary data.
GET Interface for HTTP resources.