-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathRedirectorInfoPage.cs
More file actions
49 lines (41 loc) · 1.66 KB
/
RedirectorInfoPage.cs
File metadata and controls
49 lines (41 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Specialized;
using System.Text.RegularExpressions;
namespace WebOne
{
/// <summary>
/// Redirection helper page
/// </summary>
class RedirectorInfoPage : InfoPage
{
public RedirectorInfoPage(NameValueCollection Parameters)
{
//Example & test:
//http://localhost:8080/!redirect/?RegExMask=\/RU=%28.*%29\/\/&RegExGroup=1&OriginalString=AwrhcftREsRo7AEAg.pXNyoA;_ylu=Y29sbwNiZjEEcG9zAzcEdnRpZAMEc2VjA3Ny/RV=2/RE=1758889809/RO=10/RU=http%3a%2f%2fwebsite-archive.mozilla.org%2fwww.mozilla.org%2ffirefox_releasenotes%2fen-us%2ffirefox%2f3.6%2freleasenotes%2f/RK=2/RS=9jn9Jo0P97wE2EovYeBZ1409Va0-
this.Title = "WebOne: Redirection";
this.Header = "Redirection";
string UrlMask = Parameters["RegExMask"];
int UrlMaskGroup = 0;
int.TryParse(Parameters["RegExGroup"], out UrlMaskGroup);
try
{
if (string.IsNullOrWhiteSpace(UrlMask)) throw new Exception("RegExMask is empty.");
if (string.IsNullOrWhiteSpace(Parameters["OriginalString"])) throw new Exception("OriginalString is empty.");
Match m = Regex.Match(Parameters["OriginalString"], UrlMask);
if (UrlMaskGroup > m.Groups.Count) throw new Exception("RegExGroup is more than " + m.Groups.Count + ".");
if (UrlMaskGroup < 0) throw new Exception("RegExGroup is incorrect.");
if (m.Success)
{
string Url = m.Groups[UrlMaskGroup].Value;
this.Content = "<p>It will be better to open <a href='" + Url + "'>" + Url + "</a> instead of this stub.</p>";
this.HttpStatusCode = 302;
this.HttpHeaders.Add("Location", Url);
}
}
catch (Exception e)
{
this.Content += "<p><b>Error: " + e.Message + "</b></p>";
}
}
}
}