5 use FS::UID qw(adminsuidsetup);
8 use FS::Record qw(qsearchs qsearch);
11 use FS::access_usergroup;
13 use FS::access_groupagent;
16 $FS::CurrentUser::upgrade_hack = 1;
17 my $user = shift or die &usage;
20 my $supergroup = qsearchs('access_group', { 'groupname' => 'Superuser' } );
21 unless ( $supergroup ) {
23 $supergroup = new FS::access_group { 'groupname' => 'Superuser' };
24 my $error = $supergroup->insert;
27 foreach my $rightname ( FS::AccessRight->default_superuser_rights ) {
28 my $access_right = new FS::access_right {
29 'righttype' => 'FS::access_group',
30 'rightobjnum' => $supergroup->groupnum,
31 'rightname' => $rightname,
33 my $ar_error = $access_right->insert;
34 die $ar_error if $ar_error;
37 foreach my $agent ( qsearch('agent', {} ) ) {
38 my $access_groupagent = new FS::access_groupagent {
39 'groupnum' => $supergroup->groupnum,
40 'agentnum' => $agent->agentnum,
42 my $aga_error = $access_groupagent->insert;
43 die $aga_error if $aga_error;
47 my $supergroupnum = $supergroup->groupnum;
49 my $conf = new FS::Conf;
50 my $dir = $conf->base_dir;
51 my $mapsecrets = "$dir/mapsecrets";
52 open(MAPSECRETS, "<$mapsecrets") or die "Can't open $mapsecrets: $!";
53 while (<MAPSECRETS>) {
54 /([\w]+)\s+secrets\s*$/ or die "unparsable line in mapsecrets: $_";
57 next if qsearchs('access_user', { 'username' => $username } );
59 my $access_user = new FS::access_user {
60 'username' => $username,
61 '_password' => 'notyet',
65 my $au_error = $access_user->insert;
66 die $au_error if $au_error;
68 my $access_usergroup = new FS::access_usergroup {
69 'usernum' => $access_user->usernum,
70 'groupnum' => $supergroupnum,
72 my $aug_error = $access_usergroup->insert;
73 die $aug_error if $aug_error;
78 # okay to clobber mapsecrets now i guess
79 cp $mapsecrets, "$mapsecrets.bak$$";
80 open(MAPSECRETS, ">$mapsecrets") or die $!;
81 print MAPSECRETS '* secrets'. "\n";
82 close MAPSECRETS or die $!;
85 die "Usage:\n mapsecrets2access_user user\n";