Beispiel #1
0
        public Job.Job CreateJob(
            string name,
            string config_xml)
        {
            Trace.TraceInformation("Creating job: {0} with Config xml: {2}{1}{2}",
                                   name,
                                   config_xml,
                                   Environment.NewLine);

            Login();
            Job.Job jobinfo = null; // GetJobInfo(name);
            if (jobinfo == null)
            {
                Cookie session_id = AuthCookies.GetCookies(new Uri(ServerUrl)).Cast <Cookie>().First(x => x.Name == "_session_id");
                string response   = SendPostRequest(
                    ServerUrl + String.Format(Queries.CREATE_JOB, HttpUtility.UrlEncode(name)),
                    String.Format("data={0}&_session_id={1}", HttpUtility.UrlEncode(config_xml), HttpUtility.UrlEncode(session_id.Value)),
                    "application/x-www-form-urlencoded");
                //Console.WriteLine(response);
                if (response != null)
                {
                    jobinfo = GetJobInfo(name);
                }
            }
            return(jobinfo);
        }
Beispiel #2
0
        private Dictionary <string, object> AppendSessionId(Dictionary <string, object> query)
        {
            this.Login();

            if (query == null)
            {
                query = new Dictionary <string, object>();
            }

            Cookie session_id = AuthCookies.GetCookies(new Uri(ServerUrl)).Cast <Cookie>().First(x => x.Name == "_session_id");

            query["_session_id"] = session_id.Value;
            return(query);
        }
Beispiel #3
0
        public string BuildJob(
            string name,
            string swiftFilename,
            string buildQuery = "")
        {
            Login();

            Cookie session_id = AuthCookies.GetCookies(new Uri(ServerUrl)).Cast <Cookie>().First(x => x.Name == "_session_id");
            string response   = SendPostRequest(
                ServerUrl + String.Format(Queries.BUILD_JOB, name, HttpUtility.UrlEncode(swiftFilename), buildQuery),
                String.Format("_session_id={0}", HttpUtility.UrlEncode(session_id.Value)),
                "application/x-www-form-urlencoded");

            return(response);
        }
Beispiel #4
0
        /// <summary>
        /// Stops the last build on the server
        /// </summary>
        /// <param name="name">Name of the job</param>
        public void StopJob(string name)
        {
            Login();
            var jobinfo = GetJobInfo(name);

            if (jobinfo != null)
            {
                Cookie session_id = AuthCookies.GetCookies(new Uri(ServerUrl)).Cast <Cookie>().First(x => x.Name == "_session_id");
                string response   = SendPostRequest(
                    ServerUrl + String.Format(String.Format(Queries.STOP_JOB, HttpUtility.UrlEncode(name))),
                    String.Format("_session_id={0}", HttpUtility.UrlEncode(session_id.Value)),
                    "application/x-www-form-urlencoded");
                //Console.WriteLine(response);
            }
        }
Beispiel #5
0
        public async Task Login()
        {
            if (IsAuthenticated())
            {
                return;
            }

            await ProceedUtils.Proceed <bool?>(_logger, async() =>
            {
                var session = this.LoadSession();
                if (session != null)
                {
                    AuthCookies = session;
                    _logger.LogTrace(AuthCookies.GetLog());
                    return(true);
                }

                var loginGetRequest = AccountProvider.Login.LoginGet()
                                      .SetDefault();
                var loginGet = await(await loginGetRequest.ExecuteUnparsedAsync()).ToLoginGet();
                AuthCookies  = new AuthCookies
                {
                    CfdUid  = loginGet.CfdUid,
                    Session = loginGet.Session
                };

                var loginRequest = AccountProvider.Login.Login(
                    Credentials.Username,
                    Credentials.Password,
                    loginGet.GrantType,
                    loginGet.Continue,
                    loginGet.CsrfToken)
                                   .SetDefault()
                                   .AddCacheControlMaxAge(TimeSpan.Zero)
                                   .AddOrigin("https://account.shodan.io")
                                   .AddSecFetchSite("same-origin")
                                   .AddReferer("https://account.shodan.io/login")
                                   .AddCookies(AuthCookies);
                var loginResult     = await loginRequest.ExecuteUnparsedAsync();
                AuthCookies.Polito  = loginResult.GetCookie("polito");
                AuthCookies.Session = loginResult.GetCookie("session");
                _logger.LogTrace(AuthCookies.GetLog());

                this.SaveSession(AuthCookies);

                return(true);
            });
        }
        public static ClientServiceRequest <TResponse> SetAuthCookies <TResponse>(
            this ClientServiceRequest <TResponse> request,
            AuthCookies authCookies)
        {
            request.ClearExecInterceptors();

            var res = request
                      .AddUserAgent(HttpConst.UserAgent)
                      .AddConnection("keep-alive")
                      .AddAccept("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
                      .AddAcceptLanguage("en-US,en;q=0.8")
                      .AddUpgradeInsecureRequests("1");

            if (authCookies != null)
            {
                res = res.AddCookies(authCookies);
            }

            return(res);
        }
Beispiel #7
0
 private void SaveSession(AuthCookies session)
 {
     File.WriteAllText(_sessionFilePath, JsonConvert.SerializeObject(session));
 }
        public async Task Login()
        {
            if (this.IsAuthenticated())
            {
                return;
            }

            await ProceedUtils.Proceed <bool?>(this.Logger, async() => {
                AuthCookies = new AuthCookies
                {
                    Username = this.UserSecrets.Username,
                    Password = this.UserSecrets.Password,
                    UserLang = UserLang,
                    Ga       = "GA1.2.1583055054.1567053894",
                    Gid      = "GA1.2.49410478.1567140764",
                    Gat      = "1"
                };

                var bvbRequest = this.Lr.UserSignIn.SignInBvb(UserLang, ClientVersion)
                                 .SetAuthCookies(AuthCookies)
                                 .SetSerializer(new SignInBvbSerializer());
                var bvbResponse = await bvbRequest.ExecuteAsync();
                AuthCookies.Bvb = bvbResponse.Bvb;

                var sessionIdRequest = this.Lr.UserSignIn.SignInSessionId(UserLang, ClientVersion, "1")
                                       .SetAuthCookies(AuthCookies)
                                       .AddReferer($"https://likesrock.com/client-v2/user_signin.php?user_lang={UserLang}&client_version={ClientVersion}")
                                       .SetSerializer(new WebFormsToJsonSerializer());

                var sessionId            = (await sessionIdRequest.ExecuteUnparsedAsync()).GetCookie(PhpSessionId);
                AuthCookies.PhpSessionId = sessionId;
                this.Logger.LogTrace(AuthCookies.GetLog());

                var session = this.LoadSession();
                if (session != null)
                {
                    UserSession = session;
                    this.Logger.LogTrace(UserSession.GetLog());
                    return(true);
                }

                var loginRequest = this.Lr.Ajax.Login(this.UserSecrets.Username, this.UserSecrets.Password)
                                   .ClearExecInterceptors()
                                   .AddUserAgent(HttpConst.UserAgent)
                                   .AddCookies(AuthCookies)
                                   .AddConnection("keep-alive")
                                   .AddAccept("*/*")
                                   .AddOrigin("https://likesrock.com")
                                   .AddXRequestedWith("XMLHttpRequest")
                                   .AddReferer($"https://likesrock.com/client-v2/user_signin.php?user_lang={UserLang}&client_version={ClientVersion}&security=1")
                                   .AddAcceptLanguage("en-US,en;q=0.8");

                var loginInfo = await loginRequest.ExecuteAsync();
                if (loginInfo == null)
                {
                    this.Logger.LogError("Authorization failed.");
                    DelayUtils.LargeDelay();
                    return(null);
                }

                this.Logger.LogTrace(loginInfo.GetLog());
                UserSession = new UserSession
                {
                    UserId          = loginInfo.UserId,
                    UserName        = loginInfo.UserName,
                    UserEmail       = loginInfo.UserEmail,
                    UserAccessToken = loginInfo.UserAccessToken
                };

                this.SaveSession(UserSession);

                return(true);
            });
        }
Beispiel #9
0
        private async Task UpdateViewModel()
        {
            CurrentUser       = creatioUtils.CurrentUser;
            AccounttHyperlink = new Hyperlink()
            {
                Uri  = new Uri(Domain + @"/0/Nui/ViewModule.aspx#CardModuleV2/AccountPageV2/edit/" + CurrentUser.Account.Value),
                Text = CurrentUser.Account.DisplayValue
            };
            ContactHyperlink = new Hyperlink()
            {
                Uri  = new Uri(Domain + @"/0/Nui/ViewModule.aspx#CardModuleV2/ContactPageV2/edit/" + CurrentUser.Contact.Value),
                Text = $"Loged in as: {CurrentUser.Contact.DisplayValue} ({CurrentUser.User.DisplayValue})"
            };
            CookieCollection cc = creatioUtils.Auth.GetCookies(new Uri(Domain));

            foreach (Cookie c in cc)
            {
                AuthCookies.Add(new MyAuthCookie {
                    Name = c.Name, Value = c.Value
                });
            }
            await GetImageAsync(CurrentUser.Contact.PrimaryImageValue).ConfigureAwait(false);

            //SelectQuery contactQuery = new SelectQuery()
            //{
            //    RootSchemaName = "SysAdminUnit",
            //    RowCount = 10,
            //    RowsOffset = -1,
            //    QueryKind = QueryKind.General,
            //    QuerySource = QuerySource.Filter,
            //    UseLocalization = true,
            //    QueryOptimize = true,
            //    Columns = new SelectQueryColumns()
            //    {
            //        Items = new Dictionary<string, SelectQueryColumn>()
            //        {
            //            {
            //                "Id", new SelectQueryColumn()
            //                {
            //                    Caption = "Id",
            //                    OrderDirection = OrderDirection.Ascending,
            //                    OrderPosition = 0,
            //                    Expression = new ColumnExpression()
            //                    {
            //                        ExpressionType = EntitySchemaQueryExpressionType.SchemaColumn,
            //                        ColumnPath = "Id"
            //                    }
            //                }
            //            },
            //            {
            //                "Name", new SelectQueryColumn()
            //                {
            //                    Caption = "Name",
            //                    OrderDirection = OrderDirection.Ascending,
            //                    OrderPosition = 0,
            //                    Expression = new ColumnExpression()
            //                    {
            //                        ExpressionType = EntitySchemaQueryExpressionType.SchemaColumn,
            //                        ColumnPath = "Name"
            //                    }
            //                }
            //            },
            //            {
            //                "fileName", new SelectQueryColumn()
            //                {
            //                    Caption = "fileName",
            //                    OrderDirection = OrderDirection.Ascending,
            //                    OrderPosition = 0,
            //                    Expression = new ColumnExpression()
            //                    {
            //                        ExpressionType = EntitySchemaQueryExpressionType.SchemaColumn,
            //                        ColumnPath = "Contact.Photo"
            //                    }
            //                }
            //            },
            //            {
            //                "ContactId", new SelectQueryColumn()
            //                {
            //                    Caption = "ContactId",
            //                    OrderDirection = OrderDirection.Ascending,
            //                    OrderPosition = 0,
            //                    Expression = new ColumnExpression()
            //                    {
            //                        ExpressionType = EntitySchemaQueryExpressionType.SchemaColumn,
            //                        ColumnPath = "Contact.Id"
            //                    }
            //                }
            //            },
            //            {
            //                "Photo", new SelectQueryColumn()
            //                {
            //                    Caption = "Photo",
            //                    OrderDirection = OrderDirection.Ascending,
            //                    OrderPosition = 0,
            //                    Expression = new ColumnExpression()
            //                    {
            //                        ExpressionType = EntitySchemaQueryExpressionType.SchemaColumn,
            //                        ColumnPath = "Contact.Photo.Id"
            //                    }
            //                }
            //            }
            //        }
            //    },
            //    Filters = new Filters()
            //    {
            //        IsEnabled = true,
            //        FilterType = FilterType.FilterGroup,
            //        LogicalOperation = LogicalOperationStrict.And,
            //        Items = new Dictionary<string, Filter>
            //        {
            //            {
            //                "CompareByName", new Filter
            //                {
            //                    IsEnabled=true,
            //                    FilterType = FilterType.CompareFilter,
            //                    ComparisonType = FilterComparisonType.Equal,
            //                    LeftExpression = new BaseExpression()
            //                    {
            //                        ExpressionType = EntitySchemaQueryExpressionType.SchemaColumn,
            //                        ColumnPath = "Id"
            //                    },
            //                    RightExpression = new BaseExpression()
            //                    {
            //                        ExpressionType = EntitySchemaQueryExpressionType.Parameter,
            //                        Parameter = new Parameter()
            //                        {
            //                            DataValueType = DataValueType.Guid,
            //                            Value = creatioUtils.CurrentUser.User.Value
            //                        }
            //                    }
            //                }
            //            },
            //        }
            //    }
            //};
            //string json = JsonConvert.SerializeObject(contactQuery);
            //RequestResponse result = await Utils.GetResponseAsync(json, ActionEnum.SELECT).ConfigureAwait(false);
            //System.Data.DataTable dt = creatioUtils.ConvertResponseToDataTable(result.Result);

            //string ImageId = dt.Rows[0]["Photo"].ToString();
            //await GetImageAsync(ImageId).ConfigureAwait(true);
        }