From a25cd652463a847493b4249bf4d1092fada175f6 Mon Sep 17 00:00:00 2001 From: opensides Date: Thu, 27 Mar 2008 21:23:49 +0000 Subject: [PATCH] - Moving thing around to get easiuer to package plugins git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5-plugins@10034 594d385d-05f5-0310-b6e9-bd551577e9d8 --- ssh/admin/systems/class_servSsh.inc | 191 ++++++++++++++++++++++++++++ ssh/admin/systems/servssh.tpl | 23 ++++ ssh/personal/ssh/class_ssh.inc | 191 ++++++++++++++++++++++++++++ ssh/personal/ssh/ssh.tpl | 37 ++++++ ssh/plugin.dsc | 5 + 5 files changed, 447 insertions(+) create mode 100644 ssh/admin/systems/class_servSsh.inc create mode 100644 ssh/admin/systems/servssh.tpl create mode 100644 ssh/personal/ssh/class_ssh.inc create mode 100644 ssh/personal/ssh/ssh.tpl create mode 100644 ssh/plugin.dsc diff --git a/ssh/admin/systems/class_servSsh.inc b/ssh/admin/systems/class_servSsh.inc new file mode 100644 index 000000000..1037fb4d4 --- /dev/null +++ b/ssh/admin/systems/class_servSsh.inc @@ -0,0 +1,191 @@ +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: +?> diff --git a/ssh/admin/systems/servssh.tpl b/ssh/admin/systems/servssh.tpl new file mode 100644 index 000000000..fed48d2aa --- /dev/null +++ b/ssh/admin/systems/servssh.tpl @@ -0,0 +1,23 @@ + + + + + + +
+ + + +
+ +
+
+ + + + + diff --git a/ssh/personal/ssh/class_ssh.inc b/ssh/personal/ssh/class_ssh.inc new file mode 100644 index 000000000..bb7fde8f0 --- /dev/null +++ b/ssh/personal/ssh/class_ssh.inc @@ -0,0 +1,191 @@ +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 template + */ + //$smarty->assign("ZoneList",$ZoneList->DrawList()); + $display.= $smarty->fetch(get_template_path('ssh.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: +?> diff --git a/ssh/personal/ssh/ssh.tpl b/ssh/personal/ssh/ssh.tpl new file mode 100644 index 000000000..bfc1c74f3 --- /dev/null +++ b/ssh/personal/ssh/ssh.tpl @@ -0,0 +1,37 @@ + + + + + +
+

{t}SSH Keys{/t}

+ + + + + + + +
+ {SSH Key} +
+ + + + + + + +
+

{t}SSH Key{/t}

+
+ + +
+
+
+
+ diff --git a/ssh/plugin.dsc b/ssh/plugin.dsc new file mode 100644 index 000000000..b127261f7 --- /dev/null +++ b/ssh/plugin.dsc @@ -0,0 +1,5 @@ +[gosa-plugin] +name = ssh +description = "Simple ssh key manager" +version = 2.5 +author = "Benoit Mortier " -- 2.30.2