From 9f1cb116349b6725f7c95e847abed432f71b358f Mon Sep 17 00:00:00 2001 From: hickert Date: Thu, 24 Apr 2008 08:05:38 +0000 Subject: [PATCH] Updated policy stuff for heimdal git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10663 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../services/kerberos/class_goKrbServer.inc | 174 +++++++++++++----- .../services/kerberos/class_krb5_policy.inc | 31 +++- .../systems/services/kerberos/krb5_policy.tpl | 31 ++-- 3 files changed, 167 insertions(+), 69 deletions(-) diff --git a/gosa-plugins/heimdal/admin/systems/services/kerberos/class_goKrbServer.inc b/gosa-plugins/heimdal/admin/systems/services/kerberos/class_goKrbServer.inc index 4887b9204..979da7f56 100644 --- a/gosa-plugins/heimdal/admin/systems/services/kerberos/class_goKrbServer.inc +++ b/gosa-plugins/heimdal/admin/systems/services/kerberos/class_goKrbServer.inc @@ -22,6 +22,7 @@ class goKrbServer extends goService{ var $view_logged = FALSE; var $policies = array(); + var $id = -1; function goKrbServer(&$config,$dn) { @@ -56,56 +57,27 @@ class goKrbServer extends goService{ Display sub dialogs *******/ - /* Add new Policy requested + /* CANCEL Policy dialog */ - if(isset($_POST['policy_add'])){ - $this->dialog = new krb5_policy($this->config,array()); - } - - - /* Walk through POSTs an check for image-button posts - */ - foreach($_POST as $name => $value){ - - /* Remove policy requested - */ - if(preg_match("/^policy_del/",$name)){ - $id = preg_replace("/^policy_del_([0-9]*)_.*/i","\\1",$name); - if(isset($this->policies[$id])){ - $this->policies[$id]['STATUS'] = "REMOVED"; - } - break; - } - - /* Edit Policy requested - */ - if(preg_match("/^policy_edit/",$name)){ - $id = preg_replace("/^policy_edit_([0-9]*)_.*/i","\\1",$name); - if(isset($this->policies[$id])){ - - /* Load policy information, if not done before - */ - if($this->policies[$id]['STATUS'] == "LOADED" && empty($this->policies[$id]['DATA'])){ - $o = new gosaSupportDaemon(); - $this->policies[$id]['DATA'] = $o->krb5_get_policy("00:01:6c:9d:aa:16",$this->policies[$id]['NAME']); - } - - /* Open dialog */ - $this->dialog = new krb5_policy($this->config,$this->policies[$id]); - } - break; - } - } - - if(isset($_POST['cancel_policy'])){ $this->dialog = NULL; } - if(isset($_POST['save_policy'])){ + + /* SAVE Policy dialog + */ + if($this->dialog instanceof krb5_policy && isset($_POST['save_policy'])){ $this->dialog->save_object(); - echo "NYI"; - $this->dialog = NULL; + $msgs = $this->dialog->check(); + if(count($msgs)){ + msg_dialog::displayChecks($msgs); + }else{ + $this->AddPolicy($this->id,$this->dialog->save()); + $this->dialog = NULL; + } } + + /* DISPLAY policy dialog + */ if($this->dialog instanceof krb5_policy){ $this->dialog->save_object(); return($this->dialog->execute()); @@ -128,6 +100,8 @@ class goKrbServer extends goService{ $action = ""; $action .= ""; foreach($this->policies as $key => $policy){ + if($policy['STATUS'] == "REMOVED") continue; + $actions = preg_replace("/%id/",$key,$action); $field1 = array("string" => $policy['NAME']); $field3 = array("string" => $actions, @@ -159,10 +133,122 @@ class goKrbServer extends goService{ } + + function AddPolicy($id,$policy) + { + if($id != -1 && $this->policies[$id]['NAME'] == $policy['NAME']){ + + /* Policy was edited + */ + if($this->policies[$id]['STATUS'] == "LOADED"){ + $policy['STATUS'] = "EDITED"; + }else{ + $policy['STATUS'] = $this->policies[$id]['STATUS']; + } + $this->policies[$this->id] = $policy; + + }elseif($id != -1 && $this->policies[$id]['NAME'] != $policy['NAME']){ + + /* Policy was renamed, remove old and add new policy + */ + $this->RemovePolicy($id); + $this->AddPolicy(-1,$policy); + }else{ + + /* Policy was added + */ + $name = $policy['NAME']; + + /* Check if there is already a policy with this name + which was removed before + */ + foreach($this->policies as $pid => $entry){ + if($entry['NAME'] == $name && $entry['STATUS'] == "REMOVED"){ + $id = $pid; + break; + } + } + + /* Update existing policy or create new one + */ + if(isset($this->policies[$id])){ + $policy['STATUS'] = "EDITED"; + $this->policies[$id] = $policy; + }else{ + $policy['STATUS'] = "ADDED"; + $this->policies[] = $policy; + } + } + } + + + function getPolicyNames() + { + $ret = array(); + foreach($this->policies as $policy){ + if($policy['STATUS'] == "REMOVED") continue; + $ret[] = $policy['NAME']; + } + return($ret); + } + + + function RemovePolicy($id) + { + if($this->policies[$id]['STATUS'] == "ADDED"){ + unset($this->policies[$id]); + }else{ + $this->policies[$id]['STATUS'] = "REMOVED"; + } + } + + function save_object() { if(isset($_POST['goKrbServerPosted'])){ plugin::save_object(); + + /* Add new Policy requested + */ + if(isset($_POST['policy_add'])){ + $this->dialog = new krb5_policy($this->config,array(),&$this); + $this->id = -1; + } + + /* Walk through POSTs an check for image-button posts + */ + foreach($_POST as $name => $value){ + + /* Remove policy requested + */ + if(preg_match("/^policy_del/",$name)){ + $id = preg_replace("/^policy_del_([0-9]*)_.*/i","\\1",$name); + if(isset($this->policies[$id])){ + $this->RemovePolicy($id); + } + break; + } + + /* Edit Policy requested + */ + if(preg_match("/^policy_edit/",$name)){ + $id = preg_replace("/^policy_edit_([0-9]*)_.*/i","\\1",$name); + if(isset($this->policies[$id])){ + + /* Load policy information, if not done before + */ + if($this->policies[$id]['STATUS'] == "LOADED" && empty($this->policies[$id]['DATA'])){ + $o = new gosaSupportDaemon(); + $this->policies[$id]['DATA'] = $o->krb5_get_policy("00:01:6c:9d:aa:16",$this->policies[$id]['NAME']); + } + + /* Open dialog */ + $this->id = $id; + $this->dialog = new krb5_policy($this->config,$this->policies[$id],&$this); + } + break; + } + } } } diff --git a/gosa-plugins/heimdal/admin/systems/services/kerberos/class_krb5_policy.inc b/gosa-plugins/heimdal/admin/systems/services/kerberos/class_krb5_policy.inc index 06479b7e1..18ee90b81 100644 --- a/gosa-plugins/heimdal/admin/systems/services/kerberos/class_krb5_policy.inc +++ b/gosa-plugins/heimdal/admin/systems/services/kerberos/class_krb5_policy.inc @@ -6,19 +6,22 @@ class krb5_policy extends plugin var $name = ""; var $data = array(); var $is_new = TRUE; - var $config; - var $attributes = array("MASK","POLICY","PW_HISTORY_NUM","PW_MAX_LIFE", - "PW_MIN_CLASSES","PW_MIN_LENGTH","PW_MIN_LIFE","REF_COUNT"); + var $init_name =""; + var $parent ; + var $config ; + var $attributes = array("MASK","POLICY_REFCNT","PW_HISTORY_NUM","PW_MAX_LIFE", + "PW_MIN_CLASSES","PW_MIN_LENGTH","PW_MIN_LIFE"); - public function __construct($config,$entry = array()) + public function __construct($config,$entry,$parent) { $this->config = $config; + $this->parent = $parent; if(count($entry)){ $this->is_new =FALSE; $this->name = $entry['NAME']; $this->data = $entry['DATA']; } - $this->init_name = $this->name; + $this->init_name = $this->name; } public function execute() @@ -26,6 +29,7 @@ class krb5_policy extends plugin $display = plugin::execute(); $smarty = get_smarty(); + $smarty->assign("name",$this->name); foreach($this->attributes as $attr){ $smarty->assign($attr,$this->data[$attr]); } @@ -36,6 +40,9 @@ class krb5_policy extends plugin public function save_object() { if(isset($_POST['Policy_Posted'])){ + if(isset($_POST['name'])){ + $this->name = get_post("name"); + } foreach($this->attributes as $attr){ if(isset($_POST[$attr])){ $this->data[$attr] = get_post($attr); @@ -43,12 +50,22 @@ class krb5_policy extends plugin } } } - + + + public function check() + { + $messages = array(); + $names = $this->parent->getPolicyNames(); + if($this->name != $this->init_name && in_array($this->name,$names)){ + $messages[] = msgPool::duplicated(_("Name")); + } + return($messages); + } + public function save() { $ret = array(); - $ret['INITIAL_NAME']= $this->init_name; $ret['NAME'] = $this->name; $ret['DATA'] = $this->data; return($ret); diff --git a/gosa-plugins/heimdal/admin/systems/services/kerberos/krb5_policy.tpl b/gosa-plugins/heimdal/admin/systems/services/kerberos/krb5_policy.tpl index 5284734cd..a33e643c8 100644 --- a/gosa-plugins/heimdal/admin/systems/services/kerberos/krb5_policy.tpl +++ b/gosa-plugins/heimdal/admin/systems/services/kerberos/krb5_policy.tpl @@ -1,39 +1,34 @@ - - - - - - + + - - + + - + - - + + - - + + - - + + - + - - +
{t}Mask{/t}
{t}POLICY{/t}{t}Policy name{/t}
{t}REF_COUNT{/t}{t}Mask{/t}
{t}PW_MIN_LENGTH{/t}{t}Password minimum length{/t}
{t}POLICY_REFCNT{/t}{t}Password history{/t}
{t}PW_HISTORY_NUM{/t}{t}Password minimum lifetime{/t}{t}seconds{/t}
{t}PW_MAX_LIFE{/t}{t}Password lifetime{/t}{t}seconds{/t}
{t}PW_MIN_CLASSES{/t}{t}Password min characters{/t}
{t}PW_MIN_LIFE{/t}{t}Number of principals referring to this policy{/t}: {$POLICY_REFCNT}
-- 2.30.2