Connecting to Prosody via JAXL: "This server does not serve username" - php

I have my own prosody server setup and can connect to it via a windows XMPP client. The server has two accounts on it, and I can connect as both of them and exchange messages between them (I am using the built-in client in Mozilla Thunderbird).
I have a Virtualhost configured on the server ("domain.com").
I am now trying to connect to the server via PHP as one of the accounts and send a message to the other. I have chosen JAXL to do that.
$client = new JAXL(array(
'jid' => 'username',
'host' => 'domain.com',
'pass' => 'mylongcomplicatedpassword',
'auth_type' => 'SCRAM-SHA-1',
'log_level' => JAXLLogger::DEBUG,
'log_path' => './jaxl.log',
'strict' => false,
));
$client->start();
Note the format of 'jid'. This results in an error "This server does not serve username".
If I change the jid to username#domain.com, I get instead "Invalid username."
If I add
$client->require_xep(array('0114'));
before the start(), I get a "This server does not serve... ". in both formats of the JID.
What could be wrong? This is running on PHP 7.1 and the latest versions of JAXL and prosody.

Related

Error when calling AWS Lambda from PHP script hosted on Apache but can from same script run directly

I have a PHP (8.1.8) page hosted on Apache (2.4) on a Windows Server 2019 EC2 instance in AWS. It attempts to send an event to a Lambda Function. The page is called with HTTP, not HTTPS (don't ask - required for external calling system).
If I run the script in VSCode (for example) it works fine and I get a response from the Lambda Function (so I believe the EC2 instance has no problem talking to the Lambda Function). However if I request the page through a browser I get an error (XXXXX represents my Lambda Function name, obfuscated):
Fatal error: Uncaught exception 'Aws\Lambda\Exception\LambdaException' with message 'Error executing "Invoke" on "https://lambda.eu-west-1.amazonaws.com/2015-03-31/functions/XXXXX/invocations"; AWS HTTP error: Connection refused for URI https://lambda.eu-west-1.amazonaws.com/2015-03-31/functions/XXXXX/invocations' GuzzleHttp\Exception\ConnectException: Connection refused for URI https://lambda.eu-west-1.amazonaws.com/2015-03-31/functions/XXXXX/invocations in C:\Apache24\htdocs\vendor\guzzlehttp\guzzle\src\Handler\StreamHandler.php:328
The script is:
<?php
require 'vendor/autoload.php';
use Aws\Credentials\Credentials;
use Aws\Lambda\LambdaClient;
$data = 'TEST PAYLOAD';
$array_obj = array("xml" => $data);
$json_obj = json_encode($array_obj);
$credentials = new Aws\Credentials\Credentials('<<KEY>>', '<<SECRET>>');
$client = new Aws\Lambda\LambdaClient([
'version' => 'latest',
'region' => 'eu-west-1',
'credentials' => $credentials,
'debug' => false,
]);
$lambda_result = $client->invoke([
'FunctionName' => 'XXXXX',
'InvocationType' => 'RequestResponse',
'LogType' => 'None',
'Payload' => $json_obj,
]);
print_r(json_decode($lambda_result->get('Payload')->getContents(), true))
?>
I'm pretty sure I'm just missing some config that will allow the web page script to call the Lambda, but I'm drawing a blank searching around for an answer.
EDIT:
Edited to clarify that this is running on a Windows Server 2019 EC2 instance, and the page is called with HTTP, not HTTPS.
EDIT 2:
I get the same issue with SQS, so its not a Lambda thing specifically. Seems to be generally about accessing AWS resources through the SDK APIs? (Tags adjusted accordingly)

Try to connect IBM MQ with PHP MQ 9.2

We are using linux server CENTOS 7 but virtual. We install to /var/mqm (9.2-IBM-MQC-linux) to our server. we install /mqseries-0.15.0 with /opt/cpanel/ea-php74/root/usr/bin/phpize to our server. we try to connect with IBM MQ with php code
<?php
$mq_host_ip='****(1414)';
$queue_name = '****';
$mq_server = '****';
$mqcno = array(
'Version' => MQSERIES_MQCNO_VERSION_2,
'Options' => MQSERIES_MQCNO_STANDARD_BINDING,
'MQCD' => array(
"ChannelName" => "*****",
'ConnectionName' => $mq_host_ip,
'TransportType' => MQSERIES_MQXPT_TCP
)
);
// Connect to the MQ server
mqseries_connx($mq_server,$mqcno,$conn,$comp_code,$reason);
if ($comp_code !== MQSERIES_MQCC_OK) {
echo 'Cannot open connection to server: ' . $comp_code ."--".$reason."--". mqseries_strerror($reason);
}else{
echo 'Connection good!';
}
?>
we get the error this
Cannot open connection to server: 2--2035--Not authorized for access.
.This is the our folder /home/trialwebsite/public_html.
Best Regards.
Murat ÖZKAN
The queue manager error log will usually tell you what specifically is wrong with the authentication/authorisation for a client program. The userid associated with the channel does not have appropriate rights or cannot be authenticated.
But one problem you might have with PHP is that it looks like the PECL-published PHP MQ library has not been maintained for a number of years and does not recognise the MQCSP structure needed to set the userid/password that the queue manager might be expecting. There is an un-merged PR opened at https://github.com/php/pecl-networking-mqseries/pull/5 which claims to add the MQCSP support so you might be able to do a git clone and use that branch as an alternative source of the interface.

Error retrieving credentials from the instance profile metadata server error in AWS SDK

I am developing an web application using PHP. I am storing the user credentials on the AWS Cognito service. I am logging in the user to the Cognito using PHP SDK.
I developed the feature successfully. I tested it locally on my machine, it was working. Then I deployed it onto the staging server, it was working on the staging server as well. But when I deployed it on to the live server, it gave me this error:
(1/1) CredentialsException
Error retrieving credentials from the instance profile metadata server. (cURL error 7: Failed to connect to 169.254.169.254 port 80: Connection refused (see http://curl.haxx.se/libcurl/c/libcurl-errors.html))
This is my code
try{
$client = new CognitoIdentityProviderClient([
'version' => 'latest',
'region' => 'eu-west-2'// env('AWS_REGION', '')
]);
$result = $client->adminInitiateAuth([
'AuthFlow' => 'ADMIN_NO_SRP_AUTH',
'ClientId' => COGNITO_APP_CLIENT_ID,
'UserPoolId' => COGNITO_USER_POOL_ID,
'AuthParameters' => [
'USERNAME' => $request->email,
'PASSWORD' => $request->password,
],
]);
$auth_result = $result->get('AuthenticationResult');
$cognito_access_token = $auth_result['AccessToken'];
if(!empty($cognito_access_token))
{
//register the user
$reg_user = $this->accRepo->register($request);
if($reg_user)
{
Auth::login($reg_user);
$token = $reg_user->createToken($this->tokenTag)->accessToken;
unset($reg_user->password);
return response()->json([ 'success' => true, 'access_token' => $token, 'account' => $reg_user ], SUCCESS_RESPONSE_CODE);
}
}
}
catch(Exception $e)
{
}
I am using the exact code and setting and credentials as the local machine and the staging server for the live server. But it does not work on the live server. Working on the other environments. What might be the error? I am deploying it on Heroku.
I am not familiar with Cognito, but the error you're seeing is that your code is attempting to access the Instance Metadata available in EC2. The AWS PHP SDK has a specific order in which it attempts to locate credentials. Here is an outline of different credential methods using the PHP SDK.
So, I suspect it works on your local machine because you have an IAM profile configured using the AWS CLI aws configure command.
It most likely works on your staging server because that server has an IAM Role attached to the EC2 instance. The PHP doesn't find a locally configured IAM profile, so it then skips to attempting to access the EC2 metadata, which it does successfully, so it gets authenticated.
Now, when you deploy to Heroku, it is no longer on an EC2 instance, or in your local environment. So, your CredentialProvider fails. My suggestion would be to utilize Config Vars in Heroku, then change your code to use CredentialProvider::env() as outlined here. You would need to create an IAM user with the same role as your EC2 instance that works (or enough permissions to do what you need to do). This would allow your application to securely access Cognito from an environment external to AWS.

Access Remote SQL database [2002]

Okay so i am trying to connect to my remote SQL database.
i am using the following settings:
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => '10.246.16.153:3306',
'login' => '*******',
'password' => '*******',
'database' => 'udlejnings_pris',
'prefix' => '',
//'encoding' => 'utf8',
);
My Database settings are the following:
Database server
Server: 10.246.16.153 via TCP/IP
Software: MySQL
Software version: 5.1.66-0+squeeze1 - (Debian)
Protocol version: 10
Server charset: UTF-8 Unicode (utf8)
Now when im trying to access this server i get the following error:
2013-10-12 16:27:28 Error: [MissingConnectionException] Database connection "Mysql" is missing, or could not be created.
Exception Attributes: array (
'class' => 'Mysql',
'message' => 'SQLSTATE[HY000] [2002]
',
'enabled' => true,
)
So what am i doing wrong?
Many hosted MySQL instances don't allow clients to connect remotely by default. You may need to add your IP address into some form of Remote MySQL option if your database host provides it. For example, if the server with the database on it uses cPanel, there is a 'Remote MySQL' option on there which may resolve your issue. Alternatively, you could execute the 'GRANT' SQL command to allow your user account access remotely as described in this answer.
If you still have issues, a firewall may be blocking the connection locally too.
Maybe you need to enable mysql remote access on the server that you are connecting to. By default it is disabled.
http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html

MySql Error: cannot connect to local MySql server through socket '/var/run/mysqld/mysqld.sock' (2), while other pages do connect correctly

I understand this problem has been a recurring problem on this site, but my issue is a little different than the previous ones.
PROBLEM
Some pages use the correct socket directory, while other pages try and connect through an incorrect socket directory or this is what I believe the problem is based on the error i am receiving.
DETAILS
HOST: example.com
cakePHP version: 1.3.2 (Not my choice).
Page's content comes from database.
URL: http://example.com
My website has 2 sections:
anonymous section
login section for members or admin
The anonymous section works. It accesses the database, adds the content, and funcitons as it should.
ERROR
The error occurs when I click a link "view more.." under "Job Links" on the home page. A login form should pop up, instead i receive the error "cannot connect to local MySql server through socket '/var/run/mysqld/mysqld.sock' (2)".
In addition, after I login via the "Members login" button, also on the home page, with the correct credentials, it also produces the same error.
QUESTION
Why would different sections on my webpage try to access the sockets through different directories?
ADDITIONAL STUFF
I signed up today and this is my first post, so feedback on my post regarding enough information would be helpful for future posts.
Thanks for your time.
UPDATE
Upon further research, MySql has been using the socket directory /var/run/mysqld/mysqld.sock from the start. Not sure what this means yet, but continuing research..
database.php file
class DATABASE_CONFIG {
var $default = array(
'driver' => 'mysqli',
'persistent' => true,
'host' => 'redlabelcom.netfirmsmysql.com',
'login' => 'bcp',
'password' => '********',
'database' => 'bcp',
'prefix' => '',
'encoding' => 'UTF8',
//'socket' => '/var/run/mysqld/mysqld.sock', // I've tried commenting out all variations of socket and port
//'port' => '/var/run/mysqld/mysqld.sock', // nothing works.
);
var $test = array(
'driver' => 'mysqli',
'persistent' => false,
'host' => 'redlabelcom.netfirmsmysql.com',
'login' => 'bcp',
'password' => '********',
'database' => 'bcp',
'prefix' => '',
'encoding' => 'UTF8',
//'port' => '/var/run/mysqld/mysqld.sock',
);
}
?>
This problem is really strange. I guess this has something to do with mysql connection. MySQL is a daemon, usually configured in /etc/mysql/my.cnf. There you define how the client will connect the MySQL server:
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
If your socket is wrong (there's no such socket on the server), you are probably connecting different mysql host/port from anonymous/secured parts of application. This is possible (I mean different db connections from different application parts). Check your configuration (host, port, etc.) and try to connect from MySQL console:
$ mysql -h hostname -u username -p dbname # enter password
and check if you can connect. If you can connect from console, you'll surely connect from any server-side application (php, python, whatever).
It's an application that someone else was developing, right, and now you have to maintain it?
PROBLEM SOLVED!
Thanks everyone for your support!
This was an interesting issue that initially looked more complicated than the actual problem.
cakephp version 1.3.2 is set up to make a new connection to the database if you need to access the phpbb data fields. The new connection uses a different configuration than what is set up in the database.php file.
Below is a detailed description with file locations.
the 'app/webroot/discussion/common.php' file makes a NEW connection to the database using a different set of MySql parameters than the database.php file. Again, it does NOT use database.php's MySql configuration.
Instead, cakephp defines new connection variables located at:
'app/webroot/discussion/config.php'
To solve the problem, simply change the
$dbhost => localhost -> $dbhost => yourservername
$dbname => wrongname -> $dbname => rightname
etc..
Keep in mind that it is possible the previous developer changed these values, so if this doesn't help you then good luck.
BTW, the error message above was the result of trying to connect to localhost.
To resolve this issue, I ran the following commands:
mysqld --tc-heuristic-recover=ROLLBACK
systemctl start mariadb.service

Categories