Code

2aa5a33ed0a939f765adc148bb979996ed66e210
[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     $flag = $this->StatusFlag;
44     $fields['Status']     = $this->$flag;
45     $fields['Message']    = _("Syslog service");
46     $fields['AllowStart'] = true;
47     $fields['AllowStop']  = true;
48     $fields['AllowRestart'] = true;
49     $fields['AllowRemove']= true;
50     $fields['AllowEdit']  = false;
51     return($fields);
52   }
55   function remove_from_parent()
56   {
57     plugin::remove_from_parent();
58     /* Check if this is a new entry ... add/modify */
59     $ldap = $this->config->get_ldap_link();
60     $ldap->cat($this->dn,array("objectClass"));
61     if($ldap->count()){
62       $ldap->cd($this->dn);
63       $ldap->modify($this->attrs);
64     }else{
65       $ldap->cd($this->dn);
66       $ldap->add($this->attrs);
67     }
68     show_ldap_error($ldap->get_error());
69     $this->handle_post_events("remove");
70   }
73   function save()
74   {
75     plugin::save();
76     /* Check if this is a new entry ... add/modify */
77     $ldap = $this->config->get_ldap_link();
78     $ldap->cat($this->dn,array("objectClass"));
79     if($ldap->count()){
80       $ldap->cd($this->dn);
81       $ldap->modify($this->attrs);
82     }else{
83       $ldap->cd($this->dn);
84       $ldap->add($this->attrs);
85     }
86     show_ldap_error($ldap->get_error());
87     if($this->initially_was_account){
88       $this->handle_post_events("modify");
89     }else{
90       $this->handle_post_events("add");
91     }
92   }
95   /* Directly save new status flag */
96   function setStatus($value)
97   {
98     if($value == "none") return;
99     if(!$this->initially_was_account) return;
100     $ldap = $this->config->get_ldap_link();
101     $ldap->cd($this->dn);
102     $ldap->cat($this->dn,array("objectClass"));
103     if($ldap->count()){
105       $tmp = $ldap->fetch();
106       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
107         $attrs['objectClass'][] = $tmp['objectClass'][$i];
108       }
109       $flag = $this->StatusFlag;
110       $attrs[$flag] = $value;
111       $this->$flag = $value;
112       $ldap->modify($attrs);
113       show_ldap_error($ldap->get_error());
114       $this->action_hook();
115     }
116   }
119   function check()
120   { 
121     $message = plugin::check();
122     return($message);
123   }
126   function save_object()
127   {
128     plugin::save_object();
129   } 
132   function action_hook($add_attrs= array())
133   {
134     /* Find postcreate entries for this class */
135     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
136     if ($command == "" && isset($this->config->data['TABS'])){
137       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
138     }
139     if ($command != ""){
140       /* Walk through attribute list */
141       foreach ($this->attributes as $attr){
142         if (!is_array($this->$attr)){
143           $command= preg_replace("/%$attr/", $this->$attr, $command);
144         }
145       }
146       $command= preg_replace("/%dn/", $this->dn, $command);
147       /* Additional attributes */
148       foreach ($add_attrs as $name => $value){
149         $command= preg_replace("/%$name/", $value, $command);
150       }
152       /* If there are still some %.. in our command, try to fill these with some other class vars */
153       if(preg_match("/%/",$command)){
154         $attrs = get_object_vars($this);
155         foreach($attrs as $name => $value){
156           if(!is_string($value)) continue;
157           $command= preg_replace("/%$name/", $value, $command);
158         }
159       }
161       if (check_command($command)){
162         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
163             $command, "Execute");
165         exec($command);
166       } else {
167         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
168         print_red ($message);
169       }
170     }
171   }
174 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
175 ?>