The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Automatic Deletion and Creation (Email, Subdomains, FTP, Addon/Parked domains, MySQL)

Discussion in 'cPanel Developers' started by KingDrew, Oct 24, 2004.

Thread Status:
Not open for further replies.
  1. KingDrew

    KingDrew Active Member

    Joined:
    Oct 24, 2004
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Paris, Texas
    This morning I developed a PHP class that will do the following:
    Create/Remove Addon Domains
    Create/Remove Parked Domains
    Create/Remove MySQL Databases
    Create/Remove Mail Accounts
    Create/Remove FTP Accounts
    Create/Remove Subdomains
    Generate Full Backup

    I have not yet developed any documentation for it yet, but if you look at the code it is self-explanatory. Example usage to create a subdomain would be:
    PHP:
    <?php
    include("class.cpanel.php");

    $cuser "username";
    $cpass "password";
    $cdomain "domain.com";

    $cpanel = new cpanel($cuser,$cpass,$cdomain);
    $cpanel->CreateSubDomain("sub",$cdomain);
    ?>
    This will not output or return anything. It will just simply load the page that creates the subdomain on the server-side so the client will not see your username or password. It's actually that simple to create a subdomain automatically. I'm not sure if it will work on all servers but it's worth a try. The class file is attached to this post. Please rename it to class.cpanel.php.

    Update: In case of an error, this script will not throw an error. If you are using this, please update it immediately.
     

    Attached Files:

    #1 KingDrew, Oct 24, 2004
    Last edited: Aug 14, 2006
  2. internetfab

    internetfab Well-Known Member
    PartnerNOC

    Joined:
    Feb 20, 2003
    Messages:
    336
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Gothenburg, Sweden
    cPanel Access Level:
    DataCenter Provider
    Many thanks, been looking for a class like this to set up bulk emails for customers moving to our servers and having manually create 100+ email adresses ;)

    Now they could just give us a list and we could do a while loop on the list using this class :)

    *cheers*
     
  3. Albertof

    Albertof Registered

    Joined:
    Oct 27, 2004
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Not is more easy implement a solution to cpanel-email in perl?.

    but i say perl.. but perl and suexec run the script as the user, so you can use:

    cpanel-email addpop <popuser> <password> <quota> <domain>

    Look this on my ssh shell, im running the user "prueba"

    -bash-2.05b$ /usr/local/cpanel/cpanel-email addpop testeo password 10 prueba.com
    <!---Doing Null Password Check-->
    <!---Done Doing Null Password Check-->
    <!---Doing Null Email Check-->
    <!---Done Doing Null Email Check-->
    <!---Doing Max Email Check-->
    <!---Done Max Email Check-->
    <!---Grabbing Salt-->
    <!---Done Grabbing Salt-->
    <!--crypting()-->
    <!--done crypting()-->
    <!--fetch pwnam info-->
    <!--done fetch pwnam info-->
    <!--recrecord-->
    <!--done recrecord-->
    <!--chown-->
    <!--done chown-->
    Sorry the account testeo already exists!
    -bash-2.05b$ /usr/local/cpanel/cpanel-email addpop testeo1 password 10 prueba.com
    <!---Doing Null Password Check-->
    <!---Done Doing Null Password Check-->
    <!---Doing Null Email Check-->
    <!---Done Doing Null Email Check-->
    <!---Doing Max Email Check-->
    <!---Done Max Email Check-->
    <!---Grabbing Salt-->
    <!---Done Grabbing Salt-->
    <!--crypting()-->
    <!--done crypting()-->
    <!--fetch pwnam info-->
    <!--done fetch pwnam info-->
    <!--recrecord-->
    <!--done recrecord-->
    <!--chown-->
    <!--done chown-->
    <!--open PASSWD-->
    <!--open QUOTA-->
    <!--open SHADOW-->
    <!--close QUOTA-->
    testeo1+prueba.com
    -bash-2.05b$
     
    #3 Albertof, Oct 27, 2004
    Last edited: Oct 27, 2004
  4. PartieHonteuse

    PartieHonteuse Registered

    Joined:
    May 20, 2004
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Ok, first of all I'd like to say thank you for creating this class. It's a great thing! One problem I'm having (since I'm such an intermediate user of php) I was wondering how I would be able to do something like this...

    somefile.php

    Code:
    <?php
    $cuname = "cpaneluname";
    $cpass = "mypass";
    $cdomain = "mydomain.net";
    $euname = "testing1";
    $epass = "testing";
    include("class2.cpanel.php");
    
    
    $cpanel = new cpanel('$cuname','$cpass','$cdomain');
    $cpanel->CreateEmail('$euname','$epass','$cdomain');
    ?>
    When I do that, it doesn't work but when I just use text for the cpanel username/pass/domain etc. it works and I've tried reading about variable scopes and all that good stuff but I can't figure it out for the life of me. Any help or pointers would be appreciated.

    Partie™
     
  5. smadeira

    smadeira Registered

    Joined:
    Dec 3, 2004
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Get rid of the single quotes (as shown below) and it should work.

    $cpanel = new cpanel($cuname,$cpass,$cdomain);
    $cpanel->CreateEmail($euname,$epass,$cdomain);
     
  6. PartieHonteuse

    PartieHonteuse Registered

    Joined:
    May 20, 2004
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Thanks for the response but for some reason it doesn't work. I've actually tried a NUMBER of things before posting. I really don't like posting questions until I've exhausted my resources. I'll try it again real quick, i guess maybe I could've done something dumb.

    Partie™
     
  7. zaggs

    zaggs Member

    Joined:
    Dec 5, 2004
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    1
    Problem...

    Hi,
    Great class! However, when executing the CreatParked function - it does not work for me...

    Here is the code I am using:
    PHP:
    $user "user";
    $pass "pass";
    $domain "domain";

    include(
    "config.php"); 

    $cpanel = new cpanel('$user','$pass','$domain'); 
    $cpanel->CreateParked('domain.com');
    Any help is appreciated...
     
  8. PartieHonteuse

    PartieHonteuse Registered

    Joined:
    May 20, 2004
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    ....

    look at smadeiras post. the same will apply to you.
     
  9. Blue Dot Labs

    Blue Dot Labs Registered

    Joined:
    Jan 1, 2005
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    would i need to alter the class to include my reseller account login or anything in order to let it create accounts and function properly? or would just running it from my reseller domain be enough?
     
  10. NoMercy

    NoMercy Member

    Joined:
    Jul 23, 2004
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Superb !
    This is just what I am looking for.
    Hoping to adapt it to let me administrate autoresponder messages etc

    Thanks
     
  11. NoMercy

    NoMercy Member

    Joined:
    Jul 23, 2004
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    OK I managed to make a function to add and delete autoresponders..... is there a way I can get it to view existing ones or will i need to store the autoresponder in an accessible mysql table for instance, as well as adding to cpanel ?
     
  12. Rafaelfpviana

    Rafaelfpviana Well-Known Member

    Joined:
    Mar 12, 2004
    Messages:
    142
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Brazil
    will this script work if the user's password has special characters on it?
    like @
     
  13. Shane_F

    Shane_F Member

    Joined:
    Jan 21, 2005
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1

    This is great! :) GOod for those "free" host and "free" email accounts. :)
     
  14. KingDrew

    KingDrew Active Member

    Joined:
    Oct 24, 2004
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Paris, Texas
    I'd like to thank you everyone for their comments. I've updated the code sample to use quotes instead of single quotes as smadeira suggested (thanks). If anyone is interested in adding code to this, PM me with the code and I will add it if it is legit.
     
  15. baryk

    baryk Registered

    Joined:
    Apr 30, 2005
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Thank you Thank you Thank you!

    Thank you sooo much for developing such a great class!!

    I was looking for a solution to create a subdomain without having to logon to cPanel and did a lot of search on Google for 3 days and couldn't find anything and then I registered on this forum hoping to find something..... WOW!!!! this is exactly what I wanted!!!

    Thank you!!!! :)
     
  16. BrooksBridges

    BrooksBridges Well-Known Member

    Joined:
    Sep 2, 2004
    Messages:
    50
    Likes Received:
    0
    Trophy Points:
    6
    Is there anything that could be added to this to set quotas of ftp accounts? Curious for a project I've got going.

    Thanks!
    -Brooks
     
  17. germanette

    germanette Active Member

    Joined:
    Jul 26, 2003
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    1
    A Perl rendition

    These are just the functions I needed for my program, but the general idea can be adapted to other functions also.
     

    Attached Files:

  18. internetfab

    internetfab Well-Known Member
    PartnerNOC

    Joined:
    Feb 20, 2003
    Messages:
    336
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Gothenburg, Sweden
    cPanel Access Level:
    DataCenter Provider
    The only problem is when the cpanel theme varies for different accounts and you don't know which one they're using (yes, you could check but then what's the point of this script).

    Guess an array with available cpanel themes and go through it til you get access..
     
  19. prixone

    prixone Well-Known Member

    Joined:
    Mar 4, 2004
    Messages:
    107
    Likes Received:
    3
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    only problem at your script is, you cant know if you did create with success once the module you are using just receive the code;
    return like code 200, code 404

    so you cant know if create success or errors were found.

    but if there is no erro for sure it will create.
     
  20. lastprotocol

    lastprotocol Registered

    Joined:
    Feb 4, 2006
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    As a novice with php can someone help me out here, I know that this is exactly what I need to use for a project I working on, but I have little or no idea how to implement it :confused:

    I would like to have a simple form, which will include prefered username/password etc - when submitted the form autogenerates a sub-domain and ftp account based on the username/password selected - the form checks for duplicates and returns "name already in use" if necessary etc.

    Can someone help me out?
     
Loading...
Thread Status:
Not open for further replies.

Share This Page