PHP Composer using define - php

I am using phpseclib to do some SFTP stuff. At the moment I can't login, and I am trying to find out why. In the docs, it states I should do something like this
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
include 'Net/SFTP.php';
define('NET_SFTP_LOGGING', NET_SFTP_LOG_COMPLEX);
$sftp = new NET_SFTP('***');
if(!$sftp->login('***', '***')) {
print_r($sftp->getSFTPErrors());
}
So, I need to define the type of logging in order to print out the SFTPErrors.
I am doing things differently than the above because I am using composer. So as usual, I load autoload.php. Instead of include, I make use of use e.g.
use phpseclib\Net\SFTP;
I then proceed to do something like the following
define('NET_SFTP_LOGGING', NET_SFTP_LOG_COMPLEX);
$sftp = new SFTP($config::SFTP_SERVER);
if(!$sftp->login($config::SFTP_USER, $config::SFTP_PASSWORD)) {
print_r($sftp->getSFTPErrors());
exit('Login Failed');
}
If I do this however, I get the output
Notice: Use of undefined constant NET_SFTP_LOG_COMPLEX - assumed 'NET_SFTP_LOG_COMPLEX' in ...
Array
(
)
Login Failed
So it appears that with composer, I cant define a constant in the same way, and the print out of the errors produces an empty array.
So, how can I define this constant in my composer project?
Thanks

A few of things.
If you're using the namespaced version of PHP (as evidenced by your use phpseclib\Net\SFTP;) then you're using the 2.0 branch. The documentation on the website is for the 1.0 branch. For the 2.0 branch you need to do as FĂ©lix Saparelli suggested - SSH2::LOG_COMPLEX.
That said, logging isn't going to show SFTP errors. Logging shows you the raw packets. Here's an example of what the logs produce:
http://phpseclib.sourceforge.net/ssh/log.txt
You get these logs by doing $ssh->getLogs().
For the errors you don't need to enable anything - it places any errors it receives from the server into an array that it's returning to you. phpseclib does this automatically and this behavior cannot be disabled.
Also, $sftp->getSFTPErrors() is great for SFTP errors but at the login process you might be getting SSH errors and not SFTP errors. You'd get SSH errors by doing $sftp->getErrors(). The thing is... SFTP operates in a higher layer than SSH. SSH won't succeed if TCP/IP can't make a connection and SFTP won't succeed if SSH can't make a connection. So per that you ought to be checking all the layers.
Finally, it's quite possible the failure is happening for reasons for which errors would not be returned. Maybe the server requires compression, which phpseclib doesn't support. eg.
http://www.frostjedi.com/phpbb3/viewtopic.php?p=221481#p221481
I also don't know if you'd get an error if the key or password you were using was simply invalid.
Really, there could be any number of causes for an inability to connect. You could be using selinux which, by default, disables outbound connections from PHP scripts running on port 80, there could be a routing issue, etc (all of these affect fsockopen, but, in all, there are just a lot of potential causes for failure).
Overall, I'd say you're on the right track with the logs. But do $sftp->getLog() instead of $sftp->getSFTPErrors() and then include the logs in your post.

Related

Connection to Simpro API not working - Tivoka send is failing

I'm having trouble connecting to our Simpro server via the API.
I am using a slightly modified version of the directaccessexample.php as per the Simpro GIT repository here - https://github.com/simPRO-Software/simpro-api-php
My server PHP version is 5.6.32
My composer is loading the below packages:
{
"require": {
"monolog/monolog": "",
"eher/OAuth": "1.0.",
"tivoka/tivoka": "3.1.0",
"psr/log":"*"
}
}
In my attempts to debug, the Client.php script (as provided by the Simpro GIT) appears to fail at specifically the send call from the below lines:
$rpcRequest = new \Tivoka\Client\Request($method, $args);
$this->connection->send($rpcRequest);
I have identified this by outputting to error_log above and below this line - the code appears to die in the function on the send request (and therefore never reaches the second error_log output. There is no error logged that I can see which I find bizarre, it just appears to exit the function.
I am not seeing any other errors in any php error log/apache log/etc, and I've ruled out the issue being the firewall on my server.
I am wondering if this is a problem with versions of PHP or the installed packages from composer - though I have tried a couple of different specific versions without any luck (no change to php version, however).
From the above code, the json_encoded output of $rpcRequest is:
{"id":"7b0911cc-dd67-4032-b810-474e549edecc","method":"CompanySearch","params":["%"],"request":null,"response":null,"result":null,"error":null,"errorMessage":null,"errorData":null,"responseHeaders":null,"responseHeadersRaw":null}
Can anybody assist here? I am pulling my hair out. I'm aware I could attempt to write my own code using different oauth/rpc packages but I am not that advanced with PHP.
Thanks,
Justin.

Can't ssh to server using keys authentication

Since a few days now I've been creating ssh keys using the phpseclib library (Branch 2.0) like I've done before..copying the public key over to my server thus connecting without the use of a password....but for some reason I just can't connect like this anymore. When I report the errors using $ssh->getLastError(), it displays:
SSH_MSG_USERAUTH_FAILURE: publickey,password
Does anyone know what could be the problem?
Ensure that your private key is added to authorized_keys on the server. Without that, you'll always get this error. More specifically, in my case it was:
SSH_MSG_USERAUTH_FAILURE:
publickey,gssapi-keyex,gssapi-with-mic,password

Why is Wamp server giving errors when I use Composer?

I'm trying to use the API of a dutch site that's being used by schools in The Netherlands to keep track of the grades and other data of the students. You can find the documantation here: http://www.magister-api.nl/ (it's in Dutch).
I installed Wamp server and Composer, just like the documentation of the API tells. I also have the Curl PHP extension and Mcrypt PHP extension enabled in Wamp, just like the documentation tells.
I have the composer.json file in the project root with:
{
"require": {
"stanvk/magister": "~2.0"
}
}
I then executed Composer update.
The only code that I have is:
<?php
require 'vendor/autoload.php';
use Magister\Magister;
use Magister\Models\Grade\Grade;
new Magister($school, $username, $password);
$grades = Grade::all();
foreach ($grades as $grade)
{
echo $grade->CijferStr;
}
?>
It's the exact same code as given as example on the documentation website.
But when I then run it, I get these errors:
Errors
I tried a lot to solve the problem, but I can't seem to figure it out. It's the first time I'm using composer and packagist.
The first two errors are unrelated to composer or Wamp - you're simply using two variables that hasn't been defined, $username and $password (and possibly $school). The rest of the errors seems to stem from these having no value (the Magister object seems to try to request username.magister.net, and without a username .. that field is empty).
Provide the correct username and password and things will probably work as you expect.

OpenX: Moved to different Server

I moved the installation to a different server. I updated the configfile in the var/ directory and the banners are served, but the admin interface is not working.
i get the error:
A fatal error occurred OpenX can't connect to the database. Because of
this it isn't possible to use the administrator interface
i cleaned the cache directory in var but then i get
PHP Fatal error: Call to undefined method MDB2_Error::quoteIdentifier() in /[path]/opx/lib/OA/Upgrade/VersionController.php on line 50
I dont know which version this is, but it looks like its at least 2 years old.
Is there any special cache in place im not aware of?
Any help on this would be much appreciated.
Mental note,.. if you have the db on a different server then openx it does not matter if you set the host to the ip of the db server and the port.. as long if you not set protocol=protocol !!!
this is by far the most stupidest thing i have ever seen, there is no need for a protocol config, as php always uses the socket if you set "localhost".
It's not easy to tell exactly what's wrong here, but one can make a good guess:
As we can see from the error message, there is an object in your code that doesn't implement the method quoteIdentifier().
There are mainly two possible reasons for this: Either we're calling an older or newer version of the same Class instance which doesn't implement the method. Maybe because it's deprecated or who knows. Or the object simply isn't of the expected type.
Lo and behold, if we look for an MDB2 related class that DOES implement this method, it's the class MDB2. Not MDB2_Error! So now we know the reason for the error, it's time to speculate about the root cause.
Connecting to a database with MDB2 works roughly like this:
$mdb2 =& MDB2::connect('pgsql://usr:pw#localhost/dbnam');
if (PEAR::isError($mdb2)) {
die($mdb2->getMessage());
}
There it is. We can see that $mdb2 can actually be of type MDB2_Error, in case connecting goes wrong for some reason. So that is the cause: Your code cannot connect to the DB for some reason. So the next obvious step should be checking if your db user has the correct rights and is using the correct password. I am 100% sure your admin backend doesn't use the right credentials.

Unable to query RoleEnvironment with Windows Azure SDK for PHP

I have an issue with obtaining data from Windows Azure's runtime using the newest (at the time of writing) PHP SDK from Github. Here is a test I am running on one of our hosted services:
<?php
include 'WindowsAzure/WindowsAzure.php';
use \WindowsAzure\ServiceRuntime\RoleEnvironment;
use \WindowsAzure\ServiceRuntime\Internal\RoleEnvironmentNotAvailableException;
try {
echo RoleEnvironment::getDeploymentId();
}
catch (RoleEnvironmentNotAvailableException $Exception) {
die('Failed to find deployment id');
}
RoleEnvironmentNotAvailableException is always thrown. Looking at the source, it seems to try sending commands through a named pipe (\.\pipe\WindowsAzureRuntime). Do I need to specify something within my ServiceConfiguration.csdef/cscfg in order to have access to this named pipe?
Any advice would be most welcome!
Got confirmation from MS EMEA Developer Support that current SDK does not support this function. They suggested similar workaround to jonnu above - use the previous SDK's functionality for role environment / configuration settings.
The ServiceRuntime APIs run only on Cloud so if this code snippet runs on local machine it'll throw an exception as you've pointed out. Further, if you want to debug your ServiceRuntime code you've to deploy your service to WA then use remote desktop connection to access the cloud machine and debug your code.

Categories