#! /usr/bin/perl -w use strict ; use Repocafe ; my $TEMPL = 'lib/setup.vhost' ; my $prog = substr($0,rindex($0,'/')+1) ; my $Usage = < ---------------------------------------- - $prog - show the suggested repocafe vhost or auth apache config. - $prog generates apache configs from templates ; you may have to tweak them. - The generated configs must be placed in the apache config tree ; the precise locations depend on the distro/apache installation. ---------------------------------------- USAGE sub Usage { die "$_[0]$Usage" ; } sub Error { die "$prog: $_[0]\n" ; } sub Warn { warn "$prog: $_[0]\n" ; } # usage: &GetOptions(ARG,ARG,..) defines $opt_ID as 1 or user spec'ed value # usage: &GetOptions(\%opt,ARG,ARG,..) defines $opt{ID} as 1 or user value # ARG = 'ID' | 'ID=SPC' | 'ID:SPC' for no-arg, required-arg or optional-arg # ID = perl identifier # SPC = i|f|s for integer, fixedpoint real or string argument use Getopt::Long ; Getopt::Long::config('no_ignore_case') ; our %opt = () ; Usage('') unless GetOptions ( \%opt, qw(v q d f c a help) ) ; if ( $opt{help} ) { print $Usage ; exit 0 ; } Usage("Arg count\n") unless @ARGV == 0 ; $TEMPL = 'lib/setup.authconfig' if $opt{a} ; sub trim { my $x = shift ; $x =~ s/[\s;]+$// ; $x =~ s/^\s+// ; $x ; } sub get_tups { my $dbh = shift ; my $sql = shift ; my $tab = shift ; my $key = shift ; my @res = () ; my $sth = $dbh -> prepare ( $sql ) ; $sth -> execute ( @$tab ) ; while ( my $rec = $sth -> fetchrow_hashref ) { push @res, $rec ; } @res ; } sub find_user { my $dbh = shift ; my $user = shift ; my $sql = "SELECT * FROM pg_roles where rolname = ?" ; my @tups = get_tups $dbh, $sql, [ $user ] ; @tups ? $tups [ 0 ] -> { rolname } : '' ; } my $Cafe = make_cafe ( %opt, -conn => 0 ) ; my $conf = $Cafe -> conf ; my $root = $conf -> root ; open TEMPL, $TEMPL ; my @text = ; close TEMPL ; my %pats = ( '%www_server%' => $conf -> www_server , '%www_contact%' => $conf -> www_contact , '%dir_www%' => $conf -> dir_www , '%dir_data%' => $conf -> dir_data , '%file_access%' => $conf -> file_access , '%file_guests%' => $conf -> file_guests ) ; # AuthLDAPURL ldap://ldap.cs.uu.nl:389/dc=cs,dc=uu,dc=nl?uid sub name4tag { my $tag = shift ; "ldap_$tag" ; } my $ldaps = $conf -> ldaps ; my $LDAPS = '' ; my @provs = () ; for my $ldap ( values %$ldaps ) { my $tag = $ldap -> tag ; my $serv = $ldap -> serv ; my $base = $ldap -> base ; my $dn = $ldap -> binddn ; my $pw = $ldap -> bindpw ; my $uid = $ldap -> login ; my $name = name4tag $tag ; my $tdn = "# AuthLDAPBindDN" ; my $tpw = "# AuthLDAPBindPassword" ; $tdn = " AuthLDAPBindDN \"$dn\"" if $dn ; $tpw = " AuthLDAPBindPassword \"$pw\"" if $pw ; push @provs, $name ; $LDAPS .= < AuthLDAPURL ldap://$serv:389/$base?$uid $tdn $tpw LINE } my $PROVS = join ' ', @provs ; my $PWD = `pwd` ; chop $PWD ; print <