Code

Fixed acls for system management
[gosa.git] / plugins / admin / systems / class_goTerminalServer.inc
1 <?php
3 class goTerminalServer extends plugin{
4         
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("goXdmcpIsEnabled", "goFontPath");
12   var $StatusFlag       = "goTerminalServerStatus";
13  
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     $this->updateStatusState();
47     $flag = $this->StatusFlag;
48     $fields['Status']     = $this->$flag;
49     $fields['Message']    = _("Terminal service");
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(), sprintf(_("Removing server services/terminalServer with dn '%s' failed."),$this->dn));
80     $this->handle_post_events("remove");
81   }
84   function save()
85   {
86     plugin::save();
88     if(!$this->goXdmcpIsEnabled){
89       $this->attrs['goXdmcpIsEnabled'] = "0";
90     }
92     /* Check if this is a new entry ... add/modify */
93     $ldap = $this->config->get_ldap_link();
94     $ldap->cat($this->dn,array("objectClass"));
95     if($ldap->count()){
96       $ldap->cd($this->dn);
97       $ldap->modify($this->attrs);
98     }else{
99       $ldap->cd($this->dn);
100       $ldap->add($this->attrs);
101     }
102     show_ldap_error($ldap->get_error(), sprintf(_("Saving server services/terminalServer with dn '%s' failed."),$this->dn));
103     if($this->initially_was_account){
104       $this->handle_post_events("modify");
105     }else{
106       $this->handle_post_events("add");
107     }
108   }
111   /* Directly save new status flag */
112   function setStatus($value)
113   {
114     if($value == "none") return;
115     if(!$this->initially_was_account) return;
116     $ldap = $this->config->get_ldap_link();
117     $ldap->cd($this->dn);
118     $ldap->cat($this->dn,array("objectClass"));
119     if($ldap->count()){
121       $tmp = $ldap->fetch();
122       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
123         $attrs['objectClass'][] = $tmp['objectClass'][$i];
124       }
125       $flag = $this->StatusFlag;
126       $attrs[$flag] = $value;
127       $this->$flag = $value;
128       $ldap->modify($attrs);
129       show_ldap_error($ldap->get_error(), sprintf(_("Set status flag for server services/terminalServer with dn '%s' failed."),$this->dn));
130       $this->action_hook();
131     }
132   }
135   function check()
136   { 
137     $message = plugin::check();
138     if(empty($this->goFontPath)){
139       $message[]=_("Terminal server, must have fontpath specified.");
140     }
142     return($message);
143   }
146   function save_object()
147   {
148     if(isset($_POST['goTerminalServerPosted'])){
149       plugin::save_object();
150       if(isset($_POST['goXdmcpIsEnabled'])){
151         $this->goXdmcpIsEnabled = true;
152       }else{
153         $this->goXdmcpIsEnabled = false;
154       }
155     }
156   } 
158   function action_hook($add_attrs= array())
159   {
160     /* Find postcreate entries for this class */
161     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
162     if ($command == "" && isset($this->config->data['TABS'])){
163       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
164     }
165     if ($command != ""){
166       /* Walk through attribute list */
167       foreach ($this->attributes as $attr){
168         if (!is_array($this->$attr)){
169           $command= preg_replace("/%$attr/", $this->$attr, $command);
170         }
171       }
172       $command= preg_replace("/%dn/", $this->dn, $command);
173       /* Additional attributes */
174       foreach ($add_attrs as $name => $value){
175         $command= preg_replace("/%$name/", $value, $command);
176       }
178       /* If there are still some %.. in our command, try to fill these with some other class vars */
179       if(preg_match("/%/",$command)){
180         $attrs = get_object_vars($this);
181         foreach($attrs as $name => $value){
182           if(!is_string($value)) continue;
183           $command= preg_replace("/%$name/", $value, $command);
184         }
185       }
187       if (check_command($command)){
188         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
189             $command, "Execute");
191         exec($command);
192       } else {
193         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
194         print_red ($message);
195       }
196     }
197   }
200   /* Get updates for status flag */
201   function updateStatusState()
202   {
203     if(empty($this->StatusFlag)) return;
205     $attrs = array();
206     $flag = $this->StatusFlag;
207     $ldap = $this->config->get_ldap_link();
208     $ldap->cd($this->cn);
209     $ldap->cat($this->dn,array($flag));
210     if($ldap->count()){
211       $attrs = $ldap->fetch();
212     }
213     if(isset($attrs[$flag][0])){
214       $this->$flag = $attrs[$flag][0];
215     }
216   }
218     /* Return plugin informations for acl handling */
219   function plInfo()
220   {
221     return (array(
222           "plShortName"   => _("Terminal"),
223           "plDescription" => _("Terminal service"),
224           "plSelfModify"  => FALSE,
225           "plDepends"     => array(),
226           "plPriority"    => 0,
227           "plSection"     => array("administration"),
228           "plCategory"    => array("server"),
230           "plProvidedAcls"=> array(
231             "goXdmcpIsEnabled"  => _("Temporary disable login"),
232             "goFontPath"        => _("Font path"))
233           ));
234   }
238 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
239 ?>