Skip to content

Commit d08b278

Browse files
committed
#4961 modified remote API client edit to include lock and cancel, functions moved from client_edit to functions
1 parent c40198b commit d08b278

File tree

3 files changed

+134
-117
lines changed

3 files changed

+134
-117
lines changed

interface/lib/classes/functions.inc.php

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

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

533648
?>

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 = functions::func_client_cancel($client_id, $params['canceled']);
250+
}
251+
// if locked
252+
if ($params['locked']) {
253+
$result = functions::func_client_lock($client_id, $params['locked']);
254+
}
246255

247256
return $affected_rows;
248257
}

interface/web/client/client_edit.php

Lines changed: 10 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -425,123 +425,16 @@ function onAfterUpdate() {
425425
$app->db->query($sql, $password, $client_id);
426426
}
427427

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

546439
// language changed
547440
if(isset($conf['demo_mode']) && $conf['demo_mode'] != true && isset($this->dataRecord['language']) && $this->dataRecord['language'] != '' && $this->oldDataRecord['language'] != $this->dataRecord['language']) {

0 commit comments

Comments
 (0)