From 7f75b39b1e136c655a969a4ae6ced1e00cd40ccd Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 22 Aug 2007 09:13:21 +0000 Subject: [PATCH] Added gotomasses git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@7102 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/addons/gotomasses/class_goto_task.inc | 344 ++++++++++++++ .../addons/gotomasses/class_gotomasses.inc | 447 ++++++++++++++++++ .../addons/gotomasses/class_target_list.inc | 272 +++++++++++ plugins/addons/gotomasses/goto_task.tpl | 177 +++++++ plugins/addons/gotomasses/main.inc | 46 ++ plugins/addons/gotomasses/remove.tpl | 21 + 6 files changed, 1307 insertions(+) create mode 100644 plugins/addons/gotomasses/class_goto_task.inc create mode 100644 plugins/addons/gotomasses/class_gotomasses.inc create mode 100644 plugins/addons/gotomasses/class_target_list.inc create mode 100644 plugins/addons/gotomasses/goto_task.tpl create mode 100644 plugins/addons/gotomasses/main.inc create mode 100644 plugins/addons/gotomasses/remove.tpl diff --git a/plugins/addons/gotomasses/class_goto_task.inc b/plugins/addons/gotomasses/class_goto_task.inc new file mode 100644 index 000000000..a92b93ead --- /dev/null +++ b/plugins/addons/gotomasses/class_goto_task.inc @@ -0,0 +1,344 @@ +parent = $parent; + $this->acl = $parent->acl; + + /* Intialize plugin */ + $this->config = $config; + if(count($data)){ + + $tmp = $this->get_array_values(); + foreach($this->attributes as $attr){ + if(!isset($data[$attr])){ + trigger_error("Missing parameter: '".$attr."' for goto_task contruction."); + }else{ + $this->$attr = $data[$attr]; + } + } + }else{ + $this->new = TRUE; + } + + /* Create ogroup select list */ + $this->OGroups = array("\"\"" => "["._("Keep current")."]"); + $this->OGroups = array_merge($this->OGroups,$this->parent->get_object_groups()); + + /* Prepare list of available actions */ + $this->Actions = $this->parent->get_actions(); + } + + + function execute() + { + /******** + * Handle Posts + ********/ + + /* Handle Target options */ + foreach($_POST as $name => $value){ + if(preg_match("/^remove_/",$name)){ + $value = preg_replace("/^remove_([0-9]*)_(x|y)$/i","\\1",$name); + if(isset($this->Target[$value]) && $this->Action != "initial_install"){ + unset($this->Target[$value]); + }elseif(isset($this->Initial_Target[$value]) && $this->Action == "initial_install"){ + unset($this->Initial_Target[$value]); + } + } + } + + if($this->Action != "initial_install"){ + + /* Add target */ + if(isset($_POST['add_target']) && !empty($_POST['target_text'])){ + $target = get_post("target_text"); + if($this->is_valid_target($target) && !in_array($target,$this->Target)){ + $this->Target[] = $target; + } + } + }else{ + + /* Add target */ + if(isset($_POST['add_target']) && !empty($_POST['task_MAC'])){ + $MAC = $_POST['task_MAC']; + $NAME= ""; + $IP = ""; + if(isset($_POST['task_Name'])){ + $NAME = $_POST['task_Name']; + } + if(isset($_POST['task_IP']) && is_ip($_POST['task_IP'])){ + $IP = $_POST['task_IP']; + } + if(is_mac($MAC)){ + $this->Initial_Target[] = array("MAC"=>$MAC,"IP"=>$IP,"NAME"=>$NAME); + } + } + } + + /* Add via csv */ + if(isset($_FILES['import_file'])){ + $file = $_FILES['import_file']['tmp_name']; + if(file_exists($file) && is_readable($file)){ + $str =""; + $fp = fopen($file,"r"); + while(!feof($fp)){ + $line = fgets($fp,512); + $tmp = preg_split("/(,|;)/",$line); + + $MAC = $IP = $NAME = ""; + if(isset($tmp[0])){ + $MAC = $tmp[0]; + } + if(isset($tmp[1])){ + $IP = $tmp[1]; + } + if(isset($tmp[2])){ + $NAME = $tmp[2]; + } + if(is_mac($MAC)){ + $this->Initial_Target[] = array("MAC"=>$MAC,"IP"=>$IP,"NAME"=>$NAME); + } + } + } + } + + /******** + * Add target from list + ********/ + + /* If add from list is was requsted, display this list */ + if(isset($_POST['add_from_list'])){ + $this->dialog = new target_list($this->config,$this->Target); + } + + /* Save selected objects as target */ + if(isset($_POST['SaveMultiSelectWindow'])){ + $this->dialog->save_object(); + $ret = $this->dialog->save(); + foreach($ret as $entry){ + $this->Target[] = $entry['cn'][0]; + } + $this->dialog = NULL; + } + + /* Cancel object listing */ + if(isset($_POST['CloseMultiSelectWindow'])){ + $this->dialog = NULL; + } + + /* Display object Listing */ + if($this->dialog){ + $this->dialog->save_object(); + return($this->dialog->execute()); + } + + /******** + * Display this plugin + ********/ + + $divlist = new divlist("goto_task"); + $divlist->SetHeight("160"); + $divlist->SetEntriesPerPage(0); + + if(!preg_match("/disable/i",chkacl($this->parent->acl,"remove"))){ + $field_del = array("string" => "" , + "attach" => "style='width:44px;border-right:0px;'"); + }else{ + $field_del = array("string" => "", + "attach" => "style='width:44px;border-right:0px;'"); + } + + /* Add entries to divlist */ + if($this->Action == "initial_install"){ + $divlist->SetHeader(array( + array("string" => _("Target systems")), + array("string" => _("IP") , "attach" => "style='width:90px;'"), + array("string" => _("Name") , "attach" => "style='width:150px;'"), + array("string" => _("Actions") , "attach" => "style='width:44px;border-right:0px;text-align:right;'"))); + foreach($this->Initial_Target as $key => $target){ + $field1 = array("string" => $target['MAC'] ); + $field2 = array("string" => $target['IP'] ,"attach" => "style='width:90px;'"); + $field3 = array("string" => $target['NAME'] ,"attach" => "style='width:150px;'"); + $divlist->AddEntry(array($field1,$field2,$field3,preg_replace("/%KEY%/",$key,$field_del))); + } + }else{ + $divlist->SetHeader(array( + array("string" => "Target", "attach" => "style=''"), + array("string" => "Actions" , "attach" => "style='width:44px;border-right:0px;text-align:right;'"))); + foreach($this->Target as $key => $target){ + $field1 = array("string" => $target); + $divlist->AddEntry(array($field1,preg_replace("/%KEY%/",$key,$field_del))); + } + } + + $smarty = get_smarty(); + foreach($this->attributes as $attr){ + $smarty->assign($attr."ACL", chkacl($this->parent->acl,$attr)); + $smarty->assign($attr,$this->$attr); + } + + $tmp = $this->get_array_values(); + $smarty->assign("JS" , $_SESSION['js']); + $smarty->assign("Minutes" , $tmp['Minute']); + $smarty->assign("Hours" , $tmp['Hour']); + $smarty->assign("Days" , $tmp['Day']); + $smarty->assign("Months" , $tmp['Month']); + $smarty->assign("Weekdays", $tmp['Weekday']); + $smarty->assign("OGroups" , $this->OGroups); + $smarty->assign("Actions" , $this->Actions); + $smarty->assign("Target_list" , $divlist->DrawList()); + $smarty->assign("new" , $this->new); + return ($smarty->fetch (get_template_path('goto_task.tpl', TRUE))); + } + + + /* check given values */ + function check() + { + $message = plugin::check(); + $tmp = array( + "OGroup" => _("Object group") ,"Minute" => _("Minute"), + "Hour" => _("Hour") ,"Day" => _("Day"), + "Month" => _("Month") ,"Weekday"=> _("Week day"), + "Action" => _("Action") ,"Comment"=> _("Description")); + + foreach($tmp as $name => $desc){ + if(empty($this->$name)){ + $message[] = sprintf(_("The given value for attribute '%s' is invalid."),$desc); + } + } + if(count($this->Target) == 0 && $this->Action != "initial_install"){ + $message[] = sprintf(_("You must specify at least one traget")); + } + if(count($this->Initial_Target) == 0 && $this->Action == "initial_install"){ + $message[] = sprintf(_("You must specify at least one traget")); + } + return($message); + } + + + function save_object() + { + if(isset($_POST['goto_task_posted'])){ + plugin::save_object(); + } + } + + + /* Check if given target is vald. + * It must either be a valid MAC address or an existing object group + */ + function is_valid_target($str) + { + if(is_mac($str)){ + return(TRUE); + }else{ + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(&(objectClassgosaGroupOfNames)(cn=".$str."))",array("cn")); + if($ldap->count()){ + return(TRUE); + } + } + } + + function save() + { + $tmp = array(); + foreach($this->attributes as $attr){ + $tmp[$attr] = $this->$attr; + } + return($tmp); + } + + + /* Return values for listboxes. + */ + function get_array_values() + { + $ret = array(); + + /* Create minute array */ + $Minute = array( "*" => "*", + "*/1" => "*/1", + "*/3" => "*/3", + "*/5" => "*/5", + "*/10" => "*/10", + "*/15" => "*/15", + "*/30" => "*/30", + "*/45" => "*/45", + "*/60" => "*/60"); + for($i = 0; $i < 60 ; $i ++){ + $Minute[$i] = $i; + } + + /* Create hour array */ + $Hour = array( "*" => "*"); + for($i = 1 ; $i < 24 ; $i ++ ){ + $Hour["*/".$i] = "*/".$i; + } + for($i = 0 ; $i < 24 ; $i ++ ){ + $Hour[$i] = $i; + } + + /* Create hour array */ + $Day = array( "*" => "*"); + for($i = 1 ; $i < 32 ; $i ++ ){ + $Day["*/".$i] = "*/".$i; + } + for($i = 1 ; $i < 32 ; $i ++ ){ + $Day[$i] = $i; + } + + /* Create month array */ + $Month = array( "*" => "*"); + for($i = 1 ; $i <= 12 ; $i ++ ){ + $Month["*/".$i] = "*/".$i; + } + for($i = 1 ; $i <= 12 ; $i ++ ){ + $Month[$i] = $i; + } + + /* Create week day array */ + $Weekday = array( "*" => "*"); + for($i = 1 ; $i <= 7 ; $i ++ ){ + $Weekday["*/".$i] = "*/".$i; + } + for($i = 0 ; $i <= 7 ; $i ++ ){ + $Weekday[$i] = $i; + } + + foreach(array("Minute","Weekday","Hour","Day","Month") as $var){ + $ret[$var] = $$var; + } + return($ret); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/addons/gotomasses/class_gotomasses.inc b/plugins/addons/gotomasses/class_gotomasses.inc new file mode 100644 index 000000000..9a20262b5 --- /dev/null +++ b/plugins/addons/gotomasses/class_gotomasses.inc @@ -0,0 +1,447 @@ +data_file = CONFIG_DIR."/gotomasses_machines"; + + /* Include config object */ + $this->config= $config; + $this->load_gotomasses_data(); + } + + + function execute() + { + $smarty = get_smarty(); + /************ + * Handle posts + ************/ + + $s_entry = $s_action = ""; + $arr = array( "/^edit_task_/"=>"edit","/^remove_task_/"=>"remove", + "/^new_task_/"=>"new_task","/^remove_multiple_task_/" => "remove_multiple"); + foreach($arr as $regex => $action){ + foreach($_POST as $name => $value){ + if(preg_match($regex,$name)){ + $s_action = $action; + $s_entry = preg_replace($regex,"",$name); + $s_entry = preg_replace("/_(x|y)$/","",$s_entry); + } + } + } + + /* Edit posted from list link */ + if(isset($_GET['act']) && $_GET['act'] == "edit" && isset($_GET['id']) && isset($this->tasks[$_GET['id']])){ + $s_action = "edit"; + $s_entry = $_GET['id']; + } + + /************ + * List posts + ************/ + + /* Remove multiple */ + if($s_action == "remove_multiple"){ + if(preg_match("/disable/i",chkacl($this->acl,"remove"))){ + print_red(_("You are not allowed to remove a task.")); + }else{ + $this->ids_to_remove = $this->list_get_selected_items(); + $tmp = ""; + foreach($this->ids_to_remove as $key => $id){ + if(isset($this->tasks[$id])){ + $task = $this->tasks[$id]; + $tmp.= "\n".$this->target_to_string($task); + }else{ + unset($this->ids_to_remove[$key]); + } + } + $smarty->assign("multiple", TRUE); + $smarty->assign("info",sprintf(_("Your are about to delete the following tasks: %s"),"
".$tmp."
")); + $this->current = $s_entry; + return($smarty->fetch(get_template_path('remove.tpl', TRUE))); + } + } + + /* Remove specified tasks */ + if(count($this->ids_to_remove) && isset($_POST['delete_multiple_confirm'])){ + foreach($this->ids_to_remove as $id){ + if(isset($this->tasks[$id])){ + unset($this->tasks[$id]); + } + } + $this->save(); + } + + /* Remove entry from list */ + if($s_action == "remove" && isset($this->tasks[$s_entry])){ + if(preg_match("/disable/i",chkacl($this->acl,"remove"))){ + print_red(_("You are not allowed to remove a task.")); + }else{ + $entry = $this->tasks[$s_entry]; + $this->current = $s_entry; + $smarty->assign("info",sprintf(_("Your are about to delete the following tasks: %s"), + "
".$this->target_to_string($entry)."
")); + $smarty->assign("multiple", FALSE); + return($smarty->fetch(get_template_path('remove.tpl', TRUE))); + } + } + + /* Remove entry, remove is confirmed */ + if($this->current != -1 && isset($_POST['delete_confirm'])){ + unset($this->tasks[$this->current]); + $this->current = -1; + $this->save(); + } + + /* Remove aborted */ + if(isset($_POST['delete_cancel'])){ + $this->ids_to_remove = array();; + } + + /* Edit selected entry */ + if($s_action == "edit" && isset($this->tasks[$s_entry])){ + $entry = $this->tasks[$s_entry]; + $this->dialog = new goto_task($this->config,$this,$entry); + $this->current = $s_entry; + } + + /* New entry */ + if(!preg_match("/disable/i",chkacl($this->acl,"create")) && $s_action== "new_task"){ + $this->dialog = new goto_task($this->config,$this); + $this->current = -1; + } + + /* Close dialog */ + if(isset($_POST['close_goto_task'])){ + $this->dialog = FALSE; + $this->current = -1; + } + + /* Close dialog */ + if((isset($_POST['save_goto_task']) || isset($_POST['apply_goto_task'])) && is_object($this->dialog) ){ + $this->dialog->save_object(); + $msgs = $this->dialog->check(); + if(count($msgs)){ + foreach($msgs as $msg){ + print_red($msg); + } + }else{ + if(isset($this->tasks[$this->current]) && $this->current != -1){ + $this->tasks[$this->current] = $this->dialog->save(); + }else{ + $this->tasks[] = $this->dialog->save(); + } + if(!isset($_POST['apply_goto_task'])){ + $this->dialog = FALSE; + $this->current = -1; + } + $this->save(); + } + } + + /* Display dialogs if currently opened */ + if(is_object($this->dialog)){ + $this->dialog->save_object(); + return($this->dialog->execute()); + } + + + /************ + * Handle Divlist + ************/ + + $plug = $_GET['plug']; + $divlist = new MultiSelectWindow($this->config,"GotoMasses","gotomassses"); + $divlist->SetSummary(_("List of system deployment tasks")); + $divlist->SetHeadpageMode(); + $divlist->EnableCloseButton(FALSE); + $divlist->EnableSaveButton(FALSE); + $divlist->SetInformation(_("This menu allows you to add, remove and change the properties of system deployment tasks.")); + + /* Display add button if allowed */ + $header = "
"; + if(!preg_match("/disable/i",chkacl($this->acl,"create"))){ + $header .= " "; + } + + /* Display add button if allowed */ + if(!preg_match("/disable/i",chkacl($this->acl,"remove"))){ + $header .= " "; + } + $header .= "
"; + + /* Create divlist */ + $divlist->SetListHeader($header); + /* Toggle all selected / deselected */ + $chk = ""; + + /* set Page header */ + $divlist->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'")); + + $divlist->AddHeader(array("string"=>""._("Target")."")); + $divlist->AddHeader(array("string"=>""._("Schedule")."", + "attach"=>"style='width:100px;'")); + $divlist->AddHeader(array("string"=>""._("Type")."", + "attach"=>"style='width:80px;'")); + $divlist->AddHeader(array("string"=>_("Action"), + "attach"=>"style='border-right:0px;width:40px;'")); + + /* Create edit link */ + $edit_link = "
%str%
"; + foreach($this->tasks as $key => $task){ + $action = ""; + if(!preg_match("/disable/i",chkacl($this->acl,"remove"))){ + $action.= ""; + } + /* Create each field */ + $field0 = array("string" => "" , + "attach" => "style='width:20px;'"); + + $field1 = array("string" => preg_replace(array("/%key%/","/%str%/"),array($key,$this->target_to_string($task)),$edit_link)); + $field2 = array("string" => $this->time_to_string($task),"attach" => "style='width:100px;'"); + $field3 = array("string" => $this->action_to_string($task),"attach" => "style='width:80px;'"); + $field4 = array("string" => $action,"attach" => "style='text-align:right;width:40px;border-right:0px;'"); + $divlist->AddElement(array($field0,$field1,$field2,$field3,$field4)); + } + + return($divlist->Draw()); + } + + + function target_to_string($data) + { + $ret = ""; + if($data['Action'] == "initial_install"){ + foreach($data['Initial_Target'] as $target){ + $ret .= $target['MAC'].", "; + } + }else{ + foreach($data['Target'] as $target){ + $ret .= $target.", "; + } + } + return(preg_replace("/, $/","",$ret)); + } + + + function time_to_string($data) + { + return($data['Minute']." ".$data['Hour']." ".$data['Day']." ".$data['Month']." ".$data['Weekday']); + } + + + function action_to_string($data) + { + $tmp = $this->get_actions(); + if(isset($tmp[$data['Action']])){ + return($tmp[$data['Action']]); + }else{ + return(_("Unknown")); + } + } + + + function load_gotomasses_data() + { + $ui = get_userinfo(); + + /* Check file existence */ + if(!file_exists($this->data_file) || !is_readable($this->data_file)){ + print_red(sprintf(_("Can't locate or read gotomasses storage file '%s'."),$this->data_file)); + return(FALSE); + } + + /* check if file is readable */ + $fp = @fopen($this->data_file,"r"); + if(!$fp){ + print_red(sprintf(_("Can't read gotomasses storage file '%s'."),$this->data_file)); + return(FALSE); + } + + /* Get file contents */ + $data =""; + while(!feof($fp)){ + $data.= fread($fp,512); + } + + /* Get lines from file */ + $this->tasks = array(); + $comment = ""; + $rows = split("\n",$data); + + /* Walk trough rows and parse data */ + foreach($rows as $row){ + + /* Skip empty lines */ + $row = trim($row); + if(empty($row)){ + continue; + } + + /* Get comment, if available */ + if(preg_match("/^#/",$row)){ + $comment = preg_replace("/^#/","",$row); + continue; + } + + /* Split row into minutes/ hours ...*/ + $row = preg_replace('/[\t ]/umi'," ",$row); + $row = preg_replace('/ */umi'," ",$row); + $parts = split(" ",$row); + + if(count($parts) != 8){ + print_red(_("Entry broken, skipped.")); + }else{ + + $entry = array(); + $entry['Minute'] = $parts[0]; + $entry['Hour'] = $parts[1]; + $entry['Day'] = $parts[2]; + $entry['Month'] = $parts[3]; + $entry['Weekday'] = $parts[4]; + $entry['Action'] = $parts[5]; + $entry['OGroup'] = $parts[6]; + if($entry['Action'] == "initial_install"){ + $tmp2 = split(";",$parts[7]); + foreach($tmp2 as $target){ + $tmp = split(",",$target); + $entry['Initial_Target'][] = array("MAC" => $tmp[0],"IP"=>$tmp[1],"NAME" => $tmp[2]); + } + $entry['Target'] = array(); + }else{ + $entry['Initial_Target'] = array(); + $entry['Target'] = split(";",$parts[7]); + } + $entry['Comment'] = $comment; + $this->tasks [] = $entry; + } + } + } + + + function save_gotomasses_data() + { + $str = "#GOsa generated file, please just modify if you realy know what you do."; + foreach($this->tasks as $task){ + $str .= "\n#".trim($task['Comment']); + $str .= "\n"; + if($task['Action'] == "initial_install"){ + $str .= "* * * * * "; + }else{ + $str .= str_pad($task['Minute'] ,5," ")." "; + $str .= str_pad($task['Hour'] ,5," ")." "; + $str .= str_pad($task['Day'] ,5," ")." "; + $str .= str_pad($task['Month'] ,5," ")." "; + $str .= str_pad($task['Weekday'],5," ")." "; + } + $str .= str_pad($task['Action'] ,5," ")." "; + $str .= str_pad($task['OGroup'] ,5," ")." "; + if($task['Action'] == "initial_install"){ + foreach($task['Initial_Target'] as $target){ + $str .= trim($target['MAC']).",".trim($target['IP']).",".trim($target['NAME']).";"; + } + }else{ + foreach($task['Target'] as $target){ + $str .= $target.";"; + } + } + $str = preg_replace("/;$/","",$str); + } + + /* check file existence*/ + $ui = get_userinfo(); + if(!file_exists($this->data_file) || !is_writeable($this->data_file)){ + print_red(sprintf(_("Can't locate or write gotomasses storage file '%s'."),$this->data_file)); + return(FALSE); + } + + /* check permissions */ + $fp = @fopen($this->data_file,"w"); + if(!$fp){ + print_red(sprintf(_("Can't read gotomasses storage file '%s'."),$this->data_file)); + return(FALSE); + } + + /* Write contents */ + $str .= "\n"; + fwrite($fp,$str); + fclose($fp); + } + + + function save_object() + { + } + + + /* Return list of object groups */ + function get_object_groups() + { + $ret = array(); + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(&(objectClass=gosaGroupOfNames)(cn=*))",array("cn")); + while($attrs = $ldap->fetch()){ + $ret[$attrs['cn'][0]] = $attrs['cn'][0]; + } + return($ret); + } + + + function save() + { + $this->save_gotomasses_data(); + } + + + function list_get_selected_items() + { + $ids = array(); + foreach($_POST as $name => $value){ + if(preg_match("/^item_selected_[0-9]*$/",$name)){ + $id = preg_replace("/^item_selected_/","",$name); + $ids[$id] = $id; + } + } + return($ids); + } + + + function get_actions() + { + /* Prepare list of available actions */ + $actions = array( "reboot" => _("Reboot"), + "localboot" => _("Localboot"), + "halt" => _("Halt system"), + "initial_install" => _("Initial installation"), + "update" => _("Update"), + "reinstall" => _("(Re)Install"), + "rescan" => _("Rescan"), + "wake" => _("Wake"), + "memcheck" => _("Memory check")); + return($actions); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/addons/gotomasses/class_target_list.inc b/plugins/addons/gotomasses/class_target_list.inc new file mode 100644 index 000000000..4c1e79e72 --- /dev/null +++ b/plugins/addons/gotomasses/class_target_list.inc @@ -0,0 +1,272 @@ +AddCheckBox */ + var $ogroups ; + var $servers ; + var $workstations ; + + + /* Subsearch checkbox */ + var $SubSearch ; + var $parent ; + var $ui ; + + + function target_list($config,$Targets_used) + { + MultiSelectWindow::MultiSelectWindow($config, "Targetselection", array("ogroup","gotomasses")); + + $this->Targets_used = $Targets_used; + + $this->SetInformation( _("Select the target objects for your scheduled action.")); + $this->SetTitle( _("Available targets")); + $this->SetSummary( _("Available targets")); + $this->SetHeadpageMode(FALSE); + + /* set Page header */ + $chk = ""; + $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'")); + + $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'")); + $this->AddHeader(array("string" => _("Object name"), "attach" => "style=''")); + + /* Text ,Value, Name, Is selected */ + $this->AddCheckBox("ogroups", _("Select to see object groups"), _("Show object object groups"), true); + $this->AddCheckBox("servers", _("Select to see servers") , _("Show servers"), true); + $this->AddCheckBox("workstations", _("Select to see workstations"),_("Show workstations"), true); + + /* Add SubSearch checkbox */ + $this->AddCheckBox(SEPERATOR); + $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Search in subtrees"), false); + + /* Name,Text,Default , Connect with alphabet */ + $this->AddRegex ("Regex", _("Regular expression for matching group names"), "*" , true); + $this->EnableAplhabet(TRUE); + } + + + function GenHeader() + { + $options= ""; + + /* Get all departments within this subtree */ + $ui= get_userinfo(); + $first = ""; + $found = FALSE; + $base = $this->config->current['BASE']; + + /* Add base */ + $tmp = array(); + $tmp[] = array("dn"=>$this->config->current['BASE']); + $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base, + array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH)); + + $deps = array(); + foreach($tmp as $tm){ + $deps[$tm['dn']] = $tm['dn']; + } + + /* Load possible departments */ + $ui= get_userinfo(); + $tdeps= $ui->get_module_departments("ogroups"); + $ids = $this->config->idepartments; + $first = ""; + $found = FALSE; + foreach($ids as $dep => $name){ + if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){ + + /* Keep first base dn in mind, we could need this + * info if no valid base was found + */ + if(empty($first)) { + $first = $dep['dn']; + } + + $value = $ids[$dep]; + if ($this->selectedBase == $dep){ + $found = TRUE; + $options.= ""; + } else { + $options.= ""; + } + } + } + + /* The currently used base is not visible with your acl setup. + * Set base to first useable base. + */ + if(!$found){ + $this->selectedBase = $first; + } + + /* Get copy & paste icon */ + $acls = $ui->get_permissions($this->selectedBase,"ogroups/ogroup"); + $acl_all= $ui->has_complete_category_acls($this->selectedBase,"ogroups"); + + /* Add default header */ + $listhead = MultiSelectWindow::get_default_header(); + + /* Add department selector */ + $listhead .= _("Base")." ". + "  "; + $listhead .=""; + + $this->SetListHeader($listhead); + } + + + function execute() + { + $this->ClearElementsList(); + $this->GenHeader(); + $this->reload(); + $this->SetEntries($this->list); + foreach($this->list as $key => $data){ + + } + return($this->Draw()); + } + + + function SetEntries($list) + { + /* Add Copy & Paste buttons if copy&paste is enabled + */ + // Defining Links + $linkopen = "%s"; + $editlink = "%s"; + + $ui = get_userinfo(); + + // Assigning ogroups + foreach($list as $key => $val){ + + if(in_array($val['cn'][0],$this->Targets_used) || + isset($val['macAddress'][0]) && in_array($val['macAddress'][0],$this->Targets_used)) continue; + + $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'"; + if(!isset($val['description'][0])){ + $desc = ""; + }else{ + $desc = " - [ ".$val['description'][0]." ]"; + } + + $img ="Hmm"; + if(in_array("goServer",$val['objectClass'])){ + $img = ""._("Server").""; + }elseif(in_array("gotoWorkstation",$val['objectClass'])){ + $img = ""._("Workstation").""; + }elseif(in_array("gosaGroupOfNames",$val['objectClass'])){ + $img = ""._("Object group").""; + } + + /* Create each field */ + $field0 = array("string" => "" , + "attach" => "style='width:20px;'"); + $field1 = array("string" => $img, + "attach" => "style='text- align:center;width: 20px;'"); + $field2 = array("string" => $val['cn'][0].$desc, + "attach" => "style='border-right:0px;' ".$title); + + $this->AddElement(array($field0,$field1,$field2)); + } + } + + + function save() + { + $ret = array(); + $items = $this->list_get_selected_items(); + foreach($items as $item){ + $ret[] = $this->list[$item]; + } + return($ret); + } + + + function save_object() + { + MultiSelectWindow::save_object(); + } + + + function reload() + { + /* Set base for all searches && initialise some vars */ + $this->list= array(); + $base = $this->selectedBase; + $filter = ""; + $Regex = $this->Regex; + + $chk = array( + "ogroups" => "(&(objectClass=gosaGroupOfNames)(|(gosaGroupObjects=*S*)(gosaGroupObjects=*W*)))" , + "servers" => "(objectClass=goServer)" , + "workstations" => "(objectClass=gotoWorkstation)"); + + /* Create filter */ + foreach($chk as $chkBox => $FilterPart){ + if($this->$chkBox){ + $filter .= $FilterPart; + } + } + $filter= "(&(cn=".$Regex.")(|".$filter."))"; + + if($this->SubSearch){ + $res= get_list($filter, array("ogroups","workstations","servers"), $base, + array("cn","objectClass","gosaGroupObjects"), GL_SIZELIMIT | GL_SUBSEARCH); + }else{ + $res= get_list($filter, "ogroups", get_groups_ou().$base, + array("cn","objectClass"), GL_SIZELIMIT ); + $res= array_merge($res,get_list($filter, "workstation", "ou=workstations,ou=systems,".$base, + array("cn","objectClass"), GL_SIZELIMIT )); + $res= array_merge($res,get_list($filter, "server", "ou=servers,ou=systems,".$base, + array("cn","objectClass"), GL_SIZELIMIT )); + + } + + $this->list= $res; + ksort ($this->list); + reset ($this->list); + $tmp=array(); + foreach($this->list as $tkey => $val ){ + $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val; + } + ksort($tmp); + $this->list=array(); + foreach($tmp as $val){ + $this->list[]=$val; + } + reset ($this->list); + } + + function list_get_selected_items() + { + $ids = array(); + foreach($_POST as $name => $value){ + if(preg_match("/^item_selected_[0-9]*$/",$name)){ + $id = preg_replace("/^item_selected_/","",$name); + $ids[$id] = $id; + } + } + return($ids); + } +} + + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/addons/gotomasses/goto_task.tpl b/plugins/addons/gotomasses/goto_task.tpl new file mode 100644 index 000000000..81c2b40eb --- /dev/null +++ b/plugins/addons/gotomasses/goto_task.tpl @@ -0,0 +1,177 @@ + + + + + + + + +
+

{t}Generic{/t}

+
+ + + + + + + + + +
+ {t}Description{/t} + + +
+ {t}Object group membership{/t} + + +
+
+ + + + + +
+ {t}Action{/t} + + + {if !$JS} + + {/if} +
+ +
+{if $Action == "initial_install"} +

 

+ + + + + + + + + + + +
+

{t}Systems{/t}

+
+ + + + +
+ {$Target_list} +
+
+ + + + + + + + + + + + + +
{t}MAC address{/t}{$must} + +
{t}Name{/t} + +
{t}IP address{/t} + + +
+
+ + + + + + + + +
{t}CVS import from file{/t}
+   +
+ + + +
+
+ +{else} +

 

+ + + + + + + +
+

{t}Schedule{/t}

+
+ {t}Minute{/t} + + {t}Hour{/t} + + {t}Day{/t} + + {t}Month{/t} + + {t}Week day{/t} + +
+

 

+ + + + + + + +
+

{t}Target systems{/t}

+
+ + + + +
+ {$Target_list} +
+ + + +
+{/if} +

 

+ +

+ +{if !$new} + +{/if} + +

diff --git a/plugins/addons/gotomasses/main.inc b/plugins/addons/gotomasses/main.inc new file mode 100644 index 000000000..9caebbf92 --- /dev/null +++ b/plugins/addons/gotomasses/main.inc @@ -0,0 +1,46 @@ +dn, $ui->subtreeACL); + $gotomasses->acl= get_module_permission($acl, "gotomasses", $ui->dn); + + /* Execute formular */ + $display= $gotomasses->save_object(); + if(isset($_POST['save_gotomass_changes'])){ + $gotomasses->save(); + } + $display= $gotomasses->execute (); + + /* Page header*/ + $display= print_header(get_template_path('images/system.png'), _("System deployment")).$display; + + /* Store changes in session */ + $_SESSION['gotomasses']= $gotomasses; +} diff --git a/plugins/addons/gotomasses/remove.tpl b/plugins/addons/gotomasses/remove.tpl new file mode 100644 index 000000000..023142f97 --- /dev/null +++ b/plugins/addons/gotomasses/remove.tpl @@ -0,0 +1,21 @@ +
+  {t}Warning{/t} +
+

+ {$info} + {t}This includes all account data, system access rules, imap settings, etc. for this user. Please double check if your really want to do this since there is no way for GOsa to get your data back.{/t} +

+ +

+ {t}So - if you're sure - press 'Delete' to continue or 'Cancel' to abort.{/t} +

+ +

+{if $multiple} + +{else} + +{/if} + +

+ -- 2.30.2