Serves files in the web server.
Inheritance: IModule
示例#1
0
 private void AddFileResources(Assembly assembly, FileModule fileModule)
 {
     var assemblyPath = Path.GetDirectoryName(assembly.Location);
     var filePath = Path.Combine(assemblyPath, "Public");
     if (Directory.Exists(filePath))
         fileModule.Resources.Add(new Resources.FileResources("/content/", filePath));
 }
示例#2
0
        private static void Main(string[] args)
        {
            var filter = new LogFilter();
            filter.AddStandardRules();
            //LogFactory.Assign(new ConsoleLogFactory(filter));

            // create a server.
            var server = new Server();
            
            // same as previous example.
            var module = new FileModule();
            module.Resources.Add(new FileResources("/", Environment.CurrentDirectory + "\\files\\"));
            server.Add(module);
            server.RequestReceived += OnRequest;
            server.Add(new MultiPartDecoder());

            // use one http listener.
            server.Add(HttpListener.Create(IPAddress.Any, 8085));
            server.Add(new SimpleRouter("/", "/index.html"));

            // start server, can have max 5 pending accepts.
            server.Start(5);

            Console.ReadLine();
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleServer"/> class.
        /// </summary>
        public SimpleServer()
        {
            Add(new BodyDecoders.MultiPartDecoder());
            Add(new BodyDecoders.UrlDecoder());

            var fileModule = new FileModule();
            fileModule.AddDefaultMimeTypes();
            AddEmbeddedResources(Assembly.GetCallingAssembly(), fileModule);
            AddFileResources(Assembly.GetCallingAssembly(), fileModule);
        }
示例#4
0
        //Control
        public static void Init()
        {
            //See if there is a new version of the web files waiting before we start the server
            if (File.Exists(Core.RootFolder + @"\web.zip"))
            {
                if (Directory.Exists(Core.RootFolder + @"\web\")) Directory.Delete(Core.RootFolder + @"\web\", true);
                Directory.CreateDirectory(YAMS.Core.RootFolder + @"\web\");
                AutoUpdate.ExtractZip(YAMS.Core.RootFolder + @"\web.zip", YAMS.Core.RootFolder + @"\web\");
                File.Delete(Core.RootFolder + @"\web.zip");
            }

            adminServer = new Server();
            publicServer = new Server();

            //Handle the requests for static files
            var adminModule = new FileModule();
            adminModule.Resources.Add(new FileResources("/assets/", YAMS.Core.RootFolder + "\\web\\assets\\"));
            adminServer.Add(adminModule);

            //Add any server specific folders
            var publicModule = new FileModule();
            publicModule.Resources.Add(new FileResources("/assets/", YAMS.Core.RootFolder + "\\web\\assets\\"));
            SqlCeDataReader readerServers = YAMS.Database.GetServers();
            while (readerServers.Read())
            {
                var intServerID = readerServers["ServerID"].ToString();
                if (!Directory.Exists(Core.StoragePath + intServerID + "\\renders\\")) Directory.CreateDirectory(Core.StoragePath + intServerID + "\\renders\\");
                publicModule.Resources.Add(new FileResources("/servers/" + intServerID + "/renders/", Core.StoragePath + intServerID + "\\renders\\"));
                if (!Directory.Exists(Core.StoragePath + intServerID + "\\backups\\")) Directory.CreateDirectory(Core.StoragePath + intServerID + "\\backups\\");
                publicModule.Resources.Add(new FileResources("/servers/" + intServerID + "/backups/", Core.StoragePath + intServerID + "\\backups\\"));
            }
            publicServer.Add(publicModule);

            //Handle requests to API
            adminServer.Add(new Web.AdminAPI());
            publicServer.Add(new Web.PublicAPI());

            adminServer.Add(HttpListener.Create(IPAddress.Any, Convert.ToInt32(YAMS.Database.GetSetting("AdminListenPort", "YAMS"))));
            publicServer.Add(HttpListener.Create(IPAddress.Any, Convert.ToInt32(YAMS.Database.GetSetting("PublicListenPort", "YAMS"))));

            adminServer.ErrorPageRequested += new EventHandler<ErrorPageEventArgs>(myServer_ErrorPageRequested);
            publicServer.ErrorPageRequested += new EventHandler<ErrorPageEventArgs>(myServer_ErrorPageRequested);

            adminServerThread = new Thread(new ThreadStart(StartAdmin));
            publicServerThread = new Thread(new ThreadStart(StartPublic));
            adminServerThread.Start();
            publicServerThread.Start();

            //Open firewall ports
            Networking.OpenFirewallPort(Convert.ToInt32(YAMS.Database.GetSetting("AdminListenPort", "YAMS")), "Admin website");
            Networking.OpenFirewallPort(Convert.ToInt32(YAMS.Database.GetSetting("PublicListenPort", "YAMS")), "Public website");

            Networking.OpenUPnP(Convert.ToInt32(YAMS.Database.GetSetting("AdminListenPort", "YAMS")), "Admin website");
            Networking.OpenUPnP(Convert.ToInt32(YAMS.Database.GetSetting("PublicListenPort", "YAMS")), "Public website");
        }
        //public WebServer(IPAddress address)
        //{
        //    _ipAddress = address;
        //    // same as previous example.
        //    Setup();
        //}

        public void Setup()
        {
            try
            {
                _server = new HttpServer.Server();
                var module = new FileModule();
                module.Resources.Add(new FileResources("/", ScoreboardConfig.SAVE_SERVER_FILES_FOLDER));

                _server.Add(module);

                _server.RequestReceived += OnRequest;
                _server.Add(new MultiPartDecoder());

                // use one http listener.

                _server.Add(new SimpleRouter("/", "/index.html"));
                _server.Add(new JsonRouter("/GrabOverlayUpdate"));
                _server.Add(new JsonRouter("/GrabMobileUpdate"));
                _server.Add(new JsonRouter("/GetTeam1Members"));
                _server.Add(new JsonRouter("/GetTeam2Members"));
                _server.Add(new JsonRouter("/getJamNumber"));
                _server.Add(new JsonRouter("/addAssist"));
                _server.Add(new JsonRouter("/removeAssist"));
                _server.Add(new JsonRouter("/addBlock"));
                _server.Add(new JsonRouter("/removeBlock"));
                _server.Add(new JsonRouter("/scoringLoaded"));
                _server.Add(new JsonRouter("/addScore"));
                _server.Add(new JsonRouter("/removeScore"));
                _server.Add(new JsonRouter("/setBlocker1"));
                _server.Add(new JsonRouter("/setBlocker2"));
                _server.Add(new JsonRouter("/setBlocker3"));
                _server.Add(new JsonRouter("/setBlocker4"));
                _server.Add(new JsonRouter("/setPivot"));
                _server.Add(new JsonRouter("/setJammer"));
                _server.Add(new JsonRouter("/setPBox"));
                _server.Add(new JsonRouter("/addpenalty"));
                _server.Add(new JsonRouter("/getallpenaltytypes"));
                _server.Add(new JsonRouter("/loadMainScreen"));

                PortNumber = portsToTry[triedIndex];
                _server.Add(HttpListener.Create(IpAddress, PortNumber));
            }
            catch (Exception exception)
            {
                ErrorViewModel.Save(exception, GetType());
            }
        }
示例#6
0
        private void AddEmbeddedResources(Assembly assembly, FileModule fileModule)
        {
            string contentNamespace = null;
            foreach (var resourceName in assembly.GetManifestResourceNames())
            {
                if (!resourceName.Contains("Content"))
                    continue;

                contentNamespace = resourceName;
                break;
            }

            if (contentNamespace == null)
                return;

            int pos = contentNamespace.IndexOf("Content");
            contentNamespace = contentNamespace.Substring(0, pos);
            fileModule.Resources.Add(new Resources.EmbeddedResourceLoader("/content/", Assembly.GetCallingAssembly(),
                                                                          contentNamespace));
        }
示例#7
0
        //Control
        public static void Init()
        {
            adminServer = new Server();

            //Handle the requests for static files
            var adminModule = new FileModule();
            adminModule.Resources.Add(new FileResources("/assets/", YAMS.Core.RootFolder + "\\web\\assets\\"));
            adminServer.Add(adminModule);
            //Handle requests to API
            adminServer.Add(new Web.AdminAPI());

            adminServer.Add(HttpListener.Create(IPAddress.Any, Convert.ToInt32(YAMS.Database.GetSetting("AdminListenPort", "YAMS"))));
            adminServer.ErrorPageRequested += new EventHandler<ErrorPageEventArgs>(myServer_ErrorPageRequested);
            adminServerThread = new Thread(new ThreadStart(StartAdmin));
            adminServerThread.Start();

            //Open firewall ports
            if (Database.GetSetting("EnableOpenFirewall", "YAMS") == "true")
            {
                Networking.OpenFirewallPort(Convert.ToInt32(YAMS.Database.GetSetting("AdminListenPort", "YAMS")), "Admin website");
            }
        }
示例#8
0
        static void Main(string[] args)
        {
            // create a server.
            var server = new Server();

            // same as previous example.
            var module = new FileModule();
            module.Resources.Add(new FileResources("/", Environment.CurrentDirectory + "\\files\\"));
            server.Add(module);

            // use one http listener.
            server.Add(HttpListener.Create(IPAddress.Any, 8085));

            // add our own module.
            server.Add(new Streamer());


            // start server, can have max 5 pending accepts.
            server.Start(5);

            Console.ReadLine();
        }
示例#9
0
        public WordLaunch(ServerInfo targetserver)
        {
            InitializeComponent();
            this.targetserver = targetserver;
            plugin = new PluginRpc(targetserver.conn.URL);
            medsize = plugin.GetMediumSize();

            txt_Content.NativeInterface.SetCodePage((int)Constants.SC_CP_UTF8);

            CategoryFullInfo[] cfi = targetserver.conn.GetCategories(0, targetserver.username, targetserver.password);
            foreach (CategoryFullInfo cf in cfi)
            {
                CheckBox cb = new CheckBox();
                cb.Name = "cb_" + cf.categoryName;
                cb.Text = cf.categoryName;
                cb.Tag = cf;
                flow_Categories.Controls.Add(cb);
            }

            postResources = GetNextAvailableDir();
            Directory.CreateDirectory(postResources);

            var module = new FileModule();
            webserv = new Server();
            module.Resources.Add(new FileResources("/",postResources));
            webserv.Add(module);
            webserv.Add(new MultiPartDecoder());
            webserv.RequestReceived+=new EventHandler<RequestEventArgs>(webserv_RequestReceived);

            // use one http listener.
            webserv.Add(HttpListener.Create(System.Net.IPAddress.Any, webservport));
            webserv.Start(5);

            // Find a valid post to use
            url = targetserver.conn.URL.Replace("xmlrpc.php", "?p=2147483646");
        }
示例#10
0
        public WebInterface()
        {
            if (WebInterfaceEnabled)
            {
                this.server = new Server();
                this.interpreter = new ManagedFileModule();
                this.server.Add(this.interpreter);
                this.reader = new FileModule();
                this.resource = new FileResources("/", Path.Combine(Directory.GetCurrentDirectory(), "WebInterface"));
                this.reader.Resources.Add(resource);
                this.server.Add(this.reader);
                this.server.Add(new SimpleRouter("/", "/index.html"));

                if (WebInterfaceDebug)
                {
                    if (UseSSL)
                    {
                        //
                    }
                    else
                    {
                        //
                    }
                }

                if (UseSSL)
                {
                    try
                    {
                        this.certificate = new X509Certificate2(CertificatePath);
                    }
                    catch (DirectoryNotFoundException)
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine("({0}) <Web Interface> Error: The directory specified could not be found.", DateTime.Now.ToString("hh:mm"));
                    }
                    catch (IOException)
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine("({0}) <Web Interface> Error: A file in the directory could not be accessed.", DateTime.Now.ToString("hh:mm"));
                    }
                    catch (NullReferenceException)
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine("({0}) <Web Interface> File must be a .cer file. Program does not have access to that type of file.", DateTime.Now.ToString("hh:mm"));
                    }
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("({0}) <Web Interface> Loaded Certificate: {1} Valid Date: {2} Expiry Date: {3}", DateTime.Now.ToString("hh:mm"), Path.GetFileName(CertificatePath), this.certificate.NotBefore, this.certificate.NotAfter);
                    this.securelistener = (SecureHttpListener) HttpListener.Create(IPAddress.Parse(ListenAddress), Port, this.certificate);
                    this.securelistener.UseClientCertificate = true;
                    this.server.Add(this.securelistener);
                }
                else
                {
                    this.listener = HttpListener.Create(IPAddress.Parse(ListenAddress), Port);
                    this.server.Add(this.listener);
                }
                this.reader.ContentTypes.Clear();
                this.reader.ContentTypes.Add("default", new ContentTypeHeader("application/octet-stream"));
                foreach (var mimetype in AllowedMimeTypes)
                {
                    var sbstr = mimetype.Split(',');
                    switch (sbstr.Length)
                    {
                        case 2:
                            if (sbstr[0].Length != 0 && sbstr[1].Length != 0)
                            {
                                try
                                {
                                    this.reader.ContentTypes.Add(sbstr[0], new ContentTypeHeader(sbstr[1]));
                                }
                                catch (ArgumentException)
                                {
                                    Console.ForegroundColor = ConsoleColor.Yellow;
                                    Console.WriteLine("({0}) <Web Interface> Config.xml contains duplicate Mime Types.", DateTime.Now.ToString("hh:mm"));
                                }
                            }
                            else
                            {
                                Console.ForegroundColor = ConsoleColor.Yellow;
                                Console.WriteLine("({0}) <Web Interface> Config.xml contains invalid Mime Types.", DateTime.Now.ToString("hh:mm"));
                            }
                            break;
                        default:
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine("({0}) <Web Interface> Config.xml contains invalid Mime Types.", DateTime.Now.ToString("hh:mm"));
                            break;
                    }
                }
                try
                {
                    this.server.Start(5);
                    SessionManager.Start(this.server);
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("({0}) <Web Interface> Running on Port {1}...", DateTime.Now.ToString("hh:mm"), Port);
                }
                catch (SocketException e)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("({0}) <Web Interface> {1}", DateTime.Now.ToString("hh:mm"), e);
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("({0}) <Web Interface> Disabled", DateTime.Now.ToString("hh:mm"));
            }
        }
示例#11
0
        private static void StartWebServer(string uri, string absolutePath, int port)
        {
            // create a server.
            var server = new Server();
            // add module to serve files i.e. act like a web server
            var module = new FileModule();
            
            // Add mime types for Silverlight PivotViewer
            module.ContentTypes.Add("xaml", new ContentTypeHeader("application/xaml+xml"));
            module.ContentTypes.Add("xap", new ContentTypeHeader("application/x-silverlight-2"));
            module.ContentTypes.Add("cxml", new ContentTypeHeader("text/xml"));
            module.ContentTypes.Add("xml", new ContentTypeHeader("text/xml"));
            module.ContentTypes.Add("dzi", new ContentTypeHeader("text/xml"));
            module.ContentTypes.Add("dzc", new ContentTypeHeader("text/xml"));
            
            module.Resources.Add(new FileResources("/", absolutePath));
            server.Add(module);

            // use one http listener.
            server.Add(HttpListener.Create(IPAddress.Any, port));
            // start server, can have max 5 pending accepts.
            server.Start(5);
        }