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.

Security setup for directories using xml api - Password Protect Directories

Discussion in 'cPanel Developers' started by nhk15, Apr 13, 2009.

  1. nhk15

    nhk15 Registered

    Joined:
    Mar 16, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Hi

    Is there anyone knows how to enable the password protection for a directory and create a user/password for it using XML api?



    Regards,
    Nam
     
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Here's the raw API1 call for setting the password protection for a directory:

    Code:
    <cpanel Htaccess="set_pass(directory, username, password)">
    You can then call this API1 function from the XML API. If you are not familiar with how to do that, feel welcome to use the PHP class Matt has written for using our XML API:

    http://forums.cpanel.net/showthread.php?t=111897
     
  3. nhk15

    nhk15 Registered

    Joined:
    Mar 16, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Thank you for your reply. It works great.

    Just one more thing, what is the xml api function to turn on/off for Password protect directories?

    When i tried it through cPanel, the url looks like this below:

    after turning on the option:
    http_s://mydomain.com:2083/frontend/x3/htaccess/changepro.html?protected=1&resname=mysite&action2=Save&dir=%2Fhome%2Ffusername%2Fpublic_html%2F

    after turning off the option:
    http_s://mydomain.com:2083/frontend/x3/htaccess/changepro.html?resname=&action2=Save&dir=%2Fhome%2Fusername%2Fpublic_html%2F
     
  4. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    The API call I provided earlier is for creating a user for a password protected directory. To enable or disable password protection, this is the raw API1 call:

    Code:
    <cpanel Htaccess="set_protect(directory,protected,resource_name)">
    Where directory is the directory to enable/disable protection for.

    Protected is 1 if directory protection is to be enabled, 0 to disable

    resource_name is text you can choose to display within the password prompt that is displayed by the browser to let users know what they're logging into (e.g. Member Area).

    The XML API URL for this would be:

    Code:
    /xml-api/cpanel?user=username&xmlin=<cpanelaction><module>Htaccess</module><func>set_protect</func><apiversion>1</apiversion><args>/home/username/public_html/something</args><args>1</args><args>Member Area</args></cpanelaction>
    You can view our documentation for calling API1 functions from the XML API at:

    http://twiki.cpanel.net/twiki/bin/v...ation/CallingAPIFunctions#API1_With_arguments
     
  5. nhk15

    nhk15 Registered

    Joined:
    Mar 16, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    oh Cool, thank you so much! :)
     
  6. netarus

    netarus Well-Known Member

    Joined:
    Oct 27, 2002
    Messages:
    105
    Likes Received:
    0
    Trophy Points:
    16
    I have another post where I'm trying to compare the username and password (Reference: cPanel Forums - Search Results) Does anyone know how to compare username and passwords generated by the cPanel XML API?
     
  7. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Just a head's up, search results expire after a period of time so linking to search results isn't a good idea. I recommend linking directly to the threads you were trying to direct attention to.
     
  8. netarus

    netarus Well-Known Member

    Joined:
    Oct 27, 2002
    Messages:
    105
    Likes Received:
    0
    Trophy Points:
    16
  9. netarus

    netarus Well-Known Member

    Joined:
    Oct 27, 2002
    Messages:
    105
    Likes Received:
    0
    Trophy Points:
    16
    Is there anyone else that can assist with this? Thank you for any replies.
     
  10. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    I am not 100% certain what it is that you are actually asking and it has been almost a month since your previous post.

    Still playing around with .htpasswd access setup? :confused:
     
  11. netarus

    netarus Well-Known Member

    Joined:
    Oct 27, 2002
    Messages:
    105
    Likes Received:
    0
    Trophy Points:
    16
    Thank you for your reply. Let me try phrasing it another way...

    You can set a password on a directory using cPanel (stored in htpasswd file), how do you programmatically using PHP authenticate a user to access that password protected directory? We do not want the web browser prompts to appear. They should authenticate directly through our PHP code.

    This is the related post - http://forums.cpanel.net/f42/passwor...ds-157297.html

    Thank you again for your reply and any updates or questions you may have for clarification.
     
Loading...

Share This Page