Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a legacy web application on which I need to set access control based on the URL.

There are only two possibilities: allow from all or allow from my domain.

I believe I can do something like:

<Location /app/one-part>
   Allow from all
</Location>

<Location /app/another-part>
   Allow from .foo.tld
</Location>

<Location /app/yet-another-part>
   Allow from .foo.tld
</Location>

....

The problem is that this particular application has hundreds of /app/thinguie URLs, and I don't want to code them all like I showed above.

Is there a way to do something like

<Location from file dom.txt>
   Allow from .foo.tld
</Location>

<Location from file all.txt>
   Allow from All
</Location>

and two files with the /app/whatevers listed?

thanks in advance.

Oh, by the way, there is no pattern and therefore no regular expression I can use to filter elegantly. :(

share|improve this question
    
Can you post the real data? I wonder that can we do with a DirectoryMatch directive. –  quanta Sep 16 '11 at 2:52
    
@quanta. In reality it is the same application, and the path represents a database. Some databases need to be accessible from the internet, some do not. There is not much a Match can do. –  Marcelo Morales Sep 16 '11 at 11:06
    
If so, check out the @SparX's suggestion. You can use echo -e "\t..." to keep formating and also notice that you should use <Directory> directive instead of <Location> for access control. –  quanta Sep 16 '11 at 11:13

1 Answer 1

up vote 0 down vote accepted

The apache directive "Location" only accepts URL-path or URL as parameter and there is no way to read an external list. What I would suggest is, create a script to generate a custom conf which you can include in your apache conf.

Example:

[sparx@E1]$ cat file-foo.txt
/my/local
/my/src
/my/local/src
[sparx@E1]$ 

Now create a simple bash script to generate the custom conf.

#!/bin/bash
for x in `cat file-foo.txt`
do
echo "<Location $x>"
echo "Allow from .foo.tld"
echo "<\Location>"
done

Now execute the script and redirect the output to say, my-foo.conf

[sparx@E1]$ ./apgen.sh > my-foo.conf
[sparx@E1]$ cat my-foo.conf
<Location /my/local>
Allow from .foo.tld
<\Location>
<Location /my/src>
Allow from .foo.tld
<\Location>
<Location /my/local/src>
Allow from .foo.tld
<\Location>
[sparx@E1]$ 

Now, the conf file is generated. Verify it and include in your main apache conf.

Include "path/to/my-foo.conf"
share|improve this answer
    
This was the way chosen. –  Marcelo Morales Sep 19 '11 at 14:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.