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(); /* Fill templating stuff */ $smarty= get_smarty(); $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; } } if ($this->is_account){ $display= $this->show_header(_("Remove SSH keys"), _("This server has SSH features enabled. You can disable them by clicking below.")); } else { $display= $this->show_header(_("Add SSH keys"), _("This server has SSH features disabled. You can enable them by clicking below.")); return ($display); } /* Load attributes */ foreach($this->attributes as $attr){ $smarty->assign("$attr", $this->$attr); $smarty->assign($attr."ACL", chkacl($this->acl, "$attr")); } $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); } function remove_from_parent() { /* Cancel if there's nothing to do here */ if (!$this->initially_was_account){ return; } plugin::remove_from_parent(); $ldap= $this->config->get_ldap_link(); $ldap->cd($this->dn); $this->cleanup(); $ldap->modify ($this->attrs); show_ldap_error($ldap->get_error(), _("Removing SSH key failed")); /* Optionally execute a command after we're done */ // $this->handle_post_events('remove',array("uid" => $this->uid)); } /* Save data to object */ function save_object() { plugin::save_object(); } /* Check values */ function check() { /* Call common method to give check the hook */ $message = plugin::check(); /* Check for empty or not */ if(empty($this->sshPublicKey)){ $message[]= _("Value specified as 'SSH Key' is not valid."); } return($message); } /* Save to LDAP */ function save() { plugin::save(); foreach($this->attributes as $attr){ if(chkacl($this->acl,$attr)!=""){ unset($this->attrs[$attr]); } } /* 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 key failed")); /* Optionally execute a command after we're done */ if ($this->initially_was_account == $this->is_account){ if ($this->is_modified){ $this->handle_post_events("modify",array("uid" => $this->uid)); } } else { $this->handle_post_events("add",array("uid" => $this->uid)); } } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?>