Click here to Skip to main content
15,922,015 members

Comments by ExtinctSpecie (Top 3 by date)

ExtinctSpecie 7-Jul-15 6:15am View    
public override void OnResponse(ref HTTPRequestStruct rq, ref HTTPResponseStruct rp)
{
string path = this.Folder + "\\" + rq.URL.Replace("/","\\");

//..%2f Buf fix
if (path.Contains(".."))
{
string bodyStr = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
bodyStr += "<HTML><HEAD>\n";
bodyStr += "<META http-equiv=Content-Type content=\"text/html; charset=windows-1252\">\n";
bodyStr += "</HEAD>\n";
bodyStr += "<BODY><p>The requested URL contains \"..\" used for many malicious attacks!<p>\n";
bodyStr += "</BODY></HTML>\n";

rp.BodyData = Encoding.ASCII.GetBytes(bodyStr);
return;
}
//

if (Directory.Exists(path))
{
if (File.Exists(path + "default.htm"))
path += "\\default.htm";
else
{
string[] dirs = Directory.GetDirectories(path);
string[] files = Directory.GetFiles(path);

string bodyStr = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
bodyStr += "<HTML><HEAD>\n";
bodyStr += "<META http-equiv=Content-Type content=\"text/html; charset=windows-1252\">\n";
bodyStr += "</HEAD>\n";
bodyStr += "<BODY><p>Folder listing, to do not see this add a 'default.htm' document\n<p>\n";
for ( int i = 0; i<dirs.length; i++)
="" bodystr="" +="<br><a href = \" "="" rq.url="" path.getfilename="" (="" dirs[i]="" )="" \"="">[" + Path.GetFileName( dirs[i] ) + "]\n";
for ( int i = 0; i<files.length; i++)
="" bodystr="" +="<br><a href = \" "="" rq.url="" path.getfilename(="" files[i]="" )="" "\"="">" + Path.GetFileName( files[i] ) + "\n";
bodyStr += "</BODY></HTML>\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 = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
bodyStr += "<HTML><HEAD>\n";
bodyStr += "<META http-equiv=Content-Type content=\"text/html; charset=windows-1252\">\n";
bodyStr += "</HEAD>\n";
bodyStr += "<BODY>File not found!!</BODY></HTML>\n";

rp.BodyData = Encoding.ASCII.GetBytes(bodyStr);

}

}
ExtinctSpecie 7-Jul-15 6:10am View    
Here it is, http://www.codeproject.com/Articles/17071/Sample-HTTP-Server-Skeleton-in-C
ExtinctSpecie 7-Jul-15 6:09am View    
Deleted
Here it is, http://www.codeproject.com/Articles/17071/Sample-HTTP-Server-Skeleton-in-C