# # Simple user management CGI. # # This allows one to manage a set of per-user parameters that one might be interested # in. Currently we support: # # accept_assignments True if we accept assignments from this user on p2p transfers. # Defaults to true for users that aren't one of the # pseudo-users billogix, automated_assignment(s), master, fix, # last_release # use strict; use UserDB; use FIG; use HTML; use CGI; my @pseudo_users = qw(billogix automated_assignment automated_assignments master fix last_release); my %pseudo_users; map { $pseudo_users{$_}++; } @pseudo_users; my $fig = new FIG; my $cgi = new CGI; my $udb = new UserDB($fig); my @html; push(@html, $cgi->title("SEED User Management"), $cgi->h1("SEED User Management")); # # If we're coming in thru a submit button being pressed, need to scan thru # the old_values and compare to the checked state. # if ($cgi->param('submit')) { my $need_write; for my $param ($cgi->param) { if ($param =~ /^aa_old_(\S+)/) { my $user = $1; my $form_aa = $cgi->param("aa_$user") ? 1 : 0; my $old_aa = $cgi->param($param); my $udb_aa = $udb->get_user_param($user, 'accept_assignments'); if ($old_aa != $form_aa) { $udb->set_user_param($user, 'accept_assignments', $form_aa); $need_write++; } } } $udb->write() if $need_write; } push(@html, $cgi->start_form(-action => 'users.cgi')); build_user_table($fig, $cgi, \@html); push(@html, $cgi->submit(-name => "submit", -value => 'Submit')); push(@html, $cgi->end_form); &HTML::show_page($cgi, \@html); exit; sub build_user_table { my($fig, $cgi, $html) = @_; my $need_write; my(@rows); for my $user (sort $udb->get_users()) { my $aa = $udb->get_user_param($user, 'accept_assignments'); my $aa_cb_name = "aa_$user"; my $aa_oldval_name = "aa_old_$user"; # # If we've not set a value for aa yet, default it to on unless user is a pseudo-user. # if (!defined($aa)) { warn "setting a default\n"; $aa = defined($pseudo_users{$user}) ? 0 : 1; $udb->set_user_param($user, 'accept_assignments', $aa); $need_write++; } my $aa_checkbox = $cgi->checkbox(-name => "aa_$user", -checked => $aa, -override => 1, -label => ''); push(@rows, [$user, "\@align=center:$aa_checkbox"]); push(@$html, $cgi->hidden(-name => $aa_oldval_name, -value => $aa)); } # # If we set any defaults, write the user db. # $udb->write() if $need_write; push(@$html, HTML::make_table(["User", "Assignments accepted"], \@rows)); }