Setting up proxy in chrome extension - google-chrome

I would like to allow to use proxies on my chrome extension but no matter what user enters, ERR_NO_SUPPORTED_PROXIES appears.
Here is my code for proxy connection:
var prxobj = JSON.parse(localStorage['proxy']);
ip = prxobj['proxyip'];
port = parseInt(prxobj['proxyport']);
var obj = {
mode: 'fixed_servers',
rules: {
singleProxy: {
scheme: 'https',
host: ip,
port: port
},
bypassList: ['']
}
};
chrome['proxy']['settings']['set']({
value: obj,
scope: 'regular'
}, function() {})
Code for proxy auth:
chrome['webRequest']['onAuthRequired']['addListener'](function(first, second) {
var objx= JSON.parse(localStorage['proxy']);
first({
authCredentials: {
username: objx['proxyusername'],
password: objx['proxypassword']
}
})
}, {urls: ['<all_urls>'] }, ['asyncBlocking']);

Related

Trying to connect to Aurora mysql using lambda and Sequelize installed mysql2

I am getting the following error
{"name":"SequelizeConnectionError","parent":{"code":"AUTH_SWITCH_PLUGIN_ERROR","fatal":true},"original":{"code":"AUTH_SWITCH_PLUGIN_ERROR","fatal":true}}
Code:
import { Sequelize, Options as SequelizeOptions, DataTypes } from 'sequelize';
import { Signer } from 'aws-sdk-js-v3-rds-signer';
const signer = new Signer({
hostname: process.env.MYSQLHOST,
port: 3306,
region: process.env.AWS_REGION,
username: 'someuser'
});
const sequelizeConfig: SequelizeOptions = {
host: process.env.MYSQLHOST,
dialect: 'mysql',
port: 3306,
dialectOptions: {
ssl: {
require: true,
}
},
};
if (process.env.STAGE !== 'local') {
sequelizeConfig.dialectOptions = {
ssl: {
rejectUnauthorized: true,
}
};
}
const sequelize = new Sequelize(process.env.MYSQLDATABASE || '', process.env.MYSQLUSER || '', process.env.MYSQLPASSWORD || '', sequelizeConfig);
if (process.env.STAGE !== 'local' && !sequelize.hasHook('beforeConnect')) {
sequelize.addHook('beforeConnect', async (config) => {
// #ts-ignore
config.password = await signer.getAuthToken();
});
}

nodemailer online.net 550-HELO can't be [127.0.0.1]. Please contact your ISP

I have a problem on sending mails online.net with nodemailer.
While it works fine with chilkat's mailman module (node.js) on the same environment
nodemailer version
let transporter = nodemailer.createTransport({
host: "smtpauth.online.net",
port: 587,
secure: false,
auth: {
user: "xxx#domain.fr",
pass: "xxx",
},
tls: {
rejectUnauthorized: false,
},
});
transporter
.sendMail({
from: "xxx#domain.fr",
to: "true#eadress.fr",
subject: "Test online",
text: "Test online"
})
.then((info) => {
console.log("Preview URL: " + nodemailer.getTestMessageUrl(info));
})
.catch((error) => {
console.log(error);
});
chilkat-version
var mailman = new chilkat.MailMan();
mailman.SmtpHost = "smtpauth.online.net";
mailman.SmtpUsername = "xxx#domain.fr";
mailman.SmtpPassword = "xxx";
mailman.SmtpSsl = false;
mailman.StartTLS = true;
mailman.SmtpPort = 587;
var email = new chilkat.Email();
email.Subject = "Test online";
email.Body = "Test online";
email.From = "xxx#domain.fr";
var success = email.AddTo("Bob","true#eadress.fr");
success = mailman.SendEmail(email);
if (success !== true) {
console.log(mailman.LastErrorText);
return;
}
success = mailman.CloseSmtpConnection();
if (success !== true) {
console.log("Connection to SMTP server not closed cleanly.");
}
console.log("Mail Sent!");
Following the scaleway doc (https://www.scaleway.com/en/docs/webhosting/classic/how-to/check-emails/), I tried all ports (25, 465, 587, 2525 ). I changed the host from smtpauth.online.net to smtp.online.net, nothing helped.
If anyone has solved this problem that would be a great help. Thanks
I found the solution.
it works by adding "name" option in createTransport
name – optional hostname of the client, used for identifying to the server, defaults to hostname of the machine
let transporter = nodemailer.createTransport({
name: 'www.domain.com',
host: "smtpauth.online.net",
port: 587,
secure: false,
auth: {
user: "xxx#domain.fr",
pass: "xxx",
},
tls: {
rejectUnauthorized: false,
},
});

how to store logs into mysql db using express-winston in Node.js

I am trying to store logs into mysql db(with Sequelize) using express-winston in Node.js.
According to doc(https://www.npmjs.com/package/winston-sql-transport), I should do the following:
const { Logger } = require('winston');
const { SQLTransport } = require('./../lib/winston-sql-transport');
const logger = new Logger({
transports: [
new SQLTransport({
tableName: 'winston_logs',
})]
});
module.exports = logger;
I apply above code in app.js, but not successful.
app.js
const { SQLTransport } = require('./../lib/winston-sql-transport'); // //Error: Cannot find module './../lib/winston-sql-transport'
const mysqlOption = {
tableName: 'winston_logs'
}
app.use(
expressWinston.logger({
transports: [
new SQLTransport(mysqlOption)
],
format: winston.format.combine(
winston.format.timestamp({ format: timezoned }),
winston.format.json(),
),
metaField: null,
expressFormat: true,
statusLevels: false,
level: function (req, res) {
var level = "";
if (res.statusCode < 400) { level = "info"; }
if (res.statusCode >= 400) { level = "warn"; }
if (res.statusCode >= 500) { level = "error"; }
return level;
}
})
)
I tried to change the import to const { SQLTransport } = require('winston-sql-transport');
Resulting error:
Error: You have to define client
at new SQLTransport (/server/node_modules/winston-sql-transport/lib/winston-sql-transport.js:40:13)
I found that people rarely talk about this package.
So I wonder if there is any way to do it?
Update 1:
I updated mysqlOption as suggested by the comment
const { SQLTransport } = require('winston-sql-transport');
const mysqlOption = {
tableName : "winston_logs",
client: 'mysql',
connection: {
host: '127.0.0.1:3306',
user: 'root',
password: '',
database: 'mydb'
}
}
The logs successfully appear in Console, but nothing store in my database.
Update 2:
Since I am using Sequelize, I'm going to provide the schema for the logs table
// See http://docs.sequelizejs.com/en/latest/docs/models-definition/
// for more of what you can do here.
const Sequelize = require('sequelize');
const DataTypes = Sequelize.DataTypes;
module.exports = function (app) {
const sequelizeClient = app.get('sequelizeClient');
const logs = sequelizeClient.define('winston_logs', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
autoIncrement: true,
primaryKey: true
},
level: {
type: DataTypes.STRING(45),
allowNull: false
},
message: {
type: DataTypes.TEXT,
allowNull: false
},
meta: {
type: DataTypes.STRING(255),
allowNull: false
},
hostname: {
type: DataTypes.STRING(255),
allowNull: false
},
timestamp: {
type: DataTypes.DATE,
allowNull: false
},
}, {
hooks: {
beforeCount(options) {
options.raw = true;
}
}
});
logs.associate = function (models) {
};
return logs;
};
Finally giving up to store logs in mysql db, since mysql transport package seems a bit outdated.
Instead, I store the logs locally, using winston-daily-rotate-file
It can set the frequency of rotation, Maximum size of the file etc.
link: https://github.com/winstonjs/winston-daily-rotate-file

HTTP Post request with credentials and form in nodejs

I want to make an HTTP POST request to a server with credentials (username, password) and content.
More specifically, I used various approaches without success. One of them is:
var request = require('request');
request({
url: 'https://path',
method: 'POST',
auth: {
user: 'username',
pass: 'password'
},
form: {
'grant_type': 'client_credentials',
'text' : 'input-text',
'features': {
'score': true,
}
}
}, function(err, res) {
console.log(res);
var json = JSON.parse(res.body);
console.log("Access Token:", json.access_token);
});
Do you have any suggestion?
I feel more comfortable using promises. request-promise documentation
var request = require('request-promise');
var options = {
method: 'POST',
url: '',
auth: {
user: '',
password: ''
},
headers: {
'': ''
},
json: true
}
return request(options)
.then(function (response) {
// manipulate response
}).catch(function (err) {
return err
})

Sails project - mysql connection 'Error: Consistency violation'

I have created a new sails project and installed sails-permission. First it worked fine. After creating connection to Mysql and did sails lift it throws an error as
error: Error: Consistency violation: A model (`passport`) references a
datastore which cannot be found ('mysql'). If this model definition has an explicit connection property, check that it is spelled correctly. If not, check your default connection (usually located in config/models.js).
The Model passport.js is located in node_modules/sails-permission/api/models.
config/connections.js
mysql: {
module : 'sails-mysql',
host : '127.0.0.1',
port : 3306,
user : 'review',
password : 'review',
database : 'reviews'
},
config/models.js
module.exports.models = {
connection: 'mysql',
migrate: 'alter'
};
node_modules/sails-permission/api/models
var bcrypt = require('bcryptjs');
function hashPassword (passport, next) {
var config = sails.config.auth.bcrypt;
var salt = config.salt || config.rounds;
if (passport.password) {
bcrypt.hash(passport.password, salt, function (err, hash) {
if (err) {
delete passport.password;
sails.log.error(err);
throw err;
}
passport.password = hash;
next(null, passport);
});
}
else {
next(null, passport);
}
}
var Passport = {
attributes: {
password: { type: 'string', minLength: 8 },
provider : { type: 'alphanumericdashed' },
identifier : { type: 'string' },
tokens : { type: 'json' },
user: { model: 'User', required: true },
validatePassword: function (password, next) {
bcrypt.compare(password, this.password, next);
}
},
beforeCreate: function (passport, next) {
hashPassword(passport, next);
},
beforeUpdate: function (passport, next) {
hashPassword(passport, next);
}
};
module.exports = Passport;
It beacause of sails-mysql update. [https://github.com/balderdashy/sails-mysql/pull/328/files].
Change module as adapter in
config/connection.js
mysql: {
adapter : 'sails-mysql',
host : '127.0.0.1',
port : 3306,
user : 'review',
password : 'review',
database : 'reviews'
},