| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # -*- perl -*- | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | # | 
| 4 |  |  |  |  |  |  | # $Id: Htgroup.pm,v 1.5 2004/04/02 10:32:50 eserte Exp $ | 
| 5 |  |  |  |  |  |  | # Author: Slaven Rezic | 
| 6 |  |  |  |  |  |  | # | 
| 7 |  |  |  |  |  |  | # Copyright (C) 2002 Online Office Berlin. All rights reserved. | 
| 8 |  |  |  |  |  |  | # Copyright (C) 2002 Slaven Rezic. | 
| 9 |  |  |  |  |  |  | # This is free software; you can redistribute it and/or modify it under the | 
| 10 |  |  |  |  |  |  | # terms of the GNU General Public License, see the file COPYING. | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | # | 
| 13 |  |  |  |  |  |  | # Mail: slaven@rezic.de | 
| 14 |  |  |  |  |  |  | # WWW:  http://we-framework.sourceforge.net | 
| 15 |  |  |  |  |  |  | # | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | package WE::Util::Htgroup; | 
| 18 |  |  |  |  |  |  |  | 
| 19 | 1 |  |  | 1 |  | 1266 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 25 |  | 
| 20 | 1 |  |  | 1 |  | 5 | use vars qw($VERSION); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 252 |  | 
| 21 |  |  |  |  |  |  | $VERSION = sprintf("%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/); | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | =head1 NAME | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | WE::Util::Htgroup - create apache AuthGroupFile files from a user database | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | use WE::Util::Htgroup; | 
| 30 |  |  |  |  |  |  | WE::Util::Htgroup::create("/var/www/.group", $complex_user_db); | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | Create apache AuthGroupFile files from a WE_Framework user database. | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | =head2 FUNCTIONS | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | =over 4 | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | =item create($dest_file, $user_db, %args); | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | Create the C<$dest_file> from the (complex) user database object | 
| 43 |  |  |  |  |  |  | C<$user_db>. | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | =cut | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | sub create { | 
| 48 | 0 |  |  | 0 | 1 |  | my($dest_file, $user_db, %args) = @_; | 
| 49 | 0 |  |  |  |  |  | my %groups; | 
| 50 | 0 |  |  |  |  |  | foreach my $uid ($user_db->get_all_users) { | 
| 51 | 0 |  |  |  |  |  | my(@groups) = $user_db->get_groups($uid); | 
| 52 | 0 |  |  |  |  |  | foreach my $group (@groups) { | 
| 53 | 0 |  |  |  |  |  | push @{ $groups{$group} }, $uid; | 
|  | 0 |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  | } | 
| 56 | 0 | 0 |  |  |  |  | open(GROUP, ">$dest_file") or die "Can't write to $dest_file: $!"; | 
| 57 | 0 |  |  |  |  |  | while(my($group, $members) = each %groups) { | 
| 58 | 0 |  |  |  |  |  | print GROUP "$group: " . join(" ", @$members) . "\n"; | 
| 59 |  |  |  |  |  |  | } | 
| 60 | 0 |  |  |  |  |  | close GROUP; | 
| 61 | 0 |  |  |  |  |  | 1; | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | =item invalid_chars | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | Return a string of invalid characters for group names. This is handy | 
| 67 |  |  |  |  |  |  | for using in C: | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | new WE::DB::ComplexUser(..., ..., | 
| 70 |  |  |  |  |  |  | -crypt => "none", | 
| 71 |  |  |  |  |  |  | -invalidchars => WE::Util::Htpasswd::invalid_chars(), | 
| 72 |  |  |  |  |  |  | -invalidgroupchars => WE::Util::Htgroup::invalid_chars()) | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | =cut | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | sub invalid_chars { | 
| 77 | 0 |  |  | 0 | 1 |  | ": "; | 
| 78 |  |  |  |  |  |  | } | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | 1; | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | __END__ |