Skip to content

Commit 22e7f9d

Browse files
committed
updated mail module
1 parent 76a1008 commit 22e7f9d

File tree

8 files changed

+730
-579
lines changed

8 files changed

+730
-579
lines changed

interface/lib/app.inc.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ function tpl_defaults() {
170170
$this->tpl->setVar('app_title',$conf["app_title"]);
171171
$this->tpl->setVar('delete_confirmation',$this->lng('delete_confirmation'));
172172
$this->tpl->setVar('app_module',$_SESSION["s"]["module"]["name"]);
173+
if($_SESSION["s"]["user"]["typ"] == 'admin') {
174+
$this->tpl->setVar('is_admin',1);
175+
}
173176

174177
}
175178

interface/lib/classes/tform_actions.inc.php

Lines changed: 533 additions & 520 deletions
Large diffs are not rendered by default.

interface/web/client/client_edit.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ function onAfterUpdate() {
100100
// password changed
101101
if($this->dataRecord["password"] != '') {
102102
$password = addslashes($this->dataRecord["password"]);
103+
$client_id = $this->id;
103104
$sql = "UPDATE sys_user SET passwort = md5('$password') WHERE client_id = $client_id";
105+
$app->db->query($sql);
104106
}
105107

106108

interface/web/mail/lib/lang/en_mail_domain.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ $wb["btn_cancel_txt"] = 'Cancel';
88
$wb["domain_error_empty"] = 'Domain is empty.';
99
$wb["domain_error_unique"] = 'Duplicate Domain.';
1010
$wb["domain_error_regex"] = 'Invalid domain name.';
11+
$wb["client_txt"] = 'Client';
1112

1213
?>

interface/web/mail/lib/lang/en_mail_user.lng

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ $wb["password_txt"] = 'password';
1717
$wb["maildir_txt"] = 'maildir';
1818
$wb["postfix_txt"] = 'Enable Receiving';
1919
$wb["access_txt"] = 'Enable Access';
20+
$wb["limit_mailbox_txt"] = 'The max. number of mailboxes for your account is reached.';
21+
$wb["limit_mailquota_txt"] = 'The max space for mailboxes is reached. The max. available space in MB is';
2022
?>
Lines changed: 103 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,104 @@
1-
<?php
2-
/*
3-
Copyright (c) 2005, Till Brehm, projektfarm Gmbh
4-
All rights reserved.
5-
6-
Redistribution and use in source and binary forms, with or without modification,
7-
are permitted provided that the following conditions are met:
8-
9-
* Redistributions of source code must retain the above copyright notice,
10-
this list of conditions and the following disclaimer.
11-
* Redistributions in binary form must reproduce the above copyright notice,
12-
this list of conditions and the following disclaimer in the documentation
13-
and/or other materials provided with the distribution.
14-
* Neither the name of ISPConfig nor the names of its contributors
15-
may be used to endorse or promote products derived from this software without
16-
specific prior written permission.
17-
18-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19-
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21-
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22-
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23-
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25-
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27-
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28-
*/
29-
30-
31-
/******************************************
32-
* Begin Form configuration
33-
******************************************/
34-
35-
$tform_def_file = "form/mail_domain.tform.php";
36-
37-
/******************************************
38-
* End Form configuration
39-
******************************************/
40-
41-
require_once('../../lib/config.inc.php');
42-
require_once('../../lib/app.inc.php');
43-
44-
// Checking module permissions
45-
if(!stristr($_SESSION["s"]["user"]["modules"],$_SESSION["s"]["module"]["name"])) {
46-
header("Location: ../index.php");
47-
exit;
48-
}
49-
50-
// Loading classes
51-
$app->uses('tpl,tform,tform_actions');
52-
53-
// let tform_actions handle the page
54-
$app->tform_actions->onLoad();
55-
1+
<?php
2+
/*
3+
Copyright (c) 2005, Till Brehm, projektfarm Gmbh
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without modification,
7+
are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice,
10+
this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
* Neither the name of ISPConfig nor the names of its contributors
15+
may be used to endorse or promote products derived from this software without
16+
specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
31+
/******************************************
32+
* Begin Form configuration
33+
******************************************/
34+
35+
$tform_def_file = "form/mail_domain.tform.php";
36+
37+
/******************************************
38+
* End Form configuration
39+
******************************************/
40+
41+
require_once('../../lib/config.inc.php');
42+
require_once('../../lib/app.inc.php');
43+
44+
// Checking module permissions
45+
if(!stristr($_SESSION["s"]["user"]["modules"],$_SESSION["s"]["module"]["name"])) {
46+
header("Location: ../index.php");
47+
exit;
48+
}
49+
50+
// Loading classes
51+
$app->uses('tpl,tform,tform_actions');
52+
$app->load('tform_actions');
53+
54+
class page_action extends tform_actions {
55+
56+
function onShowEnd() {
57+
global $app, $conf;
58+
59+
if($_SESSION["s"]["user"]["typ"] == 'admin') {
60+
// Getting Domains of the user
61+
$sql = "SELECT groupid, name FROM sys_group WHERE client_id > 0";
62+
$clients = $app->db->queryAllRecords($sql);
63+
$client_select = "<option value='0'></option>";
64+
if(is_array($clients)) {
65+
foreach( $clients as $client) {
66+
$selected = ($client["groupid"] == $this->dataRecord["sys_groupid"])?'SELECTED':'';
67+
$client_select .= "<option value='$client[groupid]' $selected>$client[name]</option>\r\n";
68+
}
69+
}
70+
$app->tpl->setVar("client_group_id",$client_select);
71+
}
72+
73+
parent::onShowEnd();
74+
}
75+
76+
function onSubmit() {
77+
if($_SESSION["s"]["user"]["typ"] != 'admin') unset($this->dataRecord["client_group_id"]);
78+
parent::onSubmit();
79+
}
80+
81+
function onAfterInsert() {
82+
global $app, $conf;
83+
84+
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
85+
$client_group_id = intval($this->dataRecord["client_group_id"]);
86+
$app->db->query("UPDATE mail_domain SET sys_groupid = $client_group_id WHERE domain_id = ".$this->id);
87+
}
88+
}
89+
90+
function onAfterUpdate() {
91+
global $app, $conf;
92+
93+
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
94+
$client_group_id = intval($this->dataRecord["client_group_id"]);
95+
$app->db->query("UPDATE mail_domain SET sys_groupid = $client_group_id WHERE domain_id = ".$this->id);
96+
}
97+
}
98+
99+
}
100+
101+
$page = new page_action;
102+
$page->onLoad();
103+
56104
?>

interface/web/mail/mail_user_edit.php

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,29 @@
5353

5454
class page_action extends tform_actions {
5555

56+
57+
function onShowNew() {
58+
global $app, $conf;
59+
60+
// we will check only users, not admins
61+
if($_SESSION["s"]["user"]["typ"] == 'user') {
62+
63+
// Get the limits of the client
64+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
65+
$client = $app->db->queryOneRecord("SELECT limit_mailbox FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
66+
67+
// Check if the user may add another mailbox.
68+
if($client["limit_mailbox"] >= 0) {
69+
$tmp = $app->db->queryOneRecord("SELECT count(mailuser_id) as number FROM mail_user WHERE sys_groupid = $client_group_id");
70+
if($tmp["number"] >= $client["limit_mailbox"]) {
71+
$app->error($app->tform->wordbook["limit_mailbox_txt"]);
72+
}
73+
}
74+
}
75+
76+
parent::onShowNew();
77+
}
78+
5679
function onShowEnd() {
5780
global $app, $conf;
5881

@@ -75,22 +98,54 @@ function onShowEnd() {
7598
// Convert quota from Bytes to MB
7699
$app->tpl->setVar("quota",$this->dataRecord["quota"] / 1024);
77100

78-
79101
parent::onShowEnd();
80102
}
81103

82104
function onSubmit() {
83105
global $app, $conf;
84106

107+
// Get the limits of the client
108+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
109+
$client = $app->db->queryOneRecord("SELECT limit_mailbox, limit_mailquota FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
110+
85111
// Check if Domain belongs to user
86112
$domain = $app->db->queryOneRecord("SELECT server_id, domain FROM mail_domain WHERE domain = '".$app->db->quote($_POST["email_domain"])."' AND ".$app->tform->getAuthSQL('r'));
87113
if($domain["domain"] != $_POST["email_domain"]) $app->tform->errorMessage .= $app->tform->wordbook["no_domain_perm"];
88114

89-
// if its an insert, check for password
90-
if($this->id == 0 and $_POST["password"] == '') {
91-
$app->tform->errorMessage .= $app->tform->wordbook["error_no_pwd"]."<br>";
115+
// if its an insert
116+
if($this->id == 0) {
117+
118+
// check for password
119+
if($_POST["password"] == '') {
120+
$app->tform->errorMessage .= $app->tform->wordbook["error_no_pwd"]."<br>";
121+
}
122+
123+
// Check if the user may add another mailbox.
124+
if($client["limit_mailbox"] >= 0) {
125+
$tmp = $app->db->queryOneRecord("SELECT count(mailuser_id) as number FROM mail_user WHERE sys_groupid = $client_group_id");
126+
if($tmp["number"] >= $client["limit_mailbox"]) {
127+
$app->tform->errorMessage .= $app->tform->wordbook["limit_mailbox_txt"]."<br>";
128+
}
129+
unset($tmp);
130+
}
131+
} // end if insert
132+
133+
// Check the quota and adjust
134+
if($client["limit_mailquota"] >= 0) {
135+
$tmp = $app->db->queryOneRecord("SELECT sum(quota) as mailquota FROM mail_user WHERE mailuser_id != ".intval($this->id)." AND sys_groupid = $client_group_id");
136+
$mailquota = $tmp["mailquota"] / 1024;
137+
$new_mailbox_quota = intval($this->dataRecord["quota"]);
138+
if($mailquota + $new_mailbox_quota > $client["limit_mailquota"]) {
139+
$max_free_quota = $client["limit_mailquota"] - $mailquota;
140+
$app->tform->errorMessage .= $app->tform->wordbook["limit_mailquota_txt"].": ".$max_free_quota."<br>";
141+
// Set the quota field to the max free space
142+
$this->dataRecord["quota"] = $max_free_quota;
143+
}
144+
unset($tmp);
145+
unset($tmp_quota);
92146
}
93147

148+
94149
// compose the email field
95150
$this->dataRecord["email"] = $_POST["email_local_part"]."@".$_POST["email_domain"];
96151
// Set the server id of the mailbox = server ID of mail domain.
@@ -111,10 +166,27 @@ function onSubmit() {
111166
$this->dataRecord["homedir"] = $mail_config["homedir_path"];
112167
$this->dataRecord["uid"] = $mail_config["mailuser_uid"];
113168
$this->dataRecord["gid"] = $mail_config["mailuser_gid"];
169+
114170

115171
parent::onSubmit();
116172
}
117173

174+
function onAfterInsert() {
175+
global $app, $conf;
176+
177+
// Set the domain owner as mailbox owner
178+
$domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain = '".$app->db->quote($_POST["email_domain"])."' AND ".$app->tform->getAuthSQL('r'));
179+
$app->db->query("UPDATE mail_user SET sys_groupid = ".$domain["sys_groupid"]." WHERE mailuser_id = ".$this->id);
180+
}
181+
182+
function onAfterUpdate() {
183+
global $app, $conf;
184+
185+
// Set the domain owner as mailbox owner
186+
$domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain = '".$app->db->quote($_POST["email_domain"])."' AND ".$app->tform->getAuthSQL('r'));
187+
$app->db->query("UPDATE mail_user SET sys_groupid = ".$domain["sys_groupid"]." WHERE mailuser_id = ".$this->id);
188+
}
189+
118190
}
119191

120192
$app->tform_actions = new page_action;

interface/web/mail/templates/mail_domain_edit.htm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<table width="500" border="0" cellspacing="0" cellpadding="2">
2+
<tmpl_if name="is_admin">
23
<tr>
34
<td class="frmText11">{tmpl_var name='server_id_txt'}:</td>
45
<td class="frmText11">
@@ -7,6 +8,15 @@
78
</select>
89
</td>
910
</tr>
11+
<tr>
12+
<td class="frmText11">{tmpl_var name='client_txt'}:</td>
13+
<td class="frmText11">
14+
<select name="client_group_id" class="text">
15+
{tmpl_var name='client_group_id'}
16+
</select>
17+
</td>
18+
</tr>
19+
</tmpl_if>
1020
<tr>
1121
<td class="frmText11">{tmpl_var name='domain_txt'}:</td>
1222
<td class="frmText11"><input name="domain" type="text" class="text" value="{tmpl_var name='domain'}" size="30" maxlength="255"></td>

0 commit comments

Comments
 (0)