logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Variable in directives?
Author
Virsacer



Joined: 16 Jan 2010
Posts: 108
Location: Germany, Darmstadt

PostPosted: Wed 17 Aug '11 9:35    Post subject: Variable in directives? Reply with quote

I would like to have a "Require group" depending on the URL.
The content is handled by a cgi-script so I cannot use .htaccess files...

domain.tld/dirname -> Require group dirname
domain.tld/dirname/subdir(s) -> Require group dirname
domain.tld/seconddir -> Require group seconddir
domain.tld/seconddir/subdir(s) -> Require group seconddir
...

Is that possible?
Can I get I variable from a "LocationMatch"?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Wed 17 Aug '11 10:23    Post subject: Reply with quote

I think you can work with Directory. Than all subdirs will have that too. Like with the .htaccess

<Directory "/Apache22/htdocs/dirname">
</Directory>
Back to top
Virsacer



Joined: 16 Jan 2010
Posts: 108
Location: Germany, Darmstadt

PostPosted: Wed 17 Aug '11 10:46    Post subject: Reply with quote

Well, currently I have this in my config:
Code:
<Location "/">
   AuthType Basic
   ...
   Deny from all
</Location>
<Location "/dirname">
   Allow from all
   Require group dirname
</Location>
<Location "/seconddir">
   Allow from all
   Require group seconddir
</Location>

But I'd prefer not to have a Location Block for every dir...
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Wed 17 Aug '11 10:53    Post subject: Reply with quote

If you can't do it differently, but are lazy than you should take a look at mod_macro. It makes it realy easy so set uo such a thing and keeping the overview.
Back to top
Virsacer



Joined: 16 Jan 2010
Posts: 108
Location: Germany, Darmstadt

PostPosted: Wed 17 Aug '11 14:43    Post subject: Reply with quote

Thanks, but isn't there a way to do this automatically for each existing dir?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Thu 18 Aug '11 9:25    Post subject: Reply with quote

OK, I did RTFM and it might be possible with the env REQUEST_URI and SetEnvIf.

Don't ask me for a regex doing this. I'm not good into that Wink
Back to top
Virsacer



Joined: 16 Jan 2010
Posts: 108
Location: Germany, Darmstadt

PostPosted: Thu 18 Aug '11 10:06    Post subject: Reply with quote

This looks promising!
I'll test it later today...
Back to top
Virsacer



Joined: 16 Jan 2010
Posts: 108
Location: Germany, Darmstadt

PostPosted: Thu 18 Aug '11 14:53    Post subject: Reply with quote

The Require directive does not understand the env= param...
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Thu 18 Aug '11 15:52    Post subject: Reply with quote

From the docs it shoud... argh! I found that on the new 2.3 aka 2.4 apache...

See http://httpd.apache.org/docs/2.3/mod/mod_authz_core.html#requiredirectives


Maybe this could work (haven't tested). Ok there is the regex missing Wink
Code:

Order Deny,Allow
Satisfy any
SetEnvIf REQUEST_URI "/api/" allow_all
Deny from all
Require valid-user
Allow from env=allow_all 
Back to top
Virsacer



Joined: 16 Jan 2010
Posts: 108
Location: Germany, Darmstadt

PostPosted: Thu 18 Aug '11 22:21    Post subject: Reply with quote

I also found the manualpage, but "Require Env" checks only if the var is defined and I am using Apache 2.2

The Regex would be "^/(.+)/?", but parsing would result in "Allow from dirname"...

I need to check the group - Only members of the group "dirname" are allowed to access domain.tld/dirname
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Thu 18 Aug '11 23:12    Post subject: Reply with quote

I found two links on the net. Still not sure if that is helping...

Are there so many directory you have to maintain in your apache config?

http://objectmix.com/apache/673763-locationmatch-directorymatch-regex.html
https://digitalelf.net/2010/01/apache-mod-rewrite-based-on-logged-in-user.html
Back to top
Virsacer



Joined: 16 Jan 2010
Posts: 108
Location: Germany, Darmstadt

PostPosted: Fri 19 Aug '11 10:30    Post subject: Reply with quote

I'll probably have to stick with the config from my second post.
If the number of directories grows I'll use a script to generate the config...

Thanks for trying to help!
Back to top


Reply to topic   Topic: Variable in directives? View previous topic :: View next topic
Post new topic   Forum Index -> Apache