[Tech] primi balbettamenti in apache

Franco Bagnoli bagnoli@dma.unifi.it
Mar 5 Set 2000 12:02:57 CEST


Dopo essere andato a scuola da cosimo ecco il mio primo temino:
twiki e' uno strumento per editare delle pagine via web.

http://twiki.sourceforge.net

tipici comandi sono 

/twiki/bin/edit/web/page per editare "page" nella directory "web"
/twiki/bin/wiew/web/page per vedere la pagina "page" nella directory "web"
/twiki/bin/search/web/?options per cercare (secondo options) nella
                             directory "web"

Nella versione originale ci sono delle opzioni (view,search) che possono
essere fatte da tutti, ed altre (edit, delete, ecc.) solo dagli utenti
registrati, ma dato che l'autorizzazione viene fatta sulla directory
/twiki/bin non si puo' distinguere gli accessi in base alla directory.

La seguente soluzione permette di farlo senza toccare gli script e
lasciando la gestione delle autorizzazioni all'apache: 

gli script di twiki generano dei link del tipo 

root/action/web/page

dove root e' definibile via setup (di default /twiki/bin) e action e'
view, edit, ecc

a parte alcune modifiche estetiche, l'idea ' la seguente: in httpd.conf,
per le action di cui voglio controllare l'accesso, rovescio la url

/root/action/web/page -> /newroot/web/page/action

nella directory /newroot/web prima eseguo l'autenticazione e poi
rirovescio indietro

/newroot/web/page/action -> /newroot/action/web/page

mentre le action che non necessitano di autorizzazione sono 
semplicemente trascritte in 

/root/action/web/page?options -> /newroot/action/web/page?options

il cambio tra root e newroot (di cui solo la seconda esiste
veramente) serve per evitare che la stessa trasformazione passi due volte
dalle RewiteRules.

Di seguito trovate la descrizione dettagliata (nel semi-html di wiki),
come riportato in 

http://TWiki.SourceForge.net/cgi-bin/view/Codev/UserAuthorizationSchemes
 
Domanda (per cosimo): quando usare <LocationMatch> e quando RewriteCond?

nota: il giochetto non funziona se devo autenticare delle action con
delle option (ci vogliono delle regular expression piu' furbe, credo) 



---------------------------------------------------------------------

Here is the instruction on how to perform authorization on a 
per web basis:

   * move /home/httpd/twiki to /home/httpd/realtwiki


   * edit wiki.cfg so that all but $wikiHomeUrl now points to 
	 /realtwiki, while $wikiHomeUrl points to /twiki (without bin, it is not
	 needed): 
	 
   <pre>	 
   #                   %WIKIHOMEURL% : link of TWiki icon in upper left corner :
   $wikiHomeUrl      = "http://kurt.poggiosecco.it/twiki";
   #                   Host of TWiki URL :    (Example "http://myhost.com:123")
   $defaultUrlHost   = "http://kurt.poggiosecco.it";
   #                   %SCRIPTURLPATH% : cgi-bin path of TWiki URL:
   $scriptUrlPath    = "/realtwiki/bin";
   #                   %PUBURLPATH% : Public data path of TWiki URL (root of attach$pubUrlPath       = "/realtwiki/pub";
   #                   Public data directory, must match $pubUrlPath :
   $pubDir           = "/home/httpd/realtwiki/pub";
   #                   Template directory :
   $templateDir      = "/home/httpd/realtwiki/templates";
   #                   Data (topic files) root directory :
   $dataDir          = "/home/httpd/realtwiki/data";             
   </pre>	 

   * in httpd.conf change all references to /twiki to /realtwiki, and 
	 add 
	 
   <pre> 
    RewriteEngine on
   #edit,preview,save,attach,upload are autheticated on a web basis
   RewriteRule /twiki/(edit|preview|save|attach|upload)/(.*)$ /realtwiki/data/$2/$1
   #all others are free
   RewriteRule /twiki/(.*) /realtwiki/bin/$1
   &lt;/LocationMatch&gt;
   </pre>
	 
   * in /home/httpd/realtwiki/data/Main/.htaccess 

   <pre>
   AuthUserFile /home/httpd/realtwiki/data/.htpasswd
   AuthName ByPassword
   AuthType Basic
   
   require valid-user
   RewriteEngine on
   RewriteRule ([^/]*)/([^/]*) /realtwiki/bin/$2/Main/$1
   </pre>
	 
   * repeat for all other webs.
	 
Clearly, in order to have different access controls one has to refer to
different .htpassword files. 

One should also change register: it should be called with the 
name of the web as its
argument, read the .htaccess file and alter the referred .htpasswd. 

In this way one has a flexible setup: by referring to the same .htpasswd file
the situation is the same as at present, by using different .htpasswd one can
discriminate the accesses.  



-- 
Franco Bagnoli
Dipartimento di Matematica Applicata "G. Sansone"
Universita' di Firenze, Via S. Marta, 3 I-50139 Firenze, Italy
tel. +39 0554796422, fax: +39 055471787
e-mail: bagnoli@dma.unifi.it






Maggiori informazioni sulla lista flug-tech