Skip to content

Commit 2be5c1c

Browse files
author
Marius Burkard
committed
Merge branch '4961-lock-and-cancel-user-via-API' into 'develop'
#4961 modified remote API client edit to include lock and cancel, functions... Closes #4961 See merge request ispconfig/ispconfig3!1453
2 parents 4d5be50 + 7bd07c0 commit 2be5c1c

File tree

3 files changed

+127
-113
lines changed

3 files changed

+127
-113
lines changed

interface/lib/classes/functions.inc.php

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,117 @@ public function check_language($language) {
528528
}
529529
}
530530

531+
// Function to lock a client
532+
public function func_client_lock($client_id,$locked) {
533+
global $app;
534+
$client_data = $app->db->queryOneRecord('SELECT `tmp_data` FROM `client` WHERE `client_id` = ?', $client_id);
535+
if($client_data['tmp_data'] == '') $tmp_data = array();
536+
else $tmp_data = unserialize($client_data['tmp_data']);
537+
if(!is_array($tmp_data)) $tmp_data = array();
538+
$to_disable = array('cron' => 'id',
539+
'ftp_user' => 'ftp_user_id',
540+
'mail_domain' => 'domain_id',
541+
'mail_user' => 'mailuser_id',
542+
'mail_user_smtp' => 'mailuser_id',
543+
'mail_forwarding' => 'forwarding_id',
544+
'mail_get' => 'mailget_id',
545+
'openvz_vm' => 'vm_id',
546+
'shell_user' => 'shell_user_id',
547+
'webdav_user' => 'webdav_user_id',
548+
'web_database' => 'database_id',
549+
'web_domain' => 'domain_id',
550+
'web_folder' => 'web_folder_id',
551+
'web_folder_user' => 'web_folder_user_id'
552+
);
553+
$udata = $app->db->queryOneRecord('SELECT `userid` FROM `sys_user` WHERE `client_id` = ?', $client_id);
554+
$gdata = $app->db->queryOneRecord('SELECT `groupid` FROM `sys_group` WHERE `client_id` = ?', $client_id);
555+
$sys_groupid = $gdata['groupid'];
556+
$sys_userid = $udata['userid'];
557+
if($locked == 'y') {
558+
$prev_active = array();
559+
$prev_sysuser = array();
560+
foreach($to_disable as $current => $keycolumn) {
561+
$active_col = 'active';
562+
$reverse = false;
563+
if($current == 'mail_user') {
564+
$active_col = 'postfix';
565+
} elseif($current == 'mail_user_smtp') {
566+
$current = 'mail_user';
567+
$active_col = 'disablesmtp';
568+
$reverse = true;
569+
}
570+
571+
if(!isset($prev_active[$current])) $prev_active[$current] = array();
572+
if(!isset($prev_sysuser[$current])) $prev_sysuser[$current] = array();
573+
574+
$entries = $app->db->queryAllRecords('SELECT ?? as `id`, `sys_userid`, ?? FROM ?? WHERE `sys_groupid` = ?', $keycolumn, $active_col, $current, $sys_groupid);
575+
foreach($entries as $item) {
576+
577+
if($item[$active_col] != 'y' && $reverse == false) $prev_active[$current][$item['id']][$active_col] = 'n';
578+
elseif($item[$active_col] == 'y' && $reverse == true) $prev_active[$current][$item['id']][$active_col] = 'y';
579+
if($item['sys_userid'] != $sys_userid) $prev_sysuser[$current][$item['id']] = $item['sys_userid'];
580+
// we don't have to store these if y, as everything without previous state gets enabled later
581+
582+
//$app->db->datalogUpdate($current, array($active_col => ($reverse == true ? 'y' : 'n'), 'sys_userid' => $_SESSION["s"]["user"]["userid"]), $keycolumn, $item['id']);
583+
$app->db->datalogUpdate($current, array($active_col => ($reverse == true ? 'y' : 'n'), 'sys_userid' => $sys_userid), $keycolumn, $item['id']);
584+
}
585+
}
586+
587+
$tmp_data['prev_active'] = $prev_active;
588+
$tmp_data['prev_sys_userid'] = $prev_sysuser;
589+
$app->db->query("UPDATE `client` SET `tmp_data` = ? WHERE `client_id` = ?", serialize($tmp_data), $client_id);
590+
unset($prev_active);
591+
unset($prev_sysuser);
592+
} elseif ($locked == 'n') {
593+
foreach($to_disable as $current => $keycolumn) {
594+
$active_col = 'active';
595+
$reverse = false;
596+
if($current == 'mail_user') {
597+
$active_col = 'postfix';
598+
} elseif($current == 'mail_user_smtp') {
599+
$current = 'mail_user';
600+
$active_col = 'disablesmtp';
601+
$reverse = true;
602+
}
603+
604+
$entries = $app->db->queryAllRecords('SELECT ?? as `id` FROM ?? WHERE `sys_groupid` = ?', $keycolumn, $current, $sys_groupid);
605+
foreach($entries as $item) {
606+
$set_active = ($reverse == true ? 'n' : 'y');
607+
$set_inactive = ($reverse == true ? 'y' : 'n');
608+
$set_sysuser = $sys_userid;
609+
if(array_key_exists('prev_active', $tmp_data) == true
610+
&& array_key_exists($current, $tmp_data['prev_active']) == true
611+
&& array_key_exists($item['id'], $tmp_data['prev_active'][$current]) == true
612+
&& $tmp_data['prev_active'][$current][$item['id']][$active_col] == $set_inactive) $set_active = $set_inactive;
613+
if(array_key_exists('prev_sysuser', $tmp_data) == true
614+
&& array_key_exists($current, $tmp_data['prev_sysuser']) == true
615+
&& array_key_exists($item['id'], $tmp_data['prev_sysuser'][$current]) == true
616+
&& $tmp_data['prev_sysuser'][$current][$item['id']] != $sys_userid) $set_sysuser = $tmp_data['prev_sysuser'][$current][$item['id']];
617+
$app->db->datalogUpdate($current, array($active_col => $set_active, 'sys_userid' => $set_sysuser), $keycolumn, $item['id']);
618+
}
619+
}
620+
if(array_key_exists('prev_active', $tmp_data)) unset($tmp_data['prev_active']);
621+
$app->db->query("UPDATE `client` SET `tmp_data` = ? WHERE `client_id` = ?", serialize($tmp_data), $client_id);
622+
}
623+
unset($tmp_data);
624+
unset($entries);
625+
unset($to_disable);
626+
}
627+
// Function to cancel disable/enable a client
628+
public function func_client_cancel($client_id,$cancel) {
629+
global $app;
630+
if ($cancel == 'y') {
631+
$sql = "UPDATE sys_user SET active = '0' WHERE client_id = ?";
632+
$result = $app->db->query($sql, $client_id);
633+
} elseif($cancel == 'n') {
634+
$sql = "UPDATE sys_user SET active = '1' WHERE client_id = ?";
635+
$result = $app->db->query($sql, $client_id);
636+
} else {
637+
$result = false;
638+
}
639+
return $result;
640+
}
641+
531642
}
532643

533644
?>

interface/lib/classes/remote.d/client.inc.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,15 @@ public function client_update($session_id, $client_id, $reseller_id, $params)
243243
$affected_rows = $this->updateQuery('../client/form/' . (isset($params['limit_client']) && $params['limit_client'] != 0 ? 'reseller' : 'client') . '.tform.php', $reseller_id, $client_id, $params, 'client:' . ($reseller_id ? 'reseller' : 'client') . ':on_after_update');
244244

245245
$app->remoting_lib->ispconfig_sysuser_update($params, $client_id);
246+
247+
// if canceled
248+
if ($params['canceled']) {
249+
$result = $app->functions->func_client_cancel($client_id, $params['canceled']);
250+
}
251+
// if locked
252+
if ($params['locked']) {
253+
$result = $app->functions->func_client_lock($client_id, $params['locked']);
254+
}
246255

247256
return $affected_rows;
248257
}

interface/web/client/client_edit.php

Lines changed: 7 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -434,122 +434,16 @@ function onAfterUpdate() {
434434
$app->db->query($sql, $password, $client_id);
435435
}
436436

437-
if(!isset($this->dataRecord['locked'])) $this->dataRecord['locked'] = 'n';
438-
if(isset($conf['demo_mode']) && $conf['demo_mode'] != true && $this->dataRecord["locked"] != $this->oldDataRecord['locked']) {
439-
/** lock all the things like web, mail etc. - easy to extend */
440-
441-
442-
// get tmp_data of client
443-
$client_data = $app->db->queryOneRecord('SELECT `tmp_data` FROM `client` WHERE `client_id` = ?', $this->id);
444-
445-
if($client_data['tmp_data'] == '') $tmp_data = array();
446-
else $tmp_data = unserialize($client_data['tmp_data']);
447-
448-
if(!is_array($tmp_data)) $tmp_data = array();
449-
450-
// database tables with their primary key columns
451-
$to_disable = array('cron' => 'id',
452-
'ftp_user' => 'ftp_user_id',
453-
'mail_domain' => 'domain_id',
454-
'mail_user' => 'mailuser_id',
455-
'mail_user_smtp' => 'mailuser_id',
456-
'mail_forwarding' => 'forwarding_id',
457-
'mail_get' => 'mailget_id',
458-
'openvz_vm' => 'vm_id',
459-
'shell_user' => 'shell_user_id',
460-
'webdav_user' => 'webdav_user_id',
461-
'web_database' => 'database_id',
462-
'web_domain' => 'domain_id',
463-
'web_folder' => 'web_folder_id',
464-
'web_folder_user' => 'web_folder_user_id'
465-
);
466-
467-
$udata = $app->db->queryOneRecord('SELECT `userid` FROM `sys_user` WHERE `client_id` = ?', $this->id);
468-
$gdata = $app->db->queryOneRecord('SELECT `groupid` FROM `sys_group` WHERE `client_id` = ?', $this->id);
469-
$sys_groupid = $gdata['groupid'];
470-
$sys_userid = $udata['userid'];
471-
472-
$entries = array();
473-
if($this->dataRecord['locked'] == 'y') {
474-
$prev_active = array();
475-
$prev_sysuser = array();
476-
foreach($to_disable as $current => $keycolumn) {
477-
$active_col = 'active';
478-
$reverse = false;
479-
if($current == 'mail_user') {
480-
$active_col = 'postfix';
481-
} elseif($current == 'mail_user_smtp') {
482-
$current = 'mail_user';
483-
$active_col = 'disablesmtp';
484-
$reverse = true;
485-
}
486-
487-
if(!isset($prev_active[$current])) $prev_active[$current] = array();
488-
if(!isset($prev_sysuser[$current])) $prev_sysuser[$current] = array();
489-
490-
$entries = $app->db->queryAllRecords('SELECT ?? as `id`, `sys_userid`, ?? FROM ?? WHERE `sys_groupid` = ?', $keycolumn, $active_col, $current, $sys_groupid);
491-
foreach($entries as $item) {
492-
493-
if($item[$active_col] != 'y' && $reverse == false) $prev_active[$current][$item['id']][$active_col] = 'n';
494-
elseif($item[$active_col] == 'y' && $reverse == true) $prev_active[$current][$item['id']][$active_col] = 'y';
495-
if($item['sys_userid'] != $sys_userid) $prev_sysuser[$current][$item['id']] = $item['sys_userid'];
496-
// we don't have to store these if y, as everything without previous state gets enabled later
497-
498-
$app->db->datalogUpdate($current, array($active_col => ($reverse == true ? 'y' : 'n'), 'sys_userid' => $_SESSION["s"]["user"]["userid"]), $keycolumn, $item['id']);
499-
}
500-
}
501-
502-
$tmp_data['prev_active'] = $prev_active;
503-
$tmp_data['prev_sys_userid'] = $prev_sysuser;
504-
$app->db->query("UPDATE `client` SET `tmp_data` = ? WHERE `client_id` = ?", serialize($tmp_data), $this->id);
505-
unset($prev_active);
506-
unset($prev_sysuser);
507-
} elseif($this->dataRecord['locked'] == 'n') {
508-
foreach($to_disable as $current => $keycolumn) {
509-
$active_col = 'active';
510-
$reverse = false;
511-
if($current == 'mail_user') {
512-
$active_col = 'postfix';
513-
} elseif($current == 'mail_user_smtp') {
514-
$current = 'mail_user';
515-
$active_col = 'disablesmtp';
516-
$reverse = true;
517-
}
518-
519-
$entries = $app->db->queryAllRecords('SELECT ?? as `id` FROM ?? WHERE `sys_groupid` = ?', $keycolumn, $current, $sys_groupid);
520-
foreach($entries as $item) {
521-
$set_active = ($reverse == true ? 'n' : 'y');
522-
$set_inactive = ($reverse == true ? 'y' : 'n');
523-
$set_sysuser = $sys_userid;
524-
if(array_key_exists('prev_active', $tmp_data) == true
525-
&& array_key_exists($current, $tmp_data['prev_active']) == true
526-
&& array_key_exists($item['id'], $tmp_data['prev_active'][$current]) == true
527-
&& $tmp_data['prev_active'][$current][$item['id']][$active_col] == $set_inactive) $set_active = $set_inactive;
528-
if(array_key_exists('prev_sysuser', $tmp_data) == true
529-
&& array_key_exists($current, $tmp_data['prev_sysuser']) == true
530-
&& array_key_exists($item['id'], $tmp_data['prev_sysuser'][$current]) == true
531-
&& $tmp_data['prev_sysuser'][$current][$item['id']] != $sys_userid) $set_sysuser = $tmp_data['prev_sysuser'][$current][$item['id']];
532-
533-
$app->db->datalogUpdate($current, array($active_col => $set_active, 'sys_userid' => $set_sysuser), $keycolumn, $item['id']);
534-
}
535-
}
536-
if(array_key_exists('prev_active', $tmp_data)) unset($tmp_data['prev_active']);
537-
$app->db->query("UPDATE `client` SET `tmp_data` = ? WHERE `client_id` = ?", serialize($tmp_data), $this->id);
538-
}
539-
unset($tmp_data);
540-
unset($entries);
541-
unset($to_disable);
542-
}
437+
// lock and cancel
438+
if(!isset($this->dataRecord['locked'])) $this->dataRecord['locked'] = 'n';
439+
if(isset($conf['demo_mode']) && $conf['demo_mode'] != true && $this->dataRecord["locked"] != $this->oldDataRecord['locked'])
440+
{
441+
$lock = $app->functions->func_client_lock($this->id,$this->dataRecord["locked"]);
442+
}
543443

544444
if(!isset($this->dataRecord['canceled'])) $this->dataRecord['canceled'] = 'n';
545445
if(isset($conf['demo_mode']) && $conf['demo_mode'] != true && $this->dataRecord["canceled"] != $this->oldDataRecord['canceled']) {
546-
if($this->dataRecord['canceled'] == 'y') {
547-
$sql = "UPDATE sys_user SET active = '0' WHERE client_id = ?";
548-
$app->db->query($sql, $this->id);
549-
} elseif($this->dataRecord['canceled'] == 'n') {
550-
$sql = "UPDATE sys_user SET active = '1' WHERE client_id = ?";
551-
$app->db->query($sql, $this->id);
552-
}
446+
$cancel = $app->functions->func_client_cancel($this->id,$this->dataRecord["canceled"]);
553447
}
554448

555449
// language changed

0 commit comments

Comments
 (0)