forked from khwsab/Documentum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanguage-selector.aspx
187 lines (163 loc) · 5.56 KB
/
language-selector.aspx
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Collections.Generic" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
//retrieve the base URL and host URL
string baseURL = getBaseURL();
string host = Request.ServerVariables["HTTP_HOST"].ToLower();
if (Request.IsSecureConnection)
{
host = "https://" + host;
}
else
{
host = "http://" + host;
}
//check fail conditions, should prevent XSS
if (baseURL == null || baseURL == "" || !baseURL.ToLower().StartsWith(host))
{
string referer = Request.Headers["referer"];
if ((referer == null && referer == ""))
{
Response.Redirect(referer);
}
else
{
Response.Redirect(Request.ApplicationPath);
}
}
string webappRoot = baseURL.Substring(baseURL.IndexOf(host) + host.Length + 1);
//remove the trailing slash for the webapp root so we can do the comparison with the filepath
if (webappRoot.EndsWith("/"))
{
webappRoot = webappRoot.Substring(0, webappRoot.Length - 1);
}
System.Collections.Generic.List<string> urls = getURLs();
//see if the current file path contains the webapp root if not append it to the filepath
string filePath = Server.MapPath(Request.ApplicationPath.ToLower());
if (!filePath.Contains(webappRoot))
{
if (filePath.EndsWith(@"\"))
{
filePath += webappRoot;
}
else
{
filePath += @"\" + webappRoot;
}
}
//add a slash on to the end
if (!filePath.EndsWith(@"\"))
{
filePath += @"\";
}
//loop through the potential urls
for (int i = 0; i < urls.Count; i++)
{
// if file for the url exists redirect
if (File.Exists(filePath + urls[i]))
{
Response.Redirect(baseURL + urls[i]);
}
}
Response.Redirect(baseURL);
}
protected string getBaseURL()
{
//current url
string baseURL = Request.Params["BASE_URL"];
string modifiedURL = "";
//language
string requestedLang = Request.Params["REQUESTED_LANG"];
string currentLang = Request.Params["CURRENT_LANG"];
//country
string requestedCountry = Request.Params["CURRENT_COUNTRY"];
string currentCountry = Request.Params["REQUESTED_COUNTRY"];
//if they are on the search page they should be sent to the home page of the requested site
if(Request.Params["CURRENT_PAGE"] != null && Request.Params["CURRENT_PAGE"].StartsWith("Search.aspx"))
{
currentLang = "Search";
if(requestedCountry != null && requestedCountry != "")
{
requestedLang = requestedCountry + "-" + requestedLang;
}
else
{
requestedLang = "IND-"+requestedLang;
}
}
if (currentLang != null && currentLang != "" && requestedLang != null && requestedLang != "" && (baseURL.Contains(currentLang) || baseURL.Contains(currentLang.ToLower())))
{
char[] splitchar = { '-' };
string [] splitURL= baseURL.Split(splitchar);
int count=0;
if(baseURL.Contains(currentLang))
splitURL[1]=splitURL[1].Replace(currentLang, requestedLang);
else if(baseURL.Contains(currentLang.ToLower()))
splitURL[1]=splitURL[1].Replace(currentLang.ToLower(), requestedLang);
for(count=0;count<=splitURL.Length-1;count++)
{
if(count==splitURL.Length-1)
{
modifiedURL=string.Concat(modifiedURL, splitURL[count]);
}
else
{
modifiedURL=string.Concat(string.Concat(modifiedURL, splitURL[count]),"-");
}
}
//baseURL = baseURL.Replace(currentLang, requestedLang);
baseURL=modifiedURL;
}
if (currentCountry != null && requestedCountry != null && currentCountry != "" && requestedCountry != "" && baseURL.Contains(currentCountry))
{
baseURL = baseURL.Replace(currentCountry, requestedCountry);
}
return baseURL;
}
protected List<string> getURLs()
{
List<string> urls = new List<string>();
if (Request.Params["CURRENT_PAGE"] != null && Request.Params["CURRENT_PAGE"] != "")
{
//if they are on the search page they should be sent to the home page of the requested site
if(Request.Params["CURRENT_PAGE"].StartsWith("Search.aspx"))
{
return urls;
}
urls.Add(Request.Params["CURRENT_PAGE"]);
}
int i = -1;
if (Request.Params["NUM_FALLBACKS"] != null && Request.Params["NUM_FALLBACKS"] != "")
{
try
{
i = int.Parse(Request.Params["NUM_FALLBACKS"]) - 1;
}
catch (Exception e) { }
}
for (; i > -1; i--)
{
string fallback = Request.Params["FALLBACK_" + i];
if (fallback != null && fallback != "")
{
urls.Add(fallback);
}
}
return urls;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>