1 <?php
3 class goSyslogServer extends plugin{
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";
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 = "";
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();
60 /* Remove status flag, it is not a memeber of
61 this->attributes, so ensure that it is deleted too */
62 if(!empty($this->StatusFlag)){
63 $this->attrs[$this->StatusFlag] = array();
64 }
66 /* Check if this is a new entry ... add/modify */
67 $ldap = $this->config->get_ldap_link();
68 $ldap->cat($this->dn,array("objectClass"));
69 if($ldap->count()){
70 $ldap->cd($this->dn);
71 $ldap->modify($this->attrs);
72 }else{
73 $ldap->cd($this->dn);
74 $ldap->add($this->attrs);
75 }
76 show_ldap_error($ldap->get_error());
77 $this->handle_post_events("remove");
78 }
81 function save()
82 {
83 plugin::save();
84 /* Check if this is a new entry ... add/modify */
85 $ldap = $this->config->get_ldap_link();
86 $ldap->cat($this->dn,array("objectClass"));
87 if($ldap->count()){
88 $ldap->cd($this->dn);
89 $ldap->modify($this->attrs);
90 }else{
91 $ldap->cd($this->dn);
92 $ldap->add($this->attrs);
93 }
94 show_ldap_error($ldap->get_error());
95 if($this->initially_was_account){
96 $this->handle_post_events("modify");
97 }else{
98 $this->handle_post_events("add");
99 }
100 }
103 /* Directly save new status flag */
104 function setStatus($value)
105 {
106 if($value == "none") return;
107 if(!$this->initially_was_account) return;
108 $ldap = $this->config->get_ldap_link();
109 $ldap->cd($this->dn);
110 $ldap->cat($this->dn,array("objectClass"));
111 if($ldap->count()){
113 $tmp = $ldap->fetch();
114 for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
115 $attrs['objectClass'][] = $tmp['objectClass'][$i];
116 }
117 $flag = $this->StatusFlag;
118 $attrs[$flag] = $value;
119 $this->$flag = $value;
120 $ldap->modify($attrs);
121 show_ldap_error($ldap->get_error());
122 $this->action_hook();
123 }
124 }
127 function check()
128 {
129 $message = plugin::check();
130 return($message);
131 }
134 function save_object()
135 {
136 plugin::save_object();
137 }
140 function action_hook($add_attrs= array())
141 {
142 /* Find postcreate entries for this class */
143 $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
144 if ($command == "" && isset($this->config->data['TABS'])){
145 $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
146 }
147 if ($command != ""){
148 /* Walk through attribute list */
149 foreach ($this->attributes as $attr){
150 if (!is_array($this->$attr)){
151 $command= preg_replace("/%$attr/", $this->$attr, $command);
152 }
153 }
154 $command= preg_replace("/%dn/", $this->dn, $command);
155 /* Additional attributes */
156 foreach ($add_attrs as $name => $value){
157 $command= preg_replace("/%$name/", $value, $command);
158 }
160 /* If there are still some %.. in our command, try to fill these with some other class vars */
161 if(preg_match("/%/",$command)){
162 $attrs = get_object_vars($this);
163 foreach($attrs as $name => $value){
164 if(!is_string($value)) continue;
165 $command= preg_replace("/%$name/", $value, $command);
166 }
167 }
169 if (check_command($command)){
170 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
171 $command, "Execute");
173 exec($command);
174 } else {
175 $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
176 print_red ($message);
177 }
178 }
179 }
182 /* Get updates for status flag */
183 function updateStatusState()
184 {
185 if(empty($this->StatusFlag)) return;
187 $attrs = array();
188 $flag = $this->StatusFlag;
189 $ldap = $this->config->get_ldap_link();
190 $ldap->cd($this->cn);
191 $ldap->cat($this->dn,array($flag));
192 if($ldap->count()){
193 $attrs = $ldap->fetch();
194 }
195 if(isset($attrs[$flag][0])){
196 $this->$flag = $attrs[$flag][0];
197 }
198 }
200 }
201 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
202 ?>