Commit 8537705b authored by Marius Cramer's avatar Marius Cramer
Browse files

Merge branch 'change_owner' into 'master'

Change owner on domain module changes on mail domain, sites and dns too

It's related to #97 merge request
Instead of displaying a warning about owner must be changed on mail and domain too, change it everywhere.

I have fixed some records which were not changed owner when changing mail domain's owner or web site's owner.

If you agree, I'm thinking in disable client selector on mail, domain and dns when domain module is enabled.
parents 5d1c6919 6877c68c
......@@ -149,6 +149,5 @@ $wb['strength_4'] = 'Strong';
$wb['strength_5'] = 'Very Strong';
$wb['weak_password_txt'] = 'The chosen password does not match the security guidelines. It has to be at least {chars} chars in length and have a strength of "{strength}".';
$wb['weak_password_length_txt'] = 'The chosen password does not match the security guidelines. It has to be at least {chars} chars in length.';
$wb['domain_owner_changed'] = 'You have changed the owner of domain {domain}, please change website and mail domain owner for this domain accordingly.';
?>
......@@ -148,5 +148,4 @@ $wb['strength_5'] = 'Muy fuerte';
$wb['weak_password_txt'] = 'La contraseña elegida no cumple las directrices de seguridad. Debe tener al menos {chars} caracteres y una fortaleza \"{strength}\".';
$wb['weak_password_length_txt'] = 'La contraseña elegida no cumple las directrices de seguridad. Debe tener al menos {chars} caracteres.';
$wb['Firewall'] = 'Cortafuegos';
$wb['domain_owner_changed'] = 'Has cambiado el propietario del dominio {domain}, por favor cambia también el propietario del sitio web y dominio de correo de este dominio.';
?>
<?php
/**
* dns_dns_slave_plugin plugin
*
* @author Sergio Cambra <sergio@programatica.es> 2014
*/
class dns_dns_slave_plugin {
var $plugin_name = 'dns_dns_slave_plugin';
var $class_name = 'dns_dns_slave_plugin';
/*
This function is called when the plugin is loaded
*/
function onLoad() {
global $app;
//Register for the events
$app->plugin->registerEvent('dns:dns_slave:on_after_insert', 'dns_dns_slave_plugin', 'dns_dns_slave_edit');
$app->plugin->registerEvent('dns:dns_slave:on_after_update', 'dns_dns_slave_plugin', 'dns_dns_slave_edit');
}
/*
Function to change dns slave owner
*/
function dns_dns_slave_edit($event_name, $page_form) {
global $app, $conf;
// make sure that the record belongs to the client group and not the admin group when a dmin inserts it
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($page_form->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($page_form->dataRecord["client_group_id"]);
$app->db->query("UPDATE dns_slave SET sys_groupid = $client_group_id WHERE id = ".$page_form->id);
}
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
$app->db->query("UPDATE dns_slave SET sys_groupid = $client_group_id WHERE id = ".$page_form->id);
}
//** When the client group has changed, change also the owner of the record if the owner is not the admin user
if($page_form->oldDataRecord && $page_form->oldDataRecord["client_group_id"] != $page_form->dataRecord["client_group_id"] && $page_form->dataRecord["sys_userid"] != 1) {
$client_group_id = $app->functions->intval($page_form->dataRecord["client_group_id"]);
$tmp = $app->db->queryOneREcord("SELECT userid FROM sys_user WHERE default_group = ".$client_group_id);
if($tmp["userid"] > 0) {
$app->db->query("UPDATE dns_slave SET sys_userid = ".$tmp["userid"]." WHERE id = ".$page_form->id);
}
}
}
}
<?php
/**
* dns_dns_soa_plugin plugin
*
* @author Sergio Cambra <sergio@programatica.es> 2014
*/
class dns_dns_soa_plugin {
var $plugin_name = 'dns_dns_soa_plugin';
var $class_name = 'dns_dns_soa_plugin';
/*
This function is called when the plugin is loaded
*/
function onLoad() {
global $app;
//Register for the events
$app->plugin->registerEvent('dns:dns_soa:on_after_insert', 'dns_dns_soa_plugin', 'dns_dns_soa_edit');
$app->plugin->registerEvent('dns:dns_soa:on_after_update', 'dns_dns_soa_plugin', 'dns_dns_soa_edit');
}
/*
Function to change dns soa owner
*/
function dns_dns_soa_edit($event_name, $page_form) {
global $app, $conf;
if ($event_name == 'dns:dns_soa:on_after_update') {
$tmp = $app->db->diffrec($page_form->oldDataRecord, $app->tform->getDataRecord($page_form->id));
if($tmp['diff_num'] > 0) {
// Update the serial number of the SOA record
$soa = $app->db->queryOneRecord("SELECT serial FROM dns_soa WHERE id = ".$page_form->id);
$app->db->query("UPDATE dns_soa SET serial = '".$app->validate_dns->increase_serial($soa["serial"])."' WHERE id = ".$page_form->id);
}
//** When the client group has changed, change also the owner of the record if the owner is not the admin user
if($page_form->oldDataRecord["client_group_id"] != $page_form->dataRecord["client_group_id"] && $page_form->dataRecord["sys_userid"] != 1) {
$client_group_id = $app->functions->intval($page_form->dataRecord["client_group_id"]);
$tmp = $app->db->queryOneREcord("SELECT userid FROM sys_user WHERE default_group = ".$client_group_id);
if($tmp["userid"] > 0) {
$app->db->query("UPDATE dns_soa SET sys_userid = ".$tmp["userid"]." WHERE id = ".$page_form->id);
$app->db->query("UPDATE dns_rr SET sys_userid = ".$tmp["userid"]." WHERE zone = ".$page_form->id);
}
}
}
// make sure that the record belongs to the client group and not the admin group when a dmin inserts it
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($page_form->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($page_form->dataRecord["client_group_id"]);
$app->db->query("UPDATE dns_soa SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE id = ".$page_form->id);
// And we want to update all rr records too, that belong to this record
$app->db->query("UPDATE dns_rr SET sys_groupid = $client_group_id WHERE zone = ".$page_form->id);
}
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($page_form->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($page_form->dataRecord["client_group_id"]);
$app->db->query("UPDATE dns_soa SET sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE id = ".$page_form->id);
// And we want to update all rr records too, that belong to this record
$app->db->query("UPDATE dns_rr SET sys_groupid = $client_group_id WHERE zone = ".$page_form->id);
}
}
}
<?php
/**
* mail_mail_domain_plugin plugin
*
* @author Sergio Cambra <sergio@programatica.es> 2014
*/
class mail_mail_domain_plugin {
var $plugin_name = 'mail_mail_domain_plugin';
var $class_name = 'mail_mail_domain_plugin';
/*
This function is called when the plugin is loaded
*/
function onLoad() {
global $app;
//Register for the events
$app->plugin->registerEvent('mail:mail_domain:on_after_insert', 'mail_mail_domain_plugin', 'mail_mail_domain_edit');
$app->plugin->registerEvent('mail:mail_domain:on_after_update', 'mail_mail_domain_plugin', 'mail_mail_domain_edit');
}
/*
Function to create the sites_web_domain rule and insert it into the custom rules
*/
function mail_mail_domain_edit($event_name, $page_form) {
global $app, $conf;
// make sure that the record belongs to the clinet group and not the admin group when a dmin inserts it
// also make sure that the user can not delete entry created by an admin
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($page_form->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($page_form->dataRecord["client_group_id"]);
$updates = "sys_groupid = $client_group_id, sys_perm_group = 'ru'";
if ($event_name == 'mail:mail_domain:on_after_update') {
$tmp = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE default_group = $client_group_id");
$client_user_id = ($tmp['userid'] > 0)?$tmp['userid']:1;
$updates = "sys_userid = $client_user_id, $updates";
}
$app->db->query("UPDATE mail_domain SET $updates WHERE domain_id = ".$page_form->id);
}
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($page_form->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($page_form->dataRecord["client_group_id"]);
$updates = "sys_groupid = $client_group_id, sys_perm_group = 'riud'";
if ($event_name == 'mail:mail_domain:on_after_update') {
$tmp = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE default_group = $client_group_id");
$client_user_id = ($tmp['userid'] > 0)?$tmp['userid']:1;
$updates = "sys_userid = $client_user_id, $updates";
}
$app->db->query("UPDATE mail_domain SET $updates WHERE domain_id = ".$page_form->id);
}
//** If the domain name or owner has been changed, change the domain and owner in all mailbox records
if($page_form->oldDataRecord && ($page_form->oldDataRecord['domain'] != $page_form->dataRecord['domain'] ||
(isset($page_form->dataRecord['client_group_id']) && $page_form->oldDataRecord['sys_groupid'] != $page_form->dataRecord['client_group_id']))) {
$app->uses('getconf');
$mail_config = $app->getconf->get_server_config($page_form->dataRecord["server_id"], 'mail');
//* Update the mailboxes
$mailusers = $app->db->queryAllRecords("SELECT * FROM mail_user WHERE email like '%@".$app->db->quote($page_form->oldDataRecord['domain'])."'");
$sys_groupid = $app->functions->intval((isset($page_form->dataRecord['client_group_id']))?$page_form->dataRecord['client_group_id']:$page_form->oldDataRecord['sys_groupid']);
$tmp = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE default_group = $sys_groupid");
$client_user_id = $app->functions->intval(($tmp['userid'] > 0)?$tmp['userid']:1);
if(is_array($mailusers)) {
foreach($mailusers as $rec) {
// setting Maildir, Homedir, UID and GID
$mail_parts = explode("@", $rec['email']);
$maildir = str_replace("[domain]", $page_form->dataRecord['domain'], $mail_config["maildir_path"]);
$maildir = str_replace("[localpart]", $mail_parts[0], $maildir);
$maildir = $app->db->quote($maildir);
$email = $app->db->quote($mail_parts[0].'@'.$page_form->dataRecord['domain']);
$app->db->datalogUpdate('mail_user', "maildir = '$maildir', email = '$email', sys_userid = $client_user_id, sys_groupid = '$sys_groupid'", 'mailuser_id', $rec['mailuser_id']);
}
}
//* Update the aliases
$forwardings = $app->db->queryAllRecords("SELECT * FROM mail_forwarding WHERE source like '%@".$app->db->quote($page_form->oldDataRecord['domain'])."' OR destination like '%@".$app->db->quote($page_form->oldDataRecord['domain'])."'");
if(is_array($forwardings)) {
foreach($forwardings as $rec) {
$destination = $app->db->quote(str_replace($page_form->oldDataRecord['domain'], $page_form->dataRecord['domain'], $rec['destination']));
$source = $app->db->quote(str_replace($page_form->oldDataRecord['domain'], $page_form->dataRecord['domain'], $rec['source']));
$app->db->datalogUpdate('mail_forwarding', "source = '$source', destination = '$destination', sys_userid = $client_user_id, sys_groupid = '$sys_groupid'", 'forwarding_id', $rec['forwarding_id']);
}
}
//* Update the mailinglist
$mailing_lists = $app->db->queryAllRecords("SELECT mailinglist_id FROM mail_mailinglist WHERE domain = '".$app->db->quote($page_form->oldDataRecord['domain'])."'");
if(is_array($mailing_lists)) {
foreach($mailing_lists as $rec) {
$app->db->datalogUpdate('mail_mailinglist', "sys_userid = $client_user_id, sys_groupid = '$sys_groupid'", 'mailinglist_id', $rec['mailinglist_id']);
}
}
//* Update the mailget records
$mail_gets = $app->db->queryAllRecords("SELECT mailget_id, destination FROM mail_get WHERE destination LIKE '%@".$app->db->quote($page_form->oldDataRecord['domain'])."'");
if(is_array($mail_gets)) {
foreach($mail_gets as $rec) {
$destination = $app->db->quote(str_replace($page_form->oldDataRecord['domain'], $page_form->dataRecord['domain'], $rec['destination']));
$app->db->datalogUpdate('mail_get', "destination = '$destination', sys_userid = $client_user_id, sys_groupid = '$sys_groupid'", 'mailget_id', $rec['mailget_id']);
}
}
if ($page_form->oldDataRecord["domain"] != $page_form->dataRecord['domain']) {
//* Delete the old spamfilter record
$tmp = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = '@".$app->db->quote($page_form->oldDataRecord["domain"])."'");
$app->db->datalogDelete('spamfilter_users', 'id', $tmp["id"]);
unset($tmp);
}
$app->db->query("UPDATE spamfilter_users SET email=REPLACE(email, '".$app->db->quote($page_form->oldDataRecord['domain'])."', '".$app->db->quote($page_form->dataRecord['domain'])."'), sys_userid = $client_user_id, sys_groupid = $sys_groupid WHERE email LIKE '%@".$app->db->quote($page_form->oldDataRecord['domain'])."'");
} // end if domain name changed
}
}
......@@ -113,6 +113,30 @@ class sites_web_vhost_domain_plugin {
unset($records);
unset($rec);
// Update the webdav user(s) too
$records = $app->db->queryAllRecords("SELECT webdav_user_id FROM webdav_user WHERE parent_domain_id = ".$page_form->id);
foreach($records as $rec) {
$app->db->datalogUpdate('webdav_user', "sys_userid = '".$app->functions->intval($web_rec['sys_userid'])."', sys_groupid = '".$app->functions->intval($web_rec['sys_groupid'])."'", 'webdav_user_id', $app->functions->intval($rec['webdav_user_id']));
}
unset($records);
unset($rec);
// Update the web folder(s) too
$records = $app->db->queryAllRecords("SELECT web_folder_id FROM web_folder WHERE parent_domain_id = ".$page_form->id);
foreach($records as $rec) {
$app->db->datalogUpdate('web_folder', "sys_userid = '".$app->functions->intval($web_rec['sys_userid'])."', sys_groupid = '".$app->functions->intval($web_rec['sys_groupid'])."'", 'web_folder_id', $app->functions->intval($rec['web_folder_id']));
}
unset($records);
unset($rec);
//* Update all web folder users
$records = $app->db->queryAllRecords("SELECT web_folder_user.web_folder_user_id FROM web_folder_user, web_folder WHERE web_folder_user.web_folder_id = web_folder.web_folder_id AND web_folder.parent_domain_id = ".$page_form->id);
foreach($records as $rec) {
$app->db->datalogUpdate('web_folder_user', "sys_userid = '".$app->functions->intval($web_rec['sys_userid'])."', sys_groupid = '".$app->functions->intval($web_rec['sys_groupid'])."'", 'web_folder_user_id', $app->functions->intval($rec['web_folder_user_id']));
}
unset($records);
unset($rec);
// Update the Shell user(s) too
$records = $app->db->queryAllRecords("SELECT shell_user_id FROM shell_user WHERE parent_domain_id = ".$page_form->id);
foreach($records as $rec) {
......@@ -121,6 +145,14 @@ class sites_web_vhost_domain_plugin {
unset($records);
unset($rec);
// Update the cron(s) too
$records = $app->db->queryAllRecords("SELECT id FROM cron WHERE parent_domain_id = ".$page_form->id);
foreach($records as $rec) {
$app->db->datalogUpdate('cron', "sys_userid = '".$app->functions->intval($web_rec['sys_userid'])."', sys_groupid = '".$app->functions->intval($web_rec['sys_groupid'])."'", 'id', $app->functions->intval($rec['id']));
}
unset($records);
unset($rec);
//* Update all subdomains and alias domains
$records = $app->db->queryAllRecords("SELECT domain_id, `domain`, `type`, `web_folder` FROM web_domain WHERE parent_domain_id = ".$page_form->id);
foreach($records as $rec) {
......@@ -143,6 +175,22 @@ class sites_web_vhost_domain_plugin {
foreach($records as $rec) {
$app->db->datalogUpdate('web_database', "sys_userid = '".$app->functions->intval($web_rec['sys_userid'])."', sys_groupid = '".$app->functions->intval($web_rec['sys_groupid'])."'", 'database_id', $app->functions->intval($rec['database_id']));
}
//* Update all database users
$records = $app->db->queryAllRecords("SELECT web_database_user.database_user_id FROM web_database_user, web_database WHERE web_database_user.database_user_id IN (web_database.database_user_id, web_database.database_ro_user_id) AND web_database.parent_domain_id = ".$page_form->id);
foreach($records as $rec) {
$app->db->datalogUpdate('web_database_user', "sys_userid = '".$app->functions->intval($web_rec['sys_userid'])."', sys_groupid = '".$app->functions->intval($web_rec['sys_groupid'])."'", 'database_user_id', $app->functions->intval($rec['database_user_id']));
}
unset($records);
unset($rec);
// Update APS instances
$records = $app->db->queryAllRecords("SELECT instance_id FROM aps_instances_settings WHERE name = 'main_domain' AND value = '".$app->db->quote($page_form->oldDataRecord["domain"])."'");
if(is_array($records) && !empty($records)){
foreach($records as $rec){
$app->db->datalogUpdate('aps_instances', "sys_userid = '".$app->functions->intval($web_rec['sys_userid'])."', sys_groupid = '".$app->functions->intval($web_rec['sys_groupid'])."', customer_id = '".$app->functions->intval($client_id)."'", 'id', $rec['instance_id']);
}
}
unset($records);
unset($rec);
......
......@@ -216,8 +216,44 @@ class page_action extends tform_actions {
if(isset($this->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
$app->db->query("UPDATE domain SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE domain_id = ".$this->id);
$lng_text = $app->lng("domain_owner_changed");
$_SESSION['show_warning_msg'] = str_replace("{domain}", $this->dataRecord["domain"], $lng_text);
$data = new tform_actions();
$tform = $app->tform;
$app->tform = new tform();
$app->tform->loadFormDef("../dns/form/dns_soa.tform.php");
$data->oldDataRecord = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE origin LIKE '".$this->dataRecord['domain'].".'");
if ($data->oldDataRecord) {
$data->dataRecord = array_merge($data->oldDataRecord, array('client_group_id' => $this->dataRecord["client_group_id"]));
$data->id = $data->dataRecord['id'];
$app->plugin->raiseEvent("dns:dns_soa:on_after_update", $data);
}
$app->tform->loadFormDef("../dns/form/dns_slave.tform.php");
$data->oldDataRecord = $app->db->queryOneRecord("SELECT * FROM dns_slave WHERE origin LIKE '".$this->dataRecord['domain'].".'");
if ($data->oldDataRecord) {
$data->dataRecord = array_merge($data->oldDataRecord, array('client_group_id' => $this->dataRecord["client_group_id"]));
$data->id = $data->dataRecord['id'];
$app->plugin->raiseEvent("dns:dns_slave:on_after_update", $data);
}
$app->tform->loadFormDef("../mail/form/mail_domain.tform.php");
$data->oldDataRecord = $app->db->queryOneRecord("SELECT * FROM mail_domain WHERE domain = '".$this->dataRecord['domain']."'");
if ($data->oldDataRecord) {
$data->dataRecord = array_merge($data->oldDataRecord, array('client_group_id' => $this->dataRecord["client_group_id"]));
$data->id = $data->dataRecord['domain_id'];
$app->plugin->raiseEvent("mail:mail_domain:on_after_update", $data);
}
$app->tform->loadFormDef("../sites/form/web_vhost_domain.tform.php");
$data->oldDataRecord = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain = '".$this->dataRecord['domain']."'");
if ($data->oldDataRecord) {
$data->dataRecord = array_merge($data->oldDataRecord, array('client_group_id' => $this->dataRecord["client_group_id"]));
$data->id = $data->dataRecord['domain_id'];
$app->plugin->raiseEvent("sites:web_vhost_domain:on_after_update", $data);
}
$app->tform = $tform;
}
}
......
......@@ -46,11 +46,6 @@ $app->auth->check_module_permissions('client');
$app->uses('listform_actions');
if(isset($_SESSION['show_warning_msg'])) {
$app->tpl->setVar('warning_msg', $_SESSION['show_warning_msg']);
unset($_SESSION['show_warning_msg']);
}
$app->listform_actions->SQLOrderBy = 'ORDER BY domain.domain';
$app->listform_actions->onLoad();
......
......@@ -4,16 +4,6 @@
<div class="panel panel_list_domain">
<div class="pnl_toolsarea">
<div>
<tmpl_if name='warning_msg'>
<div class="systemmonitor-state state-warning">
<div class="status"></div>
<div class="statusMsg">
{tmpl_var name='warning_msg'}
</div>
</div>
</tmpl_if>
</div>
<fieldset><legend>{tmpl_var name="toolsarea_head_txt"}</legend>
<div class="buttons">
<button class="button iconstxt icoAdd" type="button" onclick="loadContent('client/domain_edit.php');">
......
......@@ -218,47 +218,6 @@ class page_action extends tform_actions {
parent::onInsert();
}
function onAfterInsert() {
global $app, $conf;
// make sure that the record belongs to the client group and not the admin group when a dmin inserts it
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
$app->db->query("UPDATE dns_slave SET sys_groupid = $client_group_id WHERE id = ".$this->id);
}
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
$app->db->query("UPDATE dns_slave SET sys_groupid = $client_group_id WHERE id = ".$this->id);
}
}
function onAfterUpdate() {
global $app, $conf;
$tmp = $app->db->diffrec($this->oldDataRecord, $app->tform->getDataRecord($this->id));
// make sure that the record belongs to the client group and not the admin group when a dmin inserts it
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
$app->db->query("UPDATE dns_slave SET sys_groupid = $client_group_id WHERE id = ".$this->id);
}
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
$app->db->query("UPDATE dns_slave SET sys_groupid = $client_group_id WHERE id = ".$this->id);
}
//** When the client group has changed, change also the owner of the record if the owner is not the admin user
if($this->oldDataRecord["client_group_id"] != $this->dataRecord["client_group_id"] && $this->dataRecord["sys_userid"] != 1) {
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
$tmp = $app->db->queryOneREcord("SELECT userid FROM sys_user WHERE default_group = ".$client_group_id);
if($tmp["userid"] > 0) {
$app->db->query("UPDATE dns_slave SET sys_userid = ".$tmp["userid"]." WHERE id = ".$this->id);
}
}
}
}
$page = new page_action;
......
......@@ -269,25 +269,6 @@ function onSubmit() {
parent::onSubmit();
}
function onAfterInsert() {
global $app, $conf;
// make sure that the record belongs to the client group and not the admin group when a dmin inserts it
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
$app->db->query("UPDATE dns_soa SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE id = ".$this->id);
// And we want to update all rr records too, that belong to this record
$app->db->query("UPDATE dns_rr SET sys_groupid = $client_group_id WHERE zone = ".$this->id);
}
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
$app->db->query("UPDATE dns_soa SET sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE id = ".$this->id);
// And we want to update all rr records too, that belong to this record
$app->db->query("UPDATE dns_rr SET sys_groupid = $client_group_id WHERE zone = ".$this->id);
}
}
function onBeforeUpdate () {
global $app, $conf;
......@@ -305,42 +286,6 @@ function onBeforeUpdate () {
}
}
function onAfterUpdate() {
global $app, $conf;
$tmp = $app->db->diffrec($this->oldDataRecord, $app->tform->getDataRecord($this->id));
if($tmp['diff_num'] > 0) {
// Update the serial number of the SOA record
$soa = $app->db->queryOneRecord("SELECT serial FROM dns_soa WHERE id = ".$this->id);
$app->db->query("UPDATE dns_soa SET serial = '".$app->validate_dns->increase_serial($soa["serial"])."' WHERE id = ".$this->id);
}
// make sure that the record belongs to the client group and not the admin group when a dmin inserts it
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
$app->db->query("UPDATE dns_soa SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE id = ".$this->id);
// And we want to update all rr records too, that belong to this record
$app->db->query("UPDATE dns_rr SET sys_groupid = $client_group_id WHERE zone = ".$this->id);
}
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
$app->db->query("UPDATE dns_soa SET sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE id = ".$this->id);
// And we want to update all rr records too, that belong to this record
$app->db->query("UPDATE dns_rr SET sys_groupid = $client_group_id WHERE zone = ".$this->id);
}
//** When the client group has changed, change also the owner of the record if the owner is not the admin user
if($this->oldDataRecord["client_group_id"] != $this->dataRecord["client_group_id"] && $this->dataRecord["sys_userid"] != 1) {
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
$tmp = $app->db->queryOneREcord("SELECT userid FROM sys_user WHERE default_group = ".$client_group_id);
if($tmp["userid"] > 0) {
$app->db->query("UPDATE dns_soa SET sys_userid = ".$tmp["userid"]." WHERE id = ".$this->id);
$app->db->query("UPDATE dns_rr SET sys_userid = ".$tmp["userid"]." WHERE zone = ".$this->id);
}
}
}
}
$page = new page_action;
......
......@@ -261,24 +261,13 @@ class page_action extends tform_actions {
function onAfterInsert() {
global $app, $conf;
// make sure that the record belongs to the client group and not the admin group when a dmin inserts it
// also make sure that the user can not delete domain created by a admin
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
$app->db->query("UPDATE mail_domain SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE domain_id = ".$this->id);
}
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
$app->db->query("UPDATE mail_domain SET sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE domain_id = ".$this->id);
}
// Spamfilter policy
$policy_id = $app->functions->intval($this->dataRecord["policy"]);
if($policy_id > 0) {
$tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = '@".$app->db->quote($this->dataRecord["domain"])."'");
if($tmp_user["id"] > 0) {
// There is already a record that we will update
$app->db->datalogUpdate('spamfilter_users', "policy_id = $ploicy_id", 'id', $tmp_user["id"]);
$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
......@@ -287,7 +276,7 @@ class page_action extends tform_actions {
$app->db->datalogInsert('spamfilter_users', $insert_data, 'id');
unset($tmp_domain);
}
} // endif spamfilter policy
} // endif spamfilter policy
}
function onBeforeUpdate() {
......@@ -316,26 +305,9 @@ class page_action extends tform_actions {
}
}
function onAfterUpdate() {
global $app, $conf;
// make sure that the record belongs to the client group and not the admin group when admin inserts it
// also make sure that the user can not delete domain created by a admin
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
$tmp = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE default_group = $client_group_id");
$client_user_id = ($tmp['userid'] > 0)?$tmp['userid']:1;
$app->db->query("UPDATE mail_domain SET sys_userid = $client_user_id, sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE domain_id = ".$this->id);
}
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
$tmp = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE default_group = $client_group_id");
$client_user_id = ($tmp['userid'] > 0)?$tmp['userid']:1;