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.

Cron Job to Suspend Accounts

Discussion in 'General Discussion' started by Harlequin, Jan 6, 2012.

  1. Harlequin

    Harlequin Member

    Joined:
    Sep 4, 2011
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Santa Cruz de Tenerife, Spain
    cPanel Access Level:
    Reseller Owner
    Hi

    I'm currently running a hand coded billing system that spits out mails through a cron job if a user has not paid. My main problem now is that on the xth of the month, if say 5 or 10 customers have not paid I can set a cron job to run a PHP script that mails them but I also want to suspend the account.

    I am doing this manually right now, can it be done through WHM using a cron job...?
     
  2. Brian

    Brian Well-Known Member

    Joined:
    Dec 1, 2010
    Messages:
    117
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    Texas
    cPanel Access Level:
    Root Administrator
    You can do pretty much anything through cron that you can imagine. After all, the only thing it does is execute commands at specified intervals. If you write a script/program/one-liner to accomplish your task, just call it via cron. The fact that cron is involved is largely arbitrary.

    It sounds like you just are looking for this information:

    Code:
    /scripts/suspendacct <user> <reason> <allow reseller to unsuspend>
    For example:
    Code:
    /scripts/suspendacct jim "Unpaid bill from 11/23/2011" 1
    
    would suspend the user "jim" with the reason "Unpaid bill from 11/23/2011" and the "1" signifies that if jim is owned by a reseller, that the reseller cannot overturn your suspension and unsuspend jim. They only way to unsuspend jim is for root to unsuspend that user. If you set to to 0 or left it out, the reseller could overturn your suspension via WHM if they wanted.

    Simply integrate that command into your script that is firing via cron and enjoy.

    Alternatively, get fancier and use our XMLAPI instead of just the bare script: SuspendAccount < SoftwareDevelopmentKit < TWiki
     
  3. Harlequin

    Harlequin Member

    Joined:
    Sep 4, 2011
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Santa Cruz de Tenerife, Spain
    cPanel Access Level:
    Reseller Owner
    Sounds good. Also, as I am the reseller then I doubt I'll be setting that particular value to anything as I will need to unsuspend at some point.

    Given that I'm a bit of a novice at this, I was wondering how might incorporate the following:

    Into a PHP file. For example...

    PHP:
    MySQL Query Here

       
    if `$user owes money` = Yes
       
    {
    *** 
    CRON HERE...? ***
    /
    scripts/suspendacct <user> <reason> <allow reseller to unsuspend>
       }
       else
       {
       
    wish them a happy *day of the week*
       }
     
  4. Brian

    Brian Well-Known Member

    Joined:
    Dec 1, 2010
    Messages:
    117
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    Texas
    cPanel Access Level:
    Root Administrator
    The most elegant way, if you're using PHP, is to just make use of our PHP XMLAPI class to interact with the server.

    https://github.com/CpanelInc/xmlapi-php

    There's plenty of examples on how to use it here:

    https://github.com/CpanelInc/xmlapi-php/tree/master/Examples

    Referring back to my prior post, you'd want to use the XMLAPI "suspendacct" call.

    SuspendAccount < SoftwareDevelopmentKit < TWiki

    Similar to: https://github.com/CpanelInc/xmlapi-php/blob/master/Examples/createacct_example.php

    but with suspendacct() vs. createacct()
     
  5. Harlequin

    Harlequin Member

    Joined:
    Sep 4, 2011
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Santa Cruz de Tenerife, Spain
    cPanel Access Level:
    Reseller Owner
    Hi Brian

    Elegance can come later. I simply need to get a script up and running because I'm managing a large number of domains. The way I work at the moment is that I have a MySQL DB with clients in and amounts required. If I receive payment (either by PayPal, bank transfer or even cash) then I issue a receipt and the record is set to `Outstanding` = 'No'.

    I have a few CRONs triggering PHP scripts that send payment requests, reminders and then finally a demand indicating that the acocunt will be suspended. If they pay and I have issued a receipt then the PHP script passes them by and moves onto the next client.

    Ideally, what I would like to do is have a very simple PHP script (the PHP I can write) that then simply calls a task to suspend an account should the `Outstanding` value = 'Yes'.
     
Loading...

Share This Page