コード例 #1
0
        /// <summary> set all current cookies for each new request </summary>
        public static bool ApplyAllCookiesToRequest(this UnityWebRequest self)
        {
            Uri uri = new Uri(self.url);

            try {
                // If available use the CookieContainer to apply set cookies to the request:
                var container = IoC.inject.Get <System.Net.CookieContainer>(uri);
                if (container != null)
                {
                    self.SetRequestHeader("Cookie", container.GetCookieHeader(uri));
                    return(true);
                }
                // Else use the CookieJar (if available):
                CookieJar jar = IoC.inject.Get <CookieJar>(uri);
                if (jar == null)
                {
                    return(true);
                }
                var allCookies = jar.GetCookies(new CookieAccessInfo(uri.Host, uri.AbsolutePath));
                if (allCookies.IsNullOrEmpty() && uri.Scheme.Equals("https"))
                {
                    allCookies = jar.GetCookies(new CookieAccessInfo(uri.Host, uri.AbsolutePath, true));
                }
                return(self.SetCookies(allCookies));
            }
            catch (Exception e) { Log.e(e); }
            return(false);
        }
コード例 #2
0
 private static List <Cookie> LoadStoredCookiesForUri(Uri uri)
 {
     try {
         CookieJar jar = IoC.inject.Get <CookieJar>(uri);
         if (jar == null)
         {
             return(new List <Cookie>());
         }
         var c = jar.GetCookies(new CookieAccessInfo(uri.Host, uri.AbsolutePath));
         if (c.IsNullOrEmpty() && uri.Scheme.Equals("https"))
         {
             c = jar.GetCookies(new CookieAccessInfo(uri.Host, uri.AbsolutePath, true));
         }
         return(c);
     }
     catch (Exception e) { Log.e(e); }
     return(new List <Cookie>());
 }
コード例 #3
0
        public bool SendSms(string recipient, string message)
        {
            if (IsLoggedIn == false)
            {
                throw new Exception("Not logged in");
            }

            string cookieVal = CookieJar.GetCookies(new Uri(base_url))["JSESSIONID"].Value;

            cookieVal = cookieVal.Substring(cookieVal.IndexOf('~') + 1);

            CQ sendSmsPage           = Client.DownloadString(base_url + "SendSMS?id=" + cookieVal);
            NameValueCollection data = new NameValueCollection();
            //all inputs
            CQ form   = sendSmsPage.Find("form[id=frm_sendsms]");
            CQ inputs = form.Find("input[type=hidden]");

            foreach (var input in inputs)
            {
                CQ inp = input.Cq();
                data.Add(inp.Attr("name"), inp.Attr("value"));
            }

            //sms input
            CQ mobileNumberBox = form.Find("input[placeholder='Enter Mobile Number or Name']")[0].Cq();

            data.Add(mobileNumberBox.Attr("name"), recipient);

            //textarea
            data.Add("sendSMSMsg", message);
            string sendSmsPost = base_url + data["fkapps"];

            data["hid_exists"]  = "no";
            data["maxwellapps"] = cookieVal;

            //additional vsls
            data.Add("messid_0", "");
            data.Add("messid_1", "");
            data.Add("messid_2", "");
            data.Add("messid_3", "");
            data.Add("messid_4", "");
            data.Add("newsExtnUrl", "");
            data.Add("reminderDate", DateTime.Now.ToString("dd-MM-yyyy"));
            data.Add("sel_hour", "");
            data.Add("sel_minute", "");
            data.Add("ulCategories", "29");

            Client.UploadValues(sendSmsPost, data);

            return(true);
        }
コード例 #4
0
        public void CookieValuesAreOverwritten()
        {
            var cookieJar = new CookieJar();

            cookieJar.Add(new Uri("http://bar.ext"), new Cookie {
                Name = "a", Value = "x", Domain = "bar.ext"
            });
            cookieJar.Add(new Uri("http://foo.bar.ext"), new Cookie {
                Name = "a", Value = "y", Domain = "bar.ext"
            });

            var cookies = cookieJar.GetCookies(new Uri("http://bar.ext"));

            Assert.Equal(1, cookies.Count);
            Assert.Equal("y", cookies[0].Value);
        }
コード例 #5
0
        public void ClearRemovesAllCookies()
        {
            var cookieJar = new CookieJar();

            cookieJar.Add(new Uri("http://bar.ext"), new Cookie {
                Name = "a", Domain = "bar.ext"
            });
            cookieJar.Add(new Uri("http://foo.bar.ext"), new Cookie {
                Name = "b", Domain = "bar.ext"
            });
            cookieJar.Add(new Uri("http://foo.ext"), new Cookie {
                Name = "c", Domain = "foo.ext"
            });
            cookieJar.Clear();

            var cookies = cookieJar.GetCookies(new Uri("http://bar.ext"));

            Assert.Equal(0, cookies.Count);
        }
コード例 #6
0
        public void GetCookiesWillReturnAllMatchingCookies()
        {
            var cookieJar = new CookieJar();

            cookieJar.Add(new Uri("http://bar.ext"), new Cookie {
                Name = "a", Domain = "bar.ext"
            });
            cookieJar.Add(new Uri("http://foo.bar.ext"), new Cookie {
                Name = "b", Domain = "bar.ext"
            });
            cookieJar.Add(new Uri("http://foo.ext"), new Cookie {
                Name = "c", Domain = "foo.ext"
            });

            var cookies = cookieJar.GetCookies(new Uri("http://bar.ext"));

            Assert.Equal(2, cookies.Count);
            Assert.True(cookies.Cast <Cookie>().All(c => c.Domain == "bar.ext"));
        }
コード例 #7
0
        // Handle saved minecraft.net sessions
        bool LoadCookie(bool remember)
        {
            if (File.Exists(Paths.CookieContainerFile))
            {
                if (remember)
                {
                    // load a saved session
                    BinaryFormatter formatter = new BinaryFormatter();
                    using (Stream s = File.OpenRead(Paths.CookieContainerFile)) {
                        CookieJar = (CookieContainer)formatter.Deserialize(s);
                    }
                    CookieCollection cookies = CookieJar.GetCookies(new Uri(MinecraftNet));
                    foreach (Cookie c in cookies)
                    {
                        // look for a cookie that corresponds to the current minecraft username
                        int start = c.Value.IndexOf("username%3A" + MinecraftUsername,
                                                    StringComparison.OrdinalIgnoreCase);
                        if (start != -1)
                        {
                            MainForm.Log("MC.LoadCookie: Loaded saved session for " + MinecraftUsername);
                            return(true);
                        }
                    }

                    // if saved session was not for the current username, discard it
                    MainForm.Log("MC.LoadCookie: Discarded a saved session (username mismatch)");
                    ResetCookies();
                }
                else
                {
                    // discard a saved session
                    MainForm.Log("MC.LoadCookie: Discarded a saved session");
                    ResetCookies();
                }
            }
            else
            {
                // no session saved
                ResetCookies();
            }
            return(false);
        }
コード例 #8
0
ファイル: Way2Sms.cs プロジェクト: yuva2achieve/india-sms-api
        public bool SendSms(string recipient, string message)
        {
            if (IsLoggedIn == false)
            {
                throw new Exception("Not logged in");
            }

            string cookieVal = CookieJar.GetCookies(new Uri(base_url))["JSESSIONID"].Value;

            cookieVal = cookieVal.Substring(cookieVal.IndexOf('~') + 1);

            string sendSmsPost = base_url + "smstoss.action";

            NameValueCollection data = new NameValueCollection();

            data.Add("ssaction", "ss");
            data.Add("Token", cookieVal);
            data.Add("mobile", recipient);
            data.Add("message", message);
            data.Add("msgLen", (140 - message.Length).ToString());

            Client.UploadValues(sendSmsPost, data);
            return(true);
        }
コード例 #9
0
        public override void Login(string password, bool rememberSession)
        {
            if (password == null)
            {
                throw new ArgumentNullException("password");
            }

            bool restoredSession = LoadCookie(rememberSession);

            MainForm.SetSignInStatus("Connecting to Minecraft.net...");

            // check if cancel is needed
            if (cancel)
            {
                Status = LoginResult.Canceled;
                cancel = false;
                return;
            }

            // download the login page
            string loginPage = DownloadString(LoginSecureUri, MinecraftNet);

            // See if we're already logged in
            if (LoggedInAs.IsMatch(loginPage))
            {
                string loggedInUsername = LoggedInAs.Match(loginPage).Groups[1].Value;
                if (rememberSession && PlaySessionCookie != null &&
                    MinecraftUsername.Equals(loggedInUsername, StringComparison.OrdinalIgnoreCase))
                {
                    // If player is already logged in with the right account: reuse a previous session
                    MinecraftUsername = loggedInUsername;
                    MainForm.Log("MC.Login: Restored session for " + MinecraftUsername);
                    Status = LoginResult.Success;
                    SaveCookie();
                    return;
                }
                else
                {
                    // If we're not supposed to reuse session, if old username is different,
                    // or if there is no play session cookie set - relog
                    MainForm.SetSignInStatus("Switching accounts...");
                    DownloadString(LogoutUri, MinecraftNet);
                    loginPage = DownloadString(LoginSecureUri, LogoutUri);
                }
            }

            // Extract authenticityToken from the login page
            Match authTokenMatch = LoginAuthToken.Match(loginPage);

            if (!authTokenMatch.Success)
            {
                if (restoredSession)
                {
                    // restoring session failed; log out and retry
                    DownloadString(LogoutUri, MinecraftNet);
                    ResetCookies();
                    MainForm.Log("MC.Login: Unrecognized page; retrying");
                    Login(password, rememberSession);
                    return;
                }
                else
                {
                    // something unexpected happened, panic!
                    MainForm.Log("MC.Login: Unrecognized page: " + loginPage);
                    Status = LoginResult.UnrecognizedResponse;
                }
                return;
            }
            string authToken = authTokenMatch.Groups[1].Value;

            // Build up form data
            string loginString = String.Format("username={0}&password={1}&authenticityToken={2}",
                                               Uri.EscapeDataString(LoginUsername),
                                               Uri.EscapeDataString(password),
                                               Uri.EscapeDataString(authToken));

            if (rememberSession)
            {
                loginString += "&remember=true";
            }

            // check if cancel is needed
            if (cancel)
            {
                Status = LoginResult.Canceled;
                cancel = false;
                return;
            }

            // POST to the login form
            MainForm.SetSignInStatus("Sending login information...");
            string loginResponse = UploadString(LoginSecureUri, LoginSecureUri, loginString);

            // check if cancel is needed
            if (cancel)
            {
                Status = LoginResult.Canceled;
                cancel = false;
                return;
            }

            // Check the response
            if (loginResponse.Contains(WrongUsernameOrPasswordMessage))
            {
                Status = LoginResult.WrongUsernameOrPass;
            }
            else if (LoggedInAs.IsMatch(loginResponse))
            {
                MinecraftUsername = LoggedInAs.Match(loginResponse).Groups[1].Value;
                if (PlaySessionCookie == null)
                {
                    CookieCollection cookies = CookieJar.GetCookies(new Uri(MinecraftNet));
                    MainForm.Log("MC.Login: No play session. There were " + cookies.Count + " cookies served:");
                    foreach (Cookie cookie in cookies)
                    {
                        MainForm.Log("  " + cookie);
                    }
                    Status = LoginResult.NoPlaySession;
                    return;
                }
                Status = LoginResult.Success;
                SaveCookie();
            }
            else if (loginResponse.Contains(MigratedAccountMessage))
            {
                Status = LoginResult.MigratedAccount;
            }
            else
            {
                MainForm.Log("MC.Login: Unrecognized response: " + loginResponse);
                Status = LoginResult.UnrecognizedResponse;
            }
        }