Alternc  latest
Alternc logiel libre pour l'hébergement
mail_add.php File Reference

Go to the source code of this file.

Functions

 usage ()
 

Variables

global $cuid
 
 $generators = array('pwqgen', 'pwgen')
 
 $dryrun = false
 
 $default_quotas = 1024
 
if(count($argv)< 2) $user = preg_split('/@/', $argv[1])[0]
 
 $domain = preg_split('/@/', $argv[1])[1]
 
 $recipients = array_slice($argv, 2)
 
if($db->next_record()) else
 
foreach($generators as $generator) if(is_null($password)) $quotas = $default_quotas
 
 $r = join(", ", $recipients)
 
 print
 
if($dryrun) print cuid
 

Function Documentation

◆ usage()

usage ( )

Definition at line 29 of file mail_add.php.

29  {
30  global $argv;
31  // putting {$argv[0]} or $argv[0] in the heredoc fails
32  $wtfphp = $argv[0];
33  $u = '
34 Usage: $wtfphp <email> <alias> ...
35 
36 email: full email adress, including domain, which must exist
37 alias: one or many aliases the email should forward to, space separated
38 
39 ';
40  error_log($u);
41  exit(1);
42 }
43 
44 if (count($argv) < 2) {
45  usage();
46 }
47 
48 $user = preg_split('/@/', $argv[1])[0]; // first argument is user@domain
49 $domain = preg_split('/@/', $argv[1])[1];
50 $recipients = array_slice($argv, 2); // rest is recipients
51 
52 // there's no function to do that, oddly enough...
53 // there's one to extract the compte from the mail_id (!) but we
54 // haven't created it yet...
55 $db->query('SELECT id,compte FROM domaines WHERE domaine=?',array($domain));
56 if ($db->next_record()) {
57  $compte = $db->f('compte');
58  $domain_id = $db->f('id');
59 }
60 else {
61  error_log("domain $domain not found");
62  exit(2);
63 }
64 
65 foreach ($generators as $generator) {
66  $password = `$generator 2>/dev/null`;
67  if (!is_null($password) and strlen($password) > 7) {
68  $password = trim($password);
69  break;
70  }
71 }
72 if (is_null($password)) {
73  error_log('password generators failed to produce 8 characters: ' . join("\n", $generators));
74  exit(3);
75 }
76 
77 /* need not to be $quota because that would replace alternc's global
78  * $quota... even though we don't say global $quota anywhere here, yay
79  * php scoping.
80  */
82 $r = join(", ", $recipients);
83 
84 print '
85 user: $user
86 domain: $domain
87 compte: $compte
88 password: $password
89 quota: $default_quotas
90 recipients: $r
91 
92 ';
93 
94 if ($dryrun) {
95  error_log('not creating email because of $dryrun is true');
96  exit(0);
97 }
98 print "cuid: $cuid\n";
99 $mem->su($compte);
100 print "cuid: $cuid\n";
101 
102 /* function signature is:
103  * function create($dom_id, $mail,$type="",$dontcheck=false)
104  * yet $type is never passed anywhere and is actually empty in the
105  * database (!) $dontcheck is undocumented, so we'll ignore it
106  *
107  * also, this function explicitely tells me to not use it, but doesn't
108  * provide an alternative. i choose to disobey instead of rewriting it
109  * from scratch
110  */
111 if (!($mail_id = $mail->create($domain_id, $user))) {
112  error_log('failed to create: ' . $msg->msg_str());
113  exit(4);
114 }
115 
116 /* function set_passwd($mail_id,$pass)
117  *
118  * just set the password
119  *
120  * no idea why this is a different function.
121  */
122 if (!$mail->set_passwd($mail_id,$password)) {
123  error_log("failed to set password on mail $mail_id: " . $msg->msg_str());
124  exit(5);
125 }
126 
127 /* function set_details($mail_id, $islocal, $quotamb,
128  * $recipients,$delivery="dovecot",$dontcheck=false)
129  *
130  * you read that right, recipients is a string (!)
131  *
132  * if we have no aliases, it's a mailbox. deal with it.
133  */
134 if (!$mail->set_details($mail_id, !count($recipients), $quota, join("\n", $recipients))) {
135  error_log('failed to set details: ' . $msg->msg_str());
136  exit(6);
137 }
exit
Definition: adm_doadd.php:70
global $db
Definition: bootstrap.php:26
$mem
Definition: bootstrap.php:71
$msg
Definition: bootstrap.php:75
$recipients
Definition: mail_add.php:50
print
Definition: mail_add.php:92
$r
Definition: mail_add.php:82
if(count($argv)< 2) $user
Definition: mail_add.php:48
$default_quotas
Definition: mail_add.php:24
foreach($generators as $generator) if(is_null($password)) $quotas
Definition: mail_add.php:81
$generators
Definition: mail_add.php:21
$domain
Definition: mail_add.php:49
$dryrun
Definition: mail_add.php:22
usage()
Definition: mail_add.php:29
$mail_id
$password
Definition: bootstrap.php:85

References exit.

Variable Documentation

◆ $cuid

global $cuid

Definition at line 17 of file mail_add.php.

◆ $default_quotas

$default_quotas = 1024

Definition at line 24 of file mail_add.php.

◆ $domain

$domain = preg_split('/@/', $argv[1])[1]

Definition at line 49 of file mail_add.php.

◆ $dryrun

$dryrun = false

Definition at line 22 of file mail_add.php.

◆ $generators

$generators = array('pwqgen', 'pwgen')

Definition at line 21 of file mail_add.php.

◆ $quotas

foreach ( $generators as $generator) if (is_null( $password)) $quotas = $default_quotas

Definition at line 81 of file mail_add.php.

◆ $r

$r = join(", ", $recipients)

Definition at line 82 of file mail_add.php.

◆ $recipients

$recipients = array_slice($argv, 2)

Definition at line 50 of file mail_add.php.

Referenced by m_mail\set_details().

◆ $user

if (count( $argv)< 2) $user ( ) = preg_split('/@/', $argv[1])[0]

Definition at line 48 of file mail_add.php.

◆ cuid

print cuid

Definition at line 98 of file mail_add.php.

Referenced by Alternc_Api_Legacyobject\__construct().

◆ else

if ( $db->next_record()) else
Initial value:
{
error_log("domain $domain not found")

Definition at line 60 of file mail_add.php.

◆ print

print

Definition at line 84 of file mail_add.php.

Referenced by DB_Sql\np(), and DB_Sql\p().