public UserHandler(Orion orion) { database = orion.Database; SqlTable table = new SqlTable("Users", new SqlColumn("ID", MySqlDbType.Int32) { Primary = true, AutoIncrement = true }, new SqlColumn("Username", MySqlDbType.VarChar, 32) { Unique = true }, new SqlColumn("Password", MySqlDbType.VarChar, 128), new SqlColumn("UUID", MySqlDbType.VarChar, 128), new SqlColumn("Usergroup", MySqlDbType.Text), new SqlColumn("Registered", MySqlDbType.Text), new SqlColumn("LastAccessed", MySqlDbType.Text), new SqlColumn("KnownIPs", MySqlDbType.Text) ); SqlTableCreator creator = new SqlTableCreator(database, database.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder) new SqliteQueryCreator() : new MysqlQueryCreator()); creator.EnsureTableStructure(table); UserCache = new OrderedCache <User>(orion.Config.MaxUserCacheSize); UserCache.FlushEvent += OnFlush; }
private static void Main(string[] args) { Console.Title = "Orion.GlobalOffensive"; var proc = Process.GetProcessesByName("csgo")[0]; Orion.Attach(proc); while (true) { Orion.Objects.Update(); Console.Clear(); Console.WriteLine("State: {0}\n\n", Orion.Client.State); if (Orion.Client.InGame && Orion.Me != null && Orion.Me.IsValid) { var me = Orion.Me; Console.WriteLine("ID:\t\t{0}", me.Id); Console.WriteLine("Health:\t\t{0}", me.Health); Console.WriteLine("Position:\t{0}", me.Position); Console.WriteLine("Team:\t\t{0}", me.Team); Console.WriteLine("ObjectCount:\t{0}", Orion.Objects.Players.Count); var t = me.Target; Console.WriteLine("Target:\t{0}", t != null ? t.Id.ToString() : "none"); } Thread.Sleep(500); } }
/// <summary> /// Sets the database connection and the initial log level. /// </summary> /// <param name="orion">Orion</param> /// <param name="textlogFilepath">File path to a backup text log in case the SQL log fails</param> /// <param name="clearTextLog"></param> public SqlLog(Orion orion, string textlogFilepath, bool clearTextLog) { _orion = orion; _failures = new List <LogInfo>(orion.Config.MaxSqlLogFailureCount); _database = orion.Database; //FileName = String.Format("{0}://database", _database.GetSqlType()); _backupLog = new TextLog(orion, textlogFilepath, clearTextLog); SqlTable table = new SqlTable("Logs", new SqlColumn("ID", MySqlDbType.Int32) { AutoIncrement = true, Primary = true }, new SqlColumn("TimeStamp", MySqlDbType.Text), new SqlColumn("LogLevel", MySqlDbType.Int32), new SqlColumn("Caller", MySqlDbType.Text), new SqlColumn("Message", MySqlDbType.Text) ); SqlTableCreator creator = new SqlTableCreator(_database, _database.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder) new SqliteQueryCreator() : new MysqlQueryCreator()); creator.EnsureTableStructure(table); }
public BanHandler(Orion orion) { _orion = orion; database = orion.Database; SqlTable table = new SqlTable("Bans", new SqlColumn("ID", MySqlDbType.Int32) { Primary = true, AutoIncrement = true }, new SqlColumn("Username", MySqlDbType.VarChar, 32) { Unique = true }, new SqlColumn("UUID", MySqlDbType.VarChar, 128), new SqlColumn("IP", MySqlDbType.Text, 20), new SqlColumn("Expiration", MySqlDbType.Int64) ); SqlTableCreator creator = new SqlTableCreator(database, database.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder) new SqliteQueryCreator() : new MysqlQueryCreator()); creator.EnsureTableStructure(table); }
/// <summary> /// The on action executing. /// </summary> /// <param name="filterContext"> /// The filter context. /// </param> public override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); if (filterContext.RequestContext.HttpContext.Request.Cookies["OrionUser"] == null) { filterContext.Result = new RedirectResult("http://orion.shanecraven.com/Federation/Login?returnurl=http://zeus.shanecraven.com/Auth/Orion&appid=Zeus"); return; } var userKey = filterContext.RequestContext.HttpContext.Request.Cookies["OrionUser"].Value; var orion = new Orion(new DeleteMeLogger()); orion.Communicator.ApiAuthenticator = GetAuthenticatior(); var userProfile = Task.Run(() => orion.CreateUserController() .GetUserProfile(new Key() {ApiKey = userKey, Type = KeyType.UserTempKey}, "Zeus")); userProfile.Wait(); var userProfileWaited = userProfile.Result; if (userProfileWaited.Result?.Email == null || userProfileWaited.Result.Email.Equals(string.Empty)) { // filterContext.RequestContext.HttpContext.Request.Cookies["OrionUser"].Expires = DateTime.Now.AddDays(-1); var cookie = new HttpCookie("OrionUser") {Expires = DateTime.Now.AddDays(-1)}; filterContext.HttpContext.Response.Cookies.Add(cookie); filterContext.Result = new RedirectResult("http://orion.shanecraven.com/Federation/Login?returnurl=http://zeus.shanecraven.com/Auth/Orion&appid=Zeus"); return; } filterContext.HttpContext.Items["OrionUser"] = userProfileWaited.Result; filterContext.HttpContext.Items["OrionUserKey"] = userKey; }
/// <summary> /// Called when a request hits a filtered web API action. /// </summary> /// <param name="context"> /// The context. /// </param> /// <param name="cancellationToken"> /// The cancellation token. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken) { // Ensure that the auth header and scheme have been set if (context.Request.Headers.Authorization?.Parameter == null || context.Request.Headers.Authorization.Scheme == null) { this.HandleFailCase(context); return; } // Check that the correct scheme was used. if (!context.Request.Headers.Authorization.Scheme.Equals(Scheme)) { this.HandleFailCase(context); return; } var orionContext = new Orion(new DeleteMeLogger()) { Communicator = { ApiAuthenticator = new OrgStandardAuthenticator() { PublicKey = new Key() { ApiKey = this.publicKey, Type = KeyType.ApplicationPublicKey }, SecertKey = new Key() { ApiKey = this.secretKey, Type = KeyType.ApplicationSecretKey } } } }; // Call the Orion API and request the user information bound to the key! var profile = await orionContext.CreateUserController().GetUserProfileAsync(new Key() { ApiKey = context.Request.Headers.Authorization.Parameter, Type = KeyType.UserTempKey }, this.organisationPublicKey, this.allowRoamingUser); if (profile.Result != null) { var principal = new OrionPrincipal(context.Request.Headers.Authorization.Parameter) { User = profile.Result }; context.Principal = principal; } else { this.HandleFailCase(context); } }
/// <summary> /// The handle request. /// </summary> /// <param name="request"> /// The requst. /// </param> /// <param name="response"> /// The response. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task HandleRequest(IServerMessage request, IServerMessage response) { var userOrionKey = ParserFactory.GetDataParser(request.DataType).ParseData <Key>(request.User); if (userOrionKey == null) { // Do something here to stop processing and return some error to the server to // inform the client that auth has failed. request.User = null; await this.Successor.HandleRequest(request, response); } var orionContext = new Orion(new DeleteMeLogger()) { Communicator = { ApiAuthenticator = new OrgStandardAuthenticator() { PublicKey = this.Config.SystemPublicKey, SecertKey = this.Config.SystemSecretKey } } }; // Set the authentication Information var user = await orionContext.CreateUserController().GetUserProfile(userOrionKey, "Zeus"); if (user?.Result?.Meta == null || !user.Result.Meta.Any(x => x.Key.Equals("UserType"))) { request.User = null; } else { // Parse the Orion user data into local user data var firstOrDefault = user.Result.Meta.FirstOrDefault(x => x.Key.Equals("UserType")); if (firstOrDefault != null) { var parsedUser = UserFactory.GetUser( (UserType) (Convert.ToInt32(firstOrDefault.Value))); parsedUser.Email = user.Result.Email; parsedUser.Firstname = user.Result.Firstname; parsedUser.Surname = user.Result.Surname; parsedUser.Phone = user.Result.Phone; request.User = ParserFactory.GetDataParser(request.DataType).SerializeData(parsedUser); } } // Check the user type which should be contained in User Meta. await this.Successor.HandleRequest(request, response); }
/// <summary> /// Called when a request hits a filtered web API action. /// </summary> /// <param name="context"> /// The context. /// </param> /// <param name="cancellationToken"> /// The cancellation token. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken) { // Ensure that the auth header and scheme have been set if (context.Request.Headers.Authorization?.Parameter == null || context.Request.Headers.Authorization.Scheme == null) { this.HandleFailCase(context); return; } // Check that the correct scheme was used. if (!context.Request.Headers.Authorization.Scheme.Equals(Scheme)) { this.HandleFailCase(context); return; } var orionContext = new Orion(new DeleteMeLogger()) { Communicator = { ApiAuthenticator = new OrgStandardAuthenticator() { PublicKey = new Key() { ApiKey = this.publicKey, Type = KeyType.ApplicationPublicKey }, SecertKey = new Key() { ApiKey = this.secretKey, Type = KeyType.ApplicationSecretKey } } } }; var systemAccountContext = await orionContext.CreateAuthenticationController().ConvertVerificationKeyToContextAsync(new Key() { ApiKey = context.Request.Headers.Authorization.Parameter, Type = KeyType.ApplicationTempKey }); if (systemAccountContext.Result != null) { var principal = new OrionSystemAccountPrincipal(context.Request.Headers.Authorization.Parameter) { Context = systemAccountContext.Result }; context.Principal = principal; } else { this.HandleFailCase(context); } }
/// <summary> /// The handle request. /// </summary> /// <param name="request"> /// The requst. /// </param> /// <param name="response"> /// The response. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task HandleRequest(IServerMessage request, IServerMessage response) { var userOrionKey = ParserFactory.GetDataParser(request.DataType).ParseData<Key>(request.User); if (userOrionKey == null) { // Do something here to stop processing and return some error to the server to // inform the client that auth has failed. request.User = null; await this.Successor.HandleRequest(request, response); } var orionContext = new Orion(new DeleteMeLogger()) { Communicator = { ApiAuthenticator = new OrgStandardAuthenticator() { PublicKey = this.Config.SystemPublicKey, SecertKey = this.Config.SystemSecretKey } } }; // Set the authentication Information var user = await orionContext.CreateUserController().GetUserProfile(userOrionKey, "Zeus"); if (user?.Result?.Meta == null || !user.Result.Meta.Any(x => x.Key.Equals("UserType"))) { request.User = null; } else { // Parse the Orion user data into local user data var firstOrDefault = user.Result.Meta.FirstOrDefault(x => x.Key.Equals("UserType")); if (firstOrDefault != null) { var parsedUser = UserFactory.GetUser( (UserType) (Convert.ToInt32(firstOrDefault.Value))); parsedUser.Email = user.Result.Email; parsedUser.Firstname = user.Result.Firstname; parsedUser.Surname = user.Result.Surname; parsedUser.Phone = user.Result.Phone; request.User = ParserFactory.GetDataParser(request.DataType).SerializeData(parsedUser); } } // Check the user type which should be contained in User Meta. await this.Successor.HandleRequest(request, response); }
private void RelatedCalls() { Console.WriteLine("##RELATED CALLS:" + Environment.NewLine); Console.WriteLine("*Rocket Factory:"); Factory <SpaceRocket> rocketFactory = new Factory <SpaceRocket>(); // Example of using interface functions. IProduct <SpaceRocket> rocketProduct = rocketFactory.Create <Dragon>(); rocketProduct.Operate(); IProduct <SpaceRocket> rocketProductProtonM = rocketFactory.Create <ProtonM>(); rocketProductProtonM.Operate(); // Example of using a product specific function. Falcon falcon = rocketFactory.Create <Falcon>(); falcon.Operate(); falcon.FalconSpecificationOperation(); Console.WriteLine(new string('-', 25)); Console.WriteLine("*Plane Factory:"); Factory <SpacePlane> planeFactory = new Factory <SpacePlane>(); IProduct <SpacePlane> orion = planeFactory.Create <Orion>(); orion.Operate(); Console.WriteLine(new string('-', 25)); Console.WriteLine("*Rocket and Plane Factory:"); Orion orion1 = rocketFactory.Create <Orion>(); orion1.Operate(); orion1.OrionSpecificationOperation(); Orion orion2 = planeFactory.Create <Orion>(); orion2.Operate(); orion2.OrionSpecificationOperation(); Console.WriteLine(new string('-', 25)); }
/// <summary> /// The on action executing. /// </summary> /// <param name="filterContext"> /// The filter context. /// </param> public override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); if (filterContext.RequestContext.HttpContext.Request.Cookies["OrionUser"] == null) { filterContext.Result = new RedirectResult("http://orion.shanecraven.com/Federation/Login?returnurl=http://zeus.shanecraven.com/Auth/Orion&appid=Zeus"); return; } var userKey = filterContext.RequestContext.HttpContext.Request.Cookies["OrionUser"].Value; var orion = new Orion(new DeleteMeLogger()); orion.Communicator.ApiAuthenticator = GetAuthenticatior(); var userProfile = Task.Run(() => orion.CreateUserController() .GetUserProfile(new Key() { ApiKey = userKey, Type = KeyType.UserTempKey }, "Zeus")); userProfile.Wait(); var userProfileWaited = userProfile.Result; if (userProfileWaited.Result?.Email == null || userProfileWaited.Result.Email.Equals(string.Empty)) { // filterContext.RequestContext.HttpContext.Request.Cookies["OrionUser"].Expires = DateTime.Now.AddDays(-1); var cookie = new HttpCookie("OrionUser") { Expires = DateTime.Now.AddDays(-1) }; filterContext.HttpContext.Response.Cookies.Add(cookie); filterContext.Result = new RedirectResult("http://orion.shanecraven.com/Federation/Login?returnurl=http://zeus.shanecraven.com/Auth/Orion&appid=Zeus"); return; } filterContext.HttpContext.Items["OrionUser"] = userProfileWaited.Result; filterContext.HttpContext.Items["OrionUserKey"] = userKey; }
public Hasher(Orion orion) { _orion = orion; }
/// <summary> /// Creates the log file stream /// </summary> /// <param name="orion"></param> /// <param name="filename">The output filename. This file will be overwritten if 'clear' is set.</param> /// <param name="clear">Whether or not to clear the log file on initialization.</param> public TextLog(Orion orion, string filename, bool clear) { _orion = orion; FileName = filename; _logWriter = new StreamWriter(filename, !clear); }
/// <summary> /// Authenticate a request with Orion federation /// </summary> /// <param name="filterContext"> /// The filter context. /// </param> public void OnAuthentication(AuthenticationContext filterContext) { if (filterContext.HttpContext.Request.QueryString["orion_logout"] != null) { if (filterContext.HttpContext.Request.QueryString["orion_logout"].Equals("true")) { this.DeleteOrionCookie(filterContext.HttpContext.Request, filterContext.HttpContext.Response); var returnFrom = string.Empty; if (filterContext.HttpContext.Request.QueryString["return_from"] != null) { returnFrom = "?returnUrl=" + filterContext.HttpContext.Request.QueryString["return_from"]; } filterContext.Result = new RedirectResult($"{this.federationServer}/Logout{Uri.EscapeDataString(returnFrom)}"); return; } } string orionAuthKey = null; var authKeyPresent = false; if (filterContext.HttpContext.Request.QueryString["orion_key"] != null) { authKeyPresent = true; orionAuthKey = filterContext.HttpContext.Request.QueryString["orion_key"]; } else { orionAuthKey = this.ExtractOrionCookie(filterContext.HttpContext.Request); } if (orionAuthKey == null) { this.HandleAuthenticationFailed(filterContext, authKeyPresent); return; } var orion = new Orion(new DeleteMeLogger()) { Communicator = { ApiAuthenticator = new OrgStandardAuthenticator() { PublicKey = new Key() { ApiKey = this.publicKey, Type = KeyType.ApplicationPublicKey }, SecertKey = new Key() { ApiKey = this.secretKey, Type = KeyType.ApplicationSecretKey } } } }; var userProfileTask = Task.Run(() => orion.CreateUserController().GetUserProfileAsync(new Key() { ApiKey = orionAuthKey, Type = KeyType.UserTempKey }, this.applicationId, this.federationMode == FederationMode.RoamEnabled || this.federationMode == FederationMode.RoamOnly)); userProfileTask.Wait(30000); var userProfile = userProfileTask.Result; if (userProfile.Result == null) { this.HandleAuthenticationFailed(filterContext, authKeyPresent); return; } if (this.ExtractOrionCookie(filterContext.HttpContext.Request) == null || authKeyPresent) { var cookie = new HttpCookie("OrionFederationKey") { Expires = DateTime.Now.AddDays(5), Value = orionAuthKey }; filterContext.HttpContext.Response.Cookies.Add(cookie); } if (authKeyPresent) { this.RefreshKeyUrl(filterContext); return; } filterContext.HttpContext.Items["FederationStatus"] = new FederationStatus() { Authenticated = true, IsOptional = this.isOptional }; filterContext.Principal = new OrionPrincipal(orionAuthKey) { User = userProfile.Result, UserKey = new Key() { ApiKey = orionAuthKey, Type = KeyType.UserTempKey } }; }
private void InitDevices() { TRM138 pump1 = new TRM138 { Title = "Насос3", ModbusID = 8 }; //0 pump1.OnError += Device_OnError; devices.Add(pump1); MK110_8D_4R pump1m1 = new MK110_8D_4R { Title = "Насос3м1", ModbusID = 32 }; //1 pump1m1.OnError += Device_OnError; devices.Add(pump1m1); MK110_8D_4R pump1m2 = new MK110_8D_4R { Title = "Насос3м2", ModbusID = 48 }; //2 pump1m2.OnError += Device_OnError; devices.Add(pump1m2); TRM138 pump2 = new TRM138 { Title = "Насос4", ModbusID = 88 }; //3 pump2.OnError += Device_OnError; devices.Add(pump2); MK110_8D_4R pump2m1 = new MK110_8D_4R { Title = "Насос4м1", ModbusID = 64 }; //4 pump2m1.OnError += Device_OnError; devices.Add(pump2m1); MK110_8D_4R pump2m2 = new MK110_8D_4R { Title = "Насос4м2", ModbusID = 80 }; //5 pump2m2.OnError += Device_OnError; devices.Add(pump2m2); ME110 me = new ME110 { Title = "МЭ", ModbusID = 220 }; //6 me.OnError += Device_OnError; devices.Add(me); MV110_8A tankP = new MV110_8A { Title = "РВС_P", ModbusID = 96 }; //7 tankP.OnError += Device_OnError; devices.Add(tankP); MK110_8D_4R tankL1 = new MK110_8D_4R { Title = "РВС_L1", ModbusID = 128 }; //8 tankL1.OnError += Device_OnError; devices.Add(tankL1); MK110_8D_4R tankL2 = new MK110_8D_4R { Title = "РВС_L2", ModbusID = 144 }; //9 tankL2.OnError += Device_OnError; devices.Add(tankL2); MK110_8D_4R tankL3 = new MK110_8D_4R { Title = "РВС_L3", ModbusID = 160 }; //10 tankL3.OnError += Device_OnError; devices.Add(tankL3); MK110_8D_4R tankL4 = new MK110_8D_4R { Title = "РВС_L4", ModbusID = 176 }; //11 tankL4.OnError += Device_OnError; devices.Add(tankL4); Orion orion = new Orion { Title = "Орион", ModbusID = 30 }; //12 orion.OnError += Device_OnError; devices.Add(orion); // далее изменения от октября //необходимо добавить все устройства и указать номер modbus TRM138 pistonTRM = new TRM138 { Title = "Поршневые насосы1", ModbusID = 24 }; //13 pistonTRM.OnError += Device_OnError; devices.Add(pistonTRM); MK110_8D_4R pistonMK = new MK110_8D_4R { Title = "Поршневые насосы МК", ModbusID = 56 }; //14 pistonMK.OnError += Device_OnError; devices.Add(pistonMK); MV110_8A valves1 = new MV110_8A { Title = "Задвижки1", ModbusID = 104 }; //15 valves1.OnError += Device_OnError; devices.Add(valves1); MV110_8A valves2 = new MV110_8A { Title = "Задвижки2", ModbusID = 112 }; //16 valves2.OnError += Device_OnError; devices.Add(valves2); UPES upes1 = new UPES { Title = "УПЭС1", ModbusID = 2 }; upes1.OnError += Device_OnError; devices.Add(upes1); UPES upes2 = new UPES { Title = "УПЭС2", ModbusID = 3 }; upes2.OnError += Device_OnError; devices.Add(upes2); UPES upes3 = new UPES { Title = "УПЭС3", ModbusID = 4 }; upes3.OnError += Device_OnError; devices.Add(upes3); DeviceMapping(); }