File: convert-passwd-to-postfixadmin.pl

package info (click to toggle)
postfixadmin 4.0.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,888 kB
  • sloc: php: 12,256; perl: 1,156; sh: 717; python: 142; xml: 63; sql: 3; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 1,341 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/perl -w
#
# Postfix Admin 
# 
# LICENSE 
# This source file is subject to the GPL license that is bundled with  
# this package in the file LICENSE.TXT. 
# 
# Further details on the project are available at https://github.com/postfixadmin/postfixadmin
# 
# @version $Id$ 
# @license GNU GPL v2 or later. 
#
#
# Really crude attempt at taking all users from a local 
# passwd file (/etc/shadow) and creating postfixadmin mailboxes for them.
#
# The script outputs some SQL, which you need to then insert into your database
# as appropriate.
#
# Notes:
#  1) Change $mydomain and $true as required.
#  2) Ideally it should parse /etc/passwd, or call the getpw()? function and
#     populate someone's name if known.
#  3) There's plenty of room for improvement.
#
# Original author: David Goodwin <david at palepurple-co-uk> - 2007/10/05.
#
use strict;

open(FH, '</etc/shadow') or die ('Cannot open shadow file; you need to be root - ' . $!);
my $mydomain = "test.com";
my $true = "t"; # t for pgsql; 1 for mysql
foreach(<FH>) { 
    my ($username, $password) = split(':', $_);
    next if $password eq '!';
    next if $password eq '*';
    my $maildir = "$username\@$mydomain/";
    print "insert into mailbox (username, password, domain, active, maildir) values ('$username', '$password', '$mydomain', $true, '$maildir');\n";
}