submit("View info about your account") .end_form()));
push(@list, li(MyForm("ChangePassword") .
submit("Change your password") . end_form()));
push(@list, li(MyForm("ListPartitions") .
submit("List all the partitions") .end_form()));
# my $query = Query("select partitionid,partitions.name,repositories.name,repositories.id from members,partitions,repositories where userid=$loginid and class != 'Member' and partitions.id=members.partitionid and repositories.id=partitions.repositoryid");
# my @row;
# while (@row = $query->fetchrow()) {
# my ($partid,$partname,$repname,$repid) = (@row);
# my $title = "Edit partition '$partname' ($repname)";
print "<font color=red>Your account has been frozen. To make it usable, you must change your password.</font>";
}
$skiptrailer = 1;
}
sub AddUser() {
EnsureDespot();
if ($F::email eq "") {
Punt("You must enter an email address.");
}
my $email = $F::email;
my $query;
my @row;
if ($email !~ /^[^@, ]*@[^@, ]*\.[^@, ]*$/) {
Punt("Email addresses must contain exactly one '\@', and at least one '.' after the \@, and may not contain any commas or spaces.");
}
my $q = SqlQuote($email);
$query = Query("select count(*) from users where email='$q'");
@row = $query->fetchrow();
if ($row[0] < 1) {
my $p = "";
my $realname = "";
my $plain = pickrandompassword();
$p = cryptit($plain);
$feedback = "'" . tt($plain) . "'";
$mailwords = "of '$plain'";
$realname = "";
$p = $db->quote($p);
$realname = $db->quote($realname);
Query("insert into users (email,passwd,neednewpassword,realname) values ('$q',$p,'Yes',$realname)");
print p("New account created. Password initialized to $feedback; " .
"please " .
a({href=>"mailto:$email?subject=Change your mozilla.org password&body=Your new mozilla.org account has been created. It initially has a%0apassword $mailwords. Please go to http://cvs-mirror.mozilla.org/webtools/despot/despot.cgi%0aand change your password as soon as possible. You won't actually be%0aable to use it for anything until you do."},
"send mail") .
" and have the user change the password!");
print hr();
}
EditUser();
}
sub EditUser() {
EnsureDespot();
print h1("Edit a user");
my $q = SqlQuote($F::email);
my $query = Query("select * from users where email='$q'");
my @row;
@row = $query->fetchrow();
my $query2 = Query("show columns from users");
my @list;
my @desc;
for (my $i=0 ; $i<@row ; $i++) {
@desc = $query2->fetchrow();
my $line = th({-align=>"right"}, "$desc[0]:" .
hidden("orig_$desc[0]", $row[$i]));
if ($desc[0] ne ($query->name)[$i]) {
die "show columns in different order than select???";
$qstr = "update users set " . join(",", @list) . " where email='" .
SqlQuote($F::orig_email) . "'";
Query($qstr);
print h1("OK, record for $F::email has been updated.");
print hr();
MainMenu();
Query("insert into syncneeded (needed) values (1)");
}
sub GeneratePassword {
my $email = $F::email;
my $plain = pickrandompassword();
my $p = cryptit($plain);
Query("update users set passwd = " . $db->quote($p) . ", neednewpassword='Yes' where email=" .
$db->quote($email));
print h1("OK, new password generated.");
print "$email now has a new password of '" . tt($plain) . "'. ";
print "Please " .
a({href=>"mailto:$email?subject=Change your mozilla.org password&body=Your mozilla.org account now has a password of '$plain'. Please go to%0ahttp://cvs-mirror.mozilla.org/webtools/despot/despot.cgi and change your password as soon as%0apossible. You won't actually be able to use your mozilla.org account%0afor anything until you do."},
"send mail") .
" to have the user change the password!";
Query("insert into syncneeded (needed) values (1)");
}
sub ListPartitions () {
print p("If you're wondering what a 'partition' is, " .
my $query = Query("select * from users where email='$F::loginname'");
my @row;
@row = $query->fetchrow();
my $query2 = Query("show columns from users");
my @list;
my @desc;
my $userid;
for (my $i=0 ; $i<@row ; $i++) {
@desc = $query2->fetchrow();
my $line = th({-align=>"right"}, "$desc[0]:");
if ($desc[0] ne ($query->name)[$i]) {
die "show columns in different order than select???";
}
$_ = $desc[1];
$line .= td($row[$i]);
push(@list,Tr($line));
}
print table(@list);
$query = Query("select partitions.id,repositories.name,partitions.name,class from members,repositories,partitions where members.userid=$loginid and partitions.id=members.partitionid and repositories.id=partitions.repositoryid order by class");
my $query = Query("select partitions.name,partitions.description,state,repositories.name,repositories.id,branches.name from partitions,repositories,branches where partitions.id = $partitionid and repositories.id = repositoryid and branches.id = branchid");
@row = $query->fetchrow();
my ($partname,$partdesc,$state,$repname,$repid,$branchname) = (@row);
$query = Query("select pattern from files where partitionid=$partitionid order by pattern");
push(@list, CreateListRow("files", $query));
foreach my $class ("Owner", "Peer", "Member") {
$query = Query("select users.email from members,users where members.partitionid = $partitionid and members.class = '$class' and users.id = members.userid order by users.email");
$query = Query("select files.pattern,partitions.name from files,partitions where files.partitionid != $F::partitionid and partitions.id=files.partitionid and partitions.repositoryid=$F::repid");
while (@row = $query->fetchrow()) {
my $f1 = $row[0];
foreach my $f2 (@files) {
$f2 = trim($f2);
if ($f2 eq "") {
next;
}
if (FileMatches($f1, $f2) || FileMatches($f2, $f1)) {
Punt("File rule $f2 overlaps with existing rule in partition $row[1]");
}
}
}
my %idhash;
foreach my $class ("Owner", "Peer", "Member") {
my @names = split(/\n/, param($class));
foreach my $n (@names) {
$n = trim($n);
if ($n eq "") {
next;
}
$query = Query("select id,${F::repname}_group from users where email = " . $db->quote($n));
if (!(@row = $query->fetchrow())) {
Punt("$n is not an email address in the database.");
}
my ($userid,$group) = (@row);
if (exists $idhash{$n}) {
Punt("$n seems to be mentioned more than once. A given user can only have one class.");
}
$idhash{$n} = $userid;
if ($group eq "None") {
Punt("$n is not allowed to use the $F::repname repository at all, so it doesn't make sense to put this user into this partition.");
}
}
}
# And now actually update things.
$query = Query("select id from branches where name = " .
$db->quote($F::branchname));
if (!(@row = $query->fetchrow())) {
Query("insert into branches (name) values (" .
$db->quote($F::branchname) . ")");
$query = Query("select LAST_INSERT_ID()");
@row = $query->fetchrow();
}
my $branchid = $row[0];
Query("update partitions set description=" . $db->quote($F::description) . ", branchid=$branchid, state='$F::state' where id=$F::partitionid");
Query("delete from files where partitionid=$F::partitionid");
foreach my $f2 (@files) {
$f2 = trim($f2);
if ($f2 eq "") {
next;
}
Query("insert into files (partitionid,pattern) values ($F::partitionid," . $db->quote($f2) . ")");
}
Query("delete from members where partitionid=$F::partitionid");
foreach my $class ("Owner", "Peer", "Member") {
my @names = split(/\n/, param($class));
foreach my $n (@names) {
$n = trim($n);
if ($n eq "") {
next;
}
Query("insert into members(userid,partitionid,class) values ($idhash{$n},$F::partitionid,'$class')");
}
}
print h1("OK, the partition has been updated.");
print hr();
Query("unlock tables");
MainMenu();
Query("insert into syncneeded (needed) values (1)");
}
sub DeletePartition() {
EnsureCanChangePartition($F::partitionid);
Query("delete from partitions where id = '$F::partitionid'");
Query("delete from files where partitionid = '$F::partitionid'");
Query("delete from members where partitionid = '$F::partitionid'");
Query("insert into syncneeded (needed) values (1)");