From 847efb317dac770687d19b8e907d2e7cfd1de0c7 Mon Sep 17 00:00:00 2001 From: opensides Date: Wed, 22 Aug 2007 17:14:55 +0000 Subject: [PATCH] - new version of the ssh plugin - some more cleanup to come git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@7116 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/admin/systems/class_servSsh.inc | 169 ++++++++++++------------ plugins/admin/systems/servssh.tpl | 12 +- 2 files changed, 92 insertions(+), 89 deletions(-) diff --git a/plugins/admin/systems/class_servSsh.inc b/plugins/admin/systems/class_servSsh.inc index a3c03c053..7b9edeca7 100644 --- a/plugins/admin/systems/class_servSsh.inc +++ b/plugins/admin/systems/class_servSsh.inc @@ -25,69 +25,88 @@ class servssh extends plugin var $plHeadline= "SSH systems keys"; var $plDescription= "This plugin store ssh public keys for systems"; - var $sshPublickey = ""; - var $ignore_account= TRUE; + var $sshPublicKey = ""; + var $ignore_account= FALSE; /* attribute list for save action */ - var $attributes= array("sshPublickey"); - var $objectclasses= array("HostldapPublicKey"); + var $attributes = array("sshPublicKey"); + var $objectclasses = array("HostldapPublicKey"); var $uid =""; + /* Used to remember if this was an account (simply: is this an edited entry) */ + var $initialy_was_account = false; + function servssh ($config, $dn= NULL, $parent= NULL) { plugin::plugin ($config, $dn, $parent); - /* Always is account... */ - $this->is_account= TRUE; + /* Copy needed attributes */ + foreach($this->attributes as $val) { + $name = preg_replace('/_/', '-', $val); + if (isset($this->attrs["$name"][0])) { + $this->$val = $this->attrs["$name"][0]; + } + } + + $this->is_account = false; + $this->initially_was_account = false; + + if(isset($this->attrs['sshPublicKey'])) { + $this->is_account = true; + $this->initially_was_account = true; + } + + } function execute() { - /* Call parent execute */ - plugin::execute(); + /* Call parent execute */ + plugin::execute(); - /* Show main page */ + /* Fill templating stuff + */ $smarty= get_smarty(); - - /* Load attributes */ - foreach($this->attributes as $attr){ - $smarty->assign("$attr", $this->$attr); - $smarty->assign($attr."ACL", chkacl($this->acl, "$attr")); + $display= ""; + + /* Do we need to flip is_account state? + */ + if (isset($_POST['modify_state'])){ + + /* Only change account state if allowed */ + if($this->is_account && $this->acl == "#all#"){ + $this->is_account= !$this->is_account; + $this->is_modified = true; + }elseif(!$this->is_account && chkacl($this->acl,"create") == ""){ + $this->is_account= !$this->is_account; + $this->is_modified = true; + } } - $smarty->assign("sstate", ""); if ($this->is_account){ - $smarty->assign("sshState", "checked"); - $smarty->assign("sstate", ""); + $display= $this->show_header(_("Remove SSH keys"), + _("This server has SSH features enabled. You can disable them by clicking below.")); } else { - $smarty->assign("sshState", ""); - if($_SESSION['js']==1){ - if($this->acl!="#none#") - $smarty->assign("sstate", "disabled"); - }else{ - $smarty->assign("sstate", ""); - } - } - - /* Allow account status toogle? */ - $smarty->assign("sshACL", "disabled"); - if(!$this->is_account && chkacl($this->acl,"create") == ""){ - $smarty->assign("sshACL", ""); - }elseif($this->is_account && $this->acl == "#all#" ){ - $smarty->assign("sshACL", ""); + $display= $this->show_header(_("Add SSH keys"), + _("This server has SSH features disabled. You can enable them by clicking below.")); + return ($display); } - $changeState = ""; + /* Load attributes */ foreach($this->attributes as $attr){ - $smarty->assign($attr."ACL",chkacl($this->acl,$attr)); - if(chkacl($this->acl,$attr)==""){ - $changeState .= "changeState('".$attr."');\n"; - } + $smarty->assign("$attr", $this->$attr); + $smarty->assign($attr."ACL", chkacl($this->acl, "$attr")); } - $smarty->assign("changeState",$changeState); - return($smarty->fetch (get_template_path('servssh.tpl', TRUE))); + + $smarty->assign("sshPublicKeyACL",chkacl($this->acl,"sshPublicKey")); + + /* Display tempalte + */ + //$smarty->assign("ZoneList",$ZoneList->DrawList()); + $display.= $smarty->fetch(get_template_path('servssh.tpl', TRUE)); + return($display); } @@ -99,66 +118,35 @@ class servssh extends plugin } plugin::remove_from_parent(); + $ldap= $this->config->get_ldap_link(); $ldap->cd($this->dn); - @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, - $this->attributes, "Save"); $this->cleanup(); - $ldap->modify ($this->attrs); + +// $this->attrs['sshPublicKey']=""; + + $ldap->modify ($this->attrs); show_ldap_error($ldap->get_error(), _("Removing SSH account failed")); /* Optionally execute a command after we're done */ - $this->handle_post_events('remove',array("uid" => $this->uid)); +// $this->handle_post_events('remove',array("uid" => $this->uid)); } /* Save data to object */ function save_object() { - /* Do we need to flip is_account state? */ - if (isset($_POST['connectivityTab'])){ - - /* Change state if needed */ - if(!$this->is_account && isset($_POST["ssh"]) && chkacl($this->acl,"create") == ""){ - $this->is_account = true; - }elseif($this->is_account && !isset($_POST["ssh"]) && $this->acl == "#all#"){ - $this->is_account = false; - } - } - - plugin::save_object(); - - #FIXME seams to be unused code ! - #if (isset($_POST["sshStatus"])){ - # $this->sshStatus = "disabled"; - #} else { - # $this->sshStatus = "enabled"; - #} - } - - /* Check values */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - - /* Check for positive integer values */ - /* if ($this->is_account){ - if ((!is_id($this->sshPublickey))&&(chkacl($this->acl,"sshPublickey")=="")){ - $message[]= _("Value specified as 'SSH Key' is not valid."); - } - }*/ - - return $message; - } + plugin::save_object(); + } /* Save to LDAP */ function save() { - plugin::save(); + plugin::save(); + foreach($this->attributes as $attr){ if(chkacl($this->acl,$attr)!=""){ @@ -166,13 +154,14 @@ class servssh extends plugin } } + /* Write back to ldap */ $ldap= $this->config->get_ldap_link(); $ldap->cd($this->dn); $this->cleanup(); $ldap->modify ($this->attrs); - show_ldap_error($ldap->get_error(), _("Saving SSH account failed")); + show_ldap_error($ldap->get_error(), _("Saving SSH key failed")); /* Optionally execute a command after we're done */ if ($this->initially_was_account == $this->is_account){ @@ -186,5 +175,23 @@ class servssh extends plugin } + + /* Check values */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + /* Check for positive integer values */ + /* if ($this->is_account){ + if ((!is_id($this->sshPublickey))&&(chkacl($this->acl,"sshPublickey")=="")){ + $message[]= _("Value specified as 'SSH Key' is not valid."); + } + }*/ + + return $message; + } + + // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/plugins/admin/systems/servssh.tpl b/plugins/admin/systems/servssh.tpl index a8c14a6e3..fed48d2aa 100644 --- a/plugins/admin/systems/servssh.tpl +++ b/plugins/admin/systems/servssh.tpl @@ -1,9 +1,3 @@ -

- - {t}SSH account{/t} -

- @@ -12,16 +6,18 @@
+
-
+ + -- 2.30.2