public void ApplyProcessUnits(string Context) { OperatorAuthentication.AuthedAction(Context, () => { HttpPipelineProcessor.Init(processUnits.ToArray()); }, false, true, PermissionID.RTApplyRProcessUnits, PermissionID.RuntimeAll); }
public void UnregisterCmdOutProcessUnit(string Context, IPipedProcessUnit unit) { OperatorAuthentication.AuthedAction(Context, () => { CmdOutprocessUnits.Remove(unit); }, false, true, PermissionID.RTUnregisterCmdOutProcessUnit, PermissionID.RuntimeAll); }
/// <summary> /// Create a file in current folder, when the file is already exists or current folder is read-only, returns false. /// </summary> /// <param name="Name"></param> /// <param name="OutItem"></param> /// <returns></returns> public virtual bool CreateFolder(string Auth, string Name, out StorageFolder OutItem) { if (BaseWritePermission is null) { return(CreateFolder(Name, out OutItem)); } StorageFolder sf = null; bool result = false; OperatorAuthentication.AuthedAction(Auth, () => { if (isReadOnly) { result = false; return; } var path = Path.Combine(realPath, Name); if (Directory.Exists(path)) { result = false; } else { Directory.CreateDirectory(path); result = true; } sf = new StorageFolder(); sf.parent = this; sf.SetPath(path); }, false, true, BaseWritePermission); OutItem = sf; return(result); }
/// <summary> /// Create a folder in current folder. /// </summary> /// <param name="Auth"></param> /// <param name="Name"></param> /// <param name="isIgnoreExistence"></param> /// <returns></returns> /// <exception cref="ItemAlreadyExistException"></exception> public virtual StorageFolder CreateFolder(string Auth, string Name, bool isIgnoreExistence) { if (BaseWritePermission is null) { CreateFolder(Name, isIgnoreExistence); } if (isReadOnly) { throw new ItemReadOnlyException(); } StorageFolder storageFolder = null; OperatorAuthentication.AuthedAction(Auth, () => { if (_CreateFolder(Name, out storageFolder) == false) { if (isIgnoreExistence == true) { storageFolder = GetFolder(Auth, Name); } else { throw new ItemAlreadyExistException(); } } }, false, true, BaseWritePermission); return(storageFolder); }
public void Bind(string AuthContext, string URL) { OperatorAuthentication.AuthedAction(AuthContext, () => { Listener.Prefixes.Add(URL); }, false, true, PermissionID.BindPrefix); }
/// <summary> /// Create a file in current folder, when the file is already exists, returns false. /// </summary> /// <param name="Name"></param> /// <param name="OutItem"></param> /// <returns></returns> public virtual bool CreateFile(string Auth, string Name, out StorageFile OutItem) { if (BaseWritePermission is null) { return(CreateFile(Name, out OutItem)); } bool result = false; StorageFile sf = null; OperatorAuthentication.AuthedAction(Auth, () => { if (isReadOnly) { sf = null; result = false; return; } var path = Path.Combine(realPath, Name); if (File.Exists(path)) { result = false; } else { File.Create(path).Close(); result = true; } StorageFile storageFile = new StorageFile(); storageFile.parent = this; storageFile.SetPath(path); sf = storageFile; }, false, true, BaseWritePermission); OutItem = sf; return(result); }
public void ApplyWProcessUnits(string Context) { OperatorAuthentication.AuthedAction(Context, () => { PipelineStreamProcessor.DefaultPublicStreamProcessor.Init(WprocessUnits.ToArray()); }, false, true, PermissionID.RTApplyWProcessUnits, PermissionID.RuntimeAll); }
public void RegisterCmdOutProcessUnit(string Context, IPipedProcessUnit unit) { OperatorAuthentication.AuthedAction(Context, () => { CmdOutprocessUnits.Add(unit); Trace.WriteLine(Language.Query("LWMS.Pipeline.Register.CmdOut", "Registered CmdOut Unit: {0}", unit.GetType().ToString())); }, false, true, PermissionID.RTRegisterCmdOutProcessUnit, PermissionID.RuntimeAll); }
public void RegisterProcessUnit(string Context, IPipedProcessUnit unit) { OperatorAuthentication.AuthedAction(Context, () => { FileInfo fi = new FileInfo(Assembly.GetAssembly(unit.GetType()).FullName); processUnits.Add(MappedType.CreateFrom(unit)); Trace.WriteLine(Language.Query("LWMS.Pipeline.Register.R", "Registered R Unit: {0}", unit.GetType().ToString())); }, false, true, PermissionID.RTRegisterRProcessUnit, PermissionID.RuntimeAll); }
public void ApplyCmdProcessUnits(string Context) { OperatorAuthentication.AuthedAction(Context, () => { var processor = new DefaultProcessor(); processor.Init(CmdOutprocessUnits.ToArray()); Output.SetCoreStream(Context, processor); }, false, true, PermissionID.RTApplyCmdProcessUnits, PermissionID.RuntimeAll); }
public static Assembly GetAssembly(string Auth, string Name, int Version = 0) { Assembly v = null; OperatorAuthentication.AuthedAction(Auth, () => { v = DLLs[Name][Version]; }, false, true, PermissionID.Core_SBS_Read, PermissionID.Core_SBS_All); return(v); }
public static List <KeyValuePair <string, string> > ListValues(string Auth) { List <KeyValuePair <string, string> > rs = new(); OperatorAuthentication.AuthedAction(Auth, () => { if (ConfigurationData != null) { foreach (var item in ConfigurationData) { rs.Add(new(item.Key, item.Value)); }
/// <summary> /// Add or update a mime type to the known MIME-Type list. /// </summary> /// <param name="MType"></param> /// <param name="Auth"></param> public static void SetMimeType(KeyValuePair <string, string> MType, string Auth) { OperatorAuthentication.AuthedAction(Auth, () => { if (types.ContainsKey(MType.Key)) { types[MType.Key] = MType.Value; } else { types.Add(MType.Key, MType.Value); } }, false, true, PermissionID.ModifyRuntimeConfig, PermissionID.ModifyConfig, PermissionID.ConfigAll); }
public static void UpdateMappedTypes(string AuthContext, string LibFileName) { OperatorAuthentication.AuthedAction(AuthContext, () => { foreach (var item in MappedType.MappedTypeObjectCollection) { if (item.LibFileName == LibFileName) { item.Update(AuthContext); } } }, false, true, PermissionID.Core_SBS_Update, PermissionID.Core_SBS_All); }
public static void SetRealModuleRoot(string AuthContext, string ModuleRootPath) { OperatorAuthentication.AuthedAction(AuthContext, () => { StackTrace st = new StackTrace(2); var item = st.GetFrame(1); var ModuleName = item.GetMethod().DeclaringType.Assembly.GetName().Name; if (ModuleName != "LWMS.Core" && ModuleName != "LWMS.Core.Configuration") { throw new Exception("Illegal access from:" + ModuleName); } _ModuleRoot.SetPath(ModuleRootPath); }, false, true, PermissionID.SetPermission); }
public void UnregisterProcessUnit(string Context, IPipedProcessUnit unit) { OperatorAuthentication.AuthedAction(Context, () => { for (int i = 0; i < processUnits.Count; i++) { if (processUnits[i].TargetObject == unit) { processUnits.RemoveAt(i); break; } } }, false, true, PermissionID.RTUnregisterRProcessUnit, PermissionID.RuntimeAll); }
public static bool Release(string Auth) { bool v = false; OperatorAuthentication.AuthedAction(Auth, () => { if (ConfigurationData != null) { ConfigurationData.Dispose(); ConfigurationData = null; v = true; } }, false, true, PermissionID.ReleaseConfig, PermissionID.ModifyConfig); return(v); }
/// <summary> /// Delete all items including files and folders. /// </summary> /// <param name="Auth">In case this operation requires permission</param> public virtual void DeleteAllItems(string Auth, bool IgnoreDeletionError = false) { if (DeletePermissionID == null) { DeleteAllItems(); } else { OperatorAuthentication.AuthedAction(Auth, () => { if (IgnoreDeletionError) { foreach (var item in GetFolders(Auth)) { try { item.Delete(Auth); } catch (Exception) { } } foreach (var item in GetFiles(Auth)) { try { item.Delete(Auth); } catch (Exception) { } } } else { foreach (var item in GetFolders(Auth)) { item.Delete(Auth); } foreach (var item in GetFiles(Auth)) { item.Delete(Auth); } } }, false, true, DeletePermissionID); } }
/// <summary> /// Generic Values. /// </summary> /// <param name="Key"></param> /// <param name="Auth"></param> /// <param name="fallback"></param> /// <returns></returns> public static string GetValue(string Key, string Auth, string fallback = null) { string value = fallback; OperatorAuthentication.AuthedAction(Auth, () => { if (ConfigurationData != null) { var v = ConfigurationData.FindValue(Key.ToUpper()); if (v is not null) { value = v; } } }, false, true, PermissionID.ReadConfig); return(value); }
/// <summary> /// Get a contained file. Return false when cannot find it. /// </summary> /// <param name="Name"></param> /// <param name="OutItem"></param> /// <param name="CaseSensitivity"></param> /// <returns></returns> public virtual bool GetFile(string Auth, string Name, out StorageFile OutItem, bool CaseSensitivity = false) { if (BaseReadPermission is null) { return(GetFile(Name, out OutItem, CaseSensitivity)); } StorageFile storageItem = new StorageFile(); bool v = false; OperatorAuthentication.AuthedAction(Auth, () => { storageItem.DeletePermissionID = DeletePermissionID; storageItem.BaseWritePermission = BaseWritePermission; storageItem.BaseReadPermission = BaseReadPermission; var entries = Directory.EnumerateFiles(realPath); string Target = Path.Combine(realPath, Name); string TARGET = Target.ToUpper(); foreach (var item in entries) { if (CaseSensitivity == false) { if (item.ToUpper() == TARGET) { storageItem.SetPath(Target); storageItem.Parent = this; v = true; return; } } else { if (item == Target) { storageItem.SetPath(Target); storageItem.Parent = this; v = true; return; } } } storageItem = null; }, false, true, BaseReadPermission); OutItem = storageItem; return(v); }
public static Assembly LoadFromFile(string Auth, string PathToDLL) { Assembly v = null; OperatorAuthentication.AuthedAction(Auth, () => { var guid = Guid.NewGuid(); var temp = Path.Combine(Path.GetTempPath(), guid.ToString()); FileInfo fi = new(PathToDLL); Directory.CreateDirectory(temp); var Final = fi.CopyTo(Path.Combine(temp + fi.Name)); v = Assembly.LoadFrom(Final.FullName); if (!DLLs.ContainsKey(fi.Name)) { DLLs.Add(fi.Name, new()); } DLLs[fi.Name].Add(v); }, false, true, PermissionID.Core_SBS_Load, PermissionID.Core_SBS_All); return(v); }
public static void SetProperty(string Auth, int Property, object value) { OperatorAuthentication.AuthedAction(Auth, () => { switch (Property) { case 0: { BeautifyConsoleOutput = (bool)value; } break; case 1: { EnableConsoleOutput = (bool)value; } break; case 2: { WriteToFile = (bool)value; } break; case 3: { _LOG_WATCH_INTERVAL = (int)value; } break; case 4: { _MAX_LOG_SIZE = (int)value; } break; default: break; } }, false, true, PermissionID.ModifyRuntimeConfig, PermissionID.RuntimeAll, PermissionID.Log_All); }
/// <summary> /// Register and initialize a specified module. /// </summary> /// <param name="item"></param> /// <returns></returns> public static bool Register(string AuthContext, string item) { bool __ = false; try { OperatorAuthentication.AuthedAction(AuthContext, () => { try { var asm = Assembly.LoadFrom(item); FileInfo fi = new(item); var TPS = asm.GetTypes(); foreach (var TP in TPS) { if (typeof(IManageCommand).IsAssignableFrom(TP)) { var MC = (IManageCommand)Activator.CreateInstance(TP); Trace.WriteLine(Language.Query("LWMS.Commands.Found", "Found Manage Command:{0},{1}", MC.CommandName, TP.ToString())); ManageCommands.Add(MC.CommandName, MappedType.CreateFrom(MC)); var alias = MC.Alias; foreach (var MCA in alias) { ManageCommandAliases.Add(MCA, MappedType.CreateFrom(MC)); } } } __ = true; } catch (Exception) { Trace.Write(Language.Query("LWMS.Commands.Error.LoadModule", "Cannot load management module: {0}", item)); } }, false, true, PermissionID.RegisterCmdModule, PermissionID.CmdModuleAll); } catch (Exception) { Trace.Write(Language.Query("LWMS.Commands.Error.LoadModule", "Cannot load management module: {0}", item)); } return(__); }
/// <summary> /// Get a contained folder. Throw an StorageItemNotExistException when cannot find it. /// </summary> /// <param name="Auth"></param> /// <param name="Name"></param> /// <param name="CaseSensitivity">Whether case sensitive</param> /// <returns></returns> public virtual StorageFolder GetFolder(string Auth, string Name, bool CaseSensitivity = false) { if (BaseReadPermission is null) { return(GetFolder(Name, CaseSensitivity)); } StorageFolder storageItem = new StorageFolder(); OperatorAuthentication.AuthedAction(Auth, () => { storageItem.DeletePermissionID = DeletePermissionID; storageItem.BaseWritePermission = BaseWritePermission; storageItem.BaseReadPermission = BaseReadPermission; var F = GetFolder(Auth, Name, out storageItem, CaseSensitivity); if (F == false) { throw new StorageItemNotExistException(Path.Combine(realPath, Name)); } }, false, true, BaseReadPermission); return(storageItem); }
public virtual StorageFile CreateFile(string Auth, string Name) { if (BaseWritePermission is null) { CreateFile(Name); } StorageFile f = null; OperatorAuthentication.AuthedAction(Auth, () => { if (isReadOnly) { throw new ItemReadOnlyException(); } StorageFile storageFile; if (CreateFile(Auth, name, out storageFile) == false) { throw new ItemAlreadyExistException(); } f = storageFile; }, false, true, BaseWritePermission); return(f); }
public void Invoke(string AuthContext, params CommandPack[] args) { if (args.Length == 0) { PrintHelp(AuthContext); return; } OperatorAuthentication.AuthedAction(AuthContext, () => { foreach (var item in args) { if (item.PackTotal.ToUpper() == "WEBROOT") { DirectoryInfo directoryInfo = new DirectoryInfo(GlobalConfiguration.GetWebSiteContentRoot(AuthContext)); Output.WriteLine(directoryInfo.FullName, AuthContext); } else if (item.PackTotal.ToUpper() == "WEBROOTDIR") { DirectoryInfo directoryInfo = new DirectoryInfo(GlobalConfiguration.GetWebSiteContentRoot(AuthContext)); foreach (var dir in directoryInfo.EnumerateDirectories()) { Output.WriteLine("D:" + dir.FullName, AuthContext); } foreach (var file in directoryInfo.EnumerateFiles()) { Output.WriteLine("F:" + file.FullName, AuthContext); } } else if (item.ToUpper() == "USINGMEM") { var prop = Process.GetCurrentProcess(); Output.WriteLine("Using Memory(KB):" + prop.WorkingSet64 / 1024.0, AuthContext); } } }, false, true, "Basic.ViewRuntimeInfo"); }
/// <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); } }
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"); }
public void Invoke(string AuthContext, params CommandPack[] args) { OperatorAuthentication.AuthedAction(AuthContext, () => { if (args.Length > 0) { string operation = args[0]; if (operation.ToUpper() == "RELEASE") { if (GlobalConfiguration.Release(AuthContext) == true) { Output.WriteLine(Language.Query("ManageCmd.Config.Release.Tip0", "GlobalConfiguration file is released and changes will not be saved."), AuthContext); } else { Output.SetForegroundColor(ConsoleColor.Yellow, AuthContext); Output.WriteLine(Language.Query("ManageCmd.Config.Release.Tip1", "GlobalConfiguration file is already released."), AuthContext); Output.ResetColor(AuthContext); } } else if (operation.ToUpper() == "RESUME") { GlobalConfiguration.LoadConfiguation(); GlobalConfiguration.ClearLoadedSettings(); Output.WriteLine(Language.Query("ManageCmd.Config.Resume.Tip0", "Resumed."), AuthContext); Output.WriteLine(Language.Query("ManageCmd.Config.Resume.Tip1", "GlobalConfiguration changes will be automatically saved now."), AuthContext); } else if (operation.ToUpper() == "RELOAD") { GlobalConfiguration.LoadConfiguation(); GlobalConfiguration.ClearLoadedSettings(); } else if (operation.ToUpper() == "LS") { var list = GlobalConfiguration.ListValues(AuthContext); foreach (var item in list) { Output.WriteLine(item.Key + " : " + item.Value, AuthContext); } } else if (operation.ToUpper() == "SET") { if (args.Length >= 3) { string setitem = args[1].ToUpper(); if (setitem == "BUF_LENGTH") { GlobalConfiguration.SetBUF_LENGTH(AuthContext, int.Parse(args[2])); } else if (setitem == "LOG_WATCH_INTERVAL") { GlobalConfiguration.LOG_WATCH_INTERVAL = int.Parse(args[2]); } else if (setitem == "MAX_LOG_SIZE") { GlobalConfiguration.MAX_LOG_SIZE = int.Parse(args[2]); } else if (setitem == "WEBROOT" || setitem == "WEBSITEROOT" || setitem == "WEBSITECONTENTROOT" || setitem == "WEBCONTENTROOT" || setitem == "CONTENTROOT") { GlobalConfiguration.SetWebSiteContentRoot(AuthContext, args[2]); } else if (setitem == "DEFAULTPAGE") { GlobalConfiguration.SetDefaultPage(AuthContext, args[2]); } else if (setitem == "404PAGE") { GlobalConfiguration.SetPage404(AuthContext, args[2]); } else if (setitem == "LANGUAGE") { var a = args[2].ToString().Replace("\"", null); a = args[2].ToString().Replace("\'", null); GlobalConfiguration.Language = args[2]; Output.SetForegroundColor(ConsoleColor.Yellow, AuthContext); Output.WriteLine("Language is set to:" + GlobalConfiguration.Language, AuthContext); Output.ResetColor(AuthContext); Language.Initialize(args[2]); } else if (setitem == "ENABLERANGE") { try { GlobalConfiguration.SetEnableRange(AuthContext, bool.Parse(args[2])); } catch (Exception) { Output.SetForegroundColor(ConsoleColor.Red, AuthContext); Output.WriteLine("Key \"EnableRange\" only accepts bool type(true and false)!", AuthContext); Output.ResetColor(AuthContext); } } else if (setitem == "LOGUA") { try { GlobalConfiguration.SetLogUA(AuthContext, bool.Parse(args[2])); } catch (Exception) { Output.SetForegroundColor(ConsoleColor.Red, AuthContext); Output.WriteLine("Key \"LogUA\" only accepts bool type(true and false)!", AuthContext); Output.ResetColor(AuthContext); } } else { GlobalConfiguration.SetValue(setitem, args[2], AuthContext); // Output.WriteLine(Language.Query("ManageCmd.Config.UnidentifiedKey", "Unidentified Key: {0}", setitem), AuthContext); } } else { Output.SetForegroundColor(ConsoleColor.Red, AuthContext); Output.WriteLine(Language.Query("ManageCmd.Config.Set.ParameterMismatch", "Arguments does not match: Config set <key> <value>"), AuthContext); Output.ResetColor(AuthContext); } } else if (operation.ToUpper() == "ADD") { if (args.Length >= 3) { string setitem = args[1].ToUpper(); if (setitem == "LISTENPREFIX" || setitem == "LISTEN") { GlobalConfiguration.AddListenPrefix(AuthContext, args[2]); } } else { Output.SetForegroundColor(ConsoleColor.Red, AuthContext); Output.WriteLine(Language.Query("ManageCmd.Config.Add.ParameterMismatch", "Arguments does not match: Config add <key> <value>"), AuthContext); Output.ResetColor(AuthContext); } } else if (operation.ToUpper() == "RM" || operation.ToUpper() == "REMOVE") { if (args.Length >= 3) { string setitem = args[1].ToUpper(); if (setitem == "LISTENPREFIX" || setitem == "LISTEN") { try { GlobalConfiguration.RemoveListenPrefix(AuthContext, args[2]); } catch (Exception) { } } else { GlobalConfiguration.DelValue(setitem, AuthContext); } } else { Output.WriteLine(Language.Query("ManageCmd.Config.Remove.ParameterMismatch", "Arguments does not match: Config remove <key>"), AuthContext); } } else if (operation.ToUpper() == "H" || operation.ToUpper() == "-H" || operation.ToUpper() == "--H" || operation.ToUpper() == "HELP" || operation.ToUpper() == "?" || operation.ToUpper() == "-?" || operation.ToUpper() == "--?") { OutputHelp(AuthContext); } } else { Output.SetForegroundColor(ConsoleColor.Yellow, AuthContext); Output.WriteLine(Language.Query("ManageCmd.Help.Config.Error.NoOperation", "Please specify an operation."), AuthContext); Output.ResetColor(AuthContext); OutputHelp(AuthContext); } }, false, true, "Core.BasicConfig"); }
/// <summary> /// Get a contained folder. Return false when cannot find it. /// </summary> /// <param name="Auth">Authentication Context</param> /// <param name="Name"></param> /// <param name="CaseSensitivity"></param> /// <param name="OutFolder"></param> /// <returns></returns> public virtual bool GetFolder(string Auth, string Name, out StorageFolder OutFolder, bool CaseSensitivity = false) { if (BaseReadPermission is null) { return(GetFolder(Name, out OutFolder, CaseSensitivity)); } StorageFolder storageItem = new StorageFolder(); bool v = false; OperatorAuthentication.AuthedAction(Auth, () => { if (isSystemRoot) { switch (Name) { case PredefinedRootFolders.WebRoot: storageItem = ApplicationStorage.Webroot; v = true; return; case PredefinedRootFolders.Configuration: storageItem = ApplicationStorage.Configuration; v = true; return; case PredefinedRootFolders.Logs: storageItem = ApplicationStorage.Logs; v = true; return; default: storageItem = null; v = false; return; } } storageItem.DeletePermissionID = DeletePermissionID; storageItem.BaseWritePermission = BaseWritePermission; storageItem.BaseReadPermission = BaseReadPermission; var entries = Directory.EnumerateDirectories(realPath); string Target = Path.Combine(realPath, Name); string TARGET = Target.ToUpper(); foreach (var item in entries) { if (CaseSensitivity == false) { if (item.ToUpper() == TARGET) { storageItem.SetPath(Target); storageItem.Parent = this; v = true; return; } } else { if (item == Target) { storageItem.SetPath(Target); storageItem.Parent = this; v = true; return; } } } storageItem = null; }, false, true, BaseReadPermission); OutFolder = storageItem; return(v); }