Commit ecd1989c authored by flo's avatar flo
Browse files

Update to ispconfig-3.2.4

- change sql query from string to array
- update template
- update password hashing
- give more espressive name

	modified:   mailbox_import_from_csv/README
	modified:   mailbox_import_from_csv/mailbox_import.htm
	modified:   mailbox_import_from_csv/mailbox_import.menu.php
	modified:   mailbox_import_from_csv/mailbox_import.php
parent 06032f89
......@@ -2,7 +2,7 @@
Author: Till Brehm, ISPConfig UG
https://git.ispconfig.org/u/tbrehm
ISPConfig version: 3.0.5
ISPConfig version: 3.2.4
This addon is a CSV style importer for Email accounts. It creates mailboxes based
on an account list in CSV format. Email domains get added automatically when they
......
<h2><tmpl_var name="list_head_txt"></h2>
<p><tmpl_var name="list_desc_txt"></p>
<div class="panel panel_language_import">
<div class='page-header'>
<h1>Mailbox Import from CSV</h1>
</div>
<div class="panel panel_language_import" style="padding:20px;">
<div class="pnl_formsarea">
<fieldset class="inlineLabels"><legend>Mailbox Import</legend>
<div class="ctrlHolder">
<label for="lng_select">Mailbox list file</label>
<input name="file" id="file" size="30" type="file" class="fileUpload" />
<div class="form-group">
<label for="file" class="col-sm-3 control-label">Mailbox list file</label>
<input name="file" id="file" size="30" type="file" class="fileUpload col-sm-9" />
</div>
<div class="form-group">
<label for="groupid" class="col-sm-3 control-label">Client</label>
<div class="col-sm-9">
<select name="groupid" id="groupid" class="form-control">{tmpl_var name='clientlist'}</select>
</div>
<div class="ctrlHolder">
<p class="label">Client</p>
<div class="multiField">
<select name="groupid">{tmpl_var name='clientlist'}</select>
</div>
</div>
<div class="ctrlHolder">
<p class="label">Test only</p>
<div class="multiField">
<input id="test" type="checkbox" value="1" name="test" checked/> (run a test without creating the accounts)
</div>
</div>
</fieldset>
<tmpl_if name="has_emails">
<div id="OKMsg">
<table style="width:100%">
<tr>
<td style="background-color:#cccccc">Name</td>
<td style="background-color:#cccccc">Email</td>
<td style="background-color:#cccccc">Password</td>
<td style="background-color:#cccccc">Quota</td>
<td style="background-color:#cccccc">Status</td>
</div>
<div class="form-group">
<label for="test" class="col-sm-3 control-label">Test only</label>
<div class="multiField col-sm-9">
<input id="test" type="checkbox" value="1" name="test" checked/> (run a test without creating the accounts)
</div>
</div>
<tmpl_if name="has_emails">
<div id="OKMsg">
<table style="width:100%">
<tr>
<td style="background-color:#cccccc">Name</td>
<td style="background-color:#cccccc">Email</td>
<td style="background-color:#cccccc">Password</td>
<td style="background-color:#cccccc">Quota</td>
<td style="background-color:#cccccc">Status</td>
</tr>
<tmpl_loop name="email_list">
<tr>
<td><tmpl_var name="name"></td>
<td><tmpl_var name="email"></td>
<td><tmpl_var name="password"></td>
<td><tmpl_var name="quota"> MB</td>
<td><tmpl_var name="status"></td>
</tr>
</tmpl_loop>
</table>
</div>
</tmpl_if>
<tr>
<td><tmpl_var name="name"></td>
<td><tmpl_var name="email"></td>
<td><tmpl_var name="password"></td>
<td><tmpl_var name="quota"> MB</td>
<td><tmpl_var name="status"></td>
</tr>
</tmpl_loop>
</table>
</div>
</tmpl_if>
<input type="hidden" name="id" value="{tmpl_var name='id'}">
<div class="buttonHolder buttons">
<button class="positive iconstxt icoPositive" type="button" value="Import" onClick="submitUploadForm('pageForm','tools/mailbox_import.php');"><span>Import</span></button>
<button class="negative iconstxt icoNegative" type="button" value="Cancel" onClick="loadContent('tools/index.php');"><span>Cancel</span></button>
<button class="btn btn-default formbutton-success" type="button" value="Import" data-submit-form="pageForm" data-form-action="tools/mailbox_import.php" data-form-upload="true">Import</button>
<button class="btn btn-default formbutton-default" type="button" value="Cancel" data-load-content="tools/index.php">Cancel</button>
</div>
</div>
......
......@@ -5,18 +5,18 @@
if($app->auth->is_admin()) {
$items = array();
$items = array();
$items[] = array( 'title' => 'Mailbox import',
'target' => 'content',
'link' => 'tools/mailbox_import.php');
$items[] = array( 'title' => 'Mailbox import from CSV',
'target' => 'content',
'link' => 'tools/mailbox_import.php');
$module['nav'][] = array( 'title' => 'Import',
'open' => 1,
'items' => $items);
$module['nav'][] = array( 'title' => 'Import',
'open' => 1,
'items' => $items);
unset($items);
unset($items);
}
?>
\ No newline at end of file
?>
......@@ -54,9 +54,10 @@ if(isset($_FILES['file']['name']) && is_uploaded_file($_FILES['file']['tmp_name'
$sys_user = $app->db->queryOneRecord("SELECT * FROM sys_user WHERE default_group = $sys_groupid");
$sys_userid = $sys_user['userid'];
// get the default mailserver of the client
$tmp = $app->db->queryOneRecord('SELECT default_mailserver FROM sys_group,client WHERE sys_group.client_id = client.client_id and sys_group.groupid = '.$sys_groupid);
$server_id = intval($tmp['default_mailserver']);
// get the mailserver of the client
// It seems like "default_mailserver" isn't used anymore so we get the mailserver from "mail_servers"
$tmp = $app->db->queryOneRecord('SELECT mail_servers FROM sys_group,client WHERE sys_group.client_id = client.client_id and sys_group.groupid = '.$sys_groupid);
$server_id = intval($tmp['mail_servers']);
unset($tmp);
if($server_id == 0) die('Invalid server ID');
......@@ -65,6 +66,8 @@ if(isset($_FILES['file']['name']) && is_uploaded_file($_FILES['file']['tmp_name'
$parts = explode(';',$line);
// login name; full name; mail address;password;mailbox quota
// Please remind: if $login_name != $email it gets overwritten on any config change of the mailbox
// as long as "System" > "Main Config" > "Mail" > "Allow custom login name" isn't set
$login_name = $app->db->quote(trim($parts[0]));
$name = $app->db->quote(trim($parts[1]));
$email = strtolower(trim($parts[2]));
......@@ -77,20 +80,21 @@ if(isset($_FILES['file']['name']) && is_uploaded_file($_FILES['file']['tmp_name'
// Check if email domain exists
$domain_rec = $app->db->queryOneRecord("SELECT * FROM mail_domain WHERE domain = '$domain'");
if($_POST['test'] != 1 && !is_array($domain_rec)) {
$insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `domain`, `active`)
VALUES($sys_userid, $sys_groupid, 'riud', 'riud', '', $server_id, '$domain', 'y')";
$insert_data = array(
"sys_userid" => $sys_userid,
"sys_groupid" => $sys_groupid,
"sys_perm_user" => 'riud',
"sys_perm_group" => 'riud',
"sys_perm_other" => '',
"server_id" => $server_id,
"domain" => $domain,
"active" => 'y',
);
$app->db->datalogInsert('mail_domain', $insert_data, 'domain_id');
}
// encrypt the password
$salt="$1$";
$base64_alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
for ($n=0;$n<8;$n++) {
//$salt.=chr(mt_rand(64,126));
$salt.=$base64_alphabet[mt_rand(0,63)];
}
$salt.="$";
$password_enc = crypt($password,$salt);
$password_enc = $app->auth->crypt_password(stripslashes($password));
$rec = $app->db->queryOneRecord("SELECT count(mailuser_id) as number FROM mail_user WHERE email = '".$user.'@'.$domain."'");
if($rec['number'] > 0) {
......@@ -103,16 +107,17 @@ if(isset($_FILES['file']['name']) && is_uploaded_file($_FILES['file']['tmp_name'
$tmp = array();
$tmp['name'] = $name;
$tmp['email'] = $user.'@'.$domain;
$tmp['quota'] = $quota;
$tmp['password'] = $password;
$tmp['quota'] = $quota;
$tmp['status'] = $status;
$email_list[] = $tmp;
if($_POST['test'] != 1 && $status = 'OK') {
if($_POST['test'] != 1 && $status != 'Duplicate') {
$app->uses('getconf');
$mail_config = $app->getconf->get_server_config($server_id,'mail');
$maildir = str_replace("[domain]",$domain,$mail_config["maildir_path"]);
$maildir = str_replace("[localpart]",strtolower($user),$maildir);
$homedir = $mail_config["homedir_path"];
......@@ -120,11 +125,27 @@ if(isset($_FILES['file']['name']) && is_uploaded_file($_FILES['file']['tmp_name'
$gid = $mail_config["mailuser_gid"];
$quota_bytes = $quota*1024*1024;
$insert_data = "(sys_userid,sys_groupid,sys_perm_user,sys_perm_group,sys_perm_other,server_id,
email,`password`,name,uid,gid,maildir,quota,homedir,postfix,access)
VALUES ('$sys_userid','$sys_groupid','riud','riud','','$server_id','".$user.'@'.$domain."','$password_enc',
'$name','$uid','$gid','$maildir','$quota_bytes','$homedir','y','n')";
// We create a new record
$insert_data = array(
"sys_userid" => $sys_userid,
"sys_groupid" => $sys_groupid,
"sys_perm_user" => 'riud',
"sys_perm_group" => 'riud',
"sys_perm_other" => '',
"server_id" => $server_id,
"email" => $user.'@'.$domain,
"login" => $login_name,
"password" => $password_enc,
"name" => $name,
"uid" => $uid,
"gid" => $gid,
"maildir" => $maildir,
"quota" => $quota_bytes,
"cc" => '',
"homedir" => $homedir,
"postfix" => 'y',
"access" => 'n',
);
//die('INSERT INTO mail_user '.$insert_data);
$app->db->datalogInsert('mail_user', $insert_data, 'mailuser_id');
......@@ -158,4 +179,4 @@ $app->tpl_defaults();
$app->tpl->pparse();
?>
\ No newline at end of file
?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment