{
string path = this.Folder + "\\" + rq.URL.Replace("/","\\");
//..%2f Buf fix
if (path.Contains(".."))
{
string bodyStr = "\n";
bodyStr += "\n";
bodyStr += "\n";
bodyStr += "\n";
bodyStr += "
The requested URL contains \"..\" used for many malicious attacks!
\n";
bodyStr += "\n";
rp.BodyData = Encoding.ASCII.GetBytes(bodyStr);
return;
}
//
if (Directory.Exists(path))
{
if (File.Exists(path + "index.html"))
path += "\\index.html";
else
{
string[] dirs = Directory.GetDirectories(path);
string[] files = Directory.GetFiles(path);
string bodyStr = "\n";
bodyStr += "
bodyStr += "\n";
bodyStr += "\n";
bodyStr += "
Folder listing, Add an 'index.htm' document to navigate to\n
\n";
for ( int i = 0; i
[" + Path.GetFileName( dirs[i] ) + "]\n";
for ( int i = 0; i
" + Path.GetFileName( files[i] ) + "\n";
bodyStr += "\n";
rp.BodyData = Encoding.ASCII.GetBytes(bodyStr);
return;
}
}
if (File.Exists(path))
{
RegistryKey rk = Registry.ClassesRoot.OpenSubKey(Path.GetExtension(path), true);
// Get the data from a specified item in the key.
String s = (String)rk.GetValue("Content Type");
// Open the stream and read it back.
rp.fs = File.Open(path, FileMode.Open);
if ( s != "")
rp.Headers["Content-type"] = s;
}
else
{
rp.status = (int)RespState.NOT_FOUND;
string bodyStr = "\n";
bodyStr += "
bodyStr += "\n";
bodyStr += "\n";
bodyStr += "File not found!!\n";
rp.BodyData = Encoding.ASCII.GetBytes(bodyStr);
}
}
Replies
Know the answer? Post it — somebody with the same question will find it here.