1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class divListSystem extends MultiSelectWindow
24 {
26 /* Current base */
27 var $selectedBase = "";
28 var $departments = array();
30 /* Regex */
31 var $Regex = "*";
32 var $UserRegex = "*";
34 /* CheckBoxes, to change default values modify $this->AddCheckBox */
35 var $ShowServers;
36 var $ShowTerminals;
37 var $ShowWorkstations;
38 var $ShowWinWorkstations;
39 var $ShowPrinters;
40 var $ShowDevices;
41 var $ShowPhones;
43 /* Subsearch checkbox */
44 var $SubSearch;
46 var $parent ;
47 var $ui ;
49 function divListSystem (&$config,$parent)
50 {
51 MultiSelectWindow::MultiSelectWindow($config, "System", array("server",
52 "workstation",
53 "terminal",
54 "phone",
55 "incoming",
56 "printer"));
58 $this->parent = $parent;
59 $this->ui = get_userinfo();
61 /* Set list strings */
62 $this->SetTitle(_("List of systems"));
63 $this->SetSummary(_("List of systems"));
65 /* Result page will look like a headpage */
66 $this->SetHeadpageMode();
67 $this->SetInformation(_("This menu allows you to add, remove and change the properties of specific systems. You can only add systems which have already been started once."));
69 $this->EnableAplhabet (true);
71 /* Disable buttonsm */
72 $this->EnableCloseButton(false);
73 $this->EnableSaveButton (false);
75 /* Dynamic action col, depending on snapshot icons */
76 $action_col_size = 110;
77 if($this->parent->snapshotEnabled()){
78 $action_col_size += 38;
79 }
81 /* Toggle all selected / deselected */
82 $chk = "<input type='checkbox' id='select_all' name='select_all'
83 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
85 /* set Page header */
86 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
87 $this->AddHeader(array("string"=>" ","attach"=>"style='width:20px;'"));
88 $this->AddHeader(array("string"=>_("System / Department")));
89 $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
91 /* Text ,Value ,Name ,Is selected */
92 $this->AddCheckBox("ShowServers", _("Select to see servers"), _("Show servers"), true);
93 $this->AddCheckBox("ShowTerminals", _("Select to see Linux terminals"), _("Show terminals") , true);
94 $this->AddCheckBox("ShowWorkstations", _("Select to see Linux workstations"), _("Show workstations"), true);
95 $this->AddCheckBox("ShowWinWorkstations", _("Select to see MicroSoft Windows based workstations"), _("Show windows based workstations"),true);
96 $this->AddCheckBox("ShowPrinters", _("Select to see network printers"), _("Show network printers") ,true);
97 $this->AddCheckBox("ShowPhones", _("Select to see VOIP phones"), _("Show phones") , true);
98 $this->AddCheckBox("ShowDevices", _("Select to see network devices"), _("Show network devices"), true);
100 /* Add SubSearch checkbox */
101 $this->AddCheckBox(SEPERATOR);
102 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Search in subtrees"), false);
104 /* Name ,Text ,Default , Connect with alphabet */
105 $this->AddRegex ("Regex", _("Display systems matching"),"*" , true);
106 $this->AddRegex ("UserRegex", _("Display systems of user"), "*" , false, "images/search_user.png");
107 }
109 function GenHeader()
110 {
111 /* Prepare departments,
112 which are shown in the listbox on top of the listbox
113 */
114 $options= "";
116 /* Get all departments within this subtree */
117 $base = $this->config->current['BASE'];
119 /* Add base */
120 $tmp = array();
121 $tmp[] = array("dn"=>$this->config->current['BASE']);
122 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
123 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
125 $deps = array();
126 foreach($tmp as $tm){
127 $deps[$tm['dn']] = $tm['dn'];
128 }
130 /* Load possible departments */
131 $ui= get_userinfo();
132 $first = "";
133 $found = FALSE;
134 $department = $departments = array();
135 foreach($this->module as $module){
136 $d = $ui->get_module_departments($module);
137 foreach($d as $department){
138 $departments[$department] = $department;
139 }
140 }
142 /* Load possible departments */
143 $ui= get_userinfo();
144 $ids = $this->config->idepartments;
145 $first = "";
146 $found = FALSE;
147 foreach($ids as $dep => $name){
148 if(isset($deps[$dep]) && in_array_ics($dep, $departments)){
150 /* Keep first base dn in mind, we could need this
151 * info if no valid base was found
152 */
153 if(empty($first)) {
154 $first = $dep['dn'];
155 }
157 $value = $ids[$dep];
158 if ($this->selectedBase == $dep){
159 $found = TRUE;
160 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
161 } else {
162 $options.= "<option value='".$dep."'>$value</option>";
163 }
164 }
165 }
168 /* The currently used base is not visible with your acl setup.
169 * Set base to first useable base.
170 */
171 if(!$found){
172 $this->selectedBase = $first;
173 }
175 /* If there is at least one c (Create) and one w (Write) acl in this combination
176 display the snapshot paste icon. BUT check the correct acls in the management plugin */
177 $all_module_acls = "";
178 foreach($this->module as $module){
179 $all_module_acls .= $ui->has_complete_category_acls($this->selectedBase,$module);
180 }
182 /* Must we add an additional seperator */
183 $add_sep = false;
185 /* Add default header */
186 $listhead = MultiSelectWindow::get_default_header();
188 /* Add base selection */
189 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
190 " <input class='center' type='image' src='images/list_submit.png' align='middle'
191 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ";
193 /* Handle create icons */
194 $s = ".|"._("Actions")."|\n";
195 $s.= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
196 " "._("Create")."|\n";
197 if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"terminal/termgeneric"))){
198 $s.= "...|<img src='images/select_terminal.png' alt='' border='0' class='center'>".
199 " "._("Terminal")."|"."newsystem_terminal|\n";
200 }
201 if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"workstation/workgeneric"))){
202 $s.= "...|<img src='images/select_workstation.png' alt='' border='0' class='center'>".
203 " "._("Workstation")."|"."newsystem_workstation|\n";
204 }
205 if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"workstation/servgeneric"))){
206 $s.= "...|<img src='images/select_server.png' alt='' border='0' class='center'>".
207 " "._("Server")."|"."newsystem_server|\n";
208 }
209 if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"phone/phoneGeneric"))){
210 $s.= "...|<img src='images/select_phone.png' alt='' border='0' class='center'>".
211 " "._("Phone")."|"."newsystem_phone|\n";
212 }
213 if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"printer/printgeneric"))){
214 $s.= "...|<img src='images/select_printer.png' alt='' border='0' class='center'>".
215 " "._("Printer")."|"."newsystem_printer|\n";
216 }
217 if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"component/componentGeneric"))){
218 $s.= "...|<img src='images/select_component.png' alt='' border='0' class='center'>".
219 " "._("Component")."|"."newsystem_component|\n";
220 }
222 $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
224 $s.= "..|<img src='images/rocket.png' alt='' border='0' class='center'>".
225 " "._("Trigger action")."|\n";
226 foreach($events['BY_TRIGGERED_ACTION'] as $event){
227 $name = $event['CLASS_NAME'];
228 $s.= "...|".$event['MenuImage']." ".$event['s_Menu_Name']."|trigger_event_".$name."\n";
229 }
231 $s.= "..|<img src='images/clock.png' alt='' border='0' class='center'>".
232 " "._("Schedule action")."|\n";
233 foreach($events['BY_SCHEDULED_ACTION'] as $name => $event){
234 $name = $event['CLASS_NAME'];
235 $s.= "...|".$event['MenuImage']." ".$event['s_Menu_Name']."|schedule_event_".$name."\n";
236 }
238 $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
239 " "._("Remove")."|"."remove_multiple|\n";
241 /* Add multiple copy & cut icons */
242 if(is_object($this->parent->CopyPasteHandler)){
243 $s.= "..|---|\n";
244 $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
245 " "._("Copy")."|"."multiple_copy_systems|\n";
246 $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
247 " "._("Cut")."|"."multiple_cut_systems|\n";
248 }
250 /* Get copy & paste icon */
251 $Copy_Paste ="";
252 if(preg_match("/(c.*w|w.*c)/",$all_module_acls) && $this->parent->CopyPasteHandler){
253 $s .= "..|---|\n";
254 if($this->parent->CopyPasteHandler->entries_queued()){
255 $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
256 $s.="..|".$img." "._("Paste")."|editPaste|\n";
257 }else{
258 $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
259 $s.="..|".$img." "._("Paste")."\n";
260 }
261 }
263 /* Add snapshot icons */
264 if(preg_match("/(c.*w|w.*c)/",$all_module_acls)){
265 $s .= "..|---|\n";
266 $s .= $this->get_snapshot_header(TRUE);
267 }
269 $this->SetDropDownHeaderMenu($s);
270 $this->SetListHeader($listhead);
271 }
273 function execute()
274 {
275 $this->ClearElementsList();
276 $this->GenHeader();
277 }
279 function setEntries($terminals)
280 {
281 $img1 = "<img class='center' src='images/printer.png' alt='C' title='"._("Cups Server") ."'>";
282 $img2 = "<img class='center' src='images/scanner.png' alt='L' title='"._("Log Db") ."'>";
283 $img3 = "<img class='center' src='images/select_terminal.png' alt='L' title='"._("Syslog Server") ."'>";
284 $img4 = "<img class='center' src='images/mailto.png' alt='M' title='"._("Mail Server") ."'>";
285 $img5 = "<img class='center' src='images/select_phone.png' alt='I' title='"._("Imap Server") ."'>";
286 $img6 = "<img class='center' src='images/fax_small.png' alt='F' title='"._("Nfs Server") ."'>";
287 $img7 = "<img class='center' src='images/select_winstation.png' alt='K' title='"._("Kerberos Server") ."'>";
288 $img8 = "<img class='center' src='images/select_phone.png' alt='A' title='"._("Asterisk Server") ."'>";
289 $img9 = "<img class='center' src='images/fax_small.png' alt='F' title='"._("Fax Server") ."'>";
290 $img10 = "<img class='center' src='images/save.png' alt='L' title='"._("Ldap Server") ."'>";
292 $empty ="<img src='images/empty.png' style='width:16px ; height: 16px;' class='center' alt=''>";
294 /* Dynamic action col, depending on snapshot icons */
295 $action_col_size = 110;
296 if($this->parent->snapshotEnabled()){
297 $action_col_size += 38;
298 }
300 // User and Template Images
301 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
303 /* ACL mapping */
304 $ui = get_userinfo();
305 $tabs = array(
306 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
307 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
308 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
309 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
310 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
311 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
312 "incoming" => array("CLASS"=>"", "TABCLASS" =>"", "ACL"=> "incoming/systems"),
313 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
316 $cnts = array("component" => 0 , "terminal" => 0 , "workstation" => 0 ,
317 "printer" => 0 , "phone" => 0 , "server" => 0,
318 "NewDevice" => 0, "winstation"=> 0);
320 // Test Every Entry and generate divlist Array
321 foreach($terminals as $key => $val){
323 /* Get system type, it is used to fetch the acls for the current object.
324 "winstation" acls are stored as 2winworkstation", so we have to map this here */
325 $type = $this->parent->get_system_type($val);
326 if($type == "winstation") {
327 $acl_type = "winworkstation";
328 }else{
329 $acl_type = $type;
330 }
332 /* Map NewDevice acls to workstation acls */
333 if($type == "NewDevice" || $type == "ArpNewDevice"){
334 $type = "incoming";
335 $acl_type = "incoming";
336 }
338 /* Get complete category acls */
339 $acl_all = $ui->has_complete_category_acls($val['dn'],$acl_type) ;
341 /* Get specific generic acls */
342 $acl = $ui->get_permissions($val['dn'],$tabs[$type]['ACL']);
344 $action ="";
345 if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
346 $action.= "<input class='center' type='image'
347 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
348 $action.= "<input class='center' type='image'
349 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
350 }
351 $action.= "<input class='center' type='image' src='images/edit.png'
352 alt='"._("edit")."' name='system_edit_%KEY%' title='"._("Edit system")."'>";
353 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
354 $action.= $this->GetSnapShotActions($val['dn']);
355 }else{
356 $action.= $empty." ".$empty." ";
357 }
360 if(preg_match("/d/",$acl)){
361 $action.= "<input class='center' type='image' src='images/edittrash.png'
362 alt='"._("delete")."' name='system_del_%KEY%' title='"._("Delete system")."'>";
363 }else{
364 $action.= $empty;
365 }
367 /* Generate picture list, which is currently disabled */
368 if(in_array("goCupsServer" ,$val['objectClass'])) $cups = $img1; else $cups =$empty;
369 if(in_array("goLogDBServer" ,$val['objectClass'])) $logdb = $img2; else $logdb =$empty;
370 if(in_array("goSyslogServer" ,$val['objectClass'])) $syslog = $img3; else $syslog=$empty;
371 if(in_array("goImapServer" ,$val['objectClass'])) $imap = $img4; else $imap =$empty;
372 if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba = $img5; else $samba =$empty;
373 if(in_array("goShareServer" ,$val['objectClass'])) $nfs = $img6; else $nfs =$empty;
374 if(in_array("goKrbServer" ,$val['objectClass'])) $krb = $img7; else $krb =$empty;
375 if(in_array("goFonServer" ,$val['objectClass'])) $fon = $img8; else $fon =$empty;
376 if(in_array("goFaxServer" ,$val['objectClass'])) $fax = $img9; else $fax =$empty;
377 if(in_array("goLdapServer" ,$val['objectClass'])) $ldap = $img10; else $ldap =$empty;
379 $pics = $cups.$logdb.$syslog.$imap.$samba.$nfs.$krb.$fon.$fax.$ldap;
380 $pics = ""; // Pictures currently hidden
382 $val['cn'][0]= preg_replace('/\$$/', '', $val['cn'][0]);
384 // Generate Array to Add
385 $dsc= "";
386 if (isset($val['description'][0])){
387 $dsc= " [".$val['description'][0]."]";
388 }
389 if((isset($val['is_new']))&&(!empty($val['is_new']))){
390 $display= $val["cn"][0]." ".$val['is_new'].$dsc;
391 }else{
392 $display= $val["cn"][0].$dsc;
393 }
396 /* Check if this is a terminal/workstation && if we are allowed to change the gotoRootPasswd */
397 $pwd_acl ="";
398 if(in_array("gotoWorkstation",$val['objectClass'])){
399 $pwd_acl = $ui->get_permissions($val['dn'],"workstation/workgeneric","gotoRootPasswd");
400 }
401 if(in_array("gotoTerminal",$val['objectClass'])){
402 $pwd_acl = $ui->get_permissions($val['dn'],"terminal/termgeneric","gotoRootPasswd");
403 }
404 if(preg_match("/w/",$pwd_acl)){
405 $action2 = "<input class='center' type='image' src='images/certs.png' alt='"._("Password")."' name='system_setpwd_%KEY%' title='"._("Set root password")."'>";
406 }else{
407 $action2 = $empty;
408 }
411 if(in_array("gotoWorkstation",$val['objectClass'])){
412 $action2= "<input class='center' type='image' src='images/cdrom.png' alt='"._("Create CD")."'
413 name='gen_cd_%KEY%' title='"._("Create FAI CD")."'> ".$action2;
414 }else{
415 $action2= $empty.$action2;
416 }
418 if(isset($val['message'])){
419 $display.= " (".$val['message'].")";
420 }
422 $img = $this->parent->convert_list($val);
424 /* Cutted objects should be displayed in light grey */
425 if($this->parent->CopyPasteHandler){
426 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
427 if($queue_data['dn'] == $val['dn']) {
428 $display = "<font color='#999999'>".$display."</font>";
429 break;
430 }
431 }
432 }
434 $type = $this->parent->get_system_type($val);
435 if($type == "ArpNewDevice"){
436 $type = "NewDevice";
437 }
438 $cnts[$type] ++;
441 /* Create each field */
442 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
443 "attach" => "style='width:20px;'");
445 $field1 = array("string" => sprintf($img['img'],$val['dn']), "attach" => "style='text-align:center;width:20px;'");
446 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
447 $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
448 $this->AddElement( array($field0,$field1,$field2,$field3));
449 }
451 /* Create summary string for list footer */
452 $num_deps=0;
453 if(!$this->SubSearch){
454 $num_deps = count($this->Added_Departments);
455 }
457 $num_ser_str = _("Number of listed servers");
458 $num_ws_str = _("Number of listed workstations");
459 $num_ter_str = _("Number of listed terminals");
460 $num_pho_str = _("Number of listed phones");
461 $num_prt_str = _("Number of listed printers");
462 $num_com_str = _("Number of listed network components");
463 $num_new_str = _("Number of listed new devices");
464 $num_wws_str = _("Number of listed windows workstations");
465 $num_dep_str = _("Number of listed departments");
467 $str = "<img class='center' src='images/select_server.png'
468 title='".$num_ser_str."' alt='".$num_ser_str."'> ".$cnts['server']." ";
469 $str.= "<img class='center' src='images/select_workstation.png'
470 title='".$num_ws_str."' alt='".$num_ws_str."'> ".$cnts['workstation']." ";
471 $str.= "<img class='center' src='images/select_terminal.png'
472 title='".$num_ter_str."' alt='".$num_ter_str."'> ".$cnts['terminal']." ";
473 $str.= "<img class='center' src='images/select_phone.png'
474 title='".$num_pho_str."' alt='".$num_pho_str."'> ".$cnts['phone']." ";
475 $str.= "<img class='center' src='images/select_printer.png'
476 title='".$num_prt_str."' alt='".$num_prt_str."'> ".$cnts['printer']." ";
477 $str.= "<img class='center' src='images/select_component.png'
478 title='".$num_com_str."' alt='".$num_com_str."'> ".$cnts['component']." ";
479 $str.= "<img class='center' src='images/select_newsystem.png'
480 title='".$num_new_str."' alt='".$num_new_str."'> ".$cnts['NewDevice']." ";
481 $str.= "<img class='center' src='images/select_winstation.png'
482 title='".$num_wws_str."' alt='".$num_wws_str."'> ".$cnts['winstation']." ";
483 $str.= "<img class='center' src='images/folder.png'
484 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
486 $this->set_List_Bottom_Info($str);
487 }
490 function Save()
491 {
492 MultiSelectWindow :: Save();
493 }
496 function save_object()
497 {
498 /* Save automatic created POSTs like regex, checkboxes */
499 MultiSelectWindow :: save_object();
502 }
503 }
504 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
505 ?>