e6a949ab3e8b677588bb39666b7cc24f348e99e4
1 <?php
3 class termgeneric extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary= "Manage terminal base objects";
7 var $cli_description= "Some longer text\nfor help";
8 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10 /* Generic terminal attributes */
11 var $gotoMode= "disabled";
12 var $gotoTerminalPath= "";
13 var $gotoSwapServer= "";
14 var $gotoSyslogServer= "";
15 var $gotoNtpServer= "";
16 var $gotoSndModule= "";
17 var $gotoFloppyEnable= "";
18 var $gotoCdromEnable= "";
19 var $ghCpuType= "-";
20 var $ghMemSize= "-";
21 var $ghUsbSupport= "-";
22 var $ghNetNic= array();
23 var $ghIdeDev= array();
24 var $ghScsiDev= array();
25 var $ghGfxAdapter= "-";
26 var $ghSoundAdapter= "-";
27 var $gotoLastUser= "-";
28 var $netConfigDNS;
29 /* Needed values and lists */
30 var $base= "";
31 var $cn= "";
32 var $orig_dn= "";
34 /* Plugin side filled */
35 var $modes= array();
37 /* attribute list for save action */
38 var $ignore_account= TRUE;
39 var $attributes= array("gotoMode", "gotoTerminalPath",
40 "gotoSwapServer", "gotoSyslogServer", "gotoNtpServer",
41 "gotoFloppyEnable", "gotoCdromEnable", "cn", "gotoSndModule",
42 "ghCpuType", "ghMemSize","ghUsbSupport",
43 "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser");
44 var $objectclasses= array("top", "gotoTerminal", "GOhard");
46 function termgeneric ($config, $dn= NULL)
47 {
48 plugin::plugin ($config, $dn);
49 $this->netConfigDNS = new termDNS($this->config,$this->dn,$this->objectclasses);
50 /* Read arrays */
51 foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
52 if (!isset($this->attrs[$val])){
53 continue;
54 }
55 for ($i= 0; $i<$this->attrs[$val]['count']; $i++){
56 array_push($this->$val, $this->attrs[$val][$i]);
57 }
58 }
60 $this->modes["disabled"]= _("disabled");
61 $this->modes["text"]= _("text");
62 $this->modes["graphic"]= _("graphic");
64 /* Set base */
65 if ($this->dn == "new"){
66 $ui= get_userinfo();
67 $this->base= dn2base($ui->dn);
68 } else {
69 $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
70 }
72 $this->orig_dn= $this->dn;
73 }
75 function execute()
76 {
77 /* Call parent execute */
78 plugin::execute();
80 /* Do we need to flip is_account state? */
81 if (isset($_POST['modify_state'])){
82 $this->is_account= !$this->is_account;
83 }
85 if (isset($_POST['action'])){
86 switch($_POST['saction']){
87 case 'wake':
88 $cmd= search_config($this->config->data['TABS'], "termgeneric", "WAKECMD");
89 if ($cmd == ""){
90 print_red(_("No WAKECMD definition found in your gosa.conf"));
91 } else {
92 exec ($cmd." ".$this->netConfigDNS->macAddress, $dummy, $retval);
93 if ($retval != 0){
94 print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
95 }
96 }
97 break;
99 case 'reboot':
100 $cmd= search_config($this->config->data['TABS'], "termgeneric", "REBOOTCMD");
101 if ($cmd == ""){
102 print_red(_("No REBOOTCMD definition found in your gosa.conf"));
103 } else {
104 exec ($cmd." ".$this->cn, $dummy, $retval);
105 if ($retval != 0){
106 print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
107 }
108 }
109 break;
111 case 'halt':
112 $cmd= search_config($this->config->data['TABS'], "termgeneric", "HALTCMD");
113 if ($cmd == ""){
114 print_red(_("No HALTCMD definition found in your gosa.conf"));
115 } else {
116 exec ($cmd." ".$this->cn, $dummy, $retval);
117 if ($retval != 0){
118 print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
119 }
120 }
121 break;
122 }
123 }
125 /* Do we represent a valid terminal? */
126 if (!$this->is_account && $this->parent == NULL){
127 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
128 _("This 'dn' has no terminal features.")."</b>";
129 return($display);
130 }
132 /* Fill templating stuff */
133 $smarty= get_smarty();
134 $smarty->assign("cn", $this->cn);
135 $smarty->assign("staticAddress", "");
137 $smarty->assign("bases", $this->config->idepartments);
139 /* Check if terminal is online */
140 $query= "fping -q -r 1 -t 500 ".$this->cn;
141 exec ($query, $dummy, $retval);
143 /* Offline */
144 if ($retval == 0){
145 $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot")));
146 } else {
147 $smarty->assign("actions", array("wake" => _("Wake up")));
148 }
149 /* Arrays */
150 $smarty->assign("modes", $this->modes);
152 $tmp2 = array();
153 foreach($this->config->data['SERVERS']['NFS'] as $server){
154 if($server != "default"){
155 $tmp = split("\|",$server);
156 $tmp3= split(":",$tmp[0]);
158 $servername = $tmp3[0];
159 $nfsname = $tmp3[1];
161 $path ="";
162 if(isset($tmp[4])){
163 $path = $tmp[4];
164 }
166 $tmp2[$servername.":".$path]= $servername.":".$path;
167 }else{
168 $tmp2[$server]=$server;
169 }
170 }
172 $smarty->assign("nfsservers", $tmp2);
173 $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']);
174 $smarty->assign("ntpservers", $this->config->data['SERVERS']['NTP']);
176 /* Variables */
177 foreach(array("base", "gotoMode", "gotoTerminalPath", "gotoSwapServer",
178 "gotoSyslogServer", "gotoNtpServer") as $val){
180 $smarty->assign($val."_select", $this->$val);
181 $smarty->assign($val."ACL", chkacl($this->acl, $val));
182 }
184 /* Show main page */
185 $smarty->assign("netconfig", $this->netConfigDNS->execute());
186 $smarty->assign("actionACL", chkacl($this->acl, 'action'));
187 return($smarty->fetch (get_template_path('terminal.tpl', TRUE)));
188 }
190 function remove_from_parent()
191 {
193 $ldap= $this->config->get_ldap_link();
194 $ldap->cd($this->dn);
195 $ldap->cat($this->dn);
196 if($ldap->count()){
198 $ldap->rmdir($this->dn);
199 show_ldap_error($ldap->get_error());
201 /* Optionally execute a command after we're done */
202 $this->handle_post_events("remove");
204 /* Delete references to object groups */
205 $ldap->cd ($this->config->current['BASE']);
206 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
207 while ($ldap->fetch()){
208 $og= new ogroup($this->config, $ldap->getDN());
209 unset($og->member[$this->dn]);
210 $og->save ();
211 }
212 $this->netConfigDNS->remove_from_parent();
213 }
214 }
217 /* Save data to object */
218 function save_object()
219 {
220 plugin::save_object();
221 $this->netConfigDNS->save_object();
222 /* Save base, since this is no LDAP attribute */
223 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
224 $this->base= $_POST['base'];
225 }
227 /* Save terminal path to parent since it is used by termstartup, too */
228 $this->parent->by_object['termstartup']->gotoTerminalPath=
229 $this->gotoTerminalPath;
230 }
233 /* Check supplied data */
234 function check()
235 {
236 $message= $this->netConfigDNS->check();
238 /* Permissions for that base? */
239 $this->dn= "cn=".$this->cn."ou=terminals,ou=systems,".$this->base;
241 $ui= get_userinfo();
242 $acl= get_permissions ($this->dn, $ui->subtreeACL);
243 $acl= get_module_permission($acl, "group", $this->dn);
244 if (chkacl($acl, "create") != ""){
245 $message[]= _("You have no permissions to create a terminal on this 'Base'.");
246 }
248 if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
249 $message[]= _("The required field 'Terminal name' is not set.");
250 }
252 if ($this->orig_dn == 'new'){
253 $ldap= $this->config->get_ldap_link();
254 $ldap->cd ($this->base);
255 $ldap->search ("(&(objectClass=gotoTerminal)(cn=".$this->cn."))", array("cn"));
256 if ($ldap->count() != 0){
257 while ($attrs= $ldap->fetch()){
258 if (preg_match ("/,ou=incoming,/", $ldap->getDN())){
259 continue;
260 } else {
261 if ($attrs['dn'] != $this->orig_dn){
262 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
263 break;
264 }
265 }
266 }
267 }
268 }
270 return ($message);
271 }
274 /* Save to LDAP */
275 function save()
276 {
277 plugin::save();
279 /* Strip out 'default' values */
280 foreach (array("gotoTerminalPath", "gotoSwapServer", "gotoSyslogServer") as $val){
282 if ($this->attrs[$val] == "default"){
283 $this->attrs[$val]= array();
284 }
285 }
287 /* Add missing arrays */
288 foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){
289 if (isset ($this->$val) && count ($this->$val) != 0){
290 $this->attrs["$val"]= $this->$val;
291 }
292 }
294 /* Remove all empty values */
295 if ($this->orig_dn == 'new'){
296 $attrs= array();
297 foreach ($this->attrs as $key => $val){
298 if (is_array($val) && count($val) == 0){
299 continue;
300 }
301 $attrs[$key]= $val;
302 }
303 $this->attrs= $attrs;
304 }
306 /* Write back to ldap */
307 $ldap= $this->config->get_ldap_link();
308 if ($this->orig_dn == 'new'){
309 $ldap->cd($this->config->current['BASE']);
310 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
311 $ldap->cd($this->dn);
312 $ldap->add($this->attrs);
313 $this->handle_post_events("add");
314 } else {
315 if ($this->orig_dn != $this->dn){
316 $this->move($this->orig_dn, $this->dn);
317 }
318 $ldap->cd($this->dn);
319 $ldap->modify($this->attrs);
320 $this->handle_post_events("modify");
321 }
322 $this->netConfigDNS->save($this->dn);
323 show_ldap_error($ldap->get_error());
325 /* Optionally execute a command after we're done */
326 $this->postcreate();
327 }
329 }
331 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
332 ?>