Code

removed debug output
[gosa.git] / plugins / admin / systems / class_goLdapServer.inc
1 <?php
3 class goLdapServer extends plugin{
5   var $cli_summary      = "This plugin is used within the ServerService Pluign \nand indicates that this server has goLdapServer defined.";
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("goLdapServer");
11   var $attributes       = array("goLdapBase");
12   var $StatusFlag       = "goLdapServerStatus";
14   /* This class can't be assigned twice so it conflicts with itsself */
15   var $conflicts        = array("goLdapServer");
17   var $DisplayName      = "";
18   var $dn               = NULL;
19   var $acl;
20   var $cn                  = "";
21   var $goLdapServerStatus  = "";
22   var $goLdapBase          = ""; 
24   function goLdapServer($config,$dn)
25   {
26     plugin::plugin($config,$dn);
27     $this->DisplayName = _("LDAP service");
28   }
31   function execute()
32   { 
33     $smarty = get_smarty(); 
34     foreach($this->attributes as $attr){
35       $smarty->assign($attr,$this->$attr);
36       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
37     }
38     return($smarty->fetch(get_template_path("goLdapServer.tpl",TRUE,dirname(__FILE__))));
39   }
42   function getListEntry()
43   {
44     $flag = $this->StatusFlag;
45     $fields['Status']     = $this->$flag;
46     $fields['Message']    = _("LDAP Service");
47     $fields['AllowStart'] = true;
48     $fields['AllowStop']  = true;
49     $fields['AllowRestart'] = true;
50     $fields['AllowRemove']= true;
51     $fields['AllowEdit']  = true;
52     return($fields);
53   }
56   function remove_from_parent()
57   {
58     plugin::remove_from_parent();
59     /* Check if this is a new entry ... add/modify */
60     $ldap = $this->config->get_ldap_link();
61     $ldap->cat($this->dn,array("objectClass"));
62     if($ldap->count()){
63       $ldap->cd($this->dn);
64       $ldap->modify($this->attrs);
65     }else{
66       $ldap->cd($this->dn);
67       $ldap->add($this->attrs);
68     }
69     show_ldap_error($ldap->get_error());
70     $this->handle_post_events("remove");
71   }
74   function save()
75   {
76     plugin::save();
77     /* Check if this is a new entry ... add/modify */
78     $ldap = $this->config->get_ldap_link();
79     $ldap->cat($this->dn,array("objectClass"));
80     if($ldap->count()){
81       $ldap->cd($this->dn);
82       $ldap->modify($this->attrs);
83     }else{
84       $ldap->cd($this->dn);
85       $ldap->add($this->attrs);
86     }
87     show_ldap_error($ldap->get_error());
88     if($this->initially_was_account){
89       $this->handle_post_events("modify");
90     }else{
91       $this->handle_post_events("add");
92     }
94   }
97   /* Directly save new status flag */
98   function setStatus($value)
99   {
100     if($value == "none") return;
101     if(!$this->initially_was_account) return;
102     $ldap = $this->config->get_ldap_link();
103     $ldap->cd($this->dn);
104     $ldap->cat($this->dn,array("objectClass"));
105     if($ldap->count()){
107       $tmp = $ldap->fetch();
108       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
109         $attrs['objectClass'][] = $tmp['objectClass'][$i];
110       }
111       $flag = $this->StatusFlag;
112       $attrs[$flag] = $value;
113       $this->$flag = $value;
114       $ldap->modify($attrs);
115       show_ldap_error($ldap->get_error());
116       $this->action_hook();
117     }
118   }
121   function check()
122   { 
123     $message = plugin::check();
124     if(empty($this->goLdapBase)){
125       $message[] = _("The given base is empty or contains invalid characters.");
126     }
127     return($message);
128   }
131   function save_object()
132   {
133     if(isset($_POST['goLdapServerPosted'])){
134       plugin::save_object();
135     }
136   } 
138   function action_hook($add_attrs= array())
139   {
140     /* Find postcreate entries for this class */
141     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
142     if ($command == "" && isset($this->config->data['TABS'])){
143       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
144     }
145     if ($command != ""){
146       /* Walk through attribute list */
147       foreach ($this->attributes as $attr){
148         if (!is_array($this->$attr)){
149           $command= preg_replace("/%$attr/", $this->$attr, $command);
150         }
151       }
152       $command= preg_replace("/%dn/", $this->dn, $command);
153       /* Additional attributes */
154       foreach ($add_attrs as $name => $value){
155         $command= preg_replace("/%$name/", $value, $command);
156       }
158       /* If there are still some %.. in our command, try to fill these with some other class vars */
159       if(preg_match("/%/",$command)){
160         $attrs = get_object_vars($this);
161         foreach($attrs as $name => $value){
162           if(!is_string($value)) continue;
163           $command= preg_replace("/%$name/", $value, $command);
164         }
165       }
167       if (check_command($command)){
168         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
169             $command, "Execute");
171         exec($command);
172       } else {
173         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
174         print_red ($message);
175       }
176     }
177   }
180 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
181 ?>