Esempio n. 1
0
        public object Connection_Connect()
        {
            WorkContext.NeedsSession();
            var who = "{0}-{1}".Args(WorkContext.EffectiveCallerIPEndPoint.Address, WorkContext.Session.User);

            var terminal = AppRemoteTerminal.MakeNewTerminal(App);

            var info = terminal.Connect(who);

            var handle = Guid.NewGuid();

            App.ObjectStore.CheckIn(handle, terminal);

            return(GetLogicResult(new { handle, info }));
        }
Esempio n. 2
0
        public object Connect(string who = null)
        {
            WorkContext.NeedsSession();
            var terminal = WorkContext.Session[TERMINAL_SESSION_KEY] as AppRemoteTerminal;

            if (terminal != null)
            {
                return new { Status = "Already connected", WhenConnected = terminal.WhenConnected }
            }
            ;


            if (who.IsNullOrWhiteSpace())
            {
                who = "{0}-{1}".Args(WorkContext.Request.UserHostAddress, WorkContext.Session.User);
            }
            terminal = AppRemoteTerminal.MakeNewTerminal(App);
            var info = terminal.Connect(who);

            WorkContext.Session[TERMINAL_SESSION_KEY] = terminal;
            return(info);
        }
Esempio n. 3
0
 public Appl(AppRemoteTerminal terminal, IConfigSectionNode args) : base(terminal, args)
 {
 }
Esempio n. 4
0
        private static int interactiveConsoleMainBody(BootArgs args)
        {
            Console.CancelKeyPress += (_, e) => {
                var app = s_Application;//capture
                if (app != null)
                {
                    app.Stop();
                    e.Cancel = true;
                }
            };

            try
            {
                try
                {
                    Console.WriteLine("Azos Sky Application Host Process");
                    Console.WriteLine("Rev 2.0 July 3 2021 / Radio-86RK");
                    Console.WriteLine();
                    Console.WriteLine("Booting server daemon...");
                    Start(args);
                    Console.WriteLine("...server started");
                    Console.WriteLine("Application: {0} / `{1}`".Args(s_Application.AppId, s_Application.Name));
                    Console.WriteLine("Boot daemon: {0} / `{1}`".Args(s_Server.GetType().Name, s_Server.Name));
                    Console.WriteLine("Environment: {0}".Args(s_Application.EnvironmentName));
                    Console.WriteLine("Services provided: ");
                    Console.WriteLine("  " + s_Server.ServiceDescription.Default("n/a"));
                    Console.WriteLine();
                    Console.WriteLine("To stop the process enter 'exit' or 'stop' commands or hit <CTL+C>");

                    using (var term = new AppRemoteTerminal())
                    {
                        s_Application.InjectInto(term);

                        #region Perform SYSTEM Implicit Grant
                        //Impersonate the current call flow as local SYSTEM user.
                        //Warning: this code here is a very special case: a root server console.
                        //Never use the similar code in business applications as it bypasses all security
                        //by injecting the caller with SYSTEM-level privilege which results in implicit grant
                        //of all permission checks.
                        //Note: The session is injected with blank SysAuthToken() so this session is only granted locally
                        //and not capable of impersonating system on remote hosts
                        ExecutionContext.__SetThreadLevelSessionContext(new BaseSession(Guid.NewGuid(), 123)
                        {
                            User = new User(BlankCredentials.Instance, new SysAuthToken(), UserStatus.System, "sys", "Implicit grant", Rights.None)
                        });
                        #endregion

                        var wasPrompt = false;
                        while (s_Application.Active)
                        {
                            if (!wasPrompt)
                            {
                                Console.Write("{0}@{1}\n$ ".Args(s_Application.AppId, Platform.Computer.HostName));
                                wasPrompt = true;
                            }

                            if (!Console.KeyAvailable)
                            {
                                if (s_Application.WaitForStopOrShutdown(50))
                                {
                                    break;
                                }
                                continue;
                            }

                            var cmd = Console.ReadLine();
                            wasPrompt = false;

                            if (!s_Application.Active)
                            {
                                break;
                            }
                            if (cmd.IsNullOrWhiteSpace())
                            {
                                continue;
                            }
                            if (cmd.IsOneOf("quit", "exit", "stop"))
                            {
                                break;
                            }

                            try
                            {
                                var response = term.Execute(cmd);

                                if (response.StartsWith(AppRemoteTerminal.MARKUP_PRAGMA))
                                {
                                    ConsoleUtils.WriteMarkupContent(response);
                                }
                                else
                                {
                                    Console.WriteLine(response);
                                }
                            }
                            catch (Exception eterm)
                            {
                                ConsoleUtils.Error("Terminal error: ");
                                var wrap = new WrappedExceptionData(eterm, true);
                                Console.WriteLine(wrap.ToJson(JsonWritingOptions.PrettyPrintRowsAsMap));
                            }
                        }
                    }
                    Console.WriteLine("...shutting down now");
                    Console.WriteLine();
                }
                finally
                {
                    Stop();
                }

                return(0);
            }
            catch (Exception error)
            {
                ConsoleUtils.Error("App Root exception, details: ");
                var wrap = new WrappedExceptionData(error, true);
                Console.WriteLine(wrap.ToJson(JsonWritingOptions.PrettyPrintRowsAsMap));

                return(-100);
            }
        }
Esempio n. 5
0
        public static int consoleMainBody(string[] args)
        {
            Console.CancelKeyPress += (_, e) => {
                var app = s_Application;//capture
                if (app != null)
                {
                    app.Stop();
                    e.Cancel = true;
                }
            };

            try
            {
                try
                {
                    Console.WriteLine("Azos Sky Application Host Process");
                    Console.WriteLine("Rev 1.0 Nov 2020 / Radio-86RK");
                    Console.WriteLine();
                    Console.WriteLine("Booting server daemon...");
                    Start(args);
                    Console.WriteLine("...server started");
                    Console.WriteLine("Application: {0} / `{1}`".Args(s_Application.AppId, s_Application.Name));
                    Console.WriteLine("Boot daemon: {0} / `{1}`".Args(s_Server.GetType().Name, s_Server.Name));
                    Console.WriteLine("Environment: {0}".Args(s_Application.EnvironmentName));
                    Console.WriteLine("Services provided: ");
                    Console.WriteLine("  " + s_Server.ServiceDescription.Default("n/a"));
                    Console.WriteLine();
                    Console.WriteLine("To stop the process enter 'exit' or 'stop' commands or hit <CTL+C>");

                    using (var term = new AppRemoteTerminal())
                    {
                        s_Application.InjectInto(term);

                        //Impersonate the current call flow as SYSTEM
                        ExecutionContext.__SetThreadLevelSessionContext(new BaseSession(Guid.NewGuid(), 123)
                        {
                            User = new User(BlankCredentials.Instance, new SysAuthToken(), UserStatus.System, "sys", "Implicit grant", Rights.None)
                        });

                        while (s_Application.Active)
                        {
                            Console.Write("{0}@{1}\n$ ".Args(s_Application.AppId, Azos.Platform.Computer.HostName));
                            var cmd = Console.ReadLine();
                            if (cmd.IsNullOrWhiteSpace())
                            {
                                continue;
                            }
                            if (cmd.IsOneOf("quit", "exit", "stop"))
                            {
                                break;
                            }

                            try
                            {
                                var response = term.Execute(cmd);

                                if (response.StartsWith(AppRemoteTerminal.MARKUP_PRAGMA))
                                {
                                    ConsoleUtils.WriteMarkupContent(response);
                                }
                                else
                                {
                                    Console.WriteLine(response);
                                }
                            }
                            catch (Exception eterm)
                            {
                                ConsoleUtils.Error("Terminal error: ");
                                var wrap = new WrappedExceptionData(eterm, true);
                                Console.WriteLine(wrap.ToJson(JsonWritingOptions.PrettyPrintRowsAsMap));
                            }
                        }
                    }
                    Console.WriteLine("...shutting down now");
                    Console.WriteLine();
                }
                finally
                {
                    Stop();
                }

                return(0);
            }
            catch (Exception error)
            {
                ConsoleUtils.Error("App Root exception, details: ");
                var wrap = new WrappedExceptionData(error, true);
                Console.WriteLine(wrap.ToJson(JsonWritingOptions.PrettyPrintRowsAsMap));

                return(-100);
            }
        }