Author Topic: CWP accoutn API  (Read 997 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
CWP accoutn API
« on: November 23, 2016, 07:21:58 PM »
Hello,
my first post here :)

I am trying to build a module for user registration with payment etc.

I am facing the following problem:

What would be the best approach with the account api ? I am currently trying to use cURL. First the user fills in a form with its desired username, password etc. The form is then submited with POST method to a php file where I am initiating curl session where we pass the form variables to the url, but I always get empty response from server or I get an error that the username is already in the database even if it actually isn't.

my code:

Code: [Select]
<?php
$username 
$_POST["username"];
$password $_POST["password"];
$domain $_POST["domain"];
$email $_POST["email"];
$key "abv123";
$api "account_new";

$url 'http://ip:2030/api/?key='.$key.'&api='.$api.'&domain='.$domain.'&username='.$username.'&password='.$password.'&package=1&email='.$email.'&inode=10000&nofile=100&nproc=25';

        
$ch curl_init();
        
curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
        
curl_setopt($chCURLOPT_HEADER0);
        
curl_setopt($chCURLOPT_FOLLOWLOCATION1);
        
curl_setopt($chCURLOPT_URL$url);
        
$tmp curl_exec($ch);
        
curl_close($ch);
        if (
$tmp === false){
            return 
$tmp;
        }

else { echo 
"success!"; }

?>


Would you be so kind and help me with the best way to achieve what I want ?
« Last Edit: November 23, 2016, 07:31:30 PM by porosenoq »

Offline
*
Re: CWP accoutn API
« Reply #1 on: November 27, 2016, 09:12:21 PM »
have you tried to do this manually by using curl from command line ?
AntiDDoS Protection (web + mail)
http://centos-webpanel.com/website-ddos-protection-proxy

Join our Development Team and get paid !
http://centos-webpanel.com/develope-modules-for-cwp


Services Monitoring & RBL Monitoring
http://centos-webpanel.com/services-monitor


Do you need Fast and FREE Support included for your CWP linux server?
http://centos-webpanel.com/noc-partner-list
Installation Instructions
http://centos-webpanel.com/installation-instructions
Get Fast Support Here
http://centos-webpanel.com/support-services

Offline
*
Re: CWP accoutn API
« Reply #2 on: March 27, 2017, 03:48:18 PM »
Hello,

i've got this problem too... So i tried to diagnose, how to solve the problem. I found out that if you run PHP script as user "nobody" (default apache user), it ends up with this error.

I figured it out by saving PHP piece of code to a file, and then running it with cron /usr/local/bin/php /path/to/your/script.php

What surprised me was, that even running a wget in a cron didn't helped.

Hope someone will find this useful, i've spent a whole weekend on this thing :D

Offline
*
Re: CWP accoutn API
« Reply #3 on: March 28, 2017, 04:59:00 AM »
you need to check the error you get and/or in the logs
AntiDDoS Protection (web + mail)
http://centos-webpanel.com/website-ddos-protection-proxy

Join our Development Team and get paid !
http://centos-webpanel.com/develope-modules-for-cwp


Services Monitoring & RBL Monitoring
http://centos-webpanel.com/services-monitor


Do you need Fast and FREE Support included for your CWP linux server?
http://centos-webpanel.com/noc-partner-list
Installation Instructions
http://centos-webpanel.com/installation-instructions
Get Fast Support Here
http://centos-webpanel.com/support-services

Offline
*
Re: CWP accoutn API
« Reply #4 on: April 10, 2017, 10:32:11 AM »
I checked.

What was kinda weird was that it sent two requests.

In CWP Apache log i found that first response was ok,  then CWP resets the connection, and then send the "Username already in database" error because the request is called again.

I think (it's only a thought), that something went wrong in API, and before setting password for the user it ended. Weird is, that it's working in a browser.

What is working correctly is creating a user, everything even with this error, but the user has no password set.

When i was looking in messages log, it says that it could not find a passwd file, i tried to look in CWP code, but it is encrypted/encoded, and i respect the rules, so i did'nt dig deeper, then i was looking for a workaround.

Hope it helps :-)