/usr/share/asp.net-demos/1.1/handlers/monodoc.ashx is in asp.net-examples 4.2-2.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 188 189 190 191 192 193 194 195 196 197 198 199 | <%@ WebHandler Language="c#" class="Mono.Website.Handlers.MonodocHandler" %>
<%@ Assembly name="monodoc" %>
//
// Mono.Web.Handlers.MonodocHandler.
//
// Authors:
// Ben Maurer (bmaurer@users.sourceforge.net)
//
// (C) 2003 Ben Maurer
//
using System;
using System.Collections;
using System.IO;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Xsl;
using Monodoc;
namespace Mono.Website.Handlers
{
public class MonodocHandler : IHttpHandler
{
static RootTree help_tree;
static MonodocHandler ()
{
help_tree = RootTree.LoadTree ();
}
void IHttpHandler.ProcessRequest (HttpContext context)
{
string link = (string) context.Request.Params["link"];
if (link == null)
link = "root:";
if (link.StartsWith ("source-id:") && (link.EndsWith (".gif") || link.EndsWith (".jpeg") || link.EndsWith (".jpg") || link.EndsWith(".png")))
{
switch (link.Substring (link.LastIndexOf ('.') + 1))
{
case "gif":
context.Response.ContentType = "image/gif";
break;
case "jpeg":
case "jpg":
context.Response.ContentType = "image/jpeg";
break;
case "png":
context.Response.ContentType = "image/png";
break;
default:
throw new Exception ("Internal error");
}
Stream s = help_tree.GetImage (link);
if (s == null)
throw new HttpException (404, "File not found");
Copy (s, context.Response.OutputStream);
return;
}
Node n;
string content = help_tree.RenderUrl (link, out n);
PrintDocs (content, context);
}
void Copy (Stream input, Stream output)
{
const int BUFFER_SIZE=8192; // 8k buf
byte [] buffer = new byte [BUFFER_SIZE];
int len;
while ( (len = input.Read (buffer, 0, BUFFER_SIZE)) > 0)
output.Write (buffer, 0, len);
output.Flush();
}
string requestPath;
void PrintDocs (string content, HttpContext ctx)
{
Node n;
ctx.Response.Write (@"
<html>
<head>
<script>
<!--
function load ()
{
objs = document.getElementsByTagName('a');
for (i = 0; i < objs.length; i++) {
e = objs [i];
if (e.href == null) continue;
objs[i].href = makeLink (objs[i].href);
}
objs = document.getElementsByTagName('img');
for (i = 0; i < objs.length; i++)
{
e = objs [i];
if (e.src == null) continue;
objs[i].src = makeLink (objs[i].src);
}
}
function makeLink (link)
{
if (link == '') return '';
if (link.charAt(0) == '#') return link;
protocol = link.substring (0, link.indexOf (':'));
switch (protocol)
{
case 'http':
case 'ftp':
case 'mailto':
return link;
default:
return '" + ctx.Request.Path + @"?link=' + link.replace(/\+/g, '%2B');
}
}
-->
</script>
<title>Mono Documentation</title>
</head>
<body onLoad='load()'>
");
requestPath=ctx.Request.Path;
string output;
if (content == null)
output = "No documentation available on this topic";
else {
output = MakeLinks(content);
}
ctx.Response.Write (output);
ctx.Response.Write (@"</body></html>");
}
string MakeLinks(string content)
{
MatchEvaluator linkUpdater=new MatchEvaluator(MakeLink);
if(content.Trim().Length<1|| content==null)
return content;
try
{
string updatedContents=Regex.Replace(content,"(<a[^>]*href=['\"])([^'\"]+)(['\"][^>]*)(>)", linkUpdater);
return(updatedContents);
}
catch(Exception e)
{
return "LADEDA" + content+"!<!--Exception:"+e.Message+"-->";
}
}
// Delegate to be called from MakeLinks for fixing <a> tag
string MakeLink (Match theMatch)
{
string updated_link = null;
// Return the link without change if it of the form
// $protocol://... or #...
string link = theMatch.Groups[2].ToString();
if (Regex.Match(link, @"^\w+:\/\/").Success || Regex.Match(link, "^#").Success)
updated_link = theMatch.Groups[0].ToString();
else {
updated_link = String.Format ("{0}{1}?link={2}{3} target=\"content\"{4}",
theMatch.Groups[1].ToString(),
requestPath,
HttpUtility.UrlEncode (link.Replace ("file://","")),
theMatch.Groups[3].ToString(),
theMatch.Groups[4].ToString());
}
return updated_link;
}
bool IHttpHandler.IsReusable
{
get {
return true;
}
}
}
}
|