コード例 #1
0
        /// <summary>
        /// Get html representation
        /// </summary>
        /// <returns>html</returns>
        override public string GetHtml()
        {
            HtmlBuilder b = new HtmlBuilder();

            b.open("tr");
            b.open("th"); b.append(b.text(Label + ":")); b.close("th");
            b.open("td");

            string attr = b.attr("name", UniqueID, "style", "width: 300px");

            if (Form.AutoSubmit)
            {
                attr += b.attr("onchange", "this.form.submit();");
            }
            b.open("select", attr);

            for (int i = 0; i < options.Length; ++i)
            {
                attr = b.attr("value", i.ToString()) + GetExtraAttributes();
                if (GetValue().ToLower() == i.ToString())
                {
                    attr += b.attr("selected", "true");
                }
                b.open("option", attr);
                b.append(b.text(options[i]));
                b.close("option");
            }
            return(b.ToString());
        }
コード例 #2
0
        /// <summary>
        /// Get html representation
        /// </summary>
        /// <returns>html</returns>
        override public string GetHtml()
        {
            HtmlBuilder b = new HtmlBuilder();

            // Since the value of an unchecked checkbox is not sent via POST
            // we are going to use two radio buttons instead

            // build attributes
            string temp = GetExtraAttributes() + b.attr("type", "radio", "name", UniqueID);

            if (Form.AutoSubmit)
            {
                temp += b.attr("onclick", "this.form.submit();");
            }
            string[] at = new string[2];
            at[1] = temp + b.attr("value", "True");
            at[0] = temp + b.attr("value", "False");
            if (GetValue().ToLower() != "false")
            {
                at[1] += " checked";
            }
            else
            {
                at[0] += " checked";
            }

            b.open("tr");
            b.open("th"); b.append(b.text(Label + ":")); b.close("th");
            b.open("td");
            b.open("input", at[1]); b.close("input"); b.append(b.text(options[1]));
            b.open("input", at[0]); b.close("input"); b.append(b.text(options[0]));
            return(b.ToString());
        }
コード例 #3
0
        /// <summary>
        /// Get top page with frames
        /// </summary>
        /// <returns>html</returns>
        private string GetTopPage()
        {
            HtmlBuilder b = new HtmlBuilder();

            b.open("html");
            b.open("head");
            b.open("title");
            b.append("Web Config");
            b.close("title");
            b.close("head");
            b.open("frameset", b.attr("cols", "200,*"));
            b.open("frame", b.attr("src", "menu.cgi", "name", "menu")); b.close("frame");
            b.open("frame", b.attr("src", "contents.cgi", "name", "contents")); b.close("frame");
            b.open("noframes");
            b.append("A browser which supports frame display is required for browsing this page.");

            return(b.ToString());
        }
コード例 #4
0
        /// <summary>
        /// Get html representation
        /// </summary>
        /// <returns>html</returns>
        override public string GetHtml()
        {
            HtmlBuilder b = new HtmlBuilder();

            b.open("tr");
            b.open("th"); b.append(b.text(Label + ":")); b.close("th");
            b.open("td");
            b.open("input", b.attr("type", "text",
                                   "name", UniqueID,
                                   "value", GetValue(),
                                   "style", "width: 300px") + GetExtraAttributes());
            return(b.ToString());
        }
コード例 #5
0
        /// <summary>
        /// Get menu with links to each form
        /// </summary>
        /// <returns>html</returns>
        private string GetMenuPage()
        {
            HtmlBuilder b = new HtmlBuilder();

            b.open("html");
            b.open("head");
            b.open("script", b.attr("language", "javascript"));
            b.append("function frmUpdate(page){ parent.contents.location=page; }\n");
            b.close("script");
            b.close("head");
            b.open("body");
            b.open("fieldset");
            b.open("table");

            List <string> uList = new List <string>();

            foreach (var pair in inputs)
            {
                string s = pair.Value.Form.Name;
                if (!uList.Contains(s))
                {
                    uList.Add(s);

                    b.open("tr");
                    b.open("td");
                    b.open("a", b.attr("href", "", "onClick", b.fmt("frmUpdate('{0}.cgi');", s)));
                    b.append(b.text(s));
                    b.close("a");
                    b.close("td");
                    b.close("tr");
                }
            }

            b.close_all();
            return(b.ToString());
        }
コード例 #6
0
        /// <summary>
        /// Get html representation
        /// </summary>
        /// <returns>html</returns>
        override public string GetHtml()
        {
            HtmlBuilder b = new HtmlBuilder();

            b.open("tr");
            b.open("th"); b.close("th");
            b.open("td");

            string attr = b.attr("type", "button",
                                 "value", Label,
                                 "style", "width: 300px") + GetExtraAttributes();

            string script = b.fmt("document.location.href = \"{0}\";", url);

            attr += b.attr("onclick", script);

            b.open("input", attr);
            return(b.ToString());
        }
コード例 #7
0
        /// <summary>
        /// Get html representation
        /// </summary>
        /// <returns>html</returns>
        override public string GetHtml()
        {
            HtmlBuilder b = new HtmlBuilder();

            b.open("tr");
            b.open("th"); b.close("th");
            b.open("td");
            b.open("input", b.attr("type", "hidden",
                                   "name", UniqueID));

            string attr = b.attr("type", "button",
                                 "value", Label,
                                 "style", "width: 300px") + GetExtraAttributes();

            // buttons always auto-submit
            string script = b.fmt("doclick(this.form.{0});", UniqueID);

            attr += b.attr("onclick", script);

            b.open("input", attr);
            return(b.ToString());
        }
コード例 #8
0
        /// <summary>
        /// Respond to HTTP requests
        /// </summary>
        /// <param name="rq">request parameters</param>
        /// <param name="rp">response parameters</param>
        private void OnResponse(ref HTTPRequestParams rq, ref HTTPResponse rp)
        {
            // Handle post
            if (rq.Method == "POST")
            {
                string postStr = Encoding.ASCII.GetString(rq.BodyData, 0, rq.BodySize);
                Dictionary <string, string> cgivars = new Dictionary <string, string>();

                string[] settings = postStr.Split("&;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                foreach (string setting in settings)
                {
                    string[] nameValue = setting.Split("=".ToCharArray(), 2);
                    if (nameValue.Length == 2 && nameValue[1] != "")
                    {
                        string name  = HttpUtility.UrlDecode(nameValue[0]);
                        string value = HttpUtility.UrlDecode(nameValue[1]);
                        cgivars.Add(name, value);
                    }
                }

                this.OnPost(cgivars);
                // respond same as for GET
            }

            // handle top using frames
            if (rq.URL == "/")
            {
                string html = this.GetTopPage();
                rp.BodyData = Encoding.ASCII.GetBytes(html);
                return;
            }

            // handle generated menu and forms
            if (rq.URL.EndsWith(".cgi"))
            {
                if (rq.URL == "/menu.cgi")
                {
                    string html = this.GetMenuPage();
                    rp.BodyData = Encoding.ASCII.GetBytes(html);
                }
                else                 // contents
                {
                    string formName = System.IO.Path.GetFileNameWithoutExtension(rq.URL);
                    string html     = this.GetFormPage(formName);
                    rp.BodyData = Encoding.ASCII.GetBytes(html);
                }
                return;
            }

            string path = theFolder + "\\" + rq.URL.Replace("/", "\\");

            path = Path.GetFullPath(path);              // get absolute path
            bool valid = path.StartsWith(theFolder);    // make it secure

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

                    HtmlBuilder b = new HtmlBuilder();
                    b.open("html");
                    b.open("head");
                    b.close("head");
                    b.open("body");
                    b.open("h2");
                    b.append(b.text("Folder listing for " + path.Substring(theFolder.Length + 1)));
                    b.close("h2");
                    for (int i = 0; i < dirs.Length; i++)
                    {
                        b.link(rq.URL + "/" + Path.GetFileName(dirs[i]),
                               "[" + Path.GetFileName(dirs[i]) + "]");
                        b.br();
                    }
                    for (int i = 0; i < files.Length; i++)
                    {
                        b.link(rq.URL + "/" + Path.GetFileName(files[i]),
                               "[" + Path.GetFileName(files[i]) + "]");
                        b.br();
                    }
                    rp.BodyData = Encoding.ASCII.GetBytes(b.ToString());
                    return;
                }
            }

            if (valid && 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)HTTPResponseStatus.NOT_FOUND;

                HtmlBuilder b = new HtmlBuilder();
                b.open("html");
                b.open("head");
                b.close("head");
                b.open("body");
                b.append(b.text("File not found!!"));

                rp.BodyData = Encoding.ASCII.GetBytes(b.ToString());
            }
        }
コード例 #9
0
        /// <summary>
        /// Get specified form
        /// </summary>
        /// <param name="formName">name of form</param>
        /// <returns>html</returns>
        private string GetFormPage(string formName)
        {
            HtmlBuilder b = new HtmlBuilder();

            b.open("html");
            b.open("head");
            b.open("title");
            b.append(b.text(formName));
            b.close("title");
            b.open("style", b.attr("type", "text/css"));
            b.append("th	{text-align: right;}\n");
            b.append("td	{padding-left: 1em; text-align: left;}\n");
            b.close("style");
            b.include_js("scripts/slider.js");
            b.include_css("styles/slider.css");
            b.open("script", b.attr("type", "text/javascript"));
            b.append("function doclick(sel){\n");
            b.append("  sel.value=\"True\";\n");
            b.append("  sel.form.submit();\n");
            b.append("}\n");
            b.close("script");
            b.close("head");
            b.open("body");
            b.open("h2");
            b.append(b.text(formName));
            b.close("h2");
            b.hr();
            b.open("form", b.attr("name", formName,
                                  "action", b.fmt("{0}.cgi", formName),
                                  "method", "post"));
            b.open("table");
            foreach (var pair in inputs)
            {
                InputBase input = pair.Value;
                if (input.Form.Name == formName)
                {
                    b.append(input.GetHtml());
                }
            }
            b.open("tr");
            b.open("th");
            b.close("th");
            b.open("td");

            FormSettings form = GetForm(formName);

            if (!form.AutoSubmit)
            {
                b.open("input", b.attr("type", "submit", "value", "SUBMIT"));
                b.close("input");
                b.open("input", b.attr("type", "reset", "value", "RESET"));
                b.close("input");
            }

            b.close("td");
            b.close("tr");
            b.close("table");
            b.close("form");

            // required "linkware" credits
            b.hr();
            //b.link("http://carpe.ambiprospect.com/slider/", "sliders by CARPE Design");

            return(b.ToString());
        }
コード例 #10
0
        /// <summary>
        /// Get html representation
        /// </summary>
        /// <returns>html</returns>
        override public string GetHtml()
        {
            // validate value within range and compute percent
            float value = (float)Convert.ToDouble(GetValue());

            if (value < minValue)
            {
                value = minValue;
            }
            else if (value > maxValue)
            {
                value = maxValue;
            }
            float range    = maxValue - minValue;
            int   pctValue = (int)(value * 100 / range);

            string sliderID  = UniqueID;
            string displayID = UniqueID + "_display";

            HtmlBuilder b = new HtmlBuilder();

            b.open("tr");
            b.open("th"); b.append(b.text(Label + ":")); b.close("th");
            b.open("td");

            b.open("div", b.attr("class", "carpe_horizontal_slider_display_combo"));
            b.open("div", b.attr("class", "carpe_horizontal_slider_track"));
            b.open("div", b.attr("class", "carpe_slider_slit"));
            b.nbsp();
            b.close("div");
            b.open("div", b.attr("class", "carpe_slider",
                                 "id", sliderID,
                                 "display", displayID,
                                 "style", b.fmt("left: {0}px;", pctValue.ToString())));
            b.nbsp();
            b.close("div");
            b.close("div");
            b.open("div", b.attr("class", "carpe_slider_display_holder"));

            string attr = b.attr("class", "carpe_slider_display",
                                 "name", UniqueID,
                                 "id", displayID,
                                 "type", "text",
                                 "from", minValue.ToString(),
                                 "to", maxValue.ToString(),
                                 "value", value.ToString(),
                                 "valuecount", valueCount.ToString(),
                                 "decimals", decimals.ToString(),
                                 "typelock", "off") + GetExtraAttributes();

            if (Form.AutoSubmit)
            {
                attr += b.attr("onchange", "this.form.submit();");
            }
            b.open("input", attr);

            b.close("input");
            b.close("div");
            b.close("div");
            return(b.ToString());
        }