I'm trying to access my owncloud webdav interface and get the list of files in the root directory from PEAR WebDAV Client. I'm trying the following:
include("HTTP/WebDAV/Client.php");
$client = new HTTP_WebDAV_Client_Stream();
$user="admin";
$pass = "q1w2e3r4";
$dir = "webdavs://".$user.":".$pass."#127.0.0.1:10081/owncloud/remote.php/webdav/";
$stuff = $client->dir_opendir($dir, array());
var_dump($stuff);
var_dump($client->dirfiles);
The code print false, false, and when I've tried to debug it, I saw Connection refused error in Socket.php, when it tried to call the function
fsockopen("127.0.0.1", 10081, $err, $errstr);
It's even more strange since I can access this server and list the directories from cadaver though. Also I can access the test DAV server with my code by replacing my $dir variable:
$dir = "webdavs://".$user.":".$pass."#127.0.0.1:10081/owncloud/remote.php/webdav/";
It's an ugly hack, but if you add something similar to:
var_dump($err->getMessage());
to /usr/share/php/HTTP/Request.php on line 739, you should be able to see the most relevant error message. (If that is where Request.php got installed to.)
Unfortunately, there doesn't appear to be a mechanism in place in the underlying HTTP_Request package for raising that specific error message back to the HTTP_WebDAV_Client_Stream code.
Related
I am new to php . Currently as part of Migration activity we copied the existing php application to a new infrastructure where we are facing a strange issue.
Problem Statement:
From the php application,not able to read any file and it is not throwing any errors also. I used the following libraries and got the same behavior:
file_get_contents (This is the existing mechanism and I should use this one in the new infrastructure also)
Below two, checked to triage the issue:
readfile
fopen (tried with fopen just to see whether able to open like fopen($file, "r") or die( ),but this is also going to die condition
Issue Triaging
Made the below sample.php and make it available in my current server configuration. This is available by accessing through url (for e.g. https://myapplicationdomain/myapplication/sample.php). This php component is reading an input.txt which is in the same directory (actually this is the simulation of our problem)
<?php
ini_set('display_errors', 1); // show errors
error_reporting(-1);
//set your own error handler before the call
set_error_handler(function ($err_severity, $err_msg, $err_file, $err_line, array $err_context)
{
throw new ErrorException( $err_msg, 0, $err_severity, $err_file, $err_line );
}, E_WARNING);
echo "fopen url is";
var_dump(ini_get('allow_url_fopen'));
try{
$file ='input.txt';
if(is_readable($file)) {
echo "$file is readable \n"
} else {
echo "$file is not readable \n";
}
if(file_exists($file))
{
$homepage = file_get_contents($file);
var_dump($homepage);
echo "content is $homepage \n";
}else{
echo "file is not present \n";
}
}catch (Exception $e) {echo 'Error Caught $e';}
?>
Apache server is running using apache user and this user is having permission in the files and parent directories,
Following are the observations we got during triaging this:
When accessing through url for e.g. https://myapplicationdomain/myapplication/sample.php (i.e. through apache server).
a. functions is_readable & file_exists are returning true.
b. file_get_contents is returning blank and when I did var_dump, it is returning 'Null'
c. Confirmed the value of allow_url_fopen and it is returning 1 which is true
d. No errors are getting logged in this case.
e. Changed the permission of the 'input.txt' to see the permission behaviour. In that case,proper error got displayed in is_readable it self.So through this way ruled out the possibility of permission issue and also confirmed the error handler implementation is working fine.
f. Changed the location of input.txt to outside folders . ie. home/apache_user/ or root directory. Still file read operations are failing.
Able to run the same php code independently. i.e php sample.php .In this case,it is working as expected and all file reading operations are working fine.
3.Checked all the below php.ini configurations (removed all the values in disabled functions for testing)
a. open_basedir => no value
b. disabled_functions => no value
c. allow_url_fopen => true
Checked all the posts ,but not getting any idea how to proceed further. Following are version we are using: PHP 7.3.5 , CodeIgnitor framework and also configured php-fpm.
As per my understanding php library which apache was referring had some issues. Since it is a migration project and it is working fine in the current environment,copied the existing php folder (which was inside apache) and fpm binaries and configurations from the working environment to the new environment.Still not got any idea on exact root cause (as only read scenario was failing),but this got worked
I'm facing an issue in PHP where I can't open a file located on a network drive for reading
I have tried a lot of different path name
$file = fopen('G:/Folder/vak.xlsx', 'r');
$file = fopen('//10.X.X.X/Folder/vak.xlsx', 'r');
$file = fopen('\\\\10.X.X.X\\Folder\\vak.xlsx', 'r');
But I always get the same error
Could not open "G:/Folder/vak.xlsx" for reading! File does not exist.
I have read a lot of post related to this issue and try all the solutions that i've found, but nothing works.
The network drive is mapped on the server under G: and the apache service is launched with a domain user account who's allowed to access to the network drive.
The server is running WAMP (Apache + Mysql + PHP 5.6)
I don't know why it's not working. Maybe someone has already solved this issue.
EDIT :
I have also try to use scandir() like this :
$files = scandir('\\\\10.X.X.X\\');
var_dump($files);
And I get
The network name cannot be found. (code: 67)
I just installed CouchBase and the .dll files for XAMPP. I am following their example on how to connect: "Hello Couchbase" https://developer.couchbase.com/documentation/server/current/sdk/php/start-using-sdk.html
This code:
$bucketName = "default";
// Connect to Couchbase Server
$cluster = new CouchbaseCluster("couchbase://127.0.0.1");
$bucket = $cluster->openBucket($bucketName);
gives me:
LCB_AUTH_ERROR: Authentication failed. You may have provided an invalid username/password combination
I have a fresh installation, and following their guide #1, what am I doing wrong? I don't remember setting a password, I went to the CouchBase admin page and I can't find a way to change any password.
I sympathize here -- I'm having the same error (and no, it's not you, the docs have been neglected). Instantiating the CouchbaseCluster doesn't throw the error, it's actually the openBucket() method that causes problems, and for me, the problem was that the bucket didn't exist (it would be nice if the Couchbase error were in the right ballpark instead of bumbling around in irrelevant confusion). Here's some code that worked for me:
$cluster = new CouchbaseCluster('http://127.0.0.1:8091');
$manager = $cluster->manager('MYUSER', 'MYPASSWORD');
$manager->createBucket('new_bucket');
This does throw some errors:
[cb,WARN] (htconfig L:130 I:0) <couchbase:8091> (CTX=0x5601e6fd7e90,bc_http) Got 404 on config stream. Assuming terse URI not supported on cluster
[cb,EROR] (htconfig L:122 I:0) <couchbase:8091> (CTX=0x5601e6fd7e90,bc_http) Got 404 on config stream. Assuming bucket does not exist as we've tried both URL types
[cb,EROR] (htconfig L:142 I:0) <couchbase:8091> (CTX=0x5601e6fd7e90,bc_http) Got non-success HTTP status code 404
But it does work. The Couchbase forums are a better place for these types of questions -- they respond pretty quickly over there.
Running a database migrate in PHP (via Phing), I'm getting the following FAILED BUILD error:
Unable to open /site/thewebsite.co.uk/data/migrate-web_site-sed: 1: "s/[^a-z0-9]/-/gi": bad flag in substitute command: 'i'.sql for reading:
as well as several warnings along similar lines:
[PHP Error] fopen(/site/thewebsite.co.uk/data/migrate-web_site-sed 1: "s/[^a-z0-9]/-/gi": bad flag in substitute command: 'i'.sql): failed to open stream: No such file or directory [line 224 of /site/thewebsite.co.uk/vendor/phing/phing/classes/phing/tasks/ext/dbdeploy/DbDeployTask.php]
Does anyone have ideas about where to start looking for a resolution and/or the cause of the problem? The site files were cloned from a previously working repository and to my knowledge the DbDeployTask.php file has not been changed by any of my co-workers since the last working copy was cloned. I've had a look through the relevant .php file and I can't see any obvious issues. The section of the code referenced looks pretty standard:
protected function createOutputFile($file, $undo = false)
{
$fileHandle = fopen($file, "w+");
$sql = $this->generateSql($undo);
fwrite($fileHandle, $sql);
}
With createOutputFile called from within the deploy function:
protected function deploy()
{
// create deploy outputfile
$this->createOutputFile($this->outputFile, false);
// create undo deploy outputfile
$this->createOutputFile($this->undoOutputFile, true);
}
Where would people advise looking for the source of this issue, so our Apache server is able to deploy the development website correctly on this Macintosh?
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.