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.

Search accounts by email address?

Discussion in 'cPanel Developers' started by oulzac, Apr 14, 2006.

  1. oulzac

    oulzac Well-Known Member

    Joined:
    Aug 7, 2005
    Messages:
    131
    Likes Received:
    0
    Trophy Points:
    16
    Hello boys and girls!

    Is there already a mod or anything for searching in WHM for accounts by the users email addy?
    This would be very handy I think not only for me but many hosts.

    If there is not one, how easy would it be to make one?
    or request that cpanel add it?
     
  2. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    There's no such feature in WHM. Simple enough to check which domain belongs to which user, though:

    grep somedomain.com /var/cpanel/users/*
     
  3. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    To search for accounts by the users email address, you would need to search the .contactemail files in the sites root directories.

    Try
    grep email /home/*/.contactemail
    in shell
     
  4. oulzac

    oulzac Well-Known Member

    Joined:
    Aug 7, 2005
    Messages:
    131
    Likes Received:
    0
    Trophy Points:
    16
    Thanks guys,
    I already know how to search in ssh, but I was wondering about in WHM.

    Would anyone be able to point me in the right direction to start editing the list accounts functions then? Chirpy?
     
  5. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    You can't change how the function works because the code is compiled, but you can do like I do and add your own functions in WHM. Could write an addon script to do that.
     
  6. oulzac

    oulzac Well-Known Member

    Joined:
    Aug 7, 2005
    Messages:
    131
    Likes Received:
    0
    Trophy Points:
    16
    How would I go about this, in the /cgi are of /whm ?
     
  7. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    Save the following code to a text file and call it addon_findaccountsbyemail.cgi and put it on your server in the /usr/local/cpanel/whostmgr/docroot/cgi folder. Make it executable and you will find a link in your WHM under "addons" that will say "Find Accounts by Email".

    Code:
    #!/usr/bin/perl
    # You may need to change this path to /usr/local/bin/perl
    #WHMADDON:addonupdates:Find Accounts by Email
    
    read(STDIN, $buffer, $ENV{CONTENT_LENGTH});
    
    @pairs = split(/&/,$buffer);
      foreach $pair (@pairs) {
       ($name, $value) = split(/=/, $pair);
         $value =~ tr/+/ /;
         $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
         $value =~ s/<!--(.|\n)*-->//g;
        $FORM{$name} = $value;
      }
    
    
    print "Content-type: text/html\r\n\r\n";
    
    if ($FORM{email}) {&getlist;}
    
    print qq~<html>
    <body>
    <form method="post" action="addon_findaccountsbyemail.cgi">
    Email Address: <input type="text" name="email" size="25"><br>
    <input type="submit" name="submit" value=" Get List! ">
    </form>
    </body>
    </html>
    ~;
    
    exit;
    
    sub getlist {
    @accounts = `grep $FORM{email} /home*/*/.contactemail`;
    print qq~<html>
    <body>
    <b>The following .contactemail files contain $FORM{email}:</b><br>
    ~;
    
    foreach $_ (@accounts) {
      print "$_";
    }
    
    print qq~
    </body>
    </html>
    ~;
    exit;
    }
    
     
  8. sawbuck

    sawbuck Well-Known Member

    Joined:
    Jan 18, 2004
    Messages:
    1,367
    Likes Received:
    5
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    Nice work Mike. You're getting good at writing these addons.
     
  9. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    I've got a few more WHM script ideas as well, and since I've been getting several new members the last couple months, I'm going to take some time this week to add some new ideas.

    My scripts club has passed the 50 member mark. :)
     
  10. oulzac

    oulzac Well-Known Member

    Joined:
    Aug 7, 2005
    Messages:
    131
    Likes Received:
    0
    Trophy Points:
    16
    Hey thank you very much, this is excellent!

    you said a script club? can you give me details on this?

    *Edit: also, not sure if i should change anything, but its not working???
     
    #10 oulzac, Apr 18, 2006
    Last edited: Apr 18, 2006
  11. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    See:
    Custom Scripts for WHM and cPanel (join our "Scripts Club")
    in my sig.

    Do you have a link to it in WHM?
    If so, skip the next 2 questions.
    Is the file called addon_findaccountsbyemail.cgi?
    Is it located in the /usr/local/cpanel/whostmgr/docroot/cgi folder?

    Was it uploaded in ascii?
    Is it executable?

    Add
    use CGI::Carp qw(fatalsToBrowser);
    to the script somewhere after the first 3 lines and see if it tells you anything when trying it.
     
  12. oulzac

    oulzac Well-Known Member

    Joined:
    Aug 7, 2005
    Messages:
    131
    Likes Received:
    0
    Trophy Points:
    16
    excellent!!
    you are da man

    I will be looking into your other scripts here real soon!

    thanks again.
     
Loading...

Share This Page