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.

Function to replace the user names cpanel?

Discussion in 'cPanel Developers' started by Rigina, Sep 27, 2011.

  1. Rigina

    Rigina Registered

    Joined:
    Sep 14, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hello,
    Need to automatically replace the names (login) of all user cpanel. What API function can it perform?
    Help me, please.
     
    #1 Rigina, Sep 27, 2011
    Last edited: Sep 27, 2011
  2. sirdopes

    sirdopes Well-Known Member
    PartnerNOC

    Joined:
    Sep 25, 2007
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    16
    Are you wanting to change the usernames for all of the users? Do you have root access or are you wanting to do this as a reseller?
     
  3. Rigina

    Rigina Registered

    Joined:
    Sep 14, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I have root access
     
  4. sirdopes

    sirdopes Well-Known Member
    PartnerNOC

    Joined:
    Sep 25, 2007
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    16
    The following is a simple example on how to change a username with perl using cpanel's api.

    Code:
    #!/usr/bin/perl
    use LWP::UserAgent;
    use MIME::Base64;
    
    
    my ($user, $newuser) = @ARGV;
    if ((!$user) || (!$newuser)) {
            print "Usage: changeuser currentuser newuser \n";
            exit;
    }
    my $luser = "username";
    my $lpass = "password";
    my $ip = "127.0.0.1";
    my $auth = "Basic " . MIME::Base64::encode( $luser . ":" . $lpass );
    
    my $ua = LWP::UserAgent->new;
    my $request =
    HTTP::Request->new( GET =>
    "http://$ip:2086/xml-api/modifyacct?user=$user&newuser=$newuser"
    );
    $request->header( Authorization => $auth );
    my $response = $ua->request($request);
    print $response->content;
     
    
     
Loading...

Share This Page