Hi,
I am writing a script that simulates a web server. It accepts a request header and makes the appropriate response etc.
I want to impliment Basic Authentication, using dynamic variables from a .htaccess file (AuthType,AuthName). Problem is that the .htaccess file that I am working from is littered with commenting, which cannot be changed.
What I would like to know is how can I extract the two uncommented lines in the below file? What I need to be able to access is the word "Basic" (without the quotes) and "Some realm" (with the quotes). Please also note that the two required lines are indented, I think with a tab.
----------------------------------------------------
----------------------------------------------------
What I have been thinking is that I would need to read through the file line by line, checking for whitespace at the begining of the line, or checking for the words "AuthType" or "AuthName". Any help with this would be greatly appreciated.
Cheers
I am writing a script that simulates a web server. It accepts a request header and makes the appropriate response etc.
I want to impliment Basic Authentication, using dynamic variables from a .htaccess file (AuthType,AuthName). Problem is that the .htaccess file that I am working from is littered with commenting, which cannot be changed.
What I would like to know is how can I extract the two uncommented lines in the below file? What I need to be able to access is the word "Basic" (without the quotes) and "Some realm" (with the quotes). Please also note that the two required lines are indented, I think with a tab.
----------------------------------------------------
Code:
# AuthType specifies that Basic authentication must
# be used on all filesin this directory.
# AuthName specifies the name of the realm for which
# authentication is required.
AuthType Basic
AuthName "Some realm"
# AuthUserFile apache2/htpasswd.users
# Require valid-user
# Check for the existence of the .htaccess file,
# then check if AuthType and AuthName are not commented
# out. Then it must use the AuthName value when it
# implements basic authentication.
What I have been thinking is that I would need to read through the file line by line, checking for whitespace at the begining of the line, or checking for the words "AuthType" or "AuthName". Any help with this would be greatly appreciated.
Cheers