Posted By

shaunjanssens on 11/05/09


Tagged

script signup api sample DirectAdmin


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

shaunjanssens


DirectAdmin API sample script


 / Published in: PHP
 

Do not use this php file exactly as it is. It's only to demonstrate the basics of the api. You must do form checking to ensure safe values are passed. Also, it's a really bad and very insecure practice to put a form like this publicly on your website for anyone to use. If you do, you'll end up with a server full users you did not create (this script creates accounts without any involvment with an admin: bad)

  1. <?
  2.  
  3. $server_ip="11.22.33.44";
  4. $server_login="admin";
  5. $server_pass="yourpass";
  6. $server_ssl="N";
  7.  
  8.  
  9. $username=$_POST['username'];
  10. $domain=$_POST['domain'];
  11. $email=$_POST['email'];
  12. $pass=$_POST['pass'];
  13. $package=$_POST['package'];
  14.  
  15.  
  16. if (isset($_POST['action']) && $_POST['action'] == "add")
  17. {
  18.  
  19. echo "Creating user $username on server $ip.... <br>\n";
  20.  
  21. $sock = new HTTPSocket;
  22. if ($server_ssl == 'Y')
  23. {
  24. $sock->connect("ssl://".$server_ip, 2222);
  25. }
  26. else
  27. {
  28. $sock->connect($server_ip, 2222);
  29. }
  30.  
  31. $sock->set_login($server_login,$server_pass);
  32.  
  33. $sock->query('/CMD_API_ACCOUNT_USER',
  34. 'action' => 'create',
  35. 'add' => 'Submit',
  36. 'username' => $username,
  37. 'email' => $email,
  38. 'passwd' => $pass,
  39. 'passwd2' => $pass,
  40. 'domain' => $domain,
  41. 'package' => $package,
  42. 'ip' => $server_ip,
  43. 'notify' => 'yes'
  44. ));
  45.  
  46. $result = $sock->fetch_parsed_body();
  47.  
  48. if ($result['error'] != "0")
  49. {
  50. echo "<b>Error Creating user $username on server $server_ip:<br>\n";
  51. echo $result['text']."<br>\n";
  52. echo $result['details']."<br></b>\n";
  53. }
  54. else
  55. {
  56. echo "User $username created on server $server_ip<br>\n";
  57. }
  58.  
  59. exit 0;
  60. }
  61.  
  62. ?>
  63.  
  64.  
  65. <form action=? method="POST">
  66. <input type=hidden name=action value="add">
  67. Username: <input type=text name=username><br>
  68. Domain:<input type=text name=domain><br>
  69. Email: <input type=text name=email><br>
  70. Pass: <input type=password name=pass><br>
  71. Packge: <input type=text name=package><br>
  72. </form>

Report this snippet  

You need to login to post a comment.