aboutsummaryrefslogtreecommitdiffstats
path: root/ldap/obsolete/addadmin.pl
diff options
context:
space:
mode:
Diffstat (limited to 'ldap/obsolete/addadmin.pl')
-rwxr-xr-xldap/obsolete/addadmin.pl51
1 files changed, 51 insertions, 0 deletions
diff --git a/ldap/obsolete/addadmin.pl b/ldap/obsolete/addadmin.pl
new file mode 100755
index 0000000..508d100
--- /dev/null
+++ b/ldap/obsolete/addadmin.pl
@@ -0,0 +1,51 @@
+#!/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();