Mobile redirect - issue catching IE users - mobile

Any ideas why this is redirecting IE users?
function Client() {
}
Client.prototype.mobileClients = [
"palm",
"blackberry" ,
"nokia",
"phone",
"midp",
"mobi",
"symbian",
"chtml",
"ericsson",
"minimo",
"audiovox",
"motorola",
"samsung",
"telit",
"upg1",
"ce",
"ucweb",
"astel",
"plucker",
"x320",
"x240",
"j2me",
"sgh",
"portable",
"sprint",
"docomo",
"kddi",
"softbank",
"android",
"mmp",
"pdxgw",
"netfront",
"xiino",
"vodafone",
"portalmmm",
"sagem",
"mot-",
"sie-",
"ipod",
"up\\.b",
"webos",
"amoi",
"novarra",
"cdm",
"alcatel",
"pocket",
"ipad",
"iphone",
"mobileexplorer",
"mobile"
];
Client.prototype.isMobileClient = function(userAgent)
{
userAgent = userAgent.toLowerCase();
for (var i in this.mobileClients) {
if (userAgent.indexOf(this.mobileClients[i]) != -1) {
window.location.replace("../../US-EN/Moment/Mobile/");
return true;
}
}
return false;
}
var client = new Client();
client.isMobileClient(navigator.userAgent);

Well for one ce matches Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; Media **Ce**nter PC 6.0; InfoPath.3; MS-RTC LM 8; Zune 4.7) Which is the IE media center edition.
Another idea would be to give us the useragent that it is effecting.

Related

Not return the answer and also say in title list index out of range

Not return the Answer also say the list index out of range in title
url = 'https://www.adidas.com/us/women-athletic_sneakers'
driver = webdriver.Chrome('D:/chromedriver')
driver.get(url)
time.sleep(3)
time.sleep(2)
w_shoes = driver.find_elements_by_class_name('grid-item___3rAkS')
for shoe in w_shoes:
title = shoe.find_elements_by_xpath('//*[#id="product-search-results"]/div[2]/div[3]/div[4]/div[1]/div/div/div[3]/div[2]/a')[0].text
print(title)
Why don't you try using requests which should fetch you the required content with the blink of an eye?
import requests
url = "https://www.adidas.com/api/plp/content-engine?"
params = {
'sitePath': 'us',
'query': 'women-athletic_sneakers'
}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
}
res = requests.get(url,params=params,headers=headers)
for item in res.json()['raw']['itemList']['items']:
print(item['displayName'])
Output are like:
Ultraboost OG Shoes
Super Super Sleek 72 Shoes
Forum Mid Shoes
Forum Mid Shoes
Ultraboost 21 Shoes

Join EC2 Instance to AD domain via terraform

I hope you can help me with my problem. I am trying to automatically let my ec2 instance joins an ad domain with my terraform script. Since Terraform does not support any "Domain join directory" option I wanted to try to create an SSM Document to let Systems Manager make that for me. Actually I got the following Code:
resource "aws_directory_service_directory" "ad" {
name = "active-directory-service.com"
password = "${var.ad-password}"
edition = "Standard"
size = "Small"
type = "MicrosoftAD"
vpc_settings {
vpc_id = "${aws_vpc.vpc.id}"
subnet_ids = ["${aws_subnet.ds-subnet.0.id}",
"${aws_subnet.ds-subnet.1.id}"
]
}
}
resource "aws_vpc_dhcp_options" "vpc-dhcp-options" {
domain_name = "${var.dir_domain_name}"
domain_name_servers = aws_directory_service_directory.ad.dns_ip_addresses
}
resource "aws_vpc_dhcp_options_association" "dns_resolver" {
vpc_id = aws_vpc.vpc.id
dhcp_options_id = aws_vpc_dhcp_options.vpc-dhcp-options.id
}
resource "aws_ssm_document" "ad-server-domain-join-document" {
name = "myapp_dir_default_doc"
document_type = "Command"
content = <<DOC
{
"schemaVersion": "1.0",
"description": "Join an instance to a domain",
"runtimeConfig": {
"aws:domainJoin": {
"properties": {
"directoryId": "${aws_directory_service_directory.ad.id}",
"directoryName": "${var.dir_domain_name}",
"directoryOU": "${var.dir_computer_ou}",
"dnsIpAddresses": [
"${aws_directory_service_directory.ad.dns_ip_addresses[0]}",
"${aws_directory_service_directory.ad.dns_ip_addresses[1]}"
}
}
}
}
DOC
}
resource "aws_ssm_association" "ad-server-association" {
name = "dir_default_doc"
instance_id = aws_instance.ec2-ad-instance.id
}
I get the following error message:
This value does not have any indices. Can someone please tell me how to fix this issue?
If the AMI you are using does not have SSM, this is how you do it:
user_data = <<EOF
<powershell>
Add-Computer -DomainName 'NAME_OF_THE_DOMAIN' -NewName 'NEW_NAME_OF_THE_MACHINE' -Credential (New-Object -TypeName PSCredential -ArgumentList "DOMAIN_USERNAME",(ConvertTo-SecureString -String 'DOMAIN_PASSWORD' -AsPlainText -Force)[0]) -Restart
</powershell>
EOF
Or, if you want to use SSM, using the new Terraform 12/13 syntax and the latest schema version, here is a ready to copy and paste snippet:
data "aws_directory_service_directory" "my_domain_controller" {
directory_id = "d-XXXXXXXXXXXXX"
}
resource "aws_ssm_document" "ad-join-domain" {
name = "ad-join-domain"
document_type = "Command"
content = jsonencode(
{
"schemaVersion" = "2.2"
"description" = "aws:domainJoin"
"mainSteps" = [
{
"action" = "aws:domainJoin",
"name" = "domainJoin",
"inputs" = {
"directoryId" : data.aws_directory_service_directory.my_domain_controller.id,
"directoryName" : data.aws_directory_service_directory.my_domain_controller.name
"dnsIpAddresses" : sort(data.aws_directory_service_directory.my_domain_controller.dns_ip_addresses)
}
}
]
}
)
}
resource "aws_ssm_association" "windows_server" {
name = aws_ssm_document.ad-join-domain.name
targets {
key = "InstanceIds"
values = ["i-XXXXXXXXXXXX"]
}
}
You will need to specify an instance profile when creating the ec2 instance which has the required permissions for this snippet to work.
As mentioned in the comment, reproducible examples will accelerate anyone's ability to help :)
I assumed terraform 0.12 is in use.
aws_directory_service_directory.ad.dns_ip_addresses is not a list, it is a set. Conceptually, this means it is unordered. As a result, access it like:
sort(aws_directory_service_directory.ad.dns_ip_addresses)[0]
The sort will order it and allow you to access it with an index. The following issue explains this, albeit in regards to attempting to verbosely use element to access https://github.com/hashicorp/terraform/issues/22392
The documentation for this resource calls it a list which is incorrect in practice it seems: https://www.terraform.io/docs/providers/aws/r/directory_service_directory.html
As per https://aws.amazon.com/blogs/security/how-to-configure-your-ec2-instances-to-automatically-join-a-microsoft-active-directory-domain/
dnsIpAddresses expects list in json format
"dnsIpAddresses": [
"198.51.100.1",
"198.51.100.2"
]
convert aws_directory_service_directory.ad.dns_ip_addresses to json format
"dnsIpAddresses": [ "${join("\", \"",aws_directory_service_directory.ad.dns_ip_addresses)}" ]
you can make the target on your SSM association to be a tag instead of using a specific instance, so any instance you are deploying and has the tag per se adjoin will join the domain
resource "aws_ssm_association" "windows_server" {
name = aws_ssm_document.ad-join-domain.name
targets {
key = "tag:adjoin"
values = ["true"]
}
}
I've tried following solution below, which was mentioned here - but unfortunately, the EC2s do not join the Active Directory in an automated way. I've to manually enter the domain and the dns.
Any idea what's wrong with that approach?
Thank you a lot in advance!
resource "aws_instance" "some-application" {
ami = "ami-05a60358d5cda31c5"
instance_type = "t2.micro"
security_groups = [aws_security_group.sg-license-server.id]
subnet_id = module.vpc.public_subnets[0]
key_name = aws_key_pair.pubkey.key_name
tags = {
"Name" = "Some-Application"
}
user_data = <<EOF
<powershell>
msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
Add-Computer -DomainName '${aws_directory_service_directory.my_directory_service.name}' -NewName 'Some-Application' -Credential (New-Object -TypeName PSCredential -ArgumentList 'Administrator',(ConvertTo-SecureString -String '${aws_directory_service_directory.my_directory_service.password}' -AsPlainText -Force)[0]) -Restart
</powershell>
EOF
}
resource "aws_instance" "license-server" {
ami = "ami-05a60358d5cda31c5"
instance_type = "t2.micro"
security_groups = [aws_security_group.sg-license-server.id]
subnet_id = module.vpc.public_subnets[0]
key_name = aws_key_pair.pubkey.key_name
tags = {
"Name" = "License-Server"
}
user_data = <<EOF
<powershell>
msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
Add-Computer -DomainName '${aws_directory_service_directory.my_directory_service.name}' -NewName 'License-Server' -Credential (New-Object -TypeName PSCredential -ArgumentList 'Administrator',(ConvertTo-SecureString -String '${aws_directory_service_directory.my_directory_service.password}' -AsPlainText -Force)[0]) -Restart
</powershell>
EOF
}
resource "aws_security_group" "sg-fsx" {
name = "SG-FSX"
vpc_id = module.vpc.vpc_id
ingress {
from_port = 53
to_port = 636
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 3268
to_port = 3269
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 9389
to_port = 9389
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 5985
to_port = 5985
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 88
to_port = 464
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 5985
to_port = 5985
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 49152
to_port = 65535
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "sg-fsx"
}
}
resource "aws_security_group" "sg-license-server" {
name = "SG-License-Server"
vpc_id = module.vpc.vpc_id
ingress {
from_port = 0
to_port = 6556
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 27000
to_port = 27000
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 49152
to_port = 65535
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "sg-license-server"
}
}
resource "aws_key_pair" "pubkey" {
key_name = "aws-cloud"
public_key = file("key/aws_instance.pub")
}
resource "aws_vpc_dhcp_options" "vpc-dhcp-options" {
domain_name = aws_directory_service_directory.my_directory_service.name
domain_name_servers = aws_directory_service_directory.my_directory_service.dns_ip_addresses
}
resource "aws_vpc_dhcp_options_association" "dns_resolver" {
vpc_id = module.vpc.vpc_id
dhcp_options_id = aws_vpc_dhcp_options.vpc-dhcp-options.id
}
resource "aws_fsx_windows_file_system" "example" {
active_directory_id = aws_directory_service_directory.my_directory_service.id
storage_capacity = 300
subnet_ids = [module.vpc.private_subnets[0]]
throughput_capacity = 1024
security_group_ids = [aws_security_group.sg-fsx.id]
}

How can i establish rpc properties with the datasource type DB in Corda community edition?

To establish an RPC connection in the community edition we need to specify the rpc username, password and permissions but when we are integrating external database like MySQL and change the datasource type from INMEMORY to "DB" it does not allows to give user properties.
these are the settings I am using in my node.conf
security = {
authService = {
dataSource = {
type = "DB"
passwordEncryption = "SHIRO_1_CRYPT"
connection = {
jdbcUrl = "jdbc:mysql://localhost:3306"
username = "root"
password = "password"
driverClassName = "com.mysql.jdbc.Driver"
}
}
options = {
cache = {
expireAfterSecs = 120
maxEntries = 10000
}
}
}
Maybe I didn't understand your question, but database setup in node.conf is separate from RPC user setup in node.conf:
Database (PostGres in my case)
extraConfig = [
'dataSourceProperties.dataSourceClassName' : 'org.postgresql.ds.PGSimpleDataSource',
'dataSourceProperties.dataSource.url' : 'jdbc:postgresql://localhost:5432/postgres',
'dataSourceProperties.dataSource.user' : 'db_user',
'dataSourceProperties.dataSource.password' : 'db_user_password',
'database.transactionIsolationLevel' : 'READ_COMMITTED',
'database.initialiseSchema' : 'true'
]
RPC User
rpcUsers = [[ user: "rpc_user", "password": "rpc_user_password", "permissions": ["ALL"]]]
Ok, I'm adding my node's node.config (it's part of Corda TestNet, and it's deployed on Google Cloud):
baseDirectory = "."
compatibilityZoneURL = "https://netmap.testnet.r3.com"
emailAddress = "xxx"
jarDirs = [ "plugins", "cordapps" ]
sshd { port = 2222 }
myLegalName = "OU=xxx, O=TESTNET_xxx, L=London, C=GB"
keyStorePassword = "xxx"
trustStorePassword = "xxx"
crlCheckSoftFail = true
database = {
transactionIsolationLevel = "READ_COMMITTED"
initialiseSchema = "true"
}
dataSourceProperties {
dataSourceClassName = "org.postgresql.ds.PGSimpleDataSource"
dataSource.url = "jdbc:postgresql://xxx:xxx/postgres"
dataSource.user = xxx
dataSource.password = xxx
}
p2pAddress = "xxx:xxx"
rpcSettings {
useSsl = false
standAloneBroker = false
address = "0.0.0.0:xxx"
adminAddress = "0.0.0.0:xxx"
}
rpcUsers = [
{ username=cordazoneservice, password=xxx, permissions=[ ALL ] }
]
devMode = false
cordappSignerKeyFingerprintBlacklist = []
useTestClock = false

Access to API resource with Implicit flow

Does identity server 4 doesn't allow implicit flow to access API Resource.
Identity Server 4 config.cs
new Client
{
ClientId = "implicit",
ClientName = "Implicit Client",
AllowAccessTokensViaBrowser = true,
RedirectUris = { "https://notused" },
PostLogoutRedirectUris = { "https://notused" },
FrontChannelLogoutUri = "http://localhost:5000/signout-idsrv", // for testing identityserver on localhost
AccessTokenLifetime = 10,
AllowedGrantTypes = GrantTypes.Implicit,
AllowedScopes = { "openid", "profile", "email", "ProxyServer", "api" }
}
Api Resouce
new ApiResource("api", "Custom"),
new ApiResource("ProxyServer", "Proxy Server")
In Mvc Client I am using this code ConfigureServices
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = "oidc";
})
.AddCookie(options =>
{
options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
options.Cookie.Name = "mvcimplicit";
})
.AddOpenIdConnect("oidc", options =>
{
options.Authority = Constants.Authority;
options.RequireHttpsMetadata = false;
options.ClientId = "implicit";
options.Scope.Clear();
options.Scope.Add("openid");
options.Scope.Add("ProxyServer");
options.Scope.Add("profile");
options.Scope.Add("email");
options.SaveTokens = true;
options.TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = JwtClaimTypes.Name,
RoleClaimType = JwtClaimTypes.Role,
};
});
When I try in browser I get "Sorry, there was an error : invalid_scope ". But if I remove options.Scope.Add("ProxyServer"); it works fine and Identity server 4 take me to login page.
OK I found the issue but posting just in case someone else face the same problem.
Response type needs to be specified explicitly otherwise it wont work.
options.ResponseType = "id_token token";
Modify the response type accordingly.

Upload File to ASP.net Core API using Angular

I have been searching for this for about 2 days and there are many posts about this, but I cannot wrap my head around what I want to do.
What I want:
I want to upload a single file to the API using angular, then return the files that are in that folder.
What I've got:
[HttpPost]
[Route("uploadFile/{regionName}/{propertyName}")]
public async Task<IEnumerable<FileModel>> Post(ICollection<IFormFile> files, string regionName,string propertyName)
{
IEnumerable<FileModel> fileModels = null;
var route = Path.Combine(_baseRoot, regionName, propertyName);
PathCreator.CreateFolder(route, null);
try
{
var file = files.FirstOrDefault();
if(file == null)
throw new ArgumentException("File Cannot be null");
var uploads = Path.Combine(route, file.FileName);
using (var fileStream = new FileStream(uploads,FileMode.Create))
{
await file.CopyToAsync(fileStream);
}
fileModels = FileFinder.GetFiles(route);
}
catch (Exception e)
{
throw new ArgumentException(e.Message);
}
return fileModels;
}
AngularJs
viewModel.uploadFile = function () {
let regionName = "TestRegion";
let propertyName = "TestProperty";
let data = viewModel.getFormData();
let request = new XMLHttpRequest();
request.addEventListener("progress", viewModel.updateProgressBar, false);
request.addEventListener("load", transferComplete, false);
viewModel.isUploading = true;
request.open("POST", "/api/file/uploadFile/" + regionName + "/" + propertyName);
request.send(data);
}
/*gets selected file converts to form data*/
viewModel.getFormData = function() {
var formData = new FormData();
if (viewModel.file) {
formData.append("myFile",viewModel.file);
}
return formData;
}
What is Happening
this makes it to the API and my file is null every time. I cannot figure out why.
UPDATE
after changes
angularJs:
viewModel.uploadFile = function() {
let regionName = viewModel.region.name;
let propertyName = viewModel.property.name;
let postUrl = "/api/file/uploadFile/" + regionName + "-" + propertyName;
let formData = new FormData();
if (viewModel.file) {
formData.append("file", viewModel.file);
}
let request = new XMLHttpRequest();
// request.addEventListener("progress", viewModel.updateProgressBar, false);
request.addEventListener("load", transferComplete, false);
viewModel.isUploading = true;
request.open("POST", postUrl);
request.setRequestHeader("Content-Type", "multipart/form-data");
request.send(formData[0]);
}
cs:
[HttpPost]
[Route("uploadFile/{path}")]
[Consumes("multipart/form-data")]
public async Task<IActionResult> Post(IFormFile file, string path)
{
var formattedPath = FilePathFormatter.FormatFolder(path);
var newPath = PathCreator.CreateFolder(_baseRoot,formattedPath);
var size = file.Length;
if (file.Length > 0)
{
using (var stream = new FileStream(newPath,FileMode.Create))
{
await file.CopyToAsync(stream);
}
}
return Ok(new {size, newPath});
}
Request Header
Accept:*/*
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Content-Length:0
Content-Type:multipart/form-data
Cookie:.AspNetCore.Identity.Application=CfDJ8Jb7vPJ0S0dGnlF8mEfQj9lVY7ccwabgngMkzgRgijxfOqen20J0y2DkgaND5M-EtULRMv8Kun0dSchlF22T6faFlxcybpMs5PhwJ6lRznXHBAV7irCmufJu1NhRUfIvMwQBwj9dE862lPsuKUa3sNh9kUYJ6C2pjiGymMNP25NZfJKwJuMA2ewzD9iZnlk5x5E2UMzbhZH9f6Ks_VPLZ4MlNNerwiLV2mya1QaeOv9AXFi4DKOkEu64IfCNGocipF4wP-anP4FkAN1sZOXJcD52KSruxxoj3Yagl6miAZ1788tT-CBZVvgbSWBHOei7Qcm8BiDdMp6KxtQs30m-_MyrbSnMP2GG26rjDwqwsoXopjU7G3KjLu8lc8dOjZGCGLa2Yc5WF63zOis4_5CZdYwFugqA5Mg1qo8mI5xxoYZVOUR1lWbtV5H-MC2geOMH06B4s_OBt59ZP6IJfIDeKpzcDB-hBmC3EE6pW9-wVSmTwfklyMkR2dsWfrKVcQBcQKUXRhSE8YaL6UARqLXBPP9RTbMV8gybZ6SX3h1lGvsp60wW__cRbo6mKwnko-JH-FiO6ctJzI6ciETCOcaz2QSTMYZVIwEX9CYKR9VKw9MUAZCzFguJSYzSCUPCG8TXGr9MyR6HoMgqCpkHfwc522o; io=7RfOJO9stPcX4wFFAAAB
Host:localhost:57155
Origin:http://localhost:57155
Pragma:no-cache
Referer:http://localhost:57155/Files/Upload
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
General
Request URL:some url here
Request Method:POST
Status Code:500 Internal Server Error
Remote Address:[::1]:57155
Request Payload
------WebKitFormBoundaryhpPhzjBM0NH4f7IA--
I think your problem is that the name of the file input element in your form must match the action method parameter name where you receive the uploaded file.
In your example, the parameter name in the action method is files but the file input element in your form is named myFile. Rename myFile to files and it should work.

Resources