public virtual void SubmitChild(WebServer server, WebComponent source, WebSubmission values) { if (!string.IsNullOrEmpty(this.ID) && null != server.GetSubmitHandler(values.RawUrl, this.ID)) { server.GetSubmitHandler(values.RawUrl, this.ID)(source, values); } }
public override string Render(WebSubmission values) { StringBuilder outstr = new StringBuilder(); outstr.Append(base.RenderOpenTag()); outstr.Append(RenderPair("name", this.Name)); outstr.Append(RenderPair("href", this.Href)); outstr.Append(RenderPair("title", this.Title)); if (0 < this.Children.Count) { outstr.Append(">"); foreach (WebComponent child in this._children) { outstr.Append(child.Render(values)); } if (null != this._tagname) { outstr.Append(String.Format("</{0}>", this._tagname)); } } else { outstr.Append(" />"); } return(outstr.ToString()); }
private void OnOptions(WebComponent source, WebSubmission values) { foreach (KeyValuePair <string, Tuple <WebOptionComponentDelegate, WebOptionSubmitDelegate> > kv in this._options_defaults) { kv.Value.Item2(values); } throw new WebRedirectException("/"); }
public override void SubmitContainer(WebServer server, WebComponent source, WebSubmission values) { if (null != server.GetSubmitHandler(values.RawUrl, ".")) { server.GetSubmitHandler(values.RawUrl, ".")(source, values); } this.SubmitChildren(server, source, values); }
public override string Render(WebSubmission values) { StringBuilder outstr = new StringBuilder(); outstr.Append(String.Format("{0}>", this.RenderOpenTag())); outstr.Append(this.Text); outstr.Append(String.Format("</{0}>", this._tagname)); return(outstr.ToString()); }
protected void SubmitChildren(WebServer server, WebComponent source, WebSubmission values) { foreach (WebComponent child in this._children) { if (child.GetType().IsSubclassOf(typeof(WebContainer))) { ((WebContainer)child).SubmitContainer(server, source, values); } child.SubmitChild(server, source, values); } }
private void HandleConnection(object state) { HttpListenerContext ctx = state as HttpListenerContext; HttpListenerRequest hreq = ctx.Request; HttpListenerResponse hresp = ctx.Response; byte[] retbytes = new byte[] { }; string rawurl_real; if (hreq.RawUrl.Length < 2) { rawurl_real = this.DefaultPage; } else { rawurl_real = hreq.RawUrl; } WebSubmission values = new WebSubmission(rawurl_real, "XXXFIXME", hresp, hreq); try { switch (hreq.HttpMethod) { case "POST": retbytes = this.OnPOST(values); break; case "GET": retbytes = this.OnGET(values); break; default: // TODO: HTTP Bad Method Error throw new WebHTTPException(WebHTTPResponseCode.WEB_HTTP_405_BAD_METHOD, hreq.RawUrl); } hresp.ContentLength64 = retbytes.Length; hresp.OutputStream.Write(retbytes, 0, retbytes.Length); } catch (HttpListenerException ex) { Trace.TraceError(ex.Message); // XXX } catch (WebHTTPException ex) { hresp.StatusCode = ex.GetResponseCodeNumber(); retbytes = Encoding.UTF8.GetBytes(ex.ToString()); ctx.Response.ContentLength64 = retbytes.Length; ctx.Response.OutputStream.Write(retbytes, 0, retbytes.Length); } catch (WebRedirectException ex) { hresp.Redirect(ex.RedirectURL); } finally { ctx.Response.OutputStream.Close(); } }
private void OnOptionsRender(WebComponent source, WebSubmission values) { WebPage outpage = (WebPage)source; WebForm outform = (WebForm)outpage.Children.Find(o => !String.IsNullOrEmpty(o.ID) && o.ID.Equals("options")); foreach (KeyValuePair <string, Tuple <WebOptionComponentDelegate, WebOptionSubmitDelegate> > kv in this._options_defaults) { WebComponent comp = kv.Value.Item1(values); outform.Children.Add(new WebDiv("wrapper_" + kv.Key, "options_wrapper", comp)); } outform.Children.Add(new WebDiv("wrapper_submit", "options_wrapper", new WebSubmit("Submit", "Submit", this.OnOptions))); }
public override void SubmitContainer(WebServer server, WebComponent source, WebSubmission values) { string proc_xsrf_key = String.Format("proc_xsrf_{0}", this.ID); string proc_xsrf_cookie = values.GetCookieIn(proc_xsrf_key).Value; string proc_xsrf_form = values.PostData[proc_xsrf_key][0]; if (!proc_xsrf_form.Equals(proc_xsrf_cookie)) { throw new WebHTTPException(WebHTTPResponseCode.WEB_HTTP_403_ACCESS_DENIED, values.RawUrl); } else { this.SubmitChildren(server, source, values); } }
public override string Render(WebSubmission values) { StringBuilder outstr = new StringBuilder(); if (null != this._tagname) { outstr.Append(String.Format("{0}>", base.RenderOpenTag())); } foreach (WebComponent child in this._children) { outstr.Append(child.Render(values)); } if (null != this._tagname) { outstr.Append(String.Format("</{0}>", this._tagname)); } return(outstr.ToString()); }
protected virtual byte[] OnPOST(WebSubmission values) { WebFile wfile = null; WebPage outpage = null; string retstring = ""; if ( this.AuthRequired && !this._auth_exempt_paths.Contains(values.RawUrl) && (null == values.GetCookieIn("auth_token") || !this.IsLoggedIn(null, values.GetCookieIn("auth_token").Value)) ) { throw new WebRedirectException(this.AuthPageURL); } wfile = this._vfilesystem.GetFileByPath(values.RawUrl); if (null == wfile) { throw new WebHTTPException(WebHTTPResponseCode.WEB_HTTP_404_NOT_FOUND, values.RawUrl); } else if (null != wfile.GetRootWebPage()) { // This is a WebPage derived from WebComponent. outpage = (WebPage)wfile.GetRootWebPage().ToCopy(); if (this._component_render_handlers.ContainsKey(values.RawUrl)) { this._component_render_handlers[values.RawUrl](outpage, values); } // Adjust the fetched page with submission returns. outpage.SubmitContainer(this, null, values); retstring = outpage.Render(values); } else { // This is just a WebFile. retstring = wfile.ToString(); } // TODO: Return binary bytes if wfile is binary. return(Encoding.UTF8.GetBytes(retstring)); }
public new string Render(WebSubmission values) { StringBuilder output = new StringBuilder(); output.Append("<!DOCTYPE HTML>\n<html>\n<head>\n<title>" + this._title + "</title>\n"); foreach (string css_src in this._css) { output.Append("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + css_src + "\" />\n"); } output.Append("</head>\n<body>"); output.Append(base.Render(values)); output.Append("</body>\n</html>"); return(output.ToString()); }
public override string Render(WebSubmission values) { StringBuilder outstr = new StringBuilder(); if (!String.IsNullOrEmpty(this.Label)) { outstr.Append(String.Format("<label for=\"{0}\">{1}</label>", this.Name, this.Label)); } outstr.Append(base.RenderOpenTag()); outstr.Append(RenderPair("type", this._type)); outstr.Append(RenderPair("name", this.Name)); outstr.Append(RenderPair("size", this.Size)); outstr.Append(RenderPair("value", this.Value)); outstr.Append("/>"); return(outstr.ToString()); }
private void OnLogin(WebComponent source, WebSubmission values) { string username = values.PostData["username"][0]; string password = values.PostData["password"][0]; bool auth_valid = false; if (!this.AuthRequired) { return; } using (LdapConnection ldc = new LdapConnection(this.AuthDomainController)) { try { NetworkCredential cred = new NetworkCredential(username, password, this.AuthDomain); ldc.Credential = cred; ldc.Bind(); auth_valid = true; } catch (LdapException ex) { Trace.TraceError(ex.ServerErrorMessage); Trace.TraceError(ex.Message); auth_valid = false; } } if (!auth_valid) { throw new WebHTTPException(WebHTTPResponseCode.WEB_HTTP_401_BAD_AUTH, values.RawUrl); } else { string auth_token = Guid.NewGuid().ToString(); values.SetCookieOut("auth_token", auth_token); this._auth_pairs.Add(new Tuple <string, string>(values.ClientHostname, auth_token)); throw new WebRedirectException("/"); } }
public override string Render(WebSubmission values) { StringBuilder outstr = new StringBuilder(); string xsrf_token = Guid.NewGuid().ToString(); outstr.Append(String.Format("{0}", base.RenderOpenTag())); outstr.Append(RenderPair("method", "post")); outstr.Append(RenderPair("action", this.Action)); outstr.Append(">"); // Free XSRF protection. outstr.Append(String.Format("<input type=\"hidden\" name=\"proc_xsrf_{0}\" value=\"{1}\" />", this.ID, xsrf_token)); values.SetCookieOut(String.Format("proc_xsrf_{0}", this.ID), xsrf_token); foreach (WebComponent child in this._children) { outstr.Append(child.Render(values)); } if (null != this._tagname) { outstr.Append(String.Format("</{0}>", this._tagname)); } return(outstr.ToString()); }
public override string Render(WebSubmission values) { StringBuilder outstr = new StringBuilder(); outstr.Append(base.RenderOpenTag()); outstr.Append(RenderPair("src", this.Src)); outstr.Append(RenderPair("alt", this.Alt)); outstr.Append(RenderPair("title", this.Title)); if (0 < this.WidthPx) { outstr.Append(String.Format("width=\"{0}px\" ", this.WidthPx)); } if (0 < this.HeightPx) { outstr.Append(String.Format("height=\"{0}px\" ", this.HeightPx)); } outstr.Append("/>"); return(outstr.ToString()); }
public abstract string Render(WebSubmission values);
public override string Render(WebSubmission values) { return(Text); }
public virtual void SubmitContainer(WebServer server, WebComponent source, WebSubmission values) { this.SubmitChildren(server, source, values); }