Пример #1
0
        public void Start(int port)
        {
            try
            {
                // Module manager handles all modules in the server
                var moduleManager = new ModuleManager();

                // Let's serve our downloaded files (Windows 7 users)
                var fileService = new DiskFileService("/", Settings.WebServerFolder);

                // Create the file module and allow files to be listed.
                var module = new FileModule(fileService) { ListFiles = false };

                var routerModule = new RouterModule();

                // Add the module
                //moduleManager.Add(module);
                moduleManager.Add(new WebServerModule());

                //moduleManager.Add(new BodyDecodingModule(new UrlFormattedDecoder()));

                // And start the server.
                var server = new HttpServer(moduleManager);

                server.Start(IPAddress.Any, port);
            }
            catch (Exception ex)
            {
                Log.Error("Unable to start web server ", ex);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            //LogManager.Assign(new SimpleLogManager<ConsoleLogger>());

            // Module manager handles all modules in the server
            var moduleManager = new ModuleManager();

            // Let's serve our downloaded files (Windows 7 users)
            var fileService = new DiskFileService("/", string.Format(@"C:\Users\{0}\Downloads", Environment.UserName));

            // Create the file module and allow files to be listed.
            var module = new FileModule(fileService) {AllowFileListing = true};

            // Add the module
            moduleManager.Add(module);
            moduleManager.Add(new MyModule());

            moduleManager.Add(new MyModule2());
            // And start the server.
            var server = new HttpServer(moduleManager);
            server.Start(IPAddress.Any, 0);
            Console.WriteLine("PORT " + server.LocalPort);

            //TrySendARequest(server);

            Console.ReadLine();
        }
Пример #3
0
        static void Main(string[] args)
        {
            //LogManager.Assign(new SimpleLogManager<ConsoleLogger>());

            // Module manager handles all modules in the server
            var moduleManager = new ModuleManager();

            // Let's serve our downloaded files (Windows 7 users)
            var fileService = new DiskFileService("/", string.Format(@"C:\Users\{0}\Downloads", Environment.UserName));

            // Create the file module and allow files to be listed.
            var module = new FileModule(fileService) {ListFiles = true};

            // Add the module
            moduleManager.Add(module);
            moduleManager.Add(new MyModule());

            moduleManager.Add(new MyModule2());
            // And start the server.
            var server = new HttpServer(moduleManager);
            server.Start(IPAddress.Any, 0);
            Console.WriteLine("PORT " + server.LocalPort);

            var request =
                @"GET /?signature=1dfea26808d632903549c69d78558fce1c418405&echostr=5867553698596935317&timestamp=1365661332&nonce=1366146317 HTTP/1.0
User-Agent:Mozilla/4.0
Host:58.215.164.183
Pragma:no-cache
Connection/Value:Keep-Alive

";
            var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socket.Connect(IPAddress.Loopback, server.LocalPort);
            socket.Send(Encoding.UTF8.GetBytes(request));
            var buffer = new byte[65535];
            var len = socket.Receive(buffer, 0, buffer.Length, SocketFlags.None);
            var answer = Encoding.UTF8.GetString(buffer, 0, len);
            Console.WriteLine(answer);
            len = socket.Receive(buffer, 0, buffer.Length, SocketFlags.None);
            answer = Encoding.UTF8.GetString(buffer, 0, len);
            Console.WriteLine(answer);

            Console.ReadLine();
        }
Пример #4
0
        private void StartWebServer(int httpPort)
        {
            if (!isWebServerStarted)
            {
                //if (Log != null)
                //    Log(this, "Starting web server... ", false, LogLevel.Normal);

                try
                {
                    var moduleManager = new ModuleManager();

                    //string root = Path.GetPathRoot(Assembly.GetExecutingAssembly().Location);
                    string root = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\WebSite\";

                    var fileService = new DiskFileService("/", root);
                    var module = new FileModule(fileService) { ListFiles = false };

                    // Add the module
                    moduleManager.Add(new RootModule());
                    moduleManager.Add(module);
                    //moduleManager.Add(new BodyDecodingModule(new UrlFormattedDecoder()));

                    // And start the server.
                    webServer = new HttpServer(moduleManager);
                    webServer.Start(IPAddress.Any, httpPort);

                    isWebServerStarted = true;
                }
                catch (Exception)
                {
                    isWebServerStarted = false;
                }

                //if (Log != null)
                //    Log(this, isWebServerStarted ? "Success." : "Failed.", true, isWebServerStarted ? LogLevel.Success : LogLevel.Error);
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            LogManager.Assign(new SimpleLogManager<ConsoleLogger>());

            // Module manager handles all modules in the server
            var moduleManager = new ModuleManager();

            // Let's serve our downloaded files (Windows 7 users)
            var fileService = new DiskFileService("/", string.Format(@"C:\Users\{0}\Downloads", Environment.UserName));

            // Create the file module and allow files to be listed.
            var module = new FileModule(fileService) {ListFiles = true};

            // Add the module
            moduleManager.Add(module);
            moduleManager.Add(new BodyDecodingModule(new UrlFormattedDecoder()));
            moduleManager.Add(new MyModule());

            // And start the server.
            var server = new HttpServer(moduleManager);
            server.Start(IPAddress.Any, 8080);

            Console.ReadLine();
        }
Пример #6
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");
            }

            //create module manager to add all modules to admin webserver
            adminModuleManager = new ModuleManager();

            //Handle the requests for static files
            var fileService = new DiskFileService("/assets/", YAMS.Core.RootFolder + "\\web\\assets\\");
            var assets = new FileModule(fileService) { AllowFileListing = false };
            adminModuleManager.Add(assets);
            
            //Handle requests to API
            adminModuleManager.Add(new Web.AdminAPI());
            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");
            }

            if (Database.GetSetting("EnablePortForwarding", "YAMS") == "true")
            {
                Networking.OpenUPnP(Convert.ToInt32(YAMS.Database.GetSetting("AdminListenPort", "YAMS")), "Admin website", YAMS.Database.GetSetting("YAMSListenIP", "YAMS"));
            }

            if (Database.GetSetting("EnablePublicSite", "YAMS") == "true")
            {
                //Add any server specific folders
                publicModuleManager = new ModuleManager();
                publicModuleManager.Add(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\\");
                    publicModuleManager.Add(new FileModule(new DiskFileService("/servers/" + intServerID + "/renders/", Core.StoragePath + intServerID + "\\renders\\")));
                    if (!Directory.Exists(Core.StoragePath + intServerID + "\\backups\\")) Directory.CreateDirectory(Core.StoragePath + intServerID + "\\backups\\");
                    publicModuleManager.Add(new FileModule(new DiskFileService("/servers/" + intServerID + "/backups/", Core.StoragePath + intServerID + "\\backups\\")));
                }

                //Handle requests to API
                publicModuleManager.Add(new Web.PublicAPI());
                //publicServer.Add(HttpListener.Create(IPAddress.Any, Convert.ToInt32(YAMS.Database.GetSetting("PublicListenPort", "YAMS"))));

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

                //Open firewall ports
                if (Database.GetSetting("EnableOpenFirewall", "YAMS") == "true")
                {
                    Networking.OpenFirewallPort(Convert.ToInt32(YAMS.Database.GetSetting("PublicListenPort", "YAMS")), "Public website");
                }

                if (Database.GetSetting("EnablePortForwarding", "YAMS") == "true")
                {
                    Networking.OpenUPnP(Convert.ToInt32(YAMS.Database.GetSetting("PublicListenPort", "YAMS")), "Public website", YAMS.Database.GetSetting("YAMSListenIP", "YAMS"));
                }
            }
        }