Exemple #1
0
        public void BindUiControls()
        {
            //URL fields:

            URLUCValueExpression.Init(Context.GetAsContext(mAct.Context), mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.EndPointURL), true, false, UCValueExpression.eBrowserType.Folder);
            URLUserUCValueExpression.Init(Context.GetAsContext(mAct.Context), mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.URLUser), true, false, UCValueExpression.eBrowserType.Folder);
            URLDomainUCValueExpression.Init(Context.GetAsContext(mAct.Context), mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.URLDomain), true, false, UCValueExpression.eBrowserType.Folder);
            URLPasswordUCValueExpression.Init(Context.GetAsContext(mAct.Context), mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.URLPass), true, false, UCValueExpression.eBrowserType.Folder);

            //Network Credential selection radio button:
            NetworkCredentialsRadioButton.Init(typeof(ApplicationAPIUtils.eNetworkCredentials), NetworkCeredentials, mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.NetworkCredentialsRadioButton, ApplicationAPIUtils.eNetworkCredentials.Default.ToString()), NetworkCreds_SelectionChanged);

            //Request Body Selection radio button:
            RequestBodyTypeRadioButton.Init(typeof(ApplicationAPIUtils.eRequestBodyType), BodySelection, mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.RequestBodyTypeRadioButton, ApplicationAPIUtils.eRequestBodyType.FreeText.ToString()), RequestBodyType_Selection);

            //CertficiateRadioButtons :
            CertificateTypeRadioButton.Init(typeof(ApplicationAPIUtils.eCretificateType), CertificateSelection, mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.CertificateTypeRadioButton, ApplicationAPIUtils.eCretificateType.AllSSL.ToString()), CertificateSelection_Changed);

            //Response validation checkbox:
            GingerCore.GeneralLib.BindingHandler.ActInputValueBinding(DoNotFailActionOnBadRespose, CheckBox.IsCheckedProperty, mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.DoNotFailActionOnBadRespose, "False"));

            //Use Legacy JSON Parsing
            GingerCore.GeneralLib.BindingHandler.ObjFieldBinding(UseLegacyJSONParsingCheckBox, CheckBox.IsCheckedProperty, mAct, ActWebAPIBase.Fields.UseLegacyJSONParsing);

            //Request Body fields:
            RequestBodyUCValueExpression.Init(Context.GetAsContext(mAct.Context), mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.RequestBody), true, false, UCValueExpression.eBrowserType.Folder, "*", null);
            RequestBodyUCValueExpression.AdjustHight(200);
            RequestBodyUCValueExpression.ValueTextBox.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;

            //Import Request File
            GingerCore.GeneralLib.BindingHandler.ActInputValueBinding(DoNotImportRequestFile, CheckBox.IsCheckedProperty, mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.ImportRequestFile, "False"));

            //SSL Certificates:
            CertificatePath.Init(Context.GetAsContext(mAct.Context), mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.CertificatePath), true, true, UCValueExpression.eBrowserType.File, "*.*", new RoutedEventHandler(BrowseSSLCertificate));
            CertificatePasswordUCValueExpression.Init(Context.GetAsContext(mAct.Context), mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.CertificatePassword), true, false, UCValueExpression.eBrowserType.Folder);

            //Import Certificate
            GingerCore.GeneralLib.BindingHandler.ActInputValueBinding(DoNotCertificateImportFile, CheckBox.IsCheckedProperty, mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.ImportCetificateFile, "False"));

            //Security:
            SecurityTypeComboBox.Init(mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.SecurityType, ApplicationAPIUtils.eSercurityType.None.ToString()), typeof(ApplicationAPIUtils.eSercurityType), false, null);

            //Authorization:
            AuthTypeComboBox.Init(mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.AuthorizationType, ApplicationAPIUtils.eAuthType.NoAuthentication.ToString()), typeof(ApplicationAPIUtils.eAuthType), false, AuthorizationBox);

            //Authorization
            AuthUserUCValueExpression.Init(Context.GetAsContext(mAct.Context), mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.AuthUsername), true, false, UCValueExpression.eBrowserType.Folder);
            AuthPasswordUCValueExpression.Init(Context.GetAsContext(mAct.Context), mAct.GetOrCreateInputParam(ActWebAPIBase.Fields.AuthPassword), true, false, UCValueExpression.eBrowserType.Folder);

            DynamicElementsGrid.Init(Context.GetAsContext(mAct.Context), mAct.DynamicElements, "Body Content Parameters", "Place Holder", "Value", "Calculated Value");

            HttpHeadersGrid.Init(Context.GetAsContext(mAct.Context), mAct.HttpHeaders, "Request Headers", "Header", "Value", "Calculated Value");

            //FormDataGrid.btnAdd.AddHandler(Button.ClickEvent, new RoutedEventHandler(AddRow));
            SetKeyValuesGrid(mAct.RequestKeyValues);

            CheckNetworkCredentials();
            CheckRequestBodySelection();
            CheckCertificateSelection();
        }
Exemple #2
0
        /// <summary>
        /// Opens the socket and starts listening to a given port and IP
        /// </summary>
        /// <param name="port"></param>
        public void Listen(string ip, int port)
        {
            // Stop listening when application closes
            MstTimer.Instance.OnApplicationQuitEvent += Stop;

            if (ip == "127.0.0.1" | ip == "localhost")
            {
                server = new WebSocketServer(port, UseSsl);
            }
            else
            {
                server = new WebSocketServer(IPAddress.Parse(ip), port, UseSsl);
            }

            if (UseSsl)
            {
                if (string.IsNullOrEmpty(CertificatePath.Trim()))
                {
                    Logs.Error("You are using secure connection, but no path to certificate defined. Stop connection process.");
                    return;
                }

                server.SslConfiguration.ServerCertificate = new X509Certificate2(CertificatePath, CertificatePassword);
            }

            SetupService(server);

            server.Stop();
            server.Start();

            MstUpdateRunner.Instance.Add(this);
        }
Exemple #3
0
        /// <summary>
        /// Opens the socket and starts listening to a given port and IP
        /// </summary>
        /// <param name="port"></param>
        public void Listen(string ip, int port)
        {
            // Stop listening when application closes
            MstTimer.Instance.OnApplicationQuitEvent += Stop;

            if (server != null)
            {
                server.Stop();
            }

            if (ip == "127.0.0.1" | ip == "localhost")
            {
                server = new WebSocketServer(port, UseSecure);
            }
            else
            {
                server = new WebSocketServer(IPAddress.Parse(ip), port, UseSecure);
            }

            if (UseSecure)
            {
                if (string.IsNullOrEmpty(CertificatePath.Trim()))
                {
                    Logs.Error("You are using secure connection, but no path to certificate defined. Stop connection process.");
                    return;
                }

                if (string.IsNullOrEmpty(CertificatePassword.Trim()))
                {
                    server.SslConfiguration.ServerCertificate = new X509Certificate2(CertificatePath);
                }
                else
                {
                    server.SslConfiguration.ServerCertificate = new X509Certificate2(CertificatePath, CertificatePassword);
                }

                server.SslConfiguration.EnabledSslProtocols =
                    System.Security.Authentication.SslProtocols.Tls12
                    | System.Security.Authentication.SslProtocols.Ssl3
                    | System.Security.Authentication.SslProtocols.Default;
            }

            // Setup all services used by server
            SetupService(server);

            // Setup something else if needed
            OnBeforeServerStart?.Invoke(this);

            // Start server
            server.Start();

            // Add this server to updater
            MstUpdateRunner.Instance.Add(this);
        }
Exemple #4
0
        public override void Initialize(IServer server)
        {
            // Setup secure connection
            UserSecure          = MstApplicationConfig.Instance.UseSecure;
            CertificatePath     = MstApplicationConfig.Instance.CertificatePath;
            CertificatePassword = MstApplicationConfig.Instance.CertificatePassword;

            httpPort = Mst.Args.AsInt(Mst.Args.Names.WebPort, httpPort);

            // Initialize server
            httpServer = new HttpServer(httpPort, UserSecure)
            {
                AuthenticationSchemes = authenticationSchemes,
                Realm = realm,
                UserCredentialsFinder = UserCredentialsFinder
            };

            if (UserSecure)
            {
                if (string.IsNullOrEmpty(CertificatePath.Trim()))
                {
                    logger.Error("You are using secure connection, but no path to certificate defined. Stop connection process.");
                    return;
                }

                if (string.IsNullOrEmpty(CertificatePassword.Trim()))
                {
                    httpServer.SslConfiguration.ServerCertificate = new X509Certificate2(CertificatePath);
                }
                else
                {
                    httpServer.SslConfiguration.ServerCertificate = new X509Certificate2(CertificatePath, CertificatePassword);
                }

                httpServer.SslConfiguration.EnabledSslProtocols =
                    System.Security.Authentication.SslProtocols.Tls12
                    | System.Security.Authentication.SslProtocols.Ssl3
                    | System.Security.Authentication.SslProtocols.Default;
            }

            // Initialize controllers list
            surfaceControllers = new Dictionary <Type, IHttpController>();

            // Initialize handlers list
            httpRequestHandlers = new Dictionary <string, OnHttpRequestDelegate>();

            // Find all controllers and add them to server
            foreach (var controller in GetComponentsInChildren <IHttpController>())
            {
                if (surfaceControllers.ContainsKey(controller.GetType()))
                {
                    throw new Exception("A controller already exists in the server: " + controller.GetType());
                }

                surfaceControllers[controller.GetType()] = controller;
                controller.Initialize(this);
            }

            // Start listen to Get request
            httpServer.OnGet += HttpServer_OnGet;

            // Start listen to Post request
            httpServer.OnPost += HttpServer_OnPost;

            // Start listen to Put request
            httpServer.OnPut += HttpServer_OnPut;

            // Start http server
            httpServer.Start();

            if (httpServer.IsListening)
            {
                logger.Info($"Http server is started and listening port: {httpServer.Port}");
            }
        }
Exemple #5
0
        public override void Initialize(IServer server)
        {
            // Setup secure connection
            UserSecure          = MstApplicationConfig.Instance.UseSecure;
            CertificatePath     = MstApplicationConfig.Instance.CertificatePath;
            CertificatePassword = MstApplicationConfig.Instance.CertificatePassword;

            // Set port
            httpPort = Mst.Args.AsInt(Mst.Args.Names.WebPort, httpPort);

            // Set port
            httpAddress = Mst.Args.AsString(Mst.Args.Names.WebAddress, httpAddress);

            // Set root directory
            rootDirectory = Mst.Args.AsString(Mst.Args.Names.WebRootDir, rootDirectory);

            // Initialize server
            httpServer = new HttpServer(System.Net.IPAddress.Parse(httpAddress), httpPort, UserSecure)
            {
                AuthenticationSchemes = authenticationSchemes == AuthenticationSchemes.None ? AuthenticationSchemes.Anonymous : authenticationSchemes,
                Realm = realm,
                UserCredentialsFinder = UserCredentialsFinder
            };

            // Init root directory. Create if exists
            InitRooDirectory();

            if (UserSecure)
            {
                if (string.IsNullOrEmpty(CertificatePath.Trim()))
                {
                    logger.Error("You are using secure connection, but no path to certificate defined. Stop connection process.");
                    return;
                }

                if (string.IsNullOrEmpty(CertificatePassword.Trim()))
                {
                    httpServer.SslConfiguration.ServerCertificate = new X509Certificate2(CertificatePath);
                }
                else
                {
                    httpServer.SslConfiguration.ServerCertificate = new X509Certificate2(CertificatePath, CertificatePassword);
                }

                httpServer.SslConfiguration.EnabledSslProtocols =
                    System.Security.Authentication.SslProtocols.Tls12
                    | System.Security.Authentication.SslProtocols.Ssl3
                    | System.Security.Authentication.SslProtocols.Default;
            }

            // Initialize controllers lists
            SurfaceControllers = new Dictionary <Type, IHttpController>();
            WsControllers      = new Dictionary <Type, IWsController>();

            // Initialize handlers list
            httpRequestHandlers = new Dictionary <string, OnHttpRequestDelegate>();

            // Find all surface controllers and add them to server
            foreach (var controller in GetComponentsInChildren <IHttpController>())
            {
                if (SurfaceControllers.ContainsKey(controller.GetType()))
                {
                    throw new Exception("A controller already exists in the server: " + controller.GetType());
                }

                SurfaceControllers[controller.GetType()] = controller;
                controller.Initialize(this);
            }

            // Find all web socket controllers and add them to server
            foreach (var controller in GetComponentsInChildren <IWsController>())
            {
                if (WsControllers.ContainsKey(controller.GetType()))
                {
                    throw new Exception("A controller already exists in the server: " + controller.GetType());
                }

                WsControllers[controller.GetType()] = controller;
            }

            // Start listen to Get request
            httpServer.OnGet += HttpServer_OnGet;

            // Start listen to Post request
            httpServer.OnPost += HttpServer_OnPost;

            // Start listen to Put request
            httpServer.OnPut += HttpServer_OnPut;

            // Register web socket controller service
            httpServer.AddWebSocketService <WsControllerService>($"/{wsServicePath}", (service) =>
            {
                service.IgnoreExtensions = true;
                service.SetHttpServer(this);
            });

            // Start http server
            httpServer.Start();

            if (httpServer.IsListening)
            {
                logger.Info($"Web socket server is started and listening: {httpServer.Address}:{httpServer.Port}/{wsServicePath}");
                logger.Info($"Http server is started and listening: {httpServer.Address}:{httpServer.Port}");
            }
        }