Exemple #1
0
        public static ActionModelSend Pack(this ActionDM action, bool?isOnline = null)
        => new ActionModelSend()
        {
            IsOnline      = (isOnline != null ? isOnline.Value : ApiSocketServer.IsActionOnline(action)),
            Lander        = action.landerid == null ? null : LandersCache.Instance.Get(action.landerid.Value).Name,
            Prelander     = action.prelanderid == null ? null : PrelandersCache.Instance.Get(action.prelanderid.Value).Name,
            Provider      = action.providerid == null ? null : ProvidersCache.Instance.Get(action.providerid.Value),
            Country       = action.countryid == null ? null : CountryCache.Instance.Get(action.countryid.Value),
            PrelanderData = (!string.IsNullOrEmpty(action.prelander_data) && action.prelanderid.HasValue) ? PrelandersCache.Instance.ConstructTagsForAction(action.prelanderid.Value, action.prelander_data) : null,

            actionid                 = action.actionid,
            trackingid               = action.trackingid,
            affid                    = action.affid,
            pubid                    = action.pubid,
            input_redirect           = action.input_redirect,
            input_email              = action.input_email,
            input_contact            = action.input_contact,
            has_subscription         = action.has_subscription,
            has_chargeback           = action.has_chargeback,
            has_refund               = action.has_refund,
            times_charged            = action.times_charged,
            times_upsell             = action.times_upsell,
            has_redirectedToProvider = action.has_redirectedToProvider,
            has_stolen               = action.has_stolen,
            updated                  = action.updated,
            created                  = action.created
        };
        private void DoWork(object state)
        {
            LastInteraction = DateTime.Now;
            if (ApiSocketServer.Sessions != null && ApiSocketServer.Sessions.Count == 0)
            {
                return;
            }

            foreach (var session in ApiSocketServer.Sessions)
            {
                // if last interaction is more than 3 minutes
                if ((DateTime.Now - session.Value.LastInteraction).TotalMinutes >= 3 ||

                    // if session is created more than 15 minutes
                    (DateTime.Now - session.Value.Created).TotalMinutes >= 15 ||

                    //  if session is created more than minute ago and still do not have open connection
                    ((DateTime.Now - session.Value.Created).TotalMinutes > 1 && session.Value.WebSocket.State != System.Net.WebSockets.WebSocketState.Open))
                {
                    ApiSocketServer.CloseSession(session.Value);
                }
            }

            foreach (var session in DashboardSocketsServer.Sessions)
            {
                //  if session is created more than minute ago and still do not have open connection
                if (((DateTime.Now - session.Value.Created).TotalMinutes > 1 && session.Value.WebSocket.State != System.Net.WebSockets.WebSocketState.Open))
                {
                    DashboardSocketsServer.CloseSession(session.Value);
                }
            }
        }
        public async void OnUserRedirected(string key, ReceivingUserRedirected model)
        {
            try
            {
                this.Socket.Send(key, new SendingUserRedirected()
                {
                }.Pack(true));

                this.Socket.Action.Data.has_redirectedToProvider = true;
                this.Socket.Action.Data.UpdateLater();
                ApiSocketServer.CloseSession(this.Socket);

                await this.Socket.Database.TransactionalManager.RunAsync();
            }
            catch (Exception e)
            {
                this.Socket.Logging.StartLoggin("")
                .Where("lp-redirect")
                .Add(model)
                .OnException(e);
                this.Socket.Send(new FatalModel()
                {
                    Action = "OnUserRedirected", Exception = e.ToString()
                }.Pack(false, "error500"));
            }
        }
Exemple #4
0
 public IActionResult KillAll()
 {
     foreach (var session in ApiSocketServer.Sessions)
     {
         ApiSocketServer.CloseSession(session.Value);
     }
     return(this.Index());
 }
Exemple #5
0
        private static void startConnect()
        {
            Thread.Sleep(5000);
            logger.Info("START CONNECT TO SERVER");
            ApiSocketServer apiSocketServer = new ApiSocketServer();

            apiSocketServer.StartServer();
            //new EndProgramThread().Start();
            KiwoomApiController kiwoomApiController = KiwoomApiController.Instance;

            kiwoomApiController.Init();
            ApiSocketClient.Instance.ConnectServer();
        }
        public async void OnRegistration(string key, ReceivingRegistrationModel model)
        {
            try
            {
                MSLogger logger = new MSLogger();

#if DEBUG
                if (model.url.StartsWith("file:"))
                {
                    string parameters = "";
                    if (model.url.Contains("?"))
                    {
                        parameters = "?" + model.url.Split('?')[1];
                    }

                    model.url = "https://claim.giveaways-online.com/l15/" + parameters;
                }
#endif

                DomainManager domainManager = DomainManager.InitiatePrelander(model.url);

                if (domainManager.HasError)
                {
                    this.Socket.Send(key, new SendingRegistrationModel()
                    {
                    }.Pack(false, domainManager.ErrorMessage));
                    throw new Exception(string.Format("Prelander is not found for domain '{0}'", domainManager.Url));
                    return;
                }
                this.Prelander = domainManager.Prelander;

                //
                // Check for all neceseary parameters in url
                //

                if (!domainManager.Queries.ContainsKey("dbg"))
                {
                    if (!domainManager.Queries.ContainsKey("msisdn"))
                    {
                        this.Socket.Send(key, new SendingRegistrationModel()
                        {
                        }.Pack(false, "Missing msidn params"));
                        throw new Exception(string.Format("Msisdn parameter is not present in url '{0}'", domainManager.Url));
                    }
                }



                this.Socket.Action.PreLanderID     = this.Prelander.ID;
                this.Socket.Action.PreLanderTypeID = this.Prelander.Type.ID;

                await this.Socket.Session.PrelanderRegistrationLogic(domainManager.Url, domainManager.Queries, model);

                this.Socket.Action.PrepareActionBasedOnQueries(domainManager.Queries);

                logger.Track("this.Action.PrepareActionBasedOnQueries(queryValues);");

                /// SENDING
                ///

                var sendingModel = new SendingRegistrationModel()
                {
                    lead        = this.Socket.Lead,
                    country     = this.Socket.Session.CountryCode,
                    prelanderID = Prelander.ID
                };

                this.Socket.Send(sendingModel.Pack(key, true, "Welcome!!"));

                logger.Track("sending model");

                /// Inserting action and session
                ///

                //this.Socket.Action.Init(model.providerID);
                this.Socket.Action.Init();
                this.Socket.Session.Init();

                this.Socket.Session.Request.rawurl = model.url;
                this.Socket.Session.Request.UpdateLater();
                logger.Track("sessionRequest update");

                this.Socket.Send("reg-post", new SendingRegistrationPost()
                {
                    actionID  = this.Socket.Action.Data.GetStringID(),
                    sessionID = this.Socket.Session.Data.GetStringID(),
                    userID    = this.Socket.User.Key,
                    Loggers   = logger.Tracks
                }.Pack());

                await this.Socket.Database.TransactionalManager.RunAsync();
            }
            catch (Exception e)
            {
                this.Socket.Logging.StartLoggin("")
                .Where("pl-registration")
                .Add(model)
                .OnException(e);

                this.Socket.Send(new FatalModel()
                {
                    Action = "OnRegistration", Exception = e.ToString()
                }.Pack(false, "error500"));
                ApiSocketServer.CloseSession(this.Socket);
            }
        }
Exemple #7
0
        public IActionResult Index(string type, string dbg, string recompile = "0")
        {
            return(this.Ok("notActive"));

            Response.ContentType = "text/javascript";
            if (string.IsNullOrEmpty(type))
            {
                return(this.Content("console.error('ccsocket:: type missing');"));
            }

            SessionType sessionType = SessionType.Default;

            if (type.ToLower().Equals("pl"))
            {
                sessionType = SessionType.Prelander;
            }
            else if (type.ToLower().Equals("lp"))
            {
                sessionType = SessionType.Lander;
            }
            else
            {
                return(this.Content("console.error('ccsocket:: uknown type');"));
            }

            #region #compile.js#

            string js_extension = string.Empty;
            if (string.IsNullOrEmpty(ClientJS) || recompile.Equals("1"))
            {
                string path = this.HostingEnvironment.WebRootPath + @"/js/compiled/client.js";
                ClientJS = (new JSMinify.Minify(path)).getModifiedData();
            }

            if (sessionType == SessionType.Prelander)
            {
                if (string.IsNullOrEmpty(PrelanderJS) || recompile.Equals("1"))
                {
                    string path = this.HostingEnvironment.WebRootPath + @"/js/shared/prelander.js";
                    PrelanderJS = (new Microsoft.Ajax.Utilities.Minifier().MinifyJavaScript(System.IO.File.ReadAllText(path)));
                }
                js_extension = PrelanderJS;
            }
            else if (sessionType == SessionType.Lander)
            {
                if (string.IsNullOrEmpty(LanderJS) || recompile.Equals("1"))
                {
                    string path = this.HostingEnvironment.WebRootPath + @"/js/shared/lander.js";
                    LanderJS = (new Microsoft.Ajax.Utilities.Minifier().MinifyJavaScript(System.IO.File.ReadAllText(path)));
                }
                js_extension = LanderJS;
            }

            #endregion

            SessionSocket socket = null;
            try
            {
                //socket = new SessionSocket(this.Context, sessionType);
            }
            catch (Exception e)
            {
                Logger.Instance.LogException(e);
                return(this.Content("console.error('ccsocket:: error 500');"));
            }

            var    baseUrl   = $"{(this.Request.Scheme.Equals("https") ? "wss" : "ws")}://{this.Request.Host.Value.ToString()}{this.Request.PathBase.Value.ToString()}";
            string variables = "var CC=Object;";
            variables += string.Format("CC.dbg={0};", string.IsNullOrEmpty(dbg) || dbg.Equals("0") ? "false" : "true");
            variables += string.Format("CC.host='{0}';", baseUrl);
            variables += string.Format("CC.type='{0}';", type.ToLower());
            variables += string.Format("CC.sguid='{0}';", socket.Key);
            variables += string.Format("CC.uid='{0}';", socket.User.Key);

            ApiSocketServer.AddSession(socket);

            return(this.ReturnContent(variables + ClientJS + js_extension));
        }
        public async void OnRegistration(string key, ReceivingRegistrationModel model)
        {
            try
            {
                MSLogger logger = new MSLogger();

                // provider id will be present in model.url
                //if (!model.providerID.HasValue)
                //{
                //  this.Socket.Send(key, new SendingRegistrationModel() { }.Pack(false, "providerID missing"));
                //  return;
                //}

                if (string.IsNullOrEmpty(model.url))
                {
                    this.Socket.Send(key, new SendingRegistrationModel()
                    {
                    }.Pack(false, "url is missing"));
                    return;
                }

#if DEBUG
                if (model.url.StartsWith("file:"))
                {
                    model.url = "http://dusan.landing/sports-nf/iphone-11-giveaway/?ptype=cc2&country=united%20kingdom&offer_id=2782&dbg=true&lxid=12321551";
                }
#endif
                DomainManager domainManager = DomainManager.InitiateLander(model.url);
                if (domainManager.HasError)
                {
                    this.Socket.Send(key, new SendingRegistrationModel()
                    {
                    }.Pack(false, domainManager.ErrorMessage));
                    return;
                }

                var lander = domainManager.Lander;
                this.Socket.Action.LanderID     = lander.ID;
                this.Socket.Action.LanderTypeID = lander.Type.ID;
                this.Socket.Action.ProviderID   = domainManager.Provider.ID;
                this.Socket.Action.PrepareActionBasedOnQueries(domainManager.Queries);

                /// SENDING
                ///

                var sendingModel = new SendingRegistrationModel()
                {
                    lead    = this.Socket.Lead,
                    country = this.Socket.Session.CountryCode,
                    lander  = lander
                };
                if (this.Socket.Lead != null)
                {
                    sendingModel.leadHasSubscription = await this.Socket.Lead.HasLeadSubscriptions(domainManager.Provider.ID);
                }

                this.Socket.Send(sendingModel.Pack(key, true, "Welcome!!"));

                /// Inserting action and session
                ///

                //this.Socket.Action.Init(model.providerID);
                this.Socket.Action.Init();
                this.Socket.Session.Init();

                if (string.IsNullOrEmpty(this.Socket.Session.Request.rawurl))
                {
                    this.Socket.Session.Request.rawurl = model.url;
                }
                this.Socket.Session.Request.UpdateLater();

                this.Socket.Send("reg-post", new SendingRegistrationPost()
                {
                    lead      = this.Socket.Lead,
                    country   = this.Socket.Session.CountryCode,
                    actionID  = this.Socket.Action.Data.GetStringID(),
                    sessionID = this.Socket.Session.Data.GetStringID(),
                    userID    = this.Socket.User.Key,
                    provider  = domainManager.Provider,
                    lander    = domainManager.Lander,
                    Loggers   = logger.Tracks
                }.Pack());

                await this.Socket.Database.TransactionalManager.RunAsync();
            }
            catch (Exception e)
            {
                this.Socket.Logging.StartLoggin("")
                .Where("lp-registration")
                .Add("url", model.url)
                //.Add("providerID?", model.providerID.HasValue ? model.providerID.Value.ToString() : "null")
                .OnException(e);

                this.Socket.Send(new FatalModel()
                {
                    Action = "OnRegistration", Exception = e.ToString()
                }.Pack(false, "error500"));
                ApiSocketServer.CloseSession(this.Socket);
            }
        }
Exemple #9
0
 public IActionResult Kill(string id)
 {
     ApiSocketServer.CloseSession(id);
     return(this.Index());
 }