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) );
?>
Related
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"a=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
I have a local Minecraft Server set up. I decided to get myself my own domain, because ips arent really pretty. The problem is, that because the ip address of my router changes every night, I can't just do a A-record to my ip address. Instead I need a dynamic dns provider which allows me the use of my own domain. I could not seem to find one, so I coded it by myself with php (I have a free web server with a static ip address). Here's the code of the .php-file:
<?
$usernameTest = $_GET["username"];
$passTest = $_GET["pass"];
$ipaddr = $_GET["ipaddr"];
$username = "USERNAME";
$pass = "*****";
$port = ":25565";
$serverIPtxt = "serverIP.txt";
if(file_exists($serverIPtxt)) {
if($usernameTest == $username) {
if($passTest == $pass) {
$a = fopen("$serverIPtxt", "w");
fwrite($a, $ipaddr);
fclose($a);
echo $ipaddr;
}
} else {
$a = fopen("$serverIPtxt", "r+");
$dynIP = fread($a, filesize($serverIPtxt));
fclose($a);
$url="http://".$dynIP."".$port;
header("Location: $url", true);
die();
}
}
?>
My router is automaticly applying the correct ip address, so in theory I should be able to connect to the minecraft server with my new domain, but I cant. Instead Minecraft gives me this error:
[13:52:38] [Client thread/INFO]: Connecting to DOMAIN, 25565
[13:52:39] [Server Connector #5/ERROR]: Couldn't connect to server
java.net.ConnectException: Connection refused: no further information: DOMAIN/IPADDRESS:25565
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[?:1.8.0_25]
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:716) ~[?:1.8.0_25]
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:208) ~[NioSocketChannel.class:4.0.23.Final]
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:287) ~[AbstractNioChannel$AbstractNioUnsafe.class:4.0.23.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:528) ~[NioEventLoop.class:4.0.23.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468) ~[NioEventLoop.class:4.0.23.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382) ~[NioEventLoop.class:4.0.23.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354) ~[NioEventLoop.class:4.0.23.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116) ~[SingleThreadEventExecutor$2.class:4.0.23.Final]
at java.lang.Thread.run(Thread.java:745) ~[?:1.8.0_25]
What am I doing wrong? Or does Minecraft just not support php redirects?
Minecraft does not use HTTP! It uses its own protocol based on TCP.
The best option, which I have used in the past, is to run a dynamic ip updater client.
Get yourself a No-IP domain name (e.g. myname.ddns.net)
Download the dynamic updater client (available for Windows, Mac or Linux)
Set your custom domain name as a CNAME to point to myname.ddns.net (your NoIP domain name)
Give players your custom domain name (e.g. myname.com). This will refer the client to myname.ddns.net through the CNAME record which will in turn refer to your dynamic IP (e.g. xxx.xxx.xxx.xxx) as an A record.
After this you will be able to connect to your server with your custom domain and the dynamic updater will keep the dynamic IP up to date automatically.
I am trying to create an email account via script without logging into the cpanel.
Here is the script I am using
http://www.zubrag.com/scripts/cpanel-create-email-account.php
Hosting provider is bluehost
I am getting this error
Cannot create email account. Possible reasons: "fopen" function allowed on your server, PHP is running in SAFE mode
safe mode is off in my ini file.
Here is the credential area that the script is using
// cPanel info
$cpuser = 'example.com'; // cPanel username
$cppass = 'my_cpanel_pass'; // cPanel password
$cpdomain = 'example.com'; // cPanel domain or IP
$cpskin = 'x'; // I have tried x and also bluehost here
// Default email info for new email accounts
// These will only be used if not passed via URL
$epass = 'my_cpanel_pass'; // email password
$edomain = 'example.com'; // email domain (usually same as cPanel domain above)
$equota = 20; // amount of space in megabytes
The following code is sending me the errors/warnings
$f = fopen ("http://$cpuser:$cppass#$cpdomain:2082/frontend/$cpskin/mail/doaddpop.html?email=$euser&domain=$edomain&password=$epass"a=$equota", "r");
if (!$f) {
$msg = 'Cannot create email account. Possible reasons: "fopen" function allowed on your server, PHP is running in SAFE mode';
break;
}
The warning I'm getting is
Warning: fopen(http://...#example.com:2082/frontend/x/mail/doaddpop.html?email=asif.k&domain=example.com&password=SmallAn123!"a=20): failed to open stream: HTTP request failed! HTTP/1.1 401 Access Denied in E:\Web Softs\wamp\www\clnt5\cpemail.php on line 81
If I print all the stuff between fopen() I get this
http://cpanel_user_name:my_cpanel_pass#example.com:2082/frontend/x/mail/doaddpop.html?email=asif.k&domain=mydomain.com&password=SmallAn123!"a=20
I have googled a lot to fix this. Any help or an alternate script that can help me achieve this will be much appreciated.
If you have cpanel username and password then you should use cpanel API to create email accounts and for lot more functionalities too rather than these get request.
require_once 'xmlapi.php';
$xmlapi = new \xmlapi($cpanel_domain);
$xmlapi->password_auth($cpanel_username,$cpanel_password);
$xmlapi->set_port('your domain port will be here');
$api2args = array();
$result = $xmlapi->api1_query($cpanel_password, 'CustInfo', 'getemail', $api2args);
// until here you will get confirmation of your connected cpanel with cpanel api
// then create cpanel as below
$api2args = array(
'domain' => $domain,
'email' => $email_address_to_create,
'password' => $email_password,
'quota' => '2048', // quota for email you want to set
);
$result = $xmlapi->api2_query($cpanel_username, 'Email', 'addpop', $api2args);
if(isset($result->error) && $result->error!=""){
// error can be recorded here
}
else{
// email account get created
}
What I am trying to do is set up a login screen. I collect the user's credentials and verify it using an ldap server before allowing the user to take a quiz.
<?php
session_start();
$user = $_POST['user'];
$domain = 'DOMAIN';
$password = $_POST['password'];
$ldapserver="ldap.example.server";
$ldapport=389;
$ldap = ldap_connect($ldapserver,$ldapport);
if ($bind = #ldap_bind($ldap,"{$user}#{$domain}", $password)){
$_SESSION["user"] = '$user';
header('Location: quiz.php');
}
else {
header('Location: login.html');
}
?>
When I use wireshark to sniff the packets, i can see the username and password clearly. Is there a way to bind to an LDAP server without sending the password in plain text? The site doesnt have https. The owner does not want to buy a SSL certificate, nor is he interest in a self-signed one.
Does your ldap server support ldaps and have a certificate? That would be the easiest way to do this and your site wouldn't need a certificate. You'd just change your code slightly. Assuming your server uses the default ldaps port:
$ldapserver = 'ldaps://ldap.example.server';
$ldapport = 636;
I'm using XML api 2
$xmlapi = new xmlapi('MY IP Address');
$xmlapi->password_auth("root",'My Cpanel password');
$xmlapi->set_output("json");
$xmlapi->set_debug(1);
print $xmlapi->api2_query($account, "Email", "listpopswithdisk" );
But it's giving this error.
{"cpanelresult":{"apiversion":"2","error":"Access denied","data":{"reason":"Access denied","result":"0"},"type":"text"}}
How to resolve this error.
Check your port settings -
$xmlapi->set_port(2083); //2082 if not using secure connection