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("goFaxServerStatus","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 = "";
25 function goFaxServer($config,$dn)
26 {
27 plugin::plugin($config,$dn);
28 $this->DisplayName = _("FAX service");
29 }
32 function execute()
33 {
34 $smarty = get_smarty();
35 foreach($this->attributes as $attr){
36 $smarty->assign($attr,$this->$attr);
37 $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
38 }
39 return($smarty->fetch(get_template_path("goFaxServer.tpl",TRUE,dirname(__FILE__))));
40 }
43 function getListEntry()
44 {
45 $flag = $this->StatusFlag;
46 $fields['Status'] = $this->$flag;
47 $fields['Message'] = _("FAX database configuration");
48 $fields['AllowStart'] = true;
49 $fields['AllowStop'] = true;
50 $fields['AllowRestart'] = true;
51 $fields['AllowRemove']= true;
52 $fields['AllowEdit'] = true;
53 return($fields);
54 }
57 function remove_from_parent()
58 {
59 plugin::remove_from_parent();
60 /* Check if this is a new entry ... add/modify */
61 $ldap = $this->config->get_ldap_link();
62 $ldap->cat($this->dn,array("objectClass"));
63 if($ldap->count()){
64 $ldap->cd($this->dn);
65 $ldap->modify($this->attrs);
66 }else{
67 $ldap->cd($this->dn);
68 $ldap->add($this->attrs);
69 }
70 show_ldap_error($ldap->get_error());
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 }
91 /* Directly save new status flag */
92 function setStatus($value)
93 {
94 if($value == "none") return;
95 if(!$this->initially_was_account) return;
96 $ldap = $this->config->get_ldap_link();
97 $ldap->cd($this->dn);
98 $ldap->cat($this->dn,array("objectClass"));
99 if($ldap->count()){
101 $tmp = $ldap->fetch();
102 for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
103 $attrs['objectClass'][] = $tmp['objectClass'][$i];
104 }
105 $flag = $this->StatusFlag;
106 $attrs[$flag] = $value;
107 $this->$flag = $value;
108 $ldap->modify($attrs);
109 show_ldap_error($ldap->get_error());
110 $this->action_hook();
111 }
112 }
115 function check()
116 {
117 $message = plugin::check();
118 if (empty($this->goFaxAdmin)){
119 $message[]= _("The attribute user is empty or contains invalid characters.");
120 }
121 if (empty($this->goFaxPassword)){
122 $message[]= _("The attribute password is empty or contains invalid characters.");
123 }
124 return($message);
125 }
128 function save_object()
129 {
130 if(isset($_POST['goFaxServerPosted'])){
131 plugin::save_object();
132 }
133 }
135 function action_hook($add_attrs= array())
136 {
137 /* Find postcreate entries for this class */
138 $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
139 if ($command == "" && isset($this->config->data['TABS'])){
140 $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
141 }
142 if ($command != ""){
143 /* Walk through attribute list */
144 foreach ($this->attributes as $attr){
145 if (!is_array($this->$attr)){
146 $command= preg_replace("/%$attr/", $this->$attr, $command);
147 }
148 }
149 $command= preg_replace("/%dn/", $this->dn, $command);
150 /* Additional attributes */
151 foreach ($add_attrs as $name => $value){
152 $command= preg_replace("/%$name/", $value, $command);
153 }
154 if (check_command($command)){
155 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
156 $command, "Execute");
158 exec($command);
159 } else {
160 $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
161 print_red ($message);
162 }
163 }
164 }
166 }
167 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
168 ?>