Jump to content

FreeRadius Module (mysql issue)


Sp0tteh

Recommended Posts

Hey all,

 

I'm having some problems with a module I'm trying to create.

 

In short what I'm trying to do is add the new user into a freeradius database on another server using mysql. Now this works, the problem is that the account stays as "Pending" (In WHMCS) even though i can see the data in the freeradius database and no sql errors.

 

function radius_CreateAccount($params) {

$dbhost = 'fake';
$dbuser = 'fake';
$dbpass = 'fake';
$dbname = 'fake';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
//mysql_select_db($dbname, $conn);

//mysql_query("INSERT INTO radcheck (username, attribute, op, value) VALUES ('".$clientsdetails['email']."', 'User-Password', ':=', '".$password."')", $conn);
//mysql_query("INSERT INTO radusergroup (username, groupname, priority) VALUES ('".$clientsdetails['email']."', 'Dynamic', '1')", $conn);
mysql_close($conn);

return "success";
}

 

In the code above i have tried to force it with the " return "success";" but it doesn't seem to make any difference.

 

If i comment out the "mysql_connect" line above, then it shows as "active". From my understanding PHP should have no issues creating a second sql connection.

 

If someone could help me out or at least explain whats going on it would be greatly appreciated

Link to comment
Share on other sites

The problem is the way WHMCS is coded internally to use MySQL is rather sloppy as there is obviously no internal use of connection identifiers. See, how PHP works is that if you use any of the mysql_* functions if you do not pass a connection resource identifier PHP will by default use the last connection opened. Your module is working fine as you state, however your use of the other connection resource is most likely preventing WHMCS from saving the status in MySQL.

 

So here is what's happening...

 

1. WHMCS opens a MySQL connection.

2. WHMCS does some stuff..

3. Your module is called, it opens a new MySQL connection to a different server (possibly) and different table.

4. Module executes and finishes successfully.

5. Since WHMCS doesn't use connection identifiers the currently active database is still your connection. It doesn't matter if you close it or not, because if you do, then PHP has no default connection anymore.

 

There are many ways to solve this; if you're accessing the same MySQL server as WHMCS (assuming you're running under the same MySQL user too) is to just select the WHMCS database:

 

mysql_select_db($GLOBALS['db_name']);

If you're using different credentials, or using different physical servers, then just open a new connection to the WHMCS database:

 

mysql_connect($GLOBALS['db_host'], $GLOBALS['db_username'], $GLOBALS['db_password']);
mysql_select_db($GLOBALS['db_name']);

I haven't tested that code, but it should work since the WHMCS database credentials are in the global scope.

Link to comment
Share on other sites

  • 4 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated