1 <?php
3 /*
4 This code is part of GOsa (https://gosa.gonicus.de)
5 Copyright (C) 2007 Benoit Mortier
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
22 class servssh extends plugin
23 {
24 /* Definitions */
25 var $plHeadline= "SSH systems keys";
26 var $plDescription= "This plugin store ssh public keys for systems";
28 var $sshPublicKey = "";
29 var $ignore_account= FALSE;
31 /* attribute list for save action */
32 var $attributes = array("sshPublicKey");
33 var $objectclasses = array("HostldapPublicKey");
35 var $uid ="";
37 /* Used to remember if this was an account (simply: is this an edited entry) */
38 var $initialy_was_account = false;
40 function servssh ($config, $dn= NULL, $parent= NULL)
41 {
42 plugin::plugin ($config, $dn, $parent);
44 /* Copy needed attributes */
45 foreach($this->attributes as $val) {
46 $name = preg_replace('/_/', '-', $val);
47 if (isset($this->attrs["$name"][0])) {
48 $this->$val = $this->attrs["$name"][0];
49 }
50 }
52 $this->is_account = false;
53 $this->initially_was_account = false;
55 if(isset($this->attrs['sshPublicKey'])) {
56 $this->is_account = true;
57 $this->initially_was_account = true;
58 }
61 }
63 function execute()
64 {
65 /* Call parent execute */
66 plugin::execute();
68 /* Fill templating stuff
69 */
70 $smarty= get_smarty();
71 $display= "";
73 /* Do we need to flip is_account state?
74 */
75 if (isset($_POST['modify_state'])){
77 /* Only change account state if allowed */
78 if($this->is_account && $this->acl == "#all#"){
79 $this->is_account= !$this->is_account;
80 $this->is_modified = true;
81 }elseif(!$this->is_account && chkacl($this->acl,"create") == ""){
82 $this->is_account= !$this->is_account;
83 $this->is_modified = true;
84 }
85 }
87 if ($this->is_account){
88 $display= $this->show_header(_("Remove SSH keys"),
89 _("This server has SSH features enabled. You can disable them by clicking below."));
90 } else {
91 $display= $this->show_header(_("Add SSH keys"),
92 _("This server has SSH features disabled. You can enable them by clicking below."));
93 return ($display);
94 }
96 /* Load attributes */
97 foreach($this->attributes as $attr){
98 $smarty->assign("$attr", $this->$attr);
99 $smarty->assign($attr."ACL", chkacl($this->acl, "$attr"));
100 }
103 $smarty->assign("sshPublicKeyACL",chkacl($this->acl,"sshPublicKey"));
105 /* Display tempalte
106 */
107 //$smarty->assign("ZoneList",$ZoneList->DrawList());
108 $display.= $smarty->fetch(get_template_path('servssh.tpl', TRUE));
109 return($display);
111 }
113 function remove_from_parent()
114 {
115 /* Cancel if there's nothing to do here */
116 if (!$this->initially_was_account){
117 return;
118 }
120 plugin::remove_from_parent();
122 $ldap= $this->config->get_ldap_link();
124 $ldap->cd($this->dn);
125 $this->cleanup();
127 $ldap->modify ($this->attrs);
129 show_ldap_error($ldap->get_error(), _("Removing SSH key failed"));
131 /* Optionally execute a command after we're done */
132 // $this->handle_post_events('remove',array("uid" => $this->uid));
133 }
136 /* Save data to object */
137 function save_object()
138 {
139 plugin::save_object();
140 }
142 /* Check values */
143 function check()
144 {
145 /* Call common method to give check the hook */
146 $message = plugin::check();
148 /* Check for empty or not */
149 if(empty($this->sshPublicKey)){
150 $message[]= _("Value specified as 'SSH Key' is not valid.");
151 }
153 return($message);
154 }
156 /* Save to LDAP */
157 function save()
158 {
160 plugin::save();
163 foreach($this->attributes as $attr){
164 if(chkacl($this->acl,$attr)!=""){
165 unset($this->attrs[$attr]);
166 }
167 }
170 /* Write back to ldap */
171 $ldap= $this->config->get_ldap_link();
172 $ldap->cd($this->dn);
173 $this->cleanup();
174 $ldap->modify ($this->attrs);
176 show_ldap_error($ldap->get_error(), _("Saving SSH key failed"));
178 /* Optionally execute a command after we're done */
179 if ($this->initially_was_account == $this->is_account){
180 if ($this->is_modified){
181 $this->handle_post_events("modify",array("uid" => $this->uid));
182 }
183 } else {
184 $this->handle_post_events("add",array("uid" => $this->uid));
185 }
186 }
188 }
190 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
191 ?>