Code

Fixed Translation Strings.
[gosa.git] / plugins / admin / systems / class_goSyslogServer.inc
1 <?php
3 class goSyslogServer extends plugin{
4         
5   var $cli_summary      = "This plugin is used within the ServerService Pluign \nand indicates that this server has syslog server enabled.";
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("goSyslogServer");
11   var $attributes       = array();
12   var $StatusFlag       = "goSyslogServerStatus";
13  
14   /* This class can't be assigned twice so it conflicts with itsself */
15   var $conflicts        = array("goSyslogServer");
17   var $DisplayName      = "";
18   var $dn               = NULL;
19   var $acl;
20   var $cn                    = "";
21   var $goSyslogServerStatus  = "";
22  
23   function goSyslogServer($config,$dn)
24   {
25     plugin::plugin($config,$dn);
26     $this->DisplayName = _("Logging service");
27   }
30   function execute()
31   { 
32     $smarty = get_smarty(); 
33     foreach($this->attributes as $attr){
34       $smarty->assign($attr,$this->$attr);
35       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
36     }
37     return($smarty->fetch(get_template_path("goSyslogServer.tpl",TRUE,dirname(__FILE__))));
38   }
41   function getListEntry()
42   {
43     $this->updateStatusState();
44     $flag = $this->StatusFlag;
45     $fields['Status']     = $this->$flag;
46     $fields['Message']    = _("Syslog service");
47     $fields['AllowStart'] = true;
48     $fields['AllowStop']  = true;
49     $fields['AllowRestart'] = true;
50     $fields['AllowRemove']= true;
51     $fields['AllowEdit']  = false;
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     }
93   }
96   /* Directly save new status flag */
97   function setStatus($value)
98   {
99     if($value == "none") return;
100     if(!$this->initially_was_account) return;
101     $ldap = $this->config->get_ldap_link();
102     $ldap->cd($this->dn);
103     $ldap->cat($this->dn,array("objectClass"));
104     if($ldap->count()){
106       $tmp = $ldap->fetch();
107       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
108         $attrs['objectClass'][] = $tmp['objectClass'][$i];
109       }
110       $flag = $this->StatusFlag;
111       $attrs[$flag] = $value;
112       $this->$flag = $value;
113       $ldap->modify($attrs);
114       show_ldap_error($ldap->get_error());
115       $this->action_hook();
116     }
117   }
120   function check()
121   { 
122     $message = plugin::check();
123     return($message);
124   }
127   function save_object()
128   {
129     plugin::save_object();
130   } 
133   function action_hook($add_attrs= array())
134   {
135     /* Find postcreate entries for this class */
136     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
137     if ($command == "" && isset($this->config->data['TABS'])){
138       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
139     }
140     if ($command != ""){
141       /* Walk through attribute list */
142       foreach ($this->attributes as $attr){
143         if (!is_array($this->$attr)){
144           $command= preg_replace("/%$attr/", $this->$attr, $command);
145         }
146       }
147       $command= preg_replace("/%dn/", $this->dn, $command);
148       /* Additional attributes */
149       foreach ($add_attrs as $name => $value){
150         $command= preg_replace("/%$name/", $value, $command);
151       }
153       /* If there are still some %.. in our command, try to fill these with some other class vars */
154       if(preg_match("/%/",$command)){
155         $attrs = get_object_vars($this);
156         foreach($attrs as $name => $value){
157           if(!is_string($value)) continue;
158           $command= preg_replace("/%$name/", $value, $command);
159         }
160       }
162       if (check_command($command)){
163         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
164             $command, "Execute");
166         exec($command);
167       } else {
168         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
169         print_red ($message);
170       }
171     }
172   }
174   
175   /* Get updates for status flag */
176   function updateStatusState()
177   {
178     if(empty($this->StatusFlag)) return;
180     $attrs = array();
181     $flag = $this->StatusFlag;
182     $ldap = $this->config->get_ldap_link();
183     $ldap->cd($this->cn);
184     $ldap->cat($this->dn,array($flag));
185     if($ldap->count()){
186       $attrs = $ldap->fetch();
187     }
188     if(isset($attrs[$flag][0])){
189       $this->$flag = $attrs[$flag][0];
190     }
191   }
194 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
195 ?>