1 <?php
3 class goKrbServer extends plugin{
5 var $cli_summary = "This pluign is used within the ServerService Pluign \nand indicates that this server supports NTP service.";
6 var $cli_description = "Some longer text\nfor help";
7 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9 /* This plugin only writes its objectClass */
10 var $objectclasses = array("goKrbServer");
11 var $attributes = array("goKrbRealm", "goKrbAdmin","goKrbPassword");
12 var $StatusFlag = "goKrbServerStatus";
14 /* This class can't be assigned twice so it conflicts with itsself */
15 var $conflicts = array("goKrbServer");
17 var $DisplayName = "";
18 var $dn = NULL;
19 var $goKrbServerStatus= "";
20 var $acl;
21 var $cn ="";
22 var $goKrbRealm = "";
23 var $goKrbAdmin = "";
24 var $goKrbPassword ="";
26 function goKrbServer($config,$dn)
27 {
28 plugin::plugin($config,$dn);
29 $this->DisplayName = _("Kerberos service");
30 }
33 function execute()
34 {
35 $smarty = get_smarty();
36 foreach($this->attributes as $attr){
37 $smarty->assign($attr,$this->$attr);
38 $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
39 }
40 return($smarty->fetch(get_template_path("goKrbServer.tpl",TRUE,dirname(__FILE__))));
41 }
44 function getListEntry()
45 {
46 $this->updateStatusState();
47 $flag = $this->StatusFlag;
48 $fields['Status'] = $this->$flag;
49 $fields['Message'] = _("Kerberos kadmin access informations");
50 $fields['AllowStart'] = true;
51 $fields['AllowStop'] = true;
52 $fields['AllowRestart'] = true;
53 $fields['AllowRemove']= true;
54 $fields['AllowEdit'] = true;
55 return($fields);
56 }
59 function remove_from_parent()
60 {
61 plugin::remove_from_parent();
63 /* Remove status flag, it is not a memeber of
64 this->attributes, so ensure that it is deleted too */
65 if(!empty($this->StatusFlag)){
66 $this->attrs[$this->StatusFlag] = array();
67 }
69 /* Check if this is a new entry ... add/modify */
70 $ldap = $this->config->get_ldap_link();
71 $ldap->cat($this->dn,array("objectClass"));
72 if($ldap->count()){
73 $ldap->cd($this->dn);
74 $ldap->modify($this->attrs);
75 }else{
76 $ldap->cd($this->dn);
77 $ldap->add($this->attrs);
78 }
79 show_ldap_error($ldap->get_error(), sprintf(_("Removing server services/gokrb with dn '%s' failed."),$this->dn));
80 $this->handle_post_events("remove");
81 }
84 function save()
85 {
86 plugin::save();
87 /* Check if this is a new entry ... add/modify */
88 $ldap = $this->config->get_ldap_link();
89 $ldap->cat($this->dn,array("objectClass"));
90 if($ldap->count()){
91 $ldap->cd($this->dn);
92 $ldap->modify($this->attrs);
93 }else{
94 $ldap->cd($this->dn);
95 $ldap->add($this->attrs);
96 }
97 show_ldap_error($ldap->get_error(), sprintf(_("Saving server services/gokrb with dn '%s' failed."),$this->dn));
98 if($this->initially_was_account){
99 $this->handle_post_events("modify");
100 }else{
101 $this->handle_post_events("add");
102 }
103 }
106 /* Directly save new status flag */
107 function setStatus($value)
108 {
109 if($value == "none") return;
110 if(!$this->initially_was_account) return;
111 $ldap = $this->config->get_ldap_link();
112 $ldap->cd($this->dn);
113 $ldap->cat($this->dn,array("objectClass"));
114 if($ldap->count()){
116 $tmp = $ldap->fetch();
117 for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
118 $attrs['objectClass'][] = $tmp['objectClass'][$i];
119 }
120 $flag = $this->StatusFlag;
121 $attrs[$flag] = $value;
122 $this->$flag = $value;
123 $ldap->modify($attrs);
124 show_ldap_error($ldap->get_error(), sprintf(_("Set status flag for server services/gokrb with dn '%s' failed."),$this->dn));
125 $this->action_hook();
126 }
127 }
130 function check()
131 {
132 $message = plugin::check();
133 /* goKrbPassword is a must field, if goKrbServer is used as objectClass */
134 if (empty($this->goKrbPassword)){
135 $message[]= sprintf(_("The specified kerberos password is empty."), $attr);
136 }
137 if (empty($this->goKrbAdmin)){
138 $message[]= sprintf(_("The specified kerberos admin is empty."), $attr);
139 }
140 if (empty($this->goKrbRealm)){
141 $message[]= sprintf(_("The specified kerberos realm is empty."), $attr);
142 }
144 return($message);
145 }
148 function save_object()
149 {
150 if(isset($_POST['goKrbServerPosted'])){
151 plugin::save_object();
152 }
153 }
155 function action_hook($add_attrs= array())
156 {
157 /* Find postcreate entries for this class */
158 $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
159 if ($command == "" && isset($this->config->data['TABS'])){
160 $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
161 }
162 if ($command != ""){
163 /* Walk through attribute list */
164 foreach ($this->attributes as $attr){
165 if (!is_array($this->$attr)){
166 $command= preg_replace("/%$attr/", $this->$attr, $command);
167 }
168 }
169 $command= preg_replace("/%dn/", $this->dn, $command);
170 /* Additional attributes */
171 foreach ($add_attrs as $name => $value){
172 $command= preg_replace("/%$name/", $value, $command);
173 }
175 /* If there are still some %.. in our command, try to fill these with some other class vars */
176 if(preg_match("/%/",$command)){
177 $attrs = get_object_vars($this);
178 foreach($attrs as $name => $value){
179 if(!is_string($value)) continue;
180 $command= preg_replace("/%$name/", $value, $command);
181 }
182 }
184 if (check_command($command)){
185 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
186 $command, "Execute");
188 exec($command);
189 } else {
190 $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
191 print_red ($message);
192 }
193 }
194 }
197 /* Get updates for status flag */
198 function updateStatusState()
199 {
200 if(empty($this->StatusFlag)) return;
202 $attrs = array();
203 $flag = $this->StatusFlag;
204 $ldap = $this->config->get_ldap_link();
205 $ldap->cd($this->cn);
206 $ldap->cat($this->dn,array($flag));
207 if($ldap->count()){
208 $attrs = $ldap->fetch();
209 }
210 if(isset($attrs[$flag][0])){
211 $this->$flag = $attrs[$flag][0];
212 }
213 }
215 /* Return plugin informations for acl handling */
216 function plInfo()
217 {
218 return (array(
219 "plShortName" => _("Kerberos"),
220 "plDescription" => _("Kerberos service"),
221 "plSelfModify" => FALSE,
222 "plDepends" => array(),
223 "plPriority" => 0,
224 "plSection" => array("administration"),
225 "plCategory" => array("server"),
227 "plProvidedAcls"=> array(
228 "goKrbRealm" => _("Realm"),
229 "goKrbAdmin" => _("Admin"),
230 "goKrbPassword" => _("Password"))
231 ));
232 }
233 }
234 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
235 ?>