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 ApplyProcessUnits(string Context) { OperatorAuthentication.AuthedAction(Context, () => { HttpPipelineProcessor.Init(processUnits.ToArray()); }, false, true, PermissionID.RTApplyRProcessUnits, PermissionID.RuntimeAll); }
/// <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 Bind(string AuthContext, string URL) { OperatorAuthentication.AuthedAction(AuthContext, () => { Listener.Prefixes.Add(URL); }, false, true, PermissionID.BindPrefix); }
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 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 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 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)); }
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); }
/// <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 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); }
//static void PrintHint() //{ // Console.Write("["); // Console.ForegroundColor = ConsoleColor.Green; // Console.Write("Local"); // Console.ResetColor(); // Console.Write("]>"); //} static void Check00() { if (GlobalConfiguration.GetListenPrefixesCount(Auth) == 0) { Console.WriteLine("Listening Url Not Found!"); Console.WriteLine("Enter your own url prefixes: (End with \"END\")"); string URL = null; List <string> RecordedUrls = new List <string>(); while ((URL = Console.ReadLine().Trim()).ToUpper() != "END") { if (URL.ToUpper() == "UNDO") { RecordedUrls.RemoveAt(RecordedUrls.Count - 1); } if (!URL.EndsWith("/")) { URL += "/"; //Make sure that the listening url always ends with '/' } RecordedUrls.Add(URL); } GlobalConfiguration.SetListenPrefixes(Auth, RecordedUrls); Console.WriteLine("Done!"); } if (OperatorAuthentication.HasAdmin() is not true) { Console.WriteLine("Create an administrator:"); Console.WriteLine("User Name:"); string Name = Console.ReadLine(); bool isSucceed = false; while (isSucceed is not true) { Console.WriteLine("Enter password for the first time:"); var pw0 = ReadPassword(); Console.WriteLine("Please repeat your password:"******"Class1Admin", true); Auth = OperatorAuthentication.ObtainRTAuth(Name, pw0); Console.WriteLine("Succeed."); isSucceed = true; } else { Console.WriteLine("Password mismatch."); } } } }
static string ObtainAuth() { while (true) { Console.WriteLine("User Name:"); var UN = Console.ReadLine(); Console.WriteLine("Password:"******"Username + Password combination no found, please retry."); } }
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); } }
static void Login() { while (true) { Console.WriteLine("User Name:"); var UN = Console.ReadLine(); Console.WriteLine("Password:"******"Welcome, " + UN); return; } Console.WriteLine("Username + Password combination no found, please retry."); } }
/// <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 void FirstInit() { if (Inited == true) { return; } { var Auth0 = CLUNL.Utilities.RandomTool.GetRandomString(32, CLUNL.Utilities.RandomStringRange.R3); var Auth1 = CLUNL.Utilities.RandomTool.GetRandomString(32, CLUNL.Utilities.RandomStringRange.R3); TrustedInstallerAuth = OperatorAuthentication.ObtainRTAuth(Auth0, Auth1); Auth0 = CLUNL.Utilities.RandomTool.GetRandomString(32, CLUNL.Utilities.RandomStringRange.R3); Auth1 = CLUNL.Utilities.RandomTool.GetRandomString(32, CLUNL.Utilities.RandomStringRange.R3); PipelineAuth = OperatorAuthentication.ObtainRTAuth(Auth0, Auth1); OperatorAuthentication.SetTrustedInstaller(TrustedInstallerAuth); OperatorAuthentication.SetPipelineAuth(PipelineAuth, TrustedInstallerAuth); GlobalConfiguration.SetTrustedInstallerAuth(TrustedInstallerAuth); DomainManager.SetTrustedInstaller(TrustedInstallerAuth); RSServer.SetFunctions(Tools00.ResolveCommand, ServerController.Control, TrustedInstallerAuth); } { //Init MIME-Types try { var count = GlobalConfiguration.GetValue("MIMETYPE.COUNT", TrustedInstallerAuth, "0"); var _count = int.Parse(count); for (int i = 0; i < _count; i++) { var m = GlobalConfiguration.GetValue("MIMETYPE." + i, TrustedInstallerAuth, null); if (m is not null) { var d = m.Split(';'); Tools00.SetMimeType(new(d[0], d[1]), TrustedInstallerAuth); } } } catch (Exception) { } } ServerVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString() + "-Preview"; Inited = true; }
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"); }