Security setup for directories using xml api - Password Protect Directories

nhk15

Registered
Mar 16, 2009
4
0
51
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
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,212
13
313
Houston, TX
cPanel Access Level
Root Administrator
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
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
 

nhk15

Registered
Mar 16, 2009
4
0
51
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
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,212
13
313
Houston, TX
cPanel Access Level
Root Administrator
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
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
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,212
13
313
Houston, TX
cPanel Access Level
Root Administrator
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?
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.
 

netarus

Well-Known Member
Oct 27, 2002
105
0
166
Is there anyone else that can assist with this? Thank you for any replies.
 

Spiral

BANNED
Jun 24, 2005
2,018
8
193
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:
 

netarus

Well-Known Member
Oct 27, 2002
105
0
166
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.