Esempio n. 1
0
        public static XmlDocument ReadXML(string path)
        {
            var file = new XmlDocument();

            file.Load(Filesystem.ResolvePath(path));

            return(file);
        }
Esempio n. 2
0
        public static void Move(string source, string target, bool overwrite = false)
        {
            if (overwrite && Filesystem.Exist(target))
            {
                File.Delete(target);
            }

            File.Move(source, target);
        }
Esempio n. 3
0
        static string ParseRequest(string url, NameValueCollection arguments, string method, out ulong length)
        {
            try
            {
                var retval = url.ToLowerInvariant();

                if (method == "POST" && url == "/settings.html")
                {
                    retval = "/";
                }

                if (retval == "/approve.html")
                {
                    retval = "/requests.html";
                }

                if (retval == "/")
                {
                    retval = "/index.html";
                }

                if (!retval.EndsWith(".htm") && !retval.EndsWith(".html") && !retval.EndsWith(".js") &&
                    !retval.EndsWith(".css") && !retval.EndsWith(".png") && !retval.EndsWith(".gif"))
                {
                    throw new Exception("Unsupported Content type!");
                }

                var size = Filesystem.Size("http{0}".F(retval));
                length = (ulong)size;

                if (size > 10485760)                 // 10 MB
                {
                    return(string.Empty);
                }

                return("http{0}".F(retval));
            }
            catch (Exception)
            {
                length = ulong.MinValue;
                return(string.Empty);
            }
        }
Esempio n. 4
0
        public static byte[] HandleWebInterFaceRequest(ref HttpListenerRequest request, ref SQLDatabase db)
        {
            var length = ulong.MinValue;
            var url    = ParseRequest(request.Url.LocalPath != null ? request.Url.LocalPath.ToLowerInvariant() :
                                      "/", request.QueryString, request.HttpMethod, out length);

            if (string.IsNullOrEmpty(url))
            {
                return(new byte[0]);
            }

            if (!Filesystem.Exist(url) && request.HttpMethod == "GET")
            {
                return(new byte[0]);
            }

            var data      = new byte[length];
            var bytesRead = 0;

            Files.Read(url, ref data, out bytesRead);

            if (url.EndsWith(".htm") || url.EndsWith(".html") || url.EndsWith(".js") || url.EndsWith(".css"))
            {
                var pagecontent = string.Empty;
                if (url.EndsWith(".htm") || url.EndsWith(".html"))
                {
                    pagecontent += HTML_header("utf-8", ref db);

                    if (url.EndsWith("index.html"))
                    {
                        pagecontent += "\t\t<div id=\"page\">\n";

                        pagecontent += "\t\t\t<nav>\n";
                        pagecontent += Generate_head_bar(ref db);
                        pagecontent += "\t\t\t</nav>\n";

                        pagecontent += "\t\t<header>\n";
                        pagecontent += "\t\t<h2></h2>\n";
                        pagecontent += "\t\t</header>\n";
                    }

                    pagecontent += "\t<script type=\"text/javascript\">\n";
                    pagecontent += "\t\tdocument.getElementById('anchor_summary').click();\n";
                    pagecontent += "\t</script>\n";
                    pagecontent += "\t\t\t<main>\n";
                }

                pagecontent += Exts.EncodeTo(data, Encoding.UTF8);

                if (url.EndsWith(".htm") || url.EndsWith(".html"))
                {
                    pagecontent = pagecontent.Replace("[[DESIGN]]", "Default");
                    pagecontent = pagecontent.Replace("[[SERVER_INFO_BLOCK]]", Generate_device_list(ref db));

                    pagecontent += "\t\t\t</main>\n";
                    pagecontent += "\t\t</div>\n";
                    pagecontent += HTML_footer();
                }

                data = Encoding.UTF8.GetBytes(pagecontent);
            }

            return(data);
        }