Code

Added status flag fix
[gosa.git] / plugins / admin / systems / class_goKrbServer.inc
1 <?php
3 class goKrbServer extends plugin{
4         
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";
13  
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  ="";  
25  
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     $flag = $this->StatusFlag;
47     $fields['Status']      = $this->$flag;
48     $fields['Message']    = _("Kerberos kadmin access informations");
49     $fields['AllowStart'] = true;
50     $fields['AllowStop']  = true;
51     $fields['AllowRestart'] = true;
52     $fields['AllowRemove']= true;
53     $fields['AllowEdit']  = true;
54     return($fields);
55   }
58   function remove_from_parent()
59   {
60     plugin::remove_from_parent();
61     /* Check if this is a new entry ... add/modify */
62     $ldap = $this->config->get_ldap_link();
63     $ldap->cat($this->dn,array("objectClass"));
64     if($ldap->count()){
65       $ldap->cd($this->dn);
66       $ldap->modify($this->attrs);
67     }else{
68       $ldap->cd($this->dn);
69       $ldap->add($this->attrs);
70     }
71     show_ldap_error($ldap->get_error());
72     $this->handle_post_events("remove");
73   }
76   function save()
77   {
78     plugin::save();
79     /* Check if this is a new entry ... add/modify */
80     $ldap = $this->config->get_ldap_link();
81     $ldap->cat($this->dn,array("objectClass"));
82     if($ldap->count()){
83       $ldap->cd($this->dn);
84       $ldap->modify($this->attrs);
85     }else{
86       $ldap->cd($this->dn);
87       $ldap->add($this->attrs);
88     }
89     show_ldap_error($ldap->get_error());
90     if($this->initially_was_account){
91       $this->handle_post_events("modify");
92     }else{
93       $this->handle_post_events("add");
94     }
95   }
98   /* Directly save new status flag */
99   function setStatus($value)
100   {
101     if($value == "none") return;
102     if(!$this->initially_was_account) return;
103     $ldap = $this->config->get_ldap_link();
104     $ldap->cd($this->dn);
105     $ldap->cat($this->dn,array("objectClass"));
106     if($ldap->count()){
108       $tmp = $ldap->fetch();
109       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
110         $attrs['objectClass'][] = $tmp['objectClass'][$i];
111       }
112       $flag = $this->StatusFlag;
113       $attrs[$flag] = $value;
114       $this->$flag = $value;
115       $ldap->modify($attrs);
116       show_ldap_error($ldap->get_error());
117       $this->action_hook();
118     }
119   }
120  
121  
122   function check()
123   { 
124     $message = plugin::check();
125     /* goKrbPassword is a must field, if goKrbServer is used as objectClass */
126     if (empty($this->goKrbPassword)){
127       $message[]= sprintf(_("The specified kerberos password is empty."), $attr);
128     }
129     if (empty($this->goKrbAdmin)){
130       $message[]= sprintf(_("The specified kerberos admin is empty."), $attr);
131     }
132     if (empty($this->goKrbRealm)){
133       $message[]= sprintf(_("The specified kerberos realm is empty."), $attr);
134     }
136     return($message);
137   }
138   
140   function save_object()
141   {
142     if(isset($_POST['goKrbServerPosted'])){
143       plugin::save_object();
144     }
145   } 
147    function action_hook($add_attrs= array())
148   {
149     /* Find postcreate entries for this class */
150     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
151     if ($command == "" && isset($this->config->data['TABS'])){
152       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
153     }
154     if ($command != ""){
155       /* Walk through attribute list */
156       foreach ($this->attributes as $attr){
157         if (!is_array($this->$attr)){
158           $command= preg_replace("/%$attr/", $this->$attr, $command);
159         }
160       }
161       $command= preg_replace("/%dn/", $this->dn, $command);
162       /* Additional attributes */
163       foreach ($add_attrs as $name => $value){
164         $command= preg_replace("/%$name/", $value, $command);
165       }
167       /* If there are still some %.. in our command, try to fill these with some other class vars */
168       if(preg_match("/%/",$command)){
169         $attrs = get_object_vars($this);
170         foreach($attrs as $name => $value){
171           if(!is_string($value)) continue;
172           $command= preg_replace("/%$name/", $value, $command);
173         }
174       }
176       if (check_command($command)){
177         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
178             $command, "Execute");
180         exec($command);
181       } else {
182         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
183         print_red ($message);
184       }
185     }
186   }
187  
189 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
190 ?>