How to create ftp in php? - php

Hello i want to create ftp for particular users.. I have searched on google but nothing found. So i have decided to put question on stackoverflow. I have tried below code but not working at all :-
$cpaneluser = "xxxxx"; // i have entered my cpanel user
$cpanelpass = "xxx"; //pwd
$domain = "testing.domain.com"; //here i have entered the domain
$fuser = "testing#domain.com";
$fpass = "mypwd";
$homedir = "/direcctorypath";
$url = "http://$cpaneluser:$cpanelpass#$domain:2082/json-api/cpanel?";
$url .= "cpanel_jsonapi_version=2&cpanel_jsonapi_module=Ftp&cpanel_jsonapi_func=addftp&";
$url .= "user=$fuser&pass=$fpass&homedir=$homedir&quota=0";
var_dump($url);
$result = file_get_contents($url);
var_dump($http_response_header);
if ($result === FALSE)
die("ERROR: FTP Account not created. Please make sure you passed correct parameters.");
echo $result;
SEE OUTPUT
Every time its output coming FTP Account not created. Please make sure you passed correct parameters..
But i have entered the correct details. i Don't know why its not working.
So later on i have decide lets do with exec command but that also not working
Ref Url :- Creating FTP user accounts using FTP on server
exec("adduser -c 'testing#domain.com' -m testing123"); // this is not working at all
After checking above url i have added the username and password of ftp account. But i have one doubt where i passed the cpanel useranme and password in exec function. Can anyone tell me how to create ftp account of a user. Thanks in advance

Related

WHM API: Find cPanel user by domain

I'm working on a WHM API and want to find the cPanel username by passing the domain name.
NOTE: I've the credentials of WHM.
There is no such documentation exists here https://documentation.cpanel.net/pages/viewpage.action?pageId=1507786
So, is there a way to achieve do so?
Update:
Now, I'm using xmlapi.php and here is what I tried so far.
require_once(base_path() . "/vendor/cpanel_api/xmlapi.php");
$ip = env('SERVER_IP', "127.0.0.1"); //your server's IP
$xmlapi = new \xmlapi($ip);
$xmlapi->password_auth(env('CPANEL_USER', "root"),env('CPANEL_PASSWORD', "")); //the server login info for the user you want to create the emails under
$xmlapi->set_output('json');
$xmlapi->set_debug(1);
$params = array('domain'=>$domain, 'searchtype'=>'domain'); //quota is in MB
$res = json_decode($xmlapi->api2_query('root', "listaccts", "", $params), true);
print_r($res);
in $xmlapi->api2_query method, there are 4 arguments
cPanel Username
WHM Module Name
Function under the Given Module in step 2
parameters, that'll be passed to the function in step 3
I have to find out the cPanel Username, so, I wrote the 'root' for now. but no success
Please give a try with cPanel API.
Here are the some useful docs of API.
https://documentation.cpanel.net/display/SDK/Guide+to+cPanel+API+2
https://documentation.cpanel.net/display/SDK/Guide+to+WHM+API+1

Create own bot on telegram with php

I saw a couple of days ago this tutorial on youtube.
It was very interesting, so I decided to make a own bot.
I used the code from the tutorial as a template:
<?php
$bottoken = "*****";
$website = "https://api.telegram.org/bot".$bottoken;
$update = file_get_contents('php://input');
$updatearray = json_decode($update, TRUE);
$length = count($updatearray["result"]);
$chatid = $updatearray["result"][$length-1]["message"]["chat"]["id"];
$text = $updatearray["result"][$length-1]["message"]["text"];
if($text == 'hy'){
file_get_contents($website."/sendmessage?chat_id=".$chatid."&text=hello");
}
elseif($text == 'ciao'){
file_get_contents($website."/sendmessage?chat_id=".$chatid."&text=bye");
}
The script worked if I execute the script manually. However when I use the webhook it doesn't work anymore. The tutorial said that $update = file_get_contents('php://input'); is the right way, to be used before $update = file_get_contents($website."/getupdates");. My question how can I use php://input to execute my script automatically? The script is on a server from "one.com" and the certificate is also from "one.com".
If you use selfsigned ssl you have to point to the ssl path ,,
use the ssh to run this command after filling it with your real data ,,
curl -F "url=https://example.com/myscript.php" -F "certificate=#/etc/apache2/ssl/apache.crt" https://api.telegram.org/bot<SECRETTOKEN>/setWebhook
After change to WebHook method, you need to put as follows, since now we are going to handle one message at time. For me works perfectly.
instead
$chatId = $updateArray["result"][0]["message"]["chat"]["id"];
to
$chatID = $update["message"]["chat"]["id"];
this is the answer for all of your problems.
follow this step after you got a secret token for your bot:
create file in your website https://yourdomain.com/secret-folder/index.php
create your php file like this :
<?php
$website = 'https://api.telegram.org/bot123456789:1234567890ABCDEF1234567890ABCDEF123/';
$content = file_get_contents("php://input");
$update = json_decode($content, true);
if (isset($update["message"])){
$chatID = $update["message"]["chat"]["id"];
$text = $update["message"]["text"];
if ( $text == '/start' ) {
// send welcome message
file_get_contents($website."sendMessage?chat_id=".$chatID."&text=Welcome to my bot");
}else{
// send another message or do your logic (up to you)
file_get_contents($website."sendMessage?chat_id=".$chatID."&text=some text here");
}
}
?>
Set Your Webhook from this bot #set_webhookbot
choose command or type ' ست وب هوک '
reply with your secret bot token ex: ' 123456789:1234567890ABCDEF1234567890ABCDEF123 '
reply with your webhook address 'https://yourdomain.com/secret-folder/index.php'
reply with /setwebhook
if you follow step by step its will work.
enjoy it !!
Sorry for digging up this old question so enthusiastically, I had exactly the same question as you.
I think actually the answer may be easier yet less satisfying as we hoped: I don't think it's possible to get a list of previous messages to the bot while using the webhook.
Namely: what this does, is run the PHP script directly as soon as the bot receives a message. Nothing is stored in an accessible database, hence no updateArray is returned.
I came across this example, which shows how php://input works. I guess the solution to display a list of messages would be, let the php script store the message in a database everytime a message is 'forwarded' via the webhook.
If anyone found something else: I'm very interested.
As per my understanding from your code snippet above, you need to use php://input within double quotes instead of single quotes. In php, we are having bing difference in this use case.

cPanel api2 for MysqlFE authorizehost

I am trying to use cPanel xml api to add ip addresses to the mysql remote access host list.
If I use this...
$newdomain = "12.345.45.678";
$myemails = $xmlapi->api2_query($account, "MysqlFE", "authorizehost", array('host'=>$newdomain) );
I can in fact add the ip to the remote host access list. I verified by logging into cPanel and checking.
When I try to access the database remotely, I am blocked. ???? like I have not whitelisted my ip ??
If I log into cPanel and remove the ip address and add it manually(the exact same ip)...then test my remote connection, and it works.
Am I missing something here?
The xmlapi adds the ip successfully, but I still can't get a remote connection.
If it helps at all, my whitelist already has some ip addresses that were added manually. So, it is not an empty record.
<?php
require_once("xmlapi.php");
$ip = 'website ip address here';
$account = 'cpanel username here';
$domain = 'mysite.com';
$passwd = 'cpanel password here';
$xmlapi = new xmlapi($ip);
$xmlapi->password_auth($account, $passwd);
$xmlapi->set_port(2083);
$xmlapi->set_output("simplexml");
$newAuthIP = "123.45.67.890"; <----- sanitized value from a form post
$myemails = $xmlapi->api2_query($account, "MysqlFE", "authorizehost", array('host'=>$newAuthIP) );
?>

WeChat SandBox API Configuration Failed

I'm getting the "Configuration Failed" pop up after submitting my URL and Token in the WeChat sandbox environment. Could anyone suggest ways to debug or find a solution? Here are the details:
running a Heroku server and using the heroku generated URL.
pushed the sample code found in the documentation here
followed the youtube tutorial, copied the code and tried that as well.
<?php
$data[] = 'Test123';
$data[] = $_GET['timestamp'];
$data[] = $_GET['nonce'];
asort($data);
$strData = '';
$d = '';
$authString = '';
foreach($data as $d){
$authString .= $d;
}
//verify the signture
if(sha1($authString) == $_GET[signature]){
//check if the echostr
if(!empty($_GET['echostr'])){
echo $_GET['echostr'];
die();
}else{
//logic goes here
$return = '<xml>
<ToUserName><![CDATA['.$toUser.']]></ToUserName>
<FromUserName><![CDATA['.$fromUser.']]></FromUserName>
<CreateTime>'.time().'</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA['.$text.']]></Content>
<FuncFlag>0</FuncFlag>
</xml>';
echo $return;
}
}else{
die('You are not supposed to be here');
}
?>
checked the logs and found that its working fine but shows no activity when I submit the URL and token on WeChat sandbox.
have tried different variations of URL, from using the root URL to finishing with the php file ie xxxx/responder.php
Token submitted matches Token used in code.
Uploading raw php to the server, hijacked the heroku php hello world app with the documentation code or youtube code.
The code itself comes straight from the WeChat Docs or the Youtube Video. Please let me know if I could provide any additional information.
Any advice, tips or hints would be really appreciated.
Please check. The sandbox environment was broken for International. This should be resolved now. Please test again

How to check website is online if it is password protected

I just want to write a php code to check if password protected website is online or offline. I know the code to check whether if website is online or offline but it is not working if the website is password protected through .htaccess. llike if you open then website then an alert box comes and ask about the user name and password.
If i use this code then it is just saying that the website is offline because it cannot by pass the user name and password.
$host = 'http://gforms.orbnexus.com';
if($socket =# fsockopen($host, 80, $errno, $errstr, 30)) {
echo 'online!';
fclose($socket);
} else {
echo 'offline.';
}
Can any one please help me? Is there any way to by-pass user name and password?
the fact that it asks for a username and password means its online. I'm also sure you can make sure when you send your request that you get back a header, if nothing comes back the website is down.
Reference page
Use cURL to get your target, then check the http status code. If you get a 401 then it there's an authentication issue

Categories