#!/usr/bin/perl # Run `sudo ./addadmin.pl' to add yourself as an administrator for virtual # mail hosting. # (Use the optional argument if you're not happy with your login name.) # # To use the tools, you'll need to edit `~/.fripost.yml' and replace # `bind_dn' and `bind_pw' by, respectively, the returned Distinguished Name # and your password use 5.010_000; use strict; use warnings; use utf8; use FindBin qw($Bin); use lib "$Bin/lib"; use Fripost::Schema; use Fripost::Password; use Fripost::Prompt; use YAML::Syck; my $user = $ARGV[0]; $user //= $ENV{SUDO_USER}; $user //= $ENV{USER}; die "Error: Cannot find user name.\n" unless defined $user; # Connect to the LDAP server my $ldapconf = LoadFile ( 'ldap.yml' ); my $ldap = Fripost::Schema->new( $ldapconf ); $ldap = $ldap->{_ldap}; my $dn = join ',', ( 'cn='.$user , 'ou=managers' , (split ',', $ldapconf->{base_dn},2)[1] ); my $password = hash( undef, undef, prompt_password() ); my $res = $ldap->add( $dn, attrs => [ objectClass => [ 'simpleSecurityObject' , 'organizationalRole' ] , userPassword => $password ] ); die "Error: " .$res->error. "\n" if $res->code; say $dn; $ldap->unbind();