Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
137 lines (112 loc) · 6.84 KB
/
Copy pathProgram.cs
File metadata and controls
137 lines (112 loc) · 6.84 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
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
using System;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
namespace html_templates_downloader
{
class Program
{
static void Main(string[] args)
{
String[] htmlFiles = new String[] {
// Classic
"https://login.microsoftonline.com/static/tenant/default/unified.cshtml",
"https://login.microsoftonline.com/static/tenant/default/idpSelector.cshtml",
"https://login.microsoftonline.com/static/tenant/default/selfAsserted.cshtml",
"https://login.microsoftonline.com/static/tenant/default/updateProfile.cshtml", //deprecated
"https://login.microsoftonline.com/static/tenant/default/multifactor-1.0.0.cshtml",
"https://login.microsoftonline.com/static/tenant/default/exception.cshtml",
// Blue
"https://login.microsoftonline.com/static/tenant/templates/AzureBlue/unified.cshtml",
"https://login.microsoftonline.com/static/tenant/templates/AzureBlue/idpSelector.cshtml",
"https://login.microsoftonline.com/static/tenant/templates/AzureBlue/selfAsserted.cshtml",
"https://login.microsoftonline.com/static/tenant/templates/AzureBlue/multifactor-1.0.0.cshtml",
"https://login.microsoftonline.com/static/tenant/templates/AzureBlue/exception.cshtml",
// Gray
"https://login.microsoftonline.com/static/tenant/templates/MSA/unified.cshtml",
"https://login.microsoftonline.com/static/tenant/templates/MSA/idpSelector.cshtml",
"https://login.microsoftonline.com/static/tenant/templates/MSA/selfAsserted.cshtml",
"https://login.microsoftonline.com/static/tenant/templates/MSA/multifactor-1.0.0.cshtml",
"https://login.microsoftonline.com/static/tenant/templates/MSA/exception.cshtml"
};
foreach (string htmlFileURI in htmlFiles)
{
using (var client = new WebClient())
{
// Build the local path
var localpath = htmlFileURI.Replace("https://login.microsoftonline.com/static/tenant/", "");
if (htmlFileURI.IndexOf("templates/") < 0)
{
// Add the templates to the classic temlate
localpath = "templates/" + localpath.Replace("default", "classic");
}
// Replace the cshtml file name to html
localpath = localpath.Replace("cshtml", "html");
// Add the app path
localpath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), localpath);
// Create the directory
if (!Directory.Exists(Path.GetDirectoryName(localpath)))
{
Directory.CreateDirectory(Path.GetDirectoryName(localpath));
}
string reply = client.DownloadString(htmlFileURI);
// Get the resources (URIs)
MatchCollection mc = Regex.Matches(reply, @"(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})");
foreach (Match m in mc)
{
var resourceLocalPath = m.Value.ToString();
var resourceRemotePath = m.Value.ToString();
// Skip external resources
if (!resourceLocalPath.StartsWith("https://login.microsoftonline.com"))
continue;
// Remove the domain name in the local path
resourceLocalPath = resourceLocalPath.Replace("https://login.microsoftonline.com/static/tenant/", "");
// Remove the last character
if (resourceRemotePath.EndsWith("\""))
{
resourceLocalPath = resourceLocalPath.Replace("\"", "");
resourceRemotePath = resourceRemotePath.Replace("\"", "");
}
if (resourceRemotePath.EndsWith(");"))
{
resourceLocalPath = resourceLocalPath.Replace(");", "");
resourceRemotePath = resourceRemotePath.Replace(");", "");
}
// Change the directory name for the legacy template
if (resourceLocalPath.IndexOf("templates/") < 0)
{
// Add the templates to the classic temlate
resourceLocalPath = "templates/" + resourceLocalPath.Replace("default", "classic");
}
// Add the src folder to the local resource file
resourceLocalPath = resourceLocalPath.Replace("templates/", "templates/src/");
// Add the app path to the local resource file
resourceLocalPath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), resourceLocalPath);
if (!File.Exists(resourceLocalPath))
{
// Create the directory
if (!Directory.Exists(Path.GetDirectoryName(resourceLocalPath)))
{
Directory.CreateDirectory(Path.GetDirectoryName(resourceLocalPath));
}
client.DownloadFile(resourceRemotePath, resourceLocalPath);
Console.WriteLine(m);
}
}
// Change the directory name for the legacy template
if (htmlFileURI.IndexOf("templates/") < 0)
{
reply = reply.Replace("https://login.microsoftonline.com/static/tenant/default/img/",
"https://login.microsoftonline.com/static/tenant/templates/classic/img/");
}
// Remove the static tenant
reply = reply.Replace("/static/tenant/", "/");
// Add the src folder to the path
reply = reply.Replace("/templates/", "/templates/src/");
File.WriteAllText(localpath, reply);
}
}
Console.ReadLine();
}
}
}