Exemple #1
0
        public Namiono()
        {
            sqlDB        = new SQLDatabase();
            UserProvider = new UserProvider(this);
            site_public  = new WebPage(this, "html");
            ws_public    = new WebServer(this, "public_website", "*", 81);
            scProvider   = new ShoutcastProvider("the-walking-radio.de", 8000
                                                 , ws_public.DocRoot);

            UserProvider.RequestHandled += (sender, e) =>
            {
                var evtargs = new WebPageRequestedEventArgs();
                evtargs.Action = Actions.Update;
                evtargs.Type   = e.Type;

                WebPageRequested.Invoke(this, evtargs);
            };

            ws_public.WSStarted += (sender, e) =>
            {
                var tplPath = Path.Combine(ws_public.DocRoot, "templates/content_box.tpl");
                var data    = new byte[FileSystem.Size(tplPath)];

                scProvider.HTMLTemplate = Encoding.UTF8.GetString(data);
                scProvider.Start();
            };

            ws_public.WSDataReceived += (sender, e) =>
            {
                switch (e.Needs)
                {
                case Needs.ShoutCast:
                    break;
                }

                if (WebPageRequested == null)
                {
                    return;
                }

                var evargs = new WebPageRequestedEventArgs();
                evargs.Context = e.Context;
                evargs.Path    = ws_public.DocRoot;

                WebPageRequested.Invoke(this, evargs);
            };

            site_public.WebPageRendered += (sender, e) =>
            {
                if (WebRequestHandled == null)
                {
                    return;
                }

                var evargs = new WebRequestHandledEventArgs();
                evargs.Content = e.Content;
                evargs.Context = e.Context;

                WebRequestHandled.Invoke(this, evargs);
            };

            ws_public.WSError += (sender, e) =>
                                 Console.WriteLine("Webserver Exception: {0}", e.Exception);
        }
Exemple #2
0
        public WebSite(ref Common common, ref SQLDatabase <T> db, string name, string title, ushort port, Realm realm, string hostname, string design = "default")
        {
            this.title  = title;
            this.db     = db;
            this.common = common;
            this.design = design;
            this.realm  = realm;

            Webservers = new Dictionary <Guid, WebServer>();
            fs         = new Filesystem(Path.Combine(Environment.CurrentDirectory, string.Format("{0}_website", name)));

            foreach (var type in new[] { WebServer.RequestTarget.Site, WebServer.RequestTarget.api })
            {
                var _guid = Guid.NewGuid();

                var ws = new WebServer(_guid, type, this.title, ref fs, port, hostname);
                ws.DirectRequestReceived += (sender, e) =>
                {
                    var p = e.Path.Split('.')[0].ToLower();
                    if (p.StartsWith("/"))
                    {
                        p = p.Remove(0, 1);
                    }

                    var userid = Get_UserID_From_Cookie(ref e.Context);

                    foreach (var item in e.Params)
                    {
                        Console.WriteLine("{0} : {1} ", item.Key, e.Params[item.Key]);
                    }

                    switch (e.Target)
                    {
                    case WebServer.RequestTarget.api:
                        if (e.Context.User.Identity.IsAuthenticated)
                        {
                            var identity = (HttpListenerBasicIdentity)e.Context.User.Identity;
                            Console.WriteLine(identity.Name);
                            Console.WriteLine(identity.Password);
                        }

                        if (e.Context.User.Identity.IsAuthenticated)
                        {
                            Handle_Provider_Request(ref this.common, ref e.Provider, ref e.Action, ref e.Context, ref userid, ref e.Params, e.Instance);
                        }
                        else
                        {
                            e.Context.Response.StatusCode        = 401;
                            e.Context.Response.StatusDescription = "Network Authentication Required!";

                            var data = new byte[0];
                            Webservers[e.Instance].Send(ref data, ref e.Context);
                        }
                        break;

                    case WebServer.RequestTarget.Site:
                        Handle_Site_Request(ref userid, ref e.Context, e.Instance, ref e.Params);
                        break;
                    }
                };

                Webservers.Add(_guid, ws);
            }
        }