summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9d5d758)
raw | patch | inline | side by side (parent: 9d5d758)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 22 Aug 2007 09:13:21 +0000 (09:13 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 22 Aug 2007 09:13:21 +0000 (09:13 +0000) |
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 | [new file with mode: 0644] | patch | blob |
plugins/addons/gotomasses/class_gotomasses.inc | [new file with mode: 0644] | patch | blob |
plugins/addons/gotomasses/class_target_list.inc | [new file with mode: 0644] | patch | blob |
plugins/addons/gotomasses/goto_task.tpl | [new file with mode: 0644] | patch | blob |
plugins/addons/gotomasses/main.inc | [new file with mode: 0644] | patch | blob |
plugins/addons/gotomasses/remove.tpl | [new file with mode: 0644] | patch | blob |
diff --git a/plugins/addons/gotomasses/class_goto_task.inc b/plugins/addons/gotomasses/class_goto_task.inc
--- /dev/null
@@ -0,0 +1,344 @@
+<?php
+
+class goto_task extends plugin
+{
+ /* Definitions */
+ var $plHeadline = "System mass deployment";
+ var $plDescription = "This does something";
+
+ var $parent = NULL;
+
+ var $Minute = "*";
+ var $Hour = "*";
+ var $Day = "*";
+ var $Month = "*";
+ var $Weekday = "*";
+ var $Action = "install";
+ var $Comment = "";
+ var $OGroup = "keep_current";
+ var $OGroups = array();
+ var $Target = array();
+ var $Initial_Target = array();
+ var $Actions = array();
+ var $new = FALSE;
+ var $attributes = array("OGroup","Minute","Hour","Day","Month","Weekday","Action","Comment","Target","Initial_Target");
+
+
+ function goto_task($config,$parent,$data = array())
+ {
+ /* Set parent object */
+ $this->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" => "<input type='image' src='images/edittrash.png' name='remove_%KEY%'>" ,
+ "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
--- /dev/null
@@ -0,0 +1,447 @@
+<?php
+
+class gotomasses extends plugin
+{
+ /* Definitions */
+ var $plHeadline = "System deployment";
+ var $plDescription = "This does something";
+
+ /* attribute list for save action */
+ var $attributes= array();
+ var $objectclasses= array();
+
+ /* Source file that contains the gotomasses data */
+ var $data_file = "Undefined"; #Set in constructor
+
+ /* Queue tasks */
+ var $tasks = array();
+ var $current =false;
+ var $dialog = FALSE;
+ var $ids_to_remove = array();
+
+ function gotomasses($config, $dn= NULL)
+ {
+ /* Define source file */
+ $this->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"),"<pre>".$tmp."</pre>"));
+ $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"),
+ "<pre>".$this->target_to_string($entry)."</pre>"));
+ $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 = "<div style='padding:5px'>";
+ if(!preg_match("/disable/i",chkacl($this->acl,"create"))){
+ $header .= "<input type='image' src='images/gotomasses_new_task.png' name='new_task' class='center'> ";
+ }
+
+ /* Display add button if allowed */
+ if(!preg_match("/disable/i",chkacl($this->acl,"remove"))){
+ $header .= "<input type='image' src='images/edittrash.png' name='remove_multiple_task' class='center'> ";
+ }
+ $header .= "</div>";
+
+ /* Create divlist */
+ $divlist->SetListHeader($header);
+ /* Toggle all selected / deselected */
+ $chk = "<input type='checkbox' id='select_all' name='select_all'
+ onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
+
+ /* set Page header */
+ $divlist->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
+
+ $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&sort=object'>"._("Target")."</a>"));
+ $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&sort=schedule'>"._("Schedule")."</a>",
+ "attach"=>"style='width:100px;'"));
+ $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&sort=action'>"._("Type")."</a>",
+ "attach"=>"style='width:80px;'"));
+ $divlist->AddHeader(array("string"=>_("Action"),
+ "attach"=>"style='border-right:0px;width:40px;'"));
+
+ /* Create edit link */
+ $edit_link = "<div style='width:100%;overflow:hidden;'><nobr><a href='?plug=".$_GET['plug']."&act=edit&id=%key%'>%str%</nobr></div>";
+ foreach($this->tasks as $key => $task){
+ $action = "<input type='image' src='images/edit.png' name='edit_task_".$key."' class='center' alt='"._("Edit")."'>";
+ if(!preg_match("/disable/i",chkacl($this->acl,"remove"))){
+ $action.= "<input type='image' src='images/edittrash.png' name='remove_task_".$key."' class='center' alt='"._("Reomve")."'>";
+ }
+ /* Create each field */
+ $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
+ "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
--- /dev/null
@@ -0,0 +1,272 @@
+<?php
+
+class target_list extends MultiSelectWindow
+{
+ var $config;
+ var $list =array();
+ var $Targets_used =array();
+
+ /* Current base */
+ var $selectedBase = "";
+ var $departments = array();
+
+ /* Regex */
+ var $Regex = "*";
+
+ /* CheckBoxes, to change default values modify $this->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 = "<input type='checkbox' id='select_all' name='select_all'
+ onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
+ $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.= "<option selected='selected' value='".$dep."'>$value</option>";
+ } else {
+ $options.= "<option value='".$dep."'>$value</option>";
+ }
+ }
+ }
+
+ /* 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")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
+ " <input class='center' type='image' src='images/list_submit.png' align='middle'
+ title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
+ $listhead .="</div>";
+
+ $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 = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
+ $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
+
+ $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 = "<img src='images/select_server.png' alt='"._("Server")."' ".$title.">";
+ }elseif(in_array("gotoWorkstation",$val['objectClass'])){
+ $img = "<img src='images/select_workstation.png' alt='"._("Workstation")."' ".$title.">";
+ }elseif(in_array("gosaGroupOfNames",$val['objectClass'])){
+ $img = "<img src='images/list_ogroup.png' alt='"._("Object group")."' ".$title.">";
+ }
+
+ /* Create each field */
+ $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
+ "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
--- /dev/null
@@ -0,0 +1,177 @@
+<table style='width:100%'>
+ <tr>
+ <td colspan="2">
+ <h2><img alt="" src="images/head.png" class="center" align="middle"> {t}Generic{/t}</h2>
+ </td>
+ </tr>
+ <tr>
+ <td style='width:50%;border-right: 1px solid rgb(160, 160, 160);'>
+ <table>
+ <tr>
+ <td>
+ {t}Description{/t}
+ </td>
+ <td>
+ <input type="text" name="Comment" value="{$Comment}">
+ </td>
+ </tr>
+ <tr>
+ <td>
+ {t}Object group membership{/t}
+ </td>
+ <td>
+ <select name="OGroup">
+ {html_options options=$OGroups selected=$OGroup}
+ </select>
+ </td>
+ </tr>
+ </table>
+ </td>
+ <td style='vertical-align:top'>
+ <table>
+ <tr>
+ <td>
+ {t}Action{/t}
+ </td>
+ <td>
+ <select name="Action" onChange="document.mainform.submit();">
+ {html_options options=$Actions selected=$Action}
+ </select>
+ {if !$JS}
+ <input type='image' src='images/list_reload.png' class='center'>
+ {/if}
+ </td>
+ </tr>
+ </table>
+
+ </td>
+ </tr>
+</table>
+{if $Action == "initial_install"}
+<p class='seperator'> </p>
+<table style='width:100%;'>
+ <tr>
+ <td colspan="2" style='padding-top:5px;'>
+ <h2><img alt="" src="images/select_workstation.png" class="center" align="middle"> {t}Systems{/t}</h2>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="2">
+ <table summary="" style="border:1px solid #B0B0B0;width:100%; " id="t_test_scrolltable" cellspacing=0 cellpadding=0>
+ <tr>
+ <td>
+ {$Target_list}
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td style="width:50%; border-right: 1px solid #A0A0A0;">
+ <table>
+ <tr>
+ <td>{t}MAC address{/t}{$must}
+ </td>
+ <td><input type="text" name="task_MAC" value="">
+ </td>
+ </tr>
+ <tr>
+ <td>{t}Name{/t}
+ </td>
+ <td><input type="text" name="task_Name" value="">
+ </td>
+ </tr>
+ <tr>
+ <td>{t}IP address{/t}
+ </td>
+ <td><input type="text" name="task_IP" value="">
+ <input type="submit" name="add_target" value="{t}Add{/t}">
+ </td>
+ </tr>
+ </table>
+ </td>
+ <td>
+ <table>
+ <tr><td>{t}CVS import from file{/t}</td></tr>
+ <tr>
+ <td>
+
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
+ <input name="import_file" type="file" size="20" maxlength="255" accept="*.csv">
+ <input type="submit" name="add_import" value="{t}Import{/t}">
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+</table>
+
+{else}
+<p class='seperator'> </p>
+<table style='width:100%;'>
+ <tr>
+ <td colspan="2">
+ <h2><img alt="" src="images/time.png" class="center" align="middle"> {t}Schedule{/t}</h2>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="2">
+ {t}Minute{/t}
+ <select name='Minute'>
+ {html_options options=$Minutes selected=$Minute}
+ </select>
+ {t}Hour{/t}
+ <select name='Hour'>
+ {html_options options=$Hours selected=$Hour}
+ </select>
+ {t}Day{/t}
+ <select name='Day'>
+ {html_options options=$Days selected=$Day}
+ </select>
+ {t}Month{/t}
+ <select name='Month'>
+ {html_options options=$Months selected=$Month}
+ </select>
+ {t}Week day{/t}
+ <select name='Weekday'>
+ {html_options options=$Weekdays selected=$Weekday}
+ </select>
+ </td>
+ </tr>
+</table>
+<p class='seperator'> </p>
+<table style='width:100%;'>
+ <tr>
+ <td colspan="2" style='padding-top:5px;'>
+ <h2><img alt="" src="images/select_workstation.png" class="center" align="middle"> {t}Target systems{/t}</h2>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="2">
+ <table summary="" style="border:1px solid #B0B0B0;width:600px; " cellspacing=0 cellpadding=0>
+ <tr>
+ <td>
+ {$Target_list}
+ </td>
+ </tr>
+ </table>
+ <input type="text" name="target_text" value="">
+ <input type="submit" name="add_target" value="{t}Add{/t}">
+ <input type="submit" name="add_from_list" value="{t}Add from list{/t}">
+ </td>
+ </tr>
+</table>
+{/if}
+<p class='seperator'> </p>
+<input type='hidden' name='goto_task_posted' value='1'>
+<p style="text-align:right">
+ <input type='submit' name='save_goto_task' value='{t}Ok{/t}'>
+{if !$new}
+ <input type='submit' name='apply_goto_task' value='{t}Apply{/t}'>
+{/if}
+ <input type='submit' name='close_goto_task' value='{t}Abort{/t}'>
+</p>
diff --git a/plugins/addons/gotomasses/main.inc b/plugins/addons/gotomasses/main.inc
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+/*
+ This code is part of GOsa (https://gosa.gonicus.de)
+ Copyright (C) 2003 Cajus Pollmeier
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+if (!$remove_lock){
+
+ /* Create gotomasses object on demand */
+ if (!isset($_SESSION['gotomasses']) || (isset($_GET['reset']) && $_GET['reset'] == 1) || isset($_POST['reload_gotomass_data'])){
+ $_SESSION['gotomasses']= new gotomasses ($config);
+
+ }
+ $gotomasses= $_SESSION['gotomasses'];
+
+ /* set permissions */
+ $acl= get_permissions ($ui->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
--- /dev/null
@@ -0,0 +1,21 @@
+<div style="font-size:18px;">
+ <img alt="" src="images/button_cancel.png" align=top> {t}Warning{/t}
+</div>
+<p>
+ {$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}
+</p>
+
+<p>
+ {t}So - if you're sure - press 'Delete' to continue or 'Cancel' to abort.{/t}
+</p>
+
+<p class="plugbottom">
+{if $multiple}
+ <input type=submit name="delete_multiple_confirm" value="{t}Delete{/t}">
+{else}
+ <input type=submit name="delete_confirm" value="{t}Delete{/t}">
+{/if}
+ <input type=submit name="delete_cancel" value="{t}Cancel{/t}">
+</p>
+