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.

Post Package Change script

Discussion in 'cPanel Developers' started by TNiSolutions, Oct 7, 2011.

  1. TNiSolutions

    TNiSolutions Well-Known Member

    Joined:
    May 30, 2011
    Messages:
    50
    Likes Received:
    0
    Trophy Points:
    6
    I want to know which script (if any) is called when an account's package is changed...

    We use WHMPHP and it has a automatic Master Reseller creation when a package is change to any in a predefined list... The problem is, if the account is the changed back later (to a non Master Reseller package) they still get MR privileges...

    I have made a script to run after package change to remove their MR rights, but I need to know when to call it...
     
  2. sirdopes

    sirdopes Well-Known Member
    PartnerNOC

    Joined:
    Sep 25, 2007
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    16
    There is a /usr/local/cpanel/scripts/postmodifyacct script that is called after an account is modified. This is probably where you would want to add the call to your script. The file can be created if it doesn't exist. Just make sure it is executable.
     
  3. TNiSolutions

    TNiSolutions Well-Known Member

    Joined:
    May 30, 2011
    Messages:
    50
    Likes Received:
    0
    Trophy Points:
    6
    Awesome, thanks :)

    Ok. So the script I made probably won't work. I need something that does the below, any ideas.

    After account modify (postmodifyacct) check if account is on 'package1' or 'package2' or 'package 3' else rm -Rf /usr/local/cpanel/whostmgr/docroot/cgi/whmphp/mr/$username

    Ideas?
     
  4. sirdopes

    sirdopes Well-Known Member
    PartnerNOC

    Joined:
    Sep 25, 2007
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    16
    I was looking at this a little more and it doesn't look like the postmodifyscript is called when changing the plans. One option is to use to edit the account after the package is changed. You can use something like the following for the postmodifyaccount. Another option would be to just make a custom plugin for changing the plan and remove the dir.


    Code:
    #!/usr/bin/perl
    
    use LWP::UserAgent;
    use XML::Simple;
    use File::Path;
    
    my %OPTS = @ARGV;
    
    $username = $OPTS{'user'};
    #get access hash and create auth string
    open(READER, "/root/.accesshash");
    my @line = <READER>;
    close(READER);
    my $hash = join("\n", @line);
    $hash =~ s/\n//g;
    my $auth = "WHM root:" . $hash;
    
    my $ua = LWP::UserAgent->new;
    my $request =  HTTP::Request->new( GET =>"http://localhost:2086/xml-api/accountsummary?user=$username");
    $request->header( Authorization => $auth );
    my $response = $ua->request($request);
    my $xml = new XML::Simple;
    my $data = $xml->XMLin($response->content);
    
    if ( $data->{'acct'}->{'plan'} !~ /(plan1|plan2|plan3)/ ) {
            remove_tree("/usr/local/cpanel/whostmgr/docroot/cgi/whmphp/mr/$username");
    }
    
     
    #4 sirdopes, Oct 7, 2011
    Last edited: Oct 7, 2011
  5. TNiSolutions

    TNiSolutions Well-Known Member

    Joined:
    May 30, 2011
    Messages:
    50
    Likes Received:
    0
    Trophy Points:
    6
    Thanks for your help :)

    So, I would need to make a plugin for this to work? Otherwise, how would cPanel/WHM know when to call this custom script?
     
  6. sirdopes

    sirdopes Well-Known Member
    PartnerNOC

    Joined:
    Sep 25, 2007
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    16
    The code that I posted can be used in /usr/local/cpanel/scripts/postmodifyacct. However, this is only called when an account is modified. It is not called on the change package screen. So you could change the package and then change something on the modify account screen to call this. The other option would be to make a whm for setting the package and having it remove the directory after the package is changed.
     
Loading...

Share This Page