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.

Customizing the directory path for FTP Users

Discussion in 'General Discussion' started by simple_joe, Aug 5, 2010.

  1. simple_joe

    simple_joe Member

    Joined:
    Aug 5, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    Moving my dedicated server to a CPanel server, so far love everything about it.

    One question:

    is there a way to remove the "public_html/" path that is automatically filled in by CPanel when a client adds a new FTP User.

    for instance when when creating FTP User "testing" I just want the
    directory to be "/testing" and not "/public_html/testing"

    is there a file I can edit, or?

    any help is much appreciated,
    Joe
     
  2. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,449
    Likes Received:
    195
    Trophy Points:
    63
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    When creating the additional FTP account have you tried removing the part about public_html? I just tested this and it can be removed (the path can be edited on creation)
     
  3. simple_joe

    simple_joe Member

    Joined:
    Aug 5, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    Hello, yes I can do this. It's just that I have hundreds of FTP users and they all want their folders to be non-web-accessible so I was hoping to hard-code this into the cpanel templates. I was hoping there was a file that controls this and I could just remove the "public_html" portion.

    Do you know the path to the cpanel files, or the file that controls FTP users?

    thanks for your help
     
  4. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,449
    Likes Received:
    195
    Trophy Points:
    63
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    Have a peek at the users file in /etc/proftpd/cpanelaccountusernamehere

    That file should show all of your ftp accounts for that account that you might edit.

    As for editing this default behavior on addon FTP accounts creation, I'll leave that to the developers to help you out with. Sorry I can't help more than that.
     
  5. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi Joe,

    The quickest and least invasive hack for this is to modfiy the template page, /usr/local/cpanel/base/frontend/x3/ftp/accounts.html , at line 40. Remove the 'onchange="suggest_homedir()"' attribute or place your own JavaScript function call there (and include your function via a <script></script> somewhere in the template).

    ex: add custom function and mod line 40.
    Code:
    <script>
      //simply removed the static "public_html/" string in the concatenation//
      var suggest_homedir_custom=function(){YAHOO.util.Dom.get("homedir").value=YAHOO.util.Dom.get("login").value;ADD_VALID.dir.verify()};
    </script>
    <td style="width: 150px">
      <input type="text" name="login" id="login" style="width: 150px" onchange="suggest_homedir_custom()" />
    </td>
    
    This is not a permenant solution, but would work for the meantime.

    If you're having to create these accounts manually, I'd just create them with the API1 'Ftp::addftp' call via the xml-api. Here's an example using the xml-api PHP client class to perform the request:
    Code:
    include("xmlapi.php");
    
    $ip = "10.1.1.1";
    $root_user = "root";
    $root_pass = "s3cr3tPass!";
    $cpuser = 'dave';
    
    
    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth( $root_user, $root_pass );
    $xmlapi->set_output('xml');
    $xmlapi->set_port('2087');
    //$xmlapi->set_debug(1);
    
    //Ftp::addftp( user, pass, homedir, quota, disallowdot, homedir2 )
    $args = array( 'ftpuser1', 'pass1', '../testdir1', '', '', 'testdir1' );
    
    //those are create homedir: /home/$cpuser/testdir1
    //the third variable is relative to /home/$cpuser/public_html
    //the sixth variable is relative to /home/$cpuser
    //  as far as I know, you'll need to provide both for cPanel and the FTP
    //   sub-system to function properly.
    
    $xmlapi->api1_query($cpuser, 'Ftp', 'addftp', $args);
    
    There are many threads about how to use the xml-api and make requests via Perl, PHP or other languages. Check out docs.cpanel.net and/or give a shout if you need anything.

    Best Regards,
    -DavidN
     
  6. simple_joe

    simple_joe Member

    Joined:
    Aug 5, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    thank you for your help, what's strange is I don't see a line 40 or even the text "onchange" in:
    /usr/local/cpanel/base/frontend/x3/ftp/accounts.html

    i also tried a grep for "suggest_homedir" in the whole "ftp" folder and did not see anything.

    my version is the new cpanel, anything i might be doing wrong?

    thanks,
    Joe
     
  7. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    doh! my bad, sorry Joe. My suggested change for file would be specific to cPanel 11.25.1. In cPanel 11.25.0, accounts.html is a redirect to one of two files depending on which FTP server your system is running. Both have the same change, just in different files and line numbers.

    If you're using Pure-FTP, then modify accounts_pure-ftpd.html, approximately line 159.

    If you're using ProFTP, then modify add_ftp_form.html, approximately line 72.

    The change is to the JavaScript
    Code:
    // old value '= "public_html/" + YAHOO.util.Dom.get("login").value;' 
    // new value removes '"public_html/" +'
    YAHOO.util.Dom.get("homedir").value = YAHOO.util.Dom.get("login").value;
    
    Regards,
    -DavidN
     
  8. simple_joe

    simple_joe Member

    Joined:
    Aug 5, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    Thank you DavidN!

    Hello DavidN, just wanted to thank you -- it worked like a charm!

    cpanel is lucky to have people like you onboard, hope i can contribute back in the future to this forum

    this technique allows people to have the ftp users private by default, which is something ftp hosting providers especially would want, and I'm sure others will reference.

    I guess the only thing is I will have to re-edit this change each time CPanel upgrades (?), but that's ok.

    best regards, Joe :)
     
  9. PhilGlau

    PhilGlau Active Member

    Joined:
    Nov 3, 2010
    Messages:
    27
    Likes Received:
    0
    Trophy Points:
    1
    I'm looking to do a similar thing, but with the added complication of making the files in users directories read and writable by the PHP process set to DSO.

    Example:

    domain administrator = 'mysite'

    /public_html/clientarea/ftp/client1
    /public_html/clientarea/ftp/client2
    /public_html/clientarea/ftp/client3
    etc...

    The clients can upload files via FTP but they get assigned the user "mysite:mysite" for UID:GID.

    It seems like in order for PHP running as DSO to have move/delete capabilities over the files uploaded, either the UID or GID must be 'nobody'.

    I changed the file in /etc/proftpd/mysite so that the group is '99' for the client users.

    This allows the files uploaded to the directory to have the correct UID:GID as "mysite:nobody", but the permissions are 644 and they would need to be 664 in order for group 'nobody' to move or delete the files.

    How do I get the files uploaded to be 'rw' for the group 'nobody' by default?
     
  10. PhilGlau

    PhilGlau Active Member

    Joined:
    Nov 3, 2010
    Messages:
    27
    Likes Received:
    0
    Trophy Points:
    1
    Sort of figured it out for anybody interested, but would like a confirmation that what I did will work long term. I'm somewhat concerned that the /etc/proftpd.conf file will get overwritten by cPanel at some point.

    Inside proftpd.conf I added the following directive:

    Umask 0002

    in the <Virtual Host 123.123.123.123> container for the site in question. Fortunately it's a IP based site anyways.

    thus by changing the 'mysite' password file such that the client users are set to group 'nobody' and the umask to 0002 instead of 0022, when a file is uploaded I'm getting:


    rw_rw_r__ mysite:nobody mytest_file.txt

    which seems to allow PHP scripts to move or delete the file as necessary.

    Question: While I put my changes in /etc/proftpd.conf, I really suspect that they're going to get whacked if I add another virtual host inside cpanel.

    I'm thinking I should put another file in /etc/proftpd.d/ called 'mysite_custom_directives' and add the directives there. Any thoughts?
     
Loading...

Share This Page