1 <?php
3 class goFaxServer extends plugin{
5 var $cli_summary = "This pluign is used within the ServerService Pluign \nand indicates that this server supports fax informations.";
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("goFaxServer");
11 var $attributes = array("goFaxAdmin", "goFaxPassword");
12 var $StatusFlag = "goFaxServerStatus";
14 /* This class can't be assigned twice so it conflicts with itsself */
15 var $conflicts = array("goFaxServer");
17 var $DisplayName = "";
18 var $dn = NULL;
19 var $acl;
21 var $goFaxAdmin = "";
22 var $goFaxPassword = "";
23 var $goFaxServerStatus = "";
24 var $cn = "";
26 function goFaxServer($config,$dn)
27 {
28 plugin::plugin($config,$dn);
29 $this->DisplayName = _("FAX 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("goFaxServer.tpl",TRUE,dirname(__FILE__))));
41 }
44 function getListEntry()
45 {
46 $this->updateStatusState();
47 $flag = $this->StatusFlag;
48 $fields['Status'] = $this->$flag;
49 $fields['Message'] = _("FAX database configuration");
50 $fields['AllowStart'] = true;
51 $fields['AllowStop'] = true;
52 $fields['AllowRestart'] = true;
53 $fields['AllowRemove']= true;
54 $fields['AllowEdit'] = true;
55 return($fields);
56 }
59 function remove_from_parent()
60 {
61 plugin::remove_from_parent();
63 /* Remove status flag, it is not a memeber of
64 this->attributes, so ensure that it is deleted too */
65 if(!empty($this->StatusFlag)){
66 $this->attrs[$this->StatusFlag] = array();
67 }
69 /* Check if this is a new entry ... add/modify */
70 $ldap = $this->config->get_ldap_link();
71 $ldap->cat($this->dn,array("objectClass"));
72 if($ldap->count()){
73 $ldap->cd($this->dn);
74 $ldap->modify($this->attrs);
75 }else{
76 $ldap->cd($this->dn);
77 $ldap->add($this->attrs);
78 }
79 show_ldap_error($ldap->get_error());
80 $this->handle_post_events("remove");
81 }
84 function save()
85 {
86 plugin::save();
87 /* Check if this is a new entry ... add/modify */
88 $ldap = $this->config->get_ldap_link();
89 $ldap->cat($this->dn,array("objectClass"));
90 if($ldap->count()){
91 $ldap->cd($this->dn);
92 $ldap->modify($this->attrs);
93 }else{
94 $ldap->cd($this->dn);
95 $ldap->add($this->attrs);
96 }
97 if($this->initially_was_account){
98 $this->handle_post_events("modify");
99 }else{
100 $this->handle_post_events("add");
101 }
102 show_ldap_error($ldap->get_error());
103 }
106 /* Directly save new status flag */
107 function setStatus($value)
108 {
109 if($value == "none") return;
110 if(!$this->initially_was_account) return;
111 $ldap = $this->config->get_ldap_link();
112 $ldap->cd($this->dn);
113 $ldap->cat($this->dn,array("objectClass"));
114 if($ldap->count()){
116 $tmp = $ldap->fetch();
117 for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
118 $attrs['objectClass'][] = $tmp['objectClass'][$i];
119 }
120 $flag = $this->StatusFlag;
121 $attrs[$flag] = $value;
122 $this->$flag = $value;
123 $ldap->modify($attrs);
124 show_ldap_error($ldap->get_error());
125 $this->action_hook();
126 }
127 }
130 function check()
131 {
132 $message = plugin::check();
133 if (empty($this->goFaxAdmin)){
134 $message[]= _("The attribute user is empty or contains invalid characters.");
135 }
136 if (empty($this->goFaxPassword)){
137 $message[]= _("The attribute password is empty or contains invalid characters.");
138 }
139 return($message);
140 }
143 function save_object()
144 {
145 if(isset($_POST['goFaxServerPosted'])){
146 plugin::save_object();
147 }
148 }
150 function action_hook($add_attrs= array())
151 {
152 /* Find postcreate entries for this class */
153 $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
154 if ($command == "" && isset($this->config->data['TABS'])){
155 $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
156 }
157 if ($command != ""){
158 /* Walk through attribute list */
159 foreach ($this->attributes as $attr){
160 if (!is_array($this->$attr)){
161 $command= preg_replace("/%$attr/", $this->$attr, $command);
162 }
163 }
164 $command= preg_replace("/%dn/", $this->dn, $command);
165 /* Additional attributes */
166 foreach ($add_attrs as $name => $value){
167 $command= preg_replace("/%$name/", $value, $command);
168 }
170 /* If there are still some %.. in our command, try to fill these with some other class vars */
171 if(preg_match("/%/",$command)){
172 $attrs = get_object_vars($this);
173 foreach($attrs as $name => $value){
174 if(!is_string($value)) continue;
175 $command= preg_replace("/%$name/", $value, $command);
176 }
177 }
179 if (check_command($command)){
180 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
181 $command, "Execute");
183 exec($command);
184 } else {
185 $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
186 print_red ($message);
187 }
188 }
189 }
191 /* Get updates for status flag */
192 function updateStatusState()
193 {
194 if(empty($this->StatusFlag)) return;
196 $attrs = array();
197 $flag = $this->StatusFlag;
198 $ldap = $this->config->get_ldap_link();
199 $ldap->cd($this->cn);
200 $ldap->cat($this->dn,array($flag));
201 if($ldap->count()){
202 $attrs = $ldap->fetch();
203 }
204 if(isset($attrs[$flag][0])){
205 $this->$flag = $attrs[$flag][0];
206 }
207 }
208 }
209 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
210 ?>