| | |
| | | |
| | | // we will check only users, not admins |
| | | if($_SESSION["s"]["user"]["typ"] == 'user') { |
| | | |
| | | // Get the limits of the client |
| | | $client_group_id = $_SESSION["s"]["user"]["default_group"]; |
| | | $client = $app->db->queryOneRecord("SELECT limit_maildomain FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id"); |
| | | |
| | | // Check if the user may add another maildomain. |
| | | if($client["limit_maildomain"] >= 0) { |
| | | $tmp = $app->db->queryOneRecord("SELECT count(domain_id) as number FROM mail_domain WHERE sys_groupid = $client_group_id"); |
| | | if($tmp["number"] >= $client["limit_maildomain"]) { |
| | | $app->error($app->tform->wordbook["limit_maildomain_txt"]); |
| | | } |
| | | if(!$app->tform->checkClientLimit('limit_maildomain')) { |
| | | $app->error($app->tform->wordbook["limit_maildomain_txt"]); |
| | | } |
| | | if(!$app->tform->checkResellerLimit('limit_maildomain')) { |
| | | $app->error('Reseller: '.$app->tform->wordbook["limit_maildomain_txt"]); |
| | | } |
| | | } |
| | | |
| | |
| | | function onShowEnd() { |
| | | global $app, $conf; |
| | | |
| | | if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
| | | // Getting Domains of the user |
| | | $sql = "SELECT groupid, name FROM sys_group WHERE client_id > 0"; |
| | | if($_SESSION["s"]["user"]["typ"] == 'admin') { |
| | | // Getting Clients of the user |
| | | if($_SESSION["s"]["user"]["typ"] == 'admin') { |
| | | $sql = "SELECT groupid, name FROM sys_group WHERE client_id > 0"; |
| | | } else { |
| | | $client_group_id = $_SESSION["s"]["user"]["default_group"]; |
| | | $sql = "SELECT client.client_id, limit_web_domain, default_webserver FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id"; |
| | | } |
| | | $clients = $app->db->queryAllRecords($sql); |
| | | $client_select = ''; |
| | | if($_SESSION["s"]["user"]["typ"] == 'admin') $client_select .= "<option value='0'></option>"; |
| | |
| | | $client_select .= "<option value='$client[groupid]' $selected>$client[name]</option>\r\n"; |
| | | } |
| | | } |
| | | $app->tpl->setVar("client_group_id",$client_select); |
| | | $app->tpl->setVar("client_group_id",$client_select); |
| | | |
| | | } elseif ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
| | | |
| | | // Get the limits of the client |
| | | $client_group_id = $_SESSION["s"]["user"]["default_group"]; |
| | | $client = $app->db->queryOneRecord("SELECT client.client_id, contact_name FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id"); |
| | | |
| | | // Set the webserver to the default server of the client |
| | | $tmp = $app->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = $client[default_webserver]"); |
| | | $app->tpl->setVar("server_id","<option value='$client[default_webserver]'>$tmp[server_name]</option>"); |
| | | unset($tmp); |
| | | |
| | | // Fill the client select field |
| | | $sql = "SELECT groupid, name FROM sys_group, client WHERE sys_group.client_id = client.client_id AND client.parent_client_id = ".$client['client_id']; |
| | | $clients = $app->db->queryAllRecords($sql); |
| | | $client_select = '<option value="'.$client['client_id'].'">'.$client['contact_name'].'</option>'; |
| | | if(is_array($clients)) { |
| | | foreach( $clients as $client) { |
| | | $selected = @($client["groupid"] == $this->dataRecord["sys_groupid"])?'SELECTED':''; |
| | | $client_select .= "<option value='$client[groupid]' $selected>$client[name]</option>\r\n"; |
| | | } |
| | | } |
| | | $app->tpl->setVar("client_group_id",$client_select); |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | // Get the spamfilter policys for the user |
| | | $tmp_user = $app->db->queryOneRecord("SELECT policy_id FROM spamfilter_users WHERE email = '@".$this->dataRecord["domain"]."'"); |
| | |
| | | unset($policys); |
| | | unset($policy_select); |
| | | unset($tmp_user); |
| | | |
| | | if($this->id > 0) { |
| | | //* we are editing a existing record |
| | | $app->tpl->setVar("edit_disabled", 1); |
| | | $app->tpl->setVar("server_id_value", $this->dataRecord["server_id"]); |
| | | } else { |
| | | $app->tpl->setVar("edit_disabled", 0); |
| | | } |
| | | |
| | | parent::onShowEnd(); |
| | | } |
| | |
| | | // Clients may not set the client_group_id, so we unset them if user is not a admin |
| | | if(!$app->auth->has_clients($_SESSION['s']['user']['userid'])) unset($this->dataRecord["client_group_id"]); |
| | | } |
| | | |
| | | //* make sure that the email domain is lowercase |
| | | if(isset($this->dataRecord["domain"])) $this->dataRecord["domain"] = strtolower($this->dataRecord["domain"]); |
| | | |
| | | |
| | | parent::onSubmit(); |
| | | } |
| | | |
| | |
| | | // Spamfilter policy |
| | | $policy_id = intval($this->dataRecord["policy"]); |
| | | if($policy_id > 0) { |
| | | $tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = '@".addslashes($this->dataRecord["domain"])."'"); |
| | | $tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = '@".mysql_real_escape_string($this->dataRecord["domain"])."'"); |
| | | if($tmp_user["id"] > 0) { |
| | | // There is already a record that we will update |
| | | $sql = "UPDATE spamfilter_users SET policy_id = $ploicy_id WHERE id = ".$tmp_user["id"]; |
| | | $app->db->query($sql); |
| | | $app->db->datalogUpdate('spamfilter_users', "policy_id = $ploicy_id", 'id', $tmp_user["id"]); |
| | | } else { |
| | | $tmp_domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain_id = ".$this->id); |
| | | // We create a new record |
| | | $sql = "INSERT INTO `spamfilter_users` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `priority`, `policy_id`, `email`, `fullname`, `local`) |
| | | VALUES (".$_SESSION["s"]["user"]["userid"].", ".$tmp_domain["sys_groupid"].", 'riud', 'riud', '', ".$this->dataRecord["server_id"].", 5, ".$policy_id.", '@".addslashes($this->dataRecord["domain"])."', '@".addslashes($this->dataRecord["domain"])."', 'Y')"; |
| | | $app->db->query($sql); |
| | | $insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `priority`, `policy_id`, `email`, `fullname`, `local`) |
| | | VALUES (".$_SESSION["s"]["user"]["userid"].", ".$tmp_domain["sys_groupid"].", 'riud', 'riud', '', ".$this->dataRecord["server_id"].", 5, ".$policy_id.", '@".mysql_real_escape_string($this->dataRecord["domain"])."', '@".mysql_real_escape_string($this->dataRecord["domain"])."', 'Y')"; |
| | | $app->db->datalogInsert('spamfilter_users', $insert_data, 'id'); |
| | | unset($tmp_domain); |
| | | } |
| | | } // endif spamfilter policy |
| | | } |
| | | |
| | | function onBeforeUpdate() { |
| | | global $app, $conf; |
| | | |
| | | //* Check if the server has been changed |
| | | // We do this only for the admin or reseller users, as normal clients can not change the server ID anyway |
| | | if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
| | | $rec = $app->db->queryOneRecord("SELECT server_id, domain from mail_domain WHERE domain_id = ".$this->id); |
| | | if($rec['server_id'] != $this->dataRecord["server_id"]) { |
| | | //* Add a error message and switch back to old server |
| | | $app->tform->errorMessage .= $app->lng('The Server can not be changed.'); |
| | | $this->dataRecord["server_id"] = $rec['server_id']; |
| | | } |
| | | unset($rec); |
| | | //* If the user is neither admin nor reseller |
| | | } else { |
| | | //* We do not allow users to change a domain which has been created by the admin |
| | | $rec = $app->db->queryOneRecord("SELECT domain from mail_domain WHERE domain_id = ".$this->id); |
| | | if($rec['domain'] != $this->dataRecord["domain"] && $app->tform->checkPerm($this->id,'u')) { |
| | | //* Add a error message and switch back to old server |
| | | $app->tform->errorMessage .= $app->lng('The Domain can not be changed. Please ask your Administrator if you want to change the domain name.'); |
| | | $this->dataRecord["domain"] = $rec['domain']; |
| | | } |
| | | unset($rec); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | function onAfterUpdate() { |
| | | global $app, $conf; |
| | |
| | | |
| | | // Spamfilter policy |
| | | $policy_id = intval($this->dataRecord["policy"]); |
| | | $tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = '@".addslashes($this->dataRecord["domain"])."'"); |
| | | $tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = '@".mysql_real_escape_string($this->dataRecord["domain"])."'"); |
| | | if($policy_id > 0) { |
| | | if($tmp_user["id"] > 0) { |
| | | // There is already a record that we will update |
| | | $sql = "UPDATE spamfilter_users SET policy_id = $policy_id WHERE id = ".$tmp_user["id"]; |
| | | $app->db->query($sql); |
| | | $app->db->datalogUpdate('spamfilter_users', "policy_id = $policy_id", 'id', $tmp_user["id"]); |
| | | } else { |
| | | $tmp_domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain_id = ".$this->id); |
| | | // We create a new record |
| | | $sql = "INSERT INTO `spamfilter_users` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `priority`, `policy_id`, `email`, `fullname`, `local`) |
| | | VALUES (".$_SESSION["s"]["user"]["userid"].", ".$tmp_domain["sys_groupid"].", 'riud', 'riud', '', ".$this->dataRecord["server_id"].", 5, ".$policy_id.", '@".addslashes($this->dataRecord["domain"])."', '@".addslashes($this->dataRecord["domain"])."', 'Y')"; |
| | | $app->db->query($sql); |
| | | $insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `priority`, `policy_id`, `email`, `fullname`, `local`) |
| | | VALUES (".$_SESSION["s"]["user"]["userid"].", ".$tmp_domain["sys_groupid"].", 'riud', 'riud', '', ".$this->dataRecord["server_id"].", 5, ".$policy_id.", '@".mysql_real_escape_string($this->dataRecord["domain"])."', '@".mysql_real_escape_string($this->dataRecord["domain"])."', 'Y')"; |
| | | $app->db->datalogInsert('spamfilter_users', $insert_data, 'id'); |
| | | unset($tmp_domain); |
| | | } |
| | | }else { |
| | | } else { |
| | | if($tmp_user["id"] > 0) { |
| | | // There is already a record but the user shall have no policy, so we delete it |
| | | $sql = "DELETE FROM spamfilter_users WHERE id = ".$tmp_user["id"]; |
| | | $app->db->query($sql); |
| | | $app->db->datalogDelete('spamfilter_users', 'id', $tmp_user["id"]); |
| | | } |
| | | } // endif spamfilter policy |
| | | |
| | |
| | | $mail_config = $app->getconf->get_server_config($this->dataRecord["server_id"],'mail'); |
| | | |
| | | //* Update the mailboxes |
| | | $mailusers = $app->db->queryAllRecords("SELECT * FROM mail_user WHERE email like '%@".addslashes($this->oldDataRecord['domain'])."'"); |
| | | $mailusers = $app->db->queryAllRecords("SELECT * FROM mail_user WHERE email like '%@".mysql_real_escape_string($this->oldDataRecord['domain'])."'"); |
| | | if(is_array($mailusers)) { |
| | | foreach($mailusers as $rec) { |
| | | // setting Maildir, Homedir, UID and GID |
| | | $mail_parts = explode("@",$rec['email']); |
| | | $maildir = str_replace("[domain]",$this->dataRecord['domain'],$mail_config["maildir_path"]); |
| | | $maildir = str_replace("[localpart]",$mail_parts[0],$maildir); |
| | | $maildir = addslashes($maildir); |
| | | $email = addslashes($mail_parts[0].'@'.$this->dataRecord['domain']); |
| | | $maildir = mysql_real_escape_string($maildir); |
| | | $email = mysql_real_escape_string($mail_parts[0].'@'.$this->dataRecord['domain']); |
| | | $app->db->datalogUpdate('mail_user', "maildir = '$maildir', email = '$email'", 'mailuser_id', $rec['mailuser_id']); |
| | | } |
| | | } |
| | | |
| | | //* Update the aliases |
| | | $forwardings = $app->db->queryAllRecords("SELECT * FROM mail_forwarding WHERE source like '%@".addslashes($this->oldDataRecord['domain'])."' OR destination like '%@".addslashes($this->oldDataRecord['domain'])."'"); |
| | | $forwardings = $app->db->queryAllRecords("SELECT * FROM mail_forwarding WHERE source like '%@".mysql_real_escape_string($this->oldDataRecord['domain'])."' OR destination like '%@".mysql_real_escape_string($this->oldDataRecord['domain'])."'"); |
| | | if(is_array($forwardings)) { |
| | | foreach($forwardings as $rec) { |
| | | $destination = addslashes(str_replace($this->oldDataRecord['domain'],$this->dataRecord['domain'],$rec['destination'])); |
| | | $source = addslashes(str_replace($this->oldDataRecord['domain'],$this->dataRecord['domain'],$rec['source'])); |
| | | $destination = mysql_real_escape_string(str_replace($this->oldDataRecord['domain'],$this->dataRecord['domain'],$rec['destination'])); |
| | | $source = mysql_real_escape_string(str_replace($this->oldDataRecord['domain'],$this->dataRecord['domain'],$rec['source'])); |
| | | $app->db->datalogUpdate('mail_forwarding', "source = '$source', destination = '$destination'", 'forwarding_id', $rec['forwarding_id']); |
| | | } |
| | | } |
| | | |
| | | //* Delete the old spamfilter record |
| | | $tmp = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = '@".mysql_real_escape_string($this->oldDataRecord["domain"])."'"); |
| | | $app->db->datalogDelete('spamfilter_users', 'id', $tmp["id"]); |
| | | unset($tmp); |
| | | |
| | | } // end if domain name changed |
| | | |
| | | } |