Connecting to Gmail via Horde_Imap_Client - php

I have tried to connect to mit private as well to my google apps for work inbox via IMAP using the Horde_Imap_Client. I have used the following config:
$config = array(
'username' => $username,
'password' => $password,
'hostspec' => 'imap.gmail.com',
'port' => '993',
'secure' => true,
"debug" => "imap.log",
"debug_literal" => true
);
I also tried ssl, sslv2, sslv3 and tls for the secure value. The Exception i got was Error when communicating with the mail server. and the imap.log only showed me this
------------------------------
>> Thu, 28 Jan 2016 18:29:14 +0100
>> Connection to: imap://imap.gmail.com:993/
>> Server connection took 0.0156 seconds.
>> Slow Command: 10.018 seconds
>> ERROR: read/timeout error.
------------------------------
I also tried allowing "insecure apps" in my google account but the result was the same. Any clues? The connection works fine with our in-house IMAP server and the office365 IMAP server

Change
'secure' => true,
to
'secure' => 'tlsv1',
This will force TLSv1 connections.
I ran into this same problem myself. I posted to the Horde mailing list but was able to resolve the issue a day later on my own with the above change.

Related

Nextcloud not connecting to Redis

On a Nextcloud install I am receiving the error
No memory cache has been configured. To enhance performance, please configure a memcache, if available. Further information can be found in the documentation.
So I have installed APCu, Redis, redis-php and made the required settings in NCs config.php
'memcache.local' => '\OC\Memcache\APCu',
'memcache.locking' => '\OC\Memcache\Redis',
'memcache.distributed' => '\OC\Memcache\Redis',
'filelocking.enabled' => 'true',
'redis' =>
array (
'host' => '127.0.0.1',
'port' => '6379',
When I test the redis connection
redis-cli ping
I get a
PONG
(This works both w/ localhost and unix socket)
But Nextcloud obviously does not connect to Redis.
The http user is a member of the redis group.
php-redis module is activated.
Solved. The issue was with the location of the above code inside Nextcloud's config.php.
Now it is working as expected.

How to force TLS 1.2 with SoapClient?

I am using a PSP that recently switched to only support TLS 1.2 (as per PCI-DSS).
Within a php7 application, I can connect to their SOAP API. However, since their upgrade I am getting an SSL error indicating their server does not support my TLS version. I ran a wireshark and can confirm there is only a client hello, so server hello and it is on TLS 1.0.
I am using the following code:
$this->soapClient = new SoapClient('some/wsdl'), [
'location' => 'https://endpoint.of.server',
'soap_version' => SOAP_1_1,
'stream_context' => stream_context_create([
'ssl' => [
'local_cert' => '/path/to/client.crt',
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT,
],
])
]);
However, this code still uses TLS 1.0 and not the desired TLS 1.2.
Versions
OpenSSL 1.1.0h 27 Mar 2018
PHP 7.1.6-1~ubuntu16.04.1+deb.sury.org+1 (cli) ( NTS ).
As it turns out, the above code is 100% correct.
In my case, the error lay somewhere in the certificate. For still unknown reasons, our self-generated SSL client certificate did not cope well with TLS 1.2. After we generated a new certificate, everything worked like magic.
Things I've tried / verified
Make sure your have a supported openssl verion (>= 1.0.1)
Consider manually specifying the ciphers
Debug the connection using Wireshark to verify the protocol
Also, take a look at How to force a certain TLS version in a PHP stream context for the ssl:// transport?

unable to Curl or SoapClient Any remote_server:8080 port on Directadmin Centos

I am Trying To Connect a Soap Api by php
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
$opts = array(
'ssl' => array('ciphers'=>'RC4-SHA', 'verify_peer'=>false, 'verify_peer_name'=>false)
);
$params = array ('encoding' => 'UTF-8', 'verifypeer' => false, 'verifyhost' => false, 'soap_version' => SOAP_1_1, 'trace' => 1, 'exceptions' => 1, "connection_timeout" => 5, 'stream_context' => stream_context_create($opts) );
$url = "http://x.x.x.x:8080/ws-relay/MessageRelayService?wsdl";
$client =new SoapClient($url,$params);
$result = $client->sendMessageOneToMany(array(
"username" => 'xxxxx',
"password" => 'xxxxx',
"originator" => "50004132311446",
"destination" => $numbers,
"content" => $massage,
));
but it allways got an
SOAP-ERROR: Parsing WSDL: Couldn't load from 'x.x.x.x:8080/ws-relay/MessageRelayService?wsdl";' : failed to load external entity "x.x.x.x:8080/ws-relay/MessageRelayService?wsdl";")
error !
I also Tried to Curl This WSDL but I got
[root#myhost ~]# curl http://x.x.x.x:8080/ws-relay/MessageRelayService?wsdl
curl: (7) Failed to connect to x.x.x.x port 8080: Connection timed out
Error !
so i also tried to curl portquiz.net:8080/ for test and i got timeout again !
is there some rule in firewall that block me to send request to 8080 ports !
how can i unblock it in centos directadmin vps ?
often this happens because that your ip address has been blocked , or there are an issues with the server it self .
for more info about that , libcurl error codes
CURLE_COULDNT_CONNECT (7)
Failed to connect() to host or proxy.
for your command :
curl http://xx.xx.xx.xx:xxxxws-relay/MessageRelayService?wsdl
when executing it in my own pc i got the response normally .
so you will need to use proxy in your SoapClient class
For making an HTTP connection through a proxy server, the options
proxy_host, proxy_port, proxy_login and proxy_password are also
available.
so you will need to add some params to your $params array ass follows :
$params['proxy_host'] = "proxy_ip";
$params['proxy_port'] = "proxy_port";
it's also possible (personally i recommend this) to use procedures libcurl functions or packages built on it.
if you want to use the cli way , so your command may be some thing like this :
curl http://xx.xx.xx.xx:xxxx/ws-relay/MessageRelayService?wsdl -x "ip_address:ip_port"
for socks5 ips
curl http://xx.xx.xx.xx:xxxx/ws-relay/MessageRelayService?wsdl -x "ip_address:ip_port" --socks5

FTP Implicit SSL class - never connects - how to debug?

I am trying to connect to an FTP service which requires the user to connect via Implicit SSL. The details are working in CuteFTP so my credentials are 100%.
I am trying to use this class and the connection method below but it just times outs.
Class: https://gist.github.com/maxrice/4544344
<?php
include "../objects/shared/ftp-implicit-ssl-tls.php";
$FTP_Implicit_SSL = new FTP_Implicit_SSL("myuser", "mypass", "rapidata.sharefileftp.com", 990, "Organisations/Avid/RDS_Data", true);
$FTP_Implicit_SSL->upload("text.txt", "text.txt");
?>
There is a simple text.txt file in the same directory as the script.
Fatal error: Uncaught exception 'Exception' with message 'Could not upload file. cURL Error: [7] - Failed to connect to rapidata.sharefileftp.com port 990: Connection timed out
My web host reports the script should be able to connect and this is what they see:
Last login: Wed Apr 29 16:14:57 2015 from 79.174.170.1
root#server-1:~# telnet rapidata.sharefileftp.com 990
Trying 54.194.108.219...
Connected to rapidata.sharefileftp.com.
Escape character is '^]'.
Then eventually
Connection closed by foreign host.
Pleaase - any ideas what is going on here or how to find out?
what about these settings in the class?
$options = array(
CURLOPT_USERPWD => $username . ':' . $password,
CURLOPT_SSL_VERIFYPEER => false, // don't verify SSL
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_FTP_SSL => CURLFTPSSL_ALL, // require SSL For both control and data connections
CURLOPT_FTPSSLAUTH => CURLFTPAUTH_DEFAULT, // let cURL choose the FTP authentication method (either SSL or TLS)
CURLOPT_UPLOAD => true,
CURLOPT_PORT => $port,
CURLOPT_TIMEOUT => 300,
);

Cannot connect to PgSQL via Laravel SQLSTATE[08006] [7] FATAL

I'm trying to connect to pgsql via laravel and finally got everything setup (pgsql server running, pdo installed, all libs installed). I'm running on a VPS (CentOS) managed via CPanel/WHM.
Here's what I'm doing:
I'm trying to create a user database via artisan (Laravel's command line) using migrate:install.
For those that don't use Laravel, artisan uses php's PDO for pgsql to connect. Here are my settings:
'pgsql' => array(
'driver' => 'pgsql',
'host' => 'localhost',
'database' => 'dbname',
'username' => 'username',
'password' => 'password',
'charset' => 'utf8',
'prefix' => '',
),
I've also setup a test.php file:
$dbconn = pg_connect("host=localhost port=5432 dbname=dbname user=username password=password");
which also fails. I used phpPgAdmin to see what's up and all of the permissions are set correctly, the database shows up, the username is correct, same with password. I checked where postgre (version 8.4.12 btw) was running and phpPgAdmin tells me "localhost:5432".
The error I get via the command line is the following:
SQLSTATE[08006] [7] FATAL: no pg_hba.conf entry for host "::1", user "myusername", database "my_database", SSL OFF
Now, I tried to find the pg_hba.conf file but I'm not entirely sure where to look for it. Same goes for the error/access logs for pg and google hasn't been any help as far as this goes.
Any idea on what I can do?
localhost points to IPV6 ::1 address on your system. Postgresql makes the difference between ipv6 and ipv4 addresses when dealing with access list.
I was able to install/configure everything correctly. I changed the "host" to 127.0.0.1, not sure why that made a difference but it did :)

Categories