This repository has been archived by the owner on Aug 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuser_bulk_create
executable file
·72 lines (66 loc) · 1.9 KB
/
user_bulk_create
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/env php
<?php
/**
* \brief This script utilizes the OMA class
* to provide the ability of creating users on command line.
*
* @example user_bulk_create < ./file_with_users
* The file_with_users contains usernames to be created,
* with one username per line
*
* @author W-Mark Kubacki; [email protected]
*/
$creator_mbox = 'admin';
$creator_passwd = 'geheim';
$server_no = 0; // you can leave it at that
$verbose = true; // display information (including passwords) and errors?
$new_user_ops = array( // see inc/lib/openmailadmin.php::mailbox_create
'pate' => $creator_mbox,
'canonical' => '@example.com', // mailbox name will be prepended
'domains' => 'example.com', // or domain key
'max_alias' => 10,
'max_regexp' => 0,
'quota' => 100, // in MiB
);
//////////////////////////////////////////////////////////////////////////////////
// don't change anything below
//////////////////////////////////////////////////////////////////////////////////
include('./inc/_script.php');
if($fp = fopen('php://stdin', 'r')) {
$users_created = array();
while(!feof($fp)) {
$line = fgets($fp, 1024);
$usr = trim($line);
if($usr != '') {
$w = $new_user_ops;
$w['mbox'] = $usr;
$w['person'] = $usr.' (bulk created)';
$w['canonical'] = $usr.$w['canonical'];
echo("Creating mailbox for '".$usr."'... ");
try {
if($oma->mailbox_create($usr, $w)) {
$users_created[] = $usr;
echo("OK\n");
} else {
throw new Exception('mailbox_create returned false');
}
} catch (Exception $e) {
if($verbose) {
echo("failed: \n".$e->getMessage()."\n");
} else {
echo("failed\n");
}
}
if($verbose) {
echo($ErrorHandler->errors_get());
echo($ErrorHandler->info_get());
$ErrorHandler->status_reset();
}
}
}
fclose($fp);
// activate users which have been created successfully
$oma->mailbox_toggle_active($users_created);
}
echo("--\n");
?>