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.

postwwwacct script - to send automatic welcome email

Discussion in 'E-mail Discussions' started by west one, Oct 23, 2008.

  1. west one

    west one Member

    Joined:
    Sep 15, 2006
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1
    Hi

    I need help with my postwwwacct script - to send automatic welcome email to my clients
    and it is not working Wright.

    and I also would like to change it some how so it send one type of email to my resellers and one to
    my other clients

    hope you can see my needs?


    THIS IS THE SCRIPT in scripts/
    Code:
    ================================================START OF MY postwwwacct ==========================
    
    #!/usr/local/bin/perl
    # You may need to change this path to /usr/local/bin/perl
    
    $mailprog = "/usr/sbin/sendmail";
    
    #**************************************************************
    #
    #
    # To use this script, just set a few variables below, modify the email message to
    #  your desire, and upload this file to the /scripts directory on your server, renamed
    #  to postwwwacct and made executable.
    # 
    # Every time an account is created in WHM, this script is automatically called to
    #  do it's job. Variables are passed to it from WHM's wwwacct script and some of
    #  those variable are used to customize the email message.
    #
    # Here are the variables that are passed to this script:
    #  $ARGV[0] = domain
    #  $ARGV[1] = username
    #  $ARGV[2] = password
    #  $ARGV[3] = space (MB)
    #  $ARGV[4] = theme
    #  $ARGV[5] = ded IP (y/n)
    #  $ARGV[6] = cgi (y/n)
    #  $ARGV[7] = FP (y/n)
    #  $ARGV[8] = max ftp (n or #)
    #  $ARGV[9] = max sql (n or #)
    #  $ARGV[10] = max POP (n or #)
    #  $ARGV[11] = max lists (n or #)
    #  $ARGV[12] = max subs (n or #)
    #  $ARGV[13] = bandwidth (# or 0) in MB's
    #  $ARGV[14] = shell (y/n)
    #  $ARGV[15] = owner
    #  $ARGV[16] = plan
    #  $ARGV[17] = max park (# or unlimited)
    #  $ARGV[18] = max addon  (# or unlimited)
    #  $ARGV[19] = feature list (default)
    #  $ARGV[20] = contact email
    #
    #
    # 
    #**************************************************************
    
    
    # To send yourself a copy of the email, put your email address here.
    # If you use spamassassin, you should include a name, like this:
    # $email = 'me <me@mysite.com>';
    $email = 'westonehosting@talktalk.net';
    
    # This is the email address that will be the sender of the automatic email.
    # You may prefer to put your own email address here. ;-)
    $from = 'Sales <sales@westonehosting.com>';
    
    # If you prefer to send the email in html format, change the next line to Y.
    $usehtml = "Y";
    
    # Change this subject line to whatever you prefer
    $subject = "West One Hosting :: Welcome Email";
    
    # This is just to convert the bandwidth from MB to GB for the email message.
    # Calculations like this must be done before the message string variables are specified.
    $gb = $ARGV[13]/1024;
    $gb = $gb . "GB";
    
    # This is the message that will be sent if you choose to use html. You can modify
    # this message any way you like. All the $ARGV[#] variables are replaced with the
    # appropriate value. See the variables uses above. Do not touch the first or last
    # line here. If you use any of the following characters, @ $ or ", you will need to
    # escape them by putting a \ in front of them, like: \@ \$ or \"
    $html_message = "
    <b>Here are the details of your new account:</b><br>\n
    <b>Domain Name:</b> $ARGV[0]<br>\n
    <b>Username:</b> $ARGV[1]<br>\n
    <b>Password:</b> $ARGV[2]<br>\n
    <b>Package:</b> $ARGV[16]<br>\n
     - space: $ARGV[3]MB<br>\n
     - bandwidth: $ARGV[13]MB ($gb)<br>\n
     - theme: $ARGV[4]<br>\n
     - Dedicated IP ($ARGV[5])<br>\n
     - POP accounts: max - $ARGV[10]<br>\n
     - mailing lists: max - $ARGV[11]<br>\n
     - MySql databases: max - $ARGV[9]<br>\n
     - subdomains: max - $ARGV[12]<br>\n
    <br>\n
    <b>Shell Access:</b> $ARGV[14]<br>\n
    <br>\n
    ++++++++++++++++++++THIS IS THE START OF WHAT I NEED TO ADD++++++++++++++++++++++++++++++++++++
    <br>\n
    <b>Nameserver & IP 1:</b> $ARGV[?]<br>\n
    <b>Nameserver & IP 2:</b> $ARGV[?]<br>\n
    <b>Nameserver & IP 3:</b> $ARGV[?]<br>\n
    <b>Nameserver & IP 4:</b> $ARGV[?]<br>\n
    <br>\n
    ++++++++++++++++++++THIS IS THE END OF WHAT I NEED TO ADD+++++++++++++++++++++++++++++++++++++++
    <b>Contact Email:</b> $ARGV[20]<br>\n
    Please keep this up to date.<br>\n
    <br>\n
    <br>\n
    ";
    
    
    # This is the message that will be sent if you choose to use plain text. You can
    # modify this message any way you like. All the $ARGV[#] variables are replaced
    # with the appropriate value. See the variables uses above. Do not touch the first
    # or last line here. If you use any of the following characters, @ $ or ", you will
    # need to escape them by putting a \ in front of them, like: \@ \$ or \"
    $text_message = "
    Here are the details of your new account:
    Domain Name: $ARGV[0]
    Username: $ARGV[1]
    Password: text mail
    Package: $ARGV[16]
     - space: $ARGV[3]MB
     - bandwidth: $ARGV[13]MB ($gb)
     - theme: $ARGV[4]
     - Dedicated IP ($ARGV[5])
     - POP accounts: max - $ARGV[10]
     - mailing lists: max - $ARGV[11]
     - MySql databases: max - $ARGV[9]
     - subdomains: max - $ARGV[12]
    
    Shell Access: $ARGV[14]
    
    Contact Email: $ARGV[20]
    Please keep this up to date.
    ";
    
    
    
    #-------------------------------------------------------------------
    #-------------------------------------------------------------------
    # UNLESS YOU KNOW CGI, DO NOT EDIT ANYTHING BELOW HERE
    # Feel free to study the code, but alterations are at your own risk
    #-------------------------------------------------------------------
    #-------------------------------------------------------------------
    
    
    if ($ARGV[20] eq "") {
        $client_email = $ARGV[1] . "\@" . $ARGV[0];
        $emailnote = "$client_email which is username\@domain.com because no email was provided in WHM";
      }
      else {
        $client_email = $ARGV[20];
        $emailnote = "$ARGV[20] which was provided in WHM";
    }
    
    print "\nSending email to client...\n";
    
    if ($usehtml eq "Y") {
        &send_mail_html;
      }
      else {
        &send_mail_txt;
    }
    
    print "\nEmail has been sent to client at $emailnote.\n";
    if ($email ne "") {
      print "A copy was also sent to $email.\n";
    }
    
    if (-e "/scripts/postwwwacct2") {
        print "\nSending variables to postwwwacct2.\n";
    	system("/scripts/postwwwacct2",@ARGV);
    }
    
    exit;
    
    
    sub send_mail_html {
    print "\nsending mail...\n";
        # Open The Mail Program
        open(MAIL,"|$mailprog -t");
        print MAIL "Content-Type: text/html; charset=iso-8859-1\n";
    
        print MAIL "To: $client_email\n";
        if ($email ne "") {
          print MAIL "Bcc: $email\n";
        }
        print MAIL "From: $from\n";
    
        print MAIL "Subject: $subject\n";
    
        print MAIL "<html>\n";
        print MAIL "$html_message\n";
        print MAIL "</html>\n\n";
    
        close (MAIL);
    }
    
    
    sub send_mail_txt {
    print "\nsending mail...\n";
        # Open The Mail Program
        open(MAIL,"|$mailprog -t");
    
        print MAIL "To: $client_email\n";
        if ($email ne "") {
          print MAIL "Bcc: $email\n";
        }
        print MAIL "From: $from\n";
    
        print MAIL "Subject: $subject\n";
    
        print MAIL "$text_message\n";
    
        close (MAIL);
    }
    
    
    
    ================================================END OF MY postwwwacct ==========================
    THIS IS THE EMAIL SENT TO ROOT
    Code:
    ================================================START OF MY postwwwacct OUTPUT HTML ============
    (THIS IS THE COPY SENT TO ROOT)
    
    West One Hosting :: Welcome Email 
    
    
    Here are the details of your new account:
    Domain Name: plan
    Username: Standard Plan
    Password: maxpark
    Package: pass
    - space: unlimitedMB
    - bandwidth: 8MB (0.0078125GB)
    - theme: lang
    - Dedicated IP (english)
    - POP accounts: max - hasshell
    - mailing lists: max - n
    - MySql databases: max - 32
    - subdomains: max - maxaddon
    
    Shell Access: cpmod
    
    Contact Email: domain
    Please keep this up to date.
    
    
    
    ================================================END OF MY postwwwacct OUTPUT HTML ==============
     
  2. west one

    west one Member

    Joined:
    Sep 15, 2006
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1
    THIS IS THE SCRIPT in scritps/
    Code:
    ================================================START OF MY wwwacct ==============================
    
    #!/usr/bin/perl
    # cpanel12 - wwwacct                         Copyright(c) 1997-2008 cPanel, Inc.
    #                                                           All Rights Reserved.
    # copyright@cpanel.net                                         http://cpanel.net
    # This code is subject to the cPanel license. Unauthorized copying is prohibited
    
    BEGIN {
        open( my $ver_fh, '<', '/usr/local/cpanel/version' );
        my $ver = readline($ver_fh);
        close($ver_fh);
    
        if ( $ver =~ /^(8|9|10)\./ ) {
            die "cPanel 11.x $0 running on a ${1}.x machine!!! /scripts were updated without cPanel!  Please run /scripts/upcp --force to force synchronization.";
        }
    
        if ( -e '/usr/local/cpanel/FastImport.pm' ) {
            require '/usr/local/cpanel/FastImport.pm';
            FastImport::_fast_import('/usr/local/cpanel', '/scripts');
        }
        elsif ( -e '/scripts/FastImport.pm' ) {
            require '/scripts/FastImport.pm';
            FastImport::_fast_import('/usr/local/cpanel', '/scripts');
        }
        else {
            unshift @INC, '/usr/local/cpanel', '/scripts';
        }
    }
    
    use cPScript::Errors           ();
    use Whostmgr::Accounts::Create ();
    use strict;
    
    $| = 1;
    
    my $customip;
    if ( $ARGV[0] =~ s/^\-\-with\-customip\=// ) {
        $customip = shift(@ARGV);
    }
    my $forcedns = 0;
    if ( $ARGV[0] =~ s/^\-\-forcedns// ) {
        $forcedns = 1;
        shift(@ARGV);
    }
    
    my $domain = $ARGV[0];
    my $user   = $ARGV[1];
    my $pass   = $ARGV[2];
    
    if ( $pass =~ /^fd:/ ) {
        chomp($pass);
    
        $SIG{'ALRM'} = sub {
            die "Timeout while getting password from FD";
        };
    
        my ( $passwdfd, $passwdlength );
        ( undef, $passwdfd, $passwdlength ) = split( /:/, $pass );
        $passwdfd     =~ s/[\s\n\t]*//g;
        $passwdlength =~ s/[\s\n\t]*//g;
    
        alarm(30);
    
        open( FH, "<&=${passwdfd}" ) || die "$0: Error while reading from  password FD $!";
        $pass = <FH>;
        close(FH);
    
        chomp($pass);
    
        alarm(0);
    }
    
    my $sqto;
    if ( $ARGV[3] ne '' ) {
        $sqto = $ARGV[3];
    }
    else {
        $sqto = '0';
    }
    
    my $cpmo = ($ARGV[4] || 'x3');
    
    my $useip;
    if ( $ARGV[5] eq 'n' ) {
        $useip = 'n';
    }
    else {
        $useip = 'y';
    }
    
    my $hascgi;
    if ( $ARGV[6] eq 'n' ) {
        $hascgi = 'n';
    }
    else {
        $hascgi = 'y';
    }
    
    my $installfp;
    if ( $ARGV[7] eq 'n' ) {
        $installfp = 'n';
    }
    else {
        $installfp = 'y';
    }
    
    my $maxftp;
    if ( $ARGV[8] eq 'n' || $ARGV[8] eq '' || $ARGV[8] =~ m/unlimited/i ) {
        $maxftp = 'n';
    }
    else {
        $maxftp = int( $ARGV[8] );
    }
    
    my $maxsql;
    if ( $ARGV[9] eq 'n' || $ARGV[9] eq '' || $ARGV[9] =~ m/unlimited/i ) {
        $maxsql = 'n';
    }
    else {
        $maxsql = int( $ARGV[9] );
    }
    
    my $maxpop;
    if ( $ARGV[10] eq 'n' || $ARGV[10] eq '' || $ARGV[10] =~ m/unlimited/i ) {
        $maxpop = 'n';
    }
    else {
        $maxpop = int( $ARGV[10] );
    }
    
    my $maxlst;
    if ( $ARGV[11] eq 'n' || $ARGV[11] eq '' || $ARGV[11] =~ m/unlimited/i ) {
        $maxlst = 'n';
    }
    else {
        $maxlst = int( $ARGV[11] );
    }
    
    my $maxsub;
    if ( $ARGV[12] eq 'n' || $ARGV[12] eq '' || $ARGV[12] =~ m/unlimited/i ) {
        $maxsub = 'n';
    }
    else {
        $maxsub = int( $ARGV[12] );
    }
    
    my $bwlimit;
    if ( $ARGV[13] eq 'n' || $ARGV[13] eq '' || $ARGV[13] =~ m/unlimited/i ) {
        $bwlimit = 0;
    }
    else {
        $bwlimit = int( $ARGV[13] );
    }
    
    my $hasshell;
    if ( $ARGV[14] eq 'n' ) {
        $hasshell = 'n';
    }
    else {
        $hasshell = 'y';
    }
    
    my $owner = $ARGV[15];
    if ( $owner eq '' ) {
        $owner = $ENV{'REMOTE_USER'} || $ENV{'USER'} || 'root';
    }
    
    my $plan = $ARGV[16];
    if ( $plan eq '' ) {
        $plan = 'default';
    }
    
    my $maxpark;
    if ( $ARGV[17] eq 'n' || $ARGV[17] eq '' ) {
        $maxpark = 0;
    }
    else {
        if ( $ARGV[17] !~ /unlimited/i ) {
            $maxpark = int( $ARGV[17] );
        }
        else {
            $maxpark = 'unlimited';
        }
    }
    
    my $maxaddon;
    if ( $ARGV[18] eq 'n' || $ARGV[18] eq '' ) {
        $maxaddon = 0;
    }
    else {
        if ( $ARGV[18] !~ /unlimited/i ) {
            $maxaddon = int( $ARGV[18] );
        }
        else {
            $maxaddon = 'unlimited';
        }
    }
    
    my $featurelist;
    if ( $ARGV[19] eq '' ) {
        $featurelist = 'default';
    }
    else {
        $featurelist = $ARGV[19];
        $featurelist =~ s/[\r\n]*//g;
        $featurelist =~ s/\.\.//g;
    }
    
    my $ceml;
    if ( $ARGV[20] eq '' ) {
        $ceml = '';
    }
    else {
        $ceml = $ARGV[20];
    }
    
    my $useregns;
    if ( $ARGV[21] eq '' ) {
        $useregns = '';
    }
    else {
        $useregns = $ARGV[21];
    }
    
    my $language;
    if ($ARGV[22]) {
        $language=$ARGV[22];
    }
    
    if ($ARGV[0] =~ m/:/ || $ARGV[0] =~ m/--help/ || !$domain || !$user || !$pass ) {
        my $syntax = "Please use the this syntax\n";
        $syntax .=
          "wwwacct \e[1m<domain> <user> <pass>\e[0m <quota> <cpmod[advanced/?]> <ip[y/n]> <cgi[y/n]> <frontpage[y/n]> <maxftp> <maxsql> <maxpop> <maxlst> <maxsub> <bwlimit> <hasshell[y]/[n]> <owner> <plan> <maxpark> <maxaddon> <featurelist> <contactemail> <use_registered_nameservers> <language>\n\n";
        print $syntax;
        exit(1);
    }
    
    my $acctout = <<"EOM";
    +===================================+
    | New Account Info                  |
    +===================================+
    | Domain: $domain
    | UserName: $user
    | PassWord: $pass
    +===================================+
    
    EOM
    print $acctout;
    
    if ( -t STDIN && $ENV{'PKGRESTORE'} ne "1" ) {
        print "This ok? ";
        my $isok;
        while ( $isok = <STDIN> ) {
            $isok =~ s/\n//g;
            $isok =~ tr/[A-Z]/[a-z]/;
    
            if ( $isok ne "" ) {
                last if $isok =~ /^y/;
                if ( $isok =~ /^n/ ) {
                    cPScript::Errors::deaderror "Ok Guess NOT\n";
                }
            }
        }
    }
    
    if ( !$ENV{'REMOTE_USER'} || $ENV{'REMOTE_USER'} eq '' ) { $ENV{'REMOTE_USER'} = 'root'; }
    
    my %WWWACCTCFG = (
        domain       => $domain,
        username     => $user,
        password     => $pass,
        quota        => $sqto,
        cpmod        => $cpmo,
        useip        => $useip,
        cgi          => $hascgi,
        frontpage    => $installfp,
        maxftp       => $maxftp,
        maxsql       => $maxsql,
        maxpop       => $maxpop,
        maxlst       => $maxlst,
        maxsub       => $maxsub,
        bwlimit      => abs $bwlimit,
        hasshell     => $hasshell,
        owner        => $owner,
        plan         => $plan,
        maxpark      => $maxpark,
        maxaddon     => $maxaddon,
        featurelist  => $featurelist,
        contactemail => $ceml,
        forcedns     => $forcedns,
        useregns     => $useregns,
        language     => $language,
        customip     => $customip,
    );
    
    Whostmgr::ACLS::init_acls();
    my ( $status, $result, $output ) = Whostmgr::Accounts::Create::_createaccount(%WWWACCTCFG);
    
    print $result;
    print "\n";
    print $output;
    print "\n";
    
    ================================================END OF MY postwwwacct ==========================
    AND THIS IS THE EMAIL TO ROOT
    Code:
    ================================================START OF MY wwwacct OUTPUT =======================
    (THIS IS THE COPY SENT TO ROOT)
    
    New account on archie.westonehosting.com (simon5.westonecms.com)
    
    +===================================+
    | New Account Info                  |
    +===================================+
    | Domain: simon5.westonecms.com
    | Ip: 67.225.245.129 (n)
    | HasCgi: y
    | UserName: simon5w
    | PassWord: ***HIDDEN***
    | CpanelMod: x3
    | HomeRoot: /home
    | Quota: 500 Meg
    | NameServer1: ns1.westonehosting.com
    | NameServer2: ns4.westonehosting.com
    | NameServer3: 
    | NameServer4: 
    | Contact Email: forums@westonehosting.com
    | Package: Standard Plan
    | Feature List: default
    | Language: english
    +===================================+
    Account was setup by: root (root)
    
    ================================================END OF MY wwwacct OUTPUT =======================
    
    My WHM is

    WHM 11.23.2 cPanel 11.23.6-S27698
    CENTOS Enterprise 4.7 i686 on virtuozzo - WHM X v3.1.0
     
  3. west one

    west one Member

    Joined:
    Sep 15, 2006
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1
    please I need help?

    please I do need help?
     
  4. we3cares

    we3cares Member

    Joined:
    Oct 29, 2008
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    We3cares

    We3cares is a webserver administration company and we can provide you support personnel for your company. We have got engineers with 5+ years of experience in handling linux servers.

    Drop a mail to sales@we3cares.com. We can discuss further.
     
  5. cPanelNick

    cPanelNick Administrator
    Staff Member

    Joined:
    Mar 9, 2015
    Messages:
    3,426
    Likes Received:
    2
    Trophy Points:
    38
    cPanel Access Level:
    DataCenter Provider

    Rename your script

    legacypostwwwacct

    in cPanel 11 the arguments are a hash.
     
  6. hrockvn

    hrockvn Member

    Joined:
    Oct 10, 2007
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Haven't any email send to me or my customer when I save to /scripts/legacypostwwwacct.
    Why???
     
  7. cPanelNick

    cPanelNick Administrator
    Staff Member

    Joined:
    Mar 9, 2015
    Messages:
    3,426
    Likes Received:
    2
    Trophy Points:
    38
    cPanel Access Level:
    DataCenter Provider
    Please open a ticket @ https://tickets.cpanel.net/submit/
     
  8. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    Last post was a few months ago, but in case you're still having trouble, that's my postwwwacct script and it was recently edited to use the new hash method, so if you get my current version it will work.
     
  9. west one

    west one Member

    Joined:
    Sep 15, 2006
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1
    Thanks

    Will do that.
     
Loading...

Share This Page