1 <?php
3 class goCupsServer extends plugin{
5 var $cli_summary = "This plugin is used within the ServerService Pluign \nand indicates that this server supports cups management.";
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("goCupsServer");
11 var $attributes = array();
12 var $StatusFlag = "goCupsServerStatus";
14 /* This class can't be assigned twice so it conflicts with itsself */
15 var $conflicts = array("goCupsServer");
17 var $DisplayName = "";
18 var $dn = NULL;
19 var $acl;
20 var $cn = "";
21 var $goCupsServerStatus = "";
23 function goCupsServer($config,$dn)
24 {
25 plugin::plugin($config,$dn);
26 $this->DisplayName = _("Print 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("goCupsServer.tpl",TRUE,dirname(__FILE__))));
38 }
41 function getListEntry()
42 {
43 $this->updateStatusState();
44 $flag = $this->StatusFlag;
45 $fields['Status'] = $this->$flag;
46 $fields['Message'] = _("Print 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 if($this->initially_was_account){
95 $this->handle_post_events("modify");
96 }else{
97 $this->handle_post_events("add");
98 }
100 show_ldap_error($ldap->get_error());
101 }
104 /* Directly save new status flag */
105 function setStatus($value)
106 {
107 if($value == "none") return;
108 if(!$this->initially_was_account) return;
109 $ldap = $this->config->get_ldap_link();
110 $ldap->cd($this->dn);
111 $ldap->cat($this->dn,array("objectClass"));
112 if($ldap->count()){
114 $tmp = $ldap->fetch();
115 for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
116 $attrs['objectClass'][] = $tmp['objectClass'][$i];
117 }
118 $flag = $this->StatusFlag;
119 $attrs[$flag] = $value;
120 $this->$flag = $value;
121 $ldap->modify($attrs);
122 show_ldap_error($ldap->get_error());
123 $this->action_hook();
124 }
125 }
128 function check()
129 {
130 $message = plugin::check();
131 return($message);
132 }
135 function save_object()
136 {
137 plugin::save_object();
138 }
141 function action_hook($add_attrs= array())
142 {
143 /* Find postcreate entries for this class */
144 $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
145 if ($command == "" && isset($this->config->data['TABS'])){
146 $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
147 }
148 if ($command != ""){
149 /* Walk through attribute list */
150 foreach ($this->attributes as $attr){
151 if (!is_array($this->$attr)){
152 $command= preg_replace("/%$attr/", $this->$attr, $command);
153 }
154 }
155 $command= preg_replace("/%dn/", $this->dn, $command);
156 /* Additional attributes */
157 foreach ($add_attrs as $name => $value){
158 $command= preg_replace("/%$name/", $value, $command);
159 }
161 /* If there are still some %.. in our command, try to fill these with some other class vars */
162 if(preg_match("/%/",$command)){
163 $attrs = get_object_vars($this);
164 foreach($attrs as $name => $value){
165 if(!is_string($value)) continue;
166 $command= preg_replace("/%$name/", $value, $command);
167 }
168 }
170 if (check_command($command)){
171 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
172 $command, "Execute");
174 exec($command);
175 } else {
176 $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
177 print_red ($message);
178 }
179 }
180 }
183 /* Get updates for status flag */
184 function updateStatusState()
185 {
186 if(empty($this->StatusFlag)) return;
188 $attrs = array();
189 $flag = $this->StatusFlag;
190 $ldap = $this->config->get_ldap_link();
191 $ldap->cd($this->cn);
192 $ldap->cat($this->dn,array($flag));
193 if($ldap->count()){
194 $attrs = $ldap->fetch();
195 }
196 if(isset($attrs[$flag][0])){
197 $this->$flag = $attrs[$flag][0];
198 }
199 }
201 }
202 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
203 ?>