コード例 #1
0
ファイル: Program.cs プロジェクト: gumho/diva-distribution
        public static void Main(string[] args)
        {
            ConsoleAppender consoleAppender = new ConsoleAppender();
            consoleAppender.Layout =
                new PatternLayout("%date [%thread] %-5level %logger [%property{NDC}] - %message%newline");
            log4net.Config.BasicConfigurator.Configure(consoleAppender);

            if (args.Length == 0)
            {
                m_log.Debug("Please specify filename");
                return;
            }

            Program webApp = new Program();

            //string myStr = "<!--#include file=\"content-box.html\" -->";
            //string result = Processor.Processor.Process(myStr);
            //m_log.Debug(result);
            string fileName = args[0];
            using (StreamReader sr = new StreamReader(fileName))
            {
                string content = sr.ReadToEnd();
                Processor p = new Processor(webApp, null);
                string result = p.Process(content);

                m_log.Debug(result);
            }
        }
コード例 #2
0
        public string DefaultRequest(Environment env)
        {
            m_log.DebugFormat("[Wifi]: DefaultRequest");

            SessionInfo sinfo;
            if (TryGetSessionInfo(env.Request, out sinfo))
            {
                env.Session = sinfo;
                env.Flags = Flags.IsLoggedIn;
                env.State = State.Default;
                return PadURLs(env, sinfo.Sid, m_WebApp.ReadFile(env, "splash.html"));
            }

            string resourcePath = Localization.LocalizePath(env, "splash.html");
            Processor p = new Processor(m_WebApp.WifiScriptFace, env);
            return p.Process(WebAppUtils.ReadTextResource(resourcePath));
        }
コード例 #3
0
        public string DefaultRequest(Environment env)
        {
            //m_log.DebugFormat("[Wifi]: DefaultRequest from {0}", env.TheRequest.IPEndPoint.ToString());

            SessionInfo sinfo;
            if (TryGetSessionInfo(env.TheRequest, out sinfo))
            {
                env.Session = sinfo;
                env.Flags = Flags.IsLoggedIn;
                env.State = State.Default;
                return WebAppUtils.PadURLs(env, sinfo.Sid, m_WebApp.ReadFile(env, "splash.html"));
            }

            string resourcePath = Localization.LocalizePath(env, "splash.html");
            Processor p = new Processor(m_WebApp.WifiScriptFace, env);
            return p.Process(WebAppUtils.ReadTextResource(new string[] {resourcePath}, WebApp.MissingPage));
        }
コード例 #4
0
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            // path = /wifi/...
            //m_log.DebugFormat("[Wifi]: path = {0}", path);
            //m_log.DebugFormat("[Wifi]: ip address = {0}", httpRequest.RemoteIPEndPoint);
            //foreach (object o in httpRequest.Query.Keys)
            //    m_log.DebugFormat("  >> {0}={1}", o, httpRequest.Query[o]);

            string resource = GetParam(path);
            m_log.DebugFormat("[Wifi]: resource {0}", resource);
            resource = resource.Trim(new char[] { '/' });

            Request request = WifiUtils.CreateRequest(resource, httpRequest);
            Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

            if (resource == string.Empty || resource.StartsWith("index."))
            {
                httpResponse.ContentType = "text/html";
                string resourcePath = System.IO.Path.Combine(WifiUtils.DocsPath, "index.html");
                Processor p = new Processor(m_WebApp.WifiScriptFace, env);
                return WifiUtils.StringToBytes(p.Process(WifiUtils.ReadTextResource(resourcePath)));
            }
            else
            {
                string resourcePath = System.IO.Path.Combine(WifiUtils.DocsPath, resource);
                string type = WifiUtils.GetContentType(resource);
                httpResponse.ContentType = type;
                if (type.StartsWith("image"))
                    return WifiUtils.ReadBinaryResource(resourcePath);

                if (type.StartsWith("text"))
                {
                    Processor p = new Processor(m_WebApp.WifiScriptFace, env);
                    return WifiUtils.StringToBytes(p.Process(WifiUtils.ReadTextResource(resourcePath)));
                }
            }

            httpResponse.ContentType = "text/plain";
            string result = "Boo!";
            return WifiUtils.StringToBytes(result);
        }
コード例 #5
0
        public override byte[] Handle(string path, Stream requestData,
                                      IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            // path = /wifi/...
            //m_log.DebugFormat("[Wifi]: path = {0}", path);
            //m_log.DebugFormat("[Wifi]: ip address = {0}", httpRequest.RemoteIPEndPoint);
            //foreach (object o in httpRequest.Query.Keys)
            //    m_log.DebugFormat("  >> {0}={1}", o, httpRequest.Query[o]);

            string resource = GetParam(path);

            //m_log.DebugFormat("[Wifi]: resource {0}", resource);
            resource = Uri.UnescapeDataString(resource).Trim(WebAppUtils.DirectorySeparatorChars);

            Request request = RequestFactory.CreateRequest(resource, httpRequest);

            Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

            if (resource == string.Empty || resource.StartsWith("index."))
            {
                if (m_WebApp.StatisticsUpdateInterval != TimeSpan.Zero)
                {
                    m_WebApp.Services.ComputeStatistics();
                }

                httpResponse.ContentType = "text/html";

                return(WebAppUtils.StringToBytes(m_WebApp.Services.DefaultRequest(env)));
            }
            else
            {
                string resourcePath = System.IO.Path.Combine(WebApp.DocsPath, resource);
                string type         = WebAppUtils.GetContentType(resource);
                httpResponse.ContentType = type;
                //m_log.DebugFormat("[Wifi]: ContentType {0}", type);
                if (type.StartsWith("image"))
                {
                    return(WebAppUtils.ReadBinaryResource(resourcePath));
                }

                if (type.StartsWith("application"))
                {
                    string res = WebAppUtils.ReadTextResource(resourcePath, true);
                    return(WebAppUtils.StringToBytes(res));
                }
                if (type.StartsWith("text"))
                {
                    if (m_WebApp.StatisticsUpdateInterval != TimeSpan.Zero)
                    {
                        m_WebApp.Services.ComputeStatistics();
                    }

                    resourcePath = Localization.LocalizePath(env, resource);
                    Processor p   = new Processor(m_WebApp.WifiScriptFace, env);
                    string    res = p.Process(WebAppUtils.ReadTextResource(resourcePath));
                    if (res == string.Empty)
                    {
                        res = m_WebApp.Services.DefaultRequest(env);
                    }
                    return(WebAppUtils.StringToBytes(res));
                }
            }

            httpResponse.ContentType = "text/plain";
            string result = "Boo!";

            return(WebAppUtils.StringToBytes(result));
        }
コード例 #6
0
        public override byte[] Handle(string path, Stream requestData,
                IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            // path = /wifi/...
            //m_log.DebugFormat("[Wifi]: path = {0}", path);
            //m_log.DebugFormat("[Wifi]: ip address = {0}", httpRequest.RemoteIPEndPoint);
            //foreach (object o in httpRequest.Query.Keys)
            //    m_log.DebugFormat("  >> {0}={1}", o, httpRequest.Query[o]);

            string resource = GetParam(path);
            //m_log.DebugFormat("[Wifi]: resource {0}", resource);
            resource = Uri.UnescapeDataString(resource).Trim(WebAppUtils.DirectorySeparatorChars);

            Request request = RequestFactory.CreateRequest(resource, httpRequest);
            Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

            if (resource == string.Empty || resource.StartsWith("index."))
            {
                if (m_WebApp.StatisticsUpdateInterval != TimeSpan.Zero)
                    m_WebApp.Services.ComputeStatistics();

                httpResponse.ContentType = "text/html";

                return WebAppUtils.StringToBytes(m_WebApp.Services.DefaultRequest(env));
            }
            else
            {
                string resourcePath = System.IO.Path.Combine(WebApp.DocsPath, resource);
                string type = WebAppUtils.GetContentType(resource);
                httpResponse.ContentType = type;
                //m_log.DebugFormat("[Wifi]: ContentType {0}", type);
                if (type.StartsWith("image"))
                    return WebAppUtils.ReadBinaryResource(resourcePath);

                if (type.StartsWith("application"))
                {
                    string res = WebAppUtils.ReadTextResource(resourcePath, true);
                    return WebAppUtils.StringToBytes(res);
                }
                if (type.StartsWith("text"))
                {
                    if (m_WebApp.StatisticsUpdateInterval != TimeSpan.Zero)
                        m_WebApp.Services.ComputeStatistics();

                    resourcePath = Localization.LocalizePath(env, resource);
                    Processor p = new Processor(m_WebApp.WifiScriptFace, env);
                    string res = p.Process(WebAppUtils.ReadTextResource(resourcePath));
                    if (res == string.Empty)
                        res = m_WebApp.Services.DefaultRequest(env);
                    return WebAppUtils.StringToBytes(res);
                }
            }

            httpResponse.ContentType = "text/plain";
            string result = "Boo!";
            return WebAppUtils.StringToBytes(result);
        }
コード例 #7
0
        public string GetAddonsMenu(Environment env)
        {
            if (!m_WebApp.IsInstalled)
                return string.Empty;

            // are there any addons?
            if (m_WebApp.Addons.Count > 0)
            {
                SessionInfo sinfo = env.Session;
                if (sinfo.Account != null)
                {
                    if (sinfo.Account.UserLevel >= m_WebApp.AdminUserLevel) // Admin
                    {
                        string addons_menu = Translate(env, "Addons menu");
                        StringBuilder str = new StringBuilder("<p class=\"nav-headline\">" + addons_menu + "</p><div id=\"addons-menu\">  <ul>");
                        str.Append(System.Environment.NewLine);
                        foreach (WifiAddon a in m_WebApp.Addons)
                            str.AppendFormat("  <li><a href=\"{0}\">{1}</a></li>{2}", a.Path, a.MenuAnchor, System.Environment.NewLine);

                        str.Append("  </ul></div>");

                        Processor p = new Processor(m_WebApp.WifiScriptFace, env);
                        return p.Process(str.ToString());
                    }
                    else // Everyone else
                    {
                        bool atLeastOne = false;
                        string addons_menu = Translate(env, "Addons menu");
                        StringBuilder str = new StringBuilder("<p class=\"nav-headline\">" + addons_menu + "</p><div id=\"addons-menu\">  <ul>");
                        str.Append(System.Environment.NewLine);
                        foreach (WifiAddon a in m_WebApp.Addons)
                        {
                            if (a.Privilege == PrivilegeLevel.AllUsers)
                            {
                                atLeastOne = true;
                                str.AppendFormat("  <li><a href=\"{0}\">{1}</a></li>{2}", a.Path, a.MenuAnchor, System.Environment.NewLine);
                            }
                        }
                        str.Append("  </ul></div>");

                        if (atLeastOne)
                        {
                            Processor p = new Processor(m_WebApp.WifiScriptFace, env);
                            return p.Process(str.ToString());
                        }

                        return string.Empty;
                    }
                }
            }

            return string.Empty;
        }
コード例 #8
0
ファイル: WebApp.cs プロジェクト: kenvc/diva-distribution
 public string ReadFile(Environment env, string path, List<object> lot)
 {
     string file = Localization.LocalizePath(env, path);
     try
     {
         using (StreamReader sr = new StreamReader(file))
         {
             string content = sr.ReadToEnd();
             Processor p = new Processor(WifiScriptFace, m_ExtensionMethods, env, lot);
             return p.Process(content);
         }
     }
     catch (Exception e)
     {
         m_log.DebugFormat("[Wifi]: Exception on ReadFile {0}: {1}", path, e);
         return string.Empty;
     }
 }
コード例 #9
0
        private string Include(string argStr)
        {
            Match match = args.Match(argStr);
            //m_log.DebugFormat("Match {0} args? {1} {2}", args.ToString(), match.Success, match.Groups.Count);
            if (match.Groups.Count == 3)
            {
                string name = match.Groups[1].Value;
                string value = match.Groups[2].Value;
                // ignore the name which should be file
                string file = m_WebApp.LocalizePath(m_Env, value);
                //m_log.DebugFormat("[WifiScript]: Including file {0} with index = {1} (previous file is {2})", file, m_Index, m_FileName);

                using (StreamReader sr = new StreamReader(file))
                {
                    if (file == m_FileName)
                    {
                        m_Index++;
                        if (m_ListOfObjects != null)
                        {
                            if (m_Index >= m_ListOfObjects.Count)
                            {
                                return string.Empty;
                            }
                        }

                        // recurse!
                        return Process(sr.ReadToEnd());
                    }
                    else
                    {
                        m_FileName = file;
                        List<object> nextLoo = m_ListOfObjects;
                        if (m_ListOfObjects != null && m_Index < m_ListOfObjects.Count - 1)
                        {
                            m_Index++;
                            if (m_ListOfObjects[m_Index] is List<object>)
                            //if (IsGenericList(m_ListOfObjects[m_Index].GetType()))
                                nextLoo = (List<object>)m_ListOfObjects[m_Index];
                        }
                        Processor p = new Processor(m_WebApp, m_ExtensionMethods, m_Env, nextLoo);
                        //Processor p = new Processor(m_WebApp, m_ExtensionMethods, m_Env, m_ListOfObjects);
                        return p.Process(sr.ReadToEnd());
                    }
                }
            }

            return string.Empty;
        }
コード例 #10
0
ファイル: WebApp.cs プロジェクト: gumho/diva-distribution
 public string ReadFile(Environment env, string path, List<object> lot)
 {
     string file = Path.Combine(WifiUtils.DocsPath, path);
     try
     {
         using (StreamReader sr = new StreamReader(file))
         {
             string content = sr.ReadToEnd();
             Processor p = new Processor(WifiScriptFace, env, lot);
             return p.Process(content);
         }
     }
     catch (Exception e)
     {
         m_log.DebugFormat("[WebApp]: Exception on ReadFile {0}: {1}", path, e);
         return string.Empty;
     }
 }