1 <?php
3 class goTerminalServer extends plugin{
5 var $cli_summary = "This pluign is used within the ServerService Pluign \nand indicates that this server supports asterisk 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("goTerminalServer");
11 var $attributes = array("goTerminalServerStatus","goXdmcpIsEnabled", "goFontPath");
12 var $StatusFlag = "goTerminalServerStatus";
14 /* This class can't be assigned twice so it conflicts with itsself */
15 var $conflicts = array("goTerminalServer");
17 var $DisplayName = "";
18 var $dn = NULL;
19 var $acl;
20 var $cn = "";
21 var $goTerminalServerStatus = "";
22 var $goXdmcpIsEnabled = false;
23 var $goFontPath = "";
26 function goTerminalServer($config,$dn)
27 {
28 plugin::plugin($config,$dn);
29 $this->DisplayName = _("Terminal 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("goTerminalServer.tpl",TRUE,dirname(__FILE__))));
41 }
44 function getListEntry()
45 {
46 $flag = $this->StatusFlag;
47 $fields['Status'] = $this->$flag;
48 $fields['Message'] = _("Terminal service");
49 $fields['AllowStart'] = true;
50 $fields['AllowStop'] = true;
51 $fields['AllowRestart'] = true;
52 $fields['AllowRemove']= true;
53 $fields['AllowEdit'] = true;
54 return($fields);
55 }
58 function remove_from_parent()
59 {
60 plugin::remove_from_parent();
61 /* Check if this is a new entry ... add/modify */
62 $ldap = $this->config->get_ldap_link();
63 $ldap->cat($this->dn,array("objectClass"));
64 if($ldap->count()){
65 $ldap->cd($this->dn);
66 $ldap->modify($this->attrs);
67 }else{
68 $ldap->cd($this->dn);
69 $ldap->add($this->attrs);
70 }
71 show_ldap_error($ldap->get_error());
72 $this->handle_post_events("remove");
73 }
76 function save()
77 {
78 plugin::save();
80 if(!$this->goXdmcpIsEnabled){
81 $this->attrs['goXdmcpIsEnabled'] = "0";
82 }
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 if(empty($this->goFontPath)){
131 $message[]=_("Terminal server, must have fontpath specified.");
132 }
134 return($message);
135 }
138 function save_object()
139 {
140 if(isset($_POST['goTerminalServerPosted'])){
141 plugin::save_object();
142 if(isset($_POST['goXdmcpIsEnabled'])){
143 $this->goXdmcpIsEnabled = true;
144 }else{
145 $this->goXdmcpIsEnabled = false;
146 }
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 }
192 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
193 ?>