I have a script wich uses the Plesk API to create FTP accounts. The script worked perfectly untill we moved to new VPS at a new provider.
The script doesnt work anymore and I get an error like this:
cURL error number:7 cURL error:Failed to connect to xx.xx.xxx.xxx permission denied.
It seems that cURL doesnt work. What i've tried is changing the php support from fastCGI to Apache module in PLESK and the error message is gone but the PLESK API does nothing though the load time of the page is much longer then when I'm using fastCGI so it looks like it does something.
I also added port 8443 to the firewall for incoming and outgoing.
I'm using PLESK 11 and my script looks like this.
// Plesk login gegevens
$host = "**********";
$login = "**********";
$pass = "**********";
$port = 8443;
// Maak de FTP map aan
$data =<<<EOF
<packet version="1.6.3.5">
<ftp-user>
<add>
<name>John</name>
<password>Doe1234</password>
<home>/private/John_Doe/</home>
<create-non-existent>true</create-non-existent>
<webspace-id>1</webspace-id>
</add>
</ftp-user>
</packet>
EOF;
sendCommand($data, $login, $pass, $host, $port);
function write_callback($ch, $data)
{
// echo $data;
return strlen($data);
}
function sendCommand($data, $login, $passwd, $host, $port=8443)
{
echo $data;
$script = "enterprise/control/agent.php";
$url = "https://$host:$port/$script";
$headers = array(
"HTTP_AUTH_LOGIN: $login",
"HTTP_AUTH_PASSWD: $passwd",
"HTTP_PRETTY_PRINT: TRUE",
"Content-Type: text/xml",
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, &$headers);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'write_callback');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
$result = curl_exec($ch);
if (!$result)
{
echo "\n\n-------------------------\ncURL error number:".curl_errno($ch);
echo "\n\ncURL error:".curl_error($ch);
}
curl_close($ch);
return;
}
I am not plesk or linux person, But i would like to contribute my part with this discussion,
I have a script wich uses the Plesk API to create FTP accounts. The
script worked perfectly untill we moved to new VPS at a new provider.
This statement clearly says problem is not your code, It's with your VPS.
Problem maybe!
1) Client permission to update Parallels Panel via API-RPC, try with admin credentials.
Issue found : plesk 9.2. So it may be fixed in next release but i am not sure. Source
2) Check SElinux is disabled or not, if not disable it and check. Your next question must be, how to disable SElinux. Answer is here well documented
3) You should install mod_suphp and follow our tutorial and will work. Check out here for more.
I just above summarized, few thinks hope it helps.
i am not sure but see below URL I think it is very help full to you.
Unusual HTTP headers in the Plesk API
According to Unusual HTTP headers in the Plesk API by TRiG
Or Read it
Below Answer by rdo according to above URL
Plesk uses own headers. In custom http request you can add any valid headers for example some webservers add own header like 'powered by: xxxx', so it's ok.
pretty print header is required for pretty xml output.
HTTP_AUTH_LOGIN header contains panel user login. HTTP_AUTH_PASSWD header contains panel user password. CURLOPT_USERPWD is not required.
try to use these options: $ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
curl_setopt($ch, CURLOPT_POSTFIELDS, $packet);
curl_setopt($ch, CURLOPT_TIMEOUT, 1200); //wait 20min
$response = curl_exec($ch);
Assuming you remembered to change the host, was your plesk user and password recreated after the move? Try logging into plesk on the VPS directly using the credentials from your script to make sure the account is ok.
Related
The below php code is making a REST API call that returns json object. This works fine when i use it on my localhost using WAMP Absolutely no problem.
However when i push this app on the server it would TimeOut and display 503 Service Unavailable.
I checked the logs it has an entry :
The TimeOut Specified has expired.
I contacted my admin he just said this app listens to PORT=64665 and HOST=0.0.0.0. What does that mean? What more changes do i need to make in my code to make it work on the server ? Help
<?php
$url = "http://xyz.net/v2/plan/"; // I have changed the REST URI API Link for security reasons
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PROXY, false);
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
curl_close($ch);
// Will dump json
var_dump(json_decode($result, true));
$response = "http://xyz.net/v2/plan/";
echo $response;
?>
Check your server's /etc/hosts file, there could be the problem, ie. domain mapped to another (wrong) IP address.
I create a process that log me in my account of #########.com. It work like a charm when I put it on my FTP.
This is the problem :
I have an apache local server set on my machine (easyPHP) on localhost:8080.
I have also an IIS server set on my machine at the port --> localhost:80.
My cURL request don't work. This is my code:
$lien = 'https://#########.com/login';
$postfields = array(
'username' => 'xxx',
'password' => 'xxx'
);
$path_cookie = 'connexion.txt';
if (!file_exists(realpath($path_cookie))) touch($path_cookie);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $lien);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($curl, CURLOPT_COOKIEJAR, realpath($path_cookie));
$return = curl_exec($curl);
echo($return);
echo 'error:' . curl_error($curl);
curl_close($curl);
}
Firstly: Yes I have cURL install on my server, I did some other cURL request between my apache server and my IIS server and everything work fine.
Secondly: The file "connexion.txt" is well create, BUT empty.
Thirdly: The echo of ($return) response nothing, and on my server the response is "Object moved to here."
Fourthly: Yes i read this topic, but didn't help me a lot..
cURL not working
Finally: When I try to debug the cURL request the error is:
error:SSL certificate problem: unable to get local issuer certificate
Can anyone help me please? I'll stay here to answer comment/test/debug/answer etc.
Thanks !
You're most likely not using a certificate at all so either use http or try using
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
It's not a good practice to set "CURLOPT_SSL_VERIFYHOST" false.
I recommed you to download the CA root certificate bundle and tell PHP where to find it.
You can find it to download here.
Download the .pem and save it where your PHP installation can access
it.
Add to your php.ini the file location: curl.cainfo="C:\Xamp\php\cacert.pem"
Restart your server]
Job is done, safely.
Font: https://snippets.webaware.com.au/howto/stop-turning-off-curlopt_ssl_verifypeer-and-fix-your-php-config/
cURL + proxy noob here, having a hard time. I'm having trouble trying to retrieve a web page from a remote secure server via a proxy. Everything has apparently been set up correctly by a remote dev, such that the following command line instruction works and returns what we're looking for:
curl -k --socks5-hostname localhost:xxxx https://hostname/
However, the following PHP does not echo the requested webpage. Instead it echoes the error 'Couldn't resolve host name':
$proxy = 'localhost:xxxx';
$url = 'https://hostname/';
//$proxyauth = 'user:password';
$ch = curl_init();
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_URL, $url);
$curl_scraped_page = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
if ($error)
echo $error;
elseif ($curl_scraped_page)
echo $curl_scraped_page;
If the $url is changed to a public page, such as Google, the request is successful and everyone is happy.
The connection requires an SSH tunnel if that changes anything at all. The tunnel is open and functioning, as proven by the command line request succeeding.
Is there something obvious that is being missed here?
You need to set option CURLOPT_PROXYTYPE to CURLPROXY_SOCKS5_HOSTNAME, which sadly wasn't defined in old PHP versions, circa pre-5.6; if you have earlier in but you can explicitly use its value, which is equal to 7:
curl_setopt($ch, CURLOPT_PROXYTYPE, 7);
In the option CURLOPT_PROXYTYPE you need to set CURLPROXY_SOCKS5_HOSTNAME option instead of CURLPROXY_SOCKS5.
In this case, the DNS query (for hostname resolving) will be sent to SOCKS proxy and not resolved in the local network.
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);
This constant available since PHP 5.5.23 and PHP 5.6.7 and cURL 7.18.0, so you can simply use it.
I'm a bit confused here. I have a file provision_test.php which when executed with php provision_test.php will run fine, execute curl, and get the page. But when executed from the web http://example.com/provision_test.php it fails to properly run. I am running Ubuntu Linux 12.04.1 server, x86_64.
Any ideas would be greatly appreciated... and let me know if you need any extra information, I'd be glad to help you help me.
EDIT 1
FILE: provision_test.php
<?php
$domain = "example.net";
$password = "123";
$serverip = "example.com:10000";
$ch = curl_init();
$userpwd = 'root:password';
curl_setopt($ch, CURLOPT_URL, "http://{$serverip}/virtual-server/remote.cgi?program=create-domain&domain={$domain}&pass={$password}&default-features");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, $userpwd);
curl_exec($ch);
curl_close($ch);
?>
The php5-curl package is installed on the system. However I have not specifically enabled curl in the php.ini file. How would I go about doing this?
I can verify that the php5-curl package was installed properly, however I cannot confirm that apache has enabled it. I know from executing it in the command line that curl works.
Additionally, I do not have selinux or something like that on my server.
I'll be running the script again with PHP errors on to see if I find anything tomorrow.
Today I had the same issue as described.
From CLI the script works fine, from the browser it ends up with error 7
Please enable Verbose mode using:
curl_setopt($ch, CURLOPT_VERBOSE, true);
Run the script from CLI
If you have the same problem as I did, it's because of proxy and maybe authentication as well, so you will have to add the following options to your curl script
$proxy = 'url or ip';
$proxy_port = 8080;
$proxy_username = 'username';
$proxy_password = 'password';
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_username.':'.$proxy_password);
This saved the last 30minutes of my working day ;-D
Hopefully this will be helpfull for you.
Setup:
1. Joomla 1.5 website on a LAMP server (CentOS 5.2/Apache 2.2/PHP 5.2.9/mysql 5)
2. Joomla module for currency conversion added. Module uses google finance to convert currency
3. LAMP stack resides in the intranet behind a proxy. The server environment variables for http_proxy, yum.conf proxy have been setup, and kernel successfully updated.
4. phpinfo() clearly shows curl is installed
5. module mentioned in '2.' allows 3 methods to connect to google finance, fread(), file_get_contents() and using the cURL libraries. As the box is behind a proxy, only the cURL libraries method should work.
Problem:
on a WAMP stack, the curl library method works fine. On the lamp stack, however, the module is unable to communicate with google finance, and throws an error mentioning connect timed out. Here's some code to make it clearer.
if (isset($_GET['process'])) {
$url = "http://finance.google.com/finance/converter?a={
$_GET['a']}&from={$_GET['from']}&to={$_GET['to']}";
$app->get_page($url);
$data = $app->process();
}
function get_page($url) {
if ($url!='') {
echo $url;
$ch = curl_init ();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, $this->binary);
$this->html = curl_exec($ch);
curl_close($ch);
}
}
I even tried adding a curl_setopt($ch, CURLOPT_PROXY,'10.x.xx.xx:8080'); after curl_init(), to no avail. I've compiled apache with libcurl and php enabled, and I need to know the following:
1. How to instruct php to route outgoing requests(streams) through the proxy?
2. Do I need to configure cURL (libcurl) with the proxyname and port?
3. I've switched iptables off, so the linux firewall is not in the picture anymore, is there anything else I need to do to allow outgoing requests?
4. I've setup the proxy so that my LAMP stack is unblocked for all content, cURL works off the command line, but not from php/apache. What am I missing? Any environment variables? Any switches?
Thanks in advance for your time.
Shrinivas
Here's an example using a local SOCKS5 proxy on port 1090:
<?php
$url = 'www.whatismyip.com/automation/<your unique whatismyip hash>';
function get_page($url, $proxy=true) {
if ($url!='') {
$ch = curl_init ();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
if ($proxy) {
curl_setopt($ch, CURLOPT_PROXY, 'localhost');
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($ch, CURLOPT_PROXYPORT, 1090);
}
$html = curl_exec($ch);
curl_close($ch);
return $html;
}
}
var_dump(get_page($url));
var_dump(get_page($url, false));
You'd probably want to use curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); and curl_setopt($ch, CURLOPT_PROXYPORT, 8080); instead.