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.

Script: Change quota for email accounts in domain

Discussion in 'E-mail Discussions' started by SeanLee, Mar 30, 2009.

  1. SeanLee

    SeanLee Well-Known Member

    Joined:
    May 23, 2004
    Messages:
    50
    Likes Received:
    0
    Trophy Points:
    6
    Hi all,

    Here's a simple script I wrote which automatically changes the quota for multiple email accounts from a single domain. It works with the awesome plugin for FireFox - iMacros.

    I had the need to change the quota for about 1000 email accounts that were all in a single domain. This script uses an account list you specify from a MS-DOS formatted CSV file. The script automates the change quota process that a domain user can access in the cPanel interface.

    Should be self explanitory - I've commented my code and included an example.

    Let me know if you have any questions.

    Thanks,

    -SeanLee
     

    Attached Files:

  2. jmeander

    jmeander Registered

    Joined:
    Apr 26, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    This was my first stab at using an iMacro. I have a couple hundred users whose quotas I need to update. This was great but I'm a wee bit stuck...

    Modified the .csv per your comments; first column includes list of usernames in format username@domain.org as that's what my server requires for usernames. (I also tried just username without @domain.org). First line is blank.

    At the proper CPanel page, I run the macro and it successfully updates the quota of the second username listed on the CPanel page and that's it. It seemingly runs the macro but ignores the .csv file entirely. When I edited the macro to loop from 1 (rather than 2) and run it, then the quote of the first username gets changed properly, but again, doesn't go any further than that.

    I get no error message about the .csv not being found, and when I purposely made a typo in the file name within the macro I did get an error when running it, so I know it's finding the file, just not reading it?

    I tried looping the macro and it works that way, but the problem with that is with the display of X users in CPanel. If I start on Page 2 of 10 users per page, it updates the first user (#11) on the page, then goes back to user number 1 and continues looping from there.

    Sorry for my ignorance. I've played with this for a good hour now and can get it to loop perfectly through users 1 through 10 on the CPanel page so I think I'm thisclose but without an error message about why it loops only through the users on the page and not the .csv file, I can't seem to figure it out.

    Thanks for any pointers and hope I've provided enough information.
     
  3. jmeander

    jmeander Registered

    Joined:
    Apr 26, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Here's what I have managed to put together. It works (of a sort) when I loop through the cPanel page, still doesn't read my users from the .csv file. I'm sure there's a more efficient way to structure this:
    Code:
    ' cPanel email account quota change script v1.0 by Sean Murray (sean@baynetsystems.com)
    ' Copyright 2009 Bay Area Network Systems, LLC - http://baynetsystems.com
    ' In order for this script to work, you need to be logged into cpanel in the
    ' HOME>MAIL>EMAIL ACCOUNTS section of cPanel using the domain account login. (not root!)
    ' example: http://mydomain.com:2083/frontend/x3/mail/pops.html?domain=mydomain.com
    
    VERSION BUILD=6210326 RECORDER=FX
    TAB T=1
    SET !ENCRYPTION NO
    
    ' Define your MS-DOS compatible CSV file.
    ' There should only be 1 column with usernames in your CSV file.
    ' This file typically lives in the iMacros/Datasources folder
    ' located in your "my documents" folder
    CMDLINE !DATASOURCE MYFILENAME.csv
    
    ' Define the number of columns in your CSV file.
    ' In this example, we define the CSV as having 50 lines.
    ' Make sure that the 1st line in your CSV file is empty (blank).
    SET !DATASOURCE_COLUMNS 150
    
    ' Nothing to define here.
    SET !LOOP 2
    SET !DATASOURCE_LINE 1
    
    ' Change mydomain.com to your actual domain.
    ' Make sure to leave the leading *%40 before the domain name.
    TAG POS={{!LOOP}} TYPE=SPAN ATTR=ID:quota-txt-*%40MYDOMAIN.org CONTENT={{!COL1}}
    
    ' Change the CONTENT number to what you want the new quota to be.
    ' For example, if you want a 1000MB quota (1GB), choose: CONTENT=1000
    TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:quotaform ATTR=ID:quota CONTENT=250
    
    ' Nothing to define here.
    TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:quotaform ATTR=VALUE:Change
    TAG POS=1 TYPE=A ATTR=TXT:Go<SP>Back
    
    TAB T=1
    URL GOTO=http://mail.MYDOMAIN.ORG:2082/frontend/x3/mail/pops.html?domain=MYDOMAIN.ORG
    TAG POS=1 TYPE=SELECT FORM=NAME:NoFormName ATTR=NAME:itemsperpage CONTENT=%100
    
    ' We'll make it easy on the server and wait 1 second in between imports.
    ' You can safely delete this last line if you really want to.
    WAIT SECONDS=1
    Where I am now is running the macro as above ignores my users in the csv and loops once to change the quota for user#2 on my cPanel listing and stops.

    Play->Loop to max of 100, begins with user #2 on the cPanel listing and updates the quota for five total cPanel users (showing 100 per page) and then returns the following error, but again ignoring my .csv listing.

    TypeError: this.dataSource[line - 1] is undefined, line 28

    [I think I might be veering more into iMacro than cPanel territory here.]
     
Loading...

Share This Page