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