1998-08-29 03:50:39 +04:00
#!/usr/bonsaitools/bin/perl -w
# -*- Mode: perl; indent-tabs-mode: nil -*-
1999-11-02 02:33:56 +03:00
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
1998-08-29 03:50:39 +04:00
# The Original Code is the Despot Account Administration System.
1999-11-02 02:33:56 +03:00
#
1998-08-29 03:50:39 +04:00
# The Initial Developer of the Original Code is Netscape Communications
1999-11-02 02:33:56 +03:00
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
1998-08-29 03:50:39 +04:00
# Contributor(s): Terry Weissman <terry@mozilla.org>
2000-03-08 01:51:08 +03:00
# Dan Mosedale <dmose@mozilla.org>
1998-08-29 03:50:39 +04:00
# $F::debug = 1;
2005-02-25 04:02:47 +03:00
#$cvs = "/opt/cvs-tools/bin/cvs";
#$whoami = "/usr/ucb/whoami";
2003-09-09 07:51:53 +04:00
#$perlbin = "/tools/ns/bin/perl5.004";
2000-03-08 01:51:08 +03:00
2005-02-25 04:02:47 +03:00
$ cvs = "/usr/bin/cvs" ;
$ whoami = "/usr/bin/whoami" ;
2003-09-09 07:51:53 +04:00
$ perlbin = "/usr/bin/perl" ;
2000-03-30 02:15:15 +04:00
#$curdir = `pwd`;
#chop($curdir);
#$ENV{"CVS_PASSFILE"} = "$curdir/.cvspass";
2005-02-25 04:02:47 +03:00
$ ENV { "CVS_RSH" } = "ssh" ;
2000-03-30 02:15:15 +04:00
$ ENV { "CVS_PASSFILE" } = "/usr/local/etc/despot-cvspass" ;
1998-08-29 04:51:15 +04:00
$ dontcommit = 0 ;
1998-08-29 03:50:39 +04:00
$ usertoblame = "" ;
for ( $ i = 0 ; $ i < @ ARGV ; $ i + + ) {
if ( $ ARGV [ $ i ] eq "-n" ) {
$ dontcommit = 1 ;
}
if ( $ ARGV [ $ i ] eq "-user" ) {
$ usertoblame = $ ARGV [ + + $ i ] ;
}
}
$ srcdir = $ 0 ;
$ srcdir =~ s: /[^/ ] * $ :: ; # Remove last word, and slash before it.
if ( $ srcdir eq "" ) {
$ srcdir = "." ;
}
chdir $ srcdir || die "Couldn't chdir to $srcdir" ;
use Mysql ;
require 'utils.pl' ;
2005-03-15 05:58:55 +03:00
$ db = Mysql - > Connect ( "localhost" , "mozusers" , "despot" )
1998-08-29 03:50:39 +04:00
|| die "Can't connect to database server" ;
$ db = $ db ; # Make -w shut up.
2000-03-08 01:51:08 +03:00
( $ mylogin = `$whoami` ) ;
1998-08-29 03:50:39 +04:00
chop ( $ mylogin ) ;
$ hostname = 'unknown' ;
if ( open ( HOST , "/bin/hostname|" ) ) {
$ hostname = <HOST> ;
chop ( $ hostname ) ;
close ( HOST ) ;
}
$ ENV { "HOME" } = glob ( "~$mylogin" ) ; # CVS wants this.
if ( $ usertoblame eq "" ) {
$ usertoblame = $ mylogin ;
}
$ boilerplate = "" ;
open ( BOILERPLATE , "<commitcheck.templ" ) || die "Can't open template file" ;
while ( <BOILERPLATE> ) {
if ( /^#/ ) {
# Strip out comments from the boilerplate. Might as well; the
# faster our generated perl script runs, the better.
next ;
}
$ boilerplate . = $ _ ;
}
close BOILERPLATE ;
1998-12-11 01:42:36 +03:00
open ( BOILERPLATE , "<owners.templ" ) || die "Can't open template file" ;
while ( <BOILERPLATE> ) {
push @ ownersplate , $ _ ;
}
close BOILERPLATE ;
1998-08-29 03:50:39 +04:00
1998-12-11 01:42:36 +03:00
1999-01-13 23:31:36 +03:00
my @ grouplist = ( 'cvs' , 'gila' ) ; # Mailing group list. Should really query
# for this list rom the db ... ###
$ repquery = Query ( "select id,name,cvsroot,ownersrepository,ownerspath,domailing from repositories order by name" ) ;
1998-08-29 03:50:39 +04:00
while ( @ reprow = $ repquery - > fetchrow ( ) ) {
1999-01-13 23:31:36 +03:00
( $ repid , $ repname , $ reproot , $ ownersrepository , $ ownerspath , $ domailing ) =
( @ reprow ) ;
1998-08-29 03:50:39 +04:00
1998-09-22 20:56:39 +04:00
$ query = Query ( "select email,passwd,${repname}_group,neednewpassword,disabled from users where ${repname}_group != 'None' and passwd != '' order by email" ) ;
1998-08-29 03:50:39 +04:00
1999-01-13 23:31:36 +03:00
$ tmpdir = "/tmp/syncit-$repname.$$" ;
1998-08-29 03:50:39 +04:00
mkdir $ tmpdir , 0777 ;
chdir $ tmpdir ;
$ ENV { CVSROOT } = $ reproot ;
1999-01-13 23:31:36 +03:00
my @ filelist = ( 'passwd' , 'commitcheck.pl' ) ;
if ( $ domailing ) {
foreach my $ g ( @ grouplist ) {
push @ filelist , "${g}_list" ;
}
}
system "$cvs co " . join ( ' ' , grep ( s@^@CVSROOT/@ , @ filelist ) )
|| die "Couldn't checkout files." ;
if ( $ domailing ) {
foreach my $ group ( @ grouplist ) {
$ outfile = "CVSROOT/${group}_list" ;
open ( MAILLIST , ">$outfile" ) || die "Can't open $outfile" ;
print MAILLIST "# DO NOT EDIT THIS FILE! This file is created\n" ;
print MAILLIST "# by despot, and is used by /etc/aliases.\n" ;
my $ q = Query ( "select email from users where ${group}_group != 'None' and passwd != '' and disabled != 'Yes' order by email" ) ;
while ( @ r = $ q - > fetchrow ( ) ) {
print MAILLIST $ r [ 0 ] . "\n" ;
}
close MAILLIST ;
}
}
1998-08-29 03:50:39 +04:00
$ outfile = "CVSROOT/passwd" ;
2005-02-25 04:05:12 +03:00
open ( PASSWD , ">$outfile" ) || die "Can't open $outfile: $!" ;
1998-08-29 03:50:39 +04:00
2005-03-14 23:01:26 +03:00
print PASSWD "# DO NOT EDIT THIS FILE! You must instead go to https://despot.mozilla.org/, and\n" ;
1998-08-29 03:50:39 +04:00
print PASSWD "# tweak things from there.\n" ;
while ( @ row = $ query - > fetchrow ( ) ) {
1998-09-22 20:56:39 +04:00
( $ email , $ password , $ group , $ neednew , $ disabled ) = @ row ;
if ( $ neednew eq "Yes" || $ disabled eq "Yes" ) {
1998-08-29 03:50:39 +04:00
next ;
}
$ login = $ email ;
$ login =~ s/@/%/g ;
print PASSWD "$login:$password:$group\n" ;
}
close PASSWD ;
# system "$cvs co CVSROOT/commitcheck.pl" || die "Couldn't checkout passwd file.";
$ outfile = "CVSROOT/commitcheck.pl" ;
open ( COMMITCHECK , ">$outfile" ) || die "Can't open $outfile" ;
2000-03-08 01:51:08 +03:00
print COMMITCHECK "#!$perlbin --\n" ;
2005-03-14 23:01:26 +03:00
print COMMITCHECK "# DO NOT EDIT THIS FILE! You must instead go to https://despot.mozilla.org/, and\n" ;
1998-08-29 03:50:39 +04:00
print COMMITCHECK "# tweak things from there.\n\n" ;
$ query = Query ( "select partitions.id,partitions.name,state,branches.name from partitions,branches where repositoryid = '$repid' and branches.id=branchid order by partitions.name" ) ;
1998-09-04 04:13:17 +04:00
$ founddefault = 0 ;
1998-08-29 03:50:39 +04:00
while ( @ row = $ query - > fetchrow ( ) ) {
( $ id , $ name , $ state , $ branch ) = ( @ row ) ;
$ d = "\$" ;
print COMMITCHECK $ d . "mode{'$id'} = '$state';\n" ;
print COMMITCHECK $ d . "branch{'$id'} = '$branch';\n" ;
print COMMITCHECK $ d . "fullname{'$id'} = '$name';\n" ;
1998-09-04 04:13:17 +04:00
if ( $ name eq 'default' ) {
print COMMITCHECK $ d . "defaultid = '$id';\n" ;
$ founddefault = 1 ;
}
1998-08-29 03:50:39 +04:00
if ( $ state ne "Open" ) {
foreach $ n ( "blessed" , "super" ) {
print COMMITCHECK $ d . "$n" . "{'$id'} = [" ;
$ eq = "=" ;
if ( $ n eq "super" ) {
$ eq = "!=" ;
}
$ q2 = Query ( "select email from members,users where partitionid = $id and class $eq 'Member' and users.id = userid" ) ;
while ( @ r2 = $ q2 - > fetchrow ( ) ) {
my $ n = $ r2 [ 0 ] ;
$ n =~ s/@/%/ ;
print COMMITCHECK "'$n'," ;
}
print COMMITCHECK "];\n" ;
}
}
}
1998-09-04 04:13:17 +04:00
if ( ! $ founddefault ) {
print COMMITCHECK $ d . "defaultid = 'none';\n" ;
}
1998-08-29 03:50:39 +04:00
print COMMITCHECK "sub GetT {\n" ;
print COMMITCHECK '($b,$_) = (@_);' . "\n" ;
1998-10-05 21:27:44 +04:00
$ query = Query ( "select branches.name,partitions.id from partitions,branches where repositoryid = '$repid' and branches.id = branchid order by branches.name" ) ;
1998-08-29 03:50:39 +04:00
$ lastbranch = "" ;
while ( @ row = $ query - > fetchrow ( ) ) {
( $ branchname , $ partid ) = ( @ row ) ;
if ( $ branchname ne $ lastbranch ) {
if ( $ lastbranch ne "" ) {
print COMMITCHECK "}\n" ;
}
print COMMITCHECK "if (" . $ d . "b eq '$branchname') {\n" ;
$ lastbranch = $ branchname ;
}
$ q2 = Query ( "select pattern from files where partitionid=$partid order by pattern" ) ;
while ( @ r2 = $ q2 - > fetchrow ( ) ) {
my $ regexp = $ r2 [ 0 ] ;
$ regexp =~ s/\./\\./g ;
$ regexp =~ s: \ * $ : . * : ;
$ regexp =~ s: \ %$ : [ ^ / ] * : ;
1998-12-11 01:42:36 +03:00
$ regexp = '^' . $ regexp . "\$" ;
1998-08-29 03:50:39 +04:00
print COMMITCHECK "if (m:$regexp:) {return '$partid';}\n" ;
}
}
if ( $ lastbranch ne "" ) {
print COMMITCHECK "}\n" ;
}
print COMMITCHECK "return '';\n" ;
print COMMITCHECK "}\n" ;
print COMMITCHECK $ boilerplate ;
close COMMITCHECK ;
chdir "CVSROOT" ;
if ( $ dontcommit ) {
1998-08-29 04:20:10 +04:00
system "$cvs diff -c passwd" ;
system "$cvs diff -c commitcheck.pl" ;
2000-03-08 01:51:08 +03:00
# system "$cvs -q commit -m 'Pseudo-automatic update of changes made by $usertoblame.' commitcheck.pl";
1998-08-29 03:50:39 +04:00
} else {
2000-03-08 01:51:08 +03:00
system ( "$cvs -q commit -m 'Pseudo-automatic update of changes" .
" made by $usertoblame.'" ) == 0
or die "cvs commit failed" ;
1998-08-29 03:50:39 +04:00
}
1998-12-11 01:42:36 +03:00
if ( defined $ ownersrepository && $ ownersrepository > 0 &&
defined $ ownerspath && $ ownerspath ne "" ) {
$ query = Query ( "select cvsroot from repositories where id = $ownersrepository" ) ;
$ ENV { CVSROOT } = ( $ query - > fetchrow ( ) ) [ 0 ] ;
$ tdir = "$tmpdir/ownerstuff" ;
mkdir $ tdir , 0777 ;
chdir $ tdir ;
system "$cvs co $ownerspath" || die "Couldn't checkout $ownerspath" ;
open ( OWNERS , ">$ownerspath" ) || die "Can't open $ownerspath" ;
print OWNERS "<!-- THIS FILE IS AUTOMATICALLY GENERATED; DO NOT EDIT. -->\n" ;
foreach ( @ ownersplate ) {
if ( $ _ !~ m/^%%DATA%%/ ) {
print OWNERS $ _ ;
next ;
}
$ query = Query ( "select id,name,description,newsgroups,doclinks from partitions where repositoryid = '$repid' order by name" ) ;
while ( @ row = $ query - > fetchrow ( ) ) {
( $ id , $ name , $ desc , $ newsgroups , $ doclinks ) = ( @ row ) ;
1998-12-16 00:44:16 +03:00
if ( $ name eq "default" || $ name eq "despotaccess" ) {
1998-12-11 01:42:36 +03:00
next ;
}
my $ fullname = $ name ;
if ( defined $ desc && $ desc ne "" ) {
$ fullname . = " ($desc)" ;
}
2005-03-14 23:01:26 +03:00
my $ anchor_name = name_to_id_token ( $ name ) ;
1998-12-11 01:42:36 +03:00
$ q2 = Query ( "select class,email,realname from members,users where partitionid = $id and class != 'Member' and users.id = userid" ) ;
my @ owners ;
my @ ownernames ;
my @ peers ;
my @ peernames ;
while ( @ r2 = $ q2 - > fetchrow ( ) ) {
if ( $ r2 [ 0 ] eq "Owner" ) {
push @ owners , $ r2 [ 1 ] ;
push @ ownernames , $ r2 [ 2 ] ;
} else {
push @ peers , $ r2 [ 1 ] ;
push @ peernames , $ r2 [ 2 ] ;
}
}
my $ maillist = "mailto:" . join ( ',' , @ owners ) ;
if ( @ peers > 0 ) {
$ maillist . = "?cc=" . join ( ',' , @ peers ) ;
}
2005-03-14 23:01:26 +03:00
$ maillist =~ s/\@/@/g ;
print OWNERS qq | < a name = "$anchor_name" > </a>
< table class = "data" style = "width:100%" >
<thead>
<tr>
< th style = "width:15%; text-align:right; vertical-align:top" >
Module:
</th>
< th style = "text-align:left" >
$ fullname
</th>
</tr>
</thead>
<tbody>
<tr>
<th> Owner: </th>
2005-03-18 02:23:13 +03:00
<td>
< a href = "$maillist" >
| . join ( ",\n " , @ ownernames ) . qq |
</a>
</td>
2005-03-14 23:01:26 +03:00
</tr>
<tr>
<th> Source: </th>
<td> | ;
1998-12-11 01:42:36 +03:00
$ q2 = Query ( "select pattern from files where partitionid=$id order by pattern" ) ;
my @ filelist ;
while ( @ r2 = $ q2 - > fetchrow ( ) ) {
my $ name = $ r2 [ 0 ] ;
$ name =~ s/\*$// ;
$ name =~ s/%$// ;
$ name =~ s: / $ :: ;
$ name =~ s: ^ mozilla / :: ;
2005-03-14 23:01:26 +03:00
push @ filelist , qq|<a href="http://lxr.mozilla.org/mozilla/source/$name">$name</a>| ;
1998-12-11 01:42:36 +03:00
}
print OWNERS join ( ', ' , @ filelist ) ;
2005-03-14 23:01:26 +03:00
print OWNERS qq | </td>
</tr>
<tr>
<th> Newsgroup: </th>
<td> | ;
1998-12-11 01:42:36 +03:00
my @ grouplist ;
if ( ! defined $ newsgroups ) {
$ newsgroups = "" ;
}
2004-04-22 08:21:43 +04:00
foreach $ i ( split ( /[,\s]+/ , $ newsgroups ) ) {
1998-12-11 01:42:36 +03:00
my $ base = "news:" ;
if ( $ i =~ /^netscape\.public/ ) {
2005-03-14 23:01:26 +03:00
$ base = "nntp://news.mozilla.org/" ;
1998-12-11 01:42:36 +03:00
}
2005-03-14 23:01:26 +03:00
push @ grouplist , qq|<a href="$base$i">$i</a>| ;
1998-12-11 01:42:36 +03:00
}
print OWNERS join ( ', ' , @ grouplist ) ;
2005-03-14 23:01:26 +03:00
print OWNERS qq | </td>
</tr>
<tr>
<th> Peers: </th>
2005-03-18 02:23:13 +03:00
<td>
| ;
1998-12-11 01:42:36 +03:00
my @ peerlist ;
foreach $ i ( @ peers ) {
2005-03-14 23:01:26 +03:00
$ i =~ s/\@/@/g ;
push @ peerlist , qq|<a href="mailto:$i">| . shift ( @ peernames ) . "</a>" ;
1998-12-11 01:42:36 +03:00
}
2005-03-18 02:23:13 +03:00
print OWNERS join ( ",\n " , @ peerlist ) ;
print OWNERS qq |
</td>
2005-03-14 23:01:26 +03:00
</tr>
<tr>
<th> Documents: </th>
<td> | ;
1998-12-11 01:42:36 +03:00
my @ doclist ;
if ( ! defined $ doclinks ) {
$ doclinks = "" ;
}
2004-04-22 08:21:43 +04:00
foreach $ i ( split ( /[,\s]+/ , $ doclinks ) ) {
2005-03-14 23:01:26 +03:00
push @ doclist , qq|<a href="$i">$i</a>| ;
1998-12-11 01:42:36 +03:00
}
print OWNERS join ( ', ' , @ doclist ) ;
2005-03-14 23:01:26 +03:00
print OWNERS qq | </td>
</tr>
</tbody>
</table>
1998-12-11 01:42:36 +03:00
2005-03-14 23:01:26 +03:00
| ;
1998-12-11 01:42:36 +03:00
}
}
close OWNERS ;
2005-02-25 07:15:14 +03:00
if ( $ dontcommit ) {
system "$cvs diff -c" ;
} else {
system ( "$cvs -q commit -m 'Pseudo-automatic update of changes" .
" made by $usertoblame.'" ) == 0
or die "cvs commit failed" ;
}
1998-12-11 01:42:36 +03:00
}
1998-08-29 03:50:39 +04:00
chdir "/" ;
1999-01-13 23:33:03 +03:00
system "rm -rf $tmpdir" ;
1999-01-13 23:31:36 +03:00
1998-08-29 03:50:39 +04:00
}
Query ( "delete from syncneeded" ) ;