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= TRUE;
31 /* attribute list for save action */
32 var $attributes= array("sshPublickey");
33 var $objectclasses= array("HostldapPublicKey");
35 var $uid ="";
37 function servssh ($config, $dn= NULL, $parent= NULL)
38 {
39 plugin::plugin ($config, $dn, $parent);
41 /* Always is account... */
42 $this->is_account= TRUE;
43 }
45 function execute()
46 {
47 /* Call parent execute */
48 plugin::execute();
50 /* Show main page */
51 $smarty= get_smarty();
53 /* Load attributes */
54 foreach($this->attributes as $attr){
55 $smarty->assign("$attr", $this->$attr);
56 $smarty->assign($attr."ACL", chkacl($this->acl, "$attr"));
57 }
59 $smarty->assign("sstate", "");
60 if ($this->is_account){
61 $smarty->assign("sshState", "checked");
62 $smarty->assign("sstate", "");
63 } else {
64 $smarty->assign("sshState", "");
65 if($_SESSION['js']==1){
66 if($this->acl!="#none#")
67 $smarty->assign("sstate", "disabled");
68 }else{
69 $smarty->assign("sstate", "");
70 }
71 }
73 /* Allow account status toogle? */
74 $smarty->assign("sshACL", "disabled");
75 if(!$this->is_account && chkacl($this->acl,"create") == ""){
76 $smarty->assign("sshACL", "");
77 }elseif($this->is_account && $this->acl == "#all#" ){
78 $smarty->assign("sshACL", "");
79 }
81 $changeState = "";
82 foreach($this->attributes as $attr){
83 $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
84 if(chkacl($this->acl,$attr)==""){
85 $changeState .= "changeState('".$attr."');\n";
86 }
87 }
88 $smarty->assign("changeState",$changeState);
90 return($smarty->fetch (get_template_path('servssh.tpl', TRUE)));
92 }
94 function remove_from_parent()
95 {
96 /* Cancel if there's nothing to do here */
97 if (!$this->initially_was_account){
98 return;
99 }
101 plugin::remove_from_parent();
102 $ldap= $this->config->get_ldap_link();
104 $ldap->cd($this->dn);
105 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
106 $this->attributes, "Save");
107 $this->cleanup();
108 $ldap->modify ($this->attrs);
110 show_ldap_error($ldap->get_error(), _("Removing SSH account failed"));
112 /* Optionally execute a command after we're done */
113 $this->handle_post_events('remove',array("uid" => $this->uid));
114 }
117 /* Save data to object */
118 function save_object()
119 {
120 /* Do we need to flip is_account state? */
121 if (isset($_POST['connectivityTab'])){
123 /* Change state if needed */
124 if(!$this->is_account && isset($_POST["ssh"]) && chkacl($this->acl,"create") == ""){
125 $this->is_account = true;
126 }elseif($this->is_account && !isset($_POST["ssh"]) && $this->acl == "#all#"){
127 $this->is_account = false;
128 }
129 }
131 plugin::save_object();
133 #FIXME seams to be unused code !
134 #if (isset($_POST["sshStatus"])){
135 # $this->sshStatus = "disabled";
136 #} else {
137 # $this->sshStatus = "enabled";
138 #}
139 }
141 /* Check values */
142 function check()
143 {
144 /* Call common method to give check the hook */
145 $message= plugin::check();
147 /* Check for positive integer values */
148 /* if ($this->is_account){
149 if ((!is_id($this->sshPublickey))&&(chkacl($this->acl,"sshPublickey")=="")){
150 $message[]= _("Value specified as 'SSH Key' is not valid.");
151 }
152 }*/
154 return $message;
155 }
157 /* Save to LDAP */
158 function save()
159 {
161 plugin::save();
163 foreach($this->attributes as $attr){
164 if(chkacl($this->acl,$attr)!=""){
165 unset($this->attrs[$attr]);
166 }
167 }
169 /* Write back to ldap */
170 $ldap= $this->config->get_ldap_link();
171 $ldap->cd($this->dn);
172 $this->cleanup();
173 $ldap->modify ($this->attrs);
175 show_ldap_error($ldap->get_error(), _("Saving SSH account failed"));
177 /* Optionally execute a command after we're done */
178 if ($this->initially_was_account == $this->is_account){
179 if ($this->is_modified){
180 $this->handle_post_events("modify",array("uid" => $this->uid));
181 }
182 } else {
183 $this->handle_post_events("add",array("uid" => $this->uid));
184 }
185 }
187 }
189 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
190 ?>