public static void SetTrustedInstallerAuth(string auth) { if (TrustedInstaller == null) { TrustedInstaller = auth; ApplicationStorage.SetTrustedInstaller(TrustedInstaller); InitGlobalConfiguration(); { try { _WebSiteContentRoot = null; _ = WebSiteContentRoot; ApplicationStorage.SetRealWebRoot(TrustedInstaller, _WebSiteContentRoot); } catch { } try { _WebModuleStorage = null; _ = WebSiteModuleStorageRoot; ApplicationStorage.SetRealModuleRoot(TrustedInstaller, _WebModuleStorage); } catch { } } LWMSTraceListener.SetTrustedInstaller(auth); } }
public void Invoke(string AuthContext, params CommandPack[] args) { if (args.Length > 0) { switch (args[0].PackTotal.ToUpper()) { case "LS": case "LIST": { foreach (var item in ApplicationStorage.Logs.GetFiles(AuthContext)) { Output.WriteLine(item.Name, AuthContext); } } break; case "CLEAR": { ApplicationStorage.Logs.DeleteAllItems(AuthContext, true); } break; case "NEW": { LWMSTraceListener.NewLogFile(AuthContext); } break; case "STOPWATCH": { LWMSTraceListener.StopWatch(AuthContext); } break; case "HELP": case "?": case "-?": case "--?": case "--H": case "-H": PrintHelp(AuthContext); break; default: break; } } else { PrintHelp(AuthContext); } }
public PipelineData Process(PipelineData Input) { PipedRoutedWROption option = (PipedRoutedWROption)Input.Options; if (option.PipedRoutedWROperation == PipedRoutedWROperation.WRITE) { LWMSTraceListener.WriteFile((string)Input.PrimaryData); } else if (option.PipedRoutedWROperation == PipedRoutedWROperation.WRITELINE) { LWMSTraceListener.WriteFileLine((string)Input.PrimaryData); } return(Input); }
public void Invoke(string AuthContext, params CommandPack[] args) { OperatorAuthentication.AuthedAction(AuthContext, () => { for (int i = 0; i < args.Length; i++) { var item = args[i]; switch (item.ToUpper()) { case "/DISABLEBEAUTIFYCONSOLE": LWMSTraceListener.SetProperty(AuthContext, 0, false); //LWMSTraceListener.BeautifyConsoleOutput = false; break; case "/ENABLEBEAUTIFYCONSOLE": LWMSTraceListener.SetProperty(AuthContext, 0, true); //LWMSTraceListener.BeautifyConsoleOutput = true; break; case "/DISABLECONSOLE": LWMSTraceListener.SetProperty(AuthContext, 1, false); //LWMSTraceListener.EnableConsoleOutput = false; break; case "/DISABLELOGTOFILE": LWMSTraceListener.SetProperty(AuthContext, 2, false); //LWMSTraceListener.WriteToFile = false; break; case "/ENABLECONSOLE": LWMSTraceListener.SetProperty(AuthContext, 1, true); //LWMSTraceListener.EnableConsoleOutput = true; break; default: { switch (item.PackParted[0].ToUpper()) { case "BUF_LENGTH": { int B; int.TryParse(args[i].PackParted[1], out B); GlobalConfiguration.Set_BUF_LENGTH_RT(AuthContext, B); Output.WriteLine(Language.Query("ManageCmd.RuntimeConfig.SetValue", "{0} is temporarily set to {1} without saving to GlobalConfiguration file.", "BUT_LENGTH", B.ToString()), AuthContext); } break; case "WEBROOT": { string path = args[i].PackParted[1]; GlobalConfiguration.Set_WebRoot_RT(AuthContext, path); Output.WriteLine(Language.Query("ManageCmd.RuntimeConfig.SetValue", "{0} is temporarily set to {1} without saving to GlobalConfiguration file.", "WebRoot", path), AuthContext); } break; default: break; } } break; } } }, false, true, "Core.Config.Runtime"); }
static void Main(string[] args) { Environment.CurrentDirectory = (new FileInfo(typeof(Program).Assembly.Location)).Directory.FullName; //Force working directory to where the program exists. { var Auth0 = CLUNL.Utilities.RandomTool.GetRandomString(32, CLUNL.Utilities.RandomStringRange.R3); var Auth1 = CLUNL.Utilities.RandomTool.GetRandomString(32, CLUNL.Utilities.RandomStringRange.R3); Auth = OperatorAuthentication.ObtainRTAuth(Auth0, Auth1); OperatorAuthentication.SetLocalHostAuth(Auth); LWMSCoreServer.FirstInit(); } Console.WriteLine("Copyright (C) 2020-2022 Creeper Lv"); Console.WriteLine("This software is licensed under the MIT License"); var _commands = Tools00.ResolveCommand(Environment.CommandLine); bool ignore_Arg = false; _commands.RemoveAt(0);//Remove start command. if (_commands.Count > 0) { if (_commands[0].PackTotal.ToUpper() == "/PREBOOT") { _commands.RemoveAt(0); LWMSCoreServer.LoadCommandsFromManifest(); ServerController.Control(Auth, _commands.ToArray()); ignore_Arg = true; } else if (_commands[0].PackTotal.ToUpper() == "/NOBOOT") { _commands.RemoveAt(0); LWMSCoreServer.LoadCommandsFromManifest(); ServerController.Control(Auth, _commands.ToArray()); return; } else { } } Console.OutputEncoding = Encoding.UTF8; Console.InputEncoding = Encoding.UTF8; LWMSTraceListener.SetProperty(Auth, 0, true); //LWMSTraceListener.BeautifyConsoleOutput = true; Console.BackgroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.White; Console.Write("This software is in active development and extremely unstable, do not use it in production environment!"); Console.ResetColor(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("LWMS - LightWeight Managed Server"); Console.WriteLine(); Check00(); LWMSCoreServer coreServer = new LWMSCoreServer(); //coreServer.Bind("http://+:8080/"); //string p = Configuration.BasePath; coreServer.Start(8); Console.WriteLine("The server is now running good."); Login(); if (ignore_Arg == false) { if (args.Length > 0) { var cmd = new List <CommandPack>(); foreach (var item in _commands) { cmd.Add(item); } ServerController.Control(Auth, cmd.ToArray()); } } CommandListener(); }
/// <summary> /// Response to the command packs. /// </summary> /// <param name="args"></param> public static void Control(string Auth, params CommandPack[] args) { Trace.WriteLine(Language.Query("LWMS.Commands.ReceieveCommand", "Received Command:", args[0])); if (!OperatorAuthentication.IsAuthed(Auth, "Basic.ExecuteCommand")) { var name = OperatorAuthentication.GetAuthIDFromAuth(Auth); Trace.WriteLine(Language.Query("LWMS.Command.AuthReject", "Operation rejected: auth {0} have no permission.", name == null?Auth:name)); return; } if (args[0].ToUpper() == "SHUTDOWN" || args[0].ToUpper() == "EXIT" || args[0].ToUpper() == "CLOSE") { try { OperatorAuthentication.AuthedAction(Auth, () => { Output.WriteLine(Language.Query("LWMS.Goodbye", "Goodbye."), Auth); if (LWMSTraceListener.WriteToFile) { LWMSTraceListener.FlushImmediately(); } Environment.Exit(0); }, false, false, "ServerControl.Shutdown", "ServerControl.All"); } catch (Exception) { Trace.WriteLine(Language.Query("LWMS.Auth.Reject", "Operation rejected: auth {0} have no permission of {1}.", Auth, "ServerControl.Shutdown")); } } else if (args[0].ToUpper() == "VER" || args[0].ToUpper() == "VERSION") { Output.WriteLine("", Auth); Output.WriteLine(Language.Query("LWMS.Commands.Ver.Shell", "Shell: {0}", Assembly.GetEntryAssembly().GetName().Version.ToString()), Auth); Output.WriteLine(Language.Query("LWMS.Commands.Ver.Core", "Core: {0}", Assembly.GetExecutingAssembly().GetName().Version.ToString()), Auth); Output.WriteLine("", Auth); } else if (args[0].ToUpper() == "CLS" || args[0].ToUpper() == "CLEAR") { Output.Clear(Auth); //Console.Clear(); } else if (args[0].ToUpper() == "SUSPEND") { try { OperatorAuthentication.AuthedAction(Auth, () => { if (LWMSCoreServer.Listener != null) { LWMSCoreServer.Listener.Abort(); LWMSCoreServer.Listener.Close(); LWMSCoreServer.Listener = null; LWMSCoreServer.isSuspend = true; Output.WriteLine(Language.Query("Server.Suspended", "Listener is now suspended."), Auth); } }, false, false, "ServerControl.Suspend", "ServerControl.ListenerControl", "ServerControl.All"); } catch (Exception) { Trace.WriteLine(Language.Query("LWMS.Auth.Reject", "Operation rejected: auth {0} have no permission of {1}.", Auth, "ServerControl.Suspend")); } } else if (args[0].ToUpper() == "RESUME") { //LWMSCoreServer.Listener.Start(); // I do not know why HttpListener.Start() will not resume. try { OperatorAuthentication.AuthedAction(Auth, () => { if (LWMSCoreServer.Listener == null) { LWMSCoreServer.Listener = new System.Net.HttpListener(); foreach (var item in GlobalConfiguration.GetListenPrefixes(LWMSCoreServer.TrustedInstallerAuth)) { LWMSCoreServer.Listener.Prefixes.Add(item); } LWMSCoreServer.Listener.Start(); LWMSCoreServer.isSuspend = false; Output.WriteLine(Language.Query("Server.Resumed", "Listener is now resumed."), Auth); } }, false, false, "ServerControl.Resume", "ServerControl.ListenerControl", "ServerControl.All"); } catch (Exception) { Trace.WriteLine(Language.Query("LWMS.Auth.Reject", "Operation rejected: auth {0} have no permission of {1}.", Auth, "ServerControl.Resume")); } } else { foreach (var item in ManageCommands) { if (item.Key.ToUpper() == args[0].PackTotal.ToUpper()) { List <CommandPack> ManageCommandArgs = new List <CommandPack>(args); try { ManageCommandArgs.RemoveAt(0); try { (item.Value.TargetObject as IManageCommand).Invoke(Auth, ManageCommandArgs.ToArray()); } catch (Exception e) { Trace.Write($"Error in {item.Value}: {e}"); } } catch (Exception) { } return; } } foreach (var item in ManageCommandAliases) { if (item.Key.ToUpper() == args[0].PackTotal.ToUpper()) { List <CommandPack> ManageCommandArgs = new List <CommandPack>(args); try { ManageCommandArgs.RemoveAt(0); try { (item.Value.TargetObject as IManageCommand).Invoke(Auth, ManageCommandArgs.ToArray()); } catch (Exception e) { Output.SetForegroundColor(ConsoleColor.Red, Auth); Output.Write($"Error in {item.Value}: {e}", Auth); Output.ResetColor(Auth); } } catch (Exception) { } return; } } Output.WriteLine(Language.Query("LWMS.Commands.Error.NotFound", "Command Not Found."), Auth); } }